GLS  1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
program Class Reference

Class encapsulating an OpenGL program object. More...

#include <program.hpp>

Public Member Functions

GLuint name () const
 Retrieve the OpenGL name of this program. More...
 
template<typename... Shaders>
bool link (Shaders &&...shaders)
 Link a set of compiled shaders into this program. More...
 
std::string get_info_log () const
 Get the link information log. More...
 
void use ()
 Use this program. More...
 
GLint get_attribute_location (const std::string &attribute_name) const
 Get the location of an attribute. More...
 
GLenum get_attribute_type (const std::string &attribute_name) const
 Get the type of an attribute. More...
 
GLint get_attribute_size (const std::string &attribute_name) const
 Get the size of an attribute. More...
 
GLint get_uniform_location (const std::string &uniform_name) const
 Get the location of a uniform. More...
 
GLenum get_uniform_type (const std::string &uniform_name) const
 Get the type of a uniform. More...
 
GLint get_uniform_size (const std::string &uniform_name) const
 Get the size of a uniform. More...
 
GLuint get_uniform_block_index (const std::string &uniform_block_name) const
 Get the index of a uniform block. More...
 
GLint get_uniform_block_size (const std::string &uniform_block_name) const
 Get the size of a uniform block. More...
 
void uniform (const std::string &uniform_name, GLfloat v0)
 Set a 1-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLint v0)
 Set a 1-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLuint v0)
 Set a 1-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLfloat v0, GLfloat v1)
 Set a 2-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLint v0, GLint v1)
 Set a 2-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLuint v0, GLuint v1)
 Set a 2-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLfloat v0, GLfloat v1, GLfloat v2)
 Set a 3-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLint v0, GLint v1, GLint v2)
 Set a 3-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLuint v0, GLuint v1, GLuint v2)
 Set a 3-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
 Set a 4-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLint v0, GLint v1, GLint v2, GLint v3)
 Set a 4-component uniform value. More...
 
void uniform (const std::string &uniform_name, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
 Set a 4-component uniform value. More...
 
void uniform1 (const std::string &uniform_name, GLsizei count, const GLfloat *value)
 Set an array of 1-component uniform values. More...
 
void uniform1 (const std::string &uniform_name, GLsizei count, const GLint *value)
 Set an array of 1-component uniform values. More...
 
void uniform1 (const std::string &uniform_name, GLsizei count, const GLuint *value)
 Set an array of 1-component uniform values. More...
 
void uniform2 (const std::string &uniform_name, GLsizei count, const GLfloat *value)
 Set an array of 2-component uniform values. More...
 
void uniform2 (const std::string &uniform_name, GLsizei count, const GLint *value)
 Set an array of 2-component uniform values. More...
 
void uniform2 (const std::string &uniform_name, GLsizei count, const GLuint *value)
 Set an array of 2-component uniform values. More...
 
void uniform3 (const std::string &uniform_name, GLsizei count, const GLfloat *value)
 Set an array of 3-component uniform values. More...
 
void uniform3 (const std::string &uniform_name, GLsizei count, const GLint *value)
 Set an array of 3-component uniform values. More...
 
void uniform3 (const std::string &uniform_name, GLsizei count, const GLuint *value)
 Set an array of 3-component uniform values. More...
 
void uniform4 (const std::string &uniform_name, GLsizei count, const GLfloat *value)
 Set an array of 4-component uniform values. More...
 
void uniform4 (const std::string &uniform_name, GLsizei count, const GLint *value)
 Set an array of 4-component uniform values. More...
 
void uniform4 (const std::string &uniform_name, GLsizei count, const GLuint *value)
 Set an array of 4-component uniform values. More...
 
void uniform_matrix2 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 2x2 uniform matrix values. More...
 
void uniform_matrix3 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 3x3 uniform matrix values. More...
 
void uniform_matrix4 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 4x4 uniform matrix values. More...
 
void uniform_matrix2x3 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 2x3 uniform matrix values. More...
 
void uniform_matrix3x2 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 3x2 uniform matrix values. More...
 
void uniform_matrix2x4 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 2x4 uniform matrix values. More...
 
void uniform_matrix4x2 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 4x2 uniform matrix values. More...
 
void uniform_matrix3x4 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 3x4 uniform matrix values. More...
 
void uniform_matrix4x3 (const std::string &uniform_name, GLsizei count, GLboolean transpose, const GLfloat *value)
 Set an array of 4x3 uniform matrix values. More...
 

Static Public Member Functions

static void unuse ()
 No longer use a program. More...
 

Detailed Description

Class encapsulating an OpenGL program object.

A gls::program is an object that encapsulates an OpenGL program object.

Like all objects in GLS, the underlying name is generated at object construction and deleted at destruction. This can be retrieved with name().

In order to use a gls::program, you need to link successfully compiled gls::shader objects to it. If linking fails, you can check the information log for the cause. Upon successful linking, all attribute, uniform and uniform block information is queried and cached within the gls::program.

To retrieve attribute and uniform locations as well as uniform block indices, use the get_attribute_location(), get_uniform_location() and get_uniform_block_index() methods. In addition to that, you can query the size and data type of each attribute and uniform and the size of a uniform block by using the respective methods.

To set uniform values, a thin convenience wrapper is provided on top of the OpenGL interface. Where possible, overloading is used instead of explicitly naming the parameter types as part of the method name.

To use a gls::program, simply call use(). It will set the gls::program as the active one and replace any previously active program. To clear the active program, call unuse().

Example usage:

... compile your shaders ...
auto my_program = gls::program();
my_program.link( my_vertex_shader, my_fragment_shader );
... set up attributes ...
my_program.uniform( "my_uniform", 1.f, 2.f, 3.f );
my_program.use();
... draw stuff ...
my_program.unuse();

Member Function Documentation

GLuint name ( ) const

Retrieve the OpenGL name of this program.

Returns
OpenGL name of this program
bool link ( Shaders &&...  shaders)

Link a set of compiled shaders into this program.

After successfully compiling a set of gls::shader objects, call this method to link them into this program. They will be attached, linked and detached thereafter. Checking the produced information log with get_info_log() can help to solve errors that occur or warnings the driver might have produced.

After linking successfully, all attribute, uniform and block information will be extracted from the program.

Uniform blocks will automatically be bound to a unique binding point which can be queried with get_uniform_block_binding(). If there are more blocks present in a program than there are binding points, an assertion will terminate the application.

Parameters
shadersVariable collection of shaders to link to this program
Returns
true if linking was successful, false otherwise
std::string get_info_log ( ) const

Get the link information log.

After linking, whether successful or not, an information log might be available. Check this information log for warnings after successful linking, or errors after failed linking. The information log may be empty if linking was successful.

Returns
String containing the information log
void use ( )

Use this program.

Set the program as the currently used one. This replaces any previously current program.

static void unuse ( )
static

No longer use a program.

Clear the currently used program.

GLint get_attribute_location ( const std::string &  attribute_name) const

Get the location of an attribute.

After linking, you can query the program for the location of an attribute. You can use this value to set the source that the attribute should pull data from.

Parameters
attribute_nameName of the attribute
Returns
Location of the attribute, or -1 if the attribute does not exist
GLenum get_attribute_type ( const std::string &  attribute_name) const

Get the type of an attribute.

After linking, you can query the program for the type of an attribute.

Parameters
attribute_nameName of the attribute
Returns
Type of the attribute, or 0 if the attribute does not exist
GLint get_attribute_size ( const std::string &  attribute_name) const

Get the size of an attribute.

After linking, you can query the program for the size of an attribute.

Parameters
attribute_nameName of the attribute
Returns
Size of the attribute, or 0 if the attribute does not exist
GLint get_uniform_location ( const std::string &  uniform_name) const

Get the location of a uniform.

After linking, you can query the program for the location of a uniform. You can use this location to set the value that the uniform should be set to when the program is run.

Parameters
uniform_nameName of the uniform
Returns
Location of the uniform, or -1 if the uniform does not exist
GLenum get_uniform_type ( const std::string &  uniform_name) const

Get the type of a uniform.

After linking, you can query the program for the type of a uniform.

Parameters
uniform_nameName of the uniform
Returns
Type of the uniform, or 0 if the uniform does not exist
GLint get_uniform_size ( const std::string &  uniform_name) const

Get the size of a uniform.

After linking, you can query the program for the size of a uniform.

Parameters
uniform_nameName of the uniform
Returns
Size of the uniform, or 0 if the uniform does not exist
GLuint get_uniform_block_index ( const std::string &  uniform_block_name) const

Get the index of a uniform block.

After linking, you can query the program for the index of a uniform block. You can bind the index to a binding point which is then used to specify the location inside a buffer for the block to source its data from.

Parameters
uniform_block_nameName of the uniform block
Returns
Index of the uniform block, or GL_INVALID_INDEX if the block does not exist
GLint get_uniform_block_size ( const std::string &  uniform_block_name) const

Get the size of a uniform block.

Use this to determine the size requirements of a uniform block with binding it to its source buffer.

Parameters
uniform_block_nameName of the uniform block
Returns
Size of the uniform block in bytes, or 0 if the block does not exist
void uniform ( const std::string &  uniform_name,
GLfloat  v0 
)

Set a 1-component uniform value.

Set a 1-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
void uniform ( const std::string &  uniform_name,
GLint  v0 
)

Set a 1-component uniform value.

Set a 1-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
void uniform ( const std::string &  uniform_name,
GLuint  v0 
)

Set a 1-component uniform value.

Set a 1-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
void uniform ( const std::string &  uniform_name,
GLfloat  v0,
GLfloat  v1 
)

Set a 2-component uniform value.

Set a 2-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
void uniform ( const std::string &  uniform_name,
GLint  v0,
GLint  v1 
)

Set a 2-component uniform value.

Set a 2-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
void uniform ( const std::string &  uniform_name,
GLuint  v0,
GLuint  v1 
)

Set a 2-component uniform value.

Set a 2-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
void uniform ( const std::string &  uniform_name,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2 
)

Set a 3-component uniform value.

Set a 3-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
void uniform ( const std::string &  uniform_name,
GLint  v0,
GLint  v1,
GLint  v2 
)

Set a 3-component uniform value.

Set a 3-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
void uniform ( const std::string &  uniform_name,
GLuint  v0,
GLuint  v1,
GLuint  v2 
)

Set a 3-component uniform value.

Set a 3-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
void uniform ( const std::string &  uniform_name,
GLfloat  v0,
GLfloat  v1,
GLfloat  v2,
GLfloat  v3 
)

Set a 4-component uniform value.

Set a 4-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
v3Fourth component
void uniform ( const std::string &  uniform_name,
GLint  v0,
GLint  v1,
GLint  v2,
GLint  v3 
)

Set a 4-component uniform value.

Set a 4-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
v3Fourth component
void uniform ( const std::string &  uniform_name,
GLuint  v0,
GLuint  v1,
GLuint  v2,
GLuint  v3 
)

Set a 4-component uniform value.

Set a 4-component uniform with the given name to the given value.

Parameters
uniform_nameName of the uniform to set
v0First component
v1Second component
v2Third component
v3Fourth component
void uniform1 ( const std::string &  uniform_name,
GLsizei  count,
const GLfloat *  value 
)

Set an array of 1-component uniform values.

Set an array of 1-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform1 ( const std::string &  uniform_name,
GLsizei  count,
const GLint *  value 
)

Set an array of 1-component uniform values.

Set an array of 1-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform1 ( const std::string &  uniform_name,
GLsizei  count,
const GLuint *  value 
)

Set an array of 1-component uniform values.

Set an array of 1-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform2 ( const std::string &  uniform_name,
GLsizei  count,
const GLfloat *  value 
)

Set an array of 2-component uniform values.

Set an array of 2-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform2 ( const std::string &  uniform_name,
GLsizei  count,
const GLint *  value 
)

Set an array of 2-component uniform values.

Set an array of 2-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform2 ( const std::string &  uniform_name,
GLsizei  count,
const GLuint *  value 
)

Set an array of 2-component uniform values.

Set an array of 2-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform3 ( const std::string &  uniform_name,
GLsizei  count,
const GLfloat *  value 
)

Set an array of 3-component uniform values.

Set an array of 3-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform3 ( const std::string &  uniform_name,
GLsizei  count,
const GLint *  value 
)

Set an array of 3-component uniform values.

Set an array of 3-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform3 ( const std::string &  uniform_name,
GLsizei  count,
const GLuint *  value 
)

Set an array of 3-component uniform values.

Set an array of 3-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform4 ( const std::string &  uniform_name,
GLsizei  count,
const GLfloat *  value 
)

Set an array of 4-component uniform values.

Set an array of 4-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform4 ( const std::string &  uniform_name,
GLsizei  count,
const GLint *  value 
)

Set an array of 4-component uniform values.

Set an array of 4-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform4 ( const std::string &  uniform_name,
GLsizei  count,
const GLuint *  value 
)

Set an array of 4-component uniform values.

Set an array of 4-component uniforms with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
valueArray of values
void uniform_matrix2 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 2x2 uniform matrix values.

Set an array of 2x2 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix3 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 3x3 uniform matrix values.

Set an array of 3x3 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix4 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 4x4 uniform matrix values.

Set an array of 4x4 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix2x3 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 2x3 uniform matrix values.

Set an array of 2x3 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix3x2 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 3x2 uniform matrix values.

Set an array of 3x2 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix2x4 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 2x4 uniform matrix values.

Set an array of 2x4 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix4x2 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 4x2 uniform matrix values.

Set an array of 4x2 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix3x4 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 3x4 uniform matrix values.

Set an array of 3x4 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values
void uniform_matrix4x3 ( const std::string &  uniform_name,
GLsizei  count,
GLboolean  transpose,
const GLfloat *  value 
)

Set an array of 4x3 uniform matrix values.

Set an array of 4x3 uniform matrices with the given name to the given values.

Parameters
uniform_nameName of the uniform to set
countNumber of array elements
transposeGL_TRUE to transpose before loading, GL_FALSE not to
valueArray of values