16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00

merge local branch 'mover_in_c++'

This commit is contained in:
tmj-fstate
2018-10-12 17:45:01 +02:00
parent 6f6ffddd7a
commit e801953c1d
1626 changed files with 380156 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
function(glmCreateTestGTC NAME)
if(GLM_TEST_ENABLE)
set(SAMPLE_NAME test-${NAME})
add_executable(${SAMPLE_NAME} ${NAME}.cpp)
add_test(
NAME ${SAMPLE_NAME}
COMMAND $<TARGET_FILE:${SAMPLE_NAME}> )
endif(GLM_TEST_ENABLE)
endfunction()
add_subdirectory(bug)
add_subdirectory(core)
add_subdirectory(ext)
add_subdirectory(gtc)
add_subdirectory(gtx)

View File

@@ -0,0 +1 @@
glmCreateTestGTC(bug_ms_vec_static)

View File

@@ -0,0 +1,31 @@
#include <glm/glm.hpp>
#if GLM_HAS_ALIGNED_TYPE
struct vec2;
struct _swizzle
{
char _buffer[1];
};
struct vec2
{
GLM_CONSTEXPR_CTOR vec2() :
x(0), y(0)
{}
union
{
struct { float x, y; };
struct { _swizzle xx; };
};
};
#endif
// Visual C++ has a bug generating the error: fatal error C1001: An internal error has occurred in the compiler.
// vec2 Bar;
int main()
{
return 0;
}

View File

@@ -0,0 +1,41 @@
glmCreateTestGTC(core_force_pure)
glmCreateTestGTC(core_force_unrestricted_gentype)
glmCreateTestGTC(core_type_aligned)
glmCreateTestGTC(core_type_cast)
glmCreateTestGTC(core_type_ctor)
glmCreateTestGTC(core_type_float)
glmCreateTestGTC(core_type_int)
glmCreateTestGTC(core_type_length)
glmCreateTestGTC(core_type_mat2x2)
glmCreateTestGTC(core_type_mat2x3)
glmCreateTestGTC(core_type_mat2x4)
glmCreateTestGTC(core_type_mat3x2)
glmCreateTestGTC(core_type_mat3x3)
glmCreateTestGTC(core_type_mat3x4)
glmCreateTestGTC(core_type_mat4x2)
glmCreateTestGTC(core_type_mat4x3)
glmCreateTestGTC(core_type_mat4x4)
glmCreateTestGTC(core_type_vec1)
glmCreateTestGTC(core_type_vec2)
glmCreateTestGTC(core_type_vec3)
glmCreateTestGTC(core_type_vec4)
glmCreateTestGTC(core_func_common)
glmCreateTestGTC(core_func_exponential)
glmCreateTestGTC(core_func_geometric)
glmCreateTestGTC(core_func_integer)
glmCreateTestGTC(core_func_integer_bit_count)
glmCreateTestGTC(core_func_integer_find_lsb)
glmCreateTestGTC(core_func_integer_find_msb)
glmCreateTestGTC(core_func_matrix)
glmCreateTestGTC(core_func_noise)
glmCreateTestGTC(core_func_packing)
glmCreateTestGTC(core_func_trigonometric)
glmCreateTestGTC(core_func_vector_relational)
glmCreateTestGTC(core_func_swizzle)
glmCreateTestGTC(core_setup_force_cxx98)
glmCreateTestGTC(core_setup_force_size_t_length)
glmCreateTestGTC(core_setup_message)
glmCreateTestGTC(core_setup_precision)

View File

@@ -0,0 +1,430 @@
#ifndef GLM_FORCE_PURE
# define GLM_FORCE_PURE
#endif//GLM_FORCE_PURE
#define GLM_FORCE_ALIGNED
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <cstdio>
#include <ctime>
#include <vector>
int test_vec4_ctor()
{
int Error = 0;
{
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B(A);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
}
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1;
# endif
#if GLM_HAS_INITIALIZER_LISTS
{
glm::vec4 a{ 0, 1, 2, 3 };
std::vector<glm::vec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
{
glm::dvec4 a{ 0, 1, 2, 3 };
std::vector<glm::dvec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
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)) ? 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_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec4 A(1);
glm::vec4 B(1, 1, 1, 1);
Error += A == B ? 0 : 1;
}
{
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(glm::vec2(1, 2), 3, 4));
Tests.push_back(glm::vec4(1, glm::vec2(2, 3), 4));
Tests.push_back(glm::vec4(1, 2, glm::vec2(3, 4)));
Tests.push_back(glm::vec4(glm::vec3(1, 2, 3), 4));
Tests.push_back(glm::vec4(1, glm::vec3(2, 3, 4)));
Tests.push_back(glm::vec4(glm::vec2(1, 2), glm::vec2(3, 4)));
Tests.push_back(glm::vec4(1, 2, 3, 4));
Tests.push_back(glm::vec4(glm::vec4(1, 2, 3, 4)));
for(std::size_t i = 0; i < Tests.size(); ++i)
Error += Tests[i] == glm::vec4(1, 2, 3, 4) ? 0 : 1;
}
return Error;
}
int test_bvec4_ctor()
{
int Error = 0;
glm::bvec4 const A(true);
glm::bvec4 const B(true);
glm::bvec4 const C(false);
glm::bvec4 const D = A && B;
glm::bvec4 const E = A && C;
glm::bvec4 const F = A || C;
Error += D == glm::bvec4(true) ? 0 : 1;
Error += E == glm::bvec4(false) ? 0 : 1;
Error += F == glm::bvec4(true) ? 0 : 1;
bool const G = A == C;
bool const H = A != C;
Error += !G ? 0 : 1;
Error += H ? 0 : 1;
return Error;
}
int test_vec4_operators()
{
int Error = 0;
{
glm::vec4 A(1.0f);
glm::vec4 B(1.0f);
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
glm::vec4 C = A + B;
Error += C == glm::vec4(5, 7, 9, 11) ? 0 : 1;
glm::vec4 D = B - A;
Error += D == glm::vec4(3, 3, 3, 3) ? 0 : 1;
glm::vec4 E = A * B;
Error += E == glm::vec4(4, 10, 18, 28) ? 0 : 1;
glm::vec4 F = B / A;
Error += F == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
glm::vec4 G = A + 1.0f;
Error += G == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 H = B - 1.0f;
Error += H == glm::vec4(3, 4, 5, 6) ? 0 : 1;
glm::vec4 I = A * 2.0f;
Error += I == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 J = B / 2.0f;
Error += J == glm::vec4(2, 2.5, 3, 3.5) ? 0 : 1;
glm::vec4 K = 1.0f + A;
Error += K == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 L = 1.0f - B;
Error += L == glm::vec4(-3, -4, -5, -6) ? 0 : 1;
glm::vec4 M = 2.0f * A;
Error += M == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 N = 2.0f / B;
Error += N == glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A += B;
Error += A == glm::vec4(5, 7, 9, 11) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec4(6, 8, 10, 12) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B -= A;
Error += B == glm::vec4(3, 3, 3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec4(2, 2, 2, 2) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A *= B;
Error += A == glm::vec4(4, 10, 18, 28) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec4(8, 20, 36, 56) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B /= A;
Error += B == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec4(2, 1.25, 1, 7.0f / 4.0f / 2.0f) ? 0 : 1;
}
{
glm::vec4 B(2.0f);
B /= B.y;
Error += B == glm::vec4(1.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = -A;
Error += B == glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = --A;
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A--;
Error += B == glm::vec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
Error += A == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = ++A;
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A++;
Error += B == glm::vec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
Error += A == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
return Error;
}
int test_vec4_equal()
{
int Error = 0;
{
glm::vec4 const A(1, 2, 3, 4);
glm::vec4 const B(1, 2, 3, 4);
Error += A == B ? 0 : 1;
Error += A != B ? 1 : 0;
}
{
glm::ivec4 const A(1, 2, 3, 4);
glm::ivec4 const B(1, 2, 3, 4);
Error += A == B ? 0 : 1;
Error += A != B ? 1 : 0;
}
return Error;
}
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;
}
int test_vec4_swizzle_partial()
{
int Error = 0;
glm::vec4 A(1, 2, 3, 4);
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE_RELAX)
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xy, 3.0f, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, A.yz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, 2.0f, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xyz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, A.yzw);
Error += A == B ? 0 : 1;
}
# endif
return Error;
}
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;
}
namespace heap
{
struct A
{
float f;
};
struct B : public A
{
float g;
glm::vec4 v;
};
int test()
{
int Error = 0;
A* p = new B;
p->f = 0.f;
delete p;
Error += sizeof(B) == (sizeof(glm::vec4) + sizeof(float) * 2) ? 0 : 1;
return Error;
}
}//namespace heap
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();
Error += heap::test();
return Error;
}

View File

@@ -0,0 +1,11 @@
#define GLM_FORCE_UNRESTRICTED_GENTYPE
#include <glm/glm.hpp>
int main()
{
int Error = 0;
return Error;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,183 @@
#include <glm/common.hpp>
#include <glm/exponential.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/vec1.hpp>
static int test_pow()
{
int Error(0);
float A = glm::pow(2.f, 2.f);
Error += glm::epsilonEqual(A, 4.f, 0.01f) ? 0 : 1;
glm::vec1 B = glm::pow(glm::vec1(2.f), glm::vec1(2.f));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(A, 2.f, 0.01f) ? 0 : 1;
glm::vec1 B = glm::sqrt(glm::vec1(4.f));
Error += glm::all(glm::epsilonEqual(B, glm::vec1(2.f), 0.01f)) ? 0 : 1;
glm::vec2 C = glm::sqrt(glm::vec2(4.f));
Error += glm::all(glm::epsilonEqual(C, glm::vec2(2.f), 0.01f)) ? 0 : 1;
glm::vec3 D = glm::sqrt(glm::vec3(4.f));
Error += glm::all(glm::epsilonEqual(D, glm::vec3(2.f), 0.01f)) ? 0 : 1;
glm::vec4 E = glm::sqrt(glm::vec4(4.f));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::e<float>(), 0.01f) ? 0 : 1;
glm::vec1 B = glm::exp(glm::vec1(1.f));
Error += glm::all(glm::epsilonEqual(B, glm::vec1(glm::e<float>()), 0.01f)) ? 0 : 1;
glm::vec2 C = glm::exp(glm::vec2(1.f));
Error += glm::all(glm::epsilonEqual(C, glm::vec2(glm::e<float>()), 0.01f)) ? 0 : 1;
glm::vec3 D = glm::exp(glm::vec3(1.f));
Error += glm::all(glm::epsilonEqual(D, glm::vec3(glm::e<float>()), 0.01f)) ? 0 : 1;
glm::vec4 E = glm::exp(glm::vec4(1.f));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1;
glm::vec1 const B = glm::log(glm::vec1(glm::e<float>()));
Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.f), 0.01f)) ? 0 : 1;
glm::vec2 const C = glm::log(glm::vec2(glm::e<float>()));
Error += glm::all(glm::epsilonEqual(C, glm::vec2(1.f), 0.01f)) ? 0 : 1;
glm::vec3 const D = glm::log(glm::vec3(glm::e<float>()));
Error += glm::all(glm::epsilonEqual(D, glm::vec3(1.f), 0.01f)) ? 0 : 1;
glm::vec4 const E = glm::log(glm::vec4(glm::e<float>()));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, 16.f, 0.01f) ? 0 : 1;
glm::vec1 B = glm::exp2(glm::vec1(4.f));
Error += glm::all(glm::epsilonEqual(B, glm::vec1(16.f), 0.01f)) ? 0 : 1;
glm::vec2 C = glm::exp2(glm::vec2(4.f, 3.f));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(A, 4.f, 0.01f) ? 0 : 1;
glm::vec1 B = glm::log2(glm::vec1(16.f));
Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1;
glm::vec2 C = glm::log2(glm::vec2(16.f, 8.f));
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1;
glm::vec1 B = glm::inversesqrt(glm::vec1(16.f)) * glm::sqrt(16.f);;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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::epsilonEqual(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;
}

View File

@@ -0,0 +1,193 @@
#include <glm/geometric.hpp>
#include <glm/vector_relational.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/vec1.hpp>
#include <limits>
namespace length
{
int test()
{
float Length1 = glm::length(glm::vec1(1));
float Length2 = glm::length(glm::vec2(1, 0));
float Length3 = glm::length(glm::vec3(1, 0, 0));
float Length4 = glm::length(glm::vec4(1, 0, 0, 0));
int Error = 0;
Error += glm::abs(Length1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Length2 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Length3 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Length4 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
return Error;
}
}//namespace length
namespace distance
{
int test()
{
float Distance1 = glm::distance(glm::vec1(1), glm::vec1(1));
float Distance2 = glm::distance(glm::vec2(1, 0), glm::vec2(1, 0));
float Distance3 = glm::distance(glm::vec3(1, 0, 0), glm::vec3(1, 0, 0));
float Distance4 = glm::distance(glm::vec4(1, 0, 0, 0), glm::vec4(1, 0, 0, 0));
int Error = 0;
Error += glm::abs(Distance1) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Distance2) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Distance3) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Distance4) < std::numeric_limits<float>::epsilon() ? 0 : 1;
return Error;
}
}//namespace distance
namespace dot
{
int test()
{
float Dot1 = glm::dot(glm::vec1(1), glm::vec1(1));
float Dot2 = glm::dot(glm::vec2(1), glm::vec2(1));
float Dot3 = glm::dot(glm::vec3(1), glm::vec3(1));
float Dot4 = glm::dot(glm::vec4(1), glm::vec4(1));
int Error = 0;
Error += glm::abs(Dot1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Dot2 - 2.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Dot3 - 3.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += glm::abs(Dot4 - 4.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
return Error;
}
}//namespace dot
namespace cross
{
int test()
{
glm::vec3 Cross1 = glm::cross(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
glm::vec3 Cross2 = glm::cross(glm::vec3(0, 1, 0), glm::vec3(1, 0, 0));
int Error = 0;
Error += glm::all(glm::lessThan(glm::abs(Cross1 - glm::vec3(0, 0, 1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
Error += glm::all(glm::lessThan(glm::abs(Cross2 - glm::vec3(0, 0,-1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
return Error;
}
}//namespace cross
namespace normalize
{
int test()
{
glm::vec3 Normalize1 = glm::normalize(glm::vec3(1, 0, 0));
glm::vec3 Normalize2 = glm::normalize(glm::vec3(2, 0, 0));
glm::vec3 Normalize3 = glm::normalize(glm::vec3(-0.6, 0.7, -0.5));
glm::vec3 ro = glm::vec3(glm::cos(5.f) * 3.f, 2.f, glm::sin(5.f) * 3.f);
glm::vec3 w = glm::normalize(glm::vec3(0, -0.2f, 0) - ro);
glm::vec3 u = glm::normalize(glm::cross(w, glm::vec3(0, 1, 0)));
glm::vec3 v = glm::cross(u, w);
int Error = 0;
Error += glm::all(glm::lessThan(glm::abs(Normalize1 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
Error += glm::all(glm::lessThan(glm::abs(Normalize2 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
return Error;
}
}//namespace normalize
namespace faceforward
{
int test()
{
int Error = 0;
{
glm::vec3 N(0.0f, 0.0f, 1.0f);
glm::vec3 I(1.0f, 0.0f, 1.0f);
glm::vec3 Nref(0.0f, 0.0f, 1.0f);
glm::vec3 F = glm::faceforward(N, I, Nref);
}
return Error;
}
}//namespace faceforward
namespace reflect
{
int test()
{
int Error = 0;
{
glm::vec2 A(1.0f,-1.0f);
glm::vec2 B(0.0f, 1.0f);
glm::vec2 C = glm::reflect(A, B);
Error += C == glm::vec2(1.0, 1.0) ? 0 : 1;
}
{
glm::dvec2 A(1.0f,-1.0f);
glm::dvec2 B(0.0f, 1.0f);
glm::dvec2 C = glm::reflect(A, B);
Error += C == glm::dvec2(1.0, 1.0) ? 0 : 1;
}
return Error;
}
}//namespace reflect
namespace refract
{
int test()
{
int Error = 0;
{
float A(-1.0f);
float B(1.0f);
float C = glm::refract(A, B, 0.5f);
Error += glm::epsilonEqual(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::epsilonEqual(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 += C == glm::dvec2(0.0, -1.0) ? 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

View File

@@ -0,0 +1,291 @@
// This has the programs for computing the number of 1-bits
// in a word, or byte, etc.
// Max line length is 57, to fit in hacker.book.
#include <stdio.h>
#include <stdlib.h> //To define "exit", req'd by XLC.
#include <ctime>
unsigned rotatel(unsigned x, int n)
{
if (static_cast<unsigned>(n) > 63) {printf("rotatel, n out of range.\n"); exit(1);}
return (x << n) | (x >> (32 - n));
}
int pop0(unsigned x)
{
x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF);
return x;
}
int pop1(unsigned x)
{
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x = x + (x >> 8);
x = x + (x >> 16);
return x & 0x0000003F;
}
/* Note: an alternative to the last three executable lines above is:
return x*0x01010101 >> 24;
if your machine has a fast multiplier (suggested by Jari Kirma). */
int pop2(unsigned x)
{
unsigned n;
n = (x >> 1) & 033333333333; // Count bits in
x = x - n; // each 3-bit
n = (n >> 1) & 033333333333; // field.
x = x - n;
x = (x + (x >> 3)) & 030707070707; // 6-bit sums.
return x%63; // Add 6-bit sums.
}
/* An alternative to the "return" statement above is:
return ((x * 0404040404) >> 26) + // Add 6-bit sums.
(x >> 30);
which runs faster on most machines (suggested by Norbert Juffa). */
int pop3(unsigned x)
{
unsigned n;
n = (x >> 1) & 0x77777777; // Count bits in
x = x - n; // each 4-bit
n = (n >> 1) & 0x77777777; // field.
x = x - n;
n = (n >> 1) & 0x77777777;
x = x - n;
x = (x + (x >> 4)) & 0x0F0F0F0F; // Get byte sums.
x = x*0x01010101; // Add the bytes.
return x >> 24;
}
int pop4(unsigned x)
{
int n;
n = 0;
while (x != 0) {
n = n + 1;
x = x & (x - 1);
}
return n;
}
int pop5(unsigned x)
{
int i, sum;
// Rotate and sum method // Shift right & subtract
sum = x; // sum = x;
for (i = 1; i <= 31; i++) { // while (x != 0) {
x = rotatel(x, 1); // x = x >> 1;
sum = sum + x; // sum = sum - x;
} // }
return -sum; // return sum;
}
int pop5a(unsigned x)
{
int sum;
// Shift right & subtract
sum = x;
while (x != 0) {
x = x >> 1;
sum = sum - x;
}
return sum;
}
int pop6(unsigned x)
{ // Table lookup.
static char table[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
return table[x & 0xFF] +
table[(x >> 8) & 0xFF] +
table[(x >> 16) & 0xFF] +
table[(x >> 24)];
}
// The following works only for 8-bit quantities.
int pop7(unsigned x)
{
x = x*0x08040201; // Make 4 copies.
x = x >> 3; // So next step hits proper bits.
x = x & 0x11111111; // Every 4th bit.
x = x*0x11111111; // Sum the digits (each 0 or 1).
x = x >> 28; // Position the result.
return x;
}
// The following works only for 7-bit quantities.
int pop8(unsigned x)
{
x = x*0x02040810; // Make 4 copies, left-adjusted.
x = x & 0x11111111; // Every 4th bit.
x = x*0x11111111; // Sum the digits (each 0 or 1).
x = x >> 28; // Position the result.
return x;
}
// The following works only for 15-bit quantities.
int pop9(unsigned x)
{
unsigned long long y;
y = x * 0x0002000400080010ULL;
y = y & 0x1111111111111111ULL;
y = y * 0x1111111111111111ULL;
y = y >> 60;
return static_cast<int>(y);
}
int errors;
void error(int x, int y)
{
errors = errors + 1;
printf("Error for x = %08x, got %08x\n", x, y);
}
int main()
{
# ifdef NDEBUG
int i, n;
static unsigned test[] = {0,0, 1,1, 2,1, 3,2, 4,1, 5,2, 6,2, 7,3,
8,1, 9,2, 10,2, 11,3, 12,2, 13,3, 14,3, 15,4, 16,1, 17,2,
0x3F,6, 0x40,1, 0x41,2, 0x7f,7, 0x80,1, 0x81,2, 0xfe,7, 0xff,8,
0x4000,1, 0x4001,2, 0x7000,3, 0x7fff,15,
0x55555555,16, 0xAAAAAAAA, 16, 0xFF000000,8, 0xC0C0C0C0,8,
0x0FFFFFF0,24, 0x80000000,1, 0xFFFFFFFF,32};
std::size_t const Count = 1000000;
n = sizeof(test)/4;
std::clock_t TimestampBeg = 0;
std::clock_t TimestampEnd = 0;
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop0(test[i]) != test[i+1]) error(test[i], pop0(test[i]));}
TimestampEnd = std::clock();
printf("pop0: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop1(test[i]) != test[i+1]) error(test[i], pop1(test[i]));}
TimestampEnd = std::clock();
printf("pop1: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop2(test[i]) != test[i+1]) error(test[i], pop2(test[i]));}
TimestampEnd = std::clock();
printf("pop2: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop3(test[i]) != test[i+1]) error(test[i], pop3(test[i]));}
TimestampEnd = std::clock();
printf("pop3: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop4(test[i]) != test[i+1]) error(test[i], pop4(test[i]));}
TimestampEnd = std::clock();
printf("pop4: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop5(test[i]) != test[i+1]) error(test[i], pop5(test[i]));}
TimestampEnd = std::clock();
printf("pop5: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop5a(test[i]) != test[i+1]) error(test[i], pop5a(test[i]));}
TimestampEnd = std::clock();
printf("pop5a: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop6(test[i]) != test[i+1]) error(test[i], pop6(test[i]));}
TimestampEnd = std::clock();
printf("pop6: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffffff00) == 0)
if (pop7(test[i]) != test[i+1]) error(test[i], pop7(test[i]));}
TimestampEnd = std::clock();
printf("pop7: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffffff80) == 0)
if (pop8(test[i]) != test[i+1]) error(test[i], pop8(test[i]));}
TimestampEnd = std::clock();
printf("pop8: %ld clocks\n", TimestampEnd - TimestampBeg);
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffff8000) == 0)
if (pop9(test[i]) != test[i+1]) error(test[i], pop9(test[i]));}
TimestampEnd = std::clock();
printf("pop9: %ld clocks\n", TimestampEnd - TimestampBeg);
if (errors == 0)
printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
# endif//NDEBUG
}

View File

@@ -0,0 +1,406 @@
#include <glm/glm.hpp>
#include <cstdio>
#include <cstdlib> //To define "exit", req'd by XLC.
#include <ctime>
int nlz(unsigned x) {
int pop(unsigned x);
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >>16);
return pop(~x);
}
int pop(unsigned x) {
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x = x + (x << 8);
x = x + (x << 16);
return x >> 24;
}
int ntz1(unsigned x) {
return 32 - nlz(~x & (x-1));
}
int ntz2(unsigned x) {
return pop(~x & (x - 1));
}
int ntz3(unsigned x) {
int n;
if (x == 0) return(32);
n = 1;
if ((x & 0x0000FFFF) == 0) {n = n +16; x = x >>16;}
if ((x & 0x000000FF) == 0) {n = n + 8; x = x >> 8;}
if ((x & 0x0000000F) == 0) {n = n + 4; x = x >> 4;}
if ((x & 0x00000003) == 0) {n = n + 2; x = x >> 2;}
return n - (x & 1);
}
int ntz4(unsigned x) {
unsigned y;
int n;
if (x == 0) return 32;
n = 31;
y = x <<16; if (y != 0) {n = n -16; x = y;}
y = x << 8; if (y != 0) {n = n - 8; x = y;}
y = x << 4; if (y != 0) {n = n - 4; x = y;}
y = x << 2; if (y != 0) {n = n - 2; x = y;}
y = x << 1; if (y != 0) {n = n - 1;}
return n;
}
int ntz4a(unsigned x) {
unsigned y;
int n;
if (x == 0) return 32;
n = 31;
y = x <<16; if (y != 0) {n = n -16; x = y;}
y = x << 8; if (y != 0) {n = n - 8; x = y;}
y = x << 4; if (y != 0) {n = n - 4; x = y;}
y = x << 2; if (y != 0) {n = n - 2; x = y;}
n = n - ((x << 1) >> 31);
return n;
}
int ntz5(char x)
{
if (x & 15) {
if (x & 3) {
if (x & 1) return 0;
else return 1;
}
else if (x & 4) return 2;
else return 3;
}
else if (x & 0x30) {
if (x & 0x10) return 4;
else return 5;
}
else if (x & 0x40) return 6;
else if (x) return 7;
else return 8;
}
int ntz6(unsigned x) {
int n;
x = ~x & (x - 1);
n = 0; // n = 32;
while(x != 0) { // while (x != 0) {
n = n + 1; // n = n - 1;
x = x >> 1; // x = x + x;
} // }
return n; // return n;
}
int ntz6a(unsigned x)
{
int n = 32;
while (x != 0) {
n = n - 1;
x = x + x;
}
return n;
}
/* Dean Gaudet's algorithm. To be most useful there must be a good way
to evaluate the C "conditional expression" (a?b:c construction) without
branching. The result of a?b:c is b if a is true (nonzero), and c if a
is false (0).
For example, a compare to zero op that sets a target GPR to 1 if the
operand is 0, and to 0 if the operand is nonzero, will do it. With this
instruction, the algorithm is entirely branch-free. But the most
interesting thing about it is the high degree of parallelism. All six
lines with conditional expressions can be executed in parallel (on a
machine with sufficient computational units).
Although the instruction count is 30 measured statically, it could
execute in only 10 cycles on a machine with sufficient parallelism.
The first two uses of y can instead be x, which would increase the
useful parallelism on most machines (the assignments to y, bz, and b4
could then all run in parallel). */
int ntz7(unsigned x)
{
unsigned y, bz, b4, b3, b2, b1, b0;
y = x & -x; // Isolate rightmost 1-bit.
bz = y ? 0 : 1; // 1 if y = 0.
b4 = (y & 0x0000FFFF) ? 0 : 16;
b3 = (y & 0x00FF00FF) ? 0 : 8;
b2 = (y & 0x0F0F0F0F) ? 0 : 4;
b1 = (y & 0x33333333) ? 0 : 2;
b0 = (y & 0x55555555) ? 0 : 1;
return bz + b4 + b3 + b2 + b1 + b0;
}
// This file has divisions by zero to test isnan
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(disable : 4800)
#endif
int ntz7_christophe(unsigned x)
{
unsigned y, bz, b4, b3, b2, b1, b0;
y = x & -x; // Isolate rightmost 1-bit.
bz = unsigned(!bool(y)); // 1 if y = 0.
b4 = unsigned(!bool(y & 0x0000FFFF)) * 16;
b3 = unsigned(!bool(y & 0x00FF00FF)) * 8;
b2 = unsigned(!bool(y & 0x0F0F0F0F)) * 4;
b1 = unsigned(!bool(y & 0x33333333)) * 2;
b0 = unsigned(!bool(y & 0x55555555)) * 1;
return bz + b4 + b3 + b2 + b1 + b0;
}
/* Below is David Seal's algorithm, found at
http://www.ciphersbyritter.com/NEWS4/BITCT.HTM Table
entries marked "u" are unused. 6 ops including a
multiply, plus an indexed load. */
#define u 99
int ntz8(unsigned x)
{
static char table[64] =
{32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14,
10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15,
31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26,
30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u};
x = (x & -x)*0x0450FBAF;
return table[x >> 26];
}
/* Seal's algorithm with multiply expanded.
9 elementary ops plus an indexed load. */
int ntz8a(unsigned x)
{
static char table[64] =
{32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14,
10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15,
31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26,
30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u};
x = (x & -x);
x = (x << 4) + x; // x = x*17.
x = (x << 6) + x; // x = x*65.
x = (x << 16) - x; // x = x*65535.
return table[x >> 26];
}
/* Reiser's algorithm. Three ops including a "remainder,"
plus an indexed load. */
int ntz9(unsigned x) {
static char table[37] = {32, 0, 1, 26, 2, 23, 27,
u, 3, 16, 24, 30, 28, 11, u, 13, 4,
7, 17, u, 25, 22, 31, 15, 29, 10, 12,
6, u, 21, 14, 9, 5, 20, 8, 19, 18};
x = (x & -x)%37;
return table[x];
}
/* Using a de Bruijn sequence. This is a table lookup with a 32-entry
table. The de Bruijn sequence used here is
0000 0100 1101 0111 0110 0101 0001 1111,
obtained from Danny Dube's October 3, 1997, posting in
comp.compression.research. Thanks to Norbert Juffa for this reference. */
int ntz10(unsigned x) {
static char table[32] =
{ 0, 1, 2,24, 3,19, 6,25, 22, 4,20,10,16, 7,12,26,
31,23,18, 5,21, 9,15,11, 30,17, 8,14,29,13,28,27};
if (x == 0) return 32;
x = (x & -x)*0x04D7651F;
return table[x >> 27];
}
/* Norbert Juffa's code, answer to exercise 1 of Chapter 5 (2nd ed). */
#define SLOW_MUL
int ntz11 (unsigned int n) {
static unsigned char tab[32] =
{ 0, 1, 2, 24, 3, 19, 6, 25,
22, 4, 20, 10, 16, 7, 12, 26,
31, 23, 18, 5, 21, 9, 15, 11,
30, 17, 8, 14, 29, 13, 28, 27
};
unsigned int k;
n = n & (-n); /* isolate lsb */
printf("n = %d\n", n);
#if defined(SLOW_MUL)
k = (n << 11) - n;
k = (k << 2) + k;
k = (k << 8) + n;
k = (k << 5) - k;
#else
k = n * 0x4d7651f;
#endif
return n ? tab[k>>27] : 32;
}
int errors;
void error(int x, int y) {
errors = errors + 1;
printf("Error for x = %08x, got %d\n", x, y);
}
int main()
{
# ifdef NDEBUG
int i, m, n;
static unsigned test[] = {0,32, 1,0, 2,1, 3,0, 4,2, 5,0, 6,1, 7,0,
8,3, 9,0, 16,4, 32,5, 64,6, 128,7, 255,0, 256,8, 512,9, 1024,10,
2048,11, 4096,12, 8192,13, 16384,14, 32768,15, 65536,16,
0x20000,17, 0x40000,18, 0x80000,19, 0x100000,20, 0x200000,21,
0x400000,22, 0x800000,23, 0x1000000,24, 0x2000000,25,
0x4000000,26, 0x8000000,27, 0x10000000,28, 0x20000000,29,
0x40000000,30, 0x80000000,31, 0xFFFFFFF0,4, 0x3000FF00,8,
0xC0000000,30, 0x60000000,29, 0x00011000, 12};
std::size_t const Count = 1000;
n = sizeof(test)/4;
std::clock_t TimestampBeg = 0;
std::clock_t TimestampEnd = 0;
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz1(test[i]) != test[i+1]) error(test[i], ntz1(test[i]));}
TimestampEnd = std::clock();
printf("ntz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz2(test[i]) != test[i+1]) error(test[i], ntz2(test[i]));}
TimestampEnd = std::clock();
printf("ntz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz3(test[i]) != test[i+1]) error(test[i], ntz3(test[i]));}
TimestampEnd = std::clock();
printf("ntz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz4(test[i]) != test[i+1]) error(test[i], ntz4(test[i]));}
TimestampEnd = std::clock();
printf("ntz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz4a(test[i]) != test[i+1]) error(test[i], ntz4a(test[i]));}
TimestampEnd = std::clock();
printf("ntz4a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for(std::size_t k = 0; k < Count; ++k)
for(i = 0; i < n; i += 2)
{
m = test[i+1];
if(m > 8)
m = 8;
if(ntz5(static_cast<char>(test[i])) != m)
error(test[i], ntz5(static_cast<char>(test[i])));
}
TimestampEnd = std::clock();
printf("ntz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz6(test[i]) != test[i+1]) error(test[i], ntz6(test[i]));}
TimestampEnd = std::clock();
printf("ntz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz6a(test[i]) != test[i+1]) error(test[i], ntz6a(test[i]));}
TimestampEnd = std::clock();
printf("ntz6a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz7(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));}
TimestampEnd = std::clock();
printf("ntz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz7_christophe(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));}
TimestampEnd = std::clock();
printf("ntz7_christophe: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz8(test[i]) != test[i+1]) error(test[i], ntz8(test[i]));}
TimestampEnd = std::clock();
printf("ntz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz8a(test[i]) != test[i+1]) error(test[i], ntz8a(test[i]));}
TimestampEnd = std::clock();
printf("ntz8a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz9(test[i]) != test[i+1]) error(test[i], ntz9(test[i]));}
TimestampEnd = std::clock();
printf("ntz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (ntz10(test[i]) != test[i+1]) error(test[i], ntz10(test[i]));}
TimestampEnd = std::clock();
printf("ntz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
if (errors == 0)
printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
# endif//NDEBUG
}

View File

@@ -0,0 +1,440 @@
#include <glm/glm.hpp>
#include <cstdio>
#include <cstdlib> // To define "exit", req'd by XLC.
#include <ctime>
#define LE 1 // 1 for little-endian, 0 for big-endian.
int pop(unsigned x) {
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x = x + (x << 8);
x = x + (x << 16);
return x >> 24;
}
int nlz1(unsigned x) {
int n;
if (x == 0) return(32);
n = 0;
if (x <= 0x0000FFFF) {n = n +16; x = x <<16;}
if (x <= 0x00FFFFFF) {n = n + 8; x = x << 8;}
if (x <= 0x0FFFFFFF) {n = n + 4; x = x << 4;}
if (x <= 0x3FFFFFFF) {n = n + 2; x = x << 2;}
if (x <= 0x7FFFFFFF) {n = n + 1;}
return n;
}
int nlz1a(unsigned x) {
int n;
/* if (x == 0) return(32); */
if (static_cast<int>(x) <= 0) return (~x >> 26) & 32;
n = 1;
if ((x >> 16) == 0) {n = n +16; x = x <<16;}
if ((x >> 24) == 0) {n = n + 8; x = x << 8;}
if ((x >> 28) == 0) {n = n + 4; x = x << 4;}
if ((x >> 30) == 0) {n = n + 2; x = x << 2;}
n = n - (x >> 31);
return n;
}
// On basic Risc, 12 to 20 instructions.
int nlz2(unsigned x) {
unsigned y;
int n;
n = 32;
y = x >>16; if (y != 0) {n = n -16; x = y;}
y = x >> 8; if (y != 0) {n = n - 8; x = y;}
y = x >> 4; if (y != 0) {n = n - 4; x = y;}
y = x >> 2; if (y != 0) {n = n - 2; x = y;}
y = x >> 1; if (y != 0) return n - 2;
return n - x;
}
// As above but coded as a loop for compactness:
// 23 to 33 basic Risc instructions.
int nlz2a(unsigned x) {
unsigned y;
int n, c;
n = 32;
c = 16;
do {
y = x >> c; if (y != 0) {n = n - c; x = y;}
c = c >> 1;
} while (c != 0);
return n - x;
}
int nlz3(int x) {
int y, n;
n = 0;
y = x;
L: if (x < 0) return n;
if (y == 0) return 32 - n;
n = n + 1;
x = x << 1;
y = y >> 1;
goto L;
}
int nlz4(unsigned x) {
int y, m, n;
y = -(x >> 16); // If left half of x is 0,
m = (y >> 16) & 16; // set n = 16. If left half
n = 16 - m; // is nonzero, set n = 0 and
x = x >> m; // shift x right 16.
// Now x is of the form 0000xxxx.
y = x - 0x100; // If positions 8-15 are 0,
m = (y >> 16) & 8; // add 8 to n and shift x left 8.
n = n + m;
x = x << m;
y = x - 0x1000; // If positions 12-15 are 0,
m = (y >> 16) & 4; // add 4 to n and shift x left 4.
n = n + m;
x = x << m;
y = x - 0x4000; // If positions 14-15 are 0,
m = (y >> 16) & 2; // add 2 to n and shift x left 2.
n = n + m;
x = x << m;
y = x >> 14; // Set y = 0, 1, 2, or 3.
m = y & ~(y >> 1); // Set m = 0, 1, 2, or 2 resp.
return n + 2 - m;
}
int nlz5(unsigned x) {
int pop(unsigned x);
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >>16);
return pop(~x);
}
/* The four programs below are not valid ANSI C programs. This is
because they refer to the same storage locations as two different types.
However, they work with xlc/AIX, gcc/AIX, and gcc/NT. If you try to
code them more compactly by declaring a variable xx to be "double," and
then using
n = 1054 - (*((unsigned *)&xx + LE) >> 20);
then you are violating not only the rule above, but also the ANSI C
rule that pointer arithmetic can be performed only on pointers to
array elements.
When coded with the above statement, the program fails with xlc,
gcc/AIX, and gcc/NT, at some optimization levels.
BTW, these programs use the "anonymous union" feature of C++, not
available in C. */
int nlz6(unsigned k)
{
union {
unsigned asInt[2];
double asDouble;
};
int n;
asDouble = static_cast<double>(k) + 0.5;
n = 1054 - (asInt[LE] >> 20);
return n;
}
int nlz7(unsigned k)
{
union {
unsigned asInt[2];
double asDouble;
};
int n;
asDouble = static_cast<double>(k);
n = 1054 - (asInt[LE] >> 20);
n = (n & 31) + (n >> 9);
return n;
}
/* In single qualifier, round-to-nearest mode, the basic method fails for:
k = 0, k = 01FFFFFF, 03FFFFFE <= k <= 03FFFFFF,
07FFFFFC <= k <= 07FFFFFF,
0FFFFFF8 <= k <= 0FFFFFFF,
...
7FFFFFC0 <= k <= 7FFFFFFF.
FFFFFF80 <= k <= FFFFFFFF.
For k = 0 it gives 158, and for the other values it is too low by 1. */
int nlz8(unsigned k)
{
union {
unsigned asInt;
float asFloat;
};
int n;
k = k & ~(k >> 1); /* Fix problem with rounding. */
asFloat = static_cast<float>(k) + 0.5f;
n = 158 - (asInt >> 23);
return n;
}
/* The example below shows how to make a macro for nlz. It uses an
extension to the C and C++ languages that is provided by the GNU C/C++
compiler, namely, that of allowing statements and declarations in
expressions (see "Using and Porting GNU CC", by Richard M. Stallman
(1998). The underscores are necessary to protect against the
possibility that the macro argument will conflict with one of its local
variables, e.g., NLZ(k). */
int nlz9(unsigned k)
{
union {
unsigned asInt;
float asFloat;
};
int n;
k = k & ~(k >> 1); /* Fix problem with rounding. */
asFloat = static_cast<float>(k);
n = 158 - (asInt >> 23);
n = (n & 31) + (n >> 6); /* Fix problem with k = 0. */
return n;
}
/* Below are three nearly equivalent programs for computing the number
of leading zeros in a word. This material is not in HD, but may be in a
future edition.
Immediately below is Robert Harley's algorithm, found at the
comp.arch newsgroup entry dated 7/12/96, pointed out to me by Norbert
Juffa.
Table entries marked "u" are unused. 14 ops including a multiply,
plus an indexed load.
The smallest multiplier that works is 0x045BCED1 = 17*65*129*513 (all
of form 2**k + 1). There are no multipliers of three terms of the form
2**k +- 1 that work, with a table size of 64 or 128. There are some,
with a table size of 64, if you precede the multiplication with x = x -
(x >> 1), but that seems less elegant. There are also some if you use a
table size of 256, the smallest is 0x01033CBF = 65*255*1025 (this would
save two instructions in the form of this algorithm with the
multiplication expanded into shifts and adds, but the table size is
getting a bit large). */
#define u 99
int nlz10(unsigned x)
{
static char table[64] =
{32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u,
u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u,
17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18,
5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u};
x = x | (x >> 1); // Propagate leftmost
x = x | (x >> 2); // 1-bit to the right.
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >>16);
x = x*0x06EB14F9; // Multiplier is 7*255**3.
return table[x >> 26];
}
/* Harley's algorithm with multiply expanded.
19 elementary ops plus an indexed load. */
int nlz10a(unsigned x)
{
static char table[64] =
{32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u,
u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u,
17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18,
5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u};
x = x | (x >> 1); // Propagate leftmost
x = x | (x >> 2); // 1-bit to the right.
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
x = (x << 3) - x; // Multiply by 7.
x = (x << 8) - x; // Multiply by 255.
x = (x << 8) - x; // Again.
x = (x << 8) - x; // Again.
return table[x >> 26];
}
/* Julius Goryavsky's version of Harley's algorithm.
17 elementary ops plus an indexed load, if the machine
has "and not." */
int nlz10b(unsigned x)
{
static char table[64] =
{32,20,19, u, u,18, u, 7, 10,17, u, u,14, u, 6, u,
u, 9, u,16, u, u, 1,26, u,13, u, u,24, 5, u, u,
u,21, u, 8,11, u,15, u, u, u, u, 2,27, 0,25, u,
22, u,12, u, u, 3,28, u, 23, u, 4,29, u, u,30,31};
x = x | (x >> 1); // Propagate leftmost
x = x | (x >> 2); // 1-bit to the right.
x = x | (x >> 4);
x = x | (x >> 8);
x = x & ~(x >> 16);
x = x*0xFD7049FF; // Activate this line or the following 3.
// x = (x << 9) - x; // Multiply by 511.
// x = (x << 11) - x; // Multiply by 2047.
// x = (x << 14) - x; // Multiply by 16383.
return table[x >> 26];
}
int errors;
void error(int x, int y)
{
errors = errors + 1;
printf("Error for x = %08x, got %d\n", x, y);
}
int main()
{
# ifdef NDEBUG
int i, n;
static unsigned test[] = {0,32, 1,31, 2,30, 3,30, 4,29, 5,29, 6,29,
7,29, 8,28, 9,28, 16,27, 32,26, 64,25, 128,24, 255,24, 256,23,
512,22, 1024,21, 2048,20, 4096,19, 8192,18, 16384,17, 32768,16,
65536,15, 0x20000,14, 0x40000,13, 0x80000,12, 0x100000,11,
0x200000,10, 0x400000,9, 0x800000,8, 0x1000000,7, 0x2000000,6,
0x4000000,5, 0x8000000,4, 0x0FFFFFFF,4, 0x10000000,3,
0x3000FFFF,2, 0x50003333,1, 0x7FFFFFFF,1, 0x80000000,0,
0xFFFFFFFF,0};
std::size_t const Count = 1000;
n = sizeof(test)/4;
std::clock_t TimestampBeg = 0;
std::clock_t TimestampEnd = 0;
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz1(test[i]) != test[i+1]) error(test[i], nlz1(test[i]));}
TimestampEnd = std::clock();
printf("nlz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz1a(test[i]) != test[i+1]) error(test[i], nlz1a(test[i]));}
TimestampEnd = std::clock();
printf("nlz1a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz2(test[i]) != test[i+1]) error(test[i], nlz2(test[i]));}
TimestampEnd = std::clock();
printf("nlz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz2a(test[i]) != test[i+1]) error(test[i], nlz2a(test[i]));}
TimestampEnd = std::clock();
printf("nlz2a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz3(test[i]) != test[i+1]) error(test[i], nlz3(test[i]));}
TimestampEnd = std::clock();
printf("nlz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz4(test[i]) != test[i+1]) error(test[i], nlz4(test[i]));}
TimestampEnd = std::clock();
printf("nlz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz5(test[i]) != test[i+1]) error(test[i], nlz5(test[i]));}
TimestampEnd = std::clock();
printf("nlz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz6(test[i]) != test[i+1]) error(test[i], nlz6(test[i]));}
TimestampEnd = std::clock();
printf("nlz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz7(test[i]) != test[i+1]) error(test[i], nlz7(test[i]));}
TimestampEnd = std::clock();
printf("nlz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz8(test[i]) != test[i+1]) error(test[i], nlz8(test[i]));}
TimestampEnd = std::clock();
printf("nlz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz9(test[i]) != test[i+1]) error(test[i], nlz9(test[i]));}
TimestampEnd = std::clock();
printf("nlz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz10(test[i]) != test[i+1]) error(test[i], nlz10(test[i]));}
TimestampEnd = std::clock();
printf("nlz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz10a(test[i]) != test[i+1]) error(test[i], nlz10a(test[i]));}
TimestampEnd = std::clock();
printf("nlz10a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (nlz10b(test[i]) != test[i+1]) error(test[i], nlz10b(test[i]));}
TimestampEnd = std::clock();
printf("nlz10b: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
if (errors == 0)
printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
# endif//NDEBUG
}

View File

@@ -0,0 +1,329 @@
#include <glm/matrix.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <vector>
#include <ctime>
#include <cstdio>
using namespace glm;
int test_matrixCompMult()
{
int Error(0);
{
mat2 m(0, 1, 2, 3);
mat2 n = matrixCompMult(m, m);
mat2 expected = mat2(0, 1, 4, 9);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], 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);
for (length_t l = 0; l < m.length(); ++l)
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
}
return Error;
}
int test_outerProduct()
{
{ glm::mat2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec2(1.0f)); }
{ glm::mat3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec3(1.0f)); }
{ glm::mat4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec4(1.0f)); }
{ glm::mat2x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec2(1.0f)); }
{ glm::mat2x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec2(1.0f)); }
{ glm::mat3x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec3(1.0f)); }
{ glm::mat3x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec3(1.0f)); }
{ glm::mat4x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec4(1.0f)); }
{ glm::mat4x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec4(1.0f)); }
return 0;
}
int test_transpose()
{
int Error(0);
{
mat2 const m(0, 1, 2, 3);
mat2 const t = transpose(m);
mat2 const expected = mat2(0, 2, 1, 3);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], 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);
for (length_t l = 0; l < expected.length(); ++l)
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
}
return Error;
}
int test_determinant()
{
return 0;
}
int test_inverse()
{
int Error = 0;
{
glm::mat4x4 A4x4(
glm::vec4(1, 0, 1, 0),
glm::vec4(0, 1, 0, 0),
glm::vec4(0, 0, 1, 0),
glm::vec4(0, 0, 0, 1));
glm::mat4x4 B4x4 = inverse(A4x4);
glm::mat4x4 I4x4 = A4x4 * B4x4;
glm::mat4x4 Identity(1);
for (length_t l = 0; l < Identity.length(); ++l)
Error += all(epsilonEqual(I4x4[l], Identity[l], 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);
for (length_t l = 0; l < Identity.length(); ++l)
Error += all(epsilonEqual(I3x3[l], Identity[l], 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);
for (length_t l = 0; l < Identity.length(); ++l)
Error += all(epsilonEqual(I2x2[l], Identity[l], epsilon<float>())) ? 0 : 1;
}
return Error;
}
int test_inverse_simd()
{
int Error = 0;
glm::mat4x4 const Identity(1);
glm::mat4x4 const A4x4(
glm::vec4(1, 0, 1, 0),
glm::vec4(0, 1, 0, 0),
glm::vec4(0, 0, 1, 0),
glm::vec4(0, 0, 0, 1));
glm::mat4x4 const B4x4 = glm::inverse(A4x4);
glm::mat4x4 const I4x4 = A4x4 * B4x4;
Error += glm::all(glm::epsilonEqual(I4x4[0], Identity[0], 0.001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(I4x4[1], Identity[1], 0.001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(I4x4[2], Identity[2], 0.001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(I4x4[3], Identity[3], 0.001f)) ? 0 : 1;
return Error;
}
template<typename VEC3, typename MAT4>
int test_inverse_perf(std::size_t Count, std::size_t Instance, char const * Message)
{
std::vector<MAT4> TestInputs;
TestInputs.resize(Count);
std::vector<MAT4> TestOutputs;
TestOutputs.resize(TestInputs.size());
VEC3 Axis(glm::normalize(VEC3(1.0f, 2.0f, 3.0f)));
for(std::size_t i = 0; i < TestInputs.size(); ++i)
{
typename MAT4::value_type f = static_cast<typename MAT4::value_type>(i + Instance) * typename MAT4::value_type(0.1) + typename MAT4::value_type(0.1);
TestInputs[i] = glm::rotate(glm::translate(MAT4(1), Axis * f), f, Axis);
//TestInputs[i] = glm::translate(MAT4(1), Axis * f);
}
std::clock_t StartTime = std::clock();
for(std::size_t i = 0; i < TestInputs.size(); ++i)
TestOutputs[i] = glm::inverse(TestInputs[i]);
std::clock_t EndTime = std::clock();
for(std::size_t i = 0; i < TestInputs.size(); ++i)
TestOutputs[i] = TestOutputs[i] * TestInputs[i];
typename MAT4::value_type Diff(0);
for(std::size_t Entry = 0; Entry < TestOutputs.size(); ++Entry)
{
MAT4 i(1.0);
MAT4 m(TestOutputs[Entry]);
for(glm::length_t y = 0; y < m.length(); ++y)
for(glm::length_t x = 0; x < m[y].length(); ++x)
Diff = glm::max(m[y][x], i[y][x]);
}
//glm::uint Ulp = 0;
//Ulp = glm::max(glm::float_distance(*Dst, *Src), Ulp);
printf("inverse<%s>(%f): %lu\n", Message, static_cast<double>(Diff), EndTime - StartTime);
return 0;
}
int main()
{
int Error = 0;
Error += test_matrixCompMult();
Error += test_outerProduct();
Error += test_transpose();
Error += test_determinant();
Error += test_inverse();
Error += test_inverse_simd();
# ifdef NDEBUG
std::size_t const Samples = 1000;
# else
std::size_t const Samples = 1;
# endif//NDEBUG
for(std::size_t i = 0; i < 1; ++i)
{
Error += test_inverse_perf<glm::vec3, glm::mat4>(Samples, i, "mat4");
Error += test_inverse_perf<glm::dvec3, glm::dmat4>(Samples, i, "dmat4");
}
return Error;
}

View File

@@ -0,0 +1,7 @@
int main()
{
int Error = 0;
return Error;
}

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>
int test_packUnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.0f));
A.push_back(glm::vec2(0.5f, 0.7f));
A.push_back(glm::vec2(0.1f, 0.2f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packUnorm2x16(B);
glm::vec2 D = glm::unpackUnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 0.0f));
A.push_back(glm::vec2(-0.5f,-0.7f));
A.push_back(glm::vec2(-0.1f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packSnorm2x16(B);
glm::vec2 D = glm::unpackSnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm4x8()
{
int Error = 0;
glm::uint32 Packed = glm::packUnorm4x8(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f));
glm::u8vec4 Vec(255, 128, 0, 255);
glm::uint32 & Ref = *reinterpret_cast<glm::uint32*>(&Vec[0]);
Error += Packed == Ref ? 0 : 1;
std::vector<glm::vec4> A;
A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint32 C = glm::packUnorm4x8(B);
glm::vec4 D = glm::unpackUnorm4x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm4x8()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint32 C = glm::packSnorm4x8(B);
glm::vec4 D = glm::unpackSnorm4x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packHalf2x16()
{
int Error = 0;
/*
std::vector<glm::hvec2> A;
A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 2.0f)));
A.push_back(glm::hvec2(glm::half(-1.0f), glm::half(-2.0f)));
A.push_back(glm::hvec2(glm::half(-1.1f), glm::half( 1.1f)));
*/
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 2.0f));
A.push_back(glm::vec2(-1.0f,-2.0f));
A.push_back(glm::vec2(-1.1f, 1.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint C = glm::packHalf2x16(B);
glm::vec2 D = glm::unpackHalf2x16(C);
//Error += B == D ? 0 : 1;
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packDouble2x32()
{
int Error = 0;
std::vector<glm::uvec2> A;
A.push_back(glm::uvec2( 1, 2));
A.push_back(glm::uvec2(-1,-2));
A.push_back(glm::uvec2(-1000, 1100));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::uvec2 B(A[i]);
double C = glm::packDouble2x32(B);
glm::uvec2 D = glm::unpackDouble2x32(C);
Error += B == D ? 0 : 1;
assert(!Error);
}
return Error;
}
int main()
{
int Error = 0;
Error += test_packSnorm4x8();
Error += test_packUnorm4x8();
Error += test_packSnorm2x16();
Error += test_packUnorm2x16();
Error += test_packHalf2x16();
Error += test_packDouble2x32();
return Error;
}

View File

@@ -0,0 +1,83 @@
#define GLM_FORCE_MESSAGES
#define GLM_FORCE_SWIZZLE
#include <glm/glm.hpp>
#if !GLM_HAS_ONLY_XYZW
int test_ivec2_swizzle()
{
int Error = 0;
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;
return Error;
}
int test_ivec3_swizzle()
{
int Error = 0;
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;
return Error;
}
int test_ivec4_swizzle()
{
int Error = 0;
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;
return Error;
}
int test_vec4_swizzle()
{
int Error = 0;
glm::vec4 A(1, 2, 3, 4);
glm::vec4 B = A.wzyx();
glm::vec4 C = B.wzyx();
Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1;
float f = glm::dot(C.wzyx(), C.xyzw());
Error += glm::abs(f - 20.f) < 0.01f ? 0 : 1;
return Error;
}
#endif//!GLM_HAS_ONLY_XYZW
int main()
{
int Error = 0;
# if !GLM_HAS_ONLY_XYZW
Error += test_ivec2_swizzle();
Error += test_ivec3_swizzle();
Error += test_ivec4_swizzle();
Error += test_vec4_swizzle();
# endif//!GLM_HAS_ONLY_XYZW
return Error;
}

View File

@@ -0,0 +1,10 @@
#include <glm/trigonometric.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,42 @@
#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;
}
int main()
{
int Error(0);
Error += test_not();
return Error;
}

View File

@@ -0,0 +1,10 @@
#define GLM_FORCE_CXX98
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,230 @@
#define GLM_FORCE_MESSAGES
#include <glm/vec3.hpp>
#include <cstdio>
int test_compiler()
{
int Error(0);
if(GLM_COMPILER & GLM_COMPILER_VC)
{
switch(GLM_COMPILER)
{
case GLM_COMPILER_VC12:
std::printf("Visual C++ 12 - 2013\n");
break;
case GLM_COMPILER_VC14:
std::printf("Visual C++ 14 - 2015\n");
break;
case GLM_COMPILER_VC15:
std::printf("Visual C++ 15 - 2017\n");
break;
case GLM_COMPILER_VC16:
std::printf("Visual C++ 16 - 20XX\n");
break;
default:
std::printf("Visual C++ version not detected\n");
Error += 1;
break;
}
}
else if(GLM_COMPILER & GLM_COMPILER_GCC)
{
switch(GLM_COMPILER)
{
case GLM_COMPILER_GCC46:
std::printf("GCC 4.6\n");
break;
case GLM_COMPILER_GCC47:
std::printf("GCC 4.7\n");
break;
case GLM_COMPILER_GCC48:
std::printf("GCC 4.8\n");
break;
case GLM_COMPILER_GCC49:
std::printf("GCC 4.9\n");
break;
case GLM_COMPILER_GCC5:
std::printf("GCC 5\n");
break;
case GLM_COMPILER_GCC6:
std::printf("GCC 6\n");
break;
case GLM_COMPILER_GCC7:
std::printf("GCC 7\n");
break;
case GLM_COMPILER_GCC8:
std::printf("GCC 8\n");
break;
default:
std::printf("GCC version not detected\n");
Error += 1;
break;
}
}
else if(GLM_COMPILER & GLM_COMPILER_CUDA)
{
std::printf("CUDA\n");
}
else if(GLM_COMPILER & GLM_COMPILER_CLANG)
{
switch(GLM_COMPILER)
{
case GLM_COMPILER_CLANG34:
std::printf("Clang 3.4\n");
break;
case GLM_COMPILER_CLANG35:
std::printf("Clang 3.5\n");
break;
case GLM_COMPILER_CLANG36:
std::printf("Clang 3.6\n");
break;
case GLM_COMPILER_CLANG37:
std::printf("Clang 3.7\n");
break;
case GLM_COMPILER_CLANG38:
std::printf("Clang 3.8\n");
break;
case GLM_COMPILER_CLANG39:
std::printf("Clang 3.9\n");
break;
case GLM_COMPILER_CLANG40:
std::printf("Clang 4.0\n");
break;
case GLM_COMPILER_CLANG41:
std::printf("Clang 4.1\n");
break;
case GLM_COMPILER_CLANG42:
std::printf("Clang 4.2\n");
break;
default:
std::printf("LLVM version not detected\n");
break;
}
}
else if(GLM_COMPILER & GLM_COMPILER_INTEL)
{
switch(GLM_COMPILER)
{
case GLM_COMPILER_INTEL14:
std::printf("ICC 14 - 2013 SP1\n");
break;
case GLM_COMPILER_INTEL15:
std::printf("ICC 15 - 2015\n");
break;
case GLM_COMPILER_INTEL16:
std::printf("ICC 16 - 2017\n");
break;
case GLM_COMPILER_INTEL17:
std::printf("ICC 17 - 20XX\n");
break;
default:
std::printf("Intel compiler version not detected\n");
Error += 1;
break;
}
}
else
{
std::printf("Undetected compiler\n");
Error += 1;
}
return Error;
}
int test_model()
{
int Error = 0;
Error += ((sizeof(void*) == 4) && (GLM_MODEL == GLM_MODEL_32)) || ((sizeof(void*) == 8) && (GLM_MODEL == GLM_MODEL_64)) ? 0 : 1;
if(GLM_MODEL == GLM_MODEL_32)
std::printf("GLM_MODEL_32\n");
else if(GLM_MODEL == GLM_MODEL_64)
std::printf("GLM_MODEL_64\n");
return Error;
}
int test_instruction_set()
{
int Error = 0;
std::printf("GLM_ARCH: ");
if(GLM_ARCH == GLM_ARCH_PURE)
std::printf("GLM_ARCH_PURE ");
if(GLM_ARCH & GLM_ARCH_ARM_BIT)
std::printf("ARM ");
if(GLM_ARCH & GLM_ARCH_NEON_BIT)
std::printf("NEON ");
if(GLM_ARCH & GLM_ARCH_AVX2)
std::printf("AVX2 ");
if(GLM_ARCH & GLM_ARCH_AVX)
std::printf("AVX ");
if(GLM_ARCH & GLM_ARCH_SSE42_BIT)
std::printf("SSE4.2 ");
if(GLM_ARCH & GLM_ARCH_SSE41_BIT)
std::printf("SSE4.1 ");
if(GLM_ARCH & GLM_ARCH_SSSE3_BIT)
std::printf("SSSE3 ");
if(GLM_ARCH & GLM_ARCH_SSE3_BIT)
std::printf("SSE3 ");
if(GLM_ARCH & GLM_ARCH_SSE2_BIT)
std::printf("SSE2 ");
std::printf("\n");
return Error;
}
int test_cpp_version()
{
std::printf("__cplusplus: %d\n", static_cast<int>(__cplusplus));
return 0;
}
int test_operators()
{
glm::vec3 A(1.0f);
glm::vec3 B(1.0f);
bool R = A != B;
bool S = A == B;
return (S && !R) ? 0 : 1;
}
template<typename T>
struct vec
{
};
template<template<typename> class C, typename T>
struct Class
{
};
template<typename T>
struct Class<vec, T>
{
};
int main()
{
//Class<vec, float> C;
int Error = 0;
Error += test_cpp_version();
Error += test_compiler();
Error += test_model();
Error += test_instruction_set();
Error += test_operators();
return Error;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,128 @@
#include <glm/glm.hpp>
int test_aligned()
{
int Error = 0;
size_t size1_aligned = sizeof(glm::detail::storage<int, 1, true>::type);
Error += size1_aligned == 1 ? 0 : 1;
size_t size2_aligned = sizeof(glm::detail::storage<int, 2, true>::type);
Error += size2_aligned == 2 ? 0 : 1;
size_t size4_aligned = sizeof(glm::detail::storage<int, 4, true>::type);
Error += size4_aligned == 4 ? 0 : 1;
size_t size8_aligned = sizeof(glm::detail::storage<int, 8, true>::type);
Error += size8_aligned == 8 ? 0 : 1;
size_t size16_aligned = sizeof(glm::detail::storage<int, 16, true>::type);
Error += size16_aligned == 16 ? 0 : 1;
size_t size32_aligned = sizeof(glm::detail::storage<int, 32, true>::type);
Error += size32_aligned == 32 ? 0 : 1;
size_t size64_aligned = sizeof(glm::detail::storage<int, 64, true>::type);
Error += size64_aligned == 64 ? 0 : 1;
# if GLM_HAS_ALIGNOF
size_t align1_aligned = alignof(glm::detail::storage<int, 1, true>::type);
Error += align1_aligned == 1 ? 0 : 1;
size_t align2_aligned = alignof(glm::detail::storage<int, 2, true>::type);
Error += align2_aligned == 2 ? 0 : 1;
size_t align4_aligned = alignof(glm::detail::storage<int, 4, true>::type);
Error += align4_aligned == 4 ? 0 : 1;
size_t align8_aligned = alignof(glm::detail::storage<int, 8, true>::type);
Error += align8_aligned == 8 ? 0 : 1;
size_t align16_aligned = alignof(glm::detail::storage<int, 16, true>::type);
Error += align16_aligned == 16 ? 0 : 1;
size_t align32_aligned = alignof(glm::detail::storage<int, 32, true>::type);
Error += align32_aligned == 32 ? 0 : 1;
size_t align64_aligned = alignof(glm::detail::storage<int, 64, true>::type);
Error += align64_aligned == 64 ? 0 : 1;
# elif GLM_COMPILER & GLM_COMPILER_GCC
size_t align1_aligned = __alignof__(glm::detail::storage<int, 1, true>::type);
Error += align1_aligned == 1 ? 0 : 1;
size_t align2_aligned = __alignof__(glm::detail::storage<int, 2, true>::type);
Error += align2_aligned == 2 ? 0 : 1;
size_t align4_aligned = __alignof__(glm::detail::storage<int, 4, true>::type);
Error += align4_aligned == 4 ? 0 : 1;
size_t align8_aligned = __alignof__(glm::detail::storage<int, 8, true>::type);
Error += align8_aligned == 8 ? 0 : 1;
size_t align16_aligned = __alignof__(glm::detail::storage<int, 16, true>::type);
Error += align16_aligned == 16 ? 0 : 1;
size_t align32_aligned = __alignof__(glm::detail::storage<int, 32, true>::type);
Error += align32_aligned == 32 ? 0 : 1;
size_t align64_aligned = __alignof__(glm::detail::storage<int, 64, true>::type);
Error += align64_aligned == 64 ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
return Error;
}
int test_unaligned()
{
int Error = 0;
size_t size1_unaligned = sizeof(glm::detail::storage<int, 1, false>::type);
Error += size1_unaligned == 1 ? 0 : 1;
size_t size2_unaligned = sizeof(glm::detail::storage<int, 2, false>::type);
Error += size2_unaligned == 2 ? 0 : 1;
size_t size4_unaligned = sizeof(glm::detail::storage<int, 4, false>::type);
Error += size4_unaligned == 4 ? 0 : 1;
size_t size8_unaligned = sizeof(glm::detail::storage<int, 8, false>::type);
Error += size8_unaligned == 8 ? 0 : 1;
size_t size16_unaligned = sizeof(glm::detail::storage<int, 16, false>::type);
Error += size16_unaligned == 16 ? 0 : 1;
size_t size32_unaligned = sizeof(glm::detail::storage<int, 32, false>::type);
Error += size32_unaligned == 32 ? 0 : 1;
size_t size64_unaligned = sizeof(glm::detail::storage<int, 64, false>::type);
Error += size64_unaligned == 64 ? 0 : 1;
# if GLM_HAS_ALIGNOF
size_t align1_unaligned = alignof(glm::detail::storage<int, 1, false>::type);
Error += align1_unaligned == 1 ? 0 : 1;
size_t align2_unaligned = alignof(glm::detail::storage<int, 2, false>::type);
Error += align2_unaligned == 1 ? 0 : 1;
size_t align4_unaligned = alignof(glm::detail::storage<int, 4, false>::type);
Error += align4_unaligned == 1 ? 0 : 1;
size_t align8_unaligned = alignof(glm::detail::storage<int, 8, false>::type);
Error += align8_unaligned == 1 ? 0 : 1;
size_t align16_unaligned = alignof(glm::detail::storage<int, 16, false>::type);
Error += align16_unaligned == 1 ? 0 : 1;
size_t align32_unaligned = alignof(glm::detail::storage<int, 32, false>::type);
Error += align32_unaligned == 1 ? 0 : 1;
size_t align64_unaligned = alignof(glm::detail::storage<int, 64, false>::type);
Error += align64_unaligned == 1 ? 0 : 1;
# elif GLM_COMPILER & GLM_COMPILER_GCC
size_t align1_unaligned = __alignof__(glm::detail::storage<int, 1, false>::type);
Error += align1_unaligned == 1 ? 0 : 1;
size_t align2_unaligned = __alignof__(glm::detail::storage<int, 2, false>::type);
Error += align2_unaligned == 1 ? 0 : 1;
size_t align4_unaligned = __alignof__(glm::detail::storage<int, 4, false>::type);
Error += align4_unaligned == 1 ? 0 : 1;
size_t align8_unaligned = __alignof__(glm::detail::storage<int, 8, false>::type);
Error += align8_unaligned == 1 ? 0 : 1;
size_t align16_unaligned = __alignof__(glm::detail::storage<int, 16, false>::type);
Error += align16_unaligned == 1 ? 0 : 1;
size_t align32_unaligned = __alignof__(glm::detail::storage<int, 32, false>::type);
Error += align32_unaligned == 1 ? 0 : 1;
size_t align64_unaligned = __alignof__(glm::detail::storage<int, 64, false>::type);
Error += align64_unaligned == 1 ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
return Error;
}
int main()
{
int Error = 0;
Error += test_aligned();
Error += test_unaligned();
return Error;
}

View File

@@ -0,0 +1,144 @@
#include <glm/glm.hpp>
#include <algorithm>
#include <vector>
#include <iterator>
struct my_vec2
{
operator glm::vec2() { return glm::vec2(x, y); }
float x, y;
};
int test_vec2_cast()
{
glm::vec2 A(1.0f, 2.0f);
glm::lowp_vec2 B(A);
glm::mediump_vec2 C(A);
glm::highp_vec2 D(A);
glm::vec2 E = static_cast<glm::vec2>(A);
glm::lowp_vec2 F = static_cast<glm::lowp_vec2>(A);
glm::mediump_vec2 G = static_cast<glm::mediump_vec2>(A);
glm::highp_vec2 H = static_cast<glm::highp_vec2>(A);
my_vec2 I;
glm::vec2 J = static_cast<glm::vec2>(I);
glm::vec2 K(7.8f);
int Error(0);
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(B, F)) ? 0 : 1;
Error += glm::all(glm::equal(C, G)) ? 0 : 1;
Error += glm::all(glm::equal(D, H)) ? 0 : 1;
return Error;
}
int test_vec3_cast()
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::lowp_vec3 B(A);
glm::mediump_vec3 C(A);
glm::highp_vec3 D(A);
glm::vec3 E = static_cast<glm::vec3>(A);
glm::lowp_vec3 F = static_cast<glm::lowp_vec3>(A);
glm::mediump_vec3 G = static_cast<glm::mediump_vec3>(A);
glm::highp_vec3 H = static_cast<glm::highp_vec3>(A);
int Error(0);
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(B, F)) ? 0 : 1;
Error += glm::all(glm::equal(C, G)) ? 0 : 1;
Error += glm::all(glm::equal(D, H)) ? 0 : 1;
return Error;
}
int test_vec4_cast()
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::lowp_vec4 B(A);
glm::mediump_vec4 C(A);
glm::highp_vec4 D(A);
glm::vec4 E = static_cast<glm::vec4>(A);
glm::lowp_vec4 F = static_cast<glm::lowp_vec4>(A);
glm::mediump_vec4 G = static_cast<glm::mediump_vec4>(A);
glm::highp_vec4 H = static_cast<glm::highp_vec4>(A);
int Error(0);
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(B, F)) ? 0 : 1;
Error += glm::all(glm::equal(C, G)) ? 0 : 1;
Error += glm::all(glm::equal(D, H)) ? 0 : 1;
return Error;
}
int test_std_copy()
{
int Error = 0;
{
std::vector<int> High;
High.resize(64);
std::vector<int> Medium(High.size());
std::copy(High.begin(), High.end(), Medium.begin());
*Medium.begin() = *High.begin();
}
{
std::vector<glm::dvec4> High4;
High4.resize(64);
std::vector<glm::vec4> Medium4(High4.size());
std::copy(High4.begin(), High4.end(), Medium4.begin());
*Medium4.begin() = *High4.begin();
}
{
std::vector<glm::dvec3> High3;
High3.resize(64);
std::vector<glm::vec3> Medium3(High3.size());
std::copy(High3.begin(), High3.end(), Medium3.begin());
*Medium3.begin() = *High3.begin();
}
{
std::vector<glm::dvec2> High2;
High2.resize(64);
std::vector<glm::vec2> Medium2(High2.size());
std::copy(High2.begin(), High2.end(), Medium2.begin());
*Medium2.begin() = *High2.begin();
}
glm::dvec4 v1;
glm::vec4 v2;
v2 = v1;
return Error;
}
int main()
{
int Error = 0;
Error += test_std_copy();
Error += test_vec2_cast();
Error += test_vec3_cast();
Error += test_vec4_cast();
return Error;
}

View File

@@ -0,0 +1,349 @@
#include <glm/glm.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/quaternion.hpp>
static int test_vec1_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_vec2_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_vec3_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_vec4_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat2x2_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat2x2(1);
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat2x3_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat2x3(1);
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat2x4_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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)) ? 0 : 1;
B.f = glm::mat2x4(1);
glm::vec4 const D(1, 0, 0, 0);
Error += glm::all(glm::equal(B.i[0], D)) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat3x2_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat3x2(1);
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat3x3_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat3x3(1);
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat3x4_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat3x4(1);
Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat4x2_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat4x2(1);
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat4x3_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat4x3(1);
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_mat4x4_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::mat4(1);
Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
return Error;
}
static int test_quat_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS
{
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))) ? 0 : 1;
B.f = glm::quat(1, 1, 1, 1);
Error += glm::all(glm::equal(B.i, glm::quat(1, 1, 1, 1))) ? 0 : 1;
}
# endif//GLM_HAS_DEFAULTED_FUNCTIONS
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;
}

View File

@@ -0,0 +1,31 @@
#include <glm/glm.hpp>
int test_float_size()
{
return
sizeof(glm::float_t) != sizeof(glm::lowp_float) &&
sizeof(glm::float_t) != sizeof(glm::mediump_float) &&
sizeof(glm::float_t) != sizeof(glm::highp_float);
}
int test_float_precision()
{
return (
sizeof(glm::lowp_float) <= sizeof(glm::mediump_float) &&
sizeof(glm::mediump_float) <= sizeof(glm::highp_float)) ? 0 : 1;
}
int test_vec2()
{
return 0;
}
int main()
{
int Error = 0;
Error += test_float_size();
Error += test_float_precision();
return Error;
}

View File

@@ -0,0 +1,59 @@
#include <glm/glm.hpp>
static int test_int_size()
{
return
sizeof(glm::int_t) != sizeof(glm::lowp_int) &&
sizeof(glm::int_t) != sizeof(glm::mediump_int) &&
sizeof(glm::int_t) != sizeof(glm::highp_int);
}
static int test_uint_size()
{
return
sizeof(glm::uint_t) != sizeof(glm::lowp_uint) &&
sizeof(glm::uint_t) != sizeof(glm::mediump_uint) &&
sizeof(glm::uint_t) != sizeof(glm::highp_uint);
}
static int test_int_precision()
{
return (
sizeof(glm::lowp_int) <= sizeof(glm::mediump_int) &&
sizeof(glm::mediump_int) <= sizeof(glm::highp_int)) ? 0 : 1;
}
static int test_uint_precision()
{
return (
sizeof(glm::lowp_uint) <= sizeof(glm::mediump_uint) &&
sizeof(glm::mediump_uint) <= sizeof(glm::highp_uint)) ? 0 : 1;
}
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_int_size();
Error += test_int_precision();
Error += test_uint_size();
Error += test_uint_precision();
Error += test_bit_operator();
return Error;
}

View File

@@ -0,0 +1,79 @@
#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;
}

View File

@@ -0,0 +1,160 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/matrix.hpp>
#include <glm/vector_relational.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat2x3.hpp>
#include <glm/mat2x4.hpp>
#include <glm/mat3x2.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat3x4.hpp>
#include <glm/mat4x2.hpp>
#include <glm/mat4x3.hpp>
#include <glm/mat4x4.hpp>
#include <vector>
int test_operators()
{
glm::mat2x2 l(1.0f);
glm::mat2x2 m(1.0f);
glm::vec2 u(1.0f);
glm::vec2 v(1.0f);
float x = 1.0f;
glm::vec2 a = m * u;
glm::vec2 b = v * m;
glm::mat2x2 n = x / m;
glm::mat2x2 o = m / x;
glm::mat2x2 p = x * m;
glm::mat2x2 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_inverse()
{
int Error(0);
{
glm::mat2 const Matrix(1, 2, 3, 4);
glm::mat2 const Inverse = glm::inverse(Matrix);
glm::mat2 const Identity = Matrix * Inverse;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1;
}
return Error;
}
int test_ctr()
{
int Error(0);
#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}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat2x2> v1{
{0, 1, 2, 3},
{0, 1, 2, 3}
};
std::vector<glm::mat2x2> v2{
{
{ 0, 1},
{ 4, 5}
},
{
{ 0, 1},
{ 4, 5}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat2 B(A);
glm::mat2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 16 == sizeof(glm::mat2x2) ? 0 : 1;
Error += 32 == sizeof(glm::dmat2x2) ? 0 : 1;
Error += glm::mat2x2().length() == 2 ? 0 : 1;
Error += glm::dmat2x2().length() == 2 ? 0 : 1;
Error += glm::mat2x2::length() == 2 ? 0 : 1;
Error += glm::dmat2x2::length() == 2 ? 0 : 1;
return Error;
}
int main()
{
int Error(0);
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_inverse();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,133 @@
#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()
{
glm::mat2x3 l(1.0f);
glm::mat2x3 m(1.0f);
glm::vec2 u(1.0f);
glm::vec3 v(1.0f);
float x = 1.0f;
glm::vec3 a = m * u;
glm::vec2 b = v * m;
glm::mat2x3 n = x / m;
glm::mat2x3 o = m / x;
glm::mat2x3 p = x * m;
glm::mat2x3 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if GLM_HAS_INITIALIZER_LISTS
glm::mat2x3 m0(
glm::vec3(0, 1, 2),
glm::vec3(3, 4, 5));
glm::mat2x3 m1{0, 1, 2, 3, 4, 5};
glm::mat2x3 m2{
{0, 1, 2},
{3, 4, 5}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat2x3> v1{
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5}
};
std::vector<glm::mat2x3> v2{
{
{ 0, 1, 2},
{ 4, 5, 6}
},
{
{ 0, 1, 2},
{ 4, 5, 6}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat2x3 B(A);
glm::mat2x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 24 == sizeof(glm::mat2x3) ? 0 : 1;
Error += 48 == sizeof(glm::dmat2x3) ? 0 : 1;
Error += glm::mat2x3().length() == 2 ? 0 : 1;
Error += glm::dmat2x3().length() == 2 ? 0 : 1;
Error += glm::mat2x3::length() == 2 ? 0 : 1;
Error += glm::dmat2x3::length() == 2 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,138 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.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()
{
glm::mat2x4 l(1.0f);
glm::mat2x4 m(1.0f);
glm::vec2 u(1.0f);
glm::vec4 v(1.0f);
float x = 1.0f;
glm::vec4 a = m * u;
glm::vec2 b = v * m;
glm::mat2x4 n = x / m;
glm::mat2x4 o = m / x;
glm::mat2x4 p = x * m;
glm::mat2x4 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if(GLM_HAS_INITIALIZER_LISTS)
glm::mat2x4 m0(
glm::vec4(0, 1, 2, 3),
glm::vec4(4, 5, 6, 7));
glm::mat2x4 m1{0, 1, 2, 3, 4, 5, 6, 7};
glm::mat2x4 m2{
{0, 1, 2, 3},
{4, 5, 6, 7}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat2x4> v1{
{0, 1, 2, 3, 4, 5, 6, 7},
{0, 1, 2, 3, 4, 5, 6, 7}
};
std::vector<glm::mat2x4> v2{
{
{ 0, 1, 2, 3},
{ 4, 5, 6, 7}
},
{
{ 0, 1, 2, 3},
{ 4, 5, 6, 7}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat2x4 B(A);
glm::mat2x4 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,139 @@
#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 bool test_operators()
{
glm::mat3x2 l(1.0f);
glm::mat3x2 m(1.0f);
glm::vec3 u(1.0f);
glm::vec2 v(1.0f);
float x = 1.0f;
glm::vec2 a = m * u;
glm::vec3 b = v * m;
glm::mat3x2 n = x / m;
glm::mat3x2 o = m / x;
glm::mat3x2 p = x * m;
glm::mat3x2 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if(GLM_HAS_INITIALIZER_LISTS)
glm::mat3x2 m0(
glm::vec2(0, 1),
glm::vec2(2, 3),
glm::vec2(4, 5));
glm::mat3x2 m1{0, 1, 2, 3, 4, 5};
glm::mat3x2 m2{
{0, 1},
{2, 3},
{4, 5}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat3x2> v1{
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5}
};
std::vector<glm::mat3x2> v2{
{
{ 0, 1},
{ 2, 3},
{ 4, 5}
},
{
{ 0, 1},
{ 2, 3},
{ 4, 5}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat3x2 B(A);
glm::mat3x2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 24 == sizeof(glm::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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,199 @@
#include <glm/gtc/epsilon.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 <cstdio>
#include <vector>
void print(glm::dmat3 const& Mat0)
{
printf("mat3(\n");
printf("\tvec3(%2.3f, %2.3f, %2.3f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2]);
printf("\tvec3(%2.3f, %2.3f, %2.3f)\n", Mat0[1][0], Mat0[1][1], Mat0[1][2]);
printf("\tvec3(%2.3f, %2.3f, %2.3f))\n\n", Mat0[2][0], Mat0[2][1], Mat0[2][2]);
}
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;
print(Mat0);
print(Inv0);
print(Res0);
return 0;
}
static int test_operators()
{
glm::mat3x3 l(1.0f);
glm::mat3x3 m(1.0f);
glm::vec3 u(1.0f);
glm::vec3 v(1.0f);
float x = 1.0f;
glm::vec3 a = m * u;
glm::vec3 b = v * m;
glm::mat3x3 n = x / m;
glm::mat3x3 o = m / x;
glm::mat3x3 p = x * m;
glm::mat3x3 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
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::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
}
return Error;
}
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}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat3x3> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8},
{0, 1, 2, 3, 4, 5, 6, 7, 8}
};
std::vector<glm::mat3x3> v2{
{
{ 0, 1, 2},
{ 3, 4, 5},
{ 6, 7, 8}
},
{
{ 0, 1, 2},
{ 3, 4, 5},
{ 6, 7, 8}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat3x3 B(A);
glm::mat3x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_mat3x3();
Error += test_operators();
Error += test_inverse();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,140 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.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 bool test_operators()
{
glm::mat3x4 l(1.0f);
glm::mat3x4 m(1.0f);
glm::vec3 u(1.0f);
glm::vec4 v(1.0f);
float x = 1.0f;
glm::vec4 a = m * u;
glm::vec3 b = v * m;
glm::mat3x4 n = x / m;
glm::mat3x4 o = m / x;
glm::mat3x4 p = x * m;
glm::mat3x4 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if(GLM_HAS_INITIALIZER_LISTS)
glm::mat3x4 m0(
glm::vec4(0, 1, 2, 3),
glm::vec4(4, 5, 6, 7),
glm::vec4(8, 9, 10, 11));
glm::mat3x4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
glm::mat3x4 m2{
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat3x4> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
};
std::vector<glm::mat3x4> v2{
{
{ 0, 1, 2, 3},
{ 4, 5, 6, 7},
{ 8, 9, 10, 11}
},
{
{ 0, 1, 2, 3},
{ 4, 5, 6, 7},
{ 8, 9, 10, 11}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat3x4 B(A);
glm::mat3x4 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,142 @@
#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()
{
glm::mat4x2 l(1.0f);
glm::mat4x2 m(1.0f);
glm::vec4 u(1.0f);
glm::vec2 v(1.0f);
float x = 1.0f;
glm::vec2 a = m * u;
glm::vec4 b = v * m;
glm::mat4x2 n = x / m;
glm::mat4x2 o = m / x;
glm::mat4x2 p = x * m;
glm::mat4x2 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if(GLM_HAS_INITIALIZER_LISTS)
glm::mat4x2 m0(
glm::vec2(0, 1),
glm::vec2(2, 3),
glm::vec2(4, 5),
glm::vec2(6, 7));
glm::mat4x2 m1{0, 1, 2, 3, 4, 5, 6, 7};
glm::mat4x2 m2{
{0, 1},
{2, 3},
{4, 5},
{6, 7}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat4x2> v1{
{0, 1, 2, 3, 4, 5, 6, 7},
{0, 1, 2, 3, 4, 5, 6, 7}
};
std::vector<glm::mat4x2> v2{
{
{ 0, 1},
{ 4, 5},
{ 8, 9},
{ 12, 13}
},
{
{ 0, 1},
{ 4, 5},
{ 8, 9},
{ 12, 13}
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat4x2 B(A);
glm::mat4x2 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,143 @@
#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()
{
glm::mat4x3 l(1.0f);
glm::mat4x3 m(1.0f);
glm::vec4 u(1.0f);
glm::vec3 v(1.0f);
float x = 1.0f;
glm::vec3 a = m * u;
glm::vec4 b = v * m;
glm::mat4x3 n = x / m;
glm::mat4x3 o = m / x;
glm::mat4x3 p = x * m;
glm::mat4x3 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_ctr()
{
int Error(0);
#if(GLM_HAS_INITIALIZER_LISTS)
glm::mat4x3 m0(
glm::vec3(0, 1, 2),
glm::vec3(3, 4, 5),
glm::vec3(6, 7, 8),
glm::vec3(9, 10, 11));
glm::mat4x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
glm::mat4x3 m2{
{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 10, 11}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat4x3> v1{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
};
std::vector<glm::mat4x3> v2{
{
{ 0, 1, 2 },
{ 4, 5, 6 },
{ 8, 9, 10 },
{ 12, 13, 14 }
},
{
{ 0, 1, 2 },
{ 4, 5, 6 },
{ 8, 9, 10 },
{ 12, 13, 14 }
}
};
#endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat4x3 B(A);
glm::mat4x3 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::equal(B[i], Identity[i])) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
int test_size()
{
int Error = 0;
Error += 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;
}
int main()
{
int Error = 0;
Error += cast::test();
Error += test_ctr();
Error += test_operators();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,339 @@
#include <glm/gtc/constants.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/matrix.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 <cstdio>
#include <vector>
template<typename genType>
void print(genType const& Mat0)
{
printf("mat4(\n");
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[0][0]), static_cast<double>(Mat0[0][1]), static_cast<double>(Mat0[0][2]), static_cast<double>(Mat0[0][3]));
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[1][0]), static_cast<double>(Mat0[1][1]), static_cast<double>(Mat0[1][2]), static_cast<double>(Mat0[1][3]));
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[2][0]), static_cast<double>(Mat0[2][1]), static_cast<double>(Mat0[2][2]), static_cast<double>(Mat0[2][3]));
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f))\n\n", static_cast<double>(Mat0[3][0]), static_cast<double>(Mat0[3][1]), static_cast<double>(Mat0[3][2]), static_cast<double>(Mat0[3][3]));
}
int test_inverse_mat4x4()
{
glm::mat4 Mat0(
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));
glm::mat4 Inv0 = glm::inverse(Mat0);
glm::mat4 Res0 = Mat0 * Inv0;
print(Mat0);
print(Inv0);
print(Res0);
return 0;
}
int test_inverse_dmat4x4()
{
glm::dmat4 Mat0(
glm::dvec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::dvec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::dvec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::dvec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::dmat4 Inv0 = glm::inverse(Mat0);
glm::dmat4 Res0 = Mat0 * Inv0;
print(Mat0);
print(Inv0);
print(Res0);
return 0;
}
static bool test_operators()
{
glm::mat4x4 l(1.0f);
glm::mat4x4 m(1.0f);
glm::vec4 u(1.0f);
glm::vec4 v(1.0f);
float x = 1.0f;
glm::vec4 a = m * u;
glm::vec4 b = v * m;
glm::mat4x4 n = x / m;
glm::mat4x4 o = m / x;
glm::mat4x4 p = x * m;
glm::mat4x4 q = m * x;
bool R = m != q;
bool S = m == l;
return (S && !R) ? 0 : 1;
}
int test_inverse()
{
int Error(0);
{
glm::mat4 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));
glm::mat4 const Inverse = glm::inverse(Matrix);
glm::mat4 const Identity = Matrix * Inverse;
print(Matrix);
print(Inverse);
print(Identity);
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::vec4(0.01f))) ? 0 : 1;
}
{
glm::highp_mat4 const Matrix(
glm::highp_vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::highp_vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::highp_vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::highp_vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::highp_mat4 const Inverse = glm::inverse(Matrix);
glm::highp_mat4 const Identity = Matrix * Inverse;
printf("highp_mat4 inverse\n");
print(Matrix);
print(Inverse);
print(Identity);
Error += glm::all(glm::epsilonEqual(Identity[0], glm::highp_vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::highp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::highp_vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::highp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::highp_vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::highp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::highp_vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::highp_vec4(0.01f))) ? 0 : 1;
}
{
glm::mediump_mat4 const Matrix(
glm::mediump_vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::mediump_vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::mediump_vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::mediump_vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::mediump_mat4 const Inverse = glm::inverse(Matrix);
glm::mediump_mat4 const Identity = Matrix * Inverse;
printf("mediump_mat4 inverse\n");
print(Matrix);
print(Inverse);
print(Identity);
Error += glm::all(glm::epsilonEqual(Identity[0], glm::mediump_vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::mediump_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::mediump_vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::mediump_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::mediump_vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::mediump_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::mediump_vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::mediump_vec4(0.01f))) ? 0 : 1;
}
{
glm::lowp_mat4 const Matrix(
glm::lowp_vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::lowp_vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::lowp_vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::lowp_vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::lowp_mat4 const Inverse = glm::inverse(Matrix);
glm::lowp_mat4 const Identity = Matrix * Inverse;
printf("lowp_mat4 inverse\n");
print(Matrix);
print(Inverse);
print(Identity);
Error += glm::all(glm::epsilonEqual(Identity[0], glm::lowp_vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::lowp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::lowp_vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::lowp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::lowp_vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::lowp_vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::lowp_vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::lowp_vec4(0.01f))) ? 0 : 1;
}
{
glm::mat4 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));
glm::mat4 const Identity = Matrix / Matrix;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::vec4(0.01f))) ? 0 : 1;
}
return Error;
}
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 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 V{0, 1, 2, 3};
glm::mat4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
glm::mat4 m2{
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11},
{12, 13, 14, 15}};
for(glm::length_t i = 0; i < m0.length(); ++i)
Error += glm::all(glm::equal(m0[i], m2[i])) ? 0 : 1;
for(glm::length_t i = 0; i < m1.length(); ++i)
Error += glm::all(glm::equal(m1[i], m2[i])) ? 0 : 1;
std::vector<glm::mat4> 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 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> 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> 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;
}
int perf_mul()
{
int Error = 0;
return Error;
}
namespace cast
{
template<typename genType>
int entry()
{
int Error = 0;
genType A(1.0f);
glm::mat4x4 B(A);
glm::mat4x4 Identity(1.0f);
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1;
return Error;
}
int test()
{
int Error = 0;
Error += entry<glm::mat2x2>();
Error += entry<glm::mat2x3>();
Error += entry<glm::mat2x4>();
Error += entry<glm::mat3x2>();
Error += entry<glm::mat3x3>();
Error += entry<glm::mat3x4>();
Error += entry<glm::mat4x2>();
Error += entry<glm::mat4x3>();
Error += entry<glm::mat4x4>();
return Error;
}
}//namespace cast
struct repro
{
repro(){ this->matrix = new glm::mat4(); }
~repro(){delete this->matrix;}
glm::mat4* matrix;
};
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;
}
int main()
{
int Error = 0;
repro Repro;
Error += cast::test();
Error += test_ctr();
Error += test_inverse_dmat4x4();
Error += test_inverse_mat4x4();
Error += test_operators();
Error += test_inverse();
Error += test_size();
Error += perf_mul();
return Error;
}

View File

@@ -0,0 +1,155 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/vec2.hpp>
#include <vector>
static glm::vec1 g1;
static glm::vec1 g2(1);
int test_vec1_operators()
{
int Error(0);
glm::vec1 A(1.0f);
glm::vec1 B(1.0f);
{
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
A *= 1.0f;
B *= 1.0;
A += 1.0f;
B += 1.0;
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
return Error;
}
int test_vec1_ctor()
{
int Error = 0;
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
# endif
/*
#if GLM_HAS_INITIALIZER_LISTS
{
glm::vec1 a{ 0 };
std::vector<glm::vec1> v = {
{0.f},
{4.f},
{8.f}};
}
{
glm::dvec2 a{ 0 };
std::vector<glm::dvec1> v = {
{0.0},
{4.0},
{8.0}};
}
#endif
*/
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
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 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
glm::vec2 C = glm::vec2(2.0f, 3.0);
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
glm::vec2 F(glm::ivec2(2));
}
return Error;
}
int test_vec1_size()
{
int Error = 0;
Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
Error += glm::vec1().length() == 1 ? 0 : 1;
Error += glm::dvec1().length() == 1 ? 0 : 1;
Error += glm::vec1::length() == 1 ? 0 : 1;
Error += glm::dvec1::length() == 1 ? 0 : 1;
# if GLM_HAS_CONSTEXPR_PARTIAL
constexpr std::size_t Length = glm::vec1::length();
Error += Length == 1 ? 0 : 1;
# endif
return Error;
}
int test_vec1_operator_increment()
{
int Error(0);
glm::ivec1 v0(1);
glm::ivec1 v1(v0);
glm::ivec1 v2(v0);
glm::ivec1 v3 = ++v1;
glm::ivec1 v4 = v2++;
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
int i0(1);
int i1(i0);
int i2(i0);
int i3 = ++i1;
int i4 = i2++;
Error += i0 == i4 ? 0 : 1;
Error += i1 == i2 ? 0 : 1;
Error += i1 == i3 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_vec1_size();
Error += test_vec1_ctor();
Error += test_vec1_operators();
Error += test_vec1_operator_increment();
return Error;
}

View File

@@ -0,0 +1,321 @@
#define GLM_FORCE_SWIZZLE
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <vector>
#if GLM_HAS_TRIVIAL_QUERIES
# include <type_traits>
#endif
static glm::vec2 g1;
static glm::vec2 g2(1);
static glm::vec2 g3(1, 1);
int test_vec2_operators()
{
int Error = 0;
{
glm::vec2 A(1.0f);
glm::vec2 B(1.0f);
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::epsilonEqual(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::vec2(3.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::vec2(0.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::vec2(-1.0f, 2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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::epsilonEqual(A, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(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 += C == glm::vec2(5, 7) ? 0 : 1;
glm::vec2 D = B - A;
Error += D == glm::vec2(3, 3) ? 0 : 1;
glm::vec2 E = A * B;
Error += E == glm::vec2(4, 10) ? 0 : 1;
glm::vec2 F = B / A;
Error += F == glm::vec2(4, 2.5) ? 0 : 1;
glm::vec2 G = A + 1.0f;
Error += G == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 H = B - 1.0f;
Error += H == glm::vec2(3, 4) ? 0 : 1;
glm::vec2 I = A * 2.0f;
Error += I == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 J = B / 2.0f;
Error += J == glm::vec2(2, 2.5) ? 0 : 1;
glm::vec2 K = 1.0f + A;
Error += K == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 L = 1.0f - B;
Error += L == glm::vec2(-3, -4) ? 0 : 1;
glm::vec2 M = 2.0f * A;
Error += M == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 N = 2.0f / B;
Error += N == glm::vec2(0.5, 2.0 / 5.0) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A += B;
Error += A == glm::vec2(5, 7) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec2(6, 8) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B -= A;
Error += B == glm::vec2(3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec2(2, 2) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A *= B;
Error += A == glm::vec2(4, 10) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec2(8, 20) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B /= A;
Error += B == glm::vec2(4, 2.5) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec2(2, 1.25) ? 0 : 1;
}
{
glm::vec2 B(2.0f);
B /= B.y;
Error += B == glm::vec2(1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = -A;
Error += B == glm::vec2(-1.0f, -2.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = --A;
Error += B == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A--;
Error += B == glm::vec2(1.0f, 2.0f) ? 0 : 1;
Error += A == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = ++A;
Error += B == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A++;
Error += B == glm::vec2(1.0f, 2.0f) ? 0 : 1;
Error += A == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
return Error;
}
int test_vec2_ctor()
{
int Error = 0;
{
glm::vec2 A(1);
glm::vec2 B(A);
Error += A == B ? 0 : 1;
}
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec2>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec2>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec2>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec2>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec2>::value ? 0 : 1;
# endif
#if GLM_HAS_INITIALIZER_LISTS
{
glm::vec2 a{ 0, 1 };
std::vector<glm::vec2> v = {
{0, 1},
{4, 5},
{8, 9}};
}
{
glm::dvec2 a{ 0, 1 };
std::vector<glm::dvec2> v = {
{0, 1},
{4, 5},
{8, 9}};
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
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 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
glm::vec2 C = glm::vec2(2.0f, 3.0);
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
glm::vec2 F(glm::ivec2(2));
}
return Error;
}
int test_vec2_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;
# if GLM_HAS_CONSTEXPR_PARTIAL
constexpr std::size_t Length = glm::vec2::length();
Error += Length == 2 ? 0 : 1;
# endif
return Error;
}
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;
}
int main()
{
int Error = 0;
Error += test_vec2_size();
Error += test_vec2_ctor();
Error += test_vec2_operators();
Error += test_operator_increment();
return Error;
}

View File

@@ -0,0 +1,523 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/geometric.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <cstdio>
#include <vector>
static glm::vec3 g1;
static glm::vec3 g2(1);
static glm::vec3 g3(1, 1, 1);
int test_vec3_ctor()
{
int Error = 0;
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec3>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec3>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec3>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec3>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec3>::value ? 0 : 1;
# endif
#if (GLM_HAS_INITIALIZER_LISTS)
{
glm::vec3 a{ 0, 1, 2 };
std::vector<glm::vec3> v = {
{0, 1, 2},
{4, 5, 6},
{8, 9, 0}};
}
{
glm::dvec3 a{ 0, 1, 2 };
std::vector<glm::dvec3> v = {
{0, 1, 2},
{4, 5, 6},
{8, 9, 0}};
}
#endif
#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))
{
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)) ? 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;
}
#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))
{
glm::vec3 A(1);
glm::vec3 B(1, 1, 1);
Error += A == B ? 0 : 1;
}
{
std::vector<glm::vec3> Tests;
Tests.push_back(glm::vec3(glm::vec2(1, 2), 3));
Tests.push_back(glm::vec3(1, glm::vec2(2, 3)));
Tests.push_back(glm::vec3(1, 2, 3));
Tests.push_back(glm::vec3(glm::vec4(1, 2, 3, 4)));
for(std::size_t i = 0; i < Tests.size(); ++i)
Error += Tests[i] == glm::vec3(1, 2, 3) ? 0 : 1;
}
return Error;
}
float foo()
{
glm::vec3 bar = glm::vec3(0.0f, 1.0f, 1.0f);
return glm::length(bar);
}
static int test_bvec3_ctor()
{
int Error = 0;
glm::bvec3 const A(true);
glm::bvec3 const B(true);
glm::bvec3 const C(false);
glm::bvec3 const D = A && B;
glm::bvec3 const E = A && C;
glm::bvec3 const F = A || C;
Error += D == glm::bvec3(true) ? 0 : 1;
Error += E == glm::bvec3(false) ? 0 : 1;
Error += F == glm::bvec3(true) ? 0 : 1;
bool const G = A == C;
bool const H = A != C;
Error += !G ? 0 : 1;
Error += H ? 0 : 1;
return Error;
}
static int test_vec3_operators()
{
int Error = 0;
{
glm::vec3 A(1.0f);
glm::vec3 B(1.0f);
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
glm::vec3 C = A + B;
Error += C == glm::vec3(5, 7, 9) ? 0 : 1;
glm::vec3 D = B - A;
Error += D == glm::vec3(3, 3, 3) ? 0 : 1;
glm::vec3 E = A * B;
Error += E == glm::vec3(4, 10, 18) ? 0 : 1;
glm::vec3 F = B / A;
Error += F == glm::vec3(4, 2.5, 2) ? 0 : 1;
glm::vec3 G = A + 1.0f;
Error += G == glm::vec3(2, 3, 4) ? 0 : 1;
glm::vec3 H = B - 1.0f;
Error += H == glm::vec3(3, 4, 5) ? 0 : 1;
glm::vec3 I = A * 2.0f;
Error += I == glm::vec3(2, 4, 6) ? 0 : 1;
glm::vec3 J = B / 2.0f;
Error += J == glm::vec3(2, 2.5, 3) ? 0 : 1;
glm::vec3 K = 1.0f + A;
Error += K == glm::vec3(2, 3, 4) ? 0 : 1;
glm::vec3 L = 1.0f - B;
Error += L == glm::vec3(-3, -4, -5) ? 0 : 1;
glm::vec3 M = 2.0f * A;
Error += M == glm::vec3(2, 4, 6) ? 0 : 1;
glm::vec3 N = 2.0f / B;
Error += N == glm::vec3(0.5, 2.0 / 5.0, 2.0 / 6.0) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
A += B;
Error += A == glm::vec3(5, 7, 9) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec3(6, 8, 10) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
B -= A;
Error += B == glm::vec3(3, 3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec3(2, 2, 2) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
A *= B;
Error += A == glm::vec3(4, 10, 18) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec3(8, 20, 36) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B(4.0f, 5.0f, 6.0f);
B /= A;
Error += B == glm::vec3(4, 2.5, 2) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec3(2, 1.25, 1) ? 0 : 1;
}
{
glm::vec3 B(2.0f);
B /= B.y;
Error += B == glm::vec3(1.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = -A;
Error += B == glm::vec3(-1.0f, -2.0f, -3.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = --A;
Error += B == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = A--;
Error += B == glm::vec3(1.0f, 2.0f, 3.0f) ? 0 : 1;
Error += A == glm::vec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = ++A;
Error += B == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
}
{
glm::vec3 A(1.0f, 2.0f, 3.0f);
glm::vec3 B = A++;
Error += B == glm::vec3(1.0f, 2.0f, 3.0f) ? 0 : 1;
Error += A == glm::vec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
}
return Error;
}
int test_vec3_size()
{
int Error = 0;
Error += sizeof(glm::vec3) == sizeof(glm::lowp_vec3) ? 0 : 1;
Error += sizeof(glm::vec3) == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += sizeof(glm::vec3) == sizeof(glm::highp_vec3) ? 0 : 1;
Error += 12 == sizeof(glm::mediump_vec3) ? 0 : 1;
Error += sizeof(glm::dvec3) == sizeof(glm::lowp_dvec3) ? 0 : 1;
Error += sizeof(glm::dvec3) == sizeof(glm::mediump_dvec3) ? 0 : 1;
Error += sizeof(glm::dvec3) == sizeof(glm::highp_dvec3) ? 0 : 1;
Error += 24 == sizeof(glm::highp_dvec3) ? 0 : 1;
Error += glm::vec3().length() == 3 ? 0 : 1;
Error += glm::dvec3().length() == 3 ? 0 : 1;
Error += glm::vec3::length() == 3 ? 0 : 1;
Error += glm::dvec3::length() == 3 ? 0 : 1;
# if GLM_HAS_CONSTEXPR_PARTIAL
constexpr std::size_t Length = glm::vec3::length();
Error += Length == 3 ? 0 : 1;
# endif
return Error;
}
int test_vec3_swizzle3_2()
{
int Error = 0;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
glm::vec3 v(1, 2, 3);
glm::vec2 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.0f && u.y == 1.0f) ? 0 : 1;
u = v.xy; Error += (u.x == 1.0f && u.y == 2.0f) ? 0 : 1;
u = v.xz; Error += (u.x == 1.0f && u.y == 3.0f) ? 0 : 1;
u = v.yx; Error += (u.x == 2.0f && u.y == 1.0f) ? 0 : 1;
u = v.yy; Error += (u.x == 2.0f && u.y == 2.0f) ? 0 : 1;
u = v.yz; Error += (u.x == 2.0f && u.y == 3.0f) ? 0 : 1;
u = v.zx; Error += (u.x == 3.0f && u.y == 1.0f) ? 0 : 1;
u = v.zy; Error += (u.x == 3.0f && u.y == 2.0f) ? 0 : 1;
u = v.zz; Error += (u.x == 3.0f && u.y == 3.0f) ? 0 : 1;
u = v.rr; Error += (u.r == 1.0f && u.g == 1.0f) ? 0 : 1;
u = v.rg; Error += (u.r == 1.0f && u.g == 2.0f) ? 0 : 1;
u = v.rb; Error += (u.r == 1.0f && u.g == 3.0f) ? 0 : 1;
u = v.gr; Error += (u.r == 2.0f && u.g == 1.0f) ? 0 : 1;
u = v.gg; Error += (u.r == 2.0f && u.g == 2.0f) ? 0 : 1;
u = v.gb; Error += (u.r == 2.0f && u.g == 3.0f) ? 0 : 1;
u = v.br; Error += (u.r == 3.0f && u.g == 1.0f) ? 0 : 1;
u = v.bg; Error += (u.r == 3.0f && u.g == 2.0f) ? 0 : 1;
u = v.bb; Error += (u.r == 3.0f && u.g == 3.0f) ? 0 : 1;
u = v.ss; Error += (u.s == 1.0f && u.t == 1.0f) ? 0 : 1;
u = v.st; Error += (u.s == 1.0f && u.t == 2.0f) ? 0 : 1;
u = v.sp; Error += (u.s == 1.0f && u.t == 3.0f) ? 0 : 1;
u = v.ts; Error += (u.s == 2.0f && u.t == 1.0f) ? 0 : 1;
u = v.tt; Error += (u.s == 2.0f && u.t == 2.0f) ? 0 : 1;
u = v.tp; Error += (u.s == 2.0f && u.t == 3.0f) ? 0 : 1;
u = v.ps; Error += (u.s == 3.0f && u.t == 1.0f) ? 0 : 1;
u = v.pt; Error += (u.s == 3.0f && u.t == 2.0f) ? 0 : 1;
u = v.pp; Error += (u.s == 3.0f && u.t == 3.0f) ? 0 : 1;
// Mixed member aliases are not valid
//u = v.rx; //Illegal
//u = v.sy; //Illegal
u = glm::vec2(1, 2);
v = glm::vec3(1, 2, 3);
//v.xx = u; //Illegal
v.xy = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 3.0f) ? 0 : 1;
v.xz = u; Error += (v.x == 1.0f && v.y == 2.0f && v.z == 2.0f) ? 0 : 1;
v.yx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
//v.yy = u; //Illegal
v.yz = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 2.0f) ? 0 : 1;
v.zx = u; Error += (v.x == 2.0f && v.y == 1.0f && v.z == 1.0f) ? 0 : 1;
v.zy = u; Error += (v.x == 2.0f && v.y == 2.0f && v.z == 1.0f) ? 0 : 1;
//v.zz = u; //Illegal
# endif//GLM_LANG
return Error;
}
int test_vec3_swizzle3_3()
{
int Error = 0;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
glm::vec3 v(1, 2, 3);
glm::vec3 u;
u = v; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.xyz; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.zyx; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.zyx = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.rgb; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.bgr; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.bgr = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
# endif//GLM_LANG
return Error;
}
#if !GLM_HAS_ONLY_XYZW
int test_vec3_swizzle_operators()
{
int Error = 0;
glm::vec3 u = glm::vec3(1, 2, 3);
glm::vec3 v = glm::vec3(10, 20, 30);
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
glm::vec3 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::vec3(u.x * v.x)) ? 0 : 1;
q = (u.xyz / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// vec, swizzle binary operators
q = u + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u - v.xyz); Error += (q == (u - v)) ? 0 : 1;
q = (u * v.xyz); Error += (q == (u * v)) ? 0 : 1;
q = (u * v.xxx); Error += (q == v.x * u) ? 0 : 1;
q = (u / v.xyz); Error += (q == (u / v)) ? 0 : 1;
// swizzle,vec binary operators
q = u.xyz + v; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v); Error += (q == (u - v)) ? 0 : 1;
q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1;
q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1;
q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1;
# endif//GLM_LANG
// Compile errors
//q = (u.yz * v.xyz);
//q = (u * v.xy);
return Error;
}
int test_vec3_swizzle_functions()
{
int Error = 0;
// 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;
return Error;
}
int test_vec3_swizzle_partial()
{
int Error = 0;
glm::vec3 A(1, 2, 3);
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
{
glm::vec3 B(A.xy, 3.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(1.0f, A.yz);
Error += A == B ? 0 : 1;
}
{
glm::vec3 B(A.xyz);
Error += A == B ? 0 : 1;
}
# endif//GLM_LANG
return Error;
}
#endif//!GLM_HAS_ONLY_XYZW
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;
}
int main()
{
int Error = 0;
Error += test_vec3_ctor();
Error += test_bvec3_ctor();
Error += test_vec3_operators();
Error += test_vec3_size();
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_operator_increment();
# if !GLM_HAS_ONLY_XYZW
Error += test_vec3_swizzle_partial();
Error += test_vec3_swizzle_operators();
Error += test_vec3_swizzle_functions();
# endif//!GLM_HAS_ONLY_XYZW
return Error;
}

View File

@@ -0,0 +1,615 @@
#define GLM_FORCE_ALIGNED
#define GLM_FORCE_SWIZZLE
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <cstdio>
#include <ctime>
#include <vector>
static glm::vec4 g1;
static glm::vec4 g2(1);
static glm::vec4 g3(1, 1, 1, 1);
template <int Value>
struct mask
{
enum{value = Value};
};
enum comp
{
X,
Y,
Z,
W
};
//template<comp X, comp Y, comp Z, comp W>
//__m128 swizzle(glm::vec4 const& v)
//{
// __m128 Src = _mm_set_ps(v.w, v.z, v.y, v.x);
// return _mm_shuffle_ps(Src, Src, mask<(int(W) << 6) | (int(Z) << 4) | (int(Y) << 2) | (int(X) << 0)>::value);
//}
static int test_vec4_ctor()
{
int Error = 0;
{
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B(A);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
}
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1;
# endif
#if GLM_HAS_INITIALIZER_LISTS
{
glm::vec4 a{ 0, 1, 2, 3 };
std::vector<glm::vec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
{
glm::dvec4 a{ 0, 1, 2, 3 };
std::vector<glm::dvec4> v = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 0, 1}};
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
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)) ? 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_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
# if GLM_HAS_CONSTEXPR && GLM_ARCH == GLM_ARCH_PURE && !(GLM_COMPILER & GLM_COMPILER_VC) // Visual Studio bug?
{
constexpr glm::ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
# endif
{
glm::vec4 A(1);
glm::vec4 B(1, 1, 1, 1);
Error += A == B ? 0 : 1;
}
{
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(glm::vec2(1, 2), 3, 4));
Tests.push_back(glm::vec4(1, glm::vec2(2, 3), 4));
Tests.push_back(glm::vec4(1, 2, glm::vec2(3, 4)));
Tests.push_back(glm::vec4(glm::vec3(1, 2, 3), 4));
Tests.push_back(glm::vec4(1, glm::vec3(2, 3, 4)));
Tests.push_back(glm::vec4(glm::vec2(1, 2), glm::vec2(3, 4)));
Tests.push_back(glm::vec4(1, 2, 3, 4));
Tests.push_back(glm::vec4(glm::vec4(1, 2, 3, 4)));
for(std::size_t i = 0; i < Tests.size(); ++i)
Error += Tests[i] == glm::vec4(1, 2, 3, 4) ? 0 : 1;
}
return Error;
}
static int test_bvec4_ctor()
{
int Error = 0;
glm::bvec4 const A(true);
glm::bvec4 const B(true);
glm::bvec4 const C(false);
glm::bvec4 const D = A && B;
glm::bvec4 const E = A && C;
glm::bvec4 const F = A || C;
Error += D == glm::bvec4(true) ? 0 : 1;
Error += E == glm::bvec4(false) ? 0 : 1;
Error += F == glm::bvec4(true) ? 0 : 1;
bool const G = A == C;
bool const H = A != C;
Error += !G ? 0 : 1;
Error += H ? 0 : 1;
return Error;
}
static int test_vec4_operators()
{
int Error = 0;
{
glm::vec4 A(1.0f);
glm::vec4 B(1.0f);
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
glm::vec4 C = A + B;
Error += C == glm::vec4(5, 7, 9, 11) ? 0 : 1;
glm::vec4 D = B - A;
Error += D == glm::vec4(3, 3, 3, 3) ? 0 : 1;
glm::vec4 E = A * B;
Error += E == glm::vec4(4, 10, 18, 28) ? 0 : 1;
glm::vec4 F = B / A;
Error += F == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
glm::vec4 G = A + 1.0f;
Error += G == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 H = B - 1.0f;
Error += H == glm::vec4(3, 4, 5, 6) ? 0 : 1;
glm::vec4 I = A * 2.0f;
Error += I == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 J = B / 2.0f;
Error += J == glm::vec4(2, 2.5, 3, 3.5) ? 0 : 1;
glm::vec4 K = 1.0f + A;
Error += K == glm::vec4(2, 3, 4, 5) ? 0 : 1;
glm::vec4 L = 1.0f - B;
Error += L == glm::vec4(-3, -4, -5, -6) ? 0 : 1;
glm::vec4 M = 2.0f * A;
Error += M == glm::vec4(2, 4, 6, 8) ? 0 : 1;
glm::vec4 N = 2.0f / B;
Error += N == glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A += B;
Error += A == glm::vec4(5, 7, 9, 11) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec4(6, 8, 10, 12) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B -= A;
Error += B == glm::vec4(3, 3, 3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec4(2, 2, 2, 2) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
A *= B;
Error += A == glm::vec4(4, 10, 18, 28) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec4(8, 20, 36, 56) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B(4.0f, 5.0f, 6.0f, 7.0f);
B /= A;
Error += B == glm::vec4(4, 2.5, 2, 7.0f / 4.0f) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec4(2, 1.25, 1, 7.0f / 4.0f / 2.0f) ? 0 : 1;
}
{
glm::vec4 B(2.0f);
B /= B.y;
Error += B == glm::vec4(1.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = -A;
Error += B == glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = --A;
Error += B == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A--;
Error += B == glm::vec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
Error += A == glm::vec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = ++A;
Error += B == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
{
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A++;
Error += B == glm::vec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
Error += A == glm::vec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
}
return Error;
}
static int test_vec4_equal()
{
int Error = 0;
{
glm::vec4 const A(1, 2, 3, 4);
glm::vec4 const B(1, 2, 3, 4);
Error += A == B ? 0 : 1;
Error += A != B ? 1 : 0;
}
{
glm::ivec4 const A(1, 2, 3, 4);
glm::ivec4 const B(1, 2, 3, 4);
Error += A == B ? 0 : 1;
Error += A != B ? 1 : 0;
}
return Error;
}
static int test_vec4_size()
{
int Error = 0;
Error += sizeof(glm::vec4) == sizeof(glm::lowp_vec4) ? 0 : 1;
Error += sizeof(glm::vec4) == sizeof(glm::mediump_vec4) ? 0 : 1;
Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1;
Error += 16 == sizeof(glm::mediump_vec4) ? 0 : 1;
Error += sizeof(glm::dvec4) == sizeof(glm::lowp_dvec4) ? 0 : 1;
Error += sizeof(glm::dvec4) == sizeof(glm::mediump_dvec4) ? 0 : 1;
Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1;
Error += 32 == sizeof(glm::highp_dvec4) ? 0 : 1;
Error += glm::vec4().length() == 4 ? 0 : 1;
Error += glm::dvec4().length() == 4 ? 0 : 1;
Error += glm::vec4::length() == 4 ? 0 : 1;
Error += glm::dvec4::length() == 4 ? 0 : 1;
# if GLM_HAS_CONSTEXPR_PARTIAL
constexpr std::size_t Length = glm::vec4::length();
Error += Length == 4 ? 0 : 1;
# endif
return Error;
}
static int test_vec4_swizzle_partial()
{
int Error = 0;
glm::vec4 A(1, 2, 3, 4);
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE_RELAX)
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xy, 3.0f, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, A.yz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, 2.0f, A.zw);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(A.xyz, 4.0f);
Error += A == B ? 0 : 1;
}
{
glm::vec4 B(1.0f, 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;
}
struct AoS
{
glm::vec4 A;
glm::vec3 B;
glm::vec3 C;
glm::vec2 D;
};
static int test_vec4_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: %ld\n", EndTime - StartTime);
return Error;
}
static int test_vec4_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: %ld\n", 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_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;
}
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::epsilonEqual(v.x, 76.f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::epsilonEqual(v.y, 75.f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::epsilonEqual(v.z, 74.f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::epsilonEqual(v.w, 73.f, glm::epsilon<float>()) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
/*
{
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);
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);
printf("GNI\n");
}
*/
# ifdef NDEBUG
std::size_t const Size(1000000);
# else
std::size_t const Size(1);
# endif//NDEBUG
Error += test_vec4_perf_AoS(Size);
Error += test_vec4_perf_SoA(Size);
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();
Error += heap::test();
Error += test_inheritance();
return Error;
}

View File

@@ -0,0 +1,2 @@
glmCreateTestGTC(ext_vec1)
glmCreateTestGTC(ext_vector_relational)

View File

@@ -0,0 +1,148 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/ext/vec1.hpp>
#include <vector>
static glm::vec1 g1;
static glm::vec1 g2(1);
int test_vec1_operators()
{
int Error(0);
glm::vec1 A(1.0f);
glm::vec1 B(1.0f);
{
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
{
A *= 1.0f;
B *= 1.0;
A += 1.0f;
B += 1.0;
bool R = A != B;
bool S = A == B;
Error += (S && !R) ? 0 : 1;
}
return Error;
}
int test_vec1_ctor()
{
int Error = 0;
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
# endif
{
glm::ivec1 A = glm::vec1(2.0f);
glm::ivec1 E(glm::dvec1(2.0));
Error += A == E ? 0 : 1;
glm::ivec1 F(glm::ivec1(2));
Error += A == F ? 0 : 1;
}
return Error;
}
int test_vec1_size()
{
int Error = 0;
Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
Error += glm::vec1().length() == 1 ? 0 : 1;
Error += glm::dvec1().length() == 1 ? 0 : 1;
Error += glm::vec1::length() == 1 ? 0 : 1;
Error += glm::dvec1::length() == 1 ? 0 : 1;
# if GLM_HAS_CONSTEXPR_PARTIAL
constexpr std::size_t Length = glm::vec1::length();
Error += Length == 1 ? 0 : 1;
# endif
return Error;
}
int test_vec1_operator_increment()
{
int Error(0);
glm::ivec1 v0(1);
glm::ivec1 v1(v0);
glm::ivec1 v2(v0);
glm::ivec1 v3 = ++v1;
glm::ivec1 v4 = v2++;
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
int i0(1);
int i1(i0);
int i2(i0);
int i3 = ++i1;
int i4 = i2++;
Error += i0 == i4 ? 0 : 1;
Error += i1 == i2 ? 0 : 1;
Error += i1 == i3 ? 0 : 1;
return Error;
}
static int test_bvec1_ctor()
{
int Error = 0;
glm::bvec1 const A(true);
glm::bvec1 const B(true);
glm::bvec1 const C(false);
glm::bvec1 const D = A && B;
glm::bvec1 const E = A && C;
glm::bvec1 const F = A || C;
Error += D == glm::bvec1(true) ? 0 : 1;
Error += E == glm::bvec1(false) ? 0 : 1;
Error += F == glm::bvec1(true) ? 0 : 1;
bool const G = A == C;
bool const H = A != C;
Error += !G ? 0 : 1;
Error += H ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_vec1_size();
Error += test_vec1_ctor();
Error += test_bvec1_ctor();
Error += test_vec1_operators();
Error += test_vec1_operator_increment();
return Error;
}

View File

@@ -0,0 +1,42 @@
#include <glm/ext/vector_relational.hpp>
#include <glm/vec2.hpp>
int test_equal()
{
int Error = 0;
Error += glm::equal(1.01f, 1.02f, 0.1f) ? 0 : 1;
Error += glm::all(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), 0.1f)) ? 0 : 1;
Error += glm::all(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.1f))) ? 0 : 1;
Error += !glm::equal(1.01f, 1.02f, 0.001f) ? 0 : 1;
Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), 0.001f)) ? 0 : 1;
Error += !glm::any(glm::equal(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.001f))) ? 0 : 1;
return Error;
}
int test_notEqual()
{
int Error = 0;
Error += glm::notEqual(1.01f, 1.02f, 0.001f) ? 0 : 1;
Error += glm::all(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), 0.001f)) ? 0 : 1;
Error += glm::all(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.001f))) ? 0 : 1;
Error += !glm::notEqual(1.01f, 1.02f, 0.1f) ? 0 : 1;
Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), 0.1f)) ? 0 : 1;
Error += !glm::any(glm::notEqual(glm::vec2(1.01f), glm::vec2(1.02f), glm::vec2(0.1f))) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_equal();
Error += test_notEqual();
return Error;
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<includedir>
<dir name="../glm"/>
</includedir>
</project>

View File

@@ -0,0 +1,20 @@
glmCreateTestGTC(gtc_bitfield)
glmCreateTestGTC(gtc_color_space)
glmCreateTestGTC(gtc_constants)
glmCreateTestGTC(gtc_epsilon)
glmCreateTestGTC(gtc_integer)
glmCreateTestGTC(gtc_matrix_access)
glmCreateTestGTC(gtc_matrix_integer)
glmCreateTestGTC(gtc_matrix_inverse)
glmCreateTestGTC(gtc_matrix_transform)
glmCreateTestGTC(gtc_noise)
glmCreateTestGTC(gtc_packing)
glmCreateTestGTC(gtc_quaternion)
glmCreateTestGTC(gtc_random)
glmCreateTestGTC(gtc_round)
glmCreateTestGTC(gtc_reciprocal)
glmCreateTestGTC(gtc_type_aligned)
glmCreateTestGTC(gtc_type_precision)
glmCreateTestGTC(gtc_type_ptr)
glmCreateTestGTC(gtc_ulp)
glmCreateTestGTC(gtc_vec1)

View File

@@ -0,0 +1,906 @@
#include <glm/gtc/bitfield.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/vector_relational.hpp>
#include <glm/integer.hpp>
#include <ctime>
#include <cstdio>
#include <vector>
namespace mask
{
template<typename genType>
struct type
{
genType Value;
genType Return;
};
inline int mask_zero(int Bits)
{
return ~((~0) << Bits);
}
inline int mask_mix(int Bits)
{
return Bits >= sizeof(int) * 8 ? 0xffffffff : (static_cast<int>(1) << Bits) - static_cast<int>(1);
}
inline int mask_half(int Bits)
{
// We do the shift in two steps because 1 << 32 on an int is undefined.
int const Half = Bits >> 1;
int const Fill = ~0;
int const ShiftHaft = (Fill << Half);
int const Rest = Bits - Half;
int const Reversed = ShiftHaft << Rest;
return ~Reversed;
}
inline int mask_loop(int Bits)
{
int Mask = 0;
for(int Bit = 0; Bit < Bits; ++Bit)
Mask |= (static_cast<int>(1) << Bit);
return Mask;
}
int perf()
{
int const Count = 100000000;
std::clock_t Timestamp1 = std::clock();
{
std::vector<int> Mask;
Mask.resize(Count);
for(int i = 0; i < Count; ++i)
Mask[i] = mask_mix(i % 32);
}
std::clock_t Timestamp2 = std::clock();
{
std::vector<int> Mask;
Mask.resize(Count);
for(int i = 0; i < Count; ++i)
Mask[i] = mask_loop(i % 32);
}
std::clock_t Timestamp3 = std::clock();
{
std::vector<int> Mask;
Mask.resize(Count);
for(int i = 0; i < Count; ++i)
Mask[i] = glm::mask(i % 32);
}
std::clock_t Timestamp4 = std::clock();
{
std::vector<int> Mask;
Mask.resize(Count);
for(int i = 0; i < Count; ++i)
Mask[i] = mask_zero(i % 32);
}
std::clock_t Timestamp5 = std::clock();
{
std::vector<int> Mask;
Mask.resize(Count);
for(int i = 0; i < Count; ++i)
Mask[i] = mask_half(i % 32);
}
std::clock_t Timestamp6 = std::clock();
std::clock_t TimeMix = Timestamp2 - Timestamp1;
std::clock_t TimeLoop = Timestamp3 - Timestamp2;
std::clock_t TimeDefault = Timestamp4 - Timestamp3;
std::clock_t TimeZero = Timestamp5 - Timestamp4;
std::clock_t TimeHalf = Timestamp6 - Timestamp5;
printf("mask[mix]: %d\n", static_cast<unsigned int>(TimeMix));
printf("mask[loop]: %d\n", static_cast<unsigned int>(TimeLoop));
printf("mask[default]: %d\n", static_cast<unsigned int>(TimeDefault));
printf("mask[zero]: %d\n", static_cast<unsigned int>(TimeZero));
printf("mask[half]: %d\n", static_cast<unsigned int>(TimeHalf));
return TimeDefault < TimeLoop ? 0 : 1;
}
int test_uint()
{
type<glm::uint> const Data[] =
{
{ 0, 0x00000000},
{ 1, 0x00000001},
{ 2, 0x00000003},
{ 3, 0x00000007},
{31, 0x7fffffff},
{32, 0xffffffff}
};
int Error = 0;
/* mask_zero is sadly not a correct code
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = mask_zero(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
*/
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = mask_mix(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = mask_half(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = mask_loop(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
{
int Result = glm::mask(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test_uvec4()
{
type<glm::ivec4> const Data[] =
{
{glm::ivec4( 0), glm::ivec4(0x00000000)},
{glm::ivec4( 1), glm::ivec4(0x00000001)},
{glm::ivec4( 2), glm::ivec4(0x00000003)},
{glm::ivec4( 3), glm::ivec4(0x00000007)},
{glm::ivec4(31), glm::ivec4(0x7fffffff)},
{glm::ivec4(32), glm::ivec4(0xffffffff)}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::ivec4>); i < n; ++i)
{
glm::ivec4 Result = glm::mask(Data[i].Value);
Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_uint();
Error += test_uvec4();
return Error;
}
}//namespace mask
namespace bitfieldInterleave3
{
template<typename PARAM, typename RET>
inline RET refBitfieldInterleave(PARAM x, PARAM y, PARAM z)
{
RET Result = 0;
for(RET i = 0; i < sizeof(PARAM) * 8; ++i)
{
Result |= ((RET(x) & (RET(1U) << i)) << ((i << 1) + 0));
Result |= ((RET(y) & (RET(1U) << i)) << ((i << 1) + 1));
Result |= ((RET(z) & (RET(1U) << i)) << ((i << 1) + 2));
}
return Result;
}
int test()
{
int Error(0);
glm::uint16 x_max = 1 << 11;
glm::uint16 y_max = 1 << 11;
glm::uint16 z_max = 1 << 11;
for(glm::uint16 z = 0; z < z_max; z += 27)
for(glm::uint16 y = 0; y < y_max; y += 27)
for(glm::uint16 x = 0; x < x_max; x += 27)
{
glm::uint64 ResultA = refBitfieldInterleave<glm::uint16, glm::uint64>(x, y, z);
glm::uint64 ResultB = glm::bitfieldInterleave(x, y, z);
Error += ResultA == ResultB ? 0 : 1;
}
return Error;
}
}
namespace bitfieldInterleave4
{
template<typename PARAM, typename RET>
inline RET loopBitfieldInterleave(PARAM x, PARAM y, PARAM z, PARAM w)
{
RET const v[4] = {x, y, z, w};
RET Result = 0;
for(RET i = 0; i < sizeof(PARAM) * 8; i++)
{
Result |= ((((v[0] >> i) & 1U)) << ((i << 2) + 0));
Result |= ((((v[1] >> i) & 1U)) << ((i << 2) + 1));
Result |= ((((v[2] >> i) & 1U)) << ((i << 2) + 2));
Result |= ((((v[3] >> i) & 1U)) << ((i << 2) + 3));
}
return Result;
}
int test()
{
int Error(0);
glm::uint16 x_max = 1 << 11;
glm::uint16 y_max = 1 << 11;
glm::uint16 z_max = 1 << 11;
glm::uint16 w_max = 1 << 11;
for(glm::uint16 w = 0; w < w_max; w += 27)
for(glm::uint16 z = 0; z < z_max; z += 27)
for(glm::uint16 y = 0; y < y_max; y += 27)
for(glm::uint16 x = 0; x < x_max; x += 27)
{
glm::uint64 ResultA = loopBitfieldInterleave<glm::uint16, glm::uint64>(x, y, z, w);
glm::uint64 ResultB = glm::bitfieldInterleave(x, y, z, w);
Error += ResultA == ResultB ? 0 : 1;
}
return Error;
}
}
namespace bitfieldInterleave
{
inline glm::uint64 fastBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
glm::uint64 REG1;
glm::uint64 REG2;
REG1 = x;
REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
REG2 = y;
REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
return REG1 | (REG2 << 1);
}
inline glm::uint64 interleaveBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
glm::uint64 REG1;
glm::uint64 REG2;
REG1 = x;
REG2 = y;
REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
return REG1 | (REG2 << 1);
}
/*
inline glm::uint64 loopBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
static glm::uint64 const Mask[5] =
{
0x5555555555555555,
0x3333333333333333,
0x0F0F0F0F0F0F0F0F,
0x00FF00FF00FF00FF,
0x0000FFFF0000FFFF
};
glm::uint64 REG1 = x;
glm::uint64 REG2 = y;
for(int i = 4; i >= 0; --i)
{
REG1 = ((REG1 << (1 << i)) | REG1) & Mask[i];
REG2 = ((REG2 << (1 << i)) | REG2) & Mask[i];
}
return REG1 | (REG2 << 1);
}
*/
#if GLM_ARCH & GLM_ARCH_SSE2_BIT
inline glm::uint64 sseBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
__m128i const Array = _mm_set_epi32(0, y, 0, x);
__m128i const Mask4 = _mm_set1_epi32(0x0000FFFF);
__m128i const Mask3 = _mm_set1_epi32(0x00FF00FF);
__m128i const Mask2 = _mm_set1_epi32(0x0F0F0F0F);
__m128i const Mask1 = _mm_set1_epi32(0x33333333);
__m128i const Mask0 = _mm_set1_epi32(0x55555555);
__m128i Reg1;
__m128i Reg2;
// REG1 = x;
// REG2 = y;
Reg1 = _mm_load_si128(&Array);
//REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
//REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
Reg2 = _mm_slli_si128(Reg1, 2);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask4);
//REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
//REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
Reg2 = _mm_slli_si128(Reg1, 1);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask3);
//REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
//REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
Reg2 = _mm_slli_epi32(Reg1, 4);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask2);
//REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
//REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
Reg2 = _mm_slli_epi32(Reg1, 2);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask1);
//REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
//REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
Reg2 = _mm_slli_epi32(Reg1, 1);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask0);
//return REG1 | (REG2 << 1);
Reg2 = _mm_slli_epi32(Reg1, 1);
Reg2 = _mm_srli_si128(Reg2, 8);
Reg1 = _mm_or_si128(Reg1, Reg2);
__m128i Result;
_mm_store_si128(&Result, Reg1);
return *reinterpret_cast<glm::uint64*>(&Result);
}
inline glm::uint64 sseUnalignedBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
__m128i const Array = _mm_set_epi32(0, y, 0, x);
__m128i const Mask4 = _mm_set1_epi32(0x0000FFFF);
__m128i const Mask3 = _mm_set1_epi32(0x00FF00FF);
__m128i const Mask2 = _mm_set1_epi32(0x0F0F0F0F);
__m128i const Mask1 = _mm_set1_epi32(0x33333333);
__m128i const Mask0 = _mm_set1_epi32(0x55555555);
__m128i Reg1;
__m128i Reg2;
// REG1 = x;
// REG2 = y;
Reg1 = _mm_loadu_si128(&Array);
//REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
//REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
Reg2 = _mm_slli_si128(Reg1, 2);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask4);
//REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
//REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
Reg2 = _mm_slli_si128(Reg1, 1);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask3);
//REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
//REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
Reg2 = _mm_slli_epi32(Reg1, 4);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask2);
//REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
//REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
Reg2 = _mm_slli_epi32(Reg1, 2);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask1);
//REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
//REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
Reg2 = _mm_slli_epi32(Reg1, 1);
Reg1 = _mm_or_si128(Reg2, Reg1);
Reg1 = _mm_and_si128(Reg1, Mask0);
//return REG1 | (REG2 << 1);
Reg2 = _mm_slli_epi32(Reg1, 1);
Reg2 = _mm_srli_si128(Reg2, 8);
Reg1 = _mm_or_si128(Reg1, Reg2);
__m128i Result;
_mm_store_si128(&Result, Reg1);
return *reinterpret_cast<glm::uint64*>(&Result);
}
#endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
int test()
{
int Error = 0;
/*
{
for(glm::uint32 y = 0; y < (1 << 10); ++y)
for(glm::uint32 x = 0; x < (1 << 10); ++x)
{
glm::uint64 A = glm::bitfieldInterleave(x, y);
glm::uint64 B = fastBitfieldInterleave(x, y);
//glm::uint64 C = loopBitfieldInterleave(x, y);
glm::uint64 D = interleaveBitfieldInterleave(x, y);
assert(A == B);
//assert(A == C);
assert(A == D);
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
glm::uint64 E = sseBitfieldInterleave(x, y);
glm::uint64 F = sseUnalignedBitfieldInterleave(x, y);
assert(A == E);
assert(A == F);
__m128i G = glm_i128_interleave(_mm_set_epi32(0, y, 0, x));
glm::uint64 Result[2];
_mm_storeu_si128((__m128i*)Result, G);
assert(A == Result[0]);
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
}
}
*/
{
for(glm::uint8 y = 0; y < 127; ++y)
for(glm::uint8 x = 0; x < 127; ++x)
{
glm::uint64 A(glm::bitfieldInterleave(glm::uint8(x), glm::uint8(y)));
glm::uint64 B(glm::bitfieldInterleave(glm::uint16(x), glm::uint16(y)));
glm::uint64 C(glm::bitfieldInterleave(glm::uint32(x), glm::uint32(y)));
Error += A == B ? 0 : 1;
Error += A == C ? 0 : 1;
glm::int64 D(glm::bitfieldInterleave(glm::int8(x), glm::int8(y)));
glm::int64 E(glm::bitfieldInterleave(glm::int16(x), glm::int16(y)));
glm::int64 F(glm::bitfieldInterleave(glm::int32(x), glm::int32(y)));
Error += D == E ? 0 : 1;
Error += D == F ? 0 : 1;
}
}
return Error;
}
int perf()
{
glm::uint32 x_max = 1 << 11;
glm::uint32 y_max = 1 << 10;
// ALU
std::vector<glm::uint64> Data(x_max * y_max);
std::vector<glm::u32vec2> Param(x_max * y_max);
for(glm::uint32 i = 0; i < Param.size(); ++i)
Param[i] = glm::u32vec2(i % x_max, i / y_max);
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = glm::bitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("glm::bitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = fastBitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("fastBitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
/*
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = loopBitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("loopBitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
*/
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = interleaveBitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("interleaveBitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = sseBitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("sseBitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = sseUnalignedBitfieldInterleave(Param[i].x, Param[i].y);
std::clock_t Time = std::clock() - LastTime;
std::printf("sseUnalignedBitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
{
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = glm::bitfieldInterleave(Param[i].x, Param[i].y, Param[i].x);
std::clock_t Time = std::clock() - LastTime;
std::printf("glm::detail::bitfieldInterleave Time %d clocks\n", static_cast<unsigned int>(Time));
}
# if(GLM_ARCH & GLM_ARCH_SSE2_BIT && !(GLM_COMPILER & GLM_COMPILER_GCC))
{
// SIMD
std::vector<__m128i> SimdData;
SimdData.resize(static_cast<std::size_t>(x_max * y_max));
std::vector<__m128i> SimdParam;
SimdParam.resize(static_cast<std::size_t>(x_max * y_max));
for(std::size_t i = 0; i < SimdParam.size(); ++i)
SimdParam[i] = _mm_set_epi32(static_cast<int>(i % static_cast<std::size_t>(x_max)), 0, static_cast<int>(i / static_cast<std::size_t>(y_max)), 0);
std::clock_t LastTime = std::clock();
for(std::size_t i = 0; i < SimdData.size(); ++i)
SimdData[i] = glm_i128_interleave(SimdParam[i]);
std::clock_t Time = std::clock() - LastTime;
std::printf("_mm_bit_interleave_si128 Time %d clocks\n", static_cast<unsigned int>(Time));
}
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
return 0;
}
}//namespace bitfieldInterleave
namespace bitfieldInterleave5
{
GLM_FUNC_QUALIFIER glm::uint16 bitfieldInterleave_u8vec2(glm::uint8 x, glm::uint8 y)
{
glm::uint32 Result = (glm::uint32(y) << 16) | glm::uint32(x);
Result = ((Result << 4) | Result) & 0x0F0F0F0F;
Result = ((Result << 2) | Result) & 0x33333333;
Result = ((Result << 1) | Result) & 0x55555555;
return static_cast<glm::uint16>((Result & 0x0000FFFF) | (Result >> 15));
}
GLM_FUNC_QUALIFIER glm::u8vec2 bitfieldDeinterleave_u8vec2(glm::uint16 InterleavedBitfield)
{
glm::uint32 Result(InterleavedBitfield);
Result = ((Result << 15) | Result) & 0x55555555;
Result = ((Result >> 1) | Result) & 0x33333333;
Result = ((Result >> 2) | Result) & 0x0F0F0F0F;
Result = ((Result >> 4) | Result) & 0x00FF00FF;
return glm::u8vec2(Result & 0x0000FFFF, Result >> 16);
}
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u8vec4(glm::uint8 x, glm::uint8 y, glm::uint8 z, glm::uint8 w)
{
glm::uint64 Result = (glm::uint64(w) << 48) | (glm::uint64(z) << 32) | (glm::uint64(y) << 16) | glm::uint64(x);
Result = ((Result << 12) | Result) & 0x000F000F000F000Full;
Result = ((Result << 6) | Result) & 0x0303030303030303ull;
Result = ((Result << 3) | Result) & 0x1111111111111111ull;
const glm::uint32 a = static_cast<glm::uint32>((Result & 0x000000000000FFFF) >> ( 0 - 0));
const glm::uint32 b = static_cast<glm::uint32>((Result & 0x00000000FFFF0000) >> (16 - 3));
const glm::uint32 c = static_cast<glm::uint32>((Result & 0x0000FFFF00000000) >> (32 - 6));
const glm::uint32 d = static_cast<glm::uint32>((Result & 0xFFFF000000000000) >> (48 - 12));
return a | b | c | d;
}
GLM_FUNC_QUALIFIER glm::u8vec4 bitfieldDeinterleave_u8vec4(glm::uint32 InterleavedBitfield)
{
glm::uint64 Result(InterleavedBitfield);
Result = ((Result << 15) | Result) & 0x9249249249249249ull;
Result = ((Result >> 1) | Result) & 0x30C30C30C30C30C3ull;
Result = ((Result >> 2) | Result) & 0xF00F00F00F00F00Full;
Result = ((Result >> 4) | Result) & 0x00FF0000FF0000FFull;
return glm::u8vec4(
(Result >> 0) & 0x000000000000FFFFull,
(Result >> 16) & 0x00000000FFFF0000ull,
(Result >> 32) & 0x0000FFFF00000000ull,
(Result >> 48) & 0xFFFF000000000000ull);
}
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u16vec2(glm::uint16 x, glm::uint16 y)
{
glm::uint64 Result = (glm::uint64(y) << 32) | glm::uint64(x);
Result = ((Result << 8) | Result) & static_cast<glm::uint32>(0x00FF00FF00FF00FFull);
Result = ((Result << 4) | Result) & static_cast<glm::uint32>(0x0F0F0F0F0F0F0F0Full);
Result = ((Result << 2) | Result) & static_cast<glm::uint32>(0x3333333333333333ull);
Result = ((Result << 1) | Result) & static_cast<glm::uint32>(0x5555555555555555ull);
return static_cast<glm::uint32>((Result & 0x00000000FFFFFFFFull) | (Result >> 31));
}
GLM_FUNC_QUALIFIER glm::u16vec2 bitfieldDeinterleave_u16vec2(glm::uint32 InterleavedBitfield)
{
glm::uint64 Result(InterleavedBitfield);
Result = ((Result << 31) | Result) & 0x5555555555555555ull;
Result = ((Result >> 1) | Result) & 0x3333333333333333ull;
Result = ((Result >> 2) | Result) & 0x0F0F0F0F0F0F0F0Full;
Result = ((Result >> 4) | Result) & 0x00FF00FF00FF00FFull;
Result = ((Result >> 8) | Result) & 0x0000FFFF0000FFFFull;
return glm::u16vec2(Result & 0x00000000FFFFFFFFull, Result >> 32);
}
int test()
{
int Error = 0;
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
{
glm::uint16 A = bitfieldInterleave_u8vec2(glm::uint8(i), glm::uint8(j));
glm::uint16 B = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j));
Error += A == B ? 0 : 1;
glm::u8vec2 C = bitfieldDeinterleave_u8vec2(A);
Error += C.x == glm::uint8(i) ? 0 : 1;
Error += C.y == glm::uint8(j) ? 0 : 1;
}
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
{
glm::uint32 A = bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
glm::uint32 B = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
Error += A == B ? 0 : 1;
/*
glm::u8vec4 C = bitfieldDeinterleave_u8vec4(A);
Error += C.x == glm::uint8(i) ? 0 : 1;
Error += C.y == glm::uint8(j) ? 0 : 1;
Error += C.z == glm::uint8(i) ? 0 : 1;
Error += C.w == glm::uint8(j) ? 0 : 1;
*/
}
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
{
glm::uint32 A = bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j));
glm::uint32 B = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
Error += A == B ? 0 : 1;
}
return Error;
}
int perf_old_u8vec2(std::vector<glm::uint16>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("glm::bitfieldInterleave<u8vec2> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf_new_u8vec2(std::vector<glm::uint16>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == bitfieldInterleave_u8vec2(glm::uint8(i), glm::uint8(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("bitfieldInterleave_u8vec2 Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf_old_u8vec4(std::vector<glm::uint32>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("glm::bitfieldInterleave<u8vec4> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf_new_u8vec4(std::vector<glm::uint32>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("bitfieldInterleave_u8vec4 Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf_old_u16vec2(std::vector<glm::uint32>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("glm::bitfieldInterleave<u16vec2> Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf_new_u16vec2(std::vector<glm::uint32>& Result)
{
int Error = 0;
const std::clock_t BeginTime = std::clock();
for(glm::size_t k = 0; k < 10000; ++k)
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Error += Result[j * 256 + i] == bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j)) ? 0 : 1;
const std::clock_t EndTime = std::clock();
std::printf("bitfieldInterleave_u16vec2 Time %d clocks\n", static_cast<unsigned int>(EndTime - BeginTime));
return Error;
}
int perf()
{
int Error = 0;
std::printf("bitfieldInterleave perf: init\r");
std::vector<glm::uint16> Result_u8vec2(256 * 256, 0);
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Result_u8vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j));
Error += perf_old_u8vec2(Result_u8vec2);
Error += perf_new_u8vec2(Result_u8vec2);
std::vector<glm::uint32> Result_u8vec4(256 * 256, 0);
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Result_u8vec4[j * 256 + i] = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
Error += perf_old_u8vec4(Result_u8vec4);
Error += perf_new_u8vec4(Result_u8vec4);
std::vector<glm::uint32> Result_u16vec2(256 * 256, 0);
for(glm::size_t j = 0; j < 256; ++j)
for(glm::size_t i = 0; i < 256; ++i)
Result_u16vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
Error += perf_old_u16vec2(Result_u16vec2);
Error += perf_new_u16vec2(Result_u16vec2);
std::printf("bitfieldInterleave perf: %d Errors\n", Error);
return Error;
}
}//namespace bitfieldInterleave5
int main()
{
int Error = 0;
/* Tests for a faster and to reserve bitfieldInterleave
Error += ::bitfieldInterleave5::test();
Error += ::bitfieldInterleave5::perf();
*/
Error += ::mask::test();
Error += ::bitfieldInterleave3::test();
Error += ::bitfieldInterleave4::test();
Error += ::bitfieldInterleave::test();
# ifdef NDEBUG
Error += ::mask::perf();
Error += ::bitfieldInterleave::perf();
# endif//NDEBUG
return Error;
}

View File

@@ -0,0 +1,68 @@
#include <glm/gtc/color_space.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
namespace srgb
{
int test()
{
int Error(0);
glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
{
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB);
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
{
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb
namespace srgb_lowp
{
int test()
{
int Error(0);
for(float Color = 0.0f; Color < 1.0f; Color += 0.01f)
{
glm::highp_vec3 const HighpSRGB = glm::convertLinearToSRGB(glm::highp_vec3(Color));
glm::lowp_vec3 const LowpSRGB = glm::convertLinearToSRGB(glm::lowp_vec3(Color));
Error += glm::all(glm::epsilonEqual(glm::abs(HighpSRGB - glm::highp_vec3(LowpSRGB)), glm::highp_vec3(0), 0.1f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb_lowp
int main()
{
int Error(0);
Error += srgb::test();
Error += srgb_lowp::test();
return Error;
}

View File

@@ -0,0 +1,30 @@
#include <glm/gtc/constants.hpp>
int test_epsilon()
{
int Error = 0;
{
float Test = glm::epsilon<float>();
Error += Test > 0.0f ? 0 : 1;
}
{
double Test = glm::epsilon<double>();
Error += Test > 0.0 ? 0 : 1;
}
return Error;
}
int main()
{
int Error(0);
//float MinHalf = 0.0f;
//while (glm::half(MinHalf) == glm::half(0.0f))
// MinHalf += std::numeric_limits<float>::epsilon();
Error += test_epsilon();
return Error;
}

View File

@@ -0,0 +1,77 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/vector_relational.hpp>
int test_defined()
{
glm::epsilonEqual(glm::vec2(), glm::vec2(), glm::vec2());
glm::epsilonEqual(glm::vec3(), glm::vec3(), glm::vec3());
glm::epsilonEqual(glm::vec4(), glm::vec4(), glm::vec4());
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), glm::vec2());
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), glm::vec3());
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), glm::vec4());
glm::epsilonEqual(glm::vec2(), glm::vec2(), 0.0f);
glm::epsilonEqual(glm::vec3(), glm::vec3(), 0.0f);
glm::epsilonEqual(glm::vec4(), glm::vec4(), 0.0f);
glm::epsilonEqual(glm::quat(), glm::quat(), 0.0f);
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), 0.0f);
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), 0.0f);
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), 0.0f);
glm::epsilonNotEqual(glm::quat(), glm::quat(), 0.0f);
return 0;
}
template<typename T>
int test_equal()
{
int Error(0);
{
T A = glm::epsilon<T>();
T B = glm::epsilon<T>();
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
}
{
T A(0);
T B = static_cast<T>(0) + glm::epsilon<T>();
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
}
{
T A(0);
T B = static_cast<T>(0) - glm::epsilon<T>();
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
}
{
T A = static_cast<T>(0) + glm::epsilon<T>();
T B = static_cast<T>(0);
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
}
{
T A = static_cast<T>(0) - glm::epsilon<T>();
T B = static_cast<T>(0);
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
}
return Error;
}
int main()
{
int Error(0);
Error += test_defined();
Error += test_equal<float>();
Error += test_equal<double>();
return Error;
}

View File

@@ -0,0 +1,233 @@
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_INLINE
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtx/type_aligned.hpp>
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cmath>
namespace log2_
{
int test()
{
int Error = 0;
int A0 = static_cast<int>(glm::log2(16.f));
glm::ivec1 B0(glm::log2(glm::vec1(16.f)));
glm::ivec2 C0(glm::log2(glm::vec2(16.f)));
glm::ivec3 D0(glm::log2(glm::vec3(16.f)));
glm::ivec4 E0(glm::log2(glm::vec4(16.f)));
int A1 = glm::log2(int(16));
glm::ivec1 B1 = glm::log2(glm::ivec1(16));
glm::ivec2 C1 = glm::log2(glm::ivec2(16));
glm::ivec3 D1 = glm::log2(glm::ivec3(16));
glm::ivec4 E1 = glm::log2(glm::ivec4(16));
Error += A0 == A1 ? 0 : 1;
Error += glm::all(glm::equal(B0, B1)) ? 0 : 1;
Error += glm::all(glm::equal(C0, C1)) ? 0 : 1;
Error += glm::all(glm::equal(D0, D1)) ? 0 : 1;
Error += glm::all(glm::equal(E0, E1)) ? 0 : 1;
glm::uint64 A2 = glm::log2(glm::uint64(16));
glm::u64vec1 B2 = glm::log2(glm::u64vec1(16));
glm::u64vec2 C2 = glm::log2(glm::u64vec2(16));
glm::u64vec3 D2 = glm::log2(glm::u64vec3(16));
glm::u64vec4 E2 = glm::log2(glm::u64vec4(16));
Error += A2 == glm::uint64(4) ? 0 : 1;
Error += glm::all(glm::equal(B2, glm::u64vec1(4))) ? 0 : 1;
Error += glm::all(glm::equal(C2, glm::u64vec2(4))) ? 0 : 1;
Error += glm::all(glm::equal(D2, glm::u64vec3(4))) ? 0 : 1;
Error += glm::all(glm::equal(E2, glm::u64vec4(4))) ? 0 : 1;
return Error;
}
int perf(std::size_t Count)
{
int Error = 0;
{
std::vector<int> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(int i = 0; i < static_cast<int>(Count); ++i)
Result[i] = glm::log2(static_cast<int>(i));
std::clock_t End = clock();
printf("glm::log2<int>: %ld clocks\n", End - Begin);
}
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(int i = 0; i < static_cast<int>(Count); ++i)
Result[i] = glm::log2(glm::ivec4(i));
std::clock_t End = clock();
printf("glm::log2<ivec4>: %ld clocks\n", End - Begin);
}
# if GLM_HAS_BITSCAN_WINDOWS
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(std::size_t i = 0; i < Count; ++i)
{
glm::vec<4, unsigned long, glm::defaultp> Tmp;
_BitScanReverse(&Tmp.x, i);
_BitScanReverse(&Tmp.y, i);
_BitScanReverse(&Tmp.z, i);
_BitScanReverse(&Tmp.w, i);
Result[i] = glm::ivec4(Tmp);
}
std::clock_t End = clock();
printf("glm::log2<ivec4> inlined: %ld clocks\n", End - Begin);
}
{
std::vector<glm::vec<4, unsigned long, glm::defaultp> > Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(std::size_t i = 0; i < Count; ++i)
{
_BitScanReverse(&Result[i].x, i);
_BitScanReverse(&Result[i].y, i);
_BitScanReverse(&Result[i].z, i);
_BitScanReverse(&Result[i].w, i);
}
std::clock_t End = clock();
printf("glm::log2<ivec4> inlined no cast: %ld clocks\n", End - Begin);
}
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(std::size_t i = 0; i < Count; ++i)
{
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].x), i);
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].y), i);
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].z), i);
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].w), i);
}
std::clock_t End = clock();
printf("glm::log2<ivec4> reinterpret: %ld clocks\n", End - Begin);
}
# endif//GLM_HAS_BITSCAN_WINDOWS
{
std::vector<float> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(std::size_t i = 0; i < Count; ++i)
Result[i] = glm::log2(static_cast<float>(i));
std::clock_t End = clock();
printf("glm::log2<float>: %ld clocks\n", End - Begin);
}
{
std::vector<glm::vec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(int i = 0; i < static_cast<int>(Count); ++i)
Result[i] = glm::log2(glm::vec4(static_cast<float>(i)));
std::clock_t End = clock();
printf("glm::log2<vec4>: %ld clocks\n", End - Begin);
}
return Error;
}
}//namespace log2_
namespace iround
{
int test()
{
int Error = 0;
for(float f = 0.0f; f < 3.1f; f += 0.05f)
{
int RoundFast = static_cast<int>(glm::iround(f));
int RoundSTD = static_cast<int>(glm::round(f));
Error += RoundFast == RoundSTD ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace iround
namespace uround
{
int test()
{
int Error = 0;
for(float f = 0.0f; f < 3.1f; f += 0.05f)
{
int RoundFast = static_cast<int>(glm::uround(f));
int RoundSTD = static_cast<int>(glm::round(f));
Error += RoundFast == RoundSTD ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace uround
int main()
{
int Error(0);
Error += ::log2_::test();
Error += ::iround::test();
Error += ::uround::test();
# ifdef NDEBUG
std::size_t const Samples(1000);
Error += ::log2_::perf(Samples);
# endif//NDEBUG
return Error;
}

View File

@@ -0,0 +1,381 @@
#include <glm/gtc/matrix_access.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>
int test_mat2x2_row_set()
{
int Error = 0;
glm::mat2x2 m(1);
m = glm::row(m, 0, glm::vec2( 0, 1));
m = glm::row(m, 1, glm::vec2( 4, 5));
Error += glm::row(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
return Error;
}
int test_mat2x2_col_set()
{
int Error = 0;
glm::mat2x2 m(1);
m = glm::column(m, 0, glm::vec2( 0, 1));
m = glm::column(m, 1, glm::vec2( 4, 5));
Error += glm::column(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
return Error;
}
int test_mat2x3_row_set()
{
int Error = 0;
glm::mat2x3 m(1);
m = glm::row(m, 0, glm::vec2( 0, 1));
m = glm::row(m, 1, glm::vec2( 4, 5));
m = glm::row(m, 2, glm::vec2( 8, 9));
Error += glm::row(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec2( 8, 9) ? 0 : 1;
return Error;
}
int test_mat2x3_col_set()
{
int Error = 0;
glm::mat2x3 m(1);
m = glm::column(m, 0, glm::vec3( 0, 1, 2));
m = glm::column(m, 1, glm::vec3( 4, 5, 6));
Error += glm::column(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
return Error;
}
int test_mat2x4_row_set()
{
int Error = 0;
glm::mat2x4 m(1);
m = glm::row(m, 0, glm::vec2( 0, 1));
m = glm::row(m, 1, glm::vec2( 4, 5));
m = glm::row(m, 2, glm::vec2( 8, 9));
m = glm::row(m, 3, glm::vec2(12, 13));
Error += glm::row(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec2( 8, 9) ? 0 : 1;
Error += glm::row(m, 3) == glm::vec2(12, 13) ? 0 : 1;
return Error;
}
int test_mat2x4_col_set()
{
int Error = 0;
glm::mat2x4 m(1);
m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
Error += glm::column(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
return Error;
}
int test_mat3x2_row_set()
{
int Error = 0;
glm::mat3x2 m(1);
m = glm::row(m, 0, glm::vec3( 0, 1, 2));
m = glm::row(m, 1, glm::vec3( 4, 5, 6));
Error += glm::row(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
return Error;
}
int test_mat3x2_col_set()
{
int Error = 0;
glm::mat3x2 m(1);
m = glm::column(m, 0, glm::vec2( 0, 1));
m = glm::column(m, 1, glm::vec2( 4, 5));
m = glm::column(m, 2, glm::vec2( 8, 9));
Error += glm::column(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec2( 8, 9) ? 0 : 1;
return Error;
}
int test_mat3x3_row_set()
{
int Error = 0;
glm::mat3x3 m(1);
m = glm::row(m, 0, glm::vec3( 0, 1, 2));
m = glm::row(m, 1, glm::vec3( 4, 5, 6));
m = glm::row(m, 2, glm::vec3( 8, 9, 10));
Error += glm::row(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec3( 8, 9, 10) ? 0 : 1;
return Error;
}
int test_mat3x3_col_set()
{
int Error = 0;
glm::mat3x3 m(1);
m = glm::column(m, 0, glm::vec3( 0, 1, 2));
m = glm::column(m, 1, glm::vec3( 4, 5, 6));
m = glm::column(m, 2, glm::vec3( 8, 9, 10));
Error += glm::column(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec3( 8, 9, 10) ? 0 : 1;
return Error;
}
int test_mat3x4_row_set()
{
int Error = 0;
glm::mat3x4 m(1);
m = glm::row(m, 0, glm::vec3( 0, 1, 2));
m = glm::row(m, 1, glm::vec3( 4, 5, 6));
m = glm::row(m, 2, glm::vec3( 8, 9, 10));
m = glm::row(m, 3, glm::vec3(12, 13, 14));
Error += glm::row(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec3( 8, 9, 10) ? 0 : 1;
Error += glm::row(m, 3) == glm::vec3(12, 13, 14) ? 0 : 1;
return Error;
}
int test_mat3x4_col_set()
{
int Error = 0;
glm::mat3x4 m(1);
m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
m = glm::column(m, 2, glm::vec4( 8, 9, 10, 11));
Error += glm::column(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec4( 8, 9, 10, 11) ? 0 : 1;
return Error;
}
int test_mat4x2_row_set()
{
int Error = 0;
glm::mat4x2 m(1);
m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
Error += glm::row(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
return Error;
}
int test_mat4x2_col_set()
{
int Error = 0;
glm::mat4x2 m(1);
m = glm::column(m, 0, glm::vec2( 0, 1));
m = glm::column(m, 1, glm::vec2( 4, 5));
m = glm::column(m, 2, glm::vec2( 8, 9));
m = glm::column(m, 3, glm::vec2(12, 13));
Error += glm::column(m, 0) == glm::vec2( 0, 1) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec2( 4, 5) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec2( 8, 9) ? 0 : 1;
Error += glm::column(m, 3) == glm::vec2(12, 13) ? 0 : 1;
return Error;
}
int test_mat4x3_row_set()
{
int Error = 0;
glm::mat4x3 m(1);
m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
m = glm::row(m, 2, glm::vec4( 8, 9, 10, 11));
Error += glm::row(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec4( 8, 9, 10, 11) ? 0 : 1;
return Error;
}
int test_mat4x3_col_set()
{
int Error = 0;
glm::mat4x3 m(1);
m = glm::column(m, 0, glm::vec3( 0, 1, 2));
m = glm::column(m, 1, glm::vec3( 4, 5, 6));
m = glm::column(m, 2, glm::vec3( 8, 9, 10));
m = glm::column(m, 3, glm::vec3(12, 13, 14));
Error += glm::column(m, 0) == glm::vec3( 0, 1, 2) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec3( 4, 5, 6) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec3( 8, 9, 10) ? 0 : 1;
Error += glm::column(m, 3) == glm::vec3(12, 13, 14) ? 0 : 1;
return Error;
}
int test_mat4x4_row_set()
{
int Error = 0;
glm::mat4 m(1);
m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
m = glm::row(m, 2, glm::vec4( 8, 9, 10, 11));
m = glm::row(m, 3, glm::vec4(12, 13, 14, 15));
Error += glm::row(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::row(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
Error += glm::row(m, 2) == glm::vec4( 8, 9, 10, 11) ? 0 : 1;
Error += glm::row(m, 3) == glm::vec4(12, 13, 14, 15) ? 0 : 1;
return Error;
}
int test_mat4x4_col_set()
{
int Error = 0;
glm::mat4 m(1);
m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
m = glm::column(m, 2, glm::vec4( 8, 9, 10, 11));
m = glm::column(m, 3, glm::vec4(12, 13, 14, 15));
Error += glm::column(m, 0) == glm::vec4( 0, 1, 2, 3) ? 0 : 1;
Error += glm::column(m, 1) == glm::vec4( 4, 5, 6, 7) ? 0 : 1;
Error += glm::column(m, 2) == glm::vec4( 8, 9, 10, 11) ? 0 : 1;
Error += glm::column(m, 3) == glm::vec4(12, 13, 14, 15) ? 0 : 1;
return Error;
}
int test_mat4x4_row_get()
{
int Error = 0;
glm::mat4 m(1);
glm::vec4 A = glm::row(m, 0);
Error += A == glm::vec4(1, 0, 0, 0) ? 0 : 1;
glm::vec4 B = glm::row(m, 1);
Error += B == glm::vec4(0, 1, 0, 0) ? 0 : 1;
glm::vec4 C = glm::row(m, 2);
Error += C == glm::vec4(0, 0, 1, 0) ? 0 : 1;
glm::vec4 D = glm::row(m, 3);
Error += D == glm::vec4(0, 0, 0, 1) ? 0 : 1;
return Error;
}
int test_mat4x4_col_get()
{
int Error = 0;
glm::mat4 m(1);
glm::vec4 A = glm::column(m, 0);
Error += A == glm::vec4(1, 0, 0, 0) ? 0 : 1;
glm::vec4 B = glm::column(m, 1);
Error += B == glm::vec4(0, 1, 0, 0) ? 0 : 1;
glm::vec4 C = glm::column(m, 2);
Error += C == glm::vec4(0, 0, 1, 0) ? 0 : 1;
glm::vec4 D = glm::column(m, 3);
Error += D == glm::vec4(0, 0, 0, 1) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_mat2x2_row_set();
Error += test_mat2x2_col_set();
Error += test_mat2x3_row_set();
Error += test_mat2x3_col_set();
Error += test_mat2x4_row_set();
Error += test_mat2x4_col_set();
Error += test_mat3x2_row_set();
Error += test_mat3x2_col_set();
Error += test_mat3x3_row_set();
Error += test_mat3x3_col_set();
Error += test_mat3x4_row_set();
Error += test_mat3x4_col_set();
Error += test_mat4x2_row_set();
Error += test_mat4x2_col_set();
Error += test_mat4x3_row_set();
Error += test_mat4x3_col_set();
Error += test_mat4x4_row_set();
Error += test_mat4x4_col_set();
Error += test_mat4x4_row_get();
Error += test_mat4x4_col_get();
return Error;
}

View File

@@ -0,0 +1,8 @@
#include <glm/gtc/matrix_integer.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,51 @@
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/epsilon.hpp>
int test_affine()
{
int Error = 0;
{
glm::mat3 const M(
2.f, 0.f, 0.f,
0.f, 2.f, 0.f,
0.f, 0.f, 1.f);
glm::mat3 const A = glm::affineInverse(M);
glm::mat3 const I = glm::inverse(M);
glm::mat3 const R = glm::affineInverse(A);
for(glm::length_t i = 0; i < A.length(); ++i)
{
Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1;
}
}
{
glm::mat4 const M(
2.f, 0.f, 0.f, 0.f,
0.f, 2.f, 0.f, 0.f,
0.f, 0.f, 2.f, 0.f,
0.f, 0.f, 0.f, 1.f);
glm::mat4 const A = glm::affineInverse(M);
glm::mat4 const I = glm::inverse(M);
glm::mat4 const R = glm::affineInverse(A);
for(glm::length_t i = 0; i < A.length(); ++i)
{
Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1;
}
}
return Error;
}
int main()
{
int Error = 0;
Error += test_affine();
return Error;
}

View File

@@ -0,0 +1,54 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/constants.hpp>
int test_perspective()
{
int Error = 0;
glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
return Error;
}
int test_pick()
{
int Error = 0;
glm::mat4 Pick = glm::pickMatrix(glm::vec2(1, 2), glm::vec2(3, 4), glm::ivec4(0, 0, 320, 240));
return Error;
}
int test_tweakedInfinitePerspective()
{
int Error = 0;
glm::mat4 ProjectionA = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f);
glm::mat4 ProjectionB = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f, 0.001f);
return Error;
}
int test_translate()
{
int Error = 0;
glm::lowp_vec3 v(1.0);
glm::lowp_mat4 m(0);
glm::lowp_mat4 t = glm::translate(m, v);
return Error;
}
int main()
{
int Error = 0;
Error += test_translate();
Error += test_tweakedInfinitePerspective();
Error += test_pick();
Error += test_perspective();
return Error;
}

View File

@@ -0,0 +1,48 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/noise.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/raw_data.hpp>
int test_simplex()
{
int Error = 0;
glm::u8vec4 const PixelSimplex2D(glm::byte(glm::abs(glm::simplex(glm::vec2(0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelSimplex3D(glm::byte(glm::abs(glm::simplex(glm::vec3(0.f, 0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelSimplex4D(glm::byte(glm::abs(glm::simplex(glm::vec4(0.f, 0.f, 0.f, 0.f))) * 255.f));
return Error;
}
int test_perlin()
{
int Error = 0;
glm::u8vec4 const PixelPerlin2D(glm::byte(glm::abs(glm::perlin(glm::vec2(0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelPerlin3D(glm::byte(glm::abs(glm::perlin(glm::vec3(0.f, 0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelPerlin4D(glm::byte(glm::abs(glm::perlin(glm::vec4(0.f, 0.f, 0.f, 0.f))) * 255.f));
return Error;
}
int test_perlin_pedioric()
{
int Error = 0;
glm::u8vec4 const PixelPeriodic2D(glm::byte(glm::abs(glm::perlin(glm::vec2(0.f, 0.f), glm::vec2(2.0f))) * 255.f));
glm::u8vec4 const PixelPeriodic3D(glm::byte(glm::abs(glm::perlin(glm::vec3(0.f, 0.f, 0.f), glm::vec3(2.0f))) * 255.f));
glm::u8vec4 const PixelPeriodic4D(glm::byte(glm::abs(glm::perlin(glm::vec4(0.f, 0.f, 0.f, 0.f), glm::vec4(2.0f))) * 255.f));
return Error;
}
int main()
{
int Error = 0;
Error += test_simplex();
Error += test_perlin();
Error += test_perlin_pedioric();
return Error;
}

View File

@@ -0,0 +1,877 @@
#include <glm/packing.hpp>
#include <glm/gtc/packing.hpp>
#include <glm/gtc/epsilon.hpp>
#include <cstdio>
#include <vector>
void print_bits(float const& s)
{
union
{
float f;
unsigned int i;
} uif;
uif.f = s;
printf("f32: ");
for(std::size_t j = sizeof(s) * 8; j > 0; --j)
{
if(j == 23 || j == 31)
printf(" ");
printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0);
}
}
void print_10bits(glm::uint const& s)
{
printf("10b: ");
for(std::size_t j = 10; j > 0; --j)
{
if(j == 5)
printf(" ");
printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
}
}
void print_11bits(glm::uint const& s)
{
printf("11b: ");
for(std::size_t j = 11; j > 0; --j)
{
if(j == 6)
printf(" ");
printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
}
}
void print_value(float const& s)
{
printf("%2.5f, ", static_cast<double>(s));
print_bits(s);
printf(", ");
// print_11bits(detail::floatTo11bit(s));
// printf(", ");
// print_10bits(detail::floatTo10bit(s));
printf("\n");
}
int test_Half1x16()
{
int Error = 0;
std::vector<float> Tests;
Tests.push_back(0.0f);
Tests.push_back(1.0f);
Tests.push_back(-1.0f);
Tests.push_back(2.0f);
Tests.push_back(-2.0f);
Tests.push_back(1.9f);
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
float v0 = glm::unpackHalf1x16(p0);
glm::uint16 p1 = glm::packHalf1x16(v0);
float v1 = glm::unpackHalf1x16(p1);
Error += glm::epsilonEqual(v0, v1, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
int test_Half4x16()
{
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0f));
Tests.push_back(glm::vec4(0.0f));
Tests.push_back(glm::vec4(2.0f));
Tests.push_back(glm::vec4(0.1f));
Tests.push_back(glm::vec4(0.5f));
Tests.push_back(glm::vec4(-0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint64 p0 = glm::packHalf4x16(Tests[i]);
glm::vec4 v0 = glm::unpackHalf4x16(p0);
glm::uint64 p1 = glm::packHalf4x16(v0);
glm::vec4 v1 = glm::unpackHalf4x16(p1);
glm::u16vec4 p2 = glm::packHalf(v0);
glm::vec4 v2 = glm::unpackHalf(p2);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
Error += glm::all(glm::equal(v0, v2)) ? 0 : 1;
}
return Error;
}
int test_I3x10_1x2()
{
int Error = 0;
std::vector<glm::ivec4> Tests;
Tests.push_back(glm::ivec4(0));
Tests.push_back(glm::ivec4(1));
Tests.push_back(glm::ivec4(-1));
Tests.push_back(glm::ivec4(2));
Tests.push_back(glm::ivec4(-2));
Tests.push_back(glm::ivec4(3));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packI3x10_1x2(Tests[i]);
glm::ivec4 v0 = glm::unpackI3x10_1x2(p0);
glm::uint32 p1 = glm::packI3x10_1x2(v0);
glm::ivec4 v1 = glm::unpackI3x10_1x2(p1);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
return Error;
}
int test_U3x10_1x2()
{
int Error = 0;
std::vector<glm::uvec4> Tests;
Tests.push_back(glm::uvec4(0));
Tests.push_back(glm::uvec4(1));
Tests.push_back(glm::uvec4(2));
Tests.push_back(glm::uvec4(3));
Tests.push_back(glm::uvec4(4));
Tests.push_back(glm::uvec4(5));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]);
glm::uvec4 v0 = glm::unpackU3x10_1x2(p0);
glm::uint32 p1 = glm::packU3x10_1x2(v0);
glm::uvec4 v1 = glm::unpackU3x10_1x2(p1);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
glm::u8vec4 const v0(0xff, 0x77, 0x0, 0x33);
glm::uint32 const p0 = *reinterpret_cast<glm::uint32 const*>(&v0[0]);
glm::uint32 const r0 = 0x330077ff;
Error += p0 == r0 ? 0 : 1;
glm::uvec4 const v1(0xff, 0x77, 0x0, 0x33);
glm::uint32 const p1 = glm::packU3x10_1x2(v1);
glm::uint32 const r1 = 0xc001dcff;
Error += p1 == r1 ? 0 : 1;
return Error;
}
int test_Snorm3x10_1x2()
{
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0f));
Tests.push_back(glm::vec4(0.0f));
Tests.push_back(glm::vec4(2.0f));
Tests.push_back(glm::vec4(0.1f));
Tests.push_back(glm::vec4(0.5f));
Tests.push_back(glm::vec4(0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]);
glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0);
glm::uint32 p1 = glm::packSnorm3x10_1x2(v0);
glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1);
Error += glm::all(glm::epsilonEqual(v0, v1, 0.01f)) ? 0 : 1;
}
return Error;
}
int test_Unorm3x10_1x2()
{
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0f));
Tests.push_back(glm::vec4(0.0f));
Tests.push_back(glm::vec4(2.0f));
Tests.push_back(glm::vec4(0.1f));
Tests.push_back(glm::vec4(0.5f));
Tests.push_back(glm::vec4(0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packUnorm3x10_1x2(Tests[i]);
glm::vec4 v0 = glm::unpackUnorm3x10_1x2(p0);
glm::uint32 p1 = glm::packUnorm3x10_1x2(v0);
glm::vec4 v1 = glm::unpackUnorm3x10_1x2(p1);
Error += glm::all(glm::epsilonEqual(v0, v1, 0.001f)) ? 0 : 1;
}
return Error;
}
int test_F2x11_1x10()
{
int Error = 0;
std::vector<glm::vec3> Tests;
Tests.push_back(glm::vec3(1.0f));
Tests.push_back(glm::vec3(0.0f));
Tests.push_back(glm::vec3(2.0f));
Tests.push_back(glm::vec3(0.1f));
Tests.push_back(glm::vec3(0.5f));
Tests.push_back(glm::vec3(0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]);
glm::vec3 v0 = glm::unpackF2x11_1x10(p0);
glm::uint32 p1 = glm::packF2x11_1x10(v0);
glm::vec3 v1 = glm::unpackF2x11_1x10(p1);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
return Error;
}
int test_F3x9_E1x5()
{
int Error = 0;
std::vector<glm::vec3> Tests;
Tests.push_back(glm::vec3(1.0f));
Tests.push_back(glm::vec3(0.0f));
Tests.push_back(glm::vec3(2.0f));
Tests.push_back(glm::vec3(0.1f));
Tests.push_back(glm::vec3(0.5f));
Tests.push_back(glm::vec3(0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packF3x9_E1x5(Tests[i]);
glm::vec3 v0 = glm::unpackF3x9_E1x5(p0);
glm::uint32 p1 = glm::packF3x9_E1x5(v0);
glm::vec3 v1 = glm::unpackF3x9_E1x5(p1);
Error += glm::all(glm::epsilonEqual(v0, v1, 0.01f)) ? 0 : 1;
}
return Error;
}
int test_RGBM()
{
int Error = 0;
for(std::size_t i = 0; i < 1024; ++i)
{
glm::vec3 const Color(static_cast<float>(i));
glm::vec4 const RGBM = glm::packRGBM(Color);
glm::vec3 const Result= glm::unpackRGBM(RGBM);
Error += glm::all(glm::epsilonEqual(Color, Result, 0.01f)) ? 0 : 1;
}
return Error;
}
int test_packUnorm1x16()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1(1.0f));
A.push_back(glm::vec1(0.5f));
A.push_back(glm::vec1(0.1f));
A.push_back(glm::vec1(0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint16 C = glm::packUnorm1x16(B.x);
glm::vec1 D(glm::unpackUnorm1x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm1x16()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1( 1.0f));
A.push_back(glm::vec1( 0.0f));
A.push_back(glm::vec1(-0.5f));
A.push_back(glm::vec1(-0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint16 C = glm::packSnorm1x16(B.x);
glm::vec1 D(glm::unpackSnorm1x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
}
return Error;
}
int test_packUnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.0f));
A.push_back(glm::vec2(0.5f, 0.7f));
A.push_back(glm::vec2(0.1f, 0.2f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packUnorm2x16(B);
glm::vec2 D = glm::unpackUnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 0.0f));
A.push_back(glm::vec2(-0.5f,-0.7f));
A.push_back(glm::vec2(-0.1f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packSnorm2x16(B);
glm::vec2 D = glm::unpackSnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm4x16()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4(1.0f));
A.push_back(glm::vec4(0.5f));
A.push_back(glm::vec4(0.1f));
A.push_back(glm::vec4(0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint64 C = glm::packUnorm4x16(B);
glm::vec4 D(glm::unpackUnorm4x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm4x16()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4( 1.0f, 0.0f, -0.5f, 0.5f));
A.push_back(glm::vec4(-0.3f,-0.7f, 0.3f, 0.7f));
A.push_back(glm::vec4(-0.1f, 0.1f, -0.2f, 0.2f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint64 C = glm::packSnorm4x16(B);
glm::vec4 D(glm::unpackSnorm4x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm1x8()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1(1.0f));
A.push_back(glm::vec1(0.5f));
A.push_back(glm::vec1(0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint8 C = glm::packUnorm1x8(B.x);
glm::vec1 D(glm::unpackUnorm1x8(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm1x8()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1( 1.0f));
A.push_back(glm::vec1(-0.7f));
A.push_back(glm::vec1(-1.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint8 C = glm::packSnorm1x8(B.x);
glm::vec1 D(glm::unpackSnorm1x8(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
}
return Error;
}
int test_packUnorm2x8()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.7f));
A.push_back(glm::vec2(0.5f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint16 C = glm::packUnorm2x8(B);
glm::vec2 D = glm::unpackUnorm2x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm2x8()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 0.0f));
A.push_back(glm::vec2(-0.7f,-0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint16 C = glm::packSnorm2x8(B);
glm::vec2 D = glm::unpackSnorm2x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
}
return Error;
}
int test_packUnorm4x8()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint32 C = glm::packUnorm4x8(B);
glm::vec4 D = glm::unpackUnorm4x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm4x8()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint32 C = glm::packSnorm4x8(B);
glm::vec4 D = glm::unpackSnorm4x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.7f));
A.push_back(glm::vec2(0.5f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::u16vec2 C = glm::packUnorm<glm::uint16>(B);
glm::vec2 D = glm::unpackUnorm<float>(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packSnorm()
{
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::i16vec2 C = glm::packSnorm<glm::int16>(B);
glm::vec2 D = glm::unpackSnorm<float>(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm2x4()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.7f));
A.push_back(glm::vec2(0.5f, 0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint8 C = glm::packUnorm2x4(B);
glm::vec2 D = glm::unpackUnorm2x4(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm4x4()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint16 C = glm::packUnorm4x4(B);
glm::vec4 D = glm::unpackUnorm4x4(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm3x5_1x1()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint16 C = glm::packUnorm3x5_1x1(B);
glm::vec4 D = glm::unpackUnorm3x5_1x1(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm1x5_1x6_1x5()
{
int Error = 0;
std::vector<glm::vec3> A;
A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec3 B(A[i]);
glm::uint16 C = glm::packUnorm1x5_1x6_1x5(B);
glm::vec3 D = glm::unpackUnorm1x5_1x6_1x5(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUnorm2x3_1x2()
{
int Error = 0;
std::vector<glm::vec3> A;
A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec3 B(A[i]);
glm::uint8 C = glm::packUnorm2x3_1x2(B);
glm::vec3 D = glm::unpackUnorm2x3_1x2(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 3.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_packUint2x8()
{
int Error = 0;
glm::u8vec2 const Source(1, 2);
glm::uint16 const Packed = glm::packUint2x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packUint4x8()
{
int Error = 0;
glm::u8vec4 const Source(1, 2, 3, 4);
glm::uint32 const Packed = glm::packUint4x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packUint2x16()
{
int Error = 0;
glm::u16vec2 const Source(1, 2);
glm::uint32 const Packed = glm::packUint2x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packUint4x16()
{
int Error = 0;
glm::u16vec4 const Source(1, 2, 3, 4);
glm::uint64 const Packed = glm::packUint4x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packUint2x32()
{
int Error = 0;
glm::u32vec2 const Source(1, 2);
glm::uint64 const Packed = glm::packUint2x32(Source);
Error += Packed != 0 ? 0 : 1;
glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packInt2x8()
{
int Error = 0;
glm::i8vec2 const Source(1, 2);
glm::int16 const Packed = glm::packInt2x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packInt4x8()
{
int Error = 0;
glm::i8vec4 const Source(1, 2, 3, 4);
glm::int32 const Packed = glm::packInt4x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packInt2x16()
{
int Error = 0;
glm::i16vec2 const Source(1, 2);
glm::int32 const Packed = glm::packInt2x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packInt4x16()
{
int Error = 0;
glm::i16vec4 const Source(1, 2, 3, 4);
glm::int64 const Packed = glm::packInt4x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int test_packInt2x32()
{
int Error = 0;
glm::i32vec2 const Source(1, 2);
glm::int64 const Packed = glm::packInt2x32(Source);
Error += Packed != 0 ? 0 : 1;
glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_packUnorm();
Error += test_packSnorm();
Error += test_packSnorm1x16();
Error += test_packSnorm2x16();
Error += test_packSnorm4x16();
Error += test_packSnorm1x8();
Error += test_packSnorm2x8();
Error += test_packSnorm4x8();
Error += test_packUnorm1x16();
Error += test_packUnorm2x16();
Error += test_packUnorm4x16();
Error += test_packUnorm1x8();
Error += test_packUnorm2x8();
Error += test_packUnorm4x8();
Error += test_packUnorm2x4();
Error += test_packUnorm4x4();
Error += test_packUnorm3x5_1x1();
Error += test_packUnorm1x5_1x6_1x5();
Error += test_packUnorm2x3_1x2();
Error += test_packUint2x8();
Error += test_packUint4x8();
Error += test_packUint2x16();
Error += test_packUint4x16();
Error += test_packUint2x32();
Error += test_packInt2x8();
Error += test_packInt4x8();
Error += test_packInt2x16();
Error += test_packInt4x16();
Error += test_packInt2x32();
Error += test_F2x11_1x10();
Error += test_F3x9_E1x5();
Error += test_RGBM();
Error += test_Unorm3x10_1x2();
Error += test_Snorm3x10_1x2();
Error += test_I3x10_1x2();
Error += test_U3x10_1x2();
Error += test_Half1x16();
Error += test_Half4x16();
return Error;
}

View File

@@ -0,0 +1,328 @@
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <vector>
int test_quat_angle()
{
int Error = 0;
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::epsilonEqual(A, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::normalize(glm::vec3(0, 1, 1)));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::epsilonEqual(A, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::normalize(glm::vec3(1, 2, 3)));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::epsilonEqual(A, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
}
return Error;
}
int test_quat_angleAxis()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.f, glm::vec3(0.f, 0.f, 1.f));
glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_quat_mix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.f, glm::vec3(0.f, 0.f, 1.f));
glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_quat_precision()
{
int Error = 0;
Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1;
Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1;
return Error;
}
int test_quat_normalize()
{
int Error(0);
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.000001f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 2));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.000001f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(1, 2, 3));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::epsilonEqual(L, 1.0f, 0.000001f) ? 0 : 1;
}
return Error;
}
int test_quat_euler()
{
int Error = 0;
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float Roll = glm::roll(q);
float Pitch = glm::pitch(q);
float Yaw = glm::yaw(q);
glm::vec3 Angles = glm::eulerAngles(q);
Error += glm::all(glm::epsilonEqual(Angles, glm::vec3(Pitch, Yaw, Roll), 0.000001f)) ? 0 : 1;
}
{
glm::dquat q(1.0, 0.0, 0.0, 1.0);
double Roll = glm::roll(q);
double Pitch = glm::pitch(q);
double Yaw = glm::yaw(q);
glm::dvec3 Angles = glm::eulerAngles(q);
Error += glm::all(glm::epsilonEqual(Angles, glm::dvec3(Pitch, Yaw, Roll), 0.000001)) ? 0 : 1;
}
return Error;
}
int test_quat_slerp()
{
int Error = 0;
float const Epsilon = 0.0001f;//glm::epsilon<float>();
float sqrt2 = std::sqrt(2.0f)/2.0f;
glm::quat id(static_cast<float>(1), static_cast<float>(0), static_cast<float>(0), static_cast<float>(0));
glm::quat Y90rot(sqrt2, 0.0f, sqrt2, 0.0f);
glm::quat Y180rot(0.0f, 0.0f, 1.0f, 0.0f);
// Testing a == 0
// Must be id
glm::quat id2 = glm::slerp(id, Y90rot, 0.0f);
Error += glm::all(glm::epsilonEqual(id, id2, Epsilon)) ? 0 : 1;
// Testing a == 1
// Must be 90° rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot2 = glm::slerp(id, Y90rot, 1.0f);
Error += glm::all(glm::epsilonEqual(Y90rot, Y90rot2, Epsilon)) ? 0 : 1;
// Testing standard, easy case
// Must be 45° rotation on Y : 0 0.38 0 0.92
glm::quat Y45rot1 = glm::slerp(id, Y90rot, 0.5f);
// Testing reverse case
// Must be 45° rotation on Y : 0 0.38 0 0.92
glm::quat Ym45rot2 = glm::slerp(Y90rot, id, 0.5f);
// Testing against full circle around the sphere instead of shortest path
// Must be 45° rotation on Y
// certainly not a 135° rotation
glm::quat Y45rot3 = glm::slerp(id , -Y90rot, 0.5f);
float Y45angle3 = glm::angle(Y45rot3);
Error += glm::epsilonEqual(Y45angle3, glm::pi<float>() * 0.25f, Epsilon) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Ym45rot2, Y45rot3, Epsilon)) ? 0 : 1;
// Same, but inverted
// Must also be 45° rotation on Y : 0 0.38 0 0.92
// -0 -0.38 -0 -0.92 is ok too
glm::quat Y45rot4 = glm::slerp(-Y90rot, id, 0.5f);
Error += glm::all(glm::epsilonEqual(Ym45rot2, -Y45rot4, Epsilon)) ? 0 : 1;
// Testing q1 = q2
// Must be 90° rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot3 = glm::slerp(Y90rot, Y90rot, 0.5f);
Error += glm::all(glm::epsilonEqual(Y90rot, Y90rot3, Epsilon)) ? 0 : 1;
// Testing 180° rotation
// Must be 90° rotation on almost any axis that is on the XZ plane
glm::quat XZ90rot = glm::slerp(id, -Y90rot, 0.5f);
float XZ90angle = glm::angle(XZ90rot); // Must be PI/4 = 0.78;
Error += glm::epsilonEqual(XZ90angle, glm::pi<float>() * 0.25f, Epsilon) ? 0 : 1;
// Testing almost equal quaternions (this test should pass through the linear interpolation)
// Must be 0 0.00X 0 0.99999
glm::quat almostid = glm::slerp(id, glm::angleAxis(0.1f, glm::vec3(0.0f, 1.0f, 0.0f)), 0.5f);
// Testing quaternions with opposite sign
{
glm::quat a(-1, 0, 0, 0);
glm::quat result = glm::slerp(a, id, 0.5f);
Error += glm::epsilonEqual(glm::pow(glm::dot(id, result), 2.f), 1.f, 0.01f) ? 0 : 1;
}
return Error;
}
int test_quat_mul()
{
int Error(0);
glm::quat temp1 = glm::normalize(glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0)));
glm::quat temp2 = glm::normalize(glm::quat(0.5f, glm::vec3(1.0, 0.0, 0.0)));
glm::vec3 transformed0 = (temp1 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp1));
glm::vec3 temp4 = temp2 * transformed0 * glm::inverse(temp2);
glm::quat temp5 = glm::normalize(temp1 * temp2);
glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5);
glm::quat temp7(1.0f, glm::vec3(0.0, 1.0, 0.0));
temp7 *= temp5;
temp7 *= glm::inverse(temp5);
Error += temp7 != glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0));
return Error;
}
int test_quat_two_axis_ctr()
{
int Error = 0;
glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0);
Error += glm::all(glm::epsilonEqual(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q2 = q1 * q1;
glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0);
Error += glm::all(glm::epsilonEqual(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0));
glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0);
Error += glm::all(glm::epsilonEqual(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0));
glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0);
Error += glm::all(glm::epsilonEqual(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1;
glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1));
glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1);
Error += glm::all(glm::epsilonEqual(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1;
return Error;
}
int test_quat_mul_vec()
{
int Error(0);
glm::quat q = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::vec3 v(1, 0, 0);
glm::vec3 u(q * v);
glm::vec3 w(u * q);
Error += glm::all(glm::epsilonEqual(v, w, 0.01f)) ? 0 : 1;
return Error;
}
int test_quat_ctr()
{
int Error(0);
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::dquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::dquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::quat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::quat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::dquat>::value ? 0 : 1;
# endif
# if GLM_HAS_INITIALIZER_LISTS
{
glm::quat A{0, 1, 2, 3};
std::vector<glm::quat> B{
{0, 1, 2, 3},
{0, 1, 2, 3}};
}
# endif//GLM_HAS_INITIALIZER_LISTS
return Error;
}
int test_size()
{
int Error = 0;
Error += 16 == sizeof(glm::quat) ? 0 : 1;
Error += 32 == sizeof(glm::dquat) ? 0 : 1;
Error += glm::quat().length() == 4 ? 0 : 1;
Error += glm::dquat().length() == 4 ? 0 : 1;
Error += glm::quat::length() == 4 ? 0 : 1;
Error += glm::dquat::length() == 4 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_quat_ctr();
Error += test_quat_mul_vec();
Error += test_quat_two_axis_ctr();
Error += test_quat_mul();
Error += test_quat_precision();
Error += test_quat_angle();
Error += test_quat_angleAxis();
Error += test_quat_mix();
Error += test_quat_normalize();
Error += test_quat_euler();
Error += test_quat_slerp();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,380 @@
#define GLM_FORCE_ALIGNED
#include <glm/gtc/random.hpp>
#include <glm/gtc/epsilon.hpp>
#if GLM_LANG & GLM_LANG_CXX0X_FLAG
# include <array>
#endif
std::size_t const TestSamples = 10000;
int test_linearRand()
{
int Error = 0;
glm::int32 const Min = 16;
glm::int32 const Max = 32;
{
glm::u8vec2 AMin(std::numeric_limits<glm::u8>::max());
glm::u8vec2 AMax(std::numeric_limits<glm::u8>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u8vec2 A = glm::linearRand(glm::u8vec2(Min), glm::u8vec2(Max));
AMin = glm::min(AMin, A);
AMax = glm::max(AMax, A);
if(!glm::all(glm::lessThanEqual(A, glm::u8vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::u8vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(AMin, glm::u8vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(AMax, glm::u8vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u16vec2 BMin(std::numeric_limits<glm::u16>::max());
glm::u16vec2 BMax(std::numeric_limits<glm::u16>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u16vec2 B = glm::linearRand(glm::u16vec2(Min), glm::u16vec2(Max));
BMin = glm::min(BMin, B);
BMax = glm::max(BMax, B);
if(!glm::all(glm::lessThanEqual(B, glm::u16vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::u16vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(BMin, glm::u16vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(BMax, glm::u16vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u32vec2 CMin(std::numeric_limits<glm::u32>::max());
glm::u32vec2 CMax(std::numeric_limits<glm::u32>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u32vec2 C = glm::linearRand(glm::u32vec2(Min), glm::u32vec2(Max));
CMin = glm::min(CMin, C);
CMax = glm::max(CMax, C);
if(!glm::all(glm::lessThanEqual(C, glm::u32vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(C, glm::u32vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(CMin, glm::u32vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(CMax, glm::u32vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u64vec2 DMin(std::numeric_limits<glm::u64>::max());
glm::u64vec2 DMax(std::numeric_limits<glm::u64>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u64vec2 D = glm::linearRand(glm::u64vec2(Min), glm::u64vec2(Max));
DMin = glm::min(DMin, D);
DMax = glm::max(DMax, D);
if(!glm::all(glm::lessThanEqual(D, glm::u64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(D, glm::u64vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(DMin, glm::u64vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(DMax, glm::u64vec2(Max))) ? 0 : 1;
assert(!Error);
}
}
{
glm::i8vec2 AMin(std::numeric_limits<glm::i8>::max());
glm::i8vec2 AMax(std::numeric_limits<glm::i8>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i8vec2 A = glm::linearRand(glm::i8vec2(Min), glm::i8vec2(Max));
AMin = glm::min(AMin, A);
AMax = glm::max(AMax, A);
if(!glm::all(glm::lessThanEqual(A, glm::i8vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::i8vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(AMin, glm::i8vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(AMax, glm::i8vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i16vec2 BMin(std::numeric_limits<glm::i16>::max());
glm::i16vec2 BMax(std::numeric_limits<glm::i16>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i16vec2 B = glm::linearRand(glm::i16vec2(Min), glm::i16vec2(Max));
BMin = glm::min(BMin, B);
BMax = glm::max(BMax, B);
if(!glm::all(glm::lessThanEqual(B, glm::i16vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::i16vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(BMin, glm::i16vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(BMax, glm::i16vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i32vec2 CMin(std::numeric_limits<glm::i32>::max());
glm::i32vec2 CMax(std::numeric_limits<glm::i32>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i32vec2 C = glm::linearRand(glm::i32vec2(Min), glm::i32vec2(Max));
CMin = glm::min(CMin, C);
CMax = glm::max(CMax, C);
if(!glm::all(glm::lessThanEqual(C, glm::i32vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(C, glm::i32vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(CMin, glm::i32vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(CMax, glm::i32vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i64vec2 DMin(std::numeric_limits<glm::i64>::max());
glm::i64vec2 DMax(std::numeric_limits<glm::i64>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i64vec2 D = glm::linearRand(glm::i64vec2(Min), glm::i64vec2(Max));
DMin = glm::min(DMin, D);
DMax = glm::max(DMax, D);
if(!glm::all(glm::lessThanEqual(D, glm::i64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(D, glm::i64vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(DMin, glm::i64vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(DMax, glm::i64vec2(Max))) ? 0 : 1;
assert(!Error);
}
}
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::f32vec2 const A(glm::linearRand(glm::f32vec2(static_cast<float>(Min)), glm::f32vec2(static_cast<float>(Max))));
if(!glm::all(glm::lessThanEqual(A, glm::f32vec2(static_cast<float>(Max)))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::f32vec2(static_cast<float>(Min)))))
++Error;
glm::f64vec2 const B(glm::linearRand(glm::f64vec2(Min), glm::f64vec2(Max)));
if(!glm::all(glm::lessThanEqual(B, glm::f64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::f64vec2(Min))))
++Error;
assert(!Error);
}
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::linearRand(-1.0f, 1.0f);
ResultDouble += glm::linearRand(-1.0, 1.0);
}
Error += glm::epsilonEqual(ResultFloat, 0.0f, 0.0001f);
Error += glm::epsilonEqual(ResultDouble, 0.0, 0.0001);
assert(!Error);
}
return Error;
}
int test_circularRand()
{
int Error = 0;
{
std::size_t Max = TestSamples;
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
double Radius = 2.0;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloat += glm::length(glm::circularRand(1.0f));
ResultDouble += glm::length(glm::circularRand(Radius));
}
Error += glm::epsilonEqual(ResultFloat, float(Max), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDouble, double(Max) * double(Radius), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_sphericalRand()
{
int Error = 0;
{
std::size_t Max = TestSamples;
float ResultFloatA = 0.0f;
float ResultFloatB = 0.0f;
float ResultFloatC = 0.0f;
double ResultDoubleA = 0.0;
double ResultDoubleB = 0.0;
double ResultDoubleC = 0.0;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloatA += glm::length(glm::sphericalRand(1.0f));
ResultDoubleA += glm::length(glm::sphericalRand(1.0));
ResultFloatB += glm::length(glm::sphericalRand(2.0f));
ResultDoubleB += glm::length(glm::sphericalRand(2.0));
ResultFloatC += glm::length(glm::sphericalRand(3.0f));
ResultDoubleC += glm::length(glm::sphericalRand(3.0));
}
Error += glm::epsilonEqual(ResultFloatA, float(Max), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
Error += glm::epsilonEqual(ResultFloatB, float(Max * 2), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
Error += glm::epsilonEqual(ResultFloatC, float(Max * 3), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleC, double(Max * 3), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_diskRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::diskRand(2.0f));
ResultDouble += glm::length(glm::diskRand(2.0));
}
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}
return Error;
}
int test_ballRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::ballRand(2.0f));
ResultDouble += glm::length(glm::ballRand(2.0));
}
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}
return Error;
}
/*
#if(GLM_LANG & GLM_LANG_CXX0X_FLAG)
int test_grid()
{
int Error = 0;
typedef std::array<int, 8> colors;
typedef std::array<int, 8 * 8> grid;
grid Grid;
colors Colors;
grid GridBest;
colors ColorsBest;
while(true)
{
for(std::size_t i = 0; i < Grid.size(); ++i)
Grid[i] = int(glm::linearRand(0.0, 8.0 * 8.0 * 8.0 - 1.0) / 64.0);
for(std::size_t i = 0; i < Grid.size(); ++i)
++Colors[Grid[i]];
bool Exit = true;
for(std::size_t i = 0; i < Colors.size(); ++i)
{
if(Colors[i] == 8)
continue;
Exit = false;
break;
}
if(Exit == true)
break;
}
return Error;
}
#endif
*/
int main()
{
int Error = 0;
Error += test_linearRand();
Error += test_circularRand();
Error += test_sphericalRand();
Error += test_diskRand();
Error += test_ballRand();
/*
#if(GLM_LANG & GLM_LANG_CXX0X_FLAG)
Error += test_grid();
#endif
*/
return Error;
}

View File

@@ -0,0 +1,8 @@
#include <glm/gtc/reciprocal.hpp>
#include <ctime>
int main()
{
return 0;
}

View File

@@ -0,0 +1,458 @@
#include <glm/gtc/round.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
#include <vector>
#include <ctime>
#include <cstdio>
namespace isPowerOfTwo
{
template<typename genType>
struct type
{
genType Value;
bool Return;
};
int test_int16()
{
type<glm::int16> const Data[] =
{
{0x0001, true},
{0x0002, true},
{0x0004, true},
{0x0080, true},
{0x0000, true},
{0x0003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test_uint16()
{
type<glm::uint16> const Data[] =
{
{0x0001, true},
{0x0002, true},
{0x0004, true},
{0x0000, true},
{0x0000, true},
{0x0003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test_int32()
{
type<int> const Data[] =
{
{0x00000001, true},
{0x00000002, true},
{0x00000004, true},
{0x0000000f, false},
{0x00000000, true},
{0x00000003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec1 Result = glm::isPowerOfTwo(glm::ivec1(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec1(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec2 Result = glm::isPowerOfTwo(glm::ivec2(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec2(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec3 Result = glm::isPowerOfTwo(glm::ivec3(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec3(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec4 Result = glm::isPowerOfTwo(glm::ivec4(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec4(Data[i].Return), Result)) ? 0 : 1;
}
return Error;
}
int test_uint32()
{
type<glm::uint> const Data[] =
{
{0x00000001, true},
{0x00000002, true},
{0x00000004, true},
{0x80000000, true},
{0x00000000, true},
{0x00000003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_int16();
Error += test_uint16();
Error += test_int32();
Error += test_uint32();
return Error;
}
}//isPowerOfTwo
namespace ceilPowerOfTwo_advanced
{
template<typename genIUType>
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
{
genIUType tmp = Value;
genIUType result = genIUType(0);
while(tmp)
{
result = (tmp & (~tmp + 1)); // grab lowest bit
tmp &= ~result; // clear lowest bit
}
return result;
}
template<typename genType>
GLM_FUNC_QUALIFIER genType ceilPowerOfTwo_loop(genType value)
{
return glm::isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
}
template<typename genType>
struct type
{
genType Value;
genType Return;
};
int test_int32()
{
type<glm::int32> const Data[] =
{
{0x0000ffff, 0x00010000},
{-3, -4},
{-8, -8},
{0x00000001, 0x00000001},
{0x00000002, 0x00000002},
{0x00000004, 0x00000004},
{0x00000007, 0x00000008},
{0x0000fff0, 0x00010000},
{0x0000f000, 0x00010000},
{0x08000000, 0x08000000},
{0x00000000, 0x00000000},
{0x00000003, 0x00000004}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int32>); i < n; ++i)
{
glm::int32 Result = glm::ceilPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test_uint32()
{
type<glm::uint32> const Data[] =
{
{0x00000001, 0x00000001},
{0x00000002, 0x00000002},
{0x00000004, 0x00000004},
{0x00000007, 0x00000008},
{0x0000ffff, 0x00010000},
{0x0000fff0, 0x00010000},
{0x0000f000, 0x00010000},
{0x80000000, 0x80000000},
{0x00000000, 0x00000000},
{0x00000003, 0x00000004}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint32>); i < n; ++i)
{
glm::uint32 Result = glm::ceilPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int perf()
{
int Error(0);
std::vector<glm::uint> v;
v.resize(100000000);
std::clock_t Timestramp0 = std::clock();
for(glm::uint32 i = 0, n = static_cast<glm::uint>(v.size()); i < n; ++i)
v[i] = ceilPowerOfTwo_loop(i);
std::clock_t Timestramp1 = std::clock();
for(glm::uint32 i = 0, n = static_cast<glm::uint>(v.size()); i < n; ++i)
v[i] = glm::ceilPowerOfTwo(i);
std::clock_t Timestramp2 = std::clock();
std::printf("ceilPowerOfTwo_loop: %d clocks\n", static_cast<unsigned int>(Timestramp1 - Timestramp0));
std::printf("glm::ceilPowerOfTwo: %d clocks\n", static_cast<unsigned int>(Timestramp2 - Timestramp1));
return Error;
}
int test()
{
int Error(0);
Error += test_int32();
Error += test_uint32();
return Error;
}
}//namespace ceilPowerOfTwo_advanced
namespace roundPowerOfTwo
{
int test()
{
int Error = 0;
glm::uint32 const A = glm::roundPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::roundPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::roundPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
glm::uint32 const D = glm::roundPowerOfTwo(9u);
Error += D == 8u ? 0 : 1;
glm::uint32 const E = glm::roundPowerOfTwo(17u);
Error += E == 16u ? 0 : 1;
glm::uint32 const F = glm::roundPowerOfTwo(33u);
Error += F == 32u ? 0 : 1;
return Error;
}
}//namespace roundPowerOfTwo
namespace floorPowerOfTwo
{
int test()
{
int Error = 0;
glm::uint32 const A = glm::floorPowerOfTwo(7u);
Error += A == 4u ? 0 : 1;
glm::uint32 const B = glm::floorPowerOfTwo(15u);
Error += B == 8u ? 0 : 1;
glm::uint32 const C = glm::floorPowerOfTwo(31u);
Error += C == 16u ? 0 : 1;
return Error;
}
}//namespace floorPowerOfTwo
namespace ceilPowerOfTwo
{
int test()
{
int Error = 0;
glm::uint32 const A = glm::ceilPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::ceilPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::ceilPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
return Error;
}
}//namespace ceilPowerOfTwo
namespace floorMultiple
{
template<typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.3, 0.0001},
{-1.4, 0.3, -1.5, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::floorMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_float();
return Error;
}
}//namespace floorMultiple
namespace ceilMultiple
{
template<typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.6, 0.0001},
{-1.4, 0.3, -1.2, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
int test_int()
{
type<int> const Data[] =
{
{3, 4, 4, 0},
{7, 4, 8, 0},
{5, 4, 8, 0},
{1, 4, 4, 0},
{1, 3, 3, 0},
{4, 3, 6, 0},
{4, 1, 4, 0},
{1, 1, 1, 0},
{7, 1, 7, 0},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
int Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_int();
Error += test_float();
return Error;
}
}//namespace ceilMultiple
int main()
{
int Error(0);
Error += isPowerOfTwo::test();
Error += floorPowerOfTwo::test();
Error += roundPowerOfTwo::test();
Error += ceilPowerOfTwo::test();
Error += ceilPowerOfTwo_advanced::test();
# ifdef NDEBUG
Error += ceilPowerOfTwo_advanced::perf();
# endif//NDEBUG
Error += floorMultiple::test();
Error += ceilMultiple::test();
return Error;
}

View File

@@ -0,0 +1,146 @@
#define GLM_FORCE_MESSAGES
#include <glm/glm.hpp>
#if GLM_HAS_ALIGNED_TYPE
#include <glm/gtc/type_aligned.hpp>
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_lowp>::value, "aligned_lowp is not aligned");
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_mediump>::value, "aligned_mediump is not aligned");
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_highp>::value, "aligned_highp is not aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_highp>::value, "packed_highp is aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_mediump>::value, "packed_mediump is aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_lowp>::value, "packed_lowp is aligned");
struct my_vec4_packed
{
glm::uint32 a;
glm::vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_vec4_packed) == sizeof(glm::uint32) + sizeof(glm::vec4), "glm::vec4 packed is not correct");
struct my_vec4_aligned
{
glm::uint32 a;
glm::aligned_vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_vec4_aligned) == sizeof(glm::aligned_vec4) * 2, "glm::vec4 aligned is not correct");
struct my_dvec4_packed
{
glm::uint64 a;
glm::dvec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_dvec4_packed) == sizeof(glm::uint64) + sizeof(glm::dvec4), "glm::dvec4 packed is not correct");
struct my_dvec4_aligned
{
glm::uint64 a;
glm::aligned_dvec4 b;
};
//GLM_STATIC_ASSERT(sizeof(my_dvec4_aligned) == sizeof(glm::aligned_dvec4) * 2, "glm::dvec4 aligned is not correct");
struct my_ivec4_packed
{
glm::uint32 a;
glm::ivec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_ivec4_packed) == sizeof(glm::uint32) + sizeof(glm::ivec4), "glm::ivec4 packed is not correct");
struct my_ivec4_aligned
{
glm::uint32 a;
glm::aligned_ivec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_ivec4_aligned) == sizeof(glm::aligned_ivec4) * 2, "glm::ivec4 aligned is not correct");
struct my_u8vec4_packed
{
glm::uint32 a;
glm::u8vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_u8vec4_packed) == sizeof(glm::uint32) + sizeof(glm::u8vec4), "glm::u8vec4 packed is not correct");
static int test_copy()
{
int Error = 0;
{
glm::aligned_ivec4 const a(1, 2, 3, 4);
glm::ivec4 const u(a);
Error += a.x == u.x ? 0 : 1;
Error += a.y == u.y ? 0 : 1;
Error += a.z == u.z ? 0 : 1;
Error += a.w == u.w ? 0 : 1;
}
{
my_ivec4_aligned a;
a.b = glm::ivec4(1, 2, 3, 4);
my_ivec4_packed u;
u.b = a.b;
Error += a.b.x == u.b.x ? 0 : 1;
Error += a.b.y == u.b.y ? 0 : 1;
Error += a.b.z == u.b.z ? 0 : 1;
Error += a.b.w == u.b.w ? 0 : 1;
}
return Error;
}
static int test_ctor()
{
int Error = 0;
# if GLM_HAS_CONSTEXPR && GLM_ARCH == GLM_ARCH_PURE
{
constexpr glm::aligned_ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
{
constexpr glm::packed_ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
{
constexpr glm::ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
# endif
return Error;
}
int main()
{
int Error = 0;
Error += test_ctor();
Error += test_copy();
return Error;
}
#else
int main()
{
return 0;
}
#endif//GLM_HAS_ALIGNED_TYPE

View File

@@ -0,0 +1,912 @@
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/quaternion.hpp>
#include <vector>
#if GLM_HAS_OPENMP
# include <omp.h>
#endif
static int test_scalar_size()
{
int Error = 0;
Error += sizeof(glm::int8) != 1;
Error += sizeof(glm::int16) != 2;
Error += sizeof(glm::int32) != 4;
Error += sizeof(glm::int64) != 8;
Error += sizeof(glm::uint8) != 1;
Error += sizeof(glm::uint16) != 2;
Error += sizeof(glm::uint32) != 4;
Error += sizeof(glm::uint64) != 8;
Error += sizeof(glm::float32) != 4;
Error += sizeof(glm::float64) != 8;
Error += sizeof(glm::lowp_int8) != 1;
Error += sizeof(glm::lowp_int16) != 2;
Error += sizeof(glm::lowp_int32) != 4;
Error += sizeof(glm::lowp_int64) != 8;
Error += sizeof(glm::lowp_uint8) != 1;
Error += sizeof(glm::lowp_uint16) != 2;
Error += sizeof(glm::lowp_uint32) != 4;
Error += sizeof(glm::lowp_uint64) != 8;
Error += sizeof(glm::lowp_float32) != 4;
Error += sizeof(glm::lowp_float64) != 8;
Error += sizeof(glm::mediump_int8) != 1;
Error += sizeof(glm::mediump_int16) != 2;
Error += sizeof(glm::mediump_int32) != 4;
Error += sizeof(glm::mediump_int64) != 8;
Error += sizeof(glm::mediump_uint8) != 1;
Error += sizeof(glm::mediump_uint16) != 2;
Error += sizeof(glm::mediump_uint32) != 4;
Error += sizeof(glm::mediump_uint64) != 8;
Error += sizeof(glm::mediump_float32) != 4;
Error += sizeof(glm::mediump_float64) != 8;
Error += sizeof(glm::highp_int8) != 1;
Error += sizeof(glm::highp_int16) != 2;
Error += sizeof(glm::highp_int32) != 4;
Error += sizeof(glm::highp_int64) != 8;
Error += sizeof(glm::highp_uint8) != 1;
Error += sizeof(glm::highp_uint16) != 2;
Error += sizeof(glm::highp_uint32) != 4;
Error += sizeof(glm::highp_uint64) != 8;
Error += sizeof(glm::highp_float32) != 4;
Error += sizeof(glm::highp_float64) != 8;
return Error;
}
static int test_fvec_size()
{
int Error = 0;
Error += sizeof(glm::f32vec2) != 8;
Error += sizeof(glm::f32vec3) != 12;
Error += sizeof(glm::f32vec4) != 16;
Error += sizeof(glm::f64vec2) != 16;
Error += sizeof(glm::f64vec3) != 24;
Error += sizeof(glm::f64vec4) != 32;
Error += sizeof(glm::lowp_f32vec2) != 8;
Error += sizeof(glm::lowp_f32vec3) != 12;
Error += sizeof(glm::lowp_f32vec4) != 16;
Error += sizeof(glm::lowp_f64vec2) != 16;
Error += sizeof(glm::lowp_f64vec3) != 24;
Error += sizeof(glm::lowp_f64vec4) != 32;
Error += sizeof(glm::mediump_f32vec2) != 8;
Error += sizeof(glm::mediump_f32vec3) != 12;
Error += sizeof(glm::mediump_f32vec4) != 16;
Error += sizeof(glm::mediump_f64vec2) != 16;
Error += sizeof(glm::mediump_f64vec3) != 24;
Error += sizeof(glm::mediump_f64vec4) != 32;
Error += sizeof(glm::highp_f32vec2) != 8;
Error += sizeof(glm::highp_f32vec3) != 12;
Error += sizeof(glm::highp_f32vec4) != 16;
Error += sizeof(glm::highp_f64vec2) != 16;
Error += sizeof(glm::highp_f64vec3) != 24;
Error += sizeof(glm::highp_f64vec4) != 32;
return Error;
}
static int test_fvec_precision()
{
int Error = 0;
/*
{
glm::f32vec2 v1;
glm::lowp_f32vec2 v2((glm::f32vec2(v1)));
glm::mediump_f32vec2 v3((glm::f32vec2(v1)));
glm::highp_f32vec2 v4((glm::f32vec2(v1)));
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v4)) ? 0 : 1;
}
*/
{
glm::f32vec2 v1(1.f);
glm::lowp_f32vec2 v2(v1);
glm::mediump_f32vec2 v3(v1);
glm::highp_f32vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::f32vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec2(v4))) ? 0 : 1;
}
{
glm::f32vec3 v1(1.f);
glm::lowp_f32vec3 v2(v1);
glm::mediump_f32vec3 v3(v1);
glm::highp_f32vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::f32vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec3(v4))) ? 0 : 1;
}
{
glm::f32vec4 v1(1.f);
glm::lowp_f32vec4 v2(v1);
glm::mediump_f32vec4 v3(v1);
glm::highp_f32vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::f32vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f32vec4(v4))) ? 0 : 1;
}
return Error;
}
static int test_dvec_precision()
{
int Error = 0;
{
glm::f64vec2 v1(1.0);
glm::lowp_f64vec2 v2(v1);
glm::mediump_f64vec2 v3(v1);
glm::highp_f64vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::f64vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec2(v4))) ? 0 : 1;
}
{
glm::f64vec3 v1(1.0);
glm::lowp_f64vec3 v2(v1);
glm::mediump_f64vec3 v3(v1);
glm::highp_f64vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::f64vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec3(v4))) ? 0 : 1;
}
{
glm::f64vec4 v1(1.0);
glm::lowp_f64vec4 v2(v1);
glm::mediump_f64vec4 v3(v1);
glm::highp_f64vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::f64vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::f64vec4(v4))) ? 0 : 1;
}
return Error;
}
static int test_ivec_size()
{
int Error = 0;
Error += sizeof(glm::i8vec2) != 2;
Error += sizeof(glm::i8vec3) != 3;
Error += sizeof(glm::i8vec4) != 4;
Error += sizeof(glm::i16vec2) != 4;
Error += sizeof(glm::i16vec3) != 6;
Error += sizeof(glm::i16vec4) != 8;
Error += sizeof(glm::i32vec2) != 8;
Error += sizeof(glm::i32vec3) != 12;
Error += sizeof(glm::i32vec4) != 16;
Error += sizeof(glm::i64vec2) != 16;
Error += sizeof(glm::i64vec3) != 24;
Error += sizeof(glm::i64vec4) != 32;
Error += sizeof(glm::lowp_i8vec2) != 2;
Error += sizeof(glm::lowp_i8vec3) != 3;
Error += sizeof(glm::lowp_i8vec4) != 4;
Error += sizeof(glm::lowp_i16vec2) != 4;
Error += sizeof(glm::lowp_i16vec3) != 6;
Error += sizeof(glm::lowp_i16vec4) != 8;
Error += sizeof(glm::lowp_i32vec2) != 8;
Error += sizeof(glm::lowp_i32vec3) != 12;
Error += sizeof(glm::lowp_i32vec4) != 16;
Error += sizeof(glm::lowp_i64vec2) != 16;
Error += sizeof(glm::lowp_i64vec3) != 24;
Error += sizeof(glm::lowp_i64vec4) != 32;
Error += sizeof(glm::mediump_i8vec2) != 2;
Error += sizeof(glm::mediump_i8vec3) != 3;
Error += sizeof(glm::mediump_i8vec4) != 4;
Error += sizeof(glm::mediump_i16vec2) != 4;
Error += sizeof(glm::mediump_i16vec3) != 6;
Error += sizeof(glm::mediump_i16vec4) != 8;
Error += sizeof(glm::mediump_i32vec2) != 8;
Error += sizeof(glm::mediump_i32vec3) != 12;
Error += sizeof(glm::mediump_i32vec4) != 16;
Error += sizeof(glm::mediump_i64vec2) != 16;
Error += sizeof(glm::mediump_i64vec3) != 24;
Error += sizeof(glm::mediump_i64vec4) != 32;
Error += sizeof(glm::highp_i8vec2) != 2;
Error += sizeof(glm::highp_i8vec3) != 3;
Error += sizeof(glm::highp_i8vec4) != 4;
Error += sizeof(glm::highp_i16vec2) != 4;
Error += sizeof(glm::highp_i16vec3) != 6;
Error += sizeof(glm::highp_i16vec4) != 8;
Error += sizeof(glm::highp_i32vec2) != 8;
Error += sizeof(glm::highp_i32vec3) != 12;
Error += sizeof(glm::highp_i32vec4) != 16;
Error += sizeof(glm::highp_i64vec2) != 16;
Error += sizeof(glm::highp_i64vec3) != 24;
Error += sizeof(glm::highp_i64vec4) != 32;
return Error;
}
static int test_ivec_precision()
{
int Error = 0;
{
glm::i8vec2 v1(0);
glm::lowp_i8vec2 v2(v1);
glm::mediump_i8vec2 v3(v1);
glm::highp_i8vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::i8vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec2(v4))) ? 0 : 1;
}
{
glm::i8vec3 v1(0);
glm::lowp_i8vec3 v2(v1);
glm::mediump_i8vec3 v3(v1);
glm::highp_i8vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::i8vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec3(v4))) ? 0 : 1;
}
{
glm::i8vec4 v1(0);
glm::lowp_i8vec4 v2(v1);
glm::mediump_i8vec4 v3(v1);
glm::highp_i8vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::i8vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i8vec4(v4))) ? 0 : 1;
}
{
glm::i16vec2 v1(0);
glm::lowp_i16vec2 v2(v1);
glm::mediump_i16vec2 v3(v1);
glm::highp_i16vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::i16vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec2(v4))) ? 0 : 1;
}
{
glm::i16vec3 v1(0);
glm::lowp_i16vec3 v2(v1);
glm::mediump_i16vec3 v3(v1);
glm::highp_i16vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::i16vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec3(v4))) ? 0 : 1;
}
{
glm::i16vec4 v1(0);
glm::lowp_i16vec4 v2(v1);
glm::mediump_i16vec4 v3(v1);
glm::highp_i16vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::i16vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i16vec4(v4))) ? 0 : 1;
}
{
glm::i32vec2 v1(0);
glm::lowp_i32vec2 v2(v1);
glm::mediump_i32vec2 v3(v1);
glm::highp_i32vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::i32vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec2(v4))) ? 0 : 1;
}
{
glm::i32vec3 v1(0);
glm::lowp_i32vec3 v2(v1);
glm::mediump_i32vec3 v3(v1);
glm::highp_i32vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::i32vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec3(v4))) ? 0 : 1;
}
{
glm::i32vec4 v1(0);
glm::lowp_i32vec4 v2(v1);
glm::mediump_i32vec4 v3(v1);
glm::highp_i32vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::i32vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i32vec4(v4))) ? 0 : 1;
}
{
glm::i64vec2 v1(0);
glm::lowp_i64vec2 v2(v1);
glm::mediump_i64vec2 v3(v1);
glm::highp_i64vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::i64vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec2(v4))) ? 0 : 1;
}
{
glm::i64vec3 v1(0);
glm::lowp_i64vec3 v2(v1);
glm::mediump_i64vec3 v3(v1);
glm::highp_i64vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::i64vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec3(v4))) ? 0 : 1;
}
{
glm::i64vec4 v1(0);
glm::lowp_i64vec4 v2(v1);
glm::mediump_i64vec4 v3(v1);
glm::highp_i64vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::i64vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::i64vec4(v4))) ? 0 : 1;
}
return Error;
}
static int test_uvec_size()
{
int Error = 0;
Error += sizeof(glm::u8vec2) != 2;
Error += sizeof(glm::u8vec3) != 3;
Error += sizeof(glm::u8vec4) != 4;
Error += sizeof(glm::u16vec2) != 4;
Error += sizeof(glm::u16vec3) != 6;
Error += sizeof(glm::u16vec4) != 8;
Error += sizeof(glm::u32vec2) != 8;
Error += sizeof(glm::u32vec3) != 12;
Error += sizeof(glm::u32vec4) != 16;
Error += sizeof(glm::u64vec2) != 16;
Error += sizeof(glm::u64vec3) != 24;
Error += sizeof(glm::u64vec4) != 32;
Error += sizeof(glm::lowp_u8vec2) != 2;
Error += sizeof(glm::lowp_u8vec3) != 3;
Error += sizeof(glm::lowp_u8vec4) != 4;
Error += sizeof(glm::lowp_u16vec2) != 4;
Error += sizeof(glm::lowp_u16vec3) != 6;
Error += sizeof(glm::lowp_u16vec4) != 8;
Error += sizeof(glm::lowp_u32vec2) != 8;
Error += sizeof(glm::lowp_u32vec3) != 12;
Error += sizeof(glm::lowp_u32vec4) != 16;
Error += sizeof(glm::lowp_u64vec2) != 16;
Error += sizeof(glm::lowp_u64vec3) != 24;
Error += sizeof(glm::lowp_u64vec4) != 32;
Error += sizeof(glm::mediump_u8vec2) != 2;
Error += sizeof(glm::mediump_u8vec3) != 3;
Error += sizeof(glm::mediump_u8vec4) != 4;
Error += sizeof(glm::mediump_u16vec2) != 4;
Error += sizeof(glm::mediump_u16vec3) != 6;
Error += sizeof(glm::mediump_u16vec4) != 8;
Error += sizeof(glm::mediump_u32vec2) != 8;
Error += sizeof(glm::mediump_u32vec3) != 12;
Error += sizeof(glm::mediump_u32vec4) != 16;
Error += sizeof(glm::mediump_u64vec2) != 16;
Error += sizeof(glm::mediump_u64vec3) != 24;
Error += sizeof(glm::mediump_u64vec4) != 32;
Error += sizeof(glm::highp_u8vec2) != 2;
Error += sizeof(glm::highp_u8vec3) != 3;
Error += sizeof(glm::highp_u8vec4) != 4;
Error += sizeof(glm::highp_u16vec2) != 4;
Error += sizeof(glm::highp_u16vec3) != 6;
Error += sizeof(glm::highp_u16vec4) != 8;
Error += sizeof(glm::highp_u32vec2) != 8;
Error += sizeof(glm::highp_u32vec3) != 12;
Error += sizeof(glm::highp_u32vec4) != 16;
Error += sizeof(glm::highp_u64vec2) != 16;
Error += sizeof(glm::highp_u64vec3) != 24;
Error += sizeof(glm::highp_u64vec4) != 32;
return Error;
}
static int test_uvec_precision()
{
int Error = 0;
{
glm::u8vec2 v1(0);
glm::lowp_u8vec2 v2(v1);
glm::mediump_u8vec2 v3(v1);
glm::highp_u8vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::u8vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec2(v4))) ? 0 : 1;
}
{
glm::u8vec3 v1(0);
glm::lowp_u8vec3 v2(v1);
glm::mediump_u8vec3 v3(v1);
glm::highp_u8vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::u8vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec3(v4))) ? 0 : 1;
}
{
glm::u8vec4 v1(0);
glm::lowp_u8vec4 v2(v1);
glm::mediump_u8vec4 v3(v1);
glm::highp_u8vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::u8vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u8vec4(v4))) ? 0 : 1;
}
{
glm::u16vec2 v1(0);
glm::lowp_u16vec2 v2(v1);
glm::mediump_u16vec2 v3(v1);
glm::highp_u16vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::u16vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec2(v4))) ? 0 : 1;
}
{
glm::u16vec3 v1(0);
glm::lowp_u16vec3 v2(v1);
glm::mediump_u16vec3 v3(v1);
glm::highp_u16vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::u16vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec3(v4))) ? 0 : 1;
}
{
glm::u16vec4 v1(0);
glm::lowp_u16vec4 v2(v1);
glm::mediump_u16vec4 v3(v1);
glm::highp_u16vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::u16vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u16vec4(v4))) ? 0 : 1;
}
{
glm::u32vec2 v1(0);
glm::lowp_u32vec2 v2(v1);
glm::mediump_u32vec2 v3(v1);
glm::highp_u32vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::u32vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec2(v4))) ? 0 : 1;
}
{
glm::u32vec3 v1(0);
glm::lowp_u32vec3 v2(v1);
glm::mediump_u32vec3 v3(v1);
glm::highp_u32vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::u32vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec3(v4))) ? 0 : 1;
}
{
glm::u32vec4 v1(0);
glm::lowp_u32vec4 v2(v1);
glm::mediump_u32vec4 v3(v1);
glm::highp_u32vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::u32vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u32vec4(v4))) ? 0 : 1;
}
{
glm::u64vec2 v1(0);
glm::lowp_u64vec2 v2(v1);
glm::mediump_u64vec2 v3(v1);
glm::highp_u64vec2 v4(v1);
Error += glm::all(glm::equal(v1, glm::u64vec2(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec2(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec2(v4))) ? 0 : 1;
}
{
glm::u64vec3 v1(0);
glm::lowp_u64vec3 v2(v1);
glm::mediump_u64vec3 v3(v1);
glm::highp_u64vec3 v4(v1);
Error += glm::all(glm::equal(v1, glm::u64vec3(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec3(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec3(v4))) ? 0 : 1;
}
{
glm::u64vec4 v1(0);
glm::lowp_u64vec4 v2(v1);
glm::mediump_u64vec4 v3(v1);
glm::highp_u64vec4 v4(v1);
Error += glm::all(glm::equal(v1, glm::u64vec4(v2))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec4(v3))) ? 0 : 1;
Error += glm::all(glm::equal(v1, glm::u64vec4(v4))) ? 0 : 1;
}
return Error;
}
static int test_fmat_size()
{
int Error = 0;
Error += sizeof(glm::mat2) != 16;
Error += sizeof(glm::mat3) != 36;
Error += sizeof(glm::mat4) != 64;
Error += sizeof(glm::mat2x2) != 16;
Error += sizeof(glm::mat2x3) != 24;
Error += sizeof(glm::mat2x4) != 32;
Error += sizeof(glm::mat3x2) != 24;
Error += sizeof(glm::mat3x3) != 36;
Error += sizeof(glm::mat3x4) != 48;
Error += sizeof(glm::mat4x2) != 32;
Error += sizeof(glm::mat4x3) != 48;
Error += sizeof(glm::mat4x4) != 64;
Error += sizeof(glm::fmat2) != 16;
Error += sizeof(glm::fmat3) != 36;
Error += sizeof(glm::fmat4) != 64;
Error += sizeof(glm::fmat2x2) != 16;
Error += sizeof(glm::fmat2x3) != 24;
Error += sizeof(glm::fmat2x4) != 32;
Error += sizeof(glm::fmat3x2) != 24;
Error += sizeof(glm::fmat3x3) != 36;
Error += sizeof(glm::fmat3x4) != 48;
Error += sizeof(glm::fmat4x2) != 32;
Error += sizeof(glm::fmat4x3) != 48;
Error += sizeof(glm::fmat4x4) != 64;
Error += sizeof(glm::f32mat2) != 16;
Error += sizeof(glm::f32mat3) != 36;
Error += sizeof(glm::f32mat4) != 64;
Error += sizeof(glm::f32mat2x2) != 16;
Error += sizeof(glm::f32mat2x3) != 24;
Error += sizeof(glm::f32mat2x4) != 32;
Error += sizeof(glm::f32mat3x2) != 24;
Error += sizeof(glm::f32mat3x3) != 36;
Error += sizeof(glm::f32mat3x4) != 48;
Error += sizeof(glm::f32mat4x2) != 32;
Error += sizeof(glm::f32mat4x3) != 48;
Error += sizeof(glm::f32mat4x4) != 64;
Error += sizeof(glm::lowp_mat2) != 16;
Error += sizeof(glm::lowp_mat3) != 36;
Error += sizeof(glm::lowp_mat4) != 64;
Error += sizeof(glm::lowp_mat2x2) != 16;
Error += sizeof(glm::lowp_mat2x3) != 24;
Error += sizeof(glm::lowp_mat2x4) != 32;
Error += sizeof(glm::lowp_mat3x2) != 24;
Error += sizeof(glm::lowp_mat3x3) != 36;
Error += sizeof(glm::lowp_mat3x4) != 48;
Error += sizeof(glm::lowp_mat4x2) != 32;
Error += sizeof(glm::lowp_mat4x3) != 48;
Error += sizeof(glm::lowp_mat4x4) != 64;
Error += sizeof(glm::lowp_fmat2) != 16;
Error += sizeof(glm::lowp_fmat3) != 36;
Error += sizeof(glm::lowp_fmat4) != 64;
Error += sizeof(glm::lowp_fmat2x2) != 16;
Error += sizeof(glm::lowp_fmat2x3) != 24;
Error += sizeof(glm::lowp_fmat2x4) != 32;
Error += sizeof(glm::lowp_fmat3x2) != 24;
Error += sizeof(glm::lowp_fmat3x3) != 36;
Error += sizeof(glm::lowp_fmat3x4) != 48;
Error += sizeof(glm::lowp_fmat4x2) != 32;
Error += sizeof(glm::lowp_fmat4x3) != 48;
Error += sizeof(glm::lowp_fmat4x4) != 64;
Error += sizeof(glm::lowp_f32mat2) != 16;
Error += sizeof(glm::lowp_f32mat3) != 36;
Error += sizeof(glm::lowp_f32mat4) != 64;
Error += sizeof(glm::lowp_f32mat2x2) != 16;
Error += sizeof(glm::lowp_f32mat2x3) != 24;
Error += sizeof(glm::lowp_f32mat2x4) != 32;
Error += sizeof(glm::lowp_f32mat3x2) != 24;
Error += sizeof(glm::lowp_f32mat3x3) != 36;
Error += sizeof(glm::lowp_f32mat3x4) != 48;
Error += sizeof(glm::lowp_f32mat4x2) != 32;
Error += sizeof(glm::lowp_f32mat4x3) != 48;
Error += sizeof(glm::lowp_f32mat4x4) != 64;
Error += sizeof(glm::mediump_mat2) != 16;
Error += sizeof(glm::mediump_mat3) != 36;
Error += sizeof(glm::mediump_mat4) != 64;
Error += sizeof(glm::mediump_mat2x2) != 16;
Error += sizeof(glm::mediump_mat2x3) != 24;
Error += sizeof(glm::mediump_mat2x4) != 32;
Error += sizeof(glm::mediump_mat3x2) != 24;
Error += sizeof(glm::mediump_mat3x3) != 36;
Error += sizeof(glm::mediump_mat3x4) != 48;
Error += sizeof(glm::mediump_mat4x2) != 32;
Error += sizeof(glm::mediump_mat4x3) != 48;
Error += sizeof(glm::mediump_mat4x4) != 64;
Error += sizeof(glm::mediump_fmat2) != 16;
Error += sizeof(glm::mediump_fmat3) != 36;
Error += sizeof(glm::mediump_fmat4) != 64;
Error += sizeof(glm::mediump_fmat2x2) != 16;
Error += sizeof(glm::mediump_fmat2x3) != 24;
Error += sizeof(glm::mediump_fmat2x4) != 32;
Error += sizeof(glm::mediump_fmat3x2) != 24;
Error += sizeof(glm::mediump_fmat3x3) != 36;
Error += sizeof(glm::mediump_fmat3x4) != 48;
Error += sizeof(glm::mediump_fmat4x2) != 32;
Error += sizeof(glm::mediump_fmat4x3) != 48;
Error += sizeof(glm::mediump_fmat4x4) != 64;
Error += sizeof(glm::mediump_f32mat2) != 16;
Error += sizeof(glm::mediump_f32mat3) != 36;
Error += sizeof(glm::mediump_f32mat4) != 64;
Error += sizeof(glm::mediump_f32mat2x2) != 16;
Error += sizeof(glm::mediump_f32mat2x3) != 24;
Error += sizeof(glm::mediump_f32mat2x4) != 32;
Error += sizeof(glm::mediump_f32mat3x2) != 24;
Error += sizeof(glm::mediump_f32mat3x3) != 36;
Error += sizeof(glm::mediump_f32mat3x4) != 48;
Error += sizeof(glm::mediump_f32mat4x2) != 32;
Error += sizeof(glm::mediump_f32mat4x3) != 48;
Error += sizeof(glm::mediump_f32mat4x4) != 64;
Error += sizeof(glm::highp_mat2) != 16;
Error += sizeof(glm::highp_mat3) != 36;
Error += sizeof(glm::highp_mat4) != 64;
Error += sizeof(glm::highp_mat2x2) != 16;
Error += sizeof(glm::highp_mat2x3) != 24;
Error += sizeof(glm::highp_mat2x4) != 32;
Error += sizeof(glm::highp_mat3x2) != 24;
Error += sizeof(glm::highp_mat3x3) != 36;
Error += sizeof(glm::highp_mat3x4) != 48;
Error += sizeof(glm::highp_mat4x2) != 32;
Error += sizeof(glm::highp_mat4x3) != 48;
Error += sizeof(glm::highp_mat4x4) != 64;
Error += sizeof(glm::highp_fmat2) != 16;
Error += sizeof(glm::highp_fmat3) != 36;
Error += sizeof(glm::highp_fmat4) != 64;
Error += sizeof(glm::highp_fmat2x2) != 16;
Error += sizeof(glm::highp_fmat2x3) != 24;
Error += sizeof(glm::highp_fmat2x4) != 32;
Error += sizeof(glm::highp_fmat3x2) != 24;
Error += sizeof(glm::highp_fmat3x3) != 36;
Error += sizeof(glm::highp_fmat3x4) != 48;
Error += sizeof(glm::highp_fmat4x2) != 32;
Error += sizeof(glm::highp_fmat4x3) != 48;
Error += sizeof(glm::highp_fmat4x4) != 64;
Error += sizeof(glm::highp_f32mat2) != 16;
Error += sizeof(glm::highp_f32mat3) != 36;
Error += sizeof(glm::highp_f32mat4) != 64;
Error += sizeof(glm::highp_f32mat2x2) != 16;
Error += sizeof(glm::highp_f32mat2x3) != 24;
Error += sizeof(glm::highp_f32mat2x4) != 32;
Error += sizeof(glm::highp_f32mat3x2) != 24;
Error += sizeof(glm::highp_f32mat3x3) != 36;
Error += sizeof(glm::highp_f32mat3x4) != 48;
Error += sizeof(glm::highp_f32mat4x2) != 32;
Error += sizeof(glm::highp_f32mat4x3) != 48;
Error += sizeof(glm::highp_f32mat4x4) != 64;
return Error;
}
static int test_dmat_size()
{
int Error = 0;
Error += sizeof(glm::f64mat2) != 32;
Error += sizeof(glm::f64mat3) != 72;
Error += sizeof(glm::f64mat4) != 128;
Error += sizeof(glm::f64mat2x2) != 32;
Error += sizeof(glm::f64mat2x3) != 48;
Error += sizeof(glm::f64mat2x4) != 64;
Error += sizeof(glm::f64mat3x2) != 48;
Error += sizeof(glm::f64mat3x3) != 72;
Error += sizeof(glm::f64mat3x4) != 96;
Error += sizeof(glm::f64mat4x2) != 64;
Error += sizeof(glm::f64mat4x3) != 96;
Error += sizeof(glm::f64mat4x4) != 128;
Error += sizeof(glm::lowp_f64mat2) != 32;
Error += sizeof(glm::lowp_f64mat3) != 72;
Error += sizeof(glm::lowp_f64mat4) != 128;
Error += sizeof(glm::lowp_f64mat2x2) != 32;
Error += sizeof(glm::lowp_f64mat2x3) != 48;
Error += sizeof(glm::lowp_f64mat2x4) != 64;
Error += sizeof(glm::lowp_f64mat3x2) != 48;
Error += sizeof(glm::lowp_f64mat3x3) != 72;
Error += sizeof(glm::lowp_f64mat3x4) != 96;
Error += sizeof(glm::lowp_f64mat4x2) != 64;
Error += sizeof(glm::lowp_f64mat4x3) != 96;
Error += sizeof(glm::lowp_f64mat4x4) != 128;
Error += sizeof(glm::mediump_f64mat2) != 32;
Error += sizeof(glm::mediump_f64mat3) != 72;
Error += sizeof(glm::mediump_f64mat4) != 128;
Error += sizeof(glm::mediump_f64mat2x2) != 32;
Error += sizeof(glm::mediump_f64mat2x3) != 48;
Error += sizeof(glm::mediump_f64mat2x4) != 64;
Error += sizeof(glm::mediump_f64mat3x2) != 48;
Error += sizeof(glm::mediump_f64mat3x3) != 72;
Error += sizeof(glm::mediump_f64mat3x4) != 96;
Error += sizeof(glm::mediump_f64mat4x2) != 64;
Error += sizeof(glm::mediump_f64mat4x3) != 96;
Error += sizeof(glm::mediump_f64mat4x4) != 128;
Error += sizeof(glm::highp_f64mat2) != 32;
Error += sizeof(glm::highp_f64mat3) != 72;
Error += sizeof(glm::highp_f64mat4) != 128;
Error += sizeof(glm::highp_f64mat2x2) != 32;
Error += sizeof(glm::highp_f64mat2x3) != 48;
Error += sizeof(glm::highp_f64mat2x4) != 64;
Error += sizeof(glm::highp_f64mat3x2) != 48;
Error += sizeof(glm::highp_f64mat3x3) != 72;
Error += sizeof(glm::highp_f64mat3x4) != 96;
Error += sizeof(glm::highp_f64mat4x2) != 64;
Error += sizeof(glm::highp_f64mat4x3) != 96;
Error += sizeof(glm::highp_f64mat4x4) != 128;
return Error;
}
static int test_quat_size()
{
int Error = 0;
Error += sizeof(glm::f32quat) != 16;
Error += sizeof(glm::f64quat) != 32;
Error += sizeof(glm::lowp_f32quat) != 16;
Error += sizeof(glm::lowp_f64quat) != 32;
Error += sizeof(glm::mediump_f32quat) != 16;
Error += sizeof(glm::mediump_f64quat) != 32;
Error += sizeof(glm::highp_f32quat) != 16;
Error += sizeof(glm::highp_f64quat) != 32;
return Error;
}
static int test_quat_precision()
{
int Error = 0;
{
glm::f32quat q1(0.f, glm::vec3(0.f, 0.f, 1.f));
glm::lowp_f32quat qA(q1);
glm::mediump_f32quat qB(q1);
glm::highp_f32quat qC(q1);
glm::f32quat q2(qA);
glm::f32quat q3(qB);
glm::f32quat q4(qC);
Error += glm::all(glm::equal(q1, q2)) ? 0 : 1;
Error += glm::all(glm::equal(q1, q3)) ? 0 : 1;
Error += glm::all(glm::equal(q1, q4)) ? 0 : 1;
}
return Error;
}
static int test_fvec_conversion()
{
int Error(0);
{
glm::highp_vec4 a = glm::vec4(1, 2, 3, 4);
glm::mediump_vec4 b = glm::vec4(1, 2, 3, 4);
glm::lowp_vec4 c = b;
glm::mediump_vec4 d = c;
glm::lowp_ivec4 e = glm::ivec4(d);
glm::lowp_ivec3 f = glm::ivec3(e);
Error += glm::all(glm::equal(b, d)) ? 0 : 1;
}
return Error;
}
#if GLM_HAS_OPENMP
static int test_openmp()
{
std::vector<glm::u8vec3> VectorA(1000);
std::vector<glm::u8vec3> VectorB(1000);
std::vector<glm::u8vec3> VectorC(1000);
for (std::size_t i = 0; i < VectorA.size(); ++i)
{
VectorA[i] = glm::u8vec3(1, 1, 1);
VectorB[i] = glm::u8vec3(1, 1, 1);
}
#pragma omp parallel for default(none) shared(VectorA, VectorB, VectorC)
for (int i = 0; i < static_cast<int>(VectorC.size()); ++i)
{
VectorC[i] = VectorA[i] + VectorB[i];
}
return 0;
}
#endif//GLM_HAS_OPENMP
int main()
{
int Error = 0;
Error += test_scalar_size();
Error += test_fvec_size();
Error += test_fvec_precision();
Error += test_fvec_conversion();
Error += test_dvec_precision();
Error += test_uvec_size();
Error += test_uvec_precision();
Error += test_ivec_size();
Error += test_ivec_precision();
Error += test_fmat_size();
Error += test_dmat_size();
Error += test_quat_size();
Error += test_quat_precision();
# if GLM_HAS_OPENMP
Error += test_openmp();
# endif//
return Error;
}

View File

@@ -0,0 +1,333 @@
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/vec1.hpp>
int test_value_ptr_vec()
{
int Error = 0;
{
glm::vec2 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec3 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec4 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec2 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec3 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec4 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
return Error;
}
int test_value_ptr_vec_const()
{
int Error = 0;
{
glm::vec2 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec3 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec4 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec2 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec3 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec4 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
return Error;
}
int test_value_ptr_mat()
{
int Error = 0;
{
glm::mat2x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
return Error;
}
int test_value_ptr_mat_const()
{
int Error = 0;
{
glm::mat2x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
return Error;
}
int test_make_pointer_mat()
{
int Error = 0;
float ArrayA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
double ArrayB[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
glm::mat2x2 Mat2x2A = glm::make_mat2x2(ArrayA);
glm::mat2x3 Mat2x3A = glm::make_mat2x3(ArrayA);
glm::mat2x4 Mat2x4A = glm::make_mat2x4(ArrayA);
glm::mat3x2 Mat3x2A = glm::make_mat3x2(ArrayA);
glm::mat3x3 Mat3x3A = glm::make_mat3x3(ArrayA);
glm::mat3x4 Mat3x4A = glm::make_mat3x4(ArrayA);
glm::mat4x2 Mat4x2A = glm::make_mat4x2(ArrayA);
glm::mat4x3 Mat4x3A = glm::make_mat4x3(ArrayA);
glm::mat4x4 Mat4x4A = glm::make_mat4x4(ArrayA);
glm::dmat2x2 Mat2x2B = glm::make_mat2x2(ArrayB);
glm::dmat2x3 Mat2x3B = glm::make_mat2x3(ArrayB);
glm::dmat2x4 Mat2x4B = glm::make_mat2x4(ArrayB);
glm::dmat3x2 Mat3x2B = glm::make_mat3x2(ArrayB);
glm::dmat3x3 Mat3x3B = glm::make_mat3x3(ArrayB);
glm::dmat3x4 Mat3x4B = glm::make_mat3x4(ArrayB);
glm::dmat4x2 Mat4x2B = glm::make_mat4x2(ArrayB);
glm::dmat4x3 Mat4x3B = glm::make_mat4x3(ArrayB);
glm::dmat4x4 Mat4x4B = glm::make_mat4x4(ArrayB);
return Error;
}
int test_make_pointer_vec()
{
int Error = 0;
float ArrayA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int ArrayB[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
bool ArrayC[] = {true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false};
glm::vec2 Vec2A = glm::make_vec2(ArrayA);
glm::vec3 Vec3A = glm::make_vec3(ArrayA);
glm::vec4 Vec4A = glm::make_vec4(ArrayA);
glm::ivec2 Vec2B = glm::make_vec2(ArrayB);
glm::ivec3 Vec3B = glm::make_vec3(ArrayB);
glm::ivec4 Vec4B = glm::make_vec4(ArrayB);
glm::bvec2 Vec2C = glm::make_vec2(ArrayC);
glm::bvec3 Vec3C = glm::make_vec3(ArrayC);
glm::bvec4 Vec4C = glm::make_vec4(ArrayC);
return Error;
}
int test_make_vec1()
{
int Error = 0;
glm::ivec1 const v1 = glm::make_vec1(glm::ivec1(2));
Error += v1 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v2 = glm::make_vec1(glm::ivec2(2));
Error += v2 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v3 = glm::make_vec1(glm::ivec3(2));
Error += v3 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v4 = glm::make_vec1(glm::ivec4(2));
Error += v3 == glm::ivec1(2) ? 0 : 1;
return Error;
}
int test_make_vec2()
{
int Error = 0;
glm::ivec2 const v1 = glm::make_vec2(glm::ivec1(2));
Error += v1 == glm::ivec2(2, 0) ? 0 : 1;
glm::ivec2 const v2 = glm::make_vec2(glm::ivec2(2));
Error += v2 == glm::ivec2(2, 2) ? 0 : 1;
glm::ivec2 const v3 = glm::make_vec2(glm::ivec3(2));
Error += v3 == glm::ivec2(2, 2) ? 0 : 1;
glm::ivec2 const v4 = glm::make_vec2(glm::ivec4(2));
Error += v3 == glm::ivec2(2, 2) ? 0 : 1;
return Error;
}
int test_make_vec3()
{
int Error = 0;
glm::ivec3 const v1 = glm::make_vec3(glm::ivec1(2));
Error += v1 == glm::ivec3(2, 0, 0) ? 0 : 1;
glm::ivec3 const v2 = glm::make_vec3(glm::ivec2(2));
Error += v2 == glm::ivec3(2, 2, 0) ? 0 : 1;
glm::ivec3 const v3 = glm::make_vec3(glm::ivec3(2));
Error += v3 == glm::ivec3(2, 2, 2) ? 0 : 1;
glm::ivec3 const v4 = glm::make_vec3(glm::ivec4(2));
Error += v3 == glm::ivec3(2, 2, 2) ? 0 : 1;
return Error;
}
int test_make_vec4()
{
int Error = 0;
glm::ivec4 const v1 = glm::make_vec4(glm::ivec1(2));
Error += v1 == glm::ivec4(2, 0, 0, 1) ? 0 : 1;
glm::ivec4 const v2 = glm::make_vec4(glm::ivec2(2));
Error += v2 == glm::ivec4(2, 2, 0, 1) ? 0 : 1;
glm::ivec4 const v3 = glm::make_vec4(glm::ivec3(2));
Error += v3 == glm::ivec4(2, 2, 2, 1) ? 0 : 1;
glm::ivec4 const v4 = glm::make_vec4(glm::ivec4(2));
Error += v4 == glm::ivec4(2, 2, 2, 2) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_make_vec1();
Error += test_make_vec2();
Error += test_make_vec3();
Error += test_make_vec4();
Error += test_make_pointer_vec();
Error += test_make_pointer_mat();
Error += test_value_ptr_vec();
Error += test_value_ptr_vec_const();
Error += test_value_ptr_mat();
Error += test_value_ptr_mat_const();
return Error;
}

View File

@@ -0,0 +1,97 @@
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/epsilon.hpp>
#include <limits>
int test_ulp_float_dist()
{
int Error = 0;
float A = 1.0f;
float B = glm::next_float(A);
Error += !glm::epsilonEqual(A, B, glm::epsilon<float>()) ? 0 : 1;
float C = glm::prev_float(B);
Error += glm::epsilonEqual(A, C, glm::epsilon<float>()) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == 1 ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
return Error;
}
int test_ulp_float_step()
{
int Error = 0;
float A = 1.0f;
for(int i = 10; i < 1000; i *= 10)
{
float B = glm::next_float(A, i);
Error += !glm::epsilonEqual(A, B, glm::epsilon<float>()) ? 0 : 1;
float C = glm::prev_float(B, i);
Error += glm::epsilonEqual(A, C, glm::epsilon<float>()) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == i ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
}
return Error;
}
int test_ulp_double_dist()
{
int Error = 0;
double A = 1.0;
double B = glm::next_float(A);
Error += !glm::epsilonEqual(A, B, glm::epsilon<double>()) ? 0 : 1;
double C = glm::prev_float(B);
Error += glm::epsilonEqual(A, C, glm::epsilon<double>()) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == 1 ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
return Error;
}
int test_ulp_double_step()
{
int Error = 0;
double A = 1.0;
for(int i = 10; i < 1000; i *= 10)
{
double B = glm::next_float(A, i);
Error += !glm::epsilonEqual(A, B, glm::epsilon<double>()) ? 0 : 1;
double C = glm::prev_float(B, i);
Error += glm::epsilonEqual(A, C, glm::epsilon<double>()) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == i ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_ulp_float_dist();
Error += test_ulp_float_step();
Error += test_ulp_double_dist();
Error += test_ulp_double_step();
return Error;
}

View File

@@ -0,0 +1,30 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-16
// Updated : 2011-05-27
// Licence : This source is under MIT licence
// File : test/gtc/type_ptr.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_FORCE_RADIANS
#include <glm/gtc/user_defined_type.hpp>
int test_make_pointer_vec()
{
int Error = 0;
glm::func();
//func();
return Error;
}
int main()
{
int Error = 0;
Error += test_make_pointer_vec();
return Error;
}

View File

@@ -0,0 +1,8 @@
#include <glm/gtc/vec1.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,57 @@
glmCreateTestGTC(gtx)
glmCreateTestGTC(gtx_associated_min_max)
glmCreateTestGTC(gtx_closest_point)
glmCreateTestGTC(gtx_color_encoding)
glmCreateTestGTC(gtx_color_space_YCoCg)
glmCreateTestGTC(gtx_color_space)
glmCreateTestGTC(gtx_common)
glmCreateTestGTC(gtx_compatibility)
glmCreateTestGTC(gtx_component_wise)
glmCreateTestGTC(gtx_easing)
glmCreateTestGTC(gtx_euler_angle)
glmCreateTestGTC(gtx_extend)
glmCreateTestGTC(gtx_extended_min_max)
glmCreateTestGTC(gtx_exterior_product)
glmCreateTestGTC(gtx_fast_exponential)
glmCreateTestGTC(gtx_fast_square_root)
glmCreateTestGTC(gtx_fast_trigonometry)
glmCreateTestGTC(gtx_functions)
glmCreateTestGTC(gtx_gradient_paint)
glmCreateTestGTC(gtx_handed_coordinate_space)
glmCreateTestGTC(gtx_integer)
glmCreateTestGTC(gtx_intersect)
glmCreateTestGTC(gtx_io)
glmCreateTestGTC(gtx_log_base)
glmCreateTestGTC(gtx_matrix_cross_product)
glmCreateTestGTC(gtx_matrix_decompose)
glmCreateTestGTC(gtx_matrix_factorisation)
glmCreateTestGTC(gtx_matrix_interpolation)
glmCreateTestGTC(gtx_matrix_major_storage)
glmCreateTestGTC(gtx_matrix_operation)
glmCreateTestGTC(gtx_matrix_query)
glmCreateTestGTC(gtx_matrix_transform_2d)
glmCreateTestGTC(gtx_norm)
glmCreateTestGTC(gtx_normal)
glmCreateTestGTC(gtx_normalize_dot)
glmCreateTestGTC(gtx_number_precision)
glmCreateTestGTC(gtx_orthonormalize)
glmCreateTestGTC(gtx_optimum_pow)
glmCreateTestGTC(gtx_perpendicular)
glmCreateTestGTC(gtx_polar_coordinates)
glmCreateTestGTC(gtx_projection)
glmCreateTestGTC(gtx_quaternion)
glmCreateTestGTC(gtx_dual_quaternion)
glmCreateTestGTC(gtx_range)
glmCreateTestGTC(gtx_rotate_normalized_axis)
glmCreateTestGTC(gtx_rotate_vector)
glmCreateTestGTC(gtx_scalar_multiplication)
glmCreateTestGTC(gtx_scalar_relational)
glmCreateTestGTC(gtx_spline)
glmCreateTestGTC(gtx_string_cast)
glmCreateTestGTC(gtx_texture)
glmCreateTestGTC(gtx_type_aligned)
glmCreateTestGTC(gtx_type_trait)
glmCreateTestGTC(gtx_vec_swizzle)
glmCreateTestGTC(gtx_vector_angle)
glmCreateTestGTC(gtx_vector_query)
glmCreateTestGTC(gtx_wrap)

8
ref/glm/test/gtx/gtx.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,10 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/closest_point.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,51 @@
#include <glm/gtx/color_encoding.hpp>
#include <glm/gtc/color_space.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
namespace srgb
{
int test()
{
int Error(0);
glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
/*
{
glm::vec3 const ColorSRGB = glm::convertLinearSRGBToD65XYZ(ColorSourceRGB);
glm::vec3 const ColorRGB = glm::convertD65XYZToLinearSRGB(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
*/
{
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb
int main()
{
int Error(0);
Error += srgb::test();
return Error;
}

View File

@@ -0,0 +1,20 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/color_space.hpp>
int test_saturation()
{
int Error(0);
glm::vec4 Color = glm::saturation(1.0f, glm::vec4(1.0, 0.5, 0.0, 1.0));
return Error;
}
int main()
{
int Error(0);
Error += test_saturation();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/color_space_YCoCg.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,161 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/common.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <glm/common.hpp>
namespace fmod_
{
template<typename genType>
GLM_FUNC_QUALIFIER genType modTrunc(genType a, genType b)
{
return a - b * glm::trunc(a / b);
}
int test()
{
int Error(0);
{
float A0(3.0);
float B0(2.0f);
float C0 = glm::fmod(A0, B0);
Error += glm::abs(C0 - 1.0f) < 0.00001f ? 0 : 1;
glm::vec4 A1(3.0);
float B1(2.0f);
glm::vec4 C1 = glm::fmod(A1, B1);
Error += glm::all(glm::epsilonEqual(C1, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
glm::vec4 A2(3.0);
glm::vec4 B2(2.0f);
glm::vec4 C2 = glm::fmod(A2, B2);
Error += glm::all(glm::epsilonEqual(C2, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
glm::ivec4 A3(3);
int B3(2);
glm::ivec4 C3 = glm::fmod(A3, B3);
Error += glm::all(glm::equal(C3, glm::ivec4(1))) ? 0 : 1;
glm::ivec4 A4(3);
glm::ivec4 B4(2);
glm::ivec4 C4 = glm::fmod(A4, B4);
Error += glm::all(glm::equal(C4, glm::ivec4(1))) ? 0 : 1;
}
{
float A0(22.0);
float B0(-10.0f);
float C0 = glm::fmod(A0, B0);
Error += glm::abs(C0 - 2.0f) < 0.00001f ? 0 : 1;
glm::vec4 A1(22.0);
float B1(-10.0f);
glm::vec4 C1 = glm::fmod(A1, B1);
Error += glm::all(glm::epsilonEqual(C1, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
glm::vec4 A2(22.0);
glm::vec4 B2(-10.0f);
glm::vec4 C2 = glm::fmod(A2, B2);
Error += glm::all(glm::epsilonEqual(C2, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
glm::ivec4 A3(22);
int B3(-10);
glm::ivec4 C3 = glm::fmod(A3, B3);
Error += glm::all(glm::equal(C3, glm::ivec4(2))) ? 0 : 1;
glm::ivec4 A4(22);
glm::ivec4 B4(-10);
glm::ivec4 C4 = glm::fmod(A4, B4);
Error += glm::all(glm::equal(C4, glm::ivec4(2))) ? 0 : 1;
}
// http://stackoverflow.com/questions/7610631/glsl-mod-vs-hlsl-fmod
{
for (float y = -10.0f; y < 10.0f; y += 0.1f)
for (float x = -10.0f; x < 10.0f; x += 0.1f)
{
float const A(std::fmod(x, y));
//float const B(std::remainder(x, y));
float const C(glm::fmod(x, y));
float const D(modTrunc(x, y));
//Error += glm::epsilonEqual(A, B, 0.0001f) ? 0 : 1;
//assert(!Error);
Error += glm::epsilonEqual(A, C, 0.0001f) ? 0 : 1;
assert(!Error);
Error += glm::epsilonEqual(A, D, 0.00001f) ? 0 : 1;
assert(!Error);
}
}
return Error;
}
}//namespace fmod_
int test_isdenormal()
{
int Error = 0;
bool A = glm::isdenormal(1.0f);
Error += !A ? 0 : 1;
glm::bvec1 B = glm::isdenormal(glm::vec1(1.0f));
Error += !glm::any(B) ? 0 : 1;
glm::bvec2 C = glm::isdenormal(glm::vec2(1.0f));
Error += !glm::any(C) ? 0 : 1;
glm::bvec3 D = glm::isdenormal(glm::vec3(1.0f));
Error += !glm::any(D) ? 0 : 1;
glm::bvec4 E = glm::isdenormal(glm::vec4(1.0f));
Error += !glm::any(E) ? 0 : 1;
return Error;
}
int test_openBounded()
{
int Error = 0;
Error += glm::all(glm::openBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += !glm::all(glm::openBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += !glm::all(glm::openBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
return Error;
}
int test_closeBounded()
{
int Error = 0;
Error += glm::all(glm::closeBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += glm::all(glm::closeBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += glm::all(glm::closeBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_isdenormal();
Error += ::fmod_::test();
Error += test_openBounded();
Error += test_closeBounded();
return Error;
}

View File

@@ -0,0 +1,19 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/compatibility.hpp>
int main()
{
int Error(0);
Error += glm::isfinite(1.0f) ? 0 : 1;
Error += glm::isfinite(1.0) ? 0 : 1;
Error += glm::isfinite(-1.0f) ? 0 : 1;
Error += glm::isfinite(-1.0) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(1.0))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(-1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(-1.0))) ? 0 : 1;
return Error;
}

View File

@@ -0,0 +1,116 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/component_wise.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <limits>
namespace compNormalize
{
int run()
{
int Error(0);
{
glm::vec4 const A = glm::compNormalize<float>(glm::u8vec4(0, 127, 128, 255));
Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.5f ? 0 : 1;
Error += A.z > 0.5f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::i8vec4(-128, -1, 0, 127));
Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.0f ? 0 : 1;
Error += A.z > 0.0f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::u16vec4(
std::numeric_limits<glm::u16>::min(),
(std::numeric_limits<glm::u16>::max() >> 1) + 0,
(std::numeric_limits<glm::u16>::max() >> 1) + 1,
std::numeric_limits<glm::u16>::max()));
Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.5f ? 0 : 1;
Error += A.z > 0.5f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::i16vec4(
std::numeric_limits<glm::i16>::min(),
static_cast<glm::i16>(-1),
static_cast<glm::i16>(0),
std::numeric_limits<glm::i16>::max()));
Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.0f ? 0 : 1;
Error += A.z > 0.0f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
}//namespace compNormalize
namespace compScale
{
int run()
{
int Error(0);
{
glm::u8vec4 const A = glm::compScale<glm::u8>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
Error += A.x == std::numeric_limits<glm::u8>::min() ? 0 : 1;
Error += A.y < (std::numeric_limits<glm::u8>::max() >> 2) ? 0 : 1;
Error += A.z == 127 ? 0 : 1;
Error += A.w == 255 ? 0 : 1;
}
{
glm::i8vec4 const A = glm::compScale<glm::i8>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
Error += A.x == 0 ? 0 : 1;
Error += A.y == -128 ? 0 : 1;
Error += A.z == 63 ? 0 : 1;
Error += A.w == 127 ? 0 : 1;
}
{
glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
Error += A.x == std::numeric_limits<glm::u16>::min() ? 0 : 1;
Error += A.y < (std::numeric_limits<glm::u16>::max() >> 2) ? 0 : 1;
Error += A.z == 32767 ? 0 : 1;
Error += A.w == 65535 ? 0 : 1;
}
{
glm::i16vec4 const A = glm::compScale<glm::i16>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
Error += A.x == 0 ? 0 : 1;
Error += A.y == -32768 ? 0 : 1;
Error += A.z == 16383 ? 0 : 1;
Error += A.w == 32767 ? 0 : 1;
}
return Error;
}
}// compScale
int main()
{
int Error(0);
Error += compNormalize::run();
Error += compScale::run();
return Error;
}

View File

@@ -0,0 +1,205 @@
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_CTOR_INIT
#include <glm/gtx/dual_quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <glm/vector_relational.hpp>
#if GLM_HAS_TRIVIAL_QUERIES
# include <type_traits>
#endif
int myrand()
{
static int holdrand = 1;
return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
}
float myfrand() // returns values from -1 to 1 inclusive
{
return float(double(myrand()) / double( 0x7ffff )) * 2.0f - 1.0f;
}
int test_dquat_type()
{
glm::dvec3 vA;
glm::dquat dqA, dqB;
glm::ddualquat C(dqA, dqB);
glm::ddualquat B(dqA);
glm::ddualquat D(dqA, vA);
return 0;
}
int test_scalars()
{
float const Epsilon = 0.0001f;
int Error(0);
glm::quat src_q1 = glm::quat(1.0f,2.0f,3.0f,4.0f);
glm::quat src_q2 = glm::quat(5.0f,6.0f,7.0f,8.0f);
glm::dualquat src1(src_q1,src_q2);
{
glm::dualquat dst1 = src1 * 2.0f;
glm::dualquat dst2 = 2.0f * src1;
glm::dualquat dst3 = src1;
dst3 *= 2.0f;
glm::dualquat dstCmp(src_q1 * 2.0f,src_q2 * 2.0f);
Error += glm::all(glm::epsilonEqual(dst1.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst1.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst2.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst2.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst3.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst3.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
}
{
glm::dualquat dst1 = src1 / 2.0f;
glm::dualquat dst2 = src1;
dst2 /= 2.0f;
glm::dualquat dstCmp(src_q1 / 2.0f,src_q2 / 2.0f);
Error += glm::all(glm::epsilonEqual(dst1.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst1.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst2.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst2.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
}
return Error;
}
int test_inverse()
{
int Error(0);
float const Epsilon = 0.0001f;
glm::dualquat dqid = glm::dual_quat_identity<float, glm::defaultp>();
glm::mat4x4 mid(1.0f);
for (int j = 0; j < 100; ++j)
{
glm::mat4x4 rot = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::vec3 vt = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::mat4x4 m = glm::translate(mid, vt) * rot;
glm::quat qr = glm::quat_cast(m);
glm::dualquat dq(qr);
glm::dualquat invdq = glm::inverse(dq);
glm::dualquat r1 = invdq * dq;
glm::dualquat r2 = dq * invdq;
Error += glm::all(glm::epsilonEqual(r1.real, dqid.real, Epsilon)) && glm::all(glm::epsilonEqual(r1.dual, dqid.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(r2.real, dqid.real, Epsilon)) && glm::all(glm::epsilonEqual(r2.dual, dqid.dual, Epsilon)) ? 0 : 1;
// testing commutative property
glm::dualquat r ( glm::quat( myfrand() * glm::pi<float>() * 2.0f, myfrand(), myfrand(), myfrand() ),
glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f) );
glm::dualquat riq = (r * invdq) * dq;
glm::dualquat rqi = (r * dq) * invdq;
Error += glm::all(glm::epsilonEqual(riq.real, rqi.real, Epsilon)) && glm::all(glm::epsilonEqual(riq.dual, rqi.dual, Epsilon)) ? 0 : 1;
}
return Error;
}
int test_mul()
{
int Error(0);
float const Epsilon = 0.0001f;
glm::mat4x4 mid(1.0f);
for (int j = 0; j < 100; ++j)
{
// generate random rotations and translations and compare transformed by matrix and dualquats random points
glm::vec3 vt1 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::vec3 vt2 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::mat4x4 rot1 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::mat4x4 rot2 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::mat4x4 m1 = glm::translate(mid, vt1) * rot1;
glm::mat4x4 m2 = glm::translate(mid, vt2) * rot2;
glm::mat4x4 m3 = m2 * m1;
glm::mat4x4 m4 = m1 * m2;
glm::quat qrot1 = glm::quat_cast(rot1);
glm::quat qrot2 = glm::quat_cast(rot2);
glm::dualquat dq1 = glm::dualquat(qrot1,vt1);
glm::dualquat dq2 = glm::dualquat(qrot2,vt2);
glm::dualquat dq3 = dq2 * dq1;
glm::dualquat dq4 = dq1 * dq2;
for (int i = 0; i < 100; ++i)
{
glm::vec4 src_pt = glm::vec4(myfrand() * 4.0f, myfrand() * 5.0f, myfrand() * 3.0f,1.0f);
// test both multiplication orders
glm::vec4 dst_pt_m3 = m3 * src_pt;
glm::vec4 dst_pt_dq3 = dq3 * src_pt;
glm::vec4 dst_pt_m3_i = glm::inverse(m3) * src_pt;
glm::vec4 dst_pt_dq3_i = src_pt * dq3;
glm::vec4 dst_pt_m4 = m4 * src_pt;
glm::vec4 dst_pt_dq4 = dq4 * src_pt;
glm::vec4 dst_pt_m4_i = glm::inverse(m4) * src_pt;
glm::vec4 dst_pt_dq4_i = src_pt * dq4;
Error += glm::all(glm::epsilonEqual(dst_pt_m3, dst_pt_dq3, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m4, dst_pt_dq4, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m3_i, dst_pt_dq3_i, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m4_i, dst_pt_dq4_i, Epsilon)) ? 0 : 1;
}
}
return Error;
}
int test_dual_quat_ctr()
{
int Error(0);
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::dualquat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::ddualquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::dualquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::ddualquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dualquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ddualquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::dualquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::ddualquat>::value ? 0 : 1;
# endif
return Error;
}
int test_size()
{
int Error = 0;
Error += 32 == sizeof(glm::dualquat) ? 0 : 1;
Error += 64 == sizeof(glm::ddualquat) ? 0 : 1;
Error += glm::dualquat().length() == 2 ? 0 : 1;
Error += glm::ddualquat().length() == 2 ? 0 : 1;
Error += glm::dualquat::length() == 2 ? 0 : 1;
Error += glm::ddualquat::length() == 2 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_dual_quat_ctr();
Error += test_dquat_type();
Error += test_scalars();
Error += test_inverse();
Error += test_mul();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,65 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/easing.hpp>
namespace
{
template<typename T>
void _test_easing()
{
T a = static_cast<T>(0.5);
T r;
r = glm::linearInterpolation(a);
r = glm::quadraticEaseIn(a);
r = glm::quadraticEaseOut(a);
r = glm::quadraticEaseInOut(a);
r = glm::cubicEaseIn(a);
r = glm::cubicEaseOut(a);
r = glm::cubicEaseInOut(a);
r = glm::quarticEaseIn(a);
r = glm::quarticEaseOut(a);
r = glm::quinticEaseInOut(a);
r = glm::sineEaseIn(a);
r = glm::sineEaseOut(a);
r = glm::sineEaseInOut(a);
r = glm::circularEaseIn(a);
r = glm::circularEaseOut(a);
r = glm::circularEaseInOut(a);
r = glm::exponentialEaseIn(a);;
r = glm::exponentialEaseOut(a);
r = glm::exponentialEaseInOut(a);
r = glm::elasticEaseIn(a);
r = glm::elasticEaseOut(a);
r = glm::elasticEaseInOut(a);
r = glm::backEaseIn(a);
r = glm::backEaseOut(a);
r = glm::backEaseInOut(a);
r = glm::bounceEaseIn(a);;
r = glm::bounceEaseOut(a);
r = glm::bounceEaseInOut(a);
}
}
int main()
{
int Error = 0;
_test_easing<float>();
_test_easing<double>();
return Error;
}

View File

@@ -0,0 +1,539 @@
// Code sample from Filippo Ramaciotti
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/matrix_cross_product.hpp>
#include <glm/gtx/matrix_operation.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <cstdio>
#include <vector>
#include <utility>
namespace test_eulerAngleX
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const X(1.0f, 0.0f, 0.0f);
glm::vec4 const Y(0.0f, 1.0f, 0.0f, 1.0f);
glm::vec4 const Y1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Y;
glm::vec4 const Y2 = glm::eulerAngleX(Angle) * Y;
glm::vec4 const Y3 = glm::eulerAngleXY(Angle, 0.0f) * Y;
glm::vec4 const Y4 = glm::eulerAngleYX(0.0f, Angle) * Y;
glm::vec4 const Y5 = glm::eulerAngleXZ(Angle, 0.0f) * Y;
glm::vec4 const Y6 = glm::eulerAngleZX(0.0f, Angle) * Y;
glm::vec4 const Y7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Y;
Error += glm::all(glm::epsilonEqual(Y1, Y2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y7, 0.00001f)) ? 0 : 1;
glm::vec4 const Z(0.0f, 0.0f, 1.0f, 1.0f);
glm::vec4 const Z1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Z;
glm::vec4 const Z2 = glm::eulerAngleX(Angle) * Z;
glm::vec4 const Z3 = glm::eulerAngleXY(Angle, 0.0f) * Z;
glm::vec4 const Z4 = glm::eulerAngleYX(0.0f, Angle) * Z;
glm::vec4 const Z5 = glm::eulerAngleXZ(Angle, 0.0f) * Z;
glm::vec4 const Z6 = glm::eulerAngleZX(0.0f, Angle) * Z;
glm::vec4 const Z7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Z;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleX
namespace test_eulerAngleY
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const Y(0.0f, 1.0f, 0.0f);
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const X1 = glm::rotate(glm::mat4(1.0f), Angle, Y) * X;
glm::vec4 const X2 = glm::eulerAngleY(Angle) * X;
glm::vec4 const X3 = glm::eulerAngleYX(Angle, 0.0f) * X;
glm::vec4 const X4 = glm::eulerAngleXY(0.0f, Angle) * X;
glm::vec4 const X5 = glm::eulerAngleYZ(Angle, 0.0f) * X;
glm::vec4 const X6 = glm::eulerAngleZY(0.0f, Angle) * X;
glm::vec4 const X7 = glm::eulerAngleYXZ(Angle, 0.0f, 0.0f) * X;
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X7, 0.00001f)) ? 0 : 1;
glm::vec4 const Z(0.0f, 0.0f, 1.0f, 1.0f);
glm::vec4 const Z1 = glm::eulerAngleY(Angle) * Z;
glm::vec4 const Z2 = glm::rotate(glm::mat4(1.0f), Angle, Y) * Z;
glm::vec4 const Z3 = glm::eulerAngleYX(Angle, 0.0f) * Z;
glm::vec4 const Z4 = glm::eulerAngleXY(0.0f, Angle) * Z;
glm::vec4 const Z5 = glm::eulerAngleYZ(Angle, 0.0f) * Z;
glm::vec4 const Z6 = glm::eulerAngleZY(0.0f, Angle) * Z;
glm::vec4 const Z7 = glm::eulerAngleYXZ(Angle, 0.0f, 0.0f) * Z;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleY
namespace test_eulerAngleZ
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const Z(0.0f, 0.0f, 1.0f);
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const X1 = glm::rotate(glm::mat4(1.0f), Angle, Z) * X;
glm::vec4 const X2 = glm::eulerAngleZ(Angle) * X;
glm::vec4 const X3 = glm::eulerAngleZX(Angle, 0.0f) * X;
glm::vec4 const X4 = glm::eulerAngleXZ(0.0f, Angle) * X;
glm::vec4 const X5 = glm::eulerAngleZY(Angle, 0.0f) * X;
glm::vec4 const X6 = glm::eulerAngleYZ(0.0f, Angle) * X;
glm::vec4 const X7 = glm::eulerAngleYXZ(0.0f, 0.0f, Angle) * X;
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X7, 0.00001f)) ? 0 : 1;
glm::vec4 const Y(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const Z1 = glm::rotate(glm::mat4(1.0f), Angle, Z) * Y;
glm::vec4 const Z2 = glm::eulerAngleZ(Angle) * Y;
glm::vec4 const Z3 = glm::eulerAngleZX(Angle, 0.0f) * Y;
glm::vec4 const Z4 = glm::eulerAngleXZ(0.0f, Angle) * Y;
glm::vec4 const Z5 = glm::eulerAngleZY(Angle, 0.0f) * Y;
glm::vec4 const Z6 = glm::eulerAngleYZ(0.0f, Angle) * Y;
glm::vec4 const Z7 = glm::eulerAngleYXZ(0.0f, 0.0f, Angle) * Y;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZ
namespace test_derivedEulerAngles
{
bool epsilonEqual(glm::mat4 const& mat1, glm::mat4 const& mat2, glm::mat4::value_type const& epsilon)
{
return glm::all(glm::epsilonEqual(mat1[0], mat2[0], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[1], mat2[1], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[2], mat2[2], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[3], mat2[3], epsilon)) ? true : false
) : false
) : false
) : false;
}
template<typename RotationFunc, typename TestDerivedFunc>
int test(RotationFunc rotationFunc, TestDerivedFunc testDerivedFunc, const glm::vec3& basis)
{
int Error = 0;
typedef glm::vec3::value_type value;
value const zeroAngle(0.0f);
value const Angle(glm::pi<float>() * 0.75f);
value const negativeAngle(-Angle);
value const zeroAngleVelocity(0.0f);
value const AngleVelocity(glm::pi<float>() * 0.27f);
value const negativeAngleVelocity(-AngleVelocity);
typedef std::pair<value,value> AngleAndAngleVelocity;
std::vector<AngleAndAngleVelocity> testPairs;
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, negativeAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, negativeAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, negativeAngleVelocity));
for (size_t i = 0, size = testPairs.size(); i < size; ++i)
{
AngleAndAngleVelocity const& pair = testPairs.at(i);
glm::mat4 const W = glm::matrixCross4(basis * pair.second);
glm::mat4 const rotMt = glm::transpose(rotationFunc(pair.first));
glm::mat4 const derivedRotM = testDerivedFunc(pair.first, pair.second);
Error += epsilonEqual(W, derivedRotM * rotMt, 0.00001f) ? 0 : 1;
}
return Error;
}
}//namespace test_derivedEulerAngles
namespace test_eulerAngleXY
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleY(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleX, axisX) * glm::rotate(glm::mat4(1.0f), AngleY, axisY)) * V;
glm::vec4 const V2 = glm::eulerAngleXY(AngleX, AngleY) * V;
glm::vec4 const V3 = glm::eulerAngleX(AngleX) * glm::eulerAngleY(AngleY) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleXY
namespace test_eulerAngleYX
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleY(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleY, axisY) * glm::rotate(glm::mat4(1.0f), AngleX, axisX)) * V;
glm::vec4 const V2 = glm::eulerAngleYX(AngleY, AngleX) * V;
glm::vec4 const V3 = glm::eulerAngleY(AngleY) * glm::eulerAngleX(AngleX) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleYX
namespace test_eulerAngleXZ
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleX, axisX) * glm::rotate(glm::mat4(1.0f), AngleZ, axisZ)) * V;
glm::vec4 const V2 = glm::eulerAngleXZ(AngleX, AngleZ) * V;
glm::vec4 const V3 = glm::eulerAngleX(AngleX) * glm::eulerAngleZ(AngleZ) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleXZ
namespace test_eulerAngleZX
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleZ, axisZ) * glm::rotate(glm::mat4(1.0f), AngleX, axisX)) * V;
glm::vec4 const V2 = glm::eulerAngleZX(AngleZ, AngleX) * V;
glm::vec4 const V3 = glm::eulerAngleZ(AngleZ) * glm::eulerAngleX(AngleX) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZX
namespace test_eulerAngleYZ
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleY(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleY, axisY) * glm::rotate(glm::mat4(1.0f), AngleZ, axisZ)) * V;
glm::vec4 const V2 = glm::eulerAngleYZ(AngleY, AngleZ) * V;
glm::vec4 const V3 = glm::eulerAngleY(AngleY) * glm::eulerAngleZ(AngleZ) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleYZ
namespace test_eulerAngleZY
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleY(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleZ, axisZ) * glm::rotate(glm::mat4(1.0f), AngleY, axisY)) * V;
glm::vec4 const V2 = glm::eulerAngleZY(AngleZ, AngleY) * V;
glm::vec4 const V3 = glm::eulerAngleZ(AngleZ) * glm::eulerAngleY(AngleY) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZY
namespace test_eulerAngleYXZ
{
int test()
{
glm::f32 first = 1.046f;
glm::f32 second = 0.52f;
glm::f32 third = -0.785f;
glm::fmat4 rotationEuler = glm::eulerAngleYXZ(first, second, third);
glm::fmat4 rotationInvertedY = glm::eulerAngleY(-1.f*first) * glm::eulerAngleX(second) * glm::eulerAngleZ(third);
glm::fmat4 rotationDumb = glm::fmat4();
rotationDumb = glm::rotate(rotationDumb, first, glm::fvec3(0,1,0));
rotationDumb = glm::rotate(rotationDumb, second, glm::fvec3(1,0,0));
rotationDumb = glm::rotate(rotationDumb, third, glm::fvec3(0,0,1));
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler)).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationDumb)).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationInvertedY)).c_str());
std::printf("\nRESIDUAL\n");
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler-(rotationDumb))).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler-(rotationInvertedY))).c_str());
return 0;
}
}//namespace eulerAngleYXZ
namespace test_eulerAngles
{
template<typename TestRotationFunc>
int test(TestRotationFunc testRotationFunc, glm::vec3 const& I, glm::vec3 const& J, glm::vec3 const& K)
{
int Error = 0;
typedef glm::mat4::value_type value;
value const minAngle(-glm::pi<value>());
value const maxAngle(glm::pi<value>());
value const maxAngleWithDelta(maxAngle - 0.0000001f);
value const minMidAngle(-glm::pi<value>() * 0.5f);
value const maxMidAngle(glm::pi<value>() * 0.5f);
std::vector<glm::vec3> testEulerAngles;
testEulerAngles.push_back(glm::vec3(1.046f, 0.52f, -0.785f));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, maxAngle));
for (size_t i = 0, size = testEulerAngles.size(); i < size; ++i)
{
glm::vec3 const& angles = testEulerAngles.at(i);
glm::mat4 const rotationEuler = testRotationFunc(angles.x, angles.y, angles.z);
glm::mat4 rotationDumb = glm::diagonal4x4(glm::mat4::col_type(1.0f));
rotationDumb = glm::rotate(rotationDumb, angles.x, I);
rotationDumb = glm::rotate(rotationDumb, angles.y, J);
rotationDumb = glm::rotate(rotationDumb, angles.z, K);
glm::vec4 const V(1.0f,1.0f,1.0f,1.0f);
glm::vec4 const V1 = rotationEuler * V;
glm::vec4 const V2 = rotationDumb * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace test_extractsEulerAngles
namespace test_extractsEulerAngles
{
template<typename RotationFunc, typename TestExtractionFunc>
int test(RotationFunc rotationFunc, TestExtractionFunc testExtractionFunc)
{
int Error = 0;
typedef glm::mat4::value_type value;
value const minAngle(-glm::pi<value>());
value const maxAngle(glm::pi<value>());
value const maxAngleWithDelta(maxAngle - 0.0000001f);
value const minMidAngle(-glm::pi<value>() * 0.5f);
value const maxMidAngle(glm::pi<value>() * 0.5f);
std::vector<glm::vec3> testEulerAngles;
testEulerAngles.push_back(glm::vec3(1.046f, 0.52f, -0.785f));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, maxAngle));
for (size_t i = 0, size = testEulerAngles.size(); i < size; ++i)
{
glm::vec3 const& angles = testEulerAngles.at(i);
glm::mat4 const rotation = rotationFunc(angles.x, angles.y, angles.z);
glm::vec3 extractedEulerAngles(0.0f);
testExtractionFunc(rotation, extractedEulerAngles.x, extractedEulerAngles.y, extractedEulerAngles.z);
glm::mat4 const extractedRotation = rotationFunc(extractedEulerAngles.x, extractedEulerAngles.y, extractedEulerAngles.z);
glm::vec4 const V(1.0f,1.0f,1.0f,1.0f);
glm::vec4 const V1 = rotation * V;
glm::vec4 const V2 = extractedRotation * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace test_extractsEulerAngles
int main()
{
int Error = 0;
typedef glm::mat4::value_type value;
glm::vec3 const X(1.0f, 0.0f, 0.0f);
glm::vec3 const Y(0.0f, 1.0f, 0.0f);
glm::vec3 const Z(0.0f, 0.0f, 1.0f);
Error += test_eulerAngleX::test();
Error += test_eulerAngleY::test();
Error += test_eulerAngleZ::test();
Error += test_derivedEulerAngles::test(glm::eulerAngleX<value>, glm::derivedEulerAngleX<value>, X);
Error += test_derivedEulerAngles::test(glm::eulerAngleY<value>, glm::derivedEulerAngleY<value>, Y);
Error += test_derivedEulerAngles::test(glm::eulerAngleZ<value>, glm::derivedEulerAngleZ<value>, Z);
Error += test_eulerAngleXY::test();
Error += test_eulerAngleYX::test();
Error += test_eulerAngleXZ::test();
Error += test_eulerAngleZX::test();
Error += test_eulerAngleYZ::test();
Error += test_eulerAngleZY::test();
Error += test_eulerAngleYXZ::test();
Error += test_eulerAngles::test(glm::eulerAngleXZX<value>, X, Z, X);
Error += test_eulerAngles::test(glm::eulerAngleXYX<value>, X, Y, X);
Error += test_eulerAngles::test(glm::eulerAngleYXY<value>, Y, X, Y);
Error += test_eulerAngles::test(glm::eulerAngleYZY<value>, Y, Z, Y);
Error += test_eulerAngles::test(glm::eulerAngleZYZ<value>, Z, Y, Z);
Error += test_eulerAngles::test(glm::eulerAngleZXZ<value>, Z, X, Z);
Error += test_eulerAngles::test(glm::eulerAngleXZY<value>, X, Z, Y);
Error += test_eulerAngles::test(glm::eulerAngleYZX<value>, Y, Z, X);
Error += test_eulerAngles::test(glm::eulerAngleZYX<value>, Z, Y, X);
Error += test_eulerAngles::test(glm::eulerAngleZXY<value>, Z, X, Y);
Error += test_extractsEulerAngles::test(glm::eulerAngleYXZ<value>, glm::extractEulerAngleYXZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXZX<value>, glm::extractEulerAngleXZX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXYX<value>, glm::extractEulerAngleXYX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYXY<value>, glm::extractEulerAngleYXY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYZY<value>, glm::extractEulerAngleYZY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZYZ<value>, glm::extractEulerAngleZYZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZXZ<value>, glm::extractEulerAngleZXZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXZY<value>, glm::extractEulerAngleXZY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYZX<value>, glm::extractEulerAngleYZX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZYX<value>, glm::extractEulerAngleZYX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZXY<value>, glm::extractEulerAngleZXY<value>);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/extend.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,99 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/extended_min_max.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
// This file has divisions by zero to test isnan
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(disable : 4723)
#endif
namespace fmin_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fmin(glm::vec1(1), glm::vec1(Zero_f / 0.0f));
Error += glm::epsilonEqual(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec1 A1 = glm::fmin(glm::vec1(Zero_f / 0.0f), glm::vec1(1));
Error += glm::epsilonEqual(A1.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec2 B0 = glm::fmin(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::fmin(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::fmin(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::fmin(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::fmin(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::fmin(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1));
Error += D2 ? 0 : 1;
return Error;
}
}//namespace fmin_
namespace fmax_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fmax(glm::vec1(1), glm::vec1(Zero_f / 0.0f));
Error += glm::epsilonEqual(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec1 A1 = glm::fmax(glm::vec1(Zero_f / 0.0f), glm::vec1(1));
Error += glm::epsilonEqual(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec2 B0 = glm::fmax(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::fmax(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::fmax(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::fmax(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::fmax(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::fmax(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1));
Error += D2 ? 0 : 1;
return Error;
}
}//namespace fmax_
namespace fclamp_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fclamp(glm::vec1(1), glm::vec1(Zero_f / 0.0f), glm::vec1(2.0f));
Error += glm::epsilonEqual(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
return Error;
}
}//namespace fclamp_
int main()
{
int Error = 0;
Error += fmin_::test();
Error += fmax_::test();
Error += fclamp_::test();
return Error;
}

View File

@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @file test/gtx/gtx_extented_min_max.cpp
/// @date 2013-10-25 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <glm/gtx/extended_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,14 @@
#include <glm/gtx/exterior_product.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vec2.hpp>
int main()
{
int Error = 0;
float const f = glm::cross(glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f));
Error += glm::epsilonEqual(f, 0.0f, 0.001f) ? 0 : 1;
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/fast_exponential.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,46 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/fast_square_root.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
int test_fastInverseSqrt()
{
int Error(0);
Error += glm::epsilonEqual(glm::fastInverseSqrt(1.0f), 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(glm::fastInverseSqrt(1.0), 1.0, 0.01) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::vec2(1.0f)), glm::vec2(1.0f), 0.01f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::dvec3(1.0)), glm::dvec3(1.0), 0.01)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::dvec4(1.0)), glm::dvec4(1.0), 0.01)) ? 0 : 1;
return 0;
}
int test_fastDistance()
{
int Error(0);
glm::mediump_f32 A = glm::fastDistance(glm::mediump_f32(0.0f), glm::mediump_f32(1.0f));
glm::mediump_f32 B = glm::fastDistance(glm::mediump_f32vec2(0.0f), glm::mediump_f32vec2(1.0f, 0.0f));
glm::mediump_f32 C = glm::fastDistance(glm::mediump_f32vec3(0.0f), glm::mediump_f32vec3(1.0f, 0.0f, 0.0f));
glm::mediump_f32 D = glm::fastDistance(glm::mediump_f32vec4(0.0f), glm::mediump_f32vec4(1.0f, 0.0f, 0.0f, 0.0f));
Error += glm::epsilonEqual(A, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
Error += glm::epsilonEqual(B, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
Error += glm::epsilonEqual(C, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
Error += glm::epsilonEqual(D, glm::mediump_f32(1.0f), glm::mediump_f32(0.01f)) ? 0 : 1;
return Error;
}
int main()
{
int Error(0);
Error += test_fastInverseSqrt();
Error += test_fastDistance();
return Error;
}

View File

@@ -0,0 +1,563 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/fast_trigonometry.hpp>
#include <glm/gtx/integer.hpp>
#include <glm/gtx/common.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/trigonometric.hpp>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
namespace fastCos
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastCos(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::cos(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastCos Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("cos Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastCos
namespace fastSin
{
/*
float sin(float x) {
float temp;
temp = (x + M_PI) / ((2 * M_PI) - M_PI);
return limited_sin((x + M_PI) - ((2 * M_PI) - M_PI) * temp));
}
*/
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastSin(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::sin(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastSin Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("sin Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastSin
namespace fastTan
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastTan(i);
const std::clock_t timestamp2 = std::clock();
for (float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::tan(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastTan Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("tan Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastTan
namespace fastAcos
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastAcos(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::acos(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAcos Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("acos Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAcos
namespace fastAsin
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastAsin(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::asin(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAsin Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("asin Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAsin
namespace fastAtan
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::fastAtan(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::next_float(i) : i += 0.1f)
result = glm::atan(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAtan Time %d clocks\n", static_cast<unsigned int>(time_fast));
std::printf("atan Time %d clocks\n", static_cast<unsigned int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAtan
namespace taylorCos
{
using glm::qualifier;
using glm::length_t;
glm::vec4 const AngleShift(0.0f, glm::half_pi<float>(), glm::pi<float>(), glm::three_over_two_pi<float>());
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
glm::vec<L, T, Q> const Powed8(Powed4 * Powed4);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
+ Powed4 * static_cast<T>(0.04166666666666666666666666666667)
- Powed6 * static_cast<T>(0.00138888888888888888888888888889)
+ Powed8 * static_cast<T>(2.4801587301587301587301587301587e-5);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos6(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
+ Powed4 * static_cast<T>(0.04166666666666666666666666666667)
- Powed6 * static_cast<T>(0.00138888888888888888888888888889);
}
template<glm::length_t L, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, float, Q> fastAbs(glm::vec<L, float, Q> x)
{
int* Pointer = reinterpret_cast<int*>(&x[0]);
Pointer[0] &= 0x7fffffff;
Pointer[1] &= 0x7fffffff;
Pointer[2] &= 0x7fffffff;
Pointer[3] &= 0x7fffffff;
return x;
}
template<glm::length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosNew(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(fastAbs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
return taylorSeriesNewCos6(x);
/*
vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, vec<L, T, Q>(glm::half_pi<T>())));
vec<L, T, Q> const RevertAngle(mix(vec<L, T, Q>(glm::pi<T>()), vec<L, T, Q>(0), FirstQuarterPi));
vec<L, T, Q> const ReturnSign(mix(vec<L, T, Q>(-1), vec<L, T, Q>(1), FirstQuarterPi));
vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
*/
}
int perf_fastCosNew(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = fastCosNew(AngleShift + glm::vec4(Begin + Steps * i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosNew %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> deterministic_fmod(glm::vec<L, T, Q> const& x, T y)
{
return x - y * trunc(x / y);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosDeterminisctic(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(abs(deterministic_fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
}
int perf_fastCosDeterminisctic(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCos::fastCosDeterminisctic(AngleShift + glm::vec4(Begin + Steps * i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosDeterminisctic %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesRefCos(glm::vec<L, T, Q> const& x)
{
return static_cast<T>(1)
- (x * x) / glm::factorial(static_cast<T>(2))
+ (x * x * x * x) / glm::factorial(static_cast<T>(4))
- (x * x * x * x * x * x) / glm::factorial(static_cast<T>(6))
+ (x * x * x * x * x * x * x * x) / glm::factorial(static_cast<T>(8));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastRefCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(glm::abs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
// return taylorSeriesRefCos(Angle0_PI);
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesRefCos(SectionAngle);
}
int perf_fastCosRef(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCos::fastRefCos(AngleShift + glm::vec4(Begin + Steps * i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosRef %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf_fastCosOld(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = glm::fastCos(AngleShift + glm::vec4(Begin + Steps * i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosOld %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf_cos(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = glm::cos(AngleShift + glm::vec4(Begin + Steps * i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("cos %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf(std::size_t const Samples)
{
int Error = 0;
float const Begin = -glm::pi<float>();
float const End = glm::pi<float>();
Error += perf_cos(Begin, End, Samples);
Error += perf_fastCosOld(Begin, End, Samples);
Error += perf_fastCosRef(Begin, End, Samples);
//Error += perf_fastCosNew(Begin, End, Samples);
Error += perf_fastCosDeterminisctic(Begin, End, Samples);
return Error;
}
int test()
{
int Error = 0;
//for(float Angle = -4.0f * glm::pi<float>(); Angle < 4.0f * glm::pi<float>(); Angle += 0.1f)
//for(float Angle = -720.0f; Angle < 720.0f; Angle += 0.1f)
for(float Angle = 0.0f; Angle < 180.0f; Angle += 0.1f)
{
float const modAngle = std::fmod(glm::abs(Angle), 360.f);
assert(modAngle >= 0.0f && modAngle <= 360.f);
float const radAngle = glm::radians(modAngle);
float const Cos0 = std::cos(radAngle);
float const Cos1 = taylorCos::fastRefCos(glm::fvec1(radAngle)).x;
Error += glm::abs(Cos1 - Cos0) < 0.1f ? 0 : 1;
//float const Cos2 = taylorCos::fastCosNew(glm::fvec1(radAngle)).x;
//Error += glm::abs(Cos2 - Cos0) < 0.1f ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace taylorCos
namespace taylor2
{
glm::vec4 const AngleShift(0.0f, glm::pi<float>() * 0.5f, glm::pi<float>() * 1.0f, glm::pi<float>() * 1.5f);
float taylorCosA(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ (x * x * x * x) * (1.f / 24.f)
- (x * x * x * x * x * x) * (1.f / 720.f)
+ (x * x * x * x * x * x * x * x) * (1.f / 40320.f);
}
float taylorCosB(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ (x * x * x * x) * (1.f / 24.f)
- (x * x * x * x * x * x) * (1.f / 720.f)
+ (x * x * x * x * x * x * x * x) * (1.f / 40320.f);
}
float taylorCosC(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ ((x * x) * (x * x)) * (1.f / 24.f)
- (((x * x) * (x * x)) * (x * x)) * (1.f / 720.f)
+ (((x * x) * (x * x)) * ((x * x) * (x * x))) * (1.f / 40320.f);
}
int perf_taylorCosA(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosA(AngleShift.x + Begin + Steps * i);
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosA %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf_taylorCosB(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosB(AngleShift.x + Begin + Steps * i);
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosB %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf_taylorCosC(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float Steps = (End - Begin) / Samples;
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosC(AngleShift.x + Begin + Steps * i);
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosC %ld clocks\n", TimeStampEnd - TimeStampBegin);
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf(std::size_t Samples)
{
int Error = 0;
float const Begin = -glm::pi<float>();
float const End = glm::pi<float>();
Error += perf_taylorCosA(Begin, End, Samples);
Error += perf_taylorCosB(Begin, End, Samples);
Error += perf_taylorCosC(Begin, End, Samples);
return Error;
}
}//namespace taylor2
int main()
{
int Error(0);
Error += ::taylor2::perf(1000);
Error += ::taylorCos::test();
Error += ::taylorCos::perf(1000);
# ifdef NDEBUG
::fastCos::perf(false);
::fastSin::perf(false);
::fastTan::perf(false);
::fastAcos::perf(false);
::fastAsin::perf(false);
::fastAtan::perf(false);
# endif//NDEBUG
return Error;
}

View File

@@ -0,0 +1,35 @@
#include <glm/gtx/functions.hpp>
#include <vector>
int test_gauss_1d()
{
int Error = 0;
std::vector<float> Result(20);
for(std::size_t i = 0, n = Result.size(); i < n; ++i)
Result[i] = glm::gauss(static_cast<float>(i) * 0.1f, 0.0f, 1.0f);
return Error;
}
int test_gauss_2d()
{
int Error = 0;
std::vector<float> Result(20);
for(std::size_t i = 0, n = Result.size(); i < n; ++i)
Result[i] = glm::gauss(glm::vec2(static_cast<float>(i)) * 0.1f, glm::vec2(0.0f), glm::vec2(1.0f));
return Error;
}
int main()
{
int Error = 0;
Error += test_gauss_1d();
Error += test_gauss_2d();
return Error;
}

View File

@@ -0,0 +1,34 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/gradient_paint.hpp>
int test_radialGradient()
{
int Error = 0;
float Gradient = glm::radialGradient(glm::vec2(0), 1.0f, glm::vec2(1), glm::vec2(0.5));
Error += Gradient != 0.0f ? 0 : 1;
return Error;
}
int test_linearGradient()
{
int Error = 0;
float Gradient = glm::linearGradient(glm::vec2(0), glm::vec2(1), glm::vec2(0.5));
Error += Gradient != 0.0f ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_radialGradient();
Error += test_linearGradient();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/handed_coordinate_space.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,18 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2013-10-25
// Updated : 2013-10-25
// Licence : This source is under MIT licence
// File : test/gtx/associated_min_max.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,108 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/exponential.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/integer.hpp>
#include <cstdio>
/*
int test_floor_log2()
{
int Error = 0;
for(std::size_t i = 1; i < 1000000; ++i)
{
glm::uint A = glm::floor_log2(glm::uint(i));
glm::uint B = glm::uint(glm::floor(glm::log2(double(i)))); // Will fail with float, lack of accuracy
Error += A == B ? 0 : 1;
assert(!Error);
}
return Error;
}
*/
int test_log2()
{
int Error = 0;
for(std::size_t i = 1; i < 24; ++i)
{
glm::uint A = glm::log2(glm::uint(1 << i));
glm::uint B = glm::uint(glm::log2(double(1 << i)));
//Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1;
Error += glm::abs(double(A) - B) <= 24 ? 0 : 1;
assert(!Error);
printf("Log2(%d) error A=%d, B=%d\n", 1 << i, A, B);
}
printf("log2 error=%d\n", Error);
return Error;
}
int test_nlz()
{
int Error = 0;
for(glm::uint i = 1; i < glm::uint(33); ++i)
Error += glm::nlz(i) == glm::uint(31u) - glm::findMSB(i) ? 0 : 1;
//printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i));
return Error;
}
int test_pow_uint()
{
int Error = 0;
glm::uint const p0 = glm::pow(2u, 0u);
Error += p0 == 1u ? 0 : 1;
glm::uint const p1 = glm::pow(2u, 1u);
Error += p1 == 2u ? 0 : 1;
glm::uint const p2 = glm::pow(2u, 2u);
Error += p2 == 4u ? 0 : 1;
return Error;
}
int test_pow_int()
{
int Error = 0;
int const p0 = glm::pow(2, 0u);
Error += p0 == 1 ? 0 : 1;
int const p1 = glm::pow(2, 1u);
Error += p1 == 2 ? 0 : 1;
int const p2 = glm::pow(2, 2u);
Error += p2 == 4 ? 0 : 1;
int const p0n = glm::pow(-2, 0u);
Error += p0n == -1 ? 0 : 1;
int const p1n = glm::pow(-2, 1u);
Error += p1n == -2 ? 0 : 1;
int const p2n = glm::pow(-2, 2u);
Error += p2n == 4 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_nlz();
// Error += test_floor_log2();
Error += test_log2();
Error += test_pow_uint();
Error += test_pow_int();
return Error;
}

View File

@@ -0,0 +1,34 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/intersect.hpp>
int test_intersectRayTriangle()
{
int Error = 0;
glm::vec3 const Orig(0, 0, 2);
glm::vec3 const Dir(0, 0, -1);
glm::vec3 const Vert0(0, 0, 0);
glm::vec3 const Vert1(-1, -1, 0);
glm::vec3 const Vert2(1, -1, 0);
glm::vec2 BaryPosition(0);
float Distance = 0;
bool const Result = glm::intersectRayTriangle(Orig, Dir, Vert0, Vert1, Vert2, BaryPosition, Distance);
Error += glm::all(glm::epsilonEqual(BaryPosition, glm::vec2(0), std::numeric_limits<float>::epsilon())) ? 0 : 1;
Error += glm::abs(Distance - 2.f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += Result ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_intersectRayTriangle();
return Error;
}

176
ref/glm/test/gtx/gtx_io.cpp Normal file
View File

@@ -0,0 +1,176 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/io.hpp>
#include <iostream>
#include <sstream>
#include <typeinfo>
namespace
{
template<typename CTy, typename CTr>
std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, glm::qualifier const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if (cerberus)
{
switch (a) {
case glm::highp: os << "uhi"; break;
case glm::mediump: os << "umd"; break;
case glm::lowp: os << "ulo"; break;
# if GLM_HAS_ALIGNED_TYPE
case glm::aligned_highp: os << "ahi"; break;
case glm::aligned_mediump: os << "amd"; break;
case glm::aligned_lowp: os << "alo"; break;
# endif
}
}
return os;
}
template<typename U, glm::qualifier P, typename T, typename CTy, typename CTr>
std::basic_string<CTy> type_name(std::basic_ostream<CTy,CTr>&, T const&)
{
std::basic_ostringstream<CTy,CTr> ostr;
if (typeid(T) == typeid(glm::tquat<U,P>)) { ostr << "quat"; }
else if (typeid(T) == typeid(glm::vec<2, U,P>)) { ostr << "vec2"; }
else if (typeid(T) == typeid(glm::vec<3, U,P>)) { ostr << "vec3"; }
else if (typeid(T) == typeid(glm::vec<4, U,P>)) { ostr << "vec4"; }
else if (typeid(T) == typeid(glm::mat<2, 2, U,P>)) { ostr << "mat2x2"; }
else if (typeid(T) == typeid(glm::mat<2, 3, U,P>)) { ostr << "mat2x3"; }
else if (typeid(T) == typeid(glm::mat<2, 4, U,P>)) { ostr << "mat2x4"; }
else if (typeid(T) == typeid(glm::mat<3, 2, U,P>)) { ostr << "mat3x2"; }
else if (typeid(T) == typeid(glm::mat<3, 3, U,P>)) { ostr << "mat3x3"; }
else if (typeid(T) == typeid(glm::mat<3, 4, U,P>)) { ostr << "mat3x4"; }
else if (typeid(T) == typeid(glm::mat<4, 2, U,P>)) { ostr << "mat4x2"; }
else if (typeid(T) == typeid(glm::mat<4, 3, U,P>)) { ostr << "mat4x3"; }
else if (typeid(T) == typeid(glm::mat<4, 4, U,P>)) { ostr << "mat4x4"; }
else { ostr << "unknown"; }
ostr << '<' << typeid(U).name() << ',' << P << '>';
return ostr.str();
}
} // namespace {
template<typename T, glm::qualifier P, typename OS>
int test_io_quat(OS& os)
{
os << '\n' << typeid(OS).name() << '\n';
glm::tquat<T,P> const q(1, 0, 0, 0);
{
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< type_name<T,P>(os, q) << ": " << q << '\n';
}
{
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::unformatted
<< type_name<T,P>(os, q) << ": " << q << '\n';
}
return 0;
}
template<typename T, glm::qualifier P, typename OS>
int test_io_vec(OS& os)
{
os << '\n' << typeid(OS).name() << '\n';
glm::vec<2, T,P> const v2(0, 1);
glm::vec<3, T,P> const v3(2, 3, 4);
glm::vec<4, T,P> const v4(5, 6, 7, 8);
os << type_name<T,P>(os, v2) << ": " << v2 << '\n'
<< type_name<T,P>(os, v3) << ": " << v3 << '\n'
<< type_name<T,P>(os, v4) << ": " << v4 << '\n';
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< type_name<T,P>(os, v2) << ": " << v2 << '\n'
<< type_name<T,P>(os, v3) << ": " << v3 << '\n'
<< type_name<T,P>(os, v4) << ": " << v4 << '\n';
return 0;
}
template<typename T, glm::qualifier P, typename OS>
int test_io_mat(OS& os, glm::io::order_type otype)
{
os << '\n' << typeid(OS).name() << '\n';
glm::vec<2, T,P> const v2_1( 0, 1);
glm::vec<2, T,P> const v2_2( 2, 3);
glm::vec<2, T,P> const v2_3( 4, 5);
glm::vec<2, T,P> const v2_4( 6, 7);
glm::vec<3, T,P> const v3_1( 8, 9, 10);
glm::vec<3, T,P> const v3_2(11, 12, 13);
glm::vec<3, T,P> const v3_3(14, 15, 16);
glm::vec<3, T,P> const v3_4(17, 18, 19);
glm::vec<4, T,P> const v4_1(20, 21, 22, 23);
glm::vec<4, T,P> const v4_2(24, 25, 26, 27);
glm::vec<4, T,P> const v4_3(28, 29, 30, 31);
glm::vec<4, T,P> const v4_4(32, 33, 34, 35);
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< glm::io::order(otype)
<< "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
<< "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
<< "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
<< "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
<< "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
<< "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
<< "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
<< "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
<< "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
os << glm::io::unformatted
<< glm::io::order(otype)
<< "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
<< "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
<< "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
<< "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
<< "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
<< "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
<< "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
<< "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
<< "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
return 0;
}
int main()
{
int Error(0);
Error += test_io_quat<float, glm::highp>(std::cout);
Error += test_io_quat<float, glm::highp>(std::wcout);
Error += test_io_quat<int, glm::mediump>(std::cout);
Error += test_io_quat<int, glm::mediump>(std::wcout);
Error += test_io_quat<glm::uint, glm::lowp>(std::cout);
Error += test_io_quat<glm::uint, glm::lowp>(std::wcout);
Error += test_io_vec<float, glm::highp>(std::cout);
Error += test_io_vec<float, glm::highp>(std::wcout);
Error += test_io_vec<int, glm::mediump>(std::cout);
Error += test_io_vec<int, glm::mediump>(std::wcout);
Error += test_io_vec<glm::uint, glm::lowp>(std::cout);
Error += test_io_vec<glm::uint, glm::lowp>(std::wcout);
Error += test_io_mat<float, glm::highp>(std::cout, glm::io::column_major);
Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::column_major);
Error += test_io_mat<float, glm::highp>(std::cout, glm::io::row_major);
Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::row_major);
return Error;
}

View File

@@ -0,0 +1,54 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/log_base.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/exponential.hpp>
namespace test_log
{
int run()
{
int Error = 0;
{
float A = glm::log(10.f, 2.0f);
float B = glm::log2(10.f);
Error += glm::epsilonEqual(A, B, 0.00001f) ? 0 : 1;
}
{
glm::vec1 A = glm::log(glm::vec1(10.f), glm::vec1(2.0f));
glm::vec1 B = glm::log2(glm::vec1(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec1(0.00001f))) ? 0 : 1;
}
{
glm::vec2 A = glm::log(glm::vec2(10.f), glm::vec2(2.0f));
glm::vec2 B = glm::log2(glm::vec2(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec2(0.00001f))) ? 0 : 1;
}
{
glm::vec3 A = glm::log(glm::vec3(10.f), glm::vec3(2.0f));
glm::vec3 B = glm::log2(glm::vec3(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec3(0.00001f))) ? 0 : 1;
}
{
glm::vec4 A = glm::log(glm::vec4(10.f), glm::vec4(2.0f));
glm::vec4 B = glm::log2(glm::vec4(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec4(0.00001f))) ? 0 : 1;
}
return Error;
}
}//namespace test_log
int main()
{
int Error(0);
Error += test_log::run();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_cross_product.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,19 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_decompose.hpp>
int main()
{
int Error(0);
glm::mat4 Matrix(1);
glm::vec3 Scale;
glm::quat Orientation;
glm::vec3 Translation;
glm::vec3 Skew(1);
glm::vec4 Perspective(1);
glm::decompose(Matrix, Scale, Orientation, Translation, Skew, Perspective);
return Error;
}

View File

@@ -0,0 +1,105 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_factorisation.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/epsilon.hpp>
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_qr(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
glm::mat<(C < R ? C : R), R, T, Q> q(-999);
glm::mat<C, (C < R ? C : R), T, Q> r(-999);
glm::qr_decompose(m, q, r);
//Test if q*r really equals the input matrix
glm::mat<C, R, T, Q> tm = q*r;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
Error += glm::abs(err[i][j]) > epsilon ? 1 : 0;
//Test if the columns of q are orthonormal
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
{
Error += (length(q[i]) - 1) > epsilon ? 1 : 0;
for (glm::length_t j = 0; j<i; j++)
Error += glm::abs(dot(q[i], q[j])) > epsilon ? 1 : 0;
}
//Test if the matrix r is upper triangular
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = i + 1; j < (C < R ? C : R); j++)
Error += glm::epsilonEqual(r[i][j], static_cast<T>(0), glm::epsilon<T>()) ? 0 : 1;
return Error;
}
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_rq(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
glm::mat<C, (C < R ? C : R), T, Q> q(-999);
glm::mat<(C < R ? C : R), R, T, Q> r(-999);
glm::rq_decompose(m, r, q);
//Test if q*r really equals the input matrix
glm::mat<C, R, T, Q> tm = r*q;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
Error += glm::abs(err[i][j]) > epsilon ? 1 : 0;
//Test if the rows of q are orthonormal
glm::mat<(C < R ? C : R), C, T, Q> tq = transpose(q);
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
{
Error += (length(tq[i]) - 1) > epsilon ? 1 : 0;
for (glm::length_t j = 0; j<i; j++)
Error += glm::abs(dot(tq[i], tq[j])) > epsilon ? 1 : 0;
}
//Test if the matrix r is upper triangular
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
for (glm::length_t j = R - (C < R ? C : R) + i + 1; j < R; j++)
Error += glm::epsilonEqual(r[i][j], static_cast<T>(0), glm::epsilon<T>()) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
//Test QR square
Error += test_qr(glm::dmat3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0)) ? 1 : 0;
//Test RQ square
Error += test_rq(glm::dmat3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0)) ? 1 : 0;
//Test QR triangular 1
Error += test_qr(glm::dmat3x4(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test QR triangular 2
Error += test_qr(glm::dmat4x3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test RQ triangular 1 : Fails at the triangular test
Error += test_rq(glm::dmat3x4(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test QR triangular 2
Error += test_rq(glm::dmat4x3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
return Error;
}

View File

@@ -0,0 +1,46 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/matrix_interpolation.hpp>
#include <iostream>
int test_axisAngle()
{
int Error = 0;
glm::mat4 m1(-0.9946f, 0.0f, -0.104531f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.104531f, 0.0f, -0.9946f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 m2(-0.992624f, 0.0f, -0.121874f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.121874f, 0.0f, -0.992624f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 const m1rot = glm::extractMatrixRotation(m1);
glm::mat4 const dltRotation = m2 * glm::transpose(m1rot);
glm::vec3 dltAxis(0.0f);
float dltAngle = 0.0f;
glm::axisAngle(dltRotation, dltAxis, dltAngle);
std::cout << "dltAxis: (" << dltAxis.x << ", " << dltAxis.y << ", " << dltAxis.z << "), dltAngle: " << dltAngle << std::endl;
glm::fquat q = glm::quat_cast(dltRotation);
std::cout << "q: (" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")" << std::endl;
float yaw = glm::yaw(q);
std::cout << "Yaw: " << yaw << std::endl;
return Error;
}
int main()
{
int Error = 0;
Error += test_axisAngle();
return Error;
}

Some files were not shown because too many files have changed in this diff Show More