Mesh.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef MESH_H
  2. #define MESH_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. class Mesh
  6. {
  7. public:
  8. Mesh(int mode);
  9. virtual ~Mesh();
  10. void addPosition(float x, float y, float z);
  11. void addColor(float r, float g, float b, float a);
  12. void addTexture(float tx, float ty);
  13. void addNormal(float nx, float ny, float nz);
  14. void build(bool print = false);
  15. void draw();
  16. void draw(int start, int count);
  17. static const int COLOR = 1;
  18. static const int TEXTURE = 2;
  19. static const int NORMAL = 4;
  20. private:
  21. void ensureCapacity(unsigned int index);
  22. GLuint vba = 0;
  23. GLuint vbo = 0;
  24. unsigned int positionStartIndex = 0;
  25. unsigned int colorStartIndex = 0;
  26. unsigned int textureStartIndex = 0;
  27. unsigned int normalStartIndex = 0;
  28. unsigned int positionIndex = 0;
  29. unsigned int colorIndex = 0;
  30. unsigned int textureIndex = 0;
  31. unsigned int normalIndex = 0;
  32. unsigned int vertexSize = 0;
  33. unsigned int vertices = 0;
  34. unsigned int dataSize = 3;
  35. float* data = nullptr;
  36. };
  37. class NormalTextureMesh : public Mesh
  38. {
  39. public:
  40. NormalTextureMesh() : Mesh(Mesh::TEXTURE | Mesh::NORMAL) {};
  41. };
  42. #endif