AvogadroLibs 1.98.1
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ShaderProgram Class Reference

The ShaderProgram uses one or more Shader objects. More...

#include <avogadro/rendering/shaderprogram.h>

Public Types

enum  NormalizeOption {
  Normalize ,
  NoNormalize
}
 

Public Member Functions

bool attachShader (const Shader &shader)
 
bool detachShader (const Shader &shader)
 
bool link ()
 
bool bind ()
 
void release ()
 
std::string error () const
 
bool enableAttributeArray (const std::string &name)
 
bool disableAttributeArray (const std::string &name)
 
bool useAttributeArray (const std::string &name, int offset, size_t stride, Avogadro::Type elementType, int elementTupleSize, NormalizeOption normalize)
 
template<class ContainerT >
bool setAttributeArray (const std::string &name, const ContainerT &array, int tupleSize, NormalizeOption normalize)
 
bool setTextureSampler (const std::string &samplerName, const Texture2D &texture)
 
bool setUniformValue (const std::string &name, int i)
 
bool setUniformValue (const std::string &name, float f)
 
bool setUniformValue (const std::string &name, const Eigen::Matrix3f &matrix)
 
bool setUniformValue (const std::string &name, const Eigen::Matrix4f &matrix)
 
bool setUniformValue (const std::string &name, const Vector3f &v)
 
bool setUniformValue (const std::string &name, const Vector2i &v)
 
bool setUniformValue (const std::string &name, const Vector3ub &v)
 

Protected Member Functions

bool setAttributeArrayInternal (const std::string &name, void *buffer, Avogadro::Type type, int tupleSize, NormalizeOption normalize)
 

Protected Attributes

Index m_handle
 
Index m_vertexShader
 
Index m_fragmentShader
 
bool m_linked
 
std::string m_error
 
std::map< std::string, int > m_attributes
 
std::map< const Texture2D *, int > m_textureUnitBindings
 
std::vector< bool > m_boundTextureUnits
 

Detailed Description

Author
Marcus D. Hanwell

This class creates a Vertex or Fragment shader, that can be attached to a ShaderProgram in order to render geometry etc.

Member Enumeration Documentation

◆ NormalizeOption

Options for attribute normalization.

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.

NoNormalize 

The values should be used as-is. Do not perform any normalization.

Member Function Documentation

◆ attachShader()

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.

◆ detachShader()

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.

◆ link()

bool link ( )

Attempt to link the shader program.

Returns
false on failure. Query error to get the reason.
Note
The shaders attached to the program must have been compiled.

◆ bind()

bool bind ( )

Bind the program in order to use it. If the program has not been linked then link() will be called.

◆ release()

void release ( )

Releases the shader program from the current context.

◆ error()

std::string error ( ) const

Get the error message (empty if none) for the shader program.

◆ enableAttributeArray()

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.

◆ disableAttributeArray()

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.

◆ useAttributeArray()

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
nameof the attribute (as seen in the shader program).
offsetinto the bound BufferObject.
strideThe 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.
elementTypeTag identifying the memory representation of the element.
elementTupleSizeThe number of elements per vertex (e.g. a 3D position attribute would be 3).
normalizeIndicates the range used by the attribute data. See NormalizeOption for more information.
Returns
false if the attribute array does not exist.

◆ setAttributeArray()

template<class ContainerT >
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.

Parameters
nameAttribute name
arrayContainer of data. See note.
tupleSizeThe number of elements per vertex, e.g. a 3D coordinate array will have a tuple size of 3.
normalizeIndicates the range used by the attribute data. See NormalizeOption for more information.
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.

◆ setTextureSampler()

bool setTextureSampler ( const std::string &  samplerName,
const Texture2D texture 
)

Set the sampler samplerName to use the specified texture.

◆ setUniformValue() [1/6]

bool setUniformValue ( const std::string &  name,
int  i 
)

Set the name uniform value to int i.

◆ setUniformValue() [2/6]

bool setUniformValue ( const std::string &  name,
float  f 
)

Set the name uniform value to float f.

◆ setUniformValue() [3/6]

bool setUniformValue ( const std::string &  name,
const Eigen::Matrix3f &  matrix 
)

Set the name uniform value to matrix.

◆ setUniformValue() [4/6]

bool setUniformValue ( const std::string &  name,
const Vector3f &  v 
)

Set the name uniform value to the supplied value.

◆ setUniformValue() [5/6]

bool setUniformValue ( const std::string &  name,
const Vector2i &  v 
)

Set the name uniform value to the supplied value.

◆ setUniformValue() [6/6]

bool setUniformValue ( const std::string &  name,
const Vector3ub &  v 
)

Set the name uniform value to the supplied value.


The documentation for this class was generated from the following file: