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 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 _MESH_H_
  10. #define _MESH_H_
  11. #include "loader/Loader.h"
  12. /*!
  13. * \brief OpenGL Mesh
  14. */
  15. class Mesh {
  16. public:
  17. struct rectangle_t {
  18. struct vertex_t a, b, c, d;
  19. uint16_t texture;
  20. };
  21. Mesh();
  22. ~Mesh();
  23. void drawAlpha();
  24. void drawSolid();
  25. // Warning: texture is not the GL texture id,
  26. // it is an index into the object texture list!
  27. void addTexturedRectangle(struct vertex_t a, struct vertex_t b,
  28. struct vertex_t c, struct vertex_t d, uint16_t texture);
  29. void addTexturedTriangle(struct vertex_t a, struct vertex_t b,
  30. struct vertex_t c, uint16_t texture);
  31. std::vector<struct rectangle_t> texturedRectangles;
  32. std::vector<struct rectangle_t> coloredRectangles;
  33. std::vector<struct rectangle_t> texturedTriangles;
  34. std::vector<struct rectangle_t> coloredTriangles;
  35. // Old API
  36. typedef enum {
  37. MeshModeSolid,
  38. MeshModeWireframe,
  39. MeshModeTexture,
  40. MeshModeMultiTexture
  41. } MeshMode;
  42. typedef enum {
  43. fMesh_UseVertexArray = (1 << 0)
  44. } MeshFlags;
  45. typedef struct {
  46. int texture;
  47. #ifdef MULTITEXTURE
  48. int bumpmap;
  49. #endif
  50. unsigned int cnum_triangles;
  51. unsigned int cnum_alpha_triangles;
  52. unsigned int num_texcoors;
  53. float** texcoors; // 2D
  54. unsigned int num_texcoors2;
  55. float** texcoors2; // 2D
  56. //! Arrays of triangle indices sorted by texture
  57. unsigned int num_triangles;
  58. unsigned int* triangles; //!< ABCABCABC...
  59. //! Arrays of alpha triangle indices sorted by texture
  60. unsigned int num_alpha_triangles;
  61. unsigned int* alpha_triangles; //!< ABCABCABC...
  62. } tris_t;
  63. typedef struct {
  64. int texture;
  65. #ifdef MULTITEXTURE
  66. int bumpmap;
  67. #endif
  68. unsigned int cnum_quads;
  69. unsigned int cnum_alpha_quads;
  70. unsigned int num_texcoors;
  71. float** texcoors; // 2D
  72. unsigned int num_texcoors2;
  73. float** texcoors2; // 2D
  74. //! Arrays of rectangle indices sorted by texture
  75. unsigned int num_quads;
  76. unsigned int* quads; //!< ABCDABCDABCD...
  77. //! Arrays of alpha rectangle indices sorted by texture
  78. unsigned int num_alpha_quads;
  79. unsigned int* alpha_quads; //!< ABCDABCDABCD...
  80. } rect_t;
  81. void drawAlphaOld();
  82. void drawSolidOld();
  83. void allocateColors(unsigned int n);
  84. void allocateNormals(unsigned int n);
  85. void allocateRectangles(unsigned int n);
  86. void allocateTriangles(unsigned int n);
  87. void allocateVertices(unsigned int n);
  88. void bufferColorArray(unsigned int colorCount, float* colors);
  89. void bufferNormalArray(unsigned int normalCount, float* normals);
  90. void bufferTriangles(unsigned int count,
  91. unsigned int* indices, float* texCoords,
  92. int* textures, unsigned int* flags);
  93. void bufferVertexArray(unsigned int vertexCount, float* 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. #if 0
  99. void sortFacesByTexture();
  100. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  101. unsigned int vertexIndexCount, float* vertexIndices);
  102. void addTexTiledFace(int textureIndex, int textureIndexB,
  103. unsigned int flags, unsigned int indexCount,
  104. float* vertexIndices, float* texcoords);
  105. void bufferTexcoords(unsigned int texcoordCount, float* texcoords);
  106. void duplicateArraysForTexTiledTexcoords();
  107. #endif
  108. unsigned int mFlags;
  109. MeshMode mMode;
  110. unsigned int mNumVertices;
  111. float** mVertices; //!< XYZ
  112. unsigned int mNumNormals;
  113. float** mNormals; //!< IJK
  114. unsigned int mNumColors;
  115. float** 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. float* mTriangleTexCoordArray;
  125. float* mVertexArray;
  126. float* mNormalArray;
  127. float* mColorArray;
  128. };
  129. #endif