1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/rwcore/gl/DrawBuffer.cpp
Daniel Evans 4fd92a1549 Rename rwlib library to "core" to fit its new role
Also move up source files into the root directory, as there's nothing else in this directory
2018-08-09 20:28:24 +01:00

36 lines
1.0 KiB
C++

#include "gl/DrawBuffer.hpp"
#include <map>
#include <gl/gl_core_3_3.h>
#include <gl/GeometryBuffer.hpp>
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
{ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}};
DrawBuffer::DrawBuffer() : vao(0) {
}
DrawBuffer::~DrawBuffer() {
if (vao) {
glDeleteVertexArrays(1, &vao);
}
}
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));
}
}