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.

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