GLS
1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
|
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... | |
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:
GLuint name | ( | ) | const |
Retrieve the 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.
shaders | Variable collection of shaders to link to this program |
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.
void use | ( | ) |
Use this program.
Set the program as the currently used one. This replaces any previously current program.
|
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.
attribute_name | Name of the attribute |
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.
attribute_name | Name of the attribute |
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.
attribute_name | Name of the attribute |
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.
uniform_name | Name of the uniform |
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.
uniform_name | Name of the uniform |
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.
uniform_name | Name of the uniform |
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.
uniform_block_name | Name of the uniform block |
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.
uniform_block_name | Name of the uniform block |
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.
uniform_name | Name of the uniform to set |
v0 | First 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.
uniform_name | Name of the uniform to set |
v0 | First 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.
uniform_name | Name of the uniform to set |
v0 | First 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third component |
v3 | Fourth 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third component |
v3 | Fourth 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.
uniform_name | Name of the uniform to set |
v0 | First component |
v1 | Second component |
v2 | Third component |
v3 | Fourth 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array 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.
uniform_name | Name of the uniform to set |
count | Number of array elements |
transpose | GL_TRUE to transpose before loading, GL_FALSE not to |
value | Array of values |