diff options
Diffstat (limited to '3rdparty/glm/source/test/core')
56 files changed, 11584 insertions, 0 deletions
diff --git a/3rdparty/glm/source/test/core/CMakeLists.txt b/3rdparty/glm/source/test/core/CMakeLists.txt new file mode 100644 index 0000000..6cd57b1 --- /dev/null +++ b/3rdparty/glm/source/test/core/CMakeLists.txt @@ -0,0 +1,52 @@ +glmCreateTestGTC(core_cpp_constexpr) +glmCreateTestGTC(core_cpp_defaulted_ctor) +glmCreateTestGTC(core_force_aligned_gentypes) +glmCreateTestGTC(core_force_ctor_init) +glmCreateTestGTC(core_force_cxx03) +glmCreateTestGTC(core_force_cxx98) +glmCreateTestGTC(core_force_arch_unknown) +glmCreateTestGTC(core_force_compiler_unknown) +glmCreateTestGTC(core_force_cxx_unknown) +glmCreateTestGTC(core_force_explicit_ctor) +glmCreateTestGTC(core_force_inline) +glmCreateTestGTC(core_force_platform_unknown) +glmCreateTestGTC(core_force_pure) +glmCreateTestGTC(core_force_unrestricted_gentype) +glmCreateTestGTC(core_force_xyzw_only) +glmCreateTestGTC(core_force_quat_xyzw) +glmCreateTestGTC(core_type_aligned) +glmCreateTestGTC(core_type_cast) +glmCreateTestGTC(core_type_ctor) +glmCreateTestGTC(core_type_int) +glmCreateTestGTC(core_type_length) +glmCreateTestGTC(core_type_mat2x2) +glmCreateTestGTC(core_type_mat2x3) +glmCreateTestGTC(core_type_mat2x4) +glmCreateTestGTC(core_type_mat3x2) +glmCreateTestGTC(core_type_mat3x3) +glmCreateTestGTC(core_type_mat3x4) +glmCreateTestGTC(core_type_mat4x2) +glmCreateTestGTC(core_type_mat4x3) +glmCreateTestGTC(core_type_mat4x4) +glmCreateTestGTC(core_type_vec1) +glmCreateTestGTC(core_type_vec2) +glmCreateTestGTC(core_type_vec3) +glmCreateTestGTC(core_type_vec4) +glmCreateTestGTC(core_func_common) +glmCreateTestGTC(core_func_exponential) +glmCreateTestGTC(core_func_geometric) +glmCreateTestGTC(core_func_integer) +glmCreateTestGTC(core_func_integer_bit_count) +glmCreateTestGTC(core_func_integer_find_lsb) +glmCreateTestGTC(core_func_integer_find_msb) +glmCreateTestGTC(core_func_matrix) +glmCreateTestGTC(core_func_noise) +glmCreateTestGTC(core_func_packing) +glmCreateTestGTC(core_func_trigonometric) +glmCreateTestGTC(core_func_vector_relational) +glmCreateTestGTC(core_func_swizzle) +glmCreateTestGTC(core_setup_force_cxx98) +glmCreateTestGTC(core_setup_force_size_t_length) +glmCreateTestGTC(core_setup_message) +glmCreateTestGTC(core_setup_platform_unknown) +glmCreateTestGTC(core_setup_precision) diff --git a/3rdparty/glm/source/test/core/core_cpp_constexpr.cpp b/3rdparty/glm/source/test/core/core_cpp_constexpr.cpp new file mode 100644 index 0000000..3dc0a92 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_cpp_constexpr.cpp @@ -0,0 +1,750 @@ +#include <glm/glm.hpp> + +#if GLM_CONFIG_CONSTEXP == GLM_ENABLE + +#include <glm/gtc/constants.hpp> +#include <glm/gtc/quaternion.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/vector_int1.hpp> +#include <glm/ext/vector_bool1.hpp> +#include <glm/ext/vector_bool4.hpp> +#include <glm/ext/vector_float1.hpp> +#include <glm/vector_relational.hpp> + +static int test_vec1() +{ + int Error = 0; + + { + constexpr glm::bvec1 B(true); + constexpr bool A = glm::all(B); + static_assert(A, "GLM: Failed constexpr"); + + constexpr glm::bvec1 D(true); + constexpr bool C = glm::any(D); + static_assert(C, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec2 C(true); + constexpr glm::bvec2 B(true); + static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 O(glm::ivec1(1)); + static_assert(glm::ivec1(1) == O, "GLM: Failed constexpr"); + + constexpr glm::ivec1 P(1); + static_assert(glm::ivec1(1) == P, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 L(glm::ivec2(1, 2)); + static_assert(glm::ivec1(1) == L, "GLM: Failed constexpr"); + + constexpr glm::ivec1 M(glm::ivec3(1, 2, 3)); + static_assert(glm::ivec1(1) == M, "GLM: Failed constexpr"); + + constexpr glm::ivec1 N(glm::ivec4(1, 2, 3, 4)); + static_assert(glm::ivec1(1) == N, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); + static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec1 A1(true); + constexpr glm::bvec1 A2(true); + constexpr glm::bvec1 B1(false); + constexpr glm::bvec1 B2(false); + static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr"); + static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + constexpr glm::ivec1 B = A + 1; + constexpr glm::ivec1 C(3); + static_assert(A + B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D = +A; + static_assert(D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(3); + constexpr glm::ivec1 B = A - 1; + constexpr glm::ivec1 C(1); + static_assert(A - B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D = -A; + static_assert(-D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(3); + constexpr glm::ivec1 B = A * 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B * C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(3); + constexpr glm::ivec1 B = A / 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B / C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(3); + constexpr glm::ivec1 B = A % 2; + constexpr glm::ivec1 C(1); + static_assert(B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D(2); + static_assert(A % D == C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + constexpr glm::ivec1 B = A & 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A & C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + constexpr glm::ivec1 B = A | 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A | C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + constexpr glm::ivec1 B = A ^ 0; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(0); + static_assert(A == (A ^ C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(1); + constexpr glm::ivec1 B = A << 1; + static_assert(B == glm::ivec1(2), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == (A << C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(2); + constexpr glm::ivec1 B = A >> 1; + static_assert(B == glm::ivec1(1), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == A >> C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec1 A(~0); + constexpr glm::ivec1 B = ~A; + static_assert(A == ~B, "GLM: Failed constexpr"); + } + + return Error; +} + +static int test_vec2() +{ + int Error = 0; + + { + constexpr glm::bvec2 B(true); + constexpr bool A = glm::all(B); + static_assert(A, "GLM: Failed constexpr"); + + constexpr glm::bvec2 D(true, false); + constexpr bool C = glm::any(D); + static_assert(C, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec2 C(true); + constexpr glm::bvec2 B(true, false); + static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 O(glm::ivec1(1)); + static_assert(glm::ivec2(1) == O, "GLM: Failed constexpr"); + + constexpr glm::ivec2 A(1); + static_assert(glm::ivec2(1) == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 F(glm::ivec1(1), glm::ivec1(2)); + static_assert(glm::ivec2(1, 2) == F, "GLM: Failed constexpr"); + + constexpr glm::ivec2 G(1, glm::ivec1(2)); + static_assert(glm::ivec2(1, 2) == G, "GLM: Failed constexpr"); + + constexpr glm::ivec2 H(glm::ivec1(1), 2); + static_assert(glm::ivec2(1, 2) == H, "GLM: Failed constexpr"); + + constexpr glm::ivec2 I(1, 2); + static_assert(glm::ivec2(1, 2) == I, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 L(glm::ivec2(1, 2)); + static_assert(glm::ivec2(1, 2) == L, "GLM: Failed constexpr"); + + constexpr glm::ivec2 M(glm::ivec3(1, 2, 3)); + static_assert(glm::ivec2(1, 2) == M, "GLM: Failed constexpr"); + + constexpr glm::ivec2 N(glm::ivec4(1, 2, 3, 4)); + static_assert(glm::ivec2(1, 2) == N, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec2 A1(true); + constexpr glm::bvec2 A2(true); + constexpr glm::bvec2 B1(false); + constexpr glm::bvec2 B2(false); + static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr"); + static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A + 1; + constexpr glm::ivec2 C(3); + static_assert(A + B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec2 D = +A; + static_assert(D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(3); + constexpr glm::ivec2 B = A - 1; + constexpr glm::ivec2 C(1); + static_assert(A - B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec2 D = -A; + static_assert(-D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(3); + constexpr glm::ivec2 B = A * 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec2 C(1); + static_assert(B * C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(3); + constexpr glm::ivec2 B = A / 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec2 C(1); + static_assert(B / C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(3); + constexpr glm::ivec2 B = A % 2; + constexpr glm::ivec2 C(1); + static_assert(B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D(2); + static_assert(A % D == C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A & 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A & C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A | 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A | C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A ^ 0; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(0); + static_assert(A == (A ^ C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(1); + constexpr glm::ivec2 B = A << 1; + static_assert(B == glm::ivec2(2), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == (A << C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(2); + constexpr glm::ivec2 B = A >> 1; + static_assert(B == glm::ivec2(1), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == A >> C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec2 A(~0); + constexpr glm::ivec2 B = ~A; + static_assert(A == ~B, "GLM: Failed constexpr"); + } + + return Error; +} + +static int test_vec3() +{ + int Error = 0; + + { + constexpr glm::bvec3 B(true); + constexpr bool A = glm::all(B); + static_assert(A, "GLM: Failed constexpr"); + + constexpr glm::bvec3 D(true, false, true); + constexpr bool C = glm::any(D); + static_assert(C, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec3 C(true); + constexpr glm::bvec3 B(true, false, true); + static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 O(glm::ivec1(1)); + static_assert(glm::ivec3(1) == O, "GLM: Failed constexpr"); + + constexpr glm::ivec3 A(1); + static_assert(glm::ivec3(1) == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 B(glm::ivec2(1, 2), 3); + static_assert(glm::ivec3(1, 2, 3) == B, "GLM: Failed constexpr"); + + constexpr glm::ivec3 C(1, glm::ivec2(2, 3)); + static_assert(glm::ivec3(1, 2, 3) == C, "GLM: Failed constexpr"); + + constexpr glm::ivec3 D(glm::ivec1(1), glm::ivec2(2, 3)); + static_assert(glm::ivec3(1, 2, 3) == D, "GLM: Failed constexpr"); + + constexpr glm::ivec3 E(glm::ivec2(1, 2), glm::ivec1(3)); + static_assert(glm::ivec3(1, 2, 3) == E, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 F(glm::ivec1(1), glm::ivec1(2), glm::ivec1(3)); + static_assert(glm::ivec3(1, 2, 3) == F, "GLM: Failed constexpr"); + + constexpr glm::ivec3 G(1, glm::ivec1(2), glm::ivec1(3)); + static_assert(glm::ivec3(1, 2, 3) == G, "GLM: Failed constexpr"); + + constexpr glm::ivec3 H(glm::ivec1(1), 2, glm::ivec1(3)); + static_assert(glm::ivec3(1, 2, 3) == H, "GLM: Failed constexpr"); + + constexpr glm::ivec3 I(1, 2, glm::ivec1(3)); + static_assert(glm::ivec3(1, 2, 3) == I, "GLM: Failed constexpr"); + + constexpr glm::ivec3 J(glm::ivec1(1), glm::ivec1(2), 3); + static_assert(glm::ivec3(1, 2, 3) == J, "GLM: Failed constexpr"); + + constexpr glm::ivec3 K(1, glm::ivec1(2), 3); + static_assert(glm::ivec3(1, 2, 3) == K, "GLM: Failed constexpr"); + + constexpr glm::ivec3 L(glm::ivec1(1), 2, 3); + static_assert(glm::ivec3(1, 2, 3) == L, "GLM: Failed constexpr"); + + constexpr glm::ivec3 M(1, 2, 3); + static_assert(glm::ivec3(1, 2, 3) == M, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 N(glm::ivec4(1, 2, 3, 4)); + static_assert(glm::ivec3(1, 2, 3) == N, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 const A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec3 A1(true); + constexpr glm::bvec3 A2(true); + constexpr glm::bvec3 B1(false); + constexpr glm::bvec3 B2(false); + static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr"); + static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(1); + constexpr glm::ivec3 B = A + 1; + constexpr glm::ivec3 C(3); + static_assert(A + B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec3 D = +A; + static_assert(D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(3); + constexpr glm::ivec3 B = A - 1; + constexpr glm::ivec3 C(1); + static_assert(A - B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec3 D = -A; + static_assert(-D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(3); + constexpr glm::ivec3 B = A * 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec3 C(1); + static_assert(B * C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(3); + constexpr glm::ivec3 B = A / 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec3 C(1); + static_assert(B / C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(3); + constexpr glm::ivec3 B = A % 2; + constexpr glm::ivec3 C(1); + static_assert(B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D(2); + static_assert(A % D == C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(1); + constexpr glm::ivec3 B = A & 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A & C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(1); + constexpr glm::ivec3 B = A | 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A | C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(1); + constexpr glm::ivec3 B = A ^ 0; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(0); + static_assert(A == (A ^ C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(1); + constexpr glm::ivec3 B = A << 1; + static_assert(B == glm::ivec3(2), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == (A << C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(2); + constexpr glm::ivec3 B = A >> 1; + static_assert(B == glm::ivec3(1), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == A >> C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec3 A(~0); + constexpr glm::ivec3 B = ~A; + static_assert(A == ~B, "GLM: Failed constexpr"); + } + + return Error; +} + +static int test_vec4() +{ + int Error = 0; + + { + constexpr glm::bvec4 B(true); + constexpr bool A = glm::all(B); + static_assert(A, "GLM: Failed constexpr"); + + constexpr glm::bvec4 D(true, false, true, false); + constexpr bool C = glm::any(D); + static_assert(C, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec4 C(true); + constexpr glm::bvec4 B(true, false, true, false); + static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 O(glm::ivec4(1)); + static_assert(glm::ivec4(1) == O, "GLM: Failed constexpr"); + + constexpr glm::ivec4 A(1); + static_assert(glm::ivec4(1) == A, "GLM: Failed constexpr"); + + constexpr glm::ivec4 N(glm::ivec4(1, 2, 3, 4)); + static_assert(glm::ivec4(1, 2, 3, 4) == N, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(glm::ivec3(1, 2, 3), 4); + static_assert(glm::ivec4(1, 2, 3, 4) == A, "GLM: Failed constexpr"); + + constexpr glm::ivec4 B(glm::ivec2(1, 2), glm::ivec2(3, 4)); + static_assert(glm::ivec4(1, 2, 3, 4) == B, "GLM: Failed constexpr"); + + constexpr glm::ivec4 C(1, glm::ivec3(2, 3, 4)); + static_assert(glm::ivec4(1, 2, 3, 4) == C, "GLM: Failed constexpr"); + + constexpr glm::ivec4 D(glm::ivec1(1), glm::ivec2(2, 3), glm::ivec1(4)); + static_assert(glm::ivec4(1, 2, 3, 4) == D, "GLM: Failed constexpr"); + + constexpr glm::ivec4 E(glm::ivec2(1, 2), glm::ivec1(3), glm::ivec1(4)); + static_assert(glm::ivec4(1, 2, 3, 4) == E, "GLM: Failed constexpr"); + + constexpr glm::ivec4 F(glm::ivec1(1), glm::ivec1(2), glm::ivec2(3, 4)); + static_assert(glm::ivec4(1, 2, 3, 4) == F, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + static_assert(A[0] == 1, "GLM: Failed constexpr"); + static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr"); + static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr"); + static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr"); + static_assert(glm::ivec4::length() == 4, "GLM: Failed constexpr"); + } + + { + constexpr glm::bvec4 A1(true); + constexpr glm::bvec4 A2(true); + constexpr glm::bvec4 B1(false); + constexpr glm::bvec4 B2(false); + static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr"); + static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + constexpr glm::ivec4 B = A + 1; + constexpr glm::ivec4 C(3); + static_assert(A + B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec4 D = +A; + static_assert(D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(3); + constexpr glm::ivec4 B = A - 1; + constexpr glm::ivec4 C(1); + static_assert(A - B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec4 D = -A; + static_assert(-D == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(3); + constexpr glm::ivec4 B = A * 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec4 C(1); + static_assert(B * C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(3); + constexpr glm::ivec4 B = A / 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec4 C(1); + static_assert(B / C == A, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(3); + constexpr glm::ivec4 B = A % 2; + constexpr glm::ivec4 C(1); + static_assert(B == C, "GLM: Failed constexpr"); + + constexpr glm::ivec1 D(2); + static_assert(A % D == C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + constexpr glm::ivec4 B = A & 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A & C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + constexpr glm::ivec4 B = A | 1; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(A == (A | C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + constexpr glm::ivec4 B = A ^ 0; + static_assert(A == B, "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(0); + static_assert(A == (A ^ C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(1); + constexpr glm::ivec4 B = A << 1; + static_assert(B == glm::ivec4(2), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == (A << C), "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(2); + constexpr glm::ivec4 B = A >> 1; + static_assert(B == glm::ivec4(1), "GLM: Failed constexpr"); + + constexpr glm::ivec1 C(1); + static_assert(B == A >> C, "GLM: Failed constexpr"); + } + + { + constexpr glm::ivec4 A(~0); + constexpr glm::ivec4 B = ~A; + static_assert(A == ~B, "GLM: Failed constexpr"); + } + + return Error; +} + +static int test_quat() +{ + int Error = 0; + + { + static_assert(glm::quat::length() == 4, "GLM: Failed constexpr"); + static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::quat(1.0f, 0.0f, 0.0f, 0.0f).w > 0.0f, "GLM: Failed constexpr"); + + glm::quat constexpr Q = glm::identity<glm::quat>(); + static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr"); + } + + return Error; +} + +static int test_mat2x2() +{ + int Error = 0; + + static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr"); + + return Error; +} + +#endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE + +int main() +{ + int Error = 0; + +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + Error += test_vec1(); + Error += test_vec2(); + Error += test_vec3(); + Error += test_vec4(); + Error += test_quat(); + Error += test_mat2x2(); +# endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_cpp_defaulted_ctor.cpp b/3rdparty/glm/source/test/core/core_cpp_defaulted_ctor.cpp new file mode 100644 index 0000000..07afd9c --- /dev/null +++ b/3rdparty/glm/source/test/core/core_cpp_defaulted_ctor.cpp @@ -0,0 +1,145 @@ +#include <glm/glm.hpp> + +#if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + +#include <glm/gtc/constants.hpp> +#include <glm/gtc/quaternion.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <cstring> + +static int test_vec_memcpy() +{ + int Error = 0; + + { + glm::ivec1 const A = glm::ivec1(76); + glm::ivec1 B; + std::memcpy(&B, &A, sizeof(glm::ivec1)); + Error += B == A ? 0 : 1; + } + + { + glm::ivec2 const A = glm::ivec2(76); + glm::ivec2 B; + std::memcpy(&B, &A, sizeof(glm::ivec2)); + Error += B == A ? 0 : 1; + } + + { + glm::ivec3 const A = glm::ivec3(76); + glm::ivec3 B; + std::memcpy(&B, &A, sizeof(glm::ivec3)); + Error += B == A ? 0 : 1; + } + + { + glm::ivec4 const A = glm::ivec4(76); + glm::ivec4 B; + std::memcpy(&B, &A, sizeof(glm::ivec4)); + Error += B == A ? 0 : 1; + } + + return Error; +} + +static int test_mat_memcpy() +{ + int Error = 0; + + { + glm::mat2x2 const A = glm::mat2x2(76); + glm::mat2x2 B; + std::memcpy(&B, &A, sizeof(glm::mat2x2)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat2x3 const A = glm::mat2x3(76); + glm::mat2x3 B; + std::memcpy(&B, &A, sizeof(glm::mat2x3)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat2x4 const A = glm::mat2x4(76); + glm::mat2x4 B; + std::memcpy(&B, &A, sizeof(glm::mat2x4)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat3x2 const A = glm::mat3x2(76); + glm::mat3x2 B; + std::memcpy(&B, &A, sizeof(glm::mat3x2)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat3x3 const A = glm::mat3x3(76); + glm::mat3x3 B; + std::memcpy(&B, &A, sizeof(glm::mat3x3)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat3x4 const A = glm::mat3x4(76); + glm::mat3x4 B; + std::memcpy(&B, &A, sizeof(glm::mat3x4)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat4x2 const A = glm::mat4x2(76); + glm::mat4x2 B; + std::memcpy(&B, &A, sizeof(glm::mat4x2)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat4x3 const A = glm::mat4x3(76); + glm::mat4x3 B; + std::memcpy(&B, &A, sizeof(glm::mat4x3)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::mat4x4 const A = glm::mat4x4(76); + glm::mat4x4 B; + std::memcpy(&B, &A, sizeof(glm::mat4x4)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +static int test_quat_memcpy() +{ + int Error = 0; + + { + glm::quat const A = glm::quat(1, 0, 0, 0); + glm::quat B; + std::memcpy(&B, &A, sizeof(glm::quat)); + Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +#endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + +int main() +{ + int Error = 0; + +# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + Error += test_vec_memcpy(); + Error += test_mat_memcpy(); + Error += test_quat_memcpy(); +# endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_aligned_gentypes.cpp b/3rdparty/glm/source/test/core/core_force_aligned_gentypes.cpp new file mode 100644 index 0000000..70713c4 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_aligned_gentypes.cpp @@ -0,0 +1,10 @@ +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_arch_unknown.cpp b/3rdparty/glm/source/test/core/core_force_arch_unknown.cpp new file mode 100644 index 0000000..45b51bf --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_arch_unknown.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_ARCH_UNKNOWN +# define GLM_FORCE_ARCH_UNKNOWN +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_compiler_unknown.cpp b/3rdparty/glm/source/test/core/core_force_compiler_unknown.cpp new file mode 100644 index 0000000..44d7fc3 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_compiler_unknown.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_COMPILER_UNKNOWN +# define GLM_FORCE_COMPILER_UNKNOWN +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_ctor_init.cpp b/3rdparty/glm/source/test/core/core_force_ctor_init.cpp new file mode 100644 index 0000000..298b7ed --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_ctor_init.cpp @@ -0,0 +1,139 @@ +#define GLM_FORCE_CTOR_INIT + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +static int test_vec() +{ + int Error = 0; + + glm::vec1 V1; + Error += glm::all(glm::equal(V1, glm::vec1(0), glm::epsilon<float>())) ? 0 : 1; + + glm::dvec1 U1; + Error += glm::all(glm::equal(U1, glm::dvec1(0), glm::epsilon<double>())) ? 0 : 1; + + glm::vec2 V2; + Error += glm::all(glm::equal(V2, glm::vec2(0, 0), glm::epsilon<float>())) ? 0 : 1; + + glm::dvec2 U2; + Error += glm::all(glm::equal(U2, glm::dvec2(0, 0), glm::epsilon<double>())) ? 0 : 1; + + glm::vec3 V3; + Error += glm::all(glm::equal(V3, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + + glm::dvec3 U3; + Error += glm::all(glm::equal(U3, glm::dvec3(0, 0, 0), glm::epsilon<double>())) ? 0 : 1; + + glm::vec4 V4; + Error += glm::all(glm::equal(V4, glm::vec4(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + + glm::dvec4 U4; + Error += glm::all(glm::equal(U4, glm::dvec4(0, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1; + + return Error; +} + +static int test_mat() +{ + int Error = 0; + + { + glm::mat2x2 F; + Error += glm::all(glm::equal(F, glm::mat2x2(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat2x2 D; + Error += glm::all(glm::equal(D, glm::dmat2x2(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat2x3 F; + Error += glm::all(glm::equal(F, glm::mat2x3(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat2x3 D; + Error += glm::all(glm::equal(D, glm::dmat2x3(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat2x4 F; + Error += glm::all(glm::equal(F, glm::mat2x4(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat2x4 D; + Error += glm::all(glm::equal(D, glm::dmat2x4(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat3x2 F; + Error += glm::all(glm::equal(F, glm::mat3x2(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat3x2 D; + Error += glm::all(glm::equal(D, glm::dmat3x2(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat3x3 F; + Error += glm::all(glm::equal(F, glm::mat3x3(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat3x3 D; + Error += glm::all(glm::equal(D, glm::dmat3x3(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat3x4 F; + Error += glm::all(glm::equal(F, glm::mat3x4(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat3x4 D; + Error += glm::all(glm::equal(D, glm::dmat3x4(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat4x2 F; + Error += glm::all(glm::equal(F, glm::mat4x2(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat4x2 D; + Error += glm::all(glm::equal(D, glm::dmat4x2(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat4x3 F; + Error += glm::all(glm::equal(F, glm::mat4x3(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat4x3 D; + Error += glm::all(glm::equal(D, glm::dmat4x3(1), glm::epsilon<double>())) ? 0 : 1; + } + + { + glm::mat4x4 F; + Error += glm::all(glm::equal(F, glm::mat4x4(1), glm::epsilon<float>())) ? 0 : 1; + + glm::dmat4x4 D; + Error += glm::all(glm::equal(D, glm::dmat4x4(1), glm::epsilon<double>())) ? 0 : 1; + } + + return Error; +} + +static int test_qua() +{ + int Error = 0; + + glm::quat F; + Error += glm::all(glm::equal(F, glm::quat(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + + glm::dquat D; + Error += glm::all(glm::equal(D, glm::dquat(1, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_vec(); + Error += test_mat(); + Error += test_qua(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_cxx03.cpp b/3rdparty/glm/source/test/core/core_force_cxx03.cpp new file mode 100644 index 0000000..fc6e9c5 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_cxx03.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_CXX03 +# define GLM_FORCE_CXX03 +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_cxx98.cpp b/3rdparty/glm/source/test/core/core_force_cxx98.cpp new file mode 100644 index 0000000..42a5c25 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_cxx98.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_CXX98 +# define GLM_FORCE_CXX98 +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_cxx_unknown.cpp b/3rdparty/glm/source/test/core/core_force_cxx_unknown.cpp new file mode 100644 index 0000000..62299d6 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_cxx_unknown.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_CXX_UNKNOWN +# define GLM_FORCE_CXX_UNKNOWN +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_depth_zero_to_one.cpp b/3rdparty/glm/source/test/core/core_force_depth_zero_to_one.cpp new file mode 100644 index 0000000..23b3615 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_depth_zero_to_one.cpp @@ -0,0 +1,12 @@ +#define GLM_FORCE_DEPTH_ZERO_TO_ONE + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_explicit_ctor.cpp b/3rdparty/glm/source/test/core/core_force_explicit_ctor.cpp new file mode 100644 index 0000000..7af5b79 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_explicit_ctor.cpp @@ -0,0 +1,17 @@ +#define GLM_FORCE_EXPLICIT_CTOR + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + glm::ivec4 B(1); + Error += B == glm::ivec4(1) ? 0 : 1; + + //glm::vec4 A = B; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_inline.cpp b/3rdparty/glm/source/test/core/core_force_inline.cpp new file mode 100644 index 0000000..cd23fd9 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_inline.cpp @@ -0,0 +1,12 @@ +#define GLM_FORCE_INLINE + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_left_handed.cpp b/3rdparty/glm/source/test/core/core_force_left_handed.cpp new file mode 100644 index 0000000..b7ec31b --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_left_handed.cpp @@ -0,0 +1,12 @@ +#define GLM_FORCE_LEFT_HANDED + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_platform_unknown.cpp b/3rdparty/glm/source/test/core/core_force_platform_unknown.cpp new file mode 100644 index 0000000..fb7fa75 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_platform_unknown.cpp @@ -0,0 +1,14 @@ +#ifndef GLM_FORCE_PLATFORM_UNKNOWN +# define GLM_FORCE_PLATFORM_UNKNOWN +#endif + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_pure.cpp b/3rdparty/glm/source/test/core/core_force_pure.cpp new file mode 100644 index 0000000..a32a4ed --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_pure.cpp @@ -0,0 +1,434 @@ +#ifndef GLM_FORCE_PURE +# define GLM_FORCE_PURE +#endif//GLM_FORCE_PURE +#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES +#define GLM_FORCE_SWIZZLE +#include <glm/ext/vector_relational.hpp> +#include <glm/vector_relational.hpp> +#include <glm/vec2.hpp> +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> +#include <ctime> +#include <vector> + +static int test_vec4_ctor() +{ + int Error = 0; + + { + glm::ivec4 A(1, 2, 3, 4); + glm::ivec4 B(A); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + } + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1; + + Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1; +# endif + +#if GLM_HAS_INITIALIZER_LISTS + { + glm::vec4 a{ 0, 1, 2, 3 }; + std::vector<glm::vec4> v = { + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 0, 1}}; + } + + { + glm::dvec4 a{ 0, 1, 2, 3 }; + std::vector<glm::dvec4> v = { + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 0, 1}}; + } +#endif + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A.xyzw; + glm::ivec4 C(A.xyzw); + glm::ivec4 D(A.xyzw()); + glm::ivec4 E(A.x, A.yzw); + glm::ivec4 F(A.x, A.yzw()); + glm::ivec4 G(A.xyz, A.w); + glm::ivec4 H(A.xyz(), A.w); + glm::ivec4 I(A.xy, A.zw); + glm::ivec4 J(A.xy(), A.zw()); + glm::ivec4 K(A.x, A.y, A.zw); + glm::ivec4 L(A.x, A.yz, A.w); + glm::ivec4 M(A.xy, A.z, A.w); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + Error += glm::all(glm::equal(A, E)) ? 0 : 1; + Error += glm::all(glm::equal(A, F)) ? 0 : 1; + Error += glm::all(glm::equal(A, G)) ? 0 : 1; + Error += glm::all(glm::equal(A, H)) ? 0 : 1; + Error += glm::all(glm::equal(A, I)) ? 0 : 1; + Error += glm::all(glm::equal(A, J)) ? 0 : 1; + Error += glm::all(glm::equal(A, K)) ? 0 : 1; + Error += glm::all(glm::equal(A, L)) ? 0 : 1; + Error += glm::all(glm::equal(A, M)) ? 0 : 1; + } +# endif + +# if GLM_CONFIG_SWIZZLE + { + glm::ivec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A.xyzw(); + glm::ivec4 C(A.xyzw()); + glm::ivec4 D(A.xyzw()); + glm::ivec4 E(A.x, A.yzw()); + glm::ivec4 F(A.x, A.yzw()); + glm::ivec4 G(A.xyz(), A.w); + glm::ivec4 H(A.xyz(), A.w); + glm::ivec4 I(A.xy(), A.zw()); + glm::ivec4 J(A.xy(), A.zw()); + glm::ivec4 K(A.x, A.y, A.zw()); + glm::ivec4 L(A.x, A.yz(), A.w); + glm::ivec4 M(A.xy(), A.z, A.w); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + Error += glm::all(glm::equal(A, E)) ? 0 : 1; + Error += glm::all(glm::equal(A, F)) ? 0 : 1; + Error += glm::all(glm::equal(A, G)) ? 0 : 1; + Error += glm::all(glm::equal(A, H)) ? 0 : 1; + Error += glm::all(glm::equal(A, I)) ? 0 : 1; + Error += glm::all(glm::equal(A, J)) ? 0 : 1; + Error += glm::all(glm::equal(A, K)) ? 0 : 1; + Error += glm::all(glm::equal(A, L)) ? 0 : 1; + Error += glm::all(glm::equal(A, M)) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE + + { + glm::ivec4 A(1); + glm::ivec4 B(1, 1, 1, 1); + + Error += A == B ? 0 : 1; + } + + { + std::vector<glm::ivec4> Tests; + Tests.push_back(glm::ivec4(glm::ivec2(1, 2), 3, 4)); + Tests.push_back(glm::ivec4(1, glm::ivec2(2, 3), 4)); + Tests.push_back(glm::ivec4(1, 2, glm::ivec2(3, 4))); + Tests.push_back(glm::ivec4(glm::ivec3(1, 2, 3), 4)); + Tests.push_back(glm::ivec4(1, glm::ivec3(2, 3, 4))); + Tests.push_back(glm::ivec4(glm::ivec2(1, 2), glm::ivec2(3, 4))); + Tests.push_back(glm::ivec4(1, 2, 3, 4)); + Tests.push_back(glm::ivec4(glm::ivec4(1, 2, 3, 4))); + + for(std::size_t i = 0; i < Tests.size(); ++i) + Error += Tests[i] == glm::ivec4(1, 2, 3, 4) ? 0 : 1; + } + + return Error; +} + +static int test_bvec4_ctor() +{ + int Error = 0; + + glm::bvec4 const A(true); + glm::bvec4 const B(true); + glm::bvec4 const C(false); + glm::bvec4 const D = A && B; + glm::bvec4 const E = A && C; + glm::bvec4 const F = A || C; + + Error += D == glm::bvec4(true) ? 0 : 1; + Error += E == glm::bvec4(false) ? 0 : 1; + Error += F == glm::bvec4(true) ? 0 : 1; + + bool const G = A == C; + bool const H = A != C; + + Error += !G ? 0 : 1; + Error += H ? 0 : 1; + + return Error; +} + +static int test_vec4_operators() +{ + int Error = 0; + + { + glm::ivec4 A(1); + glm::ivec4 B(1); + bool R = A != B; + bool S = A == B; + + Error += (S && !R) ? 0 : 1; + } + + { + glm::vec4 const A(1.0f, 2.0f, 3.0f, 4.0f); + glm::vec4 const B(4.0f, 5.0f, 6.0f, 7.0f); + + glm::vec4 const C = A + B; + Error += glm::all(glm::equal(C, glm::vec4(5, 7, 9, 11), 0.001f)) ? 0 : 1; + + glm::vec4 D = B - A; + Error += glm::all(glm::equal(D, glm::vec4(3, 3, 3, 3), 0.001f)) ? 0 : 1; + + glm::vec4 E = A * B; + Error += glm::all(glm::equal(E, glm::vec4(4, 10, 18, 28), 0.001f)) ? 0 : 1; + + glm::vec4 F = B / A; + Error += glm::all(glm::equal(F, glm::vec4(4, 2.5, 2, 7.0f / 4.0f), 0.001f)) ? 0 : 1; + + glm::vec4 G = A + 1.0f; + Error += glm::all(glm::equal(G, glm::vec4(2, 3, 4, 5), 0.001f)) ? 0 : 1; + + glm::vec4 H = B - 1.0f; + Error += glm::all(glm::equal(H, glm::vec4(3, 4, 5, 6), 0.001f)) ? 0 : 1; + + glm::vec4 I = A * 2.0f; + Error += glm::all(glm::equal(I, glm::vec4(2, 4, 6, 8), 0.001f)) ? 0 : 1; + + glm::vec4 J = B / 2.0f; + Error += glm::all(glm::equal(J, glm::vec4(2, 2.5, 3, 3.5), 0.001f)) ? 0 : 1; + + glm::vec4 K = 1.0f + A; + Error += glm::all(glm::equal(K, glm::vec4(2, 3, 4, 5), 0.001f)) ? 0 : 1; + + glm::vec4 L = 1.0f - B; + Error += glm::all(glm::equal(L, glm::vec4(-3, -4, -5, -6), 0.001f)) ? 0 : 1; + + glm::vec4 M = 2.0f * A; + Error += glm::all(glm::equal(M, glm::vec4(2, 4, 6, 8), 0.001f)) ? 0 : 1; + + glm::vec4 const N = 2.0f / B; + Error += glm::all(glm::equal(N, glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0), 0.0001f)) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + A += B; + Error += A == glm::ivec4(5, 7, 9, 11) ? 0 : 1; + + A += 1; + Error += A == glm::ivec4(6, 8, 10, 12) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + B -= A; + Error += B == glm::ivec4(3, 3, 3, 3) ? 0 : 1; + + B -= 1; + Error += B == glm::ivec4(2, 2, 2, 2) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + A *= B; + Error += A == glm::ivec4(4, 10, 18, 28) ? 0 : 1; + + A *= 2; + Error += A == glm::ivec4(8, 20, 36, 56) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 4.0f, 6.0f, 8.0f); + + B /= A; + Error += B == glm::ivec4(4, 2, 2, 2) ? 0 : 1; + + B /= 2; + Error += B == glm::ivec4(2, 1, 1, 1) ? 0 : 1; + } + { + glm::ivec4 B(2); + + B /= B.y; + Error += B == glm::ivec4(1) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = -A; + Error += B == glm::ivec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = --A; + Error += B == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A--; + Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1; + Error += A == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = ++A; + Error += B == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A++; + Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1; + Error += A == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1; + } + + return Error; +} + +static int test_vec4_equal() +{ + int Error = 0; + + { + glm::uvec4 const A(1, 2, 3, 4); + glm::uvec4 const B(1, 2, 3, 4); + Error += A == B ? 0 : 1; + Error += A != B ? 1 : 0; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + glm::ivec4 const B(1, 2, 3, 4); + Error += A == B ? 0 : 1; + Error += A != B ? 1 : 0; + } + + return Error; +} + +static int test_vec4_size() +{ + int Error = 0; + + Error += sizeof(glm::vec4) == sizeof(glm::lowp_vec4) ? 0 : 1; + Error += sizeof(glm::vec4) == sizeof(glm::mediump_vec4) ? 0 : 1; + Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1; + Error += 16 == sizeof(glm::mediump_vec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::lowp_dvec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::mediump_dvec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1; + Error += 32 == sizeof(glm::highp_dvec4) ? 0 : 1; + Error += glm::vec4().length() == 4 ? 0 : 1; + Error += glm::dvec4().length() == 4 ? 0 : 1; + + return Error; +} + +static int test_vec4_swizzle_partial() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + + glm::ivec4 A(1, 2, 3, 4); + + { + glm::ivec4 B(A.xy, A.zw); + Error += A == B ? 0 : 1; + } + { + glm::ivec4 B(A.xy, 3, 4); + Error += A == B ? 0 : 1; + } + { + glm::ivec4 B(1, A.yz, 4); + Error += A == B ? 0 : 1; + } + { + glm::ivec4 B(1, 2, A.zw); + Error += A == B ? 0 : 1; + } + + { + glm::ivec4 B(A.xyz, 4); + Error += A == B ? 0 : 1; + } + { + glm::ivec4 B(1, A.yzw); + Error += A == B ? 0 : 1; + } +# endif + + return Error; +} + +static int test_operator_increment() +{ + int Error(0); + + glm::ivec4 v0(1); + glm::ivec4 v1(v0); + glm::ivec4 v2(v0); + glm::ivec4 v3 = ++v1; + glm::ivec4 v4 = v2++; + + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; + + int i0(1); + int i1(i0); + int i2(i0); + int i3 = ++i1; + int i4 = i2++; + + Error += i0 == i4 ? 0 : 1; + Error += i1 == i2 ? 0 : 1; + Error += i1 == i3 ? 0 : 1; + + return Error; +} + +static int test_vec4_simd() +{ + int Error = 0; + + glm::vec4 const a(std::clock(), std::clock(), std::clock(), std::clock()); + glm::vec4 const b(std::clock(), std::clock(), std::clock(), std::clock()); + + glm::vec4 const c(b * a); + glm::vec4 const d(a + c); + + Error += glm::all(glm::greaterThanEqual(d, glm::vec4(0))) ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_vec4_ctor(); + Error += test_bvec4_ctor(); + Error += test_vec4_size(); + Error += test_vec4_operators(); + Error += test_vec4_equal(); + Error += test_vec4_swizzle_partial(); + Error += test_vec4_simd(); + Error += test_operator_increment(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_quat_xyzw.cpp b/3rdparty/glm/source/test/core/core_force_quat_xyzw.cpp new file mode 100644 index 0000000..7d5281c --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_quat_xyzw.cpp @@ -0,0 +1,13 @@ +#define GLM_FORCE_QUAT_DATA_XYZW +#define GLM_FORCE_INLINE + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_size_t_length.cpp b/3rdparty/glm/source/test/core/core_force_size_t_length.cpp new file mode 100644 index 0000000..19dac89 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_size_t_length.cpp @@ -0,0 +1,12 @@ +#define GLM_FORCE_SIZE_T_LENGTH + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_unrestricted_gentype.cpp b/3rdparty/glm/source/test/core/core_force_unrestricted_gentype.cpp new file mode 100644 index 0000000..21d6e52 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_unrestricted_gentype.cpp @@ -0,0 +1,12 @@ +#define GLM_FORCE_UNRESTRICTED_GENTYPE + +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_force_xyzw_only.cpp b/3rdparty/glm/source/test/core/core_force_xyzw_only.cpp new file mode 100644 index 0000000..d19509d --- /dev/null +++ b/3rdparty/glm/source/test/core/core_force_xyzw_only.cpp @@ -0,0 +1,58 @@ +#define GLM_FORCE_XYZW_ONLY + +#include <glm/gtc/constants.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/vec2.hpp> +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> + +static int test_comp() +{ + int Error = 0; + + { + glm::ivec1 const A(1); + Error += A.x == 1 ? 0 : 1; + } + + { + glm::ivec2 const A(1, 2); + Error += A.x == 1 ? 0 : 1; + Error += A.y == 2 ? 0 : 1; + } + + { + glm::ivec3 const A(1, 2, 3); + Error += A.x == 1 ? 0 : 1; + Error += A.y == 2 ? 0 : 1; + Error += A.z == 3 ? 0 : 1; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + Error += A.x == 1 ? 0 : 1; + Error += A.y == 2 ? 0 : 1; + Error += A.z == 3 ? 0 : 1; + Error += A.w == 4 ? 0 : 1; + } + + return Error; +} + +static int test_constexpr() +{ + int Error = 0; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_comp(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_func_common.cpp b/3rdparty/glm/source/test/core/core_func_common.cpp new file mode 100644 index 0000000..b8640de --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_common.cpp @@ -0,0 +1,1349 @@ +#define GLM_FORCE_EXPLICIT_CTOR +#include <glm/gtc/constants.hpp> +#include <glm/gtc/random.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/vector_float1.hpp> +#include <glm/common.hpp> +#include <glm/vec4.hpp> +#include <glm/vec3.hpp> +#include <glm/vec2.hpp> +#include <vector> +#include <cstdio> +#include <cmath> +#include <ctime> + +// This file has divisions by zero to test isnan +#if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(disable : 4723) +#endif + +namespace floor_ +{ + static int test() + { + int Error = 0; + + { + float A = 1.1f; + float B = glm::floor(A); + Error += glm::equal(B, 1.f, 0.0001f) ? 0 : 1; + } + + { + double A = 1.1; + double B = glm::floor(A); + Error += glm::equal(B, 1.0, 0.0001) ? 0 : 1; + } + + { + glm::vec1 A(1.1f); + glm::vec1 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::vec1(1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec1 A(1.1); + glm::dvec1 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::dvec1(1.0), 0.0001)) ? 0 : 1; + } + + { + glm::vec2 A(1.1f); + glm::vec2 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::vec2(1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec2 A(1.1); + glm::dvec2 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::dvec2(1.0), 0.0001)) ? 0 : 1; + } + + { + glm::vec3 A(1.1f); + glm::vec3 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::vec3(1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec3 A(1.1); + glm::dvec3 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::dvec3(1.0), 0.0001)) ? 0 : 1; + } + + { + glm::vec4 A(1.1f); + glm::vec4 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::vec4(1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec4 A(1.1); + glm::dvec4 B = glm::floor(A); + + Error += glm::all(glm::equal(B, glm::dvec4(1.0), 0.0001)) ? 0 : 1; + } + + return Error; + } +}//namespace floor + +namespace modf_ +{ + static int test() + { + int Error(0); + + { + float X(1.5f); + float I(0.0f); + float A = glm::modf(X, I); + + Error += glm::equal(I, 1.0f, 0.0001f) ? 0 : 1; + Error += glm::equal(A, 0.5f, 0.0001f) ? 0 : 1; + } + + { + glm::vec4 X(1.1f, 1.2f, 1.5f, 1.7f); + glm::vec4 I(0.0f); + glm::vec4 A = glm::modf(X, I); + + Error += glm::ivec4(I) == glm::ivec4(1) ? 0 : 1; + Error += glm::all(glm::equal(A, glm::vec4(0.1f, 0.2f, 0.5f, 0.7f), 0.00001f)) ? 0 : 1; + } + + { + glm::dvec4 X(1.1, 1.2, 1.5, 1.7); + glm::dvec4 I(0.0); + glm::dvec4 A = glm::modf(X, I); + + Error += glm::ivec4(I) == glm::ivec4(1) ? 0 : 1; + Error += glm::all(glm::equal(A, glm::dvec4(0.1, 0.2, 0.5, 0.7), 0.000000001)) ? 0 : 1; + } + + { + double X(1.5); + double I(0.0); + double A = glm::modf(X, I); + + Error += glm::equal(I, 1.0, 0.0001) ? 0 : 1; + Error += glm::equal(A, 0.5, 0.0001) ? 0 : 1; + } + + return Error; + } +}//namespace modf + +namespace mod_ +{ + static int test() + { + int Error(0); + + { + float A(1.5f); + float B(1.0f); + float C = glm::mod(A, B); + + Error += glm::equal(C, 0.5f, 0.00001f) ? 0 : 1; + } + + { + float A(-0.2f); + float B(1.0f); + float C = glm::mod(A, B); + + Error += glm::equal(C, 0.8f, 0.00001f) ? 0 : 1; + } + + { + float A(3.0); + float B(2.0f); + float C = glm::mod(A, B); + + Error += glm::equal(C, 1.0f, 0.00001f) ? 0 : 1; + } + + { + glm::vec4 A(3.0); + float B(2.0f); + glm::vec4 C = glm::mod(A, B); + + Error += glm::all(glm::equal(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1; + } + + { + glm::vec4 A(3.0); + glm::vec4 B(2.0f); + glm::vec4 C = glm::mod(A, B); + + Error += glm::all(glm::equal(C, glm::vec4(1.0f), 0.00001f)) ? 0 : 1; + } + + return Error; + } +}//namespace mod_ + +namespace floatBitsToInt +{ + static int test() + { + int Error = 0; + + { + float A = 1.0f; + int B = glm::floatBitsToInt(A); + float C = glm::intBitsToFloat(B); + Error += glm::equal(A, C, 0.0001f) ? 0 : 1; + } + + { + glm::vec2 A(1.0f, 2.0f); + glm::ivec2 B = glm::floatBitsToInt(A); + glm::vec2 C = glm::intBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + { + glm::vec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = glm::floatBitsToInt(A); + glm::vec3 C = glm::intBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + { + glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = glm::floatBitsToInt(A); + glm::vec4 C = glm::intBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + return Error; + } +}//namespace floatBitsToInt + +namespace floatBitsToUint +{ + static int test() + { + int Error = 0; + + { + float A = 1.0f; + glm::uint B = glm::floatBitsToUint(A); + float C = glm::uintBitsToFloat(B); + Error += glm::equal(A, C, 0.0001f) ? 0 : 1; + } + + { + glm::vec2 A(1.0f, 2.0f); + glm::uvec2 B = glm::floatBitsToUint(A); + glm::vec2 C = glm::uintBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + { + glm::vec3 A(1.0f, 2.0f, 3.0f); + glm::uvec3 B = glm::floatBitsToUint(A); + glm::vec3 C = glm::uintBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + { + glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::uvec4 B = glm::floatBitsToUint(A); + glm::vec4 C = glm::uintBitsToFloat(B); + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } + + return Error; + } +}//namespace floatBitsToUint + +namespace min_ +{ + static int test() + { + int Error = 0; + + glm::vec1 A0 = glm::min(glm::vec1(1), glm::vec1(1)); + bool A1 = glm::all(glm::equal(A0, glm::vec1(1), glm::epsilon<float>())); + Error += A1 ? 0 : 1; + + glm::vec2 B0 = glm::min(glm::vec2(1), glm::vec2(1)); + glm::vec2 B1 = glm::min(glm::vec2(1), 1.0f); + bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>())); + Error += B2 ? 0 : 1; + + glm::vec3 C0 = glm::min(glm::vec3(1), glm::vec3(1)); + glm::vec3 C1 = glm::min(glm::vec3(1), 1.0f); + bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>())); + Error += C2 ? 0 : 1; + + glm::vec4 D0 = glm::min(glm::vec4(1), glm::vec4(1)); + glm::vec4 D1 = glm::min(glm::vec4(1), 1.0f); + bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>())); + Error += D2 ? 0 : 1; + + return Error; + } + + int min_tern(int a, int b) + { + return a < b ? a : b; + } + + int min_int(int x, int y) + { + return y ^ ((x ^ y) & -(x < y)); + } + + static int perf(std::size_t Count) + { + std::vector<int> A(Count); + std::vector<int> B(Count); + + std::size_t const InternalCount = 200000; + + for(std::size_t i = 0; i < Count; ++i) + { + A[i] = glm::linearRand(-1000, 1000); + B[i] = glm::linearRand(-1000, 1000); + } + + int Error = 0; + + glm::int32 SumA = 0; + { + std::clock_t Timestamp0 = std::clock(); + + for (std::size_t j = 0; j < InternalCount; ++j) + for (std::size_t i = 0; i < Count; ++i) + SumA += min_tern(A[i], B[i]); + + std::clock_t Timestamp1 = std::clock(); + + std::printf("min_tern Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0)); + } + + glm::int32 SumB = 0; + { + std::clock_t Timestamp0 = std::clock(); + + for (std::size_t j = 0; j < InternalCount; ++j) + for (std::size_t i = 0; i < Count; ++i) + SumB += min_int(A[i], B[i]); + + std::clock_t Timestamp1 = std::clock(); + + std::printf("min_int Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0)); + } + + Error += SumA == SumB ? 0 : 1; + + return Error; + } +}//namespace min_ + +namespace max_ +{ + static int test() + { + int Error = 0; + + glm::vec1 A0 = glm::max(glm::vec1(1), glm::vec1(1)); + bool A1 = glm::all(glm::equal(A0, glm::vec1(1), glm::epsilon<float>())); + Error += A1 ? 0 : 1; + + + glm::vec2 B0 = glm::max(glm::vec2(1), glm::vec2(1)); + glm::vec2 B1 = glm::max(glm::vec2(1), 1.0f); + bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>())); + Error += B2 ? 0 : 1; + + glm::vec3 C0 = glm::max(glm::vec3(1), glm::vec3(1)); + glm::vec3 C1 = glm::max(glm::vec3(1), 1.0f); + bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>())); + Error += C2 ? 0 : 1; + + glm::vec4 D0 = glm::max(glm::vec4(1), glm::vec4(1)); + glm::vec4 D1 = glm::max(glm::vec4(1), 1.0f); + bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>())); + Error += D2 ? 0 : 1; + + return Error; + } +}//namespace max_ + +namespace clamp_ +{ + static int test() + { + int Error = 0; + + return Error; + } +}//namespace clamp_ + +namespace mix_ +{ + template<typename T, typename B> + struct entry + { + T x; + T y; + B a; + T Result; + }; + + entry<float, bool> const TestBool[] = + { + {0.0f, 1.0f, false, 0.0f}, + {0.0f, 1.0f, true, 1.0f}, + {-1.0f, 1.0f, false, -1.0f}, + {-1.0f, 1.0f, true, 1.0f} + }; + + entry<float, float> const TestFloat[] = + { + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 1.0f, 1.0f}, + {-1.0f, 1.0f, 0.0f, -1.0f}, + {-1.0f, 1.0f, 1.0f, 1.0f} + }; + + entry<glm::vec2, bool> const TestVec2Bool[] = + { + {glm::vec2(0.0f), glm::vec2(1.0f), false, glm::vec2(0.0f)}, + {glm::vec2(0.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), false, glm::vec2(-1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), true, glm::vec2(1.0f)} + }; + + entry<glm::vec2, glm::bvec2> const TestBVec2[] = + { + {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(0.0f)}, + {glm::vec2(0.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(false), glm::vec2(-1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true), glm::vec2(1.0f)}, + {glm::vec2(-1.0f), glm::vec2(1.0f), glm::bvec2(true, false), glm::vec2(1.0f, -1.0f)} + }; + + entry<glm::vec3, bool> const TestVec3Bool[] = + { + {glm::vec3(0.0f), glm::vec3(1.0f), false, glm::vec3(0.0f)}, + {glm::vec3(0.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), false, glm::vec3(-1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), true, glm::vec3(1.0f)} + }; + + entry<glm::vec3, glm::bvec3> const TestBVec3[] = + { + {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(0.0f)}, + {glm::vec3(0.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(false), glm::vec3(-1.0f)}, + {glm::vec3(-1.0f), glm::vec3(1.0f), glm::bvec3(true), glm::vec3(1.0f)}, + {glm::vec3(1.0f, 2.0f, 3.0f), glm::vec3(4.0f, 5.0f, 6.0f), glm::bvec3(true, false, true), glm::vec3(4.0f, 2.0f, 6.0f)} + }; + + entry<glm::vec4, bool> const TestVec4Bool[] = + { + {glm::vec4(0.0f), glm::vec4(1.0f), false, glm::vec4(0.0f)}, + {glm::vec4(0.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), false, glm::vec4(-1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), true, glm::vec4(1.0f)} + }; + + entry<glm::vec4, glm::bvec4> const TestBVec4[] = + { + {glm::vec4(0.0f, 0.0f, 1.0f, 1.0f), glm::vec4(2.0f, 2.0f, 3.0f, 3.0f), glm::bvec4(false, true, false, true), glm::vec4(0.0f, 2.0f, 1.0f, 3.0f)}, + {glm::vec4(0.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(false), glm::vec4(-1.0f)}, + {glm::vec4(-1.0f), glm::vec4(1.0f), glm::bvec4(true), glm::vec4(1.0f)}, + {glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(5.0f, 6.0f, 7.0f, 8.0f), glm::bvec4(true, false, true, false), glm::vec4(5.0f, 2.0f, 7.0f, 4.0f)} + }; + + static int test() + { + int Error = 0; + + // Float with bool + { + for(std::size_t i = 0; i < sizeof(TestBool) / sizeof(entry<float, bool>); ++i) + { + float Result = glm::mix(TestBool[i].x, TestBool[i].y, TestBool[i].a); + Error += glm::equal(Result, TestBool[i].Result, glm::epsilon<float>()) ? 0 : 1; + } + } + + // Float with float + { + for(std::size_t i = 0; i < sizeof(TestFloat) / sizeof(entry<float, float>); ++i) + { + float Result = glm::mix(TestFloat[i].x, TestFloat[i].y, TestFloat[i].a); + Error += glm::equal(Result, TestFloat[i].Result, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec2 with bool + { + for(std::size_t i = 0; i < sizeof(TestVec2Bool) / sizeof(entry<glm::vec2, bool>); ++i) + { + glm::vec2 Result = glm::mix(TestVec2Bool[i].x, TestVec2Bool[i].y, TestVec2Bool[i].a); + Error += glm::equal(Result.x, TestVec2Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestVec2Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec2 with bvec2 + { + for(std::size_t i = 0; i < sizeof(TestBVec2) / sizeof(entry<glm::vec2, glm::bvec2>); ++i) + { + glm::vec2 Result = glm::mix(TestBVec2[i].x, TestBVec2[i].y, TestBVec2[i].a); + Error += glm::equal(Result.x, TestBVec2[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestBVec2[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec3 with bool + { + for(std::size_t i = 0; i < sizeof(TestVec3Bool) / sizeof(entry<glm::vec3, bool>); ++i) + { + glm::vec3 Result = glm::mix(TestVec3Bool[i].x, TestVec3Bool[i].y, TestVec3Bool[i].a); + Error += glm::equal(Result.x, TestVec3Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestVec3Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.z, TestVec3Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec3 with bvec3 + { + for(std::size_t i = 0; i < sizeof(TestBVec3) / sizeof(entry<glm::vec3, glm::bvec3>); ++i) + { + glm::vec3 Result = glm::mix(TestBVec3[i].x, TestBVec3[i].y, TestBVec3[i].a); + Error += glm::equal(Result.x, TestBVec3[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestBVec3[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.z, TestBVec3[i].Result.z, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec4 with bool + { + for(std::size_t i = 0; i < sizeof(TestVec4Bool) / sizeof(entry<glm::vec4, bool>); ++i) + { + glm::vec4 Result = glm::mix(TestVec4Bool[i].x, TestVec4Bool[i].y, TestVec4Bool[i].a); + Error += glm::equal(Result.x, TestVec4Bool[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestVec4Bool[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.z, TestVec4Bool[i].Result.z, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.w, TestVec4Bool[i].Result.w, glm::epsilon<float>()) ? 0 : 1; + } + } + + // vec4 with bvec4 + { + for(std::size_t i = 0; i < sizeof(TestBVec4) / sizeof(entry<glm::vec4, glm::bvec4>); ++i) + { + glm::vec4 Result = glm::mix(TestBVec4[i].x, TestBVec4[i].y, TestBVec4[i].a); + Error += glm::equal(Result.x, TestBVec4[i].Result.x, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.y, TestBVec4[i].Result.y, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.z, TestBVec4[i].Result.z, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(Result.w, TestBVec4[i].Result.w, glm::epsilon<float>()) ? 0 : 1; + } + } + + return Error; + } +}//namespace mix_ + +namespace step_ +{ + template<typename EDGE, typename VEC> + struct entry + { + EDGE edge; + VEC x; + VEC result; + }; + + entry<float, glm::vec4> TestVec4Scalar [] = + { + { 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, + { 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, + { 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) } + }; + + entry<glm::vec4, glm::vec4> TestVec4Vector [] = + { + { glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) }, + { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) }, + { glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) }, + { glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) } + }; + + static int test() + { + int Error = 0; + + // scalar + { + float const Edge = 2.0f; + + float const A = glm::step(Edge, 1.0f); + Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1; + + float const B = glm::step(Edge, 3.0f); + Error += glm::equal(B, 1.0f, glm::epsilon<float>()) ? 0 : 1; + + float const C = glm::step(Edge, 2.0f); + Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1; + } + + // vec4 and float + { + for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(entry<float, glm::vec4>); ++i) + { + glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x); + Error += glm::all(glm::equal(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1; + } + } + + // vec4 and vec4 + { + for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(entry<glm::vec4, glm::vec4>); ++i) + { + glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x); + Error += glm::all(glm::equal(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1; + } + } + + return Error; + } +}//namespace step_ + +namespace round_ +{ + static int test() + { + int Error = 0; + + { + float A = glm::round(0.0f); + Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::round(0.5f); + Error += glm::equal(B, 1.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::round(1.0f); + Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::round(0.1f); + Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::round(0.9f); + Error += glm::equal(E, 1.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::round(1.5f); + Error += glm::equal(F, 2.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::round(1.9f); + Error += glm::equal(G, 2.0f, glm::epsilon<float>()) ? 0 : 1; + } + + { + float A = glm::round(-0.0f); + Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::round(-0.5f); + Error += glm::equal(B, -1.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::round(-1.0f); + Error += glm::equal(C, -1.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::round(-0.1f); + Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::round(-0.9f); + Error += glm::equal(E, -1.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::round(-1.5f); + Error += glm::equal(F, -2.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::round(-1.9f); + Error += glm::equal(G, -2.0f, glm::epsilon<float>()) ? 0 : 1; + } + + return Error; + } +}//namespace round_ + +namespace roundEven +{ + static int test() + { + int Error = 0; + + { + float A1 = glm::roundEven(-1.5f); + Error += glm::equal(A1, -2.0f, 0.0001f) ? 0 : 1; + + float A2 = glm::roundEven(1.5f); + Error += glm::equal(A2, 2.0f, 0.0001f) ? 0 : 1; + + float A5 = glm::roundEven(-2.5f); + Error += glm::equal(A5, -2.0f, 0.0001f) ? 0 : 1; + + float A6 = glm::roundEven(2.5f); + Error += glm::equal(A6, 2.0f, 0.0001f) ? 0 : 1; + + float A3 = glm::roundEven(-3.5f); + Error += glm::equal(A3, -4.0f, 0.0001f) ? 0 : 1; + + float A4 = glm::roundEven(3.5f); + Error += glm::equal(A4, 4.0f, 0.0001f) ? 0 : 1; + + float C7 = glm::roundEven(-4.5f); + Error += glm::equal(C7, -4.0f, 0.0001f) ? 0 : 1; + + float C8 = glm::roundEven(4.5f); + Error += glm::equal(C8, 4.0f, 0.0001f) ? 0 : 1; + + float C1 = glm::roundEven(-5.5f); + Error += glm::equal(C1, -6.0f, 0.0001f) ? 0 : 1; + + float C2 = glm::roundEven(5.5f); + Error += glm::equal(C2, 6.0f, 0.0001f) ? 0 : 1; + + float C3 = glm::roundEven(-6.5f); + Error += glm::equal(C3, -6.0f, 0.0001f) ? 0 : 1; + + float C4 = glm::roundEven(6.5f); + Error += glm::equal(C4, 6.0f, 0.0001f) ? 0 : 1; + + float C5 = glm::roundEven(-7.5f); + Error += glm::equal(C5, -8.0f, 0.0001f) ? 0 : 1; + + float C6 = glm::roundEven(7.5f); + Error += glm::equal(C6, 8.0f, 0.0001f) ? 0 : 1; + + Error += 0; + } + + { + float A7 = glm::roundEven(-2.4f); + Error += glm::equal(A7, -2.0f, 0.0001f) ? 0 : 1; + + float A8 = glm::roundEven(2.4f); + Error += glm::equal(A8, 2.0f, 0.0001f) ? 0 : 1; + + float B1 = glm::roundEven(-2.6f); + Error += glm::equal(B1, -3.0f, 0.0001f) ? 0 : 1; + + float B2 = glm::roundEven(2.6f); + Error += glm::equal(B2, 3.0f, 0.0001f) ? 0 : 1; + + float B3 = glm::roundEven(-2.0f); + Error += glm::equal(B3, -2.0f, 0.0001f) ? 0 : 1; + + float B4 = glm::roundEven(2.0f); + Error += glm::equal(B4, 2.0f, 0.0001f) ? 0 : 1; + + Error += 0; + } + + { + float A = glm::roundEven(0.0f); + Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::roundEven(0.5f); + Error += glm::equal(B, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::roundEven(1.0f); + Error += glm::equal(C, 1.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::roundEven(0.1f); + Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::roundEven(0.9f); + Error += glm::equal(E, 1.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::roundEven(1.5f); + Error += glm::equal(F, 2.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::roundEven(1.9f); + Error += glm::equal(G, 2.0f, glm::epsilon<float>()) ? 0 : 1; + } + + { + float A = glm::roundEven(-0.0f); + Error += glm::equal(A, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::roundEven(-0.5f); + Error += glm::equal(B, -0.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::roundEven(-1.0f); + Error += glm::equal(C, -1.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::roundEven(-0.1f); + Error += glm::equal(D, 0.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::roundEven(-0.9f); + Error += glm::equal(E, -1.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::roundEven(-1.5f); + Error += glm::equal(F, -2.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::roundEven(-1.9f); + Error += glm::equal(G, -2.0f, glm::epsilon<float>()) ? 0 : 1; + } + + { + float A = glm::roundEven(1.5f); + Error += glm::equal(A, 2.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::roundEven(2.5f); + Error += glm::equal(B, 2.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::roundEven(3.5f); + Error += glm::equal(C, 4.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::roundEven(4.5f); + Error += glm::equal(D, 4.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::roundEven(5.5f); + Error += glm::equal(E, 6.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::roundEven(6.5f); + Error += glm::equal(F, 6.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::roundEven(7.5f); + Error += glm::equal(G, 8.0f, glm::epsilon<float>()) ? 0 : 1; + } + + { + float A = glm::roundEven(-1.5f); + Error += glm::equal(A, -2.0f, glm::epsilon<float>()) ? 0 : 1; + float B = glm::roundEven(-2.5f); + Error += glm::equal(B, -2.0f, glm::epsilon<float>()) ? 0 : 1; + float C = glm::roundEven(-3.5f); + Error += glm::equal(C, -4.0f, glm::epsilon<float>()) ? 0 : 1; + float D = glm::roundEven(-4.5f); + Error += glm::equal(D, -4.0f, glm::epsilon<float>()) ? 0 : 1; + float E = glm::roundEven(-5.5f); + Error += glm::equal(E, -6.0f, glm::epsilon<float>()) ? 0 : 1; + float F = glm::roundEven(-6.5f); + Error += glm::equal(F, -6.0f, glm::epsilon<float>()) ? 0 : 1; + float G = glm::roundEven(-7.5f); + Error += glm::equal(G, -8.0f, glm::epsilon<float>()) ? 0 : 1; + } + + return Error; + } +}//namespace roundEven + +namespace isnan_ +{ + static int test() + { + int Error = 0; + + float Zero_f = 0.0; + double Zero_d = 0.0; + + { + Error += true == glm::isnan(0.0/Zero_d) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::dvec2(0.0 / Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::dvec3(0.0 / Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::dvec4(0.0 / Zero_d))) ? 0 : 1; + } + + { + Error += true == glm::isnan(0.0f/Zero_f) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::vec2(0.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::vec3(0.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isnan(glm::vec4(0.0f/Zero_f))) ? 0 : 1; + } + + return Error; + } +}//namespace isnan_ + +namespace isinf_ +{ + static int test() + { + int Error = 0; + + float Zero_f = 0.0; + double Zero_d = 0.0; + + { + Error += true == glm::isinf( 1.0/Zero_d) ? 0 : 1; + Error += true == glm::isinf(-1.0/Zero_d) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec2( 1.0/Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec2(-1.0/Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec3( 1.0/Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec3(-1.0/Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec4( 1.0/Zero_d))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::dvec4(-1.0/Zero_d))) ? 0 : 1; + } + + { + Error += true == glm::isinf( 1.0f/Zero_f) ? 0 : 1; + Error += true == glm::isinf(-1.0f/Zero_f) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec2( 1.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec2(-1.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec3( 1.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec3(-1.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec4( 1.0f/Zero_f))) ? 0 : 1; + Error += true == glm::any(glm::isinf(glm::vec4(-1.0f/Zero_f))) ? 0 : 1; + } + + return Error; + } +}//namespace isinf_ + +namespace sign +{ + template<typename genFIType> + GLM_FUNC_QUALIFIER genFIType sign_if(genFIType x) + { + GLM_STATIC_ASSERT( + std::numeric_limits<genFIType>::is_iec559 || + (std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer), "'sign' only accept signed inputs"); + + genFIType result; + if(x > genFIType(0)) + result = genFIType(1); + else if(x < genFIType(0)) + result = genFIType(-1); + else + result = genFIType(0); + return result; + } + + template<typename genFIType> + GLM_FUNC_QUALIFIER genFIType sign_alu1(genFIType x) + { + GLM_STATIC_ASSERT( + std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer, + "'sign' only accept integer inputs"); + + return (x >> 31) | (static_cast<unsigned>(-x) >> 31); + } + + GLM_FUNC_QUALIFIER int sign_alu2(int x) + { + GLM_STATIC_ASSERT(std::numeric_limits<int>::is_signed && std::numeric_limits<int>::is_integer, "'sign' only accept integer inputs"); + +# if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable : 4146) //cast truncates constant value +# endif + + return -(static_cast<unsigned>(x) >> 31) | (-static_cast<unsigned>(x) >> 31); + +# if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif + } + + template<typename genFIType> + GLM_FUNC_QUALIFIER genFIType sign_sub(genFIType x) + { + GLM_STATIC_ASSERT( + std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer, + "'sign' only accept integer inputs"); + + return (static_cast<unsigned>(-x) >> 31) - (static_cast<unsigned>(x) >> 31); + } + + template<typename genFIType> + GLM_FUNC_QUALIFIER genFIType sign_cmp(genFIType x) + { + GLM_STATIC_ASSERT( + std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer, + "'sign' only accept integer inputs"); + + return (x > 0) - (x < 0); + } + + template<typename genType> + struct type + { + genType Value; + genType Return; + }; + + int test_int32() + { + type<glm::int32> const Data[] = + { + { std::numeric_limits<glm::int32>::max(), 1}, + { std::numeric_limits<glm::int32>::min(), -1}, + { 0, 0}, + { 1, 1}, + { 2, 1}, + { 3, 1}, + {-1,-1}, + {-2,-1}, + {-3,-1} + }; + + int Error = 0; + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i) + { + glm::int32 Result = glm::sign(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i) + { + glm::int32 Result = sign_cmp(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i) + { + glm::int32 Result = sign_if(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i) + { + glm::int32 Result = sign_alu1(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::int32>); ++i) + { + glm::int32 Result = sign_alu2(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + return Error; + } + + int test_i32vec4() + { + type<glm::ivec4> const Data[] = + { + {glm::ivec4( 1), glm::ivec4( 1)}, + {glm::ivec4( 0), glm::ivec4( 0)}, + {glm::ivec4( 2), glm::ivec4( 1)}, + {glm::ivec4( 3), glm::ivec4( 1)}, + {glm::ivec4(-1), glm::ivec4(-1)}, + {glm::ivec4(-2), glm::ivec4(-1)}, + {glm::ivec4(-3), glm::ivec4(-1)} + }; + + int Error = 0; + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::ivec4>); ++i) + { + glm::ivec4 Result = glm::sign(Data[i].Value); + Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1; + } + + return Error; + } + + int test_f32vec4() + { + type<glm::vec4> const Data[] = + { + {glm::vec4( 1), glm::vec4( 1)}, + {glm::vec4( 0), glm::vec4( 0)}, + {glm::vec4( 2), glm::vec4( 1)}, + {glm::vec4( 3), glm::vec4( 1)}, + {glm::vec4(-1), glm::vec4(-1)}, + {glm::vec4(-2), glm::vec4(-1)}, + {glm::vec4(-3), glm::vec4(-1)} + }; + + int Error = 0; + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::vec4>); ++i) + { + glm::vec4 Result = glm::sign(Data[i].Value); + Error += glm::all(glm::equal(Data[i].Return, Result, glm::epsilon<float>())) ? 0 : 1; + } + + return Error; + } + + static int test() + { + int Error = 0; + + Error += test_int32(); + Error += test_i32vec4(); + Error += test_f32vec4(); + + return Error; + } + + int perf_rand(std::size_t Samples) + { + int Error = 0; + + std::size_t const Count = Samples; + std::vector<glm::int32> Input, Output; + Input.resize(Count); + Output.resize(Count); + for(std::size_t i = 0; i < Count; ++i) + Input[i] = static_cast<glm::int32>(glm::linearRand(-65536.f, 65536.f)); + + std::clock_t Timestamp0 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_cmp(Input[i]); + + std::clock_t Timestamp1 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_if(Input[i]); + + std::clock_t Timestamp2 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_alu1(Input[i]); + + std::clock_t Timestamp3 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_alu2(Input[i]); + + std::clock_t Timestamp4 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_sub(Input[i]); + + std::clock_t Timestamp5 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = glm::sign(Input[i]); + + std::clock_t Timestamp6 = std::clock(); + + std::printf("sign_cmp(rand) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0)); + std::printf("sign_if(rand) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1)); + std::printf("sign_alu1(rand) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2)); + std::printf("sign_alu2(rand) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3)); + std::printf("sign_sub(rand) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4)); + std::printf("glm::sign(rand) Time %d clocks\n", static_cast<int>(Timestamp6 - Timestamp5)); + + return Error; + } + + int perf_linear(std::size_t Samples) + { + int Error = 0; + + std::size_t const Count = Samples; + std::vector<glm::int32> Input, Output; + Input.resize(Count); + Output.resize(Count); + for(std::size_t i = 0; i < Count; ++i) + Input[i] = static_cast<glm::int32>(i); + + std::clock_t Timestamp0 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_cmp(Input[i]); + + std::clock_t Timestamp1 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_if(Input[i]); + + std::clock_t Timestamp2 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_alu1(Input[i]); + + std::clock_t Timestamp3 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_alu2(Input[i]); + + std::clock_t Timestamp4 = std::clock(); + + for(std::size_t i = 0; i < Count; ++i) + Output[i] = sign_sub(Input[i]); + + std::clock_t Timestamp5 = std::clock(); + + std::printf("sign_cmp(linear) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0)); + std::printf("sign_if(linear) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1)); + std::printf("sign_alu1(linear) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2)); + std::printf("sign_alu2(linear) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3)); + std::printf("sign_sub(linear) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4)); + + return Error; + } + + int perf_linear_cal(std::size_t Samples) + { + int Error = 0; + + glm::int32 const Count = static_cast<glm::int32>(Samples); + + std::clock_t Timestamp0 = std::clock(); + glm::int32 Sum = 0; + + for(glm::int32 i = 1; i < Count; ++i) + Sum += sign_cmp(i); + + std::clock_t Timestamp1 = std::clock(); + + for(glm::int32 i = 1; i < Count; ++i) + Sum += sign_if(i); + + std::clock_t Timestamp2 = std::clock(); + + for(glm::int32 i = 1; i < Count; ++i) + Sum += sign_alu1(i); + + std::clock_t Timestamp3 = std::clock(); + + for(glm::int32 i = 1; i < Count; ++i) + Sum += sign_alu2(i); + + std::clock_t Timestamp4 = std::clock(); + + for(glm::int32 i = 1; i < Count; ++i) + Sum += sign_sub(i); + + std::clock_t Timestamp5 = std::clock(); + + std::printf("Sum %d\n", static_cast<int>(Sum)); + + std::printf("sign_cmp(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp1 - Timestamp0)); + std::printf("sign_if(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp2 - Timestamp1)); + std::printf("sign_alu1(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp3 - Timestamp2)); + std::printf("sign_alu2(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp4 - Timestamp3)); + std::printf("sign_sub(linear_cal) Time %d clocks\n", static_cast<int>(Timestamp5 - Timestamp4)); + + return Error; + } + + static int perf(std::size_t Samples) + { + int Error(0); + + Error += perf_linear_cal(Samples); + Error += perf_linear(Samples); + Error += perf_rand(Samples); + + return Error; + } +}//namespace sign + +namespace frexp_ +{ + static int test() + { + int Error = 0; + + { + glm::vec1 const x(1024); + glm::ivec1 exp; + glm::vec1 A = glm::frexp(x, exp); + Error += glm::all(glm::equal(A, glm::vec1(0.5), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(exp, glm::ivec1(11))) ? 0 : 1; + } + + { + glm::vec2 const x(1024, 0.24); + glm::ivec2 exp; + glm::vec2 A = glm::frexp(x, exp); + Error += glm::all(glm::equal(A, glm::vec2(0.5, 0.96), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(exp, glm::ivec2(11, -2))) ? 0 : 1; + } + + { + glm::vec3 const x(1024, 0.24, 0); + glm::ivec3 exp; + glm::vec3 A = glm::frexp(x, exp); + Error += glm::all(glm::equal(A, glm::vec3(0.5, 0.96, 0.0), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(exp, glm::ivec3(11, -2, 0))) ? 0 : 1; + } + + { + glm::vec4 const x(1024, 0.24, 0, -1.33); + glm::ivec4 exp; + glm::vec4 A = glm::frexp(x, exp); + Error += glm::all(glm::equal(A, glm::vec4(0.5, 0.96, 0.0, -0.665), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(exp, glm::ivec4(11, -2, 0, 1))) ? 0 : 1; + } + + return Error; + } +}//namespace frexp_ + +namespace ldexp_ +{ + static int test() + { + int Error(0); + + { + glm::vec1 A = glm::vec1(0.5); + glm::ivec1 exp = glm::ivec1(11); + glm::vec1 x = glm::ldexp(A, exp); + Error += glm::all(glm::equal(x, glm::vec1(1024),0.00001f)) ? 0 : 1; + } + + { + glm::vec2 A = glm::vec2(0.5, 0.96); + glm::ivec2 exp = glm::ivec2(11, -2); + glm::vec2 x = glm::ldexp(A, exp); + Error += glm::all(glm::equal(x, glm::vec2(1024, .24),0.00001f)) ? 0 : 1; + } + + { + glm::vec3 A = glm::vec3(0.5, 0.96, 0.0); + glm::ivec3 exp = glm::ivec3(11, -2, 0); + glm::vec3 x = glm::ldexp(A, exp); + Error += glm::all(glm::equal(x, glm::vec3(1024, .24, 0),0.00001f)) ? 0 : 1; + } + + { + glm::vec4 A = glm::vec4(0.5, 0.96, 0.0, -0.665); + glm::ivec4 exp = glm::ivec4(11, -2, 0, 1); + glm::vec4 x = glm::ldexp(A, exp); + Error += glm::all(glm::equal(x, glm::vec4(1024, .24, 0, -1.33),0.00001f)) ? 0 : 1; + } + + return Error; + } +}//namespace ldexp_ + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::abs(1.0f) > 0.0f, "GLM: Failed constexpr"); + constexpr glm::vec1 const A = glm::abs(glm::vec1(1.0f)); + constexpr glm::vec2 const B = glm::abs(glm::vec2(1.0f)); + constexpr glm::vec3 const C = glm::abs(glm::vec3(1.0f)); + constexpr glm::vec4 const D = glm::abs(glm::vec4(1.0f)); +#endif // GLM_HAS_CONSTEXPR + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_constexpr(); + Error += sign::test(); + Error += floor_::test(); + Error += mod_::test(); + Error += modf_::test(); + Error += floatBitsToInt::test(); + Error += floatBitsToUint::test(); + Error += mix_::test(); + Error += step_::test(); + Error += max_::test(); + Error += min_::test(); + Error += clamp_::test(); + Error += round_::test(); + Error += roundEven::test(); + Error += isnan_::test(); + Error += isinf_::test(); + Error += frexp_::test(); + Error += ldexp_::test(); + +# ifdef NDEBUG + std::size_t Samples = 1000; +# else + std::size_t Samples = 1; +# endif + Error += sign::perf(Samples); + + Error += min_::perf(Samples); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_exponential.cpp b/3rdparty/glm/source/test/core/core_func_exponential.cpp new file mode 100644 index 0000000..380cdfb --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_exponential.cpp @@ -0,0 +1,185 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/vector_float1.hpp> +#include <glm/ext/vector_float2.hpp> +#include <glm/ext/vector_float3.hpp> +#include <glm/ext/vector_float4.hpp> +#include <glm/common.hpp> +#include <glm/exponential.hpp> + +static int test_pow() +{ + int Error(0); + + float A = glm::pow(2.f, 2.f); + Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::pow(glm::vec1(2.f), glm::vec1(2.f)); + Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::pow(glm::vec2(2.f), glm::vec2(2.f)); + Error += glm::all(glm::equal(C, glm::vec2(4.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::pow(glm::vec3(2.f), glm::vec3(2.f)); + Error += glm::all(glm::equal(D, glm::vec3(4.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::pow(glm::vec4(2.f), glm::vec4(2.f)); + Error += glm::all(glm::equal(E, glm::vec4(4.f), 0.01f)) ? 0 : 1; + + return Error; +} + +static int test_sqrt() +{ + int Error = 0; + + float A = glm::sqrt(4.f); + Error += glm::equal(A, 2.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::sqrt(glm::vec1(4.f)); + Error += glm::all(glm::equal(B, glm::vec1(2.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::sqrt(glm::vec2(4.f)); + Error += glm::all(glm::equal(C, glm::vec2(2.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::sqrt(glm::vec3(4.f)); + Error += glm::all(glm::equal(D, glm::vec3(2.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::sqrt(glm::vec4(4.f)); + Error += glm::all(glm::equal(E, glm::vec4(2.f), 0.01f)) ? 0 : 1; + + return Error; +} + +static int test_exp() +{ + int Error = 0; + + float A = glm::exp(1.f); + Error += glm::equal(A, glm::e<float>(), 0.01f) ? 0 : 1; + + glm::vec1 B = glm::exp(glm::vec1(1.f)); + Error += glm::all(glm::equal(B, glm::vec1(glm::e<float>()), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::exp(glm::vec2(1.f)); + Error += glm::all(glm::equal(C, glm::vec2(glm::e<float>()), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::exp(glm::vec3(1.f)); + Error += glm::all(glm::equal(D, glm::vec3(glm::e<float>()), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::exp(glm::vec4(1.f)); + Error += glm::all(glm::equal(E, glm::vec4(glm::e<float>()), 0.01f)) ? 0 : 1; + + return Error; +} + +static int test_log() +{ + int Error = 0; + + float const A = glm::log(glm::e<float>()); + Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1; + + glm::vec1 const B = glm::log(glm::vec1(glm::e<float>())); + Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; + + glm::vec2 const C = glm::log(glm::vec2(glm::e<float>())); + Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; + + glm::vec3 const D = glm::log(glm::vec3(glm::e<float>())); + Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; + + glm::vec4 const E = glm::log(glm::vec4(glm::e<float>())); + Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; + + return Error; +} + +static int test_exp2() +{ + int Error = 0; + + float A = glm::exp2(4.f); + Error += glm::equal(A, 16.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::exp2(glm::vec1(4.f)); + Error += glm::all(glm::equal(B, glm::vec1(16.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::exp2(glm::vec2(4.f, 3.f)); + Error += glm::all(glm::equal(C, glm::vec2(16.f, 8.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::exp2(glm::vec3(4.f, 3.f, 2.f)); + Error += glm::all(glm::equal(D, glm::vec3(16.f, 8.f, 4.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::exp2(glm::vec4(4.f, 3.f, 2.f, 1.f)); + Error += glm::all(glm::equal(E, glm::vec4(16.f, 8.f, 4.f, 2.f), 0.01f)) ? 0 : 1; + +# if GLM_HAS_CXX11_STL + //large exponent + float F = glm::exp2(23.f); + Error += glm::equal(F, 8388608.f, 0.01f) ? 0 : 1; +# endif + + return Error; +} + +static int test_log2() +{ + int Error = 0; + + float A = glm::log2(16.f); + Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::log2(glm::vec1(16.f)); + Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::log2(glm::vec2(16.f, 8.f)); + Error += glm::all(glm::equal(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::log2(glm::vec3(16.f, 8.f, 4.f)); + Error += glm::all(glm::equal(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::log2(glm::vec4(16.f, 8.f, 4.f, 2.f)); + Error += glm::all(glm::equal(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1; + + return Error; +} + +static int test_inversesqrt() +{ + int Error = 0; + + float A = glm::inversesqrt(16.f) * glm::sqrt(16.f); + Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1; + + glm::vec1 B = glm::inversesqrt(glm::vec1(16.f)) * glm::sqrt(16.f); + Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; + + glm::vec2 C = glm::inversesqrt(glm::vec2(16.f)) * glm::sqrt(16.f); + Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; + + glm::vec3 D = glm::inversesqrt(glm::vec3(16.f)) * glm::sqrt(16.f); + Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; + + glm::vec4 E = glm::inversesqrt(glm::vec4(16.f)) * glm::sqrt(16.f); + Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_pow(); + Error += test_sqrt(); + Error += test_exp(); + Error += test_log(); + Error += test_exp2(); + Error += test_log2(); + Error += test_inversesqrt(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_geometric.cpp b/3rdparty/glm/source/test/core/core_func_geometric.cpp new file mode 100644 index 0000000..7ef9c68 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_geometric.cpp @@ -0,0 +1,200 @@ +#include <glm/geometric.hpp> +#include <glm/trigonometric.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/vector_float1.hpp> +#include <glm/ext/vector_float2.hpp> +#include <glm/ext/vector_float3.hpp> +#include <glm/ext/vector_float4.hpp> +#include <glm/ext/vector_double2.hpp> +#include <glm/ext/vector_double3.hpp> +#include <glm/ext/vector_double4.hpp> +#include <limits> + +namespace length +{ + int test() + { + float Length1 = glm::length(glm::vec1(1)); + float Length2 = glm::length(glm::vec2(1, 0)); + float Length3 = glm::length(glm::vec3(1, 0, 0)); + float Length4 = glm::length(glm::vec4(1, 0, 0, 0)); + + int Error = 0; + + Error += glm::abs(Length1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Length2 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Length3 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Length4 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + + return Error; + } +}//namespace length + +namespace distance +{ + int test() + { + float Distance1 = glm::distance(glm::vec1(1), glm::vec1(1)); + float Distance2 = glm::distance(glm::vec2(1, 0), glm::vec2(1, 0)); + float Distance3 = glm::distance(glm::vec3(1, 0, 0), glm::vec3(1, 0, 0)); + float Distance4 = glm::distance(glm::vec4(1, 0, 0, 0), glm::vec4(1, 0, 0, 0)); + + int Error = 0; + + Error += glm::abs(Distance1) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Distance2) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Distance3) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Distance4) < std::numeric_limits<float>::epsilon() ? 0 : 1; + + return Error; + } +}//namespace distance + +namespace dot +{ + int test() + { + float Dot1 = glm::dot(glm::vec1(1), glm::vec1(1)); + float Dot2 = glm::dot(glm::vec2(1), glm::vec2(1)); + float Dot3 = glm::dot(glm::vec3(1), glm::vec3(1)); + float Dot4 = glm::dot(glm::vec4(1), glm::vec4(1)); + + int Error = 0; + + Error += glm::abs(Dot1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Dot2 - 2.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Dot3 - 3.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + Error += glm::abs(Dot4 - 4.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1; + + return Error; + } +}//namespace dot + +namespace cross +{ + int test() + { + glm::vec3 Cross1 = glm::cross(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0)); + glm::vec3 Cross2 = glm::cross(glm::vec3(0, 1, 0), glm::vec3(1, 0, 0)); + + int Error = 0; + + Error += glm::all(glm::lessThan(glm::abs(Cross1 - glm::vec3(0, 0, 1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1; + Error += glm::all(glm::lessThan(glm::abs(Cross2 - glm::vec3(0, 0,-1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1; + + return Error; + } +}//namespace cross + +namespace normalize +{ + int test() + { + glm::vec3 Normalize1 = glm::normalize(glm::vec3(1, 0, 0)); + glm::vec3 Normalize2 = glm::normalize(glm::vec3(2, 0, 0)); + + glm::vec3 Normalize3 = glm::normalize(glm::vec3(-0.6, 0.7, -0.5)); + + glm::vec3 ro = glm::vec3(glm::cos(5.f) * 3.f, 2.f, glm::sin(5.f) * 3.f); + glm::vec3 w = glm::normalize(glm::vec3(0, -0.2f, 0) - ro); + glm::vec3 u = glm::normalize(glm::cross(w, glm::vec3(0, 1, 0))); + glm::vec3 v = glm::cross(u, w); + + int Error = 0; + + Error += glm::all(glm::lessThan(glm::abs(Normalize1 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1; + Error += glm::all(glm::lessThan(glm::abs(Normalize2 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1; + + return Error; + } +}//namespace normalize + +namespace faceforward +{ + int test() + { + int Error = 0; + + { + glm::vec3 N(0.0f, 0.0f, 1.0f); + glm::vec3 I(1.0f, 0.0f, 1.0f); + glm::vec3 Nref(0.0f, 0.0f, 1.0f); + glm::vec3 F = glm::faceforward(N, I, Nref); + } + + return Error; + } +}//namespace faceforward + +namespace reflect +{ + int test() + { + int Error = 0; + + { + glm::vec2 A(1.0f,-1.0f); + glm::vec2 B(0.0f, 1.0f); + glm::vec2 C = glm::reflect(A, B); + Error += glm::all(glm::equal(C, glm::vec2(1.0, 1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec2 A(1.0f,-1.0f); + glm::dvec2 B(0.0f, 1.0f); + glm::dvec2 C = glm::reflect(A, B); + Error += glm::all(glm::equal(C, glm::dvec2(1.0, 1.0), 0.0001)) ? 0 : 1; + } + + return Error; + } +}//namespace reflect + +namespace refract +{ + int test() + { + int Error = 0; + + { + float A(-1.0f); + float B(1.0f); + float C = glm::refract(A, B, 0.5f); + Error += glm::equal(C, -1.0f, 0.0001f) ? 0 : 1; + } + + { + glm::vec2 A(0.0f,-1.0f); + glm::vec2 B(0.0f, 1.0f); + glm::vec2 C = glm::refract(A, B, 0.5f); + Error += glm::all(glm::equal(C, glm::vec2(0.0, -1.0), 0.0001f)) ? 0 : 1; + } + + { + glm::dvec2 A(0.0f,-1.0f); + glm::dvec2 B(0.0f, 1.0f); + glm::dvec2 C = glm::refract(A, B, 0.5); + Error += glm::all(glm::equal(C, glm::dvec2(0.0, -1.0), 0.0001)) ? 0 : 1; + } + + return Error; + } +}//namespace refract + +int main() +{ + int Error(0); + + Error += length::test(); + Error += distance::test(); + Error += dot::test(); + Error += cross::test(); + Error += normalize::test(); + Error += faceforward::test(); + Error += reflect::test(); + Error += refract::test(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_integer.cpp b/3rdparty/glm/source/test/core/core_func_integer.cpp new file mode 100644 index 0000000..95d650c --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_integer.cpp @@ -0,0 +1,1556 @@ +#include <glm/integer.hpp> +#include <glm/vector_relational.hpp> +#include <glm/ext/vector_int1.hpp> +#include <glm/ext/vector_int2.hpp> +#include <glm/ext/vector_int3.hpp> +#include <glm/ext/vector_int4.hpp> +#include <glm/ext/vector_uint1.hpp> +#include <glm/ext/vector_uint2.hpp> +#include <glm/ext/vector_uint3.hpp> +#include <glm/ext/vector_uint4.hpp> +#include <glm/ext/scalar_int_sized.hpp> +#include <glm/ext/scalar_uint_sized.hpp> +#include <vector> +#include <ctime> +#include <cstdio> + +enum result +{ + SUCCESS, + FAIL, + ASSERT, + STATIC_ASSERT +}; + +namespace bitfieldInsert +{ + template<typename genType> + struct type + { + genType Base; + genType Insert; + int Offset; + int Bits; + genType Return; + }; + + typedef type<glm::uint> typeU32; + + typeU32 const Data32[] = + { + {0x00000000, 0xffffffff, 0, 32, 0xffffffff}, + {0x00000000, 0xffffffff, 0, 31, 0x7fffffff}, + {0x00000000, 0xffffffff, 0, 0, 0x00000000}, + {0xff000000, 0x000000ff, 8, 8, 0xff00ff00}, + {0xffff0000, 0xffff0000, 16, 16, 0x00000000}, + {0x0000ffff, 0x0000ffff, 16, 16, 0xffffffff} + }; + + static int test() + { + int Error = 0; + glm::uint count = sizeof(Data32) / sizeof(typeU32); + + for(glm::uint i = 0; i < count; ++i) + { + glm::uint Return = glm::bitfieldInsert( + Data32[i].Base, + Data32[i].Insert, + Data32[i].Offset, + Data32[i].Bits); + + Error += Data32[i].Return == Return ? 0 : 1; + } + + return Error; + } +}//bitfieldInsert + +namespace bitfieldExtract +{ + template<typename genType> + struct type + { + genType Value; + int Offset; + int Bits; + genType Return; + result Result; + }; + + typedef type<glm::uint> typeU32; + + typeU32 const Data32[] = + { + {0xffffffff, 0,32, 0xffffffff, SUCCESS}, + {0xffffffff, 8, 0, 0x00000000, SUCCESS}, + {0x00000000, 0,32, 0x00000000, SUCCESS}, + {0x0f0f0f0f, 0,32, 0x0f0f0f0f, SUCCESS}, + {0x00000000, 8, 0, 0x00000000, SUCCESS}, + {0x80000000,31, 1, 0x00000001, SUCCESS}, + {0x7fffffff,31, 1, 0x00000000, SUCCESS}, + {0x00000300, 8, 8, 0x00000003, SUCCESS}, + {0x0000ff00, 8, 8, 0x000000ff, SUCCESS}, + {0xfffffff0, 0, 5, 0x00000010, SUCCESS}, + {0x000000ff, 1, 3, 0x00000007, SUCCESS}, + {0x000000ff, 0, 3, 0x00000007, SUCCESS}, + {0x00000000, 0, 2, 0x00000000, SUCCESS}, + {0xffffffff, 0, 8, 0x000000ff, SUCCESS}, + {0xffff0000,16,16, 0x0000ffff, SUCCESS}, + {0xfffffff0, 0, 8, 0x00000000, FAIL}, + {0xffffffff,16,16, 0x00000000, FAIL}, + //{0xffffffff,32, 1, 0x00000000, ASSERT}, // Throw an assert + //{0xffffffff, 0,33, 0x00000000, ASSERT}, // Throw an assert + //{0xffffffff,16,16, 0x00000000, ASSERT}, // Throw an assert + }; + + static int test() + { + int Error = 0; + + glm::uint count = sizeof(Data32) / sizeof(typeU32); + + for(glm::uint i = 0; i < count; ++i) + { + glm::uint Return = glm::bitfieldExtract( + Data32[i].Value, + Data32[i].Offset, + Data32[i].Bits); + + bool Compare = Data32[i].Return == Return; + + if(Data32[i].Result == SUCCESS && Compare) + continue; + else if(Data32[i].Result == FAIL && !Compare) + continue; + + Error += 1; + } + + return Error; + } +}//extractField + +namespace bitfieldReverse +{ +/* + GLM_FUNC_QUALIFIER unsigned int bitfieldReverseLoop(unsigned int v) + { + unsigned int Result(0); + unsigned int const BitSize = static_cast<unsigned int>(sizeof(unsigned int) * 8); + for(unsigned int i = 0; i < BitSize; ++i) + { + unsigned int const BitSet(v & (static_cast<unsigned int>(1) << i)); + unsigned int const BitFirst(BitSet >> i); + Result |= BitFirst << (BitSize - 1 - i); + } + return Result; + } + + GLM_FUNC_QUALIFIER glm::uint64_t bitfieldReverseLoop(glm::uint64_t v) + { + glm::uint64_t Result(0); + glm::uint64_t const BitSize = static_cast<glm::uint64_t>(sizeof(unsigned int) * 8); + for(glm::uint64_t i = 0; i < BitSize; ++i) + { + glm::uint64_t const BitSet(v & (static_cast<glm::uint64_t>(1) << i)); + glm::uint64_t const BitFirst(BitSet >> i); + Result |= BitFirst << (BitSize - 1 - i); + } + return Result; + } +*/ + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER glm::vec<L, T, Q> bitfieldReverseLoop(glm::vec<L, T, Q> const& v) + { + GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values"); + + glm::vec<L, T, Q> Result(0); + T const BitSize = static_cast<T>(sizeof(T) * 8); + for(T i = 0; i < BitSize; ++i) + { + glm::vec<L, T, Q> const BitSet(v & (static_cast<T>(1) << i)); + glm::vec<L, T, Q> const BitFirst(BitSet >> i); + Result |= BitFirst << (BitSize - 1 - i); + } + return Result; + } + + template<typename T> + GLM_FUNC_QUALIFIER T bitfieldReverseLoop(T v) + { + return bitfieldReverseLoop(glm::vec<1, T>(v)).x; + } + + GLM_FUNC_QUALIFIER glm::uint32 bitfieldReverseUint32(glm::uint32 x) + { + x = (x & 0x55555555) << 1 | (x & 0xAAAAAAAA) >> 1; + x = (x & 0x33333333) << 2 | (x & 0xCCCCCCCC) >> 2; + x = (x & 0x0F0F0F0F) << 4 | (x & 0xF0F0F0F0) >> 4; + x = (x & 0x00FF00FF) << 8 | (x & 0xFF00FF00) >> 8; + x = (x & 0x0000FFFF) << 16 | (x & 0xFFFF0000) >> 16; + return x; + } + + GLM_FUNC_QUALIFIER glm::uint64 bitfieldReverseUint64(glm::uint64 x) + { + x = (x & 0x5555555555555555) << 1 | (x & 0xAAAAAAAAAAAAAAAA) >> 1; + x = (x & 0x3333333333333333) << 2 | (x & 0xCCCCCCCCCCCCCCCC) >> 2; + x = (x & 0x0F0F0F0F0F0F0F0F) << 4 | (x & 0xF0F0F0F0F0F0F0F0) >> 4; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + return x; + } + + template<bool EXEC = false> + struct compute_bitfieldReverseStep + { + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T, T) + { + return v; + } + }; + + template<> + struct compute_bitfieldReverseStep<true> + { + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T Mask, T Shift) + { + return (v & Mask) << Shift | (v & (~Mask)) >> Shift; + } + }; + + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER glm::vec<L, T, Q> bitfieldReverseOps(glm::vec<L, T, Q> const& v) + { + glm::vec<L, T, Q> x(v); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 2>::call(x, static_cast<T>(0x5555555555555555ull), static_cast<T>( 1)); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 4>::call(x, static_cast<T>(0x3333333333333333ull), static_cast<T>( 2)); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 8>::call(x, static_cast<T>(0x0F0F0F0F0F0F0F0Full), static_cast<T>( 4)); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 16>::call(x, static_cast<T>(0x00FF00FF00FF00FFull), static_cast<T>( 8)); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 32>::call(x, static_cast<T>(0x0000FFFF0000FFFFull), static_cast<T>(16)); + x = compute_bitfieldReverseStep<sizeof(T) * 8 >= 64>::call(x, static_cast<T>(0x00000000FFFFFFFFull), static_cast<T>(32)); + return x; + } + + template<typename genType> + GLM_FUNC_QUALIFIER genType bitfieldReverseOps(genType x) + { + return bitfieldReverseOps(glm::vec<1, genType, glm::defaultp>(x)).x; + } + + template<typename genType> + struct type + { + genType Value; + genType Return; + result Result; + }; + + typedef type<glm::uint> typeU32; + + typeU32 const Data32[] = + { + {0x00000001, 0x80000000, SUCCESS}, + {0x0000000f, 0xf0000000, SUCCESS}, + {0x000000ff, 0xff000000, SUCCESS}, + {0xf0000000, 0x0000000f, SUCCESS}, + {0xff000000, 0x000000ff, SUCCESS}, + {0xffffffff, 0xffffffff, SUCCESS}, + {0x00000000, 0x00000000, SUCCESS} + }; + + typedef type<glm::uint64> typeU64; + + typeU64 const Data64[] = + { + {0x00000000000000ff, 0xff00000000000000, SUCCESS}, + {0x000000000000000f, 0xf000000000000000, SUCCESS}, + {0xf000000000000000, 0x000000000000000f, SUCCESS}, + {0xffffffffffffffff, 0xffffffffffffffff, SUCCESS}, + {0x0000000000000000, 0x0000000000000000, SUCCESS} + }; + + static int test32_bitfieldReverse() + { + int Error = 0; + std::size_t const Count = sizeof(Data32) / sizeof(typeU32); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint Return = glm::bitfieldReverse(Data32[i].Value); + + bool Compare = Data32[i].Return == Return; + + if(Data32[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test32_bitfieldReverseLoop() + { + int Error = 0; + std::size_t const Count = sizeof(Data32) / sizeof(typeU32); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint Return = bitfieldReverseLoop(Data32[i].Value); + + bool Compare = Data32[i].Return == Return; + + if(Data32[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test32_bitfieldReverseUint32() + { + int Error = 0; + std::size_t const Count = sizeof(Data32) / sizeof(typeU32); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint Return = bitfieldReverseUint32(Data32[i].Value); + + bool Compare = Data32[i].Return == Return; + + if(Data32[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test32_bitfieldReverseOps() + { + int Error = 0; + std::size_t const Count = sizeof(Data32) / sizeof(typeU32); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint Return = bitfieldReverseOps(Data32[i].Value); + + bool Compare = Data32[i].Return == Return; + + if(Data32[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test64_bitfieldReverse() + { + int Error = 0; + std::size_t const Count = sizeof(Data64) / sizeof(typeU64); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint64 Return = glm::bitfieldReverse(Data64[i].Value); + + bool Compare = Data64[i].Return == Return; + + if(Data64[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test64_bitfieldReverseLoop() + { + int Error = 0; + std::size_t const Count = sizeof(Data64) / sizeof(typeU64); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint64 Return = bitfieldReverseLoop(Data64[i].Value); + + bool Compare = Data64[i].Return == Return; + + if(Data32[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test64_bitfieldReverseUint64() + { + int Error = 0; + std::size_t const Count = sizeof(Data64) / sizeof(typeU64); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint64 Return = bitfieldReverseUint64(Data64[i].Value); + + bool Compare = Data64[i].Return == Return; + + if(Data64[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test64_bitfieldReverseOps() + { + int Error = 0; + std::size_t const Count = sizeof(Data64) / sizeof(typeU64); + + for(std::size_t i = 0; i < Count; ++i) + { + glm::uint64 Return = bitfieldReverseOps(Data64[i].Value); + + bool Compare = Data64[i].Return == Return; + + if(Data64[i].Result == SUCCESS) + Error += Compare ? 0 : 1; + else + Error += Compare ? 1 : 0; + } + + return Error; + } + + static int test() + { + int Error = 0; + + Error += test32_bitfieldReverse(); + Error += test32_bitfieldReverseLoop(); + Error += test32_bitfieldReverseUint32(); + Error += test32_bitfieldReverseOps(); + + Error += test64_bitfieldReverse(); + Error += test64_bitfieldReverseLoop(); + Error += test64_bitfieldReverseUint64(); + Error += test64_bitfieldReverseOps(); + + return Error; + } + + static int perf32(glm::uint32 Count) + { + int Error = 0; + + std::vector<glm::uint32> Data; + Data.resize(static_cast<std::size_t>(Count)); + + std::clock_t Timestamps0 = std::clock(); + + for(glm::uint32 k = 0; k < Count; ++k) + Data[k] = glm::bitfieldReverse(k); + + std::clock_t Timestamps1 = std::clock(); + + for(glm::uint32 k = 0; k < Count; ++k) + Data[k] = bitfieldReverseLoop(k); + + std::clock_t Timestamps2 = std::clock(); + + for(glm::uint32 k = 0; k < Count; ++k) + Data[k] = bitfieldReverseUint32(k); + + std::clock_t Timestamps3 = std::clock(); + + for(glm::uint32 k = 0; k < Count; ++k) + Data[k] = bitfieldReverseOps(k); + + std::clock_t Timestamps4 = std::clock(); + + std::printf("glm::bitfieldReverse: %d clocks\n", static_cast<int>(Timestamps1 - Timestamps0)); + std::printf("bitfieldReverseLoop: %d clocks\n", static_cast<int>(Timestamps2 - Timestamps1)); + std::printf("bitfieldReverseUint32: %d clocks\n", static_cast<int>(Timestamps3 - Timestamps2)); + std::printf("bitfieldReverseOps: %d clocks\n", static_cast<int>(Timestamps4 - Timestamps3)); + + return Error; + } + + static int perf64(glm::uint64 Count) + { + int Error = 0; + + std::vector<glm::uint64> Data; + Data.resize(static_cast<std::size_t>(Count)); + + std::clock_t Timestamps0 = std::clock(); + + for(glm::uint64 k = 0; k < Count; ++k) + Data[static_cast<std::size_t>(k)] = glm::bitfieldReverse(k); + + std::clock_t Timestamps1 = std::clock(); + + for(glm::uint64 k = 0; k < Count; ++k) + Data[static_cast<std::size_t>(k)] = bitfieldReverseLoop<glm::uint64>(k); + + std::clock_t Timestamps2 = std::clock(); + + for(glm::uint64 k = 0; k < Count; ++k) + Data[static_cast<std::size_t>(k)] = bitfieldReverseUint64(k); + + std::clock_t Timestamps3 = std::clock(); + + for(glm::uint64 k = 0; k < Count; ++k) + Data[static_cast<std::size_t>(k)] = bitfieldReverseOps(k); + + std::clock_t Timestamps4 = std::clock(); + + std::printf("glm::bitfieldReverse - 64: %d clocks\n", static_cast<int>(Timestamps1 - Timestamps0)); + std::printf("bitfieldReverseLoop - 64: %d clocks\n", static_cast<int>(Timestamps2 - Timestamps1)); + std::printf("bitfieldReverseUint - 64: %d clocks\n", static_cast<int>(Timestamps3 - Timestamps2)); + std::printf("bitfieldReverseOps - 64: %d clocks\n", static_cast<int>(Timestamps4 - Timestamps3)); + + return Error; + } + + static int perf(std::size_t Samples) + { + int Error = 0; + + Error += perf32(static_cast<glm::uint32>(Samples)); + Error += perf64(static_cast<glm::uint64>(Samples)); + + return Error; + } +}//bitfieldReverse + +namespace findMSB +{ + template<typename genType, typename retType> + struct type + { + genType Value; + retType Return; + }; + +# if GLM_HAS_BITSCAN_WINDOWS + template<typename genIUType> + static int findMSB_intrinsic(genIUType Value) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); + + if(Value == 0) + return -1; + + unsigned long Result(0); + _BitScanReverse(&Result, Value); + return int(Result); + } +# endif//GLM_HAS_BITSCAN_WINDOWS + +# if GLM_ARCH & GLM_ARCH_AVX && GLM_COMPILER & GLM_COMPILER_VC + template<typename genIUType> + static int findMSB_avx(genIUType Value) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); + + if(Value == 0) + return -1; + + return int(_tzcnt_u32(Value)); + } +# endif//GLM_ARCH & GLM_ARCH_AVX && GLM_PLATFORM & GLM_PLATFORM_WINDOWS + + template<typename genIUType> + static int findMSB_095(genIUType Value) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); + + if(Value == genIUType(0) || Value == genIUType(-1)) + return -1; + else if(Value > 0) + { + genIUType Bit = genIUType(-1); + for(genIUType tmp = Value; tmp > 0; tmp >>= 1, ++Bit){} + return static_cast<int>(Bit); + } + else //if(Value < 0) + { + int const BitCount(sizeof(genIUType) * 8); + int MostSignificantBit(-1); + for(int BitIndex(0); BitIndex < BitCount; ++BitIndex) + MostSignificantBit = (Value & (1 << BitIndex)) ? MostSignificantBit : BitIndex; + assert(MostSignificantBit >= 0); + return MostSignificantBit; + } + } + + template<typename genIUType> + static int findMSB_nlz1(genIUType x) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); + + if (x == 0) + return -1; + + int n = 0; + if (x <= 0x0000FFFF) {n = n +16; x = x <<16;} + if (x <= 0x00FFFFFF) {n = n + 8; x = x << 8;} + if (x <= 0x0FFFFFFF) {n = n + 4; x = x << 4;} + if (x <= 0x3FFFFFFF) {n = n + 2; x = x << 2;} + if (x <= 0x7FFFFFFF) {n = n + 1;} + return 31 - n; + } + + static int findMSB_nlz2(unsigned int x) + { + unsigned int y; + int n = 32; + + y = x >>16; if (y != 0) {n = n -16; x = y;} + y = x >> 8; if (y != 0) {n = n - 8; x = y;} + y = x >> 4; if (y != 0) {n = n - 4; x = y;} + y = x >> 2; if (y != 0) {n = n - 2; x = y;} + y = x >> 1; if (y != 0) return n - 2; + return 32 - (n - static_cast<int>(x)); + } + + static int findMSB_pop(unsigned int x) + { + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + return 31 - glm::bitCount(~x); + } + + static int perf_int(std::size_t Count) + { + type<int, int> const Data[] = + { + {0x00000000, -1}, + {0x00000001, 0}, + {0x00000002, 1}, + {0x00000003, 1}, + {0x00000004, 2}, + {0x00000005, 2}, + {0x00000007, 2}, + {0x00000008, 3}, + {0x00000010, 4}, + {0x00000020, 5}, + {0x00000040, 6}, + {0x00000080, 7}, + {0x00000100, 8}, + {0x00000200, 9}, + {0x00000400, 10}, + {0x00000800, 11}, + {0x00001000, 12}, + {0x00002000, 13}, + {0x00004000, 14}, + {0x00008000, 15}, + {0x00010000, 16}, + {0x00020000, 17}, + {0x00040000, 18}, + {0x00080000, 19}, + {0x00100000, 20}, + {0x00200000, 21}, + {0x00400000, 22}, + {0x00800000, 23}, + {0x01000000, 24}, + {0x02000000, 25}, + {0x04000000, 26}, + {0x08000000, 27}, + {0x10000000, 28}, + {0x20000000, 29}, + {0x40000000, 30} + }; + + int Error(0); + + std::clock_t Timestamps0 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = glm::findMSB(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps1 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_nlz1(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps2 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_nlz2(static_cast<unsigned int>(Data[i].Value)); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps3 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_095(static_cast<unsigned int>(Data[i].Value)); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps4 = std::clock(); + +# if GLM_HAS_BITSCAN_WINDOWS + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_intrinsic(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } +# endif//GLM_HAS_BITSCAN_WINDOWS + + std::clock_t Timestamps5 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_pop(static_cast<unsigned int>(Data[i].Value)); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps6 = std::clock(); + +# if GLM_ARCH & GLM_ARCH_AVX && GLM_COMPILER & GLM_COMPILER_VC + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int, int>); ++i) + { + int Result = findMSB_avx(Data[i].Value); + Error += Data[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps7 = std::clock(); +# endif + + std::printf("glm::findMSB: %d clocks\n", static_cast<int>(Timestamps1 - Timestamps0)); + std::printf("findMSB - nlz1: %d clocks\n", static_cast<int>(Timestamps2 - Timestamps1)); + std::printf("findMSB - nlz2: %d clocks\n", static_cast<int>(Timestamps3 - Timestamps2)); + std::printf("findMSB - 0.9.5: %d clocks\n", static_cast<int>(Timestamps4 - Timestamps3)); + +# if GLM_HAS_BITSCAN_WINDOWS + std::printf("findMSB - intrinsics: %d clocks\n", static_cast<int>(Timestamps5 - Timestamps4)); +# endif//GLM_HAS_BITSCAN_WINDOWS + std::printf("findMSB - pop: %d clocks\n", static_cast<int>(Timestamps6 - Timestamps5)); + +# if GLM_ARCH & GLM_ARCH_AVX && GLM_COMPILER & GLM_COMPILER_VC + std::printf("findMSB - avx tzcnt: %d clocks\n", static_cast<int>(Timestamps7 - Timestamps6)); +# endif//GLM_ARCH & GLM_ARCH_AVX && GLM_PLATFORM & GLM_PLATFORM_WINDOWS + + return Error; + } + + static int test_ivec4() + { + type<glm::ivec4, glm::ivec4> const Data[] = + { + {glm::ivec4(0x00000000), glm::ivec4(-1)}, + {glm::ivec4(0x00000001), glm::ivec4( 0)}, + {glm::ivec4(0x00000002), glm::ivec4( 1)}, + {glm::ivec4(0x00000003), glm::ivec4( 1)}, + {glm::ivec4(0x00000004), glm::ivec4( 2)}, + {glm::ivec4(0x00000005), glm::ivec4( 2)}, + {glm::ivec4(0x00000007), glm::ivec4( 2)}, + {glm::ivec4(0x00000008), glm::ivec4( 3)}, + {glm::ivec4(0x00000010), glm::ivec4( 4)}, + {glm::ivec4(0x00000020), glm::ivec4( 5)}, + {glm::ivec4(0x00000040), glm::ivec4( 6)}, + {glm::ivec4(0x00000080), glm::ivec4( 7)}, + {glm::ivec4(0x00000100), glm::ivec4( 8)}, + {glm::ivec4(0x00000200), glm::ivec4( 9)}, + {glm::ivec4(0x00000400), glm::ivec4(10)}, + {glm::ivec4(0x00000800), glm::ivec4(11)}, + {glm::ivec4(0x00001000), glm::ivec4(12)}, + {glm::ivec4(0x00002000), glm::ivec4(13)}, + {glm::ivec4(0x00004000), glm::ivec4(14)}, + {glm::ivec4(0x00008000), glm::ivec4(15)}, + {glm::ivec4(0x00010000), glm::ivec4(16)}, + {glm::ivec4(0x00020000), glm::ivec4(17)}, + {glm::ivec4(0x00040000), glm::ivec4(18)}, + {glm::ivec4(0x00080000), glm::ivec4(19)}, + {glm::ivec4(0x00100000), glm::ivec4(20)}, + {glm::ivec4(0x00200000), glm::ivec4(21)}, + {glm::ivec4(0x00400000), glm::ivec4(22)}, + {glm::ivec4(0x00800000), glm::ivec4(23)}, + {glm::ivec4(0x01000000), glm::ivec4(24)}, + {glm::ivec4(0x02000000), glm::ivec4(25)}, + {glm::ivec4(0x04000000), glm::ivec4(26)}, + {glm::ivec4(0x08000000), glm::ivec4(27)}, + {glm::ivec4(0x10000000), glm::ivec4(28)}, + {glm::ivec4(0x20000000), glm::ivec4(29)}, + {glm::ivec4(0x40000000), glm::ivec4(30)} + }; + + int Error(0); + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<glm::ivec4, glm::ivec4>); ++i) + { + glm::ivec4 Result0 = glm::findMSB(Data[i].Value); + Error += glm::all(glm::equal(Data[i].Return, Result0)) ? 0 : 1; + } + + return Error; + } + + static int test_int() + { + typedef type<glm::uint, int> entry; + + entry const Data[] = + { + {0x00000000, -1}, + {0x00000001, 0}, + {0x00000002, 1}, + {0x00000003, 1}, + {0x00000004, 2}, + {0x00000005, 2}, + {0x00000007, 2}, + {0x00000008, 3}, + {0x00000010, 4}, + {0x00000020, 5}, + {0x00000040, 6}, + {0x00000080, 7}, + {0x00000100, 8}, + {0x00000200, 9}, + {0x00000400, 10}, + {0x00000800, 11}, + {0x00001000, 12}, + {0x00002000, 13}, + {0x00004000, 14}, + {0x00008000, 15}, + {0x00010000, 16}, + {0x00020000, 17}, + {0x00040000, 18}, + {0x00080000, 19}, + {0x00100000, 20}, + {0x00200000, 21}, + {0x00400000, 22}, + {0x00800000, 23}, + {0x01000000, 24}, + {0x02000000, 25}, + {0x04000000, 26}, + {0x08000000, 27}, + {0x10000000, 28}, + {0x20000000, 29}, + {0x40000000, 30} + }; + + int Error(0); + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = glm::findMSB(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = findMSB_nlz1(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } +/* + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = findMSB_nlz2(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } +*/ + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = findMSB_095(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } + +# if GLM_HAS_BITSCAN_WINDOWS + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = findMSB_intrinsic(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } +# endif//GLM_HAS_BITSCAN_WINDOWS + + for(std::size_t i = 0; i < sizeof(Data) / sizeof(entry); ++i) + { + int Result0 = findMSB_pop(Data[i].Value); + Error += Data[i].Return == Result0 ? 0 : 1; + } + + return Error; + } + + static int test() + { + int Error(0); + + Error += test_ivec4(); + Error += test_int(); + + return Error; + } + + static int perf(std::size_t Samples) + { + int Error(0); + + Error += perf_int(Samples); + + return Error; + } +}//findMSB + +namespace findLSB +{ + template<typename genType, typename retType> + struct type + { + genType Value; + retType Return; + }; + + typedef type<int, int> entry; + + entry const DataI32[] = + { + {0x00000001, 0}, + {0x00000003, 0}, + {0x00000002, 1}, + // {0x80000000, 31}, // Clang generates an error with this + {0x00010000, 16}, + {0x7FFF0000, 16}, + {0x7F000000, 24}, + {0x7F00FF00, 8}, + {0x00000000, -1} + }; + +# if GLM_HAS_BITSCAN_WINDOWS + template<typename genIUType> + static int findLSB_intrinsic(genIUType Value) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values"); + + if(Value == 0) + return -1; + + unsigned long Result(0); + _BitScanForward(&Result, Value); + return int(Result); + } +# endif + + template<typename genIUType> + static int findLSB_095(genIUType Value) + { + GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values"); + if(Value == 0) + return -1; + + genIUType Bit; + for(Bit = genIUType(0); !(Value & (1 << Bit)); ++Bit){} + return Bit; + } + + template<typename genIUType> + static int findLSB_ntz2(genIUType x) + { + if(x == 0) + return -1; + + return glm::bitCount(~x & (x - static_cast<genIUType>(1))); + } + + template<typename genIUType> + static int findLSB_branchfree(genIUType x) + { + bool IsNull(x == 0); + int const Keep(!IsNull); + int const Discard(IsNull); + + return static_cast<int>(glm::bitCount(~x & (x - static_cast<genIUType>(1)))) * Keep + Discard * -1; + } + + static int test_int() + { + int Error(0); + + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = glm::findLSB(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_095(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + +# if GLM_HAS_BITSCAN_WINDOWS + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_intrinsic(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } +# endif + + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_ntz2(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_branchfree(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + return Error; + } + + static int test() + { + int Error(0); + + Error += test_int(); + + return Error; + } + + static int perf_int(std::size_t Count) + { + int Error(0); + + std::clock_t Timestamps0 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = glm::findLSB(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps1 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_095(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps2 = std::clock(); + +# if GLM_HAS_BITSCAN_WINDOWS + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_intrinsic(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } +# endif + + std::clock_t Timestamps3 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_ntz2(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps4 = std::clock(); + + for(std::size_t k = 0; k < Count; ++k) + for(std::size_t i = 0; i < sizeof(DataI32) / sizeof(entry); ++i) + { + int Result = findLSB_branchfree(DataI32[i].Value); + Error += DataI32[i].Return == Result ? 0 : 1; + } + + std::clock_t Timestamps5 = std::clock(); + + std::printf("glm::findLSB: %d clocks\n", static_cast<int>(Timestamps1 - Timestamps0)); + std::printf("findLSB - 0.9.5: %d clocks\n", static_cast<int>(Timestamps2 - Timestamps1)); + +# if GLM_HAS_BITSCAN_WINDOWS + std::printf("findLSB - intrinsics: %d clocks\n", static_cast<int>(Timestamps3 - Timestamps2)); +# endif + + std::printf("findLSB - ntz2: %d clocks\n", static_cast<int>(Timestamps4 - Timestamps3)); + std::printf("findLSB - branchfree: %d clocks\n", static_cast<int>(Timestamps5 - Timestamps4)); + + return Error; + } + + static int perf(std::size_t Samples) + { + int Error(0); + + Error += perf_int(Samples); + + return Error; + } +}//findLSB + +namespace uaddCarry +{ + static int test() + { + int Error(0); + + { + glm::uint x = std::numeric_limits<glm::uint>::max(); + glm::uint y = 0; + glm::uint Carry = 0; + glm::uint Result = glm::uaddCarry(x, y, Carry); + + Error += Carry == 0 ? 0 : 1; + Error += Result == std::numeric_limits<glm::uint>::max() ? 0 : 1; + } + + { + glm::uint x = std::numeric_limits<glm::uint>::max(); + glm::uint y = 1; + glm::uint Carry = 0; + glm::uint Result = glm::uaddCarry(x, y, Carry); + + Error += Carry == 1 ? 0 : 1; + Error += Result == 0 ? 0 : 1; + } + + { + glm::uvec1 x(std::numeric_limits<glm::uint>::max()); + glm::uvec1 y(0); + glm::uvec1 Carry(0); + glm::uvec1 Result(glm::uaddCarry(x, y, Carry)); + + Error += glm::all(glm::equal(Carry, glm::uvec1(0))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec1(std::numeric_limits<glm::uint>::max()))) ? 0 : 1; + } + + { + glm::uvec1 x(std::numeric_limits<glm::uint>::max()); + glm::uvec1 y(1); + glm::uvec1 Carry(0); + glm::uvec1 Result(glm::uaddCarry(x, y, Carry)); + + Error += glm::all(glm::equal(Carry, glm::uvec1(1))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec1(0))) ? 0 : 1; + } + + return Error; + } +}//namespace uaddCarry + +namespace usubBorrow +{ + static int test() + { + int Error(0); + + { + glm::uint x = 16; + glm::uint y = 17; + glm::uint Borrow = 0; + glm::uint Result = glm::usubBorrow(x, y, Borrow); + + Error += Borrow == 1 ? 0 : 1; + Error += Result == 1 ? 0 : 1; + } + + { + glm::uvec1 x(16); + glm::uvec1 y(17); + glm::uvec1 Borrow(0); + glm::uvec1 Result(glm::usubBorrow(x, y, Borrow)); + + Error += glm::all(glm::equal(Borrow, glm::uvec1(1))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec1(1))) ? 0 : 1; + } + + { + glm::uvec2 x(16); + glm::uvec2 y(17); + glm::uvec2 Borrow(0); + glm::uvec2 Result(glm::usubBorrow(x, y, Borrow)); + + Error += glm::all(glm::equal(Borrow, glm::uvec2(1))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec2(1))) ? 0 : 1; + } + + { + glm::uvec3 x(16); + glm::uvec3 y(17); + glm::uvec3 Borrow(0); + glm::uvec3 Result(glm::usubBorrow(x, y, Borrow)); + + Error += glm::all(glm::equal(Borrow, glm::uvec3(1))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec3(1))) ? 0 : 1; + } + + { + glm::uvec4 x(16); + glm::uvec4 y(17); + glm::uvec4 Borrow(0); + glm::uvec4 Result(glm::usubBorrow(x, y, Borrow)); + + Error += glm::all(glm::equal(Borrow, glm::uvec4(1))) ? 0 : 1; + Error += glm::all(glm::equal(Result, glm::uvec4(1))) ? 0 : 1; + } + + return Error; + } +}//namespace usubBorrow + +namespace umulExtended +{ + static int test() + { + int Error(0); + + { + glm::uint x = 2; + glm::uint y = 3; + glm::uint msb = 0; + glm::uint lsb = 0; + glm::umulExtended(x, y, msb, lsb); + + Error += msb == 0 ? 0 : 1; + Error += lsb == 6 ? 0 : 1; + } + + { + glm::uvec1 x(2); + glm::uvec1 y(3); + glm::uvec1 msb(0); + glm::uvec1 lsb(0); + glm::umulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::uvec1(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::uvec1(6))) ? 0 : 1; + } + + { + glm::uvec2 x(2); + glm::uvec2 y(3); + glm::uvec2 msb(0); + glm::uvec2 lsb(0); + glm::umulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::uvec2(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::uvec2(6))) ? 0 : 1; + } + + { + glm::uvec3 x(2); + glm::uvec3 y(3); + glm::uvec3 msb(0); + glm::uvec3 lsb(0); + glm::umulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::uvec3(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::uvec3(6))) ? 0 : 1; + } + + { + glm::uvec4 x(2); + glm::uvec4 y(3); + glm::uvec4 msb(0); + glm::uvec4 lsb(0); + glm::umulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::uvec4(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::uvec4(6))) ? 0 : 1; + } + + return Error; + } +}//namespace umulExtended + +namespace imulExtended +{ + static int test() + { + int Error(0); + + { + int x = 2; + int y = 3; + int msb = 0; + int lsb = 0; + glm::imulExtended(x, y, msb, lsb); + + Error += msb == 0 ? 0 : 1; + Error += lsb == 6 ? 0 : 1; + } + + { + glm::ivec1 x(2); + glm::ivec1 y(3); + glm::ivec1 msb(0); + glm::ivec1 lsb(0); + glm::imulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::ivec1(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::ivec1(6))) ? 0 : 1; + } + + { + glm::ivec2 x(2); + glm::ivec2 y(3); + glm::ivec2 msb(0); + glm::ivec2 lsb(0); + glm::imulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::ivec2(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::ivec2(6))) ? 0 : 1; + } + + { + glm::ivec3 x(2); + glm::ivec3 y(3); + glm::ivec3 msb(0); + glm::ivec3 lsb(0); + glm::imulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::ivec3(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::ivec3(6))) ? 0 : 1; + } + + { + glm::ivec4 x(2); + glm::ivec4 y(3); + glm::ivec4 msb(0); + glm::ivec4 lsb(0); + glm::imulExtended(x, y, msb, lsb); + + Error += glm::all(glm::equal(msb, glm::ivec4(0))) ? 0 : 1; + Error += glm::all(glm::equal(lsb, glm::ivec4(6))) ? 0 : 1; + } + + return Error; + } +}//namespace imulExtended + +namespace bitCount +{ + template<typename genType> + struct type + { + genType Value; + genType Return; + }; + + type<int> const DataI32[] = + { + {0x00000001, 1}, + {0x00000003, 2}, + {0x00000002, 1}, + {0x7fffffff, 31}, + {0x00000000, 0} + }; + + template<typename T> + inline int bitCount_if(T v) + { + GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitCount' only accept integer values"); + + int Count(0); + for(T i = 0, n = static_cast<T>(sizeof(T) * 8); i < n; ++i) + { + if(v & static_cast<T>(1 << i)) + ++Count; + } + return Count; + } + + template<typename T> + inline int bitCount_vec(T v) + { + GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitCount' only accept integer values"); + + int Count(0); + for(T i = 0, n = static_cast<T>(sizeof(T) * 8); i < n; ++i) + { + Count += static_cast<int>((v >> i) & static_cast<T>(1)); + } + return Count; + } + + template<bool EXEC = false> + struct compute_bitfieldBitCountStep + { + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T, T) + { + return v; + } + }; + + template<> + struct compute_bitfieldBitCountStep<true> + { + template<glm::length_t L, typename T, glm::qualifier Q> + GLM_FUNC_QUALIFIER static glm::vec<L, T, Q> call(glm::vec<L, T, Q> const& v, T Mask, T Shift) + { + return (v & Mask) + ((v >> Shift) & Mask); + } + }; + + template<glm::length_t L, typename T, glm::qualifier Q> + static glm::vec<L, int, Q> bitCount_bitfield(glm::vec<L, T, Q> const& v) + { + glm::vec<L, typename glm::detail::make_unsigned<T>::type, Q> x(*reinterpret_cast<glm::vec<L, typename glm::detail::make_unsigned<T>::type, Q> const *>(&v)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 2>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x5555555555555555ull), static_cast<typename glm::detail::make_unsigned<T>::type>( 1)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 4>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x3333333333333333ull), static_cast<typename glm::detail::make_unsigned<T>::type>( 2)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 8>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x0F0F0F0F0F0F0F0Full), static_cast<typename glm::detail::make_unsigned<T>::type>( 4)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 16>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x00FF00FF00FF00FFull), static_cast<typename glm::detail::make_unsigned<T>::type>( 8)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 32>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x0000FFFF0000FFFFull), static_cast<typename glm::detail::make_unsigned<T>::type>(16)); + x = compute_bitfieldBitCountStep<sizeof(T) * 8 >= 64>::call(x, static_cast<typename glm::detail::make_unsigned<T>::type>(0x00000000FFFFFFFFull), static_cast<typename glm::detail::make_unsigned<T>::type>(32)); + return glm::vec<L, int, Q>(x); + } + + template<typename genType> + static int bitCount_bitfield(genType x) + { + return bitCount_bitfield(glm::vec<1, genType, glm::defaultp>(x)).x; + } + + static int perf(std::size_t Size) + { + int Error(0); + + std::vector<int> v; + v.resize(Size); + + std::vector<glm::ivec4> w; + w.resize(Size); + + + std::clock_t TimestampsA = std::clock(); + + // bitCount - TimeIf + { + for(std::size_t i = 0, n = v.size(); i < n; ++i) + v[i] = bitCount_if(static_cast<int>(i)); + } + + std::clock_t TimestampsB = std::clock(); + + // bitCount - TimeVec + { + for(std::size_t i = 0, n = v.size(); i < n; ++i) + v[i] = bitCount_vec(i); + } + + std::clock_t TimestampsC = std::clock(); + + // bitCount - TimeDefault + { + for(std::size_t i = 0, n = v.size(); i < n; ++i) + v[i] = glm::bitCount(i); + } + + std::clock_t TimestampsD = std::clock(); + + // bitCount - TimeVec4 + { + for(std::size_t i = 0, n = v.size(); i < n; ++i) + w[i] = glm::bitCount(glm::ivec4(static_cast<int>(i))); + } + + std::clock_t TimestampsE = std::clock(); + + { + for(std::size_t i = 0, n = v.size(); i < n; ++i) + v[i] = bitCount_bitfield(static_cast<int>(i)); + } + + std::clock_t TimestampsF = std::clock(); + + std::printf("bitCount - TimeIf %d\n", static_cast<int>(TimestampsB - TimestampsA)); + std::printf("bitCount - TimeVec %d\n", static_cast<int>(TimestampsC - TimestampsB)); + std::printf("bitCount - TimeDefault %d\n", static_cast<int>(TimestampsD - TimestampsC)); + std::printf("bitCount - TimeVec4 %d\n", static_cast<int>(TimestampsE - TimestampsD)); + std::printf("bitCount - bitfield %d\n", static_cast<int>(TimestampsF - TimestampsE)); + + return Error; + } + + static int test() + { + int Error(0); + + for(std::size_t i = 0, n = sizeof(DataI32) / sizeof(type<int>); i < n; ++i) + { + int ResultA = glm::bitCount(DataI32[i].Value); + int ResultB = bitCount_if(DataI32[i].Value); + int ResultC = bitCount_vec(DataI32[i].Value); + int ResultE = bitCount_bitfield(DataI32[i].Value); + + Error += DataI32[i].Return == ResultA ? 0 : 1; + Error += DataI32[i].Return == ResultB ? 0 : 1; + Error += DataI32[i].Return == ResultC ? 0 : 1; + Error += DataI32[i].Return == ResultE ? 0 : 1; + + assert(!Error); + } + + return Error; + } +}//bitCount + +int main() +{ + int Error = 0; + + Error += ::bitCount::test(); + Error += ::bitfieldReverse::test(); + Error += ::findMSB::test(); + Error += ::findLSB::test(); + Error += ::umulExtended::test(); + Error += ::imulExtended::test(); + Error += ::uaddCarry::test(); + Error += ::usubBorrow::test(); + Error += ::bitfieldInsert::test(); + Error += ::bitfieldExtract::test(); + +# ifdef NDEBUG + std::size_t const Samples = 1000; +# else + std::size_t const Samples = 1; +# endif + + ::bitCount::perf(Samples); + ::bitfieldReverse::perf(Samples); + ::findMSB::perf(Samples); + ::findLSB::perf(Samples); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_func_integer_bit_count.cpp b/3rdparty/glm/source/test/core/core_func_integer_bit_count.cpp new file mode 100644 index 0000000..0fa11fb --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_integer_bit_count.cpp @@ -0,0 +1,291 @@ +// This has the programs for computing the number of 1-bits +// in a word, or byte, etc. +// Max line length is 57, to fit in hacker.book. +#include <cstdio> +#include <cstdlib> //To define "exit", req'd by XLC. +#include <ctime> + +unsigned rotatel(unsigned x, int n) +{ + if (static_cast<unsigned>(n) > 63) { std::printf("rotatel, n out of range.\n"); std::exit(1);} + return (x << n) | (x >> (32 - n)); +} + +int pop0(unsigned x) +{ + x = (x & 0x55555555) + ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); + x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); + x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF); + return x; +} + +int pop1(unsigned x) +{ + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x >> 8); + x = x + (x >> 16); + return x & 0x0000003F; +} +/* Note: an alternative to the last three executable lines above is: + return x*0x01010101 >> 24; +if your machine has a fast multiplier (suggested by Jari Kirma). */ + +int pop2(unsigned x) +{ + unsigned n; + + n = (x >> 1) & 033333333333; // Count bits in + x = x - n; // each 3-bit + n = (n >> 1) & 033333333333; // field. + x = x - n; + x = (x + (x >> 3)) & 030707070707; // 6-bit sums. + return x%63; // Add 6-bit sums. +} + +/* An alternative to the "return" statement above is: + return ((x * 0404040404) >> 26) + // Add 6-bit sums. + (x >> 30); +which runs faster on most machines (suggested by Norbert Juffa). */ + +int pop3(unsigned x) +{ + unsigned n; + + n = (x >> 1) & 0x77777777; // Count bits in + x = x - n; // each 4-bit + n = (n >> 1) & 0x77777777; // field. + x = x - n; + n = (n >> 1) & 0x77777777; + x = x - n; + x = (x + (x >> 4)) & 0x0F0F0F0F; // Get byte sums. + x = x*0x01010101; // Add the bytes. + return x >> 24; +} + +int pop4(unsigned x) +{ + int n; + + n = 0; + while (x != 0) { + n = n + 1; + x = x & (x - 1); + } + return n; +} + +int pop5(unsigned x) +{ + int i, sum; + + // Rotate and sum method // Shift right & subtract + + sum = x; // sum = x; + for (i = 1; i <= 31; i++) { // while (x != 0) { + x = rotatel(x, 1); // x = x >> 1; + sum = sum + x; // sum = sum - x; + } // } + return -sum; // return sum; +} + +int pop5a(unsigned x) +{ + int sum; + + // Shift right & subtract + + sum = x; + while (x != 0) { + x = x >> 1; + sum = sum - x; + } + return sum; +} + +int pop6(unsigned x) +{ // Table lookup. + static char table[256] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; + + return table[x & 0xFF] + + table[(x >> 8) & 0xFF] + + table[(x >> 16) & 0xFF] + + table[(x >> 24)]; +} + +// The following works only for 8-bit quantities. +int pop7(unsigned x) +{ + x = x*0x08040201; // Make 4 copies. + x = x >> 3; // So next step hits proper bits. + x = x & 0x11111111; // Every 4th bit. + x = x*0x11111111; // Sum the digits (each 0 or 1). + x = x >> 28; // Position the result. + return x; +} + +// The following works only for 7-bit quantities. +int pop8(unsigned x) +{ + x = x*0x02040810; // Make 4 copies, left-adjusted. + x = x & 0x11111111; // Every 4th bit. + x = x*0x11111111; // Sum the digits (each 0 or 1). + x = x >> 28; // Position the result. + return x; +} + +// The following works only for 15-bit quantities. +int pop9(unsigned x) +{ + unsigned long long y; + y = x * 0x0002000400080010ULL; + y = y & 0x1111111111111111ULL; + y = y * 0x1111111111111111ULL; + y = y >> 60; + return static_cast<int>(y); +} + +int errors; +void error(int x, int y) +{ + errors = errors + 1; + std::printf("Error for x = %08x, got %08x\n", x, y); +} + +int main() +{ +# ifdef NDEBUG + + int i, n; + static unsigned test[] = {0,0, 1,1, 2,1, 3,2, 4,1, 5,2, 6,2, 7,3, + 8,1, 9,2, 10,2, 11,3, 12,2, 13,3, 14,3, 15,4, 16,1, 17,2, + 0x3F,6, 0x40,1, 0x41,2, 0x7f,7, 0x80,1, 0x81,2, 0xfe,7, 0xff,8, + 0x4000,1, 0x4001,2, 0x7000,3, 0x7fff,15, + 0x55555555,16, 0xAAAAAAAA, 16, 0xFF000000,8, 0xC0C0C0C0,8, + 0x0FFFFFF0,24, 0x80000000,1, 0xFFFFFFFF,32}; + + std::size_t const Count = 1000000; + + n = sizeof(test)/4; + + std::clock_t TimestampBeg = 0; + std::clock_t TimestampEnd = 0; + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop0(test[i]) != test[i+1]) error(test[i], pop0(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop0: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop1(test[i]) != test[i+1]) error(test[i], pop1(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop2(test[i]) != test[i+1]) error(test[i], pop2(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop3(test[i]) != test[i+1]) error(test[i], pop3(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop4(test[i]) != test[i+1]) error(test[i], pop4(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop5(test[i]) != test[i+1]) error(test[i], pop5(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop5a(test[i]) != test[i+1]) error(test[i], pop5a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop5a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (pop6(test[i]) != test[i+1]) error(test[i], pop6(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if ((test[i] & 0xffffff00) == 0) + if (pop7(test[i]) != test[i+1]) error(test[i], pop7(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if ((test[i] & 0xffffff80) == 0) + if (pop8(test[i]) != test[i+1]) error(test[i], pop8(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if ((test[i] & 0xffff8000) == 0) + if (pop9(test[i]) != test[i+1]) error(test[i], pop9(test[i]));} + TimestampEnd = std::clock(); + + std::printf("pop9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + if (errors == 0) + std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8)); + +# endif//NDEBUG +} diff --git a/3rdparty/glm/source/test/core/core_func_integer_find_lsb.cpp b/3rdparty/glm/source/test/core/core_func_integer_find_lsb.cpp new file mode 100644 index 0000000..7b42d33 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_integer_find_lsb.cpp @@ -0,0 +1,416 @@ +#include <glm/glm.hpp> +#include <cstdio> +#include <cstdlib> //To define "exit", req'd by XLC. +#include <ctime> + +int nlz(unsigned x) +{ + int pop(unsigned x); + + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + return pop(~x); +} + +int pop(unsigned x) +{ + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + return x >> 24; +} + +int ntz1(unsigned x) +{ + return 32 - nlz(~x & (x-1)); +} + +int ntz2(unsigned x) +{ + return pop(~x & (x - 1)); +} + +int ntz3(unsigned x) +{ + int n; + + if (x == 0) return(32); + n = 1; + if ((x & 0x0000FFFF) == 0) {n = n +16; x = x >>16;} + if ((x & 0x000000FF) == 0) {n = n + 8; x = x >> 8;} + if ((x & 0x0000000F) == 0) {n = n + 4; x = x >> 4;} + if ((x & 0x00000003) == 0) {n = n + 2; x = x >> 2;} + return n - (x & 1); +} + +int ntz4(unsigned x) +{ + unsigned y; + int n; + + if (x == 0) return 32; + n = 31; + y = x <<16; if (y != 0) {n = n -16; x = y;} + y = x << 8; if (y != 0) {n = n - 8; x = y;} + y = x << 4; if (y != 0) {n = n - 4; x = y;} + y = x << 2; if (y != 0) {n = n - 2; x = y;} + y = x << 1; if (y != 0) {n = n - 1;} + return n; +} + +int ntz4a(unsigned x) +{ + unsigned y; + int n; + + if (x == 0) return 32; + n = 31; + y = x <<16; if (y != 0) {n = n -16; x = y;} + y = x << 8; if (y != 0) {n = n - 8; x = y;} + y = x << 4; if (y != 0) {n = n - 4; x = y;} + y = x << 2; if (y != 0) {n = n - 2; x = y;} + n = n - ((x << 1) >> 31); + return n; +} + +int ntz5(char x) +{ + if (x & 15) { + if (x & 3) { + if (x & 1) return 0; + else return 1; + } + else if (x & 4) return 2; + else return 3; + } + else if (x & 0x30) { + if (x & 0x10) return 4; + else return 5; + } + else if (x & 0x40) return 6; + else if (x) return 7; + else return 8; +} + +int ntz6(unsigned x) +{ + int n; + + x = ~x & (x - 1); + n = 0; // n = 32; + while(x != 0) + { // while (x != 0) { + n = n + 1; // n = n - 1; + x = x >> 1; // x = x + x; + } // } + return n; // return n; +} + +int ntz6a(unsigned x) +{ + int n = 32; + + while (x != 0) { + n = n - 1; + x = x + x; + } + return n; +} + +/* Dean Gaudet's algorithm. To be most useful there must be a good way +to evaluate the C "conditional expression" (a?b:c construction) without +branching. The result of a?b:c is b if a is true (nonzero), and c if a +is false (0). + For example, a compare to zero op that sets a target GPR to 1 if the +operand is 0, and to 0 if the operand is nonzero, will do it. With this +instruction, the algorithm is entirely branch-free. But the most +interesting thing about it is the high degree of parallelism. All six +lines with conditional expressions can be executed in parallel (on a +machine with sufficient computational units). + Although the instruction count is 30 measured statically, it could +execute in only 10 cycles on a machine with sufficient parallelism. + The first two uses of y can instead be x, which would increase the +useful parallelism on most machines (the assignments to y, bz, and b4 +could then all run in parallel). */ + +int ntz7(unsigned x) +{ + unsigned y, bz, b4, b3, b2, b1, b0; + + y = x & -x; // Isolate rightmost 1-bit. + bz = y ? 0 : 1; // 1 if y = 0. + b4 = (y & 0x0000FFFF) ? 0 : 16; + b3 = (y & 0x00FF00FF) ? 0 : 8; + b2 = (y & 0x0F0F0F0F) ? 0 : 4; + b1 = (y & 0x33333333) ? 0 : 2; + b0 = (y & 0x55555555) ? 0 : 1; + return bz + b4 + b3 + b2 + b1 + b0; +} + +// This file has divisions by zero to test isnan +#if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(disable : 4800) +#endif + +int ntz7_christophe(unsigned x) +{ + unsigned y, bz, b4, b3, b2, b1, b0; + + y = x & -x; // Isolate rightmost 1-bit. + bz = unsigned(!bool(y)); // 1 if y = 0. + b4 = unsigned(!bool(y & 0x0000FFFF)) * 16; + b3 = unsigned(!bool(y & 0x00FF00FF)) * 8; + b2 = unsigned(!bool(y & 0x0F0F0F0F)) * 4; + b1 = unsigned(!bool(y & 0x33333333)) * 2; + b0 = unsigned(!bool(y & 0x55555555)) * 1; + return bz + b4 + b3 + b2 + b1 + b0; +} + +/* Below is David Seal's algorithm, found at +http://www.ciphersbyritter.com/NEWS4/BITCT.HTM Table +entries marked "u" are unused. 6 ops including a +multiply, plus an indexed load. */ + +#define u 99 +int ntz8(unsigned x) +{ + static char table[64] = + {32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14, + 10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15, + 31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26, + 30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u}; + + x = (x & -x)*0x0450FBAF; + return table[x >> 26]; +} + +/* Seal's algorithm with multiply expanded. +9 elementary ops plus an indexed load. */ + +int ntz8a(unsigned x) +{ + static char table[64] = + {32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14, + 10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15, + 31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26, + 30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u}; + + x = (x & -x); + x = (x << 4) + x; // x = x*17. + x = (x << 6) + x; // x = x*65. + x = (x << 16) - x; // x = x*65535. + return table[x >> 26]; +} + +/* Reiser's algorithm. Three ops including a "remainder," +plus an indexed load. */ + +int ntz9(unsigned x) +{ + static char table[37] = { + 32, 0, 1, 26, 2, 23, 27, + u, 3, 16, 24, 30, 28, 11, u, 13, 4, + 7, 17, u, 25, 22, 31, 15, 29, 10, 12, + 6, u, 21, 14, 9, 5, 20, 8, 19, 18}; + + x = (x & -x)%37; + return table[x]; +} + +/* Using a de Bruijn sequence. This is a table lookup with a 32-entry +table. The de Bruijn sequence used here is + 0000 0100 1101 0111 0110 0101 0001 1111, +obtained from Danny Dube's October 3, 1997, posting in +comp.compression.research. Thanks to Norbert Juffa for this reference. */ + +int ntz10(unsigned x) { + + static char table[32] = + { 0, 1, 2,24, 3,19, 6,25, 22, 4,20,10,16, 7,12,26, + 31,23,18, 5,21, 9,15,11, 30,17, 8,14,29,13,28,27}; + + if (x == 0) return 32; + x = (x & -x)*0x04D7651F; + return table[x >> 27]; +} + +/* Norbert Juffa's code, answer to exercise 1 of Chapter 5 (2nd ed). */ + +#define SLOW_MUL +int ntz11 (unsigned int n) { + + static unsigned char tab[32] = + { 0, 1, 2, 24, 3, 19, 6, 25, + 22, 4, 20, 10, 16, 7, 12, 26, + 31, 23, 18, 5, 21, 9, 15, 11, + 30, 17, 8, 14, 29, 13, 28, 27 + }; + unsigned int k; + n = n & (-n); /* isolate lsb */ + printf("n = %d\n", n); +#if defined(SLOW_MUL) + k = (n << 11) - n; + k = (k << 2) + k; + k = (k << 8) + n; + k = (k << 5) - k; +#else + k = n * 0x4d7651f; +#endif + return n ? tab[k>>27] : 32; +} + +int errors; +void error(int x, int y) { + errors = errors + 1; + std::printf("Error for x = %08x, got %d\n", x, y); +} + +int main() +{ +# ifdef NDEBUG + + int i, m, n; + static unsigned test[] = {0,32, 1,0, 2,1, 3,0, 4,2, 5,0, 6,1, 7,0, + 8,3, 9,0, 16,4, 32,5, 64,6, 128,7, 255,0, 256,8, 512,9, 1024,10, + 2048,11, 4096,12, 8192,13, 16384,14, 32768,15, 65536,16, + 0x20000,17, 0x40000,18, 0x80000,19, 0x100000,20, 0x200000,21, + 0x400000,22, 0x800000,23, 0x1000000,24, 0x2000000,25, + 0x4000000,26, 0x8000000,27, 0x10000000,28, 0x20000000,29, + 0x40000000,30, 0x80000000,31, 0xFFFFFFF0,4, 0x3000FF00,8, + 0xC0000000,30, 0x60000000,29, 0x00011000, 12}; + + std::size_t const Count = 1000; + + n = sizeof(test)/4; + + std::clock_t TimestampBeg = 0; + std::clock_t TimestampEnd = 0; + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz1(test[i]) != test[i+1]) error(test[i], ntz1(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz2(test[i]) != test[i+1]) error(test[i], ntz2(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz3(test[i]) != test[i+1]) error(test[i], ntz3(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz4(test[i]) != test[i+1]) error(test[i], ntz4(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz4a(test[i]) != test[i+1]) error(test[i], ntz4a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz4a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for(std::size_t k = 0; k < Count; ++k) + for(i = 0; i < n; i += 2) + { + m = test[i+1]; + if(m > 8) + m = 8; + if(ntz5(static_cast<char>(test[i])) != m) + error(test[i], ntz5(static_cast<char>(test[i]))); + } + TimestampEnd = std::clock(); + + std::printf("ntz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz6(test[i]) != test[i+1]) error(test[i], ntz6(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz6a(test[i]) != test[i+1]) error(test[i], ntz6a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz6a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz7(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz7_christophe(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz7_christophe: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz8(test[i]) != test[i+1]) error(test[i], ntz8(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz8a(test[i]) != test[i+1]) error(test[i], ntz8a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz8a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz9(test[i]) != test[i+1]) error(test[i], ntz9(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (ntz10(test[i]) != test[i+1]) error(test[i], ntz10(test[i]));} + TimestampEnd = std::clock(); + + std::printf("ntz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + if (errors == 0) + std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8)); + +# endif//NDEBUG +} diff --git a/3rdparty/glm/source/test/core/core_func_integer_find_msb.cpp b/3rdparty/glm/source/test/core/core_func_integer_find_msb.cpp new file mode 100644 index 0000000..c435467 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_integer_find_msb.cpp @@ -0,0 +1,440 @@ +#include <glm/glm.hpp> +#include <cstdio> +#include <cstdlib> // To define "exit", req'd by XLC. +#include <ctime> + +#define LE 1 // 1 for little-endian, 0 for big-endian. + +int pop(unsigned x) { + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + return x >> 24; +} + +int nlz1(unsigned x) { + int n; + + if (x == 0) return(32); + n = 0; + if (x <= 0x0000FFFF) {n = n +16; x = x <<16;} + if (x <= 0x00FFFFFF) {n = n + 8; x = x << 8;} + if (x <= 0x0FFFFFFF) {n = n + 4; x = x << 4;} + if (x <= 0x3FFFFFFF) {n = n + 2; x = x << 2;} + if (x <= 0x7FFFFFFF) {n = n + 1;} + return n; +} + +int nlz1a(unsigned x) { + int n; + +/* if (x == 0) return(32); */ + if (static_cast<int>(x) <= 0) return (~x >> 26) & 32; + n = 1; + if ((x >> 16) == 0) {n = n +16; x = x <<16;} + if ((x >> 24) == 0) {n = n + 8; x = x << 8;} + if ((x >> 28) == 0) {n = n + 4; x = x << 4;} + if ((x >> 30) == 0) {n = n + 2; x = x << 2;} + n = n - (x >> 31); + return n; +} +// On basic Risc, 12 to 20 instructions. + +int nlz2(unsigned x) { + unsigned y; + int n; + + n = 32; + y = x >>16; if (y != 0) {n = n -16; x = y;} + y = x >> 8; if (y != 0) {n = n - 8; x = y;} + y = x >> 4; if (y != 0) {n = n - 4; x = y;} + y = x >> 2; if (y != 0) {n = n - 2; x = y;} + y = x >> 1; if (y != 0) return n - 2; + return n - x; +} + +// As above but coded as a loop for compactness: +// 23 to 33 basic Risc instructions. +int nlz2a(unsigned x) { + unsigned y; + int n, c; + + n = 32; + c = 16; + do { + y = x >> c; if (y != 0) {n = n - c; x = y;} + c = c >> 1; + } while (c != 0); + return n - x; +} + +int nlz3(int x) { + int y, n; + + n = 0; + y = x; +L: if (x < 0) return n; + if (y == 0) return 32 - n; + n = n + 1; + x = x << 1; + y = y >> 1; + goto L; +} + +int nlz4(unsigned x) { + int y, m, n; + + y = -(x >> 16); // If left half of x is 0, + m = (y >> 16) & 16; // set n = 16. If left half + n = 16 - m; // is nonzero, set n = 0 and + x = x >> m; // shift x right 16. + // Now x is of the form 0000xxxx. + y = x - 0x100; // If positions 8-15 are 0, + m = (y >> 16) & 8; // add 8 to n and shift x left 8. + n = n + m; + x = x << m; + + y = x - 0x1000; // If positions 12-15 are 0, + m = (y >> 16) & 4; // add 4 to n and shift x left 4. + n = n + m; + x = x << m; + + y = x - 0x4000; // If positions 14-15 are 0, + m = (y >> 16) & 2; // add 2 to n and shift x left 2. + n = n + m; + x = x << m; + + y = x >> 14; // Set y = 0, 1, 2, or 3. + m = y & ~(y >> 1); // Set m = 0, 1, 2, or 2 resp. + return n + 2 - m; +} + +int nlz5(unsigned x) { + int pop(unsigned x); + + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + return pop(~x); +} + +/* The four programs below are not valid ANSI C programs. This is +because they refer to the same storage locations as two different types. +However, they work with xlc/AIX, gcc/AIX, and gcc/NT. If you try to +code them more compactly by declaring a variable xx to be "double," and +then using + + n = 1054 - (*((unsigned *)&xx + LE) >> 20); + +then you are violating not only the rule above, but also the ANSI C +rule that pointer arithmetic can be performed only on pointers to +array elements. + When coded with the above statement, the program fails with xlc, +gcc/AIX, and gcc/NT, at some optimization levels. + BTW, these programs use the "anonymous union" feature of C++, not +available in C. */ + +int nlz6(unsigned k) +{ + union { + unsigned asInt[2]; + double asDouble; + }; + int n; + + asDouble = static_cast<double>(k) + 0.5; + n = 1054 - (asInt[LE] >> 20); + return n; +} + +int nlz7(unsigned k) +{ + union { + unsigned asInt[2]; + double asDouble; + }; + int n; + + asDouble = static_cast<double>(k); + n = 1054 - (asInt[LE] >> 20); + n = (n & 31) + (n >> 9); + return n; +} + + /* In single qualifier, round-to-nearest mode, the basic method fails for: + k = 0, k = 01FFFFFF, 03FFFFFE <= k <= 03FFFFFF, + 07FFFFFC <= k <= 07FFFFFF, + 0FFFFFF8 <= k <= 0FFFFFFF, + ... + 7FFFFFC0 <= k <= 7FFFFFFF. + FFFFFF80 <= k <= FFFFFFFF. + For k = 0 it gives 158, and for the other values it is too low by 1. */ + +int nlz8(unsigned k) +{ + union { + unsigned asInt; + float asFloat; + }; + int n; + + k = k & ~(k >> 1); /* Fix problem with rounding. */ + asFloat = static_cast<float>(k) + 0.5f; + n = 158 - (asInt >> 23); + return n; +} + +/* The example below shows how to make a macro for nlz. It uses an +extension to the C and C++ languages that is provided by the GNU C/C++ +compiler, namely, that of allowing statements and declarations in +expressions (see "Using and Porting GNU CC", by Richard M. Stallman +(1998). The underscores are necessary to protect against the +possibility that the macro argument will conflict with one of its local +variables, e.g., NLZ(k). */ + +int nlz9(unsigned k) +{ + union { + unsigned asInt; + float asFloat; + }; + int n; + + k = k & ~(k >> 1); /* Fix problem with rounding. */ + asFloat = static_cast<float>(k); + n = 158 - (asInt >> 23); + n = (n & 31) + (n >> 6); /* Fix problem with k = 0. */ + return n; +} + +/* Below are three nearly equivalent programs for computing the number +of leading zeros in a word. This material is not in HD, but may be in a +future edition. + Immediately below is Robert Harley's algorithm, found at the +comp.arch newsgroup entry dated 7/12/96, pointed out to me by Norbert +Juffa. + Table entries marked "u" are unused. 14 ops including a multiply, +plus an indexed load. + The smallest multiplier that works is 0x045BCED1 = 17*65*129*513 (all +of form 2**k + 1). There are no multipliers of three terms of the form +2**k +- 1 that work, with a table size of 64 or 128. There are some, +with a table size of 64, if you precede the multiplication with x = x - +(x >> 1), but that seems less elegant. There are also some if you use a +table size of 256, the smallest is 0x01033CBF = 65*255*1025 (this would +save two instructions in the form of this algorithm with the +multiplication expanded into shifts and adds, but the table size is +getting a bit large). */ + +#define u 99 +int nlz10(unsigned x) +{ + static char table[64] = + {32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u, + u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u, + 17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18, + 5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u}; + + x = x | (x >> 1); // Propagate leftmost + x = x | (x >> 2); // 1-bit to the right. + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + x = x*0x06EB14F9; // Multiplier is 7*255**3. + return table[x >> 26]; +} + +/* Harley's algorithm with multiply expanded. +19 elementary ops plus an indexed load. */ + +int nlz10a(unsigned x) +{ + static char table[64] = + {32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u, + u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u, + 17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18, + 5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u}; + + x = x | (x >> 1); // Propagate leftmost + x = x | (x >> 2); // 1-bit to the right. + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >> 16); + x = (x << 3) - x; // Multiply by 7. + x = (x << 8) - x; // Multiply by 255. + x = (x << 8) - x; // Again. + x = (x << 8) - x; // Again. + return table[x >> 26]; +} + +/* Julius Goryavsky's version of Harley's algorithm. +17 elementary ops plus an indexed load, if the machine +has "and not." */ + +int nlz10b(unsigned x) +{ + static char table[64] = + {32,20,19, u, u,18, u, 7, 10,17, u, u,14, u, 6, u, + u, 9, u,16, u, u, 1,26, u,13, u, u,24, 5, u, u, + u,21, u, 8,11, u,15, u, u, u, u, 2,27, 0,25, u, + 22, u,12, u, u, 3,28, u, 23, u, 4,29, u, u,30,31}; + + x = x | (x >> 1); // Propagate leftmost + x = x | (x >> 2); // 1-bit to the right. + x = x | (x >> 4); + x = x | (x >> 8); + x = x & ~(x >> 16); + x = x*0xFD7049FF; // Activate this line or the following 3. + // x = (x << 9) - x; // Multiply by 511. + // x = (x << 11) - x; // Multiply by 2047. + // x = (x << 14) - x; // Multiply by 16383. + return table[x >> 26]; +} + +int errors; +void error(int x, int y) +{ + errors = errors + 1; + std::printf("Error for x = %08x, got %d\n", x, y); +} + +int main() +{ +# ifdef NDEBUG + + int i, n; + static unsigned test[] = {0,32, 1,31, 2,30, 3,30, 4,29, 5,29, 6,29, + 7,29, 8,28, 9,28, 16,27, 32,26, 64,25, 128,24, 255,24, 256,23, + 512,22, 1024,21, 2048,20, 4096,19, 8192,18, 16384,17, 32768,16, + 65536,15, 0x20000,14, 0x40000,13, 0x80000,12, 0x100000,11, + 0x200000,10, 0x400000,9, 0x800000,8, 0x1000000,7, 0x2000000,6, + 0x4000000,5, 0x8000000,4, 0x0FFFFFFF,4, 0x10000000,3, + 0x3000FFFF,2, 0x50003333,1, 0x7FFFFFFF,1, 0x80000000,0, + 0xFFFFFFFF,0}; + std::size_t const Count = 1000; + + n = sizeof(test)/4; + + std::clock_t TimestampBeg = 0; + std::clock_t TimestampEnd = 0; + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz1(test[i]) != test[i+1]) error(test[i], nlz1(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz1a(test[i]) != test[i+1]) error(test[i], nlz1a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz1a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz2(test[i]) != test[i+1]) error(test[i], nlz2(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz2a(test[i]) != test[i+1]) error(test[i], nlz2a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz2a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz3(test[i]) != test[i+1]) error(test[i], nlz3(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz4(test[i]) != test[i+1]) error(test[i], nlz4(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz5(test[i]) != test[i+1]) error(test[i], nlz5(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz6(test[i]) != test[i+1]) error(test[i], nlz6(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz7(test[i]) != test[i+1]) error(test[i], nlz7(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz8(test[i]) != test[i+1]) error(test[i], nlz8(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz9(test[i]) != test[i+1]) error(test[i], nlz9(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz10(test[i]) != test[i+1]) error(test[i], nlz10(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz10a(test[i]) != test[i+1]) error(test[i], nlz10a(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz10a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + TimestampBeg = std::clock(); + for (std::size_t k = 0; k < Count; ++k) + for (i = 0; i < n; i += 2) { + if (nlz10b(test[i]) != test[i+1]) error(test[i], nlz10b(test[i]));} + TimestampEnd = std::clock(); + + std::printf("nlz10b: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg)); + + if (errors == 0) + std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8)); + +# endif//NDEBUG +} diff --git a/3rdparty/glm/source/test/core/core_func_matrix.cpp b/3rdparty/glm/source/test/core/core_func_matrix.cpp new file mode 100644 index 0000000..c5b2007 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_matrix.cpp @@ -0,0 +1,312 @@ +#include <glm/ext/matrix_relational.hpp> +#include <glm/ext/matrix_transform.hpp> +#include <glm/ext/scalar_constants.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> +#include <ctime> +#include <cstdio> + +using namespace glm; + +int test_matrixCompMult() +{ + int Error(0); + + { + mat2 m(0, 1, 2, 3); + mat2 n = matrixCompMult(m, m); + mat2 expected = mat2(0, 1, 4, 9); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat2x3 m(0, 1, 2, 3, 4, 5); + mat2x3 n = matrixCompMult(m, m); + mat2x3 expected = mat2x3(0, 1, 4, 9, 16, 25); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); + mat2x4 n = matrixCompMult(m, m); + mat2x4 expected = mat2x4(0, 1, 4, 9, 16, 25, 36, 49); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); + mat3 n = matrixCompMult(m, m); + mat3 expected = mat3(0, 1, 4, 9, 16, 25, 36, 49, 64); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3x2 m(0, 1, 2, 3, 4, 5); + mat3x2 n = matrixCompMult(m, m); + mat3x2 expected = mat3x2(0, 1, 4, 9, 16, 25); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat3x4 n = matrixCompMult(m, m); + mat3x4 expected = mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + mat4 n = matrixCompMult(m, m); + mat4 expected = mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); + mat4x2 n = matrixCompMult(m, m); + mat4x2 expected = mat4x2(0, 1, 4, 9, 16, 25, 36, 49); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat4x3 n = matrixCompMult(m, m); + mat4x3 expected = mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121); + Error += all(equal(n, expected, epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +int test_outerProduct() +{ + { glm::mat2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec2(1.0f)); } + { glm::mat3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec3(1.0f)); } + { glm::mat4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec4(1.0f)); } + + { glm::mat2x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec2(1.0f)); } + { glm::mat2x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec2(1.0f)); } + + { glm::mat3x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec3(1.0f)); } + { glm::mat3x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec3(1.0f)); } + + { glm::mat4x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec4(1.0f)); } + { glm::mat4x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec4(1.0f)); } + + return 0; +} + +int test_transpose() +{ + int Error(0); + + { + mat2 const m(0, 1, 2, 3); + mat2 const t = transpose(m); + mat2 const expected = mat2(0, 2, 1, 3); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat2x3 m(0, 1, 2, 3, 4, 5); + mat3x2 t = transpose(m); + mat3x2 const expected = mat3x2(0, 3, 1, 4, 2, 5); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); + mat4x2 t = transpose(m); + mat4x2 const expected = mat4x2(0, 4, 1, 5, 2, 6, 3, 7); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); + mat3 t = transpose(m); + mat3 const expected = mat3(0, 3, 6, 1, 4, 7, 2, 5, 8); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3x2 m(0, 1, 2, 3, 4, 5); + mat2x3 t = transpose(m); + mat2x3 const expected = mat2x3(0, 2, 4, 1, 3, 5); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat4x3 t = transpose(m); + mat4x3 const expected = mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + mat4 t = transpose(m); + mat4 const expected = mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); + mat2x4 t = transpose(m); + mat2x4 const expected = mat2x4(0, 2, 4, 6, 1, 3, 5, 7); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + { + mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat3x4 t = transpose(m); + mat3x4 const expected = mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11); + Error += all(equal(t, expected, epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +int test_determinant() +{ + + + return 0; +} + +int test_inverse() +{ + int Error = 0; + + { + glm::mat4x4 A4x4( + glm::vec4(1, 0, 1, 0), + glm::vec4(0, 1, 0, 0), + glm::vec4(0, 0, 1, 0), + glm::vec4(0, 0, 0, 1)); + glm::mat4x4 B4x4 = inverse(A4x4); + glm::mat4x4 I4x4 = A4x4 * B4x4; + glm::mat4x4 Identity(1); + Error += all(equal(I4x4, Identity, epsilon<float>())) ? 0 : 1; + } + + { + glm::mat3x3 A3x3( + glm::vec3(1, 0, 1), + glm::vec3(0, 1, 0), + glm::vec3(0, 0, 1)); + glm::mat3x3 B3x3 = glm::inverse(A3x3); + glm::mat3x3 I3x3 = A3x3 * B3x3; + glm::mat3x3 Identity(1); + Error += all(equal(I3x3, Identity, epsilon<float>())) ? 0 : 1; + } + + { + glm::mat2x2 A2x2( + glm::vec2(1, 1), + glm::vec2(0, 1)); + glm::mat2x2 B2x2 = glm::inverse(A2x2); + glm::mat2x2 I2x2 = A2x2 * B2x2; + glm::mat2x2 Identity(1); + Error += all(equal(I2x2, Identity, epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +int test_inverse_simd() +{ + int Error = 0; + + glm::mat4x4 const Identity(1); + + glm::mat4x4 const A4x4( + glm::vec4(1, 0, 1, 0), + glm::vec4(0, 1, 0, 0), + glm::vec4(0, 0, 1, 0), + glm::vec4(0, 0, 0, 1)); + glm::mat4x4 const B4x4 = glm::inverse(A4x4); + glm::mat4x4 const I4x4 = A4x4 * B4x4; + + Error += glm::all(glm::equal(I4x4, Identity, 0.001f)) ? 0 : 1; + + return Error; +} + +template<typename VEC3, typename MAT4> +int test_inverse_perf(std::size_t Count, std::size_t Instance, char const * Message) +{ + std::vector<MAT4> TestInputs; + TestInputs.resize(Count); + std::vector<MAT4> TestOutputs; + TestOutputs.resize(TestInputs.size()); + + VEC3 Axis(glm::normalize(VEC3(1.0f, 2.0f, 3.0f))); + + for(std::size_t i = 0; i < TestInputs.size(); ++i) + { + typename MAT4::value_type f = static_cast<typename MAT4::value_type>(i + Instance) * typename MAT4::value_type(0.1) + typename MAT4::value_type(0.1); + TestInputs[i] = glm::rotate(glm::translate(MAT4(1), Axis * f), f, Axis); + //TestInputs[i] = glm::translate(MAT4(1), Axis * f); + } + + std::clock_t StartTime = std::clock(); + + for(std::size_t i = 0; i < TestInputs.size(); ++i) + TestOutputs[i] = glm::inverse(TestInputs[i]); + + std::clock_t EndTime = std::clock(); + + for(std::size_t i = 0; i < TestInputs.size(); ++i) + TestOutputs[i] = TestOutputs[i] * TestInputs[i]; + + typename MAT4::value_type Diff(0); + for(std::size_t Entry = 0; Entry < TestOutputs.size(); ++Entry) + { + MAT4 i(1.0); + MAT4 m(TestOutputs[Entry]); + for(glm::length_t y = 0; y < m.length(); ++y) + for(glm::length_t x = 0; x < m[y].length(); ++x) + Diff = glm::max(m[y][x], i[y][x]); + } + + //glm::uint Ulp = 0; + //Ulp = glm::max(glm::float_distance(*Dst, *Src), Ulp); + + std::printf("inverse<%s>(%f): %lu\n", Message, static_cast<double>(Diff), EndTime - StartTime); + + return 0; +} + +int main() +{ + int Error = 0; + Error += test_matrixCompMult(); + Error += test_outerProduct(); + Error += test_transpose(); + Error += test_determinant(); + Error += test_inverse(); + Error += test_inverse_simd(); + +# ifdef NDEBUG + std::size_t const Samples = 1000; +# else + std::size_t const Samples = 1; +# endif//NDEBUG + + for(std::size_t i = 0; i < 1; ++i) + { + Error += test_inverse_perf<glm::vec3, glm::mat4>(Samples, i, "mat4"); + Error += test_inverse_perf<glm::dvec3, glm::dmat4>(Samples, i, "dmat4"); + } + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_noise.cpp b/3rdparty/glm/source/test/core/core_func_noise.cpp new file mode 100644 index 0000000..4f0b430 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_noise.cpp @@ -0,0 +1,7 @@ +int main() +{ + int Error = 0; + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_packing.cpp b/3rdparty/glm/source/test/core/core_func_packing.cpp new file mode 100644 index 0000000..c3cd14a --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_packing.cpp @@ -0,0 +1,156 @@ +#include <glm/gtc/type_precision.hpp> +#include <glm/gtc/epsilon.hpp> +#include <glm/vector_relational.hpp> +#include <glm/packing.hpp> +#include <vector> + +int test_packUnorm2x16() +{ + int Error = 0; + + std::vector<glm::vec2> A; + A.push_back(glm::vec2(1.0f, 0.0f)); + A.push_back(glm::vec2(0.5f, 0.7f)); + A.push_back(glm::vec2(0.1f, 0.2f)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::vec2 B(A[i]); + glm::uint32 C = glm::packUnorm2x16(B); + glm::vec2 D = glm::unpackUnorm2x16(C); + Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packSnorm2x16() +{ + int Error = 0; + + std::vector<glm::vec2> A; + A.push_back(glm::vec2( 1.0f, 0.0f)); + A.push_back(glm::vec2(-0.5f,-0.7f)); + A.push_back(glm::vec2(-0.1f, 0.1f)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::vec2 B(A[i]); + glm::uint32 C = glm::packSnorm2x16(B); + glm::vec2 D = glm::unpackSnorm2x16(C); + Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packUnorm4x8() +{ + int Error = 0; + + glm::uint32 Packed = glm::packUnorm4x8(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)); + glm::u8vec4 Vec(255, 128, 0, 255); + glm::uint32 & Ref = *reinterpret_cast<glm::uint32*>(&Vec[0]); + + Error += Packed == Ref ? 0 : 1; + + std::vector<glm::vec4> A; + A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f)); + A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::vec4 B(A[i]); + glm::uint32 C = glm::packUnorm4x8(B); + glm::vec4 D = glm::unpackUnorm4x8(C); + Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packSnorm4x8() +{ + int Error = 0; + + std::vector<glm::vec4> A; + A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f)); + A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::vec4 B(A[i]); + glm::uint32 C = glm::packSnorm4x8(B); + glm::vec4 D = glm::unpackSnorm4x8(C); + Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packHalf2x16() +{ + int Error = 0; +/* + std::vector<glm::hvec2> A; + A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 2.0f))); + A.push_back(glm::hvec2(glm::half(-1.0f), glm::half(-2.0f))); + A.push_back(glm::hvec2(glm::half(-1.1f), glm::half( 1.1f))); +*/ + std::vector<glm::vec2> A; + A.push_back(glm::vec2( 1.0f, 2.0f)); + A.push_back(glm::vec2(-1.0f,-2.0f)); + A.push_back(glm::vec2(-1.1f, 1.1f)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::vec2 B(A[i]); + glm::uint C = glm::packHalf2x16(B); + glm::vec2 D = glm::unpackHalf2x16(C); + //Error += B == D ? 0 : 1; + Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packDouble2x32() +{ + int Error = 0; + + std::vector<glm::uvec2> A; + A.push_back(glm::uvec2( 1, 2)); + A.push_back(glm::uvec2(-1,-2)); + A.push_back(glm::uvec2(-1000, 1100)); + + for(std::size_t i = 0; i < A.size(); ++i) + { + glm::uvec2 B(A[i]); + double C = glm::packDouble2x32(B); + glm::uvec2 D = glm::unpackDouble2x32(C); + Error += B == D ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_packSnorm4x8(); + Error += test_packUnorm4x8(); + Error += test_packSnorm2x16(); + Error += test_packUnorm2x16(); + Error += test_packHalf2x16(); + Error += test_packDouble2x32(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_swizzle.cpp b/3rdparty/glm/source/test/core/core_func_swizzle.cpp new file mode 100644 index 0000000..9758533 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_swizzle.cpp @@ -0,0 +1,164 @@ +#define GLM_FORCE_SWIZZLE +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/glm.hpp> + +static int test_ivec2_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::ivec2 A(1, 2); + glm::ivec2 B = A.yx(); + glm::ivec2 C = B.yx(); + + Error += A != B ? 0 : 1; + Error += A == C ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec2 A(1, 2); + glm::ivec2 B = A.yx; + glm::ivec2 C = A.yx; + + Error += A != B ? 0 : 1; + Error += B == C ? 0 : 1; + + B.xy = B.yx; + C.xy = C.yx; + + Error += B == C ? 0 : 1; + + glm::ivec2 D(0, 0); + D.yx = A.xy; + Error += A.yx() == D ? 0 : 1; + + glm::ivec2 E = A.yx; + Error += E == D ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE + + return Error; +} + +int test_ivec3_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::ivec3 A(1, 2, 3); + glm::ivec3 B = A.zyx(); + glm::ivec3 C = B.zyx(); + + Error += A != B ? 0 : 1; + Error += A == C ? 0 : 1; + } +# endif + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec3 const A(1, 2, 3); + glm::ivec2 B = A.yx; + glm::ivec2 C = A.yx; + + Error += A.yx() == B ? 0 : 1; + Error += B == C ? 0 : 1; + + B.xy = B.yx; + C.xy = C.yx; + + Error += B == C ? 0 : 1; + + glm::ivec2 D(0, 0); + D.yx = A.xy; + + Error += A.yx() == D ? 0 : 1; + + glm::ivec2 E(0, 0); + E.xy = A.xy(); + + Error += E == A.xy() ? 0 : 1; + Error += E.xy() == A.xy() ? 0 : 1; + + glm::ivec3 const F = A.xxx + A.xxx; + Error += F == glm::ivec3(2) ? 0 : 1; + + glm::ivec3 const G = A.xxx - A.xxx; + Error += G == glm::ivec3(0) ? 0 : 1; + + glm::ivec3 const H = A.xxx * A.xxx; + Error += H == glm::ivec3(1) ? 0 : 1; + + glm::ivec3 const I = A.xxx / A.xxx; + Error += I == glm::ivec3(1) ? 0 : 1; + + glm::ivec3 J(1, 2, 3); + J.xyz += glm::ivec3(1); + Error += J == glm::ivec3(2, 3, 4) ? 0 : 1; + + glm::ivec3 K(1, 2, 3); + K.xyz += A.xyz; + Error += K == glm::ivec3(2, 4, 6) ? 0 : 1; + } +# endif + + return Error; +} + +int test_ivec4_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::ivec4 A(1, 2, 3, 4); + glm::ivec4 B = A.wzyx(); + glm::ivec4 C = B.wzyx(); + + Error += A != B ? 0 : 1; + Error += A == C ? 0 : 1; + } +# endif + + return Error; +} + +int test_vec4_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::vec4 A(1, 2, 3, 4); + glm::vec4 B = A.wzyx(); + glm::vec4 C = B.wzyx(); + + Error += glm::any(glm::notEqual(A, B, 0.0001f)) ? 0 : 1; + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + + float D = glm::dot(C.wzyx(), C.xyzw()); + Error += glm::equal(D, 20.f, 0.001f) ? 0 : 1; + } +# endif + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_ivec2_swizzle(); + Error += test_ivec3_swizzle(); + Error += test_ivec4_swizzle(); + Error += test_vec4_swizzle(); + + return Error; +} + + + diff --git a/3rdparty/glm/source/test/core/core_func_trigonometric.cpp b/3rdparty/glm/source/test/core/core_func_trigonometric.cpp new file mode 100644 index 0000000..3172340 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_trigonometric.cpp @@ -0,0 +1,10 @@ +#include <glm/trigonometric.hpp> + +int main() +{ + int Error = 0; + + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_func_vector_relational.cpp b/3rdparty/glm/source/test/core/core_func_vector_relational.cpp new file mode 100644 index 0000000..0a4e7e7 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_func_vector_relational.cpp @@ -0,0 +1,180 @@ +#include <glm/vec2.hpp> +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> +#include <glm/vector_relational.hpp> +#include <glm/gtc/vec1.hpp> + +static int test_not() +{ + int Error = 0; + + { + glm::bvec1 v(false); + Error += glm::all(glm::not_(v)) ? 0 : 1; + } + + { + glm::bvec2 v(false); + Error += glm::all(glm::not_(v)) ? 0 : 1; + } + + { + glm::bvec3 v(false); + Error += glm::all(glm::not_(v)) ? 0 : 1; + } + + { + glm::bvec4 v(false); + Error += glm::all(glm::not_(v)) ? 0 : 1; + } + + return Error; +} + +static int test_less() +{ + int Error = 0; + + { + glm::vec2 const A(1, 2); + glm::vec2 const B(2, 3); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1; + } + + { + glm::vec3 const A(1, 2, 3); + glm::vec3 const B(2, 3, 4); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1; + } + + { + glm::vec4 const A(1, 2, 3, 4); + glm::vec4 const B(2, 3, 4, 5); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1; + } + + { + glm::ivec2 const A(1, 2); + glm::ivec2 const B(2, 3); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + + glm::ivec2 const C(1, 3); + Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1; + } + + { + glm::ivec3 const A(1, 2, 3); + glm::ivec3 const B(2, 3, 4); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + + glm::ivec3 const C(1, 3, 4); + Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + glm::ivec4 const B(2, 3, 4, 5); + Error += glm::all(glm::lessThan(A, B)) ? 0: 1; + + glm::ivec4 const C(1, 3, 4, 5); + Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1; + } + + return Error; +} + +static int test_greater() +{ + int Error = 0; + + { + glm::vec2 const A(1, 2); + glm::vec2 const B(2, 3); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1; + } + + { + glm::vec3 const A(1, 2, 3); + glm::vec3 const B(2, 3, 4); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1; + } + + { + glm::vec4 const A(1, 2, 3, 4); + glm::vec4 const B(2, 3, 4, 5); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1; + } + + { + glm::ivec2 const A(1, 2); + glm::ivec2 const B(2, 3); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + + glm::ivec2 const C(1, 3); + Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1; + } + + { + glm::ivec3 const A(1, 2, 3); + glm::ivec3 const B(2, 3, 4); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + + glm::ivec3 const C(1, 3, 4); + Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + glm::ivec4 const B(2, 3, 4, 5); + Error += glm::all(glm::greaterThan(B, A)) ? 0: 1; + + glm::ivec4 const C(1, 3, 4, 5); + Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1; + } + + return Error; +} + +static int test_equal() +{ + int Error = 0; + + { + glm::ivec2 const A(1, 2); + glm::ivec2 const B(1, 2); + Error += glm::all(glm::equal(B, A)) ? 0: 1; + } + + { + glm::ivec3 const A(1, 2, 3); + glm::ivec3 const B(1, 2, 3); + Error += glm::all(glm::equal(B, A)) ? 0: 1; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + glm::ivec4 const B(1, 2, 3, 4); + Error += glm::all(glm::equal(B, A)) ? 0: 1; + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_not(); + Error += test_less(); + Error += test_greater(); + Error += test_equal(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_setup_force_cxx98.cpp b/3rdparty/glm/source/test/core/core_setup_force_cxx98.cpp new file mode 100644 index 0000000..32bb63c --- /dev/null +++ b/3rdparty/glm/source/test/core/core_setup_force_cxx98.cpp @@ -0,0 +1,12 @@ +#ifndef GLM_FORCE_CXX98 +# define GLM_FORCE_CXX98 +#endif +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_setup_force_size_t_length.cpp b/3rdparty/glm/source/test/core/core_setup_force_size_t_length.cpp new file mode 100644 index 0000000..36010e3 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_setup_force_size_t_length.cpp @@ -0,0 +1,22 @@ +#define GLM_FORCE_SIZE_T_LENGTH +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +template <typename genType> +genType add(genType const& a, genType const& b) +{ + genType result(0); + for(glm::length_t i = 0; i < a.length(); ++i) + result[i] = a[i] + b[i]; + return result; +} + +int main() +{ + int Error = 0; + + glm::ivec4 v(1); + Error += add(v, v) == glm::ivec4(2) ? 0 : 1; + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_setup_message.cpp b/3rdparty/glm/source/test/core/core_setup_message.cpp new file mode 100644 index 0000000..7594743 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_setup_message.cpp @@ -0,0 +1,230 @@ +#define GLM_FORCE_MESSAGES +#include <glm/vec3.hpp> +#include <cstdio> + +int test_compiler() +{ + int Error(0); + + if(GLM_COMPILER & GLM_COMPILER_VC) + { + switch(GLM_COMPILER) + { + case GLM_COMPILER_VC12: + std::printf("Visual C++ 12 - 2013\n"); + break; + case GLM_COMPILER_VC14: + std::printf("Visual C++ 14 - 2015\n"); + break; + case GLM_COMPILER_VC15: + std::printf("Visual C++ 15 - 2017\n"); + break; + case GLM_COMPILER_VC15_3: + std::printf("Visual C++ 15.3 - 2017\n"); + break; + case GLM_COMPILER_VC15_5: + std::printf("Visual C++ 15.5 - 2017\n"); + break; + case GLM_COMPILER_VC15_6: + std::printf("Visual C++ 15.6 - 2017\n"); + break; + case GLM_COMPILER_VC15_7: + std::printf("Visual C++ 15.7 - 2017\n"); + break; + case GLM_COMPILER_VC15_8: + std::printf("Visual C++ 15.8 - 2017\n"); + break; + case GLM_COMPILER_VC15_9: + std::printf("Visual C++ 15.9 - 2017\n"); + break; + case GLM_COMPILER_VC16: + std::printf("Visual C++ 16 - 2019\n"); + break; + default: + std::printf("Visual C++ version not detected\n"); + Error += 1; + break; + } + } + else if(GLM_COMPILER & GLM_COMPILER_GCC) + { + switch(GLM_COMPILER) + { + case GLM_COMPILER_GCC46: + std::printf("GCC 4.6\n"); + break; + case GLM_COMPILER_GCC47: + std::printf("GCC 4.7\n"); + break; + case GLM_COMPILER_GCC48: + std::printf("GCC 4.8\n"); + break; + case GLM_COMPILER_GCC49: + std::printf("GCC 4.9\n"); + break; + case GLM_COMPILER_GCC5: + std::printf("GCC 5\n"); + break; + case GLM_COMPILER_GCC6: + std::printf("GCC 6\n"); + break; + case GLM_COMPILER_GCC7: + std::printf("GCC 7\n"); + break; + case GLM_COMPILER_GCC8: + std::printf("GCC 8\n"); + break; + default: + std::printf("GCC version not detected\n"); + Error += 1; + break; + } + } + else if(GLM_COMPILER & GLM_COMPILER_CUDA) + { + std::printf("CUDA\n"); + } + else if(GLM_COMPILER & GLM_COMPILER_CLANG) + { + switch(GLM_COMPILER) + { + case GLM_COMPILER_CLANG34: + std::printf("Clang 3.4\n"); + break; + case GLM_COMPILER_CLANG35: + std::printf("Clang 3.5\n"); + break; + case GLM_COMPILER_CLANG36: + std::printf("Clang 3.6\n"); + break; + case GLM_COMPILER_CLANG37: + std::printf("Clang 3.7\n"); + break; + case GLM_COMPILER_CLANG38: + std::printf("Clang 3.8\n"); + break; + case GLM_COMPILER_CLANG39: + std::printf("Clang 3.9\n"); + break; + case GLM_COMPILER_CLANG40: + std::printf("Clang 4.0\n"); + break; + case GLM_COMPILER_CLANG41: + std::printf("Clang 4.1\n"); + break; + case GLM_COMPILER_CLANG42: + std::printf("Clang 4.2\n"); + break; + default: + std::printf("LLVM version not detected\n"); + break; + } + } + else if(GLM_COMPILER & GLM_COMPILER_INTEL) + { + switch(GLM_COMPILER) + { + case GLM_COMPILER_INTEL14: + std::printf("ICC 14 - 2013 SP1\n"); + break; + case GLM_COMPILER_INTEL15: + std::printf("ICC 15 - 2015\n"); + break; + case GLM_COMPILER_INTEL16: + std::printf("ICC 16 - 2017\n"); + break; + case GLM_COMPILER_INTEL17: + std::printf("ICC 17 - 20XX\n"); + break; + default: + std::printf("Intel compiler version not detected\n"); + Error += 1; + break; + } + } + else + { + std::printf("Undetected compiler\n"); + Error += 1; + } + + return Error; +} + +int test_model() +{ + int Error = 0; + + Error += ((sizeof(void*) == 4) && (GLM_MODEL == GLM_MODEL_32)) || ((sizeof(void*) == 8) && (GLM_MODEL == GLM_MODEL_64)) ? 0 : 1; + + if(GLM_MODEL == GLM_MODEL_32) + std::printf("GLM_MODEL_32\n"); + else if(GLM_MODEL == GLM_MODEL_64) + std::printf("GLM_MODEL_64\n"); + + return Error; +} + +int test_instruction_set() +{ + int Error = 0; + + std::printf("GLM_ARCH: "); + + if(GLM_ARCH & GLM_ARCH_ARM_BIT) + std::printf("ARM "); + if(GLM_ARCH & GLM_ARCH_NEON_BIT) + std::printf("NEON "); + if(GLM_ARCH & GLM_ARCH_AVX2_BIT) + std::printf("AVX2 "); + if(GLM_ARCH & GLM_ARCH_AVX_BIT) + std::printf("AVX "); + if(GLM_ARCH & GLM_ARCH_SSE42_BIT) + std::printf("SSE4.2 "); + if(GLM_ARCH & GLM_ARCH_SSE41_BIT) + std::printf("SSE4.1 "); + if(GLM_ARCH & GLM_ARCH_SSSE3_BIT) + std::printf("SSSE3 "); + if(GLM_ARCH & GLM_ARCH_SSE3_BIT) + std::printf("SSE3 "); + if(GLM_ARCH & GLM_ARCH_SSE2_BIT) + std::printf("SSE2 "); + + std::printf("\n"); + + return Error; +} + +int test_cpp_version() +{ + std::printf("__cplusplus: %d\n", static_cast<int>(__cplusplus)); + + return 0; +} + +int test_operators() +{ + glm::ivec3 A(1); + glm::ivec3 B(1); + bool R = A != B; + bool S = A == B; + + return (S && !R) ? 0 : 1; +} + +int main() +{ + int Error = 0; + +# if !defined(GLM_FORCE_PLATFORM_UNKNOWN) && !defined(GLM_FORCE_COMPILER_UNKNOWN) && !defined(GLM_FORCE_ARCH_UNKNOWN) && !defined(GLM_FORCE_CXX_UNKNOWN) + + Error += test_cpp_version(); + Error += test_compiler(); + Error += test_model(); + Error += test_instruction_set(); + Error += test_operators(); + +# endif + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_setup_platform_unknown.cpp b/3rdparty/glm/source/test/core/core_setup_platform_unknown.cpp new file mode 100644 index 0000000..9feaee3 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_setup_platform_unknown.cpp @@ -0,0 +1,21 @@ +#ifndef GLM_FORCE_PLATFORM_UNKNOWN +# define GLM_FORCE_PLATFORM_UNKNOWN +#endif +#ifndef GLM_FORCE_COMPILER_UNKNOWN +# define GLM_FORCE_COMPILER_UNKNOWN +#endif +#ifndef GLM_FORCE_ARCH_UNKNOWN +# define GLM_FORCE_ARCH_UNKNOWN +#endif +#ifndef GLM_FORCE_CXX_UNKNOWN +# define GLM_FORCE_CXX_UNKNOWN +#endif +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +int main() +{ + int Error = 0; + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_setup_precision.cpp b/3rdparty/glm/source/test/core/core_setup_precision.cpp new file mode 100644 index 0000000..b44bc50 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_setup_precision.cpp @@ -0,0 +1,58 @@ +#define GLM_FORCE_INLINE +#define GLM_PRECISION_HIGHP_FLOAT +#include <glm/glm.hpp> +#include <glm/ext.hpp> + +static int test_mat() +{ + int Error = 0; + + Error += sizeof(glm::mat2) == sizeof(glm::highp_mat2) ? 0 : 1; + Error += sizeof(glm::mat3) == sizeof(glm::highp_mat3) ? 0 : 1; + Error += sizeof(glm::mat4) == sizeof(glm::highp_mat4) ? 0 : 1; + + Error += sizeof(glm::mat2x2) == sizeof(glm::highp_mat2x2) ? 0 : 1; + Error += sizeof(glm::mat2x3) == sizeof(glm::highp_mat2x3) ? 0 : 1; + Error += sizeof(glm::mat2x4) == sizeof(glm::highp_mat2x4) ? 0 : 1; + Error += sizeof(glm::mat3x2) == sizeof(glm::highp_mat3x2) ? 0 : 1; + Error += sizeof(glm::mat3x3) == sizeof(glm::highp_mat3x3) ? 0 : 1; + Error += sizeof(glm::mat3x4) == sizeof(glm::highp_mat3x4) ? 0 : 1; + Error += sizeof(glm::mat4x2) == sizeof(glm::highp_mat4x2) ? 0 : 1; + Error += sizeof(glm::mat4x3) == sizeof(glm::highp_mat4x3) ? 0 : 1; + Error += sizeof(glm::mat4x4) == sizeof(glm::highp_mat4x4) ? 0 : 1; + + return Error; +} + +static int test_vec() +{ + int Error = 0; + + Error += sizeof(glm::vec2) == sizeof(glm::highp_vec2) ? 0 : 1; + Error += sizeof(glm::vec3) == sizeof(glm::highp_vec3) ? 0 : 1; + Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1; + + return Error; +} + +static int test_dvec() +{ + int Error = 0; + + Error += sizeof(glm::dvec2) == sizeof(glm::highp_dvec2) ? 0 : 1; + Error += sizeof(glm::dvec3) == sizeof(glm::highp_dvec3) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_mat(); + Error += test_vec(); + Error += test_dvec(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_aligned.cpp b/3rdparty/glm/source/test/core/core_type_aligned.cpp new file mode 100644 index 0000000..dff0939 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_aligned.cpp @@ -0,0 +1,92 @@ +#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES +#include <glm/glm.hpp> + +#if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE +#include <type_traits> + +static_assert(sizeof(glm::bvec4) > sizeof(glm::bvec2), "Invalid sizeof"); +static_assert(sizeof(glm::ivec4) > sizeof(glm::uvec2), "Invalid sizeof"); +static_assert(sizeof(glm::dvec4) > sizeof(glm::dvec2), "Invalid sizeof"); + +static_assert(sizeof(glm::bvec4) == sizeof(glm::bvec3), "Invalid sizeof"); +static_assert(sizeof(glm::uvec4) == sizeof(glm::uvec3), "Invalid sizeof"); +static_assert(sizeof(glm::dvec4) == sizeof(glm::dvec3), "Invalid sizeof"); + +static int test_storage_aligned() +{ + int Error = 0; + + size_t size1_aligned = sizeof(glm::detail::storage<1, int, true>::type); + Error += size1_aligned == sizeof(int) * 1 ? 0 : 1; + size_t size2_aligned = sizeof(glm::detail::storage<2, int, true>::type); + Error += size2_aligned == sizeof(int) * 2 ? 0 : 1; + size_t size4_aligned = sizeof(glm::detail::storage<4, int, true>::type); + Error += size4_aligned == sizeof(int) * 4 ? 0 : 1; + + size_t align1_aligned = alignof(glm::detail::storage<1, int, true>::type); + Error += align1_aligned == 4 ? 0 : 1; + size_t align2_aligned = alignof(glm::detail::storage<2, int, true>::type); + Error += align2_aligned == 8 ? 0 : 1; + size_t align4_aligned = alignof(glm::detail::storage<4, int, true>::type); + Error += align4_aligned == 16 ? 0 : 1; + + return Error; +} + +static int test_storage_unaligned() +{ + int Error = 0; + + size_t align1_unaligned = alignof(glm::detail::storage<1, int, false>::type); + Error += align1_unaligned == sizeof(int) ? 0 : 1; + size_t align2_unaligned = alignof(glm::detail::storage<2, int, false>::type); + Error += align2_unaligned == sizeof(int) ? 0 : 1; + size_t align3_unaligned = alignof(glm::detail::storage<3, int, false>::type); + Error += align3_unaligned == sizeof(int) ? 0 : 1; + size_t align4_unaligned = alignof(glm::detail::storage<4, int, false>::type); + Error += align4_unaligned == sizeof(int) ? 0 : 1; + + return Error; +} + +static int test_vec3_aligned() +{ + int Error = 0; + + struct Struct1 + { + glm::vec4 A; + float B; + glm::vec3 C; + }; + + std::size_t const Size1 = sizeof(Struct1); + Error += Size1 == 48 ? 0 : 1; + + struct Struct2 + { + glm::vec4 A; + glm::vec3 B; + float C; + }; + + std::size_t const Size2 = sizeof(Struct2); + Error += Size2 == 48 ? 0 : 1; + + return Error; +} + +#endif + +int main() +{ + int Error = 0; + +# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE + Error += test_storage_aligned(); + Error += test_storage_unaligned(); + Error += test_vec3_aligned(); +# endif + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_cast.cpp b/3rdparty/glm/source/test/core/core_type_cast.cpp new file mode 100644 index 0000000..7ff1901 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_cast.cpp @@ -0,0 +1,146 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/glm.hpp> +#include <algorithm> +#include <vector> +#include <iterator> + +struct my_vec2 +{ + operator glm::vec2() { return glm::vec2(x, y); } + float x, y; +}; + +int test_vec2_cast() +{ + glm::vec2 A(1.0f, 2.0f); + glm::lowp_vec2 B(A); + glm::mediump_vec2 C(A); + glm::highp_vec2 D(A); + + glm::vec2 E = static_cast<glm::vec2>(A); + glm::lowp_vec2 F = static_cast<glm::lowp_vec2>(A); + glm::mediump_vec2 G = static_cast<glm::mediump_vec2>(A); + glm::highp_vec2 H = static_cast<glm::highp_vec2>(A); + + my_vec2 I; + glm::vec2 J = static_cast<glm::vec2>(I); + glm::vec2 K(7.8f); + + int Error(0); + + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1; + + return Error; +} + +int test_vec3_cast() +{ + glm::vec3 A(1.0f, 2.0f, 3.0f); + glm::lowp_vec3 B(A); + glm::mediump_vec3 C(A); + glm::highp_vec3 D(A); + + glm::vec3 E = static_cast<glm::vec3>(A); + glm::lowp_vec3 F = static_cast<glm::lowp_vec3>(A); + glm::mediump_vec3 G = static_cast<glm::mediump_vec3>(A); + glm::highp_vec3 H = static_cast<glm::highp_vec3>(A); + + int Error(0); + + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1; + + return Error; +} + +int test_vec4_cast() +{ + glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::lowp_vec4 B(A); + glm::mediump_vec4 C(A); + glm::highp_vec4 D(A); + + glm::vec4 E = static_cast<glm::vec4>(A); + glm::lowp_vec4 F = static_cast<glm::lowp_vec4>(A); + glm::mediump_vec4 G = static_cast<glm::mediump_vec4>(A); + glm::highp_vec4 H = static_cast<glm::highp_vec4>(A); + + int Error(0); + + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1; + + return Error; +} + +int test_std_copy() +{ + int Error = 0; + + { + std::vector<int> High; + High.resize(64); + std::vector<int> Medium(High.size()); + + std::copy(High.begin(), High.end(), Medium.begin()); + + *Medium.begin() = *High.begin(); + } + + { + std::vector<glm::dvec4> High4; + High4.resize(64); + std::vector<glm::vec4> Medium4(High4.size()); + + std::copy(High4.begin(), High4.end(), Medium4.begin()); + + *Medium4.begin() = *High4.begin(); + } + + { + std::vector<glm::dvec3> High3; + High3.resize(64); + std::vector<glm::vec3> Medium3(High3.size()); + + std::copy(High3.begin(), High3.end(), Medium3.begin()); + + *Medium3.begin() = *High3.begin(); + } + + { + std::vector<glm::dvec2> High2; + High2.resize(64); + std::vector<glm::vec2> Medium2(High2.size()); + + std::copy(High2.begin(), High2.end(), Medium2.begin()); + + *Medium2.begin() = *High2.begin(); + } + + glm::dvec4 v1; + glm::vec4 v2; + + v2 = v1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_std_copy(); + Error += test_vec2_cast(); + Error += test_vec3_cast(); + Error += test_vec4_cast(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_ctor.cpp b/3rdparty/glm/source/test/core/core_type_ctor.cpp new file mode 100644 index 0000000..078fcdf --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_ctor.cpp @@ -0,0 +1,351 @@ +#include <glm/gtc/vec1.hpp> +#include <glm/gtc/quaternion.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/glm.hpp> + +static int test_vec1_ctor() +{ + int Error = 0; + +# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + { + union pack + { + glm::vec1 f; + glm::ivec1 i; + } A, B; + + A.f = glm::vec1(0); + Error += glm::all(glm::equal(A.i, glm::ivec1(0))) ? 0 : 1; + + B.f = glm::vec1(1); + Error += glm::all(glm::equal(B.i, glm::ivec1(1065353216))) ? 0 : 1; + } +# endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + + return Error; +} + +static int test_vec2_ctor() +{ + int Error = 0; + +# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + { + union pack + { + glm::vec2 f; + glm::ivec2 i; + } A, B; + + A.f = glm::vec2(0); + Error += glm::all(glm::equal(A.i, glm::ivec2(0))) ? 0 : 1; + + B.f = glm::vec2(1); + Error += glm::all(glm::equal(B.i, glm::ivec2(1065353216))) ? 0 : 1; + } +# endif + + return Error; +} + +static int test_vec3_ctor() +{ + int Error = 0; + +# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + { + union pack + { + glm::vec3 f; + glm::ivec3 i; + } A, B; + + A.f = glm::vec3(0); + Error += glm::all(glm::equal(A.i, glm::ivec3(0))) ? 0 : 1; + + B.f = glm::vec3(1); + Error += glm::all(glm::equal(B.i, glm::ivec3(1065353216))) ? 0 : 1; + } +# endif + + return Error; +} + +static int test_vec4_ctor() +{ + int Error = 0; + +# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE + { + union pack + { + glm::vec4 f; + glm::ivec4 i; + } A, B; + + A.f = glm::vec4(0); + Error += glm::all(glm::equal(A.i, glm::ivec4(0))) ? 0 : 1; + + B.f = glm::vec4(1); + Error += glm::all(glm::equal(B.i, glm::ivec4(1065353216))) ? 0 : 1; + } +# endif + + return Error; +} + +static int test_mat2x2_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat2x2 f; + glm::mat2x2 i; + } A, B; + + A.f = glm::mat2x2(0); + Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat2x2(1); + Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat2x3_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat2x3 f; + glm::mat2x3 i; + } A, B; + + A.f = glm::mat2x3(0); + Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat2x3(1); + Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat2x4_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat2x4 f; + glm::mat2x4 i; + } A, B; + + A.f = glm::mat2x4(0); + glm::vec4 const C(0, 0, 0, 0); + Error += glm::all(glm::equal(A.i[0], C, glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat2x4(1); + glm::vec4 const D(1, 0, 0, 0); + Error += glm::all(glm::equal(B.i[0], D, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat3x2_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat3x2 f; + glm::mat3x2 i; + } A, B; + + A.f = glm::mat3x2(0); + Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat3x2(1); + Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat3x3_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat3x3 f; + glm::mat3x3 i; + } A, B; + + A.f = glm::mat3x3(0); + Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat3x3(1); + Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat3x4_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat3x4 f; + glm::mat3x4 i; + } A, B; + + A.f = glm::mat3x4(0); + Error += glm::all(glm::equal(A.i[0], glm::vec4(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat3x4(1); + Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat4x2_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat4x2 f; + glm::mat4x2 i; + } A, B; + + A.f = glm::mat4x2(0); + Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat4x2(1); + Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat4x3_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat4x3 f; + glm::mat4x3 i; + } A, B; + + A.f = glm::mat4x3(0); + Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat4x3(1); + Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_mat4x4_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::mat4 f; + glm::mat4 i; + } A, B; + + A.f = glm::mat4(0); + Error += glm::all(glm::equal(A.i[0], glm::vec4(0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::mat4(1); + Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +static int test_quat_ctor() +{ + int Error = 0; + +# if GLM_LANG & GLM_LANG_CXX11_FLAG + { + union pack + { + glm::quat f; + glm::quat i; + } A, B; + + A.f = glm::quat(0, 0, 0, 0); + Error += glm::all(glm::equal(A.i, glm::quat(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1; + + B.f = glm::quat(1, 1, 1, 1); + Error += glm::all(glm::equal(B.i, glm::quat(1, 1, 1, 1), glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_LANG & GLM_LANG_CXX11_FLAG + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_vec1_ctor(); + Error += test_vec2_ctor(); + Error += test_vec3_ctor(); + Error += test_vec4_ctor(); + Error += test_mat2x2_ctor(); + Error += test_mat2x3_ctor(); + Error += test_mat2x4_ctor(); + Error += test_mat3x2_ctor(); + Error += test_mat3x3_ctor(); + Error += test_mat3x4_ctor(); + Error += test_mat4x2_ctor(); + Error += test_mat4x3_ctor(); + Error += test_mat4x4_ctor(); + Error += test_quat_ctor(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_int.cpp b/3rdparty/glm/source/test/core/core_type_int.cpp new file mode 100644 index 0000000..2631509 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_int.cpp @@ -0,0 +1,26 @@ +#include <glm/glm.hpp> +#include <glm/ext/scalar_int_sized.hpp> + +static int test_bit_operator() +{ + int Error = 0; + + glm::ivec4 const a(1); + glm::ivec4 const b = ~a; + Error += glm::all(glm::equal(b, glm::ivec4(-2))) ? 0 : 1; + + glm::int32 const c(1); + glm::int32 const d = ~c; + Error += d == -2 ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_bit_operator(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_length.cpp b/3rdparty/glm/source/test/core/core_type_length.cpp new file mode 100644 index 0000000..f088cb3 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_length.cpp @@ -0,0 +1,78 @@ +#include <glm/glm.hpp> + +static int test_length_mat_non_squared() +{ + int Error = 0; + + Error += glm::mat2x3().length() == 2 ? 0 : 1; + Error += glm::mat2x4().length() == 2 ? 0 : 1; + Error += glm::mat3x2().length() == 3 ? 0 : 1; + Error += glm::mat3x4().length() == 3 ? 0 : 1; + Error += glm::mat4x2().length() == 4 ? 0 : 1; + Error += glm::mat4x3().length() == 4 ? 0 : 1; + + Error += glm::dmat2x3().length() == 2 ? 0 : 1; + Error += glm::dmat2x4().length() == 2 ? 0 : 1; + Error += glm::dmat3x2().length() == 3 ? 0 : 1; + Error += glm::dmat3x4().length() == 3 ? 0 : 1; + Error += glm::dmat4x2().length() == 4 ? 0 : 1; + Error += glm::dmat4x3().length() == 4 ? 0 : 1; + + return Error; +} + +static int test_length_mat() +{ + int Error = 0; + + Error += glm::mat2().length() == 2 ? 0 : 1; + Error += glm::mat3().length() == 3 ? 0 : 1; + Error += glm::mat4().length() == 4 ? 0 : 1; + Error += glm::mat2x2().length() == 2 ? 0 : 1; + Error += glm::mat3x3().length() == 3 ? 0 : 1; + Error += glm::mat4x4().length() == 4 ? 0 : 1; + + Error += glm::dmat2().length() == 2 ? 0 : 1; + Error += glm::dmat3().length() == 3 ? 0 : 1; + Error += glm::dmat4().length() == 4 ? 0 : 1; + Error += glm::dmat2x2().length() == 2 ? 0 : 1; + Error += glm::dmat3x3().length() == 3 ? 0 : 1; + Error += glm::dmat4x4().length() == 4 ? 0 : 1; + + return Error; +} + +static int test_length_vec() +{ + int Error = 0; + + Error += glm::vec2().length() == 2 ? 0 : 1; + Error += glm::vec3().length() == 3 ? 0 : 1; + Error += glm::vec4().length() == 4 ? 0 : 1; + + Error += glm::ivec2().length() == 2 ? 0 : 1; + Error += glm::ivec3().length() == 3 ? 0 : 1; + Error += glm::ivec4().length() == 4 ? 0 : 1; + + Error += glm::uvec2().length() == 2 ? 0 : 1; + Error += glm::uvec3().length() == 3 ? 0 : 1; + Error += glm::uvec4().length() == 4 ? 0 : 1; + + Error += glm::dvec2().length() == 2 ? 0 : 1; + Error += glm::dvec3().length() == 3 ? 0 : 1; + Error += glm::dvec4().length() == 4 ? 0 : 1; + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_length_vec(); + Error += test_length_mat(); + Error += test_length_mat_non_squared(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_type_mat2x2.cpp b/3rdparty/glm/source/test/core/core_type_mat2x2.cpp new file mode 100644 index 0000000..2f8b018 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat2x2.cpp @@ -0,0 +1,177 @@ +#include <glm/ext/matrix_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/matrix.hpp> +#include <glm/vector_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +int test_operators() +{ + glm::mat2x2 l(1.0f); + glm::mat2x2 m(1.0f); + glm::vec2 u(1.0f); + glm::vec2 v(1.0f); + float x = 1.0f; + glm::vec2 a = m * u; + glm::vec2 b = v * m; + glm::mat2x2 n = x / m; + glm::mat2x2 o = m / x; + glm::mat2x2 p = x * m; + glm::mat2x2 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_inverse() +{ + int Error(0); + + { + glm::mat2 const Matrix(1, 2, 3, 4); + glm::mat2 const Inverse = glm::inverse(Matrix); + glm::mat2 const Identity = Matrix * Inverse; + + Error += glm::all(glm::equal(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1; + } + + { + glm::mat2 const Matrix(1, 2, 3, 4); + glm::mat2 const Identity = Matrix / Matrix; + + Error += glm::all(glm::equal(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1; + } + + return Error; +} + +int test_ctr() +{ + int Error = 0; + + { + glm::mediump_mat2x2 const A(1.0f); + glm::highp_mat2x2 const B(A); + glm::mediump_mat2x2 const C(B); + + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + +#if GLM_HAS_INITIALIZER_LISTS + glm::mat2x2 m0( + glm::vec2(0, 1), + glm::vec2(2, 3)); + + glm::mat2x2 m1{0, 1, 2, 3}; + + glm::mat2x2 m2{ + {0, 1}, + {2, 3}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat2x2> v1{ + {0, 1, 2, 3}, + {0, 1, 2, 3} + }; + + std::vector<glm::mat2x2> v2{ + { + { 0, 1}, + { 4, 5} + }, + { + { 0, 1}, + { 4, 5} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat2 B(A); + glm::mat2 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +int test_size() +{ + int Error = 0; + + Error += 16 == sizeof(glm::mat2x2) ? 0 : 1; + Error += 32 == sizeof(glm::dmat2x2) ? 0 : 1; + Error += glm::mat2x2().length() == 2 ? 0 : 1; + Error += glm::dmat2x2().length() == 2 ? 0 : 1; + Error += glm::mat2x2::length() == 2 ? 0 : 1; + Error += glm::dmat2x2::length() == 2 ? 0 : 1; + + return Error; +} + +int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_inverse(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_mat2x3.cpp b/3rdparty/glm/source/test/core/core_type_mat2x3.cpp new file mode 100644 index 0000000..e3ad76b --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat2x3.cpp @@ -0,0 +1,142 @@ +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static int test_operators() +{ + glm::mat2x3 l(1.0f); + glm::mat2x3 m(1.0f); + glm::vec2 u(1.0f); + glm::vec3 v(1.0f); + float x = 1.0f; + glm::vec3 a = m * u; + glm::vec2 b = v * m; + glm::mat2x3 n = x / m; + glm::mat2x3 o = m / x; + glm::mat2x3 p = x * m; + glm::mat2x3 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if GLM_HAS_INITIALIZER_LISTS + glm::mat2x3 m0( + glm::vec3(0, 1, 2), + glm::vec3(3, 4, 5)); + + glm::mat2x3 m1{0, 1, 2, 3, 4, 5}; + + glm::mat2x3 m2{ + {0, 1, 2}, + {3, 4, 5}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat2x3> v1{ + {0, 1, 2, 3, 4, 5}, + {0, 1, 2, 3, 4, 5} + }; + + std::vector<glm::mat2x3> v2{ + { + { 0, 1, 2}, + { 4, 5, 6} + }, + { + { 0, 1, 2}, + { 4, 5, 6} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat2x3 B(A); + glm::mat2x3 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +int test_size() +{ + int Error = 0; + + Error += 24 == sizeof(glm::mat2x3) ? 0 : 1; + Error += 48 == sizeof(glm::dmat2x3) ? 0 : 1; + Error += glm::mat2x3().length() == 2 ? 0 : 1; + Error += glm::dmat2x3().length() == 2 ? 0 : 1; + Error += glm::mat2x3::length() == 2 ? 0 : 1; + Error += glm::dmat2x3::length() == 2 ? 0 : 1; + + return Error; +} + +int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat2x3::length() == 2, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_mat2x4.cpp b/3rdparty/glm/source/test/core/core_type_mat2x4.cpp new file mode 100644 index 0000000..ade3a44 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat2x4.cpp @@ -0,0 +1,147 @@ +#include <glm/gtc/epsilon.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static int test_operators() +{ + glm::mat2x4 l(1.0f); + glm::mat2x4 m(1.0f); + glm::vec2 u(1.0f); + glm::vec4 v(1.0f); + float x = 1.0f; + glm::vec4 a = m * u; + glm::vec2 b = v * m; + glm::mat2x4 n = x / m; + glm::mat2x4 o = m / x; + glm::mat2x4 p = x * m; + glm::mat2x4 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat2x4 m0( + glm::vec4(0, 1, 2, 3), + glm::vec4(4, 5, 6, 7)); + + glm::mat2x4 m1{0, 1, 2, 3, 4, 5, 6, 7}; + + glm::mat2x4 m2{ + {0, 1, 2, 3}, + {4, 5, 6, 7}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat2x4> v1{ + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7} + }; + + std::vector<glm::mat2x4> v2{ + { + { 0, 1, 2, 3}, + { 4, 5, 6, 7} + }, + { + { 0, 1, 2, 3}, + { 4, 5, 6, 7} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat2x4 B(A); + glm::mat2x4 Identity(1.0f); + + for(glm::length_t i = 0, length = B.length(); i < length; ++i) + Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 32 == sizeof(glm::mat2x4) ? 0 : 1; + Error += 64 == sizeof(glm::dmat2x4) ? 0 : 1; + Error += glm::mat2x4().length() == 2 ? 0 : 1; + Error += glm::dmat2x4().length() == 2 ? 0 : 1; + Error += glm::mat2x4::length() == 2 ? 0 : 1; + Error += glm::dmat2x4::length() == 2 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat2x4::length() == 2, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + + + diff --git a/3rdparty/glm/source/test/core/core_type_mat3x2.cpp b/3rdparty/glm/source/test/core/core_type_mat3x2.cpp new file mode 100644 index 0000000..7a40f90 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat3x2.cpp @@ -0,0 +1,148 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static bool test_operators() +{ + glm::mat3x2 l(1.0f); + glm::mat3x2 m(1.0f); + glm::vec3 u(1.0f); + glm::vec2 v(1.0f); + float x = 1.0f; + glm::vec2 a = m * u; + glm::vec3 b = v * m; + glm::mat3x2 n = x / m; + glm::mat3x2 o = m / x; + glm::mat3x2 p = x * m; + glm::mat3x2 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat3x2 m0( + glm::vec2(0, 1), + glm::vec2(2, 3), + glm::vec2(4, 5)); + + glm::mat3x2 m1{0, 1, 2, 3, 4, 5}; + + glm::mat3x2 m2{ + {0, 1}, + {2, 3}, + {4, 5}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat3x2> v1{ + {0, 1, 2, 3, 4, 5}, + {0, 1, 2, 3, 4, 5} + }; + + std::vector<glm::mat3x2> v2{ + { + { 0, 1}, + { 2, 3}, + { 4, 5} + }, + { + { 0, 1}, + { 2, 3}, + { 4, 5} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat3x2 B(A); + glm::mat3x2 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 24 == sizeof(glm::mat3x2) ? 0 : 1; + Error += 48 == sizeof(glm::dmat3x2) ? 0 : 1; + Error += glm::mat3x2().length() == 3 ? 0 : 1; + Error += glm::dmat3x2().length() == 3 ? 0 : 1; + Error += glm::mat3x2::length() == 3 ? 0 : 1; + Error += glm::dmat3x2::length() == 3 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat3x2::length() == 3, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + + diff --git a/3rdparty/glm/source/test/core/core_type_mat3x3.cpp b/3rdparty/glm/source/test/core/core_type_mat3x3.cpp new file mode 100644 index 0000000..99e1f41 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat3x3.cpp @@ -0,0 +1,197 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/matrix.hpp> +#include <glm/vector_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static int test_mat3x3() +{ + glm::dmat3 Mat0( + glm::dvec3(0.6f, 0.2f, 0.3f), + glm::dvec3(0.2f, 0.7f, 0.5f), + glm::dvec3(0.3f, 0.5f, 0.7f)); + glm::dmat3 Inv0 = glm::inverse(Mat0); + glm::dmat3 Res0 = Mat0 * Inv0; + + return glm::all(glm::equal(Res0, glm::dmat3(1.0), 0.01)) ? 0 : 1; +} + +static int test_operators() +{ + glm::mat3x3 l(1.0f); + glm::mat3x3 m(1.0f); + glm::vec3 u(1.0f); + glm::vec3 v(1.0f); + float x = 1.0f; + glm::vec3 a = m * u; + glm::vec3 b = v * m; + glm::mat3x3 n = x / m; + glm::mat3x3 o = m / x; + glm::mat3x3 p = x * m; + glm::mat3x3 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +static int test_inverse() +{ + int Error(0); + + { + glm::mat3 const Matrix( + glm::vec3(0.6f, 0.2f, 0.3f), + glm::vec3(0.2f, 0.7f, 0.5f), + glm::vec3(0.3f, 0.5f, 0.7f)); + glm::mat3 const Inverse = glm::inverse(Matrix); + glm::mat3 const Identity = Matrix * Inverse; + + Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1; + } + + { + glm::mat3 const Matrix( + glm::vec3(0.6f, 0.2f, 0.3f), + glm::vec3(0.2f, 0.7f, 0.5f), + glm::vec3(0.3f, 0.5f, 0.7f)); + glm::mat3 const Identity = Matrix / Matrix; + + Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1; + Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1; + } + + return Error; +} + +static int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat3x3 m0( + glm::vec3(0, 1, 2), + glm::vec3(3, 4, 5), + glm::vec3(6, 7, 8)); + + glm::mat3x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8}; + + glm::mat3x3 m2{ + {0, 1, 2}, + {3, 4, 5}, + {6, 7, 8}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat3x3> v1{ + {0, 1, 2, 3, 4, 5, 6, 7, 8}, + {0, 1, 2, 3, 4, 5, 6, 7, 8} + }; + + std::vector<glm::mat3x3> v2{ + { + { 0, 1, 2}, + { 3, 4, 5}, + { 6, 7, 8} + }, + { + { 0, 1, 2}, + { 3, 4, 5}, + { 6, 7, 8} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat3x3 B(A); + glm::mat3x3 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 36 == sizeof(glm::mat3x3) ? 0 : 1; + Error += 72 == sizeof(glm::dmat3x3) ? 0 : 1; + Error += glm::mat3x3().length() == 3 ? 0 : 1; + Error += glm::dmat3x3().length() == 3 ? 0 : 1; + Error += glm::mat3x3::length() == 3 ? 0 : 1; + Error += glm::dmat3x3::length() == 3 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat3x3::length() == 3, "GLM: Failed constexpr"); + + constexpr glm::mat3x3 const Z(0.0f); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_mat3x3(); + Error += test_operators(); + Error += test_inverse(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_type_mat3x4.cpp b/3rdparty/glm/source/test/core/core_type_mat3x4.cpp new file mode 100644 index 0000000..97d4574 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat3x4.cpp @@ -0,0 +1,149 @@ +#include <glm/gtc/epsilon.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static bool test_operators() +{ + glm::mat3x4 l(1.0f); + glm::mat3x4 m(1.0f); + glm::vec3 u(1.0f); + glm::vec4 v(1.0f); + float x = 1.0f; + glm::vec4 a = m * u; + glm::vec3 b = v * m; + glm::mat3x4 n = x / m; + glm::mat3x4 o = m / x; + glm::mat3x4 p = x * m; + glm::mat3x4 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat3x4 m0( + glm::vec4(0, 1, 2, 3), + glm::vec4(4, 5, 6, 7), + glm::vec4(8, 9, 10, 11)); + + glm::mat3x4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + + glm::mat3x4 m2{ + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 10, 11}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat3x4> v1{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }; + + std::vector<glm::mat3x4> v2{ + { + { 0, 1, 2, 3}, + { 4, 5, 6, 7}, + { 8, 9, 10, 11} + }, + { + { 0, 1, 2, 3}, + { 4, 5, 6, 7}, + { 8, 9, 10, 11} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat3x4 B(A); + glm::mat3x4 Identity(1.0f); + + for(glm::length_t i = 0, length = B.length(); i < length; ++i) + Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 48 == sizeof(glm::mat3x4) ? 0 : 1; + Error += 96 == sizeof(glm::dmat3x4) ? 0 : 1; + Error += glm::mat3x4().length() == 3 ? 0 : 1; + Error += glm::dmat3x4().length() == 3 ? 0 : 1; + Error += glm::mat3x4::length() == 3 ? 0 : 1; + Error += glm::dmat3x4::length() == 3 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat3x4::length() == 3, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_type_mat4x2.cpp b/3rdparty/glm/source/test/core/core_type_mat4x2.cpp new file mode 100644 index 0000000..7133edc --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat4x2.cpp @@ -0,0 +1,151 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static int test_operators() +{ + glm::mat4x2 l(1.0f); + glm::mat4x2 m(1.0f); + glm::vec4 u(1.0f); + glm::vec2 v(1.0f); + float x = 1.0f; + glm::vec2 a = m * u; + glm::vec4 b = v * m; + glm::mat4x2 n = x / m; + glm::mat4x2 o = m / x; + glm::mat4x2 p = x * m; + glm::mat4x2 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat4x2 m0( + glm::vec2(0, 1), + glm::vec2(2, 3), + glm::vec2(4, 5), + glm::vec2(6, 7)); + + glm::mat4x2 m1{0, 1, 2, 3, 4, 5, 6, 7}; + + glm::mat4x2 m2{ + {0, 1}, + {2, 3}, + {4, 5}, + {6, 7}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat4x2> v1{ + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7} + }; + + std::vector<glm::mat4x2> v2{ + { + { 0, 1}, + { 4, 5}, + { 8, 9}, + { 12, 13} + }, + { + { 0, 1}, + { 4, 5}, + { 8, 9}, + { 12, 13} + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat4x2 B(A); + glm::mat4x2 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 32 == sizeof(glm::mat4x2) ? 0 : 1; + Error += 64 == sizeof(glm::dmat4x2) ? 0 : 1; + Error += glm::mat4x2().length() == 4 ? 0 : 1; + Error += glm::dmat4x2().length() == 4 ? 0 : 1; + Error += glm::mat4x2::length() == 4 ? 0 : 1; + Error += glm::dmat4x2::length() == 4 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat4x2::length() == 4, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + diff --git a/3rdparty/glm/source/test/core/core_type_mat4x3.cpp b/3rdparty/glm/source/test/core/core_type_mat4x3.cpp new file mode 100644 index 0000000..1c65e7f --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat4x3.cpp @@ -0,0 +1,152 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/mat2x2.hpp> +#include <glm/mat2x3.hpp> +#include <glm/mat2x4.hpp> +#include <glm/mat3x2.hpp> +#include <glm/mat3x3.hpp> +#include <glm/mat3x4.hpp> +#include <glm/mat4x2.hpp> +#include <glm/mat4x3.hpp> +#include <glm/mat4x4.hpp> +#include <vector> + +static int test_operators() +{ + glm::mat4x3 l(1.0f); + glm::mat4x3 m(1.0f); + glm::vec4 u(1.0f); + glm::vec3 v(1.0f); + float x = 1.0f; + glm::vec3 a = m * u; + glm::vec4 b = v * m; + glm::mat4x3 n = x / m; + glm::mat4x3 o = m / x; + glm::mat4x3 p = x * m; + glm::mat4x3 q = m * x; + bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>())); + bool S = glm::all(glm::equal(m, l, glm::epsilon<float>())); + + return (S && !R) ? 0 : 1; +} + +int test_ctr() +{ + int Error(0); + +#if(GLM_HAS_INITIALIZER_LISTS) + glm::mat4x3 m0( + glm::vec3(0, 1, 2), + glm::vec3(3, 4, 5), + glm::vec3(6, 7, 8), + glm::vec3(9, 10, 11)); + + glm::mat4x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + + glm::mat4x3 m2{ + {0, 1, 2}, + {3, 4, 5}, + {6, 7, 8}, + {9, 10, 11}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + std::vector<glm::mat4x3> v1{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }; + + std::vector<glm::mat4x3> v2{ + { + { 0, 1, 2 }, + { 4, 5, 6 }, + { 8, 9, 10 }, + { 12, 13, 14 } + }, + { + { 0, 1, 2 }, + { 4, 5, 6 }, + { 8, 9, 10 }, + { 12, 13, 14 } + } + }; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +namespace cast +{ + template<typename genType> + int entry() + { + int Error = 0; + + genType A(1.0f); + glm::mat4x3 B(A); + glm::mat4x3 Identity(1.0f); + + Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1; + + return Error; + } + + int test() + { + int Error = 0; + + Error += entry<glm::mat2x2>(); + Error += entry<glm::mat2x3>(); + Error += entry<glm::mat2x4>(); + Error += entry<glm::mat3x2>(); + Error += entry<glm::mat3x3>(); + Error += entry<glm::mat3x4>(); + Error += entry<glm::mat4x2>(); + Error += entry<glm::mat4x3>(); + Error += entry<glm::mat4x4>(); + + return Error; + } +}//namespace cast + +static int test_size() +{ + int Error = 0; + + Error += 48 == sizeof(glm::mat4x3) ? 0 : 1; + Error += 96 == sizeof(glm::dmat4x3) ? 0 : 1; + Error += glm::mat4x3().length() == 4 ? 0 : 1; + Error += glm::dmat4x3().length() == 4 ? 0 : 1; + Error += glm::mat4x3::length() == 4 ? 0 : 1; + Error += glm::dmat4x3::length() == 4 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat4x3::length() == 4, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += cast::test(); + Error += test_ctr(); + Error += test_operators(); + Error += test_size(); + Error += test_constexpr(); + + return Error; +} + + diff --git a/3rdparty/glm/source/test/core/core_type_mat4x4.cpp b/3rdparty/glm/source/test/core/core_type_mat4x4.cpp new file mode 100644 index 0000000..0be87f1 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_mat4x4.cpp @@ -0,0 +1,218 @@ +#include <glm/gtc/constants.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/ext/matrix_relational.hpp> +#include <glm/matrix.hpp> +#include <glm/mat4x4.hpp> +#include <glm/vec4.hpp> +#include <vector> + +template <typename matType, typename vecType> +static int test_operators() +{ + typedef typename matType::value_type value_type; + + value_type const Epsilon = static_cast<value_type>(0.001); + + int Error = 0; + + matType const M(static_cast<value_type>(2.0f)); + matType const N(static_cast<value_type>(1.0f)); + vecType const U(static_cast<value_type>(2.0f)); + + { + matType const P = N * static_cast<value_type>(2.0f); + Error += glm::all(glm::equal(P, M, Epsilon)) ? 0 : 1; + + matType const Q = M / static_cast<value_type>(2.0f); + Error += glm::all(glm::equal(Q, N, Epsilon)) ? 0 : 1; + } + + { + vecType const V = M * U; + Error += glm::all(glm::equal(V, vecType(static_cast<value_type>(4.f)), Epsilon)) ? 0 : 1; + + vecType const W = U / M; + Error += glm::all(glm::equal(W, vecType(static_cast<value_type>(1.f)), Epsilon)) ? 0 : 1; + } + + { + matType const O = M * N; + Error += glm::all(glm::equal(O, matType(static_cast<value_type>(2.f)), Epsilon)) ? 0 : 1; + } + + return Error; +} + +template <typename matType> +static int test_inverse() +{ + typedef typename matType::value_type value_type; + + value_type const Epsilon = static_cast<value_type>(0.001); + + int Error = 0; + + matType const Identity(static_cast<value_type>(1.0f)); + matType const Matrix( + glm::vec4(0.6f, 0.2f, 0.3f, 0.4f), + glm::vec4(0.2f, 0.7f, 0.5f, 0.3f), + glm::vec4(0.3f, 0.5f, 0.7f, 0.2f), + glm::vec4(0.4f, 0.3f, 0.2f, 0.6f)); + matType const Inverse = Identity / Matrix; + matType const Result = Matrix * Inverse; + + Error += glm::all(glm::equal(Identity, Result, Epsilon)) ? 0 : 1; + + return Error; +} + +static int test_ctr() +{ + int Error = 0; + +#if GLM_HAS_TRIVIAL_QUERIES + //Error += std::is_trivially_default_constructible<glm::mat4>::value ? 0 : 1; + //Error += std::is_trivially_copy_assignable<glm::mat4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::mat4>::value ? 0 : 1; + //Error += std::is_copy_constructible<glm::mat4>::value ? 0 : 1; + //Error += std::has_trivial_copy_constructor<glm::mat4>::value ? 0 : 1; +#endif + +#if GLM_HAS_INITIALIZER_LISTS + glm::mat4 const m0( + glm::vec4(0, 1, 2, 3), + glm::vec4(4, 5, 6, 7), + glm::vec4(8, 9, 10, 11), + glm::vec4(12, 13, 14, 15)); + + assert(sizeof(m0) == 4 * 4 * 4); + + glm::vec4 const V{0, 1, 2, 3}; + + glm::mat4 const m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + + glm::mat4 const m2{ + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 10, 11}, + {12, 13, 14, 15}}; + + Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1; + + + std::vector<glm::mat4> const m3{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}; + + glm::mat4 const m4{ + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1} }; + + Error += glm::equal(m4[0][0], 1.0f, 0.0001f) ? 0 : 1; + Error += glm::equal(m4[3][3], 1.0f, 0.0001f) ? 0 : 1; + + std::vector<glm::mat4> const v1{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}; + + std::vector<glm::mat4> const v2{ + { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 8, 9, 10, 11 }, + { 12, 13, 14, 15 } + }, + { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 8, 9, 10, 11 }, + { 12, 13, 14, 15 } + }}; + +#endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +static int test_member_alloc_bug() +{ + int Error = 0; + + struct repro + { + repro(){ this->matrix = new glm::mat4(); } + ~repro(){delete this->matrix;} + + glm::mat4* matrix; + }; + + repro Repro; + + return Error; +} + +static int test_size() +{ + int Error = 0; + + Error += 64 == sizeof(glm::mat4) ? 0 : 1; + Error += 128 == sizeof(glm::dmat4) ? 0 : 1; + Error += glm::mat4().length() == 4 ? 0 : 1; + Error += glm::dmat4().length() == 4 ? 0 : 1; + Error += glm::mat4::length() == 4 ? 0 : 1; + Error += glm::dmat4::length() == 4 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::mat4::length() == 4, "GLM: Failed constexpr"); + constexpr glm::mat4 A(1.f); + constexpr glm::mat4 B(1.f); + constexpr glm::bvec4 C = glm::equal(A, B, 0.01f); + static_assert(glm::all(C), "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_member_alloc_bug(); + Error += test_ctr(); + + Error += test_operators<glm::mat4, glm::vec4>(); + Error += test_operators<glm::lowp_mat4, glm::lowp_vec4>(); + Error += test_operators<glm::mediump_mat4, glm::mediump_vec4>(); + Error += test_operators<glm::highp_mat4, glm::highp_vec4>(); + + Error += test_operators<glm::dmat4, glm::dvec4>(); + Error += test_operators<glm::lowp_dmat4, glm::lowp_dvec4>(); + Error += test_operators<glm::mediump_dmat4, glm::mediump_dvec4>(); + Error += test_operators<glm::highp_dmat4, glm::highp_dvec4>(); + + Error += test_inverse<glm::mat4>(); + Error += test_inverse<glm::lowp_mat4>(); + Error += test_inverse<glm::mediump_mat4>(); + Error += test_inverse<glm::highp_mat4>(); + + Error += test_inverse<glm::dmat4>(); + Error += test_inverse<glm::lowp_dmat4>(); + Error += test_inverse<glm::mediump_dmat4>(); + Error += test_inverse<glm::highp_dmat4>(); + + Error += test_size(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_vec1.cpp b/3rdparty/glm/source/test/core/core_type_vec1.cpp new file mode 100644 index 0000000..77f3f84 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_vec1.cpp @@ -0,0 +1,169 @@ +#define GLM_FORCE_SWIZZLE +#include <glm/gtc/constants.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/vec2.hpp> +#include <vector> + +static glm::vec1 g1; +static glm::vec1 g2(1); + +int test_vec1_operators() +{ + int Error = 0; + + glm::ivec1 A(1); + glm::ivec1 B(1); + { + bool R = A != B; + bool S = A == B; + + Error += (S && !R) ? 0 : 1; + } + + { + A *= 1; + B *= 1; + A += 1; + B += 1; + + bool R = A != B; + bool S = A == B; + + Error += (S && !R) ? 0 : 1; + } + + return Error; +} + +int test_vec1_ctor() +{ + int Error = 0; + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1; + + Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1; +# endif + +/* +#if GLM_HAS_INITIALIZER_LISTS + { + glm::vec1 a{ 0 }; + std::vector<glm::vec1> v = { + {0.f}, + {4.f}, + {8.f}}; + } + + { + glm::dvec2 a{ 0 }; + std::vector<glm::dvec1> v = { + {0.0}, + {4.0}, + {8.0}}; + } +#endif +*/ + + { + glm::vec2 A = glm::vec2(2.0f); + glm::vec2 B = glm::vec2(2.0f, 3.0f); + glm::vec2 C = glm::vec2(2.0f, 3.0); + //glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says? + glm::vec2 E(glm::dvec2(2.0)); + glm::vec2 F(glm::ivec2(2)); + } + + return Error; +} + +static int test_vec1_size() +{ + int Error = 0; + + Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1; + Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1; + Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1; + Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1; + Error += glm::vec1().length() == 1 ? 0 : 1; + Error += glm::dvec1().length() == 1 ? 0 : 1; + Error += glm::vec1::length() == 1 ? 0 : 1; + Error += glm::dvec1::length() == 1 ? 0 : 1; + + return Error; +} + +static int test_vec1_operator_increment() +{ + int Error(0); + + glm::ivec1 v0(1); + glm::ivec1 v1(v0); + glm::ivec1 v2(v0); + glm::ivec1 v3 = ++v1; + glm::ivec1 v4 = v2++; + + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; + + int i0(1); + int i1(i0); + int i2(i0); + int i3 = ++i1; + int i4 = i2++; + + Error += i0 == i4 ? 0 : 1; + Error += i1 == i2 ? 0 : 1; + Error += i1 == i3 ? 0 : 1; + + return Error; +} + +static int test_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::vec1 A = glm::vec1(1.0f); + //glm::vec1 B = A.x; + glm::vec1 C(A.x); + + //Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr"); + static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_vec1_size(); + Error += test_vec1_ctor(); + Error += test_vec1_operators(); + Error += test_vec1_operator_increment(); + Error += test_swizzle(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_vec2.cpp b/3rdparty/glm/source/test/core/core_type_vec2.cpp new file mode 100644 index 0000000..308c61f --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_vec2.cpp @@ -0,0 +1,392 @@ +#define GLM_FORCE_SWIZZLE +#include <glm/gtc/vec1.hpp> +#include <glm/gtc/constants.hpp> +#include <glm/ext/vector_float1.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/vector_relational.hpp> +#include <glm/vec2.hpp> +#include <vector> +#if GLM_HAS_TRIVIAL_QUERIES +# include <type_traits> +#endif + +static glm::ivec2 g1; +static glm::ivec2 g2(1); +static glm::ivec2 g3(1, 1); + +static int test_operators() +{ + int Error = 0; + + { + glm::ivec2 A(1); + glm::ivec2 B(1); + Error += A != B ? 1 : 0; + Error += A == B ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A + 1.0f; + A += 1.0f; + Error += glm::all(glm::equal(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 B(2.0f,-1.0f); + glm::vec2 C = A + B; + A += B; + Error += glm::all(glm::equal(A, glm::vec2(3.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A - 1.0f; + A -= 1.0f; + Error += glm::all(glm::equal(A, glm::vec2(0.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 B(2.0f,-1.0f); + glm::vec2 C = A - B; + A -= B; + Error += glm::all(glm::equal(A, glm::vec2(-1.0f, 2.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A * 2.0f; + A *= 2.0f; + Error += glm::all(glm::equal(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(2.0f); + glm::vec2 B(2.0f); + glm::vec2 C = A / B; + A /= B; + Error += glm::all(glm::equal(A, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f, 2.0f); + glm::vec2 B(4.0f, 5.0f); + + glm::vec2 C = A + B; + Error += glm::all(glm::equal(C, glm::vec2(5, 7), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 D = B - A; + Error += glm::all(glm::equal(D, glm::vec2(3, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 E = A * B; + Error += glm::all(glm::equal(E, glm::vec2(4, 10), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 F = B / A; + Error += glm::all(glm::equal(F, glm::vec2(4, 2.5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 G = A + 1.0f; + Error += glm::all(glm::equal(G, glm::vec2(2, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 H = B - 1.0f; + Error += glm::all(glm::equal(H, glm::vec2(3, 4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 I = A * 2.0f; + Error += glm::all(glm::equal(I, glm::vec2(2, 4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 J = B / 2.0f; + Error += glm::all(glm::equal(J, glm::vec2(2, 2.5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 K = 1.0f + A; + Error += glm::all(glm::equal(K, glm::vec2(2, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 L = 1.0f - B; + Error += glm::all(glm::equal(L, glm::vec2(-3, -4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 M = 2.0f * A; + Error += glm::all(glm::equal(M, glm::vec2(2, 4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec2 N = 2.0f / B; + Error += glm::all(glm::equal(N, glm::vec2(0.5, 2.0 / 5.0), glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec2 A(1.0f, 2.0f); + glm::vec2 B(4.0f, 5.0f); + + A += B; + Error += glm::all(glm::equal(A, glm::vec2(5, 7), glm::epsilon<float>())) ? 0 : 1; + + A += 1.0f; + Error += glm::all(glm::equal(A, glm::vec2(6, 8), glm::epsilon<float>())) ? 0 : 1; + } + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B(4.0f, 5.0f); + + B -= A; + Error += B == glm::ivec2(3, 3) ? 0 : 1; + + B -= 1.0f; + Error += B == glm::ivec2(2, 2) ? 0 : 1; + } + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B(4.0f, 5.0f); + + A *= B; + Error += A == glm::ivec2(4, 10) ? 0 : 1; + + A *= 2; + Error += A == glm::ivec2(8, 20) ? 0 : 1; + } + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B(4.0f, 16.0f); + + B /= A; + Error += B == glm::ivec2(4, 8) ? 0 : 1; + + B /= 2.0f; + Error += B == glm::ivec2(2, 4) ? 0 : 1; + } + { + glm::ivec2 B(2); + + B /= B.y; + Error += B == glm::ivec2(1) ? 0 : 1; + } + + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B = -A; + Error += B == glm::ivec2(-1.0f, -2.0f) ? 0 : 1; + } + + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B = --A; + Error += B == glm::ivec2(0.0f, 1.0f) ? 0 : 1; + } + + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B = A--; + Error += B == glm::ivec2(1.0f, 2.0f) ? 0 : 1; + Error += A == glm::ivec2(0.0f, 1.0f) ? 0 : 1; + } + + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B = ++A; + Error += B == glm::ivec2(2.0f, 3.0f) ? 0 : 1; + } + + { + glm::ivec2 A(1.0f, 2.0f); + glm::ivec2 B = A++; + Error += B == glm::ivec2(1.0f, 2.0f) ? 0 : 1; + Error += A == glm::ivec2(2.0f, 3.0f) ? 0 : 1; + } + + return Error; +} + +static int test_ctor() +{ + int Error = 0; + + { + glm::ivec2 A(1); + glm::ivec2 B(A); + Error += A == B ? 0 : 1; + } + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::vec2>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::dvec2>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::ivec2>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::uvec2>::value ? 0 : 1; + + Error += std::is_copy_constructible<glm::vec2>::value ? 0 : 1; +# endif + +#if GLM_HAS_INITIALIZER_LISTS + { + glm::vec2 a{ 0, 1 }; + std::vector<glm::vec2> v = { + {0, 1}, + {4, 5}, + {8, 9}}; + } + + { + glm::dvec2 a{ 0, 1 }; + std::vector<glm::dvec2> v = { + {0, 1}, + {4, 5}, + {8, 9}}; + } +#endif + + { + glm::vec2 A = glm::vec2(2.0f); + glm::vec2 B = glm::vec2(2.0f, 3.0f); + glm::vec2 C = glm::vec2(2.0f, 3.0); + //glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says? + glm::vec2 E(glm::dvec2(2.0)); + glm::vec2 F(glm::ivec2(2)); + } + + { + glm::vec1 const R(1.0f); + glm::vec1 const S(2.0f); + glm::vec2 const O(1.0f, 2.0f); + + glm::vec2 const A(R); + glm::vec2 const B(1.0f); + Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1; + + glm::vec2 const C(R, S); + Error += glm::all(glm::equal(C, O, 0.0001f)) ? 0 : 1; + + glm::vec2 const D(R, 2.0f); + Error += glm::all(glm::equal(D, O, 0.0001f)) ? 0 : 1; + + glm::vec2 const E(1.0f, S); + Error += glm::all(glm::equal(E, O, 0.0001f)) ? 0 : 1; + } + + { + glm::vec1 const R(1.0f); + glm::dvec1 const S(2.0); + glm::vec2 const O(1.0, 2.0); + + glm::vec2 const A(R); + glm::vec2 const B(1.0); + Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1; + + glm::vec2 const C(R, S); + Error += glm::all(glm::equal(C, O, 0.0001f)) ? 0 : 1; + + glm::vec2 const D(R, 2.0); + Error += glm::all(glm::equal(D, O, 0.0001f)) ? 0 : 1; + + glm::vec2 const E(1.0, S); + Error += glm::all(glm::equal(E, O, 0.0001f)) ? 0 : 1; + } + + return Error; +} + +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::vec2) == sizeof(glm::mediump_vec2) ? 0 : 1; + Error += 8 == sizeof(glm::mediump_vec2) ? 0 : 1; + Error += sizeof(glm::dvec2) == sizeof(glm::highp_dvec2) ? 0 : 1; + Error += 16 == sizeof(glm::highp_dvec2) ? 0 : 1; + Error += glm::vec2().length() == 2 ? 0 : 1; + Error += glm::dvec2().length() == 2 ? 0 : 1; + Error += glm::vec2::length() == 2 ? 0 : 1; + Error += glm::dvec2::length() == 2 ? 0 : 1; + + GLM_CONSTEXPR std::size_t Length = glm::vec2::length(); + Error += Length == 2 ? 0 : 1; + + return Error; +} + +static int test_operator_increment() +{ + int Error = 0; + + glm::ivec2 v0(1); + glm::ivec2 v1(v0); + glm::ivec2 v2(v0); + glm::ivec2 v3 = ++v1; + glm::ivec2 v4 = v2++; + + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; + + int i0(1); + int i1(i0); + int i2(i0); + int i3 = ++i1; + int i4 = i2++; + + Error += i0 == i4 ? 0 : 1; + Error += i1 == i2 ? 0 : 1; + Error += i1 == i3 ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); +#endif + + return 0; +} + +static int test_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::vec2 A = glm::vec2(1.0f, 2.0f); + glm::vec2 B = A.xy; + glm::vec2 C(A.xy); + glm::vec2 D(A.xy()); + + Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1; + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + Error += glm::all(glm::equal(A, D, 0.0001f)) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::vec2 A = glm::vec2(1.0f, 2.0f); + glm::vec2 B = A.xy(); + glm::vec2 C(A.xy()); + + Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1; + Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_size(); + Error += test_ctor(); + Error += test_operators(); + Error += test_operator_increment(); + Error += test_swizzle(); + Error += test_constexpr(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_vec3.cpp b/3rdparty/glm/source/test/core/core_type_vec3.cpp new file mode 100644 index 0000000..4da8187 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_vec3.cpp @@ -0,0 +1,628 @@ +#define GLM_FORCE_SWIZZLE +#include <glm/gtc/constants.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/vector_relational.hpp> +#include <glm/geometric.hpp> +#include <glm/vec2.hpp> +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> +#include <vector> + +static glm::vec3 g1; +static glm::vec3 g2(1); +static glm::vec3 g3(1, 1, 1); + +int test_vec3_ctor() +{ + int Error = 0; + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::vec3>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::dvec3>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::ivec3>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::uvec3>::value ? 0 : 1; + + Error += std::is_copy_constructible<glm::vec3>::value ? 0 : 1; +# endif + +# if GLM_HAS_INITIALIZER_LISTS + { + glm::vec3 a{ 0, 1, 2 }; + std::vector<glm::vec3> v = { + {0, 1, 2}, + {4, 5, 6}, + {8, 9, 0}}; + } + + { + glm::dvec3 a{ 0, 1, 2 }; + std::vector<glm::dvec3> v = { + {0, 1, 2}, + {4, 5, 6}, + {8, 9, 0}}; + } +# endif + + { + glm::ivec3 A(1); + glm::ivec3 B(1, 1, 1); + + Error += A == B ? 0 : 1; + } + + { + std::vector<glm::ivec3> Tests; + Tests.push_back(glm::ivec3(glm::ivec2(1, 2), 3)); + Tests.push_back(glm::ivec3(1, glm::ivec2(2, 3))); + Tests.push_back(glm::ivec3(1, 2, 3)); + Tests.push_back(glm::ivec3(glm::ivec4(1, 2, 3, 4))); + + for(std::size_t i = 0; i < Tests.size(); ++i) + Error += Tests[i] == glm::ivec3(1, 2, 3) ? 0 : 1; + } + + { + glm::vec1 const R(1.0f); + glm::vec1 const S(2.0f); + glm::vec1 const T(3.0f); + glm::vec3 const O(1.0f, 2.0f, 3.0f); + + glm::vec3 const A(R); + glm::vec3 const B(1.0f); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const C(R, S, T); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const D(R, 2.0f, 3.0f); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const E(1.0f, S, 3.0f); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const F(1.0f, S, T); + Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const G(R, 2.0f, T); + Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const H(R, S, 3.0f); + Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec1 const R(1.0); + glm::dvec1 const S(2.0); + glm::vec1 const T(3.0); + glm::vec3 const O(1.0f, 2.0f, 3.0f); + + glm::vec3 const A(R); + glm::vec3 const B(1.0); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const C(R, S, T); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const D(R, 2.0, 3.0); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const E(1.0f, S, 3.0); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const F(1.0, S, T); + Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const G(R, 2.0, T); + Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const H(R, S, 3.0); + Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +float foo() +{ + glm::vec3 bar = glm::vec3(0.0f, 1.0f, 1.0f); + + return glm::length(bar); +} + +static int test_bvec3_ctor() +{ + int Error = 0; + + glm::bvec3 const A(true); + glm::bvec3 const B(true); + glm::bvec3 const C(false); + glm::bvec3 const D = A && B; + glm::bvec3 const E = A && C; + glm::bvec3 const F = A || C; + + Error += D == glm::bvec3(true) ? 0 : 1; + Error += E == glm::bvec3(false) ? 0 : 1; + Error += F == glm::bvec3(true) ? 0 : 1; + + bool const G = A == C; + bool const H = A != C; + Error += !G ? 0 : 1; + Error += H ? 0 : 1; + + return Error; +} + +static int test_vec3_operators() +{ + int Error = 0; + + { + glm::ivec3 A(1); + glm::ivec3 B(1); + bool R = A != B; + bool S = A == B; + + Error += (S && !R) ? 0 : 1; + } + + { + glm::vec3 const A(1.0f, 2.0f, 3.0f); + glm::vec3 const B(4.0f, 5.0f, 6.0f); + + glm::vec3 const C = A + B; + Error += glm::all(glm::equal(C, glm::vec3(5, 7, 9), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const D = B - A; + Error += glm::all(glm::equal(D, glm::vec3(3, 3, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const E = A * B; + Error += glm::all(glm::equal(E, glm::vec3(4, 10, 18), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const F = B / A; + Error += glm::all(glm::equal(F, glm::vec3(4, 2.5, 2), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const G = A + 1.0f; + Error += glm::all(glm::equal(G, glm::vec3(2, 3, 4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const H = B - 1.0f; + Error += glm::all(glm::equal(H, glm::vec3(3, 4, 5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const I = A * 2.0f; + Error += glm::all(glm::equal(I, glm::vec3(2, 4, 6), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const J = B / 2.0f; + Error += glm::all(glm::equal(J, glm::vec3(2, 2.5, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const K = 1.0f + A; + Error += glm::all(glm::equal(K, glm::vec3(2, 3, 4), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const L = 1.0f - B; + Error += glm::all(glm::equal(L, glm::vec3(-3, -4, -5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const M = 2.0f * A; + Error += glm::all(glm::equal(M, glm::vec3(2, 4, 6), glm::epsilon<float>())) ? 0 : 1; + + glm::vec3 const N = 2.0f / B; + Error += glm::all(glm::equal(N, glm::vec3(0.5, 2.0 / 5.0, 2.0 / 6.0), glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B(4.0f, 5.0f, 6.0f); + + A += B; + Error += A == glm::ivec3(5, 7, 9) ? 0 : 1; + + A += 1; + Error += A == glm::ivec3(6, 8, 10) ? 0 : 1; + } + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B(4.0f, 5.0f, 6.0f); + + B -= A; + Error += B == glm::ivec3(3, 3, 3) ? 0 : 1; + + B -= 1; + Error += B == glm::ivec3(2, 2, 2) ? 0 : 1; + } + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B(4.0f, 5.0f, 6.0f); + + A *= B; + Error += A == glm::ivec3(4, 10, 18) ? 0 : 1; + + A *= 2; + Error += A == glm::ivec3(8, 20, 36) ? 0 : 1; + } + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B(4.0f, 4.0f, 6.0f); + + B /= A; + Error += B == glm::ivec3(4, 2, 2) ? 0 : 1; + + B /= 2; + Error += B == glm::ivec3(2, 1, 1) ? 0 : 1; + } + { + glm::ivec3 B(2); + + B /= B.y; + Error += B == glm::ivec3(1) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = -A; + Error += B == glm::ivec3(-1.0f, -2.0f, -3.0f) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = --A; + Error += B == glm::ivec3(0.0f, 1.0f, 2.0f) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = A--; + Error += B == glm::ivec3(1.0f, 2.0f, 3.0f) ? 0 : 1; + Error += A == glm::ivec3(0.0f, 1.0f, 2.0f) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = ++A; + Error += B == glm::ivec3(2.0f, 3.0f, 4.0f) ? 0 : 1; + } + + { + glm::ivec3 A(1.0f, 2.0f, 3.0f); + glm::ivec3 B = A++; + Error += B == glm::ivec3(1.0f, 2.0f, 3.0f) ? 0 : 1; + Error += A == glm::ivec3(2.0f, 3.0f, 4.0f) ? 0 : 1; + } + + return Error; +} + +int test_vec3_size() +{ + int Error = 0; + + Error += sizeof(glm::vec3) == sizeof(glm::lowp_vec3) ? 0 : 1; + Error += sizeof(glm::vec3) == sizeof(glm::mediump_vec3) ? 0 : 1; + Error += sizeof(glm::vec3) == sizeof(glm::highp_vec3) ? 0 : 1; + Error += 12 == sizeof(glm::mediump_vec3) ? 0 : 1; + Error += sizeof(glm::dvec3) == sizeof(glm::lowp_dvec3) ? 0 : 1; + Error += sizeof(glm::dvec3) == sizeof(glm::mediump_dvec3) ? 0 : 1; + Error += sizeof(glm::dvec3) == sizeof(glm::highp_dvec3) ? 0 : 1; + Error += 24 == sizeof(glm::highp_dvec3) ? 0 : 1; + Error += glm::vec3().length() == 3 ? 0 : 1; + Error += glm::dvec3().length() == 3 ? 0 : 1; + Error += glm::vec3::length() == 3 ? 0 : 1; + Error += glm::dvec3::length() == 3 ? 0 : 1; + + GLM_CONSTEXPR std::size_t Length = glm::vec3::length(); + Error += Length == 3 ? 0 : 1; + + return Error; +} + +int test_vec3_swizzle3_2() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec3 v(1, 2, 3); + glm::ivec2 u; + + // Can not assign a vec3 swizzle to a vec2 + //u = v.xyz; //Illegal + //u = v.rgb; //Illegal + //u = v.stp; //Illegal + + u = v.xx; Error += (u.x == 1 && u.y == 1) ? 0 : 1; + u = v.xy; Error += (u.x == 1 && u.y == 2) ? 0 : 1; + u = v.xz; Error += (u.x == 1 && u.y == 3) ? 0 : 1; + u = v.yx; Error += (u.x == 2 && u.y == 1) ? 0 : 1; + u = v.yy; Error += (u.x == 2 && u.y == 2) ? 0 : 1; + u = v.yz; Error += (u.x == 2 && u.y == 3) ? 0 : 1; + u = v.zx; Error += (u.x == 3 && u.y == 1) ? 0 : 1; + u = v.zy; Error += (u.x == 3 && u.y == 2) ? 0 : 1; + u = v.zz; Error += (u.x == 3 && u.y == 3) ? 0 : 1; + + u = v.rr; Error += (u.r == 1 && u.g == 1) ? 0 : 1; + u = v.rg; Error += (u.r == 1 && u.g == 2) ? 0 : 1; + u = v.rb; Error += (u.r == 1 && u.g == 3) ? 0 : 1; + u = v.gr; Error += (u.r == 2 && u.g == 1) ? 0 : 1; + u = v.gg; Error += (u.r == 2 && u.g == 2) ? 0 : 1; + u = v.gb; Error += (u.r == 2 && u.g == 3) ? 0 : 1; + u = v.br; Error += (u.r == 3 && u.g == 1) ? 0 : 1; + u = v.bg; Error += (u.r == 3 && u.g == 2) ? 0 : 1; + u = v.bb; Error += (u.r == 3 && u.g == 3) ? 0 : 1; + + u = v.ss; Error += (u.s == 1 && u.t == 1) ? 0 : 1; + u = v.st; Error += (u.s == 1 && u.t == 2) ? 0 : 1; + u = v.sp; Error += (u.s == 1 && u.t == 3) ? 0 : 1; + u = v.ts; Error += (u.s == 2 && u.t == 1) ? 0 : 1; + u = v.tt; Error += (u.s == 2 && u.t == 2) ? 0 : 1; + u = v.tp; Error += (u.s == 2 && u.t == 3) ? 0 : 1; + u = v.ps; Error += (u.s == 3 && u.t == 1) ? 0 : 1; + u = v.pt; Error += (u.s == 3 && u.t == 2) ? 0 : 1; + u = v.pp; Error += (u.s == 3 && u.t == 3) ? 0 : 1; + // Mixed member aliases are not valid + //u = v.rx; //Illegal + //u = v.sy; //Illegal + + u = glm::ivec2(1, 2); + v = glm::ivec3(1, 2, 3); + //v.xx = u; //Illegal + v.xy = u; Error += (v.x == 1 && v.y == 2 && v.z == 3) ? 0 : 1; + v.xz = u; Error += (v.x == 1 && v.y == 2 && v.z == 2) ? 0 : 1; + v.yx = u; Error += (v.x == 2 && v.y == 1 && v.z == 2) ? 0 : 1; + //v.yy = u; //Illegal + v.yz = u; Error += (v.x == 2 && v.y == 1 && v.z == 2) ? 0 : 1; + v.zx = u; Error += (v.x == 2 && v.y == 1 && v.z == 1) ? 0 : 1; + v.zy = u; Error += (v.x == 2 && v.y == 2 && v.z == 1) ? 0 : 1; + //v.zz = u; //Illegal + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + + return Error; +} + +int test_vec3_swizzle3_3() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec3 v(1, 2, 3); + glm::ivec3 u; + + u = v; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1; + + u = v.xyz; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1; + u = v.zyx; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + u.zyx = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + + u = v.rgb; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1; + u = v.bgr; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + u.bgr = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + + u = v.stp; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1; + u = v.pts; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + u.pts = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1; + } +# endif//GLM_LANG + + return Error; +} + +int test_vec3_swizzle_operators() +{ + int Error = 0; + + glm::ivec3 const u = glm::ivec3(1, 2, 3); + glm::ivec3 const v = glm::ivec3(10, 20, 30); + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec3 q; + + // Swizzle, swizzle binary operators + q = u.xyz + v.xyz; Error += (q == (u + v)) ? 0 : 1; + q = (u.zyx + v.zyx).zyx; Error += (q == (u + v)) ? 0 : 1; + q = (u.xyz - v.xyz); Error += (q == (u - v)) ? 0 : 1; + q = (u.xyz * v.xyz); Error += (q == (u * v)) ? 0 : 1; + q = (u.xxx * v.xxx); Error += (q == glm::ivec3(u.x * v.x)) ? 0 : 1; + q = (u.xyz / v.xyz); Error += (q == (u / v)) ? 0 : 1; + + // vec, swizzle binary operators + q = u + v.xyz; Error += (q == (u + v)) ? 0 : 1; + q = (u - v.xyz); Error += (q == (u - v)) ? 0 : 1; + q = (u * v.xyz); Error += (q == (u * v)) ? 0 : 1; + q = (u * v.xxx); Error += (q == v.x * u) ? 0 : 1; + q = (u / v.xyz); Error += (q == (u / v)) ? 0 : 1; + + // swizzle,vec binary operators + q = u.xyz + v; Error += (q == (u + v)) ? 0 : 1; + q = (u.xyz - v); Error += (q == (u - v)) ? 0 : 1; + q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1; + q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1; + q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1; + } +# endif//GLM_LANG + + // Compile errors + //q = (u.yz * v.xyz); + //q = (u * v.xy); + + return Error; +} + +int test_vec3_swizzle_functions() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + // NOTE: template functions cannot pick up the implicit conversion from + // a swizzle to the unswizzled type, therefore the operator() must be + // used. E.g.: + // + // glm::dot(u.xy, v.xy); <--- Compile error + // glm::dot(u.xy(), v.xy()); <--- Compiles correctly + + float r; + + // vec2 + glm::vec2 a(1, 2); + glm::vec2 b(10, 20); + r = glm::dot(a, b); Error += (int(r) == 50) ? 0 : 1; + r = glm::dot(glm::vec2(a.xy()), glm::vec2(b.xy())); Error += (int(r) == 50) ? 0 : 1; + r = glm::dot(glm::vec2(a.xy()), glm::vec2(b.yy())); Error += (int(r) == 60) ? 0 : 1; + + // vec3 + glm::vec3 u = glm::vec3(1, 2, 3); + glm::vec3 v = glm::vec3(10, 20, 30); + r = glm::dot(u, v); Error += (int(r) == 140) ? 0 : 1; + r = glm::dot(u.xyz(), v.zyz()); Error += (int(r) == 160) ? 0 : 1; + r = glm::dot(u, v.zyx()); Error += (int(r) == 100) ? 0 : 1; + r = glm::dot(u.xyz(), v); Error += (int(r) == 140) ? 0 : 1; + r = glm::dot(u.xy(), v.xy()); Error += (int(r) == 50) ? 0 : 1; + + // vec4 + glm::vec4 s = glm::vec4(1, 2, 3, 4); + glm::vec4 t = glm::vec4(10, 20, 30, 40); + r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1; + r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1; + r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + + return Error; +} + +int test_vec3_swizzle_partial() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::vec3 const A(1, 2, 3); + glm::vec3 B(A.xy, 3); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::ivec3 const A(1, 2, 3); + glm::ivec3 const B(1, A.yz); + Error += A == B ? 0 : 1; + } + + { + glm::ivec3 const A(1, 2, 3); + glm::ivec3 const B(A.xyz); + Error += A == B ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + + return Error; +} + +static int test_operator_increment() +{ + int Error = 0; + + glm::ivec3 v0(1); + glm::ivec3 v1(v0); + glm::ivec3 v2(v0); + glm::ivec3 v3 = ++v1; + glm::ivec3 v4 = v2++; + + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; + + int i0(1); + int i1(i0); + int i2(i0); + int i3 = ++i1; + int i4 = i2++; + + Error += i0 == i4 ? 0 : 1; + Error += i1 == i2 ? 0 : 1; + Error += i1 == i3 ? 0 : 1; + + return Error; +} + +static int test_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); + glm::vec3 B = A.xyz; + glm::vec3 C(A.xyz); + glm::vec3 D(A.xyz()); + glm::vec3 E(A.x, A.yz); + glm::vec3 F(A.x, A.yz()); + glm::vec3 G(A.xy, A.z); + glm::vec3 H(A.xy(), A.z); + + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f); + glm::vec3 B = A.xyz(); + glm::vec3 C(A.xyz()); + glm::vec3 D(A.xyz()); + glm::vec3 E(A.x, A.yz()); + glm::vec3 F(A.x, A.yz()); + glm::vec3 G(A.xy(), A.z); + glm::vec3 H(A.xy(), A.z); + + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_vec3_ctor(); + Error += test_bvec3_ctor(); + Error += test_vec3_operators(); + Error += test_vec3_size(); + Error += test_operator_increment(); + Error += test_constexpr(); + + Error += test_swizzle(); + Error += test_vec3_swizzle3_2(); + Error += test_vec3_swizzle3_3(); + Error += test_vec3_swizzle_partial(); + Error += test_vec3_swizzle_operators(); + Error += test_vec3_swizzle_functions(); + + return Error; +} diff --git a/3rdparty/glm/source/test/core/core_type_vec4.cpp b/3rdparty/glm/source/test/core/core_type_vec4.cpp new file mode 100644 index 0000000..5d65259 --- /dev/null +++ b/3rdparty/glm/source/test/core/core_type_vec4.cpp @@ -0,0 +1,850 @@ +#define GLM_FORCE_SWIZZLE +#include <glm/gtc/constants.hpp> +#include <glm/gtc/vec1.hpp> +#include <glm/ext/scalar_relational.hpp> +#include <glm/ext/vector_relational.hpp> +#include <glm/vector_relational.hpp> +#include <glm/vec2.hpp> +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> +#include <cstdio> +#include <ctime> +#include <vector> + +static glm::vec4 g1; +static glm::vec4 g2(1); +static glm::vec4 g3(1, 1, 1, 1); + +template <int Value> +struct mask +{ + enum{value = Value}; +}; + +enum comp +{ + X, + Y, + Z, + W +}; + +//template<comp X, comp Y, comp Z, comp W> +//__m128 swizzle(glm::vec4 const& v) +//{ +// __m128 Src = _mm_set_ps(v.w, v.z, v.y, v.x); +// return _mm_shuffle_ps(Src, Src, mask<(int(W) << 6) | (int(Z) << 4) | (int(Y) << 2) | (int(X) << 0)>::value); +//} + +static int test_vec4_ctor() +{ + int Error = 0; + + { + glm::ivec4 A(1, 2, 3, 4); + glm::ivec4 B(A); + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + } + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1; + Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1; + + Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1; +# endif + +#if GLM_HAS_INITIALIZER_LISTS + { + glm::vec4 a{ 0, 1, 2, 3 }; + std::vector<glm::vec4> v = { + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 0, 1}}; + } + + { + glm::dvec4 a{ 0, 1, 2, 3 }; + std::vector<glm::dvec4> v = { + {0, 1, 2, 3}, + {4, 5, 6, 7}, + {8, 9, 0, 1}}; + } +#endif + + { + glm::ivec4 const A(1); + glm::ivec4 const B(1, 1, 1, 1); + + Error += A == B ? 0 : 1; + } + + { + std::vector<glm::ivec4> Tests; + Tests.push_back(glm::ivec4(glm::ivec2(1, 2), 3, 4)); + Tests.push_back(glm::ivec4(1, glm::ivec2(2, 3), 4)); + Tests.push_back(glm::ivec4(1, 2, glm::ivec2(3, 4))); + Tests.push_back(glm::ivec4(glm::ivec3(1, 2, 3), 4)); + Tests.push_back(glm::ivec4(1, glm::ivec3(2, 3, 4))); + Tests.push_back(glm::ivec4(glm::ivec2(1, 2), glm::ivec2(3, 4))); + Tests.push_back(glm::ivec4(1, 2, 3, 4)); + Tests.push_back(glm::ivec4(glm::ivec4(1, 2, 3, 4))); + + for(std::size_t i = 0; i < Tests.size(); ++i) + Error += Tests[i] == glm::ivec4(1, 2, 3, 4) ? 0 : 1; + } + + { + glm::vec1 const R(1.0f); + glm::vec1 const S(2.0f); + glm::vec1 const T(3.0f); + glm::vec1 const U(4.0f); + glm::vec4 const O(1.0f, 2.0f, 3.0f, 4.0f); + + glm::vec4 const A(R); + glm::vec4 const B(1.0f); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const C(R, S, T, U); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const D(R, 2.0f, 3.0f, 4.0f); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const E(1.0f, S, 3.0f, 4.0f); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const F(R, S, 3.0f, 4.0f); + Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const G(1.0f, 2.0f, T, 4.0f); + Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const H(R, 2.0f, T, 4.0f); + Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const I(1.0f, S, T, 4.0f); + Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const J(R, S, T, 4.0f); + Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const K(R, 2.0f, 3.0f, U); + Error += glm::all(glm::equal(K, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const L(1.0f, S, 3.0f, U); + Error += glm::all(glm::equal(L, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const M(R, S, 3.0f, U); + Error += glm::all(glm::equal(M, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const N(1.0f, 2.0f, T, U); + Error += glm::all(glm::equal(N, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const P(R, 2.0f, T, U); + Error += glm::all(glm::equal(P, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const Q(1.0f, S, T, U); + Error += glm::all(glm::equal(Q, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const V(R, S, T, U); + Error += glm::all(glm::equal(V, O, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec1 const R(1.0f); + glm::dvec1 const S(2.0); + glm::vec1 const T(3.0); + glm::dvec1 const U(4.0); + glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0); + + glm::vec4 const A(R); + glm::vec4 const B(1.0); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const C(R, S, T, U); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const D(R, 2.0f, 3.0, 4.0f); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const E(1.0, S, 3.0f, 4.0); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const F(R, S, 3.0, 4.0f); + Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const G(1.0f, 2.0, T, 4.0); + Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const H(R, 2.0, T, 4.0); + Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const I(1.0, S, T, 4.0f); + Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const J(R, S, T, 4.0f); + Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const K(R, 2.0f, 3.0, U); + Error += glm::all(glm::equal(K, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const L(1.0f, S, 3.0, U); + Error += glm::all(glm::equal(L, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const M(R, S, 3.0, U); + Error += glm::all(glm::equal(M, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const N(1.0f, 2.0, T, U); + Error += glm::all(glm::equal(N, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const P(R, 2.0, T, U); + Error += glm::all(glm::equal(P, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const Q(1.0f, S, T, U); + Error += glm::all(glm::equal(Q, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const V(R, S, T, U); + Error += glm::all(glm::equal(V, O, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec1 const v1_0(1.0f); + glm::vec1 const v1_1(2.0f); + glm::vec1 const v1_2(3.0f); + glm::vec1 const v1_3(4.0f); + + glm::vec2 const v2_0(1.0f, 2.0f); + glm::vec2 const v2_1(2.0f, 3.0f); + glm::vec2 const v2_2(3.0f, 4.0f); + + glm::vec3 const v3_0(1.0f, 2.0f, 3.0f); + glm::vec3 const v3_1(2.0f, 3.0f, 4.0f); + + glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0); + + glm::vec4 const A(v1_0, v1_1, v2_2); + Error += glm::all(glm::equal(A, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const B(1.0f, 2.0f, v2_2); + Error += glm::all(glm::equal(B, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const C(v1_0, 2.0f, v2_2); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const D(1.0f, v1_1, v2_2); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const E(v2_0, v1_2, v1_3); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const F(v2_0, 3.0, v1_3); + Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const G(v2_0, v1_2, 4.0); + Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const H(v2_0, 3.0f, 4.0); + Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec1 const v1_0(1.0f); + glm::vec1 const v1_1(2.0f); + glm::vec1 const v1_2(3.0f); + glm::vec1 const v1_3(4.0f); + + glm::vec2 const v2(2.0f, 3.0f); + + glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0); + + glm::vec4 const A(v1_0, v2, v1_3); + Error += glm::all(glm::equal(A, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const B(v1_0, v2, 4.0); + Error += glm::all(glm::equal(B, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const C(1.0, v2, v1_3); + Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const D(1.0f, v2, 4.0); + Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const E(1.0, v2, 4.0f); + Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1; + } + + return Error; +} + +static int test_bvec4_ctor() +{ + int Error = 0; + + glm::bvec4 const A(true); + glm::bvec4 const B(true); + glm::bvec4 const C(false); + glm::bvec4 const D = A && B; + glm::bvec4 const E = A && C; + glm::bvec4 const F = A || C; + + Error += D == glm::bvec4(true) ? 0 : 1; + Error += E == glm::bvec4(false) ? 0 : 1; + Error += F == glm::bvec4(true) ? 0 : 1; + + bool const G = A == C; + bool const H = A != C; + Error += !G ? 0 : 1; + Error += H ? 0 : 1; + + return Error; +} + +static int test_operators() +{ + int Error = 0; + + { + glm::ivec4 A(1); + glm::ivec4 B(1); + bool R = A != B; + bool S = A == B; + + Error += (S && !R) ? 0 : 1; + } + + { + glm::vec4 const A(1.0f, 2.0f, 3.0f, 4.0f); + glm::vec4 const B(4.0f, 5.0f, 6.0f, 7.0f); + + glm::vec4 const C = A + B; + Error += glm::all(glm::equal(C, glm::vec4(5, 7, 9, 11), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const D = B - A; + Error += glm::all(glm::equal(D, glm::vec4(3, 3, 3, 3), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const E = A * B; + Error += glm::all(glm::equal(E, glm::vec4(4, 10, 18, 28), glm::epsilon<float>()) )? 0 : 1; + + glm::vec4 const F = B / A; + Error += glm::all(glm::equal(F, glm::vec4(4, 2.5, 2, 7.0f / 4.0f), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const G = A + 1.0f; + Error += glm::all(glm::equal(G, glm::vec4(2, 3, 4, 5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const H = B - 1.0f; + Error += glm::all(glm::equal(H, glm::vec4(3, 4, 5, 6), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const I = A * 2.0f; + Error += glm::all(glm::equal(I, glm::vec4(2, 4, 6, 8), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const J = B / 2.0f; + Error += glm::all(glm::equal(J, glm::vec4(2, 2.5, 3, 3.5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const K = 1.0f + A; + Error += glm::all(glm::equal(K, glm::vec4(2, 3, 4, 5), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const L = 1.0f - B; + Error += glm::all(glm::equal(L, glm::vec4(-3, -4, -5, -6), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const M = 2.0f * A; + Error += glm::all(glm::equal(M, glm::vec4(2, 4, 6, 8), glm::epsilon<float>())) ? 0 : 1; + + glm::vec4 const N = 2.0f / B; + Error += glm::all(glm::equal(N, glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0), glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + A += B; + Error += A == glm::ivec4(5, 7, 9, 11) ? 0 : 1; + + A += 1; + Error += A == glm::ivec4(6, 8, 10, 12) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + B -= A; + Error += B == glm::ivec4(3, 3, 3, 3) ? 0 : 1; + + B -= 1; + Error += B == glm::ivec4(2, 2, 2, 2) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f); + + A *= B; + Error += A == glm::ivec4(4, 10, 18, 28) ? 0 : 1; + + A *= 2; + Error += A == glm::ivec4(8, 20, 36, 56) ? 0 : 1; + } + { + glm::ivec4 A(1.0f, 2.0f, 2.0f, 4.0f); + glm::ivec4 B(4.0f, 4.0f, 8.0f, 8.0f); + + B /= A; + Error += B == glm::ivec4(4, 2, 4, 2) ? 0 : 1; + + B /= 2; + Error += B == glm::ivec4(2, 1, 2, 1) ? 0 : 1; + } + { + glm::ivec4 B(2); + + B /= B.y; + Error += B == glm::ivec4(1) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = -A; + Error += B == glm::ivec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = --A; + Error += B == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A--; + Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1; + Error += A == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = ++A; + Error += B == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1; + } + + { + glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A++; + Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1; + Error += A == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1; + } + + return Error; +} + +static int test_equal() +{ + int Error = 0; + + { + glm::uvec4 const A(1, 2, 3, 4); + glm::uvec4 const B(1, 2, 3, 4); + Error += A == B ? 0 : 1; + Error += A != B ? 1 : 0; + } + + { + glm::ivec4 const A(1, 2, 3, 4); + glm::ivec4 const B(1, 2, 3, 4); + Error += A == B ? 0 : 1; + Error += A != B ? 1 : 0; + } + + return Error; +} + +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::vec4) == sizeof(glm::lowp_vec4) ? 0 : 1; + Error += sizeof(glm::vec4) == sizeof(glm::mediump_vec4) ? 0 : 1; + Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1; + Error += 16 == sizeof(glm::mediump_vec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::lowp_dvec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::mediump_dvec4) ? 0 : 1; + Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1; + Error += 32 == sizeof(glm::highp_dvec4) ? 0 : 1; + Error += glm::vec4().length() == 4 ? 0 : 1; + Error += glm::dvec4().length() == 4 ? 0 : 1; + Error += glm::vec4::length() == 4 ? 0 : 1; + Error += glm::dvec4::length() == 4 ? 0 : 1; + + return Error; +} + +static int test_swizzle_partial() +{ + int Error = 0; + + glm::vec4 const A(1, 2, 3, 4); + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::vec4 B(A.xy, A.zw); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + { + glm::vec4 B(A.xy, 3.0f, 4.0f); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + { + glm::vec4 B(1.0f, A.yz, 4.0f); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + { + glm::vec4 B(1.0f, 2.0f, A.zw); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + + { + glm::vec4 B(A.xyz, 4.0f); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } + { + glm::vec4 B(1.0f, A.yzw); + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + + return Error; +} + +static int test_swizzle() +{ + int Error = 0; + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + { + glm::ivec4 A = glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f); + glm::ivec4 B = A.xyzw; + glm::ivec4 C(A.xyzw); + glm::ivec4 D(A.xyzw()); + glm::ivec4 E(A.x, A.yzw); + glm::ivec4 F(A.x, A.yzw()); + glm::ivec4 G(A.xyz, A.w); + glm::ivec4 H(A.xyz(), A.w); + glm::ivec4 I(A.xy, A.zw); + glm::ivec4 J(A.xy(), A.zw()); + glm::ivec4 K(A.x, A.y, A.zw); + glm::ivec4 L(A.x, A.yz, A.w); + glm::ivec4 M(A.xy, A.z, A.w); + + Error += glm::all(glm::equal(A, B)) ? 0 : 1; + Error += glm::all(glm::equal(A, C)) ? 0 : 1; + Error += glm::all(glm::equal(A, D)) ? 0 : 1; + Error += glm::all(glm::equal(A, E)) ? 0 : 1; + Error += glm::all(glm::equal(A, F)) ? 0 : 1; + Error += glm::all(glm::equal(A, G)) ? 0 : 1; + Error += glm::all(glm::equal(A, H)) ? 0 : 1; + Error += glm::all(glm::equal(A, I)) ? 0 : 1; + Error += glm::all(glm::equal(A, J)) ? 0 : 1; + Error += glm::all(glm::equal(A, K)) ? 0 : 1; + Error += glm::all(glm::equal(A, L)) ? 0 : 1; + Error += glm::all(glm::equal(A, M)) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR + +# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + { + glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f); + glm::vec4 B = A.xyzw(); + glm::vec4 C(A.xyzw()); + glm::vec4 D(A.xyzw()); + glm::vec4 E(A.x, A.yzw()); + glm::vec4 F(A.x, A.yzw()); + glm::vec4 G(A.xyz(), A.w); + glm::vec4 H(A.xyz(), A.w); + glm::vec4 I(A.xy(), A.zw()); + glm::vec4 J(A.xy(), A.zw()); + glm::vec4 K(A.x, A.y, A.zw()); + glm::vec4 L(A.x, A.yz(), A.w); + glm::vec4 M(A.xy(), A.z, A.w); + + Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, I, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, J, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, K, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, L, glm::epsilon<float>())) ? 0 : 1; + Error += glm::all(glm::equal(A, M, glm::epsilon<float>())) ? 0 : 1; + } +# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION + + return Error; +} + +static int test_operator_increment() +{ + int Error = 0; + + glm::ivec4 v0(1); + glm::ivec4 v1(v0); + glm::ivec4 v2(v0); + glm::ivec4 v3 = ++v1; + glm::ivec4 v4 = v2++; + + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; + Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; + + int i0(1); + int i1(i0); + int i2(i0); + int i3 = ++i1; + int i4 = i2++; + + Error += i0 == i4 ? 0 : 1; + Error += i1 == i2 ? 0 : 1; + Error += i1 == i3 ? 0 : 1; + + return Error; +} + +struct AoS +{ + glm::vec4 A; + glm::vec3 B; + glm::vec3 C; + glm::vec2 D; +}; + +static int test_perf_AoS(std::size_t Size) +{ + int Error = 0; + + std::vector<AoS> In; + std::vector<AoS> Out; + In.resize(Size); + Out.resize(Size); + + std::clock_t StartTime = std::clock(); + + for(std::size_t i = 0; i < In.size(); ++i) + Out[i] = In[i]; + + std::clock_t EndTime = std::clock(); + + std::printf("AoS: %d\n", static_cast<int>(EndTime - StartTime)); + + return Error; +} + +static int test_perf_SoA(std::size_t Size) +{ + int Error = 0; + + std::vector<glm::vec4> InA; + std::vector<glm::vec3> InB; + std::vector<glm::vec3> InC; + std::vector<glm::vec2> InD; + std::vector<glm::vec4> OutA; + std::vector<glm::vec3> OutB; + std::vector<glm::vec3> OutC; + std::vector<glm::vec2> OutD; + + InA.resize(Size); + InB.resize(Size); + InC.resize(Size); + InD.resize(Size); + OutA.resize(Size); + OutB.resize(Size); + OutC.resize(Size); + OutD.resize(Size); + + std::clock_t StartTime = std::clock(); + + for(std::size_t i = 0; i < InA.size(); ++i) + { + OutA[i] = InA[i]; + OutB[i] = InB[i]; + OutC[i] = InC[i]; + OutD[i] = InD[i]; + } + + std::clock_t EndTime = std::clock(); + + std::printf("SoA: %d\n", static_cast<int>(EndTime - StartTime)); + + return Error; +} + +namespace heap +{ + struct A + { + float f; + }; + + struct B : public A + { + float g; + glm::vec4 v; + }; + + static int test() + { + int Error = 0; + + A* p = new B; + p->f = 0.0f; + delete p; + + Error += sizeof(B) == sizeof(glm::vec4) + sizeof(float) * 2 ? 0 : 1; + + return Error; + } +}//namespace heap + +static int test_simd() +{ + int Error = 0; + + glm::vec4 const a(std::clock(), std::clock(), std::clock(), std::clock()); + glm::vec4 const b(std::clock(), std::clock(), std::clock(), std::clock()); + + glm::vec4 const c(b * a); + glm::vec4 const d(a + c); + + Error += glm::all(glm::greaterThanEqual(d, glm::vec4(0))) ? 0 : 1; + + return Error; +} + +static int test_inheritance() +{ + struct my_vec4 : public glm::vec4 + { + my_vec4() + : glm::vec4(76.f, 75.f, 74.f, 73.f) + , member(82) + {} + + int member; + }; + + int Error = 0; + + my_vec4 v; + + Error += v.member == 82 ? 0 : 1; + Error += glm::equal(v.x, 76.f, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(v.y, 75.f, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(v.z, 74.f, glm::epsilon<float>()) ? 0 : 1; + Error += glm::equal(v.w, 73.f, glm::epsilon<float>()) ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::vec4::length() == 4, "GLM: Failed constexpr"); + static_assert(glm::vec4(1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec4(1.0f, -1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr"); + static_assert(glm::vec4(1.0f, -1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr"); +#endif + + return 0; +} +/* +static int test_simd_gen() +{ + int Error = 0; + + int const C = static_cast<int>(std::clock()); + int const D = static_cast<int>(std::clock()); + + glm::ivec4 const A(C); + glm::ivec4 const B(D); + + Error += A != B ? 0 : 1; + + return Error; +} +*/ +int main() +{ + int Error = 0; + + //Error += test_simd_gen(); + +/* + { + glm::ivec4 const a1(2); + glm::ivec4 const b1 = a1 >> 1; + + __m128i const e1 = _mm_set1_epi32(2); + __m128i const f1 = _mm_srli_epi32(e1, 1); + + glm::ivec4 const g1 = *reinterpret_cast<glm::ivec4 const* const>(&f1); + + glm::ivec4 const a2(-2); + glm::ivec4 const b2 = a2 >> 1; + + __m128i const e2 = _mm_set1_epi32(-1); + __m128i const f2 = _mm_srli_epi32(e2, 1); + + glm::ivec4 const g2 = *reinterpret_cast<glm::ivec4 const* const>(&f2); + + std::printf("GNI\n"); + } + + { + glm::uvec4 const a1(2); + glm::uvec4 const b1 = a1 >> 1u; + + __m128i const e1 = _mm_set1_epi32(2); + __m128i const f1 = _mm_srli_epi32(e1, 1); + + glm::uvec4 const g1 = *reinterpret_cast<glm::uvec4 const* const>(&f1); + + glm::uvec4 const a2(-1); + glm::uvec4 const b2 = a2 >> 1u; + + __m128i const e2 = _mm_set1_epi32(-1); + __m128i const f2 = _mm_srli_epi32(e2, 1); + + glm::uvec4 const g2 = *reinterpret_cast<glm::uvec4 const* const>(&f2); + + std::printf("GNI\n"); + } +*/ + +# ifdef NDEBUG + std::size_t const Size(1000000); +# else + std::size_t const Size(1); +# endif//NDEBUG + + Error += test_perf_AoS(Size); + Error += test_perf_SoA(Size); + + Error += test_vec4_ctor(); + Error += test_bvec4_ctor(); + Error += test_size(); + Error += test_operators(); + Error += test_equal(); + Error += test_swizzle(); + Error += test_swizzle_partial(); + Error += test_simd(); + Error += test_operator_increment(); + Error += heap::test(); + Error += test_inheritance(); + Error += test_constexpr(); + + return Error; +} + |