From f09aa1c17779236ce1dcafe46231606394af239c Mon Sep 17 00:00:00 2001 From: athile Date: Tue, 20 Sep 2011 20:17:52 -0400 Subject: [PATCH 1/2] 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; } From 6022ff616e4856d10b5c5946f710dd6bbc9f139f Mon Sep 17 00:00:00 2001 From: athile Date: Tue, 20 Sep 2011 22:21:15 -0400 Subject: [PATCH 2/2] Swizzle updates to handle non-POD types (e.g. hvec3) correctly --- glm/core/_swizzle.hpp | 36 +++++++++++++++----------- glm/core/type_vec2.hpp | 8 +++--- glm/core/type_vec3.hpp | 8 +++--- glm/core/type_vec4.hpp | 8 +++--- test/core/core_type_vec3.cpp | 49 +++++++++++++++++++++++++++++++++--- 5 files changed, 80 insertions(+), 29 deletions(-) diff --git a/glm/core/_swizzle.hpp b/glm/core/_swizzle.hpp index 3b154c47..e5dcf492 100644 --- a/glm/core/_swizzle.hpp +++ b/glm/core/_swizzle.hpp @@ -53,7 +53,7 @@ namespace detail for (int i = 0; i < N; ++i) t[i] = that[i]; for (int i = 0; i < N; ++i) - e[offset_dst[i]] = t[i]; + elem(offset_dst[i]) = t[i]; return *this; } @@ -63,12 +63,18 @@ namespace detail static const int offset_dst[4] = { E0, E1, E2, E3 }; for (int i = 0; i < N; ++i) - e[offset_dst[i]] = t; + elem(offset_dst[i]) = t; return *this; } - Type e[N]; + protected: + Type& elem (size_t i) { return (reinterpret_cast(_buffer))[i]; } + + // Use an opaque buffer to *ensure* the compiler doesn't call a constructor. + // Otherwise, a vec4 containg all swizzles might end up with 1000s of + // constructor calls + char _buffer[sizeof(Type) * N]; }; template @@ -76,8 +82,10 @@ namespace detail { struct Stub {}; swizzle_base& operator= (const Stub& that) {} - - Type e[N]; + + protected: + Type& elem (size_t i) { return (reinterpret_cast(_buffer))[i]; } + char _buffer[sizeof(Type) * N]; }; //! Internal class for implementing swizzle operators @@ -85,7 +93,7 @@ namespace detail struct swizzle2 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1]); } + operator P () { return P(this->elem(E0), this->elem(E1)); } }; //! Internal class for implementing swizzle operators @@ -93,7 +101,7 @@ namespace detail struct swizzle2_3 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2)); } }; //! Internal class for implementing swizzle operators @@ -101,7 +109,7 @@ namespace detail 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]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3)); } }; //! Internal class for implementing swizzle operators @@ -109,7 +117,7 @@ namespace detail struct swizzle3 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2)); } }; //! Internal class for implementing swizzle operators @@ -117,7 +125,7 @@ namespace detail struct swizzle3_2 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1]); } + operator P () { return P(this->elem(E0), this->elem(E1)); } }; //! Internal class for implementing swizzle operators @@ -125,7 +133,7 @@ namespace detail 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]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3)); } }; //! Internal class for implementing swizzle operators @@ -133,7 +141,7 @@ namespace detail 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]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3)); } }; //! Internal class for implementing swizzle operators @@ -141,7 +149,7 @@ namespace detail struct swizzle4_2 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1]); } + operator P () { return P(this->elem(E0), this->elem(E1)); } }; @@ -150,7 +158,7 @@ namespace detail struct swizzle4_3 : public swizzle_base { using swizzle_base::operator=; - operator P () { return P(this->e[E0], this->e[E1], this->e[E2]); } + operator P () { return P(this->elem(E0), this->elem(E1), this->elem(E2)); } }; }//namespace detail diff --git a/glm/core/type_vec2.hpp b/glm/core/type_vec2.hpp index 0286bdd9..3695becd 100644 --- a/glm/core/type_vec2.hpp +++ b/glm/core/type_vec2.hpp @@ -48,10 +48,6 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - 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) @@ -61,6 +57,10 @@ namespace detail _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) + + struct{value_type r, g;}; + struct{value_type s, t;}; + struct{value_type x, y;}; }; # 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 b6991a46..6c4acf01 100644 --- a/glm/core/type_vec3.hpp +++ b/glm/core/type_vec3.hpp @@ -48,10 +48,6 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - 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) @@ -61,6 +57,10 @@ namespace detail _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) + + struct{value_type r, g, b;}; + struct{value_type s, t, p;}; + struct{value_type x, y, z;}; }; # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) union {value_type x, r, s;}; diff --git a/glm/core/type_vec4.hpp b/glm/core/type_vec4.hpp index ae004dc7..898faab0 100644 --- a/glm/core/type_vec4.hpp +++ b/glm/core/type_vec4.hpp @@ -48,10 +48,6 @@ namespace detail # elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT) union { - 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) @@ -61,6 +57,10 @@ namespace detail _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) + + struct{value_type r, g, b, a;}; + struct{value_type s, t, p, q;}; + struct{value_type x, y, z, w;}; }; # 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 573d1777..0334859a 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -8,6 +8,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #include +#include static int test_vec3_operators() { @@ -91,18 +92,17 @@ int test_vec3_swizzle3_2() 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; @@ -126,6 +126,48 @@ int test_vec3_swizzle3_3() 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 test_vec3_swizzle_half() +{ + int Error = 0; + + glm::half a1(1); + glm::half b1(2); + glm::half c1(3); + glm::hvec3 v(a1, b1, c1); + glm::hvec3 u; + + float c = v.x; + float d = v.y; + u = v; + + float a = u.x; + float b = u.y; + 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; } @@ -138,6 +180,7 @@ int main() Error += test_vec3_size(); Error += test_vec3_swizzle3_2(); Error += test_vec3_swizzle3_3(); + Error += test_vec3_swizzle_half(); return Error; }