glProgramUniform1f
Sets a float uniform of any program, without making it the program in use.
Part of the family glProgramUniform*
Signature
void glProgramUniform1f(GLuint program, GLint location, GLfloat v0);
How it works
glUniform* always writes to the program bound with glUseProgram, which forces a bind just to set a value. The glProgramUniform* family takes the program as its first argument, the same idea as Direct State Access. Every glUniform variant has one: glProgramUniform1i, glProgramUniform3fv, glProgramUniformMatrix4fv…
Handy for a compute program's time step, or for setting up several programs' uniforms at load time.
Parameters
The program that owns the uniform.
From glGetUniformLocation on that same program.
The value.
Tips & pitfalls
Locations belong to a program: a location from one program means nothing in another.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- program is not a linked program, or the uniform is not a float.
Example
1glProgramUniform1f(computeProgram, glGetUniformLocation(computeProgram, "uDt"), dt);
2glUseProgram(computeProgram);
3glDispatchCompute(groups, 1, 1);