# Visualization Library A lightweight C++ OpenGL middleware for 2D/3D graphics | [Home] [Tutorials] [All Classes] [Grouped Classes]

# vl::GLSLProgram Class Reference

Wraps a GLSL program to which you can bind vertex, fragment and geometry shaders. More...

`#include <GLSL.hpp>`

Inheritance diagram for vl::GLSLProgram:

List of all members.

## Public Member Functions
| GLSLProgram ()
| Constructor.
| ~GLSLProgram ()
| Destructor. Calls deleteProgram().
virtual const char * | className ()
| Returns the name of the class.
virtual ERenderState | type () const
void | createProgram ()
| Calls glCreateProgram() in order to acquire a GLSL program handle, see also http://www.opengl.org/sdk/docs/man/xhtml/glCreateProgram.xml for more information.
void | deleteProgram ()
| Deletes the GLSL program calling glDeleteProgram(handle()), see also http://www.opengl.org/sdk/docs/man/xhtml/glDeleteProgram.xml for more information.
unsigned int | handle () const
| The handle of the GLSL program as returned by glCreateProgram().
bool | useProgram () const
| Equivalent to glUseProgram(handle()), see also http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml for more information.
void | apply (const Camera *) const
| Calls useProgram().
virtual void | initResources ()
| Calls linkProgram() and applyes this program's uniforms.
bool | linkProgram (bool force_relink=false)
| Links the GLSLProgram calling glLinkProgram(handle()) only if the program needs to be linked.
bool | linkStatus () const
bool | linked () const
| Returns true if the program has been succesfully linked.
void | scheduleRelinking ()
| Schedules a relink of the GLSL program.
bool | attachShader (GLSLShader *shader)
| Attaches the GLSLShader to this GLSLProgram.
bool | detachShader (GLSLShader *shader)
| Removes a GLSLShader from the GLSLShader and schedules a relink of the program, see also http://www.opengl.org/sdk/docs/man/xhtml/glDetachShader.xml for more information.
String | infoLog () const
| Returns the info log of this GLSL program using the OpenGL function glGetProgramInfoLog(), see also http://www.opengl.org/sdk/docs/man/xhtml/glGetProgramInfoLog.xml for more information.
bool | validateProgram () const
| Returns true if the validation of this GLSL program is succesful, see also http://www.opengl.org/sdk/docs/man/xhtml/glValidateProgram.xml for more information.
void | bindAttribLocation (unsigned int index, const std::string &name)
| Equivalent to glBindAttribLocation(handle(), index, name.c_str()).
int | getAttribLocation (const char *name) const
| Eqivalento to glGetAttribLocation(handle(), name).
int | shaderCount () const
| Returns the number of GLSLShader objects bound to this GLSLProgram.
const GLSLShader * | shader (int i) const
| Returns the i-th GLSLShader objects bound to this GLSLProgram.
GLSLShader * | shader (int i)
| Returns the i-th GLSLShader objects bound to this GLSLProgram.
void | detachAllShaders ()
| Removes all the previously linked shaders and schedules a relinking.
void | bindFragDataLocation (int color_number, const std::string &name)
void | unbindFragDataLocation (const std::string &name)
int | fragDataLocationBinding (const std::string &name) const
void | setGeometryVerticesOut (int vertex_count)
| See GL_ARB_geometry_shader4's GL_GEOMETRY_VERTICES_OUT_EXT.
int | geometryVerticesOut () const
| See GL_ARB_geometry_shader4's GL_GEOMETRY_VERTICES_OUT_EXT.
void | setGeometryInputType (EGeometryInputType type)
| See GL_ARB_geometry_shader4's GL_GEOMETRY_INPUT_TYPE_EXT.
EGeometryInputType | geometryInputType () const
| See GL_ARB_geometry_shader4's GL_GEOMETRY_INPUT_TYPE_EXT.
void | setGeometryOutputType (EGeometryOutputType type)
| See GL_ARB_geometry_shader4's GL_GEOMETRY_OUTPUT_TYPE_EXT.
EGeometryOutputType | geometryOutputType () const
| See GL_ARB_geometry_shader4's GL_GEOMETRY_OUTPUT_TYPE_EXT.
void | applyUniformSet (const UniformSet *uniforms) const
| Applies a set of uniforms to the currently bound GLSL program.
int | getUniformLocation (const std::string &name) const
| Returns the binding index of the uniform with the given name.
void | getUniformfv (int location, float *params) const
| Equivalent to glGetUniformfv(handle(), location, params).
void | getUniformfv (const std::string &name, float *params) const
| Equivalent to getUniformfv(getUniformLocation(name), params).
void | getUniformiv (int location, int *params) const
| Equivalent to glGetUniformiv(handle(), location, params).
void | getUniformiv (const std::string &name, int *params) const
| Equivalent to getUniformiv(getUniformLocation(name).
void | getUniform (int location, fvec2 &vec) const
void | getUniform (int location, fvec3 &vec) const
void | getUniform (int location, fvec4 &vec) const
void | getUniform (int location, fmat2 &mat) const
void | getUniform (int location, fmat3 &mat) const
void | getUniform (int location, fmat4 &mat) const
void | getUniform (int location, ivec2 &vec) const
void | getUniform (int location, ivec3 &vec) const
void | getUniform (int location, ivec4 &vec) const
void | getUniform (const std::string &name, fvec2 &vec) const
void | getUniform (const std::string &name, fvec3 &vec) const
void | getUniform (const std::string &name, fvec4 &vec) const
void | getUniform (const std::string &name, fmat2 &mat) const
void | getUniform (const std::string &name, fmat3 &mat) const
void | getUniform (const std::string &name, fmat4 &mat) const
void | getUniform (const std::string &name, ivec2 &vec) const
void | getUniform (const std::string &name, ivec3 &vec) const
void | getUniform (const std::string &name, ivec4 &vec) const
UniformSet * | uniformSet ()
| Returns a GLSLProgram's 'static' UniformSet.
const UniformSet * | uniformSet () const
| Returns a GLSLProgram's 'static' UniformSet.
void | setUniformSet (UniformSet *uniforms)
| Sets a GLSLProgram's 'static' UniformSet.
void | setUniform (Uniform *uniform)
| Sets a GLSLProgram's 'static' Uniform.
Uniform * | getUniform (const std::string &name)
| Returns the specified Uniform. Returns NULL if there isn't such a Uniform.
Uniform * | gocUniform (const std::string &name)
| Gets or creates the specified Uniform.
## Static Public Member Functions
static int | maxVertexAttributes ()
| Equivalent to glGetIntegerv( GL_MAX_VERTEX_ATTRIBS, &max ).
## Protected Attributes
std::vector< ref< GLSLShader > > | mShaders
std::map< std::string, int > | mFragDataLocation
std::map< std::string, int > | mUniformLocation
ref< UniformSet > | mUniformSet
unsigned int | mHandle
bool | mScheduleLink
int | mGeometryVerticesOut
EGeometryInputType | mGeometryInputType
EGeometryOutputType | mGeometryOutputType
## Friends
class | Renderer

## Detailed Description

Wraps a GLSL program to which you can bind vertex, fragment and geometry shaders.

Uniforms
  You have 3 ways to set the value of a uniform:
  1. call useProgram() to activate the GLSLProgram and directly call glUniform* (see also getUniformLocation()).
  2. add a Uniform to the Actor's UniformSet, see Actor::uniformSet()
  3. add a Uniform to the Actor's Shader UniformSet, see Shader::uniformSet()

Remarks:
  The Uniforms defined in the Actor and the ones defined in the Shader must not overlap, that is, an Actor must not define Uniforms present in the Shader and vice versa.

See also:
  - GLSLVertexShader
  - GLSLFragmentShader
  - GLSLGeometryShader
  - Shader
  - Effect
  - Actor::renderingCallbacks()

## Constructor & Destructor Documentation

GLSLProgram::GLSLProgram | ( |  | ) |

Constructor.

GLSLProgram::~GLSLProgram | ( |  | ) |

Destructor. Calls deleteProgram().

## Member Function Documentation

virtual const char* vl::GLSLProgram::className | ( |  | ) | `[inline, virtual]`

Returns the name of the class.

Reimplemented from vl::RenderState.

virtual ERenderState vl::GLSLProgram::type | ( |  | ) | const`[inline, virtual]`

Reimplemented from vl::RenderState.

void GLSLProgram::createProgram | ( |  | ) |

Calls glCreateProgram() in order to acquire a GLSL program handle, see also http://www.opengl.org/sdk/docs/man/xhtml/glCreateProgram.xml for more information.

Note:
  The program is created only if handle() == 0

void GLSLProgram::deleteProgram | ( |  | ) |

Deletes the GLSL program calling glDeleteProgram(handle()), see also http://www.opengl.org/sdk/docs/man/xhtml/glDeleteProgram.xml for more information.

After this function handle() will return 0.

unsigned int vl::GLSLProgram::handle | ( |  | ) | const`[inline]`

The handle of the GLSL program as returned by glCreateProgram().

See also:
  http://www.opengl.org/sdk/docs/man/xhtml/glCreateProgram.xml
  - createProgram()
  - deleteProgram()

bool GLSLProgram::useProgram | ( |  | ) | const

Equivalent to glUseProgram(handle()), see also http://www.opengl.org/sdk/docs/man/xhtml/glUseProgram.xml for more information.

void GLSLProgram::apply | ( | const Camera * |  | ) | const`[virtual]`

Calls useProgram().

Implements vl::RenderState.

void GLSLProgram::initResources | ( |  | ) | `[virtual]`

Calls linkProgram() and applyes this program's uniforms.

See also:
  setUniform() setUniformSet() uniformSet()

Reimplemented from vl::RenderState.

bool GLSLProgram::linkProgram | ( | bool | force_relink = `false` | ) |

Links the GLSLProgram calling glLinkProgram(handle()) only if the program needs to be linked.

See also:
  - http://www.opengl.org/sdk/docs/man/xhtml/glLinkProgram.xml
  - scheduleRelinking()
  - linked()

bool GLSLProgram::linkStatus | ( |  | ) | const

bool vl::GLSLProgram::linked | ( |  | ) | const`[inline]`

Returns true if the program has been succesfully linked.

void GLSLProgram::scheduleRelinking | ( |  | ) |

Schedules a relink of the GLSL program.

bool GLSLProgram::attachShader | ( | GLSLShader * | shader | ) |

Attaches the GLSLShader to this GLSLProgram.

Note:
  Attaching a shader triggers the compilation of the shader (if not already compiled) and relinking of the program.

bool GLSLProgram::detachShader | ( | GLSLShader * | shader | ) |

Removes a GLSLShader from the GLSLShader and schedules a relink of the program, see also http://www.opengl.org/sdk/docs/man/xhtml/glDetachShader.xml for more information.

String GLSLProgram::infoLog | ( |  | ) | const

Returns the info log of this GLSL program using the OpenGL function glGetProgramInfoLog(), see also http://www.opengl.org/sdk/docs/man/xhtml/glGetProgramInfoLog.xml for more information.

bool GLSLProgram::validateProgram | ( |  | ) | const

Returns true if the validation of this GLSL program is succesful, see also http://www.opengl.org/sdk/docs/man/xhtml/glValidateProgram.xml for more information.

void GLSLProgram::bindAttribLocation | ( | unsigned int | index,
|  | const std::string & | name |
| ) |  |  |

Equivalent to glBindAttribLocation(handle(), index, name.c_str()).

int vl::GLSLProgram::getAttribLocation | ( | const char * | name | ) | const`[inline]`

Eqivalento to glGetAttribLocation(handle(), name).

Note:
  The program must be linked before calling this function.

int GLSLProgram::maxVertexAttributes | ( |  | ) | `[static]`

Equivalent to glGetIntegerv( GL_MAX_VERTEX_ATTRIBS, &max ).

int vl::GLSLProgram::shaderCount | ( |  | ) | const`[inline]`

Returns the number of GLSLShader objects bound to this GLSLProgram.

const GLSLShader* vl::GLSLProgram::shader | ( | int | i | ) | const`[inline]`

Returns the i-th GLSLShader objects bound to this GLSLProgram.

GLSLShader* vl::GLSLProgram::shader | ( | int | i | ) | `[inline]`

Returns the i-th GLSLShader objects bound to this GLSLProgram.

void GLSLProgram::detachAllShaders | ( |  | ) |

Removes all the previously linked shaders and schedules a relinking.

void GLSLProgram::bindFragDataLocation | ( | int | color_number,
|  | const std::string & | name |
| ) |  |  |

void GLSLProgram::unbindFragDataLocation | ( | const std::string & | name | ) |

int GLSLProgram::fragDataLocationBinding | ( | const std::string & | name | ) | const

void vl::GLSLProgram::setGeometryVerticesOut | ( | int | vertex_count | ) | `[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_VERTICES_OUT_EXT.

int vl::GLSLProgram::geometryVerticesOut | ( |  | ) | const`[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_VERTICES_OUT_EXT.

void vl::GLSLProgram::setGeometryInputType | ( | EGeometryInputType | type | ) | `[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_INPUT_TYPE_EXT.

EGeometryInputType vl::GLSLProgram::geometryInputType | ( |  | ) | const`[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_INPUT_TYPE_EXT.

void vl::GLSLProgram::setGeometryOutputType | ( | EGeometryOutputType | type | ) | `[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_OUTPUT_TYPE_EXT.

EGeometryOutputType vl::GLSLProgram::geometryOutputType | ( |  | ) | const`[inline]`

See GL_ARB_geometry_shader4's GL_GEOMETRY_OUTPUT_TYPE_EXT.

void GLSLProgram::applyUniformSet | ( | const UniformSet * | uniforms | ) | const

Applies a set of uniforms to the currently bound GLSL program.

This function expects the GLSLProgram to be already bound, see useProgram().

int vl::GLSLProgram::getUniformLocation | ( | const std::string & | name | ) | const`[inline]`

Returns the binding index of the uniform with the given name.

void vl::GLSLProgram::getUniformfv | ( | int | location,
|  | float * | params |
| ) |  |  | const`[inline]`

Equivalent to glGetUniformfv(handle(), location, params).

void vl::GLSLProgram::getUniformfv | ( | const std::string & | name,
|  | float * | params |
| ) |  |  | const`[inline]`

Equivalent to getUniformfv(getUniformLocation(name), params).

void vl::GLSLProgram::getUniformiv | ( | int | location,
|  | int * | params |
| ) |  |  | const`[inline]`

Equivalent to glGetUniformiv(handle(), location, params).

void vl::GLSLProgram::getUniformiv | ( | const std::string & | name,
|  | int * | params |
| ) |  |  | const`[inline]`

Equivalent to getUniformiv(getUniformLocation(name).

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fvec2 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fvec3 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fvec4 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fmat2 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fmat3 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | fmat4 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | ivec2 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | ivec3 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | int | location,
|  | ivec4 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fvec2 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fvec3 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fvec4 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fmat2 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fmat3 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | fmat4 & | mat |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | ivec2 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | ivec3 & | vec |
| ) |  |  | const`[inline]`

void vl::GLSLProgram::getUniform | ( | const std::string & | name,
|  | ivec4 & | vec |
| ) |  |  | const`[inline]`

UniformSet* vl::GLSLProgram::uniformSet | ( |  | ) | `[inline]`

Returns a GLSLProgram's 'static' UniformSet.

See also:
  See setUniform() for more information about 'static' Uniforms and Uniform management.

const UniformSet* vl::GLSLProgram::uniformSet | ( |  | ) | const`[inline]`

Returns a GLSLProgram's 'static' UniformSet.

See also:
  See setUniform() for more information about 'static' Uniforms and Uniform management.

void vl::GLSLProgram::setUniformSet | ( | UniformSet * | uniforms | ) | `[inline]`

Sets a GLSLProgram's 'static' UniformSet.

See also:
  See setUniform() for more information about 'static' Uniforms and Uniform management.

void vl::GLSLProgram::setUniform | ( | Uniform * | uniform | ) | `[inline]`

Sets a GLSLProgram's 'static' Uniform.

This is an utility function, it is equivalent to:

     if (!uniformSet()) setUniformSet(new UniformSet); uniformSet()->setUniform(uniform);

Uniform* vl::GLSLProgram::getUniform | ( | const std::string & | name | ) | `[inline]`

Returns the specified Uniform. Returns NULL if there isn't such a Uniform.

Uniform* vl::GLSLProgram::gocUniform | ( | const std::string & | name | ) | `[inline]`

Gets or creates the specified Uniform.

## Friends And Related Function Documentation

friend class Renderer`[friend]`

## Member Data Documentation

std::vector< ref<GLSLShader> > vl::GLSLProgram::mShaders`[protected]`

std::map<std::string, int> vl::GLSLProgram::mFragDataLocation`[protected]`

std::map<std::string, int> vl::GLSLProgram::mUniformLocation`[protected]`

ref<UniformSet> vl::GLSLProgram::mUniformSet`[protected]`

unsigned int vl::GLSLProgram::mHandle`[protected]`

bool vl::GLSLProgram::mScheduleLink`[protected]`

int vl::GLSLProgram::mGeometryVerticesOut`[protected]`

EGeometryInputType vl::GLSLProgram::mGeometryInputType`[protected]`

EGeometryOutputType vl::GLSLProgram::mGeometryOutputType`[protected]`

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

- E:/VisualizationLibrary/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vl/GLSL.hpp
- E:/VisualizationLibrary/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vl/GLSL.cpp

Visualization Library v2009.08 Reference Documentation
Copyright 2005-2009 Michele Bosi. All rights reserved.
Updated on Sun Nov 29 11:11:46 2009.
Permission is granted to use this page to write and publish articles regarding Visualization Library.