Skip to content

Commit

Permalink
libdeng2: Implemented logical state of GLUniform
Browse files Browse the repository at this point in the history
Tracking the current value, notifying audiences of changes.
  • Loading branch information
skyjake committed Apr 19, 2013
1 parent 3f60879 commit f36a3c8
Show file tree
Hide file tree
Showing 2 changed files with 387 additions and 5 deletions.
82 changes: 80 additions & 2 deletions doomsday/libgui/include/de/gui/gluniform.h
Expand Up @@ -20,20 +20,98 @@
#define LIBGUI_GLUNIFORM_H

#include <de/libdeng2.h>
#include <de/Vector>
#include <de/Matrix>
#include <de/Observers>

#include "libgui.h"

#include <QLatin1String>

namespace de {

/**
* GL uniform.
* Constant variable or a sampler in a shader.
*
* GLUniform's public interface allows the uniform value to be manipulated like
* any other native variable (assignment, arithmetic, etc.).
*
* The value of the uniform is stored locally in the GLUniform instance. When
* the uniform has been bound to programs and its value changes, the programs
* are notified and they mark the uniform as changed. When the program is then
* later taken into use, the updated value of the changed uniforms is sent to
* GL.
*
* @ingroup gl
*/
class LIBGUI_PUBLIC GLUniform
{
public:
GLUniform();
enum Type
{
Int,
UInt,
Float,
Vector2,
Vector3,
Vector4,
Matrix3x3,
Matrix4x4,
Texture2D
};

/**
* Notified when the value of the uniform changes.
*/
DENG2_DEFINE_AUDIENCE(ValueChange, void uniformValueChanged(GLUniform &))

/**
* Notified when the uniform instance is deleted.
*/
DENG2_DEFINE_AUDIENCE(Deletion, void uniformDeleted(GLUniform &))

public:
GLUniform(QLatin1String const &nameInShader, Type uniformType);

virtual ~GLUniform();

void setName(QLatin1String const &nameInShader);

/**
* Returns the name of the uniform as it appears in shaders.
*/
QLatin1String name() const;

/**
* Returns the value type of the shader.
*/
Type type() const;

GLUniform &operator = (dint value);
GLUniform &operator = (duint value);
GLUniform &operator = (dfloat value);
GLUniform &operator = (Vector2f const &vec);
GLUniform &operator = (Vector3f const &vec);
GLUniform &operator = (Vector4f const &vec);
GLUniform &operator = (Matrix3f const &vec);
GLUniform &operator = (Matrix4f const &vec);

operator dint() const { return toInt(); }
operator duint() const { return toUInt(); }
operator dfloat() const { return toFloat(); }
operator ddouble() const { return ddouble(toFloat()); }
operator Vector2f() const { return toVector2f(); }
operator Vector3f() const { return toVector3f(); }
operator Vector4f() const { return toVector4f(); }

dint toInt() const;
duint toUInt() const;
dfloat toFloat() const;
Vector2f const &toVector2f() const;
Vector3f const &toVector3f() const;
Vector4f const &toVector4f() const;
Matrix3f const &toMatrix3f() const;
Matrix4f const &toMatrix4f() const;

private:
DENG2_PRIVATE(d)
Expand Down

0 comments on commit f36a3c8

Please sign in to comment.