More seperate cc files, font & overlay rendering
This commit is contained in:
53
Overlay.cc
Normal file
53
Overlay.cc
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <vector>
|
||||
#include <glbinding/gl/gl.h>
|
||||
|
||||
#include "shaders.hh"
|
||||
#include "Overlay.hh"
|
||||
|
||||
using namespace gl;
|
||||
|
||||
Overlay::Overlay(VBOManager& vboManager, std::vector<ovlVertexAttribs> const& vas,
|
||||
Program& prog)
|
||||
: vboManager_(vboManager), vbo_(vboManager_.alloc(sizeof(ovlVertexAttribs)*vas.size())),
|
||||
prog_(prog), 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_);
|
||||
GLint al;
|
||||
if((al = prog_.getAttribLocation("vertex")) != -1) {
|
||||
glEnableVertexAttribArray(al);
|
||||
glVertexAttribPointer(al, 2, GL_SHORT, GL_TRUE, sizeof(ovlVertexAttribs),
|
||||
(void*)(vbo_.getOfs()+offsetof(ovlVertexAttribs, vertex)));
|
||||
}
|
||||
if((al = prog_.getAttribLocation("vertexTC")) != -1) {
|
||||
glEnableVertexAttribArray(al);
|
||||
glVertexAttribPointer(al, 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(Program *override) const
|
||||
{
|
||||
glBindVertexArray(vaID_);
|
||||
if (override)
|
||||
override->use();
|
||||
else
|
||||
prog_.use();
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices_);
|
||||
}
|
||||
Reference in New Issue
Block a user