Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Mesh.h 3.8KB

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