Syntax validator says it's ok

That’s legal?

vec4 myvalue = vec4(1, 1, 1, 1);

passes with flying colors, but spec says it shouldn’t, least from what i can see.

p.s. that’s a bit harsh, isn’t it?

perhaps theyve decided to relaxe the syntax, good on them.

No, I don’t think that’s legal, it should be:
vec4 myvalue = vec4(1.0, 1.0, 1.0, 1.0);
My guess is that it only compiles if you are on nvidia based hardware since they don’t seem to care much about the specs and go on their own way.

Baggio,
I’m talking about 3D Labs Syntax validator
http://developer.3dlabs.com/downloads/glslvalidate/index.htm

I had v1.7 and now I just updated to 1.9 and tested again, and the code passed.

it seems to be the vec* and mat* constructors only.

float x = 1;

will fail (but slips quietly by on my nvidia board :-)).

isn’t there a way to get the compiler to just generate a warning on implicit conversions, perhaps with a pragma? you could even have a “treat warnings as errors” pragma (extension).

it would be nice to have consistency, one way or the other :slight_smile:

edit: my bad, the nvidia compiler does in fact generate warnings for implicit conversions. that’s all you need :slight_smile:

looks fine to me :slight_smile: When using constructors the conversion rules are explicit (float -> int, bool -> float etc…) When using array constructors same rules apply as scalar.

from GLSLangSpec.Full.1.10.59.pdf section 5.4

pocketmoon is right!

in section 5 it says any lexically correct parameter list is ok, while in section 4 it says that no implicit conversions are allowed (sigh).

hmmm… then it goes on to say that parameters must be of the correct size and type. pocketmoon, i don’t see where there’s an “explicit” conversion (maybe i missed it). can you quote that bit? (nevermind, i see it, 5.4.2, third paragraph). this strikes me as inconsistent with the spirit of implicit conversions, to allow them in constructors, but nowhere else.

there’s still the matter of consistency among compilers :slight_smile:

There is no implicit conversion.

Just like
float x = float(1);
is an explicit conversion from int to float…

vec4 x = vec4(1,1,1,1);
is an explicit conversion from four ints to a vec4.

hehe… yes, but none of the vec* constructors take ints.

so

float x = float(1); // ok, explicit

vec4 x = vec4(float(1), float(1), float(1), float(1)); // ok, implicit, converts 4 floats to vec4

there seems to be room for this sort of interpretation. i can see your interpretation as well, since constructors are “special cases”, not really functions, unique instances of implicit conversion safe havens, the “club med” for illicit coercions.

it just strikes me as a bit odd that no implicit casts are allowed in general, a bit odd and inconvenient.

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