glGetUniformLocationARB

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?

have you successfully linked the program before calling that function?

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.

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?

  
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.
  • 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?

nope, you pass it the number of the texture unit you’ve bound the texture to

how do i get a handle to the texture unit i bound the texture?

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.

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