[FIXED] glUniformLocation returning invalid values

Started by Rampant Pixels, June 20, 2013, 08:59:17

Previous topic - Next topic

Rampant Pixels

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)

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

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

    //...rest of code...
}

spasi

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.