1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-02 00:42:33 +01:00
openrw/rwcore/gl/DrawBuffer.cpp

32 lines
827 B
C++
Raw Normal View History

#include "gl/DrawBuffer.hpp"
2014-02-10 06:43:20 +01:00
#include <map>
#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()) {
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
}