00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef CELENGINE_LODSPHEREMESH_H_
00011 #define CELENGINE_LODSPHEREMESH_H_
00012
00013 #include <celmath/vecmath.h>
00014 #include <celmath/frustum.h>
00015 #include <celengine/mesh.h>
00016 #include <celengine/texture.h>
00017 #include <celengine/glcontext.h>
00018
00019
00020 #define MAX_SPHERE_MESH_TEXTURES 4
00021 #define NUM_SPHERE_VERTEX_BUFFERS 2
00022
00023 class LODSphereMesh
00024 {
00025 public:
00026 LODSphereMesh();
00027 ~LODSphereMesh();
00028
00029 void render(const GLContext&,
00030 unsigned int attributes, const Frustum&, float pixWidth,
00031 Texture** tex, int nTextures);
00032 void render(const GLContext&,
00033 unsigned int attributes, const Frustum&, float pixWidth,
00034 Texture* tex0 = NULL, Texture* tex1 = NULL,
00035 Texture* tex2 = NULL, Texture* tex3 = NULL);
00036 void render(const GLContext&,
00037 const Frustum&, float pixWidth,
00038 Texture** tex, int nTextures);
00039
00040 enum {
00041 Normals = 0x01,
00042 Tangents = 0x02,
00043 Colors = 0x04,
00044 TexCoords0 = 0x08,
00045 TexCoords1 = 0x10,
00046 VertexProgParams = 0x1000,
00047 Multipass = 0x10000000,
00048 };
00049
00050 private:
00051 struct RenderInfo
00052 {
00053 RenderInfo(int _step,
00054 unsigned int _attr,
00055 const Frustum& _frustum,
00056 const GLContext& _context) :
00057 step(_step),
00058 attributes(_attr),
00059 frustum(_frustum),
00060 context(_context)
00061 {};
00062
00063 int step;
00064 unsigned int attributes;
00065 const Frustum& frustum;
00066 Point3f fp[8];
00067 int texLOD[MAX_SPHERE_MESH_TEXTURES];
00068 const GLContext& context;
00069 };
00070
00071 int renderPatches(int phi0, int theta0,
00072 int extent,
00073 int level,
00074 const RenderInfo&);
00075
00076 void renderSection(int phi0, int theta0, int extent, const RenderInfo&);
00077
00078 float* vertices;
00079
00080 int maxVertices;
00081 int vertexSize;
00082
00083 int nIndices;
00084 unsigned short* indices;
00085
00086 int nTexturesUsed;
00087 Texture* textures[MAX_SPHERE_MESH_TEXTURES];
00088 unsigned int subtextures[MAX_SPHERE_MESH_TEXTURES];
00089
00090 bool vertexBuffersInitialized;
00091 bool useVertexBuffers;
00092 int currentVB;
00093 unsigned int vertexBuffers[NUM_SPHERE_VERTEX_BUFFERS];
00094 unsigned int indexBuffer;
00095 };
00096
00097 #endif // CELENGINE_LODSPHEREMESH_H_