diff --git a/glm/core/setup.hpp b/glm/core/setup.hpp index d4a54ba4..fd110011 100644 --- a/glm/core/setup.hpp +++ b/glm/core/setup.hpp @@ -718,7 +718,7 @@ #if(defined(GLM_MESSAGES) && !defined(GLM_MESSAGE_SWIZZLE_DISPLAYED)) # define GLM_MESSAGE_SWIZZLE_DISPLAYED -# if defined(GLM_SWIZZL) +# if defined(GLM_SWIZZLE) # pragma message("GLM: Swizzling operators enabled") # else # pragma message("GLM: Swizzling operators disabled") diff --git a/glm/ext.hpp b/glm/ext.hpp index b3d98a3b..f6a4d229 100644 --- a/glm/ext.hpp +++ b/glm/ext.hpp @@ -100,6 +100,7 @@ #include "./gtx/int_10_10_10_2.hpp" #include "./gtx/integer.hpp" #include "./gtx/intersect.hpp" +#include "./gtx/io.hpp" #include "./gtx/log_base.hpp" #include "./gtx/matrix_cross_product.hpp" #include "./gtx/matrix_interpolation.hpp" diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 982d8e5d..cc3c76ad 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -106,6 +106,8 @@ namespace detail GLM_FUNC_DECL T const & operator[](int i) const; // Operators + GLM_FUNC_DECL tquat & operator+=(tquat const & q); + GLM_FUNC_DECL tquat & operator*=(tquat const & q); GLM_FUNC_DECL tquat & operator*=(T const & s); GLM_FUNC_DECL tquat & operator/=(T const & s); }; diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index ab503cdb..e8aa037b 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -182,6 +182,34 @@ namespace detail ////////////////////////////////////////////////////////////// // tquat operators + template + GLM_FUNC_QUALIFIER tquat & tquat::operator += + ( + tquat const & q + ) + { + this->w += q.w; + this->x += q.x; + this->y += q.y; + this->z += q.z; + return *this; + } + + template + GLM_FUNC_QUALIFIER tquat & tquat::operator *= + ( + tquat const & q + ) + { + tquat const p(*this); + + this->w = p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z; + this->x = p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y; + this->y = p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z; + this->z = p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x; + return *this; + } + template GLM_FUNC_QUALIFIER tquat & tquat::operator *= ( @@ -194,7 +222,7 @@ namespace detail this->z *= s; return *this; } - + template GLM_FUNC_QUALIFIER tquat & tquat::operator /= ( @@ -227,11 +255,7 @@ namespace detail detail::tquat const & p ) { - return detail::tquat( - q.w + p.w, - q.x + p.x, - q.y + p.y, - q.z + p.z); + return detail::tquat(q) += p; } template @@ -241,11 +265,7 @@ namespace detail detail::tquat const & p ) { - return detail::tquat( - q.w * p.w - q.x * p.x - q.y * p.y - q.z * p.z, - q.w * p.x + q.x * p.w + q.y * p.z - q.z * p.y, - q.w * p.y + q.y * p.w + q.z * p.x - q.x * p.z, - q.w * p.z + q.z * p.w + q.x * p.y - q.y * p.x); + return detail::tquat(q) *= p; } // Transformation diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp new file mode 100644 index 00000000..d3bcb3db --- /dev/null +++ b/glm/gtx/io.hpp @@ -0,0 +1,159 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// 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 gtx_io +/// @file glm/gtx/io.hpp +/// @date 2013-11-22 +/// @author Jan P Springer (regnirpsj@gmail.com) +/// +/// @see core (dependence) +/// @see gtx_quaternion (dependence) +/// +/// @defgroup gtx_io GLM_GTX_io +/// @ingroup gtx +/// +/// @brief std::[w]ostream support for glm types +/// +/// needs to be included to use these functionalities. +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef GLM_GTX_io +#define GLM_GTX_io GLM_VERSION + +// Dependency: +#include "../glm.hpp" +#include "../gtx/quaternion.hpp" + +#if(defined(GLM_MESSAGES) && !defined(glm_ext)) +# pragma message("GLM: GLM_GTX_io extension included") +#endif + +#include // std::basic_ostream<> (fwd) +#include // std::pair<> + +namespace glm +{ + /// @addtogroup gtx_io + /// @{ + + namespace io + { + + class precision_guard { + + public: + + GLM_FUNC_DECL explicit precision_guard(); + GLM_FUNC_DECL ~precision_guard(); + + private: + + unsigned precision_; + unsigned value_width_; + + }; + + enum class order_t { column_major, row_major, }; + + class format_guard { + + public: + + GLM_FUNC_DECL explicit format_guard(); + GLM_FUNC_DECL ~format_guard(); + + private: + + order_t order_; + char cr_; + + }; + + // decimal places (dflt: 3) + GLM_FUNC_DECL unsigned& precision(); + + // sign + value + '.' + decimals (dflt: 1 + 4 + 1 + precision()) + GLM_FUNC_DECL unsigned& value_width(); + + // matrix output order (dflt: row_major) + GLM_FUNC_DECL order_t& order(); + + // carriage/return char (dflt: '\n') + GLM_FUNC_DECL char& cr(); + + // matrix output order -> column_major + GLM_FUNC_DECL std::ios_base& column_major(std::ios_base&); + + // matrix output order -> row_major + GLM_FUNC_DECL std::ios_base& row_major (std::ios_base&); + + // carriage/return char -> '\n' + GLM_FUNC_DECL std::ios_base& formatted (std::ios_base&); + + // carriage/return char -> ' ' + GLM_FUNC_DECL std::ios_base& unformatted (std::ios_base&); + + }//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" + +#endif//GLM_GTX_io diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl new file mode 100644 index 00000000..e588c480 --- /dev/null +++ b/glm/gtx/io.inl @@ -0,0 +1,420 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2013-11-22 +// Updated : 2013-11-22 +// Licence : This source is under MIT License +// File : glm/gtx/inl.inl +/////////////////////////////////////////////////////////////////////////////////////////////////// + +// #include // boost::io::ios_all_saver +#include // std::setfill<>, std::fixed, std::setprecision, std::right, + // std::setw +#include // std::basic_ostream<> + +namespace glm +{ + namespace io + { + + /* explicit */ GLM_FUNC_QUALIFIER + precision_guard::precision_guard() + : precision_ (precision()), + value_width_(value_width()) + {} + + GLM_FUNC_QUALIFIER + precision_guard::~precision_guard() + { + value_width() = value_width_; + precision() = precision_; + } + + /* explicit */ GLM_FUNC_QUALIFIER + format_guard::format_guard() + : order_(order()), + cr_ (cr()) + {} + + GLM_FUNC_QUALIFIER + format_guard::~format_guard() + { + cr() = cr_; + order() = order_; + } + + GLM_FUNC_QUALIFIER unsigned& + precision() + { + static unsigned p(3); + + return p; + } + + GLM_FUNC_QUALIFIER unsigned& + value_width() + { + static unsigned p(9); + + return p; + } + + GLM_FUNC_QUALIFIER order_t& + order() + { + static order_t p(order_t::row_major); + + return p; + } + + GLM_FUNC_QUALIFIER char& + cr() + { + static char p('\n'); return p; + } + + GLM_FUNC_QUALIFIER std::ios_base& + column_major(std::ios_base& os) + { + order() = order_t::column_major; + + return os; + } + + GLM_FUNC_QUALIFIER std::ios_base& + row_major(std::ios_base& os) + { + order() = order_t::row_major; + + return os; + } + + GLM_FUNC_QUALIFIER std::ios_base& + formatted(std::ios_base& os) + { + cr() = '\n'; + + return os; + } + + GLM_FUNC_QUALIFIER std::ios_base& + unformatted(std::ios_base& os) + { + cr() = ' '; + + return os; + } + + } // namespace io + + namespace detail { + + // functions, inlined (inline) + + 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) { + // boost::io::ios_all_saver const ias(os); + + os << std::fixed << std::setprecision(io::precision()) + << '[' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.w << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << 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) { + // boost::io::ios_all_saver const ias(os); + + os << std::fixed << std::setprecision(io::precision()) + << '[' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << 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) { + // boost::io::ios_all_saver const ias(os); + + os << std::fixed << std::setprecision(io::precision()) + << '[' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << 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) { + // boost::io::ios_all_saver const ias(os); + + os << std::fixed << std::setprecision(io::precision()) + << '[' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.x << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.y << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << a.z << ',' + << std::right << std::setfill(' ') << std::setw(io::value_width()) << 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) { + tmat2x2 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << 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) { + tmat3x2 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << 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) { + tmat4x2 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << m[2] << io::cr() + << ' ' << 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) { + tmat2x3 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << 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) { + tmat3x3 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << 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) { + tmat4x3 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << m[2] << io::cr() + << ' ' << 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) { + tmat2x4 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << 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) { + tmat3x4 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << 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) { + tmat4x4 m(a); + + if (io::order_t::row_major == io::order()) { + m = transpose(a); + } + + os << io::cr() + << '[' << m[0] << io::cr() + << ' ' << m[1] << io::cr() + << ' ' << m[2] << io::cr() + << ' ' << 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) { + tmat4x4 ml(a.first); + tmat4x4 mr(a.second); + + if (io::order_t::row_major == io::order()) { + ml = transpose(a.first); + mr = transpose(a.second); + } + + os << io::cr() + << '[' << ml[0] << " [" << mr[0] << io::cr() + << ' ' << ml[1] << " " << mr[1] << io::cr() + << ' ' << ml[2] << " " << mr[2] << io::cr() + << ' ' << ml[3] << "] " << mr[3] << ']'; + } + + return os; + } + + }//namespace detail +}//namespace glm diff --git a/glm/gtx/transform2.hpp b/glm/gtx/transform2.hpp index 9de35f4f..cdd196e4 100644 --- a/glm/gtx/transform2.hpp +++ b/glm/gtx/transform2.hpp @@ -54,7 +54,7 @@ namespace glm //! Transforms a matrix with a shearing on X axis. //! From GLM_GTX_transform2 extension. - template + template detail::tmat3x3 shearX2D( detail::tmat3x3 const & m, T y); diff --git a/glm/gtx/transform2.inl b/glm/gtx/transform2.inl index 52c16b25..a54b7251 100644 --- a/glm/gtx/transform2.inl +++ b/glm/gtx/transform2.inl @@ -9,7 +9,7 @@ namespace glm { - template + template GLM_FUNC_QUALIFIER detail::tmat3x3 shearX2D( const detail::tmat3x3& m, T s) @@ -19,7 +19,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat3x3 shearY2D( const detail::tmat3x3& m, T s) @@ -29,7 +29,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 shearX3D( const detail::tmat4x4& m, T s, @@ -41,7 +41,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 shearY3D( const detail::tmat4x4& m, T s, @@ -53,7 +53,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 shearZ3D( const detail::tmat4x4& m, T s, @@ -65,7 +65,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat3x3 reflect2D( const detail::tmat3x3& m, const detail::tvec3& normal) @@ -78,7 +78,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 reflect3D( const detail::tmat4x4& m, const detail::tvec3& normal) @@ -98,7 +98,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat3x3 proj2D( const detail::tmat3x3& m, const detail::tvec3& normal) @@ -111,7 +111,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 proj3D( const detail::tmat4x4& m, const detail::tvec3& normal) @@ -129,7 +129,7 @@ namespace glm return m * r; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 scaleBias( T scale, T bias) @@ -142,7 +142,7 @@ namespace glm return result; } - template + template GLM_FUNC_QUALIFIER detail::tmat4x4 scaleBias( const detail::tmat4x4& m, T scale, diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index e464832a..cd4f05e1 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -317,7 +318,7 @@ int test_vec4_perf_AoS(std::size_t Size) std::clock_t EndTime = std::clock(); - printf("AoS: %d\n", EndTime - StartTime); + std::printf("AoS: %d\n", EndTime - StartTime); return Error; } @@ -356,7 +357,7 @@ int test_vec4_perf_SoA(std::size_t Size) std::clock_t EndTime = std::clock(); - printf("SoA: %d\n", EndTime - StartTime); + std::printf("SoA: %d\n", EndTime - StartTime); return Error; } diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index be1638f7..079dbe7f 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -210,6 +210,15 @@ int test_quat_mul() glm::quat temp5 = glm::normalize(temp1 * temp2); glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5); + { + glm::quat temp7; + + temp7 *= temp5; + temp7 *= glm::inverse(temp5); + + Error += temp7 != glm::quat(); + } + return Error; } diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index 0c48ccbe..d3ba66a6 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -16,6 +16,7 @@ glmCreateTestGTC(gtx_handed_coordinate_space) glmCreateTestGTC(gtx_inertia) glmCreateTestGTC(gtx_integer) glmCreateTestGTC(gtx_intersect) +glmCreateTestGTC(gtx_io) glmCreateTestGTC(gtx_log_base) glmCreateTestGTC(gtx_matrix_cross_product) glmCreateTestGTC(gtx_matrix_interpolation) diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp new file mode 100644 index 00000000..d4e2aabc --- /dev/null +++ b/test/gtx/gtx_io.cpp @@ -0,0 +1,140 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2013-11-22 +// Updated : 2013-11-22 +// Licence : This source is under MIT licence +// File : test/gtx/io.cpp +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +namespace { + + template + std::basic_ostream& + operator<<(std::basic_ostream& os, glm::precision const& a) + { + typename std::basic_ostream::sentry const cerberus(os); + + if (cerberus) { + switch (a) { + case glm::highp: os << "hi"; break; + case glm::mediump: os << "md"; break; + case glm::lowp: os << "lo"; break; + } + } + + return os; + } + +} // namespace { + +template +int test_io_vec(OS& os) +{ + os << '\n' + << typeid(OS).name() + << '\n'; + + glm::detail::tvec2 const v2(0, 1); + glm::detail::tvec3 const v3(2, 3, 4); + glm::detail::tvec4 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'; + + glm::io::precision_guard const iopg; + + glm::io::precision() = 2; + glm::io::value_width() = 1 + 2 + 1 + glm::io::precision(); + + os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' + << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' + << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; + + return 0; +} + +template +int test_io_mat(OS& os) +{ + os << '\n' + << typeid(OS).name() + << '\n'; + + glm::detail::tvec2 const v2_1( 0, 1); + glm::detail::tvec2 const v2_2( 2, 3); + glm::detail::tvec2 const v2_3( 4, 5); + glm::detail::tvec2 const v2_4( 6, 7); + glm::detail::tvec3 const v3_1( 8, 9, 10); + glm::detail::tvec3 const v3_2(11, 12, 13); + glm::detail::tvec3 const v3_3(14, 15, 16); + glm::detail::tvec3 const v3_4(17, 18, 19); + glm::detail::tvec4 const v4_1(20, 21, 22, 23); + glm::detail::tvec4 const v4_2(24, 25, 26, 27); + glm::detail::tvec4 const v4_3(28, 29, 30, 31); + glm::detail::tvec4 const v4_4(32, 33, 34, 35); + +#if 0 + os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' + << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' + << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4(v4_1, v4_2) << '\n' + << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2(v2_1, v2_2, v2_3) << '\n' + << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x3(v3_1, v3_2, v3_3) << '\n' + << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x4(v4_1, v4_2, v4_3) << '\n' + << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x2(v2_1, v2_2, v2_3, v2_4) << '\n' + << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' + << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; +#endif + + glm::io::precision_guard const iopg; + + glm::io::precision() = 2; + glm::io::value_width() = 1 + 2 + 1 + glm::io::precision(); + + os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' + << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' + << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4(v4_1, v4_2) << '\n' + << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2(v2_1, v2_2, v2_3) << '\n' + << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x3(v3_1, v3_2, v3_3) << '\n' + << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x4(v4_1, v4_2, v4_3) << '\n' + << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x2(v2_1, v2_2, v2_3, v2_4) << '\n' + << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' + << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; + + os << glm::io::column_major + << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(v2_1, v2_2) << '\n' + << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x3(v3_1, v3_2) << '\n' + << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x4(v4_1, v4_2) << '\n' + << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x2(v2_1, v2_2, v2_3) << '\n' + << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x3(v3_1, v3_2, v3_3) << '\n' + << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat3x4(v4_1, v4_2, v4_3) << '\n' + << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x2(v2_1, v2_2, v2_3, v2_4) << '\n' + << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x3(v3_1, v3_2, v3_3, v3_4) << '\n' + << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat4x4(v4_1, v4_2, v4_3, v4_4) << '\n'; + + return 0; +} + +int main() +{ + int Error(0); + + Error += test_io_vec (std::cout); + Error += test_io_vec (std::wcout); + Error += test_io_vec(std::cout); + Error += test_io_vec(std::wcout); + Error += test_io_vec (std::cout); + Error += test_io_vec (std::wcout); + + Error += test_io_mat (std::cout); + Error += test_io_mat (std::wcout); + + return Error; +} diff --git a/test/gtx/gtx_simd_vec4.cpp b/test/gtx/gtx_simd_vec4.cpp index debe6bf8..8ce92371 100644 --- a/test/gtx/gtx_simd_vec4.cpp +++ b/test/gtx/gtx_simd_vec4.cpp @@ -34,7 +34,7 @@ int main() glm::simdVec4 GNI(add0); - printf("%f\n", GNI.Data.m128_f32); + printf("%f\n", GNI.Data /* .m128_f32 */); return 0; }