From 3308b7583632d2df61b2650251158b6451227a69 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 10 Jul 2018 10:52:47 +0200 Subject: [PATCH] Use initializer lists constructors for mat2 --- glm/detail/setup.hpp | 3 +- glm/detail/type_mat2x2.inl | 135 ++++++++++++++++++++++++++++--------- 2 files changed, 107 insertions(+), 31 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 51b8c680..37563298 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -324,7 +324,7 @@ ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (GLM_COMPILER & GLM_COMPILER_CLANG))) #endif -// N2672 +// N2672 Initializer lists http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm #if GLM_COMPILER & GLM_COMPILER_CLANG # define GLM_HAS_INITIALIZER_LISTS __has_feature(cxx_generalized_initializers) #elif GLM_LANG & GLM_LANG_CXX11_FLAG @@ -333,6 +333,7 @@ # define GLM_HAS_INITIALIZER_LISTS ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ ((GLM_COMPILER & GLM_COMPILER_GCC)) || \ ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC12)) || \ + ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL14)) || \ ((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA75)))) #endif diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index 2dc11d36..dca6658d 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -30,16 +30,26 @@ namespace glm template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 2, T, P> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{m.value[0], m.value[1]} +# endif { - this->value[0] = m.value[0]; - this->value[1] = m.value[1]; +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = m.value[0]; + this->value[1] = m.value[1]; +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(T scalar) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(scalar, 0), col_type(0, scalar)} +# endif { - this->value[0] = col_type(scalar, 0); - this->value[1] = col_type(0, scalar); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(scalar, 0); + this->value[1] = col_type(0, scalar); +# endif } template @@ -48,16 +58,26 @@ namespace glm T const& x0, T const& y0, T const& x1, T const& y1 ) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(x0, y0), col_type(x1, y1)} +# endif { - this->value[0] = col_type(x0, y0); - this->value[1] = col_type(x1, y1); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(x0, y0); + this->value[1] = col_type(x1, y1); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(col_type const& v0, col_type const& v1) +# if GLM_HAS_INITIALIZER_LISTS + : value{v0, v1} +# endif { - this->value[0] = v0; - this->value[1] = v1; +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = v0; + this->value[1] = v1; +# endif } // -- Conversion constructors -- @@ -69,17 +89,27 @@ namespace glm X1 const& x1, Y1 const& y1, X2 const& x2, Y2 const& y2 ) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(static_cast(x1), value_type(y1)), col_type(static_cast(x2), value_type(y2)) } +# endif { - this->value[0] = col_type(static_cast(x1), value_type(y1)); - this->value[1] = col_type(static_cast(x2), value_type(y2)); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(static_cast(x1), value_type(y1)); + this->value[1] = col_type(static_cast(x2), value_type(y2)); +# endif } template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(vec<2, V1, Q> const& v1, vec<2, V2, Q> const& v2) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(v1), col_type(v2)} +# endif { - this->value[0] = col_type(v1); - this->value[1] = col_type(v2); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(v1); + this->value[1] = col_type(v2); +# endif } // -- mat2x2 matrix conversions -- @@ -87,65 +117,110 @@ namespace glm template template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 2, U, P> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 3, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 4, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 3, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 2, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = m[0]; - this->value[1] = m[1]; +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<2, 4, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 2, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = m[0]; - this->value[1] = m[1]; +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<3, 4, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CXX14 mat<2, 2, T, Q>::mat(mat<4, 3, T, Q> const& m) +# if GLM_HAS_INITIALIZER_LISTS + : value{col_type(m[0]), col_type(m[1])} +# endif { - this->value[0] = col_type(m[0]); - this->value[1] = col_type(m[1]); +# if !GLM_HAS_INITIALIZER_LISTS + this->value[0] = col_type(m[0]); + this->value[1] = col_type(m[1]); +# endif } // -- Accesses --