From 7097e4c7c8f42a922b07208a291f1a0f587d682e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 22:13:06 +0200 Subject: [PATCH 01/20] Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to tweakedInfinitePerspective --- glm/gtc/matrix_transform.hpp | 22 +++---- glm/gtc/matrix_transform.inl | 102 +++++++++++++++--------------- readme.txt | 2 + test/core/core_type_cast.cpp | 23 +++++-- test/gtc/gtc_matrix_transform.cpp | 42 +++++++++++- 5 files changed, 123 insertions(+), 68 deletions(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 2eb24cbf..1a9f0bac 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -164,8 +164,8 @@ namespace glm /// @param far /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform - template - GLM_FUNC_DECL detail::tmat4x4 frustum( + template + GLM_FUNC_DECL detail::tmat4x4 frustum( T const & left, T const & right, T const & bottom, @@ -181,8 +181,8 @@ namespace glm /// @param far /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform - template - GLM_FUNC_DECL detail::tmat4x4 perspective( + template + GLM_FUNC_DECL detail::tmat4x4 perspective( T const & fovy, T const & aspect, T const & near, @@ -197,8 +197,8 @@ namespace glm /// @param far /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform - template - GLM_FUNC_DECL detail::tmat4x4 perspectiveFov( + template + GLM_FUNC_DECL detail::tmat4x4 perspectiveFov( T const & fov, T const & width, T const & height, @@ -212,8 +212,8 @@ namespace glm /// @param near /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform - template - GLM_FUNC_DECL detail::tmat4x4 infinitePerspective( + template + GLM_FUNC_DECL detail::tmat4x4 infinitePerspective( T fovy, T aspect, T near); /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. @@ -223,9 +223,9 @@ namespace glm /// @param near /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform - template - GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( - T fovy, T aspect, T near); + template + GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( + T fovy, T aspect, T near, T epsilon = epsilon()); /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. /// diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 25f13751..03d201c6 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -192,87 +192,87 @@ namespace glm return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 frustum + template + GLM_FUNC_QUALIFIER detail::tmat4x4 frustum ( - valType const & left, - valType const & right, - valType const & bottom, - valType const & top, - valType const & nearVal, - valType const & farVal + T const & left, + T const & right, + T const & bottom, + T const & top, + T const & nearVal, + T const & farVal ) { - detail::tmat4x4 Result(0); - Result[0][0] = (valType(2) * nearVal) / (right - left); - Result[1][1] = (valType(2) * nearVal) / (top - bottom); + detail::tmat4x4 Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); Result[2][0] = (right + left) / (right - left); Result[2][1] = (top + bottom) / (top - bottom); Result[2][2] = -(farVal + nearVal) / (farVal - nearVal); - Result[2][3] = valType(-1); - Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal); + Result[2][3] = static_cast(-1); + Result[3][2] = -(static_cast(2) * farVal * nearVal) / (farVal - nearVal); return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 perspective + template + GLM_FUNC_QUALIFIER detail::tmat4x4 perspective ( - valType const & fovy, - valType const & aspect, - valType const & zNear, - valType const & zFar + T const & fovy, + T const & aspect, + T const & zNear, + T const & zFar ) { - assert(aspect != valType(0)); + assert(aspect != static_cast(0)); assert(zFar != zNear); #ifdef GLM_FORCE_RADIANS - valType const rad = fovy; + T const rad = fovy; #else # pragma message("GLM: perspective function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.") - valType const rad = glm::radians(fovy); + T const rad = glm::radians(fovy); #endif - valType tanHalfFovy = tan(rad / valType(2)); + T tanHalfFovy = tan(rad / static_cast(2)); - detail::tmat4x4 Result(valType(0)); - Result[0][0] = valType(1) / (aspect * tanHalfFovy); - Result[1][1] = valType(1) / (tanHalfFovy); + detail::tmat4x4 Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[2][3] = - valType(1); - Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear); + Result[2][3] = - static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 perspectiveFov + template + GLM_FUNC_QUALIFIER detail::tmat4x4 perspectiveFov ( - valType const & fov, - valType const & width, - valType const & height, - valType const & zNear, - valType const & zFar + T const & fov, + T const & width, + T const & height, + T const & zNear, + T const & zFar ) { - assert(width > valType(0)); - assert(height > valType(0)); - assert(fov > valType(0)); + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); #ifdef GLM_FORCE_RADIANS - valType rad = fov; + T rad = fov; #else # pragma message("GLM: perspectiveFov function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.") - valType rad = glm::radians(fov); + T rad = glm::radians(fov); #endif - valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType(0.5) * rad); - valType w = h * height / width; ///todo max(width , Height) / min(width , Height)? + T h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T w = h * height / width; ///todo max(width , Height) / min(width , Height)? - detail::tmat4x4 Result(valType(0)); + detail::tmat4x4 Result(static_cast(0)); Result[0][0] = w; Result[1][1] = h; Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[2][3] = - valType(1); - Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear); + Result[2][3] = - static_cast(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); return Result; } @@ -304,12 +304,14 @@ namespace glm return Result; } + // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf template GLM_FUNC_QUALIFIER detail::tmat4x4 tweakedInfinitePerspective ( T fovy, T aspect, - T zNear + T zNear, + T epsilon ) { #ifdef GLM_FORCE_RADIANS @@ -324,11 +326,11 @@ namespace glm T top = range; detail::tmat4x4 Result(T(0)); - Result[0][0] = (T(2) * zNear) / (right - left); - Result[1][1] = (T(2) * zNear) / (top - bottom); - Result[2][2] = static_cast(0.0001) - T(1); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = epsilon - static_cast(1); Result[2][3] = static_cast(-1); - Result[3][2] = - (T(0.0001) - T(2)) * zNear; + Result[3][2] = (epsilon - static_cast(2)) * zNear; return Result; } diff --git a/readme.txt b/readme.txt index 9e4e826a..efeff376 100644 --- a/readme.txt +++ b/readme.txt @@ -51,6 +51,8 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed lerp when cosTheta is close to 1 in quaternion slerp #210 - Added GTX_io for io with #144 - Fixed fastDistance ambiguity #215 +- Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to + tweakedInfinitePerspective ================================================================================ GLM 0.9.5.3: 2014-04-02 diff --git a/test/core/core_type_cast.cpp b/test/core/core_type_cast.cpp index f33972c6..97e2fdd6 100644 --- a/test/core/core_type_cast.cpp +++ b/test/core/core_type_cast.cpp @@ -94,28 +94,41 @@ int test_std_copy() int Error = 0; { - std::vector High4; - std::vector Medium4(High4.size()); + std::vector High; + High.resize(64); + std::vector Medium(High.size()); + + std::copy(High.begin(), High.end(), Medium.begin()); - std::copy(&High4.begin()[0], &High4.end()[0], Medium4.begin()); + *Medium.begin() = *High.begin(); + } + + { + std::vector High4; + High4.resize(64); + std::vector Medium4(High4.size()); + + std::copy(High4.begin(), High4.end(), Medium4.begin()); *Medium4.begin() = *High4.begin(); } { std::vector High3; + High3.resize(64); std::vector Medium3(High3.size()); - std::copy(&High3.begin()[0], &High3.end()[0], Medium3.begin()); + std::copy(High3.begin(), High3.end(), Medium3.begin()); *Medium3.begin() = *High3.begin(); } { std::vector High2; + High2.resize(64); std::vector Medium2(High2.size()); - std::copy(&High2.begin()[0], &High2.end()[0], Medium2.begin()); + std::copy(High2.begin(), High2.end(), Medium2.begin()); *Medium2.begin() = *High2.begin(); } diff --git a/test/gtc/gtc_matrix_transform.cpp b/test/gtc/gtc_matrix_transform.cpp index 05d5f50e..0ea54598 100644 --- a/test/gtc/gtc_matrix_transform.cpp +++ b/test/gtc/gtc_matrix_transform.cpp @@ -11,16 +11,54 @@ #include #include -int main() +int test_perspective() { int Error = 0; - + glm::mat4 Projection = glm::perspective(glm::pi() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); + + return Error; +} + +int test_pick() +{ + int Error = 0; + glm::mat4 Pick = glm::pickMatrix(glm::vec2(1, 2), glm::vec2(3, 4), glm::ivec4(0, 0, 320, 240)); + return Error; +} + +int test_tweakedInfinitePerspective() +{ + int Error = 0; + + glm::mat4 ProjectionA = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f); + glm::mat4 ProjectionB = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f, 0.001f); + + + return Error; +} + +int test_translate() +{ + int Error = 0; + glm::lowp_vec3 v(1.0); glm::lowp_mat4 m(0); glm::lowp_mat4 t = glm::translate(m, v); return Error; } + +int main() +{ + int Error = 0; + + Error += test_translate(); + Error += test_tweakedInfinitePerspective(); + Error += test_pick(); + Error += test_perspective(); + + return Error; +} From d9bed5d7c93c7a7a16385bab7d73384c83d9a591 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 22:17:04 +0200 Subject: [PATCH 02/20] Updated readme for fixed std::copy and std::vector with GLM types #214 --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index efeff376..2dd3fbc7 100644 --- a/readme.txt +++ b/readme.txt @@ -53,6 +53,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed fastDistance ambiguity #215 - Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to tweakedInfinitePerspective +- Fixed std::copy and std::vector with GLM types #214 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 3651530ff09a2d9f7fe24f25815d24119cb2e9cc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 11:50:42 +0200 Subject: [PATCH 03/20] Fixed build --- glm/gtc/matrix_transform.hpp | 1 + glm/gtc/matrix_transform.inl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 1a9f0bac..6ea71aea 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -51,6 +51,7 @@ #include "../vec2.hpp" #include "../vec3.hpp" #include "../vec4.hpp" +#include "../gtc/constants.hpp" #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) # pragma message("GLM: GLM_GTC_matrix_transform extension included") diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 03d201c6..31fa2cc3 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -267,7 +267,7 @@ namespace glm T h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); T w = h * height / width; ///todo max(width , Height) / min(width , Height)? - detail::tmat4x4 Result(static_cast(0)); + detail::tmat4x4 Result(static_cast(0)); Result[0][0] = w; Result[1][1] = h; Result[2][2] = - (zFar + zNear) / (zFar - zNear); From 103a74f7e148bc8b4c67e814ce24f748ae8f9c19 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 11:53:28 +0200 Subject: [PATCH 04/20] clean up --- glm/core/func_exponential.inl | 224 ---------------------------------- glm/virtrev/xstream.hpp | 166 ------------------------- 2 files changed, 390 deletions(-) delete mode 100644 glm/core/func_exponential.inl delete mode 100644 glm/virtrev/xstream.hpp diff --git a/glm/core/func_exponential.inl b/glm/core/func_exponential.inl deleted file mode 100644 index e8ff4cfe..00000000 --- a/glm/core/func_exponential.inl +++ /dev/null @@ -1,224 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -/// OpenGL Mathematics (glm.g-truc.net) -/// -/// Copyright (c) 2005 - 2013 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/func_exponential.inl -/// @date 2008-08-03 / 2011-06-15 -/// @author Christophe Riccio -/////////////////////////////////////////////////////////////////////////////////// - -#include "func_vector_relational.hpp" -#include "_vectorize.hpp" -#include -#include - -namespace glm -{ - // pow - template - GLM_FUNC_QUALIFIER genType pow - ( - genType const & x, - genType const & y - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'pow' only accept floating-point inputs"); - - return std::pow(x, y); - } - - VECTORIZE_VEC_VEC(pow) - - // exp - template - GLM_FUNC_QUALIFIER genType exp - ( - genType const & x - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'exp' only accept floating-point inputs"); - - return std::exp(x); - } - - VECTORIZE_VEC(exp) - - // log - template - GLM_FUNC_QUALIFIER genType log - ( - genType const & x - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'log' only accept floating-point inputs"); - - return std::log(x); - } - - VECTORIZE_VEC(log) - - //exp2, ln2 = 0.69314718055994530941723212145818f - template - GLM_FUNC_QUALIFIER genType exp2 - ( - genType const & x - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'exp2' only accept floating-point inputs"); - - return std::exp(static_cast(0.69314718055994530941723212145818) * x); - } - - VECTORIZE_VEC(exp2) - -namespace detail -{ - template - struct compute_log2 - { - template - T operator() (T const & Value) const; - }; - - template <> - struct compute_log2 - { - template - T operator() (T const & Value) const - { - return static_cast(::std::log(Value)) * static_cast(1.4426950408889634073599246810019); - } - }; - -}//namespace detail - - // log2, ln2 = 0.69314718055994530941723212145818f - template - GLM_FUNC_QUALIFIER genType log2 - ( - genType const & x - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559 || std::numeric_limits::is_integer, - "GLM core 'log2' only accept floating-point inputs. Include for additional integer support."); - - assert(x > genType(0)); // log2 is only defined on the range (0, inf] - return detail::compute_log2::is_iec559>()(x); - } - - VECTORIZE_VEC(log2) - - // sqrt - template - GLM_FUNC_QUALIFIER genType sqrt - ( - genType const & x - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'sqrt' only accept floating-point inputs"); - - assert(x >= genType(0)); - - return std::sqrt(x); - } - - VECTORIZE_VEC(sqrt) - - template - GLM_FUNC_QUALIFIER genType inversesqrt - ( - genType const & x - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'inversesqrt' only accept floating-point inputs"); - - assert(x > genType(0)); - - return genType(1) / std::sqrt(x); - } - - VECTORIZE_VEC(inversesqrt) - - namespace detail - { - template - genType fastInversesqrt(genType const & v) - { - genType tmp(v); - genType xhalf(tmp * genType(0.5f)); - genUType i = *reinterpret_cast(const_cast(&v)); - i = genUType(0x5f375a86) - (i >> genUType(1)); - // tmp = *reinterpret_cast(&i); - { - genType* ptr(reinterpret_cast(&i)); - tmp = *ptr; - } - tmp = tmp * (genType(1.5f) - xhalf * tmp * tmp); - return tmp; - } - } - - template <> - GLM_FUNC_QUALIFIER lowp_vec1 inversesqrt(lowp_vec1 const & v) - { - assert(glm::all(glm::greaterThan(v, lowp_vec1(0)))); - - return detail::fastInversesqrt(v); - } - - template <> - GLM_FUNC_QUALIFIER lowp_vec2 inversesqrt(lowp_vec2 const & v) - { - assert(glm::all(glm::greaterThan(v, lowp_vec2(0)))); - - return detail::fastInversesqrt(v); - } - - template <> - GLM_FUNC_QUALIFIER lowp_vec3 inversesqrt(lowp_vec3 const & v) - { - assert(glm::all(glm::greaterThan(v, lowp_vec3(0)))); - - return detail::fastInversesqrt(v); - } - - template <> - GLM_FUNC_QUALIFIER lowp_vec4 inversesqrt(lowp_vec4 const & v) - { - assert(glm::all(glm::greaterThan(v, lowp_vec4(0)))); - - return detail::fastInversesqrt(v); - } - -}//namespace glm diff --git a/glm/virtrev/xstream.hpp b/glm/virtrev/xstream.hpp deleted file mode 100644 index 2d16c1ac..00000000 --- a/glm/virtrev/xstream.hpp +++ /dev/null @@ -1,166 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -/// OpenGL Mathematics (glm.g-truc.net) -/// -/// Copyright (c) 2005 - 2013 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 virtrev_xstream -/// @file glm/virtrev/xstream.hpp -/// @date 2008-05-24 / 2008-05-26 -/// @author Mathieu Roumillac (matrem84.free.fr) -/// -/// @see core (dependence) -/// @see gtc_matrix_access (dependence) -/// -/// @defgroup virtrev_xstream GLM_VIRTREV_xstream: xml like output -/// @ingroup virtrev -/// -/// @brief Streaming vector and matrix in a xml way. -/// -/// Include for this functionality. -/////////////////////////////////////////////////////////////////////////////////// - -#ifndef GLM_VIRTREV_xstream -#define GLM_VIRTREV_xstream GLM_VERSION - -#include "../glm.hpp" -#include "../gtc/matrix_access.hpp" -#include - -#if(defined(GLM_MESSAGES) && !defined(glm_ext)) -# pragma message("GLM: GLM_VIRTREV_xstream extension included") -#endif -/* -namespace glm{ -namespace detail -{ - template - std::ostream & operator << (std::ostream & stream, glm::detail::tvec2 const & vec) - { - stream << ""; - - return stream; - } - - template - std::ostream & operator << (std::ostream & stream, glm::detail::tvec3 const & vec) - { - stream << ""; - - return stream; - } - - template - std::ostream & operator << (std::ostream & stream, glm::detail::tvec4 const & vec) - { - stream << ""; - - return stream; - } - - template - std::ostream & operator << (std::ostream & stream, glm::detail::tmat2x2 const & mat) - { - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << ""; - - return stream; - } - - template - std::ostream & operator << (std::ostream & stream, glm::detail::tmat3x3 const & mat) - { - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << ""; - - return stream; - } - - template - std::ostream & operator << (std::ostream & stream, glm::detail::tmat4x4 const & mat) - { - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << "" << std::endl; - stream << ""; - - return stream; - } - -}//namespace detail -}//namespace glm -*/ -#endif//GLM_VIRTREV_xstream From f310f941c6d79f132180e1162a1db4e4ce8583fc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 12:14:39 +0200 Subject: [PATCH 05/20] Fixed strict aliasing issues #212 --- glm/gtc/packing.inl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 537e4648..234c6479 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -145,7 +145,8 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 6; - return float2packed11(reinterpret_cast(x)); + uint Pack = reinterpret_cast(x); + return float2packed11(Pack); } GLM_FUNC_QUALIFIER float packed11bitToFloat(glm::uint x) @@ -170,7 +171,8 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 5; - return float2packed10(reinterpret_cast(x)); + uint Pack = reinterpret_cast(x); + return float2packed10(Pack); } GLM_FUNC_QUALIFIER float packed10bitToFloat(glm::uint x) From f32cab2842c2b6d88fc9e81588202ff30c79009b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 13:01:54 +0200 Subject: [PATCH 06/20] Remove useless references --- glm/gtc/packing.hpp | 38 +++++++++++++++++----------------- glm/gtc/packing.inl | 50 ++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index b7fb5648..73abedd5 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -62,7 +62,7 @@ namespace glm /// @see uint32 packUnorm4x8(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); + GLM_FUNC_DECL uint8 packUnorm1x8(float v); /// Convert a single 8-bit integer to a normalized floating-point value. /// @@ -74,7 +74,7 @@ namespace glm /// @see vec4 unpackUnorm4x8(uint32 p) /// @see GLSL unpackUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackUnorm1x8(uint8 const & p); + GLM_FUNC_DECL float unpackUnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -106,7 +106,7 @@ namespace glm /// @see vec4 unpackUnorm4x8(uint32 p) /// @see GLSL unpackUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 const & p); + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into 8-bit integer value. /// Then, the results are packed into the returned 8-bit unsigned integer. @@ -119,7 +119,7 @@ namespace glm /// @see uint32 packSnorm4x8(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint8 packSnorm1x8(float const & s); + GLM_FUNC_DECL uint8 packSnorm1x8(float s); /// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. @@ -132,7 +132,7 @@ namespace glm /// @see vec4 unpackSnorm4x8(uint32 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackSnorm1x8(uint8 const & p); + GLM_FUNC_DECL float unpackSnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -164,7 +164,7 @@ namespace glm /// @see vec4 unpackSnorm4x8(uint32 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 const & p); + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into a 16-bit integer value. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -177,7 +177,7 @@ namespace glm /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packUnorm1x16(float const & v); + GLM_FUNC_DECL uint16 packUnorm1x16(float v); /// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. @@ -190,7 +190,7 @@ namespace glm /// @see vec4 unpackUnorm4x16(uint64 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackUnorm1x16(uint16 const & p); + GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. /// Then, the results are packed into the returned 64-bit unsigned integer. @@ -222,7 +222,7 @@ namespace glm /// @see vec2 unpackUnorm2x16(uint32 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & p); + GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 p); /// First, converts the normalized floating-point value v into 16-bit integer value. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -235,7 +235,7 @@ namespace glm /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packSnorm1x16(float const & v); + GLM_FUNC_DECL uint16 packSnorm1x16(float v); /// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers. /// Then, each component is converted to a normalized floating-point value to generate the returned scalar. @@ -248,7 +248,7 @@ namespace glm /// @see vec4 unpackSnorm4x16(uint64 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackSnorm1x16(uint16 const & p); + GLM_FUNC_DECL float unpackSnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. /// Then, the results are packed into the returned 64-bit unsigned integer. @@ -291,7 +291,7 @@ namespace glm /// @see uint64 packHalf4x16(vec4 const & v) /// @see GLSL packHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packHalf1x16(float const & v); + GLM_FUNC_DECL uint16 packHalf1x16(float v); /// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value, /// interpreted as a 16-bit floating-point number according to the OpenGL Specification, @@ -302,7 +302,7 @@ namespace glm /// @see vec4 unpackHalf4x16(uint64 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); + GLM_FUNC_DECL float unpackHalf1x16(uint16 v); /// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector /// to the 16-bit floating-point representation found in the OpenGL Specification, @@ -328,7 +328,7 @@ namespace glm /// @see vec2 unpackHalf2x16(uint32 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & p); + GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 p); /// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector /// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification, @@ -352,7 +352,7 @@ namespace glm /// @see uint32 packU3x10_1x2(uvec4 const & v) /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); /// @see uvec4 unpackI3x10_1x2(uint32 const & p); - GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p); + GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 p); /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification, @@ -376,7 +376,7 @@ namespace glm /// @see uint32 packU3x10_1x2(uvec4 const & v) /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); /// @see uvec4 unpackI3x10_1x2(uint32 const & p); - GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 const & p); + GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 p); /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values. @@ -411,7 +411,7 @@ namespace glm /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)) /// @see uvec4 unpackI3x10_1x2(uint32 const & p) /// @see uvec4 unpackU3x10_1x2(uint32 const & p) - GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & p); + GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 p); /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values. @@ -446,7 +446,7 @@ namespace glm /// @see vec4 unpackInorm3x10_1x2(uint32 const & p)) /// @see uvec4 unpackI3x10_1x2(uint32 const & p) /// @see uvec4 unpackU3x10_1x2(uint32 const & p) - GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 const & p); + GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 p); /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value. @@ -467,7 +467,7 @@ namespace glm /// /// @see gtc_packing /// @see uint32 packF2x11_1x10(vec3 const & v) - GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 const & p); + GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 p); /// @} }// namespace glm diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 234c6479..4f42970b 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -35,7 +35,7 @@ namespace glm{ namespace detail { - GLM_FUNC_QUALIFIER glm::uint16 float2half(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint16 float2half(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -53,7 +53,7 @@ namespace detail ((f >> 13) & 0x03ff); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 float2packed11(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint32 float2packed11(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -71,7 +71,7 @@ namespace detail ((f >> 17) & 0x003f); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 packed11ToFloat(glm::uint32 const & p) + GLM_FUNC_QUALIFIER glm::uint32 packed11ToFloat(glm::uint32 p) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -89,7 +89,7 @@ namespace detail ((p & 0x003f) << 17); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 float2packed10(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint32 float2packed10(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -110,7 +110,7 @@ namespace detail ((f >> 18) & 0x001f); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 packed10ToFloat(glm::uint32 const & p) + GLM_FUNC_QUALIFIER glm::uint32 packed10ToFloat(glm::uint32 p) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -131,7 +131,7 @@ namespace detail ((p & 0x001f) << 18); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint half2float(glm::uint const & h) + GLM_FUNC_QUALIFIER glm::uint half2float(glm::uint h) { return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); } @@ -145,7 +145,7 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 6; - uint Pack = reinterpret_cast(x); + float Copy = reinterpret_cast(x); return float2packed11(Pack); } @@ -219,12 +219,12 @@ namespace detail }//namespace detail - GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float const & v) + GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float v) { return static_cast(round(clamp(v, 0.0f, 1.0f) * 255.0f)); } - GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 const & p) + GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p) { float Unpack(static_cast(p)); return Unpack * static_cast(0.0039215686274509803921568627451); // 1 / 255 @@ -237,20 +237,20 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 const & p) + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) { u8vec2* Unpacked = reinterpret_cast(const_cast(&p)); return vec2(*Unpacked) * float(0.0039215686274509803921568627451); // 1 / 255 } - GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float const & v) + GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v) { int8 Topack(static_cast(round(clamp(v ,-1.0f, 1.0f) * 127.0f))); uint8* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 const & p) + GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p) { float Unpack(static_cast(*const_cast(&p))); return clamp( @@ -265,7 +265,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 const & p) + GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) { i8vec2* Unpack = reinterpret_cast(const_cast(&p)); return clamp( @@ -273,12 +273,12 @@ namespace detail -1.0f, 1.0f); } - GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float const & s) + GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s) { return static_cast(round(clamp(s, 0.0f, 1.0f) * 65535.0f)); } - GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 const & p) + GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p) { float Unpack = static_cast(*const_cast(&p)); return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 @@ -297,14 +297,14 @@ namespace detail return vec4(*Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 } - GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float const & v) + GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) { int16 Topack = static_cast(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); uint16* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 const & p) + GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p) { float Unpack = static_cast(*const_cast(&p)); return clamp( @@ -319,7 +319,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 const & p) + GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p) { i16vec4* Unpack(reinterpret_cast(const_cast(&p))); return clamp( @@ -327,14 +327,14 @@ namespace detail -1.0f, 1.0f); } - GLM_FUNC_QUALIFIER uint16 packHalf1x16(float const & v) + GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v) { int16 Topack = detail::toFloat16(v); uint16* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 const & v) + GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v) { int16* Unpack = reinterpret_cast(const_cast(&v)); return detail::toFloat32(*Unpack); @@ -374,7 +374,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -395,7 +395,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 v) { detail::u10u10u10u2 Unpack; Unpack.pack = v; @@ -416,7 +416,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -438,7 +438,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -458,7 +458,7 @@ namespace detail ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); } - GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v) + GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 v) { return vec3( detail::packed11bitToFloat(v >> 0), From b025413a2dd19b89f3342623e1a3850b7ab947f0 Mon Sep 17 00:00:00 2001 From: Groove Date: Sat, 21 Jun 2014 07:04:55 -0400 Subject: [PATCH 07/20] Resolve aliasing issue --- glm/gtc/packing.inl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 234c6479..9e3fa87c 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -31,11 +31,12 @@ #include "../vec3.hpp" #include "../vec4.hpp" #include "../detail/type_half.hpp" +#include namespace glm{ namespace detail { - GLM_FUNC_QUALIFIER glm::uint16 float2half(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint16 float2half(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -53,7 +54,7 @@ namespace detail ((f >> 13) & 0x03ff); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 float2packed11(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint32 float2packed11(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -71,7 +72,7 @@ namespace detail ((f >> 17) & 0x003f); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 packed11ToFloat(glm::uint32 const & p) + GLM_FUNC_QUALIFIER glm::uint32 packed11ToFloat(glm::uint32 p) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -89,7 +90,7 @@ namespace detail ((p & 0x003f) << 17); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 float2packed10(glm::uint32 const & f) + GLM_FUNC_QUALIFIER glm::uint32 float2packed10(glm::uint32 f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -110,7 +111,7 @@ namespace detail ((f >> 18) & 0x001f); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint32 packed10ToFloat(glm::uint32 const & p) + GLM_FUNC_QUALIFIER glm::uint32 packed10ToFloat(glm::uint32 p) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -131,7 +132,7 @@ namespace detail ((p & 0x001f) << 18); // Mantissa } - GLM_FUNC_QUALIFIER glm::uint half2float(glm::uint const & h) + GLM_FUNC_QUALIFIER glm::uint half2float(glm::uint h) { return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); } @@ -145,7 +146,13 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 6; - uint Pack = reinterpret_cast(x); +# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_CLANG) + uint Pack = 0; + memcpy(&Pack, &x, sizeof(Pack)); +# else + uint Pack = reinterpret_cast(x); +# endif + return float2packed11(Pack); } From 9f0fe305851508dd23fb90e23fe9919bd8a02888 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 13:22:06 +0200 Subject: [PATCH 08/20] Fixed build --- glm/gtc/packing.inl | 4 ++-- test/gtc/gtc_packing.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 4f42970b..5250352d 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -145,7 +145,7 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 6; - float Copy = reinterpret_cast(x); + uint Pack = reinterpret_cast(x); return float2packed11(Pack); } @@ -352,7 +352,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 const & v) + GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v) { i16vec4* p = reinterpret_cast(const_cast(&v)); i16vec4 Unpack(*p); diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 8acfb74f..ceec3dd2 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -100,7 +100,7 @@ int test_Half1x16() glm::uint32 p0 = glm::packHalf1x16(Tests[i]); float v0 = glm::unpackHalf1x16(p0); glm::uint32 p1 = glm::packHalf1x16(v0); - float v1 = glm::unpackHalf1x16(p0); + float v1 = glm::unpackHalf1x16(p1); Error += (v0 == v1) ? 0 : 1; } @@ -124,7 +124,7 @@ int test_Half4x16() glm::uint64 p0 = glm::packHalf4x16(Tests[i]); glm::vec4 v0 = glm::unpackHalf4x16(p0); glm::uint64 p1 = glm::packHalf4x16(v0); - glm::vec4 v1 = glm::unpackHalf4x16(p0); + glm::vec4 v1 = glm::unpackHalf4x16(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -148,7 +148,7 @@ int test_I3x10_1x2() glm::uint32 p0 = glm::packI3x10_1x2(Tests[i]); glm::ivec4 v0 = glm::unpackI3x10_1x2(p0); glm::uint32 p1 = glm::packI3x10_1x2(v0); - glm::ivec4 v1 = glm::unpackI3x10_1x2(p0); + glm::ivec4 v1 = glm::unpackI3x10_1x2(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -172,7 +172,7 @@ int test_U3x10_1x2() glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]); glm::uvec4 v0 = glm::unpackU3x10_1x2(p0); glm::uint32 p1 = glm::packU3x10_1x2(v0); - glm::uvec4 v1 = glm::unpackU3x10_1x2(p0); + glm::uvec4 v1 = glm::unpackU3x10_1x2(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -196,7 +196,7 @@ int test_Snorm3x10_1x2() glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); - glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -220,7 +220,7 @@ int test_Unorm3x10_1x2() glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); - glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -244,7 +244,7 @@ int test_F2x11_1x10() glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]); glm::vec3 v0 = glm::unpackF2x11_1x10(p0); glm::uint32 p1 = glm::packF2x11_1x10(v0); - glm::vec3 v1 = glm::unpackF2x11_1x10(p0); + glm::vec3 v1 = glm::unpackF2x11_1x10(p1); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } From b69356cadb3b74b630bd20ce13f8fc9d25489704 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 07:41:30 -0400 Subject: [PATCH 09/20] Resolve aliasing issues #152, #212 --- glm/gtc/packing.inl | 20 +++++++++++++++++--- readme.txt | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 353dc6eb..571d0f4d 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -170,6 +170,7 @@ namespace detail # if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_CLANG) float Temp = 0; memcpy(&Temp, &Result, sizeof(Temp)); + return Temp; # else return reinterpret_cast(Result); # endif @@ -184,7 +185,13 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 5; - uint Pack = reinterpret_cast(x); +# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_CLANG) + uint Pack = 0; + memcpy(&Pack, &x, sizeof(Pack)); +# else + uint Pack = reinterpret_cast(x); +# endif + return float2packed10(Pack); } @@ -197,8 +204,15 @@ namespace detail else if(x == (0x1f << 5)) return ~0;//Inf - uint result = packed10ToFloat(x); - return reinterpret_cast(result); + uint Result = packed10ToFloat(x); + +# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_CLANG) + float Temp = 0; + memcpy(&Temp, &Result, sizeof(Temp)); + return Temp; +# else + return reinterpret_cast(Result); +# endif } // GLM_FUNC_QUALIFIER glm::uint f11_f11_f10(float x, float y, float z) diff --git a/readme.txt b/readme.txt index 2dd3fbc7..dadd4c23 100644 --- a/readme.txt +++ b/readme.txt @@ -54,6 +54,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to tweakedInfinitePerspective - Fixed std::copy and std::vector with GLM types #214 +- Fixed aliasing issues #212, #152 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 2b38221f80f194018ef01a78bb615efb94d79c31 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 14:02:51 +0200 Subject: [PATCH 10/20] Fixed build --- glm/gtc/matrix_transform.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 6ea71aea..ef67a100 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -226,7 +226,7 @@ namespace glm /// @see gtc_matrix_transform template GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( - T fovy, T aspect, T near, T epsilon = epsilon()); + T fovy, T aspect, T near, T epsilon = glm::epsilon()); /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. /// From 08ff93925f40d791a908e7a08e3c74000828d56e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 15:07:03 +0200 Subject: [PATCH 11/20] Fixed std::nextafter not supported with C++11 on Android #213 --- glm/gtc/matrix_transform.hpp | 13 ++++++++++++- glm/gtc/matrix_transform.inl | 17 ++++++++++++++--- glm/gtc/ulp.inl | 16 ++++++++-------- readme.txt | 3 ++- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index ef67a100..8cd0b651 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -226,7 +226,18 @@ namespace glm /// @see gtc_matrix_transform template GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( - T fovy, T aspect, T near, T epsilon = glm::epsilon()); + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. + /// + /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// @param aspect + /// @param near + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( + T fovy, T aspect, T near, T ep); /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. /// diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 31fa2cc3..44578290 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -311,7 +311,7 @@ namespace glm T fovy, T aspect, T zNear, - T epsilon + T ep ) { #ifdef GLM_FORCE_RADIANS @@ -328,12 +328,23 @@ namespace glm detail::tmat4x4 Result(T(0)); Result[0][0] = (static_cast(2) * zNear) / (right - left); Result[1][1] = (static_cast(2) * zNear) / (top - bottom); - Result[2][2] = epsilon - static_cast(1); + Result[2][2] = ep - static_cast(1); Result[2][3] = static_cast(-1); - Result[3][2] = (epsilon - static_cast(2)) * zNear; + Result[3][2] = (ep - static_cast(2)) * zNear; return Result; } + template + GLM_FUNC_QUALIFIER detail::tmat4x4 tweakedInfinitePerspective + ( + T fovy, + T aspect, + T zNear + ) + { + return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon()); + } + template GLM_FUNC_QUALIFIER detail::tvec3 project ( diff --git a/glm/gtc/ulp.inl b/glm/gtc/ulp.inl index 19ac7b47..4099812b 100644 --- a/glm/gtc/ulp.inl +++ b/glm/gtc/ulp.inl @@ -199,9 +199,9 @@ namespace glm template <> GLM_FUNC_QUALIFIER float next_float(float const & x) { -# if((GLM_LANG & GLM_LANG_CXX11_FLAG)) +# if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafterf(x, FLT_MAX); # else return nextafterf(x, FLT_MAX); @@ -211,9 +211,9 @@ namespace glm template <> GLM_FUNC_QUALIFIER double next_float(double const & x) { -# if((GLM_LANG & GLM_LANG_CXX11_FLAG)) +# if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafter(x, std::numeric_limits::max()); # else return nextafter(x, DBL_MAX); @@ -231,9 +231,9 @@ namespace glm GLM_FUNC_QUALIFIER float prev_float(float const & x) { -# if((GLM_LANG & GLM_LANG_CXX11_FLAG)) +# if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::min()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafterf(x, FLT_MIN); # else return nextafterf(x, FLT_MIN); @@ -242,9 +242,9 @@ namespace glm GLM_FUNC_QUALIFIER double prev_float(double const & x) { -# if((GLM_LANG & GLM_LANG_CXX11_FLAG)) +# if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::min()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return _nextafter(x, DBL_MIN); # else return nextafter(x, DBL_MIN); diff --git a/readme.txt b/readme.txt index dadd4c23..29e3669b 100644 --- a/readme.txt +++ b/readme.txt @@ -54,7 +54,8 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to tweakedInfinitePerspective - Fixed std::copy and std::vector with GLM types #214 -- Fixed aliasing issues #212, #152 +- Fixed strict aliasing issues #212, #152 +- Fixed std::nextafter not supported with C++11 on Android #213 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 9b6eecc739320b468127a9848b5056b109446257 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 15:38:49 +0200 Subject: [PATCH 12/20] Fixed corner cases in exp and log functions for quaternions #199 --- glm/gtx/quaternion.inl | 28 +++++++++++++++++----------- readme.txt | 3 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 2d1a6c13..615989bc 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -8,6 +8,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #include +#include "../gtc/constants.hpp" namespace glm { @@ -62,7 +63,10 @@ namespace glm ) { detail::tvec3 u(q.x, q.y, q.z); - float Angle = glm::length(u); + T Angle = glm::length(u); + if (Angle < epsilon()) + return detail::tquat(); + detail::tvec3 v(u / Angle); return detail::tquat(cos(Angle), sin(Angle) * v); } @@ -73,18 +77,20 @@ namespace glm detail::tquat const & q ) { - if((q.x == static_cast(0)) && (q.y == static_cast(0)) && (q.z == static_cast(0))) + detail::tvec3 u(q.x, q.y, q.z); + T Vec3Len = length(u); + + if (Vec3Len < epsilon()) { - if(q.w > T(0)) - return detail::tquat(log(q.w), T(0), T(0), T(0)); - else if(q.w < T(0)) - return detail::tquat(log(-q.w), T(3.1415926535897932384626433832795), T(0),T(0)); + if(q.w > static_cast(0)) + return detail::tquat(log(q.w), static_cast(0), static_cast(0), static_cast(0)); + else if(q.w < static_cast(0)) + return detail::tquat(log(-q.w), pi(), static_cast(0), static_cast(0)); else return detail::tquat(std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity()); } else { - T Vec3Len = sqrt(q.x * q.x + q.y * q.y + q.z * q.z); T QuatLen = sqrt(Vec3Len * Vec3Len + q.w * q.w); T t = atan(Vec3Len, T(q.w)) / Vec3Len; return detail::tquat(log(QuatLen), t * q.x, t * q.y, t * q.z); @@ -98,11 +104,11 @@ namespace glm T const & y ) { - if(abs(x.w) > T(0.9999)) + if(abs(x.w) > (static_cast(1) - epsilon())) return x; - float Angle = acos(y); - float NewAngle = Angle * y; - float Div = sin(NewAngle) / sin(Angle); + T Angle = acos(y); + T NewAngle = Angle * y; + T Div = sin(NewAngle) / sin(Angle); return detail::tquat( cos(NewAngle), x.x * Div, diff --git a/readme.txt b/readme.txt index 29e3669b..9c3d238c 100644 --- a/readme.txt +++ b/readme.txt @@ -37,7 +37,7 @@ More informations in GLM manual: http://glm.g-truc.net/glm.pdf ================================================================================ -GLM 0.9.5.4: 2014-0X-XX +GLM 0.9.5.4: 2014-06-21 -------------------------------------------------------------------------------- - Fixed non-utf8 character #196 - Added FindGLM install for CMake #189 @@ -56,6 +56,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed std::copy and std::vector with GLM types #214 - Fixed strict aliasing issues #212, #152 - Fixed std::nextafter not supported with C++11 on Android #213 +- Fixed corner cases in exp and log functions for quaternions #199 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 694416701a009172f62b04d62970b384fbb21253 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 15:42:10 +0200 Subject: [PATCH 13/20] Replaced C casts by C++ casts --- glm/gtx/quaternion.inl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 615989bc..0dc95b0f 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -41,7 +41,7 @@ namespace glm detail::tquat const & s2, T const & h) { - return mix(mix(q1, q2, h), mix(s1, s2, h), T(2) * (T(1) - h) * h); + return mix(mix(q1, q2, h), mix(s1, s2, h), static_cast(2) * (static_cast(1) - h) * h); } template @@ -53,7 +53,7 @@ namespace glm ) { detail::tquat invQuat = inverse(curr); - return exp((log(next + invQuat) + log(prev + invQuat)) / T(-4)) * curr; + return exp((log(next + invQuat) + log(prev + invQuat)) / static_cast(-4)) * curr; } template @@ -152,7 +152,7 @@ namespace glm detail::tquat const & q ) { - T w = static_cast(1.0) - q.x * q.x - q.y * q.y - q.z * q.z; + T w = static_cast(1) - q.x * q.x - q.y * q.y - q.z * q.z; if(w < T(0)) return T(0); else @@ -176,12 +176,12 @@ namespace glm T const & a ) { - if(a <= T(0)) return x; - if(a >= T(1)) return y; + if(a <= static_cast(0)) return x; + if(a >= static_cast(1)) return y; T fCos = dot(x, y); detail::tquat y2(y); //BUG!!! tquat y2; - if(fCos < T(0)) + if(fCos < static_cast(0)) { y2 = -y; fCos = -fCos; @@ -189,7 +189,7 @@ namespace glm //if(fCos > 1.0f) // problem T k0, k1; - if(fCos > T(0.9999)) + if(fCos > (static_cast(1) - epsilon())) { k0 = static_cast(1) - a; k1 = static_cast(0) + a; //BUG!!! 1.0f + a; @@ -199,8 +199,8 @@ namespace glm T fSin = sqrt(T(1) - fCos * fCos); T fAngle = atan(fSin, fCos); T fOneOverSin = static_cast(1) / fSin; - k0 = sin((T(1) - a) * fAngle) * fOneOverSin; - k1 = sin((T(0) + a) * fAngle) * fOneOverSin; + k0 = sin((static_cast(1) - a) * fAngle) * fOneOverSin; + k1 = sin((static_cast(0) + a) * fAngle) * fOneOverSin; } return detail::tquat( @@ -218,7 +218,7 @@ namespace glm T const & a ) { - return glm::normalize(x * (T(1) - a) + (y * a)); + return glm::normalize(x * (static_cast(1) - a) + (y * a)); } template @@ -231,7 +231,7 @@ namespace glm T cosTheta = dot(orig, dest); detail::tvec3 rotationAxis; - if(cosTheta < T(-1) + epsilon()) + if(cosTheta < static_cast(-1) + epsilon()) { // special case when vectors in opposite directions : // there is no "ideal" rotation axis @@ -249,11 +249,11 @@ namespace glm // Implementation from Stan Melax's Game Programming Gems 1 article rotationAxis = cross(orig, dest); - T s = sqrt((T(1) + cosTheta) * T(2)); + T s = sqrt((T(1) + cosTheta) * static_cast(2)); T invs = static_cast(1) / s; return detail::tquat( - s * T(0.5f), + s * static_cast(0.5f), rotationAxis.x * invs, rotationAxis.y * invs, rotationAxis.z * invs); From 7f3c56f2782caf264427aad9a330a824093641c1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 16:00:17 +0200 Subject: [PATCH 14/20] Removed GCC warning --- test/core/core_func_matrix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index 1b609f32..a905417f 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -231,7 +231,7 @@ int test_inverse_perf(std::size_t Instance, char const * Message) printf("inverse<%s>(%f): %d\n", Message, Diff, EndTime - StartTime); return 0; -}; +} int main() { From 24cd06552cb70a028f3b95b103323072dd9c9838 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 16:23:06 +0200 Subject: [PATCH 15/20] Fixed GLM_GTX_io coding style --- glm/gtx/io.hpp | 284 ++++++------ glm/gtx/io.inl | 1149 ++++++++++++++++++++++++------------------------ 2 files changed, 721 insertions(+), 712 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 25e9d74b..7dd22182 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -57,178 +57,168 @@ namespace glm { - /// @addtogroup gtx_io - /// @{ - - namespace io - { - - enum order_type { column_major, row_major, }; - - template - class format_punct : public std::locale::facet { + /// @addtogroup gtx_io + /// @{ - typedef CTy char_type; - - public: + namespace io + { + enum order_type { column_major, row_major}; - static std::locale::id id; + template + class format_punct : public std::locale::facet + { + typedef CTy char_type; - bool formatted; - unsigned precision; - unsigned width; - char_type separator; - char_type delim_left; - char_type delim_right; - char_type space; - char_type newline; - order_type order; - - explicit format_punct(size_t a = 0); - explicit format_punct(format_punct const&); - - }; + public: - template > - class basic_state_saver { + static std::locale::id id; - public: + bool formatted; + unsigned precision; + unsigned width; + char_type separator; + char_type delim_left; + char_type delim_right; + char_type space; + char_type newline; + order_type order; - explicit basic_state_saver(std::basic_ios&); - ~basic_state_saver(); + explicit format_punct(size_t a = 0); + explicit format_punct(format_punct const&); + }; - private: + template > + class basic_state_saver { - typedef ::std::basic_ios state_type; - typedef typename state_type::char_type char_type; - typedef ::std::ios_base::fmtflags flags_type; - typedef ::std::streamsize streamsize_type; - typedef ::std::locale const locale_type; - - state_type& state_; - flags_type flags_; - streamsize_type precision_; - streamsize_type width_; - char_type fill_; - locale_type locale_; - - basic_state_saver& operator=(basic_state_saver const&); - - }; + public: - typedef basic_state_saver state_saver; - typedef basic_state_saver wstate_saver; - - template > - class basic_format_saver { + explicit basic_state_saver(std::basic_ios&); + ~basic_state_saver(); - public: + private: - explicit basic_format_saver(std::basic_ios&); - ~basic_format_saver(); + typedef ::std::basic_ios state_type; + typedef typename state_type::char_type char_type; + typedef ::std::ios_base::fmtflags flags_type; + typedef ::std::streamsize streamsize_type; + typedef ::std::locale const locale_type; - private: + state_type& state_; + flags_type flags_; + streamsize_type precision_; + streamsize_type width_; + char_type fill_; + locale_type locale_; - basic_state_saver const bss_; + basic_state_saver& operator=(basic_state_saver const&); + }; - basic_format_saver& operator=(basic_format_saver const&); - - }; + typedef basic_state_saver state_saver; + typedef basic_state_saver wstate_saver; - typedef basic_format_saver format_saver; - typedef basic_format_saver wformat_saver; - - struct precision { + template > + class basic_format_saver + { + public: - unsigned value; - - explicit precision(unsigned); - - }; + explicit basic_format_saver(std::basic_ios&); + ~basic_format_saver(); - struct width { + private: - unsigned value; - - explicit width(unsigned); - - }; + basic_state_saver const bss_; - template - struct delimeter { + basic_format_saver& operator=(basic_format_saver const&); + }; - CTy value[3]; - - explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); - - }; + typedef basic_format_saver format_saver; + typedef basic_format_saver wformat_saver; - struct order { + struct precision + { + unsigned value; - order_type value; - - explicit order(order_type); - - }; - - // functions, inlined (inline) + explicit precision(unsigned); + }; - template - FTy const& get_facet(std::basic_ios&); - template - std::basic_ios& formatted(std::basic_ios&); - template - std::basic_ios& unformattet(std::basic_ios&); - - template - std::basic_ostream& operator<<(std::basic_ostream&, precision const&); - template - std::basic_ostream& operator<<(std::basic_ostream&, width const&); - template - std::basic_ostream& operator<<(std::basic_ostream&, delimeter const&); - template - std::basic_ostream& operator<<(std::basic_ostream&, order const&); - - }//namespace io + struct width + { + unsigned value; - namespace detail - { + explicit width(unsigned); + }; - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tquat const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec2 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec3 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec4 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x2 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x3 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x4 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x2 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x3 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x4 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x2 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x3 const&); - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x4 const&); - - template - GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, - std::pair const, - tmat4x4 const> const&); - - }//namespace detail - - /// @} + template + struct delimeter + { + CTy value[3]; + + explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); + }; + + struct order + { + order_type value; + + explicit order(order_type); + }; + + // functions, inlined (inline) + + template + FTy const& get_facet(std::basic_ios&); + template + std::basic_ios& formatted(std::basic_ios&); + template + std::basic_ios& unformattet(std::basic_ios&); + + template + std::basic_ostream& operator<<(std::basic_ostream&, precision const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, width const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, delimeter const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, order const&); + }//namespace io + + namespace detail + { + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tquat const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec2 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec3 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tvec4 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x2 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x3 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat2x4 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x2 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x3 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat3x4 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x2 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x3 const&); + template + GLM_FUNC_DECL std::basic_ostream& operator<<(std::basic_ostream&, tmat4x4 const&); + + template + GLM_FUNC_DECL std::basic_ostream & operator<<( + std::basic_ostream &, + std::pair const, + tmat4x4 const> const &); + }//namespace detail + + /// @} }//namespace glm #include "io.inl" diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 3132a88e..dbad163c 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -10,570 +10,589 @@ #include // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw #include // std::basic_ostream<> -namespace glm +namespace glm{ +namespace io { - namespace io - { - - template - /* explicit */ GLM_FUNC_QUALIFIER - format_punct::format_punct(size_t a) - : std::locale::facet(a), - formatted (true), - precision (3), - width (1 + 4 + 1 + precision), - separator (','), - delim_left ('['), - delim_right (']'), - space (' '), - newline ('\n'), - order (row_major) - {} - - template - /* explicit */ GLM_FUNC_QUALIFIER - format_punct::format_punct(format_punct const& a) - : std::locale::facet(0), - formatted (a.formatted), - precision (a.precision), - width (a.width), - separator (a.separator), - delim_left (a.delim_left), - delim_right (a.delim_right), - space (a.space), - newline (a.newline), - order (a.order) - {} - - template std::locale::id format_punct::id; - - template - /* explicit */ GLM_FUNC_QUALIFIER - basic_state_saver::basic_state_saver(std::basic_ios& a) - : state_ (a), - flags_ (a.flags()), - precision_(a.precision()), - width_ (a.width()), - fill_ (a.fill()), - locale_ (a.getloc()) - {} - - template - GLM_FUNC_QUALIFIER - basic_state_saver::~basic_state_saver() - { - state_.imbue(locale_); - state_.fill(fill_); - state_.width(width_); - state_.precision(precision_); - state_.flags(flags_); - } - - template - /* explicit */ GLM_FUNC_QUALIFIER - basic_format_saver::basic_format_saver(std::basic_ios& a) - : bss_(a) - { - a.imbue(std::locale(a.getloc(), new format_punct(get_facet >(a)))); - } - - template - GLM_FUNC_QUALIFIER - basic_format_saver::~basic_format_saver() - {} - - /* explicit */ GLM_FUNC_QUALIFIER - precision::precision(unsigned a) - : value(a) - {} - - /* explicit */ GLM_FUNC_QUALIFIER - width::width(unsigned a) - : value(a) - {} - - template - /* explicit */ GLM_FUNC_QUALIFIER - delimeter::delimeter(CTy a, CTy b, CTy c) - : value() - { - value[0] = a; - value[1] = b; - value[2] = c; - } - - /* explicit */ GLM_FUNC_QUALIFIER - order::order(order_type a) - : value(a) - {} - - template - GLM_FUNC_QUALIFIER FTy const& - get_facet(std::basic_ios& ios) - { - if (!std::has_facet(ios.getloc())) { - ios.imbue(std::locale(ios.getloc(), new FTy)); - } - - return std::use_facet(ios.getloc()); - } - - template - GLM_FUNC_QUALIFIER std::basic_ios& - formatted(std::basic_ios& ios) - { - const_cast&>(get_facet >(ios)).formatted = true; - - return ios; - } - - template - GLM_FUNC_QUALIFIER std::basic_ios& - unformatted(std::basic_ios& ios) - { - const_cast&>(get_facet >(ios)).formatted = false; - - return ios; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, precision const& a) - { - const_cast&>(get_facet >(os)).precision = a.value; - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, width const& a) - { - const_cast&>(get_facet >(os)).width = a.value; - - return os; - } - - template - std::basic_ostream& operator<<(std::basic_ostream& os, - delimeter const& a) - { - format_punct& fmt(const_cast&>(get_facet >(os))); - - fmt.delim_left = a.value[0]; - fmt.delim_right = a.value[1]; - fmt.separator = a.value[2]; - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, order const& a) - { - const_cast&>(get_facet >(os)).order = a.value; - - return os; - } - - } // namespace io - - namespace detail { - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tquat const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - - if (fmt.formatted) { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.w << fmt.separator - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z - << fmt.delim_right; - } else { - os << a.w << fmt.space << a.x << fmt.space << a.y << fmt.space << a.z; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tvec2 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - - if (fmt.formatted) { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y - << fmt.delim_right; - } else { - os << a.x << fmt.space << a.y; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tvec3 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - - if (fmt.formatted) { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z - << fmt.delim_right; - } else { - os << a.x << fmt.space << a.y << fmt.space << a.z; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tvec4 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - - if (fmt.formatted) { - io::basic_state_saver const bss(os); - - os << std::fixed - << std::right - << std::setprecision(fmt.precision) - << std::setfill(fmt.space) - << fmt.delim_left - << std::setw(fmt.width) << a.x << fmt.separator - << std::setw(fmt.width) << a.y << fmt.separator - << std::setw(fmt.width) << a.z << fmt.separator - << std::setw(fmt.width) << a.w - << fmt.delim_right; - } else { - os << a.x << fmt.space << a.y << fmt.space << a.z << fmt.space << a.w; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat2x2 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat2x2 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat2x3 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat3x2 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat2x4 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat4x2 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat3x2 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat2x3 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat3x3 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat3x3 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat3x4 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat4x3 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat4x2 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat2x4 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat4x3 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat3x4 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, tmat4x4 const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat4x4 m(a); - - if (io::row_major == fmt.order) { - m = transpose(a); - } - - if (fmt.formatted) { - os << fmt.newline - << fmt.delim_left << m[0] << fmt.newline - << fmt.space << m[1] << fmt.newline - << fmt.space << m[2] << fmt.newline - << fmt.space << m[3] << fmt.delim_right; - } else { - os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; - } - } - - return os; - } - - template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, - std::pair const, tmat4x4 const> const& a) - { - typename std::basic_ostream::sentry const cerberus(os); - - if (cerberus) { - io::format_punct const& fmt(io::get_facet >(os)); - tmat4x4 ml(a.first); - tmat4x4 mr(a.second); - - if (io::row_major == fmt.order) { - ml = transpose(a.first); - mr = transpose(a.second); - } - - if (fmt.formatted) { - CTy const& l(fmt.delim_left); - CTy const& r(fmt.delim_right); - CTy const& s(fmt.space); - - os << fmt.newline - << l << ml[0] << s << s << l << mr[0] << fmt.newline - << s << ml[1] << s << s << s << mr[1] << fmt.newline - << s << ml[2] << s << s << s << mr[2] << fmt.newline - << s << ml[3] << r << s << s << mr[3] << r; - } else { - os << ml << fmt.space << mr; - } - } - - return os; - } - - }//namespace detail + template + /* explicit */ GLM_FUNC_QUALIFIER + format_punct::format_punct(size_t a) + : std::locale::facet(a), + formatted (true), + precision (3), + width (1 + 4 + 1 + precision), + separator (','), + delim_left ('['), + delim_right (']'), + space (' '), + newline ('\n'), + order (row_major) + {} + + template + /* explicit */ GLM_FUNC_QUALIFIER + format_punct::format_punct(format_punct const& a) + : std::locale::facet(0), + formatted (a.formatted), + precision (a.precision), + width (a.width), + separator (a.separator), + delim_left (a.delim_left), + delim_right (a.delim_right), + space (a.space), + newline (a.newline), + order (a.order) + {} + + template std::locale::id format_punct::id; + + template + /* explicit */ GLM_FUNC_QUALIFIER basic_state_saver::basic_state_saver(std::basic_ios& a) + : state_ (a), + flags_ (a.flags()), + precision_(a.precision()), + width_ (a.width()), + fill_ (a.fill()), + locale_ (a.getloc()) + {} + + template + GLM_FUNC_QUALIFIER basic_state_saver::~basic_state_saver() + { + state_.imbue(locale_); + state_.fill(fill_); + state_.width(width_); + state_.precision(precision_); + state_.flags(flags_); + } + + template + /* explicit */ GLM_FUNC_QUALIFIER basic_format_saver::basic_format_saver(std::basic_ios& a) + : bss_(a) + { + a.imbue(std::locale(a.getloc(), new format_punct(get_facet >(a)))); + } + + template + GLM_FUNC_QUALIFIER + basic_format_saver::~basic_format_saver() + {} + + /* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a) + : value(a) + {} + + /* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a) + : value(a) + {} + + template + /* explicit */ GLM_FUNC_QUALIFIER delimeter::delimeter(CTy a, CTy b, CTy c) + : value() + { + value[0] = a; + value[1] = b; + value[2] = c; + } + + /* explicit */ GLM_FUNC_QUALIFIER + order::order(order_type a) + : value(a) + {} + + template + GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios& ios) + { + if (!std::has_facet(ios.getloc())) { + ios.imbue(std::locale(ios.getloc(), new FTy)); + } + + return std::use_facet(ios.getloc()); + } + + template + GLM_FUNC_QUALIFIER std::basic_ios& formatted(std::basic_ios& ios) + { + const_cast&>(get_facet >(ios)).formatted = true; + + return ios; + } + + template + GLM_FUNC_QUALIFIER std::basic_ios& unformatted(std::basic_ios& ios) + { + const_cast&>(get_facet >(ios)).formatted = false; + + return ios; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, precision const& a) + { + const_cast&>(get_facet >(os)).precision = a.value; + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, width const& a) + { + const_cast&>(get_facet >(os)).width = a.value; + + return os; + } + + template + std::basic_ostream& operator<<(std::basic_ostream& os, delimeter const& a) + { + format_punct & fmt(const_cast&>(get_facet >(os))); + + fmt.delim_left = a.value[0]; + fmt.delim_right = a.value[1]; + fmt.separator = a.value[2]; + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, order const& a) + { + const_cast&>(get_facet >(os)).order = a.value; + + return os; + } +} // namespace io + +namespace detail +{ + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tquat const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) + { + io::basic_state_saver const bss(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left + << std::setw(fmt.width) << a.w << fmt.separator + << std::setw(fmt.width) << a.x << fmt.separator + << std::setw(fmt.width) << a.y << fmt.separator + << std::setw(fmt.width) << a.z + << fmt.delim_right; + } + else + { + os << a.w << fmt.space << a.x << fmt.space << a.y << fmt.space << a.z; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec2 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) + { + io::basic_state_saver const bss(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left + << std::setw(fmt.width) << a.x << fmt.separator + << std::setw(fmt.width) << a.y + << fmt.delim_right; + } + else + { + os << a.x << fmt.space << a.y; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec3 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) + { + io::basic_state_saver const bss(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left + << std::setw(fmt.width) << a.x << fmt.separator + << std::setw(fmt.width) << a.y << fmt.separator + << std::setw(fmt.width) << a.z + << fmt.delim_right; + } + else + { + os << a.x << fmt.space << a.y << fmt.space << a.z; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec4 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + + if(fmt.formatted) + { + io::basic_state_saver const bss(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left + << std::setw(fmt.width) << a.x << fmt.separator + << std::setw(fmt.width) << a.y << fmt.separator + << std::setw(fmt.width) << a.z << fmt.separator + << std::setw(fmt.width) << a.w + << fmt.delim_right; + } + else + { + os << a.x << fmt.space << a.y << fmt.space << a.z << fmt.space << a.w; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x2 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat2x2 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x3 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat3x2 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat2x4 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat4x2 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.newline + << fmt.space << m[3] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat3x2 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat2x3 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tmat3x3 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat3x3 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat3x4 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat4x3 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if (fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.newline + << fmt.space << m[3] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x2 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat2x4 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if (fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x3 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat3x4 m(a); + + if(io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream & operator<<(std::basic_ostream& os, tmat4x4 const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat4x4 m(a); + + if (io::row_major == fmt.order) + m = transpose(a); + + if(fmt.formatted) + { + os << fmt.newline + << fmt.delim_left << m[0] << fmt.newline + << fmt.space << m[1] << fmt.newline + << fmt.space << m[2] << fmt.newline + << fmt.space << m[3] << fmt.delim_right; + } + else + { + os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3]; + } + } + + return os; + } + + template + GLM_FUNC_QUALIFIER std::basic_ostream& operator<<( + std::basic_ostream & os, + std::pair const, tmat4x4 const> const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if(cerberus) + { + io::format_punct const & fmt(io::get_facet >(os)); + tmat4x4 ml(a.first); + tmat4x4 mr(a.second); + + if(io::row_major == fmt.order) + { + ml = transpose(a.first); + mr = transpose(a.second); + } + + if(fmt.formatted) + { + CTy const & l(fmt.delim_left); + CTy const & r(fmt.delim_right); + CTy const & s(fmt.space); + + os << fmt.newline + << l << ml[0] << s << s << l << mr[0] << fmt.newline + << s << ml[1] << s << s << s << mr[1] << fmt.newline + << s << ml[2] << s << s << s << mr[2] << fmt.newline + << s << ml[3] << r << s << s << mr[3] << r; + } + else + { + os << ml << fmt.space << mr; + } + } + + return os; + } +}//namespace detail }//namespace glm From 4fa38c7a03df4064f9c4fff75f9d5a93f0049ae5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 21 Jun 2014 16:29:06 +0200 Subject: [PATCH 16/20] Fixed warning --- test/core/core_func_matrix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index a905417f..5c95672c 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -228,7 +228,7 @@ int test_inverse_perf(std::size_t Instance, char const * Message) //glm::uint Ulp = 0; //Ulp = glm::max(glm::float_distance(*Dst, *Src), Ulp); - printf("inverse<%s>(%f): %d\n", Message, Diff, EndTime - StartTime); + printf("inverse<%s>(%f): %lu\n", Message, Diff, EndTime - StartTime); return 0; } From 6f59e64a55a2cbd0ac0c39bbb4936873207d6f08 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 22 Jun 2014 02:03:31 +0200 Subject: [PATCH 17/20] Use C++ cast --- glm/gtc/matrix_transform.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 44578290..15009358 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -167,7 +167,7 @@ namespace glm detail::tmat4x4 Result(1); Result[0][0] = static_cast(2) / (right - left); Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - T(2) / (zFar - zNear); + Result[2][2] = - static_cast(2) / (zFar - zNear); Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); Result[3][2] = - (zFar + zNear) / (zFar - zNear); @@ -186,7 +186,7 @@ namespace glm detail::tmat4x4 Result(1); Result[0][0] = static_cast(2) / (right - left); Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - T(1); + Result[2][2] = - static_cast(1); Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); return Result; From 74591613643e3d3048bad5dac6844805333bcb83 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 28 Jun 2014 20:45:45 +0200 Subject: [PATCH 18/20] Updated revision fornext release --- glm/detail/setup.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index c982c469..6ad9bdc0 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -38,7 +38,7 @@ #define GLM_VERSION_MAJOR 0 #define GLM_VERSION_MINOR 9 #define GLM_VERSION_PATCH 5 -#define GLM_VERSION_REVISION 4 +#define GLM_VERSION_REVISION 5 /////////////////////////////////////////////////////////////////////////////////////////////////// // Platform From 9a3f42279ba2dd5b338a59e0ffd9479f39b4fdce Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 28 Jun 2014 20:56:12 +0200 Subject: [PATCH 19/20] - Fixed std::nextafter not supported with C++11 on Android #213 --- glm/gtc/ulp.inl | 10 +++++++--- readme.txt | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/glm/gtc/ulp.inl b/glm/gtc/ulp.inl index 4099812b..91846b22 100644 --- a/glm/gtc/ulp.inl +++ b/glm/gtc/ulp.inl @@ -201,8 +201,10 @@ namespace glm { # if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafterf(x, FLT_MAX); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return _nextafterf(x, FLT_MAX); # else return nextafterf(x, FLT_MAX); # endif @@ -213,7 +215,7 @@ namespace glm { # if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafter(x, std::numeric_limits::max()); # else return nextafter(x, DBL_MAX); @@ -233,8 +235,10 @@ namespace glm { # if((GLM_LANG & GLM_LANG_CXX11_FLAG) && !(GLM_PLATFORM & GLM_PLATFORM_ANDROID)) return std::nextafter(x, std::numeric_limits::min()); -# elif((GLM_PLATFORM & GLM_PLATFORM_ANDROID) || (GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) return detail::nextafterf(x, FLT_MIN); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return _nextafterf(x, FLT_MIN); # else return nextafterf(x, FLT_MIN); # endif diff --git a/readme.txt b/readme.txt index 9c3d238c..7328ad1d 100644 --- a/readme.txt +++ b/readme.txt @@ -36,6 +36,11 @@ GLM is a header only library, there is nothing to build, just include it. More informations in GLM manual: http://glm.g-truc.net/glm.pdf +================================================================================ +GLM 0.9.5.5: 2014-XX-XX +-------------------------------------------------------------------------------- +- Fixed std::nextafter not supported with C++11 on Android #213 + ================================================================================ GLM 0.9.5.4: 2014-06-21 -------------------------------------------------------------------------------- From d84fa89cb850c3a1bec0f56ba735fb74d0359b05 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 28 Jun 2014 21:08:53 +0200 Subject: [PATCH 20/20] Fixed missing value_type for dual quaternion, Fixed return type of dual quaternion length --- glm/gtc/quaternion.hpp | 2 +- glm/gtx/dual_quaternion.hpp | 4 ++-- glm/gtx/dual_quaternion.inl | 2 +- readme.txt | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 1470a85d..a8b0c904 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -59,7 +59,7 @@ namespace detail { enum ctor{null}; - typedef T value_type; + typedef T value_type; typedef tvec4 bool_type; public: diff --git a/glm/gtx/dual_quaternion.hpp b/glm/gtx/dual_quaternion.hpp index c7c6c50a..101c28ae 100644 --- a/glm/gtx/dual_quaternion.hpp +++ b/glm/gtx/dual_quaternion.hpp @@ -57,13 +57,13 @@ namespace detail struct tdualquat { enum ctor{null}; - + typedef T value_type; typedef glm::detail::tquat part_type; public: glm::detail::tquat real, dual; - GLM_FUNC_DECL GLM_CONSTEXPR int length() const; + GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const; // Constructors GLM_FUNC_DECL tdualquat(); diff --git a/glm/gtx/dual_quaternion.inl b/glm/gtx/dual_quaternion.inl index 7f4aadd6..bd69f537 100644 --- a/glm/gtx/dual_quaternion.inl +++ b/glm/gtx/dual_quaternion.inl @@ -33,7 +33,7 @@ namespace glm{ namespace detail { template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR int tdualquat::length() const + GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tdualquat::length() const { return 8; } diff --git a/readme.txt b/readme.txt index 7328ad1d..5320c51d 100644 --- a/readme.txt +++ b/readme.txt @@ -40,6 +40,8 @@ http://glm.g-truc.net/glm.pdf GLM 0.9.5.5: 2014-XX-XX -------------------------------------------------------------------------------- - Fixed std::nextafter not supported with C++11 on Android #213 +- Fixed missing value_type for dual quaternion +- Fixed return type of dual quaternion length ================================================================================ GLM 0.9.5.4: 2014-06-21