Browse Source

Merge 0.9.5

Christophe Riccio 11 years ago
parent
commit
ae026e64d3

+ 224 - 0
glm/core/func_exponential.inl

@@ -0,0 +1,224 @@
+///////////////////////////////////////////////////////////////////////////////////
+/// 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 <limits>
+#include <cassert>
+
+namespace glm
+{
+	// pow
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType pow
+	(
+		genType const & x, 
+		genType const & y
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'pow' only accept floating-point inputs");
+
+		return std::pow(x, y);
+	}
+
+	VECTORIZE_VEC_VEC(pow)
+
+	// exp
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType exp
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'exp' only accept floating-point inputs");
+
+		return std::exp(x);
+	}
+
+	VECTORIZE_VEC(exp)
+
+	// log
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType log
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'log' only accept floating-point inputs");
+
+		return std::log(x);
+	}
+
+	VECTORIZE_VEC(log)
+
+	//exp2, ln2 = 0.69314718055994530941723212145818f
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType exp2
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'exp2' only accept floating-point inputs");
+
+		return std::exp(static_cast<genType>(0.69314718055994530941723212145818) * x);
+	}
+
+	VECTORIZE_VEC(exp2)
+
+namespace detail
+{
+	template <bool isFloat>
+	struct compute_log2
+	{
+		template <typename T>
+		T operator() (T const & Value) const;
+	};
+
+	template <>
+	struct compute_log2<true>
+	{
+		template <typename T>
+		T operator() (T const & Value) const
+		{
+			return static_cast<T>(::std::log(Value)) * static_cast<T>(1.4426950408889634073599246810019);
+		}
+	};
+
+}//namespace detail
+
+	// log2, ln2 = 0.69314718055994530941723212145818f
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType log2
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer,
+			"GLM core 'log2' only accept floating-point inputs. Include <glm/gtx/integer.hpp> for additional integer support.");
+
+		assert(x > genType(0)); // log2 is only defined on the range (0, inf]
+		return detail::compute_log2<std::numeric_limits<genType>::is_iec559>()(x);
+	}
+
+	VECTORIZE_VEC(log2)
+
+	// sqrt
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType sqrt
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'sqrt' only accept floating-point inputs");
+
+		assert(x >= genType(0));
+
+		return std::sqrt(x);
+	}
+
+	VECTORIZE_VEC(sqrt)
+
+	template <typename genType>
+	GLM_FUNC_QUALIFIER genType inversesqrt
+	(
+		genType const & x
+	)
+	{
+		GLM_STATIC_ASSERT(
+			std::numeric_limits<genType>::is_iec559,
+			"'inversesqrt' only accept floating-point inputs");
+
+		assert(x > genType(0));
+
+		return genType(1) / std::sqrt(x);
+	}
+
+	VECTORIZE_VEC(inversesqrt)
+	
+	namespace detail
+	{
+		template <typename genType, typename genUType>
+		genType fastInversesqrt(genType const & v)
+		{
+			genType tmp(v);
+			genType xhalf(tmp * genType(0.5f));
+			genUType i = *reinterpret_cast<genUType*>(const_cast<genType*>(&v));
+			i = genUType(0x5f375a86) - (i >> genUType(1));
+      // tmp = *reinterpret_cast<genType*>(&i);
+      {
+        genType* ptr(reinterpret_cast<genType*>(&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<lowp_vec1, uint>(v);
+	}
+
+	template <>
+	GLM_FUNC_QUALIFIER lowp_vec2 inversesqrt(lowp_vec2 const & v)
+	{
+		assert(glm::all(glm::greaterThan(v, lowp_vec2(0))));
+
+		return detail::fastInversesqrt<lowp_vec2, lowp_uvec2>(v);
+	}
+
+	template <>
+	GLM_FUNC_QUALIFIER lowp_vec3 inversesqrt(lowp_vec3 const & v)
+	{
+		assert(glm::all(glm::greaterThan(v, lowp_vec3(0))));
+
+		return detail::fastInversesqrt<lowp_vec3, lowp_uvec3>(v);
+	}
+
+	template <>
+	GLM_FUNC_QUALIFIER lowp_vec4 inversesqrt(lowp_vec4 const & v)
+	{
+		assert(glm::all(glm::greaterThan(v, lowp_vec4(0))));
+
+		return detail::fastInversesqrt<lowp_vec4, lowp_uvec4>(v);
+	}
+	
+}//namespace glm

+ 2 - 2
glm/detail/func_common.inl

@@ -716,7 +716,7 @@ namespace detail
 #		if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL))
 #		if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL))
 			return _isnan(x) != 0;
 			return _isnan(x) != 0;
 #		elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG))
 #		elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG))
-#			if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
+#			if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L)
 				return _isnan(x) != 0;
 				return _isnan(x) != 0;
 #			else
 #			else
 				return std::isnan(x);
 				return std::isnan(x);
@@ -787,7 +787,7 @@ namespace detail
 #		if(GLM_COMPILER & (GLM_COMPILER_INTEL | GLM_COMPILER_VC))
 #		if(GLM_COMPILER & (GLM_COMPILER_INTEL | GLM_COMPILER_VC))
 			return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
 			return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
 #		elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG))
 #		elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG))
-#			if(GLM_PLATFORM & GLM_PLATFORM_ANDROID)
+#			if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L)
 				return _isinf(x) != 0;
 				return _isinf(x) != 0;
 #			else
 #			else
 				return std::isinf(x);
 				return std::isinf(x);

+ 1 - 2
glm/detail/func_geometric.inl

@@ -92,8 +92,7 @@ namespace detail
 	{
 	{
 		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length' only accept floating-point inputs");
 		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length' only accept floating-point inputs");
 
 
-		genType sqr = x * x;
-		return sqrt(sqr);
+		return abs(x);
 	}
 	}
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>

+ 6 - 2
glm/detail/func_packing.inl

@@ -35,7 +35,9 @@ namespace glm
 	GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
 	GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
 	{
 	{
 		u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
 		u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
-		return reinterpret_cast<uint&>(Topack);
+		// return reinterpret_cast<uint&>(Topack);
+    uint* ptr(reinterpret_cast<uint*>(&Topack));
+    return *ptr;
 	}
 	}
 
 
 	GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
 	GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
@@ -47,7 +49,9 @@ namespace glm
 	GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
 	GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
 	{
 	{
 		i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
 		i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
-		return reinterpret_cast<uint32&>(Topack);
+		// return reinterpret_cast<uint32&>(Topack);
+    uint* ptr(reinterpret_cast<uint*>(&Topack));
+    return *ptr;
 	}
 	}
 
 
 	GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
 	GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)

+ 23 - 8
glm/detail/setup.hpp

@@ -578,16 +578,19 @@
 
 
 #define GLM_ARCH_PURE		0x0000
 #define GLM_ARCH_PURE		0x0000
 #define GLM_ARCH_SSE2		0x0001
 #define GLM_ARCH_SSE2		0x0001
-#define GLM_ARCH_SSE3		0x0002// | GLM_ARCH_SSE2
-#define GLM_ARCH_AVX		0x0008// | GLM_ARCH_SSE3 | GLM_ARCH_SSE2
-#define GLM_ARCH_AVX2		0x0010// | GLM_ARCH_AVX | GLM_ARCH_SSE3 | GLM_ARCH_SSE2
+#define GLM_ARCH_SSE3		0x0002
+#define GLM_ARCH_SSE4		0x0004
+#define GLM_ARCH_AVX		0x0008
+#define GLM_ARCH_AVX2		0x0010
 
 
 #if(defined(GLM_FORCE_PURE))
 #if(defined(GLM_FORCE_PURE))
 #	define GLM_ARCH GLM_ARCH_PURE
 #	define GLM_ARCH GLM_ARCH_PURE
 #elif(defined(GLM_FORCE_AVX2))
 #elif(defined(GLM_FORCE_AVX2))
-#	define GLM_ARCH (GLM_ARCH_AVX2 | GLM_ARCH_AVX | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	define GLM_ARCH (GLM_ARCH_AVX2 | GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
 #elif(defined(GLM_FORCE_AVX))
 #elif(defined(GLM_FORCE_AVX))
-#	define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#elif(defined(GLM_FORCE_SSE4))
+#	define GLM_ARCH (GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
 #elif(defined(GLM_FORCE_SSE3))
 #elif(defined(GLM_FORCE_SSE3))
 #	define GLM_ARCH (GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
 #	define GLM_ARCH (GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
 #elif(defined(GLM_FORCE_SSE2))
 #elif(defined(GLM_FORCE_SSE2))
@@ -606,14 +609,26 @@
 #	endif
 #	endif
 #elif(GLM_COMPILER & GLM_COMPILER_VC)
 #elif(GLM_COMPILER & GLM_COMPILER_VC)
 #	if _M_IX86_FP == 2 && defined(__AVX__)
 #	if _M_IX86_FP == 2 && defined(__AVX__)
-#		define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#		define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
 #	elif _M_IX86_FP == 2
 #	elif _M_IX86_FP == 2
 #		define GLM_ARCH (GLM_ARCH_SSE2)
 #		define GLM_ARCH (GLM_ARCH_SSE2)
 #	else
 #	else
 #		define GLM_ARCH (GLM_ARCH_PURE)
 #		define GLM_ARCH (GLM_ARCH_PURE)
 #	endif
 #	endif
-#elif((GLM_PLATFORM & GLM_PLATFORM_APPLE) && (GLM_COMPILER & GLM_COMPILER_GCC))
-#	define GLM_ARCH GLM_ARCH_PURE
+#elif(((GLM_COMPILER & GLM_COMPILER_GCC) && (defined(__i386__) || defined(__x86_64__))) || (GLM_COMPILER & GLM_COMPILER_LLVM_GCC) || (GLM_COMPILER & GLM_COMPILER_CLANG))
+#	if defined(__AVX2__) 
+#		define GLM_ARCH (GLM_ARCH_AVX2 | GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	elif defined(__AVX__)
+#		define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	elif defined(__SSE4_1__ )
+#		define GLM_ARCH (GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	elif defined(__SSE3__)
+#		define GLM_ARCH (GLM_ARCH_SSE3 | GLM_ARCH_SSE2)
+#	elif defined(__SSE2__)
+#		define GLM_ARCH (GLM_ARCH_SSE2)
+#	else
+#		define GLM_ARCH (GLM_ARCH_PURE)
+#	endif
 #else
 #else
 #	define GLM_ARCH GLM_ARCH_PURE
 #	define GLM_ARCH GLM_ARCH_PURE
 #endif
 #endif

+ 1 - 0
glm/detail/type_mat4x4.hpp

@@ -59,6 +59,7 @@ namespace detail
 	private:
 	private:
 		/// @cond DETAIL
 		/// @cond DETAIL
 		col_type value[4];
 		col_type value[4];
+		/// @endcond
 
 
 	public:
 	public:
 		// Constructors
 		// Constructors

+ 1 - 0
glm/gtc/quaternion.hpp

@@ -59,6 +59,7 @@ namespace detail
 	{
 	{
 		enum ctor{null};
 		enum ctor{null};
 
 
+                typedef T value_type;
 		typedef tvec4<bool, P> bool_type;
 		typedef tvec4<bool, P> bool_type;
 
 
 	public:
 	public:

+ 9 - 14
glm/gtc/quaternion.inl

@@ -255,7 +255,7 @@ namespace detail
 	template <typename T, precision P>
 	template <typename T, precision P>
 	struct compute_dot<tquat, T, P>
 	struct compute_dot<tquat, T, P>
 	{
 	{
-		static T call(tquat<T, P> const & x, tquat<T, P> const & y)
+		static GLM_FUNC_QUALIFIER T call(tquat<T, P> const & x, tquat<T, P> const & y)
 		{
 		{
 			tvec4<T, P> tmp(x.x * y.x, x.y * y.y, x.z * y.z, x.w * y.w);
 			tvec4<T, P> tmp(x.x * y.x, x.y * y.y, x.z * y.z, x.w * y.w);
 			return (tmp.x + tmp.y) + (tmp.z + tmp.w);
 			return (tmp.x + tmp.y) + (tmp.z + tmp.w);
@@ -302,16 +302,11 @@ namespace detail
 		detail::tvec3<T, P> const & v
 		detail::tvec3<T, P> const & v
 	)
 	)
 	{
 	{
-		T Two(2);
+		detail::tvec3<T, P> const QuatVector(q.x, q.y, q.z);
+		detail::tvec3<T, P> const uv(glm::cross(QuatVector, v));
+		detail::tvec3<T, P> const uuv(glm::cross(QuatVector, uv));
 
 
-		detail::tvec3<T, P> uv, uuv;
-		detail::tvec3<T, P> QuatVector(q.x, q.y, q.z);
-		uv = glm::cross(QuatVector, v);
-		uuv = glm::cross(QuatVector, uv);
-		uv *= (Two * q.w);
-		uuv *= Two;
-
-		return v + uv + uuv;
+		return v + ((uv * q.w) + uuv) * static_cast<T>(2);
 	}
 	}
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>
@@ -587,10 +582,10 @@ namespace detail
 		{
 		{
 			// Linear interpolation
 			// Linear interpolation
 			return detail::tquat<T, P>(
 			return detail::tquat<T, P>(
-				mix(x.w, y.w, a),
-				mix(x.x, y.x, a),
-				mix(x.y, y.y, a),
-				mix(x.z, y.z, a));
+				mix(x.w, z.w, a),
+				mix(x.x, z.x, a),
+				mix(x.y, z.y, a),
+				mix(x.z, z.z, a));
 		}
 		}
 		else
 		else
 		{
 		{

+ 2 - 2
glm/gtx/bit.inl

@@ -287,7 +287,7 @@ namespace glm
 		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
 		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
 
 
 		genIUType Result = Value;
 		genIUType Result = Value;
-		for(std::size_t i = 0; i <= ToBit; ++i)
+		for(signed i = 0; i <= ToBit; ++i)
 			Result |= (1 << i);
 			Result |= (1 << i);
 		return Result;
 		return Result;
 	}
 	}
@@ -304,7 +304,7 @@ namespace glm
 		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
 		assert(ToBit <= sizeof(genIUType) * std::size_t(8));
 
 
 		genIUType Result = Value;
 		genIUType Result = Value;
-		for(std::size_t i = 0; i <= ToBit; ++i)
+		for(signed i = 0; i <= ToBit; ++i)
 			Result &= ~(1 << i);
 			Result &= ~(1 << i);
 		return Result;
 		return Result;
 	}
 	}

+ 1 - 1
glm/gtx/euler_angles.inl

@@ -250,7 +250,7 @@ namespace glm
 		detail::tvec3<T, P> const & angles
 		detail::tvec3<T, P> const & angles
 	)
 	)
 	{
 	{
-		return detail::tmat3x3<T, P>(yawPitchRoll(angles.x, angles.y, angles.z));
+		return detail::tmat3x3<T, P>(yawPitchRoll(angles.z, angles.x, angles.y));
 	}
 	}
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>

+ 31 - 1
glm/gtx/fast_square_root.inl

@@ -101,13 +101,43 @@ namespace glm
 	template <typename genType>
 	template <typename genType>
 	GLM_FUNC_QUALIFIER genType fastDistance
 	GLM_FUNC_QUALIFIER genType fastDistance
 	(
 	(
-		genType const & x, 
+		genType const & x,
 		genType const & y
 		genType const & y
 	)
 	)
 	{
 	{
 		return fastLength(y - x);
 		return fastLength(y - x);
 	}
 	}
 
 
+	template <typename valType, precision P>
+	GLM_FUNC_QUALIFIER valType fastDistance
+	(
+		detail::tvec2<valType, P> const & x,
+		detail::tvec2<valType, P> const & y
+	)
+	{
+		return fastLength(y - x);
+	}
+
+	template <typename valType, precision P>
+	GLM_FUNC_QUALIFIER valType fastDistance
+	(
+		detail::tvec3<valType, P> const & x,
+		detail::tvec3<valType, P> const & y
+	)
+	{
+		return fastLength(y - x);
+	}
+
+	template <typename valType, precision P>
+	GLM_FUNC_QUALIFIER valType fastDistance
+	(
+		detail::tvec4<valType, P> const & x,
+		detail::tvec4<valType, P> const & y
+	)
+	{
+		return fastLength(y - x);
+	}
+
 	// fastNormalize
 	// fastNormalize
 	template <typename genType>
 	template <typename genType>
 	GLM_FUNC_QUALIFIER genType fastNormalize
 	GLM_FUNC_QUALIFIER genType fastNormalize

+ 130 - 44
glm/gtx/io.hpp

@@ -1,7 +1,7 @@
 ///////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////
 /// OpenGL Mathematics (glm.g-truc.net)
 /// OpenGL Mathematics (glm.g-truc.net)
 ///
 ///
-/// Copyright (c) 2005 - 2014 G-Truc Creation (www.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
 /// Permission is hereby granted, free of charge, to any person obtaining a copy
 /// of this software and associated documentation files (the "Software"), to deal
 /// of this software and associated documentation files (the "Software"), to deal
 /// in the Software without restriction, including without limitation the rights
 /// in the Software without restriction, including without limitation the rights
@@ -26,94 +26,174 @@
 /// @author Jan P Springer ([email protected])
 /// @author Jan P Springer ([email protected])
 ///
 ///
 /// @see core (dependence)
 /// @see core (dependence)
-/// @see gtx_quaternion (dependence)
+/// @see gtc_quaternion (dependence)
 ///
 ///
 /// @defgroup gtx_io GLM_GTX_io
 /// @defgroup gtx_io GLM_GTX_io
 /// @ingroup gtx
 /// @ingroup gtx
 /// 
 /// 
 /// @brief std::[w]ostream support for glm types
 /// @brief std::[w]ostream support for glm types
 ///
 ///
+///        std::[w]ostream support for glm types + precision/width/etc. manipulators
+///        based on howard hinnant's std::chrono io proposal
+///        [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html]
+///
 /// <glm/gtx/io.hpp> needs to be included to use these functionalities.
 /// <glm/gtx/io.hpp> needs to be included to use these functionalities.
 ///////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////
 
 
 #ifndef GLM_GTX_io
 #ifndef GLM_GTX_io
-#define GLM_GTX_io
+#define GLM_GTX_io GLM_VERSION
 
 
 // Dependency:
 // Dependency:
-#include "../detail/setup.hpp"
-#include "../gtc/quaternion.hpp"
+#include "../glm.hpp"
+#include "../gtx/quaternion.hpp"
 
 
-#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
-#	pragma message("GLM: GLM_GTX_io extension included")
+#if(defined(GLM_MESSAGES) && !defined(glm_ext))
+# pragma message("GLM: GLM_GTX_io extension included")
 #endif
 #endif
 
 
 #include <iosfwd>  // std::basic_ostream<> (fwd)
 #include <iosfwd>  // std::basic_ostream<> (fwd)
+#include <locale>  // std::locale, std::locale::facet, std::locale::id
 #include <utility> // std::pair<>
 #include <utility> // std::pair<>
 
 
 namespace glm
 namespace glm
 {
 {
-	/// @addtogroup gtx_io
-	/// @{
+  /// @addtogroup gtx_io
+  /// @{
   
   
   namespace io
   namespace io
   {
   {
     
     
-    class precision_guard {
+    enum order_type { column_major, row_major, };
+    
+    template <typename CTy>
+    class format_punct : public std::locale::facet {
 
 
+      typedef CTy char_type;
+      
     public:
     public:
+
+      static std::locale::id id;
+
+      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&);
       
       
-      GLM_FUNC_DECL explicit precision_guard();
-      GLM_FUNC_DECL         ~precision_guard();
-                
+    };
+
+    template <typename CTy, typename CTr = std::char_traits<CTy> >
+    class basic_state_saver {
+
+    public:
+
+      explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
+              ~basic_state_saver();
+
     private:
     private:
 
 
-      unsigned precision_;
-      unsigned value_width_;
+      typedef ::std::basic_ios<CTy,CTr>      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&);
       
       
     };
     };
 
 
-    class format_guard
-	{
-	public:
-		enum order_t { column_major, row_major, };
+    typedef basic_state_saver<char>     state_saver;
+    typedef basic_state_saver<wchar_t> wstate_saver;
+    
+    template <typename CTy, typename CTr = std::char_traits<CTy> >
+    class basic_format_saver {
 
 
-		GLM_FUNC_DECL explicit format_guard();
-		GLM_FUNC_DECL         ~format_guard();
+    public:
 
 
-	private:
+      explicit basic_format_saver(std::basic_ios<CTy,CTr>&);
+              ~basic_format_saver();
 
 
-		order_t order_;
-		char    cr_;
-	};
+    private:
 
 
-    // decimal places (dflt: 3)
-    GLM_FUNC_DECL unsigned& precision();
+      basic_state_saver<CTy> const bss_;
 
 
-    // sign + value + '.' + decimals (dflt: 1 + 4 + 1 + precision())
-    GLM_FUNC_DECL unsigned& value_width();
+      basic_format_saver& operator=(basic_format_saver const&);
+      
+    };
 
 
-    // matrix output order (dflt: row_major)
-    GLM_FUNC_DECL format_guard::order_t& order();
+    typedef basic_format_saver<char>     format_saver;
+    typedef basic_format_saver<wchar_t> wformat_saver;
+    
+    struct precision {
 
 
-    // carriage/return char (dflt: '\n')
-    GLM_FUNC_DECL char& cr();
+      unsigned value;
+      
+      explicit precision(unsigned);
+      
+    };
+
+    struct width {
 
 
-    // matrix output order -> column_major
-    GLM_FUNC_DECL std::ios_base& column_major(std::ios_base&);
+      unsigned value;
+      
+      explicit width(unsigned);
+      
+    };
 
 
-    // matrix output order -> row_major
-    GLM_FUNC_DECL std::ios_base& row_major   (std::ios_base&);
+    template <typename CTy>
+    struct delimeter {
 
 
-    // carriage/return char -> '\n'
-    GLM_FUNC_DECL std::ios_base& formatted   (std::ios_base&);
+      CTy value[3];
+      
+      explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ',');
+      
+    };
 
 
-    // carriage/return char -> ' '
-    GLM_FUNC_DECL std::ios_base& unformatted (std::ios_base&);
+    struct order {
 
 
+      order_type value;
+      
+      explicit order(order_type);
+      
+    };
+    
+    // functions, inlined (inline)
+
+    template <typename FTy, typename CTy, typename CTr>
+    FTy const& get_facet(std::basic_ios<CTy,CTr>&);
+    template <typename FTy, typename CTy, typename CTr>
+    std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>&);
+    template <typename FTy, typename CTy, typename CTr>
+    std::basic_ios<CTy,CTr>& unformattet(std::basic_ios<CTy,CTr>&);
+    
+    template <typename CTy, typename CTr>
+    std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
+    template <typename CTy, typename CTr>
+    std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, width const&);
+    template <typename CTy, typename CTr>
+    std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, delimeter<CTy> const&);
+    template <typename CTy, typename CTr>
+    std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, order const&);
+    
   }//namespace io
   }//namespace io
 
 
   namespace detail
   namespace detail
   {
   {
+
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tquat<T,P> const&);
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tquat<T,P> const&);
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
@@ -140,9 +220,15 @@ namespace glm
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x3<T,P> const&);
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x3<T,P> const&);
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x4<T,P> const&);
     GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x4<T,P> const&);
-
-	/// @}  
-}//namespace detail
+    
+    template <typename CTy, typename CTr, typename T, precision P>
+    GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&,
+                                                          std::pair<tmat4x4<T,P> const,
+                                                                    tmat4x4<T,P> const> const&);
+    
+  }//namespace detail
+  
+  /// @}
 }//namespace glm
 }//namespace glm
 
 
 #include "io.inl"
 #include "io.inl"

+ 400 - 149
glm/gtx/io.inl

@@ -1,328 +1,579 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
+// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Created : 2013-11-22
 // Created : 2013-11-22
-// Updated : 2013-11-22
+// Updated : 2013-12-18
 // Licence : This source is under MIT License
 // Licence : This source is under MIT License
 // File    : glm/gtx/inl.inl
 // File    : glm/gtx/inl.inl
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include "../matrix.hpp"
-// #include <boost/io/ios_state.hpp> // boost::io::ios_all_saver
-#include <iomanip>                // std::setfill<>, std::fixed, std::setprecision, std::right,
-                                  // std::setw
-#include <ostream>                // std::basic_ostream<>
+#include <iomanip> // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw
+#include <ostream> // std::basic_ostream<>
 
 
-namespace glm{
-namespace io
+namespace glm
 {
 {
+  namespace io
+  {
   
   
+    template <typename CTy>
     /* explicit */ GLM_FUNC_QUALIFIER
     /* explicit */ GLM_FUNC_QUALIFIER
-    precision_guard::precision_guard()
-      : precision_  (precision()),
-        value_width_(value_width())
+    format_punct<CTy>::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 <typename CTy>
+    /* explicit */ GLM_FUNC_QUALIFIER
+    format_punct<CTy>::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 <typename CTy> std::locale::id format_punct<CTy>::id;
+
+    template <typename CTy, typename CTr>
+    /* explicit */ GLM_FUNC_QUALIFIER
+    basic_state_saver<CTy,CTr>::basic_state_saver(std::basic_ios<CTy,CTr>& a)
+      : state_    (a),
+        flags_    (a.flags()),
+        precision_(a.precision()),
+        width_    (a.width()),
+        fill_     (a.fill()),
+        locale_   (a.getloc())
+    {}
+    
+    template <typename CTy, typename CTr>
     GLM_FUNC_QUALIFIER
     GLM_FUNC_QUALIFIER
-    precision_guard::~precision_guard()
+    basic_state_saver<CTy,CTr>::~basic_state_saver()
     {
     {
-      value_width() = value_width_;
-      precision()   = precision_;
+      state_.imbue(locale_);
+      state_.fill(fill_);
+      state_.width(width_);
+      state_.precision(precision_);
+      state_.flags(flags_);
+    }
+    
+    template <typename CTy, typename CTr>
+    /* explicit */ GLM_FUNC_QUALIFIER
+    basic_format_saver<CTy,CTr>::basic_format_saver(std::basic_ios<CTy,CTr>& a)
+      : bss_(a)
+    {
+      a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
     }
     }
 
 
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER
+    basic_format_saver<CTy,CTr>::~basic_format_saver()
+    {}
+    
     /* explicit */ GLM_FUNC_QUALIFIER
     /* explicit */ GLM_FUNC_QUALIFIER
-    format_guard::format_guard()
-      : order_(order()),
-        cr_   (cr())
+    precision::precision(unsigned a)
+      : value(a)
     {}
     {}
 
 
-    GLM_FUNC_QUALIFIER
-    format_guard::~format_guard()
+    /* explicit */ GLM_FUNC_QUALIFIER
+    width::width(unsigned a)
+      : value(a)
+    {}
+
+    template <typename CTy>
+    /* explicit */ GLM_FUNC_QUALIFIER
+    delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
+      : value()
     {
     {
-      cr()    = cr_;
-      order() = order_;
+      value[0] = a;
+      value[1] = b;
+      value[2] = c;
     }
     }
 
 
-    GLM_FUNC_QUALIFIER unsigned& precision()
+    /* explicit */ GLM_FUNC_QUALIFIER
+    order::order(order_type a)
+      : value(a)
+    {}
+    
+    template <typename FTy, typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER FTy const&
+    get_facet(std::basic_ios<CTy,CTr>& ios)
     {
     {
-      static unsigned p(3);
+      if (!std::has_facet<FTy>(ios.getloc())) {
+        ios.imbue(std::locale(ios.getloc(), new FTy));
+      }
 
 
-      return p;
+      return std::use_facet<FTy>(ios.getloc());
     }
     }
-    
-    GLM_FUNC_QUALIFIER unsigned& value_width()
+
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>&
+    formatted(std::basic_ios<CTy,CTr>& ios)
     {
     {
-      static unsigned p(9);
+      const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
 
 
-      return p;
+      return ios;
     }
     }
     
     
-    GLM_FUNC_QUALIFIER format_guard::order_t& order()
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>&
+    unformatted(std::basic_ios<CTy,CTr>& ios)
     {
     {
-      static format_guard::order_t p(format_guard::row_major);
+      const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
 
 
-      return p;
+      return ios;
     }
     }
     
     
-    GLM_FUNC_QUALIFIER char&
-    cr()
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
+    operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
     {
     {
-      static char p('\n'); return p;
+      const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
+
+      return os;
     }
     }
-    
-    GLM_FUNC_QUALIFIER std::ios_base& column_major(std::ios_base& os)
+
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
+    operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
     {
     {
-      order() = format_guard::column_major;
-      
+      const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
+
       return os;
       return os;
     }
     }
-    
-    GLM_FUNC_QUALIFIER std::ios_base& row_major(std::ios_base& os)
+
+    template <typename CTy, typename CTr>
+    std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os,
+                                             delimeter<CTy> const& a)
     {
     {
-      order() = format_guard::row_major;
+      format_punct<CTy>& fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)));
+
+      fmt.delim_left  = a.value[0];
+      fmt.delim_right = a.value[1];
+      fmt.separator   = a.value[2];
       
       
       return os;
       return os;
     }
     }
 
 
-    GLM_FUNC_QUALIFIER std::ios_base& formatted(std::ios_base& os)
+    template <typename CTy, typename CTr>
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>&
+    operator<<(std::basic_ostream<CTy, CTr>& os, order const& a)
     {
     {
-      cr() = '\n';
-      
+      const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
+
       return os;
       return os;
     }
     }
     
     
-    GLM_FUNC_QUALIFIER std::ios_base& unformatted(std::ios_base& os)
+  } // namespace io
+  
+  namespace detail {
+    
+    template <typename CTy, typename CTr, typename T, precision P>
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
     {
     {
-      cr() = ' ';
+      typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
+
+      if (cerberus) {
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+
+        if (fmt.formatted) {
+          io::basic_state_saver<CTy> 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;
       return os;
     }
     }
     
     
-} // namespace io
-namespace detail
-{
-    // functions, inlined (inline)
-
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-        // boost::io::ios_all_saver const ias(os);
-      
-        os << std::fixed << std::setprecision(io::precision())
-           << '['
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.w << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z
-           << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+
+        if (fmt.formatted) {
+          io::basic_state_saver<CTy> 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;
       return os;
     }
     }
-    
+  
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-        // boost::io::ios_all_saver const ias(os);
-      
-        os << std::fixed << std::setprecision(io::precision())
-           << '['
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y
-           << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+
+        if (fmt.formatted) {
+          io::basic_state_saver<CTy> 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;
       return os;
     }
     }
-  
+    
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-        // boost::io::ios_all_saver const ias(os);
-      
-        os << std::fixed << std::setprecision(io::precision())
-           << '['
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z
-           << ']';
-      }
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
 
 
+        if (fmt.formatted) {
+          io::basic_state_saver<CTy> 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-        // boost::io::ios_all_saver const ias(os);
-      
-        os << std::fixed << std::setprecision(io::precision())
-           << '['
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.x << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.y << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.z << ','
-           << std::right << std::setfill<CTy>(' ') << std::setw(io::value_width()) << a.w
-           << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat2x2<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x3<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-        
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat3x2<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x3<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x4<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat4x2<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x4<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x2<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat2x3<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x2<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x3<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat3x3<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x3<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x4<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat4x3<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x4<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x2<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat2x4<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x2<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x3<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << io::cr()
-           << ' ' << m[3] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat3x4<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x3<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x4<T,P> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << io::cr()
-           << ' ' << m[3] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat4x4<T,P>                 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;
       return os;
     }
     }
 
 
     template <typename CTy, typename CTr, typename T, precision P>
     template <typename CTy, typename CTr, typename T, precision P>
-    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x4<T,P> const& m)
+    GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>&
+    operator<<(std::basic_ostream<CTy,CTr>& os,
+               std::pair<tmat4x4<T,P> const, tmat4x4<T,P> const> const& a)
     {
     {
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
       typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
 
 
       if (cerberus) {
       if (cerberus) {
-
-        os << io::cr()
-           << '[' << m[0] << io::cr()
-           << ' ' << m[1] << io::cr()
-           << ' ' << m[2] << io::cr()
-           << ' ' << m[3] << ']';
+        io::format_punct<CTy> const& fmt(io::get_facet<io::format_punct<CTy> >(os));
+        tmat4x4<T,P>                 ml(a.first);
+        tmat4x4<T,P>                 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;
       return os;
     }
     }
-
-}//namespace detail
+    
+  }//namespace detail
 }//namespace glm
 }//namespace glm

+ 9 - 0
readme.txt

@@ -50,6 +50,15 @@ GLM 0.9.5.4: 2014-0X-XX
 - Fixed non-utf8 character #196
 - Fixed non-utf8 character #196
 - Added FindGLM install for CMake #189
 - Added FindGLM install for CMake #189
 - Fixed GTX_color_space - saturation #195
 - Fixed GTX_color_space - saturation #195
+- Fixed glm::isinf and glm::isnan for with Android NDK 9d #191
+- Fixed builtin GLM_ARCH_SSE4 #204
+- Optimized Quaternion vector rotation #205
+- Fixed missing doxygen @endcond tag #211
+- Fixed instruction set detection with Clang #158
+- Fixed orientate3 function #207
+- Fixed lerp when cosTheta is close to 1 in quaternion slerp #210
+- Added GTX_io for io with <iostream> #144
+- Fixed fastDistance ambiguity #215
 
 
 ================================================================================
 ================================================================================
 GLM 0.9.5.3: 2014-04-02
 GLM 0.9.5.3: 2014-04-02

+ 43 - 0
test/core/core_type_cast.cpp

@@ -9,6 +9,9 @@
 
 
 #define GLM_FORCE_RADIANS
 #define GLM_FORCE_RADIANS
 #include <glm/glm.hpp>
 #include <glm/glm.hpp>
+#include <algorithm>
+#include <vector>
+#include <iterator>
 
 
 struct my_vec2
 struct my_vec2
 {
 {
@@ -86,10 +89,50 @@ int test_vec4_cast()
 	return Error;
 	return Error;
 }
 }
 
 
+int test_std_copy()
+{
+	int Error = 0;
+
+	{
+		std::vector<glm::dvec4> High4;
+		std::vector<glm::vec4> Medium4(High4.size());
+
+		std::copy(&High4.begin()[0], &High4.end()[0], Medium4.begin());
+
+		*Medium4.begin() = *High4.begin();
+	}
+
+	{
+		std::vector<glm::dvec3> High3;
+		std::vector<glm::vec3> Medium3(High3.size());
+
+		std::copy(&High3.begin()[0], &High3.end()[0], Medium3.begin());
+
+		*Medium3.begin() = *High3.begin();
+	}
+
+	{
+		std::vector<glm::dvec2> High2;
+		std::vector<glm::vec2> Medium2(High2.size());
+
+		std::copy(&High2.begin()[0], &High2.end()[0], Medium2.begin());
+
+		*Medium2.begin() = *High2.begin();
+	}
+
+	glm::dvec4 v1;
+	glm::vec4 v2;
+
+	v2 = v1;
+
+	return Error;
+}
+
 int main()
 int main()
 {
 {
 	int Error = 0;
 	int Error = 0;
 
 
+	Error += test_std_copy();
 	Error += test_vec2_cast();
 	Error += test_vec2_cast();
 	Error += test_vec3_cast();
 	Error += test_vec3_cast();
 	Error += test_vec4_cast();
 	Error += test_vec4_cast();

+ 24 - 0
test/gtc/gtc_quaternion.cpp

@@ -196,6 +196,15 @@ int test_quat_slerp()
 	// Must be 0 0.00X 0 0.99999
 	// Must be 0 0.00X 0 0.99999
 	glm::quat almostid = glm::slerp(id, glm::angleAxis(0.1f, glm::vec3(0.0f, 1.0f, 0.0f)), 0.5f);
 	glm::quat almostid = glm::slerp(id, glm::angleAxis(0.1f, glm::vec3(0.0f, 1.0f, 0.0f)), 0.5f);
 
 
+	// Testing quaternions with opposite sign
+	{
+		glm::quat a(-1, 0, 0, 0);
+
+		glm::quat result = glm::slerp(a, id, 0.5f);
+
+		Error += glm::epsilonEqual(glm::pow(glm::dot(id, result), 2.f), 1.f, 0.01f) ? 0 : 1;
+	}
+
 	return Error;
 	return Error;
 }
 }
 
 
@@ -247,6 +256,20 @@ int test_quat_type()
 	return 0;
 	return 0;
 }
 }
 
 
+int test_quat_mul_vec()
+{
+	int Error(0);
+
+	glm::quat q = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
+	glm::vec3 v(1, 0, 0);
+	glm::vec3 u(q * v);
+	glm::vec3 w(u * q);
+
+	Error += glm::all(glm::epsilonEqual(v, w, 0.01f)) ? 0 : 1;
+
+	return Error;
+}
+
 int test_quat_ctr()
 int test_quat_ctr()
 {
 {
 	int Error(0);
 	int Error(0);
@@ -269,6 +292,7 @@ int main()
 	int Error(0);
 	int Error(0);
 
 
 	Error += test_quat_ctr();
 	Error += test_quat_ctr();
+	Error += test_quat_mul_vec();
 	Error += test_quat_two_axis_ctr();
 	Error += test_quat_two_axis_ctr();
 	Error += test_quat_mul();
 	Error += test_quat_mul();
 	Error += test_quat_precision();
 	Error += test_quat_precision();

+ 18 - 0
test/gtx/gtx_fast_square_root.cpp

@@ -27,11 +27,29 @@ int test_fastInverseSqrt()
 	return 0;
 	return 0;
 }
 }
 
 
+int test_fastDistance()
+{
+	int Error(0);
+
+	glm::mediump_f32 A = glm::fastDistance(glm::mediump_f32(0.0f), glm::mediump_f32(1.0f));
+	glm::mediump_f32 B = glm::fastDistance(glm::mediump_f32vec2(0.0f), glm::mediump_f32vec2(1.0f, 0.0f));
+	glm::mediump_f32 C = glm::fastDistance(glm::mediump_f32vec3(0.0f), glm::mediump_f32vec3(1.0f, 0.0f, 0.0f));
+	glm::mediump_f32 D = glm::fastDistance(glm::mediump_f32vec4(0.0f), glm::mediump_f32vec4(1.0f, 0.0f, 0.0f, 0.0f));
+
+	Error += glm::epsilonEqual(A, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
+	Error += glm::epsilonEqual(B, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
+	Error += glm::epsilonEqual(C, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
+	Error += glm::epsilonEqual(D, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
+
+	return Error;
+}
+
 int main()
 int main()
 {
 {
 	int Error(0);
 	int Error(0);
 
 
 	Error += test_fastInverseSqrt();
 	Error += test_fastInverseSqrt();
+	Error += test_fastDistance();
 
 
 	return Error;
 	return Error;
 }
 }

+ 73 - 16
test/gtx/gtx_io.cpp

@@ -11,6 +11,7 @@
 #include <glm/gtc/type_precision.hpp>
 #include <glm/gtc/type_precision.hpp>
 #include <glm/gtx/io.hpp>
 #include <glm/gtx/io.hpp>
 #include <iostream>
 #include <iostream>
+#include <sstream>
 #include <typeinfo>
 #include <typeinfo>
 
 
 namespace {
 namespace {
@@ -32,8 +33,60 @@ namespace {
     return os;
     return os;
   }
   }
 
 
+  template <typename U, glm::precision P, typename T, typename CTy, typename CTr>
+  std::basic_string<CTy>
+  type_name(std::basic_ostream<CTy,CTr>& os, T const&)
+  {
+    std::basic_ostringstream<CTy,CTr> ostr;
+    
+    if      (typeid(T) == typeid(glm::detail::tquat<U,P>))   { ostr << "quat"; }
+    else if (typeid(T) == typeid(glm::detail::tvec2<U,P>))   { ostr << "vec2"; }
+    else if (typeid(T) == typeid(glm::detail::tvec3<U,P>))   { ostr << "vec3"; }
+    else if (typeid(T) == typeid(glm::detail::tvec4<U,P>))   { ostr << "vec4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x2<U,P>)) { ostr << "mat2x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x3<U,P>)) { ostr << "mat2x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat2x4<U,P>)) { ostr << "mat2x4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x2<U,P>)) { ostr << "mat3x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x3<U,P>)) { ostr << "mat3x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat3x4<U,P>)) { ostr << "mat3x4"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x2<U,P>)) { ostr << "mat4x2"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x3<U,P>)) { ostr << "mat4x3"; }
+    else if (typeid(T) == typeid(glm::detail::tmat4x4<U,P>)) { ostr << "mat4x4"; }
+    else                                                     { ostr << "unknown"; }
+
+    ostr << '<' << typeid(U).name() << ',' << P << '>';
+
+    return ostr.str();
+  }
+  
 } // namespace {
 } // namespace {
 
 
+template <typename T, glm::precision P, typename OS>
+int test_io_quat(OS& os)
+{
+  os << '\n'
+     << typeid(OS).name()
+     << '\n';
+  
+  glm::detail::tquat<T,P> const q(1, 0, 0, 0);
+
+  {
+    glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
+    
+    os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
+       << type_name<T,P>(os, q) << ": " << q << '\n';
+  }
+  
+  {
+    glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
+  
+    os << glm::io::unformatted
+       << type_name<T,P>(os, q) << ": " << q << '\n';
+  }  
+
+  return 0;
+}
+
 template <typename T, glm::precision P, typename OS>
 template <typename T, glm::precision P, typename OS>
 int test_io_vec(OS& os)
 int test_io_vec(OS& os)
 {
 {
@@ -45,18 +98,16 @@ int test_io_vec(OS& os)
   glm::detail::tvec3<T,P> const v3(2, 3, 4);
   glm::detail::tvec3<T,P> const v3(2, 3, 4);
   glm::detail::tvec4<T,P> const v4(5, 6, 7, 8);
   glm::detail::tvec4<T,P> const v4(5, 6, 7, 8);
 
 
-  os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n'
-     << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n'
-     << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n';
+  os << type_name<T,P>(os, v2) << ": " << v2 << '\n'
+     << type_name<T,P>(os, v3) << ": " << v3 << '\n'
+     << type_name<T,P>(os, v4) << ": " << v4 << '\n';
 
 
-  glm::io::precision_guard const iopg;
-  
-  glm::io::precision()   = 2;
-  glm::io::value_width() = 1 + 2 + 1 + glm::io::precision();
+  glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
   
   
-  os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n'
-     << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n'
-     << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n';
+  os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
+     << type_name<T,P>(os, v2) << ": " << v2 << '\n'
+     << type_name<T,P>(os, v3) << ": " << v3 << '\n'
+     << type_name<T,P>(os, v4) << ": " << v4 << '\n';
 
 
   return 0;
   return 0;
 }
 }
@@ -93,12 +144,10 @@ int test_io_mat(OS& os)
      << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4<T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
      << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4<T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
 #endif
 #endif
   
   
-  glm::io::precision_guard const iopg;
-  
-  glm::io::precision()   = 2;
-  glm::io::value_width() = 1 + 2 + 1 + glm::io::precision();
+  glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
   
   
-  os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2<T,P>(v2_1, v2_2) << '\n'
+  os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
+     << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2<T,P>(v2_1, v2_2) << '\n'
      << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3<T,P>(v3_1, v3_2) << '\n'
      << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3<T,P>(v3_1, v3_2) << '\n'
      << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4<T,P>(v4_1, v4_2) << '\n'
      << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4<T,P>(v4_1, v4_2) << '\n'
      << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2<T,P>(v2_1, v2_2, v2_3) << '\n'
      << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2<T,P>(v2_1, v2_2, v2_3) << '\n'
@@ -108,7 +157,8 @@ int test_io_mat(OS& os)
      << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3<T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
      << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3<T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
      << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4<T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
      << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4<T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
   
   
-  os << glm::io::column_major
+  os << glm::io::unformatted
+     << glm::io::order(glm::io::column_major)
      << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2<T,P>(v2_1, v2_2) << '\n'
      << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2<T,P>(v2_1, v2_2) << '\n'
      << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3<T,P>(v3_1, v3_2) << '\n'
      << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3<T,P>(v3_1, v3_2) << '\n'
      << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4<T,P>(v4_1, v4_2) << '\n'
      << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4<T,P>(v4_1, v4_2) << '\n'
@@ -126,6 +176,13 @@ int main()
 {
 {
 	int Error(0);
 	int Error(0);
 
 
+	Error += test_io_quat<float, glm::highp>(std::cout);
+	Error += test_io_quat<float, glm::highp>(std::wcout);
+	Error += test_io_quat<int, glm::mediump>(std::cout);
+	Error += test_io_quat<int, glm::mediump>(std::wcout);
+	Error += test_io_quat<glm::uint, glm::lowp>(std::cout);
+	Error += test_io_quat<glm::uint, glm::lowp>(std::wcout);
+
 	Error += test_io_vec<float, glm::highp>(std::cout);
 	Error += test_io_vec<float, glm::highp>(std::cout);
 	Error += test_io_vec<float, glm::highp>(std::wcout);
 	Error += test_io_vec<float, glm::highp>(std::wcout);
 	Error += test_io_vec<int, glm::mediump>(std::cout);
 	Error += test_io_vec<int, glm::mediump>(std::cout);