From f70ee7ef288134330420696a2bf75f463b56bf8e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 25 Oct 2014 00:08:10 +0200 Subject: [PATCH] Vectorize many common functions --- glm/detail/_vectorize.hpp | 49 ++++++- glm/detail/func_common.hpp | 71 +++++---- glm/detail/func_common.inl | 292 +++++++++---------------------------- 3 files changed, 159 insertions(+), 253 deletions(-) diff --git a/glm/detail/_vectorize.hpp b/glm/detail/_vectorize.hpp index b5fde689..fe065a8c 100644 --- a/glm/detail/_vectorize.hpp +++ b/glm/detail/_vectorize.hpp @@ -42,7 +42,7 @@ namespace detail template struct functor1 { - GLM_FUNC_QUALIFIER static tvec1 call(T (*Func) (T x), tvec1 const & v) + GLM_FUNC_QUALIFIER static tvec1 call(R (*Func) (T x), tvec1 const & v) { return tvec1(Func(v.x)); } @@ -51,7 +51,7 @@ namespace detail template struct functor1 { - GLM_FUNC_QUALIFIER static tvec2 call(T (*Func) (T x), tvec2 const & v) + GLM_FUNC_QUALIFIER static tvec2 call(R (*Func) (T x), tvec2 const & v) { return tvec2(Func(v.x), Func(v.y)); } @@ -60,7 +60,7 @@ namespace detail template struct functor1 { - GLM_FUNC_QUALIFIER static tvec3 call(T (*Func) (T x), tvec3 const & v) + GLM_FUNC_QUALIFIER static tvec3 call(R (*Func) (T x), tvec3 const & v) { return tvec3(Func(v.x), Func(v.y), Func(v.z)); } @@ -69,7 +69,7 @@ namespace detail template struct functor1 { - GLM_FUNC_QUALIFIER static tvec4 call(T (*Func) (T x), tvec4 const & v) + GLM_FUNC_QUALIFIER static tvec4 call(R (*Func) (T x), tvec4 const & v) { return tvec4(Func(v.x), Func(v.y), Func(v.z), Func(v.w)); } @@ -113,6 +113,45 @@ namespace detail return tvec4(Func(a.x, b.x), Func(a.y, b.y), Func(a.z, b.z), Func(a.w, b.w)); } }; + + template class vecType> + struct functor2_vec_sca{}; + + template + struct functor2_vec_sca + { + GLM_FUNC_QUALIFIER static tvec1 call(T (*Func) (T x, T y), tvec1 const & a, T b) + { + return tvec1(Func(a.x, b)); + } + }; + + template + struct functor2_vec_sca + { + GLM_FUNC_QUALIFIER static tvec2 call(T (*Func) (T x, T y), tvec2 const & a, T b) + { + return tvec2(Func(a.x, b), Func(a.y, b)); + } + }; + + template + struct functor2_vec_sca + { + GLM_FUNC_QUALIFIER static tvec3 call(T (*Func) (T x, T y), tvec3 const & a, T b) + { + return tvec3(Func(a.x, b), Func(a.y, b), Func(a.z, b)); + } + }; + + template + struct functor2_vec_sca + { + GLM_FUNC_QUALIFIER static tvec4 call(T (*Func) (T x, T y), tvec4 const & a, T b) + { + return tvec4(Func(a.x, b), Func(a.y, b), Func(a.z, b), Func(a.w, b)); + } + }; }//namespace detail }//namespace glm @@ -169,7 +208,7 @@ namespace detail GLM_FUNC_QUALIFIER tvec1 func \ ( \ tvec1 const & x, \ - typename tvec1::value_type const & y \ + T y \ ) \ { \ return tvec1( \ diff --git a/glm/detail/func_common.hpp b/glm/detail/func_common.hpp index 58a4d8ae..7989a023 100644 --- a/glm/detail/func_common.hpp +++ b/glm/detail/func_common.hpp @@ -136,15 +136,11 @@ namespace glm template GLM_FUNC_DECL genType mod(genType x, genType y); - /// Modulus. Returns x - y * floor(x / y) - /// for each component in x using the floating point value y. - /// - /// @tparam genType Floating-point scalar or vector types. - /// - /// @see GLSL mod man page - /// @see GLSL 4.20.8 specification, section 8.3 Common Functions - template - GLM_FUNC_DECL genType mod(genType const & x, typename genType::value_type const & y); + template class vecType> + GLM_FUNC_DECL vecType mod(vecType const & x, T y); + + template class vecType> + GLM_FUNC_DECL vecType mod(vecType const & x, vecType const & y); /// Returns the fractional part of x and sets i to the integer /// part (as a whole number floating point value). Both the @@ -156,7 +152,7 @@ namespace glm /// @see GLSL modf man page /// @see GLSL 4.20.8 specification, section 8.3 Common Functions template - GLM_FUNC_DECL genType modf(genType const & x, genType & i); + GLM_FUNC_DECL genType modf(genType x, genType & i); /// Returns y if y < x; otherwise, it returns x. /// @@ -167,8 +163,11 @@ namespace glm template GLM_FUNC_DECL genType min(genType x, genType y); - template - GLM_FUNC_DECL genType min(genType const & x, typename genType::value_type const & y); + template class vecType> + GLM_FUNC_DECL vecType min(vecType const & x, T y); + + template class vecType> + GLM_FUNC_DECL vecType min(vecType const & x, vecType const & y); /// Returns y if x < y; otherwise, it returns x. /// @@ -179,8 +178,11 @@ namespace glm template GLM_FUNC_DECL genType max(genType x, genType y); - template - GLM_FUNC_DECL genType max(genType const & x, typename genType::value_type const & y); + template class vecType> + GLM_FUNC_DECL vecType max(vecType const & x, T y); + + template class vecType> + GLM_FUNC_DECL vecType max(vecType const & x, vecType const & y); /// Returns min(max(x, minVal), maxVal) for each component in x /// using the floating-point values minVal and maxVal. @@ -190,10 +192,13 @@ namespace glm /// @see GLSL clamp man page /// @see GLSL 4.20.8 specification, section 8.3 Common Functions template - GLM_FUNC_DECL genType clamp(genType const & x, genType const & minVal, genType const & maxVal); + GLM_FUNC_DECL genType clamp(genType x, genType minVal, genType maxVal); - template - GLM_FUNC_DECL genType clamp(genType const & x, typename genType::value_type const & minVal, typename genType::value_type const & maxVal); + template class vecType> + GLM_FUNC_DECL vecType clamp(vecType const & x, T minVal, T maxVal); + + template class vecType> + GLM_FUNC_DECL vecType clamp(vecType const & x, vecType const & minVal, vecType const & maxVal); /// If genTypeU is a floating scalar or vector: /// Returns x * (1.0 - a) + y * a, i.e., the linear blend of @@ -241,24 +246,31 @@ namespace glm GLM_FUNC_DECL vecType mix(vecType const & x, vecType const & y, vecType const & a); template class vecType> - GLM_FUNC_DECL vecType mix(vecType const & x, vecType const & y, U const & a); + GLM_FUNC_DECL vecType mix(vecType const & x, vecType const & y, U a); template - GLM_FUNC_DECL genTypeT mix(genTypeT const & x, genTypeT const & y, genTypeU const & a); + GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a); /// Returns 0.0 if x < edge, otherwise it returns 1.0 for each component of a genType. /// /// @see GLSL step man page /// @see GLSL 4.20.8 specification, section 8.3 Common Functions template - GLM_FUNC_DECL genType step(genType const & edge, genType const & x); + GLM_FUNC_DECL genType step(genType edge, genType x); /// Returns 0.0 if x < edge, otherwise it returns 1.0. /// /// @see GLSL step man page /// @see GLSL 4.20.8 specification, section 8.3 Common Functions template