From 623cdaa55274168f96ee5413aa039f3b935080c6 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Tue, 17 Dec 2013 22:37:34 +0000 Subject: [PATCH 01/24] reimplemented io support for basic types --- glm/gtx/io.hpp | 118 ++++++++---- glm/gtx/io.inl | 450 +++++++++++++++++++++++++++++--------------- test/gtx/gtx_io.cpp | 52 +++-- 3 files changed, 420 insertions(+), 200 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index d3bcb3db..71ae187d 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -33,6 +33,10 @@ /// /// @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] +/// /// needs to be included to use these functionalities. /////////////////////////////////////////////////////////////////////////////////// @@ -47,8 +51,11 @@ # pragma message("GLM: GLM_GTX_io extension included") #endif -#include // std::basic_ostream<> (fwd) -#include // std::pair<> +#include // basic_ios_all_saver<> (fwd) +#include // boost::noncopyable +#include // std::basic_ostream<> (fwd) +#include // std::locale, std::locale::facet, std::locale::id +#include // std::pair<> namespace glm { @@ -58,60 +65,103 @@ namespace glm namespace io { - class precision_guard { + enum class order_type { column_major, row_major, }; + + template + class format_punct : public std::locale::facet { - public: + typedef CTy char_type; - GLM_FUNC_DECL explicit precision_guard(); - GLM_FUNC_DECL ~precision_guard(); - - private: + public: - unsigned precision_; - unsigned value_width_; + 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&); }; - enum class order_t { column_major, row_major, }; - - class format_guard { + template > + class basic_format_saver : private boost::noncopyable { public: - GLM_FUNC_DECL explicit format_guard(); - GLM_FUNC_DECL ~format_guard(); - + explicit basic_format_saver(std::basic_ios&); + ~basic_format_saver(); + private: - order_t order_; - char cr_; + boost::io::basic_ios_all_saver const ias_; }; - // decimal places (dflt: 3) - GLM_FUNC_DECL unsigned& precision(); + typedef basic_format_saver format_saver; + typedef basic_format_saver wformat_saver; + + struct formatted { /* empty */ }; + struct unformatted { /* empty */ }; + + struct precision { - // sign + value + '.' + decimals (dflt: 1 + 4 + 1 + precision()) - GLM_FUNC_DECL unsigned& value_width(); + unsigned value; + + explicit precision(unsigned); + + }; - // matrix output order (dflt: row_major) - GLM_FUNC_DECL order_t& order(); + struct width { - // carriage/return char (dflt: '\n') - GLM_FUNC_DECL char& cr(); + unsigned value; + + explicit width(unsigned); + + }; - // matrix output order -> column_major - GLM_FUNC_DECL std::ios_base& column_major(std::ios_base&); + template + struct delimeter { - // matrix output order -> row_major - GLM_FUNC_DECL std::ios_base& row_major (std::ios_base&); + CTy value[3]; + + explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ','); + + }; - // carriage/return char -> '\n' - GLM_FUNC_DECL std::ios_base& formatted (std::ios_base&); + struct order { - // carriage/return char -> ' ' - GLM_FUNC_DECL std::ios_base& unformatted (std::ios_base&); + order_type value; + + explicit order(order_type); + + }; + + // functions, inlined (inline) + template + FTy const& get_facet(std::basic_ios&); + + template + std::basic_ostream& operator<<(std::basic_ostream&, formatted const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, unformatted const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, precision const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, width const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, delimeter const&); + template + std::basic_ostream& operator<<(std::basic_ostream&, order const&); + }//namespace io namespace detail diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index e588c480..c102f10a 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -2,12 +2,12 @@ // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2013-11-22 -// Updated : 2013-11-22 +// Updated : 2013-12-17 // Licence : This source is under MIT License // File : glm/gtx/inl.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -// #include // boost::io::ios_all_saver +#include // boost::io::ios_all_saver #include // std::setfill<>, std::fixed, std::setprecision, std::right, // std::setw #include // std::basic_ostream<> @@ -17,91 +17,143 @@ namespace glm namespace io { + template /* explicit */ GLM_FUNC_QUALIFIER - precision_guard::precision_guard() - : precision_ (precision()), - value_width_(value_width()) + format_punct::format_punct(size_t a) + : std::locale::facet(a), + formatted (true), + precision (3), + width (1 + 4 + 1 + precision), + separator (','), + delim_left ('['), + delim_right (']'), + space (' '), + newline ('\n'), + order (order_type::row_major) {} - GLM_FUNC_QUALIFIER - precision_guard::~precision_guard() + template + /* explicit */ GLM_FUNC_QUALIFIER + format_punct::format_punct(format_punct const& a) + : std::locale::facet(0), + formatted (a.formatted), + precision (a.precision), + width (a.width), + separator (a.separator), + delim_left (a.delim_left), + delim_right (a.delim_right), + space (a.space), + newline (a.newline), + order (a.order) + {} + + template std::locale::id format_punct::id; + + template + /* explicit */ GLM_FUNC_QUALIFIER + basic_format_saver::basic_format_saver(std::basic_ios& a) + : boost::noncopyable(), + ias_ (a) { - value_width() = value_width_; - precision() = precision_; + a.imbue(std::locale(a.getloc(), new format_punct(get_facet>(a)))); } + template + GLM_FUNC_QUALIFIER + basic_format_saver::~basic_format_saver() + {} + + /* explicit */ GLM_FUNC_QUALIFIER + precision::precision(unsigned a) + : value(a) + {} + /* explicit */ GLM_FUNC_QUALIFIER - format_guard::format_guard() - : order_(order()), - cr_ (cr()) + width::width(unsigned a) + : value(a) {} - GLM_FUNC_QUALIFIER - format_guard::~format_guard() + template + /* explicit */ GLM_FUNC_QUALIFIER + delimeter::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() - { - static unsigned p(3); - - return p; - } + /* explicit */ GLM_FUNC_QUALIFIER + order::order(order_type a) + : value(a) + {} - GLM_FUNC_QUALIFIER unsigned& - value_width() + template + GLM_FUNC_QUALIFIER FTy const& + get_facet(std::basic_ios& ios) { - static unsigned p(9); + if (!std::has_facet(ios.getloc())) { + ios.imbue(std::locale(ios.getloc(), new FTy)); + } - return p; + return std::use_facet(ios.getloc()); } - - GLM_FUNC_QUALIFIER order_t& - order() + + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, formatted const&) { - static order_t p(order_t::row_major); + const_cast&>(get_facet>(os)).formatted = true; - return p; + return os; } - - GLM_FUNC_QUALIFIER char& - cr() + + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, unformatted const&) { - static char p('\n'); return p; + const_cast&>(get_facet>(os)).formatted = false; + + return os; } - GLM_FUNC_QUALIFIER std::ios_base& - column_major(std::ios_base& os) + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, precision const& a) { - order() = order_t::column_major; - + const_cast&>(get_facet>(os)).precision = a.value; + return os; } - - GLM_FUNC_QUALIFIER std::ios_base& - row_major(std::ios_base& os) + + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, width const& a) { - order() = order_t::row_major; - + const_cast&>(get_facet>(os)).width = a.value; + return os; } - GLM_FUNC_QUALIFIER std::ios_base& - formatted(std::ios_base& os) + template + std::basic_ostream& operator<<(std::basic_ostream& os, + delimeter const& a) { - cr() = '\n'; + format_punct& fmt(const_cast&>(get_facet>(os))); + + fmt.delim_left = a.value[0]; + fmt.delim_right = a.value[1]; + fmt.separator = a.value[2]; return os; } - - GLM_FUNC_QUALIFIER std::ios_base& - unformatted(std::ios_base& os) + + template + GLM_FUNC_QUALIFIER std::basic_ostream& + operator<<(std::basic_ostream& os, order const& a) { - cr() = ' '; - + const_cast&>(get_facet>(os)).order = a.value; + return os; } @@ -109,8 +161,6 @@ namespace glm namespace detail { - // functions, inlined (inline) - template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tquat const& a) @@ -118,17 +168,26 @@ namespace glm 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 - << ']'; - } + io::format_punct const& fmt(io::get_facet>(os)); + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; } @@ -139,13 +198,22 @@ namespace glm 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 - << ']'; + io::format_punct const& fmt(io::get_facet>(os)); + + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; @@ -158,19 +226,28 @@ namespace glm 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 - << ']'; + io::format_punct const& fmt(io::get_facet>(os)); + + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(os); + + os << std::fixed + << std::right + << std::setprecision(fmt.precision) + << std::setfill(fmt.space) + << fmt.delim_left + << std::setw(fmt.width) << a.x << fmt.separator + << std::setw(fmt.width) << a.y << fmt.separator + << std::setw(fmt.width) << a.z + << fmt.delim_right; + } else { + os << a.x << fmt.space << a.y << fmt.space << a.z; + } } - + return os; } - + template GLM_FUNC_QUALIFIER std::basic_ostream& operator<<(std::basic_ostream& os, tvec4 const& a) @@ -178,17 +255,26 @@ namespace glm 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 - << ']'; - } + io::format_punct const& fmt(io::get_facet>(os)); + if (fmt.formatted) { + boost::io::basic_ios_all_saver const ias(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; } @@ -199,15 +285,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + + 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; @@ -220,16 +311,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -242,17 +338,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x2 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x2 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -265,15 +366,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + 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; @@ -286,16 +392,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -308,17 +419,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x3 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x3 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -331,15 +447,20 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat2x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat2x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << ']'; + 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; @@ -352,16 +473,21 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat3x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat3x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << ']'; + 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; @@ -374,17 +500,22 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x4 m(a); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x4 m(a); - if (io::order_t::row_major == io::order()) { + if (io::order_type::row_major == fmt.order) { m = transpose(a); } - os << io::cr() - << '[' << m[0] << io::cr() - << ' ' << m[1] << io::cr() - << ' ' << m[2] << io::cr() - << ' ' << m[3] << ']'; + 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; @@ -398,19 +529,28 @@ namespace glm typename std::basic_ostream::sentry const cerberus(os); if (cerberus) { - tmat4x4 ml(a.first); - tmat4x4 mr(a.second); + io::format_punct const& fmt(io::get_facet>(os)); + tmat4x4 ml(a.first); + tmat4x4 mr(a.second); - if (io::order_t::row_major == io::order()) { + if (io::order_type::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 << io::cr() - << '[' << ml[0] << " [" << mr[0] << io::cr() - << ' ' << ml[1] << " " << mr[1] << io::cr() - << ' ' << ml[2] << " " << mr[2] << io::cr() - << ' ' << ml[3] << "] " << mr[3] << ']'; + 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; diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index 86792bc9..1f23a4f2 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -34,6 +34,32 @@ namespace { } // namespace { +template +int test_io_quat(OS& os) +{ + os << '\n' + << typeid(OS).name() + << '\n'; + + glm::detail::tquat const q(1, 0, 0, 0); + + { + glm::io::basic_format_saver const iofs(os); + + os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + } + + { + glm::io::basic_format_saver const iofs(os); + + os << glm::io::unformatted() + << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + } + + return 0; +} + template int test_io_vec(OS& os) { @@ -49,12 +75,10 @@ int test_io_vec(OS& os) << "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(); + glm::io::basic_format_saver const iofs(os); - os << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' + os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) + << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; @@ -93,12 +117,10 @@ int test_io_mat(OS& os) << "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(); + glm::io::basic_format_saver const iofs(os); - os << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::detail::tmat2x2(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(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' @@ -108,7 +130,8 @@ int test_io_mat(OS& os) << "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 + os << glm::io::unformatted() + << glm::io::order(glm::io::order_type::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' @@ -126,6 +149,13 @@ int main() { int Error(0); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_quat(std::cout); + Error += test_io_quat(std::wcout); + Error += test_io_vec(std::cout); Error += test_io_vec(std::wcout); Error += test_io_vec(std::cout); From 0e3cebf23a48c0ddb3763d9d7eedaf4cfef664d8 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Wed, 18 Dec 2013 10:34:06 +0000 Subject: [PATCH 02/24] removed boost dependencies --- glm/gtx/io.hpp | 46 +++++++++++++++++++++++++++++++++++++-------- glm/gtx/io.inl | 41 +++++++++++++++++++++++++++++----------- test/gtx/gtx_io.cpp | 43 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 103 insertions(+), 27 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index 71ae187d..f1b8dd53 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -26,7 +26,7 @@ /// @author Jan P Springer (regnirpsj@gmail.com) /// /// @see core (dependence) -/// @see gtx_quaternion (dependence) +/// @see gtc_quaternion (dependence) /// /// @defgroup gtx_io GLM_GTX_io /// @ingroup gtx @@ -51,11 +51,9 @@ # pragma message("GLM: GLM_GTX_io extension included") #endif -#include // basic_ios_all_saver<> (fwd) -#include // boost::noncopyable -#include // std::basic_ostream<> (fwd) -#include // std::locale, std::locale::facet, std::locale::id -#include // std::pair<> +#include // std::basic_ostream<> (fwd) +#include // std::locale, std::locale::facet, std::locale::id +#include // std::pair<> namespace glm { @@ -92,7 +90,37 @@ namespace glm }; template > - class basic_format_saver : private boost::noncopyable { + class basic_state_saver { + + public: + + explicit basic_state_saver(std::basic_ios&); + ~basic_state_saver(); + + private: + + typedef ::std::basic_ios state_type; + typedef typename state_type::char_type char_type; + typedef ::std::ios_base::fmtflags flags_type; + typedef ::std::streamsize streamsize_type; + typedef ::std::locale const locale_type; + + state_type& state_; + flags_type flags_; + streamsize_type precision_; + streamsize_type width_; + char_type fill_; + locale_type locale_; + + basic_state_saver& operator=(basic_state_saver const&); + + }; + + typedef basic_state_saver state_saver; + typedef basic_state_saver wstate_saver; + + template > + class basic_format_saver { public: @@ -101,7 +129,9 @@ namespace glm private: - boost::io::basic_ios_all_saver const ias_; + basic_state_saver const bss_; + + basic_format_saver& operator=(basic_format_saver const&); }; diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index c102f10a..7d3e88fc 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -2,15 +2,13 @@ // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2013-11-22 -// Updated : 2013-12-17 +// Updated : 2013-12-18 // 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<> +#include // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw +#include // std::basic_ostream<> namespace glm { @@ -49,11 +47,32 @@ namespace glm template std::locale::id format_punct::id; + template + /* explicit */ GLM_FUNC_QUALIFIER + basic_state_saver::basic_state_saver(std::basic_ios& a) + : state_ (a), + flags_ (a.flags()), + precision_(a.precision()), + width_ (a.width()), + fill_ (a.fill()), + locale_ (a.getloc()) + {} + + template + GLM_FUNC_QUALIFIER + basic_state_saver::~basic_state_saver() + { + state_.imbue(locale_); + state_.fill(fill_); + state_.width(width_); + state_.precision(precision_); + state_.flags(flags_); + } + template /* explicit */ GLM_FUNC_QUALIFIER basic_format_saver::basic_format_saver(std::basic_ios& a) - : boost::noncopyable(), - ias_ (a) + : bss_(a) { a.imbue(std::locale(a.getloc(), new format_punct(get_facet>(a)))); } @@ -171,7 +190,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -201,7 +220,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -229,7 +248,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right @@ -258,7 +277,7 @@ namespace glm io::format_punct const& fmt(io::get_facet>(os)); if (fmt.formatted) { - boost::io::basic_ios_all_saver const ias(os); + io::basic_state_saver const bss(os); os << std::fixed << std::right diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index 1f23a4f2..e9ab76e7 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace { @@ -32,6 +33,32 @@ namespace { return os; } + template + std::basic_string + type_name(std::basic_ostream& os, T const&) + { + std::basic_ostringstream ostr; + + if (typeid(T) == typeid(glm::detail::tquat)) { ostr << "quat"; } + else if (typeid(T) == typeid(glm::detail::tvec2)) { ostr << "vec2"; } + else if (typeid(T) == typeid(glm::detail::tvec3)) { ostr << "vec3"; } + else if (typeid(T) == typeid(glm::detail::tvec4)) { ostr << "vec4"; } + else if (typeid(T) == typeid(glm::detail::tmat2x2)) { ostr << "mat2x2"; } + else if (typeid(T) == typeid(glm::detail::tmat2x3)) { ostr << "mat2x3"; } + else if (typeid(T) == typeid(glm::detail::tmat2x4)) { ostr << "mat2x4"; } + else if (typeid(T) == typeid(glm::detail::tmat3x2)) { ostr << "mat3x2"; } + else if (typeid(T) == typeid(glm::detail::tmat3x3)) { ostr << "mat3x3"; } + else if (typeid(T) == typeid(glm::detail::tmat3x4)) { ostr << "mat3x4"; } + else if (typeid(T) == typeid(glm::detail::tmat4x2)) { ostr << "mat4x2"; } + else if (typeid(T) == typeid(glm::detail::tmat4x3)) { ostr << "mat4x3"; } + else if (typeid(T) == typeid(glm::detail::tmat4x4)) { ostr << "mat4x4"; } + else { ostr << "unknown"; } + + ostr << '<' << typeid(U).name() << ',' << P << '>'; + + return ostr.str(); + } + } // namespace { template @@ -47,14 +74,14 @@ int test_io_quat(OS& os) glm::io::basic_format_saver const iofs(os); os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) - << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + << type_name(os, q) << ": " << q << '\n'; } { glm::io::basic_format_saver const iofs(os); os << glm::io::unformatted() - << "quat<" << typeid(T).name() << ',' << P << ">: " << q << '\n'; + << type_name(os, q) << ": " << q << '\n'; } return 0; @@ -71,16 +98,16 @@ int test_io_vec(OS& os) 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'; + os << type_name(os, v2) << ": " << v2 << '\n' + << type_name(os, v3) << ": " << v3 << '\n' + << type_name(os, v4) << ": " << v4 << '\n'; glm::io::basic_format_saver const iofs(os); os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2) - << "vec2<" << typeid(T).name() << ',' << P << ">: " << v2 << '\n' - << "vec3<" << typeid(T).name() << ',' << P << ">: " << v3 << '\n' - << "vec4<" << typeid(T).name() << ',' << P << ">: " << v4 << '\n'; + << type_name(os, v2) << ": " << v2 << '\n' + << type_name(os, v3) << ": " << v3 << '\n' + << type_name(os, v4) << ": " << v4 << '\n'; return 0; } From 39179ba1adde7f860826bc5e667f0f224758e5b3 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Thu, 26 Dec 2013 15:15:53 +0000 Subject: [PATCH 03/24] un/formatted() usage to un/formatted --- glm/gtx/io.hpp | 11 ++++------- glm/gtx/io.inl | 18 +++++++++--------- test/gtx/gtx_io.cpp | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/glm/gtx/io.hpp b/glm/gtx/io.hpp index f1b8dd53..9e68cd39 100644 --- a/glm/gtx/io.hpp +++ b/glm/gtx/io.hpp @@ -138,9 +138,6 @@ namespace glm typedef basic_format_saver format_saver; typedef basic_format_saver wformat_saver; - struct formatted { /* empty */ }; - struct unformatted { /* empty */ }; - struct precision { unsigned value; @@ -178,11 +175,11 @@ namespace glm template FTy const& get_facet(std::basic_ios&); + template + std::basic_ios& formatted(std::basic_ios&); + template + std::basic_ios& unformattet(std::basic_ios&); - template - std::basic_ostream& operator<<(std::basic_ostream&, formatted const&); - template - std::basic_ostream& operator<<(std::basic_ostream&, unformatted const&); template std::basic_ostream& operator<<(std::basic_ostream&, precision const&); template diff --git a/glm/gtx/io.inl b/glm/gtx/io.inl index 7d3e88fc..84fc29d9 100644 --- a/glm/gtx/io.inl +++ b/glm/gtx/io.inl @@ -119,21 +119,21 @@ namespace glm } template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, formatted const&) + GLM_FUNC_QUALIFIER std::basic_ios& + formatted(std::basic_ios& ios) { - const_cast&>(get_facet>(os)).formatted = true; + const_cast&>(get_facet>(ios)).formatted = true; - return os; + return ios; } - + template - GLM_FUNC_QUALIFIER std::basic_ostream& - operator<<(std::basic_ostream& os, unformatted const&) + GLM_FUNC_QUALIFIER std::basic_ios& + unformatted(std::basic_ios& ios) { - const_cast&>(get_facet>(os)).formatted = false; + const_cast&>(get_facet>(ios)).formatted = false; - return os; + return ios; } template diff --git a/test/gtx/gtx_io.cpp b/test/gtx/gtx_io.cpp index e9ab76e7..8c479b5f 100644 --- a/test/gtx/gtx_io.cpp +++ b/test/gtx/gtx_io.cpp @@ -80,7 +80,7 @@ int test_io_quat(OS& os) { glm::io::basic_format_saver const iofs(os); - os << glm::io::unformatted() + os << glm::io::unformatted << type_name(os, q) << ": " << q << '\n'; } @@ -157,7 +157,7 @@ int test_io_mat(OS& os) << "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::unformatted() + os << glm::io::unformatted << glm::io::order(glm::io::order_type::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' From 478dc697ff9c46a034c9bc4143d6498ae63f98df Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:11:25 +0100 Subject: [PATCH 04/24] fixed: compile problems w/ non-existent header files --- glm/ext.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/ext.hpp b/glm/ext.hpp index 95121dc7..5ea95f2f 100644 --- a/glm/ext.hpp +++ b/glm/ext.hpp @@ -73,7 +73,7 @@ #include "./gtc/quaternion.hpp" #include "./gtc/random.hpp" #include "./gtc/reciprocal.hpp" -#include "./gtc/swizzle.hpp" +// #include "./gtc/swizzle.hpp" #include "./gtc/type_precision.hpp" #include "./gtc/type_ptr.hpp" #include "./gtc/ulp.hpp" @@ -81,7 +81,7 @@ #include "./gtx/associated_min_max.hpp" #include "./gtx/bit.hpp" #include "./gtx/closest_point.hpp" -#include "./gtx/color_cast.hpp" +// #include "./gtx/color_cast.hpp" #include "./gtx/color_space.hpp" #include "./gtx/color_space_YCoCg.hpp" #include "./gtx/compatibility.hpp" From ae691ce39ada6783f451869350425325836a6b2b Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:12:38 +0100 Subject: [PATCH 05/24] commented out already declred types (in glm/fwd.hpp) --- glm/gtc/type_precision.hpp | 164 ++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/glm/gtc/type_precision.hpp b/glm/gtc/type_precision.hpp index 5894bc58..bc4a1c91 100644 --- a/glm/gtc/type_precision.hpp +++ b/glm/gtc/type_precision.hpp @@ -255,70 +255,70 @@ namespace glm /// 8 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i8vec1; + // typedef detail::tvec1 i8vec1; /// 8 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i8vec2; + //typedef detail::tvec2 i8vec2; /// 8 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i8vec3; + //typedef detail::tvec3 i8vec3; /// 8 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i8vec4; + //typedef detail::tvec4 i8vec4; /// 16 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i16vec1; + //typedef detail::tvec1 i16vec1; /// 16 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i16vec2; + //typedef detail::tvec2 i16vec2; /// 16 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i16vec3; + //typedef detail::tvec3 i16vec3; /// 16 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i16vec4; + //typedef detail::tvec4 i16vec4; /// 32 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i32vec1; + //typedef detail::tvec1 i32vec1; /// 32 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i32vec2; + //typedef detail::tvec2 i32vec2; /// 32 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i32vec3; + //typedef detail::tvec3 i32vec3; /// 32 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i32vec4; + //typedef detail::tvec4 i32vec4; /// 64 bit signed integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 i64vec1; + //typedef detail::tvec1 i64vec1; /// 64 bit signed integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 i64vec2; + //typedef detail::tvec2 i64vec2; /// 64 bit signed integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 i64vec3; + //typedef detail::tvec3 i64vec3; /// 64 bit signed integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 i64vec4; + //typedef detail::tvec4 i64vec4; ///////////////////////////// @@ -520,70 +520,70 @@ namespace glm /// Default precision 8 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u8vec1; + //typedef detail::tvec1 u8vec1; /// Default precision 8 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u8vec2; + //typedef detail::tvec2 u8vec2; /// Default precision 8 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u8vec3; + //typedef detail::tvec3 u8vec3; /// Default precision 8 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u8vec4; + //typedef detail::tvec4 u8vec4; /// Default precision 16 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u16vec1; + //typedef detail::tvec1 u16vec1; /// Default precision 16 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u16vec2; + //typedef detail::tvec2 u16vec2; /// Default precision 16 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u16vec3; + //typedef detail::tvec3 u16vec3; /// Default precision 16 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u16vec4; + //typedef detail::tvec4 u16vec4; /// Default precision 32 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u32vec1; + //typedef detail::tvec1 u32vec1; /// Default precision 32 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u32vec2; + //typedef detail::tvec2 u32vec2; /// Default precision 32 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u32vec3; + //typedef detail::tvec3 u32vec3; /// Default precision 32 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u32vec4; + //typedef detail::tvec4 u32vec4; /// Default precision 64 bit unsigned integer scalar type. /// @see gtc_type_precision - typedef detail::tvec1 u64vec1; + //typedef detail::tvec1 u64vec1; /// Default precision 64 bit unsigned integer vector of 2 components type. /// @see gtc_type_precision - typedef detail::tvec2 u64vec2; + //typedef detail::tvec2 u64vec2; /// Default precision 64 bit unsigned integer vector of 3 components type. /// @see gtc_type_precision - typedef detail::tvec3 u64vec3; + //typedef detail::tvec3 u64vec3; /// Default precision 64 bit unsigned integer vector of 4 components type. /// @see gtc_type_precision - typedef detail::tvec4 u64vec4; + //typedef detail::tvec4 u64vec4; ////////////////////// @@ -618,53 +618,53 @@ namespace glm /// Single-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 fvec1; + //typedef detail::tvec1 fvec1; /// Single-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 fvec2; + //typedef detail::tvec2 fvec2; /// Single-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 fvec3; + //typedef detail::tvec3 fvec3; /// Single-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 fvec4; + //typedef detail::tvec4 fvec4; /// Single-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 f32vec1; + //typedef detail::tvec1 f32vec1; /// Single-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 f32vec2; + //typedef detail::tvec2 f32vec2; /// Single-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 f32vec3; + //typedef detail::tvec3 f32vec3; /// Single-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 f32vec4; + //typedef detail::tvec4 f32vec4; /// Double-precision floating-point vector of 1 component. /// @see gtc_type_precision - typedef detail::tvec1 f64vec1; + //typedef detail::tvec1 f64vec1; /// Double-precision floating-point vector of 2 components. /// @see gtc_type_precision - typedef detail::tvec2 f64vec2; + //typedef detail::tvec2 f64vec2; /// Double-precision floating-point vector of 3 components. /// @see gtc_type_precision - typedef detail::tvec3 f64vec3; + //typedef detail::tvec3 f64vec3; /// Double-precision floating-point vector of 4 components. /// @see gtc_type_precision - typedef detail::tvec4 f64vec4; + //typedef detail::tvec4 f64vec4; ////////////////////// @@ -676,15 +676,15 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 fmat2; + //typedef detail::tmat2x2 fmat2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 fmat3; + //typedef detail::tmat3x3 fmat3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 fmat4; + //typedef detail::tmat4x4 fmat4; /// Single-precision floating-point 1x1 matrix. @@ -693,39 +693,39 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 fmat2x2; + //typedef detail::tmat2x2 fmat2x2; /// Single-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 fmat2x3; + //typedef detail::tmat2x3 fmat2x3; /// Single-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 fmat2x4; + //typedef detail::tmat2x4 fmat2x4; /// Single-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 fmat3x2; + //typedef detail::tmat3x2 fmat3x2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 fmat3x3; + //typedef detail::tmat3x3 fmat3x3; /// Single-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 fmat3x4; + //typedef detail::tmat3x4 fmat3x4; /// Single-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 fmat4x2; + //typedef detail::tmat4x2 fmat4x2; /// Single-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 fmat4x3; + //typedef detail::tmat4x3 fmat4x3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 fmat4x4; + //typedef detail::tmat4x4 fmat4x4; /// Single-precision floating-point 1x1 matrix. @@ -734,15 +734,15 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f32mat2; + //typedef detail::tmat2x2 f32mat2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f32mat3; + //typedef detail::tmat3x3 f32mat3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f32mat4; + //typedef detail::tmat4x4 f32mat4; /// Single-precision floating-point 1x1 matrix. @@ -751,39 +751,39 @@ namespace glm /// Single-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f32mat2x2; + //typedef detail::tmat2x2 f32mat2x2; /// Single-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 f32mat2x3; + //typedef detail::tmat2x3 f32mat2x3; /// Single-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 f32mat2x4; + //typedef detail::tmat2x4 f32mat2x4; /// Single-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 f32mat3x2; + //typedef detail::tmat3x2 f32mat3x2; /// Single-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f32mat3x3; + //typedef detail::tmat3x3 f32mat3x3; /// Single-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 f32mat3x4; + //typedef detail::tmat3x4 f32mat3x4; /// Single-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 f32mat4x2; + //typedef detail::tmat4x2 f32mat4x2; /// Single-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 f32mat4x3; + //typedef detail::tmat4x3 f32mat4x3; /// Single-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f32mat4x4; + //typedef detail::tmat4x4 f32mat4x4; /// Double-precision floating-point 1x1 matrix. @@ -792,15 +792,15 @@ namespace glm /// Double-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f64mat2; + //typedef detail::tmat2x2 f64mat2; /// Double-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f64mat3; + //typedef detail::tmat3x3 f64mat3; /// Double-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f64mat4; + //typedef detail::tmat4x4 f64mat4; /// Double-precision floating-point 1x1 matrix. @@ -809,39 +809,39 @@ namespace glm /// Double-precision floating-point 2x2 matrix. /// @see gtc_type_precision - typedef detail::tmat2x2 f64mat2x2; + //typedef detail::tmat2x2 f64mat2x2; /// Double-precision floating-point 2x3 matrix. /// @see gtc_type_precision - typedef detail::tmat2x3 f64mat2x3; + //typedef detail::tmat2x3 f64mat2x3; /// Double-precision floating-point 2x4 matrix. /// @see gtc_type_precision - typedef detail::tmat2x4 f64mat2x4; + //typedef detail::tmat2x4 f64mat2x4; /// Double-precision floating-point 3x2 matrix. /// @see gtc_type_precision - typedef detail::tmat3x2 f64mat3x2; + //typedef detail::tmat3x2 f64mat3x2; /// Double-precision floating-point 3x3 matrix. /// @see gtc_type_precision - typedef detail::tmat3x3 f64mat3x3; + //typedef detail::tmat3x3 f64mat3x3; /// Double-precision floating-point 3x4 matrix. /// @see gtc_type_precision - typedef detail::tmat3x4 f64mat3x4; + //typedef detail::tmat3x4 f64mat3x4; /// Double-precision floating-point 4x2 matrix. /// @see gtc_type_precision - typedef detail::tmat4x2 f64mat4x2; + //typedef detail::tmat4x2 f64mat4x2; /// Double-precision floating-point 4x3 matrix. /// @see gtc_type_precision - typedef detail::tmat4x3 f64mat4x3; + //typedef detail::tmat4x3 f64mat4x3; /// Double-precision floating-point 4x4 matrix. /// @see gtc_type_precision - typedef detail::tmat4x4 f64mat4x4; + //typedef detail::tmat4x4 f64mat4x4; ////////////////////////// @@ -849,11 +849,11 @@ namespace glm /// Single-precision floating-point quaternion. /// @see gtc_type_precision - typedef detail::tquat f32quat; + //typedef detail::tquat f32quat; /// Double-precision floating-point quaternion. /// @see gtc_type_precision - typedef detail::tquat f64quat; + //typedef detail::tquat f64quat; /// @} }//namespace glm From 37e586820080437a7e26441b2dd54398cc1d4d48 Mon Sep 17 00:00:00 2001 From: jan p springer Date: Mon, 14 Apr 2014 00:13:20 +0100 Subject: [PATCH 06/24] fixed: warning wrt. strict aliasing on gcc 4.8.2/clang3.3 --- glm/core/func_exponential.inl | 6 +++++- glm/core/func_integer.inl | 5 +++-- glm/core/func_packing.inl | 12 +++++++++--- glm/gtx/bit.inl | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/glm/core/func_exponential.inl b/glm/core/func_exponential.inl index 9c03129e..e8ff4cfe 100644 --- a/glm/core/func_exponential.inl +++ b/glm/core/func_exponential.inl @@ -179,7 +179,11 @@ namespace detail genType xhalf(tmp * genType(0.5f)); genUType i = *reinterpret_cast(const_cast(&v)); i = genUType(0x5f375a86) - (i >> genUType(1)); - tmp = *reinterpret_cast(&i); + // tmp = *reinterpret_cast(&i); + { + genType* ptr(reinterpret_cast(&i)); + tmp = *ptr; + } tmp = tmp * (genType(1.5f) - xhalf * tmp * tmp); return tmp; } diff --git a/glm/core/func_integer.inl b/glm/core/func_integer.inl index 370e7770..b18696bd 100644 --- a/glm/core/func_integer.inl +++ b/glm/core/func_integer.inl @@ -172,7 +172,8 @@ namespace glm uint64 Value64 = static_cast(x) * static_cast(y); msb = *(reinterpret_cast(&Value64) + 1); - lsb = reinterpret_cast(Value64); + //lsb = reinterpret_cast(Value64); + lsb = *(reinterpret_cast(Value64)); } template <> @@ -231,7 +232,7 @@ namespace glm int64 Value64 = static_cast(x) * static_cast(y); msb = *(reinterpret_cast(&Value64) + 1); - lsb = reinterpret_cast(Value64); + // lsb = reinterpret_cast(Value64); } template <> diff --git a/glm/core/func_packing.inl b/glm/core/func_packing.inl index 7e26b91c..47b84733 100644 --- a/glm/core/func_packing.inl +++ b/glm/core/func_packing.inl @@ -35,7 +35,9 @@ namespace glm GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v) { u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f)); - return reinterpret_cast(Topack); + // return reinterpret_cast(Topack); + uint* ptr(reinterpret_cast(&Topack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p) @@ -47,7 +49,9 @@ namespace glm GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v) { i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); - return reinterpret_cast(Topack); + // return reinterpret_cast(Topack); + uint* ptr(reinterpret_cast(&Topack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p) @@ -100,7 +104,9 @@ namespace glm detail::toFloat16(v.x), detail::toFloat16(v.y)); - return *reinterpret_cast(&Unpack); + //return *reinterpret_cast(&Unpack); + uint* ptr(reinterpret_cast(&Unpack)); + return *ptr; } GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) diff --git a/glm/gtx/bit.inl b/glm/gtx/bit.inl index 53ac2954..571baf25 100644 --- a/glm/gtx/bit.inl +++ b/glm/gtx/bit.inl @@ -551,7 +551,7 @@ namespace glm assert(ToBit <= sizeof(genIUType) * std::size_t(8)); genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) + for(signed i = 0; i <= ToBit; ++i) Result |= (1 << i); return Result; } @@ -568,7 +568,7 @@ namespace glm assert(ToBit <= sizeof(genIUType) * std::size_t(8)); genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) + for(signed i = 0; i <= ToBit; ++i) Result &= ~(1 << i); return Result; } From 9ecc30c5dddd31b3cfdbcf667bbded186a5db2ef Mon Sep 17 00:00:00 2001 From: jan p springer Date: Tue, 15 Apr 2014 18:37:34 +0100 Subject: [PATCH 07/24] added: missing value_type typedef --- glm/gtc/quaternion.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index cc3c76ad..7ce9468c 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -56,6 +56,7 @@ namespace detail { enum ctor{null}; + typedef T value_type; typedef tvec4 bool_type; public: From d19766fcbf190dee8155a6ebaaabbb8dc6878bcf Mon Sep 17 00:00:00 2001 From: dachziegel Date: Mon, 5 May 2014 13:45:36 +0200 Subject: [PATCH 08/24] added GLM_FUNC_QUALIFIER to be able to use in CUDA --- glm/gtc/quaternion.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 951b62c4..6422cf6b 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -255,7 +255,7 @@ namespace detail template struct compute_dot { - static T call(tquat const & x, tquat const & y) + static GLM_FUNC_QUALIFIER T call(tquat const & x, tquat const & y) { tvec4 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); From e04ded9e39eb1a9a0ba900d51bdce47ffaadfd59 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 5 May 2014 23:08:49 +0200 Subject: [PATCH 09/24] Fixed glm::isinf and glm::isnan for with Android NDK 9d #191 --- glm/detail/func_common.inl | 12 ++++++++++-- glm/detail/setup.hpp | 2 ++ readme.txt | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index a788eb4c..5463e574 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -717,7 +717,11 @@ namespace detail return _isnan(x) != 0; # elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) # if(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return _isnan(x) != 0; +# if(GLM_PLATFORM_ANDROID_VERSION >= 19) + return std::isnan(x); +# else + return _isnan(x) != 0; +# endif # else return std::isnan(x); # endif @@ -788,7 +792,11 @@ namespace detail return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF; # elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) # if(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return _isinf(x) != 0; +# if(GLM_PLATFORM_ANDROID_VERSION >= 19) + return std::isinf(x); +# else + return _isinf(x) != 0; +# endif # else return std::isinf(x); # endif diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 3eb99bc9..cd56a19d 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -68,6 +68,8 @@ # define GLM_PLATFORM GLM_PLATFORM_CHROME_NACL #elif defined(__ANDROID__) # define GLM_PLATFORM GLM_PLATFORM_ANDROID +# include +# define GLM_PLATFORM_ANDROID_VERSION __ANDROID_API__ #elif defined(__linux) # define GLM_PLATFORM GLM_PLATFORM_LINUX #elif defined(__unix) diff --git a/readme.txt b/readme.txt index 8c5c6a3d..89721e88 100644 --- a/readme.txt +++ b/readme.txt @@ -42,6 +42,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed non-utf8 character #196 - Added FindGLM install for CMake #189 - Fixed GTX_color_space - saturation #195 +- Fixed glm::isinf and glm::isnan for with Android NDK 9d #191 ================================================================================ GLM 0.9.5.3: 2014-04-02 From affd405b37de71fc0fe2408edb8ed37f3bb0b7a4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 6 May 2014 22:45:18 +0200 Subject: [PATCH 10/24] Fixed glm::isinf and glm::isnan for with Android NDK 9d #191, take 2 --- glm/detail/func_common.inl | 16 ++++------------ glm/detail/setup.hpp | 2 -- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index 5463e574..4026e0c8 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -716,12 +716,8 @@ namespace detail # if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL)) return _isnan(x) != 0; # elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) -# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID) -# if(GLM_PLATFORM_ANDROID_VERSION >= 19) - return std::isnan(x); -# else - return _isnan(x) != 0; -# endif +# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L) + return _isnan(x) != 0; # else return std::isnan(x); # endif @@ -791,12 +787,8 @@ namespace detail # if(GLM_COMPILER & (GLM_COMPILER_INTEL | GLM_COMPILER_VC)) return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF; # elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) -# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID) -# if(GLM_PLATFORM_ANDROID_VERSION >= 19) - return std::isinf(x); -# else - return _isinf(x) != 0; -# endif +# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L) + return _isinf(x) != 0; # else return std::isinf(x); # endif diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index cd56a19d..3eb99bc9 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -68,8 +68,6 @@ # define GLM_PLATFORM GLM_PLATFORM_CHROME_NACL #elif defined(__ANDROID__) # define GLM_PLATFORM GLM_PLATFORM_ANDROID -# include -# define GLM_PLATFORM_ANDROID_VERSION __ANDROID_API__ #elif defined(__linux) # define GLM_PLATFORM GLM_PLATFORM_LINUX #elif defined(__unix) From a2f4df2b1d5635ac7eb14ca3a1de2a7094736d2b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 23 May 2014 22:23:27 +0200 Subject: [PATCH 11/24] Fixed builtin GLM_ARCH_SSE4 #204 --- glm/detail/setup.hpp | 21 +++++++++++++-------- readme.txt | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 3eb99bc9..10ecc937 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -552,23 +552,26 @@ #define GLM_ARCH_PURE 0x0000 #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)) # define GLM_ARCH GLM_ARCH_PURE #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)) -# 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)) # define GLM_ARCH (GLM_ARCH_SSE3 | GLM_ARCH_SSE2) #elif(defined(GLM_FORCE_SSE2)) # define GLM_ARCH (GLM_ARCH_SSE2) #elif(GLM_COMPILER & GLM_COMPILER_VC) # 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 # define GLM_ARCH (GLM_ARCH_SSE2) # else @@ -578,9 +581,11 @@ # define GLM_ARCH GLM_ARCH_PURE #elif(((GLM_COMPILER & GLM_COMPILER_GCC) && (defined(__i386__) || defined(__x86_64__))) || (GLM_COMPILER & GLM_COMPILER_LLVM_GCC)) # if defined(__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(__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(__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__) diff --git a/readme.txt b/readme.txt index 89721e88..0c7f374b 100644 --- a/readme.txt +++ b/readme.txt @@ -43,6 +43,7 @@ GLM 0.9.5.4: 2014-0X-XX - Added FindGLM install for CMake #189 - Fixed GTX_color_space - saturation #195 - Fixed glm::isinf and glm::isnan for with Android NDK 9d #191 +- Fixed builtin GLM_ARCH_SSE4 #204 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 4da58d88d4249fa43e49835c360e312a1653701e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 23 May 2014 23:09:32 +0200 Subject: [PATCH 12/24] Optimized Quaternion vector rotation #205 --- glm/gtc/quaternion.inl | 13 ++++--------- readme.txt | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 6422cf6b..9e926ee9 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -302,16 +302,11 @@ namespace detail detail::tvec3 const & v ) { - T Two(2); + detail::tvec3 u(q.x, q.y, q.z); + detail::tvec3 uv(glm::cross(u, v) * q.w); + detail::tvec3 uuv(glm::cross(u, uv)); - detail::tvec3 uv, uuv; - detail::tvec3 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 + uuv) * static_cast(2); } template diff --git a/readme.txt b/readme.txt index 0c7f374b..3c6c6905 100644 --- a/readme.txt +++ b/readme.txt @@ -44,6 +44,7 @@ GLM 0.9.5.4: 2014-0X-XX - 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 ================================================================================ GLM 0.9.5.3: 2014-04-02 From f8fa1513fa911660806593f95ed7f6144999539f Mon Sep 17 00:00:00 2001 From: Florian Euchner Date: Sat, 24 May 2014 16:59:14 +0200 Subject: [PATCH 13/24] Fix missing @endcond --- glm/detail/type_mat4x4.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index de561636..85844b07 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -59,6 +59,7 @@ namespace detail private: /// @cond DETAIL col_type value[4]; + /// @endcond public: // Constructors From e610e9446e6207390548c1a7e63f2caebec55cc7 Mon Sep 17 00:00:00 2001 From: Joel Nises Date: Thu, 5 Jun 2014 17:48:53 +0200 Subject: [PATCH 14/24] fixed bug in quaternion slerp --- glm/gtc/quaternion.inl | 8 ++++---- test/gtc/gtc_quaternion.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 9e926ee9..4059d426 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -582,10 +582,10 @@ namespace detail { // Linear interpolation return detail::tquat( - 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 { diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 4346e8fc..5e5b120a 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -196,6 +196,15 @@ int test_quat_slerp() // 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); + // 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; } From e2a565e866c7848115286733324c72453ac211b7 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 11 Jun 2014 16:39:46 +0200 Subject: [PATCH 15/24] Updated readme for issue #211 --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 3c6c6905..cfafddb8 100644 --- a/readme.txt +++ b/readme.txt @@ -45,6 +45,7 @@ GLM 0.9.5.4: 2014-0X-XX - 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 ================================================================================ GLM 0.9.5.3: 2014-04-02 From c3c180559a4d245258b03f39b1245b790d1baed8 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 11 Jun 2014 16:56:16 +0200 Subject: [PATCH 16/24] Fixed instruction set detection with Clang #158 --- glm/detail/setup.hpp | 2 +- readme.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 10ecc937..c982c469 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -579,7 +579,7 @@ # 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)) +#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__) diff --git a/readme.txt b/readme.txt index cfafddb8..416f3619 100644 --- a/readme.txt +++ b/readme.txt @@ -46,6 +46,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed builtin GLM_ARCH_SSE4 #204 - Optimized Quaternion vector rotation #205 - Fixed missing doxygen @endcond tag #211 +- Fixed instruction set detection with Clang #158 ================================================================================ GLM 0.9.5.3: 2014-04-02 From ea45a7b966eb8dd6dff5a90c3578bbbb4e5fbc62 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 11 Jun 2014 22:47:37 +0200 Subject: [PATCH 17/24] Fixed orientate3 function #207 --- glm/gtx/euler_angles.inl | 2 +- readme.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/glm/gtx/euler_angles.inl b/glm/gtx/euler_angles.inl index b3102242..a1afcf3a 100644 --- a/glm/gtx/euler_angles.inl +++ b/glm/gtx/euler_angles.inl @@ -250,7 +250,7 @@ namespace glm detail::tvec3 const & angles ) { - return detail::tmat3x3(yawPitchRoll(angles.x, angles.y, angles.z)); + return detail::tmat3x3(yawPitchRoll(angles.z, angles.x, angles.y)); } template diff --git a/readme.txt b/readme.txt index 416f3619..e7dd0eb0 100644 --- a/readme.txt +++ b/readme.txt @@ -47,6 +47,7 @@ GLM 0.9.5.4: 2014-0X-XX - Optimized Quaternion vector rotation #205 - Fixed missing doxygen @endcond tag #211 - Fixed instruction set detection with Clang #158 +- Fixed orientate3 function #207 ================================================================================ GLM 0.9.5.3: 2014-04-02 From c506b43d49ac212388c2749d14a8acada4482021 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 12 Jun 2014 00:29:56 +0200 Subject: [PATCH 18/24] Quaternion vector rotation error. #209 --- glm/gtc/quaternion.inl | 8 ++++---- test/gtc/gtc_quaternion.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 9e926ee9..6396ea2e 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -302,11 +302,11 @@ namespace detail detail::tvec3 const & v ) { - detail::tvec3 u(q.x, q.y, q.z); - detail::tvec3 uv(glm::cross(u, v) * q.w); - detail::tvec3 uuv(glm::cross(u, uv)); + detail::tvec3 const QuatVector(q.x, q.y, q.z); + detail::tvec3 const uv(glm::cross(QuatVector, v)); + detail::tvec3 const uuv(glm::cross(QuatVector, uv)); - return v + (uv + uuv) * static_cast(2); + return v + ((uv * q.w) + uuv) * static_cast(2); } template diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 4346e8fc..f56ad47e 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -247,6 +247,16 @@ int test_quat_type() return 0; } +int test_quat_mul_vec() +{ + glm::quat q = glm::angleAxis(glm::pi() * 0.5f, glm::vec3(0, 0, 1)); + glm::vec3 v(1, 0, 0); + glm::vec3 u(q * v); + glm::vec3 w(u * q); + + return glm::all(glm::epsilonEqual(v, w, 0.01f)); +} + int test_quat_ctr() { int Error(0); @@ -269,6 +279,7 @@ int main() int Error(0); Error += test_quat_ctr(); + Error += test_quat_mul_vec(); Error += test_quat_two_axis_ctr(); Error += test_quat_mul(); Error += test_quat_precision(); From d4a8c3fe5798eaf910bab96802621b331261c007 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 12 Jun 2014 19:30:53 +0200 Subject: [PATCH 19/24] Updated readme for #210 --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index e7dd0eb0..c8d11120 100644 --- a/readme.txt +++ b/readme.txt @@ -48,6 +48,7 @@ GLM 0.9.5.4: 2014-0X-XX - 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 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 83f594b5ed2689f4e4ec6845396c46032b6ccacb Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 19 Jun 2014 23:05:35 +0200 Subject: [PATCH 20/24] Fixed quaternion mul/vec test --- test/gtc/gtc_quaternion.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 1d4c9233..fab238af 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -258,12 +258,16 @@ int test_quat_type() int test_quat_mul_vec() { + int Error(0); + glm::quat q = glm::angleAxis(glm::pi() * 0.5f, glm::vec3(0, 0, 1)); glm::vec3 v(1, 0, 0); glm::vec3 u(q * v); glm::vec3 w(u * q); - return glm::all(glm::epsilonEqual(v, w, 0.01f)); + Error += glm::all(glm::epsilonEqual(v, w, 0.01f)) ? 0 : 1; + + return Error; } int test_quat_ctr() From 2935cdc18e2b152f96c56e8b60cc0e2a47222b96 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 00:21:53 +0200 Subject: [PATCH 21/24] Updated readme.txt --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index c8d11120..61dc33a0 100644 --- a/readme.txt +++ b/readme.txt @@ -49,6 +49,7 @@ GLM 0.9.5.4: 2014-0X-XX - 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 #144 ================================================================================ GLM 0.9.5.3: 2014-04-02 From 7fe8a1944c66fb9acf3aa2930966cfafa4ee9e09 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 01:09:50 +0200 Subject: [PATCH 22/24] Fixed fastDistance ambiguity #215 --- glm/detail/func_geometric.inl | 3 +-- glm/gtx/fast_square_root.inl | 32 ++++++++++++++++++++++++++++++- readme.txt | 1 + test/gtx/gtx_fast_square_root.cpp | 18 +++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/glm/detail/func_geometric.inl b/glm/detail/func_geometric.inl index 2f8691dd..1e8cd633 100644 --- a/glm/detail/func_geometric.inl +++ b/glm/detail/func_geometric.inl @@ -92,8 +92,7 @@ namespace detail { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'length' only accept floating-point inputs"); - genType sqr = x * x; - return sqrt(sqr); + return abs(x); } template diff --git a/glm/gtx/fast_square_root.inl b/glm/gtx/fast_square_root.inl index a08bdbf2..198e03ab 100644 --- a/glm/gtx/fast_square_root.inl +++ b/glm/gtx/fast_square_root.inl @@ -101,13 +101,43 @@ namespace glm template GLM_FUNC_QUALIFIER genType fastDistance ( - genType const & x, + genType const & x, genType const & y ) { return fastLength(y - x); } + template + GLM_FUNC_QUALIFIER valType fastDistance + ( + detail::tvec2 const & x, + detail::tvec2 const & y + ) + { + return fastLength(y - x); + } + + template + GLM_FUNC_QUALIFIER valType fastDistance + ( + detail::tvec3 const & x, + detail::tvec3 const & y + ) + { + return fastLength(y - x); + } + + template + GLM_FUNC_QUALIFIER valType fastDistance + ( + detail::tvec4 const & x, + detail::tvec4 const & y + ) + { + return fastLength(y - x); + } + // fastNormalize template GLM_FUNC_QUALIFIER genType fastNormalize diff --git a/readme.txt b/readme.txt index 61dc33a0..9e4e826a 100644 --- a/readme.txt +++ b/readme.txt @@ -50,6 +50,7 @@ GLM 0.9.5.4: 2014-0X-XX - Fixed orientate3 function #207 - Fixed lerp when cosTheta is close to 1 in quaternion slerp #210 - Added GTX_io for io with #144 +- Fixed fastDistance ambiguity #215 ================================================================================ GLM 0.9.5.3: 2014-04-02 diff --git a/test/gtx/gtx_fast_square_root.cpp b/test/gtx/gtx_fast_square_root.cpp index 788b341c..b9d41dcd 100644 --- a/test/gtx/gtx_fast_square_root.cpp +++ b/test/gtx/gtx_fast_square_root.cpp @@ -27,11 +27,29 @@ int test_fastInverseSqrt() 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 Error(0); Error += test_fastInverseSqrt(); + Error += test_fastDistance(); return Error; } From 84e05bbbb336095cdac880a58b4ec267b495220b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 01:46:28 +0200 Subject: [PATCH 23/24] Added test for issue #214 --- test/core/core_type_cast.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/core/core_type_cast.cpp b/test/core/core_type_cast.cpp index 7c002886..f86b9649 100644 --- a/test/core/core_type_cast.cpp +++ b/test/core/core_type_cast.cpp @@ -9,6 +9,9 @@ #define GLM_FORCE_RADIANS #include +#include +#include +#include struct my_vec2 { @@ -86,10 +89,23 @@ int test_vec4_cast() return Error; } +int test_std_copy() +{ + int Error = 0; + + std::vector High; + std::vector Medium(High.size()); + + std::copy(High.begin(), Medium.end(), Medium.begin()); + + return Error; +} + int main() { int Error = 0; + Error += test_std_copy(); Error += test_vec2_cast(); Error += test_vec3_cast(); Error += test_vec4_cast(); From 95cd2c8b241d2c21ad0c067ab6f064c79f984649 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 20 Jun 2014 20:06:41 +0200 Subject: [PATCH 24/24] Added #214 issue tests. --- test/core/core_type_cast.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test/core/core_type_cast.cpp b/test/core/core_type_cast.cpp index f86b9649..f33972c6 100644 --- a/test/core/core_type_cast.cpp +++ b/test/core/core_type_cast.cpp @@ -93,10 +93,37 @@ int test_std_copy() { int Error = 0; - std::vector High; - std::vector Medium(High.size()); + { + std::vector High4; + std::vector Medium4(High4.size()); - std::copy(High.begin(), Medium.end(), Medium.begin()); + std::copy(&High4.begin()[0], &High4.end()[0], Medium4.begin()); + + *Medium4.begin() = *High4.begin(); + } + + { + std::vector High3; + std::vector Medium3(High3.size()); + + std::copy(&High3.begin()[0], &High3.end()[0], Medium3.begin()); + + *Medium3.begin() = *High3.begin(); + } + + { + std::vector High2; + std::vector 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; }