Setting uniforms: Nvidia bug/feature, or general problem?

I noticed (the hard way, by trial and error) that uniform sampler variables need to have their values set before the activation of the shader program object, but uniform floats need to have their values set after the program activation.

This is quite illogical and looks like a bug, or at least an undocumented and strange constraint. Is this something that pertains only to Nvidia drivers, or is it common behavior?

location_texture = glGetUniformLocationARB(programObj, "texture");
location_time = glGetUniformLocationARB(programObj, "time");

glUniform1iARB(location_texture, textureID); // Set BEFORE activation
glUniform1fARB(location_time, t); // Set AFTER activation

I would suggest a bug in your code as how would the nvidia drivers know what program to bind the uniform to if the program is not bound yet?

May I suggest you try my tool ( and run with the options:

LogFormat = XML;
Enabled = True;

ThreadChecking = True;

LogEnabled = True;
RenderCallStateLog = True;

AttachLogState = True;
UniformLogPreRender = True;

Then after the app starts press CRTL-SHIFT-F to grab a frame. Then open up the XML file and see what uniform values are being used on the render calls. (should look like this:
-scroll down to the first render call and click on GLSL1)

Also check the gliLog.txt for any errors.

Your bug is most likely that you are setting the sampler uniform to a texture ID instead of a texture unit.

All glUniform calls should occur after glUseProgramObject is called, this is the correct behavior for samplers or floats.

I think there’s something in your code. It should work fine to set both the floats and the samplers after you use the program. That’s what I do, and it works fine, both on NVIDIA and ATI hardware.

I’m sure that it’s a problem in your code, because in the Shader Desinger, all uniforms are inserted inmediatelly after the program object is binded, and the application works without problems on NV hardware.

Ah, that was the problem. I should set the uniform to a texture UNIT to which the texture ID is bound, not to the texture ID itself. The GLSL specification
is not at all clear on this, and I have seen others being confused over the same issue. Thanks!

Stefan G

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.