VertexBuffer.cpp 1.4 KB

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