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