lodspheremesh.h
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:3k
源码类别:

OpenGL

开发平台:

Visual C++

  1. // lodspheremesh.h
  2. // 
  3. // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
  4. //
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. #ifndef CELENGINE_LODSPHEREMESH_H_
  10. #define CELENGINE_LODSPHEREMESH_H_
  11. #include <celmath/vecmath.h>
  12. #include <celmath/frustum.h>
  13. #include <celengine/mesh.h>
  14. #include <celengine/texture.h>
  15. #include <celengine/glcontext.h>
  16. #define MAX_SPHERE_MESH_TEXTURES 6
  17. #define NUM_SPHERE_VERTEX_BUFFERS 2
  18. class LODSphereMesh
  19. {
  20. public:
  21.     LODSphereMesh();
  22.     ~LODSphereMesh();
  23.     void render(const GLContext&,
  24.                 unsigned int attributes, const Frustum&, float pixWidth,
  25.                 Texture** tex, int nTextures);
  26.     void render(const GLContext&,
  27.                 unsigned int attributes, const Frustum&, float pixWidth,
  28.                 Texture* tex0 = NULL, Texture* tex1 = NULL,
  29.                 Texture* tex2 = NULL, Texture* tex3 = NULL);
  30.     void render(const GLContext&,
  31.                 const Frustum&, float pixWidth,
  32.                 Texture** tex, int nTextures);
  33.     enum {
  34.         Normals    = 0x01,
  35.         Tangents   = 0x02,
  36.         Colors     = 0x04,
  37.         TexCoords0 = 0x08,
  38.         TexCoords1 = 0x10,
  39.         VertexProgParams = 0x1000,
  40.         Multipass  = 0x10000000,
  41.     };
  42.  private:
  43.     struct RenderInfo
  44.     {
  45.         RenderInfo(int _step,
  46.                    unsigned int _attr,
  47.                    const Frustum& _frustum,
  48.                    const GLContext& _context) :
  49.             step(_step),
  50.             attributes(_attr),
  51.             frustum(_frustum),
  52.             context(_context)
  53.         {};
  54.         int step;                 
  55.         unsigned int attributes;  // vertex attributes
  56.         const Frustum& frustum;   // frustum, for culling
  57.         Point3f fp[8];            // frustum points, for culling
  58.         int texLOD[MAX_SPHERE_MESH_TEXTURES];
  59.         const GLContext& context;
  60.     };
  61.     int renderPatches(int phi0, int theta0, 
  62.                       int extent,
  63.                       int level,
  64.                       const RenderInfo&);
  65.     void renderSection(int phi0, int theta0, int extent, const RenderInfo&);
  66.     float* vertices;
  67.     int maxVertices;
  68.     int vertexSize;
  69.     int nIndices;
  70.     unsigned short* indices;
  71.     int nTexturesUsed;
  72.     Texture* textures[MAX_SPHERE_MESH_TEXTURES];
  73.     unsigned int subtextures[MAX_SPHERE_MESH_TEXTURES];
  74.     bool vertexBuffersInitialized;
  75.     bool useVertexBuffers;
  76.     int currentVB;
  77.     unsigned int vertexBuffers[NUM_SPHERE_VERTEX_BUFFERS];
  78.     unsigned int indexBuffer;
  79. };
  80. #endif // CELENGINE_LODSPHEREMESH_H_