replace math_graphics with glm version 1.0.3

This commit is contained in:
Sven Balzer
2026-04-15 10:50:41 +02:00
parent 07af9deb6a
commit 4ec664c8db
1676 changed files with 289261 additions and 1477 deletions
+20
View File
@@ -0,0 +1,20 @@
glmCreateTestGTC(gtc_bitfield)
glmCreateTestGTC(gtc_color_space)
glmCreateTestGTC(gtc_constants)
glmCreateTestGTC(gtc_epsilon)
glmCreateTestGTC(gtc_integer)
glmCreateTestGTC(gtc_matrix_access)
glmCreateTestGTC(gtc_matrix_integer)
glmCreateTestGTC(gtc_matrix_inverse)
glmCreateTestGTC(gtc_matrix_transform)
glmCreateTestGTC(gtc_noise)
glmCreateTestGTC(gtc_packing)
glmCreateTestGTC(gtc_quaternion)
glmCreateTestGTC(gtc_random)
glmCreateTestGTC(gtc_round)
glmCreateTestGTC(gtc_reciprocal)
glmCreateTestGTC(gtc_type_aligned)
glmCreateTestGTC(gtc_type_precision)
glmCreateTestGTC(gtc_type_ptr)
glmCreateTestGTC(gtc_ulp)
glmCreateTestGTC(gtc_vec1)
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
#include <glm/gtc/color_space.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
namespace srgb
{
static 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;
}
glm::vec4 const ColorSourceGNI = glm::vec4(107, 107, 104, 131) / glm::vec4(255);
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceGNI);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceGNI, ColorRGB, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb
namespace srgb_lowp
{
static int test()
{
int Error(0);
for(float Color = 0.0f; Color < 1.0f; Color += 0.01f)
{
glm::highp_vec3 const HighpSRGB = glm::convertLinearToSRGB(glm::highp_vec3(Color));
glm::lowp_vec3 const LowpSRGB = glm::convertLinearToSRGB(glm::lowp_vec3(Color));
Error += glm::all(glm::epsilonEqual(glm::abs(HighpSRGB - glm::highp_vec3(LowpSRGB)), glm::highp_vec3(0), 0.1f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb_lowp
int main()
{
int Error(0);
Error += srgb::test();
Error += srgb_lowp::test();
return Error;
}
+30
View File
@@ -0,0 +1,30 @@
#include <glm/gtc/constants.hpp>
static int test_epsilon()
{
int Error = 0;
{
float Test = glm::epsilon<float>();
Error += Test > 0.0f ? 0 : 1;
}
{
double Test = glm::epsilon<double>();
Error += Test > 0.0 ? 0 : 1;
}
return Error;
}
int main()
{
int Error(0);
//float MinHalf = 0.0f;
//while (glm::half(MinHalf) == glm::half(0.0f))
// MinHalf += std::numeric_limits<float>::epsilon();
Error += test_epsilon();
return Error;
}
+80
View File
@@ -0,0 +1,80 @@
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/vector_relational.hpp>
static int test_defined()
{
int Error = 0;
Error += glm::all(glm::epsilonEqual(glm::vec2(0.0f), glm::vec2(0.0f), glm::vec2(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::vec3(0.0f), glm::vec3(0.0f), glm::vec3(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::vec4(0.0f), glm::vec4(0.0f), glm::vec4(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec2(1.0f), glm::vec2(2.0f), glm::vec2(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec3(1.0f), glm::vec3(2.0f), glm::vec3(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec4(1.0f), glm::vec4(2.0f), glm::vec4(glm::epsilon<float>()))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::vec2(0.0f), glm::vec2(0.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::vec3(0.0f), glm::vec3(0.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::vec4(0.0f), glm::vec4(0.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::quat(glm::vec3(0.0f)), glm::quat(glm::vec3(0.0f)), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec2(1.0f), glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec3(1.0f), glm::vec3(2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::vec4(1.0f), glm::vec4(2.0f), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::epsilonNotEqual(glm::quat(glm::vec3(0.0f)), glm::quat(glm::vec3(1.0f)), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
template<typename T>
static 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;
}
+281
View File
@@ -0,0 +1,281 @@
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_INLINE
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtx/type_aligned.hpp>
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cmath>
namespace log2_
{
static 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;
}
static int perf(std::size_t Count)
{
int Error = 0;
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wsign-conversion"
#endif
{
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();
std::printf("glm::log2<int>: %d clocks\n", static_cast<int>(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();
std::printf("glm::log2<ivec4>: %d clocks\n", static_cast<int>(End - Begin));
}
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
# if GLM_HAS_BITSCAN_WINDOWS
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
#if GLM_COMPILER& GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable: 4267)
#endif
for(std::size_t i = 0; i < Count; ++i)
{
glm::vec<4, unsigned long, glm::defaultp> Tmp;
_BitScanReverse(&Tmp.x, i);
_BitScanReverse(&Tmp.y, i);
_BitScanReverse(&Tmp.z, i);
_BitScanReverse(&Tmp.w, i);
Result[i] = glm::ivec4(Tmp);
}
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(pop)
#endif
std::clock_t End = clock();
std::printf("glm::log2<ivec4> inlined: %d clocks\n", static_cast<int>(End - Begin));
}
{
std::vector<glm::vec<4, unsigned long, glm::defaultp> > Result;
Result.resize(Count);
std::clock_t Begin = clock();
#if GLM_COMPILER& GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable: 4267)
#endif
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);
}
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(pop)
#endif
std::clock_t End = clock();
std::printf("glm::log2<ivec4> inlined no cast: %d clocks\n", static_cast<int>(End - Begin));
}
{
std::vector<glm::ivec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
#if GLM_COMPILER& GLM_COMPILER_VC
# pragma warning(push)
# pragma warning(disable: 4267)
#endif
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);
}
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(pop)
#endif
std::clock_t End = clock();
std::printf("glm::log2<ivec4> reinterpret: %d clocks\n", static_cast<int>(End - Begin));
}
# endif//GLM_HAS_BITSCAN_WINDOWS
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wsign-conversion"
#endif
{
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();
std::printf("glm::log2<float>: %d clocks\n", static_cast<int>(End - Begin));
}
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wsign-conversion"
#endif
{
std::vector<glm::vec4> Result;
Result.resize(Count);
std::clock_t Begin = clock();
for(int i = 0; i < static_cast<int>(Count); ++i)
Result[i] = glm::log2(glm::vec4(static_cast<float>(i)));
std::clock_t End = clock();
std::printf("glm::log2<vec4>: %d clocks\n", static_cast<int>(End - Begin));
}
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
return Error;
}
}//namespace log2_
namespace iround
{
static int test()
{
int Error = 0;
for(float f = 0.0f; f < 3.1f; f += 0.05f)
{
int RoundFast = static_cast<int>(glm::iround(f));
int RoundSTD = static_cast<int>(glm::round(f));
Error += RoundFast == RoundSTD ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace iround
namespace uround
{
static int test()
{
int Error = 0;
for(float f = 0.0f; f < 3.1f; f += 0.05f)
{
int RoundFast = static_cast<int>(glm::uround(f));
int RoundSTD = static_cast<int>(glm::round(f));
Error += RoundFast == RoundSTD ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace uround
int main()
{
int Error(0);
Error += ::log2_::test();
Error += ::iround::test();
Error += ::uround::test();
std::size_t const Samples(1000);
Error += ::log2_::perf(Samples);
return Error;
}
+383
View File
@@ -0,0 +1,383 @@
#include <glm/ext/vector_relational.hpp>
#include <glm/gtc/constants.hpp>
#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>
static 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::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 3), glm::vec2(12, 13), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 3), glm::vec3(12, 13, 14), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 3), glm::vec2(12, 13), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 3), glm::vec3(12, 13, 14), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::row(m, 3), glm::vec4(12, 13, 14, 15), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static 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::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(glm::column(m, 3), glm::vec4(12, 13, 14, 15), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static int test_mat4x4_row_get()
{
int Error = 0;
glm::mat4 m(1);
glm::vec4 A = glm::row(m, 0);
Error += glm::all(glm::equal(A, glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 B = glm::row(m, 1);
Error += glm::all(glm::equal(B, glm::vec4(0, 1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 C = glm::row(m, 2);
Error += glm::all(glm::equal(C, glm::vec4(0, 0, 1, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 D = glm::row(m, 3);
Error += glm::all(glm::equal(D, glm::vec4(0, 0, 0, 1), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
static int test_mat4x4_col_get()
{
int Error = 0;
glm::mat4 m(1);
glm::vec4 A = glm::column(m, 0);
Error += glm::all(glm::equal(A, glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 B = glm::column(m, 1);
Error += glm::all(glm::equal(B, glm::vec4(0, 1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 C = glm::column(m, 2);
Error += glm::all(glm::equal(C, glm::vec4(0, 0, 1, 0), glm::epsilon<float>())) ? 0 : 1;
glm::vec4 D = glm::column(m, 3);
Error += glm::all(glm::equal(D, glm::vec4(0, 0, 0, 1), glm::epsilon<float>())) ? 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>
static 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;
}
+161
View File
@@ -0,0 +1,161 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/matrix_relational.hpp>
#include <glm/ext/scalar_relational.hpp>
static int test_perspective()
{
int Error = 0;
const float Near = 0.1f;
const float Far = 100.0f;
const float Eps = glm::epsilon<float>();
glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
Projection = glm::perspectiveLH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, Far, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::perspectiveLH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, Far, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::perspectiveRH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, -Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, -Far, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::perspectiveRH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near, Far);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, -Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, -Far, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
return Error;
}
static int test_infinitePerspective()
{
int Error = 0;
const float Near = 0.1f;
const float Inf = 1.0e+10f;
const float Eps = glm::epsilon<float>();
glm::mat4 Projection = glm::infinitePerspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
Projection = glm::infinitePerspectiveLH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, Inf, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::infinitePerspectiveLH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, Inf, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::infinitePerspectiveRH_ZO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, -Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, -Inf, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, 0.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
Projection = glm::infinitePerspectiveRH_NO(glm::pi<float>() * 0.25f, 4.0f / 3.0f, Near);
{
glm::vec4 N = Projection * glm::vec4(0.f, 0.f, -Near, 1.f);
glm::vec4 F = Projection * glm::vec4(0.f, 0.f, -Inf, 1.f);
N /= N.w;
F /= F.w;
Error += glm::notEqual(N.z, -1.f, Eps);
Error += glm::notEqual(F.z, 1.f, Eps);
}
return Error;
}
static 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));
Error += !glm::all(glm::notEqual(Pick, glm::mat4(2.0), 0.001f));
return Error;
}
static 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);
Error += !glm::all(glm::notEqual(ProjectionA, glm::mat4(1.0), 0.001f));
Error += !glm::all(glm::notEqual(ProjectionB, glm::mat4(1.0), 0.001f));
return Error;
}
static 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);
glm::bvec4 b = glm::notEqual(t, glm::lowp_mat4(1.0), 0.001f);
Error += !glm::all(b);
return Error;
}
int main()
{
int Error = 0;
Error += test_translate();
Error += test_tweakedInfinitePerspective();
Error += test_pick();
Error += test_perspective();
Error += test_infinitePerspective();
return Error;
}
+86
View File
@@ -0,0 +1,86 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/noise.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/raw_data.hpp>
static int test_simplex_float()
{
int Error = 0;
glm::u8vec4 const PixelSimplex2D(glm::byte(glm::abs(glm::simplex(glm::vec2(0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelSimplex3D(glm::byte(glm::abs(glm::simplex(glm::vec3(0.f, 0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelSimplex4D(glm::byte(glm::abs(glm::simplex(glm::vec4(0.f, 0.f, 0.f, 0.f))) * 255.f));
return Error;
}
static int test_simplex_double()
{
int Error = 0;
glm::u8vec4 const PixelSimplex2D(glm::byte(glm::abs(glm::simplex(glm::dvec2(0.f, 0.f))) * 255.));
glm::u8vec4 const PixelSimplex3D(glm::byte(glm::abs(glm::simplex(glm::dvec3(0.f, 0.f, 0.f))) * 255.));
glm::u8vec4 const PixelSimplex4D(glm::byte(glm::abs(glm::simplex(glm::dvec4(0.f, 0.f, 0.f, 0.f))) * 255.));
return Error;
}
static int test_perlin_float()
{
int Error = 0;
glm::u8vec4 const PixelPerlin2D(glm::byte(glm::abs(glm::perlin(glm::vec2(0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelPerlin3D(glm::byte(glm::abs(glm::perlin(glm::vec3(0.f, 0.f, 0.f))) * 255.f));
glm::u8vec4 const PixelPerlin4D(glm::byte(glm::abs(glm::perlin(glm::vec4(0.f, 0.f, 0.f, 0.f))) * 255.f));
return Error;
}
static int test_perlin_double()
{
int Error = 0;
glm::u8vec4 const PixelPerlin2D(glm::byte(glm::abs(glm::perlin(glm::dvec2(0.f, 0.f))) * 255.));
glm::u8vec4 const PixelPerlin3D(glm::byte(glm::abs(glm::perlin(glm::dvec3(0.f, 0.f, 0.f))) * 255.));
glm::u8vec4 const PixelPerlin4D(glm::byte(glm::abs(glm::perlin(glm::dvec4(0.f, 0.f, 0.f, 0.f))) * 255.));
return Error;
}
static int test_perlin_pedioric_float()
{
int Error = 0;
glm::u8vec4 const PixelPeriodic2D(glm::byte(glm::abs(glm::perlin(glm::vec2(0.f, 0.f), glm::vec2(2.0f))) * 255.f));
glm::u8vec4 const PixelPeriodic3D(glm::byte(glm::abs(glm::perlin(glm::vec3(0.f, 0.f, 0.f), glm::vec3(2.0f))) * 255.f));
glm::u8vec4 const PixelPeriodic4D(glm::byte(glm::abs(glm::perlin(glm::vec4(0.f, 0.f, 0.f, 0.f), glm::vec4(2.0f))) * 255.f));
return Error;
}
static int test_perlin_pedioric_double()
{
int Error = 0;
glm::u8vec4 const PixelPeriodic2D(glm::byte(glm::abs(glm::perlin(glm::dvec2(0.f, 0.f), glm::dvec2(2.0))) * 255.));
glm::u8vec4 const PixelPeriodic3D(glm::byte(glm::abs(glm::perlin(glm::dvec3(0.f, 0.f, 0.f), glm::dvec3(2.0))) * 255.));
glm::u8vec4 const PixelPeriodic4D(glm::byte(glm::abs(glm::perlin(glm::dvec4(0.f, 0.f, 0.f, 0.f), glm::dvec4(2.0))) * 255.));
return Error;
}
int main()
{
int Error = 0;
Error += test_simplex_float();
Error += test_simplex_double();
Error += test_perlin_float();
Error += test_perlin_double();
Error += test_perlin_pedioric_float();
Error += test_perlin_pedioric_double();
return Error;
}
+879
View File
@@ -0,0 +1,879 @@
#include <glm/packing.hpp>
#include <glm/gtc/packing.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/ext/vector_relational.hpp>
#include <cstdio>
#include <vector>
/*
static void print_bits(float const& s)
{
union
{
float f;
unsigned int i;
} uif;
uif.f = s;
std::printf("f32: ");
for(std::size_t j = sizeof(s) * 8; j > 0; --j)
{
if(j == 23 || j == 31)
std::printf(" ");
std::printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0);
}
}
static void print_10bits(glm::uint const& s)
{
std::printf("10b: ");
for(std::size_t j = 10; j > 0; --j)
{
if(j == 5)
std::printf(" ");
std::printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
}
}
static void print_11bits(glm::uint const& s)
{
std::printf("11b: ");
for(std::size_t j = 11; j > 0; --j)
{
if(j == 6)
std::printf(" ");
std::printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
}
}
static void print_value(float const& s)
{
std::printf("%2.5f, ", static_cast<double>(s));
print_bits(s);
std::printf(", ");
// print_11bits(detail::floatTo11bit(s));
// std::printf(", ");
// print_10bits(detail::floatTo10bit(s));
std::printf("\n");
}
*/
static int test_Half1x16()
{
int Error = 0;
std::vector<float> Tests;
Tests.push_back(0.0f);
Tests.push_back(1.0f);
Tests.push_back(-1.0f);
Tests.push_back(2.0f);
Tests.push_back(-2.0f);
Tests.push_back(1.9f);
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
float v0 = glm::unpackHalf1x16(p0);
glm::uint16 p1 = glm::packHalf1x16(v0);
float v1 = glm::unpackHalf1x16(p1);
Error += glm::epsilonEqual(v0, v1, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
static 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, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v0, v2, glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static 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;
}
static int test_U3x10_1x2()
{
int Error = 0;
std::vector<glm::uvec4> Tests;
Tests.push_back(glm::uvec4(0));
Tests.push_back(glm::uvec4(1));
Tests.push_back(glm::uvec4(2));
Tests.push_back(glm::uvec4(3));
Tests.push_back(glm::uvec4(4));
Tests.push_back(glm::uvec4(5));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]);
glm::uvec4 v0 = glm::unpackU3x10_1x2(p0);
glm::uint32 p1 = glm::packU3x10_1x2(v0);
glm::uvec4 v1 = glm::unpackU3x10_1x2(p1);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
glm::u8vec4 const v0(0xff, 0x77, 0x0, 0x33);
glm::uint32 const p0 = *reinterpret_cast<glm::uint32 const*>(&v0[0]);
glm::uint32 const r0 = 0x330077ff;
Error += p0 == r0 ? 0 : 1;
glm::uvec4 const v1(0xff, 0x77, 0x0, 0x33);
glm::uint32 const p1 = glm::packU3x10_1x2(v1);
glm::uint32 const r1 = 0xc001dcff;
Error += p1 == r1 ? 0 : 1;
return Error;
}
static 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;
}
static 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;
}
static 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, glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static 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::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
static int test_RGBM()
{
int Error = 0;
for(std::size_t i = 0; i < 1024; ++i)
{
glm::vec3 const Color(static_cast<float>(i));
glm::vec4 const RGBM = glm::packRGBM(Color);
glm::vec3 const Result= glm::unpackRGBM(RGBM);
Error += glm::all(glm::equal(Color, Result, 0.01f)) ? 0 : 1;
}
return Error;
}
static int test_packUnorm1x16()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1(1.0f));
A.push_back(glm::vec1(0.5f));
A.push_back(glm::vec1(0.1f));
A.push_back(glm::vec1(0.0f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint16 C = glm::packUnorm1x16(B.x);
glm::vec1 D(glm::unpackUnorm1x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_packSnorm1x16()
{
int Error = 0;
std::vector<glm::vec1> A;
A.push_back(glm::vec1( 1.0f));
A.push_back(glm::vec1( 0.0f));
A.push_back(glm::vec1(-0.5f));
A.push_back(glm::vec1(-0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec1 B(A[i]);
glm::uint16 C = glm::packSnorm1x16(B.x);
glm::vec1 D(glm::unpackSnorm1x16(C));
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
}
return Error;
}
static int test_packUnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.0f));
A.push_back(glm::vec2(0.5f, 0.7f));
A.push_back(glm::vec2(0.1f, 0.2f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packUnorm2x16(B);
glm::vec2 D = glm::unpackUnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_packSnorm2x16()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 0.0f));
A.push_back(glm::vec2(-0.5f,-0.7f));
A.push_back(glm::vec2(-0.1f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::uint32 C = glm::packSnorm2x16(B);
glm::vec2 D = glm::unpackSnorm2x16(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static int test_packSnorm4x8()
{
int Error = 0;
std::vector<glm::vec4> A;
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec4 B(A[i]);
glm::uint32 C = glm::packSnorm4x8(B);
glm::vec4 D = glm::unpackSnorm4x8(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_packUnorm()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2(1.0f, 0.7f));
A.push_back(glm::vec2(0.5f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::u16vec2 C = glm::packUnorm<glm::uint16>(B);
glm::vec2 D = glm::unpackUnorm<float>(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_packSnorm()
{
int Error = 0;
std::vector<glm::vec2> A;
A.push_back(glm::vec2( 1.0f, 0.0f));
A.push_back(glm::vec2(-0.5f,-0.7f));
A.push_back(glm::vec2(-0.1f, 0.1f));
for(std::size_t i = 0; i < A.size(); ++i)
{
glm::vec2 B(A[i]);
glm::i16vec2 C = glm::packSnorm<glm::int16>(B);
glm::vec2 D = glm::unpackSnorm<float>(C);
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
assert(!Error);
}
return Error;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static 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;
}
static int test_packUint2x8()
{
int Error = 0;
glm::u8vec2 const Source(1, 2);
glm::uint16 const Packed = glm::packUint2x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packUint4x8()
{
int Error = 0;
glm::u8vec4 const Source(1, 2, 3, 4);
glm::uint32 const Packed = glm::packUint4x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packUint2x16()
{
int Error = 0;
glm::u16vec2 const Source(1, 2);
glm::uint32 const Packed = glm::packUint2x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packUint4x16()
{
int Error = 0;
glm::u16vec4 const Source(1, 2, 3, 4);
glm::uint64 const Packed = glm::packUint4x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packUint2x32()
{
int Error = 0;
glm::u32vec2 const Source(1, 2);
glm::uint64 const Packed = glm::packUint2x32(Source);
Error += Packed != 0 ? 0 : 1;
glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packInt2x8()
{
int Error = 0;
glm::i8vec2 const Source(1, 2);
glm::int16 const Packed = glm::packInt2x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packInt4x8()
{
int Error = 0;
glm::i8vec4 const Source(1, 2, 3, 4);
glm::int32 const Packed = glm::packInt4x8(Source);
Error += Packed != 0 ? 0 : 1;
glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packInt2x16()
{
int Error = 0;
glm::i16vec2 const Source(1, 2);
glm::int32 const Packed = glm::packInt2x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packInt4x16()
{
int Error = 0;
glm::i16vec4 const Source(1, 2, 3, 4);
glm::int64 const Packed = glm::packInt4x16(Source);
Error += Packed != 0 ? 0 : 1;
glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
static int test_packInt2x32()
{
int Error = 0;
glm::i32vec2 const Source(1, 2);
glm::int64 const Packed = glm::packInt2x32(Source);
Error += Packed != 0 ? 0 : 1;
glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed);
Error += Source == Unpacked ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_packUnorm();
Error += test_packSnorm();
Error += test_packSnorm1x16();
Error += test_packSnorm2x16();
Error += test_packSnorm4x16();
Error += test_packSnorm1x8();
Error += test_packSnorm2x8();
Error += test_packSnorm4x8();
Error += test_packUnorm1x16();
Error += test_packUnorm2x16();
Error += test_packUnorm4x16();
Error += test_packUnorm1x8();
Error += test_packUnorm2x8();
Error += test_packUnorm4x8();
Error += test_packUnorm2x4();
Error += test_packUnorm4x4();
Error += test_packUnorm3x5_1x1();
Error += test_packUnorm1x5_1x6_1x5();
Error += test_packUnorm2x3_1x2();
Error += test_packUint2x8();
Error += test_packUint4x8();
Error += test_packUint2x16();
Error += test_packUint4x16();
Error += test_packUint2x32();
Error += test_packInt2x8();
Error += test_packInt4x8();
Error += test_packInt2x16();
Error += test_packInt4x16();
Error += test_packInt2x32();
Error += test_F2x11_1x10();
Error += test_F3x9_E1x5();
Error += test_RGBM();
Error += test_Unorm3x10_1x2();
Error += test_Snorm3x10_1x2();
Error += test_I3x10_1x2();
Error += test_U3x10_1x2();
Error += test_Half1x16();
Error += test_Half4x16();
return Error;
}
+348
View File
@@ -0,0 +1,348 @@
#include <glm/gtc/constants.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/ext/matrix_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/glm.hpp>
#include <vector>
static 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::equal(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::equal(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::equal(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::equal(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::equal(L, 1.0f, 0.01f) ? 0 : 1;
float A = glm::angle(N);
Error += glm::equal(A, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
}
return Error;
}
static int test_quat_angleAxis()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.f, glm::vec3(0.f, 0.f, 1.f));
glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::equal(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::equal(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::equal(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::equal(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
static int test_quat_mix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.f, glm::vec3(0.f, 0.f, 1.f));
glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::equal(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::equal(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::equal(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::equal(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
static 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::equal(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::equal(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::equal(L, 1.0f, 0.000001f) ? 0 : 1;
}
return Error;
}
static int test_quat_euler()
{
int Error = 0;
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float Roll = glm::roll(q);
float Pitch = glm::pitch(q);
float Yaw = glm::yaw(q);
glm::vec3 Angles = glm::eulerAngles(q);
Error += glm::all(glm::equal(Angles, glm::vec3(Pitch, Yaw, Roll), 0.000001f)) ? 0 : 1;
}
{
glm::dquat q(1.0, 0.0, 0.0, 1.0);
double Roll = glm::roll(q);
double Pitch = glm::pitch(q);
double Yaw = glm::yaw(q);
glm::dvec3 Angles = glm::eulerAngles(q);
Error += glm::all(glm::equal(Angles, glm::dvec3(Pitch, Yaw, Roll), 0.000001)) ? 0 : 1;
}
return Error;
}
static int test_quat_slerp()
{
int Error = 0;
float const Epsilon = 0.0001f;//glm::epsilon<float>();
float sqrt2 = std::sqrt(2.0f)/2.0f;
glm::quat id(static_cast<float>(1), static_cast<float>(0), static_cast<float>(0), static_cast<float>(0));
glm::quat Y90rot(sqrt2, 0.0f, sqrt2, 0.0f);
// Testing a == 0
// Must be id
glm::quat id2 = glm::slerp(id, Y90rot, 0.0f);
Error += glm::all(glm::equal(id, id2, Epsilon)) ? 0 : 1;
// Testing a == 1
// Must be 90 degrees rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot2 = glm::slerp(id, Y90rot, 1.0f);
Error += glm::all(glm::equal(Y90rot, Y90rot2, Epsilon)) ? 0 : 1;
// Testing standard, easy case
// Must be 45 degrees rotation on Y : 0 0.38 0 0.92
glm::quat Y45rot1 = glm::slerp(id, Y90rot, 0.5f);
Error += glm::all(glm::equal(Y45rot1, glm::quat(0.924f, 0.0f, 0.383f, 0.0f), 0.01f)) ? 0 : 1;
// Testing reverse case
// Must be 45 degrees 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 degrees rotation on Y
// certainly not a 135 degrees rotation
glm::quat Y45rot3 = glm::slerp(id , -Y90rot, 0.5f);
float Y45angle3 = glm::angle(Y45rot3);
Error += glm::equal(Y45angle3, glm::pi<float>() * 0.25f, Epsilon) ? 0 : 1;
Error += glm::all(glm::equal(Ym45rot2, Y45rot3, Epsilon)) ? 0 : 1;
// Same, but inverted
// Must also be 45 degrees 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::equal(Ym45rot2, -Y45rot4, Epsilon)) ? 0 : 1;
// Testing q1 = q2
// Must be 90 degrees rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot3 = glm::slerp(Y90rot, Y90rot, 0.5f);
Error += glm::all(glm::equal(Y90rot, Y90rot3, Epsilon)) ? 0 : 1;
// Testing 180 degrees rotation
// Must be 90 degrees 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::equal(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);
Error += glm::all(glm::equal(almostid, glm::quat(1.0f, 0.0f, 0.0f, 0.0f), 0.1f)) ? 0 : 1;
// Testing quaternions with opposite sign
{
glm::quat a(-1, 0, 0, 0);
glm::quat result = glm::slerp(a, id, 0.5f);
Error += glm::equal(glm::pow(glm::dot(id, result), 2.f), 1.f, 0.01f) ? 0 : 1;
}
return Error;
}
static int test_quat_slerp_spins()
{
int Error = 0;
float const Epsilon = 0.0001f;//glm::epsilon<float>();
float sqrt2 = std::sqrt(2.0f) / 2.0f;
glm::quat id(static_cast<float>(1), static_cast<float>(0), static_cast<float>(0), static_cast<float>(0));
glm::quat Y90rot(sqrt2, 0.0f, sqrt2, 0.0f);
glm::quat Y180rot(0.0f, 0.0f, 1.0f, 0.0f);
// Testing a == 0, k == 1
// Must be id
glm::quat id2 = glm::slerp(id, id, 1.0f, 1);
Error += glm::all(glm::equal(id, id2, Epsilon)) ? 0 : 1;
// Testing a == 1, k == 2
// Must be id
glm::quat id3 = glm::slerp(id, id, 1.0f, 2);
Error += glm::all(glm::equal(id, id3, Epsilon)) ? 0 : 1;
// Testing a == 1, k == 1
// Must be 90 degrees rotation on Y : 0 0.7 0 0.7
// Negative quaternion is representing same orientation
glm::quat Y90rot2 = glm::slerp(id, Y90rot, 1.0f, 1);
Error += glm::all(glm::equal(Y90rot, -Y90rot2, Epsilon)) ? 0 : 1;
// Testing a == 1, k == 2
// Must be id
glm::quat Y90rot3 = glm::slerp(id, Y90rot, 8.0f / 9.0f, 2);
Error += glm::all(glm::equal(id, Y90rot3, Epsilon)) ? 0 : 1;
// Testing a == 1, k == 1
// Must be 90 degrees rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot4 = glm::slerp(id, Y90rot, 0.2f, 1);
Error += glm::all(glm::equal(Y90rot, Y90rot4, Epsilon)) ? 0 : 1;
// Testing reverse case
// Must be 45 degrees rotation on Y : 0 0.38 0 0.92
// Negative quaternion is representing same orientation
glm::quat Ym45rot2 = glm::slerp(Y90rot, id, 0.9f, 1);
glm::quat Ym45rot3 = glm::slerp(Y90rot, id, 0.5f);
Error += glm::all(glm::equal(-Ym45rot2, Ym45rot3, Epsilon)) ? 0 : 1;
// Testing against full circle around the sphere instead of shortest path
// Must be 45 degrees rotation on Y
// certainly not a 135 degrees rotation
glm::quat Y45rot3 = glm::slerp(id, -Y90rot, 0.5f, 0);
float Y45angle3 = glm::angle(Y45rot3);
Error += glm::equal(Y45angle3, glm::pi<float>() * 0.25f, Epsilon) ? 0 : 1;
Error += glm::all(glm::equal(Ym45rot3, Y45rot3, Epsilon)) ? 0 : 1;
// Same, but inverted
// Must also be 45 degrees 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, 0);
Error += glm::all(glm::equal(Ym45rot2, Y45rot4, Epsilon)) ? 0 : 1;
// Testing q1 = q2 k == 2
// Must be 90 degrees rotation on Y : 0 0.7 0 0.7
glm::quat Y90rot5 = glm::slerp(Y90rot, Y90rot, 0.5f, 2);
Error += glm::all(glm::equal(Y90rot, Y90rot5, Epsilon)) ? 0 : 1;
// Testing 180 degrees rotation
// Must be 90 degrees rotation on almost any axis that is on the XZ plane
glm::quat XZ90rot = glm::slerp(id, -Y90rot, 0.5f, 1);
float XZ90angle = glm::angle(XZ90rot); // Must be PI/4 = 0.78;
Error += glm::equal(XZ90angle, glm::pi<float>() * 1.25f, Epsilon) ? 0 : 1;
// Testing rotation over long arc
// Distance from id to 90 degrees is 270 degrees, so 2/3 of it should be 180 degrees
// Negative quaternion is representing same orientation
glm::quat Neg90rot = glm::slerp(id, Y90rot, 2.0f / 3.0f, -1);
Error += glm::all(glm::equal(Y180rot, -Neg90rot, Epsilon)) ? 0 : 1;
return Error;
}
static 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::equal(v, w, 0.01f)) ? 0 : 1;
return Error;
}
static int test_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);
Error += glm::all(glm::equal(temp4, glm::vec3(0.0f, -0.28f, -0.96f), 0.01f)) ? 0 : 1;
glm::quat temp5 = glm::normalize(temp1 * temp2);
glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5);
Error += glm::all(glm::equal(temp6, glm::vec3(-0.48f, 0.36f, -0.8f), 0.01f)) ? 0 : 1;
glm::quat temp7(1.0f, glm::vec3(0.0, 1.0, 0.0));
temp7 *= temp5;
temp7 *= glm::inverse(temp5);
Error += glm::any(glm::notEqual(temp7, glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0)), glm::epsilon<float>())) ? 1 : 0;
return Error;
}
static int test_identity()
{
int Error = 0;
glm::quat const Q = glm::identity<glm::quat>();
Error += glm::all(glm::equal(Q, glm::quat(1, 0, 0, 0), 0.0001f)) ? 0 : 1;
Error += glm::any(glm::notEqual(Q, glm::quat(1, 0, 0, 0), 0.0001f)) ? 1 : 0;
glm::mat4 const M = glm::identity<glm::mat4x4>();
glm::mat4 const N(1.0f);
Error += glm::all(glm::equal(M, N, 0.0001f)) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_mul();
Error += test_quat_mul_vec();
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_quat_slerp_spins();
Error += test_identity();
return Error;
}
+383
View File
@@ -0,0 +1,383 @@
#ifndef GLM_FORCE_PURE
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
#endif
#include <glm/gtc/random.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/type_precision.hpp>
#if GLM_LANG & GLM_LANG_CXX0X_FLAG
# include <array>
#endif
std::size_t const TestSamples = 10000;
static int test_linearRand()
{
int Error = 0;
glm::int32 const Min = 16;
glm::int32 const Max = 32;
{
glm::u8vec2 AMin(std::numeric_limits<glm::u8>::max());
glm::u8vec2 AMax(std::numeric_limits<glm::u8>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u8vec2 A = glm::linearRand(glm::u8vec2(Min), glm::u8vec2(Max));
AMin = glm::min(AMin, A);
AMax = glm::max(AMax, A);
if(!glm::all(glm::lessThanEqual(A, glm::u8vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::u8vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(AMin, glm::u8vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(AMax, glm::u8vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u16vec2 BMin(std::numeric_limits<glm::u16>::max());
glm::u16vec2 BMax(std::numeric_limits<glm::u16>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u16vec2 B = glm::linearRand(glm::u16vec2(Min), glm::u16vec2(Max));
BMin = glm::min(BMin, B);
BMax = glm::max(BMax, B);
if(!glm::all(glm::lessThanEqual(B, glm::u16vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::u16vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(BMin, glm::u16vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(BMax, glm::u16vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u32vec2 CMin(std::numeric_limits<glm::u32>::max());
glm::u32vec2 CMax(std::numeric_limits<glm::u32>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u32vec2 C = glm::linearRand(glm::u32vec2(Min), glm::u32vec2(Max));
CMin = glm::min(CMin, C);
CMax = glm::max(CMax, C);
if(!glm::all(glm::lessThanEqual(C, glm::u32vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(C, glm::u32vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(CMin, glm::u32vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(CMax, glm::u32vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::u64vec2 DMin(std::numeric_limits<glm::u64>::max());
glm::u64vec2 DMax(std::numeric_limits<glm::u64>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::u64vec2 D = glm::linearRand(glm::u64vec2(Min), glm::u64vec2(Max));
DMin = glm::min(DMin, D);
DMax = glm::max(DMax, D);
if(!glm::all(glm::lessThanEqual(D, glm::u64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(D, glm::u64vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(DMin, glm::u64vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(DMax, glm::u64vec2(Max))) ? 0 : 1;
assert(!Error);
}
}
{
glm::i8vec2 AMin(std::numeric_limits<glm::i8>::max());
glm::i8vec2 AMax(std::numeric_limits<glm::i8>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i8vec2 A = glm::linearRand(glm::i8vec2(Min), glm::i8vec2(Max));
AMin = glm::min(AMin, A);
AMax = glm::max(AMax, A);
if(!glm::all(glm::lessThanEqual(A, glm::i8vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::i8vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(AMin, glm::i8vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(AMax, glm::i8vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i16vec2 BMin(std::numeric_limits<glm::i16>::max());
glm::i16vec2 BMax(std::numeric_limits<glm::i16>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i16vec2 B = glm::linearRand(glm::i16vec2(Min), glm::i16vec2(Max));
BMin = glm::min(BMin, B);
BMax = glm::max(BMax, B);
if(!glm::all(glm::lessThanEqual(B, glm::i16vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::i16vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(BMin, glm::i16vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(BMax, glm::i16vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i32vec2 CMin(std::numeric_limits<glm::i32>::max());
glm::i32vec2 CMax(std::numeric_limits<glm::i32>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i32vec2 C = glm::linearRand(glm::i32vec2(Min), glm::i32vec2(Max));
CMin = glm::min(CMin, C);
CMax = glm::max(CMax, C);
if(!glm::all(glm::lessThanEqual(C, glm::i32vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(C, glm::i32vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(CMin, glm::i32vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(CMax, glm::i32vec2(Max))) ? 0 : 1;
assert(!Error);
}
glm::i64vec2 DMin(std::numeric_limits<glm::i64>::max());
glm::i64vec2 DMax(std::numeric_limits<glm::i64>::min());
{
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::i64vec2 D = glm::linearRand(glm::i64vec2(Min), glm::i64vec2(Max));
DMin = glm::min(DMin, D);
DMax = glm::max(DMax, D);
if(!glm::all(glm::lessThanEqual(D, glm::i64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(D, glm::i64vec2(Min))))
++Error;
assert(!Error);
}
Error += glm::all(glm::equal(DMin, glm::i64vec2(Min))) ? 0 : 1;
Error += glm::all(glm::equal(DMax, glm::i64vec2(Max))) ? 0 : 1;
assert(!Error);
}
}
for(std::size_t i = 0; i < TestSamples; ++i)
{
glm::f32vec2 const A(glm::linearRand(glm::f32vec2(static_cast<float>(Min)), glm::f32vec2(static_cast<float>(Max))));
if(!glm::all(glm::lessThanEqual(A, glm::f32vec2(static_cast<float>(Max)))))
++Error;
if(!glm::all(glm::greaterThanEqual(A, glm::f32vec2(static_cast<float>(Min)))))
++Error;
glm::f64vec2 const B(glm::linearRand(glm::f64vec2(Min), glm::f64vec2(Max)));
if(!glm::all(glm::lessThanEqual(B, glm::f64vec2(Max))))
++Error;
if(!glm::all(glm::greaterThanEqual(B, glm::f64vec2(Min))))
++Error;
assert(!Error);
}
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::linearRand(-1.0f, 1.0f);
ResultDouble += glm::linearRand(-1.0, 1.0);
}
Error += glm::epsilonEqual(ResultFloat, 0.0f, 0.0001f);
Error += glm::epsilonEqual(ResultDouble, 0.0, 0.0001);
assert(!Error);
}
return Error;
}
static int test_circularRand()
{
int Error = 0;
{
std::size_t Max = TestSamples;
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
double Radius = 2.0;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloat += glm::length(glm::circularRand(1.0f));
ResultDouble += glm::length(glm::circularRand(Radius));
}
Error += glm::epsilonEqual(ResultFloat, float(Max), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDouble, double(Max) * double(Radius), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_sphericalRand()
{
int Error = 0;
{
std::size_t Max = TestSamples;
float ResultFloatA = 0.0f;
float ResultFloatB = 0.0f;
float ResultFloatC = 0.0f;
double ResultDoubleA = 0.0;
double ResultDoubleB = 0.0;
double ResultDoubleC = 0.0;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloatA += glm::length(glm::sphericalRand(1.0f));
ResultDoubleA += glm::length(glm::sphericalRand(1.0));
ResultFloatB += glm::length(glm::sphericalRand(2.0f));
ResultDoubleB += glm::length(glm::sphericalRand(2.0));
ResultFloatC += glm::length(glm::sphericalRand(3.0f));
ResultDoubleC += glm::length(glm::sphericalRand(3.0));
}
Error += glm::epsilonEqual(ResultFloatA, float(Max), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
Error += glm::epsilonEqual(ResultFloatB, float(Max * 2), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
Error += glm::epsilonEqual(ResultFloatC, float(Max * 3), 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(ResultDoubleC, double(Max * 3), 0.01) ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_diskRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::diskRand(2.0f));
ResultDouble += glm::length(glm::diskRand(2.0));
}
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}
return Error;
}
static int test_ballRand()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0;
for(std::size_t i = 0; i < TestSamples; ++i)
{
ResultFloat += glm::length(glm::ballRand(2.0f));
ResultDouble += glm::length(glm::ballRand(2.0));
}
Error += ResultFloat < float(TestSamples) * 2.f ? 0 : 1;
Error += ResultDouble < double(TestSamples) * 2.0 ? 0 : 1;
assert(!Error);
}
return Error;
}
/*
#if(GLM_LANG & GLM_LANG_CXX0X_FLAG)
int test_grid()
{
int Error = 0;
typedef std::array<int, 8> colors;
typedef std::array<int, 8 * 8> grid;
grid Grid;
colors Colors;
grid GridBest;
colors ColorsBest;
while(true)
{
for(std::size_t i = 0; i < Grid.size(); ++i)
Grid[i] = int(glm::linearRand(0.0, 8.0 * 8.0 * 8.0 - 1.0) / 64.0);
for(std::size_t i = 0; i < Grid.size(); ++i)
++Colors[Grid[i]];
bool Exit = true;
for(std::size_t i = 0; i < Colors.size(); ++i)
{
if(Colors[i] == 8)
continue;
Exit = false;
break;
}
if(Exit == true)
break;
}
return Error;
}
#endif
*/
int main()
{
int Error = 0;
Error += test_linearRand();
Error += test_circularRand();
Error += test_sphericalRand();
Error += test_diskRand();
Error += test_ballRand();
/*
#if(GLM_LANG & GLM_LANG_CXX0X_FLAG)
Error += test_grid();
#endif
*/
return Error;
}
+8
View File
@@ -0,0 +1,8 @@
#include <glm/gtc/reciprocal.hpp>
#include <ctime>
int main()
{
return 0;
}
+467
View File
@@ -0,0 +1,467 @@
#include <glm/gtc/round.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
#include <vector>
#include <ctime>
#include <cstdio>
namespace isPowerOfTwo
{
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
template<typename genType>
struct type
{
genType Value;
bool Return;
};
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
static int test_int16()
{
type<glm::int16> const Data[] =
{
{0x0001, true},
{0x0002, true},
{0x0004, true},
{0x0080, true},
{0x0000, true},
{0x0003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int test_uint16()
{
type<glm::uint16> const Data[] =
{
{0x0001, true},
{0x0002, true},
{0x0004, true},
{0x0000, true},
{0x0000, true},
{0x0003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint16>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int test_int32()
{
type<int> const Data[] =
{
{0x00000001, true},
{0x00000002, true},
{0x00000004, true},
{0x0000000f, false},
{0x00000000, true},
{0x00000003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec1 Result = glm::isPowerOfTwo(glm::ivec1(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec1(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec2 Result = glm::isPowerOfTwo(glm::ivec2(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec2(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec3 Result = glm::isPowerOfTwo(glm::ivec3(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec3(Data[i].Return), Result)) ? 0 : 1;
}
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
glm::bvec4 Result = glm::isPowerOfTwo(glm::ivec4(Data[i].Value));
Error += glm::all(glm::equal(glm::bvec4(Data[i].Return), Result)) ? 0 : 1;
}
return Error;
}
static int test_uint32()
{
type<glm::uint> const Data[] =
{
{0x00000001, true},
{0x00000002, true},
{0x00000004, true},
{0x80000000, true},
{0x00000000, true},
{0x00000003, false}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint>); i < n; ++i)
{
bool Result = glm::isPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int test()
{
int Error(0);
Error += test_int16();
Error += test_uint16();
Error += test_int32();
Error += test_uint32();
return Error;
}
}//isPowerOfTwo
namespace ceilPowerOfTwo_advanced
{
template<typename genIUType>
GLM_FUNC_QUALIFIER
static genIUType highestBitValue(genIUType Value)
{
genIUType tmp = Value;
genIUType result = genIUType(0);
while(tmp)
{
result = (tmp & (~tmp + 1)); // grab lowest bit
tmp &= ~result; // clear lowest bit
}
return result;
}
template<typename genType>
GLM_FUNC_QUALIFIER
static genType ceilPowerOfTwo_loop(genType value)
{
return glm::isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
}
template<typename genType>
struct type
{
genType Value;
genType Return;
};
static int test_int32()
{
type<glm::int32> const Data[] =
{
{0x0000ffff, 0x00010000},
{-3, -4},
{-8, -8},
{0x00000001, 0x00000001},
{0x00000002, 0x00000002},
{0x00000004, 0x00000004},
{0x00000007, 0x00000008},
{0x0000fff0, 0x00010000},
{0x0000f000, 0x00010000},
{0x08000000, 0x08000000},
{0x00000000, 0x00000000},
{0x00000003, 0x00000004}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int32>); i < n; ++i)
{
glm::int32 Result = glm::ceilPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int test_uint32()
{
type<glm::uint32> const Data[] =
{
{0x00000001, 0x00000001},
{0x00000002, 0x00000002},
{0x00000004, 0x00000004},
{0x00000007, 0x00000008},
{0x0000ffff, 0x00010000},
{0x0000fff0, 0x00010000},
{0x0000f000, 0x00010000},
{0x80000000, 0x80000000},
{0x00000000, 0x00000000},
{0x00000003, 0x00000004}
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint32>); i < n; ++i)
{
glm::uint32 Result = glm::ceilPowerOfTwo(Data[i].Value);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int perf()
{
int Error(0);
std::vector<glm::uint> v;
v.resize(10000);
std::clock_t Timestramp0 = std::clock();
for(glm::uint32 i = 0, n = static_cast<glm::uint>(v.size()); i < n; ++i)
v[i] = ceilPowerOfTwo_loop(i);
std::clock_t Timestramp1 = std::clock();
for(glm::uint32 i = 0, n = static_cast<glm::uint>(v.size()); i < n; ++i)
v[i] = glm::ceilPowerOfTwo(i);
std::clock_t Timestramp2 = std::clock();
std::printf("ceilPowerOfTwo_loop: %d clocks\n", static_cast<int>(Timestramp1 - Timestramp0));
std::printf("glm::ceilPowerOfTwo: %d clocks\n", static_cast<int>(Timestramp2 - Timestramp1));
return Error;
}
static int test()
{
int Error(0);
Error += test_int32();
Error += test_uint32();
return Error;
}
}//namespace ceilPowerOfTwo_advanced
namespace roundPowerOfTwo
{
static int test()
{
int Error = 0;
glm::uint32 const A = glm::roundPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::roundPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::roundPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
glm::uint32 const D = glm::roundPowerOfTwo(9u);
Error += D == 8u ? 0 : 1;
glm::uint32 const E = glm::roundPowerOfTwo(17u);
Error += E == 16u ? 0 : 1;
glm::uint32 const F = glm::roundPowerOfTwo(33u);
Error += F == 32u ? 0 : 1;
return Error;
}
}//namespace roundPowerOfTwo
namespace floorPowerOfTwo
{
static int test()
{
int Error = 0;
glm::uint32 const A = glm::floorPowerOfTwo(7u);
Error += A == 4u ? 0 : 1;
glm::uint32 const B = glm::floorPowerOfTwo(15u);
Error += B == 8u ? 0 : 1;
glm::uint32 const C = glm::floorPowerOfTwo(31u);
Error += C == 16u ? 0 : 1;
return Error;
}
}//namespace floorPowerOfTwo
namespace ceilPowerOfTwo
{
static int test()
{
int Error = 0;
glm::uint32 const A = glm::ceilPowerOfTwo(7u);
Error += A == 8u ? 0 : 1;
glm::uint32 const B = glm::ceilPowerOfTwo(15u);
Error += B == 16u ? 0 : 1;
glm::uint32 const C = glm::ceilPowerOfTwo(31u);
Error += C == 32u ? 0 : 1;
return Error;
}
}//namespace ceilPowerOfTwo
namespace floorMultiple
{
template<typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
static int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.3, 0.0001},
{-1.4, 0.3, -1.5, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::floorMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
static int test()
{
int Error(0);
Error += test_float();
return Error;
}
}//namespace floorMultiple
namespace ceilMultiple
{
template<typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
static int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.6, 0.0001},
{-1.4, 0.3, -1.2, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
static int test_int()
{
type<int> const Data[] =
{
{3, 4, 4, 0},
{7, 4, 8, 0},
{5, 4, 8, 0},
{1, 4, 4, 0},
{1, 3, 3, 0},
{4, 3, 6, 0},
{4, 1, 4, 0},
{1, 1, 1, 0},
{7, 1, 7, 0},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
{
int Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple);
Error += Data[i].Return == Result ? 0 : 1;
}
return Error;
}
static int test()
{
int Error(0);
Error += test_int();
Error += test_float();
return Error;
}
}//namespace ceilMultiple
int main()
{
int Error(0);
Error += isPowerOfTwo::test();
Error += floorPowerOfTwo::test();
Error += roundPowerOfTwo::test();
Error += ceilPowerOfTwo::test();
Error += ceilPowerOfTwo_advanced::test();
Error += ceilPowerOfTwo_advanced::perf();
Error += floorMultiple::test();
Error += ceilMultiple::test();
return Error;
}
+560
View File
@@ -0,0 +1,560 @@
// Force explicit ctors in this test to catch returning the wrong vector size from e.g. glm::xyz
#define GLM_FORCE_EXPLICIT_CTOR
#include <glm/glm.hpp>
#if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
#include <glm/gtc/type_aligned.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/matrix_relational.hpp>
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_lowp>::value, "aligned_lowp is not aligned");
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_mediump>::value, "aligned_mediump is not aligned");
GLM_STATIC_ASSERT(glm::detail::is_aligned<glm::aligned_highp>::value, "aligned_highp is not aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_highp>::value, "packed_highp is aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_mediump>::value, "packed_mediump is aligned");
GLM_STATIC_ASSERT(!glm::detail::is_aligned<glm::packed_lowp>::value, "packed_lowp is aligned");
struct my_vec4_packed
{
glm::uint32 a;
glm::vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_vec4_packed) == sizeof(glm::uint32) + sizeof(glm::vec4), "glm::vec4 packed is not correct");
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
struct my_vec4_aligned
{
glm::uint32 a;
glm::aligned_vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_vec4_aligned) == sizeof(glm::aligned_vec4) * 2, "glm::vec4 aligned is not correct");
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
struct my_dvec4_packed
{
glm::uint64 a;
glm::dvec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_dvec4_packed) == sizeof(glm::uint64) + sizeof(glm::dvec4), "glm::dvec4 packed is not correct");
struct my_dvec4_aligned
{
glm::uint64 a;
glm::aligned_dvec4 b;
};
//GLM_STATIC_ASSERT(sizeof(my_dvec4_aligned) == sizeof(glm::aligned_dvec4) * 2, "glm::dvec4 aligned is not correct");
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
struct my_ivec4_packed
{
glm::uint32 a;
glm::ivec4 b;
};
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
GLM_STATIC_ASSERT(sizeof(my_ivec4_packed) == sizeof(glm::uint32) + sizeof(glm::ivec4), "glm::ivec4 packed is not correct");
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
struct my_ivec4_aligned
{
glm::uint32 a;
glm::aligned_ivec4 b;
};
#if GLM_COMPILER & GLM_COMPILER_CLANG
# pragma clang diagnostic pop
#endif
GLM_STATIC_ASSERT(sizeof(my_ivec4_aligned) == sizeof(glm::aligned_ivec4) * 2, "glm::ivec4 aligned is not correct");
struct my_u8vec4_packed
{
glm::uint32 a;
glm::u8vec4 b;
};
GLM_STATIC_ASSERT(sizeof(my_u8vec4_packed) == sizeof(glm::uint32) + sizeof(glm::u8vec4), "glm::u8vec4 packed is not correct");
static int test_copy_vec4()
{
int Error = 0;
{
glm::aligned_vec4 const u(1.f, 2.f, 3.f, 4.f);
glm::packed_vec4 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::packed_vec4 const u(1.f, 2.f, 3.f, 4.f);
glm::aligned_vec4 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dvec4 const u(1., 2., 3., 4.);
glm::packed_dvec4 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::packed_dvec4 const u(1.f, 2.f, 3.f, 4.f);
glm::aligned_dvec4 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_ivec4 const u(1, 2, 3, 4);
glm::packed_ivec4 const v(u);
Error += v.x == u.x ? 0 : 1;
Error += v.y == u.y ? 0 : 1;
Error += v.z == u.z ? 0 : 1;
Error += v.w == u.w ? 0 : 1;
}
{
glm::packed_ivec4 const u(1, 2, 3, 4);
glm::aligned_ivec4 const v(u);
Error += v.x == u.x ? 0 : 1;
Error += v.y == u.y ? 0 : 1;
Error += v.z == u.z ? 0 : 1;
Error += v.w == u.w ? 0 : 1;
}
return Error;
}
static int test_copy_vec3()
{
int Error = 0;
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::packed_vec3 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::packed_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec3 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::packed_dvec3 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::packed_dvec3 const u(1.f, 2.f, 3.f);
glm::aligned_dvec3 const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_ivec3 const u(1, 2, 3);
glm::packed_ivec3 const v(u);
Error += v.x == u.x ? 0 : 1;
Error += v.y == u.y ? 0 : 1;
Error += v.z == u.z ? 0 : 1;
}
{
glm::packed_ivec3 const u(1, 2, 3);
glm::aligned_ivec3 const v(u);
Error += v.x == u.x ? 0 : 1;
Error += v.y == u.y ? 0 : 1;
Error += v.z == u.z ? 0 : 1;
}
return Error;
}
static int test_copy_quat()
{
int Error = 0;
{
glm::aligned_quat const u(1.f, 2.f, 3.f, 4.f);
glm::packed_quat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::packed_quat const u(1.f, 2.f, 3.f, 4.f);
glm::aligned_quat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dquat const u(1., 2., 3., 4.);
glm::packed_dquat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::packed_dquat const u(1., 2., 3., 4.);
glm::aligned_dquat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}
return Error;
}
static int test_splat_vec3()
{
int Error = 0;
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec3 const v(glm::splatX(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.x, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec3 const v(glm::splatY(u));
Error += glm::equal(v.x, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.y, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec3 const v(glm::splatZ(u));
Error += glm::equal(v.x, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec3 const v(glm::splatX(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.x, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec3 const v(glm::splatY(u));
Error += glm::equal(v.x, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.y, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec3 const v(glm::splatZ(u));
Error += glm::equal(v.x, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
}
return Error;
}
static int test_splat_vec4()
{
int Error = 0;
{
glm::aligned_vec4 const u(1.f, 2.f, 3.f, 4.f);
{
glm::aligned_vec4 const v(glm::splatX(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.x, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_vec4 const v(glm::splatY(u));
Error += glm::equal(v.x, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.y, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_vec4 const v(glm::splatZ(u));
Error += glm::equal(v.x, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.z, glm::epsilon<float>()) ? 0 : 1;
}
}
{
glm::aligned_dvec4 const u(1., 2., 3., 4.);
{
glm::aligned_dvec4 const v(glm::splatX(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.x, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_dvec4 const v(glm::splatY(u));
Error += glm::equal(v.x, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.y, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_dvec4 const v(glm::splatZ(u));
Error += glm::equal(v.x, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.z, glm::epsilon<double>()) ? 0 : 1;
}
}
return Error;
}
static int test_copy_vec4_vec3()
{
int Error = 0;
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec4 const v(glm::xyz0(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, 0.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec4 const v(glm::xyz1(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, 1.0f, glm::epsilon<float>()) ? 0 : 1; ;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec4 const v(glm::xyz0(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, 0.0, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec4 const v(glm::xyz1(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, 1.0, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_vec3 const u(1.f, 2.f, 3.f);
glm::aligned_vec4 const v(glm::xyzz(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.z, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dvec3 const u(1., 2., 3.);
glm::aligned_dvec4 const v(glm::xyzz(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.z, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::aligned_vec4 const u(1.f, 2.f, 3.f, 4.f);
glm::aligned_vec3 const v(glm::xyz(u));
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::aligned_dvec4 const u(1., 2., 3., 4.);
glm::aligned_dvec3 const v(glm::xyz(u));
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
}
return Error;
}
static int test_copy()
{
int Error = 0;
{
glm::aligned_ivec4 const a(1, 2, 3, 4);
glm::ivec4 const u(a);
Error += a.x == u.x ? 0 : 1;
Error += a.y == u.y ? 0 : 1;
Error += a.z == u.z ? 0 : 1;
Error += a.w == u.w ? 0 : 1;
}
{
my_ivec4_aligned a;
a.b = glm::ivec4(1, 2, 3, 4);
my_ivec4_packed u;
u.b = a.b;
Error += a.b.x == u.b.x ? 0 : 1;
Error += a.b.y == u.b.y ? 0 : 1;
Error += a.b.z == u.b.z ? 0 : 1;
Error += a.b.w == u.b.w ? 0 : 1;
}
return Error;
}
static int test_ctor()
{
int Error = 0;
# if GLM_HAS_CONSTEXPR
{
constexpr glm::aligned_ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
{
constexpr glm::packed_ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
{
constexpr glm::ivec4 v(1);
Error += v.x == 1 ? 0 : 1;
Error += v.y == 1 ? 0 : 1;
Error += v.z == 1 ? 0 : 1;
Error += v.w == 1 ? 0 : 1;
}
# endif//GLM_HAS_CONSTEXPR
return Error;
}
static int test_aligned_ivec4()
{
int Error = 0;
glm::aligned_ivec4 const v(1, 2, 3, 4);
Error += glm::all(glm::equal(v, glm::aligned_ivec4(1, 2, 3, 4))) ? 0 : 1;
glm::aligned_ivec4 const u = v * 2;
Error += glm::all(glm::equal(u, glm::aligned_ivec4(2, 4, 6, 8))) ? 0 : 1;
return Error;
}
static int test_aligned_mat4()
{
int Error = 0;
glm::aligned_vec4 const u(1.f, 2.f, 3.f, 4.f);
Error += glm::all(glm::equal(u, glm::aligned_vec4(1.f, 2.f, 3.f, 4.f), 0.0001f)) ? 0 : 1;
glm::aligned_vec4 const v(1, 2, 3, 4);
Error += glm::all(glm::equal(v, glm::aligned_vec4(1.f, 2.f, 3.f, 4.f), 0.0001f)) ? 0 : 1;
glm::aligned_mat4 const m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
glm::aligned_mat4 const t = glm::transpose(m);
glm::aligned_mat4 const expected = glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
Error += glm::all(glm::equal(t, expected, 0.0001f)) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_ctor();
Error += test_copy_vec4();
Error += test_copy_vec3();
Error += test_splat_vec3();
Error += test_splat_vec4();
Error += test_copy_vec4_vec3();
Error += test_copy();
Error += test_copy_vec4();
Error += test_copy_vec3();
Error += test_copy_quat();
Error += test_aligned_ivec4();
Error += test_aligned_mat4();
return Error;
}
#else
int main()
{
return 0;
}
#endif
File diff suppressed because it is too large Load Diff
+387
View File
@@ -0,0 +1,387 @@
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/matrix_relational.hpp>
static int test_value_ptr_vec()
{
int Error = 0;
{
glm::vec2 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec3 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec4 v(1.0);
float * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec2 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec3 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec4 v(1.0);
double * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
return Error;
}
static int test_value_ptr_vec_const()
{
int Error = 0;
{
glm::vec2 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec3 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::vec4 const v(1.0);
float const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec2 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec3 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
{
glm::dvec4 const v(1.0);
double const * p = glm::value_ptr(v);
Error += p == &v[0] ? 0 : 1;
}
return Error;
}
static int test_value_ptr_mat()
{
int Error = 0;
{
glm::mat2x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x2 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x3 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x4 m(1.0);
float * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
return Error;
}
static int test_value_ptr_mat_const()
{
int Error = 0;
{
glm::mat2x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat2x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat3x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x2 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x3 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
{
glm::mat4x4 const m(1.0);
float const * p = glm::value_ptr(m);
Error += p == &m[0][0] ? 0 : 1;
}
return Error;
}
static int test_make_pointer_mat()
{
int Error = 0;
float ArrayA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
double ArrayB[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
glm::mat2x2 Mat2x2A = glm::make_mat2x2(ArrayA);
Error += glm::all(glm::equal(Mat2x2A, glm::mat2x2(0, 1, 2, 3), 0.001f)) ? 0 : 1;
glm::mat2x3 Mat2x3A = glm::make_mat2x3(ArrayA);
Error += glm::all(glm::equal(Mat2x3A, glm::mat2x3(0, 1, 2, 3, 4, 5), 0.001f)) ? 0 : 1;
glm::mat2x4 Mat2x4A = glm::make_mat2x4(ArrayA);
Error += glm::all(glm::equal(Mat2x4A, glm::mat2x4(0, 1, 2, 3, 4, 5, 6, 7), 0.001f)) ? 0 : 1;
glm::mat3x2 Mat3x2A = glm::make_mat3x2(ArrayA);
Error += glm::all(glm::equal(Mat3x2A, glm::mat3x2(0, 1, 2, 3, 4, 5), 0.001f)) ? 0 : 1;
glm::mat3x3 Mat3x3A = glm::make_mat3x3(ArrayA);
Error += glm::all(glm::equal(Mat3x3A, glm::mat3x3(0, 1, 2, 3, 4, 5, 6, 7, 8), 0.001f)) ? 0 : 1;
glm::mat3x4 Mat3x4A = glm::make_mat3x4(ArrayA);
Error += glm::all(glm::equal(Mat3x4A, glm::mat3x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), 0.001f)) ? 0 : 1;
glm::mat4x2 Mat4x2A = glm::make_mat4x2(ArrayA);
Error += glm::all(glm::equal(Mat4x2A, glm::mat4x2(0, 1, 2, 3, 4, 5, 6, 7), 0.001f)) ? 0 : 1;
glm::mat4x3 Mat4x3A = glm::make_mat4x3(ArrayA);
Error += glm::all(glm::equal(Mat4x3A, glm::mat4x3(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), 0.001f)) ? 0 : 1;
glm::mat4x4 Mat4x4A = glm::make_mat4x4(ArrayA);
Error += glm::all(glm::equal(Mat4x4A, glm::mat4x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), 0.001f)) ? 0 : 1;
glm::dmat2x2 Mat2x2B = glm::make_mat2x2(ArrayB);
Error += glm::all(glm::equal(Mat2x2B, glm::dmat2x2(0, 1, 2, 3), 0.001)) ? 0 : 1;
glm::dmat2x3 Mat2x3B = glm::make_mat2x3(ArrayB);
Error += glm::all(glm::equal(Mat2x3B, glm::dmat2x3(0, 1, 2, 3, 4, 5), 0.001)) ? 0 : 1;
glm::dmat2x4 Mat2x4B = glm::make_mat2x4(ArrayB);
Error += glm::all(glm::equal(Mat2x4B, glm::dmat2x4(0, 1, 2, 3, 4, 5, 6, 7), 0.001)) ? 0 : 1;
glm::dmat3x2 Mat3x2B = glm::make_mat3x2(ArrayB);
Error += glm::all(glm::equal(Mat3x2B, glm::dmat3x2(0, 1, 2, 3, 4, 5), 0.001)) ? 0 : 1;
glm::dmat3x3 Mat3x3B = glm::make_mat3x3(ArrayB);
Error += glm::all(glm::equal(Mat3x3B, glm::dmat3x3(0, 1, 2, 3, 4, 5, 6, 7, 8), 0.001)) ? 0 : 1;
glm::dmat3x4 Mat3x4B = glm::make_mat3x4(ArrayB);
Error += glm::all(glm::equal(Mat3x4B, glm::dmat3x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), 0.001)) ? 0 : 1;
glm::dmat4x2 Mat4x2B = glm::make_mat4x2(ArrayB);
Error += glm::all(glm::equal(Mat4x2B, glm::dmat4x2(0, 1, 2, 3, 4, 5, 6, 7), 0.001)) ? 0 : 1;
glm::dmat4x3 Mat4x3B = glm::make_mat4x3(ArrayB);
Error += glm::all(glm::equal(Mat4x3B, glm::dmat4x3(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), 0.001)) ? 0 : 1;
glm::dmat4x4 Mat4x4B = glm::make_mat4x4(ArrayB);
Error += glm::all(glm::equal(Mat4x4B, glm::dmat4x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), 0.001)) ? 0 : 1;
return Error;
}
static int test_make_pointer_vec()
{
int Error = 0;
float ArrayA[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int ArrayB[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
bool ArrayC[] = {true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false};
glm::vec2 Vec2A = glm::make_vec2(ArrayA);
Error += glm::all(glm::equal(Vec2A, glm::vec2(0, 1), 0.001f)) ? 0 : 1;
glm::vec3 Vec3A = glm::make_vec3(ArrayA);
Error += glm::all(glm::equal(Vec3A, glm::vec3(0, 1, 2), 0.001f)) ? 0 : 1;
glm::vec4 Vec4A = glm::make_vec4(ArrayA);
Error += glm::all(glm::equal(Vec4A, glm::vec4(0, 1, 2, 3), 0.001f)) ? 0 : 1;
glm::ivec2 Vec2B = glm::make_vec2(ArrayB);
Error += glm::all(glm::equal(Vec2B, glm::ivec2(0, 1))) ? 0 : 1;
glm::ivec3 Vec3B = glm::make_vec3(ArrayB);
Error += glm::all(glm::equal(Vec3B, glm::ivec3(0, 1, 2))) ? 0 : 1;
glm::ivec4 Vec4B = glm::make_vec4(ArrayB);
Error += glm::all(glm::equal(Vec4B, glm::ivec4(0, 1, 2, 3))) ? 0 : 1;
glm::bvec2 Vec2C = glm::make_vec2(ArrayC);
Error += glm::all(glm::equal(Vec2C, glm::bvec2(true, false))) ? 0 : 1;
glm::bvec3 Vec3C = glm::make_vec3(ArrayC);
Error += glm::all(glm::equal(Vec3C, glm::bvec3(true, false, true))) ? 0 : 1;
glm::bvec4 Vec4C = glm::make_vec4(ArrayC);
Error += glm::all(glm::equal(Vec4C, glm::bvec4(true, false, true, false))) ? 0 : 1;
return Error;
}
static int test_make_vec1()
{
int Error = 0;
glm::ivec1 const v1 = glm::make_vec1(glm::ivec1(2));
Error += v1 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v2 = glm::make_vec1(glm::ivec2(2));
Error += v2 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v3 = glm::make_vec1(glm::ivec3(2));
Error += v3 == glm::ivec1(2) ? 0 : 1;
glm::ivec1 const v4 = glm::make_vec1(glm::ivec4(2));
Error += v4 == glm::ivec1(2) ? 0 : 1;
return Error;
}
static int test_make_vec2()
{
int Error = 0;
glm::ivec2 const v1 = glm::make_vec2(glm::ivec1(2));
Error += v1 == glm::ivec2(2, 0) ? 0 : 1;
glm::ivec2 const v2 = glm::make_vec2(glm::ivec2(2));
Error += v2 == glm::ivec2(2, 2) ? 0 : 1;
glm::ivec2 const v3 = glm::make_vec2(glm::ivec3(2));
Error += v3 == glm::ivec2(2, 2) ? 0 : 1;
glm::ivec2 const v4 = glm::make_vec2(glm::ivec4(2));
Error += v4 == glm::ivec2(2, 2) ? 0 : 1;
return Error;
}
static int test_make_vec3()
{
int Error = 0;
glm::ivec3 const v1 = glm::make_vec3(glm::ivec1(2));
Error += v1 == glm::ivec3(2, 0, 0) ? 0 : 1;
glm::ivec3 const v2 = glm::make_vec3(glm::ivec2(2));
Error += v2 == glm::ivec3(2, 2, 0) ? 0 : 1;
glm::ivec3 const v3 = glm::make_vec3(glm::ivec3(2));
Error += v3 == glm::ivec3(2, 2, 2) ? 0 : 1;
glm::ivec3 const v4 = glm::make_vec3(glm::ivec4(2));
Error += v4 == glm::ivec3(2, 2, 2) ? 0 : 1;
return Error;
}
static int test_make_vec4()
{
int Error = 0;
glm::ivec4 const v1 = glm::make_vec4(glm::ivec1(2));
Error += v1 == glm::ivec4(2, 0, 0, 1) ? 0 : 1;
glm::ivec4 const v2 = glm::make_vec4(glm::ivec2(2));
Error += v2 == glm::ivec4(2, 2, 0, 1) ? 0 : 1;
glm::ivec4 const v3 = glm::make_vec4(glm::ivec3(2));
Error += v3 == glm::ivec4(2, 2, 2, 1) ? 0 : 1;
glm::ivec4 const v4 = glm::make_vec4(glm::ivec4(2));
Error += v4 == glm::ivec4(2, 2, 2, 2) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_make_vec1();
Error += test_make_vec2();
Error += test_make_vec3();
Error += test_make_vec4();
Error += test_make_pointer_vec();
Error += test_make_pointer_mat();
Error += test_value_ptr_vec();
Error += test_value_ptr_vec_const();
Error += test_value_ptr_mat();
Error += test_value_ptr_mat_const();
return Error;
}
+99
View File
@@ -0,0 +1,99 @@
#include <glm/gtc/ulp.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <limits>
static int test_ulp_float_dist()
{
int Error = 0;
float A = 1.0f;
float B = glm::next_float(A);
Error += glm::notEqual(A, B, 0) ? 0 : 1;
float C = glm::prev_float(B);
Error += glm::equal(A, C, 0) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == 1 ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
return Error;
}
static int test_ulp_float_step()
{
int Error = 0;
float A = 1.0f;
for(int i = 10; i < 1000; i *= 10)
{
float B = glm::next_float(A, i);
Error += glm::notEqual(A, B, 0) ? 0 : 1;
float C = glm::prev_float(B, i);
Error += glm::equal(A, C, 0) ? 0 : 1;
int D = glm::float_distance(A, B);
Error += D == i ? 0 : 1;
int E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
}
return Error;
}
static int test_ulp_double_dist()
{
int Error = 0;
double A = 1.0;
double B = glm::next_float(A);
Error += glm::notEqual(A, B, 0) ? 0 : 1;
double C = glm::prev_float(B);
Error += glm::equal(A, C, 0) ? 0 : 1;
glm::int64 const D = glm::float_distance(A, B);
Error += D == 1 ? 0 : 1;
glm::int64 const E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
return Error;
}
static int test_ulp_double_step()
{
int Error = 0;
double A = 1.0;
for(int i = 10; i < 1000; i *= 10)
{
double B = glm::next_float(A, i);
Error += glm::notEqual(A, B, 0) ? 0 : 1;
double C = glm::prev_float(B, i);
Error += glm::equal(A, C, 0) ? 0 : 1;
glm::int64 const D = glm::float_distance(A, B);
Error += D == i ? 0 : 1;
glm::int64 const E = glm::float_distance(A, C);
Error += E == 0 ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_ulp_float_dist();
Error += test_ulp_float_step();
Error += test_ulp_double_dist();
Error += test_ulp_double_step();
return Error;
}
@@ -0,0 +1,30 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-16
// Updated : 2011-05-27
// Licence : This source is under MIT licence
// File : test/gtc/type_ptr.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_FORCE_RADIANS
#include <glm/gtc/user_defined_type.hpp>
int test_make_pointer_vec()
{
int Error = 0;
glm::func();
//func();
return Error;
}
int main()
{
int Error = 0;
Error += test_make_pointer_vec();
return Error;
}
+8
View File
@@ -0,0 +1,8 @@
#include <glm/gtc/vec1.hpp>
int main()
{
int Error = 0;
return Error;
}