VertexBuffer.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "rendering/VertexBuffer.h"
  2. VertexBuffer::VertexBuffer()
  3. : vertexArray(GL::genVertexArray()), vertexBuffer(GL::genBuffer()),
  4. size(0) {
  5. }
  6. VertexBuffer::~VertexBuffer() {
  7. GL::deleteBuffer(vertexBuffer);
  8. GL::deleteVertexArray(vertexArray);
  9. }
  10. void VertexBuffer::bindArray() const {
  11. GL::bindVertexArray(vertexArray);
  12. }
  13. void VertexBuffer::bindBuffer() const {
  14. GL::bindBuffer(vertexBuffer);
  15. }
  16. void VertexBuffer::setAttributes(const Attributes& attributes) {
  17. bindArray();
  18. bindBuffer();
  19. attributes.set();
  20. }
  21. void VertexBuffer::setStaticData(int size, const void* data) {
  22. VertexBuffer::size = size;
  23. bindBuffer();
  24. GL::bufferDataStatic(size, data);
  25. }
  26. void VertexBuffer::setStreamData(int size, const void* data) {
  27. VertexBuffer::size = size;
  28. bindBuffer();
  29. GL::bufferDataStream(size, data);
  30. }
  31. void VertexBuffer::setDynamicData(int size, const void* data) {
  32. VertexBuffer::size = size;
  33. bindBuffer();
  34. GL::bufferDataDynamic(size, data);
  35. }
  36. void VertexBuffer::updateData(int offset, int size, const void* data) {
  37. bindBuffer();
  38. GL::bufferSubData(offset, size, data);
  39. }
  40. void VertexBuffer::draw(int vertices, int offset) {
  41. bindArray();
  42. GL::drawTriangles(offset, vertices);
  43. }
  44. void VertexBuffer::drawStrip(int vertices, int offset) {
  45. bindArray();
  46. GL::drawTriangleStrip(offset, vertices);
  47. }
  48. void VertexBuffer::drawPoints(int vertices, int offset) {
  49. bindArray();
  50. GL::drawPoints(offset, vertices);
  51. }
  52. int VertexBuffer::getSize() const {
  53. return size;
  54. }