On compilers that support anonymous struct as union members (like Visual C++), GLM_FORCE_SWIZZLE enables true GLSL-like swizzling, allowing both R-value and L-value expressions.
Note: Swizzle objects returned by this method are implementation-specific and implicitly convert to vector types. They cannot be passed directly to GLM functions; you must use an explicit constructor or the () operator.
Example of L-value usage:
ColorRGBA.bgra = ColorRGBA.rgba;
Example of required conversion for GLM functions:
// ERROR: Color.rgba is not a vector type
vec4 ClampedA = glm::clamp(Color.rgba, 0.f, 1.f);
// OK: Explicit conversion
vec4 ClampedB = glm::clamp(vec4(Color.rgba), 0.f, 1.f);
// OK: Explicit conversion via operator()
vec4 ClampedC = glm::clamp(Color.rgba(), 0.f, 1.f);
#define GLM_FORCE_SWIZZLE
#include <glm/glm.hpp>
using glm::vec4;
void foo()
{
vec4 Color(1.0f, 0.5f, 0.0f, 1.0f);
// Generates compiler errors. Color.rgba is not a vector type.
vec4 ClampedA = glm::clamp(Color.rgba, 0.f, 1.f); // ERROR
// Explicit conversion through a constructor
vec4 ClampedB = glm::clamp(vec4(Color.rgba), 0.f, 1.f); // OK
// Explicit conversion through operator()
vec4 ClampedC = glm::clamp(Color.rgba(), 0.f, 1.f); // OK
}