Does anyone know how the ^^ operator ended up in GLSL?

I find it very curious. Other than this special “logical xor” operator, GLSL is pretty in line with standard C90/C99, only adding “discard;” and new storage classes like in, out and uniform to the syntax of the language. Why was this added? I can’t really see a good reason tbh, if (!a != !b) is already the same as (a ^^ b), and it also doesn’t short circuit (this was part of the reason it’s not in C, see c-faq DOT com/misc/xor.dmr.html). I understand why adding discard makes sense (although it could have been “discard();” instead, but I don’t really think too much of that), and why adding the storage classes is necessary (if you don’t want to have heavy notation like the C+±style “in < vec4 > v;” instead of “in vec4 v;”), but the addition of ^^ seems like needlessly adding an incompatibility, so I would like to know, if anyone knows why this was added and never removed in almost 20 years now.

the addition of ^^ seems like needlessly adding an incompatibility

It’s not an “incompatibility” because it was never intended to be “compatible”. GLSL was never meant to be compilable to C of any version. You’re judging it by a standard it never meant to follow. It wasn’t meant to be needlessly surprising to C programmers, but adding an operator is hardly “surprising”.

And if you want “surprising for a C programmer”, GLSL 1.10 didn’t even allow implicit conversions. Yes, something as simple as float f = 1; was a compile error. It would be several revisions of the language before that was corrected. Another thing that would be surprising to a C programmer is that 1.0 is a float, not a double. And the suffix for double is lf.

So it seems weird to me that you single out this operator as being the only questionable design choice of GLSL.

As to why it was added, who knows? I looked at the oldest easily-available version of GLSL, and 1.10 seems to have had it. So there’s a pretty decent chance that GLSL, from its inception, had this functionality.

The genesis of the OpenGL Shading Language was the OpenGL 2.0 initiative largely led by 3D Labs, a company that was bought and renamed since then. This initiative largely failed to do what it meant to, and the only real thing that came out of it was its framework for a high-level shading language. 3D Labs brought a lot of… unusual things to the language (they’re responsible for lacking implicit conversions, for example). So one could speculate that 3D Labs had a special opcode in some of their hardware for doing this operation. Or maybe someone on the GLSL design team liked it.

At this point, it’s almost entirely lost to history. Unless you can track down the people at 3DLabs who originally proposed the thing, you’ll likely never know.

why adding the storage classes is necessary

FYI: C and C++ also have storage classes; that’s what static is and what auto was pre-C++11. It just doesn’t have quite as many.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.