2016-04-07 01:13:46 +01:00
|
|
|
#include <gl/DrawBuffer.hpp>
|
|
|
|
#include <gl/GeometryBuffer.hpp>
|
2014-02-10 05:43:20 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
|
|
|
|
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
|
2016-09-09 21:13:21 +01:00
|
|
|
{ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}};
|
2014-02-10 05:43:20 +00:00
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
DrawBuffer::DrawBuffer() : vao(0) {
|
2014-02-10 05:43:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
DrawBuffer::~DrawBuffer() {
|
|
|
|
if (vao) {
|
|
|
|
glDeleteVertexArrays(1, &vao);
|
|
|
|
}
|
2014-02-10 05:43:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 21:13:21 +01: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()) {
|
|
|
|
GLuint vaoindex = semantic_to_attrib_array[at.sem];
|
|
|
|
glEnableVertexAttribArray(vaoindex);
|
|
|
|
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
|
|
|
|
reinterpret_cast<GLvoid*>(at.offset));
|
|
|
|
}
|
2014-02-10 05:43:20 +00:00
|
|
|
}
|