CGPdocs

opengl_shader_structure

load() compiles a vertex and a fragment file into a GPU program and keeps its id; drawables hold copies sharing the same id, and loading a new shader into one of them leaves the others unchanged.
load() compiles a vertex and a fragment file into a GPU program and keeps its id; drawables hold copies sharing the same id, and loading a new shader into one of them leaves the others unchanged. Tap to enlarge.

Fields and methods

Members of the struct opengl_shader_structure. Most of what you do with a CGP type goes through the free functions listed below.

Fields

GLuint id = 0OpenGL id of the shader program, 0 when no shader is loaded.

Methods

Compiles and links the vertex and fragment shader files into a new program and stores its id, stopping the program on a missing file or a compilation error and without deleting the previous program. src
Compiles and links a program from the vertex and fragment source texts, sets id to 0 and load_shader_ok to false on failure instead of stopping, and does not delete the previous program. src
Deletes the program, removes its entries from the uniform-location cache and sets id to 0, doing nothing when id is already 0. src
Returns the location of a uniform in the program (-1 if absent), calling glGetUniformLocation only the first time and reading a cache shared by all shaders afterwards. src
Empties the uniform-location cache for every shader program, not only this one. src
Returns a text listing every cached (program id, uniform name, location) entry, for debugging. src

Functions taking a opengl_shader_structure

Other 12

opengl_uniform

12 overloads
void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, int value, bool expected = true)
source

Send an int uniform to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, GLuint value, bool expected = true)
source

Send an unsigned value as an int uniform (e.g. a texture unit) to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, float value, bool expected = true)
source

Send a float uniform to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, vec2 const& value, bool expected = true)
source

Send a vec2 uniform to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, vec3 const& value, bool expected = true)
source

Send a vec3 uniform to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, vec4 const& value, bool expected = true)
source

Send a vec4 uniform to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, float x, float y, bool expected = true)
source

Send a vec2 uniform given by its two components to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, float x, float y, float z, bool expected = true)
source

Send a vec3 uniform given by its three components to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, float x, float y, float z, float w, bool expected = true)
source

Send a vec4 uniform given by its four components to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, mat4 const& m, bool expected = true)
source

Send a mat4 uniform (row-major, transposed on upload) to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, mat3 const& m, bool expected = true)
source

Send a mat3 uniform (row-major, transposed on upload) to the shader.

void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, mat2 const& m, bool expected = true)
source

Send a mat2 uniform (row-major, transposed on upload) to the shader.

Warns if the uniform is not found and expected is true.

Functions returning a opengl_shader_structure

None.

Operators

None.

CGP - Computer Graphics Programming.