glUniform* with location = -1


The man pages say that the location of a uniform should be the value returned by glGetUniformLocation:

The location of the uniform variable to be modified is specified by location, which should be a value returned by glGetUniformLocation.

It later says that:

If location is equal to -1, the data passed in will be silently ignored and the specified uniform variable will not be changed.

What I would like to know is: is it safe to assign an uniform location at -1 by ourself, without using glGetAttribLocation. Or should this be avoided ?

Currently, I would like to assign some uniforms, but depending on some situations, the program can use different shaders, some requiring some uniforms, and other not requiring some.

I can modify the code to detect if the current shader needs all uniforms and call to glUniform only for the required ones, but currently this will imply some ‘annoying’ changes. And if it is safe to do as I asked for, then this will preserve me doing those changes.

What do you know about this ?

doc read here:

From performance point of view, I think it is most probably better to track it on your own so that you can avoid the unnecessary API calls, though assigning -1 to uniform locations manually would not cause any issues as if you don’t do it, the driver will do check the value of the location before doing anything else.

Yes, this will be changed later but for now I’ll keep it like this since this will cause no issues. Thanks.