Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 15, 2013
1 parent 9ee0af2 commit dba57b3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
32 changes: 26 additions & 6 deletions doomsday/libgui/include/de/gui/glbuffer.h
Expand Up @@ -60,11 +60,17 @@ namespace internal
typedef std::pair<AttribSpec const *, duint> AttribSpecs;
}

#define DENG2_DECLARE_VERTEX_FORMAT(NumElems) \
#define LIBGUI_DECLARE_VERTEX_FORMAT(NumElems) \
public: static internal::AttribSpecs formatSpec(); \
private: static internal::AttribSpec const _spec[NumElems]; \
public:

#define LIBGUI_VERTEX_FORMAT_SPEC(TypeName, ExpectedSize) \
internal::AttribSpecs TypeName::formatSpec() { \
DENG2_ASSERT(sizeof(TypeName) == ExpectedSize); /* sanity check */ \
return internal::AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0])); \
}

/**
* Vertex format with 2D coordinates and one set of texture coordinates.
*/
Expand All @@ -73,7 +79,7 @@ struct LIBGUI_PUBLIC Vertex2Tex
Vector2f pos;
Vector2f texCoord;

DENG2_DECLARE_VERTEX_FORMAT(2)
LIBGUI_DECLARE_VERTEX_FORMAT(2)
};

/**
Expand All @@ -84,7 +90,7 @@ struct LIBGUI_PUBLIC Vertex2Rgba
Vector2f pos;
Vector4f rgba;

DENG2_DECLARE_VERTEX_FORMAT(2)
LIBGUI_DECLARE_VERTEX_FORMAT(2)
};

/**
Expand All @@ -97,7 +103,7 @@ struct LIBGUI_PUBLIC Vertex2TexRgba
Vector2f texCoord;
Vector4f rgba;

DENG2_DECLARE_VERTEX_FORMAT(3)
LIBGUI_DECLARE_VERTEX_FORMAT(3)
};

/**
Expand All @@ -108,7 +114,7 @@ struct LIBGUI_PUBLIC Vertex3Tex
Vector3f pos;
Vector2f texCoord;

DENG2_DECLARE_VERTEX_FORMAT(2)
LIBGUI_DECLARE_VERTEX_FORMAT(2)
};

/**
Expand All @@ -121,7 +127,21 @@ struct LIBGUI_PUBLIC Vertex3TexRgba
Vector2f texCoord;
Vector4f rgba;

DENG2_DECLARE_VERTEX_FORMAT(3)
LIBGUI_DECLARE_VERTEX_FORMAT(3)
};

/**
* Vertex format with 3D coordinates, normal vector, one set of texture
* coordinates, and an RGBA color.
*/
struct LIBGUI_PUBLIC Vertex3NormalTexRgba
{
Vector3f pos;
Vector3f normal;
Vector2f texCoord;
Vector4f rgba;

LIBGUI_DECLARE_VERTEX_FORMAT(4)
};

namespace gl
Expand Down
37 changes: 15 additions & 22 deletions doomsday/libgui/src/glbuffer.cpp
Expand Up @@ -23,56 +23,49 @@ namespace de {
using namespace internal;
using namespace gl;

// Vertex Formats ------------------------------------------------------------
// Vertex Format Layout ------------------------------------------------------

AttribSpec const Vertex2Tex::_spec[2] = {
{ AttribSpec::Position, 2, GL_FLOAT, false, sizeof(Vertex2Tex), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex2Tex), 2 * sizeof(float) }
};
AttribSpecs Vertex2Tex::formatSpec() {
DENG2_ASSERT(sizeof(Vertex2Tex) == 4 * sizeof(float)); // sanity check
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}
LIBGUI_VERTEX_FORMAT_SPEC(Vertex2Tex, 4 * sizeof(float))

AttribSpec const Vertex2Rgba::_spec[2] = {
{ AttribSpec::Position, 2, GL_FLOAT, false, sizeof(Vertex2Rgba), 0 },
{ AttribSpec::Color, 4, GL_FLOAT, false, sizeof(Vertex2Rgba), 2 * sizeof(float) }
};
AttribSpecs Vertex2Rgba::formatSpec() {
DENG2_ASSERT(sizeof(Vertex2Rgba) == 6 * sizeof(float)); // sanity check
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}
LIBGUI_VERTEX_FORMAT_SPEC(Vertex2Rgba, 6 * sizeof(float))

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) }
};
AttribSpecs Vertex2TexRgba::formatSpec() {
DENG2_ASSERT(sizeof(Vertex2TexRgba) == 8 * sizeof(float)); // sanity check
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}
LIBGUI_VERTEX_FORMAT_SPEC(Vertex2TexRgba, 8 * sizeof(float))

AttribSpec const Vertex3Tex::_spec[2] = {
{ AttribSpec::Position, 3, GL_FLOAT, false, sizeof(Vertex3Tex), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex3Tex), 3 * sizeof(float) }
};
AttribSpecs Vertex3Tex::formatSpec() {
DENG2_ASSERT(sizeof(Vertex3Tex) == 5 * sizeof(float)); // sanity check
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}
LIBGUI_VERTEX_FORMAT_SPEC(Vertex3Tex, 5 * sizeof(float))

AttribSpec const Vertex3TexRgba::_spec[3] = {
{ AttribSpec::Position, 3, GL_FLOAT, false, sizeof(Vertex3TexRgba), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex3TexRgba), 3 * sizeof(float) },
{ AttribSpec::Color, 4, GL_FLOAT, false, sizeof(Vertex3TexRgba), 5 * sizeof(float) }
};
AttribSpecs Vertex3TexRgba::formatSpec() {
DENG2_ASSERT(sizeof(Vertex3TexRgba) == 9 * sizeof(float)); // sanity check
return AttribSpecs(_spec, sizeof(_spec)/sizeof(_spec[0]));
}
LIBGUI_VERTEX_FORMAT_SPEC(Vertex3TexRgba, 9 * sizeof(float))

AttribSpec const Vertex3NormalTexRgba::_spec[4] = {
{ AttribSpec::Position, 3, GL_FLOAT, false, sizeof(Vertex3NormalTexRgba), 0 },
{ AttribSpec::Normal, 3, GL_FLOAT, false, sizeof(Vertex3NormalTexRgba), 3 * sizeof(float) },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex3NormalTexRgba), 6 * sizeof(float) },
{ AttribSpec::Color, 4, GL_FLOAT, false, sizeof(Vertex3NormalTexRgba), 8 * sizeof(float) }
};
LIBGUI_VERTEX_FORMAT_SPEC(Vertex3NormalTexRgba, 12 * sizeof(float))

// ---------------------------------------------------------------------------
//----------------------------------------------------------------------------

DENG2_PIMPL(GLBuffer)
{
Expand Down

0 comments on commit dba57b3

Please sign in to comment.