Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

OpenGLMesh.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*!
  2. * \file OpenGLMesh.h
  3. * \brief OpenGL Mesh
  4. *
  5. * Defining UNIT_TEST_OPENGLMESH builds OpenGLMesh class as a console unit test
  6. *
  7. * \author Mongoose
  8. *
  9. * \todo Unify the parallel systems here, arrays and the allocate/set
  10. */
  11. #ifndef GUARD__OPENRAIDER_MONGOOSE_OPENGLMESH_H_
  12. #define GUARD__OPENRAIDER_MONGOOSE_OPENGLMESH_H_
  13. #include "hel/math.h"
  14. class OpenGLMesh {
  15. public:
  16. typedef enum {
  17. OpenGLMeshModeSolid = 0,
  18. OpenGLMeshModeWireframe = 1,
  19. OpenGLMeshModeTexture = 2,
  20. OpenGLMeshModeMultiTexture = 3
  21. } OpenGLMeshMode;
  22. typedef enum {
  23. fOpenGLMesh_Transparent = 1,
  24. fOpenGLMesh_BumpMap = 2,
  25. fOpenGLMesh_UseVertexArray = 4
  26. } OpenGLMeshFlags;
  27. typedef struct tris_s {
  28. int texture;
  29. #ifdef MULTITEXTURE
  30. int bumpmap;
  31. #endif
  32. unsigned int cnum_triangles;
  33. unsigned int cnum_alpha_triangles;
  34. unsigned int num_texcoors;
  35. vec2_t *texcoors;
  36. unsigned int num_texcoors2;
  37. vec2_t *texcoors2;
  38. //! Arrays of triangle indices sorted by texture
  39. unsigned int num_triangles;
  40. unsigned int *triangles; //!< ABCABCABC...
  41. //! Arrays of alpha triangle indices sorted by texture
  42. unsigned int num_alpha_triangles;
  43. unsigned int *alpha_triangles; //!< ABCABCABC...
  44. } tris_t;
  45. typedef struct rect_s {
  46. int texture;
  47. #ifdef MULTITEXTURE
  48. int bumpmap;
  49. #endif
  50. unsigned int cnum_quads;
  51. unsigned int cnum_alpha_quads;
  52. unsigned int num_texcoors;
  53. vec2_t *texcoors;
  54. unsigned int num_texcoors2;
  55. vec2_t *texcoors2;
  56. //! Arrays of rectangle indices sorted by texture
  57. unsigned int num_quads;
  58. unsigned int *quads; //!< ABCDABCDABCD...
  59. //! Arrays of alpha rectangle indices sorted by texture
  60. unsigned int num_alpha_quads;
  61. unsigned int *alpha_quads; //!< ABCDABCDABCD...
  62. } rect_t;
  63. ////////////////////////////////////////////////////////////
  64. // Constructors
  65. ////////////////////////////////////////////////////////////
  66. /*!
  67. * \brief Constructs an object of OpenGLMesh
  68. */
  69. OpenGLMesh();
  70. /*!
  71. * \brief Deconstructs an object of OpenGLMesh
  72. */
  73. ~OpenGLMesh();
  74. ////////////////////////////////////////////////////////////
  75. // Public Accessors
  76. ////////////////////////////////////////////////////////////
  77. void drawAlpha();
  78. void drawSolid();
  79. ////////////////////////////////////////////////////////////
  80. // Public Mutators
  81. ////////////////////////////////////////////////////////////
  82. void allocateColors(unsigned int n);
  83. void allocateNormals(unsigned int n);
  84. void allocateRectangles(unsigned int n);
  85. void allocateTriangles(unsigned int n);
  86. void allocateVertices(unsigned int n);
  87. void bufferColorArray(unsigned int colorCount, vec_t *colors,
  88. unsigned int colorWidth);
  89. void bufferNormalArray(unsigned int normalCount, vec_t *normals);
  90. void bufferTriangles(unsigned int count,
  91. unsigned int *indices, vec_t *texCoords,
  92. int *textures, unsigned int *flags);
  93. void bufferVertexArray(unsigned int vertexCount, vec_t *vertices);
  94. void setColor(unsigned int index, float r, float g, float b, float a);
  95. void setColor(unsigned int index, float rgba[4]);
  96. void setNormal(unsigned int index, float i, float j, float k);
  97. void setVertex(unsigned int index, float x, float y, float z);
  98. #ifdef NOT_IMPLEMENTED
  99. void sortFacesByTexture();
  100. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  101. unsigned int vertexIndexCount, vec_t *vertexIndices);
  102. void addTexTiledFace(int textureIndex, int textureIndexB,
  103. unsigned int flags, unsigned int indexCount,
  104. vec_t *vertexIndices, vec_t *texcoords);
  105. void bufferTexcoords(unsigned int texcoordCount, vec_t *texcoords);
  106. void duplicateArraysForTexTiledTexcoords();
  107. #endif
  108. unsigned int mFlags;
  109. OpenGLMeshMode mMode;
  110. unsigned int mNumVertices;
  111. vec3_t *mVertices; //!< XYZ
  112. unsigned int mNumNormals;
  113. vec3_t *mNormals; //!< IJK
  114. unsigned int mNumColors;
  115. vec4_t *mColors; //!< RGBA
  116. unsigned int mNumTris;
  117. tris_t *mTris;
  118. unsigned int mNumQuads;
  119. rect_t *mQuads;
  120. unsigned int mTriangleCount;
  121. int *mTriangleTextures;
  122. unsigned int *mTriangleIndices;
  123. unsigned int *mTriangleFlags;
  124. vec_t *mTriangleTexCoordArray;
  125. vec_t *mVertexArray;
  126. vec_t *mNormalArray;
  127. vec_t *mColorArray;
  128. private:
  129. ////////////////////////////////////////////////////////////
  130. // Private Accessors
  131. ////////////////////////////////////////////////////////////
  132. ////////////////////////////////////////////////////////////
  133. // Private Mutators
  134. ////////////////////////////////////////////////////////////
  135. };
  136. #endif