replace math_graphics with glm version 1.0.3

This commit is contained in:
Sven Balzer
2026-04-15 10:50:41 +02:00
parent 07af9deb6a
commit 4ec664c8db
1676 changed files with 289261 additions and 1477 deletions
+52
View File
@@ -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_arch_unknown)
glmCreateTestGTC(core_force_compiler_unknown)
glmCreateTestGTC(core_force_explicit_ctor)
glmCreateTestGTC(core_force_inline)
glmCreateTestGTC(core_force_intrinsics)
glmCreateTestGTC(core_force_platform_unknown)
glmCreateTestGTC(core_force_pure)
glmCreateTestGTC(core_force_unrestricted_gentype)
glmCreateTestGTC(core_force_xyzw_only)
glmCreateTestGTC(core_force_quat_wxyz)
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_cxx_unknown)
glmCreateTestGTC(core_setup_force_cxx98)
glmCreateTestGTC(core_setup_force_cxx03)
glmCreateTestGTC(core_setup_force_size_t_length)
glmCreateTestGTC(core_setup_message)
glmCreateTestGTC(core_setup_platform_unknown)
glmCreateTestGTC(core_setup_precision)
+750
View File
@@ -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;
}
@@ -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;
}
@@ -0,0 +1,10 @@
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
@@ -0,0 +1,38 @@
#ifndef GLM_FORCE_COMPILER_UNKNOWN
# define GLM_FORCE_COMPILER_UNKNOWN
#endif
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
# pragma clang diagnostic ignored "-Wnested-anon-types"
# pragma clang diagnostic ignored "-Wsign-conversion"
# pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wc++11-long-long"
#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpedantic"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
# pragma warning(disable: 4324) // structure was padded due to alignment specifier
#endif
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif
int main()
{
int Error = 0;
return Error;
}
+139
View File
@@ -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;
}
@@ -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;
}
@@ -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;
}
+12
View File
@@ -0,0 +1,12 @@
#define GLM_FORCE_INLINE
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -0,0 +1,442 @@
#ifndef GLM_FORCE_INTRINSICS
# define GLM_FORCE_INTRINSICS
#endif//GLM_FORCE_INTRINSICS
#define GLM_FORCE_SWIZZLE
#include <glm/ext/scalar_constants.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 <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 };
Error += glm::all(glm::equal(a, glm::vec4(0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::vec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
Error += glm::all(glm::equal(v[0], glm::vec4(0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v[1], glm::vec4(4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v[2], glm::vec4(8, 9, 0, 1), glm::epsilon<float>())) ? 0 : 1;
}
{
glm::dvec4 a{ 0, 1, 2, 3 };
Error += glm::all(glm::equal(a, glm::dvec4(0, 1, 2, 3), glm::epsilon<double>())) ? 0 : 1;
std::vector<glm::dvec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
Error += glm::all(glm::equal(v[0], glm::dvec4(0, 1, 2, 3), glm::epsilon<double>())) ? 0 : 1;
Error += glm::all(glm::equal(v[1], glm::dvec4(4, 5, 6, 7), glm::epsilon<double>())) ? 0 : 1;
Error += glm::all(glm::equal(v[2], glm::dvec4(8, 9, 0, 1), glm::epsilon<double>())) ? 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 A(true);
glm::bvec4 B(true);
glm::bvec4 C(false);
glm::bvec4 D = A && B;
glm::bvec4 E = A && C;
glm::bvec4 F = A || C;
Error += (D == A) ? 0 : 1;
Error += (E == C) ? 0 : 1;
Error += (F == A) ? 0 : 1;
bool G = A == C;
bool 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 A(1, 2, 3, 4);
Error += (A == glm::uvec4(1, 2, 3, 4)) ? 0 : 1;
Error += (A != glm::uvec4(1, 2, 3, 4)) ? 1 : 0;
}
{
glm::ivec4 A(1, 2, 3, 4);
Error += (A == glm::ivec4(1, 2, 3, 4)) ? 0 : 1;
Error += (A != glm::ivec4(1, 2, 3, 4)) ? 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;
}
@@ -0,0 +1,12 @@
#define GLM_FORCE_LEFT_HANDED
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
+443
View File
@@ -0,0 +1,443 @@
#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/scalar_constants.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 <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 };
Error += glm::all(glm::equal(a, glm::vec4(0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
std::vector<glm::vec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
Error += glm::all(glm::equal(v[0], glm::vec4(0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v[1], glm::vec4(4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v[2], glm::vec4(8, 9, 0, 1), glm::epsilon<float>())) ? 0 : 1;
}
{
glm::dvec4 a{ 0, 1, 2, 3 };
Error += glm::all(glm::equal(a, glm::dvec4(0, 1, 2, 3), glm::epsilon<double>())) ? 0 : 1;
std::vector<glm::dvec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
Error += glm::all(glm::equal(v[0], glm::dvec4(0, 1, 2, 3), glm::epsilon<double>())) ? 0 : 1;
Error += glm::all(glm::equal(v[1], glm::dvec4(4, 5, 6, 7), glm::epsilon<double>())) ? 0 : 1;
Error += glm::all(glm::equal(v[2], glm::dvec4(8, 9, 0, 1), glm::epsilon<double>())) ? 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 A(true);
glm::bvec4 B(true);
glm::bvec4 C(false);
glm::bvec4 D = A && B;
glm::bvec4 E = A && C;
glm::bvec4 F = A || C;
Error += (D == A) ? 0 : 1;
Error += (E == C) ? 0 : 1;
Error += (F == A) ? 0 : 1;
bool G = A == C;
bool 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 A(1, 2, 3, 4);
Error += (A == glm::uvec4(1, 2, 3, 4)) ? 0 : 1;
Error += (A != glm::uvec4(1, 2, 3, 4)) ? 1 : 0;
}
{
glm::ivec4 A(1, 2, 3, 4);
Error += (A == glm::ivec4(1, 2, 3, 4)) ? 0 : 1;
Error += (A != glm::ivec4(1, 2, 3, 4)) ? 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;
}
@@ -0,0 +1,13 @@
#define GLM_FORCE_QUAT_DATA_WXYZ
#define GLM_FORCE_INLINE
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
@@ -0,0 +1,12 @@
#define GLM_FORCE_UNRESTRICTED_GENTYPE
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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 A(1);
Error += A.x == 1 ? 0 : 1;
}
{
glm::ivec2 A(1, 2);
Error += A.x == 1 ? 0 : 1;
Error += A.y == 2 ? 0 : 1;
}
{
glm::ivec3 A(1, 2, 3);
Error += A.x == 1 ? 0 : 1;
Error += A.y == 2 ? 0 : 1;
Error += A.z == 3 ? 0 : 1;
}
{
glm::ivec4 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;
}
File diff suppressed because it is too large Load Diff
@@ -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;
}
+210
View File
@@ -0,0 +1,210 @@
#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
{
static 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
{
static 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
{
static 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
{
static 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
{
static int test()
{
int Error = 0;
glm::vec3 Normalize1 = glm::normalize(glm::vec3(1, 0, 0));
glm::vec3 Normalize2 = glm::normalize(glm::vec3(2, 0, 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;
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);
glm::vec3 x = glm::cross(w, u);
Error += glm::all(glm::equal(x + v, glm::vec3(0), 0.01f)) ? 0 : 1;
return Error;
}
}//namespace normalize
namespace faceforward
{
static 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);
Error += glm::all(glm::equal(F, glm::vec3(0.0, 0.0, -1.0), 0.0001f)) ? 0 : 1;
}
return Error;
}
}//namespace faceforward
namespace reflect
{
static 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
{
static 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;
}
{
glm::vec4 A(0.0f, -1.0f, 0.0f, 0.0f);
glm::vec4 B(0.0f, 1.0f, 0.0f, 0.0f);
glm::vec4 C = glm::refract(A, B, 0.5f);
Error += glm::all(glm::equal(C, glm::vec4(0.0, -1.0, 0.0f, 0.0f), 0.0001f)) ? 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;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,318 @@
// 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>
#include <glm/glm.hpp>
#ifdef NDEBUG
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wsign-conversion"
#endif
static 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));
}
static 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;
}
static 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). */
static 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). */
static 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;
}
static int pop4(unsigned x)
{
int n;
n = 0;
while (x != 0) {
n = n + 1;
x = x & (x - 1);
}
return n;
}
static 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;
}
static int pop5a(unsigned x)
{
int sum;
// Shift right & subtract
sum = x;
while (x != 0) {
x = x >> 1;
sum = sum - x;
}
return sum;
}
static 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.
static 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.
static 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.
static 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);
}
static int errors;
static void error(int x, int y)
{
errors = errors + 1;
std::printf("Error for x = %08x, got %08x\n", x, y);
}
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4389) // nonstandard extension used : nameless struct/union
#endif
int main()
{
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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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));
}
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
#else
int main()
{
return 0;
}
#endif//NDEBUG
@@ -0,0 +1,455 @@
#include <glm/glm.hpp>
#include <cstdio>
#include <cstdlib> //To define "exit", req'd by XLC.
#include <ctime>
#ifdef NDEBUG
static 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;
}
static int nlz(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);
}
static int ntz1(unsigned x)
{
return 32 - nlz(~x & (x-1));
}
static int ntz2(unsigned x)
{
return pop(~x & (x - 1));
}
static 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 - static_cast<int>(x & 1);
}
static 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;
}
static 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 - static_cast<int>((x << 1) >> 31);
return n;
}
static 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;
}
static 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;
}
static 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). */
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable : 4146)
#endif
static int ntz7(unsigned x)
{
unsigned y;
int 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;
}
#if(GLM_COMPILER & GLM_COMPILER_VC)
# pragma warning(pop)
#endif
// This file has divisions by zero to test isnan
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable : 4146)
#endif
/*
static int ntz7_christophe(unsigned x)
{
unsigned y, bz, b4, b3, b2, b1, b0;
y = x & -x; // Isolate rightmost 1-bit.
bz = static_cast<unsigned>(!static_cast<bool>(y)); // 1 if y = 0.
b4 = static_cast<unsigned>(!static_cast<bool>(y & 0x0000FFFF)) * 16;
b3 = static_cast<unsigned>(!static_cast<bool>(y & 0x00FF00FF)) * 8;
b2 = static_cast<unsigned>(!static_cast<bool>(y & 0x0F0F0F0F)) * 4;
b1 = static_cast<unsigned>(!static_cast<bool>(y & 0x33333333)) * 2;
b0 = static_cast<unsigned>(!static_cast<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
static 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. */
static 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. */
static 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. */
static 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
static 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;
}
#if(GLM_COMPILER & GLM_COMPILER_VC)
# pragma warning(pop)
#endif
static int errors;
static void error(unsigned x, int y) {
errors = errors + 1;
std::printf("Error for x = %08x, got %d\n", x, y);
}
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4389) // nonstandard extension used : nameless struct/union
#endif
int main()
{
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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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 = static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(test[i+1])) error(test[i], ntz10(test[i]));}
TimestampEnd = std::clock();
std::printf("ntz10: %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 (ntz11(test[i]) != static_cast<int>(test[i + 1])) error(test[i], ntz11(test[i]));
}
TimestampEnd = std::clock();
std::printf("ntz11: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
if (errors == 0)
std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
}
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#else
int main()
{
return 0;
}
#endif//NDEBUG
@@ -0,0 +1,465 @@
#include <glm/glm.hpp>
#include <cstdio>
#include <cstdlib> // To define "exit", req'd by XLC.
#include <ctime>
#ifdef NDEBUG
#define LE 1 // 1 for little-endian, 0 for big-endian.
static 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;
}
static 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;
}
static 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 - static_cast<int>(x >> 31);
return n;
}
// On basic Risc, 12 to 20 instructions.
static 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 - static_cast<int>(x);
}
// As above but coded as a loop for compactness:
// 23 to 33 basic Risc instructions.
static 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 - static_cast<int>(x);
}
static int nlz3(unsigned x) {
int y, n;
n = 0;
y = static_cast<int>(x);
L: if (x > 0x7fffffff) return n;
if (y == 0) return 32 - n;
n = n + 1;
x = x << 1;
y = y >> 1;
goto L;
}
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable : 4146)
#endif
static 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 = static_cast<int>(x) - 0x100;
m = (y >> 16) & 8; // If positions 8-15 are 0,
n = n + m; // add 8 to n and shift x left 8.
x = x << m;
y = static_cast<int>(x) - 0x1000;
m = (y >> 16) & 4; // If positions 12-15 are 0,
n = n + m; // add 4 to n and shift x left 4.
x = x << m;
y = static_cast<int>(x) - 0x4000;
m = (y >> 16) & 2; // If positions 14-15 are 0,
n = n + m; // add 2 to n and shift x left 2.
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;
}
#if(GLM_COMPILER & GLM_COMPILER_VC)
# pragma warning(pop)
#endif
static 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. */
static 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;
}
static 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. */
static 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). */
static 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
static 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. */
static 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." */
static 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];
}
static int errors;
static void error(unsigned x, int y)
{
errors = errors + 1;
std::printf("Error for x = %08x, got %d\n", x, y);
}
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4389) // nonstandard extension used : nameless struct/union
#endif
int main()
{
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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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]) != static_cast<int>(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));
}
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#else
int main()
{
return 0;
}
#endif//NDEBUG
+426
View File
@@ -0,0 +1,426 @@
#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;
static 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;
}
static int test_outerProduct()
{
int Error = 0;
glm::mat2 m0 = glm::outerProduct(glm::vec2(1.0f), glm::vec2(1.0f));
glm::mat2 n0(1, 1, 1, 1);
Error += all(equal(m0, n0, epsilon<float>())) ? 0 : 1;
glm::mat3 m1 = glm::outerProduct(glm::vec3(1.0f), glm::vec3(1.0f));
glm::mat3 n1(1, 1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m1, n1, epsilon<float>())) ? 0 : 1;
glm::mat4 m2 = glm::outerProduct(glm::vec4(1.0f), glm::vec4(1.0f));
glm::mat4 n2(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m2, n2, epsilon<float>())) ? 0 : 1;
glm::mat2x3 m3 = glm::outerProduct(glm::vec3(1.0f), glm::vec2(1.0f));
glm::mat2x3 n3(1, 1, 1, 1, 1, 1);
Error += all(equal(m3, n3, epsilon<float>())) ? 0 : 1;
glm::mat2x4 m4 = glm::outerProduct(glm::vec4(1.0f), glm::vec2(1.0f));
glm::mat2x4 n4(1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m4, n4, epsilon<float>())) ? 0 : 1;
glm::mat3x2 m5 = glm::outerProduct(glm::vec2(1.0f), glm::vec3(1.0f));
glm::mat3x2 n5(1, 1, 1, 1, 1, 1);
Error += all(equal(m5, n5, epsilon<float>())) ? 0 : 1;
glm::mat3x4 m6 = glm::outerProduct(glm::vec4(1.0f), glm::vec3(1.0f));
glm::mat3x4 n6(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m6, n6, epsilon<float>())) ? 0 : 1;
glm::mat4x2 m7 = glm::outerProduct(glm::vec2(1.0f), glm::vec4(1.0f));
glm::mat4x2 n7(1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m7, n7, epsilon<float>())) ? 0 : 1;
glm::mat4x3 m8 = glm::outerProduct(glm::vec3(1.0f), glm::vec4(1.0f));
glm::mat4x3 n8(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
Error += all(equal(m8, n8, epsilon<float>())) ? 0 : 1;
return Error;
}
static 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;
}
static int test_determinant()
{
return 0;
}
static 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;
}
static 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;
}
static int test_shearing()
{
int Error = 0;
{
glm::vec3 const center(0, 0, 0);
glm::vec2 const l_x(2, 0);
glm::vec2 const l_y(0, 0);
glm::vec2 const l_z(0, 0);
glm::mat4x4 const A4x4(
glm::vec4(0, 0, 1, 1),
glm::vec4(0, 1, 1, 0),
glm::vec4(1, 1, 1, 0),
glm::vec4(1, 1, 0, 1));
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const expected(
glm::vec4(0, 0, 1, 1),
glm::vec4(0, 1, 3, 2),
glm::vec4(1, 1, 1, 0),
glm::vec4(1, 1, 0, 1));
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
}
{
glm::vec3 const center(0, 0, 0);
glm::vec2 const l_x(1, 0);
glm::vec2 const l_y(0, 1);
glm::vec2 const l_z(1, 0);
glm::mat4x4 const A4x4(
glm::vec4(0, 0, 1, 0),
glm::vec4(0, 1, 1, 0),
glm::vec4(1, 1, 1, 0),
glm::vec4(1, 0, 0, 0));
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const expected(
glm::vec4(1, 1, 2, 0),
glm::vec4(0, 1, 2, 0),
glm::vec4(1, 2, 2, 0),
glm::vec4(1, 0, 0, 0));
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
}
{
glm::vec3 const center(3, 2, 1);
glm::vec2 const l_x(1, 2);
glm::vec2 const l_y(3, 1);
glm::vec2 const l_z(4, 5);
glm::mat4x4 const A4x4(1);
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const expected(
glm::vec4(1, 3, 4, 0),
glm::vec4(1, 1, 5, 0),
glm::vec4(2, 1, 1, 0),
glm::vec4(-9, -8, -9, 1));
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
}
{
glm::vec3 const center(3, 2, 1);
glm::vec2 const l_x(1, 2);
glm::vec2 const l_y(3, 1);
glm::vec2 const l_z(4, 5);
glm::mat4x4 const A4x4(
glm::vec4(-3, 2, 1, 0),
glm::vec4(3, 2, 1, 0),
glm::vec4(4, -8, 0, 0),
glm::vec4(7, 1, -2, 0));
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
glm::mat4x4 const expected(
glm::vec4(22, -24, 4, 0),
glm::vec4(20, -36, 2, 0),
glm::vec4(1, -2, 3, 0),
glm::vec4(-26, 39, -19, 0));
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
}
return Error;
}
template<typename VEC3, typename MAT4>
static 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), static_cast<unsigned long>(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();
Error += test_shearing();
#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;
}
+7
View File
@@ -0,0 +1,7 @@
int main()
{
int Error = 0;
return Error;
}
+156
View File
@@ -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>
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
+164
View File
@@ -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;
}
static 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;
}
static 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;
}
static 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;
}
@@ -0,0 +1,10 @@
#include <glm/trigonometric.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
@@ -0,0 +1,34 @@
#ifdef GLM_FORCE_CXX_UNKNOWN
#undef GLM_FORCE_CXX_UNKNOWN
#endif
#ifdef GLM_FORCE_CXX20
#undef GLM_FORCE_CXX20
#endif
#ifdef GLM_FORCE_CXX17
#undef GLM_FORCE_CXX17
#endif
#ifdef GLM_FORCE_CXX14
#undef GLM_FORCE_CXX14
#endif
#ifdef GLM_FORCE_CXX11
#undef GLM_FORCE_CXX11
#endif
#ifdef GLM_FORCE_CXX03
#undef GLM_FORCE_CXX03
#endif
#ifdef GLM_FORCE_CXX98
#undef GLM_FORCE_CXX98
#endif
#define GLM_FORCE_CXX03
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -0,0 +1,33 @@
#ifdef GLM_FORCE_CXX_UNKNOWN
#undef GLM_FORCE_CXX_UNKNOWN
#endif
#ifdef GLM_FORCE_CXX20
#undef GLM_FORCE_CXX20
#endif
#ifdef GLM_FORCE_CXX17
#undef GLM_FORCE_CXX17
#endif
#ifdef GLM_FORCE_CXX14
#undef GLM_FORCE_CXX14
#endif
#ifdef GLM_FORCE_CXX11
#undef GLM_FORCE_CXX11
#endif
#ifdef GLM_FORCE_CXX03
#undef GLM_FORCE_CXX03
#endif
#ifdef GLM_FORCE_CXX98
#undef GLM_FORCE_CXX98
#endif
#define GLM_FORCE_CXX98
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
@@ -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;
}
+315
View File
@@ -0,0 +1,315 @@
#define GLM_FORCE_MESSAGES
#include <glm/vec3.hpp>
#include <cstdio>
static 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;
case GLM_COMPILER_VC17:
std::printf("Visual C++ 17 - 2022\n");
break;
default:
std::printf("Visual C++ version not detected\n");
Error += 1;
break;
}
}
# elif(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;
case GLM_COMPILER_GCC9:
std::printf("GCC 9\n");
break;
case GLM_COMPILER_GCC10:
std::printf("GCC 10\n");
break;
case GLM_COMPILER_GCC11:
std::printf("GCC 11\n");
break;
case GLM_COMPILER_GCC12:
std::printf("GCC 12\n");
break;
case GLM_COMPILER_GCC13:
std::printf("GCC 13\n");
break;
case GLM_COMPILER_GCC14:
std::printf("GCC 14\n");
break;
default:
std::printf("GCC version not detected\n");
Error += 1;
break;
}
}
# elif(GLM_COMPILER & GLM_COMPILER_CUDA)
{
std::printf("CUDA\n");
}
# elif(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_CLANG4:
std::printf("Clang 4\n");
break;
case GLM_COMPILER_CLANG5:
std::printf("Clang 5\n");
break;
case GLM_COMPILER_CLANG6:
std::printf("Clang 6\n");
break;
case GLM_COMPILER_CLANG7:
std::printf("Clang 7\n");
break;
case GLM_COMPILER_CLANG8:
std::printf("Clang 8\n");
break;
case GLM_COMPILER_CLANG9:
std::printf("Clang 9\n");
break;
case GLM_COMPILER_CLANG10:
std::printf("Clang 10\n");
break;
case GLM_COMPILER_CLANG11:
std::printf("Clang 11\n");
break;
case GLM_COMPILER_CLANG12:
std::printf("Clang 12\n");
break;
case GLM_COMPILER_CLANG13:
std::printf("Clang 13\n");
break;
case GLM_COMPILER_CLANG14:
std::printf("Clang 14\n");
break;
case GLM_COMPILER_CLANG15:
std::printf("Clang 15\n");
break;
case GLM_COMPILER_CLANG16:
std::printf("Clang 16\n");
break;
case GLM_COMPILER_CLANG17:
std::printf("Clang 17\n");
break;
case GLM_COMPILER_CLANG18:
std::printf("Clang 18\n");
break;
case GLM_COMPILER_CLANG19:
std::printf("Clang 19\n");
break;
default:
std::printf("LLVM version not detected\n");
break;
}
}
# elif(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 - 2015\n");
break;
case GLM_COMPILER_INTEL17:
std::printf("ICC 17 - 2016\n");
break;
case GLM_COMPILER_INTEL18:
std::printf("ICC 18 - 2017\n");
break;
case GLM_COMPILER_INTEL19:
std::printf("ICC 19 - 2018\n");
break;
case GLM_COMPILER_INTEL21:
std::printf("ICC 21 - 2021\n");
break;
default:
std::printf("Intel compiler version not detected\n");
Error += 1;
break;
}
}
#else
{
std::printf("Undetected compiler\n");
Error += 1;
}
#endif
return Error;
}
static 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");
# elif GLM_MODEL == GLM_MODEL_64
std::printf("GLM_MODEL_64\n");
# endif
return Error;
}
static int test_instruction_set()
{
int Error = 0;
std::printf("GLM_ARCH: ");
# if(GLM_ARCH & GLM_ARCH_ARM_BIT)
std::printf("ARM ");
# elif(GLM_ARCH & GLM_ARCH_NEON_BIT)
std::printf("NEON ");
# elif(GLM_ARCH & GLM_ARCH_AVX2_BIT)
std::printf("AVX2 ");
# elif(GLM_ARCH & GLM_ARCH_AVX_BIT)
std::printf("AVX ");
# elif(GLM_ARCH & GLM_ARCH_SSE42_BIT)
std::printf("SSE4.2 ");
# elif(GLM_ARCH & GLM_ARCH_SSE41_BIT)
std::printf("SSE4.1 ");
# elif(GLM_ARCH & GLM_ARCH_SSSE3_BIT)
std::printf("SSSE3 ");
# elif(GLM_ARCH & GLM_ARCH_SSE3_BIT)
std::printf("SSE3 ");
# elif(GLM_ARCH & GLM_ARCH_SSE2_BIT)
std::printf("SSE2 ");
# endif
std::printf("\n");
return Error;
}
static int test_cpp_version()
{
std::printf("__cplusplus: %d\n", static_cast<int>(__cplusplus));
std::printf("GLM_LANG: ");
# if(GLM_LANG & GLM_LANG_CXX20_FLAG)
std::printf("C++ 20");
# elif(GLM_LANG & GLM_LANG_CXX17_FLAG)
std::printf("C++ 17");
# elif(GLM_LANG & GLM_LANG_CXX14_FLAG)
std::printf("C++ 14");
# elif(GLM_LANG & GLM_LANG_CXX11_FLAG)
std::printf("C++ 11");
# elif(GLM_LANG & GLM_LANG_CXX98_FLAG)
std::printf("C++ 98");
# endif
return 0;
}
static 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;
}
@@ -0,0 +1,45 @@
#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
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
# pragma clang diagnostic ignored "-Wnested-anon-types"
# pragma clang diagnostic ignored "-Wsign-conversion"
# pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wc++11-long-long"
#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpedantic"
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
#endif
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#if defined(__clang__)
# pragma clang diagnostic pop
#elif defined(__GNUC__)
# pragma GCC diagnostic pop
#elif defined(_MSC_VER)
# pragma warning(pop)
#endif
int main()
{
int Error = 0;
return Error;
}
@@ -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;
}
+124
View File
@@ -0,0 +1,124 @@
#include <glm/detail/setup.hpp>
#if GLM_PLATFORM & GLM_PLATFORM_APPLE // Fail on Github macOS-latest (macOS-13 was fine)
int main()
{
return 0;
}
#else
#ifndef GLM_FORCE_PURE
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
#endif
#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;
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
struct Struct1
{
glm::vec4 A;
float B;
glm::vec3 C;
};
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
std::size_t const Size1 = sizeof(Struct1);
Error += Size1 == 48 ? 0 : 1;
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
struct Struct2
{
glm::vec4 A;
glm::vec3 B;
float C;
};
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
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;
}
#endif//GLM_PLATFORM & GLM_PLATFORM_APPLE
+154
View File
@@ -0,0 +1,154 @@
#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;
};
static int test_vec2_cast()
{
int Error(0);
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);
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;
my_vec2 I;
I.x = 1.0f;
I.y = 2.0f;
glm::vec2 J0 = static_cast<glm::vec2>(I);
glm::vec2 J1(1.0f, 2.0f);
Error += glm::all(glm::equal(J1, J0, glm::epsilon<float>())) ? 0 : 1;
glm::vec2 K(7.8f);
glm::vec2 L(7.8f, 7.8f);
Error += glm::all(glm::equal(K, L, glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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;
}
static 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;
}
static 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;
}
+351
View File
@@ -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;
}
+26
View File
@@ -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;
}
+78
View File
@@ -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;
}
+198
View File
@@ -0,0 +1,198 @@
#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>
static int test_operators()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 b = v * m;
Error += glm::all(glm::equal(b, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat2x2 n0(1.0f, 1.0f, 1.0f, 1.0f);
glm::mat2x2 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x2 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x2 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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;
}
static 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>
static 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;
}
static 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 += 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;
}
static int test_constexpr()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
constexpr glm::mat2x2 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat2x2(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
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;
}
+163
View File
@@ -0,0 +1,163 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec3(u, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 b = v * m;
Error += glm::all(glm::equal(b, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat2x3 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat2x3 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x3 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x3 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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::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;
}
static int test_constexpr()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat2x3::length() == 2, "GLM: Failed constexpr");
constexpr glm::mat2x3 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat2x3(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+168
View File
@@ -0,0 +1,168 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec4(u, 0.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 b = v * m;
Error += glm::all(glm::equal(b, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat2x4 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat2x4 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x4 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat2x4 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat2x4::length() == 2, "GLM: Failed constexpr");
constexpr glm::mat2x4 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat2x4(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+169
View File
@@ -0,0 +1,169 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec3 b = v * m;
Error += glm::all(glm::equal(b, glm::vec3(v, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat3x2 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat3x2 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x2 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x2 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat3x2::length() == 3, "GLM: Failed constexpr");
constexpr glm::mat3x2 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat3x2(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+216
View File
@@ -0,0 +1,216 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec3(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec3 b = v * m;
Error += glm::all(glm::equal(b, glm::vec3(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat3x3 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat3x3 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x3 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x3 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat3x3::length() == 3, "GLM: Failed constexpr");
constexpr glm::mat3x3 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat3x3(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
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;
}
+170
View File
@@ -0,0 +1,170 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec4(u, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec3 b = v * m;
Error += glm::all(glm::equal(b, glm::vec3(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat3x4 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat3x4 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x4 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat3x4 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat3x4::length() == 3, "GLM: Failed constexpr");
constexpr glm::mat3x4 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat3x4(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+172
View File
@@ -0,0 +1,172 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 b = v * m;
Error += glm::all(glm::equal(b, glm::vec4(v, 0.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat4x2 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat4x2 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat4x2 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat4x2 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat4x2::length() == 4, "GLM: Failed constexpr");
constexpr glm::mat4x2 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat4x2(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+173
View File
@@ -0,0 +1,173 @@
#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()
{
int Error = 0;
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;
Error += glm::all(glm::equal(a, glm::vec3(1.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 b = v * m;
Error += glm::all(glm::equal(b, glm::vec4(v, 0.0f), glm::epsilon<float>())) ? 0 : 1;
glm::mat4x3 n0(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
glm::mat4x3 n = x / n0;
Error += glm::all(glm::equal(n, n0, glm::epsilon<float>())) ? 0 : 1;
glm::mat4x3 o = m / x;
Error += glm::all(glm::equal(o, m, glm::epsilon<float>())) ? 0 : 1;
glm::mat4x3 p = x * m;
Error += glm::all(glm::equal(p, m, glm::epsilon<float>())) ? 0 : 1;
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>()));
Error += (S && !R) ? 0 : 1;
return Error;
}
static 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>
static 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;
}
static 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()
{
int Error = 0;
#if GLM_HAS_CONSTEXPR
static_assert(glm::mat4x3::length() == 4, "GLM: Failed constexpr");
constexpr glm::mat4x3 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat4x3(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
Error += test_constexpr();
return Error;
}
+223
View File
@@ -0,0 +1,223 @@
#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{
V,
{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()
{
int Error = 0;
#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");
constexpr glm::mat4 const Z(1.0f);
Error += glm::all(glm::equal(Z, glm::mat4(1.0f), glm::epsilon<float>())) ? 0 : 1;
#endif
return Error;
}
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;
}
+193
View File
@@ -0,0 +1,193 @@
#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>
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wglobal-constructors"
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
static glm::vec1 g1;
static glm::vec1 g2(1);
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
static int test_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;
}
static int test_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::vec1 A = glm::vec2(2.0f);
Error += glm::all(glm::equal(A, glm::vec1(2.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec1 B = glm::vec2(2.0f, 3.0f);
Error += glm::all(glm::equal(B, glm::vec1(2.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec1 C = glm::vec2(2.0f, 3.0);
Error += glm::all(glm::equal(C, glm::vec1(2.0f), glm::epsilon<float>())) ? 0 : 1;
//glm::vec1 D = glm::dvec1(2.0); // Build error TODO: What does the specification says?
glm::vec1 E(glm::dvec2(2.0));
Error += glm::all(glm::equal(E, glm::vec1(2.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec1 F(glm::ivec2(2));
Error += glm::all(glm::equal(F, glm::vec1(2.0f), glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static int test_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_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()
{
// Suppress unused variable warnings
(void)g1;
(void)g2;
int Error = 0;
Error += test_size();
Error += test_ctor();
Error += test_operators();
Error += test_operator_increment();
Error += test_swizzle();
Error += test_constexpr();
return Error;
}
+428
View File
@@ -0,0 +1,428 @@
#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
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wglobal-constructors"
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
static glm::ivec2 g1;
static glm::ivec2 g2(1);
static glm::ivec2 g3(1, 1);
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
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;
Error += B == glm::ivec2(2, 4) ? 0 : 1;
}
{
glm::ivec2 A(1.0f, 2.0f);
glm::ivec2 B(4.0f, 16.0f);
B = B / A;
Error += B == glm::ivec2(4, 8) ? 0 : 1;
B = B / 2;
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 = {
a,
{4, 5},
{8, 9}};
}
{
glm::dvec2 a{ 0, 1 };
std::vector<glm::dvec2> v = {
a,
{4, 5},
{8, 9}};
}
#endif
{
glm::vec2 A = glm::vec2(2.0f);
Error += glm::all(glm::equal(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 B = glm::vec2(2.0f, 3.0f);
Error += glm::all(glm::equal(B, glm::vec2(2.0f, 3.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 C = glm::vec2(2.0f, 3.0);
Error += glm::all(glm::equal(C, glm::vec2(2.0f, 3.0f), glm::epsilon<float>())) ? 0 : 1;
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
Error += glm::all(glm::equal(E, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
glm::vec2 F(glm::ivec2(2));
Error += glm::all(glm::equal(F, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
}
{
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 glm::length_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()
{
// Suppress unused variable warnings
(void)g1;
(void)g2;
(void)g3;
int Error = 0;
Error += test_size();
Error += test_ctor();
Error += test_operators();
Error += test_operator_increment();
Error += test_swizzle();
Error += test_constexpr();
return Error;
}
+649
View File
@@ -0,0 +1,649 @@
#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>
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wglobal-constructors"
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
static glm::vec3 g1;
static glm::vec3 g2(1);
static glm::vec3 g3(1, 1, 1);
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
static 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 = {
a,
{4, 5, 6},
{8, 9, 0}};
}
{
glm::dvec3 a{ 0, 1, 2 };
std::vector<glm::dvec3> v = {
a,
{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;
}
static int test_bvec3_ctor()
{
int Error = 0;
glm::bvec3 A(true);
glm::bvec3 B(true);
glm::bvec3 C(false);
glm::bvec3 D = A && B;
glm::bvec3 E = A && C;
glm::bvec3 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 G = A == C;
bool 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 A(1.0f, 2.0f, 3.0f);
glm::ivec3 B(4.0f, 4.0f, 6.0f);
B = B / A;
Error += B == glm::ivec3(4, 2, 2) ? 0 : 1;
B = 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;
}
static 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 glm::length_t Length = glm::vec3::length();
Error += Length == 3 ? 0 : 1;
return Error;
}
static 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;
}
static 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;
}
static int test_vec3_swizzle_operators()
{
int Error = 0;
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::ivec3 const u = glm::ivec3(1, 2, 3);
glm::ivec3 const v = glm::ivec3(10, 20, 30);
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;
}
static 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;
}
static 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()
{
// Suppress unused variable warnings
(void)g1;
(void)g2;
(void)g3;
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;
}
+858
View File
@@ -0,0 +1,858 @@
#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>
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wglobal-constructors"
# pragma clang diagnostic ignored "-Wunused-variable"
#endif
static glm::vec4 g1;
static glm::vec4 g2(1);
static glm::vec4 g3(1, 1, 1, 1);
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
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 = {
a,
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
{
glm::dvec4 a{ 0, 1, 2, 3 };
std::vector<glm::dvec4> v = {
a,
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
#endif
{
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;
}
{
glm::vec1 R(1.0f);
glm::vec1 S(2.0f);
glm::vec1 T(3.0f);
glm::vec1 U(4.0f);
glm::vec4 O(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 A(R);
glm::vec4 B(1.0f);
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 C(R, S, T, U);
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 D(R, 2.0f, 3.0f, 4.0f);
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 E(1.0f, S, 3.0f, 4.0f);
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 F(R, S, 3.0f, 4.0f);
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 G(1.0f, 2.0f, T, 4.0f);
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 H(R, 2.0f, T, 4.0f);
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 I(1.0f, S, T, 4.0f);
Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 J(R, S, T, 4.0f);
Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 K(R, 2.0f, 3.0f, U);
Error += glm::all(glm::equal(K, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 L(1.0f, S, 3.0f, U);
Error += glm::all(glm::equal(L, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 M(R, S, 3.0f, U);
Error += glm::all(glm::equal(M, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 N(1.0f, 2.0f, T, U);
Error += glm::all(glm::equal(N, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 P(R, 2.0f, T, U);
Error += glm::all(glm::equal(P, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 Q(1.0f, S, T, U);
Error += glm::all(glm::equal(Q, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 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 v1_0(1.0f);
glm::vec1 v1_1(2.0f);
glm::vec1 v1_2(3.0f);
glm::vec1 v1_3(4.0f);
glm::vec2 v2_0(1.0f, 2.0f);
glm::vec2 v2_1(2.0f, 3.0f);
glm::vec2 v2_2(3.0f, 4.0f);
glm::vec3 v3_0(1.0f, 2.0f, 3.0f);
glm::vec3 v3_1(2.0f, 3.0f, 4.0f);
glm::vec4 O(1.0f, 2.0, 3.0f, 4.0);
glm::vec4 A(v1_0, v1_1, v2_2);
Error += glm::all(glm::equal(A, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 B(1.0f, 2.0f, v2_2);
Error += glm::all(glm::equal(B, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 C(v1_0, 2.0f, v2_2);
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 D(1.0f, v1_1, v2_2);
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 E(v2_0, v1_2, v1_3);
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 F(v2_0, 3.0, v1_3);
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 G(v2_0, v1_2, 4.0);
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 H(v2_0, 3.0f, 4.0);
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 I(v3_0, 4.0);
Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 J(1.0f, v3_1);
Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1;
glm::vec4 K(1.0f, v2_1, 4.0f);
Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static int test_bvec4_ctor()
{
int Error = 0;
glm::bvec4 A(true);
glm::bvec4 B(true);
glm::bvec4 C(false);
glm::bvec4 D = A && B;
glm::bvec4 E = A && C;
glm::bvec4 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 G = A == C;
bool 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 A(1.0f, 2.0f, 2.0f, 4.0f);
glm::ivec4 B(4.0f, 4.0f, 8.0f, 8.0f);
B = B / A;
Error += B == glm::ivec4(4, 2, 4, 2) ? 0 : 1;
B = 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 A(1, 2, 3, 4);
glm::uvec4 B(1, 2, 3, 4);
Error += A == B ? 0 : 1;
Error += A != B ? 1 : 0;
}
{
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 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;
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
glm::vec4 const A(1, 2, 3, 4);
{
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()
{
// Suppress unused variable warnings
(void)g1;
(void)g2;
(void)g3;
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;
}