PDA

View Full Version : How to disable auto-optimization for GLSL



shapeare
09-25-2013, 08:07 PM
If I define a uniform variable in GLSL and do not use it in the main function, then at runtime there will be an error message saying "no such uniform named XXX". How to disable this kind of auto-optimization.

rombust
09-26-2013, 12:47 AM
Instead, use glGetUniformLocation(program, "uniform_name").
This function returns -1 if uniform_name does not correspond to an active uniform variable in program

i.e. If the function returns >=0, then it is okay to set the uniform

GClements
09-26-2013, 01:08 AM
Use a uniform block with the shared or std140 qualifiers. These have a fixed layout so that they can be shared between different shaders.

Alternatively, force the variable to be used in some way, e.g. multiply it by a very small value (so that the effect isn't discernible) then add it to an output.