Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Opengl (bug?) cant get a uniform bool variable working correctly
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wspilot
    wrote on last edited by
    #1

    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.

    shader:
    @...
    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
    else
    {
    if(criticalHeights[2] < (vertex.z + criticalHeights[0]))//1000
    {varAmbientLight = orangeAmbientLight; varDiffuseLight = orangeDiffuseLight;};
    };
    };
    @
    Thanks.

    1 Reply Last reply
    0
    • clogwogC Offline
      clogwogC Offline
      clogwog
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Ymalaika
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wspilot
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • clogwogC Offline
            clogwogC Offline
            clogwog
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wspilot
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wspilot
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wspilot
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved