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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. void bufferNormalArray(unsigned int normalCount, vec_t *normals);
  81. void bufferTriangles(unsigned int count,
  82. unsigned int *indices, vec_t *texCoords,
  83. int *textures, unsigned int *flags);
  84. void bufferVertexArray(unsigned int vertexCount, vec_t *vertices);
  85. void setColor(unsigned int index, float r, float g, float b, float a);
  86. void setColor(unsigned int index, float rgba[4]);
  87. void setNormal(unsigned int index, float i, float j, float k);
  88. void setVertex(unsigned int index, float x, float y, float z);
  89. #ifdef NOT_IMPLEMENTED
  90. void sortFacesByTexture();
  91. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  92. unsigned int vertexIndexCount, vec_t *vertexIndices);
  93. void addTexTiledFace(int textureIndex, int textureIndexB,
  94. unsigned int flags, unsigned int indexCount,
  95. vec_t *vertexIndices, vec_t *texcoords);
  96. void bufferTexcoords(unsigned int texcoordCount, vec_t *texcoords);
  97. void duplicateArraysForTexTiledTexcoords();
  98. #endif
  99. unsigned int mFlags;
  100. OpenGLMeshMode mMode;
  101. unsigned int mNumVertices;
  102. vec3_t *mVertices; //!< XYZ
  103. unsigned int mNumNormals;
  104. vec3_t *mNormals; //!< IJK
  105. unsigned int mNumColors;
  106. vec4_t *mColors; //!< RGBA
  107. unsigned int mNumTris;
  108. tris_t *mTris;
  109. unsigned int mNumQuads;
  110. rect_t *mQuads;
  111. unsigned int mTriangleCount;
  112. int *mTriangleTextures;
  113. unsigned int *mTriangleIndices;
  114. unsigned int *mTriangleFlags;
  115. vec_t *mTriangleTexCoordArray;
  116. vec_t *mVertexArray;
  117. vec_t *mNormalArray;
  118. vec_t *mColorArray;
  119. };
  120. #endif