diff --git a/copying.txt b/copying.txt index 124698cc..efd93bab 100644 --- a/copying.txt +++ b/copying.txt @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2005 - 2012 G-Truc Creation +Copyright (c) 2005 - 2013 G-Truc Creation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/glm/core/func_common.hpp b/glm/core/func_common.hpp index 2d55ab91..f184c45e 100644 --- a/glm/core/func_common.hpp +++ b/glm/core/func_common.hpp @@ -220,7 +220,7 @@ namespace glm /// /// If genTypeU is a boolean scalar or vector: /// Selects which vector each returned component comes - /// from. For a component of a that is false, the + /// from. For a component of that is false, the /// corresponding component of x is returned. For a /// component of a that is true, the corresponding /// component of y is returned. Components of x and y that diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index 17d0a62b..11045da6 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -420,93 +420,87 @@ namespace detail } // mix - template - GLM_FUNC_QUALIFIER genTypeT mix + template + GLM_FUNC_QUALIFIER genType mix ( - genTypeT const & x, - genTypeT const & y, - genTypeU const & a + genType const & x, + genType const & y, + genType const & a ) { - // It could be a vector too - //GLM_STATIC_ASSERT( - // detail::type::is_float && - // detail::type::is_float); + GLM_STATIC_ASSERT(detail::type::is_float , "'genType' is not floating-point type"); - //return x + a * (y - x); - return genTypeT(genTypeU(x) + a * genTypeU(y - x)); + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 mix + template + GLM_FUNC_QUALIFIER detail::tvec2 mix ( - detail::tvec2 const & x, - detail::tvec2 const & y, - valTypeB const & a + detail::tvec2 const & x, + detail::tvec2 const & y, + valType const & a ) { - return detail::tvec2( - detail::tvec2(x) + a * detail::tvec2(y - x)); + GLM_STATIC_ASSERT(detail::type::is_float , "'genType' is not floating-point type"); + + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec3 mix + template + GLM_FUNC_QUALIFIER detail::tvec3 mix ( - detail::tvec3 const & x, - detail::tvec3 const & y, - valTypeB const & a + detail::tvec3 const & x, + detail::tvec3 const & y, + valType const & a ) { - return detail::tvec3( - detail::tvec3(x) + a * detail::tvec3(y - x)); + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec4 mix + template + GLM_FUNC_QUALIFIER detail::tvec4 mix ( - detail::tvec4 const & x, - detail::tvec4 const & y, - valTypeB const & a + detail::tvec4 const & x, + detail::tvec4 const & y, + valType const & a ) { - return detail::tvec4( - detail::tvec4(x) + a * detail::tvec4(y - x)); + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 mix + template + GLM_FUNC_QUALIFIER detail::tvec2 mix ( - detail::tvec2 const & x, - detail::tvec2 const & y, - detail::tvec2 const & a + detail::tvec2 const & x, + detail::tvec2 const & y, + detail::tvec2 const & a ) { - return detail::tvec2( - detail::tvec2(x) + a * detail::tvec2(y - x)); + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec3 mix + template + GLM_FUNC_QUALIFIER detail::tvec3 mix ( - detail::tvec3 const & x, - detail::tvec3 const & y, - detail::tvec3 const & a + detail::tvec3 const & x, + detail::tvec3 const & y, + detail::tvec3 const & a ) { - return detail::tvec3( - detail::tvec3(x) + a * detail::tvec3(y - x)); + GLM_STATIC_ASSERT(detail::type::is_float , "'genType' is not floating-point type"); + + return x + a * (y - x); } - template - GLM_FUNC_QUALIFIER detail::tvec4 mix + template + GLM_FUNC_QUALIFIER detail::tvec4 mix ( - detail::tvec4 const & x, - detail::tvec4 const & y, - detail::tvec4 const & a + detail::tvec4 const & x, + detail::tvec4 const & y, + detail::tvec4 const & a ) { - return detail::tvec4( - detail::tvec4(x) + a * detail::tvec4(y - x)); + return x + a * (y - x); } //template @@ -525,15 +519,63 @@ namespace detail // return x + a * (y - x); //} - template - GLM_FUNC_QUALIFIER genType mix + template <> + GLM_FUNC_QUALIFIER float mix ( - genType const & x, - genType const & y, + float const & x, + float const & y, + bool const & a + ) + { + return a ? y : x; + } + + template <> + GLM_FUNC_QUALIFIER double mix + ( + double const & x, + double const & y, bool const & a ) { - GLM_STATIC_ASSERT(detail::type::is_float, "'mix' only accept floating-point inputs"); + return a ? y : x; + } + + template + GLM_FUNC_QUALIFIER detail::tvec2 mix + ( + detail::tvec2 const & x, + detail::tvec2 const & y, + bool a + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'mix' only accept floating-point inputs"); + + return a ? y : x; + } + + template + GLM_FUNC_QUALIFIER detail::tvec3 mix + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + bool a + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'mix' only accept floating-point inputs"); + + return a ? y : x; + } + + template + GLM_FUNC_QUALIFIER detail::tvec4 mix + ( + detail::tvec4 const & x, + detail::tvec4 const & y, + bool a + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'mix' only accept floating-point inputs"); return a ? y : x; } @@ -552,8 +594,7 @@ namespace detail for ( typename detail::tvec2::size_type i = 0; - i < detail::tvec2::value_size(); - ++i + i < x.length(); ++i ) { result[i] = a[i] ? y[i] : x[i]; @@ -575,8 +616,7 @@ namespace detail for ( typename detail::tvec3::size_type i = 0; - i < detail::tvec3::value_size(); - ++i + i < x.length(); ++i ) { result[i] = a[i] ? y[i] : x[i]; @@ -598,8 +638,7 @@ namespace detail for ( typename detail::tvec4::size_type i = 0; - i < detail::tvec4::value_size(); - ++i + i < x.length(); ++i ) { result[i] = a[i] ? y[i] : x[i]; diff --git a/glm/core/setup.hpp b/glm/core/setup.hpp index e0bde506..0a838e55 100644 --- a/glm/core/setup.hpp +++ b/glm/core/setup.hpp @@ -442,17 +442,11 @@ #elif(defined(GLM_FORCE_CXX98)) # define GLM_LANG GLM_LANG_CXX98 #else +# if(__cplusplus >= 201103L) +# define GLM_LANG GLM_LANG_CXX11 // -std=c++0x or -std=gnu++0x -# if(GLM_COMPILER & GLM_COMPILER_GCC) -# if(defined(__GXX_EXPERIMENTAL_CXX0X__)) -# if(GLM_COMPILER >= GLM_COMPILER_GCC47) -# define GLM_LANG GLM_LANG_CXX11 -# else -# define GLM_LANG GLM_LANG_CXX0X -# endif -# else -# define GLM_LANG GLM_LANG_CXX98 -# endif +# elif(((GLM_COMPILER & GLM_COMPILER_GCC) == GLM_COMPILER_GCC) && defined(__GXX_EXPERIMENTAL_CXX0X__)) +# define GLM_LANG GLM_LANG_CXX0X # elif(GLM_COMPILER & GLM_COMPILER_VC) # if(defined(_MSC_EXTENSIONS)) # if(GLM_COMPILER >= GLM_COMPILER_VC2012) @@ -485,7 +479,7 @@ # define GLM_LANG (GLM_LANG_CXX98) # endif # endif -# elif((GLM_COMPILER & GLM_COMPILER_CLANG) == GLM_COMPILER_CLANG) +# elif(__cplusplus >= 199711L) # define GLM_LANG GLM_LANG_CXX98 # else # define GLM_LANG GLM_LANG_CXX diff --git a/glm/gtc/half_float.hpp b/glm/gtc/half_float.hpp index 6713d79d..102724ae 100644 --- a/glm/gtc/half_float.hpp +++ b/glm/gtc/half_float.hpp @@ -432,6 +432,20 @@ namespace detail /// @see gtc_half_float hvec4 abs(hvec4 const & x); + /// Selects which vector each returned component comes + /// from. For a component of that is false, the + /// corresponding component of x is returned. For a + /// component of a that is true, the corresponding + /// component of y is returned. Components of x and y that + /// are not selected are allowed to be invalid floating point + /// values and will have no effect on the results. Thus, this + /// provides different functionality than + /// genType mix(genType x, genType y, genType(a)) + /// where a is a Boolean vector. + /// + /// @see gtc_half_float + half mix(half const & x, half const & y, bool const & a); + /// @} }// namespace glm diff --git a/glm/gtc/half_float.inl b/glm/gtc/half_float.inl index 77dd50ed..57dae8ee 100644 --- a/glm/gtc/half_float.inl +++ b/glm/gtc/half_float.inl @@ -1036,4 +1036,15 @@ namespace detail float(v.w) >= float(0) ? v.w : -v.w); } + template <> + GLM_FUNC_QUALIFIER glm::half mix + ( + glm::half const & x, + glm::half const & y, + bool const & a + ) + { + return a ? y : x; + } + }//namespace glm diff --git a/readme.txt b/readme.txt index 69135c16..9d18efbd 100644 --- a/readme.txt +++ b/readme.txt @@ -46,7 +46,7 @@ GLM 0.9.5.0: 2013-XX-XX - Added rotation function to GTX_quaternion (#22) ================================================================================ -GLM 0.9.4.3: 2013-03-17 +GLM 0.9.4.3: 2013-03-20 -------------------------------------------------------------------------------- - Detected qualifier for Clang - Fixed C++11 mode for GCC, couldn't be enabled without MS extensions @@ -56,7 +56,8 @@ GLM 0.9.4.3: 2013-03-17 - Added a docx copy of the manual - Fixed GLM_GTX_matrix_interpolation - Fixed isnan and isinf on Android with Clang - +- Autodetected C++ version using __cplusplus value +- Fixed mix for bool and bvec* third parameter ================================================================================ GLM 0.9.4.2: 2013-02-14 diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index 21e5cc0e..05f7dafd 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -168,7 +168,7 @@ namespace test_mix {-1.0f, 1.0f, true, 1.0f} }; - test TestFloat[] = + test TestFloat[] = { {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 1.0f}, @@ -189,7 +189,42 @@ namespace test_mix {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)}, {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)}, {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)}, - {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)} + {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)} + }; + + test TestVec3Bool[] = + { + {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)}, + {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)} + }; + + test TestBVec3[] = + { + {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)}, + {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)}, + {glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)} + }; + + test TestVec4Bool[] = + { + {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)}, + {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)} + }; + + test TestBVec4[] = + { + {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(0.0f)}, + {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)}, + {glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)} }; int run() @@ -234,6 +269,52 @@ namespace test_mix } } + // vec3 with bool + { + for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(test); ++i) + { + glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a); + Error += glm::epsilonEqual(Result.x, TestVec3Bool[i].Result.x, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.y, TestVec3Bool[i].Result.y, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.z, TestVec3Bool[i].Result.z, glm::epsilon()) ? 0 : 1; + } + } + + // vec3 with bvec3 + { + for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(test); ++i) + { + glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a); + Error += glm::epsilonEqual(Result.x, TestBVec3[i].Result.x, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.y, TestBVec3[i].Result.y, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.z, TestBVec3[i].Result.z, glm::epsilon()) ? 0 : 1; + } + } + + // vec4 with bool + { + for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(test); ++i) + { + glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a); + Error += glm::epsilonEqual(Result.x, TestVec4Bool[i].Result.x, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.y, TestVec4Bool[i].Result.y, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.z, TestVec4Bool[i].Result.z, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.w, TestVec4Bool[i].Result.w, glm::epsilon()) ? 0 : 1; + } + } + + // vec4 with bvec4 + { + for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(test); ++i) + { + glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a); + Error += glm::epsilonEqual(Result.x, TestBVec4[i].Result.x, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.y, TestBVec4[i].Result.y, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.z, TestBVec4[i].Result.z, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(Result.w, TestBVec4[i].Result.w, glm::epsilon()) ? 0 : 1; + } + } + return Error; } }//namespace test_mix