View Full Version : GLMath assignment to swizzle doesn't work ?

01-10-2010, 06:42 AM
Hi there,

I notice that the following doesn't seem to work:

mat4 mat;
mat[3].xyz = vec3( 10.0f, 10.0f, 10.0f );

Is this due to my compilationsettings, or is it not a feature of GLM ?

I figured GLM has a full GLSL implementation, and since you can do this in GLSL, it should work..

anyone ?



01-10-2010, 06:53 AM
hmm, looking at type_vec4.inl in GLMath- I see:

template <typename valType>
inline tvec3<valType> tvec4<valType>::swizzle(comp x, comp y, comp z) const {
return tvec3<valType>(

this creates a new instance of a vec4 and so doesn't offer access to the members of a vec4, which doesn't comply with GLSL spec 1.20.8 (page 34, "The component group notation can occur on the left hand side of an expression." ) as GLM claims.


01-10-2010, 11:45 AM
#include <glm/setup.hpp>
#include <glm/glm.hpp>

int main()
glm::vec4 v1(1, 2, 3, 4);
glm::vec4 v2;
glm::vec4 v3;
glm::vec4 v4;
v2.wyxz = v1.zyxw;
v3 = v1.xzyw;
v4.xzyw = v1;

return 0;

And that will work.
I'm not sure if I can advice to use it... that's why the feature isn't able by default.

xyzw is actually a #define which can bring some compatibility with OSs or software libraries.