Hello Guest

[FIXED] glUniformLocation returning invalid values

  • 1 Replies
[FIXED] glUniformLocation returning invalid values
« on: June 20, 2013, 08:59:17 »
We're seing weird return values from glUniformLocation on Intel hardware. All returned values are greater than 0x10000, leading me to believe it is a byte order failure somewhere. I tried taking the returned value and shift it down 16 bits, but no luck. The returned size is also wrong, always the same as type (which is returned correctly, GL_FLOAT_VEC4)

Code: [Select]
final int numUniform = glGetProgrami(programObject, GL_ACTIVE_UNIFORMS);
for (int iu = 0; iu < numUniform; ++iu)
    String uniformName = glGetActiveUniform(programObject, iu, 128);

    if (uniformName == null || uniformName.length() <= 0)
    if (uniformName.startsWith("gl_"))
        continue; //Built-in
    int location = glGetUniformLocation(programObject, uniformName);
    if (location < 0)
    if (location > 0x10000)
        System.out.println("Uniform failed sanity check: " + uniformName + " has location " + location);

    int gltype = glGetActiveUniformType(programObject, iu);
    int glsize = glGetActiveUniformSize(programObject, iu);

    //...rest of code...
« Last Edit: June 20, 2013, 11:01:28 by Rampant Pixels »


Offline spasi

  • *****
  • 2191
    • WebHotelier
Re: [BUG] glUniformLocation returning invalid values
« Reply #1 on: June 20, 2013, 12:30:05 »
Hey Rampant Pixels,

The uniform location is obviously not the same as the uniform index. The uniform index starts at 0 and goes up to ACTIVE_UNIFORMS-1. The uniform location can be an arbitrary implementation-dependent integer. I'm seeing the same thing when testing on Intel and it's not a problem. You'll see that if you use that weird uniform location when updating the uniform value(s) everything will work fine.

The size not being returned correctly is indeed a driver bug. I was able to find a workaround and pushed a change just now. Until the new build is up, you can use glGetActiveUniform directly instead of the helper Type/Size ones. The problem seems to be passing 0 to the name's max_length parameter, the Intel driver doesn't like that and does not return the size value.