Skip to content

Commit

Permalink
libgui: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 16, 2013
1 parent acc3e98 commit 152422c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
30 changes: 18 additions & 12 deletions doomsday/libgui/include/de/gui/glbuffer.h
Expand Up @@ -59,6 +59,11 @@ namespace internal
typedef std::pair<AttribSpec const *, duint> AttribSpecs;
}

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

/**
* Vertex format with 2D coordinates and one set of texture coordinates.
*/
Expand All @@ -67,12 +72,19 @@ struct LIBGUI_PUBLIC Vertex2Tex
Vector2f pos;
Vector2f texCoord;

static internal::AttribSpecs formatSpec();

private:
static internal::AttribSpec const _spec[2];
DENG2_DECLARE_VERTEX_FORMAT(2)
};

/**
* Vertex format with 2D coordinates and a color.
*/
struct LIBGUI_PUBLIC Vertex2Rgba
{
Vector2f pos;
Vector4f rgba;

DENG2_DECLARE_VERTEX_FORMAT(2)
};
/**
* Vertex format with 2D coordinates, one set of texture coordinates, and an
* RGBA color.
Expand All @@ -83,10 +95,7 @@ struct LIBGUI_PUBLIC Vertex2TexRgba
Vector2f texCoord;
Vector4f rgba;

static internal::AttribSpecs formatSpec();

private:
static internal::AttribSpec const _spec[3];
DENG2_DECLARE_VERTEX_FORMAT(3)
};

/**
Expand All @@ -99,10 +108,7 @@ struct LIBGUI_PUBLIC Vertex3TexRgba
Vector2f texCoord;
Vector4f rgba;

static internal::AttribSpecs formatSpec();

private:
static internal::AttribSpec const _spec[3];
DENG2_DECLARE_VERTEX_FORMAT(3)
};

namespace gl
Expand Down
3 changes: 0 additions & 3 deletions doomsday/libgui/include/de/gui/glprogram.h
Expand Up @@ -65,9 +65,6 @@ class LIBGUI_PUBLIC GLProgram : public Asset
*/
void clear();

/*GLProgram &build(IByteArray const &vertexShaderSource,
IByteArray const &fragmentShaderSource);*/

/**
* Builds a program out of two shaders. GLProgram retains a reference to
* both shaders.
Expand Down
6 changes: 1 addition & 5 deletions doomsday/libgui/include/de/gui/glshader.h
Expand Up @@ -41,11 +41,7 @@ namespace de {
class LIBGUI_PUBLIC GLShader : public Counted, public Asset
{
public:
enum Type
{
Vertex,
Fragment
};
enum Type { Vertex, Fragment };

/// There was a failure related to OpenGL resource allocation. @ingroup errors
DENG2_ERROR(AllocError);
Expand Down
12 changes: 9 additions & 3 deletions doomsday/libgui/src/glbuffer.cpp
Expand Up @@ -29,18 +29,25 @@ 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]));
}

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]));
}

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]));
Expand All @@ -51,7 +58,6 @@ AttribSpec const Vertex3TexRgba::_spec[3] = {
{ 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]));
Expand Down
1 change: 1 addition & 0 deletions doomsday/libgui/src/glshader.cpp
Expand Up @@ -41,6 +41,7 @@ DENG2_PIMPL(GLShader)
if(!name)
{
name = glCreateShader(type == Vertex? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
LIBGUI_ASSERT_GL_OK();
if(!name)
{
throw AllocError("GLShader::alloc", "Failed to create shader");
Expand Down
6 changes: 2 additions & 4 deletions doomsday/libgui/src/gltexture.cpp
Expand Up @@ -141,8 +141,7 @@ DENG2_PIMPL(GLTexture)
{
DENG2_ASSERT(name != 0);

glBindTexture(texTarget, name);
LIBGUI_ASSERT_GL_OK();
glBindTexture(texTarget, name); LIBGUI_ASSERT_GL_OK();
}

void glUnbind() const
Expand Down Expand Up @@ -368,8 +367,7 @@ void GLTexture::generateMipmap()
if(d->name)
{
d->glBind();
glGenerateMipmap(d->texTarget);
LIBGUI_ASSERT_GL_OK();
glGenerateMipmap(d->texTarget); LIBGUI_ASSERT_GL_OK();
d->glUnbind();

d->flags |= MipmapAvailable;
Expand Down

0 comments on commit 152422c

Please sign in to comment.