UniformsGL 2.0
glUniformMatrix3fv
Sets a mat3 uniform — most often the normal matrix.
Part of the family glUniform*
Signature
void glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
How it works
Normals must not be moved by translation and must stay perpendicular after non-uniform scaling. The fix is the normal matrix, transpose(inverse(mat3(model))), usually computed on the CPU and uploaded with this call.
Parameters
locationGLint
Uniform location from glGetUniformLocation. -1 is silently ignored.
countGLsizei
Number of matrices (1 unless the uniform is an array).
transposeGLboolean
GL_FALSE for GLM/column-major data.
valueconst GLfloat *
Pointer to 9 × count floats.
Tips & pitfalls
Uniforms are written to the program currently selected with
glUseProgram.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- No program in use, or the function's type/size does not match the uniform declared in GLSL.
Example
example.cpp
1glm::mat3 normalMatrix = glm::transpose(glm::inverse(glm::mat3(model)));
2glUniformMatrix3fv(uNormalMatrix, 1, GL_FALSE, glm::value_ptr(normalMatrix));