# opentl::cvprocess::GlShaderMgr Class Reference

Class for managing GPU shader code (GLSL). Uses singleton pattern to avoid duplicate allocation of program and shader code objectModels. More...

List of all members.

## Public Member Functions
| GlShaderMgr ()
| Constructor.
bool | loadAndAttachShaderFromFile (const GLuint &progId, const GLenum shaderType, const char *shaderFileName, GLuint &dstShaderId)
| Load GLSL shader code from textfile, compile and attach it to program object. Uses Singleton pattern.
bool | loadAndAttachShaderFromString (const GLuint &progId, const GLenum shaderType, const std::string &shaderSource, GLuint &dstShaderId)
| Load GLSL shader code from string, compile and attach it to program object. Uses Singleton pattern.
bool | registerProgObj (const std::string &str, GLuint &progId)
| Register a GLSL program object. Uses Time elapsed: 0.073425 --> 13.6193 fps Singleton pattern.
virtual | ~GlShaderMgr ()
## Static Public Member Functions
static int | checkSupportForProgrammableShaders ()
| Check if programmable shaders are supported by OpenGL version.
static int | convertShaderFileToString (const char *srcFileName, const char *dstFileName, bool appendToFile=true)
| Convert the shader code of a text files to a string for inclusion in a header file The resulting string has the name of the text file with "." replaced by "_".
static bool | linkShadersToProgram (const GLuint program)
| Link Shaders to program object.
static void | printProgramInfoLog (const GLuint program)
| Print program object log information.
static void | printShaderInfoLog (const GLuint shader)
| Print Shader object log information.
static unsigned char * | readShaderFile (const char *fileName)
| Read shader code from file.
static void | resetProgObj ()
static void | useProgObj (const GLuint progId)

## Detailed Description

Class for managing GPU shader code (GLSL). Uses singleton pattern to avoid duplicate allocation of program and shader code objectModels.

Author:
  Erwin Roth <erwin.roth@weihenstephan.org> TODO: should support also other shader languages: CG, ...

## Constructor & Destructor Documentation

opentl::cvprocess::GlShaderMgr::GlShaderMgr | ( |  | ) |

Constructor.

virtual opentl::cvprocess::GlShaderMgr::~GlShaderMgr | ( |  | ) | `[virtual]`

## Member Function Documentation

static int opentl::cvprocess::GlShaderMgr::checkSupportForProgrammableShaders | ( |  | ) | `[static]`

Check if programmable shaders are supported by OpenGL version.

Returns:
  1 = OK, -1 = not OK.

static int opentl::cvprocess::GlShaderMgr::convertShaderFileToString | ( | const char * | srcFileName,
|  | const char * | dstFileName,
|  | bool | appendToFile = `true` |
| ) |  |  | `[static]`

Convert the shader code of a text files to a string for inclusion in a header file The resulting string has the name of the text file with "." replaced by "_".

Parameters:

  | srcFileName | Name of source text file.
  | dstFileName | Name of header file.
  | appendToFile | Flag if destination file should be overwritten.

static bool opentl::cvprocess::GlShaderMgr::linkShadersToProgram | ( | const GLuint | program | ) | `[static]`

Link Shaders to program object.

bool opentl::cvprocess::GlShaderMgr::loadAndAttachShaderFromFile | ( | const GLuint & | progId,
|  | const GLenum | shaderType,
|  | const char * | shaderFileName,
|  | GLuint & | dstShaderId |
| ) |  |  |

Load GLSL shader code from textfile, compile and attach it to program object. Uses Singleton pattern.

Parameters:

  | progId | Attach shader code to program object.
  | shaderType | GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
  | shaderFileName | Path and file name of (GLSL) shader code
  | dstShaderId | Resulting shader Id.

Returns:
  True, if operation was successful.

bool opentl::cvprocess::GlShaderMgr::loadAndAttachShaderFromString | ( | const GLuint & | progId,
|  | const GLenum | shaderType,
|  | const std::string & | shaderSource,
|  | GLuint & | dstShaderId |
| ) |  |  |

Load GLSL shader code from string, compile and attach it to program object. Uses Singleton pattern.

Parameters:

  | progId | Attach shader code to program object.
  | shaderType | GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
  | shaderSource | String containing (GLSL) shader code (for generation see, convertShaderFileToString())
  | dstShaderId | Resulting shader Id.

Returns:
  True, if operation was successful.

static void opentl::cvprocess::GlShaderMgr::printProgramInfoLog | ( | const GLuint | program | ) | `[static]`

Print program object log information.

static void opentl::cvprocess::GlShaderMgr::printShaderInfoLog | ( | const GLuint | shader | ) | `[static]`

Print Shader object log information.

static unsigned char* opentl::cvprocess::GlShaderMgr::readShaderFile | ( | const char * | fileName | ) | `[static]`

Read shader code from file.

Parameters:

  | fileName | Path and name of shader code file to read.

Returns:
  Shader source code as array. TODO: should be private

bool opentl::cvprocess::GlShaderMgr::registerProgObj | ( | const std::string & | str,
|  | GLuint & | progId |
| ) |  |  |

Register a GLSL program object. Uses Time elapsed: 0.073425 --> 13.6193 fps Singleton pattern.

Parameters:

  | str | Arbitrary name of program object.
  | progId | Program Id of new registered or already registered program.

Returns:
  true = a new program id was created, false program already existing.

static void opentl::cvprocess::GlShaderMgr::resetProgObj | ( |  | ) | `[static]`

static void opentl::cvprocess::GlShaderMgr::useProgObj | ( | const GLuint | progId | ) | `[static]`