VertexBuffer.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "client/rendering/wrapper/VertexBuffer.h"
  2. VertexBuffer::VertexBuffer() : vertexArray(0), vertexBuffer(0) {
  3. glGenVertexArrays(1, &vertexArray);
  4. glGenBuffers(1, &vertexBuffer);
  5. }
  6. VertexBuffer::~VertexBuffer() {
  7. glDeleteBuffers(1, &vertexBuffer);
  8. glDeleteVertexArrays(1, &vertexArray);
  9. }
  10. void VertexBuffer::setFloatAttribute(uint index, uint length, uint offset, uint step) {
  11. glVertexAttribPointer(index, length, GL_FLOAT, false, sizeof (float) * step, static_cast<float*> (0) + offset);
  12. glEnableVertexAttribArray(index);
  13. }
  14. void VertexBuffer::setData(u64 size, const void* data) {
  15. glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
  16. }
  17. void VertexBuffer::bindArray() const {
  18. glBindVertexArray(vertexArray);
  19. }
  20. void VertexBuffer::bindBuffer() const {
  21. glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  22. }
  23. void VertexBuffer::bind() const {
  24. bindArray();
  25. bindBuffer();
  26. }
  27. void VertexBuffer::draw(uint vertices) const {
  28. glDrawArrays(GL_TRIANGLES, 0, vertices);
  29. }
  30. void VertexBuffer::drawLines(uint vertices) const {
  31. glDrawArrays(GL_LINES, 0, vertices);
  32. }