View Full Version : glGetUniformLocation fails
08-09-2007, 03:04 PM
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?
08-09-2007, 07:20 PM
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 ?
08-10-2007, 05:24 AM
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 ;)
08-10-2007, 07:59 AM
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.
08-10-2007, 09:07 AM
... 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
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. ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.