From 1fb8bec873f3dc499f563f6ff4c6698d83703dcd Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 6 Nov 2012 01:23:14 +0100 Subject: [PATCH] Fixed abs function for half based types --- glm/core/func_common.inl | 56 ++++++++++++++++++++-------------------- glm/gtc/half_float.hpp | 38 +++++++++++++++++++-------- glm/gtc/half_float.inl | 32 ++++++++++++++++++++++- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index be1308e9..a47f0cc3 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -60,19 +60,19 @@ namespace detail // abs template - GLM_FUNC_QUALIFIER genFIType abs + GLM_FUNC_QUALIFIER genFIType abs ( genFIType const & x ) - { + { return detail::Abs_::is_signed>::get(x); - } + } VECTORIZE_VEC(abs) - // sign + // sign //Try something like based on x >> 31 to get the sign bit - template + template GLM_FUNC_QUALIFIER genFIType sign ( genFIType const & x @@ -81,43 +81,43 @@ namespace detail GLM_STATIC_ASSERT( detail::type::is_float || detail::type::is_int, "'sign' only accept signed inputs"); - + genFIType result; if(x > genFIType(0)) - result = genFIType(1); - else if(x < genFIType(0)) - result = genFIType(-1); - else - result = genFIType(0); - return result; + result = genFIType(1); + else if(x < genFIType(0)) + result = genFIType(-1); + else + result = genFIType(0); + return result; } VECTORIZE_VEC(sign) - // floor - template <> + // floor + template <> GLM_FUNC_QUALIFIER detail::half floor(detail::half const & x) - { - return detail::half(::std::floor(float(x))); - } + { + return detail::half(::std::floor(float(x))); + } - template - GLM_FUNC_QUALIFIER genType floor(genType const & x) - { + template + GLM_FUNC_QUALIFIER genType floor(genType const & x) + { GLM_STATIC_ASSERT(detail::type::is_float, "'floor' only accept floating-point inputs"); - return ::std::floor(x); - } + return ::std::floor(x); + } VECTORIZE_VEC(floor) - // trunc - template - GLM_FUNC_QUALIFIER genType trunc(genType const & x) - { + // trunc + template + GLM_FUNC_QUALIFIER genType trunc(genType const & x) + { GLM_STATIC_ASSERT(detail::type::is_float, "'trunc' only accept floating-point inputs"); - return x < 0 ? -floor(-x) : floor(x); - } + return x < 0 ? -floor(-x) : floor(x); + } VECTORIZE_VEC(trunc) diff --git a/glm/gtc/half_float.hpp b/glm/gtc/half_float.hpp index 5eb438d6..ac1d65c5 100644 --- a/glm/gtc/half_float.hpp +++ b/glm/gtc/half_float.hpp @@ -22,7 +22,7 @@ /// /// @ref gtc_half_float /// @file glm/gtc/half_float.hpp -/// @date 2009-04-29 / 2011-06-05 +/// @date 2009-04-29 / 2012-11-06 /// @author Christophe Riccio /// /// @see core (dependence) @@ -55,7 +55,7 @@ namespace detail typedef half value_type; typedef std::size_t size_type; - GLM_FUNC_DECL size_type length() const; + GLM_FUNC_DECL size_type length() const; static GLM_FUNC_DECL size_type value_size(); typedef tvec2 type; @@ -148,7 +148,7 @@ namespace detail enum ctor{null}; typedef half value_type; typedef std::size_t size_type; - GLM_FUNC_DECL size_type length() const; + GLM_FUNC_DECL size_type length() const; static GLM_FUNC_DECL size_type value_size(); typedef tvec3 type; @@ -245,7 +245,7 @@ namespace detail enum ctor{null}; typedef half value_type; typedef std::size_t size_type; - GLM_FUNC_DECL size_type length() const; + GLM_FUNC_DECL size_type length() const; static GLM_FUNC_DECL size_type value_size(); typedef tvec4 type; @@ -371,7 +371,7 @@ namespace detail /// 2 * 2 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat2x2 hmat2; - + /// 3 * 3 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat3x3 hmat3; @@ -383,11 +383,11 @@ namespace detail /// 2 * 2 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat2x2 hmat2x2; - + /// 2 * 3 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat2x3 hmat2x3; - + /// 2 * 4 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat2x4 hmat2x4; @@ -395,11 +395,11 @@ namespace detail /// 3 * 2 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat3x2 hmat3x2; - + /// 3 * 3 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat3x3 hmat3x3; - + /// 3 * 4 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat3x4 hmat3x4; @@ -411,11 +411,27 @@ namespace detail /// 4 * 3 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat4x3 hmat4x3; - + /// 4 * 4 matrix of half-precision floating-point numbers. /// @see gtc_half_float typedef detail::tmat4x4 hmat4x4; - + + /// Returns the absolute value of a half-precision floating-point value + /// @see gtc_half_float + half abs(half const & x); + + /// Returns the absolute value of a half-precision floating-point two dimensional vector + /// @see gtc_half_float + hvec2 abs(hvec2 const & x); + + /// Returns the absolute value of a half-precision floating-point three dimensional vector + /// @see gtc_half_float + hvec3 abs(hvec3 const & x); + + /// Returns the absolute value of a half-precision floating-point four dimensional vector + /// @see gtc_half_float + hvec4 abs(hvec4 const & x); + /// @} }// namespace glm diff --git a/glm/gtc/half_float.inl b/glm/gtc/half_float.inl index 8a4a2c38..241def44 100644 --- a/glm/gtc/half_float.inl +++ b/glm/gtc/half_float.inl @@ -22,7 +22,7 @@ /// /// @ref gtc_half_float /// @file glm/gtc/half_float.inl -/// @date 2009-04-29 / 2011-06-05 +/// @date 2009-04-29 / 2012-11-06 /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// @@ -1006,4 +1006,34 @@ namespace detail #endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98) }//namespace detail + + GLM_FUNC_QUALIFIER half abs(half const & x) + { + return float(x) >= float(0) ? x : -x; + } + + GLM_FUNC_QUALIFIER hvec2 abs(hvec2 const & v) + { + return hvec2( + float(v.x) >= float(0) ? v.x : -v.x, + float(v.y) >= float(0) ? v.y : -v.y); + } + + GLM_FUNC_QUALIFIER hvec3 abs(hvec3 const & v) + { + return hvec3( + float(v.x) >= float(0) ? v.x : -v.x, + float(v.y) >= float(0) ? v.y : -v.y, + float(v.z) >= float(0) ? v.z : -v.z); + } + + GLM_FUNC_QUALIFIER hvec4 abs(hvec4 const & v) + { + return hvec4( + float(v.x) >= float(0) ? v.x : -v.x, + float(v.y) >= float(0) ? v.y : -v.y, + float(v.z) >= float(0) ? v.z : -v.z, + float(v.w) >= float(0) ? v.w : -v.w); + } + }//namespace glm