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

Shader use by Renderer to draw textured rectangles (sprites). More...

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

Public Member Functions

void setGlobalProjectionTransform (const Matrix4 &matrix)
 Sets the projection matrix, which is a global uniform. More...
 
void setTransform (const Matrix4 &matrix)
 Sets the model transform. More...
 
void setTexCoordScale (const Vector2 &value)
 Sets the offset to apply to texture coordinates, shifting the source rectangle in the source texture. More...
 
void setTexCoordOffset (const Vector2 &value)
 Sets the scaling factor to apply to texture coordinates, shrinking or expanding the source rectangle in the source texture. More...
 
void setOpacity (float value)
 Sets the overall transparency of the rendered texture, with 0.0f completely transparent, and 1.0f fully opaque. More...
 
void setTexture (const TexturePtr &texture)
 Sets the source Texture to apply to the drawn rectangle. More...
 
- Public Member Functions inherited from InstancedShaderBase< SpriteShader >
 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...
 

Protected Member Functions

virtual void updateState () override
 Implementation of InstancedShader::updateState(). More...
 

Friends

class InstancedShaderBase< SpriteShader >
 

Additional Inherited Members

- Public Types inherited from SingletonInstancedShaderBase< SpriteShader >
typedef std::shared_ptr
< SpriteShader
TShaderImplPtr
 Helper typedef for a shared pointer to a TShaderImpl. More...
 
typedef std::weak_ptr
< SpriteShader
TShaderImplWeakPtr
 Helper typedef for a weak shared pointer to a TShaderImpl. More...
 
- Static Public Member Functions inherited from SingletonInstancedShaderBase< SpriteShader >
static TShaderImplPtr getInstance ()
 Returns the singleton instance of this shader, creating it if necessary. More...
 
- Static Public Member Functions inherited from InstancedShaderBase< SpriteShader >
static const ShaderPtrgetSharedShader ()
 Returns the shared Shader singleton, creating it if necessary. More...
 
- Static Protected Member Functions inherited from InstancedShaderBase< SpriteShader >
static ShaderPtr createSharedShader ()
 The default implementation of createSharedShader(). More...
 

Detailed Description

Shader use by Renderer to draw textured rectangles (sprites).

This Shader can take two transform matrices, a projection and model transform. The projection matrix is set once (usually by Renderer) and is global. The model matrix positions the rectangle in space, potentially rotated. This Shader also allows selection of a source rectangle in the given Texture. This is done by offsetting texture UV coordinates.

Note
This Shader is not intended to be used for batched rendering of sprites.

Member Function Documentation

void SpriteShader::setGlobalProjectionTransform ( const Matrix4 matrix)

Sets the projection matrix, which is a global uniform.

Note
This is usually set by Renderer at the start of frame rendering and does not need to be set manually.
Parameters
matrixMatrix to set
void SpriteShader::setOpacity ( float  value)

Sets the overall transparency of the rendered texture, with 0.0f completely transparent, and 1.0f fully opaque.

This value is multiplied with the source texture's alpha, if it has an alpha channel, to produce per-pixel alpha.

Parameters
valueTransparency to set
void SpriteShader::setTexCoordOffset ( const Vector2 value)

Sets the scaling factor to apply to texture coordinates, shrinking or expanding the source rectangle in the source texture.

Parameters
valueAmount to scale
void SpriteShader::setTexCoordScale ( const Vector2 value)

Sets the offset to apply to texture coordinates, shifting the source rectangle in the source texture.

Parameters
valueAmount to offset
void SpriteShader::setTexture ( const TexturePtr texture)

Sets the source Texture to apply to the drawn rectangle.

The source rectangle into the Texture will be transformed by the texture coordinate offset and scale.

Parameters
textureTexture to set
void SpriteShader::setTransform ( const Matrix4 matrix)

Sets the model transform.

Parameters
matrixMatrix to set
virtual void SpriteShader::updateState ( )
overrideprotectedvirtual

Implementation of InstancedShader::updateState().

Reimplemented from InstancedShader.