diff --git a/glm/detail/func_vector_relational.inl b/glm/detail/func_vector_relational.inl index 83045a65..c6cee24b 100644 --- a/glm/detail/func_vector_relational.inl +++ b/glm/detail/func_vector_relational.inl @@ -14,10 +14,15 @@ namespace detail { enum relational_type { + EQUAL, + NOT_EQUAL, LESS, LESS_EQUAL, GREATER, - GREATER_EQUAL + GREATER_EQUAL, + ANY, + ALL, + NOT }; template @@ -27,6 +32,26 @@ namespace detail GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1); }; + template <> + struct relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1) + { + return Src0 == Src1; + } + }; + + template <> + struct relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1) + { + return Src0 != Src1; + } + }; + template <> struct relational { @@ -67,6 +92,59 @@ namespace detail } }; + template <> + struct relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1) + { + return Src0 || Src1; + } + }; + + template <> + struct relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T Src1) + { + return Src0 && Src1; + } + }; + + template <> + struct relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static bool call(T Src0, T) + { + return !Src0; + } + }; + + + + template + struct reduce_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(bool& Dst, vecType const& Src) + { + Dst = relational::call(Dst, Src[I]); + reduce_relational::call(Dst, Src); + } + }; + + template + struct reduce_relational + { + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR static void call(bool&, vecType const&) + {} + }; + + + template struct loop_relational { @@ -120,47 +198,42 @@ namespace detail } template - GLM_FUNC_QUALIFIER vec equal(vec const& x, vec const& y) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec equal(vec const& x, vec const& y) { vec Result GLM_BUG_VC_INIT; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = detail::compute_equal::is_iec559>::call(x[i], y[i]); + detail::loop_relational<0, L, detail::EQUAL>::call(Result, x, y); return Result; } template - GLM_FUNC_QUALIFIER vec notEqual(vec const& x, vec const& y) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(vec const& x, vec const& y) { vec Result GLM_BUG_VC_INIT; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = !detail::compute_equal::is_iec559>::call(x[i], y[i]); + detail::loop_relational<0, L, detail::NOT_EQUAL>::call(Result, x, y); return Result; } template - GLM_FUNC_QUALIFIER bool any(vec const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool any(vec const& v) { bool Result = false; - for(length_t i = 0; i < v.length(); ++i) - Result = Result || v[i]; + detail::reduce_relational<0, L, detail::ANY>::call(Result, v); return Result; } template - GLM_FUNC_QUALIFIER bool all(vec const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool all(vec const& v) { bool Result = true; - for(length_t i = 0; i < v.length(); ++i) - Result = Result && v[i]; + detail::reduce_relational<0, L, detail::ALL>::call(Result, v); return Result; } template - GLM_FUNC_QUALIFIER vec not_(vec const& v) + GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec not_(vec const& v) { vec Result; - for(length_t i = 0; i < v.length(); ++i) - Result[i] = !v[i]; + detail::loop_relational<0, L, detail::NOT>::call(Result, v, v); return Result; } }//namespace glm diff --git a/glm/detail/type_int.hpp b/glm/detail/type_int.hpp index c8b1d150..c3c0b7e2 100644 --- a/glm/detail/type_int.hpp +++ b/glm/detail/type_int.hpp @@ -258,28 +258,20 @@ namespace detail /// @see GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier typedef detail::highp_uint_t highp_uint; -#if(!defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT)) - typedef mediump_int int_t; -#elif(defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT)) - typedef highp_int int_t; -#elif(!defined(GLM_PRECISION_HIGHP_INT) && defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT)) - typedef mediump_int int_t; -#elif(!defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && defined(GLM_PRECISION_LOWP_INT)) +#if GLM_CONFIG_PRECISION_INT == GLM_LOWP typedef lowp_int int_t; +#elif GLM_CONFIG_PRECISION_INT == GLM_MEDIUMP + typedef mediump_int int_t; #else -# error "GLM error: multiple default precision requested for signed integer types" + typedef highp_int int_t; #endif -#if(!defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT)) - typedef mediump_uint uint_t; -#elif(defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT)) - typedef highp_uint uint_t; -#elif(!defined(GLM_PRECISION_HIGHP_UINT) && defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT)) - typedef mediump_uint uint_t; -#elif(!defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && defined(GLM_PRECISION_LOWP_UINT)) +#if GLM_CONFIG_PRECISION_UINT == GLM_LOWP typedef lowp_uint uint_t; +#elif GLM_CONFIG_PRECISION_UINT == GLM_MEDIUMP + typedef mediump_uint uint_t; #else -# error "GLM error: multiple default precision requested for unsigned integer types" + typedef highp_uint uint_t; #endif /// Unsigned integer type. diff --git a/glm/vector_relational.hpp b/glm/vector_relational.hpp index b0953635..2c411b8e 100644 --- a/glm/vector_relational.hpp +++ b/glm/vector_relational.hpp @@ -73,7 +73,7 @@ namespace glm /// @see GLSL equal man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions template - GLM_FUNC_DECL vec equal(vec const& x, vec const& y); + GLM_FUNC_DECL GLM_CONSTEXPR vec equal(vec const& x, vec const& y); /// Returns the component-wise comparison of result x != y. /// @@ -83,7 +83,7 @@ namespace glm /// @see GLSL notEqual man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions template - GLM_FUNC_DECL vec notEqual(vec const& x, vec const& y); + GLM_FUNC_DECL GLM_CONSTEXPR vec notEqual(vec const& x, vec const& y); /// Returns true if any component of x is true. /// @@ -92,7 +92,7 @@ namespace glm /// @see GLSL any man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions template - GLM_FUNC_DECL bool any(vec const& v); + GLM_FUNC_DECL GLM_CONSTEXPR bool any(vec const& v); /// Returns true if all components of x are true. /// @@ -101,7 +101,7 @@ namespace glm /// @see GLSL all man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions template - GLM_FUNC_DECL bool all(vec const& v); + GLM_FUNC_DECL GLM_CONSTEXPR bool all(vec const& v); /// Returns the component-wise logical complement of x. /// /!\ Because of language incompatibilities between C++ and GLSL, GLM defines the function not but not_ instead. @@ -111,7 +111,7 @@ namespace glm /// @see GLSL not man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions template - GLM_FUNC_DECL vec not_(vec const& v); + GLM_FUNC_DECL GLM_CONSTEXPR vec not_(vec const& v); /// @} }//namespace glm