VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | List of all members

Shader program abstract base class. More...

Inheritance diagram for Shader:
InstancedShader ShaderBase InstancedShaderBase< TShaderImpl > InstancedShaderBase< SpriteShader > TerrainShader SingletonInstancedShaderBase< TShaderImpl > SingletonInstancedShaderBase< SpriteShader > SpriteShader

Public Member Functions

 Shader (const AttributeSetPtr &attributes, const std::vector< std::string > &uniformNames)
 Construct a Shader with the given list of attributes and uniforms. More...
 
virtual bool isCurrent () const =0
 Returns whether or not this shader is bound. More...
 
virtual bool isValid () const =0
 Returns whether or not this shader is valid (compiled and linked) and can be used for rendering. More...
 
virtual bool isCompiled () const =0
 Returns whether or not this shader has been processed for compilation. More...
 
virtual GLuint getProgramId () const =0
 Returns the GL program id for this shader. More...
 
virtual void begin ()=0
 Binds this shader, updating state as necessary. More...
 
virtual void end ()=0
 Unbinds this shader if bound by a corresponding call to begin(). More...
 
virtual void compile ()=0
 Compiles this shader, if not already compiled. More...
 
virtual std::string getErrorLog () const =0
 Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is false. More...
 
const AttributeSetPtrgetAttributes () const
 Returns the list of indexed Attributes for this shader, as an AttributeSet. More...
 
const std::vector< std::string > & getUniformNames () const
 Returns the list of indexed uniforms. More...
 
virtual int getAttributeLocation (int index) const =0
 Returns the location of an indexed Attribute. More...
 
virtual int getUniformLocation (int index) const =0
 Returns the location of an indexed uniform. More...
 
void setIndexedUniform1f (int index, bool global, float value, float *stateValue)
 Set the value of a float scalar uniform at the given index. More...
 
void setIndexedUniform2f (int index, bool global, const Vector2 &value, Vector2 *stateValue)
 Set the value of a 2D float vector uniform at the given index. More...
 
void setIndexedUniform3f (int index, bool global, float value1, float value2, float value3, float *stateValue)
 Set the value of a 3D float vector uniform at the given index. More...
 
void setIndexedUniform4f (int index, bool global, float value1, float value2, float value3, float value4, float *stateValue)
 Set the value of a 4D float vector uniform at the given index. More...
 
void setIndexedUniform1i (int index, bool global, int value, int *stateValue)
 Set the value of an integer scalar uniform at the given index. More...
 
void setIndexedUniformMatrix4f (int index, bool global, bool transpose, const Matrix4 &value, Matrix4 *stateValue)
 Set the value of a 4x4 float matrix uniform at the given index. More...
 

Detailed Description

Shader program abstract base class.

This class is a wrapper around a GL program, with the added concept of indexed attributes and uniforms. Indexed attributes and uniforms allow attributes and uniforms to be referenced by index, rather than name, for efficient lookups. The index of an attribute or uniform is determined by its index into the list of attributes and uniforms passed into Shader's constructor. For example, if you provide the list of uniforms, "color", "offset", "direction", the uniform color would have index 0, offset index 1, and direction index 2. These indices can be provided to functions like getAttributeLocation(), getUniformLocation(), and the setIndexed family of functions such as setIndexedUniformMatrix4f().

See InstancedShader for the details on how to use the setIndexed family of methods to implement an instanced shader.

Shaders can either be used on their own as wrappers around GL programs and managers of their state or in conjunction with Renderer. If used with Renderer, begin() and end() will be called as needed when selected.

Constructor & Destructor Documentation

Shader::Shader ( const AttributeSetPtr attributes,
const std::vector< std::string > &  uniformNames 
)

Construct a Shader with the given list of attributes and uniforms.

Parameters
attributesAttributeSet containing the list of indexed attributes for this shader
uniformNamesList of indexed uniforms

Member Function Documentation

virtual void Shader::begin ( )
pure virtual

Binds this shader, updating state as necessary.

Implemented in InstancedShader, and ShaderBase.

virtual void Shader::compile ( )
pure virtual

Compiles this shader, if not already compiled.

Implemented in InstancedShader, and ShaderBase.

virtual void Shader::end ( )
pure virtual

Unbinds this shader if bound by a corresponding call to begin().

Implemented in InstancedShader, and ShaderBase.

virtual int Shader::getAttributeLocation ( int  index) const
pure virtual

Returns the location of an indexed Attribute.

Indexed attributes are those that are named in the AttributeSet provided to the shader's constructor.

Parameters
indexIndex into the list of attributes

Implemented in InstancedShader, and ShaderBase.

const AttributeSetPtr& Shader::getAttributes ( ) const
inline

Returns the list of indexed Attributes for this shader, as an AttributeSet.

virtual std::string Shader::getErrorLog ( ) const
pure virtual

Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is false.

Returns
String describing compilation errors

Implemented in InstancedShader, and ShaderBase.

virtual GLuint Shader::getProgramId ( ) const
pure virtual

Returns the GL program id for this shader.

Implemented in InstancedShader, and ShaderBase.

virtual int Shader::getUniformLocation ( int  index) const
pure virtual

Returns the location of an indexed uniform.

Indexed uniforms are those that are named in the list of uniforms provided to the shader's constructor.

Parameters
indexIndex into the list of uniforms

Implemented in InstancedShader, and ShaderBase.

const std::vector<std::string>& Shader::getUniformNames ( ) const
inline

Returns the list of indexed uniforms.

virtual bool Shader::isCompiled ( ) const
pure virtual

Returns whether or not this shader has been processed for compilation.

Note
This does not indicate whether compilation succeeded. To test for success, use isValid().

Implemented in InstancedShader, and ShaderBase.

virtual bool Shader::isCurrent ( ) const
pure virtual

Returns whether or not this shader is bound.

Implemented in InstancedShader, and ShaderBase.

virtual bool Shader::isValid ( ) const
pure virtual

Returns whether or not this shader is valid (compiled and linked) and can be used for rendering.

Implemented in InstancedShader, and ShaderBase.

void Shader::setIndexedUniform1f ( int  index,
bool  global,
float  value,
float *  stateValue 
)

Set the value of a float scalar uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
valueScalar value to set
stateValueMemory to save off state to, or nullptr if state should not be saved
void Shader::setIndexedUniform1i ( int  index,
bool  global,
int  value,
int *  stateValue 
)

Set the value of an integer scalar uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
valueScalar value to set
stateValueMemory to save off state to, or nullptr if state should not be saved
void Shader::setIndexedUniform2f ( int  index,
bool  global,
const Vector2 value,
Vector2 stateValue 
)

Set the value of a 2D float vector uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
valueVector2 to set
stateValueMemory to save off state to, or nullptr if state should not be saved
void Shader::setIndexedUniform3f ( int  index,
bool  global,
float  value1,
float  value2,
float  value3,
float *  stateValue 
)

Set the value of a 3D float vector uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
value1First vector element
value2Second vector element
value3Third vector element
stateValueMemory to save off state to, or nullptr if state should not be saved
void Shader::setIndexedUniform4f ( int  index,
bool  global,
float  value1,
float  value2,
float  value3,
float  value4,
float *  stateValue 
)

Set the value of a 4D float vector uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
value1First vector element
value2Second vector element
value3Third vector element
value4Fourth vector element
stateValueMemory to save off state to, or nullptr if state should not be saved
void Shader::setIndexedUniformMatrix4f ( int  index,
bool  global,
bool  transpose,
const Matrix4 value,
Matrix4 stateValue 
)

Set the value of a 4x4 float matrix uniform at the given index.

See InstancedShader for details on the setIndexed family of methods.

Note
This method currently differs from glUniformMatrix4fv() in that only one matrix, not an array of matrices, can be uploaded.
Parameters
indexIndex of the uniform to set
globalWhether or not this uniform is global and should be set even if the shader is not bound
transposeWhether or not to upload this matrix transposed
valueMatrix to set
stateValueMemory to save off state to, or nullptr if state should not be saved