VoltAir
|
Shader program abstract base class. More...
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 AttributeSetPtr & | getAttributes () 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... | |
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.
Shader::Shader | ( | const AttributeSetPtr & | attributes, |
const std::vector< std::string > & | uniformNames | ||
) |
Construct a Shader with the given list of attributes and uniforms.
attributes | AttributeSet containing the list of indexed attributes for this shader |
uniformNames | List of indexed uniforms |
|
pure virtual |
Binds this shader, updating state as necessary.
Implemented in InstancedShader, and ShaderBase.
|
pure virtual |
Compiles this shader, if not already compiled.
Implemented in InstancedShader, and ShaderBase.
|
pure virtual |
Unbinds this shader if bound by a corresponding call to begin().
Implemented in InstancedShader, and ShaderBase.
|
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.
index | Index into the list of attributes |
Implemented in InstancedShader, and ShaderBase.
|
inline |
Returns the list of indexed Attributes for this shader, as an AttributeSet.
|
pure virtual |
Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is false
.
Implemented in InstancedShader, and ShaderBase.
|
pure virtual |
Returns the GL program id for this shader.
Implemented in InstancedShader, and ShaderBase.
|
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.
index | Index into the list of uniforms |
Implemented in InstancedShader, and ShaderBase.
|
inline |
Returns the list of indexed uniforms.
|
pure virtual |
Returns whether or not this shader has been processed for compilation.
Implemented in InstancedShader, and ShaderBase.
|
pure virtual |
Returns whether or not this shader is bound.
Implemented in InstancedShader, and ShaderBase.
|
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.
index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
value | Scalar value to set |
stateValue | Memory 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.
index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
value | Scalar value to set |
stateValue | Memory 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.
index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
value | Vector2 to set |
stateValue | Memory 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.
index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
value1 | First vector element |
value2 | Second vector element |
value3 | Third vector element |
stateValue | Memory 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.
index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
value1 | First vector element |
value2 | Second vector element |
value3 | Third vector element |
value4 | Fourth vector element |
stateValue | Memory 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.
glUniformMatrix4fv()
in that only one matrix, not an array of matrices, can be uploaded. index | Index of the uniform to set |
global | Whether or not this uniform is global and should be set even if the shader is not bound |
transpose | Whether or not to upload this matrix transposed |
value | Matrix to set |
stateValue | Memory to save off state to, or nullptr if state should not be saved |