glGetUniformLocation fails

Hi there,

i have a weird problem and i really hope you can help me.
In my fragment shader i have set up a uniform variable like this
uniform sampler2D tex0;
Now when i try glGetUniformLocation(prog_obj, “tex0”) it always returns -1.

The shaders compiled and linked sucessfully, but glGetProgram says i only have 12 active uniforms (the standard ones, gl_ModelViewMatrix etc) no matter how many i have actually specified in my program.
Any ideas what could cause this?

Make sure you use (reference) that uniform someware in the shader.

On my Geforce 7600gt with 93.71 driver,
glGetUniformLocation will alway return -1
for unused (unreferenced) uniform variable

Can someone confirm this ?

That did the trick, thanks a lot!
I had the texture lookup commented out, but it works fine now.
I guess that confirms that glGetUniformLocation will alway return -1 for an unreferenced uniform variable :wink:

Can someone confirm this ?
Uniform vairable used at least once in program object is called “active uniform”.
Specs say that glGetUniformLocation returns location of an active uniform.

… and “used” means “contributes to an output” in way that the compiler is unable to eliminate it.
It’s not enough to write the variable into a function body, it needs to affect the output or it’s scrapped.
BTW, if you’re concerned about calling glUniform with a -1 location, that is simply ignored.
So you can do something like
glUniform*(glGetUniformLocation(“id”), x);
without producing a GL error.
BUT you shouldn’t call glGetUniformLocation more than once after a successful link, the location won’t change, and you shouldn’t call OpenGL calls which do nothing, e.g. like glUniform(-1, x);
Ok, just forget about that example above for a program which should run fast. :wink:

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