Open Source Tomb Raider Engine
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Mesh.h 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*!
  2. * \file include/Mesh.h
  3. * \brief Textured/Colored Mesh
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _MESH_H_
  8. #define _MESH_H_
  9. #include <vector>
  10. #include "system/Shader.h"
  11. struct IndexedRectangle {
  12. unsigned int v1, v2, v3, v4; // Vertex list indices
  13. unsigned int texture; // Index into object-texture list
  14. IndexedRectangle(unsigned int t, unsigned int _v1,
  15. unsigned int _v2, unsigned int _v3, unsigned int _v4 = 0)
  16. : v1(_v1), v2(_v2), v3(_v3), v4(_v4), texture(t) { }
  17. };
  18. struct IndexedColoredRectangle {
  19. unsigned int v1, v2, v3, v4, index;
  20. IndexedColoredRectangle(unsigned int paletteIndex,
  21. unsigned int _v1, unsigned int _v2,
  22. unsigned int _v3, unsigned int _v4 = 0)
  23. : v1(_v1), v2(_v2), v3(_v3), v4(_v4), index(paletteIndex) { }
  24. };
  25. // --------------------------------------
  26. class Mesh {
  27. public:
  28. Mesh(const std::vector<glm::vec3>& vertices,
  29. const std::vector<IndexedRectangle>& rectangles,
  30. const std::vector<IndexedRectangle>& triangles,
  31. const std::vector<IndexedColoredRectangle>& coloredRectangles,
  32. const std::vector<IndexedColoredRectangle>& coloredTriangles);
  33. void prepare();
  34. void display(glm::mat4 MVP, ShaderTexture* shaderTexture = nullptr);
  35. private:
  36. std::vector<unsigned short> indicesBuff;
  37. std::vector<glm::vec3> verticesBuff;
  38. std::vector<unsigned int> texturesBuff;
  39. std::vector<unsigned short> indicesColorBuff;
  40. std::vector<glm::vec3> verticesColorBuff;
  41. std::vector<unsigned int> colorsBuff;
  42. ShaderBuffer indices, vertices, uvs;
  43. ShaderBuffer indicesColor, verticesColor, colors;
  44. };
  45. #endif