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.

Mesh.h 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "BoundingSphere.h"
  11. #include "system/Shader.h"
  12. struct IndexedRectangle {
  13. unsigned int v1, v2, v3, v4; // Vertex list indices
  14. unsigned int texture; // Index into object-texture list
  15. IndexedRectangle(unsigned int t, unsigned int _v1,
  16. unsigned int _v2, unsigned int _v3, unsigned int _v4 = 0)
  17. : v1(_v1), v2(_v2), v3(_v3), v4(_v4), texture(t) { }
  18. };
  19. struct IndexedColoredRectangle {
  20. unsigned int v1, v2, v3, v4, index;
  21. IndexedColoredRectangle(unsigned int paletteIndex,
  22. unsigned int _v1, unsigned int _v2,
  23. unsigned int _v3, unsigned int _v4 = 0)
  24. : v1(_v1), v2(_v2), v3(_v3), v4(_v4), index(paletteIndex) { }
  25. };
  26. // --------------------------------------
  27. class Mesh {
  28. public:
  29. Mesh(const std::vector<glm::vec3>& vertices,
  30. const std::vector<IndexedRectangle>& rectangles,
  31. const std::vector<IndexedRectangle>& triangles,
  32. const std::vector<IndexedColoredRectangle>& coloredRectangles,
  33. const std::vector<IndexedColoredRectangle>& coloredTriangles);
  34. void prepare();
  35. void display(glm::mat4 MVP, ShaderTexture* shaderTexture = nullptr);
  36. BoundingSphere& getBoundingSphere() { return sphere; }
  37. private:
  38. std::vector<unsigned short> indicesBuff;
  39. std::vector<glm::vec3> verticesBuff;
  40. std::vector<glm::vec2> uvsBuff;
  41. std::vector<unsigned int> texturesBuff;
  42. std::vector<unsigned short> indicesColorBuff;
  43. std::vector<glm::vec3> verticesColorBuff;
  44. std::vector<glm::vec3> colorsBuff;
  45. std::vector<unsigned int> colorsIndexBuff;
  46. BoundingSphere sphere;
  47. };
  48. #endif