Clone this wiki locally
Swizzle is a way of accessing class fields, introduced in the GPU program assembly and subsequently used in all GPU programming languages.
It allows the programmer to refer to several fields of a structure at the same time. Here are a few examples, that are not usable with MathGP, but simply illustrate swizzling:
v = vec3(1, 2, 3); v.xz; // equivalent to a 2d vector with fields 1 and 3 v.xz = vec2(10, 20); // v is now (10, 2, 20)
Alas, this was impossible to implement in C++ while also maintaining the other requirements of MathGP, so the working compromise were generated functions that look like this:
// valid MathGP code vector3 v = vector3::coord(1, 2, 3); // creates a 3d vector v.xz(); // equivalent to a 2d vector with fields 1 and 3 v.xz() = vector2::coord(10, 20); // v is now (10, 2, 20)