vector equality

Im probably missing something blatantly obvious, but given compUVIndex and prevUVIndex are both vec4, shouldnt the following two fragments of code return the same result?


if(vec2(compUVIndex) == vec2(prevUVIndex))
	{
	a_point = 0;
	}
else
	{
	a_point = 1;
	}


if( (compUVIndex.x == prevUVIndex.x && compUVIndex.y == prevUVIndex.y) )
	{
	a_point = 0;
	}
else
	{
	a_point = 1;
	}

Yet, when I swap the codes, the results are different.

Kind regards,
Fugi

Try this:

if(all(vec2(compUVIndex) == vec2(prevUVIndex)))

Fugitive, I think the results should be the same too. It sounds like a driver bug to me.

Maybe you can tell which graphics card, OS and driver version, and OpenGL version you have?

I have the ATI 4870x2, with the latest catalyst drivers, on windows XP 64-bit. Im guessing my opengl version would be 3.0 or above but I thought the GPU driver took care of that? Any I will update my drivers once again, just in case.

Gumby, I will try that. Thanks.

Kind regards,
Fugi

I have ATI Radeon 2400HD with Catalyst 9.10.
Made some experiments on your case.

The problem is: vec2 == vec2 is not a boolean expression in theory (GLSL spec).
It should be of ‘bvec2’ that is not accepted in ‘if’ statement.
In order to pass it to ‘if’ you need to cover it with either ‘all’ or ‘any’ function.

However, the driver doesn’t complain about ‘vec2==vec2’ passed to ‘if’.
Experimentally I discovered that it works like: any( equal(vec2,vec2) )

From the GLSL specs (1.50):

The equality operators equal (==), and not equal (!=) operate on all types. They result in a scalar
Boolean. If the operand types do not match, then there must be a conversion from Section 4.1.10
“Implicit Conversions” applied to one operand that can make them match, in which case this
conversion is done. For vectors, matrices, structures, and arrays, all components, fields, or elements of
one operand must equal the corresponding components, fields, or elements in the other operand for the
operands to be considered equal. To get a vector of component-wise equality results for vectors, use
the built-in functions equal and notEqual.

This actually says, that vec2==vec2 should indeed work and returns true, if all pairs of components (x0/x1; y0/y1) are equal. So it seems, the OP tripped on a driver bug.

I second the call for platform specs.

Have you tried something like

a_point = float(compUVIndex != prevUVIndex); // Assuming a_point is float

?

hi,

fyi, this bug in the GLSL compiler has been fixed in an upcoming driver release.

regards,

Pierre B.

Hi Guys,

The fix made it to the Catalyst 9.12 release. It should work fine now.

Cheers,

Graham