1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "client/rendering/wrapper/VertexBuffer.h"
- VertexBuffer::VertexBuffer() : vertexArray(0), vertexBuffer(0) {
- glGenVertexArrays(1, &vertexArray);
- glGenBuffers(1, &vertexBuffer);
- }
- VertexBuffer::~VertexBuffer() {
- glDeleteBuffers(1, &vertexBuffer);
- glDeleteVertexArrays(1, &vertexArray);
- }
- void VertexBuffer::setFloatAttribute(uint index, uint length, uint offset, uint step) {
- glVertexAttribPointer(index, length, GL_FLOAT, false, sizeof (float) * step, static_cast<float*> (0) + offset);
- glEnableVertexAttribArray(index);
- }
- void VertexBuffer::setData(u64 size, const void* data) {
- glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
- }
- void VertexBuffer::bindArray() const {
- glBindVertexArray(vertexArray);
- }
- void VertexBuffer::bindBuffer() const {
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- }
- void VertexBuffer::bind() const {
- bindArray();
- bindBuffer();
- }
- void VertexBuffer::draw(uint vertices) const {
- glDrawArrays(GL_TRIANGLES, 0, vertices);
- }
- void VertexBuffer::drawLines(uint vertices) const {
- glDrawArrays(GL_LINES, 0, vertices);
- }
|