diff --git a/.gitignore b/.gitignore index ec55f089..e5d044b7 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ Makefile # local build(s) build* +/.vs +/CMakeSettings.json diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index a78e3d38..67fda483 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -696,7 +696,15 @@ namespace detail GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v) { - return reinterpret_cast(const_cast(v)); + union + { + float in; + int out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -707,7 +715,15 @@ namespace detail GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v) { - return reinterpret_cast(const_cast(v)); + union + { + float in; + uint out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -718,7 +734,15 @@ namespace detail GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v) { - return reinterpret_cast(const_cast(v)); + union + { + int in; + float out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> @@ -729,7 +753,15 @@ namespace detail GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v) { - return reinterpret_cast(const_cast(v)); + union + { + uint in; + float out; + } u; + + u.in = v; + + return u.out; } template class vecType, length_t L, precision P> diff --git a/glm/detail/func_common_simd.inl b/glm/detail/func_common_simd.inl index e6daa269..2b6ac5fa 100644 --- a/glm/detail/func_common_simd.inl +++ b/glm/detail/func_common_simd.inl @@ -191,7 +191,7 @@ namespace detail { GLM_FUNC_QUALIFIER static vec<4, float, P> call(vec<4, float, P> const & x, vec<4, float, P> const & y, vec<4, bool, P> const & a) { - __m128i const Load = _mm_set_epi32(-(int)a.w, -(int)a.z, -(int)a.y, -(int)a.x); + __m128i const Load = _mm_set_epi32(-static_cast(a.w), -static_cast(a.z), -static_cast(a.y), -static_cast(a.x)); __m128 const Mask = _mm_castsi128_ps(Load); vec<4, float, P> Result(uninitialize); diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index d4b184c8..8c3b1dd0 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -298,12 +298,12 @@ namespace detail GLM_FUNC_QUALIFIER vecType bitfieldReverse(vecType const& v) { vecType x(v); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); - x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 2>::call(x, static_cast(0x5555555555555555ull), static_cast( 1)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 4>::call(x, static_cast(0x3333333333333333ull), static_cast( 2)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 8>::call(x, static_cast(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 16>::call(x, static_cast(0x00FF00FF00FF00FFull), static_cast( 8)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 32>::call(x, static_cast(0x0000FFFF0000FFFFull), static_cast(16)); + x = detail::compute_bitfieldReverseStep::value, sizeof(T) * 8>= 64>::call(x, static_cast(0x00000000FFFFFFFFull), static_cast(32)); return x; } diff --git a/glm/detail/func_integer_simd.inl b/glm/detail/func_integer_simd.inl index ddff75ba..095adfb9 100644 --- a/glm/detail/func_integer_simd.inl +++ b/glm/detail/func_integer_simd.inl @@ -11,11 +11,11 @@ namespace detail template struct compute_bitfieldReverseStep<4, uint32, P, vec, true, true> { - GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const & v, uint32 Mask, uint32 Shift) + GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const& v, uint32 Mask, uint32 Shift) { __m128i const set0 = v.data; - __m128i const set1 = _mm_set1_epi32(Mask); + __m128i const set1 = _mm_set1_epi32(static_cast(Mask)); __m128i const and1 = _mm_and_si128(set0, set1); __m128i const sft1 = _mm_slli_epi32(and1, Shift); @@ -32,11 +32,11 @@ namespace detail template struct compute_bitfieldBitCountStep<4, uint32, P, vec, true, true> { - GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const & v, uint32 Mask, uint32 Shift) + GLM_FUNC_QUALIFIER static vec<4, uint32, P> call(vec<4, uint32, P> const& v, uint32 Mask, uint32 Shift) { __m128i const set0 = v.data; - __m128i const set1 = _mm_set1_epi32(Mask); + __m128i const set1 = _mm_set1_epi32(static_cast(Mask)); __m128i const and0 = _mm_and_si128(set0, set1); __m128i const sft0 = _mm_slli_epi32(set0, Shift); __m128i const and1 = _mm_and_si128(sft0, set1); diff --git a/glm/detail/func_matrix_simd.inl b/glm/detail/func_matrix_simd.inl index 99491866..bf5e5ee8 100644 --- a/glm/detail/func_matrix_simd.inl +++ b/glm/detail/func_matrix_simd.inl @@ -19,9 +19,9 @@ namespace detail { mat<4, 4, float, P> result(uninitialize); glm_mat4_matrixCompMult( - *(glm_vec4 const (*)[4])&x[0].data, - *(glm_vec4 const (*)[4])&y[0].data, - *(glm_vec4(*)[4])&result[0].data); + *static_cast(&x[0].data), + *static_cast(&y[0].data), + *static_cast(&result[0].data)); return result; } }; @@ -33,8 +33,8 @@ namespace detail { mat<4, 4, float, P> result(uninitialize); glm_mat4_transpose( - *(glm_vec4 const (*)[4])&m[0].data, - *(glm_vec4(*)[4])&result[0].data); + *static_cast(&m[0].data), + *static_cast(&result[0].data)); return result; } }; diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index c2ed8ade..2e0b2d0d 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -692,14 +692,8 @@ #if GLM_HAS_DEFAULTED_FUNCTIONS # define GLM_DEFAULT = default -# ifdef GLM_FORCE_NO_CTOR_INIT -# define GLM_DEFAULT_CTOR = default -# else -# define GLM_DEFAULT_CTOR -# endif #else # define GLM_DEFAULT -# define GLM_DEFAULT_CTOR #endif #if GLM_HAS_CONSTEXPR || GLM_HAS_CONSTEXPR_PARTIAL @@ -765,10 +759,6 @@ namespace glm /////////////////////////////////////////////////////////////////////////////////// // countof -#ifndef __has_feature -# define __has_feature(x) 0 // Compatibility with non-clang compilers. -#endif - #if GLM_HAS_CONSTEXPR_PARTIAL namespace glm { diff --git a/glm/detail/type_half.inl b/glm/detail/type_half.inl index 78d3e261..fa049f7e 100644 --- a/glm/detail/type_half.inl +++ b/glm/detail/type_half.inl @@ -46,7 +46,7 @@ namespace detail // detail::uif32 result; - result.i = (unsigned int)(s << 31); + result.i = static_cast(s << 31); return result.f; } else @@ -74,7 +74,7 @@ namespace detail // uif32 result; - result.i = (unsigned int)((s << 31) | 0x7f800000); + result.i = static_cast((s << 31) | 0x7f800000); return result.f; } else @@ -84,7 +84,7 @@ namespace detail // uif32 result; - result.i = (unsigned int)((s << 31) | 0x7f800000 | (m << 13)); + result.i = static_cast((s << 31) | 0x7f800000 | (m << 13)); return result.f; } } @@ -101,15 +101,15 @@ namespace detail // uif32 Result; - Result.i = (unsigned int)((s << 31) | (e << 23) | m); + Result.i = static_cast((s << 31) | (e << 23) | m); return Result.f; } - GLM_FUNC_QUALIFIER hdata toFloat16(float const & f) + GLM_FUNC_QUALIFIER hdata toFloat16(float const& f) { uif32 Entry; Entry.f = f; - int i = (int)Entry.i; + int i = static_cast(Entry.i); // // Our floating point number, f, is represented by the bit diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 4d86b72a..2ad233d6 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -24,9 +24,17 @@ namespace glm col_type value[2]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<2, 2, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<2, 2, T, Q> const & m); @@ -66,14 +74,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<3, 4, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 2;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<2, 2, T, P> & operator=(mat<2, 2, T, P> const & v) GLM_DEFAULT; diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index cfd7a868..fb909e5e 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -7,15 +7,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<2, 2, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0); - this->value[1] = col_type(0, 1); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat2x3.hpp b/glm/detail/type_mat2x3.hpp index 01eb777a..30ae1ac4 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[2]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<2, 3, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<2, 3, T, Q> const & m); @@ -67,14 +75,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 2, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 2;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<2, 3, T, P> & operator=(mat<2, 3, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat2x3.inl b/glm/detail/type_mat2x3.inl index e18ab386..fb2d1d04 100644 --- a/glm/detail/type_mat2x3.inl +++ b/glm/detail/type_mat2x3.inl @@ -5,15 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) - template +# if !GLM_HAS_DEFAULTED_FUNCTIONS + template GLM_FUNC_QUALIFIER mat<2, 3, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0); - this->value[1] = col_type(0, 1, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat2x4.hpp b/glm/detail/type_mat2x4.hpp index cfe61f4e..20c1a65b 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[2]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 2; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<2, 4, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<2, 4, T, Q> const & m); @@ -69,14 +77,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 2, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 2;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<2, 4, T, P> & operator=(mat<2, 4, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat2x4.inl b/glm/detail/type_mat2x4.inl index ee9c3c42..c7526ce0 100644 --- a/glm/detail/type_mat2x4.inl +++ b/glm/detail/type_mat2x4.inl @@ -5,15 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<2, 4, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0, 0); - this->value[1] = col_type(0, 1, 0, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat3x2.hpp b/glm/detail/type_mat3x2.hpp index f738dc60..0258d06d 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[3]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<3, 2, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<3, 2, T, Q> const & m); @@ -74,14 +82,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 2, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 3;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<3, 2, T, P> & operator=(mat<3, 2, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat3x2.inl b/glm/detail/type_mat3x2.inl index 9f66a015..0f5ea0ac 100644 --- a/glm/detail/type_mat3x2.inl +++ b/glm/detail/type_mat3x2.inl @@ -5,16 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<3, 2, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0); - this->value[1] = col_type(0, 1); - this->value[2] = col_type(0, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index 1a9f3365..4e1d7e9f 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -24,9 +24,17 @@ namespace glm col_type value[3]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<3, 3, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<3, 3, T, Q> const & m); @@ -73,14 +81,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<3, 4, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 3;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<3, 3, T, P> & operator=(mat<3, 3, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat3x3.inl b/glm/detail/type_mat3x3.inl index f4b4ad8e..8fee082b 100644 --- a/glm/detail/type_mat3x3.inl +++ b/glm/detail/type_mat3x3.inl @@ -7,16 +7,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<3, 3, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0); - this->value[1] = col_type(0, 1, 0); - this->value[2] = col_type(0, 0, 1); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat3x4.hpp b/glm/detail/type_mat3x4.hpp index 77d2143e..6775ab2e 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[3]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 3; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<3, 4, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<3, 4, T, Q> const & m); @@ -74,14 +82,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 2, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 3;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<3, 4, T, P> & operator=(mat<3, 4, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat3x4.inl b/glm/detail/type_mat3x4.inl index 73f4aebb..f931cc60 100644 --- a/glm/detail/type_mat3x4.inl +++ b/glm/detail/type_mat3x4.inl @@ -5,16 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<3, 4, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0, 0); - this->value[1] = col_type(0, 1, 0, 0); - this->value[2] = col_type(0, 0, 1, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat4x2.hpp b/glm/detail/type_mat4x2.hpp index feff316e..9f875183 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[4]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<4, 2, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<4, 2, T, Q> const & m); @@ -79,14 +87,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 3, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<3, 4, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 4;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<4, 2, T, P> & operator=(mat<4, 2, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat4x2.inl b/glm/detail/type_mat4x2.inl index 68d34630..7b8986d8 100644 --- a/glm/detail/type_mat4x2.inl +++ b/glm/detail/type_mat4x2.inl @@ -5,17 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<4, 2, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0); - this->value[1] = col_type(0, 1); - this->value[2] = col_type(0, 0); - this->value[3] = col_type(0, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat4x3.hpp b/glm/detail/type_mat4x3.hpp index 2efa8699..e3926e3e 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -25,9 +25,17 @@ namespace glm col_type value[4]; public: + // -- Accesses -- + + typedef length_t length_type; + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length() { return 4; } + + GLM_FUNC_DECL col_type & operator[](length_type i); + GLM_FUNC_DECL col_type const & operator[](length_type i) const; + // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<4, 3, T, P> const & m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<4, 3, T, Q> const & m); @@ -79,14 +87,6 @@ namespace glm GLM_FUNC_DECL GLM_EXPLICIT mat(mat<4, 2, T, P> const & x); GLM_FUNC_DECL GLM_EXPLICIT mat(mat<3, 4, T, P> const & x); - // -- Accesses -- - - typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 4;} - - GLM_FUNC_DECL col_type & operator[](length_type i); - GLM_FUNC_DECL col_type const & operator[](length_type i) const; - // -- Unary arithmetic operators -- GLM_FUNC_DECL mat<4, 3, T, P> & operator=(mat<4, 3, T, P> const & m) GLM_DEFAULT; diff --git a/glm/detail/type_mat4x3.inl b/glm/detail/type_mat4x3.inl index b3c8d87e..a304a033 100644 --- a/glm/detail/type_mat4x3.inl +++ b/glm/detail/type_mat4x3.inl @@ -5,17 +5,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<4, 3, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0); - this->value[1] = col_type(0, 1, 0); - this->value[2] = col_type(0, 0, 1); - this->value[3] = col_type(0, 0, 0); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index e0d109ac..4b1d9d41 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -27,14 +27,14 @@ namespace glm // -- Accesses -- typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 4;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} GLM_FUNC_DECL col_type & operator[](length_type i); GLM_FUNC_DECL col_type const & operator[](length_type i) const; // -- Constructors -- - GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL mat() GLM_DEFAULT; GLM_FUNC_DECL mat(mat<4, 4, T, P> const& m) GLM_DEFAULT; template GLM_FUNC_DECL mat(mat<4, 4, T, Q> const& m); diff --git a/glm/detail/type_mat4x4.inl b/glm/detail/type_mat4x4.inl index 880ce931..bce3cc71 100644 --- a/glm/detail/type_mat4x4.inl +++ b/glm/detail/type_mat4x4.inl @@ -7,17 +7,10 @@ namespace glm { // -- Constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER mat<4, 4, T, P>::mat() - { -# ifndef GLM_FORCE_NO_CTOR_INIT - this->value[0] = col_type(1, 0, 0, 0); - this->value[1] = col_type(0, 1, 0, 0); - this->value[2] = col_type(0, 0, 1, 0); - this->value[3] = col_type(0, 0, 0, 1); -# endif - } + {} # endif # if !GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index 8f877eda..db047f51 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -78,14 +78,14 @@ namespace glm /// Return the count of components of the vector typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 1;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 1;} GLM_FUNC_DECL T & operator[](length_type i); GLM_FUNC_DECL T const & operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const& v) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, T, Q> const& v); diff --git a/glm/detail/type_vec1.inl b/glm/detail/type_vec1.inl index e3f56b25..283f3593 100644 --- a/glm/detail/type_vec1.inl +++ b/glm/detail/type_vec1.inl @@ -5,12 +5,9 @@ namespace glm { // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<1, T, P>::vec() -# ifndef GLM_FORCE_NO_CTOR_INIT - : x(0) -# endif {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 1eb81c92..c6ae942f 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -79,14 +79,14 @@ namespace glm /// Return the count of components of the vector typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 2;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;} GLM_FUNC_DECL T& operator[](length_type i); GLM_FUNC_DECL T const& operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const& v) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, T, Q> const& v); diff --git a/glm/detail/type_vec2.inl b/glm/detail/type_vec2.inl index fa6c2902..4fdb8e04 100644 --- a/glm/detail/type_vec2.inl +++ b/glm/detail/type_vec2.inl @@ -5,12 +5,9 @@ namespace glm { // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, P>::vec() -# ifndef GLM_FORCE_NO_CTOR_INIT - : x(0), y(0) -# endif {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index bd95530a..81db2bf5 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -79,14 +79,14 @@ namespace glm /// Return the count of components of the vector typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 3;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 3;} GLM_FUNC_DECL T & operator[](length_type i); GLM_FUNC_DECL T const & operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const & v) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, T, Q> const & v); diff --git a/glm/detail/type_vec3.inl b/glm/detail/type_vec3.inl index e5524ab3..a02e14e1 100644 --- a/glm/detail/type_vec3.inl +++ b/glm/detail/type_vec3.inl @@ -5,12 +5,9 @@ namespace glm { // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, P>::vec() -# ifndef GLM_FORCE_NO_CTOR_INIT - : x(0), y(0), z(0) -# endif {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 6ecb1602..95fb2fb1 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -82,14 +82,14 @@ namespace glm /// Return the count of components of the vector typedef length_t length_type; - GLM_FUNC_DECL static length_type length(){return 4;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} GLM_FUNC_DECL T & operator[](length_type i); GLM_FUNC_DECL T const & operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, P> const& v) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, Q> const& v); diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index e333de19..214236b4 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -154,12 +154,9 @@ namespace detail // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec() -# ifndef GLM_FORCE_NO_CTOR_INIT - : x(0), y(0), z(0), w(0) -# endif {} # endif//!GLM_HAS_DEFAULTED_FUNCTIONS diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 59595648..d34370a5 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -518,7 +518,7 @@ namespace glm template GLM_FUNC_DECL vec packUnorm(vec const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see vecType packUnorm(vecType const & v) @@ -532,7 +532,7 @@ namespace glm template GLM_FUNC_DECL vec packSnorm(vec const & v); - /// Convert each signed integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see vecType packSnorm(vecType const & v) @@ -545,7 +545,7 @@ namespace glm /// @see vec2 unpackUnorm2x4(uint8 p) GLM_FUNC_DECL uint8 packUnorm2x4(vec2 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint8 packUnorm2x4(vec2 const & v) @@ -557,7 +557,7 @@ namespace glm /// @see vec4 unpackUnorm4x4(uint16 p) GLM_FUNC_DECL uint16 packUnorm4x4(vec4 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm4x4(vec4 const & v) @@ -569,7 +569,7 @@ namespace glm /// @see vec3 unpackUnorm1x5_1x6_1x5(uint16 p) GLM_FUNC_DECL uint16 packUnorm1x5_1x6_1x5(vec3 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm1x5_1x6_1x5(vec3 const & v) @@ -581,7 +581,7 @@ namespace glm /// @see vec4 unpackUnorm3x5_1x1(uint16 p) GLM_FUNC_DECL uint16 packUnorm3x5_1x1(vec4 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm3x5_1x1(vec4 const & v) @@ -593,11 +593,135 @@ namespace glm /// @see vec3 unpackUnorm2x3_1x2(uint8 p) GLM_FUNC_DECL uint8 packUnorm2x3_1x2(vec3 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint8 packUnorm2x3_1x2(vec3 const & v) GLM_FUNC_DECL vec3 unpackUnorm2x3_1x2(uint8 p); + + + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i8vec2 unpackInt2x8(int16 p) + GLM_FUNC_DECL int16 packInt2x8(i8vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int16 packInt2x8(i8vec2 const& v) + GLM_FUNC_DECL i8vec2 unpackInt2x8(int16 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u8vec2 unpackInt2x8(uint16 p) + GLM_FUNC_DECL uint16 packUint2x8(u8vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint16 packInt2x8(u8vec2 const& v) + GLM_FUNC_DECL u8vec2 unpackUint2x8(uint16 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i8vec4 unpackInt4x8(int32 p) + GLM_FUNC_DECL int32 packInt4x8(i8vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int32 packInt2x8(i8vec4 const& v) + GLM_FUNC_DECL i8vec4 unpackInt4x8(int32 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u8vec4 unpackUint4x8(uint32 p) + GLM_FUNC_DECL uint32 packUint4x8(u8vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint32 packUint4x8(u8vec2 const& v) + GLM_FUNC_DECL u8vec4 unpackUint4x8(uint32 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i16vec2 unpackInt2x16(int p) + GLM_FUNC_DECL int packInt2x16(i16vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packInt2x16(i16vec2 const& v) + GLM_FUNC_DECL i16vec2 unpackInt2x16(int p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i16vec4 unpackInt4x16(int64 p) + GLM_FUNC_DECL int64 packInt4x16(i16vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int64 packInt4x16(i16vec4 const& v) + GLM_FUNC_DECL i16vec4 unpackInt4x16(int64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u16vec2 unpackUint2x16(uint p) + GLM_FUNC_DECL uint packUint2x16(u16vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint packUint2x16(u16vec2 const& v) + GLM_FUNC_DECL u16vec2 unpackUint2x16(uint p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u16vec4 unpackUint4x16(uint64 p) + GLM_FUNC_DECL uint64 packUint4x16(u16vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint64 packUint4x16(u16vec4 const& v) + GLM_FUNC_DECL u16vec4 unpackUint4x16(uint64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i32vec2 unpackInt2x32(int p) + GLM_FUNC_DECL int64 packInt2x32(i32vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packInt2x16(i32vec2 const& v) + GLM_FUNC_DECL i32vec2 unpackInt2x32(int64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u32vec2 unpackUint2x32(int p) + GLM_FUNC_DECL uint64 packUint2x32(u32vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packUint2x16(u32vec2 const& v) + GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p); + + /// @} }// namespace glm diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 7333ef86..0af0005d 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -793,5 +793,145 @@ namespace detail Unpack.pack = v; return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor; } + + GLM_FUNC_QUALIFIER int16 packInt2x8(i8vec2 const& v) + { + int16 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i8vec2 unpackInt2x8(int16 p) + { + i8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint16 packUint2x8(u8vec2 const& v) + { + uint16 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u8vec2 unpackUint2x8(uint16 p) + { + u8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int32 packInt4x8(i8vec4 const& v) + { + int32 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i8vec4 unpackInt4x8(int32 p) + { + i8vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint32 packUint4x8(u8vec4 const& v) + { + uint32 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u8vec4 unpackUint4x8(uint32 p) + { + u8vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int packInt2x16(i16vec2 const& v) + { + int Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i16vec2 unpackInt2x16(int p) + { + i16vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int64 packInt4x16(i16vec4 const& v) + { + int64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i16vec4 unpackInt4x16(int64 p) + { + i16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint packUint2x16(u16vec2 const& v) + { + uint Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u16vec2 unpackUint2x16(uint p) + { + u16vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint64 packUint4x16(u16vec4 const& v) + { + uint64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u16vec4 unpackUint4x16(uint64 p) + { + u16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int64 packInt2x32(i32vec2 const& v) + { + int64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i32vec2 unpackInt2x32(int64 p) + { + i32vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint64 packUint2x32(u32vec2 const& v) + { + uint64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u32vec2 unpackUint2x32(uint64 p) + { + u32vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } }//namespace glm diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index edf07faa..de8d2050 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -70,14 +70,14 @@ namespace glm typedef length_t length_type; /// Return the count of components of a quaternion - GLM_FUNC_DECL static length_type length(){return 4;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;} GLM_FUNC_DECL T & operator[](length_type i); GLM_FUNC_DECL T const & operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat const& q) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat const& q); diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index dbdf504d..cbe4667d 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -83,12 +83,9 @@ namespace detail // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat() -# ifndef GLM_FORCE_NO_CTOR_INIT - : x(0), y(0), z(0), w(1) -# endif {} # endif @@ -294,19 +291,19 @@ namespace detail // -- Binary operators -- template - GLM_FUNC_QUALIFIER tquat operator+(tquat const & q, tquat const & p) + GLM_FUNC_QUALIFIER tquat operator+(tquat const & q, tquat const & p) { return tquat(q) += p; } template - GLM_FUNC_QUALIFIER tquat operator*(tquat const & q, tquat const & p) + GLM_FUNC_QUALIFIER tquat operator*(tquat const & q, tquat const & p) { return tquat(q) *= p; } template - GLM_FUNC_QUALIFIER vec<3, T, P> operator*(tquat const & q, vec<3, T, P> const & v) + GLM_FUNC_QUALIFIER vec<3, T, P> operator*(tquat const & q, vec<3, T, P> const & v) { vec<3, T, P> const QuatVector(q.x, q.y, q.z); vec<3, T, P> const uv(glm::cross(QuatVector, v)); @@ -380,7 +377,7 @@ namespace detail { T len = length(q); if(len <= T(0)) // Problem - return tquat(1, 0, 0, 0); + return tquat(static_cast(1), static_cast(0), static_cast(0), static_cast(0)); T oneOverLen = T(1) / len; return tquat(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen); } diff --git a/glm/gtx/dual_quaternion.hpp b/glm/gtx/dual_quaternion.hpp index 1fa23f57..7c346794 100644 --- a/glm/gtx/dual_quaternion.hpp +++ b/glm/gtx/dual_quaternion.hpp @@ -49,14 +49,14 @@ namespace glm typedef length_t length_type; /// Return the count of components of a dual quaternion - GLM_FUNC_DECL static length_type length(){return 2;} + GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 2;} GLM_FUNC_DECL part_type & operator[](length_type i); GLM_FUNC_DECL part_type const & operator[](length_type i) const; // -- Implicit basic constructors -- - GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT; GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat const & d) GLM_DEFAULT; template GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat const & d); diff --git a/glm/gtx/dual_quaternion.inl b/glm/gtx/dual_quaternion.inl index 86915284..0565caa3 100644 --- a/glm/gtx/dual_quaternion.inl +++ b/glm/gtx/dual_quaternion.inl @@ -24,13 +24,9 @@ namespace glm // -- Implicit basic constructors -- -# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) +# if !GLM_HAS_DEFAULTED_FUNCTIONS template GLM_FUNC_QUALIFIER GLM_CONSTEXPR tdualquat::tdualquat() -# ifndef GLM_FORCE_NO_CTOR_INIT - : real(tquat()) - , dual(tquat(0, 0, 0, 0)) -# endif {} # endif diff --git a/glm/gtx/integer.hpp b/glm/gtx/integer.hpp index d96b3d82..9420581c 100644 --- a/glm/gtx/integer.hpp +++ b/glm/gtx/integer.hpp @@ -31,7 +31,7 @@ namespace glm //! Returns x raised to the y power. //! From GLM_GTX_integer extension. - GLM_FUNC_DECL int pow(int x, int y); + GLM_FUNC_DECL int pow(int x, uint y); //! Returns the positive square root of x. //! From GLM_GTX_integer extension. diff --git a/glm/gtx/integer.inl b/glm/gtx/integer.inl index bddfd2ca..186072f6 100644 --- a/glm/gtx/integer.inl +++ b/glm/gtx/integer.inl @@ -4,10 +4,11 @@ namespace glm { // pow - GLM_FUNC_QUALIFIER int pow(int x, int y) + GLM_FUNC_QUALIFIER int pow(int x, uint y) { if(y == 0) - return 1; + return x >= 0 ? 1 : -1; + int result = x; for(int i = 1; i < y; ++i) result *= x; @@ -111,6 +112,9 @@ namespace detail GLM_FUNC_QUALIFIER uint pow(uint x, uint y) { + if (y == 0) + return 1u; + uint result = x; for(uint i = 1; i < y; ++i) result *= x; diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp new file mode 100644 index 00000000..fafbff09 --- /dev/null +++ b/glm/gtx/matrix_factorisation.hpp @@ -0,0 +1,65 @@ +/// @ref gtx_matrix_factorisation +/// @file glm/gtx/matrix_factorisation.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtx_matrix_factorisation GLM_GTX_matrix_factorisation +/// @ingroup gtx +/// +/// @brief Functions to factor matrices in various forms +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependency: +#include "../glm.hpp" + +#ifndef GLM_ENABLE_EXPERIMENTAL +# error "GLM: GLM_GTX_matrix_factorisation is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it." +#endif + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTX_matrix_factorisation extension included") +#endif + +/* +Suggestions: + - Move helper functions flipud and fliplr to another file: They may be helpful in more general circumstances. + - Implement other types of matrix factorisation, such as: QL and LQ, L(D)U, eigendecompositions, etc... +*/ + +namespace glm +{ + /// @addtogroup gtx_matrix_factorisation + /// @{ + + /// Flips the matrix rows up and down. + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL matType flipud(matType const& in); + + /// Flips the matrix columns right and left. + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL matType fliplr(matType const& in); + + /// Performs QR factorisation of a matrix. + /// Returns 2 matrices, q and r, such that the columns of q are orthonormal and span the same subspace than those of the input matrix, r is an upper triangular matrix, and q*r=in. + /// Given an n-by-m input matrix, q has dimensions min(n,m)-by-m, and r has dimensions n-by-min(n,m). + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL void qr_decompose(matType const& in, matType<(C < R ? C : R), R, T, P>& q, matType& r); + + /// Performs RQ factorisation of a matrix. + /// Returns 2 matrices, r and q, such that r is an upper triangular matrix, the rows of q are orthonormal and span the same subspace than those of the input matrix, and r*q=in. + /// Note that in the context of RQ factorisation, the diagonal is seen as starting in the lower-right corner of the matrix, instead of the usual upper-left. + /// Given an n-by-m input matrix, r has dimensions min(n,m)-by-m, and q has dimensions n-by-min(n,m). + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL void rq_decompose(matType const& in, matType<(C < R ? C : R), R, T, P>& r, matType& q); + + /// @} +} + +#include "matrix_factorisation.inl" diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl new file mode 100644 index 00000000..90fb7857 --- /dev/null +++ b/glm/gtx/matrix_factorisation.inl @@ -0,0 +1,85 @@ +/// @ref gtx_matrix_factorisation +/// @file glm/gtx/matrix_factorisation.inl + +namespace glm +{ + template class matType> + GLM_FUNC_QUALIFIER matType flipud(matType const& in) + { + matType tin = transpose(in); + tin = fliplr(tin); + matType out = transpose(tin); + + return out; + } + + template class matType> + GLM_FUNC_QUALIFIER matType fliplr(matType const& in) + { + matType out(uninitialize); + for (length_t i = 0; i < C; i++) + { + out[i] = in[(C - i) - 1]; + } + + return out; + } + + template class matType> + GLM_FUNC_QUALIFIER void qr_decompose(matType const& in, matType<(C < R ? C : R), R, T, P>& q, matType& r) + { + // Uses modified Gram-Schmidt method + // Source: https://en.wikipedia.org/wiki/Gram–Schmidt_process + // And https://en.wikipedia.org/wiki/QR_decomposition + + //For all the linearly independs columns of the input... + // (there can be no more linearly independents columns than there are rows.) + for (length_t i = 0; i < (C < R ? C : R); i++) + { + //Copy in Q the input's i-th column. + q[i] = in[i]; + + //j = [0,i[ + // Make that column orthogonal to all the previous ones by substracting to it the non-orthogonal projection of all the previous columns. + // Also: Fill the zero elements of R + for (length_t j = 0; j < i; j++) + { + q[i] -= dot(q[i], q[j])*q[j]; + r[j][i] = 0; + } + + //Now, Q i-th column is orthogonal to all the previous columns. Normalize it. + q[i] = normalize(q[i]); + + //j = [i,C[ + //Finally, compute the corresponding coefficients of R by computing the projection of the resulting column on the other columns of the input. + for (length_t j = i; j < C; j++) + { + r[j][i] = dot(in[j], q[i]); + } + } + } + + template class matType> + GLM_FUNC_QUALIFIER void rq_decompose(matType const& in, matType<(C < R ? C : R), R, T, P>& r, matType& q) + { + // From https://en.wikipedia.org/wiki/QR_decomposition: + // The RQ decomposition transforms a matrix A into the product of an upper triangular matrix R (also known as right-triangular) and an orthogonal matrix Q. The only difference from QR decomposition is the order of these matrices. + // QR decomposition is Gram–Schmidt orthogonalization of columns of A, started from the first column. + // RQ decomposition is Gram–Schmidt orthogonalization of rows of A, started from the last row. + + matType tin = transpose(in); + tin = fliplr(tin); + + matType tr; + matType<(C < R ? C : R), C, T, P> tq; + qr_decompose(tin, tq, tr); + + tr = fliplr(tr); + r = transpose(tr); + r = fliplr(r); + + tq = fliplr(tq); + q = transpose(tq); + } +} //namespace glm diff --git a/glm/gtx/matrix_interpolation.inl b/glm/gtx/matrix_interpolation.inl index 8e99ac4d..b3954499 100644 --- a/glm/gtx/matrix_interpolation.inl +++ b/glm/gtx/matrix_interpolation.inl @@ -1,6 +1,8 @@ /// @ref gtx_matrix_interpolation /// @file glm/gtx/matrix_interpolation.hpp +#include "../gtc/constants.hpp" + namespace glm { template @@ -72,7 +74,11 @@ namespace glm T s = sqrt((mat[2][1] - mat[1][2]) * (mat[2][1] - mat[1][2]) + (mat[2][0] - mat[0][2]) * (mat[2][0] - mat[0][2]) + (mat[1][0] - mat[0][1]) * (mat[1][0] - mat[0][1])); if (glm::abs(s) < T(0.001)) s = (T)1.0; - angle = acos((mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) * (T)0.5); + T const angleCos = (mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) * (T)0.5; + if (angleCos - static_cast(1) < epsilon) + angle = pi() * static_cast(0.25); + else + angle = acos(angleCos); axis.x = (mat[1][2] - mat[2][1]) / s; axis.y = (mat[2][0] - mat[0][2]) / s; axis.z = (mat[0][1] - mat[1][0]) / s; diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index ad298dae..cce10892 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -177,6 +177,34 @@ namespace glm vec<3, T, P> const & orig, vec<3, T, P> const & dest); + /// Build a look at quaternion based on the default handedness. + /// + /// @param direction Desired direction of the camera. + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). + template + GLM_FUNC_DECL tquat quatLookAt( + tvec3 const & direction, + tvec3 const & up); + + /// Build a right-handed look at quaternion. + /// + /// @param direction Desired direction of the camera. + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). + template + GLM_FUNC_DECL tquat quatLookAtRH( + tvec3 const & direction, + tvec3 const & up); + + /// Build a left-handed look at quaternion. + /// + /// @param eye Position of the camera + /// @param direction Desired direction onto which the +z-axis gets mapped + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). + template + GLM_FUNC_DECL tquat quatLookAtLH( + tvec3 const & direction, + tvec3 const & up); + /// Returns the squared length of x. /// /// @see gtx_quaternion diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 7bdcdf60..c69426bb 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -208,5 +208,39 @@ namespace glm rotationAxis.y * invs, rotationAxis.z * invs); } + + template + GLM_FUNC_QUALIFIER tquat quatLookAt(tvec3 const& direction, tvec3 const& up) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return quatLookAtLH(direction, up); +# else + return quatLookAtRH(direction, up); +# endif + } + + template + GLM_FUNC_QUALIFIER tquat quatLookAtRH(tvec3 const& direction, tvec3 const& up) + { + tmat3x3 Result(uninitialize); + + Result[2] = -normalize(direction); + Result[0] = normalize(cross(up, Result[2])); + Result[1] = cross(Result[2], Result[0]); + + return quat_cast(Result); + } + + template + GLM_FUNC_QUALIFIER tquat quatLookAtLH(tvec3 const& direction, tvec3 const& up) + { + tmat3x3 Result(uninitialize); + + Result[2] = normalize(direction); + Result[0] = normalize(cross(up, Result[2])); + Result[1] = cross(Result[2], Result[0]); + + return quat_cast(Result); + } }//namespace glm diff --git a/glm/simd/common.h b/glm/simd/common.h index d8c212d2..143a941f 100644 --- a/glm/simd/common.h +++ b/glm/simd/common.h @@ -112,7 +112,7 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_round(glm_vec4 x) # if GLM_ARCH & GLM_ARCH_SSE41_BIT return _mm_round_ps(x, _MM_FROUND_TO_NEAREST_INT); # else - glm_vec4 const sgn0 = _mm_castsi128_ps(_mm_set1_epi32(0x80000000)); + glm_vec4 const sgn0 = _mm_castsi128_ps(_mm_set1_epi32(int(0x80000000))); glm_vec4 const and0 = _mm_and_ps(sgn0, x); glm_vec4 const or0 = _mm_or_ps(and0, _mm_set_ps1(8388608.0f)); glm_vec4 const add0 = glm_vec4_add(x, or0); @@ -144,7 +144,7 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_trunc(glm_vec4 x) //roundEven GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_roundEven(glm_vec4 x) { - glm_vec4 const sgn0 = _mm_castsi128_ps(_mm_set1_epi32(0x80000000)); + glm_vec4 const sgn0 = _mm_castsi128_ps(_mm_set1_epi32(int(0x80000000))); glm_vec4 const and0 = _mm_and_ps(sgn0, x); glm_vec4 const or0 = _mm_or_ps(and0, _mm_set_ps1(8388608.0f)); glm_vec4 const add0 = glm_vec4_add(x, or0); @@ -220,7 +220,7 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_nan(glm_vec4 x) { glm_ivec4 const t1 = _mm_castps_si128(x); // reinterpret as 32-bit integer glm_ivec4 const t2 = _mm_sll_epi32(t1, _mm_cvtsi32_si128(1)); // shift out sign bit - glm_ivec4 const t3 = _mm_set1_epi32(0xFF000000); // exponent mask + glm_ivec4 const t3 = _mm_set1_epi32(int(0xFF000000)); // exponent mask glm_ivec4 const t4 = _mm_and_si128(t2, t3); // exponent glm_ivec4 const t5 = _mm_andnot_si128(t3, t2); // fraction glm_ivec4 const Equal = _mm_cmpeq_epi32(t3, t4); @@ -234,7 +234,7 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_inf(glm_vec4 x) { glm_ivec4 const t1 = _mm_castps_si128(x); // reinterpret as 32-bit integer glm_ivec4 const t2 = _mm_sll_epi32(t1, _mm_cvtsi32_si128(1)); // shift out sign bit - return _mm_castsi128_ps(_mm_cmpeq_epi32(t2, _mm_set1_epi32(0xFF000000))); // exponent is all 1s, fraction is 0 + return _mm_castsi128_ps(_mm_cmpeq_epi32(t2, _mm_set1_epi32(int(0xFF000000)))); // exponent is all 1s, fraction is 0 } #endif//GLM_ARCH & GLM_ARCH_SSE2_BIT diff --git a/manual.md b/manual.md index cecd6951..31a33063 100644 --- a/manual.md +++ b/manual.md @@ -22,9 +22,8 @@ + [3.4. SIMD support](#section3_4) + [3.5. Force inline](#section3_5) + [3.6. Vector and matrix static size](#section3_6) -+ [3.7. Disabling default constructor initialization](#section3_7) -+ [3.8. Requiring explicit conversions](#section3_8) -+ [3.9. Removing genType restriction](#section3_9) ++ [3.7. Requiring explicit conversions](#section3_7) ++ [3.8. Removing genType restriction](#section3_8) + [4. Stable extensions](#section4) + [4.1. GLM_GTC_bitfield](#section4_1) + [4.2. GLM_GTC_color_space](#section4_2) @@ -469,49 +468,7 @@ void foo(vec4 const & v) } ``` -### 3.7. Disabling default constructor initialization - -By default and following GLSL specifications, vector and matrix default constructors initialize the components to zero. This is a reliable behavior but initialization has a cost and it’s not always necessary. -This behavior can be disabled at compilation time by define GLM\_FORCE\_NO\_CTOR\_INIT before any inclusion of <glm/glm.hpp> or other GLM include. - -GLM default behavior: - -```cpp -#include - -void foo() -{ - glm::vec4 v; // v is (0.0f, 0.0f, 0.0f, 0.0f) - ... -} -``` - -GLM behavior using GLM\_FORCE\_NO\_CTOR\_INIT: - -```cpp -#define GLM_FORCE_NO_CTOR_INIT -#include - -void foo() -{ - glm::vec4 v; // v is filled with garbage - ... -} -``` - -Alternatively, GLM allows to explicitly not initialize a variable: - -```cpp -#include - -void foo() -{ - glm::vec4 v(glm::uninitialize); - ... -} -``` - -### 3.8. Require explicit conversions +### 3.7. Requiring explicit conversions GLSL supports implicit conversions of vector and matrix types. For example, an ivec4 can be implicitly converted into vec4. @@ -548,7 +505,7 @@ void foo() } ``` -### 3.9. Removing genType restriction +### 3.8. Removing genType restriction By default GLM only supports basic types as genType for vector, matrix and quaternion types: diff --git a/readme.md b/readme.md index f49f2fd2..84f02007 100644 --- a/readme.md +++ b/readme.md @@ -57,9 +57,14 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added GTX_color_encoding extension - Added GTX_vec_swizzle, faster compile time swizzling then swizzle operator #558 - Added GTX_exterior_product with a vec2 cross implementation #621 +- Added GTX_matrix_factorisation to factor matrices in various forms #654 - Added [GLM_ENABLE_EXPERIMENTAL](manual.md#section7_4) to enable experimental features. +- Added packing functions for integer vectors #639 +- Added conan packaging configuration #643 #641 +- Added quatLookAt to GTX_quaternion #659 #### Improvements: +- No more default initialization of vector, matrix and quaternion types - Added lowp variant of GTC_color_space convertLinearToSRGB #419 - Replaced the manual by a markdown version #458 - Optimized GTC_packing implementation @@ -70,7 +75,9 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added FAQ 12: Windows headers cause build errors... #557 - Removed GCC shadow warnings #595 - Added error for including of different versions of GLM #619 -- Added GLM_FORCE_IGNORE_VERSION to ignore error caused by including different version of GLM #619 +- Added GLM_FORCE_IGNORE_VERSION to ignore error caused by including different version of GLM #619 +- Reduced warnings when using very strict compilation flags #646 +- length() member functions are constexpr #657 #### Fixes: - Removed doxygen references to GTC_half_float which was removed in 0.9.4 @@ -80,6 +87,10 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Fixed usused variable warning in GTX_spline #618 - Fixed references to GLM_FORCE_RADIANS which was removed #642 - Fixed glm::fastInverseSqrt to use fast inverse square #640 +- Fixed axisAngle NaN #638 +- Fixed integer pow from GTX_integer with null exponent #658 +- Fixed quat normalize build error #656 +- Fixed Visual C++ 2017.2 warning regarding __has_feature definision #655 #### Deprecation: - Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler diff --git a/test/core/core_type_vec1.cpp b/test/core/core_type_vec1.cpp index ff1555fe..543729eb 100644 --- a/test/core/core_type_vec1.cpp +++ b/test/core/core_type_vec1.cpp @@ -106,6 +106,11 @@ int test_vec1_size() Error += glm::vec1::length() == 1 ? 0 : 1; Error += glm::dvec1::length() == 1 ? 0 : 1; +# if GLM_HAS_CONSTEXPR_PARTIAL + constexpr std::size_t Length = glm::vec2::length(); + Error += Length == 1 ? 0 : 1; +# endif + return Error; } diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 89ab00cb..551220b8 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -272,6 +272,11 @@ int test_vec2_size() Error += glm::vec2::length() == 2 ? 0 : 1; Error += glm::dvec2::length() == 2 ? 0 : 1; +# if GLM_HAS_CONSTEXPR_PARTIAL + constexpr std::size_t Length = glm::vec2::length(); + Error += Length == 2 ? 0 : 1; +# endif + return Error; } diff --git a/test/core/core_type_vec3.cpp b/test/core/core_type_vec3.cpp index 072767f9..bbbd1841 100644 --- a/test/core/core_type_vec3.cpp +++ b/test/core/core_type_vec3.cpp @@ -246,6 +246,11 @@ int test_vec3_size() Error += glm::vec3::length() == 3 ? 0 : 1; Error += glm::dvec3::length() == 3 ? 0 : 1; +# if GLM_HAS_CONSTEXPR_PARTIAL + constexpr std::size_t Length = glm::vec3::length(); + Error += Length == 3 ? 0 : 1; +# endif + return Error; } diff --git a/test/core/core_type_vec4.cpp b/test/core/core_type_vec4.cpp index 72af25d8..79c62c04 100644 --- a/test/core/core_type_vec4.cpp +++ b/test/core/core_type_vec4.cpp @@ -322,6 +322,11 @@ int test_vec4_size() Error += glm::vec4::length() == 4 ? 0 : 1; Error += glm::dvec4::length() == 4 ? 0 : 1; +# if GLM_HAS_CONSTEXPR_PARTIAL + constexpr std::size_t Length = glm::vec4::length(); + Error += Length == 4 ? 0 : 1; +# endif + return Error; } diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 205f90cf..a5593fd5 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -670,6 +670,156 @@ int test_packUnorm2x3_1x2() return Error; } +int test_packUint2x8() +{ + int Error = 0; + + glm::u8vec2 const Source(1, 2); + + glm::uint16 const Packed = glm::packUint2x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint4x8() +{ + int Error = 0; + + glm::u8vec4 const Source(1, 2, 3, 4); + + glm::uint32 const Packed = glm::packUint4x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint2x16() +{ + int Error = 0; + + glm::u16vec2 const Source(1, 2); + + glm::uint32 const Packed = glm::packUint2x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint4x16() +{ + int Error = 0; + + glm::u16vec4 const Source(1, 2, 3, 4); + + glm::uint64 const Packed = glm::packUint4x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint2x32() +{ + int Error = 0; + + glm::u32vec2 const Source(1, 2); + + glm::uint64 const Packed = glm::packUint2x32(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x8() +{ + int Error = 0; + + glm::i8vec2 const Source(1, 2); + + glm::int16 const Packed = glm::packInt2x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt4x8() +{ + int Error = 0; + + glm::i8vec4 const Source(1, 2, 3, 4); + + glm::int32 const Packed = glm::packInt4x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x16() +{ + int Error = 0; + + glm::i16vec2 const Source(1, 2); + + glm::int32 const Packed = glm::packInt2x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt4x16() +{ + int Error = 0; + + glm::i16vec4 const Source(1, 2, 3, 4); + + glm::int64 const Packed = glm::packInt4x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x32() +{ + int Error = 0; + + glm::i32vec2 const Source(1, 2); + + glm::int64 const Packed = glm::packInt2x32(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + int main() { int Error = 0; @@ -699,6 +849,18 @@ int main() Error += test_packUnorm1x5_1x6_1x5(); Error += test_packUnorm2x3_1x2(); + Error += test_packUint2x8(); + Error += test_packUint4x8(); + Error += test_packUint2x16(); + Error += test_packUint4x16(); + Error += test_packUint2x32(); + + Error += test_packInt2x8(); + Error += test_packInt4x8(); + Error += test_packInt2x16(); + Error += test_packInt4x16(); + Error += test_packInt2x32(); + Error += test_F2x11_1x10(); Error += test_F3x9_E1x5(); Error += test_RGBM(); diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index 6fe2fc27..6b320294 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -21,6 +21,7 @@ glmCreateTestGTC(gtx_io) glmCreateTestGTC(gtx_log_base) glmCreateTestGTC(gtx_matrix_cross_product) glmCreateTestGTC(gtx_matrix_decompose) +glmCreateTestGTC(gtx_matrix_factorisation) glmCreateTestGTC(gtx_matrix_interpolation) glmCreateTestGTC(gtx_matrix_major_storage) glmCreateTestGTC(gtx_matrix_operation) diff --git a/test/gtx/gtx_integer.cpp b/test/gtx/gtx_integer.cpp index f810953f..ae3be761 100644 --- a/test/gtx/gtx_integer.cpp +++ b/test/gtx/gtx_integer.cpp @@ -52,6 +52,47 @@ int test_nlz() return Error; } +int test_pow_uint() +{ + int Error = 0; + + glm::uint const p0 = glm::pow(2u, 0u); + Error += p0 == 1u ? 0 : 1; + + glm::uint const p1 = glm::pow(2u, 1u); + Error += p1 == 2u ? 0 : 1; + + glm::uint const p2 = glm::pow(2u, 2u); + Error += p2 == 4u ? 0 : 1; + + return Error; +} + +int test_pow_int() +{ + int Error = 0; + + int const p0 = glm::pow(2, 0u); + Error += p0 == 1 ? 0 : 1; + + int const p1 = glm::pow(2, 1u); + Error += p1 == 2 ? 0 : 1; + + int const p2 = glm::pow(2, 2u); + Error += p2 == 4 ? 0 : 1; + + int const p0n = glm::pow(-2, 0u); + Error += p0n == -1 ? 0 : 1; + + int const p1n = glm::pow(-2, 1u); + Error += p1n == -2 ? 0 : 1; + + int const p2n = glm::pow(-2, 2u); + Error += p2n == 4 ? 0 : 1; + + return Error; +} + int main() { int Error = 0; @@ -59,6 +100,8 @@ int main() Error += test_nlz(); // Error += test_floor_log2(); Error += test_log2(); + Error += test_pow_uint(); + Error += test_pow_int(); return Error; } diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp new file mode 100644 index 00000000..40e56e4b --- /dev/null +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -0,0 +1,101 @@ +#define GLM_ENABLE_EXPERIMENTAL +#include + +float const epsilon = 1e-10f; + +template class matType> +int test_qr(matType m) +{ + int Error = 0; + + matType<(C < R ? C : R), R, T, P> q(-999); + matType r(-999); + + glm::qr_decompose(m, q, r); + + //Test if q*r really equals the input matrix + matType tm = q*r; + matType err = tm - m; + + for (glm::length_t i = 0; i < C; i++) + for (glm::length_t j = 0; j < R; j++) + Error += std::abs(err[i][j]) > epsilon ? 1 : 0; + + //Test if the columns of q are orthonormal + for (glm::length_t i = 0; i < (C < R ? C : R); i++) + { + Error += (length(q[i]) - 1) > epsilon ? 1 : 0; + + for (glm::length_t j = 0; j epsilon ? 1 : 0; + } + + //Test if the matrix r is upper triangular + for (glm::length_t i = 0; i < C; i++) + for (glm::length_t j = i + 1; j < (C < R ? C : R); j++) + Error += r[i][j] != 0 ? 1 : 0; + + return Error; +} + +template class matType> +int test_rq(matType m) +{ + int Error = 0; + + matType q(-999); + matType<(C < R ? C : R), R, T, P> r(-999); + + glm::rq_decompose(m, r, q); + + //Test if q*r really equals the input matrix + matType tm = r*q; + matType err = tm - m; + + for (glm::length_t i = 0; i < C; i++) + for (glm::length_t j = 0; j < R; j++) + Error += std::abs(err[i][j]) > epsilon ? 1 : 0; + + //Test if the rows of q are orthonormal + matType<(C < R ? C : R), C, T, P> tq = transpose(q); + + for (glm::length_t i = 0; i < (C < R ? C : R); i++) + { + Error += (length(tq[i]) - 1) > epsilon ? 1 : 0; + + for (glm::length_t j = 0; j epsilon ? 1 : 0; + } + + //Test if the matrix r is upper triangular + for (glm::length_t i = 0; i < (C < R ? C : R); i++) + for (glm::length_t j = R - (C < R ? C : R) + i + 1; j < R; j++) + Error += r[i][j] != 0 ? 1 : 0; + + return Error; +} + +int main() +{ + int Error = 0; + + //Test QR square + Error += test_qr(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41)) ? 1 : 0; + + //Test RQ square + Error += test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41)) ? 1 : 0; + + //Test QR triangular 1 + Error += test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; + + //Test QR triangular 2 + Error += test_qr(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; + + //Test RQ triangular 1 : Fails at the triangular test + Error += test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; + + //Test QR triangular 2 + Error += test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; + + return Error; +} diff --git a/test/gtx/gtx_matrix_interpolation.cpp b/test/gtx/gtx_matrix_interpolation.cpp index 6498339b..e35fa100 100644 --- a/test/gtx/gtx_matrix_interpolation.cpp +++ b/test/gtx/gtx_matrix_interpolation.cpp @@ -1,9 +1,45 @@ #define GLM_ENABLE_EXPERIMENTAL +#include #include +#include + +int test_axisAngle() +{ + int Error = 0; + + float p = 0.171654f; + glm::mat4 m1(-0.9946f, 0.0f, -0.104531f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.104531f, 0.0f, -0.9946f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + glm::mat4 m2(-0.992624f, 0.0f, -0.121874f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.121874f, 0.0f, -0.992624f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + + glm::mat4 const m1rot = glm::extractMatrixRotation(m1); + glm::mat4 const dltRotation = m2 * glm::transpose(m1rot); + + glm::vec3 dltAxis(0.0f); + float dltAngle = 0.0f; + glm::axisAngle(dltRotation, dltAxis, dltAngle); + + std::cout << "dltAngle: (" << dltAxis.x << ", " << dltAxis.y << ", " << dltAxis.z << "), dltAngle: " << dltAngle << std::endl; + + glm::fquat q = glm::quat_cast(dltRotation); + std::cout << "q: (" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")" << std::endl; + float yaw = glm::yaw(q); + std::cout << "Yaw: " << yaw << std::endl; + + return Error; +} + int main() { - int Error(0); + int Error = 0; + + Error += test_axisAngle(); return Error; } diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index a6daf715..e27981c4 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -90,6 +90,23 @@ int test_log() return Error; } +int test_quat_lookAt() +{ + int Error(0); + + glm::vec3 eye(0.0f); + glm::vec3 center(1.1f, -2.0f, 3.1416f); + glm::vec3 up = glm::vec3(-0.17f, 7.23f, -1.744f); + + glm::quat test_quat = glm::quatLookAt(center - eye, up); + glm::quat test_mat = glm::conjugate(glm::quat_cast(glm::lookAt(eye, center, up))); + + Error += static_cast(glm::abs(glm::length(test_quat) - 1.0f) > glm::epsilon()); + Error += static_cast(glm::min(glm::length(test_quat + (-test_mat)), glm::length(test_quat + test_mat)) > glm::epsilon()); + + return Error; +} + int main() { int Error = 0; @@ -98,6 +115,7 @@ int main() Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); + Error += test_quat_lookAt(); return Error; }