From f09aa1c17779236ce1dcafe46231606394af239c Mon Sep 17 00:00:00 2001 From: athile Date: Tue, 20 Sep 2011 20:17:52 -0400 Subject: [PATCH] First pass at adding swizzling members. --- glm/core/_swizzle.hpp | 507 +++++++++++++++++++++++++++++++++++ glm/core/type_vec2.hpp | 10 + glm/core/type_vec3.hpp | 12 +- glm/core/type_vec4.hpp | 10 + test/core/core_type_vec3.cpp | 99 +++++++ 5 files changed, 637 insertions(+), 1 deletion(-) diff --git a/glm/core/_swizzle.hpp b/glm/core/_swizzle.hpp index 34dabfab..3b154c47 100644 --- a/glm/core/_swizzle.hpp +++ b/glm/core/_swizzle.hpp @@ -29,6 +29,513 @@ namespace glm }; }//namespace glm + +namespace glm{ +namespace detail +{ + //! Internal class for implementing swizzle operators + /*! + Template parameters: + + Type = type of scalar values (e.g. float, double) + Class = class the swizzle is applies to (e.g. vector3f) + N = number of components in the vector (e.g. 3) + E0...3 = what index the n-th element of this swizzle refers to + */ + template + struct swizzle_base + { + swizzle_base& operator= (const Class& that) + { + static const int offset_dst[4] = { E0, E1, E2, E3 }; + + Type t[N]; + for (int i = 0; i < N; ++i) + t[i] = that[i]; + for (int i = 0; i < N; ++i) + e[offset_dst[i]] = t[i]; + + return *this; + } + + swizzle_base& operator= (const Type& t) + { + static const int offset_dst[4] = { E0, E1, E2, E3 }; + + for (int i = 0; i < N; ++i) + e[offset_dst[i]] = t; + + return *this; + } + + Type e[N]; + }; + + template + struct swizzle_base + { + struct Stub {}; + swizzle_base& operator= (const Stub& that) {} + + Type e[N]; + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle2 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle2_3 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle2_4 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2], this->e[E3]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle3 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle3_2 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle3_4 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2], this->e[E3]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle4 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2], this->e[E3]); } + }; + + //! Internal class for implementing swizzle operators + template + struct swizzle4_2 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1]); } + }; + + + //! Internal class for implementing swizzle operators + template + struct swizzle4_3 : public swizzle_base + { + using swizzle_base::operator=; + operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + }; + +}//namespace detail +}//namespace glm + +#define _GLM_SWIZZLE2_2_MEMBERS(T,P,E0,E1) \ + struct { glm::detail::swizzle2 E0 ## E0; }; \ + struct { glm::detail::swizzle2 E0 ## E1; }; \ + struct { glm::detail::swizzle2 E1 ## E0; }; \ + struct { glm::detail::swizzle2 E1 ## E1; }; + +#define _GLM_SWIZZLE2_3_MEMBERS(T,P2,E0,E1) \ + struct { glm::detail::swizzle2_3 E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_3 E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_3 E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_3 E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle2_3 E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_3 E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_3 E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_3 E1 ## E1 ## E1; }; + + +#define _GLM_SWIZZLE3_3_MEMBERS(T,P,E0,E1,E2) \ + struct { glm::detail::swizzle3 E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3 E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3 E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3 E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3 E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3 E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3 E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3 E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3 E0 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle3 E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3 E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3 E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3 E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3 E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3 E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3 E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3 E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3 E1 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle3 E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3 E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3 E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3 E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3 E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3 E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3 E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3 E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3 E2 ## E2 ## E2; }; + +#define _GLM_SWIZZLE3_2_MEMBERS(T,P2,E0,E1,E2) \ + struct { glm::detail::swizzle3_2 E0 ## E0; }; \ + struct { glm::detail::swizzle3_2 E0 ## E1; }; \ + struct { glm::detail::swizzle3_2 E0 ## E2; }; \ + struct { glm::detail::swizzle3_2 E1 ## E0; }; \ + struct { glm::detail::swizzle3_2 E1 ## E1; }; \ + struct { glm::detail::swizzle3_2 E1 ## E2; }; \ + struct { glm::detail::swizzle3_2 E2 ## E0; }; \ + struct { glm::detail::swizzle3_2 E2 ## E1; }; \ + struct { glm::detail::swizzle3_2 E2 ## E2; }; + +#define _GLM_SWIZZLE3_4_MEMBERS(T,P2,E0,E1,E2) \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E0 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E1 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E0 ## E2 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E0 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E1 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E1 ## E2 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E0 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E1 ## E2 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle3_4 E2 ## E2 ## E2 ## E2; }; \ + + +#define _GLM_SWIZZLE2_4_MEMBERS(T,P2,E0,E1) \ + struct { glm::detail::swizzle2_4 E0 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_4 E0 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_4 E0 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_4 E0 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle2_4 E0 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_4 E0 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_4 E0 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_4 E0 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle2_4 E1 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_4 E1 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_4 E1 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_4 E1 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle2_4 E1 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle2_4 E1 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle2_4 E1 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle2_4 E1 ## E1 ## E1 ## E1; }; + + +#define _GLM_SWIZZLE4_2_MEMBERS(T,P,E0,E1,E2,E3) \ + struct { glm::detail::swizzle4_2 E0 ## E0; }; \ + struct { glm::detail::swizzle4_2 E0 ## E1; }; \ + struct { glm::detail::swizzle4_2 E0 ## E2; }; \ + struct { glm::detail::swizzle4_2 E0 ## E3; }; \ + struct { glm::detail::swizzle4_2 E1 ## E0; }; \ + struct { glm::detail::swizzle4_2 E1 ## E1; }; \ + struct { glm::detail::swizzle4_2 E1 ## E2; }; \ + struct { glm::detail::swizzle4_2 E1 ## E3; }; \ + struct { glm::detail::swizzle4_2 E2 ## E0; }; \ + struct { glm::detail::swizzle4_2 E2 ## E1; }; \ + struct { glm::detail::swizzle4_2 E2 ## E2; }; \ + struct { glm::detail::swizzle4_2 E2 ## E3; }; \ + struct { glm::detail::swizzle4_2 E3 ## E0; }; \ + struct { glm::detail::swizzle4_2 E3 ## E1; }; \ + struct { glm::detail::swizzle4_2 E3 ## E2; }; \ + struct { glm::detail::swizzle4_2 E3 ## E3; }; + +#define _GLM_SWIZZLE4_3_MEMBERS(T,P,E0,E1,E2,E3) \ + struct { glm::detail::swizzle4_3 E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4_3 E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4_3 E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4_3 E0 ## E0 ## E3; }; \ + struct { glm::detail::swizzle4_3 E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4_3 E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4_3 E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4_3 E0 ## E1 ## E3; }; \ + struct { glm::detail::swizzle4_3 E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4_3 E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4_3 E0 ## E2 ## E2; }; \ + struct { glm::detail::swizzle4_3 E0 ## E2 ## E3; }; \ + struct { glm::detail::swizzle4_3 E0 ## E3 ## E0; }; \ + struct { glm::detail::swizzle4_3 E0 ## E3 ## E1; }; \ + struct { glm::detail::swizzle4_3 E0 ## E3 ## E2; }; \ + struct { glm::detail::swizzle4_3 E0 ## E3 ## E3; }; \ + \ + struct { glm::detail::swizzle4_3 E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4_3 E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4_3 E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4_3 E1 ## E0 ## E3; }; \ + struct { glm::detail::swizzle4_3 E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4_3 E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4_3 E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4_3 E1 ## E1 ## E3; }; \ + struct { glm::detail::swizzle4_3 E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4_3 E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4_3 E1 ## E2 ## E2; }; \ + struct { glm::detail::swizzle4_3 E1 ## E2 ## E3; }; \ + struct { glm::detail::swizzle4_3 E1 ## E3 ## E0; }; \ + struct { glm::detail::swizzle4_3 E1 ## E3 ## E1; }; \ + struct { glm::detail::swizzle4_3 E1 ## E3 ## E2; }; \ + struct { glm::detail::swizzle4_3 E1 ## E3 ## E3; }; \ + \ + struct { glm::detail::swizzle4_3 E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4_3 E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4_3 E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4_3 E2 ## E0 ## E3; }; \ + struct { glm::detail::swizzle4_3 E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4_3 E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4_3 E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4_3 E2 ## E1 ## E3; }; \ + struct { glm::detail::swizzle4_3 E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4_3 E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4_3 E2 ## E2 ## E2; }; \ + struct { glm::detail::swizzle4_3 E2 ## E2 ## E3; }; \ + struct { glm::detail::swizzle4_3 E2 ## E3 ## E0; }; \ + struct { glm::detail::swizzle4_3 E2 ## E3 ## E1; }; \ + struct { glm::detail::swizzle4_3 E2 ## E3 ## E2; }; \ + struct { glm::detail::swizzle4_3 E2 ## E3 ## E3; }; \ + \ + struct { glm::detail::swizzle4_3 E3 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4_3 E3 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4_3 E3 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4_3 E3 ## E0 ## E3; }; \ + struct { glm::detail::swizzle4_3 E3 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4_3 E3 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4_3 E3 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4_3 E3 ## E1 ## E3; }; \ + struct { glm::detail::swizzle4_3 E3 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4_3 E3 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4_3 E3 ## E2 ## E2; }; \ + struct { glm::detail::swizzle4_3 E3 ## E2 ## E3; }; \ + struct { glm::detail::swizzle4_3 E3 ## E3 ## E0; }; \ + struct { glm::detail::swizzle4_3 E3 ## E3 ## E1; }; \ + struct { glm::detail::swizzle4_3 E3 ## E3 ## E2; }; \ + struct { glm::detail::swizzle4_3 E3 ## E3 ## E3; }; + + +#define _GLM_SWIZZLE4_4_MEMBERS(T,P,E0,E1,E2,E3) \ + struct { glm::detail::swizzle4 E0 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E0 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E0 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E1 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E0 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E0 ## E2 ## E2 ## E2; }; \ + \ + \ + struct { glm::detail::swizzle4 E1 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E0 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E1 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E1 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E1 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E1 ## E2 ## E2 ## E2; }; \ + \ + \ + struct { glm::detail::swizzle4 E2 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E0 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E2 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E1 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E2 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E2 ## E2 ## E2 ## E2; }; \ + \ + \ + struct { glm::detail::swizzle4 E3 ## E0 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E0 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E3 ## E1 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E1 ## E2 ## E2; }; \ + \ + struct { glm::detail::swizzle4 E3 ## E2 ## E0 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E0 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E0 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E1 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E1 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E1 ## E2; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E2 ## E0; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E2 ## E1; }; \ + struct { glm::detail::swizzle4 E3 ## E2 ## E2 ## E2; }; + + + + + #if(defined(GLM_SWIZZLE_XYZW) || defined(GLM_SWIZZLE)) #define xx swizzle(glm::X, glm::X) diff --git a/glm/core/type_vec2.hpp b/glm/core/type_vec2.hpp index b8d47b7b..0286bdd9 100644 --- a/glm/core/type_vec2.hpp +++ b/glm/core/type_vec2.hpp @@ -51,6 +51,16 @@ namespace detail struct{value_type x, y;}; struct{value_type r, g;}; struct{value_type s, t;}; + + _GLM_SWIZZLE2_2_MEMBERS(value_type,glm::detail::tvec2,x,y) + _GLM_SWIZZLE2_2_MEMBERS(value_type,glm::detail::tvec2,r,g) + _GLM_SWIZZLE2_2_MEMBERS(value_type,glm::detail::tvec2,s,t) + _GLM_SWIZZLE2_3_MEMBERS(value_type,glm::detail::tvec3,x,y) + _GLM_SWIZZLE2_3_MEMBERS(value_type,glm::detail::tvec3,r,g) + _GLM_SWIZZLE2_3_MEMBERS(value_type,glm::detail::tvec3,s,t) + _GLM_SWIZZLE2_4_MEMBERS(value_type,glm::detail::tvec4,x,y) + _GLM_SWIZZLE2_4_MEMBERS(value_type,glm::detail::tvec4,r,g) + _GLM_SWIZZLE2_4_MEMBERS(value_type,glm::detail::tvec4,s,t) }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec3.hpp b/glm/core/type_vec3.hpp index 7b568789..b6991a46 100644 --- a/glm/core/type_vec3.hpp +++ b/glm/core/type_vec3.hpp @@ -51,7 +51,17 @@ namespace detail struct{value_type x, y, z;}; struct{value_type r, g, b;}; struct{value_type s, t, p;}; - }; + + _GLM_SWIZZLE3_2_MEMBERS(value_type,glm::detail::tvec2,x,y,z) + _GLM_SWIZZLE3_2_MEMBERS(value_type,glm::detail::tvec2,r,g,b) + _GLM_SWIZZLE3_2_MEMBERS(value_type,glm::detail::tvec2,s,t,p) + _GLM_SWIZZLE3_3_MEMBERS(value_type,glm::detail::tvec3,x,y,z) + _GLM_SWIZZLE3_3_MEMBERS(value_type,glm::detail::tvec3,r,g,b) + _GLM_SWIZZLE3_3_MEMBERS(value_type,glm::detail::tvec3,s,t,p) + _GLM_SWIZZLE3_4_MEMBERS(value_type,glm::detail::tvec4,x,y,z) + _GLM_SWIZZLE3_4_MEMBERS(value_type,glm::detail::tvec4,r,g,b) + _GLM_SWIZZLE3_4_MEMBERS(value_type,glm::detail::tvec4,s,t,p) + }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; union {value_type y, g, t;}; diff --git a/glm/core/type_vec4.hpp b/glm/core/type_vec4.hpp index 940b5c19..ae004dc7 100644 --- a/glm/core/type_vec4.hpp +++ b/glm/core/type_vec4.hpp @@ -51,6 +51,16 @@ namespace detail struct{value_type x, y, z, w;}; struct{value_type r, g, b, a;}; struct{value_type s, t, p, q;}; + + _GLM_SWIZZLE4_2_MEMBERS(value_type,glm::detail::tvec2,x,y,z,w) + _GLM_SWIZZLE4_2_MEMBERS(value_type,glm::detail::tvec2,r,g,b,a) + _GLM_SWIZZLE4_2_MEMBERS(value_type,glm::detail::tvec2,s,t,p,q) + _GLM_SWIZZLE4_3_MEMBERS(value_type,glm::detail::tvec3,x,y,z,w) + _GLM_SWIZZLE4_3_MEMBERS(value_type,glm::detail::tvec3,r,g,b,a) + _GLM_SWIZZLE4_3_MEMBERS(value_type,glm::detail::tvec3,s,t,p,q) + _GLM_SWIZZLE4_4_MEMBERS(value_type,glm::detail::tvec4,x,y,z,w) + _GLM_SWIZZLE4_4_MEMBERS(value_type,glm::detail::tvec4,r,g,b,a) + _GLM_SWIZZLE4_4_MEMBERS(value_type,glm::detail::tvec4,s,t,p,q) }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index a7e470e2..573d1777 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -33,12 +33,111 @@ int test_vec3_size() return Error; } +int test_vec3_swizzle3_2() +{ + int Error = 0; + + glm::vec3 v(1, 2, 3); + glm::vec2 u; + + // Can not assign a vec3 swizzle to a vec2 + //u = v.xyz; //Illegal + //u = v.rgb; //Illegal + //u = v.stp; //Illegal + + u = v.xx; Error += (u.x == 1.0f && u.y == 1.0f) ? 0 : 1; + u = v.xy; Error += (u.x == 1.0f && u.y == 2.0f) ? 0 : 1; + u = v.xz; Error += (u.x == 1.0f && u.y == 3.0f) ? 0 : 1; + u = v.yx; Error += (u.x == 2.0f && u.y == 1.0f) ? 0 : 1; + u = v.yy; Error += (u.x == 2.0f && u.y == 2.0f) ? 0 : 1; + u = v.yz; Error += (u.x == 2.0f && u.y == 3.0f) ? 0 : 1; + u = v.zx; Error += (u.x == 3.0f && u.y == 1.0f) ? 0 : 1; + u = v.zy; Error += (u.x == 3.0f && u.y == 2.0f) ? 0 : 1; + u = v.zz; Error += (u.x == 3.0f && u.y == 3.0f) ? 0 : 1; + + u = v.rr; Error += (u.r == 1.0f && u.g == 1.0f) ? 0 : 1; + u = v.rg; Error += (u.r == 1.0f && u.g == 2.0f) ? 0 : 1; + u = v.rb; Error += (u.r == 1.0f && u.g == 3.0f) ? 0 : 1; + u = v.gr; Error += (u.r == 2.0f && u.g == 1.0f) ? 0 : 1; + u = v.gg; Error += (u.r == 2.0f && u.g == 2.0f) ? 0 : 1; + u = v.gb; Error += (u.r == 2.0f && u.g == 3.0f) ? 0 : 1; + u = v.br; Error += (u.r == 3.0f && u.g == 1.0f) ? 0 : 1; + u = v.bg; Error += (u.r == 3.0f && u.g == 2.0f) ? 0 : 1; + u = v.bb; Error += (u.r == 3.0f && u.g == 3.0f) ? 0 : 1; + + u = v.ss; Error += (u.s == 1.0f && u.t == 1.0f) ? 0 : 1; + u = v.st; Error += (u.s == 1.0f && u.t == 2.0f) ? 0 : 1; + u = v.sp; Error += (u.s == 1.0f && u.t == 3.0f) ? 0 : 1; + u = v.ts; Error += (u.s == 2.0f && u.t == 1.0f) ? 0 : 1; + u = v.tt; Error += (u.s == 2.0f && u.t == 2.0f) ? 0 : 1; + u = v.tp; Error += (u.s == 2.0f && u.t == 3.0f) ? 0 : 1; + u = v.ps; Error += (u.s == 3.0f && u.t == 1.0f) ? 0 : 1; + u = v.pt; Error += (u.s == 3.0f && u.t == 2.0f) ? 0 : 1; + u = v.pp; Error += (u.s == 3.0f && u.t == 3.0f) ? 0 : 1; + + // Mixed member aliases are not valid + //u = v.rx; //Illegal + //u = v.sy; //Illegal + + + u = glm::vec2(1, 2); + v = glm::vec3(1, 2, 3); + //v.xx = u; //Illegal + v.xy = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 3.0f) ? 0 : 1; + v.xz = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 2.0f) ? 0 : 1; + v.yx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1; + //v.yy = u; //Illegal + v.yz = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1; + v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1; + v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1; + //v.zz = u; //Illegal + + return Error; +} + + +int test_vec3_swizzle3_3() +{ + int Error = 0; + + glm::vec3 v(1, 2, 3); + glm::vec3 u; + + u = v; + Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; + + u = v.xyz; + Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; + u = v.zyx; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + u.zyx = v; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + + u = v.rgb; + Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; + u = v.bgr; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + u.bgr = v; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + + u = v.stp; + Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1; + u = v.pts; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + u.pts = v; + Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1; + + return Error; +} + int main() { int Error = 0; Error += test_vec3_operators(); Error += test_vec3_size(); + Error += test_vec3_swizzle3_2(); + Error += test_vec3_swizzle3_3(); return Error; }