chai3d::cShaderProgram Class Reference

This class implements a shader program primitive. More...

#include <CShaderProgram.h>

Public Member Functions

 cShaderProgram ()
 Constructor of cShaderProgram. More...
 
 cShaderProgram (const std::string &a_vertexShader, const std::string &a_fragmentShader)
 Constructor of cShaderProgram. More...
 
virtual ~cShaderProgram ()
 Destructor of cShaderProgram. More...
 
void attachShader (cShaderPtr a_shader)
 This method attaches a shader to the shader program. More...
 
bool linkProgram ()
 This method links the shader program and returns the link status. More...
 
void use (cGenericObject *a_object, cRenderOptions &a_options)
 This method enables the shader program. More...
 
void disable ()
 This method disables the shader program. More...
 
bool isUsed ()
 This method returns true if this shader is currently in use. false otherwise. More...
 
void bindAttributeLocation (const unsigned int a_index, const char *a_name)
 This method binds an attribute to a name. More...
 
int getAttributeLocation (const char *a_name)
 This method returns the location of a specified attribute. More...
 
int getUniformLocation (const char *a_name)
 This method returns the location of a specified uniform. More...
 
GLint getId ()
 This method returns the program ID. More...
 
void setGeometryInputType (GLenum a_type)
 Set the geometry shader input primitype type. More...
 
void setGeometryOutputType (GLenum a_type)
 Set the geometry shader output primitype type. More...
 
void setGeometryVerticesOut (int a_numVertices)
 Set the maximum number of vertices emitted by the gemoetry shader. More...
 
void setUniformi (const char *a_name, const GLint a_value)
 This method sets an int uniform to a specified value. More...
 
void setUniformf (const char *a_name, const GLfloat a_value)
 This method sets a float uniform to a specified value. More...
 
void setUniform (const char *a_name, cVector3d &a_value)
 This method sets a cVector3d uniform to a specified value. More...
 
void setUniform (const char *a_name, cMatrix3d &a_value, bool a_transposed)
 This method sets a cMatrix3d uniform to a specified value. More...
 
void setUniform (const char *a_name, cTransform &a_value, bool a_transposed)
 This method sets a cTransform uniform to a specified value. More...
 
void setUniformiv (const char *a_name, const GLint *a_values, const int a_count)
 This method sets an int array uniform to specified values. More...
 
void setUniformfv (const char *a_name, const GLfloat *a_values, const int a_count)
 This method sets a float array uniform to specified values. More...
 

Static Public Member Functions

static cShaderProgramPtr create ()
 Shared cShaderProgram allocator. More...
 
static cShaderProgramPtr create (const std::string &a_vertexShader, const std::string &a_fragmentShader)
 Shared cShaderProgram allocator. More...
 

Protected Attributes

GLuint m_id
 OpenGL handle ID for the shader program. More...
 
bool m_linked
 If true then shader program was successfully linked, false otherwise. More...
 
bool m_enabled
 If true then program shader is currently enabled. More...
 
GLuint m_shaderCount
 Number of shaders that are attached to the shader program. More...
 
std::map< std::string, int > m_attributeLocList
 Map of attributes and their binding locations. More...
 
std::map< std::string, int > m_uniformLocList
 Map of uniforms and their binding locations. More...
 
std::vector< cShaderPtrm_shaders
 List of attached shaders. More...
 
bool m_geometryShaderAttached
 Whether or not this program has a geometry shader attached. More...
 
GLenum m_geometryInputType
 Geometry shader input primitive type, if applicable. More...
 
GLenum m_geometryOutputType
 Geometry shader output primitive type, if applicable. More...
 
GLint m_geometryVerticesOut
 Maximum number of vertices generated by the geometry shader. More...
 

Detailed Description

This class implements a shader program that contain a list of shader primitives. Shader programs can be assigned to cGenericObject entities to control their graphical output.

Constructor & Destructor Documentation

chai3d::cShaderProgram::cShaderProgram ( )

Constructor of cShaderProgram.

chai3d::cShaderProgram::cShaderProgram ( const std::string &  a_vertexShader,
const std::string &  a_fragmentShader 
)

Constructor of cShaderProgram.

Parameters
a_vertexShaderVertex shader code.
a_vertexShaderFragment shader code.
chai3d::cShaderProgram::~cShaderProgram ( )
virtual

Destructor of cShaderProgram.

Member Function Documentation

static cShaderProgramPtr chai3d::cShaderProgram::create ( )
inlinestatic
static cShaderProgramPtr chai3d::cShaderProgram::create ( const std::string &  a_vertexShader,
const std::string &  a_fragmentShader 
)
inlinestatic
void chai3d::cShaderProgram::attachShader ( cShaderPtr  a_shader)

This method attaches a shader to the shader program.

Parameters
a_shaderShader object.
bool chai3d::cShaderProgram::linkProgram ( )

This method links the shader program and return the link status.

Returns
true if the operation succeeded, __false__otherwise.
void chai3d::cShaderProgram::use ( cGenericObject a_object,
cRenderOptions a_options 
)

This method enables the shader program.

Parameters
a_objectObject on which the program shader will apply
a_optionsRendering options.
void chai3d::cShaderProgram::disable ( )

This method disables the shader program.

bool chai3d::cShaderProgram::isUsed ( )
inline
void chai3d::cShaderProgram::bindAttributeLocation ( const unsigned int  a_index,
const char *  a_name 
)

This method binds an attribute to a name.

Parameters
a_indexIndex of the attribute to be bound
a_nameName of the attribute.
int chai3d::cShaderProgram::getAttributeLocation ( const char *  a_name)

This method returns the location of a specified attribute.

Parameters
a_nameName of the attribute.
Returns
Attribute location.
int chai3d::cShaderProgram::getUniformLocation ( const char *  a_name)

This method returns the location of a specified uniform.

Parameters
a_nameName of the uniform.
Returns
Uniform location.
GLint chai3d::cShaderProgram::getId ( )
inline
void chai3d::cShaderProgram::setGeometryInputType ( GLenum  a_type)
inline
void chai3d::cShaderProgram::setGeometryOutputType ( GLenum  a_type)
inline
void chai3d::cShaderProgram::setGeometryVerticesOut ( int  a_numVertices)
inline
void chai3d::cShaderProgram::setUniformi ( const char *  a_name,
const GLint  a_value 
)

This method sets an int uniform to a specified value.

Parameters
a_nameName of the uniform.
a_valueNew value of the uniform.
void chai3d::cShaderProgram::setUniformf ( const char *  a_name,
const GLfloat  a_value 
)

This method sets a float uniform to a specified value.

Parameters
a_nameName of the uniform.
a_valueNew value of the uniform.
void chai3d::cShaderProgram::setUniform ( const char *  a_name,
cVector3d a_value 
)

This method sets a cVector3d uniform to a specified value.

Parameters
a_nameName of the uniform.
a_valueNew value of the uniform.
void chai3d::cShaderProgram::setUniform ( const char *  a_name,
cMatrix3d a_value,
bool  a_transposed 
)

This method sets a cMatrix3d uniform to a specified value.

Parameters
a_nameName of the uniform.
a_valueNew 3x3 matrix of the uniform.
a_transposedIs the matrix transposed?
void chai3d::cShaderProgram::setUniform ( const char *  a_name,
cTransform a_value,
bool  a_transposed 
)

This method sets a cTransform uniform to a specified value.

Parameters
a_nameName of the uniform.
a_valueNew 4x4 matrix of the uniform.
a_transposedIs the matrix transposed?
void chai3d::cShaderProgram::setUniformiv ( const char *  a_name,
const GLint *  a_values,
const int  a_count 
)

This method sets an int array uniform to specified values.

Parameters
a_nameName of the uniform.
a_valuesPointer to an array with the new values.
a_countNumber of values in the given array.
void chai3d::cShaderProgram::setUniformfv ( const char *  a_name,
const GLfloat *  a_values,
const int  a_count 
)

This method sets a float array uniform to specified values.

Parameters
a_nameName of the uniform.
a_valuesPointer to an array with the new values.
a_countNumber of values in the given array.

Member Data Documentation

GLuint chai3d::cShaderProgram::m_id
protected
bool chai3d::cShaderProgram::m_linked
protected
bool chai3d::cShaderProgram::m_enabled
protected
GLuint chai3d::cShaderProgram::m_shaderCount
protected
std::map<std::string, int> chai3d::cShaderProgram::m_attributeLocList
protected
std::map<std::string, int> chai3d::cShaderProgram::m_uniformLocList
protected
std::vector<cShaderPtr> chai3d::cShaderProgram::m_shaders
protected
bool chai3d::cShaderProgram::m_geometryShaderAttached
protected
GLenum chai3d::cShaderProgram::m_geometryInputType
protected
GLenum chai3d::cShaderProgram::m_geometryOutputType
protected
GLint chai3d::cShaderProgram::m_geometryVerticesOut
protected

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