Avogadro::Rendering::ShaderProgram#
-
class ShaderProgram#
The ShaderProgram uses one or more Shader objects.
This class creates a Vertex or Fragment shader, that can be attached to a ShaderProgram in order to render geometry etc.
- Author
Marcus D. Hanwell
Unnamed Group
-
bool setUniformValue(const std::string &name, const Vector3f &v)#
Set the
name
uniform value to the supplied value.
-
bool setUniformValue(const std::string &name, const Vector2i &v)#
Set the
name
uniform value to the supplied value.
-
bool setUniformValue(const std::string &name, const Vector3ub &v)#
Set the
name
uniform value to the supplied value.
Public Types
-
enum NormalizeOption#
Options for attribute normalization.
Values:
-
enumerator Normalize#
The values range across the limits of the numeric type. This option instructs the rendering engine to normalize them to the range [0.0, 1.0] for unsigned types, and [-1.0, 1.0] for signed types. For example, unsigned char values will be mapped so that 0 = 0.0, and 255 = 1.0. The resulting floating point numbers will be passed into the shader program.
-
enumerator NoNormalize#
The values should be used as-is. Do not perform any normalization.
-
enumerator Normalize#
Public Functions
-
ShaderProgram()#
-
~ShaderProgram()#
-
bool attachShader(const Shader &shader)#
Attach the supplied shader to this program.
Note
A maximum of one Vertex shader and one Fragment shader can be attached to a shader prorgram.
- Returns:
true on success.
-
bool detachShader(const Shader &shader)#
Detach the supplied shader from this program.
Note
A maximum of one Vertex shader and one Fragment shader can be attached to a shader prorgram.
- Returns:
true on success.
-
bool link()#
Attempt to link the shader program.
Note
The shaders attached to the program must have been compiled.
- Returns:
false on failure. Query error to get the reason.
-
bool bind()#
Bind the program in order to use it. If the program has not been linked then link() will be called.
-
void release()#
Releases the shader program from the current context.
-
inline std::string error() const#
Get the error message (empty if none) for the shader program.
-
bool enableAttributeArray(const std::string &name)#
Enable the named attribute array. Return false if the attribute array is not contained in the linked shader program.
-
bool disableAttributeArray(const std::string &name)#
Disable the named attribute array. Return false if the attribute array is not contained in the linked shader program.
-
bool useAttributeArray(const std::string &name, int offset, size_t stride, Avogadro::Type elementType, int elementTupleSize, NormalizeOption normalize)#
Use the named attribute array with the bound BufferObject.
- Parameters:
name – of the attribute (as seen in the shader program).
offset – into the bound BufferObject.
stride – The stride of the element access (i.e. the size of each element in the currently bound BufferObject). 0 may be used to indicate tightly packed data.
elementType – Tag identifying the memory representation of the element.
elementTupleSize – The number of elements per vertex (e.g. a 3D position attribute would be 3).
normalize – Indicates the range used by the attribute data. See NormalizeOption for more information.
- Returns:
false if the attribute array does not exist.
-
template<class ContainerT>
inline bool setAttributeArray(const std::string &name, const ContainerT &array, int tupleSize, NormalizeOption normalize)# Upload the supplied array of tightly packed values to the named attribute. BufferObject attributes should be preferred and this may be removed in future.
Note
The ContainerT type must have tightly packed values of ContainerT::value_type accessible by reference via ContainerT::operator[]. Additionally, the standard size() and empty() methods must be implemented. The std::vector and Avogadro::Core::Array classes are examples of such supported containers.
- Parameters:
name – Attribute name
array – Container of data. See note.
tupleSize – The number of elements per vertex, e.g. a 3D coordinate array will have a tuple size of 3.
normalize – Indicates the range used by the attribute data. See NormalizeOption for more information.
-
bool setTextureSampler(const std::string &samplerName, const Texture2D &texture)#
Set the sampler samplerName to use the specified texture.
-
bool setUniformValue(const std::string &name, int i)#
Set the
name
uniform value to inti
.
-
bool setUniformValue(const std::string &name, float f)#
Set the
name
uniform value to floatf
.
-
bool setUniformValue(const std::string &name, const Eigen::Matrix3f &matrix)#
Set the
name
uniform value tomatrix
.
-
bool setUniformValue(const std::string &name, const Eigen::Matrix4f &matrix)#
Protected Functions
-
bool setAttributeArrayInternal(const std::string &name, void *buffer, Avogadro::Type type, int tupleSize, NormalizeOption normalize)#