Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Mesh.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "glm/vec3.hpp"
  12. /*!
  13. * \brief OpenGL Mesh
  14. */
  15. class Mesh {
  16. public:
  17. struct rectangle_t {
  18. glm::vec3 a, b, c, d;
  19. uint16_t texture;
  20. float red, green, blue;
  21. rectangle_t(glm::vec3 _a, glm::vec3 _b, glm::vec3 _c, glm::vec3 _d, uint16_t t,
  22. float re = 0.0f, float gr = 0.0f, float bl = 0.0f)
  23. : a(_a), b(_b), c(_c), d(_d), texture(t), red(re), green(gr), blue(bl) { }
  24. };
  25. Mesh();
  26. ~Mesh();
  27. void drawAlpha();
  28. void drawSolid();
  29. void addTexturedRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, uint16_t textile);
  30. void addTexturedTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, uint16_t textile);
  31. void addColoredRectangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, glm::vec3 d, float re, float gr,
  32. float bl);
  33. void addColoredTriangle(glm::vec3 a, glm::vec3 b, glm::vec3 c, float re, float gr, float bl);
  34. void addNormal(glm::vec3 n);
  35. std::vector<rectangle_t> texturedRectangles;
  36. std::vector<rectangle_t> coloredRectangles;
  37. std::vector<rectangle_t> texturedTriangles;
  38. std::vector<rectangle_t> coloredTriangles;
  39. std::vector<glm::vec3> normals;
  40. // Old API
  41. typedef enum {
  42. MeshModeSolid,
  43. MeshModeWireframe,
  44. MeshModeTexture,
  45. MeshModeMultiTexture
  46. } MeshMode;
  47. typedef enum {
  48. fMesh_UseVertexArray = (1 << 0)
  49. } MeshFlags;
  50. typedef struct {
  51. int texture;
  52. #ifdef MULTITEXTURE
  53. int bumpmap;
  54. #endif
  55. unsigned int cnum_triangles;
  56. unsigned int cnum_alpha_triangles;
  57. unsigned int num_texcoors;
  58. float** texcoors; // 2D
  59. unsigned int num_texcoors2;
  60. float** texcoors2; // 2D
  61. //! Arrays of triangle indices sorted by texture
  62. unsigned int num_triangles;
  63. unsigned int* triangles; //!< ABCABCABC...
  64. //! Arrays of alpha triangle indices sorted by texture
  65. unsigned int num_alpha_triangles;
  66. unsigned int* alpha_triangles; //!< ABCABCABC...
  67. } tris_t;
  68. typedef struct {
  69. int texture;
  70. #ifdef MULTITEXTURE
  71. int bumpmap;
  72. #endif
  73. unsigned int cnum_quads;
  74. unsigned int cnum_alpha_quads;
  75. unsigned int num_texcoors;
  76. float** texcoors; // 2D
  77. unsigned int num_texcoors2;
  78. float** texcoors2; // 2D
  79. //! Arrays of rectangle indices sorted by texture
  80. unsigned int num_quads;
  81. unsigned int* quads; //!< ABCDABCDABCD...
  82. //! Arrays of alpha rectangle indices sorted by texture
  83. unsigned int num_alpha_quads;
  84. unsigned int* alpha_quads; //!< ABCDABCDABCD...
  85. } rect_t;
  86. void drawAlphaOld();
  87. void drawSolidOld();
  88. void allocateColors(unsigned int n);
  89. void allocateNormals(unsigned int n);
  90. void allocateRectangles(unsigned int n);
  91. void allocateTriangles(unsigned int n);
  92. void allocateVertices(unsigned int n);
  93. void bufferColorArray(unsigned int colorCount, float* colors);
  94. void bufferNormalArray(unsigned int normalCount, float* normals);
  95. void bufferTriangles(unsigned int count,
  96. unsigned int* indices, float* texCoords,
  97. int* textures, unsigned int* flags);
  98. void bufferVertexArray(unsigned int vertexCount, float* vertices);
  99. void setColor(unsigned int index, float r, float g, float b, float a);
  100. void setColor(unsigned int index, float rgba[4]);
  101. void setNormal(unsigned int index, float i, float j, float k);
  102. void setVertex(unsigned int index, float x, float y, float z);
  103. #if 0
  104. void sortFacesByTexture();
  105. void addFace(int textureIndex, int textureIndexB, unsigned int flags,
  106. unsigned int vertexIndexCount, float* vertexIndices);
  107. void addTexTiledFace(int textureIndex, int textureIndexB,
  108. unsigned int flags, unsigned int indexCount,
  109. float* vertexIndices, float* texcoords);
  110. void bufferTexcoords(unsigned int texcoordCount, float* texcoords);
  111. void duplicateArraysForTexTiledTexcoords();
  112. #endif
  113. unsigned int mFlags;
  114. MeshMode mMode;
  115. unsigned int mNumVertices;
  116. float** mVertices; //!< XYZ
  117. unsigned int mNumNormals;
  118. float** mNormals; //!< IJK
  119. unsigned int mNumColors;
  120. float** mColors; //!< RGBA
  121. unsigned int mNumTris;
  122. tris_t* mTris;
  123. unsigned int mNumQuads;
  124. rect_t* mQuads;
  125. unsigned int mTriangleCount;
  126. int* mTriangleTextures;
  127. unsigned int* mTriangleIndices;
  128. unsigned int* mTriangleFlags;
  129. float* mTriangleTexCoordArray;
  130. float* mVertexArray;
  131. float* mNormalArray;
  132. float* mColorArray;
  133. };
  134. #endif