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.

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