Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpenGLMesh.h 4.9KB

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