Skip to content

Commit

Permalink
libgui|GLBuffer: Vertex attribute indices
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 21, 2013
1 parent 3342ab1 commit 25fc2ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
13 changes: 13 additions & 0 deletions doomsday/libgui/include/de/gui/glbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ namespace internal
/// Describes an attribute array inside a GL buffer.
struct AttribSpec
{
enum Semantic {
Position,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
Color,
Normal,
Tangent,
Bitangent
};

Semantic semantic;
dint size; ///< Number of components in an element.
GLenum type; ///< Data type.
bool normalized; ///< Whether to normalize non-floats to [0.f, 1.f].
Expand Down
21 changes: 11 additions & 10 deletions doomsday/libgui/src/glbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

namespace de {

internal::AttribSpec const Vertex2TexRgba::_spec[3] =
{
{ 2, GL_FLOAT, false, sizeof(Vertex2TexRgba), 0 }, // pos
{ 2, GL_FLOAT, false, sizeof(Vertex2TexRgba), 2 * sizeof(float) }, // texCoord
{ 4, GL_FLOAT, false, sizeof(Vertex2TexRgba), 4 * sizeof(float) } // rgba
using namespace internal;

AttribSpec const Vertex2TexRgba::_spec[3] = {
{ AttribSpec::Position, 2, GL_FLOAT, false, sizeof(Vertex2TexRgba), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex2TexRgba), 2 * sizeof(float) },
{ AttribSpec::Color, 4, GL_FLOAT, false, sizeof(Vertex2TexRgba), 4 * sizeof(float) }
};

internal::AttribSpecs Vertex2TexRgba::formatSpec()
AttribSpecs Vertex2TexRgba::formatSpec()
{
DENG2_ASSERT(sizeof(Vertex2TexRgba) == 8 * sizeof(float)); // sanity check
return internal::AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}

DENG2_PIMPL(GLBuffer)
Expand All @@ -40,7 +41,7 @@ DENG2_PIMPL(GLBuffer)
dsize count;
dsize idxCount;
Primitive prim;
internal::AttribSpecs specs;
AttribSpecs specs;

Instance(Public *i) : Base(i), name(0), idxName(0), count(0), idxCount(0), prim(Points)
{
Expand Down Expand Up @@ -124,7 +125,7 @@ DENG2_PIMPL(GLBuffer)

for(duint i = 0; i < specs.second; ++i)
{
internal::AttribSpec const &spec = specs.first[i];
AttribSpec const &spec = specs.first[i];
if(enable)
{
glEnableVertexAttribArray(i);
Expand Down Expand Up @@ -229,7 +230,7 @@ void GLBuffer::draw(duint first, dint count)
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

void GLBuffer::setFormat(internal::AttribSpecs const &format)
void GLBuffer::setFormat(AttribSpecs const &format)
{
d->specs = format;
}
Expand Down

0 comments on commit 25fc2ba

Please sign in to comment.