123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "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(int index, int length, int offset, int step) {
- glVertexAttribPointer(index, length, GL_FLOAT, false, step, static_cast<char*> (0) + offset);
- glEnableVertexAttribArray(index);
- }
- void VertexBuffer::setColorAttribute(int index, int offset, int step) {
- glVertexAttribPointer(index, GL_BGRA, GL_UNSIGNED_BYTE, true, step, static_cast<char*> (0) + offset);
- glEnableVertexAttribArray(index);
- }
- void VertexBuffer::setData(int 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(int vertices) const {
- glDrawArrays(GL_TRIANGLES, 0, vertices);
- }
|