First thing is that I know how to give values to uniforms in OpenGL. Second thing is that it is a question related to optimization and performance.
The habit for changing the uniforms, we preferred is like this:
//Consider that we have shaders having 'aValue' as uniform
//During initialization
GLint loc = glGetUniformLocation(program, "aValue");
//During a loop or when required to change uniform's value
if (loc != -1)
{
glUniform1f(loc, 0.75);
}
But what if it is like this:
//'program' is a global variable
//Can be anywhere but not after destructing 'program'
void updateUniformf( const char* name, float value )
{
glUniform1f(glGetUniformLocation(program, name), value);
}
//During a loop or when required to change uniform's value
updateUniformf("aValue", 0.75);
How much would such approach decreases the performance? Or would this approach even affects the performance? It will be appreciable to have some measurements or practical example rather than all theories. Of course, I need to know reasons as well.
Thanks for answering this question!