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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "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;
  20. unsigned char r, g, b;
  21. IndexedColoredRectangle(unsigned char _r, unsigned char _g, unsigned char _b,
  22. unsigned int _v1, unsigned int _v2,
  23. unsigned int _v3, unsigned int _v4 = 0)
  24. : v1(_v1), v2(_v2), v3(_v3), v4(_v4), r(_r), g(_g), b(_b) { }
  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);
  36. private:
  37. std::vector<unsigned short> indicesBuff;
  38. std::vector<glm::vec3> verticesBuff;
  39. std::vector<unsigned int> texturesBuff;
  40. std::vector<unsigned short> indicesColorBuff;
  41. std::vector<glm::vec3> verticesColorBuff;
  42. std::vector<glm::vec3> colorsBuff;
  43. ShaderBuffer indices, vertices, uvs;
  44. ShaderBuffer indicesColor, verticesColor, colors;
  45. };
  46. #endif