48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include <vector>
|
|
#include <glbinding/gl/gl.h>
|
|
|
|
#include "shaders.hh"
|
|
#include "Overlay.hh"
|
|
|
|
using namespace gl;
|
|
|
|
Overlay::Overlay(std::vector<ovlVertexAttribs> const& vas)
|
|
: vbo_(VBOManager::getInstance().alloc(sizeof(ovlVertexAttribs)*vas.size())),
|
|
vaID_(0), vertices_(vas.size())
|
|
{
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_.getVBOId());
|
|
glBufferSubData(GL_ARRAY_BUFFER, vbo_.getOfs(),
|
|
sizeof(ovlVertexAttribs)*vas.size(),
|
|
static_cast<void const*>(vas.data()));
|
|
|
|
glGenVertexArrays(1, &vaID_);
|
|
try {
|
|
glBindVertexArray(vaID_);
|
|
|
|
glEnableVertexAttribArray(ATTRIB_VERTEX_POS);
|
|
glVertexAttribPointer(ATTRIB_VERTEX_POS, 2, GL_SHORT, GL_FALSE,
|
|
sizeof(ovlVertexAttribs),
|
|
(void*)(vbo_.getOfs()+offsetof(ovlVertexAttribs, vertex)));
|
|
|
|
glEnableVertexAttribArray(ATTRIB_VERTEX_TC);
|
|
glVertexAttribPointer(ATTRIB_VERTEX_TC, 2, GL_UNSIGNED_SHORT, GL_TRUE,
|
|
sizeof(ovlVertexAttribs),
|
|
(void*)(vbo_.getOfs()+offsetof(ovlVertexAttribs, texCoords)));
|
|
} catch(...) {
|
|
glDeleteVertexArrays(1, &vaID_);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
Overlay::~Overlay()
|
|
{
|
|
glDeleteVertexArrays(1, &vaID_);
|
|
}
|
|
|
|
void Overlay::draw() const
|
|
{
|
|
glBindVertexArray(vaID_);
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, vertices_);
|
|
}
|