VertexBuffer.cpp 1.6 KB

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