diff --git a/glm/detail/_vectorize.hpp b/glm/detail/_vectorize.hpp index fe065a8c..203213d7 100644 --- a/glm/detail/_vectorize.hpp +++ b/glm/detail/_vectorize.hpp @@ -155,54 +155,6 @@ namespace detail }//namespace detail }//namespace glm -#define VECTORIZE1_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec1 func( \ - tvec1 const & v) \ - { \ - return tvec1( \ - func(v.x)); \ - } - -#define VECTORIZE2_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec2 func( \ - tvec2 const & v) \ - { \ - return tvec2( \ - func(v.x), \ - func(v.y)); \ - } - -#define VECTORIZE3_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec3 func( \ - tvec3 const & v) \ - { \ - return tvec3( \ - func(v.x), \ - func(v.y), \ - func(v.z)); \ - } - -#define VECTORIZE4_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec4 func( \ - tvec4 const & v) \ - { \ - return tvec4( \ - func(v.x), \ - func(v.y), \ - func(v.z), \ - func(v.w)); \ - } - -#define VECTORIZE_VEC(func) \ - VECTORIZE1_VEC(func) \ - VECTORIZE2_VEC(func) \ - VECTORIZE3_VEC(func) \ - VECTORIZE4_VEC(func) - #define VECTORIZE1_VEC_SCA(func) \ template \ GLM_FUNC_QUALIFIER tvec1 func \ @@ -263,66 +215,6 @@ namespace detail VECTORIZE3_VEC_SCA(func) \ VECTORIZE4_VEC_SCA(func) -#define VECTORIZE1_VEC_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec1 func \ - ( \ - tvec1 const & x, \ - tvec1 const & y \ - ) \ - { \ - return tvec1( \ - func(x.x, y.x)); \ - } - -#define VECTORIZE2_VEC_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec2 func \ - ( \ - tvec2 const & x, \ - tvec2 const & y \ - ) \ - { \ - return tvec2( \ - func(x.x, y.x), \ - func(x.y, y.y)); \ - } - -#define VECTORIZE3_VEC_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec3 func \ - ( \ - tvec3 const & x, \ - tvec3 const & y \ - ) \ - { \ - return tvec3( \ - func(x.x, y.x), \ - func(x.y, y.y), \ - func(x.z, y.z)); \ - } - -#define VECTORIZE4_VEC_VEC(func) \ - template \ - GLM_FUNC_QUALIFIER tvec4 func \ - ( \ - tvec4 const & x, \ - tvec4 const & y \ - ) \ - { \ - return tvec4( \ - func(x.x, y.x), \ - func(x.y, y.y), \ - func(x.z, y.z), \ - func(x.w, y.w)); \ - } - -#define VECTORIZE_VEC_VEC(func) \ - VECTORIZE1_VEC_VEC(func) \ - VECTORIZE2_VEC_VEC(func) \ - VECTORIZE3_VEC_VEC(func) \ - VECTORIZE4_VEC_VEC(func) - namespace glm{ namespace detail { diff --git a/glm/gtc/random.hpp b/glm/gtc/random.hpp index 7c4b616f..68074235 100644 --- a/glm/gtc/random.hpp +++ b/glm/gtc/random.hpp @@ -60,8 +60,8 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL genTYpe linearRand( - genTYpe const & Min, - genTYpe const & Max); + genTYpe Min, + genTYpe Max); template class vecType> GLM_FUNC_DECL vecType linearRand( @@ -75,8 +75,8 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL genType gaussRand( - genType const & Mean, - genType const & Deviation); + genType Mean, + genType Deviation); /// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius /// @@ -84,7 +84,7 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL tvec2 circularRand( - T const & Radius); + T Radius); /// Generate a random 3D vector which coordinates are regulary distributed on a sphere of a given radius /// @@ -92,7 +92,7 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL tvec3 sphericalRand( - T const & Radius); + T Radius); /// Generate a random 2D vector which coordinates are regulary distributed within the area of a disk of a given radius /// @@ -100,7 +100,7 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL tvec2 diskRand( - T const & Radius); + T Radius); /// Generate a random 3D vector which coordinates are regulary distributed within the volume of a ball of a given radius /// @@ -108,7 +108,7 @@ namespace glm /// @see gtc_random template GLM_FUNC_DECL tvec3 ballRand( - T const & Radius); + T Radius); /// @} }//namespace glm diff --git a/glm/gtc/random.inl b/glm/gtc/random.inl index 60859871..d2131ff0 100644 --- a/glm/gtc/random.inl +++ b/glm/gtc/random.inl @@ -280,46 +280,22 @@ namespace detail }; }//namespace detail - template class vecType> - GLM_FUNC_QUALIFIER vecType linearRand - ( - vecType const & Min, - vecType const & Max - ) - { - return detail::compute_linearRand::call(Min, Max); - } - - template <> - GLM_FUNC_QUALIFIER float linearRand - ( - float const & Min, - float const & Max - ) + template + GLM_FUNC_QUALIFIER genType linearRand(genType Min, genType Max) { - return detail::compute_linearRand::call( - tvec1(Min), - tvec1(Max)).x; + return detail::compute_linearRand::call( + tvec1(Min), + tvec1(Max)).x; } - template <> - GLM_FUNC_QUALIFIER double linearRand - ( - double const & Min, - double const & Max - ) + template class vecType> + GLM_FUNC_QUALIFIER vecType linearRand(vecType const & Min, vecType const & Max) { - return detail::compute_linearRand::call( - tvec1(Min), - tvec1(Max)).x; + return detail::compute_linearRand::call(Min, Max); } template - GLM_FUNC_QUALIFIER genType gaussRand - ( - genType const & Mean, - genType const & Deviation - ) + GLM_FUNC_QUALIFIER genType gaussRand(genType Mean, genType Deviation) { genType w, x1, x2; @@ -334,13 +310,14 @@ namespace detail return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean; } - VECTORIZE_VEC_VEC(gaussRand) + template class vecType> + GLM_FUNC_QUALIFIER vecType gaussRand(vecType const & Mean, vecType const & Deviation) + { + return detail::functor2::call(gaussRand, Mean, Deviation); + } template - GLM_FUNC_QUALIFIER tvec2 diskRand - ( - T const & Radius - ) + GLM_FUNC_QUALIFIER tvec2 diskRand(T Radius) { tvec2 Result(T(0)); T LenRadius(T(0)); @@ -358,10 +335,7 @@ namespace detail } template - GLM_FUNC_QUALIFIER tvec3 ballRand - ( - T const & Radius - ) + GLM_FUNC_QUALIFIER tvec3 ballRand(T Radius) { tvec3 Result(T(0)); T LenRadius(T(0)); @@ -379,20 +353,14 @@ namespace detail } template - GLM_FUNC_QUALIFIER tvec2 circularRand - ( - T const & Radius - ) + GLM_FUNC_QUALIFIER tvec2 circularRand(T Radius) { T a = linearRand(T(0), T(6.283185307179586476925286766559f)); return tvec2(cos(a), sin(a)) * Radius; } template - GLM_FUNC_QUALIFIER tvec3 sphericalRand - ( - T const & Radius - ) + GLM_FUNC_QUALIFIER tvec3 sphericalRand(T Radius) { T z = linearRand(T(-1), T(1)); T a = linearRand(T(0), T(6.283185307179586476925286766559f)); diff --git a/glm/gtx/fast_exponential.hpp b/glm/gtx/fast_exponential.hpp index cc151457..15641fb0 100644 --- a/glm/gtx/fast_exponential.hpp +++ b/glm/gtx/fast_exponential.hpp @@ -52,42 +52,63 @@ namespace glm /// Faster than the common pow function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL genType fastPow( - genType const & x, - genType const & y); + template + GLM_FUNC_DECL genType fastPow(genType x, genType y); /// Faster than the common pow function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL genTypeT fastPow( - genTypeT const & x, - genTypeU const & y); - + template class vecType> + GLM_FUNC_DECL vecType fastPow(vecType const & x, vecType const & y); + + /// Faster than the common pow function but less accurate. + /// @see gtx_fast_exponential + template + GLM_FUNC_DECL genTypeT fastPow(genTypeT x, genTypeU y); + + /// Faster than the common pow function but less accurate. + /// @see gtx_fast_exponential + template class vecType> + GLM_FUNC_DECL vecType fastPow(vecType const & x); + + /// Faster than the common exp function but less accurate. + /// @see gtx_fast_exponential + template + GLM_FUNC_DECL T fastExp(T x); + /// Faster than the common exp function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL T fastExp(const T& x); - + template class vecType> + GLM_FUNC_DECL vecType fastExp(vecType const & x); + /// Faster than the common log function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL T fastLog(const T& x); + template + GLM_FUNC_DECL T fastLog(T x); /// Faster than the common exp2 function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL T fastExp2(const T& x); - + template class vecType> + GLM_FUNC_DECL vecType fastLog(vecType const & x); + + /// Faster than the common exp2 function but less accurate. + /// @see gtx_fast_exponential + template + GLM_FUNC_DECL T fastExp2(T x); + + /// Faster than the common exp2 function but less accurate. + /// @see gtx_fast_exponential + template class vecType> + GLM_FUNC_DECL vecType fastExp2(vecType const & x); + /// Faster than the common log2 function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL T fastLog2(const T& x); + template + GLM_FUNC_DECL T fastLog2(T x); - /// Faster than the common ln function but less accurate. + /// Faster than the common log2 function but less accurate. /// @see gtx_fast_exponential - template - GLM_FUNC_DECL T fastLn(const T& x); + template class vecType> + GLM_FUNC_DECL vecType fastLog2(vecType const & x); /// @} }//namespace glm diff --git a/glm/gtx/fast_exponential.inl b/glm/gtx/fast_exponential.inl index 0ef5b1ae..babedf3b 100644 --- a/glm/gtx/fast_exponential.inl +++ b/glm/gtx/fast_exponential.inl @@ -11,15 +11,19 @@ namespace glm { // fastPow: template - GLM_FUNC_QUALIFIER genType fastPow(genType const & x, genType const & y) + GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y) { return exp(y * log(x)); } - VECTORIZE_VEC_VEC(fastPow) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastPow(vecType const & x, vecType const & y) + { + return exp(y * log(x)); + } template - GLM_FUNC_QUALIFIER T fastPow(const T x, int y) + GLM_FUNC_QUALIFIER T fastPow(T x, int y) { T f = static_cast(1); for(int i = 0; i < y; ++i) @@ -27,43 +31,19 @@ namespace glm return f; } - template - GLM_FUNC_QUALIFIER tvec2 fastPow( - const tvec2& x, - const tvec2& y) - { - return tvec2( - fastPow(x.x, y.x), - fastPow(x.y, y.y)); - } - - template - GLM_FUNC_QUALIFIER tvec3 fastPow( - const tvec3& x, - const tvec3& y) - { - return tvec3( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z)); - } - - template - GLM_FUNC_QUALIFIER tvec4 fastPow( - const tvec4& x, - const tvec4& y) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastPow(vecType const & x, vecType const & y) { - return tvec4( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z), - fastPow(x.w, y.w)); + vecType Result(uninitialize); + for(detail::component_count_t i = 0; i < detail::component_count(x); ++i) + Result[i] = fastPow(x[i], y[i]); + return Result; } // fastExp // Note: This function provides accurate results only for value between -1 and 1, else avoid it. template - GLM_FUNC_QUALIFIER T fastExp(const T x) + GLM_FUNC_QUALIFIER T fastExp(T x) { // This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower. // return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f)))); @@ -107,11 +87,15 @@ namespace glm } */ - VECTORIZE_VEC(fastExp) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastExp(vecType const & x) + { + return detail::functor1::call(fastExp, x); + } // fastLog template - GLM_FUNC_QUALIFIER genType fastLog(genType const & x) + GLM_FUNC_QUALIFIER genType fastLog(genType x) { return std::log(x); } @@ -125,24 +109,35 @@ namespace glm } */ - VECTORIZE_VEC(fastLog) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastLog(vecType const & x) + { + return detail::functor1::call(fastLog, x); + } //fastExp2, ln2 = 0.69314718055994530941723212145818f template - GLM_FUNC_QUALIFIER genType fastExp2(genType const & x) + GLM_FUNC_QUALIFIER genType fastExp2(genType x) { return fastExp(0.69314718055994530941723212145818f * x); } - VECTORIZE_VEC(fastExp2) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastExp2(vecType const & x) + { + return detail::functor1::call(fastExp2, x); + } // fastLog2, ln2 = 0.69314718055994530941723212145818f template - GLM_FUNC_QUALIFIER genType fastLog2(genType const & x) + GLM_FUNC_QUALIFIER genType fastLog2(genType x) { return fastLog(x) / 0.69314718055994530941723212145818f; } - VECTORIZE_VEC(fastLog2) - + template class vecType> + GLM_FUNC_QUALIFIER vecType fastLog2(vecType const & x) + { + return detail::functor1::call(fastLog2, x); + } }//namespace glm diff --git a/glm/gtx/fast_square_root.hpp b/glm/gtx/fast_square_root.hpp index f62bc278..75f74a01 100644 --- a/glm/gtx/fast_square_root.hpp +++ b/glm/gtx/fast_square_root.hpp @@ -54,12 +54,12 @@ namespace glm //! Faster than the common sqrt function but less accurate. //! From GLM_GTX_fast_square_root extension. template - GLM_FUNC_DECL genType fastSqrt(genType const & x); + GLM_FUNC_DECL genType fastSqrt(genType x); //! Faster than the common inversesqrt function but less accurate. //! From GLM_GTX_fast_square_root extension. template - GLM_FUNC_DECL genType fastInverseSqrt(genType const & x); + GLM_FUNC_DECL genType fastInverseSqrt(genType x); //! Faster than the common inversesqrt function but less accurate. //! From GLM_GTX_fast_square_root extension. @@ -73,8 +73,13 @@ namespace glm //! Faster than the common distance function but less accurate. //! From GLM_GTX_fast_square_root extension. - template - GLM_FUNC_DECL typename genType::value_type fastDistance(genType const & x, genType const & y); + template + GLM_FUNC_DECL genType fastDistance(genType x, genType y); + + //! Faster than the common distance function but less accurate. + //! From GLM_GTX_fast_square_root extension. + template class vecType> + GLM_FUNC_DECL T fastDistance(vecType const & x, vecType const & y); //! Faster than the common normalize function but less accurate. //! From GLM_GTX_fast_square_root extension. diff --git a/glm/gtx/fast_square_root.inl b/glm/gtx/fast_square_root.inl index 31bd02c7..c912c509 100644 --- a/glm/gtx/fast_square_root.inl +++ b/glm/gtx/fast_square_root.inl @@ -11,170 +11,77 @@ namespace glm { // fastSqrt template - GLM_FUNC_QUALIFIER genType fastSqrt - ( - genType const & x - ) + GLM_FUNC_QUALIFIER genType fastSqrt(genType x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'fastSqrt' only accept floating-point input"); return genType(1) / fastInverseSqrt(x); } - VECTORIZE_VEC(fastSqrt) - - // fastInversesqrt - template <> - GLM_FUNC_QUALIFIER float fastInverseSqrt(float const & x) + template class vecType> + GLM_FUNC_QUALIFIER vecType fastSqrt(vecType const & x) { -# ifdef __CUDACC__ // Wordaround for a CUDA compiler bug up to CUDA6 - tvec1 tmp(detail::compute_inversesqrt::call(tvec1(x))); - return tmp.x; -# else - return detail::compute_inversesqrt::call(tvec1(x)).x; -# endif + return detail::functor1::call(fastSqrt, x); } - template <> - GLM_FUNC_QUALIFIER double fastInverseSqrt(double const & x) + // fastInversesqrt + template + GLM_FUNC_QUALIFIER genType fastInverseSqrt(genType x) { # ifdef __CUDACC__ // Wordaround for a CUDA compiler bug up to CUDA6 - tvec1 tmp(detail::compute_inversesqrt::call(tvec1(x))); + tvec1 tmp(detail::compute_inversesqrt::call(tvec1(x))); return tmp.x; # else - return detail::compute_inversesqrt::call(tvec1(x)).x; + return detail::compute_inversesqrt::call(tvec1(x)).x; # endif } - template