From 10dc67e2b5eb520b49eaddb918630d87415eb3f6 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 1 Sep 2016 23:32:12 +0200 Subject: [PATCH] - Added GLM_FORCE_UNRESTRICTED_GENTYPE allowing non basic genType #543 --- glm/detail/setup.hpp | 21 ++++++++++++++++++--- glm/detail/type_vec1.hpp | 10 +++++----- glm/detail/type_vec2.hpp | 10 +++++----- glm/detail/type_vec3.hpp | 12 ++++++------ glm/detail/type_vec4.hpp | 10 +++++----- glm/detail/type_vec4_simd.inl | 4 ++-- readme.md | 2 ++ test/core/core_func_swizzle.cpp | 2 +- test/core/core_type_vec1.cpp | 6 +++--- test/core/core_type_vec2.cpp | 6 +++--- test/core/core_type_vec3.cpp | 6 +++--- test/core/core_type_vec4.cpp | 6 +++--- 12 files changed, 56 insertions(+), 39 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 4fe783a4..c8973989 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -524,11 +524,21 @@ /////////////////////////////////////////////////////////////////////////////////// // Swizzle operators -// User defines: GLM_SWIZZLE +// User defines: GLM_FORCE_SWIZZLE + +#define GLM_SWIZZLE_ENABLED 1 +#define GLM_SWIZZLE_DISABLE 0 +#if defined(GLM_FORCE_SWIZZLE) || defined(GLM_SWIZZLE) +#undef GLM_SWIZZLE +#define GLM_SWIZZLE GLM_SWIZZLE_ENABLED +#else +#undef GLM_SWIZZLE +#define GLM_SWIZZLE GLM_SWIZZLE_DISABLE +#endif #if defined(GLM_MESSAGES) && !defined(GLM_MESSAGE_SWIZZLE_DISPLAYED) # define GLM_MESSAGE_SWIZZLE_DISPLAYED -# if defined(GLM_SWIZZLE) +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED # pragma message("GLM: Swizzling operators enabled") # else # pragma message("GLM: Swizzling operators disabled, #define GLM_SWIZZLE to enable swizzle operators") @@ -551,6 +561,11 @@ # define GLM_DEPTH_CLIP_SPACE GLM_DEPTH_NEGATIVE_ONE_TO_ONE #endif +/////////////////////////////////////////////////////////////////////////////////// +// Allows using not basic types as genType + +// #define GLM_FORCE_UNRESTRICTED_GENTYPE + /////////////////////////////////////////////////////////////////////////////////// // Coordinate system, define GLM_FORCE_LEFT_HANDED before including GLM // to use left handed coordinate system by default. @@ -617,7 +632,7 @@ # define GLM_VECTOR_CALL #endif//GLM_COMPILER -#if GLM_HAS_DEFAULTED_FUNCTIONS +#if GLM_HAS_DEFAULTED_FUNCTIONS && !defined(GLM_FORCE_UNRESTRICTED_GENTYPE) # define GLM_DEFAULT = default # ifdef GLM_FORCE_NO_CTOR_INIT # define GLM_DEFAULT_CTOR = default diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index dff3140d..1a817f66 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -5,7 +5,7 @@ #include "../fwd.hpp" #include "type_vec.hpp" -#ifdef GLM_SWIZZLE +#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED # if GLM_HAS_UNRESTRICTED_UNIONS # include "_swizzle.hpp" # else @@ -44,7 +44,7 @@ namespace glm T r; T s; /* -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, x) _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, r) _GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, s) @@ -66,7 +66,7 @@ namespace glm # else union {T x, r, s;}; /* -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, P, tvec2, tvec2, tvec3, tvec4) # endif//GLM_SWIZZLE*/ # endif @@ -110,13 +110,13 @@ namespace glm // -- Swizzle constructors -- /* -# if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) +# if(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)) template GLM_FUNC_DECL tvec1(detail::_swizzle<1, T, P, tvec1, E0, -1,-2,-3> const & that) { *this = that(); } -# endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) +# endif//(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)) */ // -- Unary arithmetic operators -- diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 718919e4..90904345 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -4,7 +4,7 @@ #pragma once #include "type_vec.hpp" -#ifdef GLM_SWIZZLE +#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED # if GLM_HAS_UNRESTRICTED_UNIONS # include "_swizzle.hpp" # else @@ -43,7 +43,7 @@ namespace glm struct{ T r, g; }; struct{ T s, t; }; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, x, y) _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, r, g) _GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, s, t) @@ -67,7 +67,7 @@ namespace glm union {T x, r, s;}; union {T y, g, t;}; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, tvec2, tvec2, tvec3, tvec4) # endif//GLM_SWIZZLE # endif @@ -116,13 +116,13 @@ namespace glm GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec2(tvec2 const & v); // -- Swizzle constructors -- -# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) template GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, glm::tvec2, E0, E1,-1,-2> const& that) { *this = that(); } -# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) // -- Unary arithmetic operators -- diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 79d9ee32..e1d2f949 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -4,13 +4,13 @@ #pragma once #include "type_vec.hpp" -#ifdef GLM_SWIZZLE +#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED # if GLM_HAS_UNRESTRICTED_UNIONS # include "_swizzle.hpp" # else # include "_swizzle_func.hpp" # endif -#endif //GLM_SWIZZLE +#endif //GLM_SWIZZLE == GLM_SWIZZLE_ENABLED #include namespace glm @@ -43,7 +43,7 @@ namespace glm struct{ T r, g, b; }; struct{ T s, t, p; }; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, x, y, z) _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, r, g, b) _GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, s, t, p) @@ -67,7 +67,7 @@ namespace glm union { T y, g, t; }; union { T z, b, p; }; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, tvec3, tvec2, tvec3, tvec4) # endif//GLM_SWIZZLE # endif//GLM_LANG @@ -125,7 +125,7 @@ namespace glm GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec3(tvec3 const & v); // -- Swizzle constructors -- -# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) template GLM_FUNC_DECL tvec3(detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & that) { @@ -143,7 +143,7 @@ namespace glm { *this = tvec3(scalar, v()); } -# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) // -- Unary arithmetic operators -- diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 8e0de77a..97daf350 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -4,7 +4,7 @@ #pragma once #include "type_vec.hpp" -#ifdef GLM_SWIZZLE +#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED # if GLM_HAS_UNRESTRICTED_UNIONS # include "_swizzle.hpp" # else @@ -45,7 +45,7 @@ namespace glm typename detail::storage::value>::type data; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w) _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, r, g, b, a) _GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, s, t, p, q) @@ -70,7 +70,7 @@ namespace glm union { T z, b, p; }; union { T w, a, q; }; -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, tvec4, tvec2, tvec3, tvec4) # endif//GLM_SWIZZLE # endif @@ -146,7 +146,7 @@ namespace glm GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec4(tvec4 const& v); // -- Swizzle constructors -- -# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) template GLM_FUNC_DECL tvec4(detail::_swizzle<4, T, P, glm::tvec4, E0, E1, E2, E3> const & that) { @@ -188,7 +188,7 @@ namespace glm { *this = tvec4(x, v()); } -# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED) // -- Unary arithmetic operators -- diff --git a/glm/detail/type_vec4_simd.inl b/glm/detail/type_vec4_simd.inl index 97b65f44..6ae818f5 100644 --- a/glm/detail/type_vec4_simd.inl +++ b/glm/detail/type_vec4_simd.inl @@ -6,7 +6,7 @@ namespace glm{ namespace detail { -# ifdef GLM_SWIZZLE +# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED template struct _swizzle_base1<4, float, P, glm::tvec4, E0,E1,E2,E3, true> : public _swizzle_base0 { @@ -49,7 +49,7 @@ namespace detail return Result; } }; -# endif//GLM_SWIZZLE +# endif// GLM_SWIZZLE == GLM_SWIZZLE_ENABLED template struct compute_vec4_add diff --git a/readme.md b/readme.md index 920b1f25..04ab2e46 100644 --- a/readme.md +++ b/readme.md @@ -68,6 +68,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added GTC_functions extension - Added quaternion version of isnan and isinf #521 - Added lowestBitValue to GTX_bit #536 +- Added GLM_FORCE_UNRESTRICTED_GENTYPE allowing non basic genType #543 ##### Improvements: - Improved SIMD and swizzle operators interactions with GCC and Clang #474 @@ -99,6 +100,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Deprecated GLM_GTX_simd_vec4 extension - Deprecated GLM_GTX_simd_mat4 extension - Deprecated GLM_GTX_simd_quat extension +- Deprecated GLM_SWIZZLE, use GLM_FORCE_SWIZZLE instead -------------------------------------------------------------------------------- #### [GLM 0.9.7.6](https://github.com/g-truc/glm/releases/tag/0.9.7.6) - 2016-07-16 diff --git a/test/core/core_func_swizzle.cpp b/test/core/core_func_swizzle.cpp index 09fc0f3f..c12ed47b 100644 --- a/test/core/core_func_swizzle.cpp +++ b/test/core/core_func_swizzle.cpp @@ -1,5 +1,5 @@ #define GLM_MESSAGES -#define GLM_SWIZZLE +#define GLM_FORCE_SWIZZLE #include int test_ivec2_swizzle() diff --git a/test/core/core_type_vec1.cpp b/test/core/core_type_vec1.cpp index a023de6e..9177e380 100644 --- a/test/core/core_type_vec1.cpp +++ b/test/core/core_type_vec1.cpp @@ -1,4 +1,4 @@ -#define GLM_SWIZZLE +#define GLM_FORCE_SWIZZLE #include #include #include @@ -65,7 +65,7 @@ int test_vec1_ctor() } #endif */ -#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec2 A = glm::vec2(1.0f, 2.0f); glm::vec2 B = A.xy; @@ -76,7 +76,7 @@ int test_vec1_ctor() Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, D)) ? 0 : 1; } -#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec2 A = glm::vec2(2.0f); diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 48da72a2..af7997af 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -1,4 +1,4 @@ -#define GLM_SWIZZLE +#define GLM_FORCE_SWIZZLE #include #include #include @@ -230,7 +230,7 @@ int test_vec2_ctor() } #endif -#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec2 A = glm::vec2(1.0f, 2.0f); glm::vec2 B = A.xy; @@ -241,7 +241,7 @@ int test_vec2_ctor() Error += glm::all(glm::equal(A, C)) ? 0 : 1; Error += glm::all(glm::equal(A, D)) ? 0 : 1; } -#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec2 A = glm::vec2(2.0f); diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index cbce6ba2..e6b894c7 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -1,4 +1,4 @@ -#define GLM_SWIZZLE +#define GLM_FORCE_SWIZZLE #include #include #include @@ -40,7 +40,7 @@ int test_vec3_ctor() } #endif -#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) +#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)) { glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); glm::vec3 B = A.xyz; @@ -59,7 +59,7 @@ int test_vec3_ctor() Error += glm::all(glm::equal(A, G)) ? 0 : 1; Error += glm::all(glm::equal(A, H)) ? 0 : 1; } -#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)) +#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)) { glm::vec3 A(1); diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 4d78c7d7..86e302c7 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -1,5 +1,5 @@ #define GLM_FORCE_ALIGNED -#define GLM_SWIZZLE +#define GLM_FORCE_SWIZZLE #include #include #include @@ -68,7 +68,7 @@ int test_vec4_ctor() } #endif -#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); glm::vec4 B = A.xyzw; @@ -97,7 +97,7 @@ int test_vec4_ctor() Error += glm::all(glm::equal(A, L)) ? 0 : 1; Error += glm::all(glm::equal(A, M)) ? 0 : 1; } -#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE) +#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE) { glm::vec4 A(1);