Open hmarthinsen opened 6 years ago
Thanks for the report.
a.xy = b.xy; is an historical issue in GLM swizzle implementation. Unless I am mistaken, even on previous versions, this code would compile but fail to do the assignment. This is due to some specific constructor rules (used by the swizzle operator implementation) where we can't assign if the types are the same on both sides of the assignment operators.
It's correct that this is not tested in GLM because I think I gave up on left side swizzle operators which are very complicated to implement for very little use.
Are you using left side swizzle operators in your project?
Yes, I'm using left (and right) side swizzles in my project, e.g. like this:
a.x += tmp.x;
b.yz -= tmp.yz;
where a
, b
, and tmp
are glm::vec3
s. This code compiled yesterday. Chapter 2 of the manual says that
vec4 A;
vec2 B;
B.yx = A.wy;
is legal code. I tried compiling it and this gives the same compilation error as in my first example.
Ok, I'll investigate.
Both case you mention used to be something that worked, only:
vec4 A;
vec2 B;
B.yx = A.yx;
was the issue case and as far as I remember didn't have any known solution unfortunately...
I think silently doing nothing in the a.xy = b.xy
case is quite bad. I think this is unexpected behaviour. Could you at least give a compiler warning in this case?
I can confirm that a.xy = b.xy
is not working as expected. Actually only the first component get copied. I have no idea if throwing a warning or an error is possible.
I'll investigate further to either have an option to disable left side swizzle operator or better document this case.
Thanks, Christophe
I can confirm that
a.xy = b.xy
is not working as expected. Actually only the first component get copied. I have no idea if throwing a warning or an error is possible.I'll investigate further to either have an option to disable left side swizzle operator or better document this case.
Thanks, Christophe
Would you think it an appropriate way to implement swizzle with std::tuple
?
Because c++
does not have a getter or setter for a member, may be the only way is to implement two functions.
void set_xy(vec2);
vec2 xy();
And it's the same with other combinations such as yx
.
I saw a cppcon talk by Valentin Galea: https://www.youtube.com/watch?v=8FoAxasNssA. He seems to have taken another approach at the swizzling problem (no unions and no member functions) with the explicit goal of supporting GLSL swizzles exactly as they are. Given a c++17 compiler, maybe adopting that approach would be worth a consideration?
Compiling this short program fails:
Here are the error messages: