Skip to content

Commit

Permalink
libgui|GLUniform: 3-component vector array uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 12, 2014
1 parent 0f3f023 commit d182c48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doomsday/libgui/include/de/graphics/gluniform.h
Expand Up @@ -62,6 +62,7 @@ class LIBGUI_PUBLIC GLUniform
Mat3,
Mat4,
Sampler2D,
Vec3Array,
Vec4Array,
Mat4Array
};
Expand Down Expand Up @@ -103,6 +104,7 @@ class LIBGUI_PUBLIC GLUniform
GLUniform &operator = (GLTexture const &texture);
GLUniform &operator = (GLTexture const *texture);

GLUniform &set(duint elementIndex, Vector3f const &vec);
GLUniform &set(duint elementIndex, Vector4f const &vec);
GLUniform &set(duint elementIndex, Matrix4f const &mat);

Expand Down
31 changes: 30 additions & 1 deletion doomsday/libgui/src/graphics/gluniform.cpp
Expand Up @@ -35,6 +35,7 @@ DENG2_PIMPL(GLUniform)
dint int32;
duint uint32;
dfloat float32;
Vector3f *vec3array;
Vector4f *vector;
Matrix3f *mat3;
Matrix4f *mat4;
Expand All @@ -50,7 +51,9 @@ DENG2_PIMPL(GLUniform)
{
name.append('\0');

DENG2_ASSERT(elemCount == 1 || (elemCount > 1 && (type == Mat4Array || type == Vec4Array)));
DENG2_ASSERT(elemCount == 1 || (elemCount > 1 && (type == Mat4Array ||
type == Vec4Array ||
type == Vec3Array)));

// Allocate the value type.
zap(value);
Expand All @@ -62,6 +65,10 @@ DENG2_PIMPL(GLUniform)
value.vector = new Vector4f;
break;

case Vec3Array:
value.vec3array = new Vector3f[elemCount];
break;

case Vec4Array:
value.vector = new Vector4f[elemCount];
break;
Expand Down Expand Up @@ -95,6 +102,10 @@ DENG2_PIMPL(GLUniform)
delete value.vector;
break;

case Vec3Array:
delete [] value.vec3array;
break;

case Vec4Array:
delete [] value.vector;
break;
Expand Down Expand Up @@ -318,6 +329,19 @@ GLUniform &GLUniform::operator = (GLTexture const *texture)
return *this;
}

GLUniform &GLUniform::set(duint elementIndex, Vector3f const &vec)
{
DENG2_ASSERT(d->type == Vec3Array);
DENG2_ASSERT(elementIndex < d->elemCount);

if(d->value.vec3array[elementIndex] != vec)
{
d->value.vec3array[elementIndex] = vec;
d->markAsChanged();
}
return *this;
}

GLUniform &GLUniform::set(duint elementIndex, Vector4f const &vec)
{
DENG2_ASSERT(d->type == Vec4Array);
Expand Down Expand Up @@ -476,6 +500,11 @@ void GLUniform::applyInProgram(GLProgram &program) const
LIBGUI_ASSERT_GL_OK();
break;

case Vec3Array:
glUniform3fv(loc, d->elemCount, &d->value.vec3array->x); // sequentially laid out
LIBGUI_ASSERT_GL_OK();
break;

case Vec4:
case Vec4Array:
glUniform4fv(loc, d->elemCount, &d->value.vector->x); // sequentially laid out
Expand Down

0 comments on commit d182c48

Please sign in to comment.