PDA

View Full Version : glGetUniformLocationARB



supagu
04-27-2004, 06:51 PM
here is some of my parsing code:

p.handle = glGetUniformLocationARB( program, third );

this asks the program, for a handle to a string eg:
sampler2D myTexture; third would = "myTexture"

but glGetUniformLocationARB only retusn -1's and 0's when i print the handle out with printf %i

hrmm ideas whats goin on here?

bobvodka
04-27-2004, 09:33 PM
have you successfully linked the program before calling that function?

Relic
04-27-2004, 10:05 PM
0 is a valid uniform location.
If you got a 0 sometimes then surrounding things seem to work.
-1 means the name you asked for was not an active uniform in the program.
This can happen because it's not there at all or the compiler found that it's not used in the shader, aka. inactive.

supagu
04-27-2004, 11:34 PM
okay they werent being used ;p

now another problem, i bind 3 textures like:
glUniform1iARB( texture, handle );

edit: also tried this:
glUniform1iARB( handle, texture );
but this results in no textures at all :-/ (ie. black model

but still, tho model is only rendered as if 1 texture is being used.

heres my shader:
uniform sampler2D texture;
uniform sampler2D normal;
uniform sampler2D height;

void main( void )
{
gl_FragColor = texture2D( texture, vec2(gl_TexCoord[0]) ) +
texture2D( normal, vec2(gl_TexCoord[0]) ) +
texture2D( height, vec2(gl_TexCoord[0]) );
}

just to test. But all i get is "texture" showing through, am i doing something wrong?

Relic
04-28-2004, 12:52 AM
loc = glGetUniformLocationARB(program, "texture");
if (loc != -1) glUniform1iARB(loc, texUnitTexture);
loc = glGetUniformLocationARB(program, "normal");
if (loc != -1) glUniform1iARB(loc, texUnitNormal);
loc = glGetUniformLocationARB(program, "height");
if (loc != -1) glUniform1iARB(loc, texUnitHeight);Important things to watch out for:
- The program needs to be in use when you set the uniforms.
- The samplers get texture image unit ids, not texture object ids.
- The texture image units need to be setup with a consistent texture. Watch out for the typical mipmap error, default minification filtering is GL_LINEAR_MIPMAP_NEAREST. If you didn't download a mipmap chain, set the filter to GL_LINEAR or GL_NEAREST for each texture unit.
Texture objects store texture parameters. You need to do that once per texture object and never again, because glBindTexture will update it in the texture unit.

supagu
04-28-2004, 06:56 PM
- The samplers get texture image unit ids, not texture object ids.

doint i just pass the glint i get when i make a handle to my texture?

bobvodka
04-28-2004, 07:07 PM
nope, you pass it the number of the texture unit you've bound the texture to

supagu
04-28-2004, 11:46 PM
how do i get a handle to the texture unit i bound the texture?

Relic
04-29-2004, 05:05 AM
You got the answer to your same question on http://www.shadertech.com/forums/viewtopic.php?t=2745

It's a running integer number from 0 to max. texture image units - 1.
If you bind something to glActiveTexture(GL_TEXTURE0) the sampler needs to be set to integer 0, and so on.

BTW, I think there's no need to enable the unit, this is texture image units, not texture units.

Please read the spec and some demo shaders.