VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | List of all members
InstancedShaderBase< TShaderImpl > Class Template Reference

Helper class to implement InstancedShader subclasses, by managing a shared Shader. More...

Inheritance diagram for InstancedShaderBase< TShaderImpl >:
InstancedShader Shader SingletonInstancedShaderBase< TShaderImpl >

Public Member Functions

 InstancedShaderBase ()
 Construct this InstancedShader, creating the shared Shader if necessary. More...
 
- Public Member Functions inherited from InstancedShader
 InstancedShader (const ShaderPtr &sharedShader)
 Create an InstancedShader which references a shader Shader. More...
 
const ShaderPtrgetSharedShader () const
 Returns the Shader that is shared among instances. More...
 
virtual bool isCurrent () const override
 Returns whether or not this instance is bound. More...
 
virtual bool isValid () const override
 Returns whether or not this shader is valid (compiled and linked) and can be used for rendering. More...
 
virtual bool isCompiled () const override
 Returns whether or not this shader has been processed for compilation. More...
 
virtual GLuint getProgramId () const override
 Returns the GL program id for this shader. More...
 
virtual void begin () override
 Binds this shader, and sets uniforms and other GL state associated with this instance. More...
 
virtual void end () override
 Unbinds this shader if bound by a corresponding call to begin(). More...
 
virtual void compile () override
 Compiles this shader, resulting in the compilation of the shared Shader if necessary. More...
 
virtual std::string getErrorLog () const override
 Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is false. More...
 
virtual int getAttributeLocation (int index) const override
 Returns the location of an indexed Attribute. More...
 
virtual int getUniformLocation (int index) const override
 Returns the location of an indexed uniform. More...
 
void setIndexedTexture (int index, int stage, const TexturePtr &value, TexturePtr *stateValue)
 Set the indexed texture for this instance at the given index. More...
 
- Public Member Functions inherited from Shader
 Shader (const AttributeSetPtr &attributes, const std::vector< std::string > &uniformNames)
 Construct a Shader with the given list of attributes and uniforms. 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...
 
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...
 

Static Public Member Functions

static const ShaderPtrgetSharedShader ()
 Returns the shared Shader singleton, creating it if necessary. More...
 

Static Protected Member Functions

static ShaderPtr createSharedShader ()
 The default implementation of createSharedShader(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from InstancedShader
virtual void updateState ()
 Update state in response to this instance getting bound. More...
 

Detailed Description

template<typename TShaderImpl>
class InstancedShaderBase< TShaderImpl >

Helper class to implement InstancedShader subclasses, by managing a shared Shader.

This class creates and manages a shared Shader as a singleton. The singleton Shader is created by a call to createSharedShader, a static method. The default implementation builds the shader using data returned from static methods which must be traits of the subclass TShaderImpl. The following traits should exist:

Alternatively, the subclass can implement and hide the createSharedShader() static function to manually create a custom shader. The signature should be:

Constructor & Destructor Documentation

template<typename TShaderImpl>
InstancedShaderBase< TShaderImpl >::InstancedShaderBase ( )
inline

Construct this InstancedShader, creating the shared Shader if necessary.

Member Function Documentation

template<typename TShaderImpl>
static ShaderPtr InstancedShaderBase< TShaderImpl >::createSharedShader ( )
inlinestaticprotected

The default implementation of createSharedShader().

This method calls static trait methods in TShaderImpl to build the shared Shader.

Returns
A new shader to be used as the shared Shader singleton
template<typename TShaderImpl>
static const ShaderPtr& InstancedShaderBase< TShaderImpl >::getSharedShader ( )
inlinestatic

Returns the shared Shader singleton, creating it if necessary.

The shared Shader is created through a call to TShaderImpl::createSharedShader(). If TShaderImpl implements this static method, that implementation will be used. If not, the default implementation in this class will be used.