diff --git a/glm/core/_vectorize.hpp b/glm/core/_vectorize.hpp new file mode 100644 index 00000000..bfabdf3b --- /dev/null +++ b/glm/core/_vectorize.hpp @@ -0,0 +1,98 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref core +/// @file glm/core/_vectorize.hpp +/// @date 2011-10-14 / 2011-10-14 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////// + +#define VECTORIZE_1PARAM(func) \ + template \ + GLM_FUNC_QUALIFIER detail::tvec2 func( \ + detail::tvec2 const & v) \ + { \ + return detail::tvec2( \ + func(v.x), \ + func(v.y)); \ + } \ + \ + template \ + GLM_FUNC_QUALIFIER detail::tvec3 func( \ + detail::tvec3 const & v) \ + { \ + return detail::tvec3( \ + func(v.x), \ + func(v.y), \ + func(v.z)); \ + } \ + \ + template \ + GLM_FUNC_QUALIFIER detail::tvec4 func( \ + detail::tvec4 const & v) \ + { \ + return detail::tvec4( \ + func(v.x), \ + func(v.y), \ + func(v.z), \ + func(v.w)); \ + } + +#define VECTORIZE_2PARAMS(func) \ + template \ + GLM_FUNC_QUALIFIER detail::tvec2 func \ + ( \ + detail::tvec2 const & x, \ + detail::tvec2 const & y \ + ) \ + { \ + return detail::tvec2( \ + func(x.x, y.x), \ + func(x.y, y.y)); \ + } \ + \ + template \ + GLM_FUNC_QUALIFIER detail::tvec3 func \ + ( \ + detail::tvec3 const & x, \ + detail::tvec3 const & y \ + ) \ + { \ + return detail::tvec3( \ + func(x.x, y.x), \ + func(x.y, y.y), \ + func(x.z, y.z)); \ + } \ + \ + template \ + GLM_FUNC_QUALIFIER detail::tvec4 func \ + ( \ + detail::tvec4 const & x, \ + detail::tvec4 const & y \ + ) \ + { \ + return detail::tvec4( \ + func(x.x, y.x), \ + func(x.y, y.y), \ + func(x.z, y.z), \ + func(x.w, y.w)); \ + } diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index 0d587d66..dfb54431 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -26,6 +26,8 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#include "_vectorize.hpp" + namespace glm{ namespace detail { @@ -60,56 +62,23 @@ namespace detail // abs template - GLM_FUNC_QUALIFIER genFIType abs( - genFIType const & x) + GLM_FUNC_QUALIFIER genFIType abs + ( + genFIType const & x + ) { return detail::Abs_::is_signed>::get(x); } - //template - //GLM_FUNC_QUALIFIER detail::tvec1 abs( - // detail::tvec1 const & v) - //{ - // return detail::tvec1( - // abs(v.x)); - //} - - template - GLM_FUNC_QUALIFIER detail::tvec2 abs( - detail::tvec2 const & v) - { - return detail::tvec2( - abs(v.x), - abs(v.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 abs( - detail::tvec3 const & v) - { - return detail::tvec3( - abs(v.x), - abs(v.y), - abs(v.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 abs( - detail::tvec4 const & v) - { - return detail::tvec4( - abs(v.x), - abs(v.y), - abs(v.z), - abs(v.w)); - } + VECTORIZE_1PARAM(abs) // sign - //Try something like based on x >> 31 to get the sign bit template - GLM_FUNC_QUALIFIER genFIType sign( - genFIType const & x) + GLM_FUNC_QUALIFIER genFIType sign + ( + genFIType const & x + ) { GLM_STATIC_ASSERT( detail::type::is_float || @@ -125,35 +94,7 @@ namespace detail return result; } - template - GLM_FUNC_QUALIFIER detail::tvec2 sign( - detail::tvec2 const & x) - { - return detail::tvec2( - sign(x.x), - sign(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 sign( - detail::tvec3 const & x) - { - return detail::tvec3( - sign(x.x), - sign(x.y), - sign(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 sign( - detail::tvec4 const & x) - { - return detail::tvec4( - sign(x.x), - sign(x.y), - sign(x.z), - sign(x.w)); - } + VECTORIZE_1PARAM(sign) // floor template <> @@ -170,32 +111,7 @@ namespace detail return ::std::floor(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 floor(detail::tvec2 const& x) - { - return detail::tvec2( - floor(x.x), - floor(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 floor(detail::tvec3 const& x) - { - return detail::tvec3( - floor(x.x), - floor(x.y), - floor(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 floor(detail::tvec4 const& x) - { - return detail::tvec4( - floor(x.x), - floor(x.y), - floor(x.z), - floor(x.w)); - } + VECTORIZE_1PARAM(floor) // trunc template @@ -205,32 +121,7 @@ namespace detail return x < 0 ? -floor(-x) : floor(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 trunc(detail::tvec2 const & x) - { - return detail::tvec2( - trunc(x.x), - trunc(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 trunc(detail::tvec3 const & x) - { - return detail::tvec3( - trunc(x.x), - trunc(x.y), - trunc(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 trunc(detail::tvec4 const & x) - { - return detail::tvec4( - trunc(x.x), - trunc(x.y), - trunc(x.z), - trunc(x.w)); - } + VECTORIZE_1PARAM(trunc) // round template @@ -243,32 +134,8 @@ namespace detail return genType(int(x + genType(0.5))); } - template - GLM_FUNC_QUALIFIER detail::tvec2 round(detail::tvec2 const& x) - { - return detail::tvec2( - round(x.x), - round(x.y)); - } + VECTORIZE_1PARAM(round) - template - GLM_FUNC_QUALIFIER detail::tvec3 round(detail::tvec3 const& x) - { - return detail::tvec3( - round(x.x), - round(x.y), - round(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 round(detail::tvec4 const& x) - { - return detail::tvec4( - round(x.x), - round(x.y), - round(x.z), - round(x.w)); - } /* // roundEven template @@ -294,32 +161,7 @@ namespace detail return genType(int(x + RoundValue)); } - template - GLM_FUNC_QUALIFIER detail::tvec2 roundEven(detail::tvec2 const& x) - { - return detail::tvec2( - roundEven(x.x), - roundEven(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 roundEven(detail::tvec3 const& x) - { - return detail::tvec3( - roundEven(x.x), - roundEven(x.y), - roundEven(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 roundEven(detail::tvec4 const& x) - { - return detail::tvec4( - roundEven(x.x), - roundEven(x.y), - roundEven(x.z), - roundEven(x.w)); - } + VECTORIZE_1PARAM(roundEven) // ceil template @@ -330,32 +172,7 @@ namespace detail return ::std::ceil(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 ceil(detail::tvec2 const & x) - { - return detail::tvec2( - ceil(x.x), - ceil(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 ceil(detail::tvec3 const & x) - { - return detail::tvec3( - ceil(x.x), - ceil(x.y), - ceil(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 ceil(detail::tvec4 const & x) - { - return detail::tvec4( - ceil(x.x), - ceil(x.y), - ceil(x.z), - ceil(x.w)); - } + VECTORIZE_1PARAM(ceil) // fract template @@ -369,41 +186,7 @@ namespace detail return x - ::std::floor(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 fract - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - fract(x.x), - fract(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 fract - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - fract(x.x), - fract(x.y), - fract(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 fract - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - fract(x.x), - fract(x.y), - fract(x.z), - fract(x.w)); - } + VECTORIZE_1PARAM(fract) // mod template