Skip to content

Commit

Permalink
libgui|GLBuffer: Added "TexBounds0" vertex attribute
Browse files Browse the repository at this point in the history
The texture bounds attribute is useful for example when rendering
geometry that uses a shared texture atlas; one can store the individual
texture bounds in the vertex data and use normalized (0,1) UV
coordinates, which a shader will then convert to coordinates on the
atlas. This also allows repeating UV patterns by applying wrapping in
the shader.
  • Loading branch information
skyjake committed Mar 5, 2014
1 parent 0cbf724 commit 7084b82
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
15 changes: 15 additions & 0 deletions doomsday/libgui/include/de/gui/glbuffer.h
Expand Up @@ -43,6 +43,7 @@ namespace internal
TexCoord1,
TexCoord2,
TexCoord3,
TexBounds0,
Color,
Normal,
Tangent,
Expand Down Expand Up @@ -130,6 +131,20 @@ struct LIBGUI_PUBLIC Vertex3TexRgba
LIBGUI_DECLARE_VERTEX_FORMAT(3)
};

/**
* Vertex format with 3D coordinates, one set of texture coordinates with indirect
* bounds, and an RGBA color.
*/
struct LIBGUI_PUBLIC Vertex3TexBoundsRgba
{
Vector3f pos;
Vector2f texCoord; ///< mapped using texBounds
Vector4f texBounds; ///< UV space: x, y, width, height
Vector4f rgba;

LIBGUI_DECLARE_VERTEX_FORMAT(4)
};

/**
* Vertex format with 3D coordinates, two sets of texture coordinates, and an
* RGBA color.
Expand Down
8 changes: 8 additions & 0 deletions doomsday/libgui/src/glbuffer.cpp
Expand Up @@ -59,6 +59,14 @@ AttribSpec const Vertex3TexRgba::_spec[3] = {
};
LIBGUI_VERTEX_FORMAT_SPEC(Vertex3TexRgba, 9 * sizeof(float))

AttribSpec const Vertex3TexBoundsRgba::_spec[4] = {
{ AttribSpec::Position, 3, GL_FLOAT, false, sizeof(Vertex3TexBoundsRgba), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex3TexBoundsRgba), 3 * sizeof(float) },
{ AttribSpec::TexBounds0, 4, GL_FLOAT, false, sizeof(Vertex3TexBoundsRgba), 5 * sizeof(float) },
{ AttribSpec::Color, 4, GL_FLOAT, false, sizeof(Vertex3TexBoundsRgba), 9 * sizeof(float) }
};
LIBGUI_VERTEX_FORMAT_SPEC(Vertex3TexBoundsRgba, 13 * sizeof(float))

AttribSpec const Vertex3Tex2Rgba::_spec[4] = {
{ AttribSpec::Position, 3, GL_FLOAT, false, sizeof(Vertex3Tex2Rgba), 0 },
{ AttribSpec::TexCoord0, 2, GL_FLOAT, false, sizeof(Vertex3Tex2Rgba), 3 * sizeof(float) },
Expand Down
19 changes: 10 additions & 9 deletions doomsday/libgui/src/glprogram.cpp
Expand Up @@ -164,15 +164,16 @@ DENG2_PIMPL(GLProgram)
char const *varName;
}
const names[] = {
{ AttribSpec::Position, "aVertex" },
{ AttribSpec::TexCoord0, "aUV" },
{ AttribSpec::TexCoord1, "aUV2" },
{ AttribSpec::TexCoord2, "aUV3" },
{ AttribSpec::TexCoord3, "aUV4" },
{ AttribSpec::Color, "aColor" },
{ AttribSpec::Normal, "aNormal" },
{ AttribSpec::Tangent, "aTangent" },
{ AttribSpec::Bitangent, "aBitangent" }
{ AttribSpec::Position, "aVertex" },
{ AttribSpec::TexCoord0, "aUV" },
{ AttribSpec::TexCoord1, "aUV2" },
{ AttribSpec::TexCoord2, "aUV3" },
{ AttribSpec::TexCoord3, "aUV4" },
{ AttribSpec::TexBounds0, "aBounds" },
{ AttribSpec::Color, "aColor" },
{ AttribSpec::Normal, "aNormal" },
{ AttribSpec::Tangent, "aTangent" },
{ AttribSpec::Bitangent, "aBitangent" }
};

for(uint i = 0; i < sizeof(names)/sizeof(names[0]); ++i)
Expand Down

0 comments on commit 7084b82

Please sign in to comment.