WIP: GUI Toolkit

This commit is contained in:
2015-03-09 01:11:13 +01:00
parent ffbc59140a
commit 9d7dd452c7
24 changed files with 1003 additions and 134 deletions

View File

@@ -12,16 +12,15 @@
using namespace gl;
Object::Object(VBOManager& vboManager, std::vector<objVertexAttribs> const& vas,
std::vector<uint16_t> indices, Program& prog)
: _vboManager(vboManager), _prog(prog), _indices(std::move(indices)), _vaID(0)
Object::Object(std::vector<objVertexAttribs> const& vas,
std::vector<uint16_t> indices)
: _indices(std::move(indices)), _vaID(0)
{
construct(vas);
}
Object::Object(VBOManager& vboManager, std::string const& filename,
Program& prog)
: _vboManager(vboManager), _prog(prog), _vaID(0)
Object::Object(std::string const& filename)
: _vaID(0)
{
auto tmp = readObject(filename);
_indices = std::get<1>(tmp);
@@ -33,22 +32,17 @@ Object::~Object()
glDeleteVertexArrays(1, &_vaID);
}
void Object::draw(glm::mat4 const& modelview, Program *override) const
void Object::draw() const
{
glBindVertexArray(_vaID);
if (override)
override->use();
else
_prog.use();
glUniformMatrix4fv(_prog.getUniformLocation("model_matrix"), 1, GL_FALSE,
glm::value_ptr(modelview));
glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT,
_indices.data());
}
void Object::construct(std::vector<objVertexAttribs> const& vas)
{
_vbo = _vboManager.alloc(sizeof(objVertexAttribs)*vas.size());
_vbo = VBOManager::getInstance().alloc(sizeof(objVertexAttribs)*vas.size());
glBindBuffer(GL_ARRAY_BUFFER, _vbo.getVBOId());
glBufferSubData(GL_ARRAY_BUFFER, _vbo.getOfs(),
sizeof(objVertexAttribs)*vas.size(), (void*)vas.data());
@@ -56,22 +50,17 @@ void Object::construct(std::vector<objVertexAttribs> const& vas)
glGenVertexArrays(1, &_vaID);
glBindVertexArray(_vaID);
GLint al;
if((al = _prog.getAttribLocation("vertex")) != -1) {
glEnableVertexAttribArray(al);
glVertexAttribPointer(al, 3, GL_FLOAT, GL_FALSE, sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, vertex)));
}
if((al = _prog.getAttribLocation("vertexTC")) != -1) {
glEnableVertexAttribArray(al);
glVertexAttribPointer(al, 2, GL_UNSIGNED_SHORT, GL_TRUE,
sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, texCoords)));
}
if((al = _prog.getAttribLocation("vertexNorm")) != -1) {
glEnableVertexAttribArray(al);
glVertexAttribPointer(al, 4, GL_INT_2_10_10_10_REV, GL_TRUE,
sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, normal)));
}
glEnableVertexAttribArray(ATTRIB_VERTEX_POS);
glVertexAttribPointer(ATTRIB_VERTEX_POS, 3, GL_FLOAT, GL_FALSE, sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, vertex)));
glEnableVertexAttribArray(ATTRIB_VERTEX_TC);
glVertexAttribPointer(ATTRIB_VERTEX_TC, 2, GL_UNSIGNED_SHORT, GL_TRUE,
sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, texCoords)));
glEnableVertexAttribArray(ATTRIB_VERTEX_NORM);
glVertexAttribPointer(ATTRIB_VERTEX_NORM, 4, GL_INT_2_10_10_10_REV, GL_TRUE,
sizeof(objVertexAttribs),
(void*)(_vbo.getOfs()+offsetof(objVertexAttribs, normal)));
}