2017-10-30 23:44:40 +01:00
|
|
|
#include "gl/DrawBuffer.hpp"
|
|
|
|
|
2014-02-10 06:43:20 +01:00
|
|
|
#include <map>
|
|
|
|
|
2017-10-30 23:44:40 +01:00
|
|
|
#include <gl/gl_core_3_3.h>
|
|
|
|
#include <gl/GeometryBuffer.hpp>
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
DrawBuffer::DrawBuffer() : vao(0) {
|
2014-02-10 06:43:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
DrawBuffer::~DrawBuffer() {
|
|
|
|
if (vao) {
|
|
|
|
glDeleteVertexArrays(1, &vao);
|
|
|
|
}
|
2014-02-10 06:43:20 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void DrawBuffer::addGeometry(GeometryBuffer* gbuff) {
|
|
|
|
if (vao == 0) {
|
|
|
|
glGenVertexArrays(1, &vao);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindVertexArray(vao);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName());
|
|
|
|
// Iterate the attributes present in the gbuff
|
|
|
|
for (const AttributeIndex& at : gbuff->getDataAttributes()) {
|
2018-09-20 22:42:47 +02:00
|
|
|
auto vaoindex = static_cast<GLuint>(at.sem);
|
2016-09-09 22:13:21 +02:00
|
|
|
glEnableVertexAttribArray(vaoindex);
|
2018-08-29 22:46:00 +02:00
|
|
|
glVertexAttribPointer(vaoindex, static_cast<GLint>(at.size), at.type, GL_TRUE, at.stride,
|
|
|
|
reinterpret_cast<void*>(at.offset));
|
2016-09-09 22:13:21 +02:00
|
|
|
}
|
2014-02-10 06:43:20 +01:00
|
|
|
}
|