From 412b562200994f326790e199d349035ae26d1acc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Jun 2017 12:12:00 +0200 Subject: [PATCH 01/30] Added packing functions for integer vectors #639 --- glm/gtc/packing.hpp | 138 +++++++++++++++++++++++++++++++-- glm/gtc/packing.inl | 140 +++++++++++++++++++++++++++++++++ readme.md | 1 + test/gtc/gtc_packing.cpp | 162 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 434 insertions(+), 7 deletions(-) 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/readme.md b/readme.md index f49f2fd2..8fe751c5 100644 --- a/readme.md +++ b/readme.md @@ -58,6 +58,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added GTX_vec_swizzle, faster compile time swizzling then swizzle operator #558 - Added GTX_exterior_product with a vec2 cross implementation #621 - Added [GLM_ENABLE_EXPERIMENTAL](manual.md#section7_4) to enable experimental features. +- Added packing functions for integer vectors #639 #### Improvements: - Added lowp variant of GTC_color_space convertLinearToSRGB #419 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(); From 631fd1703fcd9bde8a9093dec63c386356391d5e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Jun 2017 12:16:51 +0200 Subject: [PATCH 02/30] Added conan packaging configuration #643 #641, updated readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 8fe751c5..ce9c4be9 100644 --- a/readme.md +++ b/readme.md @@ -59,6 +59,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added GTX_exterior_product with a vec2 cross implementation #621 - 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 #### Improvements: - Added lowp variant of GTC_color_space convertLinearToSRGB #419 From 26b3e3ed788f5f6adcde11c5ec6a41aa100d29cd Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Jun 2017 12:43:00 +0200 Subject: [PATCH 03/30] Fixed axisAngle NaN #638 --- glm/gtx/matrix_interpolation.inl | 8 +++++- readme.md | 1 + test/gtx/gtx_matrix_interpolation.cpp | 38 ++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/glm/gtx/matrix_interpolation.inl b/glm/gtx/matrix_interpolation.inl index 8e99ac4d..3ba49df0 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/readme.md b/readme.md index ce9c4be9..f50970e5 100644 --- a/readme.md +++ b/readme.md @@ -82,6 +82,7 @@ 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 #### Deprecation: - Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler 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; } From 0ca6a444541f3faf993c384e1d25f04c185d4eec Mon Sep 17 00:00:00 2001 From: Magnus Bergsten Date: Sat, 1 Jul 2017 02:51:31 +0900 Subject: [PATCH 04/30] Fixed stray ')' that was breaking gtx/matrix_interpolation. --- glm/gtx/matrix_interpolation.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/matrix_interpolation.inl b/glm/gtx/matrix_interpolation.inl index 3ba49df0..b3954499 100644 --- a/glm/gtx/matrix_interpolation.inl +++ b/glm/gtx/matrix_interpolation.inl @@ -75,7 +75,7 @@ namespace glm if (glm::abs(s) < T(0.001)) s = (T)1.0; T const angleCos = (mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) * (T)0.5; - if (angleCos - static_cast(1)) < epsilon) + if (angleCos - static_cast(1) < epsilon) angle = pi() * static_cast(0.25); else angle = acos(angleCos); From f9531c152405f52373467b28b7b01d1759bc85db Mon Sep 17 00:00:00 2001 From: Magnus Bergsten Date: Sat, 1 Jul 2017 03:13:25 +0900 Subject: [PATCH 05/30] Fix -Wsign-conversion warnings in `simd/common.h`. --- glm/simd/common.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From d6abdb79350593136d5cca9615d3c26e1a555570 Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Wed, 5 Jul 2017 18:52:46 -0400 Subject: [PATCH 06/30] Implements QR and RQ matrix decomposition functions. --- .gitignore | 2 + glm/gtx/matrix_factorisation.hpp | 65 ++++++++++++++++ glm/gtx/matrix_factorisation.inl | 74 ++++++++++++++++++ test/gtx/CMakeLists.txt | 1 + test/gtx/gtx_matrix_factorisation.cpp | 103 ++++++++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 glm/gtx/matrix_factorisation.hpp create mode 100644 glm/gtx/matrix_factorisation.inl create mode 100644 test/gtx/gtx_matrix_factorisation.cpp 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/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp new file mode 100644 index 00000000..dcdd6989 --- /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 +#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 flip lr to another file: They may be helpful in more general circumstances. + - When rq_decompose is fed a matrix that has more rows than columns, the resulting r matrix is NOT upper triangular. Is that a bug? + - 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(const matType& in); + + /// Flips the matrix columns right and left. + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL matType fliplr(const matType& in); + + /// Performs QR factorisation of a matrix. + /// Returns 2 matrices, q and r, such that q columns are orthonormal, r is an upper triangular matrix, and q*r=in. + /// r is a square matrix whose dimensions are the same than the width of the input matrix, and q has the same dimensions than the input matrix. + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL void qr_decompose(matType& q, matType& r, const matType& in); + + /// Performs RQ factorisation of a matrix. + /// Returns 2 matrices, r and q, such that r is an upper triangular matrix, q rows are orthonormal, and r*q=in. + /// q has the same dimensions than the input matrix, and r is a square matrix whose dimensions are the same than the height of the input matrix. + /// From GLM_GTX_matrix_factorisation extension. + template class matType> + GLM_FUNC_DECL void rq_decompose(matType& r, matType& q, const matType& in); + + /// @} +} + +#include "matrix_factorisation.inl" diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl new file mode 100644 index 00000000..ec9ae0f1 --- /dev/null +++ b/glm/gtx/matrix_factorisation.inl @@ -0,0 +1,74 @@ +/// @ref gtx_matrix_factorisation +/// @file glm/gtx/matrix_factorisation.inl + +namespace glm { + template class matType> + GLM_FUNC_QUALIFIER matType flipud(const matType& in) { + matType tin = transpose(in); + tin = fliplr(tin); + matType out = transpose(tin); + + return out; + } + + template class matType> + GLM_FUNC_QUALIFIER matType fliplr(const matType& in) { + constexpr length_t num_cols = C; + + matType out; + for (length_t i = 0; i < num_cols; i++) { + out[i] = in[(num_cols - i) - 1]; + } + + return out; + } + + template class matType> + GLM_FUNC_QUALIFIER void qr_decompose(matType& q, matType& r, const matType& in) { + // Uses modified Gram-Schmidt method + // Source: https://en.wikipedia.org/wiki/Gram–Schmidt_process + // And https://en.wikipedia.org/wiki/QR_decomposition + + for (length_t i = 0; i < std::min(R, C); i++) { + q[i] = in[i]; + + for (length_t j = 0; j < i; j++) { + q[i] -= dot(q[i], q[j])*q[j]; + } + + q[i] = normalize(q[i]); + } + + for (length_t i = 0; i < std::min(R, C); i++) { + for (length_t j = 0; j < i; j++) { + r[j][i] = 0; + } + + 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& r, matType& q, const matType& in) { + // 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 tq; + qr_decompose(tq, tr, tin); + + tr = fliplr(tr); + r = transpose(tr); + r = fliplr(r); + + tq = fliplr(tq); + q = transpose(tq); + } +} //namespace glm 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_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp new file mode 100644 index 00000000..9ea46874 --- /dev/null +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -0,0 +1,103 @@ +#define GLM_ENABLE_EXPERIMENTAL +#include + +const double epsilon = 1e-10f; + +template class matType> +int test_qr(matType m) { + matType q(-999); + matType r(-999); + + glm::qr_decompose(q, r, m); + + //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++) { + if (abs(err[i][j]) > epsilon) return 1; + } + } + + //Test if the columns of q are orthonormal + for (glm::length_t i = 0; i < std::min(C, R); i++) { + if ((length(q[i]) - 1) > epsilon) return 1; + + for (glm::length_t j = 0; j epsilon) return 1; + } + } + + //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 < std::min(C, R); j++) { + if (r[i][j] != 0) return 1; + } + } + + return 0; +} + +template class matType> +int test_rq(matType m) { + matType q(-999); + matType r(-999); + + glm::rq_decompose(r, q, m); + + //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++) { + if (abs(err[i][j]) > epsilon) return 1; + } + } + + + //Test if the rows of q are orthonormal + matType tq = transpose(q); + + for (glm::length_t i = 0; i < std::min(C, R); i++) { + if ((length(tq[i]) - 1) > epsilon) return 1; + + for (glm::length_t j = 0; j epsilon) return 1; + } + } + + //Test if the matrix r is upper triangular + for (glm::length_t i = 0; i < std::min(C, R); i++) { + for (glm::length_t j = i + 1; j < R; j++) { + if (r[i][j] != 0) return 1; + } + } + + return 0; +} + +int main() +{ + + //Test QR square + if(test_qr(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 1; + + //Test RQ square + if (test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 1; + + //Test QR triangular 1 + if (test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + + //Test QR triangular 2 + if (test_qr(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + + //Test RQ triangular 1 : Fails at the triangular test + //if (test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + + //Test QR triangular 2 + if (test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + + return 0; +} From 80bd3f16c1af84137cfa2e323ca6bf71fa0ad971 Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Thu, 6 Jul 2017 15:01:19 -0400 Subject: [PATCH 07/30] More comments Fix RQ test Slight optimisation in QR --- glm/gtx/matrix_factorisation.hpp | 10 +++++----- glm/gtx/matrix_factorisation.inl | 18 +++++++++++------- test/gtx/gtx_matrix_factorisation.cpp | 24 ++++++++++++------------ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp index dcdd6989..c553c121 100644 --- a/glm/gtx/matrix_factorisation.hpp +++ b/glm/gtx/matrix_factorisation.hpp @@ -27,7 +27,6 @@ /* Suggestions: - Move helper functions flipud and flip lr to another file: They may be helpful in more general circumstances. - - When rq_decompose is fed a matrix that has more rows than columns, the resulting r matrix is NOT upper triangular. Is that a bug? - Implement other types of matrix factorisation, such as: QL and LQ, L(D)U, eigendecompositions, etc... */ @@ -46,15 +45,16 @@ namespace glm{ GLM_FUNC_DECL matType fliplr(const matType& in); /// Performs QR factorisation of a matrix. - /// Returns 2 matrices, q and r, such that q columns are orthonormal, r is an upper triangular matrix, and q*r=in. - /// r is a square matrix whose dimensions are the same than the width of the input matrix, and q has the same dimensions than the input 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& q, matType& r, const matType& in); /// Performs RQ factorisation of a matrix. - /// Returns 2 matrices, r and q, such that r is an upper triangular matrix, q rows are orthonormal, and r*q=in. - /// q has the same dimensions than the input matrix, and r is a square matrix whose dimensions are the same than the height of the input 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& r, matType& q, const matType& in); diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index ec9ae0f1..f53d8280 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -29,21 +29,25 @@ namespace glm { // 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 < std::min(R, C); 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]; - } - - q[i] = normalize(q[i]); - } - - for (length_t i = 0; i < std::min(R, C); i++) { - for (length_t j = 0; j < i; 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]); } diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp index 9ea46874..d45c352e 100644 --- a/test/gtx/gtx_matrix_factorisation.cpp +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -22,17 +22,17 @@ int test_qr(matType m) { //Test if the columns of q are orthonormal for (glm::length_t i = 0; i < std::min(C, R); i++) { - if ((length(q[i]) - 1) > epsilon) return 1; + if ((length(q[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j epsilon) return 1; + if (abs(dot(q[i], q[j])) > epsilon) return 3; } } //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 < std::min(C, R); j++) { - if (r[i][j] != 0) return 1; + if (r[i][j] != 0) return 4; } } @@ -61,17 +61,17 @@ int test_rq(matType m) { matType tq = transpose(q); for (glm::length_t i = 0; i < std::min(C, R); i++) { - if ((length(tq[i]) - 1) > epsilon) return 1; + if ((length(tq[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j epsilon) return 1; + if (abs(dot(tq[i], tq[j])) > epsilon) return 3; } } //Test if the matrix r is upper triangular for (glm::length_t i = 0; i < std::min(C, R); i++) { - for (glm::length_t j = i + 1; j < R; j++) { - if (r[i][j] != 0) return 1; + for (glm::length_t j = R - std::min(C, R) + i + 1; j < R; j++) { + if (r[i][j] != 0) return 4; } } @@ -85,19 +85,19 @@ int main() if(test_qr(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 1; //Test RQ square - if (test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 1; + if (test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 2; //Test QR triangular 1 - if (test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + if (test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 3; //Test QR triangular 2 - if (test_qr(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + if (test_qr(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 4; //Test RQ triangular 1 : Fails at the triangular test - //if (test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + if (test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 5; //Test QR triangular 2 - if (test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 1; + if (test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 6; return 0; } From edde2bcf6088ff972d8e62d047dd7980a63f09c8 Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Thu, 6 Jul 2017 15:04:00 -0400 Subject: [PATCH 08/30] Fix a comment --- glm/gtx/matrix_factorisation.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp index c553c121..3c66776e 100644 --- a/glm/gtx/matrix_factorisation.hpp +++ b/glm/gtx/matrix_factorisation.hpp @@ -26,7 +26,7 @@ /* Suggestions: - - Move helper functions flipud and flip lr to another file: They may be helpful in more general circumstances. + - 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... */ From f9962054d9f0c46fba55abc44351a4845843b586 Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Thu, 6 Jul 2017 17:45:40 -0400 Subject: [PATCH 09/30] Make C++98 compliant --- glm/gtx/matrix_factorisation.hpp | 5 ++--- glm/gtx/matrix_factorisation.inl | 10 +++++----- test/gtx/gtx_matrix_factorisation.cpp | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp index 3c66776e..9acc7f3a 100644 --- a/glm/gtx/matrix_factorisation.hpp +++ b/glm/gtx/matrix_factorisation.hpp @@ -13,7 +13,6 @@ #pragma once // Dependency: -#include #include "../glm.hpp" #ifndef GLM_ENABLE_EXPERIMENTAL @@ -49,7 +48,7 @@ namespace glm{ /// 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& q, matType& r, const matType& in); + GLM_FUNC_DECL void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in); /// 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. @@ -57,7 +56,7 @@ namespace glm{ /// 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& r, matType& q, const matType& in); + GLM_FUNC_DECL void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in); /// @} } diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index f53d8280..52f0d56c 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -24,14 +24,14 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER void qr_decompose(matType& q, matType& r, const matType& in) { + GLM_FUNC_QUALIFIER void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in) { // 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 < std::min(R, C); i++) { + for (length_t i = 0; i < (C < R ? C : R); i++) { //Copy in Q the input's i-th column. q[i] = in[i]; @@ -55,7 +55,7 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER void rq_decompose(matType& r, matType& q, const matType& in) { + GLM_FUNC_QUALIFIER void rq_decompose(matType<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in) { // 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. @@ -64,8 +64,8 @@ namespace glm { matType tin = transpose(in); tin = fliplr(tin); - matType tr; - matType tq; + matType tr; + matType<(C < R ? C : R), C, T, P> tq; qr_decompose(tq, tr, tin); tr = fliplr(tr); diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp index d45c352e..573f3d0a 100644 --- a/test/gtx/gtx_matrix_factorisation.cpp +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -5,8 +5,8 @@ const double epsilon = 1e-10f; template class matType> int test_qr(matType m) { - matType q(-999); - matType r(-999); + matType<(C < R ? C : R), R, T, P> q(-999); + matType r(-999); glm::qr_decompose(q, r, m); @@ -21,7 +21,7 @@ int test_qr(matType m) { } //Test if the columns of q are orthonormal - for (glm::length_t i = 0; i < std::min(C, R); i++) { + for (glm::length_t i = 0; i < (C < R ? C : R); i++) { if ((length(q[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j m) { //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 < std::min(C, R); j++) { + for (glm::length_t j = i + 1; j < (C < R ? C : R); j++) { if (r[i][j] != 0) return 4; } } @@ -41,8 +41,8 @@ int test_qr(matType m) { template class matType> int test_rq(matType m) { - matType q(-999); - matType r(-999); + matType q(-999); + matType<(C < R ? C : R), R, T, P> r(-999); glm::rq_decompose(r, q, m); @@ -58,9 +58,9 @@ int test_rq(matType m) { //Test if the rows of q are orthonormal - matType tq = transpose(q); + matType<(C < R ? C : R), C, T, P> tq = transpose(q); - for (glm::length_t i = 0; i < std::min(C, R); i++) { + for (glm::length_t i = 0; i < (C < R ? C : R); i++) { if ((length(tq[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j m) { } //Test if the matrix r is upper triangular - for (glm::length_t i = 0; i < std::min(C, R); i++) { - for (glm::length_t j = R - std::min(C, R) + i + 1; j < R; j++) { + 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++) { if (r[i][j] != 0) return 4; } } From da47fac3845ad06577c01d9514ebd7a48fd967b0 Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Thu, 6 Jul 2017 17:54:13 -0400 Subject: [PATCH 10/30] Make C++98 compliant, part 2 --- glm/gtx/matrix_factorisation.inl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index 52f0d56c..f165016f 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -13,11 +13,9 @@ namespace glm { template class matType> GLM_FUNC_QUALIFIER matType fliplr(const matType& in) { - constexpr length_t num_cols = C; - matType out; - for (length_t i = 0; i < num_cols; i++) { - out[i] = in[(num_cols - i) - 1]; + for (length_t i = 0; i < C; i++) { + out[i] = in[(C - i) - 1]; } return out; From a4a6ea2825303cdd917071b8f9e80a30ad8061aa Mon Sep 17 00:00:00 2001 From: Vincent Aymong Date: Thu, 6 Jul 2017 19:17:55 -0400 Subject: [PATCH 11/30] std::abs instead of just abs. Fixes compilation issues with gcc. --- test/gtx/gtx_matrix_factorisation.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp index 573f3d0a..7d32078f 100644 --- a/test/gtx/gtx_matrix_factorisation.cpp +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -16,7 +16,7 @@ int test_qr(matType m) { for (glm::length_t i = 0; i < C; i++) { for (glm::length_t j = 0; j < R; j++) { - if (abs(err[i][j]) > epsilon) return 1; + if (std::abs(err[i][j]) > epsilon) return 1; } } @@ -25,7 +25,7 @@ int test_qr(matType m) { if ((length(q[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j epsilon) return 3; + if (std::abs(dot(q[i], q[j])) > epsilon) return 3; } } @@ -52,7 +52,7 @@ int test_rq(matType m) { for (glm::length_t i = 0; i < C; i++) { for (glm::length_t j = 0; j < R; j++) { - if (abs(err[i][j]) > epsilon) return 1; + if (std::abs(err[i][j]) > epsilon) return 1; } } @@ -64,7 +64,7 @@ int test_rq(matType m) { if ((length(tq[i]) - 1) > epsilon) return 2; for (glm::length_t j = 0; j epsilon) return 3; + if (std::abs(dot(tq[i], tq[j])) > epsilon) return 3; } } From 64cfbc04515f912e284796fa40621909269f97bd Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 09:34:34 +0430 Subject: [PATCH 12/30] Updated GTX_matrix_factorisation to be more consistency with the rest of the codebase #654 --- glm/gtx/matrix_factorisation.hpp | 11 ++++++----- glm/gtx/matrix_factorisation.inl | 27 ++++++++++++++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/glm/gtx/matrix_factorisation.hpp b/glm/gtx/matrix_factorisation.hpp index 9acc7f3a..fafbff09 100644 --- a/glm/gtx/matrix_factorisation.hpp +++ b/glm/gtx/matrix_factorisation.hpp @@ -29,26 +29,27 @@ Suggestions: - Implement other types of matrix factorisation, such as: QL and LQ, L(D)U, eigendecompositions, etc... */ -namespace glm{ +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(const matType& in); + 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(const matType& in); + 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<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in); + 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. @@ -56,7 +57,7 @@ namespace glm{ /// 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<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in); + GLM_FUNC_DECL void rq_decompose(matType const& in, matType<(C < R ? C : R), R, T, P>& r, matType& q); /// @} } diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index f165016f..be7d6c8c 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -1,9 +1,11 @@ /// @ref gtx_matrix_factorisation /// @file glm/gtx/matrix_factorisation.inl -namespace glm { +namespace glm +{ template class matType> - GLM_FUNC_QUALIFIER matType flipud(const matType& in) { + GLM_FUNC_QUALIFIER matType flipud(matType const& in) + { matType tin = transpose(in); tin = fliplr(tin); matType out = transpose(tin); @@ -12,9 +14,11 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER matType fliplr(const matType& in) { + GLM_FUNC_QUALIFIER matType fliplr(matType const& in) + { matType out; - for (length_t i = 0; i < C; i++) { + for (length_t i = 0; i < C; i++) + { out[i] = in[(C - i) - 1]; } @@ -22,21 +26,24 @@ namespace glm { } template class matType> - GLM_FUNC_QUALIFIER void qr_decompose(matType<(C < R ? C : R), R, T, P>& q, matType& r, const matType& in) { + 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++) { + 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++) { + for (length_t j = 0; j < i; j++) + { q[i] -= dot(q[i], q[j])*q[j]; r[j][i] = 0; } @@ -46,14 +53,16 @@ namespace glm { //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++) { + 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<(C < R ? C : R), R, T, P>& r, matType& q, const matType& in) { + 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. From 566d20e8cfc17755f35f76335d29940719f16cec Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 09:58:34 +0430 Subject: [PATCH 13/30] Fixed GTX_matrix_factorisation tests to return the number of errors #654 --- glm/gtx/matrix_factorisation.inl | 2 +- test/gtx/gtx_matrix_factorisation.cpp | 96 +++++++++++++-------------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index be7d6c8c..7f2418c0 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -73,7 +73,7 @@ namespace glm matType tr; matType<(C < R ? C : R), C, T, P> tq; - qr_decompose(tq, tr, tin); + qr_decompose(tin, tq, tr); tr = fliplr(tr); r = transpose(tr); diff --git a/test/gtx/gtx_matrix_factorisation.cpp b/test/gtx/gtx_matrix_factorisation.cpp index 7d32078f..40e56e4b 100644 --- a/test/gtx/gtx_matrix_factorisation.cpp +++ b/test/gtx/gtx_matrix_factorisation.cpp @@ -1,103 +1,101 @@ #define GLM_ENABLE_EXPERIMENTAL #include -const double epsilon = 1e-10f; +float const epsilon = 1e-10f; template class matType> -int test_qr(matType m) { +int test_qr(matType m) +{ + int Error = 0; + matType<(C < R ? C : R), R, T, P> q(-999); matType r(-999); - glm::qr_decompose(q, r, m); + 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++) { - if (std::abs(err[i][j]) > epsilon) return 1; - } - } + 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++) { - if ((length(q[i]) - 1) > epsilon) return 2; + 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) return 3; - } + 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++) { - if (r[i][j] != 0) return 4; - } - } + 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 0; + return Error; } template class matType> -int test_rq(matType m) { +int test_rq(matType m) +{ + int Error = 0; + matType q(-999); matType<(C < R ? C : R), R, T, P> r(-999); - glm::rq_decompose(r, q, m); + 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++) { - if (std::abs(err[i][j]) > epsilon) return 1; - } - } - - + + 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++) { - if ((length(tq[i]) - 1) > epsilon) return 2; + 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) return 3; - } + 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++) { - if (r[i][j] != 0) return 4; - } - } + 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 0; + return Error; } int main() { - + int Error = 0; + //Test QR square - if(test_qr(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 1; + Error += test_qr(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41)) ? 1 : 0; //Test RQ square - if (test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41))) return 2; + Error += test_rq(glm::dmat3(12, 6, -4, -51, 167, 24, 4, -68, -41)) ? 1 : 0; //Test QR triangular 1 - if (test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 3; + Error += test_qr(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; //Test QR triangular 2 - if (test_qr(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 4; + 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 - if (test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 5; + Error += test_rq(glm::dmat3x4(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; //Test QR triangular 2 - if (test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15))) return 6; + Error += test_rq(glm::dmat4x3(12, 6, -4, -51, 167, 24, 4, -68, -41, 7, 2, 15)) ? 1 : 0; - return 0; + return Error; } From 759a1d8ef2a3f9d204c1d0f56dbe25bc0330be5f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 10:01:20 +0430 Subject: [PATCH 14/30] Added GTX_matrix_factorisation to factor matrices in various forms #654 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index f50970e5..f5181bc6 100644 --- a/readme.md +++ b/readme.md @@ -57,6 +57,7 @@ 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 From 27f8e5b0a161b49f06ff259ca783dabd7a9498fd Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 11:20:40 +0430 Subject: [PATCH 15/30] Slight optimization by avoiding an unnecessary initialization #654 --- glm/gtx/matrix_factorisation.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/matrix_factorisation.inl b/glm/gtx/matrix_factorisation.inl index 7f2418c0..90fb7857 100644 --- a/glm/gtx/matrix_factorisation.inl +++ b/glm/gtx/matrix_factorisation.inl @@ -16,7 +16,7 @@ namespace glm template class matType> GLM_FUNC_QUALIFIER matType fliplr(matType const& in) { - matType out; + matType out(uninitialize); for (length_t i = 0; i < C; i++) { out[i] = in[(C - i) - 1]; From 1ad55c5016339b83b7eec98c31007e0aee57d2bf Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Jul 2017 11:26:12 +0430 Subject: [PATCH 16/30] Reduced warnings when using very strict compilation flags #646 --- CMakeLists.txt | 2 +- glm/detail/func_common.inl | 40 ++++++++++++++++++++++++++++---- glm/detail/func_common_simd.inl | 2 +- glm/detail/func_integer.inl | 12 +++++----- glm/detail/func_integer_simd.inl | 8 +++---- glm/detail/func_matrix_simd.inl | 10 ++++---- glm/detail/type_half.inl | 12 +++++----- readme.md | 3 ++- 8 files changed, 61 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5c87550..f0f99dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ include(CMakePackageConfigHelpers) enable_testing() -add_definitions(-D_CRT_SECURE_NO_WARNINGS) +add_definitions(-D_CRT_SECURE_NO_WARNINGS -g -Weverything -Wpedantic -Werror -Wno-padded -Wno-c++98-compat -Wno-documentation -std=c++11) option(GLM_STATIC_LIBRARY_ENABLE "GLM static library" OFF) if(GLM_STATIC_LIBRARY_ENABLE) 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/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/readme.md b/readme.md index f5181bc6..e2d75ca3 100644 --- a/readme.md +++ b/readme.md @@ -73,7 +73,8 @@ 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 #### Fixes: - Removed doxygen references to GTC_half_float which was removed in 0.9.4 From 7223cd1b47c4ba6328759a96d3dd135c1706fb3a Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:08:49 +0200 Subject: [PATCH 17/30] Add files via upload --- test/gtx/gtx_quaternion.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index a6daf715..398adaee 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -90,7 +90,24 @@ int test_log() return Error; } -int main() +int test_quatLookAt() +{ + 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 main1() { int Error = 0; @@ -98,6 +115,7 @@ int main() Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); + Error += test_quatLookAt(); return Error; } From 3ee83a15ef776cd9db9af29d3426bb9d7c39e6a2 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:09:21 +0200 Subject: [PATCH 18/30] Add files via upload --- glm/gtx/quaternion.hpp | 28 ++++++++++++++++++++++++++++ glm/gtx/quaternion.inl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index ad298dae..401f22c0 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, 0, 1). + 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, 0, 1). + 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, 0, 1). + 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 From 9a2176690603ea68d537d1737b44e6228a9003ca Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:10:31 +0200 Subject: [PATCH 19/30] Update gtx_quaternion.cpp --- test/gtx/gtx_quaternion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 398adaee..2ab6d21b 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -107,7 +107,7 @@ int test_quatLookAt() return Error; } -int main1() +int main() { int Error = 0; From 580f36836592866e78801c9f834ca50e40647050 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:16:49 +0200 Subject: [PATCH 20/30] Update quaternion.hpp --- glm/gtx/quaternion.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 401f22c0..801f0bc4 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -177,10 +177,10 @@ namespace glm vec<3, T, P> const & orig, vec<3, T, P> const & dest); - /// Build a look at quaternion based on the default handedness. + /// 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, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAt( tvec3 const & direction, @@ -189,7 +189,7 @@ namespace glm /// 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, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAtRH( tvec3 const & direction, @@ -199,7 +199,7 @@ namespace glm /// /// @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, 0, 1). + /// @param up Up vector, how the camera is oriented. Typically (0, 1, 0). template GLM_FUNC_DECL tquat quatLookAtLH( tvec3 const & direction, From df7f6cc03c5c2fe976c276097884549bd0c65622 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sat, 22 Jul 2017 17:20:45 +0200 Subject: [PATCH 21/30] Update gtx_quaternion.cpp --- test/gtx/gtx_quaternion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 2ab6d21b..e27981c4 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -90,7 +90,7 @@ int test_log() return Error; } -int test_quatLookAt() +int test_quat_lookAt() { int Error(0); @@ -115,7 +115,7 @@ int main() Error += test_rotation(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); - Error += test_quatLookAt(); + Error += test_quat_lookAt(); return Error; } From c184671583d55242ca29b585c4f980baa90108d1 Mon Sep 17 00:00:00 2001 From: CaptainCarrot Date: Sun, 23 Jul 2017 09:27:25 +0200 Subject: [PATCH 22/30] Update quaternion.hpp --- glm/gtx/quaternion.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 801f0bc4..cce10892 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -200,7 +200,7 @@ namespace glm /// @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 + template GLM_FUNC_DECL tquat quatLookAtLH( tvec3 const & direction, tvec3 const & up); From ad744735f66359b6aecdfe75e93c024f0c7ec055 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 11:10:20 +0200 Subject: [PATCH 23/30] Fixed build #660 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f99dc5..f5c87550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ include(CMakePackageConfigHelpers) enable_testing() -add_definitions(-D_CRT_SECURE_NO_WARNINGS -g -Weverything -Wpedantic -Werror -Wno-padded -Wno-c++98-compat -Wno-documentation -std=c++11) +add_definitions(-D_CRT_SECURE_NO_WARNINGS) option(GLM_STATIC_LIBRARY_ENABLE "GLM static library" OFF) if(GLM_STATIC_LIBRARY_ENABLE) From 50a527c97dd44db9f2579314b1f1aa1a3969b7bb Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 11:39:16 +0200 Subject: [PATCH 24/30] - Fixed integer pow from GTX_integer with null exponent #658 --- glm/gtx/integer.hpp | 2 +- glm/gtx/integer.inl | 8 ++++++-- readme.md | 1 + test/gtx/gtx_integer.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) 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/readme.md b/readme.md index e2d75ca3..5882061a 100644 --- a/readme.md +++ b/readme.md @@ -85,6 +85,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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 #### Deprecation: - Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler 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; } From 1b78e2b6815ca705e81204fb12c84d64fbad2da1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 12:01:44 +0200 Subject: [PATCH 25/30] length() member functions are constexpr #657 --- glm/detail/type_mat2x2.hpp | 16 ++++++++-------- glm/detail/type_mat2x3.hpp | 16 ++++++++-------- glm/detail/type_mat2x4.hpp | 16 ++++++++-------- glm/detail/type_mat3x2.hpp | 16 ++++++++-------- glm/detail/type_mat3x3.hpp | 16 ++++++++-------- glm/detail/type_mat3x4.hpp | 16 ++++++++-------- glm/detail/type_mat4x2.hpp | 16 ++++++++-------- glm/detail/type_mat4x3.hpp | 16 ++++++++-------- glm/detail/type_mat4x4.hpp | 2 +- glm/detail/type_vec1.hpp | 2 +- glm/detail/type_vec2.hpp | 2 +- glm/detail/type_vec3.hpp | 2 +- glm/detail/type_vec4.hpp | 2 +- glm/gtc/quaternion.hpp | 2 +- glm/gtx/dual_quaternion.hpp | 2 +- readme.md | 3 ++- 16 files changed, 73 insertions(+), 72 deletions(-) diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 4d86b72a..3ec4ed19 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -24,6 +24,14 @@ 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; @@ -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_mat2x3.hpp b/glm/detail/type_mat2x3.hpp index 01eb777a..bcaae3bd 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat2x4.hpp b/glm/detail/type_mat2x4.hpp index cfe61f4e..dc4d2087 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat3x2.hpp b/glm/detail/type_mat3x2.hpp index f738dc60..a488c970 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index 1a9f3365..6e7f70e4 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -24,6 +24,14 @@ 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; @@ -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_mat3x4.hpp b/glm/detail/type_mat3x4.hpp index 77d2143e..8437bc07 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat4x2.hpp b/glm/detail/type_mat4x2.hpp index feff316e..ab999dfe 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat4x3.hpp b/glm/detail/type_mat4x3.hpp index 2efa8699..c6ac5595 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -25,6 +25,14 @@ 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; @@ -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_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index e0d109ac..17063ac2 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -27,7 +27,7 @@ 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; diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index 8f877eda..e05ae88d 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -78,7 +78,7 @@ 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; diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 1eb81c92..bf6966e9 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -79,7 +79,7 @@ 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; diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index bd95530a..814c5a90 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -79,7 +79,7 @@ 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; diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 6ecb1602..141b20d7 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -82,7 +82,7 @@ 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; diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index edf07faa..b10873cd 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -70,7 +70,7 @@ 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; diff --git a/glm/gtx/dual_quaternion.hpp b/glm/gtx/dual_quaternion.hpp index 1fa23f57..d7a27c9e 100644 --- a/glm/gtx/dual_quaternion.hpp +++ b/glm/gtx/dual_quaternion.hpp @@ -49,7 +49,7 @@ 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; diff --git a/readme.md b/readme.md index 5882061a..c40bc99f 100644 --- a/readme.md +++ b/readme.md @@ -74,7 +74,8 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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 -- Reduced warnings when using very strict compilation flags #646 +- 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 From 55d6d2c35c26b018dcce25af9c1364eb655bb311 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 12:07:04 +0200 Subject: [PATCH 26/30] Udpated readme with Added quatLookAt to GTX_quaternion #659 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index c40bc99f..a0077dc0 100644 --- a/readme.md +++ b/readme.md @@ -61,6 +61,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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: - Added lowp variant of GTC_color_space convertLinearToSRGB #419 From 3c7bd2eb53e1ac3b0962eef164aa51ba370e6999 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 12:09:20 +0200 Subject: [PATCH 27/30] Fixed quat normalize build error #656 --- glm/gtc/quaternion.inl | 2 +- readme.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index dbdf504d..08c3cb88 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -380,7 +380,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/readme.md b/readme.md index a0077dc0..c87c00b7 100644 --- a/readme.md +++ b/readme.md @@ -88,6 +88,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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 #### Deprecation: - Requires Visual Studio 2013, GCC 4.7, Clang 3.4, Cuda 7, ICC 2013 or a C++11 compiler From c834d06c2739f63e28e5665d4569dca9415e3891 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 12:20:58 +0200 Subject: [PATCH 28/30] Fixed Visual C++ 2017.2 warning regarding __has_feature definision #655 --- glm/detail/setup.hpp | 4 ---- readme.md | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index c2ed8ade..e07fd90a 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -765,10 +765,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/readme.md b/readme.md index c87c00b7..48bf30cd 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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 From 4cf8a10af2bba678c2ad136006e6ec41118b6746 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 12:46:54 +0200 Subject: [PATCH 29/30] No more default initialization of vector, matrix and quaternion types --- glm/detail/setup.hpp | 6 ----- glm/detail/type_mat2x2.hpp | 2 +- glm/detail/type_mat2x2.inl | 9 ++----- glm/detail/type_mat2x3.hpp | 2 +- glm/detail/type_mat2x3.inl | 11 +++----- glm/detail/type_mat2x4.hpp | 2 +- glm/detail/type_mat2x4.inl | 9 ++----- glm/detail/type_mat3x2.hpp | 2 +- glm/detail/type_mat3x2.inl | 10 ++------ glm/detail/type_mat3x3.hpp | 2 +- glm/detail/type_mat3x3.inl | 10 ++------ glm/detail/type_mat3x4.hpp | 2 +- glm/detail/type_mat3x4.inl | 10 ++------ glm/detail/type_mat4x2.hpp | 2 +- glm/detail/type_mat4x2.inl | 11 ++------ glm/detail/type_mat4x3.hpp | 2 +- glm/detail/type_mat4x3.inl | 11 ++------ glm/detail/type_mat4x4.hpp | 2 +- glm/detail/type_mat4x4.inl | 11 ++------ glm/detail/type_vec1.hpp | 2 +- glm/detail/type_vec1.inl | 5 +--- glm/detail/type_vec2.hpp | 2 +- glm/detail/type_vec2.inl | 5 +--- glm/detail/type_vec3.hpp | 2 +- glm/detail/type_vec3.inl | 5 +--- glm/detail/type_vec4.hpp | 2 +- glm/detail/type_vec4.inl | 5 +--- glm/gtc/quaternion.hpp | 2 +- glm/gtc/quaternion.inl | 11 +++----- glm/gtx/dual_quaternion.hpp | 2 +- glm/gtx/dual_quaternion.inl | 6 +---- manual.md | 51 +++---------------------------------- readme.md | 1 + 33 files changed, 48 insertions(+), 169 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index e07fd90a..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 diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 3ec4ed19..2ad233d6 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -34,7 +34,7 @@ namespace glm // -- 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); 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 bcaae3bd..30ae1ac4 100644 --- a/glm/detail/type_mat2x3.hpp +++ b/glm/detail/type_mat2x3.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 dc4d2087..20c1a65b 100644 --- a/glm/detail/type_mat2x4.hpp +++ b/glm/detail/type_mat2x4.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 a488c970..0258d06d 100644 --- a/glm/detail/type_mat3x2.hpp +++ b/glm/detail/type_mat3x2.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 6e7f70e4..4e1d7e9f 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -34,7 +34,7 @@ namespace glm // -- 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); 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 8437bc07..6775ab2e 100644 --- a/glm/detail/type_mat3x4.hpp +++ b/glm/detail/type_mat3x4.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 ab999dfe..9f875183 100644 --- a/glm/detail/type_mat4x2.hpp +++ b/glm/detail/type_mat4x2.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 c6ac5595..e3926e3e 100644 --- a/glm/detail/type_mat4x3.hpp +++ b/glm/detail/type_mat4x3.hpp @@ -35,7 +35,7 @@ namespace glm // -- 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); 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 17063ac2..4b1d9d41 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -34,7 +34,7 @@ namespace glm // -- 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 e05ae88d..db047f51 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -85,7 +85,7 @@ namespace glm // -- 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 bf6966e9..c6ae942f 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -86,7 +86,7 @@ namespace glm // -- 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 814c5a90..81db2bf5 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -86,7 +86,7 @@ namespace glm // -- 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 141b20d7..95fb2fb1 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -89,7 +89,7 @@ namespace glm // -- 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/quaternion.hpp b/glm/gtc/quaternion.hpp index b10873cd..de8d2050 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -77,7 +77,7 @@ namespace glm // -- 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 08c3cb88..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)); diff --git a/glm/gtx/dual_quaternion.hpp b/glm/gtx/dual_quaternion.hpp index d7a27c9e..7c346794 100644 --- a/glm/gtx/dual_quaternion.hpp +++ b/glm/gtx/dual_quaternion.hpp @@ -56,7 +56,7 @@ namespace glm // -- 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/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 48bf30cd..84f02007 100644 --- a/readme.md +++ b/readme.md @@ -64,6 +64,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - 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 From 9443d8d9ca9d93e911a3108dac0ec6ea951925e5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 24 Jul 2017 13:17:00 +0200 Subject: [PATCH 30/30] Added length constexpr test #657 --- test/core/core_type_vec1.cpp | 5 +++++ test/core/core_type_vec2.cpp | 5 +++++ test/core/core_type_vec3.cpp | 5 +++++ test/core/core_type_vec4.cpp | 5 +++++ 4 files changed, 20 insertions(+) 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; }