first commit

This commit is contained in:
2024-08-22 14:06:11 +02:00
commit 830cc47cf4
1144 changed files with 263724 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
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(gtc)
add_subdirectory(gtx)
+1
View File
@@ -0,0 +1 @@
glmCreateTestGTC(bug_ms_vec_static)
+14
View File
@@ -0,0 +1,14 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vec2.hpp>
struct Foo
{
static glm::vec2 Bar;
};
glm::vec2 Foo::Bar = glm::vec2(1.f, 1.f);
int main()
{
return 0;
}
+40
View File
@@ -0,0 +1,40 @@
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_message)
glmCreateTestGTC(core_setup_precision)
+423
View File
@@ -0,0 +1,423 @@
#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;
bool const G = A == C;
bool const H = A != C;
Error += D == glm::bvec4(true) ? 0 : 1;
Error += E == glm::bvec4(false) ? 0 : 1;
Error += F == glm::bvec4(true) ? 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
{
class A
{
float f;
};
class B : public A
{
float g;
glm::vec4 v;
};
int test()
{
int Error(0);
A* p = new B;
delete p;
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;
}
@@ -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
+129
View File
@@ -0,0 +1,129 @@
#include <glm/common.hpp>
#include <glm/exponential.hpp>
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/vec1.hpp>
int test_pow()
{
int Error(0);
float A = glm::pow(10.f, 10.f);
glm::vec1 B = glm::pow(glm::vec1(10.f), glm::vec1(10.f));
glm::vec2 C = glm::pow(glm::vec2(10.f), glm::vec2(10.f));
glm::vec3 D = glm::pow(glm::vec3(10.f), glm::vec3(10.f));
glm::vec4 E = glm::pow(glm::vec4(10.f), glm::vec4(10.f));
return Error;
}
int test_exp()
{
int Error(0);
float A = glm::exp(10.f);
glm::vec1 B = glm::exp(glm::vec1(10.f));
glm::vec2 C = glm::exp(glm::vec2(10.f));
glm::vec3 D = glm::exp(glm::vec3(10.f));
glm::vec4 E = glm::exp(glm::vec4(10.f));
return Error;
}
int test_log()
{
int Error(0);
float A = glm::log(10.f);
glm::vec1 B = glm::log(glm::vec1(10.f));
glm::vec2 C = glm::log(glm::vec2(10.f));
glm::vec3 D = glm::log(glm::vec3(10.f));
glm::vec4 E = glm::log(glm::vec4(10.f));
return Error;
}
int test_exp2()
{
int Error(0);
float A = glm::exp2(10.f);
glm::vec1 B = glm::exp2(glm::vec1(10.f));
glm::vec2 C = glm::exp2(glm::vec2(10.f));
glm::vec3 D = glm::exp2(glm::vec3(10.f));
glm::vec4 E = glm::exp2(glm::vec4(10.f));
return Error;
}
int test_log2()
{
int Error(0);
float A = glm::log2(10.f);
glm::vec1 B = glm::log2(glm::vec1(10.f));
glm::vec2 C = glm::log2(glm::vec2(10.f));
glm::vec3 D = glm::log2(glm::vec3(10.f));
glm::vec4 E = glm::log2(glm::vec4(10.f));
return Error;
}
int test_sqrt()
{
int Error(0);
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
for(float f = 0.1f; f < 30.0f; f += 0.1f)
{
float r = _mm_cvtss_f32(_mm_sqrt_ps(_mm_set1_ps(f)));
float s = std::sqrt(f);
Error += glm::abs(r - s) < 0.01f ? 0 : 1;
assert(!Error);
}
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
float A = glm::sqrt(10.f);
glm::vec1 B = glm::sqrt(glm::vec1(10.f));
glm::vec2 C = glm::sqrt(glm::vec2(10.f));
glm::vec3 D = glm::sqrt(glm::vec3(10.f));
glm::vec4 E = glm::sqrt(glm::vec4(10.f));
return Error;
}
int test_inversesqrt()
{
int Error(0);
glm::uint ulp(0);
float diff(0.0f);
for(float f = 0.001f; f < 10.f; f *= 1.01f)
{
glm::lowp_fvec1 u(f);
glm::lowp_fvec1 lowp_v = glm::inversesqrt(u);
float defaultp_v = glm::inversesqrt(f);
ulp = glm::max(glm::float_distance(lowp_v.x, defaultp_v), ulp);
diff = glm::abs(lowp_v.x - defaultp_v);
Error += diff > 0.1f ? 1 : 0;
}
return Error;
}
int main()
{
int Error(0);
Error += test_pow();
Error += test_exp();
Error += test_log();
Error += test_exp2();
Error += test_log2();
Error += test_sqrt();
Error += test_inversesqrt();
return Error;
}
+193
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 += C == -1.0f ? 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
@@ -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 ((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 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", sizeof(test)/8);
# endif//NDEBUG
}
@@ -0,0 +1,400 @@
// This has the programs for computing the number of trailing zeros
// in a word.
// Max line length is 57, to fit in hacker.book.
#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;
}
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);
}
/* ------------------------------ main ------------------------------ */
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", 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", 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", 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", 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", 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(test[i]) != m) error(test[i], ntz5(test[i]));}
TimestampEnd = std::clock();
printf("ntz5: %d clocks\n", 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", 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", 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", 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", 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", 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", 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", 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", TimestampEnd - TimestampBeg);
if (errors == 0)
printf("Passed all %d cases.\n", sizeof(test)/8);
# endif//NDEBUG
}
@@ -0,0 +1,438 @@
// This has the programs for computing the number of leading zeros
// in a word.
// Max line length is 57, to fit in hacker.book.
// Compile with g++, not gcc.
#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 ((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 = (double)k + 0.5;
n = 1054 - (asInt[LE] >> 20);
return n;
}
int nlz7(unsigned k) {
union {
unsigned asInt[2];
double asDouble;
};
int n;
asDouble = (double)k;
n = 1054 - (asInt[LE] >> 20);
n = (n & 31) + (n >> 9);
return n;
}
/* In single precision, 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 = (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 = (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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", TimestampEnd - TimestampBeg);
if (errors == 0)
printf("Passed all %d cases.\n", sizeof(test)/8);
# endif//NDEBUG
}
+277
View File
@@ -0,0 +1,277 @@
#include <glm/matrix.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/ulp.hpp>
#include <glm/gtc/epsilon.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);
Error += n == mat2(0, 1, 4, 9) ? 0 : 1;
}
{
mat2x3 m(0, 1, 2, 3, 4, 5);
mat2x3 n = matrixCompMult(m, m);
Error += n == mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1;
}
{
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
mat2x4 n = matrixCompMult(m, m);
Error += n == mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
}
{
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
mat3 n = matrixCompMult(m, m);
Error += n == mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1;
}
{
mat3x2 m(0, 1, 2, 3, 4, 5);
mat3x2 n = matrixCompMult(m, m);
Error += n == mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1;
}
{
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat3x4 n = matrixCompMult(m, m);
Error += n == mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 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);
Error += n == mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1;
}
{
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
mat4x2 n = matrixCompMult(m, m);
Error += n == mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
}
{
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat4x3 n = matrixCompMult(m, m);
Error += n == mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 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 m(0, 1, 2, 3);
mat2 t = transpose(m);
Error += t == mat2(0, 2, 1, 3) ? 0 : 1;
}
{
mat2x3 m(0, 1, 2, 3, 4, 5);
mat3x2 t = transpose(m);
Error += t == mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
}
{
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
mat4x2 t = transpose(m);
Error += t == mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
}
{
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
mat3 t = transpose(m);
Error += t == mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
}
{
mat3x2 m(0, 1, 2, 3, 4, 5);
mat2x3 t = transpose(m);
Error += t == mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
}
{
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat4x3 t = transpose(m);
Error += t == mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
}
{
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
mat4 t = transpose(m);
Error += t == mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
}
{
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
mat2x4 t = transpose(m);
Error += t == mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
}
{
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat3x4 t = transpose(m);
Error += t == mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
}
return Error;
}
int test_determinant()
{
return 0;
}
int test_inverse()
{
int Failed(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;
Failed += I4x4 == glm::mat4x4(1) ? 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;
Failed += I3x3 == glm::mat3x3(1) ? 0 : 1;
glm::mat2x2 A2x2(
glm::vec2(1, 1),
glm::vec2(0, 1));
glm::mat2x2 B2x2 = glm::inverse(A2x2);
glm::mat2x2 I2x2 = A2x2 * B2x2;
Failed += I2x2 == glm::mat2x2(1) ? 0 : 1;
return Failed;
}
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, 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);
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");
}
# endif//NDEBUG
return Error;
}
+22
View File
@@ -0,0 +1,22 @@
struct vec4
{
static int length();
};
int vec4::length()
{
return 4;
}
int main()
{
int Failed = 0;
vec4 V;
int LengthA = V.length();
int LengthB = vec4::length();
return Failed;
}
+156
View File
@@ -0,0 +1,156 @@
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <glm/packing.hpp>
#include <vector>
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;
}
+83
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;
}
@@ -0,0 +1,10 @@
#include <glm/trigonometric.hpp>
int main()
{
int Error = 0;
return Error;
}
@@ -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>
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;
}
@@ -0,0 +1,10 @@
#define GLM_FORCE_CXX98
#include <glm/glm.hpp>
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}
+275
View File
@@ -0,0 +1,275 @@
#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_VC10:
std::printf("Visual C++ 10 - 2010\n");
break;
case GLM_COMPILER_VC11:
std::printf("Visual C++ 11 - 2012\n");
break;
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 - 201X\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_GCC44:
std::printf("GCC 4.4\n");
break;
case GLM_COMPILER_GCC45:
std::printf("GCC 4.5\n");
break;
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_GCC50:
std::printf("GCC 5.0\n");
break;
case GLM_COMPILER_GCC51:
std::printf("GCC 5.1\n");
break;
case GLM_COMPILER_GCC52:
std::printf("GCC 5.2\n");
break;
case GLM_COMPILER_GCC53:
std::printf("GCC 5.3\n");
break;
case GLM_COMPILER_GCC54:
std::printf("GCC 5.4\n");
break;
case GLM_COMPILER_GCC60:
std::printf("GCC 6.0\n");
break;
case GLM_COMPILER_GCC61:
std::printf("GCC 6.1\n");
break;
case GLM_COMPILER_GCC62:
std::printf("GCC 6.2\n");
break;
case GLM_COMPILER_GCC70:
std::printf("GCC 7.0\n");
break;
case GLM_COMPILER_GCC71:
std::printf("GCC 7.1\n");
break;
case GLM_COMPILER_GCC72:
std::printf("GCC 7.2\n");
break;
case GLM_COMPILER_GCC80:
std::printf("GCC 8.0\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_CLANG32:
std::printf("Clang 3.2\n");
break;
case GLM_COMPILER_CLANG33:
std::printf("Clang 3.3\n");
break;
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_INTEL12:
std::printf("ICC 12\n");
break;
case GLM_COMPILER_INTEL12_1:
std::printf("ICC 12.1\n");
break;
case GLM_COMPILER_INTEL13:
std::printf("ICC 13\n");
break;
case GLM_COMPILER_INTEL14:
std::printf("ICC 14\n");
break;
case GLM_COMPILER_INTEL15:
std::printf("ICC 15\n");
break;
case GLM_COMPILER_INTEL16:
std::printf("ICC 16\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;
}
+58
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;
}
+128
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;
}
+144
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;
}
+358
View File
@@ -0,0 +1,358 @@
#define GLM_FORCE_NO_CTOR_INIT
#include <glm/glm.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/quaternion.hpp>
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;
}
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;
}
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;
}
int test_vec4_ctor()
{
int Error = 0;
# ifndef GLM_FORCE_NO_CTOR_INIT
{
glm::vec4 A;
glm::vec4 B(0);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
}
# endif//GLM_FORCE_NO_CTOR_INIT
# 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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
int test_quat_ctor()
{
int Error = 0;
# if GLM_HAS_DEFAULTED_FUNCTIONS && defined(GLM_FORCE_NO_CTOR_INIT)
{
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;
}
+31
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;
}
+43
View File
@@ -0,0 +1,43 @@
#include <glm/glm.hpp>
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);
}
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);
}
int test_int_precision()
{
return (
sizeof(glm::lowp_int) <= sizeof(glm::mediump_int) &&
sizeof(glm::mediump_int) <= sizeof(glm::highp_int)) ? 0 : 1;
}
int test_uint_precision()
{
return (
sizeof(glm::lowp_uint) <= sizeof(glm::mediump_uint) &&
sizeof(glm::mediump_uint) <= sizeof(glm::highp_uint)) ? 0 : 1;
}
int main()
{
int Error = 0;
Error += test_int_size();
Error += test_int_precision();
Error += test_uint_size();
Error += test_uint_precision();
return Error;
}
+79
View File
@@ -0,0 +1,79 @@
#include <glm/glm.hpp>
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;
}
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;
}
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;
}
+160
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;
}
+133
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;
}
+136
View File
@@ -0,0 +1,136 @@
#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::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::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;
}
+139
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;
}
+199
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;
}
+138
View File
@@ -0,0 +1,138 @@
#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::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::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;
}
+142
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;
}
+143
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;
}
+328
View File
@@ -0,0 +1,328 @@
#include <glm/gtc/epsilon.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", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[1][0], Mat0[1][1], Mat0[1][2], Mat0[1][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", Mat0[2][0], Mat0[2][1], Mat0[2][2], Mat0[2][3]);
printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f))\n\n", Mat0[3][0], Mat0[3][1], Mat0[3][2], 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}};
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::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
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;
}
+152
View File
@@ -0,0 +1,152 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/gtc/vec1.hpp>
#include <vector>
static glm::vec1 v1;
static glm::vec1 v2(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;
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;
glm::vec1 v;
assert(v.length() == 1);
Error += test_vec1_size();
Error += test_vec1_ctor();
Error += test_vec1_operators();
Error += test_vec1_operator_increment();
return Error;
}
+318
View File
@@ -0,0 +1,318 @@
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <vector>
#if GLM_HAS_TRIVIAL_QUERIES
# include <type_traits>
#endif
static glm::vec2 v1;
static glm::vec2 v2(1);
static glm::vec2 v3(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 += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A + B;
A += B;
Error += A.x == 3.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A - 1.0f;
A -= 1.0f;
Error += A.x == 0.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A - B;
A -= B;
Error += A.x == -1.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A * 2.0f;
A *= 2.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(2.0f);
glm::vec2 B(2.0f);
glm::vec2 C = A / B;
A /= B;
Error += A.x == 1.0f && A.y == 1.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 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;
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;
glm::vec2 v;
assert(v.length() == 2);
Error += test_vec2_size();
Error += test_vec2_ctor();
Error += test_vec2_operators();
Error += test_operator_increment();
return Error;
}
+498
View File
@@ -0,0 +1,498 @@
#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 v1;
static glm::vec3 v2(1);
static glm::vec3 v3(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);
}
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;
return Error;
}
int test_vec3_swizzle3_2()
{
int Error = 0;
glm::vec3 v(1, 2, 3);
glm::vec2 u;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
// 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;
glm::vec3 v(1, 2, 3);
glm::vec3 u;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
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 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
// 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 q, u, v;
u = glm::vec3(1, 2, 3);
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, t;
s = glm::vec4(1, 2, 3, 4);
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;
glm::vec3 v;
assert(v.length() == 3);
Error += test_vec3_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;
}
+565
View File
@@ -0,0 +1,565 @@
#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>
static glm::vec4 v1;
static glm::vec4 v2(1);
static glm::vec4 v3(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);
//}
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;
bool const G = A == C;
bool const H = A != C;
Error += D == glm::bvec4(true) ? 0 : 1;
Error += E == glm::bvec4(false) ? 0 : 1;
Error += F == glm::bvec4(true) ? 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;
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;
}
struct AoS
{
glm::vec4 A;
glm::vec3 B;
glm::vec3 C;
glm::vec2 D;
};
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;
}
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
{
class A
{
float f;
};
class B : public A
{
float g;
glm::vec4 v;
};
int test()
{
int Error(0);
A* p = new B;
delete p;
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);
/*
{
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");
}
*/
glm::vec4 v;
assert(v.length() == 4);
# ifdef NDEBUG
std::size_t const Size(1000000);
Error += test_vec4_perf_AoS(Size);
Error += test_vec4_perf_SoA(Size);
# endif//NDEBUG
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;
}
+27
View File
@@ -0,0 +1,27 @@
set(NAME gli)
file(GLOB ROOT_SOURCE *.cpp)
file(GLOB ROOT_INLINE *.inl)
file(GLOB ROOT_HEADER *.hpp)
file(GLOB_RECURSE CORE_SOURCE ./core/*.cpp)
file(GLOB_RECURSE CORE_INLINE ./core/*.inl)
file(GLOB_RECURSE CORE_HEADER ./core/*.hpp)
file(GLOB_RECURSE GTX_SOURCE ./gtx/*.cpp)
file(GLOB_RECURSE GTX_INLINE ./gtx/*.inl)
file(GLOB_RECURSE GTX_HEADER ./gtx/*.hpp)
source_group("Core Files" FILES ${CORE_SOURCE})
source_group("Core Files" FILES ${CORE_INLINE})
source_group("Core Files" FILES ${CORE_HEADER})
source_group("GTX Files" FILES ${GTX_SOURCE})
source_group("GTX Files" FILES ${GTX_INLINE})
source_group("GTX Files" FILES ${GTX_HEADER})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
add_executable(${NAME}
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} )
+4
View File
@@ -0,0 +1,4 @@
int main()
{
}
+25
View File
@@ -0,0 +1,25 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-27
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/core/generate_mipmaps.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GENERATE_MIPMAPS_INCLUDED
#define GLI_GENERATE_MIPMAPS_INCLUDED
#include "texture2d.hpp"
namespace gli
{
texture2D generateMipmaps(
texture2D const & Texture,
texture2D::level_type const & BaseLevel);
}//namespace gli
#include "generate_mipmaps.inl"
#endif//GLI_GENERATE_MIPMAPS_INCLUDED
+69
View File
@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-27
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/core/generate_mipmaps.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
/*
inline texture2D generateMipmaps
(
texture2D const & Image,
texture2D::level_type const & BaseLevel
)
{
assert(BaseLevel < Image.levels());
texture2D::format_type Format = Image[BaseLevel].format();
assert(Format == R8U || Format == RG8U || Format == RGB8U || Format == RGBA8U);
texture2D::level_type Levels = std::size_t(glm::log2(float(glm::compMax(Image[0].dimensions())))) + 1;
texture2D Result(Levels);
for(texture2D::level_type Level = 0; Level <= BaseLevel; ++Level)
Result[Level] = detail::duplicate(Image[Level]);
for(texture2D::level_type Level = BaseLevel; Level < Levels - 1; ++Level)
{
std::size_t BaseWidth = Result[Level + 0].dimensions().x;
texture2D::value_type * DataSrc = Result[Level + 0].data();
texture2D::dimensions_type LevelDimensions = Result[Level + 0].dimensions() >> texture2D::dimensions_type(1);
LevelDimensions = glm::max(LevelDimensions, texture2D::dimensions_type(1));
texture2D::size_type Components = Result[Level + 0].components();
texture2D::data_type DataDst(glm::compMul(LevelDimensions) * Components);
for(std::size_t j = 0; j < LevelDimensions.y; ++j)
for(std::size_t i = 0; i < LevelDimensions.x; ++i)
for(std::size_t c = 0; c < Components; ++c)
{
std::size_t x = (i << 1);
std::size_t y = (j << 1);
std::size_t Index00 = ((x + 0) + (y + 0) * BaseWidth) * Components + c;
std::size_t Index01 = ((x + 0) + (y + 1) * BaseWidth) * Components + c;
std::size_t Index11 = ((x + 1) + (y + 1) * BaseWidth) * Components + c;
std::size_t Index10 = ((x + 1) + (y + 0) * BaseWidth) * Components + c;
glm::u32 Data00 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index00];
glm::u32 Data01 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index01];
glm::u32 Data11 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index11];
glm::u32 Data10 = reinterpret_cast<texture2D::value_type*>(DataSrc)[Index10];
texture2D::value_type Result = (Data00 + Data01 + Data11 + Data10) >> 2;
texture2D::value_type * Data = reinterpret_cast<texture2D::value_type*>(DataDst.data());
*(Data + ((i + j * LevelDimensions.x) * Components + c)) = Result;
}
Result[Level + 1] = image2D(LevelDimensions, Format, DataDst);
}
return Result;
}
*/
}//namespace gli
+169
View File
@@ -0,0 +1,169 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-05
// Updated : 2011-04-05
// Licence : This source is under MIT License
// File : gli/core/image2d.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_IMAGE2D_INCLUDED
#define GLI_CORE_IMAGE2D_INCLUDED
// STD
#include <vector>
#include <cassert>
#include <cmath>
#include <cstring>
// GLM
#include <glm/glm.hpp>
#include <glm/gtx/number_precision.hpp>
#include <glm/gtx/raw_data.hpp>
#include <glm/gtx/gradient_paint.hpp>
#include <glm/gtx/component_wise.hpp>
namespace gli
{
enum format
{
FORMAT_NULL,
// Unsigned integer formats
R8U,
RG8U,
RGB8U,
RGBA8U,
R16U,
RG16U,
RGB16U,
RGBA16U,
R32U,
RG32U,
RGB32U,
RGBA32U,
// Signed integer formats
R8I,
RG8I,
RGB8I,
RGBA8I,
R16I,
RG16I,
RGB16I,
RGBA16I,
R32I,
RG32I,
RGB32I,
RGBA32I,
// Floating formats
R16F,
RG16F,
RGB16F,
RGBA16F,
R32F,
RG32F,
RGB32F,
RGBA32F,
// Packed formats
RGBE8,
RGB9E5,
RG11B10F,
R5G6B5,
RGBA4,
RGB10A2,
// Depth formats
D16,
D24X8,
D24S8,
D32F,
D32FS8X24,
// Compressed formats
DXT1,
DXT3,
DXT5,
ATI1N_UNORM,
ATI1N_SNORM,
ATI2N_UNORM,
ATI2N_SNORM,
BP_UF16,
BP_SF16,
BP,
FORMAT_MAX
};
enum size_type
{
LINEAR_SIZE,
BLOCK_SIZE,
BIT_PER_PIXEL,
COMPONENT
};
class image2D
{
public:
typedef glm::uvec2 dimensions_type;
typedef glm::vec2 texcoord_type;
typedef glm::uint32 size_type;
typedef glm::byte value_type;
typedef gli::format format_type;
typedef std::vector<value_type> data_type;
public:
image2D();
image2D(
image2D const & Image);
explicit image2D(
dimensions_type const & Dimensions,
format_type const & Format);
template <typename genType>
explicit image2D(
dimensions_type const & Dimensions,
format_type const & Format,
genType const & Value);
explicit image2D(
dimensions_type const & Dimensions,
format_type const & Format,
std::vector<value_type> const & Data);
~image2D();
template <typename genType>
void setPixel(
dimensions_type const & TexelCoord,
genType const & TexelData);
size_type value_size() const;
size_type capacity() const;
dimensions_type dimensions() const;
size_type components() const;
format_type format() const;
value_type * data();
value_type const * const data() const;
private:
data_type Data;
dimensions_type Dimensions;
format_type Format;
};
}//namespace gli
#include "image2d.inl"
#endif//GLI_CORE_IMAGE2D_INCLUDED
+229
View File
@@ -0,0 +1,229 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-05
// Updated : 2011-04-05
// Licence : This source is under MIT License
// File : gli/core/image2d.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
namespace detail
{
struct format_desc
{
image2D::size_type BlockSize;
image2D::size_type BBP;
image2D::size_type Component;
};
inline format_desc getFormatInfo(format const & Format)
{
format_desc Desc[FORMAT_MAX] =
{
{ 0, 0, 0}, //FORMAT_NULL
// Unsigned integer formats
{ 1, 8, 1}, //R8U,
{ 2, 16, 2}, //RG8U,
{ 3, 24, 3}, //RGB8U,
{ 4, 32, 4}, //RGBA8U,
{ 2, 16, 1}, //R16U,
{ 4, 32, 2}, //RG16U,
{ 6, 48, 3}, //RGB16U,
{ 8, 64, 4}, //RGBA16U,
{ 4, 32, 1}, //R32U,
{ 8, 64, 2}, //RG32U,
{ 12, 96, 3}, //RGB32U,
{ 16, 128, 4}, //RGBA32U,
//// Signed integer formats
{ 4, 32, 1}, //R8I,
{ 8, 64, 2}, //RG8I,
{ 12, 96, 3}, //RGB8I,
{ 16, 128, 4}, //RGBA8I,
{ 2, 16, 1}, //R16I,
{ 4, 32, 2}, //RG16I,
{ 6, 48, 3}, //RGB16I,
{ 8, 64, 4}, //RGBA16I,
{ 4, 32, 1}, //R32I,
{ 8, 64, 2}, //RG32I,
{ 12, 96, 3}, //RGB32I,
{ 16, 128, 4}, //RGBA32I,
//// Floating formats
{ 2, 16, 1}, //R16F,
{ 4, 32, 2}, //RG16F,
{ 6, 48, 3}, //RGB16F,
{ 8, 64, 4}, //RGBA16F,
{ 4, 32, 1}, //R32F,
{ 8, 64, 2}, //RG32F,
{ 12, 96, 3}, //RGB32F,
{ 16, 128, 4}, //RGBA32F,
//// Packed formats
{ 4, 32, 3}, //RGBE8,
{ 4, 32, 3}, //RGB9E5,
{ 4, 32, 3}, //RG11B10F,
{ 2, 16, 3}, //R5G6B5,
{ 2, 16, 4}, //RGBA4,
{ 4, 32, 3}, //RGB10A2,
//// Depth formats
{ 2, 16, 1}, //D16,
{ 4, 32, 1}, //D24X8,
{ 4, 32, 2}, //D24S8,
{ 4, 32, 1}, //D32F,
{ 8, 64, 2}, //D32FS8X24,
//// Compressed formats
{ 8, 4, 4}, //DXT1,
{ 16, 8, 4}, //DXT3,
{ 16, 8, 4}, //DXT5,
{ 8, 4, 1}, //ATI1N_UNORM,
{ 8, 4, 1}, //ATI1N_SNORM,
{ 16, 8, 2}, //ATI2N_UNORM,
{ 16, 8, 2}, //ATI2N_SNORM,
{ 16, 8, 3}, //BP_UF16,
{ 16, 8, 3}, //BP_SF16,
{ 16, 8, 4}, //BP,
};
return Desc[Format];
}
inline image2D::size_type sizeBlock
(
format const & Format
)
{
return getFormatInfo(Format).BlockSize;
}
inline image2D::size_type sizeBitPerPixel
(
format const & Format
)
{
return getFormatInfo(Format).BBP;
}
inline image2D::size_type sizeComponent
(
format const & Format
)
{
return getFormatInfo(Format).Component;
}
inline image2D::size_type sizeLinear
(
image2D const & Image
)
{
image2D::dimensions_type Dimension = Image.dimensions();
Dimension = glm::max(Dimension, image2D::dimensions_type(1));
image2D::size_type BlockSize = sizeBlock(Image.format());
image2D::size_type BPP = sizeBitPerPixel(Image.format());
image2D::size_type BlockCount = 0;
if((BlockSize << 3) == BPP)
BlockCount = Dimension.x * Dimension.y;
else
BlockCount = ((Dimension.x + 3) >> 2) * ((Dimension.y + 3) >> 2);
return BlockCount * BlockSize;
}
}//namespace detail
inline image2D::image2D() :
Data(0),
Dimensions(0),
Format(FORMAT_NULL)
{}
inline image2D::image2D
(
image2D const & Image
) :
Data(Image.Data),
Dimensions(Image.Dimensions),
Format(Image.Format)
{}
inline image2D::image2D
(
dimensions_type const & Dimensions,
format_type const & Format
) :
Data((glm::compMul(Dimensions) * detail::sizeBitPerPixel(Format)) >> 3),
Dimensions(Dimensions),
Format(Format)
{}
inline image2D::image2D
(
dimensions_type const & Dimensions,
format_type const & Format,
std::vector<value_type> const & Data
) :
Data(Data),
Dimensions(Dimensions),
Format(Format)
{}
inline image2D::~image2D()
{}
template <typename genType>
inline void image2D::setPixel
(
dimensions_type const & TexelCoord,
genType const & TexelData
)
{
size_type Index = this->dimensions().x * sizeof(genType) * TexelCoord.y + sizeof(genType) * TexelCoord.x;
memcpy(this->data() + Index, &TexelData[0], sizeof(genType));
}
inline image2D::size_type image2D::value_size() const
{
return detail::sizeBitPerPixel(this->format());
}
inline image2D::size_type image2D::capacity() const
{
return detail::sizeLinear(*this);
}
inline image2D::dimensions_type image2D::dimensions() const
{
return this->Dimensions;
}
inline image2D::size_type image2D::components() const
{
return detail::sizeComponent(this->format());
}
inline image2D::format_type image2D::format() const
{
return this->Format;
}
inline image2D::value_type * image2D::data()
{
return &this->Data[0];
}
inline image2D::value_type const * const image2D::data() const
{
return &this->Data[0];
}
}//namespace gli
+82
View File
@@ -0,0 +1,82 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/operation.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_OPERATION_INCLUDED
#define GLI_OPERATION_INCLUDED
#include "texture2d.hpp"
namespace gli
{
texture2D duplicate(texture2D const & Texture);
texture2D flip(texture2D const & Texture);
texture2D mirror(texture2D const & Texture);
texture2D swizzle(
texture2D const & Texture,
glm::uvec4 const & Channel);
texture2D crop(
texture2D const & Texture,
texture2D::dimensions_type const & Position,
texture2D::dimensions_type const & Size);
image2D crop(
image2D const & Image,
texture2D::dimensions_type const & Position,
texture2D::dimensions_type const & Size);
image2D copy(
image2D const & SrcImage,
image2D::dimensions_type const & SrcPosition,
image2D::dimensions_type const & SrcSize,
image2D & DstImage,
image2D::dimensions_type const & DstPosition);
//image operator+(image const & MipmapA, image const & MipmapB);
//image operator-(image const & MipmapA, image const & MipmapB);
//image operator*(image const & MipmapA, image const & MipmapB);
//image operator/(image const & MipmapA, image const & MipmapB);
//namespace wip
//{
// template <typename GENTYPE, template <typename> class SURFACE>
// GENTYPE fetch(SURFACE<GENTYPE> const & Image)
// {
// return GENTYPE();
// }
// template
// <
// typename GENTYPE,
// template
// <
// typename
// >
// class SURFACE,
// template
// <
// typename,
// template
// <
// typename
// >
// class
// >
// class IMAGE
// >
// GENTYPE fetch(IMAGE<GENTYPE, SURFACE> const & Image)
// {
// return GENTYPE();
// }
//}//namespace wip
}//namespace gli
#include "operation.inl"
#endif//GLI_OPERATION_INCLUDED
+233
View File
@@ -0,0 +1,233 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-09-08
// Licence : This source is under MIT License
// File : gli/core/operation.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <cstring>
namespace gli
{
namespace detail
{
inline image2D duplicate(image2D const & Mipmap2D)
{
image2D Result(Mipmap2D.dimensions(), Mipmap2D.format());
memcpy(Result.data(), Mipmap2D.data(), Mipmap2D.capacity());
return Result;
}
inline image2D flip(image2D const & Mipmap2D)
{
image2D Result(Mipmap2D.dimensions(), Mipmap2D.format());
std::size_t ValueSize = Result.value_size();
glm::byte * DstPtr = Result.data();
glm::byte const * const SrcPtr = Mipmap2D.data();
for(std::size_t j = 0; j < Result.dimensions().y; ++j)
for(std::size_t i = 0; i < Result.dimensions().x; ++i)
{
std::size_t DstIndex = (i + j * Result.dimensions().y) * ValueSize;
std::size_t SrcIndex = (i + (Result.dimensions().y - j) * Result.dimensions().x) * ValueSize;
memcpy(DstPtr + DstIndex, SrcPtr + SrcIndex, ValueSize);
}
return Result;
}
inline image2D mirror(image2D const & Mipmap2D)
{
image2D Result(Mipmap2D.dimensions(), Mipmap2D.format());
std::size_t ValueSize = Mipmap2D.value_size();
glm::byte * DstPtr = Result.data();
glm::byte const * const SrcPtr = Mipmap2D.data();
for(std::size_t j = 0; j < Result.dimensions().y; ++j)
for(std::size_t i = 0; i < Result.dimensions().x; ++i)
{
std::size_t DstIndex = (i + j * Result.dimensions().x) * ValueSize;
std::size_t SrcIndex = ((Result.dimensions().x - i) + j * Result.dimensions().x) * ValueSize;
memcpy(DstPtr + DstIndex, SrcPtr + SrcIndex, ValueSize);
}
return Result;
}
inline image2D swizzle
(
image2D const & Mipmap,
glm::uvec4 const & Channel
)
{
image2D Result = detail::duplicate(Mipmap);
glm::byte * DataDst = Result.data();
glm::byte const * const DataSrc = Mipmap.data();
gli::texture2D::size_type CompSize = Mipmap.value_size() / Mipmap.components();
gli::texture2D::size_type TexelCount = Mipmap.capacity() / Mipmap.value_size();
for(gli::texture2D::size_type t = 0; t < TexelCount; ++t)
for(gli::texture2D::size_type c = 0; c < Mipmap.components(); ++c)
{
gli::texture2D::size_type IndexSrc = t * Mipmap.components() + Channel[static_cast<int>(c)];
gli::texture2D::size_type IndexDst = t * Mipmap.components() + c;
memcpy(DataDst + IndexDst, DataSrc + IndexSrc, CompSize);
}
return Result;
}
inline image2D crop
(
image2D const & Image,
image2D::dimensions_type const & Position,
image2D::dimensions_type const & Size
)
{
assert((Position.x + Size.x) <= Image.dimensions().x && (Position.y + Size.y) <= Image.dimensions().y);
image2D Result(Size, Image.format());
glm::byte* DstData = Result.data();
glm::byte const * const SrcData = Image.data();
for(std::size_t j = 0; j < Size.y; ++j)
{
std::size_t DstIndex = 0 + (0 + j) * Size.x * Image.value_size();
std::size_t SrcIndex = Position.x * Image.value_size() + (Position.y + j) * Image.dimensions().x * Image.value_size();
memcpy(DstData + DstIndex, SrcData + SrcIndex, Image.value_size() * Size.x);
}
return Result;
}
inline image2D copy
(
image2D const & SrcMipmap,
image2D::dimensions_type const & SrcPosition,
image2D::dimensions_type const & SrcSize,
image2D & DstMipmap,
image2D::dimensions_type const & DstPosition
)
{
assert((SrcPosition.x + SrcSize.x) <= SrcMipmap.dimensions().x && (SrcPosition.y + SrcSize.y) <= SrcMipmap.dimensions().y);
assert(SrcMipmap.format() == DstMipmap.format());
glm::byte * DstData = DstMipmap.data();
glm::byte const * const SrcData = SrcMipmap.data();
std::size_t SizeX = glm::min(std::size_t(SrcSize.x + SrcPosition.x), std::size_t(DstMipmap.dimensions().x + DstPosition.x));
std::size_t SizeY = glm::min(std::size_t(SrcSize.y + SrcPosition.y), std::size_t(DstMipmap.dimensions().y + DstPosition.y));
for(std::size_t j = 0; j < SizeY; ++j)
{
std::size_t DstIndex = DstPosition.x * DstMipmap.value_size() + (DstPosition.y + j) * DstMipmap.dimensions().x * DstMipmap.value_size();
std::size_t SrcIndex = SrcPosition.x * SrcMipmap.value_size() + (SrcPosition.y + j) * SrcMipmap.dimensions().x * SrcMipmap.value_size();
memcpy(DstData + DstIndex, SrcData + SrcIndex, SrcMipmap.value_size() * SizeX);
}
return DstMipmap;
}
}//namespace detail
inline texture2D duplicate(texture2D const & Texture2D)
{
texture2D Result(Texture2D.levels());
for(texture2D::level_type Level = 0; Level < Texture2D.levels(); ++Level)
Result[Level] = detail::duplicate(Texture2D[Level]);
return Result;
}
inline texture2D flip(texture2D const & Texture2D)
{
texture2D Result(Texture2D.levels());
for(texture2D::level_type Level = 0; Level < Texture2D.levels(); ++Level)
Result[Level] = detail::flip(Texture2D[Level]);
return Result;
}
inline texture2D mirror(texture2D const & Texture2D)
{
texture2D Result(Texture2D.levels());
for(texture2D::level_type Level = 0; Level < Texture2D.levels(); ++Level)
Result[Level] = detail::mirror(Texture2D[Level]);
return Result;
}
inline texture2D crop
(
texture2D const & Texture2D,
texture2D::dimensions_type const & Position,
texture2D::dimensions_type const & Size
)
{
texture2D Result(Texture2D.levels());
for(texture2D::level_type Level = 0; Level < Texture2D.levels(); ++Level)
Result[Level] = detail::crop(
Texture2D[Level],
Position >> texture2D::dimensions_type(Level),
Size >> texture2D::dimensions_type(Level));
return Result;
}
inline texture2D swizzle
(
texture2D const & Texture2D,
glm::uvec4 const & Channel
)
{
texture2D Result(Texture2D.levels());
for(texture2D::level_type Level = 0; Level < Texture2D.levels(); ++Level)
Result[Level] = detail::swizzle(Texture2D[Level], Channel);
return Result;
}
inline texture2D copy
(
texture2D const & SrcImage,
texture2D::level_type const & SrcLevel,
texture2D::dimensions_type const & SrcPosition,
texture2D::dimensions_type const & SrcDimensions,
texture2D & DstMipmap,
texture2D::level_type const & DstLevel,
texture2D::dimensions_type const & DstDimensions
)
{
detail::copy(
SrcImage[SrcLevel],
SrcPosition,
SrcDimensions,
DstMipmap[DstLevel],
DstDimensions);
return DstMipmap;
}
//inline image operator+(image const & MipmapA, image const & MipmapB)
//{
//
//}
//inline image operator-(image const & MipmapA, image const & MipmapB)
//{
//
//}
//inline image operator*(image const & MipmapA, image const & MipmapB)
//{
//
//}
//inline image operator/(image const & MipmapA, image const & MipmapB)
//{
//
//}
}//namespace gli
+28
View File
@@ -0,0 +1,28 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-01-19
// Updated : 2010-01-19
// Licence : This source is under MIT License
// File : gli/core/operator.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_OPERATOR_INCLUDED
#define GLI_OPERATOR_INCLUDED
#include "texture2d.hpp"
namespace gli{
namespace detail
{
}//namespace detail
texture2D operator+(texture2D const & TextureA, texture2D const & TextureB);
texture2D operator-(texture2D const & TextureA, texture2D const & TextureB);
}//namespace gli
#include "operator.inl"
#endif//GLI_OPERATOR_INCLUDED
+210
View File
@@ -0,0 +1,210 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-01-19
// Updated : 2010-01-19
// Licence : This source is under MIT License
// File : gli/core/operator.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
namespace detail
{
template <typename T>
void element
(
T & DataDst,
T const & DataSrcA,
T const & DataSrcB,
std::binary_function<T, T, T> const & Func
)
{
*DataDst = Func(DataSrcA, DataSrcB);
}
void op
(
texture2D::value_type * DataDst,
texture2D::value_type const * const DataSrcA,
texture2D::value_type const * const DataSrcB,
format Format
)
{
std::plus<>()
switch(Format)
{
case R8U:
*((glm::u8*)DataDst) = *((glm::u8*)DataSrcA) + *((glm::u8*)DataSrcB);
break;
case RG8U:
*((glm::u8vec2*)DataDst) = *((glm::u8vec2*)DataSrcA) + *((glm::u8vec2*)DataSrcB);
break;
case RGB8U:
*((glm::u8vec3*)DataDst) = *((glm::u8vec3*)DataSrcA) + *((glm::u8vec3*)DataSrcB);
break;
case RGBA8U:
*((glm::u8vec4*)DataDst) = *((glm::u8vec4*)DataSrcA) + *((glm::u8vec4*)DataSrcB);
break;
case R16U:
*((glm::u16*)DataDst) = *((glm::u16*)DataSrcA) + *((glm::u16*)DataSrcB);
break;
case RG16U:
*((glm::u16vec2*)DataDst) = *((glm::u16vec2*)DataSrcA) + *((glm::u16vec2*)DataSrcB);
break;
case RGB16U:
*((glm::u16vec3*)DataDst) = *((glm::u16vec3*)DataSrcA) + *((glm::u16vec3*)DataSrcB);
break;
case RGBA16U:
*((glm::u16vec4*)DataDst) = *((glm::u16vec4*)DataSrcA) + *((glm::u16vec4*)DataSrcB);
break;
case R32U:
*((glm::u32*)DataDst) = *((glm::u32*)DataSrcA) + *((glm::u32*)DataSrcB);
break;
case RG32U:
*((glm::u32vec2*)DataDst) = *((glm::u32vec2*)DataSrcA) + *((glm::u32vec2*)DataSrcB);
break;
case RGB32U:
*((glm::u32vec3*)DataDst) = *((glm::u32vec3*)DataSrcA) + *((glm::u32vec3*)DataSrcB);
break;
case RGBA32U:
*((glm::u32vec4*)DataDst) = *((glm::u32vec4*)DataSrcA) + *((glm::u32vec4*)DataSrcB);
break;
case R8I:
*((glm::i8*)DataDst) = *((glm::i8*)DataSrcA) + *((glm::i8*)DataSrcB);
break;
case RG8I:
*((glm::i8vec2*)DataDst) = *((glm::i8vec2*)DataSrcA) + *((glm::i8vec2*)DataSrcB);
break;
case RGB8I:
*((glm::i8vec3*)DataDst) = *((glm::i8vec3*)DataSrcA) + *((glm::i8vec3*)DataSrcB);
break;
case RGBA8I:
*((glm::i8vec4*)DataDst) = *((glm::i8vec4*)DataSrcA) + *((glm::i8vec4*)DataSrcB);
break;
case R16I:
*((glm::i16*)DataDst) = *((glm::i16*)DataSrcA) + *((glm::i16*)DataSrcB);
break;
case RG16I:
*((glm::i16vec2*)DataDst) = *((glm::i16vec2*)DataSrcA) + *((glm::i16vec2*)DataSrcB);
break;
case RGB16I:
*((glm::i16vec3*)DataDst) = *((glm::i16vec3*)DataSrcA) + *((glm::i16vec3*)DataSrcB);
break;
case RGBA16I:
*((glm::i16vec4*)DataDst) = *((glm::i16vec4*)DataSrcA) + *((glm::i16vec4*)DataSrcB);
break;
case R32I:
*((glm::i32*)DataDst) = *((glm::i32*)DataSrcA) + *((glm::i32*)DataSrcB);
break;
case RG32I:
*((glm::i32vec2*)DataDst) = *((glm::i32vec2*)DataSrcA) + *((glm::i32vec2*)DataSrcB);
break;
case RGB32I:
*((glm::i32vec3*)DataDst) = *((glm::i32vec3*)DataSrcA) + *((glm::i32vec3*)DataSrcB);
break;
case RGBA32I:
*((glm::i32vec4*)DataDst) = *((glm::i32vec4*)DataSrcA) + *((glm::i32vec4*)DataSrcB);
break;
case R16F:
*((glm::f16*)DataDst) = *((glm::f16*)DataSrcA) + *((glm::f16*)DataSrcB);
break;
case RG16F:
*((glm::f16vec2*)DataDst) = *((glm::f16vec2*)DataSrcA) + *((glm::f16vec2*)DataSrcB);
break;
case RGB16F:
*((glm::f16vec3*)DataDst) = *((glm::f16vec3*)DataSrcA) + *((glm::f16vec3*)DataSrcB);
break;
case RGBA16F:
*((glm::f16vec4*)DataDst) = *((glm::f16vec4*)DataSrcA) + *((glm::f16vec4*)DataSrcB);
break;
case R32F:
*((glm::f32*)DataDst) = *((glm::f32*)DataSrcA) + *((glm::f32*)DataSrcB);
break;
case RG32F:
*((glm::f32vec2*)DataDst) = *((glm::f32vec2*)DataSrcA) + *((glm::f32vec2*)DataSrcB);
break;
case RGB32F:
*((glm::f32vec3*)DataDst) = *((glm::f32vec3*)DataSrcA) + *((glm::f32vec3*)DataSrcB);
break;
case RGBA32F:
*((glm::f32vec4*)DataDst) = *((glm::f32vec4*)DataSrcA) + *((glm::f32vec4*)DataSrcB);
break;
default:
assert(0);
}
}
void add
(
texture2D::image & Result,
texture2D::image const & ImageA,
texture2D::image const & ImageB,
)
{
}
}//namespace detail
texture2D operator+
(
texture2D const & ImageA,
texture2D const & ImageB
)
{
assert(ImageA.levels() == ImageB.levels());
texture2D Result[ImageA.levels()];
for(texture2D::level_type Level = 0; Level < Result.levels(); ++Level)
{
assert(ImageA.capacity() == ImageB.capacity());
assert(ImageA.format() == ImageB.format());
Result[Level] = texture2D::image(ImageA[Level].dimensions(), ImageA[Level].format());
add(Result[Level], ImageA[Level], ImageB[Level]);
texture2D::size_type ValueSize = Result.value_size();
texture2D::size_type TexelCount = this->capacity() / ValueSize;
for(texture2D::size_type Texel = 0; Texel < TexelCount; ++Texel)
{
texture2D::value_type * DataDst = Result[Level].data() + Texel * ValueSize;
texture2D::value_type const * const DataSrcA = ImageA[Level].data() + Texel * ValueSize;
texture2D::value_type const * const DataSrcB = ImageB[Level].data() + Texel * ValueSize;
detail::op(DataDst, DataSrcA, DataSrcB, Result.format(), std::plus);
}
}
return Result;
}
texture2D operator-
(
texture2D const & ImageA,
texture2D const & ImageB
)
{
assert(ImageA.levels() == ImageB.levels());
texture2D Result[ImageA.levels()];
for(texture2D::level_type Level = 0; Level < ImageA.levels(); ++Level)
{
assert(ImageA.capacity() == ImageB.capacity());
}
return Result;
}
}//namespace gli
+48
View File
@@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2005-06-13
// Licence : This source is under MIT License
// File : gli/shared_array.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_SHARED_ARRAY_INCLUDED
#define GLI_SHARED_ARRAY_INCLUDED
namespace gli
{
template <typename T>
class shared_array
{
public:
shared_array();
shared_array(shared_array const & SharedArray);
shared_array(T * Pointer);
virtual ~shared_array();
void reset();
void reset(T * Pointer);
T & operator*();
T * operator->();
T const & operator*() const;
T const * const operator->() const;
T * get();
T const * const get() const;
shared_array & operator=(shared_array const & SharedArray);
bool operator==(shared_array const & SharedArray) const;
bool operator!=(shared_array const & SharedArray) const;
private:
int * Counter;
T * Pointer;
};
}//namespace gli
#include "shared_array.inl"
#endif //GLI_SHARED_ARRAY_INCLUDED
+151
View File
@@ -0,0 +1,151 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2005-06-13
// Licence : This source is under MIT License
// File : gli/shared_array.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
template <typename T>
shared_array<T>::shared_array() :
Counter(0),
Pointer(0)
{}
template <typename T>
shared_array<T>::shared_array
(
shared_array<T> const & SharedArray
)
{
this->Counter = SharedArray.Counter;
this->Pointer = SharedArray.Pointer;
(*this->Counter)++;
}
template <typename T>
shared_array<T>::shared_array
(
T * Pointer
)
{
this->reset(Pointer);
}
template <typename T>
shared_array<T>::~shared_array()
{
this->reset();
}
template <typename T>
void shared_array<T>::reset()
{
if(this->Pointer)
{
(*this->Counter)--;
if(*this->Counter <= 0)
{
delete this->Counter;
this->Counter = 0;
delete[] this->Pointer;
this->Pointer = 0;
}
}
}
template <typename T>
void shared_array<T>::reset(T * Pointer)
{
this->Counter = new int;
this->Pointer = Pointer;
*this->Counter = 1;
}
template <typename T>
shared_array<T>& shared_array<T>::operator=
(
shared_array<T> const & SharedArray
)
{
this->reset();
this->Counter = SharedArray.Counter;
this->Pointer = SharedArray.Pointer;
(*this->Counter)++;
return *this;
}
//template <typename T>
//shared_array<T> & shared_array<T>::operator=(T * Pointer)
//{
// if(this->Pointer)
// {
// (*this->Counter)--;
// if(*this->Counter <= 0)
// {
// delete this->Counter;
// delete[] this->Pointer;
// }
// }
// this->Counter = new int;
// this->Pointer = this->Pointer;
// (*this->Counter) = 1;
// return *this;
//}
template <typename T>
bool shared_array<T>::operator==(shared_array<T> const & SharedArray) const
{
return this->Pointer == SharedArray.Pointer;
}
template <typename T>
bool shared_array<T>::operator!=(shared_array<T> const & SharedArray) const
{
return this->Pointer != SharedArray.Pointer;
}
template <typename T>
T & shared_array<T>::operator*()
{
return *this->Pointer;
}
template <typename T>
T * shared_array<T>::operator->()
{
return this->Pointer;
}
template <typename T>
T const & shared_array<T>::operator*() const
{
return * this->Pointer;
}
template <typename T>
T const * const shared_array<T>::operator->() const
{
return this->Pointer;
}
template <typename T>
T * shared_array<T>::get()
{
return this->Pointer;
}
template <typename T>
T const * const shared_array<T>::get() const
{
return this->Pointer;
}
}//namespace gli
+41
View File
@@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2005-06-13
// Licence : This source is under MIT License
// File : gli/fetch.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_SHARED_PTR_INCLUDED
#define GLI_SHARED_PTR_INCLUDED
namespace gli
{
template <typename T>
class shared_ptr
{
public:
shared_ptr();
shared_ptr(shared_ptr const & SmartPtr);
shared_ptr(T* pPointer);
~shared_ptr();
T& operator*();
T* operator->();
const T& operator*() const;
const T* operator->() const;
shared_ptr& operator=(shared_ptr const & SmartPtr);
shared_ptr& operator=(T* pPointer);
bool operator==(shared_ptr const & SmartPtr) const;
bool operator!=(shared_ptr const & SmartPtr) const;
private:
int* m_pReference;
T* m_pPointer;
};
}//namespace gli
#include "shared_ptr.inl"
#endif //GLI_SHARED_PTR_INCLUDED
+125
View File
@@ -0,0 +1,125 @@
///////////////////////////////////////////////////////////////////////////
// Interstate Gangs : smart_ptr.inl
///////////////////////////////////////////////////////////////////////////
// This file is under GPL licence
///////////////////////////////////////////////////////////////////////////
// CHANGELOG
// Groove - 13/06/2005 :
// - Create file
///////////////////////////////////////////////////////////////////////////
namespace gli
{
template <typename T>
util::CSmartPtr<T>::CSmartPtr()
{
m_pPointer = 0;
}
template <typename T>
util::CSmartPtr<T>::CSmartPtr(const util::CSmartPtr<T> & SmartPtr)
{
m_pReference = SmartPtr.m_pReference;
m_pPointer = SmartPtr.m_pPointer;
(*m_pReference)++;
}
template <typename T>
util::CSmartPtr<T>::CSmartPtr(T* pPointer)
{
m_pReference = new int;
m_pPointer = pPointer;
(*m_pReference) = 1;
}
template <typename T>
util::CSmartPtr<T>::~CSmartPtr()
{
if(!m_pPointer)
return;
(*m_pReference)--;
if(*m_pReference <= 0)
{
delete m_pReference;
delete m_pPointer;
}
}
template <typename T>
util::CSmartPtr<T>& util::CSmartPtr<T>::operator=(const util::CSmartPtr<T> & SmartPtr)
{
if(m_pPointer)
{
(*m_pReference)--;
if(*m_pReference <= 0)
{
delete m_pReference;
delete m_pPointer;
}
}
m_pReference = SmartPtr.m_pReference;
m_pPointer = SmartPtr.m_pPointer;
(*m_pReference)++;
return *this;
}
template <typename T>
util::CSmartPtr<T>& util::CSmartPtr<T>::operator=(T* pPointer)
{
if(m_pPointer)
{
(*m_pReference)--;
if(*m_pReference <= 0)
{
delete m_pReference;
delete m_pPointer;
}
}
m_pReference = new int;
m_pPointer = pPointer;
(*m_pReference) = 1;
return *this;
}
template <typename T>
bool util::CSmartPtr<T>::operator==(const util::CSmartPtr<T> & SmartPtr) const
{
return m_pPointer == SmartPtr.m_pPointer;
}
template <typename T>
bool util::CSmartPtr<T>::operator!=(const util::CSmartPtr<T> & SmartPtr) const
{
return m_pPointer != SmartPtr.m_pPointer;
}
template <typename T>
T& util::CSmartPtr<T>::operator*()
{
return *m_pPointer;
}
template <typename T>
T* util::CSmartPtr<T>::operator->()
{
return m_pPointer;
}
template <typename T>
const T& util::CSmartPtr<T>::operator*() const
{
return *m_pPointer;
}
template <typename T>
const T* util::CSmartPtr<T>::operator->() const
{
return m_pPointer;
}
}//namespace gli
+31
View File
@@ -0,0 +1,31 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-08
// Licence : This source is under MIT License
// File : gli/core/size.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_SIZE_INCLUDED
#define GLI_CORE_SIZE_INCLUDED
#include "texture2d.hpp"
namespace gli
{
//template <size_type sizeType>
image2D::size_type size(
image2D const & Image,
image2D::size_type const & SizeType);
//template <size_type sizeType>
texture2D::size_type size(
texture2D const & Texture,
texture2D::size_type const & SizeType);
}//namespace gli
#include "size.inl"
#endif//GLI_CORE_SIZE_INCLUDED
+47
View File
@@ -0,0 +1,47 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-09-08
// Licence : This source is under MIT License
// File : gli/core/size.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
inline image2D::size_type size
(
image2D const & Image,
image2D::size_type const & SizeType
)
{
switch(SizeType)
{
case LINEAR_SIZE:
return detail::sizeLinear(Image);
case BLOCK_SIZE:
return detail::sizeBlock(Image.format());
case BIT_PER_PIXEL:
return detail::sizeBitPerPixel(Image.format());
case COMPONENT:
return detail::sizeComponent(Image.format());
default:
assert(0);
return 0;
};
}
inline texture2D::size_type size
(
texture2D const & Texture,
texture2D::size_type const & SizeType
)
{
texture2D::size_type Size = 0;
for(texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
Size += size(Texture[Level], SizeType);
return Size;
}
}//namespace
+122
View File
@@ -0,0 +1,122 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-01-09
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/core/texture2d.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_TEXTURE2D_INCLUDED
#define GLI_CORE_TEXTURE2D_INCLUDED
#include "image2d.hpp"
namespace gli
{
enum comp
{
X = 0,
R = 0,
S = 0,
Y = 1,
G = 1,
T = 1,
Z = 2,
B = 2,
P = 2,
W = 3,
A = 3,
Q = 3
};
//template <template <typename> class mem>
class texture2D
{
public:
typedef image2D::dimensions_type dimensions_type;
typedef image2D::texcoord_type texcoord_type;
typedef image2D::size_type size_type;
typedef image2D::value_type value_type;
typedef image2D::format_type format_type;
typedef image2D::data_type data_type;
typedef std::size_t level_type;
public:
texture2D();
explicit texture2D(level_type const & Levels);
//texture2D(image const & Mipmap, bool GenerateMipmaps = false);
~texture2D();
image2D & operator[] (
level_type const & Level);
image2D const & operator[] (
level_type const & Level) const;
bool empty() const;
format_type format() const;
level_type levels() const;
void resize(level_type const & Levels);
template <typename genType>
void swizzle(gli::comp X, gli::comp Y, gli::comp Z, gli::comp W);
private:
std::vector<image2D> Images;
};
//namespace wip
//{
// // plain
// template <typename genType>
// class plain
// {
// public:
//
// private:
// boost::shared_array<genType> Data;
// };
//
// // texture2D
// template
// <
// typename genType,
// template <typename> class surface = plain
// >
// class texture2D
// {
// public:
// typedef genType value_type;
//
// private:
// class image_impl
// {
// public:
// template <typename coordType>
// value_type const & operator() (coordType const & Coord) const;
//
// private:
// surface<value_type> Surface;
// };
//
// public:
// typedef image_impl image;
// typedef std::vector<image> mipmaps;
// typedef typename mipmaps::size_type level_type;
//
// level_type levels() const;
// image & operator[] (level_type Level);
// image const & operator[] (level_type Level) const;
//
// private:
// mipmaps Mipmaps;
// };
//
//}//namespace wip
}//namespace gli
#include "texture2d.inl"
#endif//GLI_CORE_TEXTURE2D_INCLUDED
+304
View File
@@ -0,0 +1,304 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-27
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/core/texture2D.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
namespace detail
{
inline texture2D::size_type sizeLinear
(
texture2D const & Texture
)
{
texture2D::size_type Result = 0;
for(texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
Result += sizeLinear(Texture[Level]);
return Result;
}
}//namespace detail
inline texture2D::texture2D()
{}
inline texture2D::texture2D
(
level_type const & Levels
)
{
this->Images.resize(Levels);
}
//inline texture2D::texture2D
//(
// image const & Mipmap,
// bool GenerateMipmaps // ToDo
//)
//{
// //std::size_t Levels = !GenerateMipmaps ? 1 : std::size_t(glm::log2(float(glm::max(Mipmap.width(), Mipmap.height()))));
// texture2D::level_type Levels = !GenerateMipmaps ? 1 : std::size_t(glm::log2(float(glm::compMax(Mipmap.dimensions()))));
// this->Mipmaps.resize(Levels);
// this->Mipmaps[0] = Mipmap;
// if(GenerateMipmaps)
// this->generateMipmaps(0);
//}
inline texture2D::~texture2D()
{}
inline image2D & texture2D::operator[] (level_type const & Level)
{
return this->Images[Level];
}
inline image2D const & texture2D::operator[] (level_type const & Level) const
{
return this->Images[Level];
}
inline bool texture2D::empty() const
{
return this->Images.size() == 0;
}
inline texture2D::format_type texture2D::format() const
{
return this->Images.empty() ? FORMAT_NULL : this->Images[0].format();
}
inline texture2D::level_type texture2D::levels() const
{
return this->Images.size();
}
inline void texture2D::resize
(
texture2D::level_type const & Levels
)
{
this->Images.resize(Levels);
}
template <typename genType>
inline void texture2D::swizzle(gli::comp X, gli::comp Y, gli::comp Z, gli::comp W)
{
for(texture2D::level_type Level = 0; Level < this->levels(); ++Level)
{
genType * Data = reinterpret_cast<genType*>(this->Images[Level].data());
texture2D::size_type Components = this->Images[Level].components();
//gli::detail::getComponents(this->Images[Level].format());
texture2D::size_type Size = (glm::compMul(this->Images[Level].dimensions()) * Components) / sizeof(genType);
for(texture2D::size_type i = 0; i < Size; ++i)
{
genType Copy = Data[i];
if(Components > 0)
Data[i][0] = Copy[X];
if(Components > 1)
Data[i][1] = Copy[Y];
if(Components > 2)
Data[i][2] = Copy[Z];
if(Components > 3)
Data[i][3] = Copy[W];
}
}
}
/*
template <typename T>
inline T texture<T>::texture(float x, float y) const
{
size_type x_below = size_type(std::floor(x * (_width - 1)));
size_type x_above = size_type(std::ceil(x * (_width - 1)));
size_type y_below = size_type(std::floor(y * (_height - 1)));
size_type y_above = size_type(std::ceil(y * (_height - 1)));
float x_step = 1.0f / float(_width);
float y_step = 1.0f / float(_height);
float x_below_normalized = float(x_below) / float(_width - 1);
float x_above_normalized = float(x_above) / float(_width - 1);
float y_below_normalized = float(y_below) / float(_height - 1);
float y_above_normalized = float(y_above) / float(_height - 1);
T value1 = _data[x_below + y_below * _width];
T value2 = _data[x_above + y_below * _width];
T value3 = _data[x_above + y_above * _width];
T value4 = _data[x_below + y_above * _width];
T valueA = glm::mix(value1, value2, x - x_below_normalized);
T valueB = glm::mix(value4, value3, x - x_below_normalized);
T valueC = glm::mix(valueA, valueB, y - y_below_normalized);
return valueC;
}
*/
/*
template <typename T>
inline T texture(const texture2D<T>& Image2D, const glm::vec2& TexCoord)
{
texture2D<T>::size_type s_below = texture2D<T>::size_type(std::floor(TexCoord.s * (Image2D.width() - 1)));
texture2D<T>::size_type s_above = texture2D<T>::size_type(std::ceil(TexCoord.s * (Image2D.width() - 1)));
texture2D<T>::size_type t_below = texture2D<T>::size_type(std::floor(TexCoord.t * (Image2D.height() - 1)));
texture2D<T>::size_type t_above = texture2D<T>::size_type(std::ceil(TexCoord.t * (Image2D.height() - 1)));
glm::vec2::value_type s_step = 1.0f / glm::vec2::value_type(Image2D.width());
glm::vec2::value_type t_step = 1.0f / glm::vec2::value_type(Image2D.height());
glm::vec2::value_type s_below_normalized = glm::vec2::value_type(s_below) / glm::vec2::value_type(Image2D.width() - 1);
glm::vec2::value_type s_above_normalized = glm::vec2::value_type(s_above) / glm::vec2::value_type(Image2D.width() - 1);
glm::vec2::value_type t_below_normalized = glm::vec2::value_type(t_below) / glm::vec2::value_type(Image2D.height() - 1);
glm::vec2::value_type t_above_normalized = glm::vec2::value_type(t_above) / glm::vec2::value_type(Image2D.height() - 1);
T value1 = Image2D[s_below + t_below * Image2D.width()];
T value2 = Image2D[s_above + t_below * Image2D.width()];
T value3 = Image2D[s_above + t_above * Image2D.width()];
T value4 = Image2D[s_below + t_above * Image2D.width()];
T valueA = glm::mix(value1, value2, TexCoord.s - s_below_normalized);
T valueB = glm::mix(value4, value3, TexCoord.s - s_below_normalized);
T valueC = glm::mix(valueA, valueB, TexCoord.t - t_below_normalized);
return valueC;
}
template <typename T>
inline T textureNearest(const texture2D<T>& Image2D, const glm::vec2& TexCoord)
{
texture2D<T>::size_type s = texture2D<T>::size_type(glm::roundGTX(TexCoord.s * (Image2D.width() - 1)));
texture2D<T>::size_type t = texture2D<T>::size_type(std::roundGTX(TexCoord.t * (Image2D.height() - 1)));
return Image2D[s + t * Image2D.width()];
}
*/
namespace wip
{
////////////////
// image
/*
//
template
<
typename coordType
>
template
<
typename genType,
template <typename> class surface
>
typename texture2D<genType, surface>::value_type &
texture2D<genType, surface>::image_impl<coordType>::operator()
(
coordType const & Coord
)
{
}
*/
/*
//
template
<
typename coordType
>
template
<
typename genType,
template <typename> class surface
>
typename texture2D<genType, surface>::value_type const &
texture2D<genType, surface>::image_impl::operator()
(
coordType const & Coord
) const
{
return value_type(0);
}
*/
/*
//
template
<
typename coordType
>
template
<
typename genType,
template <typename> class surface
>
void texture2D<genType, surface>::image_impl::operator()
(
coordType const & Coord
) const
{
}
*/
////
//template
//<
// typename genType,
// template <typename> class surface
//>
//template
//<
// typename coordType
//>
//typename texture2D<genType, surface>::value_type const &
//texture2D<genType, surface>::image_impl::operator()
//(
// coordType const & Coord
//) const
//{
// return value_type(0);
//}
//////////////////
//// texture2D
////
//template
//<
// typename genType,
// template <typename> class surface
//>
//typename texture2D<genType, surface>::level_type texture2D<genType, surface>::levels() const
//{
// return this->Mipmaps.size();
//}
////
//template
//<
// typename genType,
// template <typename> class surface
//>
//typename texture2D<genType, surface>::image & texture2D<genType, surface>::operator[]
//(
// typename texture2D<genType, surface>::level_type Level
//)
//{
// return this->Mipmaps[Level];
//}
////
//template
//<
// typename genType,
// template <typename> class surface
//>
//typename texture2D<genType, surface>::image const & texture2D<genType, surface>::operator[]
//(
// typename texture2D<genType, surface>::level_type Level
//) const
//{
// return this->Mipmaps[Level];
//}
}//namespace wip
}//namespace gli
+59
View File
@@ -0,0 +1,59 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture2d_array.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_TEXTURE2D_ARRAY_INCLUDED
#define GLI_CORE_TEXTURE2D_ARRAY_INCLUDED
#include "texture2d.hpp"
namespace gli
{
class texture2DArray
{
public:
typedef texture2D::dimensions_type dimensions_type;
typedef texture2D::texcoord_type texcoord_type;
typedef texture2D::size_type size_type;
typedef texture2D::value_type value_type;
typedef texture2D::format_type format_type;
typedef texture2D::data_type data_type;
typedef texture2D::level_type level_type;
typedef std::vector<texture2D>::size_type layer_type;
public:
texture2DArray();
explicit texture2DArray(
layer_type const & Layers,
level_type const & Levels);
~texture2DArray();
texture2D & operator[] (
layer_type const & Layer);
texture2D const & operator[] (
layer_type const & Layer) const;
bool empty() const;
format_type format() const;
layer_type layers() const;
level_type levels() const;
void resize(
layer_type const & Layers,
level_type const & Levels);
private:
std::vector<texture2D> Arrays;
};
}//namespace gli
#include "texture2d_array.inl"
#endif//GLI_CORE_TEXTURE2D_ARRAY_INCLUDED
+78
View File
@@ -0,0 +1,78 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture_cube.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
inline texture2DArray::texture2DArray()
{}
inline texture2DArray::texture2DArray
(
texture2DArray::layer_type const & Layers,
texture2DArray::level_type const & Levels
)
{
this->Arrays.resize(Layers);
for(texture2DArray::size_type i = 0; i < this->Arrays.size(); ++i)
this->Arrays[i].resize(Levels);
}
inline texture2DArray::~texture2DArray()
{}
inline texture2D & texture2DArray::operator[]
(
layer_type const & Layer
)
{
return this->Arrays[Layer];
}
inline texture2D const & texture2DArray::operator[]
(
layer_type const & Layer
) const
{
return this->Arrays[Layer];
}
inline bool texture2DArray::empty() const
{
return this->Arrays.empty();
}
inline texture2DArray::format_type texture2DArray::format() const
{
return this->Arrays.empty() ? FORMAT_NULL : this->Arrays[0].format();
}
inline texture2DArray::layer_type texture2DArray::layers() const
{
return this->Arrays.size();
}
inline texture2DArray::level_type texture2DArray::levels() const
{
if(this->empty())
return 0;
return this->Arrays[0].levels();
}
inline void texture2DArray::resize
(
texture2DArray::layer_type const & Layers,
texture2DArray::level_type const & Levels
)
{
this->Arrays.resize(Layers);
for(texture2DArray::layer_type i = 0; i < this->Arrays.size(); ++i)
this->Arrays[i].resize(Levels);
}
}//namespace gli
+65
View File
@@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture_cube.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_TEXTURE_CUBE_INCLUDED
#define GLI_CORE_TEXTURE_CUBE_INCLUDED
#include "texture2d.hpp"
namespace gli
{
enum face
{
POSITIVE_X,
NEGATIVE_X,
POSITIVE_Y,
NEGATIVE_Y,
POSITIVE_Z,
NEGATIVE_Z,
FACE_MAX
};
class textureCube
{
public:
typedef texture2D::dimensions_type dimensions_type;
typedef texture2D::texcoord_type texcoord_type;
typedef texture2D::size_type size_type;
typedef texture2D::value_type value_type;
typedef texture2D::format_type format_type;
typedef texture2D::data_type data_type;
typedef texture2D::level_type level_type;
typedef face face_type;
public:
textureCube();
explicit textureCube(level_type const & Levels);
~textureCube();
texture2D & operator[] (
face_type const & Face);
texture2D const & operator[] (
face_type const & Face) const;
bool empty() const;
format_type format() const;
level_type levels() const;
void resize(level_type const & Levels);
private:
std::vector<texture2D> Faces;
};
}//namespace gli
#include "texture_cube.inl"
#endif//GLI_CORE_TEXTURE_CUBE_INCLUDED
+70
View File
@@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture_cube.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
inline textureCube::textureCube()
{}
inline textureCube::textureCube
(
level_type const & Levels
)
{
this->Faces.resize(FACE_MAX);
for(textureCube::size_type i = 0; i < FACE_MAX; ++i)
this->Faces[i].resize(Levels);
}
inline textureCube::~textureCube()
{}
inline texture2D & textureCube::operator[]
(
face_type const & Face
)
{
return this->Faces[Face];
}
inline texture2D const & textureCube::operator[]
(
face_type const & Face
) const
{
return this->Faces[Face];
}
inline bool textureCube::empty() const
{
return this->Faces.size() == 0;
}
inline textureCube::format_type textureCube::format() const
{
return this->Faces.empty() ? FORMAT_NULL : this->Faces[0].format();
}
inline textureCube::level_type textureCube::levels() const
{
if(this->empty())
return 0;
return this->Faces[POSITIVE_X].levels();
}
inline void textureCube::resize
(
level_type const & Levels
)
{
for(textureCube::size_type i = 0; i < FACE_MAX; ++i)
this->Faces[i].resize(Levels);
}
}//namespace gli
+59
View File
@@ -0,0 +1,59 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture_cube_array.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_CORE_TEXTURE_CUBE_ARRAY_INCLUDED
#define GLI_CORE_TEXTURE_CUBE_ARRAY_INCLUDED
#include "texture_cube.hpp"
namespace gli
{
class textureCubeArray
{
public:
typedef textureCube::dimensions_type dimensions_type;
typedef textureCube::texcoord_type texcoord_type;
typedef textureCube::size_type size_type;
typedef textureCube::value_type value_type;
typedef textureCube::format_type format_type;
typedef std::vector<textureCube> data_type;
typedef textureCube::level_type level_type;
typedef data_type::size_type layer_type;
public:
textureCubeArray();
explicit textureCubeArray(
layer_type const & Layers,
level_type const & Levels);
~textureCubeArray();
textureCube & operator[] (
layer_type const & Layer);
textureCube const & operator[] (
layer_type const & Layer) const;
bool empty() const;
format_type format() const;
layer_type layers() const;
level_type levels() const;
void resize(
layer_type const & Layers,
level_type const & Levels);
private:
data_type Arrays;
};
}//namespace gli
#include "texture_cube_array.inl"
#endif//GLI_CORE_TEXTURE_CUBE_ARRAY_INCLUDED
+72
View File
@@ -0,0 +1,72 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-04-06
// Updated : 2011-04-06
// Licence : This source is under MIT License
// File : gli/core/texture_cube_array.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli
{
inline textureCubeArray::textureCubeArray()
{}
inline textureCubeArray::textureCubeArray
(
layer_type const & Layers,
level_type const & Levels
)
{
this->Arrays.resize(Layers);
for(textureCubeArray::size_type i = 0; i < this->Arrays.size(); ++i)
this->Arrays[i].resize(Levels);
}
inline textureCubeArray::~textureCubeArray()
{}
inline textureCube & textureCubeArray::operator[]
(
layer_type const & Layer
)
{
return this->Arrays[Layer];
}
inline textureCube const & textureCubeArray::operator[]
(
layer_type const & Layer
) const
{
return this->Arrays[Layer];
}
inline bool textureCubeArray::empty() const
{
return this->Arrays.empty();
}
inline textureCubeArray::format_type textureCubeArray::format() const
{
return this->Arrays.empty() ? FORMAT_NULL : this->Arrays[0].format();
}
inline textureCubeArray::level_type textureCubeArray::levels() const
{
if(this->empty())
return 0;
return this->Arrays[0].levels();
}
inline void textureCubeArray::resize
(
layer_type const & Layers,
level_type const & Levels
)
{
for(textureCubeArray::size_type i = 0; i < this->Arrays.size(); ++i)
this->Arrays[i].resize(Levels);
}
}//namespace gli
+31
View File
@@ -0,0 +1,31 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-09-29
// Licence : This source is under MIT License
// File : gli/gli.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
/*! \mainpage OpenGL Image
*
*/
#ifndef GLI_GLI_INCLUDED
#define GLI_GLI_INCLUDED
#define GLI_VERSION 31
#define GLI_VERSION_MAJOR 0
#define GLI_VERSION_MINOR 3
#define GLI_VERSION_PATCH 1
#define GLI_VERSION_REVISION 0
#include "./core/texture2d.hpp"
#include "./core/texture2d_array.hpp"
#include "./core/texture_cube.hpp"
#include "./core/texture_cube_array.hpp"
#include "./core/size.hpp"
#include "./core/operation.hpp"
#include "./core/generate_mipmaps.hpp"
#endif//GLI_GLI_INCLUDED
+27
View File
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/compression.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_COMPRESSION_INCLUDED
#define GLI_GTX_COMPRESSION_INCLUDED
namespace gli{
namespace gtx{
namespace compression
{
}//namespace compression
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::compression;}
#include "compression.inl"
#endif//GLI_GTX_COMPRESSION_INCLUDED
+8
View File
@@ -0,0 +1,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/compression.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
+46
View File
@@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/fetch.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_FETCH_INCLUDED
#define GLI_GTX_FETCH_INCLUDED
#include "../gli.hpp"
namespace gli{
namespace gtx{
namespace fetch
{
template <typename genType>
genType texelFetch(
texture2D const & Texture,
texture2D::dimensions_type const & Texcoord,
texture2D::level_type const & Level);
template <typename genType>
genType textureLod(
texture2D const & Texture,
texture2D::texcoord_type const & Texcoord,
texture2D::level_type const & Level);
template <typename genType>
void texelWrite(
texture2D & Texture,
texture2D::dimensions_type const & Texcoord,
texture2D::level_type const & Level,
genType const & Color);
}//namespace fetch
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::fetch;}
#include "fetch.inl"
#endif//GLI_GTX_FETCH_INCLUDED
+91
View File
@@ -0,0 +1,91 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/fetch.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace fetch
{
template <typename genType>
inline genType texelFetch
(
texture2D const & Image,
texture2D::dimensions_type const & TexCoord,
texture2D::level_type const & Level
)
{
assert(Image[Level].format() == R8U || Image[Level].format() == RG8U || Image[Level].format() == RGB8U || Image[Level].format() == RGBA8U);
texture2D::dimensions_type Dimensions = Image[Level].dimensions();
texture2D::value_type const * const Data = Image[Level].data();
return reinterpret_cast<genType const * const>(Data)[TexCoord.x + TexCoord.y * Dimensions.x];
}
template <typename genType>
inline genType textureLod
(
texture2D const & Image,
texture2D::texcoord_type const & TexCoord,
texture2D::level_type const & Level
)
{
assert(Image[Level].format() == R8U || Image[Level].format() == RG8U || Image[Level].format() == RGB8U || Image[Level].format() == RGBA8U);
texture2D::dimensions_type Dimensions = Image[Level].dimensions();
texture2D::value_type const * const Data = Image[Level].data();
std::size_t s_below = std::size_t(glm::floor(TexCoord.s * float(Dimensions.x - 1)));
std::size_t s_above = std::size_t(glm::ceil( TexCoord.s * float(Dimensions.x - 1)));
std::size_t t_below = std::size_t(glm::floor(TexCoord.t * float(Dimensions.y - 1)));
std::size_t t_above = std::size_t(glm::ceil( TexCoord.t * float(Dimensions.y - 1)));
float s_step = 1.0f / float(Dimensions.x);
float t_step = 1.0f / float(Dimensions.y);
float s_below_normalized = s_below / float(Dimensions.x);
float s_above_normalized = s_above / float(Dimensions.x);
float t_below_normalized = t_below / float(Dimensions.y);
float t_above_normalized = t_above / float(Dimensions.y);
genType Value1 = reinterpret_cast<genType const * const>(Data)[s_below + t_below * Dimensions.x];
genType Value2 = reinterpret_cast<genType const * const>(Data)[s_above + t_below * Dimensions.x];
genType Value3 = reinterpret_cast<genType const * const>(Data)[s_above + t_above * Dimensions.x];
genType Value4 = reinterpret_cast<genType const * const>(Data)[s_below + t_above * Dimensions.x];
float BlendA = float(TexCoord.s - s_below_normalized) * float(Dimensions.x - 1);
float BlendB = float(TexCoord.s - s_below_normalized) * float(Dimensions.x - 1);
float BlendC = float(TexCoord.t - t_below_normalized) * float(Dimensions.y - 1);
genType ValueA(glm::mix(Value1, Value2, BlendA));
genType ValueB(glm::mix(Value4, Value3, BlendB));
return genType(glm::mix(ValueA, ValueB, BlendC));
}
template <typename genType>
void texelWrite
(
texture2D & Image,
texture2D::dimensions_type const & Texcoord,
texture2D::level_type const & Level,
genType const & Color
)
{
genType * Data = (genType*)Image[Level].data();
std::size_t Index = Texcoord.x + Texcoord.y * Image[Level].dimensions().x;
std::size_t Capacity = Image[Level].capacity();
assert(Index < Capacity);
*(Data + Index) = Color;
}
}//namespace fetch
}//namespace gtx
}//namespace gli
+33
View File
@@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-27
// Updated : 2010-10-01
// Licence : This source is under MIT License
// File : gli/gtx/gl_texture2d.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_GL_TEXTURE2D_INCLUDED
#define GLI_GTX_GL_TEXTURE2D_INCLUDED
#include "../gli.hpp"
#include "../gtx/loader.hpp"
#ifndef GL_VERSION_1_1
#error "ERROR: OpenGL must be included before GLI_GTX_gl_texture2d"
#endif//GL_VERSION_1_1
namespace gli{
namespace gtx{
namespace gl_texture2d
{
GLuint createTexture2D(std::string const & Filename);
}//namespace gl_texture2d
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::gl_texture2d;}
#include "gl_texture2d.inl"
#endif//GLI_GTX_GL_TEXTURE2D_INCLUDED
+210
View File
@@ -0,0 +1,210 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-27
// Updated : 2010-10-01
// Licence : This source is under MIT License
// File : gli/gtx/gl_texture2d.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace gl_texture2d{
namespace detail
{
//GL_COMPRESSED_RED, GL_COMPRESSED_RG, GL_COMPRESSED_RGB, GL_COMPRESSED_RGBA, GL_COMPRESSED_SRGB, GL_COMPRESSED_SRGB_ALPHA,
//GL_SRGB, GL_SRGB8, GL_SRGB_ALPHA, or GL_SRGB8_ALPHA8
struct texture_desc
{
GLint InternalFormat;
GLint InternalFormatCompressed;
GLint InternalFormatSRGB;
GLint InternalFormatCompressedSRGB;
GLenum ExternalFormat;
GLenum ExternalFormatRev;
GLenum Type;
};
//GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, and GL_BGRA.
//GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT,
//GL_INT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
//GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4,
//GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
//GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2,
//GL_UNSIGNED_INT_2_10_10_10_REV
# ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
# define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
# endif
# ifndef GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
# define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D
# endif
# ifndef GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
# define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E
# endif
# ifndef GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
# define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F
# endif
inline texture_desc gli2ogl_cast(format const & Format)
{
texture_desc Cast[] =
{
{GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE, GL_NONE},
//// Normalized
//{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_BYTE},
//{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_BYTE},
//{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_BYTE},
//{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE},
//{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_SHORT},
//{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_SHORT},
//{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_SHORT},
//{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_SHORT},
//{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_INT},
//{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_INT},
//{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_INT},
//{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_INT},
// Unsigned
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_BYTE},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_BYTE},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_BYTE},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_SHORT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_SHORT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_SHORT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_SHORT},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_UNSIGNED_INT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_UNSIGNED_INT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_UNSIGNED_INT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_UNSIGNED_INT},
// Signed
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_BYTE},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_BYTE},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_BYTE},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_BYTE},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_SHORT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_SHORT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_SHORT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_SHORT},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_INT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_INT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_INT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_INT},
// Float
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_HALF_FLOAT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_HALF_FLOAT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_HALF_FLOAT},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_FLOAT},
{GL_RG, GL_COMPRESSED_RG, GL_RG, GL_COMPRESSED_RG, GL_RG, GL_RG, GL_FLOAT},
{GL_RGB, GL_COMPRESSED_RGB, GL_SRGB8, GL_COMPRESSED_SRGB, GL_RGB, GL_BGR, GL_FLOAT},
{GL_RGBA, GL_COMPRESSED_RGBA, GL_SRGB8_ALPHA8, GL_COMPRESSED_SRGB_ALPHA, GL_RGBA, GL_BGRA, GL_FLOAT},
// Packed
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_RGB9_E5, GL_RGB9_E5, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_R11F_G11F_B10F, GL_R11F_G11F_B10F, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_RED, GL_COMPRESSED_RED, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_RGBA4, GL_RGBA4, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
{GL_RGB10_A2, GL_RGB10_A2, GL_RED, GL_COMPRESSED_RED, GL_RED, GL_RED, GL_HALF_FLOAT},
// Depth
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT},
{GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT},
{GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_UNSIGNED_INT},
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT},
{GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, GL_UNSIGNED_INT},
// Compressed formats
{GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_NONE, GL_NONE, GL_NONE},
{GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, GL_NONE, GL_NONE, GL_NONE},
};
return Cast[Format];
}
}//namespace detail
inline GLuint createTexture2D(std::string const & Filename)
{
gli::texture2D Texture = gli::load(Filename);
if(Texture.empty())
return 0;
detail::texture_desc TextureDesc = detail::gli2ogl_cast(Texture.format());
GLint Alignment = 0;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &Alignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLuint Name = 0;
glGenTextures(1, &Name);
glBindTexture(GL_TEXTURE_2D, Name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Texture.levels() > 1 ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if(size(Texture, BIT_PER_PIXEL) == size(Texture, BLOCK_SIZE) << 3)
{
for(gli::texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
{
glTexImage2D(
GL_TEXTURE_2D,
GLint(Level),
TextureDesc.InternalFormat,
GLsizei(Texture[Level].dimensions().x),
GLsizei(Texture[Level].dimensions().y),
0,
TextureDesc.ExternalFormatRev,
TextureDesc.Type,
Texture[Level].data());
}
}
else
{
for(gli::texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
{
glCompressedTexImage2D(
GL_TEXTURE_2D,
GLint(Level),
TextureDesc.InternalFormat,
GLsizei(Texture[Level].dimensions().x),
GLsizei(Texture[Level].dimensions().y),
0,
GLsizei(Texture[Level].capacity()),
Texture[Level].data());
}
}
glBindTexture(GL_TEXTURE_2D, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, Alignment);
return Name;
}
}//namespace gl_texture_2d
}//namespace gtx
}//namespace gli
+38
View File
@@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/gradient.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_GRADIENT_INCLUDED
#define GLI_GTX_GRADIENT_INCLUDED
#include "../gli.hpp"
namespace gli{
namespace gtx{
namespace gradient
{
texture2D radial(
texture2D::dimensions_type const & Size,
texture2D::texcoord_type const & Center,
float const & Radius,
texture2D::texcoord_type const & Focal);
texture2D linear(
texture2D::dimensions_type const & Size,
texture2D::texcoord_type const & Point0,
texture2D::texcoord_type const & Point1);
}//namespace gradient
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::gradient;}
#include "gradient.inl"
#endif//GLI_GTX_GRADIENT_INCLUDED
+74
View File
@@ -0,0 +1,74 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-12-19
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/gradient.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace gradient
{
inline texture2D radial
(
texture2D::dimensions_type const & Size,
texture2D::texcoord_type const & Center,
float const & Radius,
texture2D::texcoord_type const & Focal
)
{
image2D Result(texture2D::dimensions_type(Size), gli::RGB8U);
glm::u8vec3 * DstData = (glm::u8vec3 *)Result.data();
for(std::size_t y = 0; y < Result.dimensions().y; ++y)
for(std::size_t x = 0; x < Result.dimensions().x; ++x)
{
float Value = glm::radialGradient(
Center * glm::vec2(Size),
Radius,
Focal * glm::vec2(Size),
glm::vec2(x, y));
std::size_t Index = x + y * Result.dimensions().x;
*(DstData + Index) = glm::u8vec3(glm::u8(glm::clamp(Value * 255.f, 0.f, 255.f)));
}
gli::texture2D Image(1);
Image[0] = Result;
return Image;
}
inline texture2D linear
(
texture2D::dimensions_type const & Size,
texture2D::texcoord_type const & Point0,
texture2D::texcoord_type const & Point1
)
{
image2D Result(texture2D::dimensions_type(Size), gli::RGB8U);
glm::u8vec3 * DstData = (glm::u8vec3 *)Result.data();
for(std::size_t y = 0; y < Result.dimensions().y; ++y)
for(std::size_t x = 0; x < Result.dimensions().x; ++x)
{
float Value = glm::linearGradient(
Point0 * glm::vec2(Size),
Point1 * glm::vec2(Size),
texture2D::texcoord_type(x, y));
std::size_t Index = x + y * Result.dimensions().x;
*(DstData + Index) = glm::u8vec3(glm::u8(glm::clamp(Value * 255.f, 0.f, 255.f)));
}
gli::texture2D Image(1);
Image[0] = Result;
return Image;
}
}//namespace gradient
}//namespace gtx
}//namespace gli
+37
View File
@@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_LOADER_INCLUDED
#define GLI_GTX_LOADER_INCLUDED
#include "../gli.hpp"
#include "../gtx/loader_dds9.hpp"
#include "../gtx/loader_dds10.hpp"
#include "../gtx/loader_tga.hpp"
namespace gli{
namespace gtx{
namespace loader
{
inline texture2D load(
std::string const & Filename);
inline void save(
texture2D const & Image,
std::string const & Filename);
}//namespace loader
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::loader;}
#include "loader.inl"
#endif//GLI_GTX_LOADER_INCLUDED
+46
View File
@@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace loader
{
inline texture2D load
(
std::string const & Filename
)
{
if(Filename.find(".dds") != std::string::npos)
return loadDDS10(Filename);
else if(Filename.find(".tga") != std::string::npos)
return loadTGA(Filename);
else
{
assert(0); // File format not supported
return texture2D();
}
}
inline void save
(
texture2D const & Image,
std::string const & Filename
)
{
if(Filename.find(".dds") != std::string::npos)
saveDDS10(Image, Filename);
else if(Filename.find(".tga") != std::string::npos)
saveTGA(Image, Filename);
else
assert(0); // File format not supported
}
}//namespace loader
}//namespace gtx
}//namespace gli
+35
View File
@@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-26
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_dds10.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_LOADER_DDS10_INCLUDED
#define GLI_GTX_LOADER_DDS10_INCLUDED
#include "../gli.hpp"
#include <fstream>
namespace gli{
namespace gtx{
namespace loader_dds10
{
texture2D loadDDS10(
std::string const & Filename);
void saveDDS10(
texture2D const & Image,
std::string const & Filename);
}//namespace loader_dds10
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::loader_dds10;}
#include "loader_dds10.inl"
#endif//GLI_GTX_LOADER_DDS10_INCLUDED
+595
View File
@@ -0,0 +1,595 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-26
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_dds10.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace loader_dds10{
namespace detail
{
// DDS Documentation
/*
http://msdn.microsoft.com/en-us/library/bb943991(VS.85).aspx#File_Layout1
http://msdn.microsoft.com/en-us/library/bb943992.aspx
*/
#define GLI_MAKEFOURCC(ch0, ch1, ch2, ch3) \
(glm::uint32)( \
(((glm::uint32)(glm::uint8)(ch3) << 24) & 0xFF000000) | \
(((glm::uint32)(glm::uint8)(ch2) << 16) & 0x00FF0000) | \
(((glm::uint32)(glm::uint8)(ch1) << 8) & 0x0000FF00) | \
((glm::uint32)(glm::uint8)(ch0) & 0x000000FF) )
enum DXGI_FORMAT
{
DXGI_FORMAT_UNKNOWN = 0,
DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
DXGI_FORMAT_R32G32B32A32_UINT = 3,
DXGI_FORMAT_R32G32B32A32_SINT = 4,
DXGI_FORMAT_R32G32B32_TYPELESS = 5,
DXGI_FORMAT_R32G32B32_FLOAT = 6,
DXGI_FORMAT_R32G32B32_UINT = 7,
DXGI_FORMAT_R32G32B32_SINT = 8,
DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
DXGI_FORMAT_R16G16B16A16_UNORM = 11,
DXGI_FORMAT_R16G16B16A16_UINT = 12,
DXGI_FORMAT_R16G16B16A16_SNORM = 13,
DXGI_FORMAT_R16G16B16A16_SINT = 14,
DXGI_FORMAT_R32G32_TYPELESS = 15,
DXGI_FORMAT_R32G32_FLOAT = 16,
DXGI_FORMAT_R32G32_UINT = 17,
DXGI_FORMAT_R32G32_SINT = 18,
DXGI_FORMAT_R32G8X24_TYPELESS = 19,
DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
DXGI_FORMAT_R10G10B10A2_UNORM = 24,
DXGI_FORMAT_R10G10B10A2_UINT = 25,
DXGI_FORMAT_R11G11B10_FLOAT = 26,
DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
DXGI_FORMAT_R8G8B8A8_UNORM = 28,
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
DXGI_FORMAT_R8G8B8A8_UINT = 30,
DXGI_FORMAT_R8G8B8A8_SNORM = 31,
DXGI_FORMAT_R8G8B8A8_SINT = 32,
DXGI_FORMAT_R16G16_TYPELESS = 33,
DXGI_FORMAT_R16G16_FLOAT = 34,
DXGI_FORMAT_R16G16_UNORM = 35,
DXGI_FORMAT_R16G16_UINT = 36,
DXGI_FORMAT_R16G16_SNORM = 37,
DXGI_FORMAT_R16G16_SINT = 38,
DXGI_FORMAT_R32_TYPELESS = 39,
DXGI_FORMAT_D32_FLOAT = 40,
DXGI_FORMAT_R32_FLOAT = 41,
DXGI_FORMAT_R32_UINT = 42,
DXGI_FORMAT_R32_SINT = 43,
DXGI_FORMAT_R24G8_TYPELESS = 44,
DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
DXGI_FORMAT_R8G8_TYPELESS = 48,
DXGI_FORMAT_R8G8_UNORM = 49,
DXGI_FORMAT_R8G8_UINT = 50,
DXGI_FORMAT_R8G8_SNORM = 51,
DXGI_FORMAT_R8G8_SINT = 52,
DXGI_FORMAT_R16_TYPELESS = 53,
DXGI_FORMAT_R16_FLOAT = 54,
DXGI_FORMAT_D16_UNORM = 55,
DXGI_FORMAT_R16_UNORM = 56,
DXGI_FORMAT_R16_UINT = 57,
DXGI_FORMAT_R16_SNORM = 58,
DXGI_FORMAT_R16_SINT = 59,
DXGI_FORMAT_R8_TYPELESS = 60,
DXGI_FORMAT_R8_UNORM = 61,
DXGI_FORMAT_R8_UINT = 62,
DXGI_FORMAT_R8_SNORM = 63,
DXGI_FORMAT_R8_SINT = 64,
DXGI_FORMAT_A8_UNORM = 65,
DXGI_FORMAT_R1_UNORM = 66,
DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
DXGI_FORMAT_BC1_TYPELESS = 70,
DXGI_FORMAT_BC1_UNORM = 71,
DXGI_FORMAT_BC1_UNORM_SRGB = 72,
DXGI_FORMAT_BC2_TYPELESS = 73,
DXGI_FORMAT_BC2_UNORM = 74,
DXGI_FORMAT_BC2_UNORM_SRGB = 75,
DXGI_FORMAT_BC3_TYPELESS = 76,
DXGI_FORMAT_BC3_UNORM = 77,
DXGI_FORMAT_BC3_UNORM_SRGB = 78,
DXGI_FORMAT_BC4_TYPELESS = 79,
DXGI_FORMAT_BC4_UNORM = 80,
DXGI_FORMAT_BC4_SNORM = 81,
DXGI_FORMAT_BC5_TYPELESS = 82,
DXGI_FORMAT_BC5_UNORM = 83,
DXGI_FORMAT_BC5_SNORM = 84,
DXGI_FORMAT_B5G6R5_UNORM = 85,
DXGI_FORMAT_B5G5R5A1_UNORM = 86,
DXGI_FORMAT_B8G8R8A8_UNORM = 87,
DXGI_FORMAT_B8G8R8X8_UNORM = 88,
DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
DXGI_FORMAT_BC6H_TYPELESS = 94,
DXGI_FORMAT_BC6H_UF16 = 95,
DXGI_FORMAT_BC6H_SF16 = 96,
DXGI_FORMAT_BC7_TYPELESS = 97,
DXGI_FORMAT_BC7_UNORM = 98,
DXGI_FORMAT_BC7_UNORM_SRGB = 99,
DXGI_FORMAT_FORCE_UINT = 0xffffffffUL
};
enum D3D10_RESOURCE_DIMENSION
{
D3D10_RESOURCE_DIMENSION_UNKNOWN = 0,
D3D10_RESOURCE_DIMENSION_BUFFER = 1,
D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2,
D3D10_RESOURCE_DIMENSION_TEXTURE2D = 3,
D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4
};
enum D3D10_RESOURCE_MISC_FLAG
{
D3D10_RESOURCE_MISC_GENERATE_MIPS = 0x1L,
D3D10_RESOURCE_MISC_SHARED = 0x2L,
D3D10_RESOURCE_MISC_TEXTURECUBE = 0x4L,
D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX = 0x10L,
D3D10_RESOURCE_MISC_GDI_COMPATIBLE = 0x20L
};
enum dds_format
{
GLI_D3DFMT_R8G8B8 = 20,
GLI_D3DFMT_A8R8G8B8 = 21,
GLI_D3DFMT_X8R8G8B8 = 22,
GLI_D3DFMT_A8 = 28,
GLI_D3DFMT_A2B10G10R10 = 31,
GLI_D3DFMT_A8B8G8R8 = 32,
GLI_D3DFMT_X8B8G8R8 = 33,
GLI_D3DFMT_G16R16 = 34,
GLI_D3DFMT_A2R10G10B10 = 35,
GLI_D3DFMT_A16B16G16R16 = 36,
GLI_D3DFMT_L8 = 50,
GLI_D3DFMT_A8L8 = 51,
GLI_D3DFMT_DXT1 = GLI_MAKEFOURCC('D', 'X', 'T', '1'),
GLI_D3DFMT_DXT2 = GLI_MAKEFOURCC('D', 'X', 'T', '2'),
GLI_D3DFMT_DXT3 = GLI_MAKEFOURCC('D', 'X', 'T', '3'),
GLI_D3DFMT_DXT4 = GLI_MAKEFOURCC('D', 'X', 'T', '4'),
GLI_D3DFMT_DXT5 = GLI_MAKEFOURCC('D', 'X', 'T', '5'),
GLI_D3DFMT_DX10 = GLI_MAKEFOURCC('D', 'X', '1', '0'),
GLI_D3DFMT_D32 = 71,
GLI_D3DFMT_D24S8 = 75,
GLI_D3DFMT_D24X8 = 77,
GLI_D3DFMT_D16 = 80,
GLI_D3DFMT_L16 = 81,
GLI_D3DFMT_D32F_LOCKABLE = 82,
GLI_D3DFMT_D24FS8 = 83,
GLI_D3DFMT_R16F = 111,
GLI_D3DFMT_G16R16F = 112,
GLI_D3DFMT_A16B16G16R16F = 113,
GLI_D3DFMT_R32F = 114,
GLI_D3DFMT_G32R32F = 115,
GLI_D3DFMT_A32B32G32R32F = 116
};
struct ddsHeader10
{
DXGI_FORMAT dxgiFormat;
D3D10_RESOURCE_DIMENSION resourceDimension;
glm::uint32 miscFlag; // D3D10_RESOURCE_MISC_GENERATE_MIPS
glm::uint32 arraySize;
glm::uint32 reserved;
};
inline gli::format format_fourcc2gli_cast(glm::uint32 const & FourCC)
{
switch(FourCC)
{
case loader_dds9::detail::GLI_FOURCC_DXT1:
return DXT1;
case loader_dds9::detail::GLI_FOURCC_DXT2:
case loader_dds9::detail::GLI_FOURCC_DXT3:
return DXT3;
case loader_dds9::detail::GLI_FOURCC_DXT4:
case loader_dds9::detail::GLI_FOURCC_DXT5:
return DXT5;
case loader_dds9::detail::GLI_FOURCC_R16F:
return R16F;
case loader_dds9::detail::GLI_FOURCC_G16R16F:
return RG16F;
case loader_dds9::detail::GLI_FOURCC_A16B16G16R16F:
return RGBA16F;
case loader_dds9::detail::GLI_FOURCC_R32F:
return R32F;
case loader_dds9::detail::GLI_FOURCC_G32R32F:
return RG32F;
case loader_dds9::detail::GLI_FOURCC_A32B32G32R32F:
return RGBA32F;
case loader_dds9::detail::GLI_D3DFMT_R8G8B8:
return RGB8U;
case loader_dds9::detail::GLI_D3DFMT_A8R8G8B8:
case loader_dds9::detail::GLI_D3DFMT_X8R8G8B8:
case loader_dds9::detail::GLI_D3DFMT_A8B8G8R8:
case loader_dds9::detail::GLI_D3DFMT_X8B8G8R8:
return RGBA8U;
case loader_dds9::detail::GLI_D3DFMT_R5G6B5:
return R5G6B5;
case loader_dds9::detail::GLI_D3DFMT_A4R4G4B4:
case loader_dds9::detail::GLI_D3DFMT_X4R4G4B4:
return RGBA4;
case loader_dds9::detail::GLI_D3DFMT_G16R16:
return RG16U;
case loader_dds9::detail::GLI_D3DFMT_A16B16G16R16:
return RGBA16U;
case loader_dds9::detail::GLI_D3DFMT_A2R10G10B10:
case loader_dds9::detail::GLI_D3DFMT_A2B10G10R10:
return RGB10A2;
default:
assert(0);
return FORMAT_NULL;
}
}
inline DXGI_FORMAT format_gli2dds_cast(gli::format const & Format)
{
DXGI_FORMAT Cast[] =
{
DXGI_FORMAT_UNKNOWN, //FORMAT_NULL,
// Unsigned integer formats
DXGI_FORMAT_R8_UINT, //R8U,
DXGI_FORMAT_R8G8_UINT, //RG8U,
DXGI_FORMAT_UNKNOWN, //RGB8U,
DXGI_FORMAT_R8G8B8A8_UINT, //RGBA8U,
DXGI_FORMAT_R16_UINT, //R16U,
DXGI_FORMAT_R16G16_UINT, //RG16U,
DXGI_FORMAT_UNKNOWN, //RGB16U,
DXGI_FORMAT_R16G16B16A16_UINT, //RGBA16U,
DXGI_FORMAT_R32_UINT, //R32U,
DXGI_FORMAT_R32G32_UINT, //RG32U,
DXGI_FORMAT_R32G32B32_UINT, //RGB32U,
DXGI_FORMAT_R32G32B32A32_UINT, //RGBA32U,
// Signed integer formats
DXGI_FORMAT_R8_SINT, //R8I,
DXGI_FORMAT_R8G8_SINT, //RG8I,
DXGI_FORMAT_UNKNOWN, //RGB8I,
DXGI_FORMAT_R8G8B8A8_SINT, //RGBA8I,
DXGI_FORMAT_R16_SINT, //R16I,
DXGI_FORMAT_R16G16_SINT, //RG16I,
DXGI_FORMAT_UNKNOWN, //RGB16I,
DXGI_FORMAT_R16G16B16A16_SINT, //RGBA16I,
DXGI_FORMAT_R32_SINT, //R32I,
DXGI_FORMAT_R32G32_SINT, //RG32I,
DXGI_FORMAT_R32G32B32_SINT, //RGB32I,
DXGI_FORMAT_R32G32B32A32_SINT, //RGBA32I,
// Floating formats
DXGI_FORMAT_R16_FLOAT, //R16F,
DXGI_FORMAT_R16G16_FLOAT, //RG16F,
DXGI_FORMAT_UNKNOWN, //RGB16F,
DXGI_FORMAT_R16G16B16A16_FLOAT, //RGBA16F,
DXGI_FORMAT_R32_FLOAT, //R32F,
DXGI_FORMAT_R32G32_FLOAT, //RG32F,
DXGI_FORMAT_R32G32B32_FLOAT, //RGB32F,
DXGI_FORMAT_R32G32B32A32_FLOAT, //RGBA32F,
// Packed formats
DXGI_FORMAT_UNKNOWN, //RGBE8,
DXGI_FORMAT_R9G9B9E5_SHAREDEXP, //RGB9E5,
DXGI_FORMAT_R11G11B10_FLOAT,
DXGI_FORMAT_B5G6R5_UNORM, //R5G6B5,
DXGI_FORMAT_UNKNOWN, //RGBA4,
DXGI_FORMAT_R10G10B10A2_TYPELESS, //RGB10A2,
// Depth formats
DXGI_FORMAT_D16_UNORM, //D16,
DXGI_FORMAT_D24_UNORM_S8_UINT, //D24X8,
DXGI_FORMAT_D24_UNORM_S8_UINT, //D24S8,
DXGI_FORMAT_D32_FLOAT, //D32F,
DXGI_FORMAT_D32_FLOAT_S8X24_UINT, //D32FS8X24,
// Compressed formats
DXGI_FORMAT_BC1_UNORM, //DXT1,
DXGI_FORMAT_BC2_UNORM, //DXT3,
DXGI_FORMAT_BC3_UNORM, //DXT5,
DXGI_FORMAT_BC4_UNORM, //ATI1N_UNORM,
DXGI_FORMAT_BC4_SNORM, //ATI1N_SNORM,
DXGI_FORMAT_BC5_UNORM, //ATI2N_UNORM,
DXGI_FORMAT_BC5_SNORM, //ATI2N_SNORM,
DXGI_FORMAT_BC6H_UF16, //BP_FLOAT,
DXGI_FORMAT_BC6H_SF16, //BP_FLOAT,
DXGI_FORMAT_BC7_UNORM //BP,
};
return Cast[Format];
}
inline gli::format format_dds2gli_cast(DXGI_FORMAT const & Format)
{
gli::format Cast[] =
{
gli::FORMAT_NULL, //DXGI_FORMAT_UNKNOWN = 0,
gli::RGBA32U, //DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
gli::RGBA32F, //DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
gli::RGBA32U, //DXGI_FORMAT_R32G32B32A32_UINT = 3,
gli::RGBA32I, //DXGI_FORMAT_R32G32B32A32_SINT = 4,
gli::RGB32U, //DXGI_FORMAT_R32G32B32_TYPELESS = 5,
gli::RGB32F, //DXGI_FORMAT_R32G32B32_FLOAT = 6,
gli::RGB32U, //DXGI_FORMAT_R32G32B32_UINT = 7,
gli::RGB32I, //DXGI_FORMAT_R32G32B32_SINT = 8,
gli::RGBA16U, //DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
gli::RGBA16F, //DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
gli::RGBA16U, //DXGI_FORMAT_R16G16B16A16_UNORM = 11,
gli::RGBA16I, //DXGI_FORMAT_R16G16B16A16_UINT = 12,
gli::RGBA16I, //DXGI_FORMAT_R16G16B16A16_SNORM = 13,
gli::RGBA16I, //DXGI_FORMAT_R16G16B16A16_SINT = 14,
gli::RG32U, //DXGI_FORMAT_R32G32_TYPELESS = 15,
gli::RG32F, //DXGI_FORMAT_R32G32_FLOAT = 16,
gli::RG32U, //DXGI_FORMAT_R32G32_UINT = 17,
gli::RG32I, //DXGI_FORMAT_R32G32_SINT = 18,
gli::FORMAT_NULL, //DXGI_FORMAT_R32G8X24_TYPELESS = 19,
gli::D32FS8X24, //DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
gli::FORMAT_NULL, //DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
gli::FORMAT_NULL, //DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
gli::RGB10A2, //DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
gli::RGB10A2, //DXGI_FORMAT_R10G10B10A2_UNORM = 24,
gli::RGB10A2, //DXGI_FORMAT_R10G10B10A2_UINT = 25,
gli::RG11B10F, //DXGI_FORMAT_R11G11B10_FLOAT = 26,
gli::RGBA8U, //DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
gli::RGBA8U, //DXGI_FORMAT_R8G8B8A8_UNORM = 28,
gli::RGBA8U, //DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
gli::RGBA8U, //DXGI_FORMAT_R8G8B8A8_UINT = 30,
gli::RGBA8I, //DXGI_FORMAT_R8G8B8A8_SNORM = 31,
gli::RGBA8I, //DXGI_FORMAT_R8G8B8A8_SINT = 32,
gli::RG16U, //DXGI_FORMAT_R16G16_TYPELESS = 33,
gli::RG16F, //DXGI_FORMAT_R16G16_FLOAT = 34,
gli::RG16U, //DXGI_FORMAT_R16G16_UNORM = 35,
gli::RG16U, //DXGI_FORMAT_R16G16_UINT = 36,
gli::RG16I, //DXGI_FORMAT_R16G16_SNORM = 37,
gli::RG16I, //DXGI_FORMAT_R16G16_SINT = 38,
gli::R32F, //DXGI_FORMAT_R32_TYPELESS = 39,
gli::D32F, //DXGI_FORMAT_D32_FLOAT = 40,
gli::R32F, //DXGI_FORMAT_R32_FLOAT = 41,
gli::R32U, //DXGI_FORMAT_R32_UINT = 42,
gli::R32I, //DXGI_FORMAT_R32_SINT = 43,
gli::FORMAT_NULL, //DXGI_FORMAT_R24G8_TYPELESS = 44,
gli::FORMAT_NULL, //DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
gli::FORMAT_NULL, //DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
gli::FORMAT_NULL, //DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
gli::RG8U, //DXGI_FORMAT_R8G8_TYPELESS = 48,
gli::RG8U, //DXGI_FORMAT_R8G8_UNORM = 49,
gli::RG8U, //DXGI_FORMAT_R8G8_UINT = 50,
gli::RG8I, //DXGI_FORMAT_R8G8_SNORM = 51,
gli::RG8I, //DXGI_FORMAT_R8G8_SINT = 52,
gli::R16U, //DXGI_FORMAT_R16_TYPELESS = 53,
gli::R16F, //DXGI_FORMAT_R16_FLOAT = 54,
gli::D16, //DXGI_FORMAT_D16_UNORM = 55,
gli::R16U, //DXGI_FORMAT_R16_UNORM = 56,
gli::R16U, //DXGI_FORMAT_R16_UINT = 57,
gli::R16I, //DXGI_FORMAT_R16_SNORM = 58,
gli::R16I, //DXGI_FORMAT_R16_SINT = 59,
gli::R8U, //DXGI_FORMAT_R8_TYPELESS = 60,
gli::R8U, //DXGI_FORMAT_R8_UNORM = 61,
gli::R8U, //DXGI_FORMAT_R8_UINT = 62,
gli::R8I, //DXGI_FORMAT_R8_SNORM = 63,
gli::R8I, //DXGI_FORMAT_R8_SINT = 64,
gli::R8U, //DXGI_FORMAT_A8_UNORM = 65,
gli::FORMAT_NULL, //DXGI_FORMAT_R1_UNORM = 66,
gli::RGB9E5, //DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
gli::FORMAT_NULL, //DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
gli::FORMAT_NULL, //DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
gli::DXT1, //DXGI_FORMAT_BC1_TYPELESS = 70,
gli::DXT1, //DXGI_FORMAT_BC1_UNORM = 71,
gli::DXT1, //DXGI_FORMAT_BC1_UNORM_SRGB = 72,
gli::DXT3, //DXGI_FORMAT_BC2_TYPELESS = 73,
gli::DXT3, //DXGI_FORMAT_BC2_UNORM = 74,
gli::DXT3, //DXGI_FORMAT_BC2_UNORM_SRGB = 75,
gli::DXT5, //DXGI_FORMAT_BC3_TYPELESS = 76,
gli::DXT5, //DXGI_FORMAT_BC3_UNORM = 77,
gli::DXT5, //DXGI_FORMAT_BC3_UNORM_SRGB = 78,
gli::ATI1N_UNORM, //DXGI_FORMAT_BC4_TYPELESS = 79,
gli::ATI1N_UNORM, //DXGI_FORMAT_BC4_UNORM = 80,
gli::ATI1N_SNORM, //DXGI_FORMAT_BC4_SNORM = 81,
gli::ATI2N_UNORM, //DXGI_FORMAT_BC5_TYPELESS = 82,
gli::ATI2N_UNORM, //DXGI_FORMAT_BC5_UNORM = 83,
gli::ATI2N_SNORM, //DXGI_FORMAT_BC5_SNORM = 84,
gli::FORMAT_NULL, //DXGI_FORMAT_B5G6R5_UNORM = 85,
gli::FORMAT_NULL, //DXGI_FORMAT_B5G5R5A1_UNORM = 86,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8A8_UNORM = 87,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8X8_UNORM = 88,
gli::FORMAT_NULL, //DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
gli::RGBA8U, //DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
gli::BP_UF16, //DXGI_FORMAT_BC6H_TYPELESS = 94,
gli::BP_UF16, //DXGI_FORMAT_BC6H_UF16 = 95,
gli::BP_SF16, //DXGI_FORMAT_BC6H_SF16 = 96,
gli::BP, //DXGI_FORMAT_BC7_TYPELESS = 97,
gli::BP, //DXGI_FORMAT_BC7_UNORM = 98,
gli::BP, //DXGI_FORMAT_BC7_UNORM_SRGB = 99,
gli::R32U //DXGI_FORMAT_FORCE_UINT = 0xffffffffUL
};
return Cast[Format];
}
}//namespace detail
inline texture2D loadDDS10
(
std::string const & Filename
)
{
std::ifstream FileIn(Filename.c_str(), std::ios::in | std::ios::binary);
if(FileIn.fail())
return texture2D();
loader_dds9::detail::ddsHeader HeaderDesc;
detail::ddsHeader10 HeaderDesc10;
char Magic[4];
//* Read magic number and check if valid .dds file
FileIn.read((char*)&Magic, sizeof(Magic));
assert(strncmp(Magic, "DDS ", 4) == 0);
// Get the surface descriptor
FileIn.read((char*)&HeaderDesc, sizeof(HeaderDesc));
if(HeaderDesc.format.flags & loader_dds9::detail::GLI_DDPF_FOURCC && HeaderDesc.format.fourCC == loader_dds9::detail::GLI_FOURCC_DX10)
FileIn.read((char*)&HeaderDesc10, sizeof(HeaderDesc10));
loader_dds9::detail::DDLoader Loader;
if(HeaderDesc.format.fourCC == loader_dds9::detail::GLI_FOURCC_DX10)
Loader.Format = detail::format_dds2gli_cast(HeaderDesc10.dxgiFormat);
else if(HeaderDesc.format.flags & loader_dds9::detail::GLI_DDPF_FOURCC)
Loader.Format = detail::format_fourcc2gli_cast(HeaderDesc.format.fourCC);
else
{
switch(HeaderDesc.format.bpp)
{
case 8:
Loader.Format = R8U;
break;
case 16:
Loader.Format = RG8U;
break;
case 24:
Loader.Format = RGB8U;
break;
case 32:
Loader.Format = RGBA8U;
break;
}
}
Loader.BlockSize = size(image2D(texture2D::dimensions_type(0), Loader.Format), BLOCK_SIZE);
Loader.BPP = size(image2D(image2D::dimensions_type(0), Loader.Format), BIT_PER_PIXEL);
std::size_t Width = HeaderDesc.width;
std::size_t Height = HeaderDesc.height;
gli::format Format = Loader.Format;
std::streamoff Curr = FileIn.tellg();
FileIn.seekg(0, std::ios_base::end);
std::streamoff End = FileIn.tellg();
FileIn.seekg(Curr, std::ios_base::beg);
std::vector<glm::byte> Data(std::size_t(End - Curr), 0);
std::size_t Offset = 0;
FileIn.read((char*)&Data[0], std::streamsize(Data.size()));
//texture2D Image(glm::min(MipMapCount, Levels));//SurfaceDesc.mipMapLevels);
std::size_t MipMapCount = (HeaderDesc.flags & loader_dds9::detail::GLI_DDSD_MIPMAPCOUNT) ? HeaderDesc.mipMapLevels : 1;
//if(Loader.Format == DXT1 || Loader.Format == DXT3 || Loader.Format == DXT5)
// MipMapCount -= 2;
texture2D Image(MipMapCount);
for(std::size_t Level = 0; Level < Image.levels() && (Width || Height); ++Level)
{
Width = glm::max(std::size_t(Width), std::size_t(1));
Height = glm::max(std::size_t(Height), std::size_t(1));
std::size_t MipmapSize = 0;
if((Loader.BlockSize << 3) > Loader.BPP)
MipmapSize = ((Width + 3) >> 2) * ((Height + 3) >> 2) * Loader.BlockSize;
else
MipmapSize = Width * Height * Loader.BlockSize;
std::vector<glm::byte> MipmapData(MipmapSize, 0);
memcpy(&MipmapData[0], &Data[0] + Offset, MipmapSize);
image2D::dimensions_type Dimensions(Width, Height);
Image[Level] = image2D(Dimensions, Format, MipmapData);
Offset += MipmapSize;
Width >>= 1;
Height >>= 1;
}
return Image;
}
inline void saveDDS10
(
gli::texture2D const & Image,
std::string const & Filename
)
{
std::ofstream FileOut(Filename.c_str(), std::ios::out | std::ios::binary);
if (!FileOut)
return;
char const * Magic = "DDS ";
FileOut.write((char*)Magic, sizeof(char) * 4);
glm::uint32 Caps = loader_dds9::detail::GLI_DDSD_CAPS | loader_dds9::detail::GLI_DDSD_HEIGHT | loader_dds9::detail::GLI_DDSD_WIDTH | loader_dds9::detail::GLI_DDSD_PIXELFORMAT;
loader_dds9::detail::ddsHeader HeaderDesc;
HeaderDesc.size = sizeof(loader_dds9::detail::ddsHeader);
HeaderDesc.flags = Caps | (loader_dds9::detail::isCompressed(Image) ? loader_dds9::detail::GLI_DDSD_LINEARSIZE : loader_dds9::detail::GLI_DDSD_PITCH) | (Image.levels() > 1 ? loader_dds9::detail::GLI_DDSD_MIPMAPCOUNT : 0); //659463;
HeaderDesc.width = Image[0].dimensions().x;
HeaderDesc.height = Image[0].dimensions().y;
HeaderDesc.pitch = loader_dds9::detail::isCompressed(Image) ? size(Image, LINEAR_SIZE) : 32;
HeaderDesc.depth = 0;
HeaderDesc.mipMapLevels = glm::uint32(Image.levels());
HeaderDesc.format.size = sizeof(loader_dds9::detail::ddsPixelFormat);
HeaderDesc.format.flags = loader_dds9::detail::GLI_DDPF_FOURCC;
HeaderDesc.format.fourCC = loader_dds9::detail::GLI_FOURCC_DX10;
HeaderDesc.format.bpp = size(Image, BIT_PER_PIXEL);
HeaderDesc.format.redMask = 0;
HeaderDesc.format.greenMask = 0;
HeaderDesc.format.blueMask = 0;
HeaderDesc.format.alphaMask = 0;
HeaderDesc.surfaceFlags = loader_dds9::detail::GLI_DDSCAPS_TEXTURE | (Image.levels() > 1 ? loader_dds9::detail::GLI_DDSCAPS_MIPMAP : 0);
HeaderDesc.cubemapFlags = 0;
FileOut.write((char*)&HeaderDesc, sizeof(HeaderDesc));
detail::ddsHeader10 HeaderDesc10;
HeaderDesc10.arraySize = 1;
HeaderDesc10.resourceDimension = detail::D3D10_RESOURCE_DIMENSION_TEXTURE2D;
HeaderDesc10.miscFlag = 0;//Image.levels() > 0 ? detail::D3D10_RESOURCE_MISC_GENERATE_MIPS : 0;
HeaderDesc10.dxgiFormat = detail::format_gli2dds_cast(Image.format());
HeaderDesc10.reserved = 0;
FileOut.write((char*)&HeaderDesc10, sizeof(HeaderDesc10));
for(gli::texture2D::level_type Level = 0; Level < Image.levels(); ++Level)
{
gli::texture2D::size_type ImageSize = size(Image[Level], gli::LINEAR_SIZE);
FileOut.write((char*)(Image[Level].data()), ImageSize);
}
if(FileOut.fail() || FileOut.bad())
return;
FileOut.close ();
}
}//namespace loader_dds10
}//namespace gtx
}//namespace gli
+39
View File
@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_dds9.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_LOADER_DDS9_INCLUDED
#define GLI_GTX_LOADER_DDS9_INCLUDED
#include "../gli.hpp"
#include <fstream>
namespace gli{
namespace gtx{
namespace loader_dds9
{
texture2D loadDDS9(
std::string const & Filename);
void saveDDS9(
texture2D const & Texture,
std::string const & Filename);
void saveTextureCubeDDS9(
textureCube const & Texture,
std::string const & Filename);
}//namespace loader_dds9
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::loader_dds9;}
#include "loader_dds9.inl"
#endif//GLI_GTX_LOADER_DDS9_INCLUDED
+790
View File
@@ -0,0 +1,790 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_dds9.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace loader_dds9{
namespace detail
{
// DDS Documentation
/*
http://msdn.microsoft.com/en-us/library/bb943991(VS.85).aspx#File_Layout1
http://msdn.microsoft.com/en-us/library/bb943992.aspx
*/
#define GLI_MAKEFOURCC(ch0, ch1, ch2, ch3) \
(glm::uint32)( \
(((glm::uint32)(glm::uint8)(ch3) << 24) & 0xFF000000) | \
(((glm::uint32)(glm::uint8)(ch2) << 16) & 0x00FF0000) | \
(((glm::uint32)(glm::uint8)(ch1) << 8) & 0x0000FF00) | \
((glm::uint32)(glm::uint8)(ch0) & 0x000000FF) )
//enum dds_format
//{
// GLI_D3DFMT_R8G8B8 = 20,
// GLI_D3DFMT_A8R8G8B8 = 21,
// GLI_D3DFMT_X8R8G8B8 = 22,
// GLI_D3DFMT_A8 = 28,
// GLI_D3DFMT_A2B10G10R10 = 31,
// GLI_D3DFMT_A8B8G8R8 = 32,
// GLI_D3DFMT_X8B8G8R8 = 33,
// GLI_D3DFMT_G16R16 = 34,
// GLI_D3DFMT_A2R10G10B10 = 35,
// GLI_D3DFMT_A16B16G16R16 = 36,
// GLI_D3DFMT_L8 = 50,
// GLI_D3DFMT_A8L8 = 51,
// GLI_D3DFMT_DXT1 = GLI_MAKEFOURCC('D', 'X', 'T', '1'),
// GLI_D3DFMT_DXT2 = GLI_MAKEFOURCC('D', 'X', 'T', '2'),
// GLI_D3DFMT_DXT3 = GLI_MAKEFOURCC('D', 'X', 'T', '3'),
// GLI_D3DFMT_DXT4 = GLI_MAKEFOURCC('D', 'X', 'T', '4'),
// GLI_D3DFMT_DXT5 = GLI_MAKEFOURCC('D', 'X', 'T', '5'),
// GLI_D3DFMT_DX10 = GLI_MAKEFOURCC('D', 'X', '1', '0'),
// GLI_D3DFMT_D32 = 71,
// GLI_D3DFMT_D24S8 = 75,
// GLI_D3DFMT_D24X8 = 77,
// GLI_D3DFMT_D16 = 80,
// GLI_D3DFMT_L16 = 81,
// GLI_D3DFMT_D32F_LOCKABLE = 82,
// GLI_D3DFMT_D24FS8 = 83,
// GLI_D3DFMT_R16F = 111,
// GLI_D3DFMT_G16R16F = 112,
// GLI_D3DFMT_A16B16G16R16F = 113,
// GLI_D3DFMT_R32F = 114,
// GLI_D3DFMT_G32R32F = 115,
// GLI_D3DFMT_A32B32G32R32F = 116
//};
enum ddsCubemapflag
{
GLI_DDSCAPS2_CUBEMAP = 0x00000200,
GLI_DDSCAPS2_CUBEMAP_POSITIVEX = 0x00000400,
GLI_DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800,
GLI_DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000,
GLI_DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000,
GLI_DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000,
GLI_DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000,
GLI_DDSCAPS2_VOLUME = 0x00200000
};
enum ddsSurfaceflag
{
GLI_DDSCAPS_COMPLEX = 0x00000008,
GLI_DDSCAPS_MIPMAP = 0x00400000,
GLI_DDSCAPS_TEXTURE = 0x00001000
};
struct ddsPixelFormat
{
glm::uint32 size; // 32
glm::uint32 flags;
glm::uint32 fourCC;
glm::uint32 bpp;
glm::uint32 redMask;
glm::uint32 greenMask;
glm::uint32 blueMask;
glm::uint32 alphaMask;
};
struct ddsHeader
{
glm::uint32 size;
glm::uint32 flags;
glm::uint32 height;
glm::uint32 width;
glm::uint32 pitch;
glm::uint32 depth;
glm::uint32 mipMapLevels;
glm::uint32 reserved1[11];
ddsPixelFormat format;
glm::uint32 surfaceFlags;
glm::uint32 cubemapFlags;
glm::uint32 reserved2[3];
};
glm::uint32 const GLI_D3DFMT_R8G8B8 = 20;
glm::uint32 const GLI_D3DFMT_A8R8G8B8 = 21;
glm::uint32 const GLI_D3DFMT_X8R8G8B8 = 22;
glm::uint32 const GLI_D3DFMT_R5G6B5 = 23;
glm::uint32 const GLI_D3DFMT_X1R5G5B5 = 24;
glm::uint32 const GLI_D3DFMT_A1R5G5B5 = 25;
glm::uint32 const GLI_D3DFMT_A4R4G4B4 = 26;
glm::uint32 const GLI_D3DFMT_X4R4G4B4 = 30;
glm::uint32 const GLI_D3DFMT_A2B10G10R10 = 31;
glm::uint32 const GLI_D3DFMT_A8B8G8R8 = 32;
glm::uint32 const GLI_D3DFMT_X8B8G8R8 = 33;
glm::uint32 const GLI_D3DFMT_G16R16 = 34;
glm::uint32 const GLI_D3DFMT_A2R10G10B10 = 35;
glm::uint32 const GLI_D3DFMT_A16B16G16R16 = 36;
glm::uint32 const GLI_FOURCC_DXT1 = GLI_MAKEFOURCC('D', 'X', 'T', '1');
glm::uint32 const GLI_FOURCC_DXT2 = GLI_MAKEFOURCC('D', 'X', 'T', '2');
glm::uint32 const GLI_FOURCC_DXT3 = GLI_MAKEFOURCC('D', 'X', 'T', '3');
glm::uint32 const GLI_FOURCC_DXT4 = GLI_MAKEFOURCC('D', 'X', 'T', '4');
glm::uint32 const GLI_FOURCC_DXT5 = GLI_MAKEFOURCC('D', 'X', 'T', '5');
glm::uint32 const GLI_FOURCC_ATI1 = GLI_MAKEFOURCC('A', 'T', 'I', '1'); // ATI1
glm::uint32 const GLI_FOURCC_ATI2 = GLI_MAKEFOURCC('A', 'T', 'I', '2'); // ATI2 (AKA 3Dc)
glm::uint32 const GLI_FOURCC_DX10 = GLI_MAKEFOURCC('D', 'X', '1', '0');
glm::uint32 const GLI_FOURCC_BC4U = GLI_MAKEFOURCC('B', 'C', '4', 'U');
glm::uint32 const GLI_FOURCC_BC4S = GLI_MAKEFOURCC('B', 'C', '4', 'S');
glm::uint32 const GLI_FOURCC_BC5U = GLI_MAKEFOURCC('B', 'C', '5', 'U');
glm::uint32 const GLI_FOURCC_BC5S = GLI_MAKEFOURCC('B', 'C', '5', 'S');
glm::uint32 const GLI_FOURCC_BC6H = GLI_MAKEFOURCC('B', 'C', '6', 'H');
glm::uint32 const GLI_FOURCC_BC7 = GLI_MAKEFOURCC('B', 'C', '7', 'U');
glm::uint32 const GLI_FOURCC_R16F = 0x0000006f; // 16-bit float Red
glm::uint32 const GLI_FOURCC_G16R16F = 0x00000070; // 16-bit float Red/Green
glm::uint32 const GLI_FOURCC_A16B16G16R16F = 0x00000071; // 16-bit float RGBA
glm::uint32 const GLI_FOURCC_R32F = 0x00000072; // 32-bit float Red
glm::uint32 const GLI_FOURCC_G32R32F = 0x00000073; // 32-bit float Red/Green
glm::uint32 const GLI_FOURCC_A32B32G32R32F = 0x00000074; // 32-bit float RGBA
glm::uint32 const GLI_DDPF_ALPHAPIXELS = 0x00000001; // The surface has alpha channel information in the pixel format.
glm::uint32 const GLI_DDPF_ALPHA = 0x00000002; // The pixel format contains alpha only information
glm::uint32 const GLI_DDPF_FOURCC = 0x00000004; // The FourCC code is valid.
glm::uint32 const GLI_DDPF_RGB = 0x00000040; // The RGB data in the pixel format structure is valid.
//glm::uint32 const GLI_DDPF_COMPRESSED = 0x00000080; // The surface will accept pixel data in the format specified and compress it during the write.
//glm::uint32 const GLI_DDPF_RGBTOYUV = 0x00000100; // The surface will accept RGB data and translate it during the write to YUV data.
glm::uint32 const GLI_DDPF_YUV = 0x00000200; // Pixel format is YUV - YUV data in pixel format struct is valid.
//glm::uint32 const GLI_DDPF_ZBUFFER = 0x00000400; // Pixel format is a z buffer only surface
//glm::uint32 const GLI_DDPF_ZPIXELS = 0x00002000; // The surface contains Z information in the pixels
//glm::uint32 const GLI_DDPF_STENCILBUFFER = 0x00004000; // The surface contains stencil information along with Z
//glm::uint32 const GLI_DDPF_ALPHAPREMULT = 0x00008000; // Premultiplied alpha format -- the color components have been premultiplied by the alpha component.
glm::uint32 const GLI_DDPF_LUMINANCE = 0x00020000; // Luminance data in the pixel format is valid.
//glm::uint32 const GLI_DDPF_BUMPLUMINANCE = 0x00040000; // Use this flag for luminance-only or luminance+alpha surfaces, the bit depth is then ddpf.dwLuminanceBitCount.
//glm::uint32 const GLI_DDPF_BUMPDUDV = 0x00080000; // Bump map dUdV data in the pixel format is valid.
glm::uint32 const GLI_DDSD_CAPS = 0x00000001;
glm::uint32 const GLI_DDSD_HEIGHT = 0x00000002;
glm::uint32 const GLI_DDSD_WIDTH = 0x00000004;
glm::uint32 const GLI_DDSD_PITCH = 0x00000008;
glm::uint32 const GLI_DDSD_PIXELFORMAT = 0x00001000;
glm::uint32 const GLI_DDSD_MIPMAPCOUNT = 0x00020000;
glm::uint32 const GLI_DDSD_LINEARSIZE = 0x00080000;
glm::uint32 const GLI_DDSD_DEPTH = 0x00800000;
struct DDLoader
{
glm::uint32 BlockSize;
glm::uint32 BPP;
gli::format Format;
};
enum format_type
{
FORMAT_TYPE_NULL,
FORMAT_RGBA,
FORMAT_FOURCC
};
inline glm::uint32 getFormatFourCC(gli::texture2D const & Image)
{
switch(Image.format())
{
default:
return 0;
case DXT1:
return GLI_FOURCC_DXT1;
case DXT3:
return GLI_FOURCC_DXT3;
case DXT5:
return GLI_FOURCC_DXT5;
case ATI1N_UNORM:
case ATI1N_SNORM:
case ATI2N_UNORM:
case ATI2N_SNORM:
case BP_UF16:
case BP_SF16:
case BP:
return GLI_FOURCC_DX10;
case R16F:
return GLI_FOURCC_R16F;
case RG16F:
return GLI_FOURCC_G16R16F;
case RGBA16F:
return GLI_FOURCC_A16B16G16R16F;
case R32F:
return GLI_FOURCC_R32F;
case RG32F:
return GLI_FOURCC_G32R32F;
case RGBA32F:
return GLI_FOURCC_A32B32G32R32F;
}
}
inline glm::uint32 getFormatBlockSize(gli::texture2D const & Image)
{
switch(Image.format())
{
default:
return 0;
case DXT1:
return 8;
case DXT3:
return 16;
case DXT5:
return 16;
case ATI1N_UNORM:
case ATI1N_SNORM:
return 16;
case ATI2N_UNORM:
case ATI2N_SNORM:
return 32;
case BP_UF16:
case BP_SF16:
return 32;
case BP:
return 32;
case R16F:
return 2;
case RG16F:
return 4;
case RGBA16F:
return 8;
case R32F:
return 4;
case RG32F:
return 8;
case RGBA32F:
return 16;
}
}
inline glm::uint32 getFormatFlags(gli::texture2D const & Image)
{
glm::uint32 Result = 0;
switch(Image.format())
{
default:
break;
case R8U:
case RG8U:
case RGB8U:
case RGBA8U:
case R16U:
case RG16U:
case RGB16U:
case RGBA16U:
case R32U:
case RG32U:
case RGB32U:
case RGBA32U:
case R8I:
case RG8I:
case RGB8I:
case RGBA8I:
case R16I:
case RG16I:
case RGB16I:
case RGBA16I:
case R32I:
case RG32I:
case RGB32I:
case RGBA32I:
Result |= GLI_DDPF_RGB;
break;
case R16F:
case RG16F:
case RGB16F:
case RGBA16F:
case R32F:
case RG32F:
case RGB32F:
case RGBA32F:
case RGBE8:
case RGB9E5:
case RG11B10F:
case R5G6B5:
case RGBA4:
case RGB10A2:
case D16:
case D24X8:
case D24S8:
case D32F:
case D32FS8X24:
case DXT1:
case DXT3:
case DXT5:
case ATI1N_UNORM:
case ATI1N_SNORM:
case ATI2N_UNORM:
case ATI2N_SNORM:
case BP_UF16:
case BP_SF16:
case BP:
Result |= GLI_DDPF_FOURCC;
break;
};
return Result;
}
inline glm::uint32 getFormatBPP(gli::texture2D const & Image)
{
switch(Image.format())
{
default:
return 0;
case R8U:
case R8I:
return 8;
case RG8U:
case RG8I:
return 16;
case RGB8U:
case RGB8I:
return 24;
case RGBA8U:
case RGBA8I:
return 32;
case DXT1:
return 4;
case DXT3:
return 8;
case DXT5:
return 8;
case ATI1N_UNORM:
case ATI1N_SNORM:
return 4;
case ATI2N_UNORM:
case ATI2N_SNORM:
return 8;
case BP_UF16:
case BP_SF16:
return 8;
case BP:
return 8;
}
}
inline bool isCompressed(gli::texture2D const & Image)
{
switch(Image.format())
{
default:
return false;
case DXT1:
case DXT3:
case DXT5:
case ATI1N_UNORM:
case ATI1N_SNORM:
case ATI2N_UNORM:
case ATI2N_SNORM:
case BP_UF16:
case BP_SF16:
case BP:
return true;
}
return false;
}
}//namespace detail
inline texture2D loadDDS9
(
std::string const & Filename
)
{
std::ifstream FileIn(Filename.c_str(), std::ios::in | std::ios::binary);
if(FileIn.fail())
return texture2D();
detail::ddsHeader SurfaceDesc;
char Magic[4];
//* Read magic number and check if valid .dds file
FileIn.read((char*)&Magic, sizeof(Magic));
assert(strncmp(Magic, "DDS ", 4) == 0);
// Get the surface descriptor
FileIn.read((char*)&SurfaceDesc, sizeof(SurfaceDesc));
std::size_t Width = SurfaceDesc.width;
std::size_t Height = SurfaceDesc.height;
//std::size_t Levels = glm::max(glm::highestBit(Width), glm::highestBit(Height));
detail::DDLoader Loader;
if(SurfaceDesc.format.flags & detail::GLI_DDPF_FOURCC)
{
switch(SurfaceDesc.format.fourCC)
{
case detail::GLI_FOURCC_DX10:
assert(0);
break;
case detail::GLI_FOURCC_DXT1:
Loader.BlockSize = 8;
Loader.Format = DXT1;
break;
case detail::GLI_FOURCC_DXT3:
Loader.BlockSize = 16;
Loader.Format = DXT3;
break;
case detail::GLI_FOURCC_DXT5:
Loader.BlockSize = 16;
Loader.Format = DXT5;
break;
case detail::GLI_FOURCC_R16F:
Loader.BlockSize = 2;
Loader.Format = R16F;
break;
case detail::GLI_FOURCC_G16R16F:
Loader.BlockSize = 4;
Loader.Format = RG16F;
break;
case detail::GLI_FOURCC_A16B16G16R16F:
Loader.BlockSize = 8;
Loader.Format = RGBA16F;
break;
case detail::GLI_FOURCC_R32F:
Loader.BlockSize = 4;
Loader.Format = R32F;
break;
case detail::GLI_FOURCC_G32R32F:
Loader.BlockSize = 8;
Loader.Format = RG32F;
break;
case detail::GLI_FOURCC_A32B32G32R32F:
Loader.BlockSize = 16;
Loader.Format = RGBA32F;
break;
default:
assert(0);
return texture2D();
}
}
else if(SurfaceDesc.format.flags & detail::GLI_DDPF_RGB)
{
switch(SurfaceDesc.format.bpp)
{
case 8:
Loader.BlockSize = 2;
Loader.Format = R8U;
break;
case 16:
Loader.BlockSize = 2;
Loader.Format = RG8U;
break;
case 24:
Loader.BlockSize = 3;
Loader.Format = RGB8U;
break;
case 32:
Loader.BlockSize = 4;
Loader.Format = RGBA8U;
break;
}
}
else
{
}
gli::format Format = Loader.Format;
std::streamoff Curr = FileIn.tellg();
FileIn.seekg(0, std::ios_base::end);
std::streamoff End = FileIn.tellg();
FileIn.seekg(Curr, std::ios_base::beg);
std::vector<glm::byte> Data(std::size_t(End - Curr), 0);
std::size_t Offset = 0;
FileIn.read((char*)&Data[0], std::streamsize(Data.size()));
//image Image(glm::min(MipMapCount, Levels));//SurfaceDesc.mipMapLevels);
std::size_t MipMapCount = (SurfaceDesc.flags & detail::GLI_DDSD_MIPMAPCOUNT) ? SurfaceDesc.mipMapLevels : 1;
//if(Loader.Format == DXT1 || Loader.Format == DXT3 || Loader.Format == DXT5)
// MipMapCount -= 2;
texture2D Image(MipMapCount);
for(std::size_t Level = 0; Level < Image.levels() && (Width || Height); ++Level)
{
Width = glm::max(std::size_t(Width), std::size_t(1));
Height = glm::max(std::size_t(Height), std::size_t(1));
std::size_t MipmapSize = 0;
if(Loader.Format == DXT1 || Loader.Format == DXT3 || Loader.Format == DXT5)
MipmapSize = ((Width + 3) >> 2) * ((Height + 3) >> 2) * Loader.BlockSize;
else
MipmapSize = Width * Height * Loader.BlockSize;
std::vector<glm::byte> MipmapData(MipmapSize, 0);
memcpy(&MipmapData[0], &Data[0] + Offset, MipmapSize);
image2D::dimensions_type Dimensions(Width, Height);
Image[Level] = image2D(Dimensions, Format, MipmapData);
Offset += MipmapSize;
Width >>= 1;
Height >>= 1;
}
return Image;
}
inline textureCube loadTextureCubeDDS9
(
std::string const & Filename
)
{
std::ifstream FileIn(Filename.c_str(), std::ios::in | std::ios::binary);
if(FileIn.fail())
return textureCube();
detail::ddsHeader SurfaceDesc;
char Magic[4];
//* Read magic number and check if valid .dds file
FileIn.read((char*)&Magic, sizeof(Magic));
assert(strncmp(Magic, "DDS ", 4) == 0);
// Get the surface descriptor
FileIn.read((char*)&SurfaceDesc, sizeof(SurfaceDesc));
std::size_t Width = SurfaceDesc.width;
std::size_t Height = SurfaceDesc.height;
//std::size_t Levels = glm::max(glm::highestBit(Width), glm::highestBit(Height));
detail::DDLoader Loader;
if(SurfaceDesc.format.flags & detail::GLI_DDPF_FOURCC)
{
switch(SurfaceDesc.format.fourCC)
{
case detail::GLI_FOURCC_DX10:
assert(0);
break;
case detail::GLI_FOURCC_DXT1:
Loader.BlockSize = 8;
Loader.Format = DXT1;
break;
case detail::GLI_FOURCC_DXT3:
Loader.BlockSize = 16;
Loader.Format = DXT3;
break;
case detail::GLI_FOURCC_DXT5:
Loader.BlockSize = 16;
Loader.Format = DXT5;
break;
case detail::GLI_FOURCC_R16F:
Loader.BlockSize = 2;
Loader.Format = R16F;
break;
case detail::GLI_FOURCC_G16R16F:
Loader.BlockSize = 4;
Loader.Format = RG16F;
break;
case detail::GLI_FOURCC_A16B16G16R16F:
Loader.BlockSize = 8;
Loader.Format = RGBA16F;
break;
case detail::GLI_FOURCC_R32F:
Loader.BlockSize = 4;
Loader.Format = R32F;
break;
case detail::GLI_FOURCC_G32R32F:
Loader.BlockSize = 8;
Loader.Format = RG32F;
break;
case detail::GLI_FOURCC_A32B32G32R32F:
Loader.BlockSize = 16;
Loader.Format = RGBA32F;
break;
default:
assert(0);
return textureCube();
}
}
else if(SurfaceDesc.format.flags & detail::GLI_DDPF_RGB)
{
switch(SurfaceDesc.format.bpp)
{
case 8:
Loader.BlockSize = 2;
Loader.Format = R8U;
break;
case 16:
Loader.BlockSize = 2;
Loader.Format = RG8U;
break;
case 24:
Loader.BlockSize = 3;
Loader.Format = RGB8U;
break;
case 32:
Loader.BlockSize = 4;
Loader.Format = RGBA8U;
break;
}
}
else
{
}
gli::format Format = Loader.Format;
std::streamoff Curr = FileIn.tellg();
FileIn.seekg(0, std::ios_base::end);
std::streamoff End = FileIn.tellg();
FileIn.seekg(Curr, std::ios_base::beg);
std::vector<glm::byte> Data(std::size_t(End - Curr), 0);
std::size_t Offset = 0;
FileIn.read((char*)&Data[0], std::streamsize(Data.size()));
//image Image(glm::min(MipMapCount, Levels));//SurfaceDesc.mipMapLevels);
std::size_t MipMapCount = (SurfaceDesc.flags & detail::GLI_DDSD_MIPMAPCOUNT) ? SurfaceDesc.mipMapLevels : 1;
//if(Loader.Format == DXT1 || Loader.Format == DXT3 || Loader.Format == DXT5)
// MipMapCount -= 2;
textureCube Texture(MipMapCount);
for(textureCube::size_type Face = 0; Face < FACE_MAX; ++Face)
{
Width = SurfaceDesc.width;
Height = SurfaceDesc.height;
for(textureCube::size_type Level = 0; Level < Texture.levels() && (Width || Height); ++Level)
{
Width = glm::max(std::size_t(Width), std::size_t(1));
Height = glm::max(std::size_t(Height), std::size_t(1));
std::size_t MipmapSize = 0;
if(Loader.Format == DXT1 || Loader.Format == DXT3 || Loader.Format == DXT5)
MipmapSize = ((Width + 3) >> 2) * ((Height + 3) >> 2) * Loader.BlockSize;
else
MipmapSize = Width * Height * Loader.BlockSize;
std::vector<glm::byte> MipmapData(MipmapSize, 0);
memcpy(&MipmapData[0], &Data[0] + Offset, MipmapSize);
textureCube::dimensions_type Dimensions(Width, Height);
Texture[textureCube::face_type(Face)][Level] = image2D(Dimensions, Format, MipmapData);
Offset += MipmapSize;
Width >>= 1;
Height >>= 1;
}
}
return Texture;
}
inline void saveDDS9
(
texture2D const & Texture,
std::string const & Filename
)
{
std::ofstream FileOut(Filename.c_str(), std::ios::out | std::ios::binary);
if (!FileOut)
return;
char const * Magic = "DDS ";
FileOut.write((char*)Magic, sizeof(char) * 4);
glm::uint32 Caps = detail::GLI_DDSD_CAPS | detail::GLI_DDSD_HEIGHT | detail::GLI_DDSD_WIDTH | detail::GLI_DDSD_PIXELFORMAT;
detail::ddsHeader SurfaceDesc;
SurfaceDesc.size = sizeof(detail::ddsHeader);
SurfaceDesc.flags = Caps | (detail::isCompressed(Texture) ? detail::GLI_DDSD_LINEARSIZE : detail::GLI_DDSD_PITCH) | (Texture.levels() > 1 ? detail::GLI_DDSD_MIPMAPCOUNT : 0); //659463;
SurfaceDesc.width = Texture[0].dimensions().x;
SurfaceDesc.height = Texture[0].dimensions().y;
SurfaceDesc.pitch = loader_dds9::detail::isCompressed(Texture) ? size(Texture, LINEAR_SIZE) : 32;
SurfaceDesc.depth = 0;
SurfaceDesc.mipMapLevels = glm::uint32(Texture.levels());
SurfaceDesc.format.size = sizeof(detail::ddsPixelFormat);
SurfaceDesc.format.flags = detail::getFormatFlags(Texture);
SurfaceDesc.format.fourCC = detail::getFormatFourCC(Texture);
SurfaceDesc.format.bpp = detail::getFormatBPP(Texture);
SurfaceDesc.format.redMask = 0;
SurfaceDesc.format.greenMask = 0;
SurfaceDesc.format.blueMask = 0;
SurfaceDesc.format.alphaMask = 0;
SurfaceDesc.surfaceFlags = detail::GLI_DDSCAPS_TEXTURE | (Texture.levels() > 1 ? detail::GLI_DDSCAPS_MIPMAP : 0);
SurfaceDesc.cubemapFlags = 0;
FileOut.write((char*)&SurfaceDesc, sizeof(SurfaceDesc));
for(texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
{
texture2D::size_type ImageSize = size(Texture[Level], gli::LINEAR_SIZE);
FileOut.write((char*)(Texture[Level].data()), ImageSize);
}
if(FileOut.fail() || FileOut.bad())
return;
FileOut.close ();
}
inline void saveTextureCubeDDS9
(
textureCube const & Texture,
std::string const & Filename
)
{
std::ofstream FileOut(Filename.c_str(), std::ios::out | std::ios::binary);
if (!FileOut || Texture.empty())
return;
char const * Magic = "DDS ";
FileOut.write((char*)Magic, sizeof(char) * 4);
glm::uint32 Caps = detail::GLI_DDSD_CAPS | detail::GLI_DDSD_HEIGHT | detail::GLI_DDSD_WIDTH | detail::GLI_DDSD_PIXELFORMAT | detail::GLI_DDSCAPS_COMPLEX;
detail::ddsHeader SurfaceDesc;
SurfaceDesc.size = sizeof(detail::ddsHeader);
SurfaceDesc.flags = Caps | (detail::isCompressed(Texture[POSITIVE_X]) ? detail::GLI_DDSD_LINEARSIZE : detail::GLI_DDSD_PITCH) | (Texture.levels() > 1 ? detail::GLI_DDSD_MIPMAPCOUNT : 0); //659463;
SurfaceDesc.width = Texture[POSITIVE_X][0].dimensions().x;
SurfaceDesc.height = Texture[POSITIVE_X][0].dimensions().y;
SurfaceDesc.pitch = loader_dds9::detail::isCompressed(Texture[POSITIVE_X]) ? size(Texture[POSITIVE_X], LINEAR_SIZE) : 32;
SurfaceDesc.depth = 0;
SurfaceDesc.mipMapLevels = glm::uint32(Texture.levels());
SurfaceDesc.format.size = sizeof(detail::ddsPixelFormat);
SurfaceDesc.format.flags = detail::getFormatFlags(Texture[POSITIVE_X]);
SurfaceDesc.format.fourCC = detail::getFormatFourCC(Texture[POSITIVE_X]);
SurfaceDesc.format.bpp = detail::getFormatBPP(Texture[POSITIVE_X]);
SurfaceDesc.format.redMask = 0;
SurfaceDesc.format.greenMask = 0;
SurfaceDesc.format.blueMask = 0;
SurfaceDesc.format.alphaMask = 0;
SurfaceDesc.surfaceFlags = detail::GLI_DDSCAPS_TEXTURE | (Texture.levels() > 1 ? detail::GLI_DDSCAPS_MIPMAP : 0);
SurfaceDesc.cubemapFlags =
detail::GLI_DDSCAPS2_CUBEMAP | detail::GLI_DDSCAPS2_CUBEMAP_POSITIVEX | detail::GLI_DDSCAPS2_CUBEMAP_NEGATIVEX | detail::GLI_DDSCAPS2_CUBEMAP_POSITIVEY | detail::GLI_DDSCAPS2_CUBEMAP_NEGATIVEY | detail::GLI_DDSCAPS2_CUBEMAP_POSITIVEZ | detail::GLI_DDSCAPS2_CUBEMAP_NEGATIVEZ;
FileOut.write((char*)&SurfaceDesc, sizeof(SurfaceDesc));
for(textureCube::size_type Face = 0; Face < FACE_MAX; ++Face)
for(texture2D::level_type Level = 0; Level < Texture.levels(); ++Level)
{
texture2D::size_type ImageSize = size(Texture[textureCube::face_type(Face)][Level], gli::LINEAR_SIZE);
FileOut.write((char*)(Texture[textureCube::face_type(Face)][Level].data()), ImageSize);
}
if(FileOut.fail() || FileOut.bad())
return;
FileOut.close ();
}
}//namespace loader_dds9
}//namespace gtx
}//namespace gli
+36
View File
@@ -0,0 +1,36 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_tga.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_LOADER_TGA_INCLUDED
#define GLI_GTX_LOADER_TGA_INCLUDED
#include "../gli.hpp"
#include <string>
#include <fstream>
namespace gli{
namespace gtx{
namespace loader_tga
{
texture2D loadTGA(
std::string const & Filename);
void saveTGA(
texture2D const & Image,
std::string const & Filename);
}//namespace loader_tga
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::loader_tga;}
#include "loader_tga.inl"
#endif//GLI_GTX_LOADER_TGA_INCLUDED
+159
View File
@@ -0,0 +1,159 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-08
// Updated : 2010-09-27
// Licence : This source is under MIT License
// File : gli/gtx/loader_tga.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace gli{
namespace gtx{
namespace loader_tga
{
inline texture2D loadTGA
(
std::string const & Filename
)
{
std::ifstream FileIn(Filename.c_str(), std::ios::in | std::ios::binary);
if(!FileIn)
return texture2D();
unsigned char IdentificationFieldSize;
unsigned char ColorMapType;
unsigned char ImageType;
unsigned short ColorMapOrigin;
unsigned short ColorMapLength;
unsigned char ColorMapEntrySize;
unsigned short OriginX;
unsigned short OriginY;
unsigned short Width;
unsigned short Height;
unsigned char TexelSize;
unsigned char Descriptor;
FileIn.read((char*)&IdentificationFieldSize, sizeof(IdentificationFieldSize));
FileIn.read((char*)&ColorMapType, sizeof(ColorMapType));
FileIn.read((char*)&ImageType, sizeof(ImageType));
FileIn.read((char*)&ColorMapOrigin, sizeof(ColorMapOrigin));
FileIn.read((char*)&ColorMapLength, sizeof(ColorMapLength));
FileIn.read((char*)&ColorMapEntrySize, sizeof(ColorMapEntrySize));
FileIn.read((char*)&OriginX, sizeof(OriginX));
FileIn.read((char*)&OriginY, sizeof(OriginY));
FileIn.read((char*)&Width, sizeof(Width));
FileIn.read((char*)&Height, sizeof(Height));
FileIn.read((char*)&TexelSize, sizeof(TexelSize));
FileIn.read((char*)&Descriptor, sizeof(Descriptor));
gli::format Format = gli::FORMAT_NULL;
if(TexelSize == 24)
Format = gli::RGB8U;
else if(TexelSize == 32)
Format = gli::RGBA8U;
else
assert(0);
image2D Mipmap(texture2D::dimensions_type(Width, Height), Format);
if (FileIn.fail() || FileIn.bad())
{
assert(0);
return texture2D();
}
switch(ImageType)
{
default:
assert(0);
return texture2D();
case 2:
FileIn.seekg(18 + ColorMapLength, std::ios::beg);
char* IdentificationField = new char[IdentificationFieldSize + 1];
FileIn.read(IdentificationField, IdentificationFieldSize);
IdentificationField[IdentificationFieldSize] = '\0';
delete[] IdentificationField;
std::size_t DataSize = Width * Height * (TexelSize >> 3);
FileIn.read((char*)Mipmap.data(), std::streamsize(DataSize));
if(FileIn.fail() || FileIn.bad())
return texture2D();
break;
}
FileIn.close();
texture2D Image(1);
Image[0] = Mipmap;
// TGA images are saved in BGR or BGRA format.
if(TexelSize == 24)
Image.swizzle<glm::u8vec3>(gli::B, gli::G, gli::R, gli::A);
if(TexelSize == 32)
Image.swizzle<glm::u8vec4>(gli::B, gli::G, gli::R, gli::A);
return Image;
}
inline void saveTGA
(
gli::texture2D const & ImageIn,
std::string const & Filename
)
{
std::ofstream FileOut(Filename.c_str(), std::ios::out | std::ios::binary);
if (!FileOut)
return;
gli::texture2D Image = duplicate(ImageIn);
unsigned char IdentificationFieldSize = 1;
unsigned char ColorMapType = 0;
unsigned char ImageType = 2;
unsigned short ColorMapOrigin = 0;
unsigned short ColorMapLength = 0;
unsigned char ColorMapEntrySize = 0;
unsigned short OriginX = 0;
unsigned short OriginY = 0;
unsigned short Width = Image[0].dimensions().x;
unsigned short Height = Image[0].dimensions().y;
unsigned char TexelSize = (unsigned char)(Image[0].value_size());
unsigned char Descriptor = 0;
if(TexelSize == 24)
Image.swizzle<glm::u8vec3>(gli::B, gli::G, gli::R, gli::A);
if(TexelSize == 32)
Image.swizzle<glm::u8vec4>(gli::B, gli::G, gli::R, gli::A);
FileOut.write((char*)&IdentificationFieldSize, sizeof(IdentificationFieldSize));
FileOut.write((char*)&ColorMapType, sizeof(ColorMapType));
FileOut.write((char*)&ImageType, sizeof(ImageType));
FileOut.write((char*)&ColorMapOrigin, sizeof(ColorMapOrigin));
FileOut.write((char*)&ColorMapLength, sizeof(ColorMapLength));
FileOut.write((char*)&ColorMapEntrySize, sizeof(ColorMapEntrySize));
FileOut.write((char*)&OriginX, sizeof(OriginX));
FileOut.write((char*)&OriginY, sizeof(OriginY));
FileOut.write((char*)&Width, sizeof(Width));
FileOut.write((char*)&Height, sizeof(Height));
FileOut.write((char*)&TexelSize, sizeof(TexelSize));
FileOut.write((char*)&Descriptor, sizeof(Descriptor));
if (FileOut.fail () || FileOut.bad ())
return;
FileOut.seekp(18 + ColorMapLength, std::ios::beg);
char* IdentificationField = new char[IdentificationFieldSize + 1];
FileOut.write(IdentificationField, std::streamsize(IdentificationFieldSize));
delete[] IdentificationField;
FileOut.write((char*)Image[0].data(), std::streamsize(Image[0].capacity()));
if(FileOut.fail() || FileOut.bad())
return;
FileOut.close ();
}
}//namespace loader_tga
}//namespace gtx
}//namespace gli
+27
View File
@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-01-09
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/wavelet.hpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef GLI_GTX_WAVELET_INCLUDED
#define GLI_GTX_WAVELET_INCLUDED
namespace gli{
namespace gtx{
namespace wavelet
{
}//namespace wavelet
}//namespace gtx
}//namespace gli
namespace gli{using namespace gtx::wavelet;}
#include "wavelet.inl"
#endif//GLI_GTX_WAVELET_INCLUDED
+8
View File
@@ -0,0 +1,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-01-09
// Updated : 2010-01-09
// Licence : This source is under MIT License
// File : gli/gtx/wavelet.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<includedir>
<dir name="../glm"/>
</includedir>
</project>
+21
View File
@@ -0,0 +1,21 @@
glmCreateTestGTC(gtc_bitfield)
glmCreateTestGTC(gtc_color_space)
glmCreateTestGTC(gtc_constants)
glmCreateTestGTC(gtc_epsilon)
glmCreateTestGTC(gtc_functions)
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)
+642
View File
@@ -0,0 +1,642 @@
#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)
{
GLM_ALIGN(16) glm::uint32 const Array[4] = {x, 0, y, 0};
__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((__m128i*)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);
GLM_ALIGN(16) glm::uint64 Result[2];
_mm_store_si128((__m128i*)Result, Reg1);
return Result[0];
}
inline glm::uint64 sseUnalignedBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{
glm::uint32 const Array[4] = {x, 0, y, 0};
__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((__m128i*)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);
glm::uint64 Result[2];
_mm_storeu_si128((__m128i*)Result, Reg1);
return Result[0];
}
#endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
int test()
{
{
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)));
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)));
assert(D == E);
assert(D == F);
}
}
return 0;
}
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(x_max * y_max);
std::vector<__m128i> SimdParam;
SimdParam.resize(x_max * y_max);
for(int i = 0; i < SimdParam.size(); ++i)
SimdParam[i] = _mm_set_epi32(i % x_max, 0, i / 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
int main()
{
int Error(0);
Error += ::mask::test();
Error += ::bitfieldInterleave3::test();
Error += ::bitfieldInterleave4::test();
Error += ::bitfieldInterleave::test();
//Error += ::bitRevert::test();
# ifdef NDEBUG
Error += ::mask::perf();
Error += ::bitfieldInterleave::perf();
# endif//NDEBUG
return Error;
}
+50
View File
@@ -0,0 +1,50 @@
#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
int main()
{
int Error(0);
Error += srgb::test();
return Error;
}
+28
View File
@@ -0,0 +1,28 @@
#include <glm/gtc/constants.hpp>
int test_epsilon()
{
int Error(0);
{
float Test = glm::epsilon<float>();
}
{
double Test = glm::epsilon<double>();
}
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;
}
+77
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;
}
+35
View File
@@ -0,0 +1,35 @@
#include <glm/gtc/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(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;
}
+232
View File
@@ -0,0 +1,232 @@
#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::tvec4<unsigned long, glm::defaultp> Tmp(glm::uninitialize);
_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::tvec4<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(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 = glm::iround(f);
int RoundSTD = 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 = glm::uround(f);
int RoundSTD = 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;
}
+381
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;
}
+8
View File
@@ -0,0 +1,8 @@
#include <glm/gtc/matrix_integer.hpp>
int main()
{
int Error = 0;
return Error;
}
+51
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;
}
+54
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;
}
+184
View File
@@ -0,0 +1,184 @@
#include <glm/gtc/noise.hpp>
#include <gli/gli.hpp>
#include <gli/gtx/loader.hpp>
std::size_t const Size = 64;
int test_simplex()
{
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::simplex(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_simplex4d_256.dds");
}
return 0;
}
int test_perlin()
{
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin4d_256.dds");
}
return 0;
}
int test_perlin_pedioric()
{
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec2(x / 64.f, y / 64.f), glm::vec2(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_2d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec3(x / 64.f, y / 64.f, 0.5f), glm::vec3(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_3d_256.dds");
}
{
std::vector<glm::byte> ImageData(Size * Size * 3);
for(std::size_t y = 0; y < Size; ++y)
for(std::size_t x = 0; x < Size; ++x)
{
ImageData[(x + y * Size) * 3 + 0] = glm::byte(glm::perlin(glm::vec4(x / 64.f, y / 64.f, 0.5f, 0.5f), glm::vec4(2.0f)) * 128.f + 127.f);
ImageData[(x + y * Size) * 3 + 1] = ImageData[(x + y * Size) * 3 + 0];
ImageData[(x + y * Size) * 3 + 2] = ImageData[(x + y * Size) * 3 + 0];
}
gli::texture2D Texture(1);
Texture[0] = gli::image2D(glm::uvec2(Size), gli::RGB8U);
memcpy(Texture[0].data(), &ImageData[0], ImageData.size());
gli::saveDDS9(Texture, "texture_perlin_pedioric_4d_256.dds");
}
return 0;
}
int main()
{
int Error = 0;
Error += test_simplex();
Error += test_perlin();
Error += test_perlin_pedioric();
return Error;
}
+685
View File
@@ -0,0 +1,685 @@
#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, ", 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::uint32 p0 = glm::packHalf1x16(Tests[i]);
float v0 = glm::unpackHalf1x16(p0);
glm::uint32 p1 = glm::packHalf1x16(v0);
float v1 = glm::unpackHalf1x16(p1);
Error += (v0 == v1) ? 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;
}
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_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::uint32 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::uint32 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<glm::uint16, 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<glm::int16, 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 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_F2x11_1x10();
Error += test_F3x9_E1x5();
Error += test_Snorm3x10_1x2();
Error += test_Unorm3x10_1x2();
Error += test_I3x10_1x2();
Error += test_U3x10_1x2();
Error += test_Half1x16();
Error += test_Half4x16();
return Error;
}
+327
View File
@@ -0,0 +1,327 @@
#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.0f, glm::vec3(0, 0, 1));
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.0f, glm::vec3(0, 0, 1));
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);
}
{
glm::dquat q(1.0f, 0.0f, 0.0f, 1.0f);
double Roll = glm::roll(q);
double Pitch = glm::pitch(q);
double Yaw = glm::yaw(q);
glm::dvec3 Angles = glm::eulerAngles(q);
}
return Error;
}
int test_quat_slerp()
{
int Error(0);
float const Epsilon = 0.0001f;//glm::epsilon<float>();
float sqrt2 = sqrt(2.0f)/2.0f;
glm::quat id;
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);
# ifndef GLM_FORCE_NO_CTOR_INIT
{
glm::quat temp7;
temp7 *= temp5;
temp7 *= glm::inverse(temp5);
Error += temp7 != glm::quat();
}
# endif
return Error;
}
int test_quat_two_axis_ctr()
{
int Error(0);
glm::quat q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
glm::vec3 v1 = q1 * glm::vec3(1, 0, 0);
Error += glm::all(glm::epsilonEqual(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1;
glm::quat q2 = q1 * q1;
glm::vec3 v2 = q2 * glm::vec3(1, 0, 0);
Error += glm::all(glm::epsilonEqual(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
return Error;
}
int test_quat_type()
{
glm::quat A;
glm::dquat B;
return 0;
}
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_type();
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;
}
+379
View File
@@ -0,0 +1,379 @@
#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.0f;
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.0f;
double Radius = 2.0f;
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.0f;
double ResultDoubleB = 0.0f;
double ResultDoubleC = 0.0f;
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.0f;
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.0f;
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;
}

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