Qt World Summit: Submit your Presentation

Opengl (bug?) cant get a uniform bool variable working correctly

  • Hi,
    Qt5.1; ubuntu 13.04-64bit.
    I have a shader prg that works OK., except for checking a boolean value: if(altChecked==false).
    If I replace if(altChecked==false) with if(1==1) or if(1==0) things work OK.
    But, somehow if(altChecked==true) and if(altChecked==false) both always evaluates to TRUE!!
    In C++:
    altCheckedUniform = mapShaderProgram->uniformLocation("altChecked");
    if (altCheckedUniform < 0)
    qWarning() << "ERROR";
    mapShaderProgram->setUniformValue(altCheckedUniform, (GLboolean)false);;

    No errors during building and running.

    uniform bool altChecked;
    void main(void)
    varAmbientLight = ambientLight;
    varDiffuseLight = diffuseLight;
    if(altChecked == false)//HERE IT GOES WRONG
    if(criticalHeights[2] < (vertex.z + criticalHeights[1] ))//500
    {varAmbientLight = redAmbientLight; varDiffuseLight = redDiffuseLight;}//25
    if(criticalHeights[2] < (vertex.z + criticalHeights[0]))//1000
    {varAmbientLight = orangeAmbientLight; varDiffuseLight = orangeDiffuseLight;};

  • can you inspect the value in the debugger at that time ?
    or perhaps add a
    qDebug() << "altChecked value: " << altChecked ;
    to see what the value is?

    from the main() it looks to me that altChecked might not be initialised ?

    i must admit that i'm not familiar with the uniform keyword. i did a search and found a lot of GL based articles. what does it mean ?

  • I've recently started learning GLSL and have run into a couple situations where setUniformValue quietly fails to update the uniform. Turns out it was related to type. Does it work if you try using, say, a vec4 instead of a boolean?

  • Thanks.
    I have tried it as a float. Same problem.
    It turns out that if() always returns true when I use != .
    Possibly sth. like saying the value isn't equal to anything.
    So, I guess it stays undefined (indeed silently).
    I dont think any debugging is possible from within the shader.
    So, quite stuck here.

  • how about using an int, initialising it to -1
    then setting it in the shader to 0 or 1

    and then seeing in the shader if it's -1 , 0 or 1 ?
    that way you at least know if it is the setting or the test that fails

  • Cannot change a uniform during pipeline processing, you can only change it from C++ before or after the shaders processing.
    I do have another (float) uniform that does seems to work....
    I'll study the differences with altChecked a bit more.

  • After some more testing:
    the "if" statement is completely unpredictable when I use a (any) uniform variable in it (I checked, they were set). As if they were out of scope.
    Still, if that true, I should have got an undefined error.
    Other variables do work fine.
    I think this a bug.

  • This happened after upgrading to ubuntu 13.4!
    So, not a Qt bug.

Log in to reply