View Full Version : Syntax validator says it's ok
02-20-2006, 05:16 PM
vec4 myvalue = vec4(1, 1, 1, 1);
02-20-2006, 06:02 PM
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.
02-20-2006, 09:54 PM
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.
02-21-2006, 03:40 AM
I'm talking about 3D Labs Syntax validator
I had v1.7 and now I just updated to 1.9 and tested again, and the code passed.
02-21-2006, 04:53 AM
it seems to be the vec* and mat* constructors only.
float x = 1;
will fail (but slips quietly by on my nvidia board :-)).
02-21-2006, 05:59 AM
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 :-)
edit: my bad, the nvidia compiler does in fact generate warnings for implicit conversions. that's all you need :-)
02-21-2006, 06:19 AM
looks fine to me :) 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
02-21-2006, 06:30 AM
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 :-)
02-23-2006, 12:07 AM
There is no implicit conversion.
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.
02-23-2006, 06:12 AM
hehe... yes, but none of the vec* constructors take ints.
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.