Overview     Modules     Class Hierarchy     Classes     Members  

tlp::GlShaderProgram Class Reference

A class to manage OpenGL shader program. More...

#include <GlShaderProgram.h>

Collaboration diagram for tlp::GlShaderProgram:

List of all members.

Public Member Functions

Static Public Member Functions


Detailed Description

A class to manage OpenGL shader program.

This class allows to create and use shader programs by linking several shader objects. At least one shader object must be provided in order to use the shader program. Multiple shader objects of the same type can be added but exactly one of these shader objects must have a main() function. As in C, in order to use a function defined in a separate shader object from another shader object, this function has to be declared with the same prototype in the source code of the last one.

This class also allows to specify uniform and attribute variables values of the shader program.


Constructor & Destructor Documentation

tlp::GlShaderProgram::GlShaderProgram ( const std::string &  name = ""  ) 

GlShaderProgram constructor

Parameters:
name An optionnal name can be provided to identify the shader program
tlp::GlShaderProgram::~GlShaderProgram (  ) 

GlShaderProgram destructor


Member Function Documentation

void tlp::GlShaderProgram::activate (  ) 

Activate the shader program. If the shader program has not been linked, the link method will be called.

void tlp::GlShaderProgram::addGeometryShaderFromSourceCode ( const std::string &  geometryShaderSrc,
GLenum  inputPrimitiveType,
GLenum  outputPrimitiveType 
)

Convenient method to add a geometry shader object from a source code stored in a C++ string The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
geometryShaderSrc the C++ string containing the geometry shader object source code
inputPrimitiveType the type of graphic primitive the geometry shader takes as input. (must be one from the following list : GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_EXT, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY_EXT)
outputPrimitiveType the type of graphics primitives the geometry shader will output (must be one of the following list : GL_POINTS, GL_LINE_STRIP, GL_TRIANGLE_STRIP)
void tlp::GlShaderProgram::addGeometryShaderFromSourceCode ( const char *  geometryShaderSrc,
GLenum  inputPrimitiveType,
GLenum  outputPrimitiveType 
)

Convenient method to add a geometry shader object from a source code stored in a C string The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
geometryShaderSrc the C string containing the geometry shader object source code
inputPrimitiveType the type of graphic primitive the geometry shader takes as input. (must be one from the following list : GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_EXT, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY_EXT)
outputPrimitiveType the type of graphics primitives the geometry shader will output (must be one of the following list : GL_POINTS, GL_LINE_STRIP, GL_TRIANGLE_STRIP)
void tlp::GlShaderProgram::addGeometryShaderFromSourceFile ( const std::string &  geometryShaderSrcFilename,
GLenum  inputPrimitiveType,
GLenum  outputPrimitiveType 
)

Convenient method to add a geometry shader object from a source code stored in a file The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
geometryShaderSrcFilename the absolute path to the file containing the geometry shader object source code
inputPrimitiveType the type of graphic primitive the geometry shader takes as input. (must be one from the following list : GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_EXT, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY_EXT)
outputPrimitiveType the type of graphics primitives the geometry shader will output (must be one of the following list : GL_POINTS, GL_LINE_STRIP, GL_TRIANGLE_STRIP)
void tlp::GlShaderProgram::addShader ( GlShader shader  ) 

Add a shader object to this shader program

Parameters:
shader the shader object to add to this shader program
void tlp::GlShaderProgram::addShaderFromSourceCode ( const ShaderType  shaderType,
const std::string &  shaderSrc 
)

Convenient method to add a shader object (from type Vertex or Fragment) from a source code stored in a C++ string The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
shaderType the type of the shader object to add (must be Vertex or Fragment)
shaderSrc the C++ string containing the shader object source code
void tlp::GlShaderProgram::addShaderFromSourceCode ( const ShaderType  shaderType,
const char *  shaderSrc 
)

Convenient method to add a shader object (from type Vertex or Fragment) from a source code stored in a C string The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
shaderType the type of the shader object to add (must be Vertex or Fragment)
shaderSrc the C string containing the shader object source code
void tlp::GlShaderProgram::addShaderFromSourceFile ( const ShaderType  shaderType,
const std::string &  shaderSrcFilename 
)

Convenient method to add a shader object (from type Vertex or Fragment) from a source code stored in a file The created shader object will be automatically destroyed when removing all attached shader objects or destroying the shader program

Parameters:
shaderType the type of the shader object to add (must be Vertex or Fragment)
shaderSrcFilename the aboslute path to the file containing the shader object source code
void tlp::GlShaderProgram::desactivate (  ) 

Deactivate the shader program.

static bool tlp::GlShaderProgram::geometryShaderSupported (  )  [static]

A static function which returns true if geometry shaders are supported by the host graphic card

static GlShaderProgram* tlp::GlShaderProgram::getCurrentActiveShader (  )  [static]

A static function which returns the current active shader if any

std::string tlp::GlShaderProgram::getName (  )  const [inline]

Return the string identifier of this shader program

GLuint tlp::GlShaderProgram::getShaderProgramId (  )  const [inline]

Return the OpenGL identifier of this shader program

void tlp::GlShaderProgram::getUniformBoolVariableValue ( const std::string &  variableName,
bool *  value 
)
void tlp::GlShaderProgram::getUniformFloatVariableValue ( const std::string &  variableName,
float *  value 
)
void tlp::GlShaderProgram::getUniformIntVariableValue ( const std::string &  variableName,
int *  value 
)
void tlp::GlShaderProgram::getUniformVec2BoolVariableValue ( const std::string &  variableName,
bool *  value 
)
void tlp::GlShaderProgram::getUniformVec3BoolVariableValue ( const std::string &  variableName,
bool *  value 
)
void tlp::GlShaderProgram::getUniformVec4BoolVariableValue ( const std::string &  variableName,
bool *  value 
)
bool tlp::GlShaderProgram::isLinked (  )  const [inline]

return true if the shader program has been successfully linked, false otherwise

void tlp::GlShaderProgram::link (  ) 

Link the shader program.

void tlp::GlShaderProgram::printInfoLog (  ) 

Print the info log containing errors and warnings related to shader objects compilation and shader program linkage

void tlp::GlShaderProgram::removeAllShaders (  ) 

remove all shaders from this shader program

void tlp::GlShaderProgram::removeShader ( GlShader shader  ) 

Remove a shader object from this shader program Note that the shader object will not be destroyed

Parameters:
shader the shader object to remove from this shader program
void tlp::GlShaderProgram::setAttributeBool ( const std::string &  variableName,
const bool  b 
)
void tlp::GlShaderProgram::setAttributeColor ( const std::string &  variableName,
const Color &  color 
)
void tlp::GlShaderProgram::setAttributeFloat ( const std::string &  variableName,
const float  f 
)
void tlp::GlShaderProgram::setAttributeInt ( const std::string &  variableName,
const int  f 
)
void tlp::GlShaderProgram::setAttributeVec2Bool ( const std::string &  variableName,
const bool  b1,
const bool  b2 
)
void tlp::GlShaderProgram::setAttributeVec2Bool ( const std::string &  variableName,
const Array< bool, 2 > &  vec2b 
)
void tlp::GlShaderProgram::setAttributeVec2Float ( const std::string &  variableName,
const float  f1,
const float  f2 
)
void tlp::GlShaderProgram::setAttributeVec2Float ( const std::string &  variableName,
const Vector< float, 2 > &  vec2f 
)
void tlp::GlShaderProgram::setAttributeVec2Int ( const std::string &  variableName,
const int  i1,
const int  i2 
)
void tlp::GlShaderProgram::setAttributeVec2Int ( const std::string &  variableName,
const Vector< int, 2 > &  vec2i 
)
void tlp::GlShaderProgram::setAttributeVec3Bool ( const std::string &  variableName,
const bool  b1,
const bool  b2,
const bool  b3 
)
void tlp::GlShaderProgram::setAttributeVec3Bool ( const std::string &  variableName,
const Array< bool, 3 > &  vec3b 
)
void tlp::GlShaderProgram::setAttributeVec3Float ( const std::string &  variableName,
const float  f1,
const float  f2,
const float  f3 
)
void tlp::GlShaderProgram::setAttributeVec3Float ( const std::string &  variableName,
const Vector< float, 3 > &  vec3f 
)
void tlp::GlShaderProgram::setAttributeVec3Int ( const std::string &  variableName,
const int  i1,
const int  i2,
const int  i3 
)
void tlp::GlShaderProgram::setAttributeVec3Int ( const std::string &  variableName,
const Vector< int, 3 > &  vec3i 
)
void tlp::GlShaderProgram::setAttributeVec4Bool ( const std::string &  variableName,
const bool  b1,
const bool  b2,
const bool  b3,
const bool  b4 
)
void tlp::GlShaderProgram::setAttributeVec4Bool ( const std::string &  variableName,
const Array< bool, 4 > &  vec4b 
)
void tlp::GlShaderProgram::setAttributeVec4Float ( const std::string &  variableName,
const float  f1,
const float  f2,
const float  f3,
const float  f4 
)
void tlp::GlShaderProgram::setAttributeVec4Float ( const std::string &  variableName,
const Vector< float, 4 > &  vec4f 
)
void tlp::GlShaderProgram::setAttributeVec4Int ( const std::string &  variableName,
const int  i1,
const int  i2,
const int  i3,
const int  i4 
)
void tlp::GlShaderProgram::setAttributeVec4Int ( const std::string &  variableName,
const Vector< int, 4 > &  vec4i 
)
void tlp::GlShaderProgram::setUniformBool ( const std::string &  variableName,
const bool  b 
)
void tlp::GlShaderProgram::setUniformBoolArray ( const std::string &  variableName,
const unsigned int  bCount,
const bool *  b 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformBoolArray ( const std::string &  variableName,
const Array< bool, SIZE > &  vecb 
) [inline]
void tlp::GlShaderProgram::setUniformColor ( const std::string &  variableName,
const Color &  color 
)
void tlp::GlShaderProgram::setUniformFloat ( const std::string &  variateName,
const float  f 
)
void tlp::GlShaderProgram::setUniformFloatArray ( const std::string &  variableName,
const unsigned int  fCount,
const float *  f 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformFloatArray ( const std::string &  variableName,
const Vector< float, SIZE > &  vecf 
) [inline]
void tlp::GlShaderProgram::setUniformInt ( const std::string &  variableName,
const int  f 
)
void tlp::GlShaderProgram::setUniformIntArray ( const std::string &  variableName,
const unsigned int  iCount,
const int *  i 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformIntArray ( const std::string &  variableName,
const Vector< int, SIZE > &  veci 
) [inline]
void tlp::GlShaderProgram::setUniformMat2Float ( const std::string &  variableName,
const float *  f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat2Float ( const std::string &  variableName,
const Matrix< float, 2 > &  mat2f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat2FloatArray ( const std::string &  variableName,
const unsigned int  mat2fCount,
const float *  f,
const bool  transpose = false 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformMat2FloatArray ( const std::string &  variableName,
const Vector< Matrix< float, 2 >, SIZE > &  vecmat2f,
const bool  transpose = false 
) [inline]
void tlp::GlShaderProgram::setUniformMat3Float ( const std::string &  variableName,
const float *  f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat3Float ( const std::string &  variableName,
const Matrix< float, 3 > &  mat3f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat3FloatArray ( const std::string &  variableName,
const unsigned int  mat3fCount,
const float *  f,
const bool  transpose = false 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformMat3FloatArray ( const std::string &  variableName,
const Vector< Matrix< float, 3 >, SIZE > &  vecmat3f,
const bool  transpose = false 
) [inline]
void tlp::GlShaderProgram::setUniformMat4Float ( const std::string &  variableName,
const float *  f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat4Float ( const std::string &  variableName,
const Matrix< float, 4 > &  mat4f,
const bool  transpose = false 
)
void tlp::GlShaderProgram::setUniformMat4FloatArray ( const std::string &  variableName,
const unsigned int  mat4fCount,
const float *  f,
const bool  transpose = false 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformMat4FloatArray ( const std::string &  variableName,
const Vector< Matrix< float, 4 >, SIZE > &  vecmat4f,
const bool  transpose = false 
) [inline]
void tlp::GlShaderProgram::setUniformTextureSampler ( const std::string &  samplerVariateName,
const int  samplerId 
)
void tlp::GlShaderProgram::setUniformVec2Bool ( const std::string &  variableName,
const bool  b1,
const bool  b2 
)
void tlp::GlShaderProgram::setUniformVec2Bool ( const std::string &  variableName,
const Array< bool, 2 > &  vec2b 
)
void tlp::GlShaderProgram::setUniformVec2BoolArray ( const std::string &  variableName,
const unsigned int  vec2bCount,
const bool *  b 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec2BoolArray ( const std::string &  variableName,
const Array< Array< bool, 2 >, SIZE > &  vecvec2b 
) [inline]
void tlp::GlShaderProgram::setUniformVec2Float ( const std::string &  variableName,
const float  f1,
const float  f2 
)
void tlp::GlShaderProgram::setUniformVec2Float ( const std::string &  variableName,
const Vector< float, 2 > &  vec2f 
)
void tlp::GlShaderProgram::setUniformVec2FloatArray ( const std::string &  variableName,
const unsigned int  vec2fCount,
const float *  f 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec2FloatArray ( const std::string &  variableName,
const Array< Vector< float, 2 >, SIZE > &  vecvec2f 
) [inline]
void tlp::GlShaderProgram::setUniformVec2Int ( const std::string &  variableName,
const int  i1,
const int  i2 
)
void tlp::GlShaderProgram::setUniformVec2Int ( const std::string &  variableName,
const Vector< int, 2 > &  vec2i 
)
void tlp::GlShaderProgram::setUniformVec2IntArray ( const std::string &  variableName,
const unsigned int  vec2iCount,
const int *  i 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec2IntArray ( const std::string &  variableName,
const Array< Vector< int, 2 >, SIZE > &  vecvec2i 
) [inline]
void tlp::GlShaderProgram::setUniformVec3Bool ( const std::string &  variableName,
const bool  b1,
const bool  b2,
const bool  b3 
)
void tlp::GlShaderProgram::setUniformVec3Bool ( const std::string &  variableName,
const Array< bool, 3 > &  vec3b 
)
void tlp::GlShaderProgram::setUniformVec3BoolArray ( const std::string &  variableName,
const unsigned int  vec3bCount,
const bool *  b 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec3BoolArray ( const std::string &  variableName,
const Array< Array< bool, 3 >, SIZE > &  vecvec3b 
) [inline]
void tlp::GlShaderProgram::setUniformVec3Float ( const std::string &  variableName,
const float  f1,
const float  f2,
const float  f3 
)
void tlp::GlShaderProgram::setUniformVec3Float ( const std::string &  variableName,
const Vector< float, 3 > &  vec3f 
)
void tlp::GlShaderProgram::setUniformVec3FloatArray ( const std::string &  variableName,
const unsigned int  vec3fCount,
const float *  f 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec3FloatArray ( const std::string &  variableName,
const Array< Vector< float, 3 >, SIZE > &  vecvec3f 
) [inline]
void tlp::GlShaderProgram::setUniformVec3Int ( const std::string &  variableName,
const int  i1,
const int  i2,
const int  i3 
)
void tlp::GlShaderProgram::setUniformVec3Int ( const std::string &  variableName,
const Vector< int, 3 > &  vec3i 
)
void tlp::GlShaderProgram::setUniformVec3IntArray ( const std::string &  variableName,
const unsigned int  vec3iCount,
const int *  i 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec3IntArray ( const std::string &  variableName,
const Array< Vector< int, 3 >, SIZE > &  vecvec3i 
) [inline]
void tlp::GlShaderProgram::setUniformVec4Bool ( const std::string &  variableName,
const bool  i1,
const bool  i2,
const bool  i3,
const bool  i4 
)
void tlp::GlShaderProgram::setUniformVec4Bool ( const std::string &  variableName,
const Array< bool, 4 > &  vec4b 
)
void tlp::GlShaderProgram::setUniformVec4BoolArray ( const std::string &  variableName,
const unsigned int  vec4bCount,
const bool *  b 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec4BoolArray ( const std::string &  variableName,
const Array< Array< bool, 4 >, SIZE > &  vecvec4b 
) [inline]
void tlp::GlShaderProgram::setUniformVec4Float ( const std::string &  variableName,
const float  f1,
const float  f2,
const float  f3,
const float  f4 
)
void tlp::GlShaderProgram::setUniformVec4Float ( const std::string &  variableName,
const Vector< float, 4 > &  vec4f 
)
void tlp::GlShaderProgram::setUniformVec4FloatArray ( const std::string &  variableName,
const unsigned int  vec4fCount,
const float *  f 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec4FloatArray ( const std::string &  variableName,
const Array< Vector< float, 4 >, SIZE > &  vecvec4f 
) [inline]
void tlp::GlShaderProgram::setUniformVec4Int ( const std::string &  variableName,
const int  i1,
const int  i2,
const int  i3,
const int  i4 
)
void tlp::GlShaderProgram::setUniformVec4Int ( const std::string &  variableName,
const Vector< int, 4 > &  vec4i 
)
void tlp::GlShaderProgram::setUniformVec4IntArray ( const std::string &  variableName,
const unsigned int  vec4iCount,
const int *  i 
)
template<unsigned int SIZE>
void tlp::GlShaderProgram::setUniformVec4IntArray ( const std::string &  variableName,
const Array< Vector< int, 4 >, SIZE > &  vecvec4i 
) [inline]
static bool tlp::GlShaderProgram::shaderProgramsSupported (  )  [static]

A static function which returns true if vertex and fragment shaders are supported by the host graphic card



Tulip Software by LaBRI Visualization Team    2001 - 2011