Example/Uniform Location Query New

From OpenGL Wiki
< Example
Revision as of 11:15, 3 January 2018 by Flfirsla (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Querying and using uniform locations, under the new introspection API.

Vertex shader code:

uniform vec3 someVector;
uniform mat4 someMatrix;
// Code must use these uniforms to be active.

C++ code:

GLuint program = // Compile and link program.
GLint someVectorLoc = glGetProgramResourceLocation​(program, GL_UNIFORM, "someVector");
assert(someVectorLoc != -1); // If fails, then the uniform is inactive.
GLint someMatrixLoc = glGetProgramResourceLocation​(program, GL_UNIFORM, "someMatrix");
assert(someMatrixLoc != -1); // If fails, then the uniform is inactive.
glProgramUniform3f(program, someVectorLoc, 3.0f, 3.0f, 4.0f);
GLfloat matrix[16];
// Fill `matrix` with data. Non-transposed matrix data.
glProgramUniformMatrix4fv(program, someMatrixLoc, 1, GL_FALSE, matrix);