VertexBuffer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef VERTEXBUFFER_H
  2. #define VERTEXBUFFER_H
  3. #include "data/ArrayList.h"
  4. #include "rendering/GL.h"
  5. #include "utils/Buffer.h"
  6. #include "utils/TypedBuffer.h"
  7. class VertexBuffer final {
  8. GL::VertexArray vertexArray;
  9. GL::Buffer vertexBuffer;
  10. int size;
  11. public:
  12. class Attributes final {
  13. ArrayList<GL::Attribute, 10> attributes;
  14. friend class VertexBuffer;
  15. public:
  16. Attributes& addFloat(int count);
  17. Attributes& addColor4();
  18. Attributes& addSpacer();
  19. private:
  20. void set() const;
  21. };
  22. VertexBuffer();
  23. ~VertexBuffer();
  24. VertexBuffer(const VertexBuffer& other) = delete;
  25. VertexBuffer(VertexBuffer&& other) = delete;
  26. VertexBuffer& operator=(const VertexBuffer& other) = delete;
  27. VertexBuffer& operator=(VertexBuffer&& other) = delete;
  28. void init(const Attributes& attributes);
  29. void setData(int size, const void* data, GL::BufferUsage usage);
  30. void setData(const Buffer& buffer, GL::BufferUsage usage);
  31. template<typename T>
  32. void setData(GL::BufferUsage usage, const TypedBuffer<T>& buffer) {
  33. setData(buffer.getByteLength(), buffer, usage);
  34. }
  35. void updateData(int offset, int size, const void* data);
  36. void draw(int vertices, int offset = 0);
  37. void drawStrip(int vertices, int offset = 0);
  38. void drawPoints(int vertices, int offset = 0);
  39. int getSize() const;
  40. private:
  41. void bindArray() const;
  42. void bindBuffer() const;
  43. };
  44. #endif