[ADD] template project with correct name
This commit is contained in:
246
lib/glm/test/CMakeLists.txt
Normal file
246
lib/glm/test/CMakeLists.txt
Normal file
@@ -0,0 +1,246 @@
|
||||
option(GLM_QUIET "No CMake Message" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
||||
option(BUILD_STATIC_LIBS "Build static library" ON)
|
||||
option(GLM_TEST_ENABLE_CXX_98 "Enable C++ 98" OFF)
|
||||
option(GLM_TEST_ENABLE_CXX_11 "Enable C++ 11" OFF)
|
||||
option(GLM_TEST_ENABLE_CXX_14 "Enable C++ 14" OFF)
|
||||
option(GLM_TEST_ENABLE_CXX_17 "Enable C++ 17" OFF)
|
||||
option(GLM_TEST_ENABLE_CXX_20 "Enable C++ 20" OFF)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(GLM_TEST_ENABLE_CXX_20)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
add_definitions(-DGLM_FORCE_CXX2A)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with C++20 features")
|
||||
endif()
|
||||
|
||||
elseif(GLM_TEST_ENABLE_CXX_17)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
add_definitions(-DGLM_FORCE_CXX17)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with C++17 features")
|
||||
endif()
|
||||
|
||||
elseif(GLM_TEST_ENABLE_CXX_14)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
add_definitions(-DGLM_FORCE_CXX14)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with C++14 features")
|
||||
endif()
|
||||
|
||||
elseif(GLM_TEST_ENABLE_CXX_11)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
add_definitions(-DGLM_FORCE_CXX11)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with C++11 features")
|
||||
endif()
|
||||
|
||||
elseif(GLM_TEST_ENABLE_CXX_98)
|
||||
set(CMAKE_CXX_STANDARD 98)
|
||||
add_definitions(-DGLM_FORCE_CXX98)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with C++98 features")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(GLM_TEST_ENABLE_LANG_EXTENSIONS "Enable language extensions" OFF)
|
||||
|
||||
option(GLM_DISABLE_AUTO_DETECTION "Enable language extensions" OFF)
|
||||
|
||||
if(GLM_DISABLE_AUTO_DETECTION)
|
||||
add_definitions(-DGLM_FORCE_PLATFORM_UNKNOWN -DGLM_FORCE_COMPILER_UNKNOWN -DGLM_FORCE_ARCH_UNKNOWN -DGLM_FORCE_CXX_UNKNOWN)
|
||||
endif()
|
||||
|
||||
if(GLM_TEST_ENABLE_LANG_EXTENSIONS)
|
||||
set(CMAKE_CXX_EXTENSIONS ON)
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
|
||||
add_compile_options(-fms-extensions)
|
||||
endif()
|
||||
message(STATUS "GLM: Build with C++ language extensions")
|
||||
else()
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/Za)
|
||||
if(MSVC15)
|
||||
add_compile_options(/permissive-)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(GLM_TEST_ENABLE_FAST_MATH "Enable fast math optimizations" OFF)
|
||||
if(GLM_TEST_ENABLE_FAST_MATH)
|
||||
if(NOT GLM_QUIET)
|
||||
message(STATUS "GLM: Build with fast math optimizations")
|
||||
endif()
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
|
||||
add_compile_options(-ffast-math)
|
||||
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/fp:fast)
|
||||
endif()
|
||||
else()
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/fp:precise)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(GLM_TEST_ENABLE "Build unit tests" ON)
|
||||
option(GLM_TEST_ENABLE_SIMD_SSE2 "Enable SSE2 optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_SSE3 "Enable SSE3 optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_SSSE3 "Enable SSSE3 optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_SSE4_1 "Enable SSE 4.1 optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_SSE4_2 "Enable SSE 4.2 optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_AVX "Enable AVX optimizations" OFF)
|
||||
option(GLM_TEST_ENABLE_SIMD_AVX2 "Enable AVX2 optimizations" OFF)
|
||||
option(GLM_TEST_FORCE_PURE "Force 'pure' instructions" OFF)
|
||||
|
||||
if(GLM_TEST_FORCE_PURE)
|
||||
add_definitions(-DGLM_FORCE_PURE)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
add_compile_options(-mfpmath=387)
|
||||
endif()
|
||||
message(STATUS "GLM: No SIMD instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_AVX2)
|
||||
add_definitions(-DGLM_FORCE_PURE)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-mavx2)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxAVX2)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/arch:AVX2)
|
||||
endif()
|
||||
message(STATUS "GLM: AVX2 instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_AVX)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-mavx)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxAVX)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/arch:AVX)
|
||||
endif()
|
||||
message(STATUS "GLM: AVX instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_SSE4_2)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-msse4.2)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxSSE4.2)
|
||||
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND NOT CMAKE_CL_64)
|
||||
add_compile_options(/arch:SSE2) # VC doesn't support SSE4.2
|
||||
endif()
|
||||
message(STATUS "GLM: SSE4.2 instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_SSE4_1)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-msse4.1)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxSSE4.1)
|
||||
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND NOT CMAKE_CL_64)
|
||||
add_compile_options(/arch:SSE2) # VC doesn't support SSE4.1
|
||||
endif()
|
||||
message(STATUS "GLM: SSE4.1 instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_SSSE3)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-mssse3)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxSSSE3)
|
||||
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND NOT CMAKE_CL_64)
|
||||
add_compile_options(/arch:SSE2) # VC doesn't support SSSE3
|
||||
endif()
|
||||
message(STATUS "GLM: SSSE3 instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_SSE3)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-msse3)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxSSE3)
|
||||
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND NOT CMAKE_CL_64)
|
||||
add_compile_options(/arch:SSE2) # VC doesn't support SSE3
|
||||
endif()
|
||||
message(STATUS "GLM: SSE3 instruction set")
|
||||
|
||||
elseif(GLM_TEST_ENABLE_SIMD_SSE2)
|
||||
add_definitions(-DGLM_FORCE_INTRINSICS)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-msse2)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
add_compile_options(/QxSSE2)
|
||||
elseif((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND NOT CMAKE_CL_64)
|
||||
add_compile_options(/arch:SSE2)
|
||||
endif()
|
||||
message(STATUS "GLM: SSE2 instruction set")
|
||||
endif()
|
||||
|
||||
# Compiler and default options
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if(NOT GLM_QUIET)
|
||||
message("GLM: Clang - ${CMAKE_CXX_COMPILER_ID} compiler")
|
||||
endif()
|
||||
|
||||
add_compile_options(-Werror -Weverything)
|
||||
add_compile_options(-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++11-long-long -Wno-padded -Wno-gnu-anonymous-struct -Wno-nested-anon-types)
|
||||
add_compile_options(-Wno-undefined-reinterpret-cast -Wno-sign-conversion -Wno-unused-variable -Wno-missing-prototypes -Wno-unreachable-code -Wno-missing-variable-declarations -Wno-sign-compare -Wno-global-constructors -Wno-unused-macros -Wno-format-nonliteral)
|
||||
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
if(NOT GLM_QUIET)
|
||||
message("GLM: GCC - ${CMAKE_CXX_COMPILER_ID} compiler")
|
||||
endif()
|
||||
|
||||
add_compile_options(-O2)
|
||||
add_compile_options(-Wno-long-long)
|
||||
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
|
||||
if(NOT GLM_QUIET)
|
||||
message("GLM: Intel - ${CMAKE_CXX_COMPILER_ID} compiler")
|
||||
endif()
|
||||
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
if(NOT GLM_QUIET)
|
||||
message("GLM: Visual C++ - ${CMAKE_CXX_COMPILER_ID} compiler")
|
||||
endif()
|
||||
|
||||
add_compile_options(/W4 /WX)
|
||||
add_compile_options(/wd4309 /wd4324 /wd4389 /wd4127 /wd4267 /wd4146 /wd4201 /wd4464 /wd4514 /wd4701 /wd4820 /wd4365)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
function(glmCreateTestGTC NAME)
|
||||
set(SAMPLE_NAME test-${NAME})
|
||||
add_executable(${SAMPLE_NAME} ${NAME}.cpp)
|
||||
|
||||
add_test(
|
||||
NAME ${SAMPLE_NAME}
|
||||
COMMAND $<TARGET_FILE:${SAMPLE_NAME}> )
|
||||
target_link_libraries(${SAMPLE_NAME} PRIVATE glm::glm)
|
||||
endfunction()
|
||||
|
||||
if(GLM_TEST_ENABLE)
|
||||
add_subdirectory(bug)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(ext)
|
||||
add_subdirectory(gtc)
|
||||
add_subdirectory(gtx)
|
||||
add_subdirectory(perf)
|
||||
endif()
|
||||
|
||||
|
||||
1
lib/glm/test/bug/CMakeLists.txt
Normal file
1
lib/glm/test/bug/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
glmCreateTestGTC(bug_ms_vec_static)
|
||||
31
lib/glm/test/bug/bug_ms_vec_static.cpp
Normal file
31
lib/glm/test/bug/bug_ms_vec_static.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#if GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE
|
||||
struct vec2;
|
||||
|
||||
struct _swizzle
|
||||
{
|
||||
char _buffer[1];
|
||||
};
|
||||
|
||||
struct vec2
|
||||
{
|
||||
GLM_CONSTEXPR vec2() :
|
||||
x(0), y(0)
|
||||
{}
|
||||
|
||||
union
|
||||
{
|
||||
struct { float x, y; };
|
||||
struct { _swizzle xx; };
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
// Visual C++ has a bug generating the error: fatal error C1001: An internal error has occurred in the compiler.
|
||||
// vec2 Bar;
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
52
lib/glm/test/core/CMakeLists.txt
Normal file
52
lib/glm/test/core/CMakeLists.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
glmCreateTestGTC(core_cpp_constexpr)
|
||||
glmCreateTestGTC(core_cpp_defaulted_ctor)
|
||||
glmCreateTestGTC(core_force_aligned_gentypes)
|
||||
glmCreateTestGTC(core_force_ctor_init)
|
||||
glmCreateTestGTC(core_force_cxx03)
|
||||
glmCreateTestGTC(core_force_cxx98)
|
||||
glmCreateTestGTC(core_force_arch_unknown)
|
||||
glmCreateTestGTC(core_force_compiler_unknown)
|
||||
glmCreateTestGTC(core_force_cxx_unknown)
|
||||
glmCreateTestGTC(core_force_explicit_ctor)
|
||||
glmCreateTestGTC(core_force_inline)
|
||||
glmCreateTestGTC(core_force_platform_unknown)
|
||||
glmCreateTestGTC(core_force_pure)
|
||||
glmCreateTestGTC(core_force_unrestricted_gentype)
|
||||
glmCreateTestGTC(core_force_xyzw_only)
|
||||
glmCreateTestGTC(core_force_quat_wxyz)
|
||||
glmCreateTestGTC(core_type_aligned)
|
||||
glmCreateTestGTC(core_type_cast)
|
||||
glmCreateTestGTC(core_type_ctor)
|
||||
glmCreateTestGTC(core_type_int)
|
||||
glmCreateTestGTC(core_type_length)
|
||||
glmCreateTestGTC(core_type_mat2x2)
|
||||
glmCreateTestGTC(core_type_mat2x3)
|
||||
glmCreateTestGTC(core_type_mat2x4)
|
||||
glmCreateTestGTC(core_type_mat3x2)
|
||||
glmCreateTestGTC(core_type_mat3x3)
|
||||
glmCreateTestGTC(core_type_mat3x4)
|
||||
glmCreateTestGTC(core_type_mat4x2)
|
||||
glmCreateTestGTC(core_type_mat4x3)
|
||||
glmCreateTestGTC(core_type_mat4x4)
|
||||
glmCreateTestGTC(core_type_vec1)
|
||||
glmCreateTestGTC(core_type_vec2)
|
||||
glmCreateTestGTC(core_type_vec3)
|
||||
glmCreateTestGTC(core_type_vec4)
|
||||
glmCreateTestGTC(core_func_common)
|
||||
glmCreateTestGTC(core_func_exponential)
|
||||
glmCreateTestGTC(core_func_geometric)
|
||||
glmCreateTestGTC(core_func_integer)
|
||||
glmCreateTestGTC(core_func_integer_bit_count)
|
||||
glmCreateTestGTC(core_func_integer_find_lsb)
|
||||
glmCreateTestGTC(core_func_integer_find_msb)
|
||||
glmCreateTestGTC(core_func_matrix)
|
||||
glmCreateTestGTC(core_func_noise)
|
||||
glmCreateTestGTC(core_func_packing)
|
||||
glmCreateTestGTC(core_func_trigonometric)
|
||||
glmCreateTestGTC(core_func_vector_relational)
|
||||
glmCreateTestGTC(core_func_swizzle)
|
||||
glmCreateTestGTC(core_setup_force_cxx98)
|
||||
glmCreateTestGTC(core_setup_force_size_t_length)
|
||||
glmCreateTestGTC(core_setup_message)
|
||||
glmCreateTestGTC(core_setup_platform_unknown)
|
||||
glmCreateTestGTC(core_setup_precision)
|
||||
750
lib/glm/test/core/core_cpp_constexpr.cpp
Normal file
750
lib/glm/test/core/core_cpp_constexpr.cpp
Normal file
@@ -0,0 +1,750 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_int1.hpp>
|
||||
#include <glm/ext/vector_bool1.hpp>
|
||||
#include <glm/ext/vector_bool4.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
|
||||
static int test_vec1()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
constexpr glm::bvec1 B(true);
|
||||
constexpr bool A = glm::all(B);
|
||||
static_assert(A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::bvec1 D(true);
|
||||
constexpr bool C = glm::any(D);
|
||||
static_assert(C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec2 C(true);
|
||||
constexpr glm::bvec2 B(true);
|
||||
static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 O(glm::ivec1(1));
|
||||
static_assert(glm::ivec1(1) == O, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 P(1);
|
||||
static_assert(glm::ivec1(1) == P, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 L(glm::ivec2(1, 2));
|
||||
static_assert(glm::ivec1(1) == L, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 M(glm::ivec3(1, 2, 3));
|
||||
static_assert(glm::ivec1(1) == M, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 N(glm::ivec4(1, 2, 3, 4));
|
||||
static_assert(glm::ivec1(1) == N, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec1 A1(true);
|
||||
constexpr glm::bvec1 A2(true);
|
||||
constexpr glm::bvec1 B1(false);
|
||||
constexpr glm::bvec1 B2(false);
|
||||
static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
|
||||
static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
constexpr glm::ivec1 B = A + 1;
|
||||
constexpr glm::ivec1 C(3);
|
||||
static_assert(A + B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D = +A;
|
||||
static_assert(D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(3);
|
||||
constexpr glm::ivec1 B = A - 1;
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A - B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D = -A;
|
||||
static_assert(-D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(3);
|
||||
constexpr glm::ivec1 B = A * 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B * C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(3);
|
||||
constexpr glm::ivec1 B = A / 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B / C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(3);
|
||||
constexpr glm::ivec1 B = A % 2;
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D(2);
|
||||
static_assert(A % D == C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
constexpr glm::ivec1 B = A & 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A & C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
constexpr glm::ivec1 B = A | 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A | C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
constexpr glm::ivec1 B = A ^ 0;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(0);
|
||||
static_assert(A == (A ^ C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(1);
|
||||
constexpr glm::ivec1 B = A << 1;
|
||||
static_assert(B == glm::ivec1(2), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == (A << C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(2);
|
||||
constexpr glm::ivec1 B = A >> 1;
|
||||
static_assert(B == glm::ivec1(1), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == A >> C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec1 A(~0);
|
||||
constexpr glm::ivec1 B = ~A;
|
||||
static_assert(A == ~B, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
constexpr glm::bvec2 B(true);
|
||||
constexpr bool A = glm::all(B);
|
||||
static_assert(A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::bvec2 D(true, false);
|
||||
constexpr bool C = glm::any(D);
|
||||
static_assert(C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec2 C(true);
|
||||
constexpr glm::bvec2 B(true, false);
|
||||
static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 O(glm::ivec1(1));
|
||||
static_assert(glm::ivec2(1) == O, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 A(1);
|
||||
static_assert(glm::ivec2(1) == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 F(glm::ivec1(1), glm::ivec1(2));
|
||||
static_assert(glm::ivec2(1, 2) == F, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 G(1, glm::ivec1(2));
|
||||
static_assert(glm::ivec2(1, 2) == G, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 H(glm::ivec1(1), 2);
|
||||
static_assert(glm::ivec2(1, 2) == H, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 I(1, 2);
|
||||
static_assert(glm::ivec2(1, 2) == I, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 L(glm::ivec2(1, 2));
|
||||
static_assert(glm::ivec2(1, 2) == L, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 M(glm::ivec3(1, 2, 3));
|
||||
static_assert(glm::ivec2(1, 2) == M, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 N(glm::ivec4(1, 2, 3, 4));
|
||||
static_assert(glm::ivec2(1, 2) == N, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec2 A1(true);
|
||||
constexpr glm::bvec2 A2(true);
|
||||
constexpr glm::bvec2 B1(false);
|
||||
constexpr glm::bvec2 B2(false);
|
||||
static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
|
||||
static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A + 1;
|
||||
constexpr glm::ivec2 C(3);
|
||||
static_assert(A + B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 D = +A;
|
||||
static_assert(D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(3);
|
||||
constexpr glm::ivec2 B = A - 1;
|
||||
constexpr glm::ivec2 C(1);
|
||||
static_assert(A - B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 D = -A;
|
||||
static_assert(-D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(3);
|
||||
constexpr glm::ivec2 B = A * 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 C(1);
|
||||
static_assert(B * C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(3);
|
||||
constexpr glm::ivec2 B = A / 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec2 C(1);
|
||||
static_assert(B / C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(3);
|
||||
constexpr glm::ivec2 B = A % 2;
|
||||
constexpr glm::ivec2 C(1);
|
||||
static_assert(B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D(2);
|
||||
static_assert(A % D == C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A & 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A & C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A | 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A | C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A ^ 0;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(0);
|
||||
static_assert(A == (A ^ C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(1);
|
||||
constexpr glm::ivec2 B = A << 1;
|
||||
static_assert(B == glm::ivec2(2), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == (A << C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(2);
|
||||
constexpr glm::ivec2 B = A >> 1;
|
||||
static_assert(B == glm::ivec2(1), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == A >> C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec2 A(~0);
|
||||
constexpr glm::ivec2 B = ~A;
|
||||
static_assert(A == ~B, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec3()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
constexpr glm::bvec3 B(true);
|
||||
constexpr bool A = glm::all(B);
|
||||
static_assert(A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::bvec3 D(true, false, true);
|
||||
constexpr bool C = glm::any(D);
|
||||
static_assert(C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec3 C(true);
|
||||
constexpr glm::bvec3 B(true, false, true);
|
||||
static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 O(glm::ivec1(1));
|
||||
static_assert(glm::ivec3(1) == O, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 A(1);
|
||||
static_assert(glm::ivec3(1) == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 B(glm::ivec2(1, 2), 3);
|
||||
static_assert(glm::ivec3(1, 2, 3) == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 C(1, glm::ivec2(2, 3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 D(glm::ivec1(1), glm::ivec2(2, 3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == D, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 E(glm::ivec2(1, 2), glm::ivec1(3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == E, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 F(glm::ivec1(1), glm::ivec1(2), glm::ivec1(3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == F, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 G(1, glm::ivec1(2), glm::ivec1(3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == G, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 H(glm::ivec1(1), 2, glm::ivec1(3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == H, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 I(1, 2, glm::ivec1(3));
|
||||
static_assert(glm::ivec3(1, 2, 3) == I, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 J(glm::ivec1(1), glm::ivec1(2), 3);
|
||||
static_assert(glm::ivec3(1, 2, 3) == J, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 K(1, glm::ivec1(2), 3);
|
||||
static_assert(glm::ivec3(1, 2, 3) == K, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 L(glm::ivec1(1), 2, 3);
|
||||
static_assert(glm::ivec3(1, 2, 3) == L, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 M(1, 2, 3);
|
||||
static_assert(glm::ivec3(1, 2, 3) == M, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 N(glm::ivec4(1, 2, 3, 4));
|
||||
static_assert(glm::ivec3(1, 2, 3) == N, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 const A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec3 A1(true);
|
||||
constexpr glm::bvec3 A2(true);
|
||||
constexpr glm::bvec3 B1(false);
|
||||
constexpr glm::bvec3 B2(false);
|
||||
static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
|
||||
static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(1);
|
||||
constexpr glm::ivec3 B = A + 1;
|
||||
constexpr glm::ivec3 C(3);
|
||||
static_assert(A + B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 D = +A;
|
||||
static_assert(D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(3);
|
||||
constexpr glm::ivec3 B = A - 1;
|
||||
constexpr glm::ivec3 C(1);
|
||||
static_assert(A - B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 D = -A;
|
||||
static_assert(-D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(3);
|
||||
constexpr glm::ivec3 B = A * 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 C(1);
|
||||
static_assert(B * C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(3);
|
||||
constexpr glm::ivec3 B = A / 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec3 C(1);
|
||||
static_assert(B / C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(3);
|
||||
constexpr glm::ivec3 B = A % 2;
|
||||
constexpr glm::ivec3 C(1);
|
||||
static_assert(B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D(2);
|
||||
static_assert(A % D == C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(1);
|
||||
constexpr glm::ivec3 B = A & 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A & C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(1);
|
||||
constexpr glm::ivec3 B = A | 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A | C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(1);
|
||||
constexpr glm::ivec3 B = A ^ 0;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(0);
|
||||
static_assert(A == (A ^ C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(1);
|
||||
constexpr glm::ivec3 B = A << 1;
|
||||
static_assert(B == glm::ivec3(2), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == (A << C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(2);
|
||||
constexpr glm::ivec3 B = A >> 1;
|
||||
static_assert(B == glm::ivec3(1), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == A >> C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec3 A(~0);
|
||||
constexpr glm::ivec3 B = ~A;
|
||||
static_assert(A == ~B, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
constexpr glm::bvec4 B(true);
|
||||
constexpr bool A = glm::all(B);
|
||||
static_assert(A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::bvec4 D(true, false, true, false);
|
||||
constexpr bool C = glm::any(D);
|
||||
static_assert(C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec4 C(true);
|
||||
constexpr glm::bvec4 B(true, false, true, false);
|
||||
static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 O(glm::ivec4(1));
|
||||
static_assert(glm::ivec4(1) == O, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 A(1);
|
||||
static_assert(glm::ivec4(1) == A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 N(glm::ivec4(1, 2, 3, 4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == N, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(glm::ivec3(1, 2, 3), 4);
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == A, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 B(glm::ivec2(1, 2), glm::ivec2(3, 4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 C(1, glm::ivec3(2, 3, 4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 D(glm::ivec1(1), glm::ivec2(2, 3), glm::ivec1(4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == D, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 E(glm::ivec2(1, 2), glm::ivec1(3), glm::ivec1(4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == E, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 F(glm::ivec1(1), glm::ivec1(2), glm::ivec2(3, 4));
|
||||
static_assert(glm::ivec4(1, 2, 3, 4) == F, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
static_assert(A[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr");
|
||||
static_assert(glm::ivec4::length() == 4, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::bvec4 A1(true);
|
||||
constexpr glm::bvec4 A2(true);
|
||||
constexpr glm::bvec4 B1(false);
|
||||
constexpr glm::bvec4 B2(false);
|
||||
static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
|
||||
static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
constexpr glm::ivec4 B = A + 1;
|
||||
constexpr glm::ivec4 C(3);
|
||||
static_assert(A + B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 D = +A;
|
||||
static_assert(D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(3);
|
||||
constexpr glm::ivec4 B = A - 1;
|
||||
constexpr glm::ivec4 C(1);
|
||||
static_assert(A - B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 D = -A;
|
||||
static_assert(-D == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(3);
|
||||
constexpr glm::ivec4 B = A * 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 C(1);
|
||||
static_assert(B * C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(3);
|
||||
constexpr glm::ivec4 B = A / 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec4 C(1);
|
||||
static_assert(B / C == A, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(3);
|
||||
constexpr glm::ivec4 B = A % 2;
|
||||
constexpr glm::ivec4 C(1);
|
||||
static_assert(B == C, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 D(2);
|
||||
static_assert(A % D == C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
constexpr glm::ivec4 B = A & 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A & C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
constexpr glm::ivec4 B = A | 1;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(A == (A | C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
constexpr glm::ivec4 B = A ^ 0;
|
||||
static_assert(A == B, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(0);
|
||||
static_assert(A == (A ^ C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(1);
|
||||
constexpr glm::ivec4 B = A << 1;
|
||||
static_assert(B == glm::ivec4(2), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == (A << C), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(2);
|
||||
constexpr glm::ivec4 B = A >> 1;
|
||||
static_assert(B == glm::ivec4(1), "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::ivec1 C(1);
|
||||
static_assert(B == A >> C, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
{
|
||||
constexpr glm::ivec4 A(~0);
|
||||
constexpr glm::ivec4 B = ~A;
|
||||
static_assert(A == ~B, "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_quat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
|
||||
static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::quat(1.0f, 0.0f, 0.0f, 0.0f).w > 0.0f, "GLM: Failed constexpr");
|
||||
|
||||
glm::quat constexpr Q = glm::identity<glm::quat>();
|
||||
static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat2x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
#endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
Error += test_vec1();
|
||||
Error += test_vec2();
|
||||
Error += test_vec3();
|
||||
Error += test_vec4();
|
||||
Error += test_quat();
|
||||
Error += test_mat2x2();
|
||||
# endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
145
lib/glm/test/core/core_cpp_defaulted_ctor.cpp
Normal file
145
lib/glm/test/core/core_cpp_defaulted_ctor.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <cstring>
|
||||
|
||||
static int test_vec_memcpy()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec1 const A = glm::ivec1(76);
|
||||
glm::ivec1 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::ivec1));
|
||||
Error += B == A ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 const A = glm::ivec2(76);
|
||||
glm::ivec2 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::ivec2));
|
||||
Error += B == A ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A = glm::ivec3(76);
|
||||
glm::ivec3 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::ivec3));
|
||||
Error += B == A ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A = glm::ivec4(76);
|
||||
glm::ivec4 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::ivec4));
|
||||
Error += B == A ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat_memcpy()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat2x2 const A = glm::mat2x2(76);
|
||||
glm::mat2x2 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat2x2));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2x3 const A = glm::mat2x3(76);
|
||||
glm::mat2x3 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat2x3));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2x4 const A = glm::mat2x4(76);
|
||||
glm::mat2x4 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat2x4));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x2 const A = glm::mat3x2(76);
|
||||
glm::mat3x2 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat3x2));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x3 const A = glm::mat3x3(76);
|
||||
glm::mat3x3 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat3x3));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x4 const A = glm::mat3x4(76);
|
||||
glm::mat3x4 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat3x4));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x2 const A = glm::mat4x2(76);
|
||||
glm::mat4x2 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat4x2));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x3 const A = glm::mat4x3(76);
|
||||
glm::mat4x3 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat4x3));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x4 const A = glm::mat4x4(76);
|
||||
glm::mat4x4 B;
|
||||
std::memcpy(&B, &A, sizeof(glm::mat4x4));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_quat_memcpy()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::quat const A = glm::quat(1, 0, 0, 0);
|
||||
glm::quat B;
|
||||
std::memcpy(&B, &A, sizeof(glm::quat));
|
||||
Error += glm::all(glm::equal(B, A, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
#endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
Error += test_vec_memcpy();
|
||||
Error += test_mat_memcpy();
|
||||
Error += test_quat_memcpy();
|
||||
# endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
10
lib/glm/test/core/core_force_aligned_gentypes.cpp
Normal file
10
lib/glm/test/core/core_force_aligned_gentypes.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_arch_unknown.cpp
Normal file
14
lib/glm/test/core/core_force_arch_unknown.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_ARCH_UNKNOWN
|
||||
# define GLM_FORCE_ARCH_UNKNOWN
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_compiler_unknown.cpp
Normal file
14
lib/glm/test/core/core_force_compiler_unknown.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_COMPILER_UNKNOWN
|
||||
# define GLM_FORCE_COMPILER_UNKNOWN
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
139
lib/glm/test/core/core_force_ctor_init.cpp
Normal file
139
lib/glm/test/core/core_force_ctor_init.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#define GLM_FORCE_CTOR_INIT
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
static int test_vec()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec1 V1;
|
||||
Error += glm::all(glm::equal(V1, glm::vec1(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dvec1 U1;
|
||||
Error += glm::all(glm::equal(U1, glm::dvec1(0), glm::epsilon<double>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 V2;
|
||||
Error += glm::all(glm::equal(V2, glm::vec2(0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dvec2 U2;
|
||||
Error += glm::all(glm::equal(U2, glm::dvec2(0, 0), glm::epsilon<double>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 V3;
|
||||
Error += glm::all(glm::equal(V3, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dvec3 U3;
|
||||
Error += glm::all(glm::equal(U3, glm::dvec3(0, 0, 0), glm::epsilon<double>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 V4;
|
||||
Error += glm::all(glm::equal(V4, glm::vec4(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dvec4 U4;
|
||||
Error += glm::all(glm::equal(U4, glm::dvec4(0, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat2x2 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat2x2(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat2x2 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat2x2(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2x3 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat2x3(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat2x3 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat2x3(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2x4 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat2x4(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat2x4 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat2x4(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x2 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat3x2(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat3x2 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat3x2(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x3 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat3x3(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat3x3 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat3x3(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x4 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat3x4(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat3x4 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat3x4(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x2 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat4x2(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat4x2 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat4x2(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x3 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat4x3(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat4x3 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat4x3(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4x4 F;
|
||||
Error += glm::all(glm::equal(F, glm::mat4x4(1), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dmat4x4 D;
|
||||
Error += glm::all(glm::equal(D, glm::dmat4x4(1), glm::epsilon<double>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_qua()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat F;
|
||||
Error += glm::all(glm::equal(F, glm::quat(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::dquat D;
|
||||
Error += glm::all(glm::equal(D, glm::dquat(1, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec();
|
||||
Error += test_mat();
|
||||
Error += test_qua();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_cxx03.cpp
Normal file
14
lib/glm/test/core/core_force_cxx03.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_CXX03
|
||||
# define GLM_FORCE_CXX03
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_cxx98.cpp
Normal file
14
lib/glm/test/core/core_force_cxx98.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_CXX98
|
||||
# define GLM_FORCE_CXX98
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_cxx_unknown.cpp
Normal file
14
lib/glm/test/core/core_force_cxx_unknown.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_CXX_UNKNOWN
|
||||
# define GLM_FORCE_CXX_UNKNOWN
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_force_depth_zero_to_one.cpp
Normal file
12
lib/glm/test/core/core_force_depth_zero_to_one.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
17
lib/glm/test/core/core_force_explicit_ctor.cpp
Normal file
17
lib/glm/test/core/core_force_explicit_ctor.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#define GLM_FORCE_EXPLICIT_CTOR
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec4 B(1);
|
||||
Error += B == glm::ivec4(1) ? 0 : 1;
|
||||
|
||||
//glm::vec4 A = B;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_force_inline.cpp
Normal file
12
lib/glm/test/core/core_force_inline.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#define GLM_FORCE_INLINE
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_force_left_handed.cpp
Normal file
12
lib/glm/test/core/core_force_left_handed.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#define GLM_FORCE_LEFT_HANDED
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
14
lib/glm/test/core/core_force_platform_unknown.cpp
Normal file
14
lib/glm/test/core/core_force_platform_unknown.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef GLM_FORCE_PLATFORM_UNKNOWN
|
||||
# define GLM_FORCE_PLATFORM_UNKNOWN
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
434
lib/glm/test/core/core_force_pure.cpp
Normal file
434
lib/glm/test/core/core_force_pure.cpp
Normal file
@@ -0,0 +1,434 @@
|
||||
#ifndef GLM_FORCE_PURE
|
||||
# define GLM_FORCE_PURE
|
||||
#endif//GLM_FORCE_PURE
|
||||
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
static int test_vec4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec4 A(1, 2, 3, 4);
|
||||
glm::ivec4 B(A);
|
||||
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
}
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::vec4 a{ 0, 1, 2, 3 };
|
||||
std::vector<glm::vec4> v = {
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 0, 1}};
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec4 a{ 0, 1, 2, 3 };
|
||||
std::vector<glm::dvec4> v = {
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 0, 1}};
|
||||
}
|
||||
#endif
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A.xyzw;
|
||||
glm::ivec4 C(A.xyzw);
|
||||
glm::ivec4 D(A.xyzw());
|
||||
glm::ivec4 E(A.x, A.yzw);
|
||||
glm::ivec4 F(A.x, A.yzw());
|
||||
glm::ivec4 G(A.xyz, A.w);
|
||||
glm::ivec4 H(A.xyz(), A.w);
|
||||
glm::ivec4 I(A.xy, A.zw);
|
||||
glm::ivec4 J(A.xy(), A.zw());
|
||||
glm::ivec4 K(A.x, A.y, A.zw);
|
||||
glm::ivec4 L(A.x, A.yz, A.w);
|
||||
glm::ivec4 M(A.xy, A.z, A.w);
|
||||
|
||||
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE
|
||||
{
|
||||
glm::ivec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A.xyzw();
|
||||
glm::ivec4 C(A.xyzw());
|
||||
glm::ivec4 D(A.xyzw());
|
||||
glm::ivec4 E(A.x, A.yzw());
|
||||
glm::ivec4 F(A.x, A.yzw());
|
||||
glm::ivec4 G(A.xyz(), A.w);
|
||||
glm::ivec4 H(A.xyz(), A.w);
|
||||
glm::ivec4 I(A.xy(), A.zw());
|
||||
glm::ivec4 J(A.xy(), A.zw());
|
||||
glm::ivec4 K(A.x, A.y, A.zw());
|
||||
glm::ivec4 L(A.x, A.yz(), A.w);
|
||||
glm::ivec4 M(A.xy(), A.z, A.w);
|
||||
|
||||
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE
|
||||
|
||||
{
|
||||
glm::ivec4 A(1);
|
||||
glm::ivec4 B(1, 1, 1, 1);
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::ivec4> Tests;
|
||||
Tests.push_back(glm::ivec4(glm::ivec2(1, 2), 3, 4));
|
||||
Tests.push_back(glm::ivec4(1, glm::ivec2(2, 3), 4));
|
||||
Tests.push_back(glm::ivec4(1, 2, glm::ivec2(3, 4)));
|
||||
Tests.push_back(glm::ivec4(glm::ivec3(1, 2, 3), 4));
|
||||
Tests.push_back(glm::ivec4(1, glm::ivec3(2, 3, 4)));
|
||||
Tests.push_back(glm::ivec4(glm::ivec2(1, 2), glm::ivec2(3, 4)));
|
||||
Tests.push_back(glm::ivec4(1, 2, 3, 4));
|
||||
Tests.push_back(glm::ivec4(glm::ivec4(1, 2, 3, 4)));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
Error += Tests[i] == glm::ivec4(1, 2, 3, 4) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_bvec4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::bvec4 const A(true);
|
||||
glm::bvec4 const B(true);
|
||||
glm::bvec4 const C(false);
|
||||
glm::bvec4 const D = A && B;
|
||||
glm::bvec4 const E = A && C;
|
||||
glm::bvec4 const F = A || C;
|
||||
|
||||
Error += D == glm::bvec4(true) ? 0 : 1;
|
||||
Error += E == glm::bvec4(false) ? 0 : 1;
|
||||
Error += F == glm::bvec4(true) ? 0 : 1;
|
||||
|
||||
bool const G = A == C;
|
||||
bool const H = A != C;
|
||||
|
||||
Error += !G ? 0 : 1;
|
||||
Error += H ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec4 A(1);
|
||||
glm::ivec4 B(1);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 const A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 const B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
glm::vec4 const C = A + B;
|
||||
Error += glm::all(glm::equal(C, glm::vec4(5, 7, 9, 11), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 D = B - A;
|
||||
Error += glm::all(glm::equal(D, glm::vec4(3, 3, 3, 3), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = A * B;
|
||||
Error += glm::all(glm::equal(E, glm::vec4(4, 10, 18, 28), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 F = B / A;
|
||||
Error += glm::all(glm::equal(F, glm::vec4(4, 2.5, 2, 7.0f / 4.0f), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 G = A + 1.0f;
|
||||
Error += glm::all(glm::equal(G, glm::vec4(2, 3, 4, 5), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 H = B - 1.0f;
|
||||
Error += glm::all(glm::equal(H, glm::vec4(3, 4, 5, 6), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 I = A * 2.0f;
|
||||
Error += glm::all(glm::equal(I, glm::vec4(2, 4, 6, 8), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 J = B / 2.0f;
|
||||
Error += glm::all(glm::equal(J, glm::vec4(2, 2.5, 3, 3.5), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 K = 1.0f + A;
|
||||
Error += glm::all(glm::equal(K, glm::vec4(2, 3, 4, 5), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 L = 1.0f - B;
|
||||
Error += glm::all(glm::equal(L, glm::vec4(-3, -4, -5, -6), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 M = 2.0f * A;
|
||||
Error += glm::all(glm::equal(M, glm::vec4(2, 4, 6, 8), 0.001f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 const N = 2.0f / B;
|
||||
Error += glm::all(glm::equal(N, glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0), 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A += B;
|
||||
Error += A == glm::ivec4(5, 7, 9, 11) ? 0 : 1;
|
||||
|
||||
A += 1;
|
||||
Error += A == glm::ivec4(6, 8, 10, 12) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::ivec4(3, 3, 3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1;
|
||||
Error += B == glm::ivec4(2, 2, 2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::ivec4(4, 10, 18, 28) ? 0 : 1;
|
||||
|
||||
A *= 2;
|
||||
Error += A == glm::ivec4(8, 20, 36, 56) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 4.0f, 6.0f, 8.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::ivec4(4, 2, 2, 2) ? 0 : 1;
|
||||
|
||||
B /= 2;
|
||||
Error += B == glm::ivec4(2, 1, 1, 1) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(2);
|
||||
|
||||
B /= B.y;
|
||||
Error += B == glm::ivec4(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = -A;
|
||||
Error += B == glm::ivec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = --A;
|
||||
Error += B == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A--;
|
||||
Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = ++A;
|
||||
Error += B == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A++;
|
||||
Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_equal()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::uvec4 const A(1, 2, 3, 4);
|
||||
glm::uvec4 const B(1, 2, 3, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A != B ? 1 : 0;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
glm::ivec4 const B(1, 2, 3, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A != B ? 1 : 0;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::lowp_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::mediump_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1;
|
||||
Error += 16 == sizeof(glm::mediump_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::lowp_dvec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::mediump_dvec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1;
|
||||
Error += 32 == sizeof(glm::highp_dvec4) ? 0 : 1;
|
||||
Error += glm::vec4().length() == 4 ? 0 : 1;
|
||||
Error += glm::dvec4().length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_swizzle_partial()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
glm::ivec4 A(1, 2, 3, 4);
|
||||
|
||||
{
|
||||
glm::ivec4 B(A.xy, A.zw);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(A.xy, 3, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(1, A.yz, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(1, 2, A.zw);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 B(A.xyz, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(1, A.yzw);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_operator_increment()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::ivec4 v0(1);
|
||||
glm::ivec4 v1(v0);
|
||||
glm::ivec4 v2(v0);
|
||||
glm::ivec4 v3 = ++v1;
|
||||
glm::ivec4 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_simd()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const a(std::clock(), std::clock(), std::clock(), std::clock());
|
||||
glm::vec4 const b(std::clock(), std::clock(), std::clock(), std::clock());
|
||||
|
||||
glm::vec4 const c(b * a);
|
||||
glm::vec4 const d(a + c);
|
||||
|
||||
Error += glm::all(glm::greaterThanEqual(d, glm::vec4(0))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec4_ctor();
|
||||
Error += test_bvec4_ctor();
|
||||
Error += test_vec4_size();
|
||||
Error += test_vec4_operators();
|
||||
Error += test_vec4_equal();
|
||||
Error += test_vec4_swizzle_partial();
|
||||
Error += test_vec4_simd();
|
||||
Error += test_operator_increment();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
13
lib/glm/test/core/core_force_quat_wxyz.cpp
Normal file
13
lib/glm/test/core/core_force_quat_wxyz.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#define GLM_FORCE_QUAT_DATA_WXYZ
|
||||
#define GLM_FORCE_INLINE
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_force_size_t_length.cpp
Normal file
12
lib/glm/test/core/core_force_size_t_length.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#define GLM_FORCE_SIZE_T_LENGTH
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_force_unrestricted_gentype.cpp
Normal file
12
lib/glm/test/core/core_force_unrestricted_gentype.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#define GLM_FORCE_UNRESTRICTED_GENTYPE
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
58
lib/glm/test/core/core_force_xyzw_only.cpp
Normal file
58
lib/glm/test/core/core_force_xyzw_only.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#define GLM_FORCE_XYZW_ONLY
|
||||
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
|
||||
static int test_comp()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec1 const A(1);
|
||||
Error += A.x == 1 ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 const A(1, 2);
|
||||
Error += A.x == 1 ? 0 : 1;
|
||||
Error += A.y == 2 ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
Error += A.x == 1 ? 0 : 1;
|
||||
Error += A.y == 2 ? 0 : 1;
|
||||
Error += A.z == 3 ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
Error += A.x == 1 ? 0 : 1;
|
||||
Error += A.y == 2 ? 0 : 1;
|
||||
Error += A.z == 3 ? 0 : 1;
|
||||
Error += A.w == 4 ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_comp();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
1349
lib/glm/test/core/core_func_common.cpp
Normal file
1349
lib/glm/test/core/core_func_common.cpp
Normal file
File diff suppressed because it is too large
Load Diff
185
lib/glm/test/core/core_func_exponential.cpp
Normal file
185
lib/glm/test/core/core_func_exponential.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/exponential.hpp>
|
||||
|
||||
static int test_pow()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
float A = glm::pow(2.f, 2.f);
|
||||
Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::pow(glm::vec1(2.f), glm::vec1(2.f));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::pow(glm::vec2(2.f), glm::vec2(2.f));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::pow(glm::vec3(2.f), glm::vec3(2.f));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::pow(glm::vec4(2.f), glm::vec4(2.f));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_sqrt()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::sqrt(4.f);
|
||||
Error += glm::equal(A, 2.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::sqrt(glm::vec1(4.f));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::sqrt(glm::vec2(4.f));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::sqrt(glm::vec3(4.f));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::sqrt(glm::vec4(4.f));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_exp()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::exp(1.f);
|
||||
Error += glm::equal(A, glm::e<float>(), 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::exp(glm::vec1(1.f));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::exp(glm::vec2(1.f));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::exp(glm::vec3(1.f));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::exp(glm::vec4(1.f));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(glm::e<float>()), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_log()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float const A = glm::log(glm::e<float>());
|
||||
Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 const B = glm::log(glm::vec1(glm::e<float>()));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const C = glm::log(glm::vec2(glm::e<float>()));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 const D = glm::log(glm::vec3(glm::e<float>()));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E = glm::log(glm::vec4(glm::e<float>()));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_exp2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::exp2(4.f);
|
||||
Error += glm::equal(A, 16.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::exp2(glm::vec1(4.f));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(16.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::exp2(glm::vec2(4.f, 3.f));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(16.f, 8.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::exp2(glm::vec3(4.f, 3.f, 2.f));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(16.f, 8.f, 4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::exp2(glm::vec4(4.f, 3.f, 2.f, 1.f));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(16.f, 8.f, 4.f, 2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
# if GLM_HAS_CXX11_STL
|
||||
//large exponent
|
||||
float F = glm::exp2(23.f);
|
||||
Error += glm::equal(F, 8388608.f, 0.01f) ? 0 : 1;
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_log2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::log2(16.f);
|
||||
Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::log2(glm::vec1(16.f));
|
||||
Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::log2(glm::vec2(16.f, 8.f));
|
||||
Error += glm::all(glm::equal(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::log2(glm::vec3(16.f, 8.f, 4.f));
|
||||
Error += glm::all(glm::equal(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::log2(glm::vec4(16.f, 8.f, 4.f, 2.f));
|
||||
Error += glm::all(glm::equal(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_inversesqrt()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = glm::inversesqrt(16.f) * glm::sqrt(16.f);
|
||||
Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1;
|
||||
|
||||
glm::vec1 B = glm::inversesqrt(glm::vec1(16.f)) * glm::sqrt(16.f);
|
||||
Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 C = glm::inversesqrt(glm::vec2(16.f)) * glm::sqrt(16.f);
|
||||
Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = glm::inversesqrt(glm::vec3(16.f)) * glm::sqrt(16.f);
|
||||
Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
glm::vec4 E = glm::inversesqrt(glm::vec4(16.f)) * glm::sqrt(16.f);
|
||||
Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_pow();
|
||||
Error += test_sqrt();
|
||||
Error += test_exp();
|
||||
Error += test_log();
|
||||
Error += test_exp2();
|
||||
Error += test_log2();
|
||||
Error += test_inversesqrt();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
200
lib/glm/test/core/core_func_geometric.cpp
Normal file
200
lib/glm/test/core/core_func_geometric.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
#include <glm/geometric.hpp>
|
||||
#include <glm/trigonometric.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_double2.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <limits>
|
||||
|
||||
namespace length
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Length1 = glm::length(glm::vec1(1));
|
||||
float Length2 = glm::length(glm::vec2(1, 0));
|
||||
float Length3 = glm::length(glm::vec3(1, 0, 0));
|
||||
float Length4 = glm::length(glm::vec4(1, 0, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Length1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length2 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length3 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length4 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace length
|
||||
|
||||
namespace distance
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Distance1 = glm::distance(glm::vec1(1), glm::vec1(1));
|
||||
float Distance2 = glm::distance(glm::vec2(1, 0), glm::vec2(1, 0));
|
||||
float Distance3 = glm::distance(glm::vec3(1, 0, 0), glm::vec3(1, 0, 0));
|
||||
float Distance4 = glm::distance(glm::vec4(1, 0, 0, 0), glm::vec4(1, 0, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Distance1) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance2) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance3) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance4) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace distance
|
||||
|
||||
namespace dot
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Dot1 = glm::dot(glm::vec1(1), glm::vec1(1));
|
||||
float Dot2 = glm::dot(glm::vec2(1), glm::vec2(1));
|
||||
float Dot3 = glm::dot(glm::vec3(1), glm::vec3(1));
|
||||
float Dot4 = glm::dot(glm::vec4(1), glm::vec4(1));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Dot1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot2 - 2.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot3 - 3.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot4 - 4.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace dot
|
||||
|
||||
namespace cross
|
||||
{
|
||||
int test()
|
||||
{
|
||||
glm::vec3 Cross1 = glm::cross(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
glm::vec3 Cross2 = glm::cross(glm::vec3(0, 1, 0), glm::vec3(1, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::lessThan(glm::abs(Cross1 - glm::vec3(0, 0, 1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
Error += glm::all(glm::lessThan(glm::abs(Cross2 - glm::vec3(0, 0,-1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cross
|
||||
|
||||
namespace normalize
|
||||
{
|
||||
int test()
|
||||
{
|
||||
glm::vec3 Normalize1 = glm::normalize(glm::vec3(1, 0, 0));
|
||||
glm::vec3 Normalize2 = glm::normalize(glm::vec3(2, 0, 0));
|
||||
|
||||
glm::vec3 Normalize3 = glm::normalize(glm::vec3(-0.6, 0.7, -0.5));
|
||||
|
||||
glm::vec3 ro = glm::vec3(glm::cos(5.f) * 3.f, 2.f, glm::sin(5.f) * 3.f);
|
||||
glm::vec3 w = glm::normalize(glm::vec3(0, -0.2f, 0) - ro);
|
||||
glm::vec3 u = glm::normalize(glm::cross(w, glm::vec3(0, 1, 0)));
|
||||
glm::vec3 v = glm::cross(u, w);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::lessThan(glm::abs(Normalize1 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
Error += glm::all(glm::lessThan(glm::abs(Normalize2 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace normalize
|
||||
|
||||
namespace faceforward
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec3 N(0.0f, 0.0f, 1.0f);
|
||||
glm::vec3 I(1.0f, 0.0f, 1.0f);
|
||||
glm::vec3 Nref(0.0f, 0.0f, 1.0f);
|
||||
glm::vec3 F = glm::faceforward(N, I, Nref);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace faceforward
|
||||
|
||||
namespace reflect
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f,-1.0f);
|
||||
glm::vec2 B(0.0f, 1.0f);
|
||||
glm::vec2 C = glm::reflect(A, B);
|
||||
Error += glm::all(glm::equal(C, glm::vec2(1.0, 1.0), 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec2 A(1.0f,-1.0f);
|
||||
glm::dvec2 B(0.0f, 1.0f);
|
||||
glm::dvec2 C = glm::reflect(A, B);
|
||||
Error += glm::all(glm::equal(C, glm::dvec2(1.0, 1.0), 0.0001)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace reflect
|
||||
|
||||
namespace refract
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float A(-1.0f);
|
||||
float B(1.0f);
|
||||
float C = glm::refract(A, B, 0.5f);
|
||||
Error += glm::equal(C, -1.0f, 0.0001f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(0.0f,-1.0f);
|
||||
glm::vec2 B(0.0f, 1.0f);
|
||||
glm::vec2 C = glm::refract(A, B, 0.5f);
|
||||
Error += glm::all(glm::equal(C, glm::vec2(0.0, -1.0), 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec2 A(0.0f,-1.0f);
|
||||
glm::dvec2 B(0.0f, 1.0f);
|
||||
glm::dvec2 C = glm::refract(A, B, 0.5);
|
||||
Error += glm::all(glm::equal(C, glm::dvec2(0.0, -1.0), 0.0001)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace refract
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += length::test();
|
||||
Error += distance::test();
|
||||
Error += dot::test();
|
||||
Error += cross::test();
|
||||
Error += normalize::test();
|
||||
Error += faceforward::test();
|
||||
Error += reflect::test();
|
||||
Error += refract::test();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
1556
lib/glm/test/core/core_func_integer.cpp
Normal file
1556
lib/glm/test/core/core_func_integer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
291
lib/glm/test/core/core_func_integer_bit_count.cpp
Normal file
291
lib/glm/test/core/core_func_integer_bit_count.cpp
Normal file
@@ -0,0 +1,291 @@
|
||||
// This has the programs for computing the number of 1-bits
|
||||
// in a word, or byte, etc.
|
||||
// Max line length is 57, to fit in hacker.book.
|
||||
#include <cstdio>
|
||||
#include <cstdlib> //To define "exit", req'd by XLC.
|
||||
#include <ctime>
|
||||
|
||||
unsigned rotatel(unsigned x, int n)
|
||||
{
|
||||
if (static_cast<unsigned>(n) > 63) { std::printf("rotatel, n out of range.\n"); std::exit(1);}
|
||||
return (x << n) | (x >> (32 - n));
|
||||
}
|
||||
|
||||
int pop0(unsigned x)
|
||||
{
|
||||
x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F);
|
||||
x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF);
|
||||
x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF);
|
||||
return x;
|
||||
}
|
||||
|
||||
int pop1(unsigned x)
|
||||
{
|
||||
x = x - ((x >> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
x = (x + (x >> 4)) & 0x0F0F0F0F;
|
||||
x = x + (x >> 8);
|
||||
x = x + (x >> 16);
|
||||
return x & 0x0000003F;
|
||||
}
|
||||
/* Note: an alternative to the last three executable lines above is:
|
||||
return x*0x01010101 >> 24;
|
||||
if your machine has a fast multiplier (suggested by Jari Kirma). */
|
||||
|
||||
int pop2(unsigned x)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
n = (x >> 1) & 033333333333; // Count bits in
|
||||
x = x - n; // each 3-bit
|
||||
n = (n >> 1) & 033333333333; // field.
|
||||
x = x - n;
|
||||
x = (x + (x >> 3)) & 030707070707; // 6-bit sums.
|
||||
return x%63; // Add 6-bit sums.
|
||||
}
|
||||
|
||||
/* An alternative to the "return" statement above is:
|
||||
return ((x * 0404040404) >> 26) + // Add 6-bit sums.
|
||||
(x >> 30);
|
||||
which runs faster on most machines (suggested by Norbert Juffa). */
|
||||
|
||||
int pop3(unsigned x)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
n = (x >> 1) & 0x77777777; // Count bits in
|
||||
x = x - n; // each 4-bit
|
||||
n = (n >> 1) & 0x77777777; // field.
|
||||
x = x - n;
|
||||
n = (n >> 1) & 0x77777777;
|
||||
x = x - n;
|
||||
x = (x + (x >> 4)) & 0x0F0F0F0F; // Get byte sums.
|
||||
x = x*0x01010101; // Add the bytes.
|
||||
return x >> 24;
|
||||
}
|
||||
|
||||
int pop4(unsigned x)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
while (x != 0) {
|
||||
n = n + 1;
|
||||
x = x & (x - 1);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int pop5(unsigned x)
|
||||
{
|
||||
int i, sum;
|
||||
|
||||
// Rotate and sum method // Shift right & subtract
|
||||
|
||||
sum = x; // sum = x;
|
||||
for (i = 1; i <= 31; i++) { // while (x != 0) {
|
||||
x = rotatel(x, 1); // x = x >> 1;
|
||||
sum = sum + x; // sum = sum - x;
|
||||
} // }
|
||||
return -sum; // return sum;
|
||||
}
|
||||
|
||||
int pop5a(unsigned x)
|
||||
{
|
||||
int sum;
|
||||
|
||||
// Shift right & subtract
|
||||
|
||||
sum = x;
|
||||
while (x != 0) {
|
||||
x = x >> 1;
|
||||
sum = sum - x;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int pop6(unsigned x)
|
||||
{ // Table lookup.
|
||||
static char table[256] = {
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
|
||||
|
||||
return table[x & 0xFF] +
|
||||
table[(x >> 8) & 0xFF] +
|
||||
table[(x >> 16) & 0xFF] +
|
||||
table[(x >> 24)];
|
||||
}
|
||||
|
||||
// The following works only for 8-bit quantities.
|
||||
int pop7(unsigned x)
|
||||
{
|
||||
x = x*0x08040201; // Make 4 copies.
|
||||
x = x >> 3; // So next step hits proper bits.
|
||||
x = x & 0x11111111; // Every 4th bit.
|
||||
x = x*0x11111111; // Sum the digits (each 0 or 1).
|
||||
x = x >> 28; // Position the result.
|
||||
return x;
|
||||
}
|
||||
|
||||
// The following works only for 7-bit quantities.
|
||||
int pop8(unsigned x)
|
||||
{
|
||||
x = x*0x02040810; // Make 4 copies, left-adjusted.
|
||||
x = x & 0x11111111; // Every 4th bit.
|
||||
x = x*0x11111111; // Sum the digits (each 0 or 1).
|
||||
x = x >> 28; // Position the result.
|
||||
return x;
|
||||
}
|
||||
|
||||
// The following works only for 15-bit quantities.
|
||||
int pop9(unsigned x)
|
||||
{
|
||||
unsigned long long y;
|
||||
y = x * 0x0002000400080010ULL;
|
||||
y = y & 0x1111111111111111ULL;
|
||||
y = y * 0x1111111111111111ULL;
|
||||
y = y >> 60;
|
||||
return static_cast<int>(y);
|
||||
}
|
||||
|
||||
int errors;
|
||||
void error(int x, int y)
|
||||
{
|
||||
errors = errors + 1;
|
||||
std::printf("Error for x = %08x, got %08x\n", x, y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
# ifdef NDEBUG
|
||||
|
||||
int i, n;
|
||||
static unsigned test[] = {0,0, 1,1, 2,1, 3,2, 4,1, 5,2, 6,2, 7,3,
|
||||
8,1, 9,2, 10,2, 11,3, 12,2, 13,3, 14,3, 15,4, 16,1, 17,2,
|
||||
0x3F,6, 0x40,1, 0x41,2, 0x7f,7, 0x80,1, 0x81,2, 0xfe,7, 0xff,8,
|
||||
0x4000,1, 0x4001,2, 0x7000,3, 0x7fff,15,
|
||||
0x55555555,16, 0xAAAAAAAA, 16, 0xFF000000,8, 0xC0C0C0C0,8,
|
||||
0x0FFFFFF0,24, 0x80000000,1, 0xFFFFFFFF,32};
|
||||
|
||||
std::size_t const Count = 1000000;
|
||||
|
||||
n = sizeof(test)/4;
|
||||
|
||||
std::clock_t TimestampBeg = 0;
|
||||
std::clock_t TimestampEnd = 0;
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop0(test[i]) != test[i+1]) error(test[i], pop0(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop0: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop1(test[i]) != test[i+1]) error(test[i], pop1(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop2(test[i]) != test[i+1]) error(test[i], pop2(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop3(test[i]) != test[i+1]) error(test[i], pop3(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop4(test[i]) != test[i+1]) error(test[i], pop4(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop5(test[i]) != test[i+1]) error(test[i], pop5(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop5a(test[i]) != test[i+1]) error(test[i], pop5a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop5a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (pop6(test[i]) != test[i+1]) error(test[i], pop6(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if ((test[i] & 0xffffff00) == 0)
|
||||
if (pop7(test[i]) != test[i+1]) error(test[i], pop7(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if ((test[i] & 0xffffff80) == 0)
|
||||
if (pop8(test[i]) != test[i+1]) error(test[i], pop8(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if ((test[i] & 0xffff8000) == 0)
|
||||
if (pop9(test[i]) != test[i+1]) error(test[i], pop9(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("pop9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
if (errors == 0)
|
||||
std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
|
||||
|
||||
# endif//NDEBUG
|
||||
}
|
||||
416
lib/glm/test/core/core_func_integer_find_lsb.cpp
Normal file
416
lib/glm/test/core/core_func_integer_find_lsb.cpp
Normal file
@@ -0,0 +1,416 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstdlib> //To define "exit", req'd by XLC.
|
||||
#include <ctime>
|
||||
|
||||
int nlz(unsigned x)
|
||||
{
|
||||
int pop(unsigned x);
|
||||
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >>16);
|
||||
return pop(~x);
|
||||
}
|
||||
|
||||
int pop(unsigned x)
|
||||
{
|
||||
x = x - ((x >> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
x = (x + (x >> 4)) & 0x0F0F0F0F;
|
||||
x = x + (x << 8);
|
||||
x = x + (x << 16);
|
||||
return x >> 24;
|
||||
}
|
||||
|
||||
int ntz1(unsigned x)
|
||||
{
|
||||
return 32 - nlz(~x & (x-1));
|
||||
}
|
||||
|
||||
int ntz2(unsigned x)
|
||||
{
|
||||
return pop(~x & (x - 1));
|
||||
}
|
||||
|
||||
int ntz3(unsigned x)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (x == 0) return(32);
|
||||
n = 1;
|
||||
if ((x & 0x0000FFFF) == 0) {n = n +16; x = x >>16;}
|
||||
if ((x & 0x000000FF) == 0) {n = n + 8; x = x >> 8;}
|
||||
if ((x & 0x0000000F) == 0) {n = n + 4; x = x >> 4;}
|
||||
if ((x & 0x00000003) == 0) {n = n + 2; x = x >> 2;}
|
||||
return n - (x & 1);
|
||||
}
|
||||
|
||||
int ntz4(unsigned x)
|
||||
{
|
||||
unsigned y;
|
||||
int n;
|
||||
|
||||
if (x == 0) return 32;
|
||||
n = 31;
|
||||
y = x <<16; if (y != 0) {n = n -16; x = y;}
|
||||
y = x << 8; if (y != 0) {n = n - 8; x = y;}
|
||||
y = x << 4; if (y != 0) {n = n - 4; x = y;}
|
||||
y = x << 2; if (y != 0) {n = n - 2; x = y;}
|
||||
y = x << 1; if (y != 0) {n = n - 1;}
|
||||
return n;
|
||||
}
|
||||
|
||||
int ntz4a(unsigned x)
|
||||
{
|
||||
unsigned y;
|
||||
int n;
|
||||
|
||||
if (x == 0) return 32;
|
||||
n = 31;
|
||||
y = x <<16; if (y != 0) {n = n -16; x = y;}
|
||||
y = x << 8; if (y != 0) {n = n - 8; x = y;}
|
||||
y = x << 4; if (y != 0) {n = n - 4; x = y;}
|
||||
y = x << 2; if (y != 0) {n = n - 2; x = y;}
|
||||
n = n - ((x << 1) >> 31);
|
||||
return n;
|
||||
}
|
||||
|
||||
int ntz5(char x)
|
||||
{
|
||||
if (x & 15) {
|
||||
if (x & 3) {
|
||||
if (x & 1) return 0;
|
||||
else return 1;
|
||||
}
|
||||
else if (x & 4) return 2;
|
||||
else return 3;
|
||||
}
|
||||
else if (x & 0x30) {
|
||||
if (x & 0x10) return 4;
|
||||
else return 5;
|
||||
}
|
||||
else if (x & 0x40) return 6;
|
||||
else if (x) return 7;
|
||||
else return 8;
|
||||
}
|
||||
|
||||
int ntz6(unsigned x)
|
||||
{
|
||||
int n;
|
||||
|
||||
x = ~x & (x - 1);
|
||||
n = 0; // n = 32;
|
||||
while(x != 0)
|
||||
{ // while (x != 0) {
|
||||
n = n + 1; // n = n - 1;
|
||||
x = x >> 1; // x = x + x;
|
||||
} // }
|
||||
return n; // return n;
|
||||
}
|
||||
|
||||
int ntz6a(unsigned x)
|
||||
{
|
||||
int n = 32;
|
||||
|
||||
while (x != 0) {
|
||||
n = n - 1;
|
||||
x = x + x;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Dean Gaudet's algorithm. To be most useful there must be a good way
|
||||
to evaluate the C "conditional expression" (a?b:c construction) without
|
||||
branching. The result of a?b:c is b if a is true (nonzero), and c if a
|
||||
is false (0).
|
||||
For example, a compare to zero op that sets a target GPR to 1 if the
|
||||
operand is 0, and to 0 if the operand is nonzero, will do it. With this
|
||||
instruction, the algorithm is entirely branch-free. But the most
|
||||
interesting thing about it is the high degree of parallelism. All six
|
||||
lines with conditional expressions can be executed in parallel (on a
|
||||
machine with sufficient computational units).
|
||||
Although the instruction count is 30 measured statically, it could
|
||||
execute in only 10 cycles on a machine with sufficient parallelism.
|
||||
The first two uses of y can instead be x, which would increase the
|
||||
useful parallelism on most machines (the assignments to y, bz, and b4
|
||||
could then all run in parallel). */
|
||||
|
||||
int ntz7(unsigned x)
|
||||
{
|
||||
unsigned y, bz, b4, b3, b2, b1, b0;
|
||||
|
||||
y = x & -x; // Isolate rightmost 1-bit.
|
||||
bz = y ? 0 : 1; // 1 if y = 0.
|
||||
b4 = (y & 0x0000FFFF) ? 0 : 16;
|
||||
b3 = (y & 0x00FF00FF) ? 0 : 8;
|
||||
b2 = (y & 0x0F0F0F0F) ? 0 : 4;
|
||||
b1 = (y & 0x33333333) ? 0 : 2;
|
||||
b0 = (y & 0x55555555) ? 0 : 1;
|
||||
return bz + b4 + b3 + b2 + b1 + b0;
|
||||
}
|
||||
|
||||
// This file has divisions by zero to test isnan
|
||||
#if GLM_COMPILER & GLM_COMPILER_VC
|
||||
# pragma warning(disable : 4800)
|
||||
#endif
|
||||
|
||||
int ntz7_christophe(unsigned x)
|
||||
{
|
||||
unsigned y, bz, b4, b3, b2, b1, b0;
|
||||
|
||||
y = x & -x; // Isolate rightmost 1-bit.
|
||||
bz = unsigned(!bool(y)); // 1 if y = 0.
|
||||
b4 = unsigned(!bool(y & 0x0000FFFF)) * 16;
|
||||
b3 = unsigned(!bool(y & 0x00FF00FF)) * 8;
|
||||
b2 = unsigned(!bool(y & 0x0F0F0F0F)) * 4;
|
||||
b1 = unsigned(!bool(y & 0x33333333)) * 2;
|
||||
b0 = unsigned(!bool(y & 0x55555555)) * 1;
|
||||
return bz + b4 + b3 + b2 + b1 + b0;
|
||||
}
|
||||
|
||||
/* Below is David Seal's algorithm, found at
|
||||
http://www.ciphersbyritter.com/NEWS4/BITCT.HTM Table
|
||||
entries marked "u" are unused. 6 ops including a
|
||||
multiply, plus an indexed load. */
|
||||
|
||||
#define u 99
|
||||
int ntz8(unsigned x)
|
||||
{
|
||||
static char table[64] =
|
||||
{32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14,
|
||||
10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15,
|
||||
31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26,
|
||||
30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u};
|
||||
|
||||
x = (x & -x)*0x0450FBAF;
|
||||
return table[x >> 26];
|
||||
}
|
||||
|
||||
/* Seal's algorithm with multiply expanded.
|
||||
9 elementary ops plus an indexed load. */
|
||||
|
||||
int ntz8a(unsigned x)
|
||||
{
|
||||
static char table[64] =
|
||||
{32, 0, 1,12, 2, 6, u,13, 3, u, 7, u, u, u, u,14,
|
||||
10, 4, u, u, 8, u, u,25, u, u, u, u, u,21,27,15,
|
||||
31,11, 5, u, u, u, u, u, 9, u, u,24, u, u,20,26,
|
||||
30, u, u, u, u,23, u,19, 29, u,22,18,28,17,16, u};
|
||||
|
||||
x = (x & -x);
|
||||
x = (x << 4) + x; // x = x*17.
|
||||
x = (x << 6) + x; // x = x*65.
|
||||
x = (x << 16) - x; // x = x*65535.
|
||||
return table[x >> 26];
|
||||
}
|
||||
|
||||
/* Reiser's algorithm. Three ops including a "remainder,"
|
||||
plus an indexed load. */
|
||||
|
||||
int ntz9(unsigned x)
|
||||
{
|
||||
static char table[37] = {
|
||||
32, 0, 1, 26, 2, 23, 27,
|
||||
u, 3, 16, 24, 30, 28, 11, u, 13, 4,
|
||||
7, 17, u, 25, 22, 31, 15, 29, 10, 12,
|
||||
6, u, 21, 14, 9, 5, 20, 8, 19, 18};
|
||||
|
||||
x = (x & -x)%37;
|
||||
return table[x];
|
||||
}
|
||||
|
||||
/* Using a de Bruijn sequence. This is a table lookup with a 32-entry
|
||||
table. The de Bruijn sequence used here is
|
||||
0000 0100 1101 0111 0110 0101 0001 1111,
|
||||
obtained from Danny Dube's October 3, 1997, posting in
|
||||
comp.compression.research. Thanks to Norbert Juffa for this reference. */
|
||||
|
||||
int ntz10(unsigned x) {
|
||||
|
||||
static char table[32] =
|
||||
{ 0, 1, 2,24, 3,19, 6,25, 22, 4,20,10,16, 7,12,26,
|
||||
31,23,18, 5,21, 9,15,11, 30,17, 8,14,29,13,28,27};
|
||||
|
||||
if (x == 0) return 32;
|
||||
x = (x & -x)*0x04D7651F;
|
||||
return table[x >> 27];
|
||||
}
|
||||
|
||||
/* Norbert Juffa's code, answer to exercise 1 of Chapter 5 (2nd ed). */
|
||||
|
||||
#define SLOW_MUL
|
||||
int ntz11 (unsigned int n) {
|
||||
|
||||
static unsigned char tab[32] =
|
||||
{ 0, 1, 2, 24, 3, 19, 6, 25,
|
||||
22, 4, 20, 10, 16, 7, 12, 26,
|
||||
31, 23, 18, 5, 21, 9, 15, 11,
|
||||
30, 17, 8, 14, 29, 13, 28, 27
|
||||
};
|
||||
unsigned int k;
|
||||
n = n & (-n); /* isolate lsb */
|
||||
printf("n = %d\n", n);
|
||||
#if defined(SLOW_MUL)
|
||||
k = (n << 11) - n;
|
||||
k = (k << 2) + k;
|
||||
k = (k << 8) + n;
|
||||
k = (k << 5) - k;
|
||||
#else
|
||||
k = n * 0x4d7651f;
|
||||
#endif
|
||||
return n ? tab[k>>27] : 32;
|
||||
}
|
||||
|
||||
int errors;
|
||||
void error(int x, int y) {
|
||||
errors = errors + 1;
|
||||
std::printf("Error for x = %08x, got %d\n", x, y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
# ifdef NDEBUG
|
||||
|
||||
int i, m, n;
|
||||
static unsigned test[] = {0,32, 1,0, 2,1, 3,0, 4,2, 5,0, 6,1, 7,0,
|
||||
8,3, 9,0, 16,4, 32,5, 64,6, 128,7, 255,0, 256,8, 512,9, 1024,10,
|
||||
2048,11, 4096,12, 8192,13, 16384,14, 32768,15, 65536,16,
|
||||
0x20000,17, 0x40000,18, 0x80000,19, 0x100000,20, 0x200000,21,
|
||||
0x400000,22, 0x800000,23, 0x1000000,24, 0x2000000,25,
|
||||
0x4000000,26, 0x8000000,27, 0x10000000,28, 0x20000000,29,
|
||||
0x40000000,30, 0x80000000,31, 0xFFFFFFF0,4, 0x3000FF00,8,
|
||||
0xC0000000,30, 0x60000000,29, 0x00011000, 12};
|
||||
|
||||
std::size_t const Count = 1000;
|
||||
|
||||
n = sizeof(test)/4;
|
||||
|
||||
std::clock_t TimestampBeg = 0;
|
||||
std::clock_t TimestampEnd = 0;
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz1(test[i]) != test[i+1]) error(test[i], ntz1(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz2(test[i]) != test[i+1]) error(test[i], ntz2(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz3(test[i]) != test[i+1]) error(test[i], ntz3(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz4(test[i]) != test[i+1]) error(test[i], ntz4(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz4a(test[i]) != test[i+1]) error(test[i], ntz4a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz4a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for(std::size_t k = 0; k < Count; ++k)
|
||||
for(i = 0; i < n; i += 2)
|
||||
{
|
||||
m = test[i+1];
|
||||
if(m > 8)
|
||||
m = 8;
|
||||
if(ntz5(static_cast<char>(test[i])) != m)
|
||||
error(test[i], ntz5(static_cast<char>(test[i])));
|
||||
}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz6(test[i]) != test[i+1]) error(test[i], ntz6(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz6a(test[i]) != test[i+1]) error(test[i], ntz6a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz6a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz7(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz7_christophe(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz7_christophe: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz8(test[i]) != test[i+1]) error(test[i], ntz8(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz8a(test[i]) != test[i+1]) error(test[i], ntz8a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz8a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz9(test[i]) != test[i+1]) error(test[i], ntz9(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (ntz10(test[i]) != test[i+1]) error(test[i], ntz10(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("ntz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
if (errors == 0)
|
||||
std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
|
||||
|
||||
# endif//NDEBUG
|
||||
}
|
||||
440
lib/glm/test/core/core_func_integer_find_msb.cpp
Normal file
440
lib/glm/test/core/core_func_integer_find_msb.cpp
Normal file
@@ -0,0 +1,440 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <cstdio>
|
||||
#include <cstdlib> // To define "exit", req'd by XLC.
|
||||
#include <ctime>
|
||||
|
||||
#define LE 1 // 1 for little-endian, 0 for big-endian.
|
||||
|
||||
int pop(unsigned x) {
|
||||
x = x - ((x >> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
x = (x + (x >> 4)) & 0x0F0F0F0F;
|
||||
x = x + (x << 8);
|
||||
x = x + (x << 16);
|
||||
return x >> 24;
|
||||
}
|
||||
|
||||
int nlz1(unsigned x) {
|
||||
int n;
|
||||
|
||||
if (x == 0) return(32);
|
||||
n = 0;
|
||||
if (x <= 0x0000FFFF) {n = n +16; x = x <<16;}
|
||||
if (x <= 0x00FFFFFF) {n = n + 8; x = x << 8;}
|
||||
if (x <= 0x0FFFFFFF) {n = n + 4; x = x << 4;}
|
||||
if (x <= 0x3FFFFFFF) {n = n + 2; x = x << 2;}
|
||||
if (x <= 0x7FFFFFFF) {n = n + 1;}
|
||||
return n;
|
||||
}
|
||||
|
||||
int nlz1a(unsigned x) {
|
||||
int n;
|
||||
|
||||
/* if (x == 0) return(32); */
|
||||
if (static_cast<int>(x) <= 0) return (~x >> 26) & 32;
|
||||
n = 1;
|
||||
if ((x >> 16) == 0) {n = n +16; x = x <<16;}
|
||||
if ((x >> 24) == 0) {n = n + 8; x = x << 8;}
|
||||
if ((x >> 28) == 0) {n = n + 4; x = x << 4;}
|
||||
if ((x >> 30) == 0) {n = n + 2; x = x << 2;}
|
||||
n = n - (x >> 31);
|
||||
return n;
|
||||
}
|
||||
// On basic Risc, 12 to 20 instructions.
|
||||
|
||||
int nlz2(unsigned x) {
|
||||
unsigned y;
|
||||
int n;
|
||||
|
||||
n = 32;
|
||||
y = x >>16; if (y != 0) {n = n -16; x = y;}
|
||||
y = x >> 8; if (y != 0) {n = n - 8; x = y;}
|
||||
y = x >> 4; if (y != 0) {n = n - 4; x = y;}
|
||||
y = x >> 2; if (y != 0) {n = n - 2; x = y;}
|
||||
y = x >> 1; if (y != 0) return n - 2;
|
||||
return n - x;
|
||||
}
|
||||
|
||||
// As above but coded as a loop for compactness:
|
||||
// 23 to 33 basic Risc instructions.
|
||||
int nlz2a(unsigned x) {
|
||||
unsigned y;
|
||||
int n, c;
|
||||
|
||||
n = 32;
|
||||
c = 16;
|
||||
do {
|
||||
y = x >> c; if (y != 0) {n = n - c; x = y;}
|
||||
c = c >> 1;
|
||||
} while (c != 0);
|
||||
return n - x;
|
||||
}
|
||||
|
||||
int nlz3(int x) {
|
||||
int y, n;
|
||||
|
||||
n = 0;
|
||||
y = x;
|
||||
L: if (x < 0) return n;
|
||||
if (y == 0) return 32 - n;
|
||||
n = n + 1;
|
||||
x = x << 1;
|
||||
y = y >> 1;
|
||||
goto L;
|
||||
}
|
||||
|
||||
int nlz4(unsigned x) {
|
||||
int y, m, n;
|
||||
|
||||
y = -(x >> 16); // If left half of x is 0,
|
||||
m = (y >> 16) & 16; // set n = 16. If left half
|
||||
n = 16 - m; // is nonzero, set n = 0 and
|
||||
x = x >> m; // shift x right 16.
|
||||
// Now x is of the form 0000xxxx.
|
||||
y = x - 0x100; // If positions 8-15 are 0,
|
||||
m = (y >> 16) & 8; // add 8 to n and shift x left 8.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x - 0x1000; // If positions 12-15 are 0,
|
||||
m = (y >> 16) & 4; // add 4 to n and shift x left 4.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x - 0x4000; // If positions 14-15 are 0,
|
||||
m = (y >> 16) & 2; // add 2 to n and shift x left 2.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x >> 14; // Set y = 0, 1, 2, or 3.
|
||||
m = y & ~(y >> 1); // Set m = 0, 1, 2, or 2 resp.
|
||||
return n + 2 - m;
|
||||
}
|
||||
|
||||
int nlz5(unsigned x) {
|
||||
int pop(unsigned x);
|
||||
|
||||
x = x | (x >> 1);
|
||||
x = x | (x >> 2);
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >>16);
|
||||
return pop(~x);
|
||||
}
|
||||
|
||||
/* The four programs below are not valid ANSI C programs. This is
|
||||
because they refer to the same storage locations as two different types.
|
||||
However, they work with xlc/AIX, gcc/AIX, and gcc/NT. If you try to
|
||||
code them more compactly by declaring a variable xx to be "double," and
|
||||
then using
|
||||
|
||||
n = 1054 - (*((unsigned *)&xx + LE) >> 20);
|
||||
|
||||
then you are violating not only the rule above, but also the ANSI C
|
||||
rule that pointer arithmetic can be performed only on pointers to
|
||||
array elements.
|
||||
When coded with the above statement, the program fails with xlc,
|
||||
gcc/AIX, and gcc/NT, at some optimization levels.
|
||||
BTW, these programs use the "anonymous union" feature of C++, not
|
||||
available in C. */
|
||||
|
||||
int nlz6(unsigned k)
|
||||
{
|
||||
union {
|
||||
unsigned asInt[2];
|
||||
double asDouble;
|
||||
};
|
||||
int n;
|
||||
|
||||
asDouble = static_cast<double>(k) + 0.5;
|
||||
n = 1054 - (asInt[LE] >> 20);
|
||||
return n;
|
||||
}
|
||||
|
||||
int nlz7(unsigned k)
|
||||
{
|
||||
union {
|
||||
unsigned asInt[2];
|
||||
double asDouble;
|
||||
};
|
||||
int n;
|
||||
|
||||
asDouble = static_cast<double>(k);
|
||||
n = 1054 - (asInt[LE] >> 20);
|
||||
n = (n & 31) + (n >> 9);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* In single qualifier, round-to-nearest mode, the basic method fails for:
|
||||
k = 0, k = 01FFFFFF, 03FFFFFE <= k <= 03FFFFFF,
|
||||
07FFFFFC <= k <= 07FFFFFF,
|
||||
0FFFFFF8 <= k <= 0FFFFFFF,
|
||||
...
|
||||
7FFFFFC0 <= k <= 7FFFFFFF.
|
||||
FFFFFF80 <= k <= FFFFFFFF.
|
||||
For k = 0 it gives 158, and for the other values it is too low by 1. */
|
||||
|
||||
int nlz8(unsigned k)
|
||||
{
|
||||
union {
|
||||
unsigned asInt;
|
||||
float asFloat;
|
||||
};
|
||||
int n;
|
||||
|
||||
k = k & ~(k >> 1); /* Fix problem with rounding. */
|
||||
asFloat = static_cast<float>(k) + 0.5f;
|
||||
n = 158 - (asInt >> 23);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* The example below shows how to make a macro for nlz. It uses an
|
||||
extension to the C and C++ languages that is provided by the GNU C/C++
|
||||
compiler, namely, that of allowing statements and declarations in
|
||||
expressions (see "Using and Porting GNU CC", by Richard M. Stallman
|
||||
(1998). The underscores are necessary to protect against the
|
||||
possibility that the macro argument will conflict with one of its local
|
||||
variables, e.g., NLZ(k). */
|
||||
|
||||
int nlz9(unsigned k)
|
||||
{
|
||||
union {
|
||||
unsigned asInt;
|
||||
float asFloat;
|
||||
};
|
||||
int n;
|
||||
|
||||
k = k & ~(k >> 1); /* Fix problem with rounding. */
|
||||
asFloat = static_cast<float>(k);
|
||||
n = 158 - (asInt >> 23);
|
||||
n = (n & 31) + (n >> 6); /* Fix problem with k = 0. */
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Below are three nearly equivalent programs for computing the number
|
||||
of leading zeros in a word. This material is not in HD, but may be in a
|
||||
future edition.
|
||||
Immediately below is Robert Harley's algorithm, found at the
|
||||
comp.arch newsgroup entry dated 7/12/96, pointed out to me by Norbert
|
||||
Juffa.
|
||||
Table entries marked "u" are unused. 14 ops including a multiply,
|
||||
plus an indexed load.
|
||||
The smallest multiplier that works is 0x045BCED1 = 17*65*129*513 (all
|
||||
of form 2**k + 1). There are no multipliers of three terms of the form
|
||||
2**k +- 1 that work, with a table size of 64 or 128. There are some,
|
||||
with a table size of 64, if you precede the multiplication with x = x -
|
||||
(x >> 1), but that seems less elegant. There are also some if you use a
|
||||
table size of 256, the smallest is 0x01033CBF = 65*255*1025 (this would
|
||||
save two instructions in the form of this algorithm with the
|
||||
multiplication expanded into shifts and adds, but the table size is
|
||||
getting a bit large). */
|
||||
|
||||
#define u 99
|
||||
int nlz10(unsigned x)
|
||||
{
|
||||
static char table[64] =
|
||||
{32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u,
|
||||
u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u,
|
||||
17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18,
|
||||
5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u};
|
||||
|
||||
x = x | (x >> 1); // Propagate leftmost
|
||||
x = x | (x >> 2); // 1-bit to the right.
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >>16);
|
||||
x = x*0x06EB14F9; // Multiplier is 7*255**3.
|
||||
return table[x >> 26];
|
||||
}
|
||||
|
||||
/* Harley's algorithm with multiply expanded.
|
||||
19 elementary ops plus an indexed load. */
|
||||
|
||||
int nlz10a(unsigned x)
|
||||
{
|
||||
static char table[64] =
|
||||
{32,31, u,16, u,30, 3, u, 15, u, u, u,29,10, 2, u,
|
||||
u, u,12,14,21, u,19, u, u,28, u,25, u, 9, 1, u,
|
||||
17, u, 4, u, u, u,11, u, 13,22,20, u,26, u, u,18,
|
||||
5, u, u,23, u,27, u, 6, u,24, 7, u, 8, u, 0, u};
|
||||
|
||||
x = x | (x >> 1); // Propagate leftmost
|
||||
x = x | (x >> 2); // 1-bit to the right.
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x | (x >> 16);
|
||||
x = (x << 3) - x; // Multiply by 7.
|
||||
x = (x << 8) - x; // Multiply by 255.
|
||||
x = (x << 8) - x; // Again.
|
||||
x = (x << 8) - x; // Again.
|
||||
return table[x >> 26];
|
||||
}
|
||||
|
||||
/* Julius Goryavsky's version of Harley's algorithm.
|
||||
17 elementary ops plus an indexed load, if the machine
|
||||
has "and not." */
|
||||
|
||||
int nlz10b(unsigned x)
|
||||
{
|
||||
static char table[64] =
|
||||
{32,20,19, u, u,18, u, 7, 10,17, u, u,14, u, 6, u,
|
||||
u, 9, u,16, u, u, 1,26, u,13, u, u,24, 5, u, u,
|
||||
u,21, u, 8,11, u,15, u, u, u, u, 2,27, 0,25, u,
|
||||
22, u,12, u, u, 3,28, u, 23, u, 4,29, u, u,30,31};
|
||||
|
||||
x = x | (x >> 1); // Propagate leftmost
|
||||
x = x | (x >> 2); // 1-bit to the right.
|
||||
x = x | (x >> 4);
|
||||
x = x | (x >> 8);
|
||||
x = x & ~(x >> 16);
|
||||
x = x*0xFD7049FF; // Activate this line or the following 3.
|
||||
// x = (x << 9) - x; // Multiply by 511.
|
||||
// x = (x << 11) - x; // Multiply by 2047.
|
||||
// x = (x << 14) - x; // Multiply by 16383.
|
||||
return table[x >> 26];
|
||||
}
|
||||
|
||||
int errors;
|
||||
void error(int x, int y)
|
||||
{
|
||||
errors = errors + 1;
|
||||
std::printf("Error for x = %08x, got %d\n", x, y);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
# ifdef NDEBUG
|
||||
|
||||
int i, n;
|
||||
static unsigned test[] = {0,32, 1,31, 2,30, 3,30, 4,29, 5,29, 6,29,
|
||||
7,29, 8,28, 9,28, 16,27, 32,26, 64,25, 128,24, 255,24, 256,23,
|
||||
512,22, 1024,21, 2048,20, 4096,19, 8192,18, 16384,17, 32768,16,
|
||||
65536,15, 0x20000,14, 0x40000,13, 0x80000,12, 0x100000,11,
|
||||
0x200000,10, 0x400000,9, 0x800000,8, 0x1000000,7, 0x2000000,6,
|
||||
0x4000000,5, 0x8000000,4, 0x0FFFFFFF,4, 0x10000000,3,
|
||||
0x3000FFFF,2, 0x50003333,1, 0x7FFFFFFF,1, 0x80000000,0,
|
||||
0xFFFFFFFF,0};
|
||||
std::size_t const Count = 1000;
|
||||
|
||||
n = sizeof(test)/4;
|
||||
|
||||
std::clock_t TimestampBeg = 0;
|
||||
std::clock_t TimestampEnd = 0;
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz1(test[i]) != test[i+1]) error(test[i], nlz1(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz1a(test[i]) != test[i+1]) error(test[i], nlz1a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz1a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz2(test[i]) != test[i+1]) error(test[i], nlz2(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz2a(test[i]) != test[i+1]) error(test[i], nlz2a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz2a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz3(test[i]) != test[i+1]) error(test[i], nlz3(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz4(test[i]) != test[i+1]) error(test[i], nlz4(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz5(test[i]) != test[i+1]) error(test[i], nlz5(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz6(test[i]) != test[i+1]) error(test[i], nlz6(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz7(test[i]) != test[i+1]) error(test[i], nlz7(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz8(test[i]) != test[i+1]) error(test[i], nlz8(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz9(test[i]) != test[i+1]) error(test[i], nlz9(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz10(test[i]) != test[i+1]) error(test[i], nlz10(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz10: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz10a(test[i]) != test[i+1]) error(test[i], nlz10a(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz10a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
TimestampBeg = std::clock();
|
||||
for (std::size_t k = 0; k < Count; ++k)
|
||||
for (i = 0; i < n; i += 2) {
|
||||
if (nlz10b(test[i]) != test[i+1]) error(test[i], nlz10b(test[i]));}
|
||||
TimestampEnd = std::clock();
|
||||
|
||||
std::printf("nlz10b: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
|
||||
|
||||
if (errors == 0)
|
||||
std::printf("Passed all %d cases.\n", static_cast<int>(sizeof(test)/8));
|
||||
|
||||
# endif//NDEBUG
|
||||
}
|
||||
329
lib/glm/test/core/core_func_matrix.cpp
Normal file
329
lib/glm/test/core/core_func_matrix.cpp
Normal file
@@ -0,0 +1,329 @@
|
||||
#include <glm/matrix.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/ulp.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
int test_matrixCompMult()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
mat2 m(0, 1, 2, 3);
|
||||
mat2 n = matrixCompMult(m, m);
|
||||
mat2 expected = mat2(0, 1, 4, 9);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x3 m(0, 1, 2, 3, 4, 5);
|
||||
mat2x3 n = matrixCompMult(m, m);
|
||||
mat2x3 expected = mat2x3(0, 1, 4, 9, 16, 25);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat2x4 n = matrixCompMult(m, m);
|
||||
mat2x4 expected = mat2x4(0, 1, 4, 9, 16, 25, 36, 49);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
mat3 n = matrixCompMult(m, m);
|
||||
mat3 expected = mat3(0, 1, 4, 9, 16, 25, 36, 49, 64);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x2 m(0, 1, 2, 3, 4, 5);
|
||||
mat3x2 n = matrixCompMult(m, m);
|
||||
mat3x2 expected = mat3x2(0, 1, 4, 9, 16, 25);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat3x4 n = matrixCompMult(m, m);
|
||||
mat3x4 expected = mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
mat4 n = matrixCompMult(m, m);
|
||||
mat4 expected = mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat4x2 n = matrixCompMult(m, m);
|
||||
mat4x2 expected = mat4x2(0, 1, 4, 9, 16, 25, 36, 49);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat4x3 n = matrixCompMult(m, m);
|
||||
mat4x3 expected = mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121);
|
||||
for (length_t l = 0; l < m.length(); ++l)
|
||||
Error += all(epsilonEqual(n[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_outerProduct()
|
||||
{
|
||||
{ glm::mat2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec2(1.0f)); }
|
||||
{ glm::mat3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec3(1.0f)); }
|
||||
{ glm::mat4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec4(1.0f)); }
|
||||
|
||||
{ glm::mat2x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec2(1.0f)); }
|
||||
{ glm::mat2x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec2(1.0f)); }
|
||||
|
||||
{ glm::mat3x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec3(1.0f)); }
|
||||
{ glm::mat3x4 m = glm::outerProduct(glm::vec4(1.0f), glm::vec3(1.0f)); }
|
||||
|
||||
{ glm::mat4x2 m = glm::outerProduct(glm::vec2(1.0f), glm::vec4(1.0f)); }
|
||||
{ glm::mat4x3 m = glm::outerProduct(glm::vec3(1.0f), glm::vec4(1.0f)); }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_transpose()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
mat2 const m(0, 1, 2, 3);
|
||||
mat2 const t = transpose(m);
|
||||
mat2 const expected = mat2(0, 2, 1, 3);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x3 m(0, 1, 2, 3, 4, 5);
|
||||
mat3x2 t = transpose(m);
|
||||
mat3x2 const expected = mat3x2(0, 3, 1, 4, 2, 5);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat4x2 t = transpose(m);
|
||||
mat4x2 const expected = mat4x2(0, 4, 1, 5, 2, 6, 3, 7);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
mat3 t = transpose(m);
|
||||
mat3 const expected = mat3(0, 3, 6, 1, 4, 7, 2, 5, 8);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x2 m(0, 1, 2, 3, 4, 5);
|
||||
mat2x3 t = transpose(m);
|
||||
mat2x3 const expected = mat2x3(0, 2, 4, 1, 3, 5);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat4x3 t = transpose(m);
|
||||
mat4x3 const expected = mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
|
||||
mat4 t = transpose(m);
|
||||
mat4 const expected = mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
|
||||
mat2x4 t = transpose(m);
|
||||
mat2x4 const expected = mat2x4(0, 2, 4, 6, 1, 3, 5, 7);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
mat3x4 t = transpose(m);
|
||||
mat3x4 const expected = mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11);
|
||||
for (length_t l = 0; l < expected.length(); ++l)
|
||||
Error += all(epsilonEqual(t[l], expected[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_determinant()
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_inverse()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat4x4 A4x4(
|
||||
glm::vec4(1, 0, 1, 0),
|
||||
glm::vec4(0, 1, 0, 0),
|
||||
glm::vec4(0, 0, 1, 0),
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
glm::mat4x4 B4x4 = inverse(A4x4);
|
||||
glm::mat4x4 I4x4 = A4x4 * B4x4;
|
||||
glm::mat4x4 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I4x4[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3x3 A3x3(
|
||||
glm::vec3(1, 0, 1),
|
||||
glm::vec3(0, 1, 0),
|
||||
glm::vec3(0, 0, 1));
|
||||
glm::mat3x3 B3x3 = glm::inverse(A3x3);
|
||||
glm::mat3x3 I3x3 = A3x3 * B3x3;
|
||||
glm::mat3x3 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I3x3[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2x2 A2x2(
|
||||
glm::vec2(1, 1),
|
||||
glm::vec2(0, 1));
|
||||
glm::mat2x2 B2x2 = glm::inverse(A2x2);
|
||||
glm::mat2x2 I2x2 = A2x2 * B2x2;
|
||||
glm::mat2x2 Identity(1);
|
||||
for (length_t l = 0; l < Identity.length(); ++l)
|
||||
Error += all(epsilonEqual(I2x2[l], Identity[l], epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_inverse_simd()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4x4 const Identity(1);
|
||||
|
||||
glm::mat4x4 const A4x4(
|
||||
glm::vec4(1, 0, 1, 0),
|
||||
glm::vec4(0, 1, 0, 0),
|
||||
glm::vec4(0, 0, 1, 0),
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
glm::mat4x4 const B4x4 = glm::inverse(A4x4);
|
||||
glm::mat4x4 const I4x4 = A4x4 * B4x4;
|
||||
|
||||
Error += glm::all(glm::epsilonEqual(I4x4[0], Identity[0], 0.001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(I4x4[1], Identity[1], 0.001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(I4x4[2], Identity[2], 0.001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(I4x4[3], Identity[3], 0.001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template<typename VEC3, typename MAT4>
|
||||
int test_inverse_perf(std::size_t Count, std::size_t Instance, char const * Message)
|
||||
{
|
||||
std::vector<MAT4> TestInputs;
|
||||
TestInputs.resize(Count);
|
||||
std::vector<MAT4> TestOutputs;
|
||||
TestOutputs.resize(TestInputs.size());
|
||||
|
||||
VEC3 Axis(glm::normalize(VEC3(1.0f, 2.0f, 3.0f)));
|
||||
|
||||
for(std::size_t i = 0; i < TestInputs.size(); ++i)
|
||||
{
|
||||
typename MAT4::value_type f = static_cast<typename MAT4::value_type>(i + Instance) * typename MAT4::value_type(0.1) + typename MAT4::value_type(0.1);
|
||||
TestInputs[i] = glm::rotate(glm::translate(MAT4(1), Axis * f), f, Axis);
|
||||
//TestInputs[i] = glm::translate(MAT4(1), Axis * f);
|
||||
}
|
||||
|
||||
std::clock_t StartTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < TestInputs.size(); ++i)
|
||||
TestOutputs[i] = glm::inverse(TestInputs[i]);
|
||||
|
||||
std::clock_t EndTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < TestInputs.size(); ++i)
|
||||
TestOutputs[i] = TestOutputs[i] * TestInputs[i];
|
||||
|
||||
typename MAT4::value_type Diff(0);
|
||||
for(std::size_t Entry = 0; Entry < TestOutputs.size(); ++Entry)
|
||||
{
|
||||
MAT4 i(1.0);
|
||||
MAT4 m(TestOutputs[Entry]);
|
||||
for(glm::length_t y = 0; y < m.length(); ++y)
|
||||
for(glm::length_t x = 0; x < m[y].length(); ++x)
|
||||
Diff = glm::max(m[y][x], i[y][x]);
|
||||
}
|
||||
|
||||
//glm::uint Ulp = 0;
|
||||
//Ulp = glm::max(glm::float_distance(*Dst, *Src), Ulp);
|
||||
|
||||
std::printf("inverse<%s>(%f): %lu\n", Message, static_cast<double>(Diff), EndTime - StartTime);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
Error += test_matrixCompMult();
|
||||
Error += test_outerProduct();
|
||||
Error += test_transpose();
|
||||
Error += test_determinant();
|
||||
Error += test_inverse();
|
||||
Error += test_inverse_simd();
|
||||
|
||||
# ifdef NDEBUG
|
||||
std::size_t const Samples = 1000;
|
||||
# else
|
||||
std::size_t const Samples = 1;
|
||||
# endif//NDEBUG
|
||||
|
||||
for(std::size_t i = 0; i < 1; ++i)
|
||||
{
|
||||
Error += test_inverse_perf<glm::vec3, glm::mat4>(Samples, i, "mat4");
|
||||
Error += test_inverse_perf<glm::dvec3, glm::dmat4>(Samples, i, "dmat4");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
7
lib/glm/test/core/core_func_noise.cpp
Normal file
7
lib/glm/test/core/core_func_noise.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
156
lib/glm/test/core/core_func_packing.cpp
Normal file
156
lib/glm/test/core/core_func_packing.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/packing.hpp>
|
||||
#include <vector>
|
||||
|
||||
int test_packUnorm2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2(1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(0.5f, 0.7f));
|
||||
A.push_back(glm::vec2(0.1f, 0.2f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint32 C = glm::packUnorm2x16(B);
|
||||
glm::vec2 D = glm::unpackUnorm2x16(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(-0.5f,-0.7f));
|
||||
A.push_back(glm::vec2(-0.1f, 0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint32 C = glm::packSnorm2x16(B);
|
||||
glm::vec2 D = glm::unpackSnorm2x16(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::uint32 Packed = glm::packUnorm4x8(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f));
|
||||
glm::u8vec4 Vec(255, 128, 0, 255);
|
||||
glm::uint32 & Ref = *reinterpret_cast<glm::uint32*>(&Vec[0]);
|
||||
|
||||
Error += Packed == Ref ? 0 : 1;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
|
||||
A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint32 C = glm::packUnorm4x8(B);
|
||||
glm::vec4 D = glm::unpackUnorm4x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
|
||||
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint32 C = glm::packSnorm4x8(B);
|
||||
glm::vec4 D = glm::unpackSnorm4x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packHalf2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
/*
|
||||
std::vector<glm::hvec2> A;
|
||||
A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 2.0f)));
|
||||
A.push_back(glm::hvec2(glm::half(-1.0f), glm::half(-2.0f)));
|
||||
A.push_back(glm::hvec2(glm::half(-1.1f), glm::half( 1.1f)));
|
||||
*/
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2( 1.0f, 2.0f));
|
||||
A.push_back(glm::vec2(-1.0f,-2.0f));
|
||||
A.push_back(glm::vec2(-1.1f, 1.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint C = glm::packHalf2x16(B);
|
||||
glm::vec2 D = glm::unpackHalf2x16(C);
|
||||
//Error += B == D ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packDouble2x32()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::uvec2> A;
|
||||
A.push_back(glm::uvec2( 1, 2));
|
||||
A.push_back(glm::uvec2(-1,-2));
|
||||
A.push_back(glm::uvec2(-1000, 1100));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::uvec2 B(A[i]);
|
||||
double C = glm::packDouble2x32(B);
|
||||
glm::uvec2 D = glm::unpackDouble2x32(C);
|
||||
Error += B == D ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_packSnorm4x8();
|
||||
Error += test_packUnorm4x8();
|
||||
Error += test_packSnorm2x16();
|
||||
Error += test_packUnorm2x16();
|
||||
Error += test_packHalf2x16();
|
||||
Error += test_packDouble2x32();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
164
lib/glm/test/core/core_func_swizzle.cpp
Normal file
164
lib/glm/test/core/core_func_swizzle.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
static int test_ivec2_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::ivec2 A(1, 2);
|
||||
glm::ivec2 B = A.yx();
|
||||
glm::ivec2 C = B.yx();
|
||||
|
||||
Error += A != B ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec2 A(1, 2);
|
||||
glm::ivec2 B = A.yx;
|
||||
glm::ivec2 C = A.yx;
|
||||
|
||||
Error += A != B ? 0 : 1;
|
||||
Error += B == C ? 0 : 1;
|
||||
|
||||
B.xy = B.yx;
|
||||
C.xy = C.yx;
|
||||
|
||||
Error += B == C ? 0 : 1;
|
||||
|
||||
glm::ivec2 D(0, 0);
|
||||
D.yx = A.xy;
|
||||
Error += A.yx() == D ? 0 : 1;
|
||||
|
||||
glm::ivec2 E = A.yx;
|
||||
Error += E == D ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_ivec3_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::ivec3 A(1, 2, 3);
|
||||
glm::ivec3 B = A.zyx();
|
||||
glm::ivec3 C = B.zyx();
|
||||
|
||||
Error += A != B ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec2 B = A.yx;
|
||||
glm::ivec2 C = A.yx;
|
||||
|
||||
Error += A.yx() == B ? 0 : 1;
|
||||
Error += B == C ? 0 : 1;
|
||||
|
||||
B.xy = B.yx;
|
||||
C.xy = C.yx;
|
||||
|
||||
Error += B == C ? 0 : 1;
|
||||
|
||||
glm::ivec2 D(0, 0);
|
||||
D.yx = A.xy;
|
||||
|
||||
Error += A.yx() == D ? 0 : 1;
|
||||
|
||||
glm::ivec2 E(0, 0);
|
||||
E.xy = A.xy();
|
||||
|
||||
Error += E == A.xy() ? 0 : 1;
|
||||
Error += E.xy() == A.xy() ? 0 : 1;
|
||||
|
||||
glm::ivec3 const F = A.xxx + A.xxx;
|
||||
Error += F == glm::ivec3(2) ? 0 : 1;
|
||||
|
||||
glm::ivec3 const G = A.xxx - A.xxx;
|
||||
Error += G == glm::ivec3(0) ? 0 : 1;
|
||||
|
||||
glm::ivec3 const H = A.xxx * A.xxx;
|
||||
Error += H == glm::ivec3(1) ? 0 : 1;
|
||||
|
||||
glm::ivec3 const I = A.xxx / A.xxx;
|
||||
Error += I == glm::ivec3(1) ? 0 : 1;
|
||||
|
||||
glm::ivec3 J(1, 2, 3);
|
||||
J.xyz += glm::ivec3(1);
|
||||
Error += J == glm::ivec3(2, 3, 4) ? 0 : 1;
|
||||
|
||||
glm::ivec3 K(1, 2, 3);
|
||||
K.xyz += A.xyz;
|
||||
Error += K == glm::ivec3(2, 4, 6) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_ivec4_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::ivec4 A(1, 2, 3, 4);
|
||||
glm::ivec4 B = A.wzyx();
|
||||
glm::ivec4 C = B.wzyx();
|
||||
|
||||
Error += A != B ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec4_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::vec4 A(1, 2, 3, 4);
|
||||
glm::vec4 B = A.wzyx();
|
||||
glm::vec4 C = B.wzyx();
|
||||
|
||||
Error += glm::any(glm::notEqual(A, B, 0.0001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
|
||||
|
||||
float D = glm::dot(C.wzyx(), C.xyzw());
|
||||
Error += glm::equal(D, 20.f, 0.001f) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_ivec2_swizzle();
|
||||
Error += test_ivec3_swizzle();
|
||||
Error += test_ivec4_swizzle();
|
||||
Error += test_vec4_swizzle();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
lib/glm/test/core/core_func_trigonometric.cpp
Normal file
10
lib/glm/test/core/core_func_trigonometric.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
180
lib/glm/test/core/core_func_vector_relational.cpp
Normal file
180
lib/glm/test/core/core_func_vector_relational.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
|
||||
static int test_not()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::bvec1 v(false);
|
||||
Error += glm::all(glm::not_(v)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::bvec2 v(false);
|
||||
Error += glm::all(glm::not_(v)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::bvec3 v(false);
|
||||
Error += glm::all(glm::not_(v)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::bvec4 v(false);
|
||||
Error += glm::all(glm::not_(v)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_less()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec2 const A(1, 2);
|
||||
glm::vec2 const B(2, 3);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 const A(1, 2, 3);
|
||||
glm::vec3 const B(2, 3, 4);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 const A(1, 2, 3, 4);
|
||||
glm::vec4 const B(2, 3, 4, 5);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
Error += glm::all(glm::lessThanEqual(A, B)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 const A(1, 2);
|
||||
glm::ivec2 const B(2, 3);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
|
||||
glm::ivec2 const C(1, 3);
|
||||
Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec3 const B(2, 3, 4);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
|
||||
glm::ivec3 const C(1, 3, 4);
|
||||
Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
glm::ivec4 const B(2, 3, 4, 5);
|
||||
Error += glm::all(glm::lessThan(A, B)) ? 0: 1;
|
||||
|
||||
glm::ivec4 const C(1, 3, 4, 5);
|
||||
Error += glm::all(glm::lessThanEqual(A, C)) ? 0: 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_greater()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec2 const A(1, 2);
|
||||
glm::vec2 const B(2, 3);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 const A(1, 2, 3);
|
||||
glm::vec3 const B(2, 3, 4);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 const A(1, 2, 3, 4);
|
||||
glm::vec4 const B(2, 3, 4, 5);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
Error += glm::all(glm::greaterThanEqual(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 const A(1, 2);
|
||||
glm::ivec2 const B(2, 3);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
|
||||
glm::ivec2 const C(1, 3);
|
||||
Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec3 const B(2, 3, 4);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
|
||||
glm::ivec3 const C(1, 3, 4);
|
||||
Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
glm::ivec4 const B(2, 3, 4, 5);
|
||||
Error += glm::all(glm::greaterThan(B, A)) ? 0: 1;
|
||||
|
||||
glm::ivec4 const C(1, 3, 4, 5);
|
||||
Error += glm::all(glm::greaterThanEqual(C, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_equal()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec2 const A(1, 2);
|
||||
glm::ivec2 const B(1, 2);
|
||||
Error += glm::all(glm::equal(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec3 const B(1, 2, 3);
|
||||
Error += glm::all(glm::equal(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
glm::ivec4 const B(1, 2, 3, 4);
|
||||
Error += glm::all(glm::equal(B, A)) ? 0: 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_not();
|
||||
Error += test_less();
|
||||
Error += test_greater();
|
||||
Error += test_equal();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
12
lib/glm/test/core/core_setup_force_cxx98.cpp
Normal file
12
lib/glm/test/core/core_setup_force_cxx98.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef GLM_FORCE_CXX98
|
||||
# define GLM_FORCE_CXX98
|
||||
#endif
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
22
lib/glm/test/core/core_setup_force_size_t_length.cpp
Normal file
22
lib/glm/test/core/core_setup_force_size_t_length.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#define GLM_FORCE_SIZE_T_LENGTH
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
template <typename genType>
|
||||
genType add(genType const& a, genType const& b)
|
||||
{
|
||||
genType result(0);
|
||||
for(glm::length_t i = 0; i < a.length(); ++i)
|
||||
result[i] = a[i] + b[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec4 v(1);
|
||||
Error += add(v, v) == glm::ivec4(2) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
230
lib/glm/test/core/core_setup_message.cpp
Normal file
230
lib/glm/test/core/core_setup_message.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
#define GLM_FORCE_MESSAGES
|
||||
#include <glm/vec3.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
int test_compiler()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
if(GLM_COMPILER & GLM_COMPILER_VC)
|
||||
{
|
||||
switch(GLM_COMPILER)
|
||||
{
|
||||
case GLM_COMPILER_VC12:
|
||||
std::printf("Visual C++ 12 - 2013\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC14:
|
||||
std::printf("Visual C++ 14 - 2015\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15:
|
||||
std::printf("Visual C++ 15 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_3:
|
||||
std::printf("Visual C++ 15.3 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_5:
|
||||
std::printf("Visual C++ 15.5 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_6:
|
||||
std::printf("Visual C++ 15.6 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_7:
|
||||
std::printf("Visual C++ 15.7 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_8:
|
||||
std::printf("Visual C++ 15.8 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC15_9:
|
||||
std::printf("Visual C++ 15.9 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_VC16:
|
||||
std::printf("Visual C++ 16 - 2019\n");
|
||||
break;
|
||||
default:
|
||||
std::printf("Visual C++ version not detected\n");
|
||||
Error += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(GLM_COMPILER & GLM_COMPILER_GCC)
|
||||
{
|
||||
switch(GLM_COMPILER)
|
||||
{
|
||||
case GLM_COMPILER_GCC46:
|
||||
std::printf("GCC 4.6\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC47:
|
||||
std::printf("GCC 4.7\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC48:
|
||||
std::printf("GCC 4.8\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC49:
|
||||
std::printf("GCC 4.9\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC5:
|
||||
std::printf("GCC 5\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC6:
|
||||
std::printf("GCC 6\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC7:
|
||||
std::printf("GCC 7\n");
|
||||
break;
|
||||
case GLM_COMPILER_GCC8:
|
||||
std::printf("GCC 8\n");
|
||||
break;
|
||||
default:
|
||||
std::printf("GCC version not detected\n");
|
||||
Error += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(GLM_COMPILER & GLM_COMPILER_CUDA)
|
||||
{
|
||||
std::printf("CUDA\n");
|
||||
}
|
||||
else if(GLM_COMPILER & GLM_COMPILER_CLANG)
|
||||
{
|
||||
switch(GLM_COMPILER)
|
||||
{
|
||||
case GLM_COMPILER_CLANG34:
|
||||
std::printf("Clang 3.4\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG35:
|
||||
std::printf("Clang 3.5\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG36:
|
||||
std::printf("Clang 3.6\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG37:
|
||||
std::printf("Clang 3.7\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG38:
|
||||
std::printf("Clang 3.8\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG39:
|
||||
std::printf("Clang 3.9\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG40:
|
||||
std::printf("Clang 4.0\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG41:
|
||||
std::printf("Clang 4.1\n");
|
||||
break;
|
||||
case GLM_COMPILER_CLANG42:
|
||||
std::printf("Clang 4.2\n");
|
||||
break;
|
||||
default:
|
||||
std::printf("LLVM version not detected\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(GLM_COMPILER & GLM_COMPILER_INTEL)
|
||||
{
|
||||
switch(GLM_COMPILER)
|
||||
{
|
||||
case GLM_COMPILER_INTEL14:
|
||||
std::printf("ICC 14 - 2013 SP1\n");
|
||||
break;
|
||||
case GLM_COMPILER_INTEL15:
|
||||
std::printf("ICC 15 - 2015\n");
|
||||
break;
|
||||
case GLM_COMPILER_INTEL16:
|
||||
std::printf("ICC 16 - 2017\n");
|
||||
break;
|
||||
case GLM_COMPILER_INTEL17:
|
||||
std::printf("ICC 17 - 20XX\n");
|
||||
break;
|
||||
default:
|
||||
std::printf("Intel compiler version not detected\n");
|
||||
Error += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("Undetected compiler\n");
|
||||
Error += 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_model()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += ((sizeof(void*) == 4) && (GLM_MODEL == GLM_MODEL_32)) || ((sizeof(void*) == 8) && (GLM_MODEL == GLM_MODEL_64)) ? 0 : 1;
|
||||
|
||||
if(GLM_MODEL == GLM_MODEL_32)
|
||||
std::printf("GLM_MODEL_32\n");
|
||||
else if(GLM_MODEL == GLM_MODEL_64)
|
||||
std::printf("GLM_MODEL_64\n");
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_instruction_set()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::printf("GLM_ARCH: ");
|
||||
|
||||
if(GLM_ARCH & GLM_ARCH_ARM_BIT)
|
||||
std::printf("ARM ");
|
||||
if(GLM_ARCH & GLM_ARCH_NEON_BIT)
|
||||
std::printf("NEON ");
|
||||
if(GLM_ARCH & GLM_ARCH_AVX2)
|
||||
std::printf("AVX2 ");
|
||||
if(GLM_ARCH & GLM_ARCH_AVX)
|
||||
std::printf("AVX ");
|
||||
if(GLM_ARCH & GLM_ARCH_SSE42_BIT)
|
||||
std::printf("SSE4.2 ");
|
||||
if(GLM_ARCH & GLM_ARCH_SSE41_BIT)
|
||||
std::printf("SSE4.1 ");
|
||||
if(GLM_ARCH & GLM_ARCH_SSSE3_BIT)
|
||||
std::printf("SSSE3 ");
|
||||
if(GLM_ARCH & GLM_ARCH_SSE3_BIT)
|
||||
std::printf("SSE3 ");
|
||||
if(GLM_ARCH & GLM_ARCH_SSE2_BIT)
|
||||
std::printf("SSE2 ");
|
||||
|
||||
std::printf("\n");
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_cpp_version()
|
||||
{
|
||||
std::printf("__cplusplus: %d\n", static_cast<int>(__cplusplus));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_operators()
|
||||
{
|
||||
glm::ivec3 A(1);
|
||||
glm::ivec3 B(1);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if !defined(GLM_FORCE_PLATFORM_UNKNOWN) && !defined(GLM_FORCE_COMPILER_UNKNOWN) && !defined(GLM_FORCE_ARCH_UNKNOWN) && !defined(GLM_FORCE_CXX_UNKNOWN)
|
||||
|
||||
Error += test_cpp_version();
|
||||
Error += test_compiler();
|
||||
Error += test_model();
|
||||
Error += test_instruction_set();
|
||||
Error += test_operators();
|
||||
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
21
lib/glm/test/core/core_setup_platform_unknown.cpp
Normal file
21
lib/glm/test/core/core_setup_platform_unknown.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GLM_FORCE_PLATFORM_UNKNOWN
|
||||
# define GLM_FORCE_PLATFORM_UNKNOWN
|
||||
#endif
|
||||
#ifndef GLM_FORCE_COMPILER_UNKNOWN
|
||||
# define GLM_FORCE_COMPILER_UNKNOWN
|
||||
#endif
|
||||
#ifndef GLM_FORCE_ARCH_UNKNOWN
|
||||
# define GLM_FORCE_ARCH_UNKNOWN
|
||||
#endif
|
||||
#ifndef GLM_FORCE_CXX_UNKNOWN
|
||||
# define GLM_FORCE_CXX_UNKNOWN
|
||||
#endif
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
58
lib/glm/test/core/core_setup_precision.cpp
Normal file
58
lib/glm/test/core/core_setup_precision.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#define GLM_FORCE_INLINE
|
||||
#define GLM_PRECISION_HIGHP_FLOAT
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
static int test_mat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::mat2) == sizeof(glm::highp_mat2) ? 0 : 1;
|
||||
Error += sizeof(glm::mat3) == sizeof(glm::highp_mat3) ? 0 : 1;
|
||||
Error += sizeof(glm::mat4) == sizeof(glm::highp_mat4) ? 0 : 1;
|
||||
|
||||
Error += sizeof(glm::mat2x2) == sizeof(glm::highp_mat2x2) ? 0 : 1;
|
||||
Error += sizeof(glm::mat2x3) == sizeof(glm::highp_mat2x3) ? 0 : 1;
|
||||
Error += sizeof(glm::mat2x4) == sizeof(glm::highp_mat2x4) ? 0 : 1;
|
||||
Error += sizeof(glm::mat3x2) == sizeof(glm::highp_mat3x2) ? 0 : 1;
|
||||
Error += sizeof(glm::mat3x3) == sizeof(glm::highp_mat3x3) ? 0 : 1;
|
||||
Error += sizeof(glm::mat3x4) == sizeof(glm::highp_mat3x4) ? 0 : 1;
|
||||
Error += sizeof(glm::mat4x2) == sizeof(glm::highp_mat4x2) ? 0 : 1;
|
||||
Error += sizeof(glm::mat4x3) == sizeof(glm::highp_mat4x3) ? 0 : 1;
|
||||
Error += sizeof(glm::mat4x4) == sizeof(glm::highp_mat4x4) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec2) == sizeof(glm::highp_vec2) ? 0 : 1;
|
||||
Error += sizeof(glm::vec3) == sizeof(glm::highp_vec3) ? 0 : 1;
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_dvec()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::dvec2) == sizeof(glm::highp_dvec2) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec3) == sizeof(glm::highp_dvec3) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_mat();
|
||||
Error += test_vec();
|
||||
Error += test_dvec();
|
||||
|
||||
return Error;
|
||||
}
|
||||
92
lib/glm/test/core/core_type_aligned.cpp
Normal file
92
lib/glm/test/core/core_type_aligned.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(sizeof(glm::bvec4) > sizeof(glm::bvec2), "Invalid sizeof");
|
||||
static_assert(sizeof(glm::ivec4) > sizeof(glm::uvec2), "Invalid sizeof");
|
||||
static_assert(sizeof(glm::dvec4) > sizeof(glm::dvec2), "Invalid sizeof");
|
||||
|
||||
static_assert(sizeof(glm::bvec4) == sizeof(glm::bvec3), "Invalid sizeof");
|
||||
static_assert(sizeof(glm::uvec4) == sizeof(glm::uvec3), "Invalid sizeof");
|
||||
static_assert(sizeof(glm::dvec4) == sizeof(glm::dvec3), "Invalid sizeof");
|
||||
|
||||
static int test_storage_aligned()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
size_t size1_aligned = sizeof(glm::detail::storage<1, int, true>::type);
|
||||
Error += size1_aligned == sizeof(int) * 1 ? 0 : 1;
|
||||
size_t size2_aligned = sizeof(glm::detail::storage<2, int, true>::type);
|
||||
Error += size2_aligned == sizeof(int) * 2 ? 0 : 1;
|
||||
size_t size4_aligned = sizeof(glm::detail::storage<4, int, true>::type);
|
||||
Error += size4_aligned == sizeof(int) * 4 ? 0 : 1;
|
||||
|
||||
size_t align1_aligned = alignof(glm::detail::storage<1, int, true>::type);
|
||||
Error += align1_aligned == 4 ? 0 : 1;
|
||||
size_t align2_aligned = alignof(glm::detail::storage<2, int, true>::type);
|
||||
Error += align2_aligned == 8 ? 0 : 1;
|
||||
size_t align4_aligned = alignof(glm::detail::storage<4, int, true>::type);
|
||||
Error += align4_aligned == 16 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_storage_unaligned()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
size_t align1_unaligned = alignof(glm::detail::storage<1, int, false>::type);
|
||||
Error += align1_unaligned == sizeof(int) ? 0 : 1;
|
||||
size_t align2_unaligned = alignof(glm::detail::storage<2, int, false>::type);
|
||||
Error += align2_unaligned == sizeof(int) ? 0 : 1;
|
||||
size_t align3_unaligned = alignof(glm::detail::storage<3, int, false>::type);
|
||||
Error += align3_unaligned == sizeof(int) ? 0 : 1;
|
||||
size_t align4_unaligned = alignof(glm::detail::storage<4, int, false>::type);
|
||||
Error += align4_unaligned == sizeof(int) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec3_aligned()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
struct Struct1
|
||||
{
|
||||
glm::vec4 A;
|
||||
float B;
|
||||
glm::vec3 C;
|
||||
};
|
||||
|
||||
std::size_t const Size1 = sizeof(Struct1);
|
||||
Error += Size1 == 48 ? 0 : 1;
|
||||
|
||||
struct Struct2
|
||||
{
|
||||
glm::vec4 A;
|
||||
glm::vec3 B;
|
||||
float C;
|
||||
};
|
||||
|
||||
std::size_t const Size2 = sizeof(Struct2);
|
||||
Error += Size2 == 48 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
|
||||
Error += test_storage_aligned();
|
||||
Error += test_storage_unaligned();
|
||||
Error += test_vec3_aligned();
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
146
lib/glm/test/core/core_type_cast.cpp
Normal file
146
lib/glm/test/core/core_type_cast.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
|
||||
struct my_vec2
|
||||
{
|
||||
operator glm::vec2() { return glm::vec2(x, y); }
|
||||
float x, y;
|
||||
};
|
||||
|
||||
int test_vec2_cast()
|
||||
{
|
||||
glm::vec2 A(1.0f, 2.0f);
|
||||
glm::lowp_vec2 B(A);
|
||||
glm::mediump_vec2 C(A);
|
||||
glm::highp_vec2 D(A);
|
||||
|
||||
glm::vec2 E = static_cast<glm::vec2>(A);
|
||||
glm::lowp_vec2 F = static_cast<glm::lowp_vec2>(A);
|
||||
glm::mediump_vec2 G = static_cast<glm::mediump_vec2>(A);
|
||||
glm::highp_vec2 H = static_cast<glm::highp_vec2>(A);
|
||||
|
||||
my_vec2 I;
|
||||
glm::vec2 J = static_cast<glm::vec2>(I);
|
||||
glm::vec2 K(7.8f);
|
||||
|
||||
int Error(0);
|
||||
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_cast()
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::lowp_vec3 B(A);
|
||||
glm::mediump_vec3 C(A);
|
||||
glm::highp_vec3 D(A);
|
||||
|
||||
glm::vec3 E = static_cast<glm::vec3>(A);
|
||||
glm::lowp_vec3 F = static_cast<glm::lowp_vec3>(A);
|
||||
glm::mediump_vec3 G = static_cast<glm::mediump_vec3>(A);
|
||||
glm::highp_vec3 H = static_cast<glm::highp_vec3>(A);
|
||||
|
||||
int Error(0);
|
||||
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec4_cast()
|
||||
{
|
||||
glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::lowp_vec4 B(A);
|
||||
glm::mediump_vec4 C(A);
|
||||
glm::highp_vec4 D(A);
|
||||
|
||||
glm::vec4 E = static_cast<glm::vec4>(A);
|
||||
glm::lowp_vec4 F = static_cast<glm::lowp_vec4>(A);
|
||||
glm::mediump_vec4 G = static_cast<glm::mediump_vec4>(A);
|
||||
glm::highp_vec4 H = static_cast<glm::highp_vec4>(A);
|
||||
|
||||
int Error(0);
|
||||
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(B, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(C, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(D, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_std_copy()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
std::vector<int> High;
|
||||
High.resize(64);
|
||||
std::vector<int> Medium(High.size());
|
||||
|
||||
std::copy(High.begin(), High.end(), Medium.begin());
|
||||
|
||||
*Medium.begin() = *High.begin();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::dvec4> High4;
|
||||
High4.resize(64);
|
||||
std::vector<glm::vec4> Medium4(High4.size());
|
||||
|
||||
std::copy(High4.begin(), High4.end(), Medium4.begin());
|
||||
|
||||
*Medium4.begin() = *High4.begin();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::dvec3> High3;
|
||||
High3.resize(64);
|
||||
std::vector<glm::vec3> Medium3(High3.size());
|
||||
|
||||
std::copy(High3.begin(), High3.end(), Medium3.begin());
|
||||
|
||||
*Medium3.begin() = *High3.begin();
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::dvec2> High2;
|
||||
High2.resize(64);
|
||||
std::vector<glm::vec2> Medium2(High2.size());
|
||||
|
||||
std::copy(High2.begin(), High2.end(), Medium2.begin());
|
||||
|
||||
*Medium2.begin() = *High2.begin();
|
||||
}
|
||||
|
||||
glm::dvec4 v1;
|
||||
glm::vec4 v2;
|
||||
|
||||
v2 = v1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_std_copy();
|
||||
Error += test_vec2_cast();
|
||||
Error += test_vec3_cast();
|
||||
Error += test_vec4_cast();
|
||||
|
||||
return Error;
|
||||
}
|
||||
351
lib/glm/test/core/core_type_ctor.cpp
Normal file
351
lib/glm/test/core/core_type_ctor.cpp
Normal file
@@ -0,0 +1,351 @@
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
static int test_vec1_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::vec1 f;
|
||||
glm::ivec1 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::vec1(0);
|
||||
Error += glm::all(glm::equal(A.i, glm::ivec1(0))) ? 0 : 1;
|
||||
|
||||
B.f = glm::vec1(1);
|
||||
Error += glm::all(glm::equal(B.i, glm::ivec1(1065353216))) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec2_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::vec2 f;
|
||||
glm::ivec2 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::vec2(0);
|
||||
Error += glm::all(glm::equal(A.i, glm::ivec2(0))) ? 0 : 1;
|
||||
|
||||
B.f = glm::vec2(1);
|
||||
Error += glm::all(glm::equal(B.i, glm::ivec2(1065353216))) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::vec3 f;
|
||||
glm::ivec3 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::vec3(0);
|
||||
Error += glm::all(glm::equal(A.i, glm::ivec3(0))) ? 0 : 1;
|
||||
|
||||
B.f = glm::vec3(1);
|
||||
Error += glm::all(glm::equal(B.i, glm::ivec3(1065353216))) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_ENABLE
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::vec4 f;
|
||||
glm::ivec4 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::vec4(0);
|
||||
Error += glm::all(glm::equal(A.i, glm::ivec4(0))) ? 0 : 1;
|
||||
|
||||
B.f = glm::vec4(1);
|
||||
Error += glm::all(glm::equal(B.i, glm::ivec4(1065353216))) ? 0 : 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat2x2_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat2x2 f;
|
||||
glm::mat2x2 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat2x2(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat2x2(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat2x3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat2x3 f;
|
||||
glm::mat2x3 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat2x3(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat2x3(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat2x4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat2x4 f;
|
||||
glm::mat2x4 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat2x4(0);
|
||||
glm::vec4 const C(0, 0, 0, 0);
|
||||
Error += glm::all(glm::equal(A.i[0], C, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat2x4(1);
|
||||
glm::vec4 const D(1, 0, 0, 0);
|
||||
Error += glm::all(glm::equal(B.i[0], D, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat3x2_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat3x2 f;
|
||||
glm::mat3x2 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat3x2(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat3x2(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat3x3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat3x3 f;
|
||||
glm::mat3x3 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat3x3(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat3x3(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat3x4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat3x4 f;
|
||||
glm::mat3x4 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat3x4(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec4(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat3x4(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat4x2_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat4x2 f;
|
||||
glm::mat4x2 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat4x2(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec2(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat4x2(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec2(1, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat4x3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat4x3 f;
|
||||
glm::mat4x3 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat4x3(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec3(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat4x3(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec3(1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mat4x4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::mat4 f;
|
||||
glm::mat4 i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::mat4(0);
|
||||
Error += glm::all(glm::equal(A.i[0], glm::vec4(0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::mat4(1);
|
||||
Error += glm::all(glm::equal(B.i[0], glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_quat_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
{
|
||||
union pack
|
||||
{
|
||||
glm::quat f;
|
||||
glm::quat i;
|
||||
} A, B;
|
||||
|
||||
A.f = glm::quat(0, 0, 0, 0);
|
||||
Error += glm::all(glm::equal(A.i, glm::quat(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
B.f = glm::quat(1, 1, 1, 1);
|
||||
Error += glm::all(glm::equal(B.i, glm::quat(1, 1, 1, 1), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec1_ctor();
|
||||
Error += test_vec2_ctor();
|
||||
Error += test_vec3_ctor();
|
||||
Error += test_vec4_ctor();
|
||||
Error += test_mat2x2_ctor();
|
||||
Error += test_mat2x3_ctor();
|
||||
Error += test_mat2x4_ctor();
|
||||
Error += test_mat3x2_ctor();
|
||||
Error += test_mat3x3_ctor();
|
||||
Error += test_mat3x4_ctor();
|
||||
Error += test_mat4x2_ctor();
|
||||
Error += test_mat4x3_ctor();
|
||||
Error += test_mat4x4_ctor();
|
||||
Error += test_quat_ctor();
|
||||
|
||||
return Error;
|
||||
}
|
||||
26
lib/glm/test/core/core_type_int.cpp
Normal file
26
lib/glm/test/core/core_type_int.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/scalar_int_sized.hpp>
|
||||
|
||||
static int test_bit_operator()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec4 const a(1);
|
||||
glm::ivec4 const b = ~a;
|
||||
Error += glm::all(glm::equal(b, glm::ivec4(-2))) ? 0 : 1;
|
||||
|
||||
glm::int32 const c(1);
|
||||
glm::int32 const d = ~c;
|
||||
Error += d == -2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_bit_operator();
|
||||
|
||||
return Error;
|
||||
}
|
||||
79
lib/glm/test/core/core_type_length.cpp
Normal file
79
lib/glm/test/core/core_type_length.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
static int test_length_mat_non_squared()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::mat2x3().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat2x4().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat3x2().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat3x4().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat4x2().length() == 4 ? 0 : 1;
|
||||
Error += glm::mat4x3().length() == 4 ? 0 : 1;
|
||||
|
||||
Error += glm::dmat2x3().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x4().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat3x2().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x4().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat4x2().length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4x3().length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_length_mat()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::mat2().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat3().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat4().length() == 4 ? 0 : 1;
|
||||
Error += glm::mat2x2().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat3x3().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat4x4().length() == 4 ? 0 : 1;
|
||||
|
||||
Error += glm::dmat2().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat3().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat4().length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat2x2().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat3x3().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat4x4().length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_length_vec()
|
||||
{
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::vec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::vec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::vec4().length() == 4 ? 0 : 1;
|
||||
|
||||
Error += glm::ivec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::ivec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::ivec4().length() == 4 ? 0 : 1;
|
||||
|
||||
Error += glm::uvec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::uvec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::uvec4().length() == 4 ? 0 : 1;
|
||||
|
||||
Error += glm::dvec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::dvec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::dvec4().length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_length_vec();
|
||||
Error += test_length_mat();
|
||||
Error += test_length_mat_non_squared();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
177
lib/glm/test/core/core_type_mat2x2.cpp
Normal file
177
lib/glm/test/core/core_type_mat2x2.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
int test_operators()
|
||||
{
|
||||
glm::mat2x2 l(1.0f);
|
||||
glm::mat2x2 m(1.0f);
|
||||
glm::vec2 u(1.0f);
|
||||
glm::vec2 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec2 a = m * u;
|
||||
glm::vec2 b = v * m;
|
||||
glm::mat2x2 n = x / m;
|
||||
glm::mat2x2 o = m / x;
|
||||
glm::mat2x2 p = x * m;
|
||||
glm::mat2x2 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_inverse()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
glm::mat2 const Matrix(1, 2, 3, 4);
|
||||
glm::mat2 const Inverse = glm::inverse(Matrix);
|
||||
glm::mat2 const Identity = Matrix * Inverse;
|
||||
|
||||
Error += glm::all(glm::equal(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat2 const Matrix(1, 2, 3, 4);
|
||||
glm::mat2 const Identity = Matrix / Matrix;
|
||||
|
||||
Error += glm::all(glm::equal(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mediump_mat2x2 const A(1.0f);
|
||||
glm::highp_mat2x2 const B(A);
|
||||
glm::mediump_mat2x2 const C(B);
|
||||
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
glm::mat2x2 m0(
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(2, 3));
|
||||
|
||||
glm::mat2x2 m1{0, 1, 2, 3};
|
||||
|
||||
glm::mat2x2 m2{
|
||||
{0, 1},
|
||||
{2, 3}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat2x2> v1{
|
||||
{0, 1, 2, 3},
|
||||
{0, 1, 2, 3}
|
||||
};
|
||||
|
||||
std::vector<glm::mat2x2> v2{
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 4, 5}
|
||||
},
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 4, 5}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat2 B(A);
|
||||
glm::mat2 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 16 == sizeof(glm::mat2x2) ? 0 : 1;
|
||||
Error += 32 == sizeof(glm::dmat2x2) ? 0 : 1;
|
||||
Error += glm::mat2x2().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x2().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat2x2::length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x2::length() == 2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_inverse();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
142
lib/glm/test/core/core_type_mat2x3.cpp
Normal file
142
lib/glm/test/core/core_type_mat2x3.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
glm::mat2x3 l(1.0f);
|
||||
glm::mat2x3 m(1.0f);
|
||||
glm::vec2 u(1.0f);
|
||||
glm::vec3 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec3 a = m * u;
|
||||
glm::vec2 b = v * m;
|
||||
glm::mat2x3 n = x / m;
|
||||
glm::mat2x3 o = m / x;
|
||||
glm::mat2x3 p = x * m;
|
||||
glm::mat2x3 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
glm::mat2x3 m0(
|
||||
glm::vec3(0, 1, 2),
|
||||
glm::vec3(3, 4, 5));
|
||||
|
||||
glm::mat2x3 m1{0, 1, 2, 3, 4, 5};
|
||||
|
||||
glm::mat2x3 m2{
|
||||
{0, 1, 2},
|
||||
{3, 4, 5}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat2x3> v1{
|
||||
{0, 1, 2, 3, 4, 5},
|
||||
{0, 1, 2, 3, 4, 5}
|
||||
};
|
||||
|
||||
std::vector<glm::mat2x3> v2{
|
||||
{
|
||||
{ 0, 1, 2},
|
||||
{ 4, 5, 6}
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2},
|
||||
{ 4, 5, 6}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat2x3 B(A);
|
||||
glm::mat2x3 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 24 == sizeof(glm::mat2x3) ? 0 : 1;
|
||||
Error += 48 == sizeof(glm::dmat2x3) ? 0 : 1;
|
||||
Error += glm::mat2x3().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x3().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat2x3::length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x3::length() == 2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat2x3::length() == 2, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
147
lib/glm/test/core/core_type_mat2x4.cpp
Normal file
147
lib/glm/test/core/core_type_mat2x4.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
glm::mat2x4 l(1.0f);
|
||||
glm::mat2x4 m(1.0f);
|
||||
glm::vec2 u(1.0f);
|
||||
glm::vec4 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec4 a = m * u;
|
||||
glm::vec2 b = v * m;
|
||||
glm::mat2x4 n = x / m;
|
||||
glm::mat2x4 o = m / x;
|
||||
glm::mat2x4 p = x * m;
|
||||
glm::mat2x4 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat2x4 m0(
|
||||
glm::vec4(0, 1, 2, 3),
|
||||
glm::vec4(4, 5, 6, 7));
|
||||
|
||||
glm::mat2x4 m1{0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
glm::mat2x4 m2{
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat2x4> v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
};
|
||||
|
||||
std::vector<glm::mat2x4> v2{
|
||||
{
|
||||
{ 0, 1, 2, 3},
|
||||
{ 4, 5, 6, 7}
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2, 3},
|
||||
{ 4, 5, 6, 7}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat2x4 B(A);
|
||||
glm::mat2x4 Identity(1.0f);
|
||||
|
||||
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
|
||||
Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 32 == sizeof(glm::mat2x4) ? 0 : 1;
|
||||
Error += 64 == sizeof(glm::dmat2x4) ? 0 : 1;
|
||||
Error += glm::mat2x4().length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x4().length() == 2 ? 0 : 1;
|
||||
Error += glm::mat2x4::length() == 2 ? 0 : 1;
|
||||
Error += glm::dmat2x4::length() == 2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat2x4::length() == 2, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
148
lib/glm/test/core/core_type_mat3x2.cpp
Normal file
148
lib/glm/test/core/core_type_mat3x2.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static bool test_operators()
|
||||
{
|
||||
glm::mat3x2 l(1.0f);
|
||||
glm::mat3x2 m(1.0f);
|
||||
glm::vec3 u(1.0f);
|
||||
glm::vec2 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec2 a = m * u;
|
||||
glm::vec3 b = v * m;
|
||||
glm::mat3x2 n = x / m;
|
||||
glm::mat3x2 o = m / x;
|
||||
glm::mat3x2 p = x * m;
|
||||
glm::mat3x2 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat3x2 m0(
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(2, 3),
|
||||
glm::vec2(4, 5));
|
||||
|
||||
glm::mat3x2 m1{0, 1, 2, 3, 4, 5};
|
||||
|
||||
glm::mat3x2 m2{
|
||||
{0, 1},
|
||||
{2, 3},
|
||||
{4, 5}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat3x2> v1{
|
||||
{0, 1, 2, 3, 4, 5},
|
||||
{0, 1, 2, 3, 4, 5}
|
||||
};
|
||||
|
||||
std::vector<glm::mat3x2> v2{
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 2, 3},
|
||||
{ 4, 5}
|
||||
},
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 2, 3},
|
||||
{ 4, 5}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat3x2 B(A);
|
||||
glm::mat3x2 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 24 == sizeof(glm::mat3x2) ? 0 : 1;
|
||||
Error += 48 == sizeof(glm::dmat3x2) ? 0 : 1;
|
||||
Error += glm::mat3x2().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x2().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat3x2::length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x2::length() == 3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat3x2::length() == 3, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
197
lib/glm/test/core/core_type_mat3x3.cpp
Normal file
197
lib/glm/test/core/core_type_mat3x3.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_mat3x3()
|
||||
{
|
||||
glm::dmat3 Mat0(
|
||||
glm::dvec3(0.6f, 0.2f, 0.3f),
|
||||
glm::dvec3(0.2f, 0.7f, 0.5f),
|
||||
glm::dvec3(0.3f, 0.5f, 0.7f));
|
||||
glm::dmat3 Inv0 = glm::inverse(Mat0);
|
||||
glm::dmat3 Res0 = Mat0 * Inv0;
|
||||
|
||||
return glm::all(glm::equal(Res0, glm::dmat3(1.0), 0.01)) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
glm::mat3x3 l(1.0f);
|
||||
glm::mat3x3 m(1.0f);
|
||||
glm::vec3 u(1.0f);
|
||||
glm::vec3 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec3 a = m * u;
|
||||
glm::vec3 b = v * m;
|
||||
glm::mat3x3 n = x / m;
|
||||
glm::mat3x3 o = m / x;
|
||||
glm::mat3x3 p = x * m;
|
||||
glm::mat3x3 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int test_inverse()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
glm::mat3 const Matrix(
|
||||
glm::vec3(0.6f, 0.2f, 0.3f),
|
||||
glm::vec3(0.2f, 0.7f, 0.5f),
|
||||
glm::vec3(0.3f, 0.5f, 0.7f));
|
||||
glm::mat3 const Inverse = glm::inverse(Matrix);
|
||||
glm::mat3 const Identity = Matrix * Inverse;
|
||||
|
||||
Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat3 const Matrix(
|
||||
glm::vec3(0.6f, 0.2f, 0.3f),
|
||||
glm::vec3(0.2f, 0.7f, 0.5f),
|
||||
glm::vec3(0.3f, 0.5f, 0.7f));
|
||||
glm::mat3 const Identity = Matrix / Matrix;
|
||||
|
||||
Error += glm::all(glm::equal(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat3x3 m0(
|
||||
glm::vec3(0, 1, 2),
|
||||
glm::vec3(3, 4, 5),
|
||||
glm::vec3(6, 7, 8));
|
||||
|
||||
glm::mat3x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
glm::mat3x3 m2{
|
||||
{0, 1, 2},
|
||||
{3, 4, 5},
|
||||
{6, 7, 8}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat3x3> v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8}
|
||||
};
|
||||
|
||||
std::vector<glm::mat3x3> v2{
|
||||
{
|
||||
{ 0, 1, 2},
|
||||
{ 3, 4, 5},
|
||||
{ 6, 7, 8}
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2},
|
||||
{ 3, 4, 5},
|
||||
{ 6, 7, 8}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat3x3 B(A);
|
||||
glm::mat3x3 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 36 == sizeof(glm::mat3x3) ? 0 : 1;
|
||||
Error += 72 == sizeof(glm::dmat3x3) ? 0 : 1;
|
||||
Error += glm::mat3x3().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x3().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat3x3::length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x3::length() == 3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat3x3::length() == 3, "GLM: Failed constexpr");
|
||||
|
||||
constexpr glm::mat3x3 const Z(0.0f);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_mat3x3();
|
||||
Error += test_operators();
|
||||
Error += test_inverse();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
149
lib/glm/test/core/core_type_mat3x4.cpp
Normal file
149
lib/glm/test/core/core_type_mat3x4.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static bool test_operators()
|
||||
{
|
||||
glm::mat3x4 l(1.0f);
|
||||
glm::mat3x4 m(1.0f);
|
||||
glm::vec3 u(1.0f);
|
||||
glm::vec4 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec4 a = m * u;
|
||||
glm::vec3 b = v * m;
|
||||
glm::mat3x4 n = x / m;
|
||||
glm::mat3x4 o = m / x;
|
||||
glm::mat3x4 p = x * m;
|
||||
glm::mat3x4 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat3x4 m0(
|
||||
glm::vec4(0, 1, 2, 3),
|
||||
glm::vec4(4, 5, 6, 7),
|
||||
glm::vec4(8, 9, 10, 11));
|
||||
|
||||
glm::mat3x4 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||
|
||||
glm::mat3x4 m2{
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 10, 11}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat3x4> v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||
};
|
||||
|
||||
std::vector<glm::mat3x4> v2{
|
||||
{
|
||||
{ 0, 1, 2, 3},
|
||||
{ 4, 5, 6, 7},
|
||||
{ 8, 9, 10, 11}
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2, 3},
|
||||
{ 4, 5, 6, 7},
|
||||
{ 8, 9, 10, 11}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat3x4 B(A);
|
||||
glm::mat3x4 Identity(1.0f);
|
||||
|
||||
for(glm::length_t i = 0, length = B.length(); i < length; ++i)
|
||||
Error += glm::all(glm::epsilonEqual(B[i], Identity[i], glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 48 == sizeof(glm::mat3x4) ? 0 : 1;
|
||||
Error += 96 == sizeof(glm::dmat3x4) ? 0 : 1;
|
||||
Error += glm::mat3x4().length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x4().length() == 3 ? 0 : 1;
|
||||
Error += glm::mat3x4::length() == 3 ? 0 : 1;
|
||||
Error += glm::dmat3x4::length() == 3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat3x4::length() == 3, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
151
lib/glm/test/core/core_type_mat4x2.cpp
Normal file
151
lib/glm/test/core/core_type_mat4x2.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
glm::mat4x2 l(1.0f);
|
||||
glm::mat4x2 m(1.0f);
|
||||
glm::vec4 u(1.0f);
|
||||
glm::vec2 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec2 a = m * u;
|
||||
glm::vec4 b = v * m;
|
||||
glm::mat4x2 n = x / m;
|
||||
glm::mat4x2 o = m / x;
|
||||
glm::mat4x2 p = x * m;
|
||||
glm::mat4x2 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat4x2 m0(
|
||||
glm::vec2(0, 1),
|
||||
glm::vec2(2, 3),
|
||||
glm::vec2(4, 5),
|
||||
glm::vec2(6, 7));
|
||||
|
||||
glm::mat4x2 m1{0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
glm::mat4x2 m2{
|
||||
{0, 1},
|
||||
{2, 3},
|
||||
{4, 5},
|
||||
{6, 7}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat4x2> v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
};
|
||||
|
||||
std::vector<glm::mat4x2> v2{
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 4, 5},
|
||||
{ 8, 9},
|
||||
{ 12, 13}
|
||||
},
|
||||
{
|
||||
{ 0, 1},
|
||||
{ 4, 5},
|
||||
{ 8, 9},
|
||||
{ 12, 13}
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat4x2 B(A);
|
||||
glm::mat4x2 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 32 == sizeof(glm::mat4x2) ? 0 : 1;
|
||||
Error += 64 == sizeof(glm::dmat4x2) ? 0 : 1;
|
||||
Error += glm::mat4x2().length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4x2().length() == 4 ? 0 : 1;
|
||||
Error += glm::mat4x2::length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4x2::length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat4x2::length() == 4, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
152
lib/glm/test/core/core_type_mat4x3.cpp
Normal file
152
lib/glm/test/core/core_type_mat4x3.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
#include <glm/mat2x3.hpp>
|
||||
#include <glm/mat2x4.hpp>
|
||||
#include <glm/mat3x2.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include <glm/mat3x4.hpp>
|
||||
#include <glm/mat4x2.hpp>
|
||||
#include <glm/mat4x3.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
glm::mat4x3 l(1.0f);
|
||||
glm::mat4x3 m(1.0f);
|
||||
glm::vec4 u(1.0f);
|
||||
glm::vec3 v(1.0f);
|
||||
float x = 1.0f;
|
||||
glm::vec3 a = m * u;
|
||||
glm::vec4 b = v * m;
|
||||
glm::mat4x3 n = x / m;
|
||||
glm::mat4x3 o = m / x;
|
||||
glm::mat4x3 p = x * m;
|
||||
glm::mat4x3 q = m * x;
|
||||
bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
|
||||
bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
#if(GLM_HAS_INITIALIZER_LISTS)
|
||||
glm::mat4x3 m0(
|
||||
glm::vec3(0, 1, 2),
|
||||
glm::vec3(3, 4, 5),
|
||||
glm::vec3(6, 7, 8),
|
||||
glm::vec3(9, 10, 11));
|
||||
|
||||
glm::mat4x3 m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||
|
||||
glm::mat4x3 m2{
|
||||
{0, 1, 2},
|
||||
{3, 4, 5},
|
||||
{6, 7, 8},
|
||||
{9, 10, 11}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat4x3> v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||
};
|
||||
|
||||
std::vector<glm::mat4x3> v2{
|
||||
{
|
||||
{ 0, 1, 2 },
|
||||
{ 4, 5, 6 },
|
||||
{ 8, 9, 10 },
|
||||
{ 12, 13, 14 }
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2 },
|
||||
{ 4, 5, 6 },
|
||||
{ 8, 9, 10 },
|
||||
{ 12, 13, 14 }
|
||||
}
|
||||
};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace cast
|
||||
{
|
||||
template<typename genType>
|
||||
int entry()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType A(1.0f);
|
||||
glm::mat4x3 B(A);
|
||||
glm::mat4x3 Identity(1.0f);
|
||||
|
||||
Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += entry<glm::mat2x2>();
|
||||
Error += entry<glm::mat2x3>();
|
||||
Error += entry<glm::mat2x4>();
|
||||
Error += entry<glm::mat3x2>();
|
||||
Error += entry<glm::mat3x3>();
|
||||
Error += entry<glm::mat3x4>();
|
||||
Error += entry<glm::mat4x2>();
|
||||
Error += entry<glm::mat4x3>();
|
||||
Error += entry<glm::mat4x4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cast
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 48 == sizeof(glm::mat4x3) ? 0 : 1;
|
||||
Error += 96 == sizeof(glm::dmat4x3) ? 0 : 1;
|
||||
Error += glm::mat4x3().length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4x3().length() == 4 ? 0 : 1;
|
||||
Error += glm::mat4x3::length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4x3::length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat4x3::length() == 4, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += cast::test();
|
||||
Error += test_ctr();
|
||||
Error += test_operators();
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
218
lib/glm/test/core/core_type_mat4x4.cpp
Normal file
218
lib/glm/test/core/core_type_mat4x4.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
|
||||
template <typename matType, typename vecType>
|
||||
static int test_operators()
|
||||
{
|
||||
typedef typename matType::value_type value_type;
|
||||
|
||||
value_type const Epsilon = static_cast<value_type>(0.001);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
matType const M(static_cast<value_type>(2.0f));
|
||||
matType const N(static_cast<value_type>(1.0f));
|
||||
vecType const U(static_cast<value_type>(2.0f));
|
||||
|
||||
{
|
||||
matType const P = N * static_cast<value_type>(2.0f);
|
||||
Error += glm::all(glm::equal(P, M, Epsilon)) ? 0 : 1;
|
||||
|
||||
matType const Q = M / static_cast<value_type>(2.0f);
|
||||
Error += glm::all(glm::equal(Q, N, Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
vecType const V = M * U;
|
||||
Error += glm::all(glm::equal(V, vecType(static_cast<value_type>(4.f)), Epsilon)) ? 0 : 1;
|
||||
|
||||
vecType const W = U / M;
|
||||
Error += glm::all(glm::equal(W, vecType(static_cast<value_type>(1.f)), Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
matType const O = M * N;
|
||||
Error += glm::all(glm::equal(O, matType(static_cast<value_type>(2.f)), Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename matType>
|
||||
static int test_inverse()
|
||||
{
|
||||
typedef typename matType::value_type value_type;
|
||||
|
||||
value_type const Epsilon = static_cast<value_type>(0.001);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
matType const Identity(static_cast<value_type>(1.0f));
|
||||
matType const Matrix(
|
||||
glm::vec4(0.6f, 0.2f, 0.3f, 0.4f),
|
||||
glm::vec4(0.2f, 0.7f, 0.5f, 0.3f),
|
||||
glm::vec4(0.3f, 0.5f, 0.7f, 0.2f),
|
||||
glm::vec4(0.4f, 0.3f, 0.2f, 0.6f));
|
||||
matType const Inverse = Identity / Matrix;
|
||||
matType const Result = Matrix * Inverse;
|
||||
|
||||
Error += glm::all(glm::equal(Identity, Result, Epsilon)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ctr()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
#if GLM_HAS_TRIVIAL_QUERIES
|
||||
//Error += std::is_trivially_default_constructible<glm::mat4>::value ? 0 : 1;
|
||||
//Error += std::is_trivially_copy_assignable<glm::mat4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::mat4>::value ? 0 : 1;
|
||||
//Error += std::is_copy_constructible<glm::mat4>::value ? 0 : 1;
|
||||
//Error += std::has_trivial_copy_constructor<glm::mat4>::value ? 0 : 1;
|
||||
#endif
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
glm::mat4 const m0(
|
||||
glm::vec4(0, 1, 2, 3),
|
||||
glm::vec4(4, 5, 6, 7),
|
||||
glm::vec4(8, 9, 10, 11),
|
||||
glm::vec4(12, 13, 14, 15));
|
||||
|
||||
assert(sizeof(m0) == 4 * 4 * 4);
|
||||
|
||||
glm::vec4 const V{0, 1, 2, 3};
|
||||
|
||||
glm::mat4 const m1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
|
||||
glm::mat4 const m2{
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 10, 11},
|
||||
{12, 13, 14, 15}};
|
||||
|
||||
Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
|
||||
std::vector<glm::mat4> const m3{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
|
||||
|
||||
glm::mat4 const m4{
|
||||
{1, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1} };
|
||||
|
||||
Error += glm::equal(m4[0][0], 1.0f, 0.0001f) ? 0 : 1;
|
||||
Error += glm::equal(m4[3][3], 1.0f, 0.0001f) ? 0 : 1;
|
||||
|
||||
std::vector<glm::mat4> const v1{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
|
||||
|
||||
std::vector<glm::mat4> const v2{
|
||||
{
|
||||
{ 0, 1, 2, 3 },
|
||||
{ 4, 5, 6, 7 },
|
||||
{ 8, 9, 10, 11 },
|
||||
{ 12, 13, 14, 15 }
|
||||
},
|
||||
{
|
||||
{ 0, 1, 2, 3 },
|
||||
{ 4, 5, 6, 7 },
|
||||
{ 8, 9, 10, 11 },
|
||||
{ 12, 13, 14, 15 }
|
||||
}};
|
||||
|
||||
#endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_member_alloc_bug()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
struct repro
|
||||
{
|
||||
repro(){ this->matrix = new glm::mat4(); }
|
||||
~repro(){delete this->matrix;}
|
||||
|
||||
glm::mat4* matrix;
|
||||
};
|
||||
|
||||
repro Repro;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += 64 == sizeof(glm::mat4) ? 0 : 1;
|
||||
Error += 128 == sizeof(glm::dmat4) ? 0 : 1;
|
||||
Error += glm::mat4().length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4().length() == 4 ? 0 : 1;
|
||||
Error += glm::mat4::length() == 4 ? 0 : 1;
|
||||
Error += glm::dmat4::length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::mat4::length() == 4, "GLM: Failed constexpr");
|
||||
constexpr glm::mat4 A(1.f);
|
||||
constexpr glm::mat4 B(1.f);
|
||||
constexpr glm::bvec4 C = glm::equal(A, B, 0.01f);
|
||||
static_assert(glm::all(C), "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_member_alloc_bug();
|
||||
Error += test_ctr();
|
||||
|
||||
Error += test_operators<glm::mat4, glm::vec4>();
|
||||
Error += test_operators<glm::lowp_mat4, glm::lowp_vec4>();
|
||||
Error += test_operators<glm::mediump_mat4, glm::mediump_vec4>();
|
||||
Error += test_operators<glm::highp_mat4, glm::highp_vec4>();
|
||||
|
||||
Error += test_operators<glm::dmat4, glm::dvec4>();
|
||||
Error += test_operators<glm::lowp_dmat4, glm::lowp_dvec4>();
|
||||
Error += test_operators<glm::mediump_dmat4, glm::mediump_dvec4>();
|
||||
Error += test_operators<glm::highp_dmat4, glm::highp_dvec4>();
|
||||
|
||||
Error += test_inverse<glm::mat4>();
|
||||
Error += test_inverse<glm::lowp_mat4>();
|
||||
Error += test_inverse<glm::mediump_mat4>();
|
||||
Error += test_inverse<glm::highp_mat4>();
|
||||
|
||||
Error += test_inverse<glm::dmat4>();
|
||||
Error += test_inverse<glm::lowp_dmat4>();
|
||||
Error += test_inverse<glm::mediump_dmat4>();
|
||||
Error += test_inverse<glm::highp_dmat4>();
|
||||
|
||||
Error += test_size();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
169
lib/glm/test/core/core_type_vec1.cpp
Normal file
169
lib/glm/test/core/core_type_vec1.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <vector>
|
||||
|
||||
static glm::vec1 g1;
|
||||
static glm::vec1 g2(1);
|
||||
|
||||
int test_vec1_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec1 A(1);
|
||||
glm::ivec1 B(1);
|
||||
{
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
A *= 1;
|
||||
B *= 1;
|
||||
A += 1;
|
||||
B += 1;
|
||||
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec1_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
/*
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::vec1 a{ 0 };
|
||||
std::vector<glm::vec1> v = {
|
||||
{0.f},
|
||||
{4.f},
|
||||
{8.f}};
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec2 a{ 0 };
|
||||
std::vector<glm::dvec1> v = {
|
||||
{0.0},
|
||||
{4.0},
|
||||
{8.0}};
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
{
|
||||
glm::vec2 A = glm::vec2(2.0f);
|
||||
glm::vec2 B = glm::vec2(2.0f, 3.0f);
|
||||
glm::vec2 C = glm::vec2(2.0f, 3.0);
|
||||
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
|
||||
glm::vec2 E(glm::dvec2(2.0));
|
||||
glm::vec2 F(glm::ivec2(2));
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec1_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
|
||||
Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
|
||||
Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
|
||||
Error += glm::vec1().length() == 1 ? 0 : 1;
|
||||
Error += glm::dvec1().length() == 1 ? 0 : 1;
|
||||
Error += glm::vec1::length() == 1 ? 0 : 1;
|
||||
Error += glm::dvec1::length() == 1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec1_operator_increment()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::ivec1 v0(1);
|
||||
glm::ivec1 v1(v0);
|
||||
glm::ivec1 v2(v0);
|
||||
glm::ivec1 v3 = ++v1;
|
||||
glm::ivec1 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::vec1 A = glm::vec1(1.0f);
|
||||
//glm::vec1 B = A.x;
|
||||
glm::vec1 C(A.x);
|
||||
|
||||
//Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec1_size();
|
||||
Error += test_vec1_ctor();
|
||||
Error += test_vec1_operators();
|
||||
Error += test_vec1_operator_increment();
|
||||
Error += test_swizzle();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
392
lib/glm/test/core/core_type_vec2.cpp
Normal file
392
lib/glm/test/core/core_type_vec2.cpp
Normal file
@@ -0,0 +1,392 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <vector>
|
||||
#if GLM_HAS_TRIVIAL_QUERIES
|
||||
# include <type_traits>
|
||||
#endif
|
||||
|
||||
static glm::ivec2 g1;
|
||||
static glm::ivec2 g2(1);
|
||||
static glm::ivec2 g3(1, 1);
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec2 A(1);
|
||||
glm::ivec2 B(1);
|
||||
Error += A != B ? 1 : 0;
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f);
|
||||
glm::vec2 C = A + 1.0f;
|
||||
A += 1.0f;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f);
|
||||
glm::vec2 B(2.0f,-1.0f);
|
||||
glm::vec2 C = A + B;
|
||||
A += B;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(3.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f);
|
||||
glm::vec2 C = A - 1.0f;
|
||||
A -= 1.0f;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(0.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f);
|
||||
glm::vec2 B(2.0f,-1.0f);
|
||||
glm::vec2 C = A - B;
|
||||
A -= B;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(-1.0f, 2.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f);
|
||||
glm::vec2 C = A * 2.0f;
|
||||
A *= 2.0f;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(2.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(2.0f);
|
||||
glm::vec2 B(2.0f);
|
||||
glm::vec2 C = A / B;
|
||||
A /= B;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(1.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f, 2.0f);
|
||||
glm::vec2 B(4.0f, 5.0f);
|
||||
|
||||
glm::vec2 C = A + B;
|
||||
Error += glm::all(glm::equal(C, glm::vec2(5, 7), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 D = B - A;
|
||||
Error += glm::all(glm::equal(D, glm::vec2(3, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 E = A * B;
|
||||
Error += glm::all(glm::equal(E, glm::vec2(4, 10), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 F = B / A;
|
||||
Error += glm::all(glm::equal(F, glm::vec2(4, 2.5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 G = A + 1.0f;
|
||||
Error += glm::all(glm::equal(G, glm::vec2(2, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 H = B - 1.0f;
|
||||
Error += glm::all(glm::equal(H, glm::vec2(3, 4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 I = A * 2.0f;
|
||||
Error += glm::all(glm::equal(I, glm::vec2(2, 4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 J = B / 2.0f;
|
||||
Error += glm::all(glm::equal(J, glm::vec2(2, 2.5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 K = 1.0f + A;
|
||||
Error += glm::all(glm::equal(K, glm::vec2(2, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 L = 1.0f - B;
|
||||
Error += glm::all(glm::equal(L, glm::vec2(-3, -4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 M = 2.0f * A;
|
||||
Error += glm::all(glm::equal(M, glm::vec2(2, 4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec2 N = 2.0f / B;
|
||||
Error += glm::all(glm::equal(N, glm::vec2(0.5, 2.0 / 5.0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec2 A(1.0f, 2.0f);
|
||||
glm::vec2 B(4.0f, 5.0f);
|
||||
|
||||
A += B;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(5, 7), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
A += 1.0f;
|
||||
Error += glm::all(glm::equal(A, glm::vec2(6, 8), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B(4.0f, 5.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::ivec2(3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1.0f;
|
||||
Error += B == glm::ivec2(2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B(4.0f, 5.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::ivec2(4, 10) ? 0 : 1;
|
||||
|
||||
A *= 2;
|
||||
Error += A == glm::ivec2(8, 20) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B(4.0f, 16.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::ivec2(4, 8) ? 0 : 1;
|
||||
|
||||
B /= 2.0f;
|
||||
Error += B == glm::ivec2(2, 4) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec2 B(2);
|
||||
|
||||
B /= B.y;
|
||||
Error += B == glm::ivec2(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = -A;
|
||||
Error += B == glm::ivec2(-1.0f, -2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = --A;
|
||||
Error += B == glm::ivec2(0.0f, 1.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = A--;
|
||||
Error += B == glm::ivec2(1.0f, 2.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec2(0.0f, 1.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = ++A;
|
||||
Error += B == glm::ivec2(2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec2 A(1.0f, 2.0f);
|
||||
glm::ivec2 B = A++;
|
||||
Error += B == glm::ivec2(1.0f, 2.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec2(2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec2 A(1);
|
||||
glm::ivec2 B(A);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec2>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec2>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec2>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec2>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec2>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec2>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec2>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::vec2 a{ 0, 1 };
|
||||
std::vector<glm::vec2> v = {
|
||||
{0, 1},
|
||||
{4, 5},
|
||||
{8, 9}};
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec2 a{ 0, 1 };
|
||||
std::vector<glm::dvec2> v = {
|
||||
{0, 1},
|
||||
{4, 5},
|
||||
{8, 9}};
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
glm::vec2 A = glm::vec2(2.0f);
|
||||
glm::vec2 B = glm::vec2(2.0f, 3.0f);
|
||||
glm::vec2 C = glm::vec2(2.0f, 3.0);
|
||||
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
|
||||
glm::vec2 E(glm::dvec2(2.0));
|
||||
glm::vec2 F(glm::ivec2(2));
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0f);
|
||||
glm::vec1 const S(2.0f);
|
||||
glm::vec2 const O(1.0f, 2.0f);
|
||||
|
||||
glm::vec2 const A(R);
|
||||
glm::vec2 const B(1.0f);
|
||||
Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const C(R, S);
|
||||
Error += glm::all(glm::equal(C, O, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const D(R, 2.0f);
|
||||
Error += glm::all(glm::equal(D, O, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const E(1.0f, S);
|
||||
Error += glm::all(glm::equal(E, O, 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0f);
|
||||
glm::dvec1 const S(2.0);
|
||||
glm::vec2 const O(1.0, 2.0);
|
||||
|
||||
glm::vec2 const A(R);
|
||||
glm::vec2 const B(1.0);
|
||||
Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const C(R, S);
|
||||
Error += glm::all(glm::equal(C, O, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const D(R, 2.0);
|
||||
Error += glm::all(glm::equal(D, O, 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::vec2 const E(1.0, S);
|
||||
Error += glm::all(glm::equal(E, O, 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec2) == sizeof(glm::mediump_vec2) ? 0 : 1;
|
||||
Error += 8 == sizeof(glm::mediump_vec2) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec2) == sizeof(glm::highp_dvec2) ? 0 : 1;
|
||||
Error += 16 == sizeof(glm::highp_dvec2) ? 0 : 1;
|
||||
Error += glm::vec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::dvec2().length() == 2 ? 0 : 1;
|
||||
Error += glm::vec2::length() == 2 ? 0 : 1;
|
||||
Error += glm::dvec2::length() == 2 ? 0 : 1;
|
||||
|
||||
GLM_CONSTEXPR std::size_t Length = glm::vec2::length();
|
||||
Error += Length == 2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_operator_increment()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec2 v0(1);
|
||||
glm::ivec2 v1(v0);
|
||||
glm::ivec2 v2(v0);
|
||||
glm::ivec2 v3 = ++v1;
|
||||
glm::ivec2 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::vec2 A = glm::vec2(1.0f, 2.0f);
|
||||
glm::vec2 B = A.xy;
|
||||
glm::vec2 C(A.xy);
|
||||
glm::vec2 D(A.xy());
|
||||
|
||||
Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D, 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::vec2 A = glm::vec2(1.0f, 2.0f);
|
||||
glm::vec2 B = A.xy();
|
||||
glm::vec2 C(A.xy());
|
||||
|
||||
Error += glm::all(glm::equal(A, B, 0.0001f)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, 0.0001f)) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_size();
|
||||
Error += test_ctor();
|
||||
Error += test_operators();
|
||||
Error += test_operator_increment();
|
||||
Error += test_swizzle();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
628
lib/glm/test/core/core_type_vec3.cpp
Normal file
628
lib/glm/test/core/core_type_vec3.cpp
Normal file
@@ -0,0 +1,628 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/geometric.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
|
||||
static glm::vec3 g1;
|
||||
static glm::vec3 g2(1);
|
||||
static glm::vec3 g3(1, 1, 1);
|
||||
|
||||
int test_vec3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec3>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec3>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec3>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec3>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec3>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec3>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec3>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
# if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::vec3 a{ 0, 1, 2 };
|
||||
std::vector<glm::vec3> v = {
|
||||
{0, 1, 2},
|
||||
{4, 5, 6},
|
||||
{8, 9, 0}};
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec3 a{ 0, 1, 2 };
|
||||
std::vector<glm::dvec3> v = {
|
||||
{0, 1, 2},
|
||||
{4, 5, 6},
|
||||
{8, 9, 0}};
|
||||
}
|
||||
# endif
|
||||
|
||||
{
|
||||
glm::ivec3 A(1);
|
||||
glm::ivec3 B(1, 1, 1);
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::ivec3> Tests;
|
||||
Tests.push_back(glm::ivec3(glm::ivec2(1, 2), 3));
|
||||
Tests.push_back(glm::ivec3(1, glm::ivec2(2, 3)));
|
||||
Tests.push_back(glm::ivec3(1, 2, 3));
|
||||
Tests.push_back(glm::ivec3(glm::ivec4(1, 2, 3, 4)));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
Error += Tests[i] == glm::ivec3(1, 2, 3) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0f);
|
||||
glm::vec1 const S(2.0f);
|
||||
glm::vec1 const T(3.0f);
|
||||
glm::vec3 const O(1.0f, 2.0f, 3.0f);
|
||||
|
||||
glm::vec3 const A(R);
|
||||
glm::vec3 const B(1.0f);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const C(R, S, T);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const D(R, 2.0f, 3.0f);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const E(1.0f, S, 3.0f);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const F(1.0f, S, T);
|
||||
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const G(R, 2.0f, T);
|
||||
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const H(R, S, 3.0f);
|
||||
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0);
|
||||
glm::dvec1 const S(2.0);
|
||||
glm::vec1 const T(3.0);
|
||||
glm::vec3 const O(1.0f, 2.0f, 3.0f);
|
||||
|
||||
glm::vec3 const A(R);
|
||||
glm::vec3 const B(1.0);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const C(R, S, T);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const D(R, 2.0, 3.0);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const E(1.0f, S, 3.0);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const F(1.0, S, T);
|
||||
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const G(R, 2.0, T);
|
||||
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const H(R, S, 3.0);
|
||||
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
float foo()
|
||||
{
|
||||
glm::vec3 bar = glm::vec3(0.0f, 1.0f, 1.0f);
|
||||
|
||||
return glm::length(bar);
|
||||
}
|
||||
|
||||
static int test_bvec3_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::bvec3 const A(true);
|
||||
glm::bvec3 const B(true);
|
||||
glm::bvec3 const C(false);
|
||||
glm::bvec3 const D = A && B;
|
||||
glm::bvec3 const E = A && C;
|
||||
glm::bvec3 const F = A || C;
|
||||
|
||||
Error += D == glm::bvec3(true) ? 0 : 1;
|
||||
Error += E == glm::bvec3(false) ? 0 : 1;
|
||||
Error += F == glm::bvec3(true) ? 0 : 1;
|
||||
|
||||
bool const G = A == C;
|
||||
bool const H = A != C;
|
||||
Error += !G ? 0 : 1;
|
||||
Error += H ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec3_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec3 A(1);
|
||||
glm::ivec3 B(1);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 const A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 const B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
glm::vec3 const C = A + B;
|
||||
Error += glm::all(glm::equal(C, glm::vec3(5, 7, 9), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const D = B - A;
|
||||
Error += glm::all(glm::equal(D, glm::vec3(3, 3, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const E = A * B;
|
||||
Error += glm::all(glm::equal(E, glm::vec3(4, 10, 18), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const F = B / A;
|
||||
Error += glm::all(glm::equal(F, glm::vec3(4, 2.5, 2), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const G = A + 1.0f;
|
||||
Error += glm::all(glm::equal(G, glm::vec3(2, 3, 4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const H = B - 1.0f;
|
||||
Error += glm::all(glm::equal(H, glm::vec3(3, 4, 5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const I = A * 2.0f;
|
||||
Error += glm::all(glm::equal(I, glm::vec3(2, 4, 6), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const J = B / 2.0f;
|
||||
Error += glm::all(glm::equal(J, glm::vec3(2, 2.5, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const K = 1.0f + A;
|
||||
Error += glm::all(glm::equal(K, glm::vec3(2, 3, 4), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const L = 1.0f - B;
|
||||
Error += glm::all(glm::equal(L, glm::vec3(-3, -4, -5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const M = 2.0f * A;
|
||||
Error += glm::all(glm::equal(M, glm::vec3(2, 4, 6), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec3 const N = 2.0f / B;
|
||||
Error += glm::all(glm::equal(N, glm::vec3(0.5, 2.0 / 5.0, 2.0 / 6.0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
A += B;
|
||||
Error += A == glm::ivec3(5, 7, 9) ? 0 : 1;
|
||||
|
||||
A += 1;
|
||||
Error += A == glm::ivec3(6, 8, 10) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::ivec3(3, 3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1;
|
||||
Error += B == glm::ivec3(2, 2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::ivec3(4, 10, 18) ? 0 : 1;
|
||||
|
||||
A *= 2;
|
||||
Error += A == glm::ivec3(8, 20, 36) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B(4.0f, 4.0f, 6.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::ivec3(4, 2, 2) ? 0 : 1;
|
||||
|
||||
B /= 2;
|
||||
Error += B == glm::ivec3(2, 1, 1) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec3 B(2);
|
||||
|
||||
B /= B.y;
|
||||
Error += B == glm::ivec3(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = -A;
|
||||
Error += B == glm::ivec3(-1.0f, -2.0f, -3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = --A;
|
||||
Error += B == glm::ivec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = A--;
|
||||
Error += B == glm::ivec3(1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec3(0.0f, 1.0f, 2.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = ++A;
|
||||
Error += B == glm::ivec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::ivec3 B = A++;
|
||||
Error += B == glm::ivec3(1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec3(2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec3) == sizeof(glm::lowp_vec3) ? 0 : 1;
|
||||
Error += sizeof(glm::vec3) == sizeof(glm::mediump_vec3) ? 0 : 1;
|
||||
Error += sizeof(glm::vec3) == sizeof(glm::highp_vec3) ? 0 : 1;
|
||||
Error += 12 == sizeof(glm::mediump_vec3) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec3) == sizeof(glm::lowp_dvec3) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec3) == sizeof(glm::mediump_dvec3) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec3) == sizeof(glm::highp_dvec3) ? 0 : 1;
|
||||
Error += 24 == sizeof(glm::highp_dvec3) ? 0 : 1;
|
||||
Error += glm::vec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::dvec3().length() == 3 ? 0 : 1;
|
||||
Error += glm::vec3::length() == 3 ? 0 : 1;
|
||||
Error += glm::dvec3::length() == 3 ? 0 : 1;
|
||||
|
||||
GLM_CONSTEXPR std::size_t Length = glm::vec3::length();
|
||||
Error += Length == 3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_swizzle3_2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec3 v(1, 2, 3);
|
||||
glm::ivec2 u;
|
||||
|
||||
// Can not assign a vec3 swizzle to a vec2
|
||||
//u = v.xyz; //Illegal
|
||||
//u = v.rgb; //Illegal
|
||||
//u = v.stp; //Illegal
|
||||
|
||||
u = v.xx; Error += (u.x == 1 && u.y == 1) ? 0 : 1;
|
||||
u = v.xy; Error += (u.x == 1 && u.y == 2) ? 0 : 1;
|
||||
u = v.xz; Error += (u.x == 1 && u.y == 3) ? 0 : 1;
|
||||
u = v.yx; Error += (u.x == 2 && u.y == 1) ? 0 : 1;
|
||||
u = v.yy; Error += (u.x == 2 && u.y == 2) ? 0 : 1;
|
||||
u = v.yz; Error += (u.x == 2 && u.y == 3) ? 0 : 1;
|
||||
u = v.zx; Error += (u.x == 3 && u.y == 1) ? 0 : 1;
|
||||
u = v.zy; Error += (u.x == 3 && u.y == 2) ? 0 : 1;
|
||||
u = v.zz; Error += (u.x == 3 && u.y == 3) ? 0 : 1;
|
||||
|
||||
u = v.rr; Error += (u.r == 1 && u.g == 1) ? 0 : 1;
|
||||
u = v.rg; Error += (u.r == 1 && u.g == 2) ? 0 : 1;
|
||||
u = v.rb; Error += (u.r == 1 && u.g == 3) ? 0 : 1;
|
||||
u = v.gr; Error += (u.r == 2 && u.g == 1) ? 0 : 1;
|
||||
u = v.gg; Error += (u.r == 2 && u.g == 2) ? 0 : 1;
|
||||
u = v.gb; Error += (u.r == 2 && u.g == 3) ? 0 : 1;
|
||||
u = v.br; Error += (u.r == 3 && u.g == 1) ? 0 : 1;
|
||||
u = v.bg; Error += (u.r == 3 && u.g == 2) ? 0 : 1;
|
||||
u = v.bb; Error += (u.r == 3 && u.g == 3) ? 0 : 1;
|
||||
|
||||
u = v.ss; Error += (u.s == 1 && u.t == 1) ? 0 : 1;
|
||||
u = v.st; Error += (u.s == 1 && u.t == 2) ? 0 : 1;
|
||||
u = v.sp; Error += (u.s == 1 && u.t == 3) ? 0 : 1;
|
||||
u = v.ts; Error += (u.s == 2 && u.t == 1) ? 0 : 1;
|
||||
u = v.tt; Error += (u.s == 2 && u.t == 2) ? 0 : 1;
|
||||
u = v.tp; Error += (u.s == 2 && u.t == 3) ? 0 : 1;
|
||||
u = v.ps; Error += (u.s == 3 && u.t == 1) ? 0 : 1;
|
||||
u = v.pt; Error += (u.s == 3 && u.t == 2) ? 0 : 1;
|
||||
u = v.pp; Error += (u.s == 3 && u.t == 3) ? 0 : 1;
|
||||
// Mixed member aliases are not valid
|
||||
//u = v.rx; //Illegal
|
||||
//u = v.sy; //Illegal
|
||||
|
||||
u = glm::ivec2(1, 2);
|
||||
v = glm::ivec3(1, 2, 3);
|
||||
//v.xx = u; //Illegal
|
||||
v.xy = u; Error += (v.x == 1 && v.y == 2 && v.z == 3) ? 0 : 1;
|
||||
v.xz = u; Error += (v.x == 1 && v.y == 2 && v.z == 2) ? 0 : 1;
|
||||
v.yx = u; Error += (v.x == 2 && v.y == 1 && v.z == 2) ? 0 : 1;
|
||||
//v.yy = u; //Illegal
|
||||
v.yz = u; Error += (v.x == 2 && v.y == 1 && v.z == 2) ? 0 : 1;
|
||||
v.zx = u; Error += (v.x == 2 && v.y == 1 && v.z == 1) ? 0 : 1;
|
||||
v.zy = u; Error += (v.x == 2 && v.y == 2 && v.z == 1) ? 0 : 1;
|
||||
//v.zz = u; //Illegal
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_swizzle3_3()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec3 v(1, 2, 3);
|
||||
glm::ivec3 u;
|
||||
|
||||
u = v; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1;
|
||||
|
||||
u = v.xyz; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1;
|
||||
u = v.zyx; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
u.zyx = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
|
||||
u = v.rgb; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1;
|
||||
u = v.bgr; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
u.bgr = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
|
||||
u = v.stp; Error += (u.x == 1 && u.y == 2 && u.z == 3) ? 0 : 1;
|
||||
u = v.pts; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
u.pts = v; Error += (u.x == 3 && u.y == 2 && u.z == 1) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_swizzle_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec3 const u = glm::ivec3(1, 2, 3);
|
||||
glm::ivec3 const v = glm::ivec3(10, 20, 30);
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec3 q;
|
||||
|
||||
// Swizzle, swizzle binary operators
|
||||
q = u.xyz + v.xyz; Error += (q == (u + v)) ? 0 : 1;
|
||||
q = (u.zyx + v.zyx).zyx; Error += (q == (u + v)) ? 0 : 1;
|
||||
q = (u.xyz - v.xyz); Error += (q == (u - v)) ? 0 : 1;
|
||||
q = (u.xyz * v.xyz); Error += (q == (u * v)) ? 0 : 1;
|
||||
q = (u.xxx * v.xxx); Error += (q == glm::ivec3(u.x * v.x)) ? 0 : 1;
|
||||
q = (u.xyz / v.xyz); Error += (q == (u / v)) ? 0 : 1;
|
||||
|
||||
// vec, swizzle binary operators
|
||||
q = u + v.xyz; Error += (q == (u + v)) ? 0 : 1;
|
||||
q = (u - v.xyz); Error += (q == (u - v)) ? 0 : 1;
|
||||
q = (u * v.xyz); Error += (q == (u * v)) ? 0 : 1;
|
||||
q = (u * v.xxx); Error += (q == v.x * u) ? 0 : 1;
|
||||
q = (u / v.xyz); Error += (q == (u / v)) ? 0 : 1;
|
||||
|
||||
// swizzle,vec binary operators
|
||||
q = u.xyz + v; Error += (q == (u + v)) ? 0 : 1;
|
||||
q = (u.xyz - v); Error += (q == (u - v)) ? 0 : 1;
|
||||
q = (u.xyz * v); Error += (q == (u * v)) ? 0 : 1;
|
||||
q = (u.xxx * v); Error += (q == u.x * v) ? 0 : 1;
|
||||
q = (u.xyz / v); Error += (q == (u / v)) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_LANG
|
||||
|
||||
// Compile errors
|
||||
//q = (u.yz * v.xyz);
|
||||
//q = (u * v.xy);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_swizzle_functions()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
// NOTE: template functions cannot pick up the implicit conversion from
|
||||
// a swizzle to the unswizzled type, therefore the operator() must be
|
||||
// used. E.g.:
|
||||
//
|
||||
// glm::dot(u.xy, v.xy); <--- Compile error
|
||||
// glm::dot(u.xy(), v.xy()); <--- Compiles correctly
|
||||
|
||||
float r;
|
||||
|
||||
// vec2
|
||||
glm::vec2 a(1, 2);
|
||||
glm::vec2 b(10, 20);
|
||||
r = glm::dot(a, b); Error += (int(r) == 50) ? 0 : 1;
|
||||
r = glm::dot(glm::vec2(a.xy()), glm::vec2(b.xy())); Error += (int(r) == 50) ? 0 : 1;
|
||||
r = glm::dot(glm::vec2(a.xy()), glm::vec2(b.yy())); Error += (int(r) == 60) ? 0 : 1;
|
||||
|
||||
// vec3
|
||||
glm::vec3 u = glm::vec3(1, 2, 3);
|
||||
glm::vec3 v = glm::vec3(10, 20, 30);
|
||||
r = glm::dot(u, v); Error += (int(r) == 140) ? 0 : 1;
|
||||
r = glm::dot(u.xyz(), v.zyz()); Error += (int(r) == 160) ? 0 : 1;
|
||||
r = glm::dot(u, v.zyx()); Error += (int(r) == 100) ? 0 : 1;
|
||||
r = glm::dot(u.xyz(), v); Error += (int(r) == 140) ? 0 : 1;
|
||||
r = glm::dot(u.xy(), v.xy()); Error += (int(r) == 50) ? 0 : 1;
|
||||
|
||||
// vec4
|
||||
glm::vec4 s = glm::vec4(1, 2, 3, 4);
|
||||
glm::vec4 t = glm::vec4(10, 20, 30, 40);
|
||||
r = glm::dot(s, t); Error += (int(r) == 300) ? 0 : 1;
|
||||
r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1;
|
||||
r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_swizzle_partial()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::vec3 const A(1, 2, 3);
|
||||
glm::vec3 B(A.xy, 3);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec3 const B(1, A.yz);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec3 const A(1, 2, 3);
|
||||
glm::ivec3 const B(A.xyz);
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_operator_increment()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec3 v0(1);
|
||||
glm::ivec3 v1(v0);
|
||||
glm::ivec3 v2(v0);
|
||||
glm::ivec3 v3 = ++v1;
|
||||
glm::ivec3 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = A.xyz;
|
||||
glm::vec3 C(A.xyz);
|
||||
glm::vec3 D(A.xyz());
|
||||
glm::vec3 E(A.x, A.yz);
|
||||
glm::vec3 F(A.x, A.yz());
|
||||
glm::vec3 G(A.xy, A.z);
|
||||
glm::vec3 H(A.xy(), A.z);
|
||||
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B = A.xyz();
|
||||
glm::vec3 C(A.xyz());
|
||||
glm::vec3 D(A.xyz());
|
||||
glm::vec3 E(A.x, A.yz());
|
||||
glm::vec3 F(A.x, A.yz());
|
||||
glm::vec3 G(A.xy(), A.z);
|
||||
glm::vec3 H(A.xy(), A.z);
|
||||
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec3_ctor();
|
||||
Error += test_bvec3_ctor();
|
||||
Error += test_vec3_operators();
|
||||
Error += test_vec3_size();
|
||||
Error += test_operator_increment();
|
||||
Error += test_constexpr();
|
||||
|
||||
Error += test_swizzle();
|
||||
Error += test_vec3_swizzle3_2();
|
||||
Error += test_vec3_swizzle3_3();
|
||||
Error += test_vec3_swizzle_partial();
|
||||
Error += test_vec3_swizzle_operators();
|
||||
Error += test_vec3_swizzle_functions();
|
||||
|
||||
return Error;
|
||||
}
|
||||
850
lib/glm/test/core/core_type_vec4.cpp
Normal file
850
lib/glm/test/core/core_type_vec4.cpp
Normal file
@@ -0,0 +1,850 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
static glm::vec4 g1;
|
||||
static glm::vec4 g2(1);
|
||||
static glm::vec4 g3(1, 1, 1, 1);
|
||||
|
||||
template <int Value>
|
||||
struct mask
|
||||
{
|
||||
enum{value = Value};
|
||||
};
|
||||
|
||||
enum comp
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
W
|
||||
};
|
||||
|
||||
//template<comp X, comp Y, comp Z, comp W>
|
||||
//__m128 swizzle(glm::vec4 const& v)
|
||||
//{
|
||||
// __m128 Src = _mm_set_ps(v.w, v.z, v.y, v.x);
|
||||
// return _mm_shuffle_ps(Src, Src, mask<(int(W) << 6) | (int(Z) << 4) | (int(Y) << 2) | (int(X) << 0)>::value);
|
||||
//}
|
||||
|
||||
static int test_vec4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec4 A(1, 2, 3, 4);
|
||||
glm::ivec4 B(A);
|
||||
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
}
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec4>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec4>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec4>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec4>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
#if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::vec4 a{ 0, 1, 2, 3 };
|
||||
std::vector<glm::vec4> v = {
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 0, 1}};
|
||||
}
|
||||
|
||||
{
|
||||
glm::dvec4 a{ 0, 1, 2, 3 };
|
||||
std::vector<glm::dvec4> v = {
|
||||
{0, 1, 2, 3},
|
||||
{4, 5, 6, 7},
|
||||
{8, 9, 0, 1}};
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1);
|
||||
glm::ivec4 const B(1, 1, 1, 1);
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::ivec4> Tests;
|
||||
Tests.push_back(glm::ivec4(glm::ivec2(1, 2), 3, 4));
|
||||
Tests.push_back(glm::ivec4(1, glm::ivec2(2, 3), 4));
|
||||
Tests.push_back(glm::ivec4(1, 2, glm::ivec2(3, 4)));
|
||||
Tests.push_back(glm::ivec4(glm::ivec3(1, 2, 3), 4));
|
||||
Tests.push_back(glm::ivec4(1, glm::ivec3(2, 3, 4)));
|
||||
Tests.push_back(glm::ivec4(glm::ivec2(1, 2), glm::ivec2(3, 4)));
|
||||
Tests.push_back(glm::ivec4(1, 2, 3, 4));
|
||||
Tests.push_back(glm::ivec4(glm::ivec4(1, 2, 3, 4)));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
Error += Tests[i] == glm::ivec4(1, 2, 3, 4) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0f);
|
||||
glm::vec1 const S(2.0f);
|
||||
glm::vec1 const T(3.0f);
|
||||
glm::vec1 const U(4.0f);
|
||||
glm::vec4 const O(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
|
||||
glm::vec4 const A(R);
|
||||
glm::vec4 const B(1.0f);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const C(R, S, T, U);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const D(R, 2.0f, 3.0f, 4.0f);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E(1.0f, S, 3.0f, 4.0f);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const F(R, S, 3.0f, 4.0f);
|
||||
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const G(1.0f, 2.0f, T, 4.0f);
|
||||
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const H(R, 2.0f, T, 4.0f);
|
||||
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const I(1.0f, S, T, 4.0f);
|
||||
Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const J(R, S, T, 4.0f);
|
||||
Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const K(R, 2.0f, 3.0f, U);
|
||||
Error += glm::all(glm::equal(K, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const L(1.0f, S, 3.0f, U);
|
||||
Error += glm::all(glm::equal(L, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const M(R, S, 3.0f, U);
|
||||
Error += glm::all(glm::equal(M, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const N(1.0f, 2.0f, T, U);
|
||||
Error += glm::all(glm::equal(N, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const P(R, 2.0f, T, U);
|
||||
Error += glm::all(glm::equal(P, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const Q(1.0f, S, T, U);
|
||||
Error += glm::all(glm::equal(Q, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const V(R, S, T, U);
|
||||
Error += glm::all(glm::equal(V, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const R(1.0f);
|
||||
glm::dvec1 const S(2.0);
|
||||
glm::vec1 const T(3.0);
|
||||
glm::dvec1 const U(4.0);
|
||||
glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0);
|
||||
|
||||
glm::vec4 const A(R);
|
||||
glm::vec4 const B(1.0);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const C(R, S, T, U);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const D(R, 2.0f, 3.0, 4.0f);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E(1.0, S, 3.0f, 4.0);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const F(R, S, 3.0, 4.0f);
|
||||
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const G(1.0f, 2.0, T, 4.0);
|
||||
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const H(R, 2.0, T, 4.0);
|
||||
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const I(1.0, S, T, 4.0f);
|
||||
Error += glm::all(glm::equal(I, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const J(R, S, T, 4.0f);
|
||||
Error += glm::all(glm::equal(J, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const K(R, 2.0f, 3.0, U);
|
||||
Error += glm::all(glm::equal(K, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const L(1.0f, S, 3.0, U);
|
||||
Error += glm::all(glm::equal(L, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const M(R, S, 3.0, U);
|
||||
Error += glm::all(glm::equal(M, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const N(1.0f, 2.0, T, U);
|
||||
Error += glm::all(glm::equal(N, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const P(R, 2.0, T, U);
|
||||
Error += glm::all(glm::equal(P, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const Q(1.0f, S, T, U);
|
||||
Error += glm::all(glm::equal(Q, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const V(R, S, T, U);
|
||||
Error += glm::all(glm::equal(V, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const v1_0(1.0f);
|
||||
glm::vec1 const v1_1(2.0f);
|
||||
glm::vec1 const v1_2(3.0f);
|
||||
glm::vec1 const v1_3(4.0f);
|
||||
|
||||
glm::vec2 const v2_0(1.0f, 2.0f);
|
||||
glm::vec2 const v2_1(2.0f, 3.0f);
|
||||
glm::vec2 const v2_2(3.0f, 4.0f);
|
||||
|
||||
glm::vec3 const v3_0(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 const v3_1(2.0f, 3.0f, 4.0f);
|
||||
|
||||
glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0);
|
||||
|
||||
glm::vec4 const A(v1_0, v1_1, v2_2);
|
||||
Error += glm::all(glm::equal(A, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const B(1.0f, 2.0f, v2_2);
|
||||
Error += glm::all(glm::equal(B, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const C(v1_0, 2.0f, v2_2);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const D(1.0f, v1_1, v2_2);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E(v2_0, v1_2, v1_3);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const F(v2_0, 3.0, v1_3);
|
||||
Error += glm::all(glm::equal(F, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const G(v2_0, v1_2, 4.0);
|
||||
Error += glm::all(glm::equal(G, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const H(v2_0, 3.0f, 4.0);
|
||||
Error += glm::all(glm::equal(H, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec1 const v1_0(1.0f);
|
||||
glm::vec1 const v1_1(2.0f);
|
||||
glm::vec1 const v1_2(3.0f);
|
||||
glm::vec1 const v1_3(4.0f);
|
||||
|
||||
glm::vec2 const v2(2.0f, 3.0f);
|
||||
|
||||
glm::vec4 const O(1.0f, 2.0, 3.0f, 4.0);
|
||||
|
||||
glm::vec4 const A(v1_0, v2, v1_3);
|
||||
Error += glm::all(glm::equal(A, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const B(v1_0, v2, 4.0);
|
||||
Error += glm::all(glm::equal(B, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const C(1.0, v2, v1_3);
|
||||
Error += glm::all(glm::equal(C, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const D(1.0f, v2, 4.0);
|
||||
Error += glm::all(glm::equal(D, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E(1.0, v2, 4.0f);
|
||||
Error += glm::all(glm::equal(E, O, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_bvec4_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::bvec4 const A(true);
|
||||
glm::bvec4 const B(true);
|
||||
glm::bvec4 const C(false);
|
||||
glm::bvec4 const D = A && B;
|
||||
glm::bvec4 const E = A && C;
|
||||
glm::bvec4 const F = A || C;
|
||||
|
||||
Error += D == glm::bvec4(true) ? 0 : 1;
|
||||
Error += E == glm::bvec4(false) ? 0 : 1;
|
||||
Error += F == glm::bvec4(true) ? 0 : 1;
|
||||
|
||||
bool const G = A == C;
|
||||
bool const H = A != C;
|
||||
Error += !G ? 0 : 1;
|
||||
Error += H ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::ivec4 A(1);
|
||||
glm::ivec4 B(1);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 const A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 const B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
glm::vec4 const C = A + B;
|
||||
Error += glm::all(glm::equal(C, glm::vec4(5, 7, 9, 11), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const D = B - A;
|
||||
Error += glm::all(glm::equal(D, glm::vec4(3, 3, 3, 3), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const E = A * B;
|
||||
Error += glm::all(glm::equal(E, glm::vec4(4, 10, 18, 28), glm::epsilon<float>()) )? 0 : 1;
|
||||
|
||||
glm::vec4 const F = B / A;
|
||||
Error += glm::all(glm::equal(F, glm::vec4(4, 2.5, 2, 7.0f / 4.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const G = A + 1.0f;
|
||||
Error += glm::all(glm::equal(G, glm::vec4(2, 3, 4, 5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const H = B - 1.0f;
|
||||
Error += glm::all(glm::equal(H, glm::vec4(3, 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const I = A * 2.0f;
|
||||
Error += glm::all(glm::equal(I, glm::vec4(2, 4, 6, 8), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const J = B / 2.0f;
|
||||
Error += glm::all(glm::equal(J, glm::vec4(2, 2.5, 3, 3.5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const K = 1.0f + A;
|
||||
Error += glm::all(glm::equal(K, glm::vec4(2, 3, 4, 5), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const L = 1.0f - B;
|
||||
Error += glm::all(glm::equal(L, glm::vec4(-3, -4, -5, -6), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const M = 2.0f * A;
|
||||
Error += glm::all(glm::equal(M, glm::vec4(2, 4, 6, 8), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::vec4 const N = 2.0f / B;
|
||||
Error += glm::all(glm::equal(N, glm::vec4(0.5, 2.0 / 5.0, 2.0 / 6.0, 2.0 / 7.0), glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A += B;
|
||||
Error += A == glm::ivec4(5, 7, 9, 11) ? 0 : 1;
|
||||
|
||||
A += 1;
|
||||
Error += A == glm::ivec4(6, 8, 10, 12) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
B -= A;
|
||||
Error += B == glm::ivec4(3, 3, 3, 3) ? 0 : 1;
|
||||
|
||||
B -= 1;
|
||||
Error += B == glm::ivec4(2, 2, 2, 2) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 5.0f, 6.0f, 7.0f);
|
||||
|
||||
A *= B;
|
||||
Error += A == glm::ivec4(4, 10, 18, 28) ? 0 : 1;
|
||||
|
||||
A *= 2;
|
||||
Error += A == glm::ivec4(8, 20, 36, 56) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 2.0f, 4.0f);
|
||||
glm::ivec4 B(4.0f, 4.0f, 8.0f, 8.0f);
|
||||
|
||||
B /= A;
|
||||
Error += B == glm::ivec4(4, 2, 4, 2) ? 0 : 1;
|
||||
|
||||
B /= 2;
|
||||
Error += B == glm::ivec4(2, 1, 2, 1) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::ivec4 B(2);
|
||||
|
||||
B /= B.y;
|
||||
Error += B == glm::ivec4(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = -A;
|
||||
Error += B == glm::ivec4(-1.0f, -2.0f, -3.0f, -4.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = --A;
|
||||
Error += B == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A--;
|
||||
Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec4(0.0f, 1.0f, 2.0f, 3.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = ++A;
|
||||
Error += B == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 A(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A++;
|
||||
Error += B == glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f) ? 0 : 1;
|
||||
Error += A == glm::ivec4(2.0f, 3.0f, 4.0f, 5.0f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_equal()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::uvec4 const A(1, 2, 3, 4);
|
||||
glm::uvec4 const B(1, 2, 3, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A != B ? 1 : 0;
|
||||
}
|
||||
|
||||
{
|
||||
glm::ivec4 const A(1, 2, 3, 4);
|
||||
glm::ivec4 const B(1, 2, 3, 4);
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A != B ? 1 : 0;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::lowp_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::mediump_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::vec4) == sizeof(glm::highp_vec4) ? 0 : 1;
|
||||
Error += 16 == sizeof(glm::mediump_vec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::lowp_dvec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::mediump_dvec4) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec4) == sizeof(glm::highp_dvec4) ? 0 : 1;
|
||||
Error += 32 == sizeof(glm::highp_dvec4) ? 0 : 1;
|
||||
Error += glm::vec4().length() == 4 ? 0 : 1;
|
||||
Error += glm::dvec4().length() == 4 ? 0 : 1;
|
||||
Error += glm::vec4::length() == 4 ? 0 : 1;
|
||||
Error += glm::dvec4::length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_swizzle_partial()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const A(1, 2, 3, 4);
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::vec4 B(A.xy, A.zw);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 B(A.xy, 3.0f, 4.0f);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 B(1.0f, A.yz, 4.0f);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 B(1.0f, 2.0f, A.zw);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 B(A.xyz, 4.0f);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::vec4 B(1.0f, A.yzw);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_swizzle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
{
|
||||
glm::ivec4 A = glm::ivec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::ivec4 B = A.xyzw;
|
||||
glm::ivec4 C(A.xyzw);
|
||||
glm::ivec4 D(A.xyzw());
|
||||
glm::ivec4 E(A.x, A.yzw);
|
||||
glm::ivec4 F(A.x, A.yzw());
|
||||
glm::ivec4 G(A.xyz, A.w);
|
||||
glm::ivec4 H(A.xyz(), A.w);
|
||||
glm::ivec4 I(A.xy, A.zw);
|
||||
glm::ivec4 J(A.xy(), A.zw());
|
||||
glm::ivec4 K(A.x, A.y, A.zw);
|
||||
glm::ivec4 L(A.x, A.yz, A.w);
|
||||
glm::ivec4 M(A.xy, A.z, A.w);
|
||||
|
||||
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR
|
||||
|
||||
# if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
{
|
||||
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
glm::vec4 B = A.xyzw();
|
||||
glm::vec4 C(A.xyzw());
|
||||
glm::vec4 D(A.xyzw());
|
||||
glm::vec4 E(A.x, A.yzw());
|
||||
glm::vec4 F(A.x, A.yzw());
|
||||
glm::vec4 G(A.xyz(), A.w);
|
||||
glm::vec4 H(A.xyz(), A.w);
|
||||
glm::vec4 I(A.xy(), A.zw());
|
||||
glm::vec4 J(A.xy(), A.zw());
|
||||
glm::vec4 K(A.x, A.y, A.zw());
|
||||
glm::vec4 L(A.x, A.yz(), A.w);
|
||||
glm::vec4 M(A.xy(), A.z, A.w);
|
||||
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, D, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, F, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, G, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, H, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, I, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, J, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, K, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, L, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(A, M, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
# endif//GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_OPERATOR || GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_operator_increment()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::ivec4 v0(1);
|
||||
glm::ivec4 v1(v0);
|
||||
glm::ivec4 v2(v0);
|
||||
glm::ivec4 v3 = ++v1;
|
||||
glm::ivec4 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
struct AoS
|
||||
{
|
||||
glm::vec4 A;
|
||||
glm::vec3 B;
|
||||
glm::vec3 C;
|
||||
glm::vec2 D;
|
||||
};
|
||||
|
||||
static int test_perf_AoS(std::size_t Size)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<AoS> In;
|
||||
std::vector<AoS> Out;
|
||||
In.resize(Size);
|
||||
Out.resize(Size);
|
||||
|
||||
std::clock_t StartTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < In.size(); ++i)
|
||||
Out[i] = In[i];
|
||||
|
||||
std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("AoS: %d\n", static_cast<int>(EndTime - StartTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_perf_SoA(std::size_t Size)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> InA;
|
||||
std::vector<glm::vec3> InB;
|
||||
std::vector<glm::vec3> InC;
|
||||
std::vector<glm::vec2> InD;
|
||||
std::vector<glm::vec4> OutA;
|
||||
std::vector<glm::vec3> OutB;
|
||||
std::vector<glm::vec3> OutC;
|
||||
std::vector<glm::vec2> OutD;
|
||||
|
||||
InA.resize(Size);
|
||||
InB.resize(Size);
|
||||
InC.resize(Size);
|
||||
InD.resize(Size);
|
||||
OutA.resize(Size);
|
||||
OutB.resize(Size);
|
||||
OutC.resize(Size);
|
||||
OutD.resize(Size);
|
||||
|
||||
std::clock_t StartTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < InA.size(); ++i)
|
||||
{
|
||||
OutA[i] = InA[i];
|
||||
OutB[i] = InB[i];
|
||||
OutC[i] = InC[i];
|
||||
OutD[i] = InD[i];
|
||||
}
|
||||
|
||||
std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("SoA: %d\n", static_cast<int>(EndTime - StartTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
namespace heap
|
||||
{
|
||||
struct A
|
||||
{
|
||||
float f;
|
||||
};
|
||||
|
||||
struct B : public A
|
||||
{
|
||||
float g;
|
||||
glm::vec4 v;
|
||||
};
|
||||
|
||||
static int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
A* p = new B;
|
||||
p->f = 0.0f;
|
||||
delete p;
|
||||
|
||||
Error += sizeof(B) == sizeof(glm::vec4) + sizeof(float) * 2 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace heap
|
||||
|
||||
static int test_simd()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const a(std::clock(), std::clock(), std::clock(), std::clock());
|
||||
glm::vec4 const b(std::clock(), std::clock(), std::clock(), std::clock());
|
||||
|
||||
glm::vec4 const c(b * a);
|
||||
glm::vec4 const d(a + c);
|
||||
|
||||
Error += glm::all(glm::greaterThanEqual(d, glm::vec4(0))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_inheritance()
|
||||
{
|
||||
struct my_vec4 : public glm::vec4
|
||||
{
|
||||
my_vec4()
|
||||
: glm::vec4(76.f, 75.f, 74.f, 73.f)
|
||||
, member(82)
|
||||
{}
|
||||
|
||||
int member;
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
my_vec4 v;
|
||||
|
||||
Error += v.member == 82 ? 0 : 1;
|
||||
Error += glm::equal(v.x, 76.f, glm::epsilon<float>()) ? 0 : 1;
|
||||
Error += glm::equal(v.y, 75.f, glm::epsilon<float>()) ? 0 : 1;
|
||||
Error += glm::equal(v.z, 74.f, glm::epsilon<float>()) ? 0 : 1;
|
||||
Error += glm::equal(v.w, 73.f, glm::epsilon<float>()) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::vec4::length() == 4, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec4(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec4(1.0f, -1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec4(1.0f, -1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
static int test_simd_gen()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
int const C = static_cast<int>(std::clock());
|
||||
int const D = static_cast<int>(std::clock());
|
||||
|
||||
glm::ivec4 const A(C);
|
||||
glm::ivec4 const B(D);
|
||||
|
||||
Error += A != B ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
//Error += test_simd_gen();
|
||||
|
||||
/*
|
||||
{
|
||||
glm::ivec4 const a1(2);
|
||||
glm::ivec4 const b1 = a1 >> 1;
|
||||
|
||||
__m128i const e1 = _mm_set1_epi32(2);
|
||||
__m128i const f1 = _mm_srli_epi32(e1, 1);
|
||||
|
||||
glm::ivec4 const g1 = *reinterpret_cast<glm::ivec4 const* const>(&f1);
|
||||
|
||||
glm::ivec4 const a2(-2);
|
||||
glm::ivec4 const b2 = a2 >> 1;
|
||||
|
||||
__m128i const e2 = _mm_set1_epi32(-1);
|
||||
__m128i const f2 = _mm_srli_epi32(e2, 1);
|
||||
|
||||
glm::ivec4 const g2 = *reinterpret_cast<glm::ivec4 const* const>(&f2);
|
||||
|
||||
std::printf("GNI\n");
|
||||
}
|
||||
|
||||
{
|
||||
glm::uvec4 const a1(2);
|
||||
glm::uvec4 const b1 = a1 >> 1u;
|
||||
|
||||
__m128i const e1 = _mm_set1_epi32(2);
|
||||
__m128i const f1 = _mm_srli_epi32(e1, 1);
|
||||
|
||||
glm::uvec4 const g1 = *reinterpret_cast<glm::uvec4 const* const>(&f1);
|
||||
|
||||
glm::uvec4 const a2(-1);
|
||||
glm::uvec4 const b2 = a2 >> 1u;
|
||||
|
||||
__m128i const e2 = _mm_set1_epi32(-1);
|
||||
__m128i const f2 = _mm_srli_epi32(e2, 1);
|
||||
|
||||
glm::uvec4 const g2 = *reinterpret_cast<glm::uvec4 const* const>(&f2);
|
||||
|
||||
std::printf("GNI\n");
|
||||
}
|
||||
*/
|
||||
|
||||
# ifdef NDEBUG
|
||||
std::size_t const Size(1000000);
|
||||
# else
|
||||
std::size_t const Size(1);
|
||||
# endif//NDEBUG
|
||||
|
||||
Error += test_perf_AoS(Size);
|
||||
Error += test_perf_SoA(Size);
|
||||
|
||||
Error += test_vec4_ctor();
|
||||
Error += test_bvec4_ctor();
|
||||
Error += test_size();
|
||||
Error += test_operators();
|
||||
Error += test_equal();
|
||||
Error += test_swizzle();
|
||||
Error += test_swizzle_partial();
|
||||
Error += test_simd();
|
||||
Error += test_operator_increment();
|
||||
Error += heap::test();
|
||||
Error += test_inheritance();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
26
lib/glm/test/ext/CMakeLists.txt
Normal file
26
lib/glm/test/ext/CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
glmCreateTestGTC(ext_matrix_relational)
|
||||
glmCreateTestGTC(ext_matrix_transform)
|
||||
glmCreateTestGTC(ext_matrix_common)
|
||||
glmCreateTestGTC(ext_quaternion_common)
|
||||
glmCreateTestGTC(ext_quaternion_exponential)
|
||||
glmCreateTestGTC(ext_quaternion_geometric)
|
||||
glmCreateTestGTC(ext_quaternion_relational)
|
||||
glmCreateTestGTC(ext_quaternion_transform)
|
||||
glmCreateTestGTC(ext_quaternion_trigonometric)
|
||||
glmCreateTestGTC(ext_quaternion_type)
|
||||
glmCreateTestGTC(ext_scalar_common)
|
||||
glmCreateTestGTC(ext_scalar_constants)
|
||||
glmCreateTestGTC(ext_scalar_int_sized)
|
||||
glmCreateTestGTC(ext_scalar_uint_sized)
|
||||
glmCreateTestGTC(ext_scalar_integer)
|
||||
glmCreateTestGTC(ext_scalar_ulp)
|
||||
glmCreateTestGTC(ext_scalar_relational)
|
||||
glmCreateTestGTC(ext_vec1)
|
||||
glmCreateTestGTC(ext_vector_bool1)
|
||||
glmCreateTestGTC(ext_vector_common)
|
||||
glmCreateTestGTC(ext_vector_iec559)
|
||||
glmCreateTestGTC(ext_vector_integer)
|
||||
glmCreateTestGTC(ext_vector_integer_sized)
|
||||
glmCreateTestGTC(ext_vector_relational)
|
||||
glmCreateTestGTC(ext_vector_ulp)
|
||||
|
||||
13
lib/glm/test/ext/ext_matrix_clip_space.cpp
Normal file
13
lib/glm/test/ext/ext_matrix_clip_space.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
53
lib/glm/test/ext/ext_matrix_common.cpp
Normal file
53
lib/glm/test/ext/ext_matrix_common.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <glm/ext/matrix_common.hpp>
|
||||
#include <glm/ext/matrix_double4x4.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/vector_bool4.hpp>
|
||||
|
||||
static int test_mix()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat4 A(2);
|
||||
glm::mat4 B(4);
|
||||
glm::mat4 C = glm::mix(A, B, 0.5f);
|
||||
glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1);
|
||||
Error += glm::all(D) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4 A(2);
|
||||
glm::mat4 B(4);
|
||||
glm::mat4 C = glm::mix(A, B, 0.5);
|
||||
glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1);
|
||||
Error += glm::all(D) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::dmat4 A(2);
|
||||
glm::dmat4 B(4);
|
||||
glm::dmat4 C = glm::mix(A, B, 0.5);
|
||||
glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1);
|
||||
Error += glm::all(D) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::dmat4 A(2);
|
||||
glm::dmat4 B(4);
|
||||
glm::dmat4 C = glm::mix(A, B, 0.5f);
|
||||
glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1);
|
||||
Error += glm::all(D) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_mix();
|
||||
|
||||
return Error;
|
||||
}
|
||||
13
lib/glm/test/ext/ext_matrix_projection.cpp
Normal file
13
lib/glm/test/ext/ext_matrix_projection.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/matrix_projection.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
163
lib/glm/test/ext/ext_matrix_relational.cpp
Normal file
163
lib/glm/test/ext/ext_matrix_relational.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/matrix_double2x2.hpp>
|
||||
#include <glm/ext/matrix_double2x3.hpp>
|
||||
#include <glm/ext/matrix_double2x4.hpp>
|
||||
#include <glm/ext/matrix_double3x2.hpp>
|
||||
#include <glm/ext/matrix_double3x3.hpp>
|
||||
#include <glm/ext/matrix_double3x4.hpp>
|
||||
#include <glm/ext/matrix_double4x2.hpp>
|
||||
#include <glm/ext/matrix_double4x3.hpp>
|
||||
#include <glm/ext/matrix_double4x4.hpp>
|
||||
#include <glm/ext/vector_double2.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <glm/ext/matrix_float2x2.hpp>
|
||||
#include <glm/ext/matrix_float2x3.hpp>
|
||||
#include <glm/ext/matrix_float2x4.hpp>
|
||||
#include <glm/ext/matrix_float3x2.hpp>
|
||||
#include <glm/ext/matrix_float3x3.hpp>
|
||||
#include <glm/ext/matrix_float3x4.hpp>
|
||||
#include <glm/ext/matrix_float4x2.hpp>
|
||||
#include <glm/ext/matrix_float4x3.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/scalar_ulp.hpp>
|
||||
|
||||
template <typename matType, typename vecType>
|
||||
static int test_equal()
|
||||
{
|
||||
typedef typename matType::value_type valType;
|
||||
|
||||
valType const Epsilon = static_cast<valType>(0.001f);
|
||||
valType const One = static_cast<valType>(1);
|
||||
valType const Two = static_cast<valType>(2);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::equal(matType(One), matType(One), Epsilon)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(matType(One), matType(Two), vecType(Epsilon))) ? 1 : 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename matType, typename vecType>
|
||||
static int test_notEqual()
|
||||
{
|
||||
typedef typename matType::value_type valType;
|
||||
|
||||
valType const Epsilon = static_cast<valType>(0.001f);
|
||||
valType const One = static_cast<valType>(1);
|
||||
valType const Two = static_cast<valType>(2);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += !glm::any(glm::notEqual(matType(One), matType(One), Epsilon)) ? 0 : 1;
|
||||
Error += !glm::any(glm::notEqual(matType(One), matType(Two), vecType(Epsilon))) ? 1 : 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
static int test_equal_ulps()
|
||||
{
|
||||
typedef glm::mat<4, 4, T, glm::defaultp> mat4;
|
||||
|
||||
T const One(1);
|
||||
mat4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::nextFloat(One);
|
||||
Error += glm::all(glm::equal(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += !glm::all(glm::equal(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prevFloat(One);
|
||||
Error += glm::all(glm::equal(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += !glm::all(glm::equal(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_notEqual_ulps()
|
||||
{
|
||||
typedef glm::mat<4, 4, T, glm::defaultp> mat4;
|
||||
|
||||
T const One(1);
|
||||
mat4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::nextFloat(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += glm::all(glm::notEqual(Ones, mat4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prevFloat(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, mat4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += glm::all(glm::notEqual(Ones, mat4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_equal_ulps<float>();
|
||||
Error += test_equal_ulps<double>();
|
||||
Error += test_notEqual_ulps<float>();
|
||||
Error += test_notEqual_ulps<double>();
|
||||
|
||||
Error += test_equal<glm::mat2x2, glm::vec2>();
|
||||
Error += test_equal<glm::mat2x3, glm::vec2>();
|
||||
Error += test_equal<glm::mat2x4, glm::vec2>();
|
||||
Error += test_equal<glm::mat3x2, glm::vec3>();
|
||||
Error += test_equal<glm::mat3x3, glm::vec3>();
|
||||
Error += test_equal<glm::mat3x4, glm::vec3>();
|
||||
Error += test_equal<glm::mat4x2, glm::vec4>();
|
||||
Error += test_equal<glm::mat4x3, glm::vec4>();
|
||||
Error += test_equal<glm::mat4x4, glm::vec4>();
|
||||
|
||||
Error += test_equal<glm::dmat2x2, glm::dvec2>();
|
||||
Error += test_equal<glm::dmat2x3, glm::dvec2>();
|
||||
Error += test_equal<glm::dmat2x4, glm::dvec2>();
|
||||
Error += test_equal<glm::dmat3x2, glm::dvec3>();
|
||||
Error += test_equal<glm::dmat3x3, glm::dvec3>();
|
||||
Error += test_equal<glm::dmat3x4, glm::dvec3>();
|
||||
Error += test_equal<glm::dmat4x2, glm::dvec4>();
|
||||
Error += test_equal<glm::dmat4x3, glm::dvec4>();
|
||||
Error += test_equal<glm::dmat4x4, glm::dvec4>();
|
||||
|
||||
Error += test_notEqual<glm::mat2x2, glm::vec2>();
|
||||
Error += test_notEqual<glm::mat2x3, glm::vec2>();
|
||||
Error += test_notEqual<glm::mat2x4, glm::vec2>();
|
||||
Error += test_notEqual<glm::mat3x2, glm::vec3>();
|
||||
Error += test_notEqual<glm::mat3x3, glm::vec3>();
|
||||
Error += test_notEqual<glm::mat3x4, glm::vec3>();
|
||||
Error += test_notEqual<glm::mat4x2, glm::vec4>();
|
||||
Error += test_notEqual<glm::mat4x3, glm::vec4>();
|
||||
Error += test_notEqual<glm::mat4x4, glm::vec4>();
|
||||
|
||||
Error += test_notEqual<glm::dmat2x2, glm::dvec2>();
|
||||
Error += test_notEqual<glm::dmat2x3, glm::dvec2>();
|
||||
Error += test_notEqual<glm::dmat2x4, glm::dvec2>();
|
||||
Error += test_notEqual<glm::dmat3x2, glm::dvec3>();
|
||||
Error += test_notEqual<glm::dmat3x3, glm::dvec3>();
|
||||
Error += test_notEqual<glm::dmat3x4, glm::dvec3>();
|
||||
Error += test_notEqual<glm::dmat4x2, glm::dvec4>();
|
||||
Error += test_notEqual<glm::dmat4x3, glm::dvec4>();
|
||||
Error += test_notEqual<glm::dmat4x4, glm::dvec4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
61
lib/glm/test/ext/ext_matrix_transform.cpp
Normal file
61
lib/glm/test/ext/ext_matrix_transform.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
|
||||
static int test_translate()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4 const M(1.0f);
|
||||
glm::vec3 const V(1.0f);
|
||||
|
||||
glm::mat4 const T = glm::translate(M, V);
|
||||
Error += glm::all(glm::equal(T[3], glm::vec4(1.0f), glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_scale()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4 const M(1.0f);
|
||||
glm::vec3 const V(2.0f);
|
||||
|
||||
glm::mat4 const S = glm::scale(M, V);
|
||||
glm::mat4 const R = glm::mat4(
|
||||
glm::vec4(2, 0, 0, 0),
|
||||
glm::vec4(0, 2, 0, 0),
|
||||
glm::vec4(0, 0, 2, 0),
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
Error += glm::all(glm::equal(S, R, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_rotate()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const A(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
glm::mat4 const R = glm::rotate(glm::mat4(1.0f), glm::radians(90.f), glm::vec3(0, 0, 1));
|
||||
glm::vec4 const B = R * A;
|
||||
Error += glm::all(glm::equal(B, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.0001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_translate();
|
||||
Error += test_scale();
|
||||
Error += test_rotate();
|
||||
|
||||
return Error;
|
||||
}
|
||||
61
lib/glm/test/ext/ext_quaternion_common.cpp
Normal file
61
lib/glm/test/ext/ext_quaternion_common.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/quaternion_common.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_relational.hpp>
|
||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
|
||||
static int test_conjugate()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat const A(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
glm::quat const C = glm::conjugate(A);
|
||||
Error += glm::any(glm::notEqual(A, C, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
glm::quat const B = glm::conjugate(C);
|
||||
Error += glm::all(glm::equal(A, B, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_mix()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat const Q1(glm::vec3(1, 0, 0), glm::vec3(1, 0, 0));
|
||||
glm::quat const Q2(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
|
||||
{
|
||||
glm::quat const Q3 = glm::mix(Q1, Q2, 0.5f);
|
||||
float const F3 = glm::degrees(glm::angle(Q3));
|
||||
Error += glm::equal(F3, 45.0f, 0.001f) ? 0 : 1;
|
||||
|
||||
glm::quat const Q4 = glm::mix(Q2, Q1, 0.5f);
|
||||
float const F4 = glm::degrees(glm::angle(Q4));
|
||||
Error += glm::equal(F4, 45.0f, 0.001f) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat const Q3 = glm::slerp(Q1, Q2, 0.5f);
|
||||
float const F3 = glm::degrees(glm::angle(Q3));
|
||||
Error += glm::equal(F3, 45.0f, 0.001f) ? 0 : 1;
|
||||
|
||||
glm::quat const Q4 = glm::slerp(Q2, Q1, 0.5f);
|
||||
float const F4 = glm::degrees(glm::angle(Q4));
|
||||
Error += glm::equal(F4, 45.0f, 0.001f) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_conjugate();
|
||||
Error += test_mix();
|
||||
|
||||
return Error;
|
||||
}
|
||||
87
lib/glm/test/ext/ext_quaternion_exponential.cpp
Normal file
87
lib/glm/test/ext/ext_quaternion_exponential.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <glm/ext/quaternion_exponential.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_float_precision.hpp>
|
||||
#include <glm/ext/quaternion_double.hpp>
|
||||
#include <glm/ext/quaternion_double_precision.hpp>
|
||||
#include <glm/ext/quaternion_relational.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float3_precision.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double3_precision.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
|
||||
template <typename quaType, typename vecType>
|
||||
int test_log()
|
||||
{
|
||||
typedef typename quaType::value_type T;
|
||||
|
||||
T const Epsilon = static_cast<T>(0.001f);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
quaType const Q(vecType(1, 0, 0), vecType(0, 1, 0));
|
||||
quaType const P = glm::log(Q);
|
||||
Error += glm::any(glm::notEqual(Q, P, Epsilon)) ? 0 : 1;
|
||||
|
||||
quaType const R = glm::exp(P);
|
||||
Error += glm::all(glm::equal(Q, R, Epsilon)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename quaType, typename vecType>
|
||||
int test_pow()
|
||||
{
|
||||
typedef typename quaType::value_type T;
|
||||
|
||||
T const Epsilon = static_cast<T>(0.001f);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
quaType const Q(vecType(1, 0, 0), vecType(0, 1, 0));
|
||||
|
||||
{
|
||||
T const One = static_cast<T>(1.0f);
|
||||
quaType const P = glm::pow(Q, One);
|
||||
Error += glm::all(glm::equal(Q, P, Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
T const Two = static_cast<T>(2.0f);
|
||||
quaType const P = glm::pow(Q, Two);
|
||||
quaType const R = Q * Q;
|
||||
Error += glm::all(glm::equal(P, R, Epsilon)) ? 0 : 1;
|
||||
|
||||
quaType const U = glm::sqrt(P);
|
||||
Error += glm::all(glm::equal(Q, U, Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_log<glm::quat, glm::vec3>();
|
||||
Error += test_log<glm::lowp_quat, glm::lowp_vec3>();
|
||||
Error += test_log<glm::mediump_quat, glm::mediump_vec3>();
|
||||
Error += test_log<glm::highp_quat, glm::highp_vec3>();
|
||||
|
||||
Error += test_log<glm::dquat, glm::dvec3>();
|
||||
Error += test_log<glm::lowp_dquat, glm::lowp_dvec3>();
|
||||
Error += test_log<glm::mediump_dquat, glm::mediump_dvec3>();
|
||||
Error += test_log<glm::highp_dquat, glm::highp_dvec3>();
|
||||
|
||||
Error += test_pow<glm::quat, glm::vec3>();
|
||||
Error += test_pow<glm::lowp_quat, glm::lowp_vec3>();
|
||||
Error += test_pow<glm::mediump_quat, glm::mediump_vec3>();
|
||||
Error += test_pow<glm::highp_quat, glm::highp_vec3>();
|
||||
|
||||
Error += test_pow<glm::dquat, glm::dvec3>();
|
||||
Error += test_pow<glm::lowp_dquat, glm::lowp_dvec3>();
|
||||
Error += test_pow<glm::mediump_dquat, glm::mediump_dvec3>();
|
||||
Error += test_pow<glm::highp_dquat, glm::highp_dvec3>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
88
lib/glm/test/ext/ext_quaternion_geometric.cpp
Normal file
88
lib/glm/test/ext/ext_quaternion_geometric.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||
#include <glm/ext/quaternion_float_precision.hpp>
|
||||
#include <glm/ext/quaternion_double.hpp>
|
||||
#include <glm/ext/quaternion_double_precision.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float3_precision.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double3_precision.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
|
||||
float const Epsilon = 0.001f;
|
||||
|
||||
static int test_length()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float const A = glm::length(glm::quat(1, 0, 0, 0));
|
||||
Error += glm::equal(A, 1.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
float const A = glm::length(glm::quat(1, glm::vec3(0)));
|
||||
Error += glm::equal(A, 1.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
float const A = glm::length(glm::quat(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0)));
|
||||
Error += glm::equal(A, 1.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_normalize()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::quat const A = glm::quat(1, 0, 0, 0);
|
||||
glm::quat const N = glm::normalize(A);
|
||||
Error += glm::all(glm::equal(A, N, Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat const A = glm::quat(1, glm::vec3(0));
|
||||
glm::quat const N = glm::normalize(A);
|
||||
Error += glm::all(glm::equal(A, N, Epsilon)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_dot()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::quat const A = glm::quat(1, 0, 0, 0);
|
||||
glm::quat const B = glm::quat(1, 0, 0, 0);
|
||||
float const C = glm::dot(A, B);
|
||||
Error += glm::equal(C, 1.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_cross()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_length();
|
||||
Error += test_normalize();
|
||||
Error += test_dot();
|
||||
Error += test_cross();
|
||||
|
||||
return Error;
|
||||
}
|
||||
51
lib/glm/test/ext/ext_quaternion_relational.cpp
Normal file
51
lib/glm/test/ext/ext_quaternion_relational.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/quaternion_relational.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_float_precision.hpp>
|
||||
#include <glm/ext/quaternion_double.hpp>
|
||||
#include <glm/ext/quaternion_double_precision.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float3_precision.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double3_precision.hpp>
|
||||
|
||||
template <typename quaType>
|
||||
static int test_equal()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
quaType const Q(1, 0, 0, 0);
|
||||
quaType const P(1, 0, 0, 0);
|
||||
Error += glm::all(glm::equal(Q, P, glm::epsilon<float>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename quaType>
|
||||
static int test_notEqual()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
quaType const Q(1, 0, 0, 0);
|
||||
quaType const P(1, 0, 0, 0);
|
||||
Error += glm::any(glm::notEqual(Q, P, glm::epsilon<float>())) ? 1 : 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_equal<glm::quat>();
|
||||
Error += test_equal<glm::lowp_quat>();
|
||||
Error += test_equal<glm::mediump_quat>();
|
||||
Error += test_equal<glm::highp_quat>();
|
||||
|
||||
Error += test_notEqual<glm::quat>();
|
||||
Error += test_notEqual<glm::lowp_quat>();
|
||||
Error += test_notEqual<glm::mediump_quat>();
|
||||
Error += test_notEqual<glm::highp_quat>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
45
lib/glm/test/ext/ext_quaternion_transform.cpp
Normal file
45
lib/glm/test/ext/ext_quaternion_transform.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <glm/ext/quaternion_transform.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
static int test_lookAt()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::vec3 eye(0.0f);
|
||||
glm::vec3 center(1.1f, -2.0f, 3.1416f);
|
||||
glm::vec3 up(-0.17f, 7.23f, -1.744f);
|
||||
|
||||
glm::quat test_quat = glm::quatLookAt(glm::normalize(center - eye), up);
|
||||
glm::quat test_mat = glm::conjugate(glm::quat_cast(glm::lookAt(eye, center, up)));
|
||||
|
||||
Error += static_cast<int>(glm::abs(glm::length(test_quat) - 1.0f) > glm::epsilon<float>());
|
||||
Error += static_cast<int>(glm::min(glm::length(test_quat + (-test_mat)), glm::length(test_quat + test_mat)) > glm::epsilon<float>());
|
||||
|
||||
// Test left-handed implementation
|
||||
glm::quat test_quatLH = glm::quatLookAtLH(glm::normalize(center - eye), up);
|
||||
glm::quat test_matLH = glm::conjugate(glm::quat_cast(glm::lookAtLH(eye, center, up)));
|
||||
Error += static_cast<int>(glm::abs(glm::length(test_quatLH) - 1.0f) > glm::epsilon<float>());
|
||||
Error += static_cast<int>(glm::min(glm::length(test_quatLH - test_matLH), glm::length(test_quatLH + test_matLH)) > glm::epsilon<float>());
|
||||
|
||||
// Test right-handed implementation
|
||||
glm::quat test_quatRH = glm::quatLookAtRH(glm::normalize(center - eye), up);
|
||||
glm::quat test_matRH = glm::conjugate(glm::quat_cast(glm::lookAtRH(eye, center, up)));
|
||||
Error += static_cast<int>(glm::abs(glm::length(test_quatRH) - 1.0f) > glm::epsilon<float>());
|
||||
Error += static_cast<int>(glm::min(glm::length(test_quatRH - test_matRH), glm::length(test_quatRH + test_matRH)) > glm::epsilon<float>());
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_lookAt();
|
||||
|
||||
return Error;
|
||||
}
|
||||
34
lib/glm/test/ext/ext_quaternion_trigonometric.cpp
Normal file
34
lib/glm/test/ext/ext_quaternion_trigonometric.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
|
||||
float const Epsilon = 0.001f;
|
||||
|
||||
static int test_angle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::quat const Q = glm::quat(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
float const A = glm::degrees(glm::angle(Q));
|
||||
Error += glm::equal(A, 90.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::quat const Q = glm::quat(glm::vec3(0, 1, 0), glm::vec3(1, 0, 0));
|
||||
float const A = glm::degrees(glm::angle(Q));
|
||||
Error += glm::equal(A, 90.0f, Epsilon) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_angle();
|
||||
|
||||
return Error;
|
||||
}
|
||||
113
lib/glm/test/ext/ext_quaternion_type.cpp
Normal file
113
lib/glm/test/ext/ext_quaternion_type.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/quaternion_relational.hpp>
|
||||
#include <glm/ext/quaternion_float.hpp>
|
||||
#include <glm/ext/quaternion_float_precision.hpp>
|
||||
#include <glm/ext/quaternion_double.hpp>
|
||||
#include <glm/ext/quaternion_double_precision.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <vector>
|
||||
|
||||
static int test_ctr()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::quat>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_default_constructible<glm::dquat>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::quat>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::dquat>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::quat>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dquat>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::quat>::value ? 0 : 1;
|
||||
Error += std::is_copy_constructible<glm::dquat>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
# if GLM_HAS_INITIALIZER_LISTS
|
||||
{
|
||||
glm::quat A{0, 1, 2, 3};
|
||||
|
||||
std::vector<glm::quat> B{
|
||||
{0, 1, 2, 3},
|
||||
{0, 1, 2, 3}};
|
||||
}
|
||||
# endif//GLM_HAS_INITIALIZER_LISTS
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_two_axis_ctr()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0);
|
||||
Error += glm::all(glm::equal(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::quat const q2 = q1 * q1;
|
||||
glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0);
|
||||
Error += glm::all(glm::equal(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0));
|
||||
glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0);
|
||||
Error += glm::all(glm::equal(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0));
|
||||
glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0);
|
||||
Error += glm::all(glm::equal(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1;
|
||||
|
||||
glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1));
|
||||
glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1);
|
||||
Error += glm::all(glm::equal(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::size_t const A = sizeof(glm::quat);
|
||||
Error += 16 == A ? 0 : 1;
|
||||
std::size_t const B = sizeof(glm::dquat);
|
||||
Error += 32 == B ? 0 : 1;
|
||||
Error += glm::quat().length() == 4 ? 0 : 1;
|
||||
Error += glm::dquat().length() == 4 ? 0 : 1;
|
||||
Error += glm::quat::length() == 4 ? 0 : 1;
|
||||
Error += glm::dquat::length() == 4 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_precision()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1;
|
||||
Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
|
||||
static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_ctr();
|
||||
Error += test_two_axis_ctr();
|
||||
Error += test_size();
|
||||
Error += test_precision();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
207
lib/glm/test/ext/ext_scalar_common.cpp
Normal file
207
lib/glm/test/ext/ext_scalar_common.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
#include <glm/ext/scalar_common.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/common.hpp>
|
||||
|
||||
#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
|
||||
# define GLM_NAN(T) NAN
|
||||
#else
|
||||
# define GLM_NAN(T) (static_cast<T>(0.0f) / static_cast<T>(0.0f))
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
static int test_min()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const N = static_cast<T>(0);
|
||||
T const B = static_cast<T>(1);
|
||||
Error += glm::equal(glm::min(N, B), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(B, N), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::equal(glm::min(N, B, C), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(B, N, C), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(C, N, B), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(C, B, N), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(B, C, N), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(N, C, B), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += glm::equal(glm::min(D, N, B, C), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(B, D, N, C), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(C, N, D, B), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(C, B, D, N), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(B, C, N, D), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::min(N, C, B, D), N, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_min_nan()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const B = static_cast<T>(1);
|
||||
T const N = static_cast<T>(GLM_NAN(T));
|
||||
Error += glm::isnan(glm::min(N, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(B, N)) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::isnan(glm::min(N, B, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(B, N, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(C, N, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(C, B, N)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(B, C, N)) ? 0 : 1;
|
||||
Error += glm::isnan(glm::min(N, C, B)) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += !glm::isnan(glm::min(D, N, B, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(B, D, N, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(C, N, D, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(C, B, D, N)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::min(B, C, N, D)) ? 0 : 1;
|
||||
Error += glm::isnan(glm::min(N, C, B, D)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_max()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const N = static_cast<T>(0);
|
||||
T const B = static_cast<T>(1);
|
||||
Error += glm::equal(glm::max(N, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(B, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::equal(glm::max(N, B, C), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(B, N, C), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(C, N, B), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(C, B, N), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(B, C, N), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(N, C, B), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += glm::equal(glm::max(D, N, B, C), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(B, D, N, C), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(C, N, D, B), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(C, B, D, N), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(B, C, N, D), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::max(N, C, B, D), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_max_nan()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const B = static_cast<T>(1);
|
||||
T const N = static_cast<T>(GLM_NAN(T));
|
||||
Error += glm::isnan(glm::max(N, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(B, N)) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::isnan(glm::max(N, B, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(B, N, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(C, N, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(C, B, N)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(B, C, N)) ? 0 : 1;
|
||||
Error += glm::isnan(glm::max(N, C, B)) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += !glm::isnan(glm::max(D, N, B, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(B, D, N, C)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(C, N, D, B)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(C, B, D, N)) ? 0 : 1;
|
||||
Error += !glm::isnan(glm::max(B, C, N, D)) ? 0 : 1;
|
||||
Error += glm::isnan(glm::max(N, C, B, D)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_fmin()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const B = static_cast<T>(1);
|
||||
T const N = static_cast<T>(GLM_NAN(T));
|
||||
Error += glm::equal(glm::fmin(N, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(B, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::equal(glm::fmin(N, B, C), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(B, N, C), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(C, N, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(C, B, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(B, C, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(N, C, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += glm::equal(glm::fmin(D, N, B, C), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(B, D, N, C), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(C, N, D, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(C, B, D, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(B, C, N, D), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmin(N, C, B, D), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_fmax()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const B = static_cast<T>(1);
|
||||
T const N = static_cast<T>(GLM_NAN(T));
|
||||
Error += glm::equal(glm::fmax(N, B), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(B, N), B, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const C = static_cast<T>(2);
|
||||
Error += glm::equal(glm::fmax(N, B, C), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(B, N, C), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(C, N, B), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(C, B, N), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(B, C, N), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(N, C, B), C, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
T const D = static_cast<T>(3);
|
||||
Error += glm::equal(glm::fmax(D, N, B, C), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(B, D, N, C), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(C, N, D, B), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(C, B, D, N), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(B, C, N, D), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
Error += glm::equal(glm::fmax(N, C, B, D), D, glm::epsilon<T>()) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_min<float>();
|
||||
Error += test_min<double>();
|
||||
Error += test_min_nan<float>();
|
||||
Error += test_min_nan<double>();
|
||||
|
||||
Error += test_max<float>();
|
||||
Error += test_max<double>();
|
||||
Error += test_max_nan<float>();
|
||||
Error += test_max_nan<double>();
|
||||
|
||||
Error += test_fmin<float>();
|
||||
Error += test_fmin<double>();
|
||||
|
||||
Error += test_fmax<float>();
|
||||
Error += test_fmax<double>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
36
lib/glm/test/ext/ext_scalar_constants.cpp
Normal file
36
lib/glm/test/ext/ext_scalar_constants.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
|
||||
template <typename valType>
|
||||
static int test_epsilon()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
valType const Test = glm::epsilon<valType>();
|
||||
Error += Test > static_cast<valType>(0) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
static int test_pi()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
valType const Test = glm::pi<valType>();
|
||||
Error += Test > static_cast<valType>(3.14) ? 0 : 1;
|
||||
Error += Test < static_cast<valType>(3.15) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_epsilon<float>();
|
||||
Error += test_epsilon<double>();
|
||||
Error += test_pi<float>();
|
||||
Error += test_pi<double>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
43
lib/glm/test/ext/ext_scalar_int_sized.cpp
Normal file
43
lib/glm/test/ext/ext_scalar_int_sized.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <glm/ext/scalar_int_sized.hpp>
|
||||
|
||||
#if GLM_HAS_STATIC_ASSERT
|
||||
static_assert(sizeof(glm::int8) == 1, "int8 size isn't 1 byte on this platform");
|
||||
static_assert(sizeof(glm::int16) == 2, "int16 size isn't 2 bytes on this platform");
|
||||
static_assert(sizeof(glm::int32) == 4, "int32 size isn't 4 bytes on this platform");
|
||||
static_assert(sizeof(glm::int64) == 8, "int64 size isn't 8 bytes on this platform");
|
||||
static_assert(sizeof(glm::int16) == sizeof(short), "signed short size isn't 4 bytes on this platform");
|
||||
static_assert(sizeof(glm::int32) == sizeof(int), "signed int size isn't 4 bytes on this platform");
|
||||
#endif
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::int8) == 1 ? 0 : 1;
|
||||
Error += sizeof(glm::int16) == 2 ? 0 : 1;
|
||||
Error += sizeof(glm::int32) == 4 ? 0 : 1;
|
||||
Error += sizeof(glm::int64) == 8 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_comp()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::int8) < sizeof(glm::int16) ? 0 : 1;
|
||||
Error += sizeof(glm::int16) < sizeof(glm::int32) ? 0 : 1;
|
||||
Error += sizeof(glm::int32) < sizeof(glm::int64) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_size();
|
||||
Error += test_comp();
|
||||
|
||||
return Error;
|
||||
}
|
||||
686
lib/glm/test/ext/ext_scalar_integer.cpp
Normal file
686
lib/glm/test/ext/ext_scalar_integer.cpp
Normal file
@@ -0,0 +1,686 @@
|
||||
#include <glm/ext/scalar_integer.hpp>
|
||||
#include <glm/ext/scalar_int_sized.hpp>
|
||||
#include <glm/ext/scalar_uint_sized.hpp>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
#if GLM_LANG & GLM_LANG_CXX11_FLAG
|
||||
#include <chrono>
|
||||
|
||||
namespace isPowerOfTwo
|
||||
{
|
||||
template<typename genType>
|
||||
struct type
|
||||
{
|
||||
genType Value;
|
||||
bool Return;
|
||||
};
|
||||
|
||||
int test_int16()
|
||||
{
|
||||
type<glm::int16> const Data[] =
|
||||
{
|
||||
{0x0001, true},
|
||||
{0x0002, true},
|
||||
{0x0004, true},
|
||||
{0x0080, true},
|
||||
{0x0000, true},
|
||||
{0x0003, false}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int16>); i < n; ++i)
|
||||
{
|
||||
bool Result = glm::isPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_uint16()
|
||||
{
|
||||
type<glm::uint16> const Data[] =
|
||||
{
|
||||
{0x0001, true},
|
||||
{0x0002, true},
|
||||
{0x0004, true},
|
||||
{0x0000, true},
|
||||
{0x0000, true},
|
||||
{0x0003, false}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint16>); i < n; ++i)
|
||||
{
|
||||
bool Result = glm::isPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_int32()
|
||||
{
|
||||
type<int> const Data[] =
|
||||
{
|
||||
{0x00000001, true},
|
||||
{0x00000002, true},
|
||||
{0x00000004, true},
|
||||
{0x0000000f, false},
|
||||
{0x00000000, true},
|
||||
{0x00000003, false}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<int>); i < n; ++i)
|
||||
{
|
||||
bool Result = glm::isPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_uint32()
|
||||
{
|
||||
type<glm::uint> const Data[] =
|
||||
{
|
||||
{0x00000001, true},
|
||||
{0x00000002, true},
|
||||
{0x00000004, true},
|
||||
{0x80000000, true},
|
||||
{0x00000000, true},
|
||||
{0x00000003, false}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint>); i < n; ++i)
|
||||
{
|
||||
bool Result = glm::isPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_int16();
|
||||
Error += test_uint16();
|
||||
Error += test_int32();
|
||||
Error += test_uint32();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//isPowerOfTwo
|
||||
|
||||
namespace nextPowerOfTwo_advanced
|
||||
{
|
||||
template<typename genIUType>
|
||||
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
|
||||
{
|
||||
genIUType tmp = Value;
|
||||
genIUType result = genIUType(0);
|
||||
while(tmp)
|
||||
{
|
||||
result = (tmp & (~tmp + 1)); // grab lowest bit
|
||||
tmp &= ~result; // clear lowest bit
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename genType>
|
||||
GLM_FUNC_QUALIFIER genType nextPowerOfTwo_loop(genType value)
|
||||
{
|
||||
return glm::isPowerOfTwo(value) ? value : highestBitValue(value) << 1;
|
||||
}
|
||||
|
||||
template<typename genType>
|
||||
struct type
|
||||
{
|
||||
genType Value;
|
||||
genType Return;
|
||||
};
|
||||
|
||||
int test_int32()
|
||||
{
|
||||
type<glm::int32> const Data[] =
|
||||
{
|
||||
{0x0000ffff, 0x00010000},
|
||||
{-3, -4},
|
||||
{-8, -8},
|
||||
{0x00000001, 0x00000001},
|
||||
{0x00000002, 0x00000002},
|
||||
{0x00000004, 0x00000004},
|
||||
{0x00000007, 0x00000008},
|
||||
{0x0000fff0, 0x00010000},
|
||||
{0x0000f000, 0x00010000},
|
||||
{0x08000000, 0x08000000},
|
||||
{0x00000000, 0x00000000},
|
||||
{0x00000003, 0x00000004}
|
||||
};
|
||||
|
||||
int Error(0);
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::int32>); i < n; ++i)
|
||||
{
|
||||
glm::int32 Result = glm::nextPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_uint32()
|
||||
{
|
||||
type<glm::uint32> const Data[] =
|
||||
{
|
||||
{0x00000001, 0x00000001},
|
||||
{0x00000002, 0x00000002},
|
||||
{0x00000004, 0x00000004},
|
||||
{0x00000007, 0x00000008},
|
||||
{0x0000ffff, 0x00010000},
|
||||
{0x0000fff0, 0x00010000},
|
||||
{0x0000f000, 0x00010000},
|
||||
{0x80000000, 0x80000000},
|
||||
{0x00000000, 0x00000000},
|
||||
{0x00000003, 0x00000004}
|
||||
};
|
||||
|
||||
int Error(0);
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::uint32>); i < n; ++i)
|
||||
{
|
||||
glm::uint32 Result = glm::nextPowerOfTwo(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
std::vector<glm::uint> v;
|
||||
v.resize(100000000);
|
||||
|
||||
std::clock_t Timestramp0 = std::clock();
|
||||
|
||||
for(glm::uint32 i = 0, n = static_cast<glm::uint>(v.size()); i < n; ++i)
|
||||
v[i] = nextPowerOfTwo_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::nextPowerOfTwo(i);
|
||||
|
||||
std::clock_t Timestramp2 = std::clock();
|
||||
|
||||
std::printf("nextPowerOfTwo_loop: %d clocks\n", static_cast<int>(Timestramp1 - Timestramp0));
|
||||
std::printf("glm::nextPowerOfTwo: %d clocks\n", static_cast<int>(Timestramp2 - Timestramp1));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += test_int32();
|
||||
Error += test_uint32();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace nextPowerOfTwo_advanced
|
||||
|
||||
namespace prevPowerOfTwo
|
||||
{
|
||||
template <typename T>
|
||||
int run()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const A = glm::prevPowerOfTwo(static_cast<T>(7));
|
||||
Error += A == static_cast<T>(4) ? 0 : 1;
|
||||
|
||||
T const B = glm::prevPowerOfTwo(static_cast<T>(15));
|
||||
Error += B == static_cast<T>(8) ? 0 : 1;
|
||||
|
||||
T const C = glm::prevPowerOfTwo(static_cast<T>(31));
|
||||
Error += C == static_cast<T>(16) ? 0 : 1;
|
||||
|
||||
T const D = glm::prevPowerOfTwo(static_cast<T>(32));
|
||||
Error += D == static_cast<T>(32) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<glm::int8>();
|
||||
Error += run<glm::int16>();
|
||||
Error += run<glm::int32>();
|
||||
Error += run<glm::int64>();
|
||||
|
||||
Error += run<glm::uint8>();
|
||||
Error += run<glm::uint16>();
|
||||
Error += run<glm::uint32>();
|
||||
Error += run<glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace prevPowerOfTwo
|
||||
|
||||
namespace nextPowerOfTwo
|
||||
{
|
||||
template <typename T>
|
||||
int run()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
T const A = glm::nextPowerOfTwo(static_cast<T>(7));
|
||||
Error += A == static_cast<T>(8) ? 0 : 1;
|
||||
|
||||
T const B = glm::nextPowerOfTwo(static_cast<T>(15));
|
||||
Error += B == static_cast<T>(16) ? 0 : 1;
|
||||
|
||||
T const C = glm::nextPowerOfTwo(static_cast<T>(31));
|
||||
Error += C == static_cast<T>(32) ? 0 : 1;
|
||||
|
||||
T const D = glm::nextPowerOfTwo(static_cast<T>(32));
|
||||
Error += D == static_cast<T>(32) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<glm::int8>();
|
||||
Error += run<glm::int16>();
|
||||
Error += run<glm::int32>();
|
||||
Error += run<glm::int64>();
|
||||
|
||||
Error += run<glm::uint8>();
|
||||
Error += run<glm::uint16>();
|
||||
Error += run<glm::uint32>();
|
||||
Error += run<glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace nextPowerOfTwo
|
||||
|
||||
namespace prevMultiple
|
||||
{
|
||||
template<typename genIUType>
|
||||
struct type
|
||||
{
|
||||
genIUType Source;
|
||||
genIUType Multiple;
|
||||
genIUType Return;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
int run()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{8, 3, 6},
|
||||
{7, 7, 7}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
T const Result = glm::prevMultiple(Data[i].Source, Data[i].Multiple);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<glm::int8>();
|
||||
Error += run<glm::int16>();
|
||||
Error += run<glm::int32>();
|
||||
Error += run<glm::int64>();
|
||||
|
||||
Error += run<glm::uint8>();
|
||||
Error += run<glm::uint16>();
|
||||
Error += run<glm::uint32>();
|
||||
Error += run<glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace prevMultiple
|
||||
|
||||
namespace nextMultiple
|
||||
{
|
||||
static glm::uint const Multiples = 128;
|
||||
|
||||
int perf_nextMultiple(glm::uint Samples)
|
||||
{
|
||||
std::vector<glm::uint> Results(Samples * Multiples);
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for(glm::uint Source = 0; Source < Samples; ++Source)
|
||||
for(glm::uint Multiple = 0; Multiple < Multiples; ++Multiple)
|
||||
{
|
||||
Results[Source * Multiples + Multiple] = glm::nextMultiple(Source, Multiples);
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::printf("- glm::nextMultiple Time %d microseconds\n", static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()));
|
||||
|
||||
glm::uint Result = 0;
|
||||
for(std::size_t i = 0, n = Results.size(); i < n; ++i)
|
||||
Result += Results[i];
|
||||
|
||||
return Result > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T nextMultipleMod(T Source, T Multiple)
|
||||
{
|
||||
T const Tmp = Source - static_cast<T>(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
}
|
||||
|
||||
int perf_nextMultipleMod(glm::uint Samples)
|
||||
{
|
||||
std::vector<glm::uint> Results(Samples * Multiples);
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for(glm::uint Multiple = 0; Multiple < Multiples; ++Multiple)
|
||||
for (glm::uint Source = 0; Source < Samples; ++Source)
|
||||
{
|
||||
Results[Source * Multiples + Multiple] = nextMultipleMod(Source, Multiples);
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::printf("- nextMultipleMod Time %d microseconds\n", static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()));
|
||||
|
||||
glm::uint Result = 0;
|
||||
for(std::size_t i = 0, n = Results.size(); i < n; ++i)
|
||||
Result += Results[i];
|
||||
|
||||
return Result > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T nextMultipleNeg(T Source, T Multiple)
|
||||
{
|
||||
if(Source > static_cast<T>(0))
|
||||
{
|
||||
T const Tmp = Source - static_cast<T>(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
}
|
||||
else
|
||||
return Source + (-Source % Multiple);
|
||||
}
|
||||
|
||||
int perf_nextMultipleNeg(glm::uint Samples)
|
||||
{
|
||||
std::vector<glm::uint> Results(Samples * Multiples);
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for(glm::uint Source = 0; Source < Samples; ++Source)
|
||||
for(glm::uint Multiple = 0; Multiple < Multiples; ++Multiple)
|
||||
{
|
||||
Results[Source * Multiples + Multiple] = nextMultipleNeg(Source, Multiples);
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::printf("- nextMultipleNeg Time %d microseconds\n", static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()));
|
||||
|
||||
glm::uint Result = 0;
|
||||
for (std::size_t i = 0, n = Results.size(); i < n; ++i)
|
||||
Result += Results[i];
|
||||
|
||||
return Result > 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T nextMultipleUFloat(T Source, T Multiple)
|
||||
{
|
||||
return Source + (Multiple - std::fmod(Source, Multiple));
|
||||
}
|
||||
|
||||
int perf_nextMultipleUFloat(glm::uint Samples)
|
||||
{
|
||||
std::vector<float> Results(Samples * Multiples);
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for(glm::uint Source = 0; Source < Samples; ++Source)
|
||||
for(glm::uint Multiple = 0; Multiple < Multiples; ++Multiple)
|
||||
{
|
||||
Results[Source * Multiples + Multiple] = nextMultipleUFloat(static_cast<float>(Source), static_cast<float>(Multiples));
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::printf("- nextMultipleUFloat Time %d microseconds\n", static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()));
|
||||
|
||||
float Result = 0;
|
||||
for (std::size_t i = 0, n = Results.size(); i < n; ++i)
|
||||
Result += Results[i];
|
||||
|
||||
return Result > 0.0f ? 0 : 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T nextMultipleFloat(T Source, T Multiple)
|
||||
{
|
||||
if(Source > static_cast<float>(0))
|
||||
return Source + (Multiple - std::fmod(Source, Multiple));
|
||||
else
|
||||
return Source + std::fmod(-Source, Multiple);
|
||||
}
|
||||
|
||||
int perf_nextMultipleFloat(glm::uint Samples)
|
||||
{
|
||||
std::vector<float> Results(Samples * Multiples);
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for(glm::uint Source = 0; Source < Samples; ++Source)
|
||||
for(glm::uint Multiple = 0; Multiple < Multiples; ++Multiple)
|
||||
{
|
||||
Results[Source * Multiples + Multiple] = nextMultipleFloat(static_cast<float>(Source), static_cast<float>(Multiples));
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::printf("- nextMultipleFloat Time %d microseconds\n", static_cast<int>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()));
|
||||
|
||||
float Result = 0;
|
||||
for (std::size_t i = 0, n = Results.size(); i < n; ++i)
|
||||
Result += Results[i];
|
||||
|
||||
return Result > 0.0f ? 0 : 1;
|
||||
}
|
||||
|
||||
template<typename genIUType>
|
||||
struct type
|
||||
{
|
||||
genIUType Source;
|
||||
genIUType Multiple;
|
||||
genIUType Return;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
int test_uint()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{ 3, 4, 4 },
|
||||
{ 6, 3, 6 },
|
||||
{ 5, 3, 6 },
|
||||
{ 7, 7, 7 },
|
||||
{ 0, 1, 0 },
|
||||
{ 8, 3, 9 }
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
T const Result0 = glm::nextMultiple(Data[i].Source, Data[i].Multiple);
|
||||
Error += Data[i].Return == Result0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
|
||||
T const Result1 = nextMultipleMod(Data[i].Source, Data[i].Multiple);
|
||||
Error += Data[i].Return == Result1 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::uint const Samples = 10000;
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
std::printf("Run %d :\n", i);
|
||||
Error += perf_nextMultiple(Samples);
|
||||
Error += perf_nextMultipleMod(Samples);
|
||||
Error += perf_nextMultipleNeg(Samples);
|
||||
Error += perf_nextMultipleUFloat(Samples);
|
||||
Error += perf_nextMultipleFloat(Samples);
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_uint<glm::int8>();
|
||||
Error += test_uint<glm::int16>();
|
||||
Error += test_uint<glm::int32>();
|
||||
Error += test_uint<glm::int64>();
|
||||
|
||||
Error += test_uint<glm::uint8>();
|
||||
Error += test_uint<glm::uint16>();
|
||||
Error += test_uint<glm::uint32>();
|
||||
Error += test_uint<glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace nextMultiple
|
||||
|
||||
namespace findNSB
|
||||
{
|
||||
template<typename T>
|
||||
struct type
|
||||
{
|
||||
T Source;
|
||||
int SignificantBitCount;
|
||||
int Return;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
int run()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{ 0x00, 1,-1 },
|
||||
{ 0x01, 2,-1 },
|
||||
{ 0x02, 2,-1 },
|
||||
{ 0x06, 3,-1 },
|
||||
{ 0x01, 1, 0 },
|
||||
{ 0x03, 1, 0 },
|
||||
{ 0x03, 2, 1 },
|
||||
{ 0x07, 2, 1 },
|
||||
{ 0x05, 2, 2 },
|
||||
{ 0x0D, 2, 2 }
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
int const Result0 = glm::findNSB(Data[i].Source, Data[i].SignificantBitCount);
|
||||
Error += Data[i].Return == Result0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<glm::uint8>();
|
||||
Error += run<glm::uint16>();
|
||||
Error += run<glm::uint32>();
|
||||
Error += run<glm::uint64>();
|
||||
|
||||
Error += run<glm::int8>();
|
||||
Error += run<glm::int16>();
|
||||
Error += run<glm::int32>();
|
||||
Error += run<glm::int64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace findNSB
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += findNSB::test();
|
||||
|
||||
Error += isPowerOfTwo::test();
|
||||
Error += prevPowerOfTwo::test();
|
||||
Error += nextPowerOfTwo::test();
|
||||
Error += nextPowerOfTwo_advanced::test();
|
||||
Error += prevMultiple::test();
|
||||
Error += nextMultiple::test();
|
||||
|
||||
# ifdef NDEBUG
|
||||
Error += nextPowerOfTwo_advanced::perf();
|
||||
Error += nextMultiple::perf();
|
||||
# endif//NDEBUG
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
106
lib/glm/test/ext/ext_scalar_relational.cpp
Normal file
106
lib/glm/test/ext/ext_scalar_relational.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/scalar_integer.hpp>
|
||||
#include <glm/ext/scalar_ulp.hpp>
|
||||
#include <cmath>
|
||||
|
||||
static int test_equal_epsilon()
|
||||
{
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
static_assert(glm::equal(1.01f, 1.02f, 0.1f), "GLM: Failed constexpr");
|
||||
static_assert(!glm::equal(1.01f, 1.02f, 0.001f), "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::equal(1.01f, 1.02f, 0.1f) ? 0 : 1;
|
||||
Error += !glm::equal(1.01f, 1.02f, 0.001f) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_notEqual_epsilon()
|
||||
{
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
static_assert(glm::notEqual(1.01f, 1.02f, 0.001f), "GLM: Failed constexpr");
|
||||
static_assert(!glm::notEqual(1.01f, 1.02f, 0.1f), "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::notEqual(1.01f, 1.02f, 0.001f) ? 0 : 1;
|
||||
Error += !glm::notEqual(1.01f, 1.02f, 0.1f) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_equal_ulps()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float const ULP1Plus = glm::nextFloat(1.0f);
|
||||
Error += glm::equal(1.0f, ULP1Plus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += !glm::equal(1.0f, ULP2Plus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP1Minus = glm::prevFloat(1.0f);
|
||||
Error += glm::equal(1.0f, ULP1Minus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += !glm::equal(1.0f, ULP2Minus, 1) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_notEqual_ulps()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float const ULP1Plus = glm::nextFloat(1.0f);
|
||||
Error += !glm::notEqual(1.0f, ULP1Plus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += glm::notEqual(1.0f, ULP2Plus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP1Minus = glm::prevFloat(1.0f);
|
||||
Error += !glm::notEqual(1.0f, ULP1Minus, 1) ? 0 : 1;
|
||||
|
||||
float const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += glm::notEqual(1.0f, ULP2Minus, 1) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_equal_sign()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += !glm::equal(-0.0f, 0.0f, 2) ? 0 : 1;
|
||||
Error += !glm::equal(-0.0, 0.0, 2) ? 0 : 1;
|
||||
|
||||
Error += !glm::equal(-1.0f, 2.0f, 2) ? 0 : 1;
|
||||
Error += !glm::equal(-1.0, 2.0, 2) ? 0 : 1;
|
||||
|
||||
Error += !glm::equal(-0.00001f, 1.00000f, 2) ? 0 : 1;
|
||||
Error += !glm::equal(-0.00001, 1.00000, 2) ? 0 : 1;
|
||||
|
||||
Error += !glm::equal(-1.0f, 1.0f, 2) ? 0 : 1;
|
||||
Error += !glm::equal(-1.0, 1.0, 2) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_equal_epsilon();
|
||||
Error += test_notEqual_epsilon();
|
||||
|
||||
Error += test_equal_ulps();
|
||||
Error += test_notEqual_ulps();
|
||||
|
||||
Error += test_equal_sign();
|
||||
|
||||
return Error;
|
||||
}
|
||||
43
lib/glm/test/ext/ext_scalar_uint_sized.cpp
Normal file
43
lib/glm/test/ext/ext_scalar_uint_sized.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <glm/ext/scalar_uint_sized.hpp>
|
||||
|
||||
#if GLM_HAS_STATIC_ASSERT
|
||||
static_assert(sizeof(glm::uint8) == 1, "uint8 size isn't 1 byte on this platform");
|
||||
static_assert(sizeof(glm::uint16) == 2, "uint16 size isn't 2 bytes on this platform");
|
||||
static_assert(sizeof(glm::uint32) == 4, "uint32 size isn't 4 bytes on this platform");
|
||||
static_assert(sizeof(glm::uint64) == 8, "uint64 size isn't 8 bytes on this platform");
|
||||
static_assert(sizeof(glm::uint16) == sizeof(unsigned short), "unsigned short size isn't 4 bytes on this platform");
|
||||
static_assert(sizeof(glm::uint32) == sizeof(unsigned int), "unsigned int size isn't 4 bytes on this platform");
|
||||
#endif
|
||||
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::uint8) == 1 ? 0 : 1;
|
||||
Error += sizeof(glm::uint16) == 2 ? 0 : 1;
|
||||
Error += sizeof(glm::uint32) == 4 ? 0 : 1;
|
||||
Error += sizeof(glm::uint64) == 8 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_comp()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::uint8) < sizeof(glm::uint16) ? 0 : 1;
|
||||
Error += sizeof(glm::uint16) < sizeof(glm::uint32) ? 0 : 1;
|
||||
Error += sizeof(glm::uint32) < sizeof(glm::uint64) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_size();
|
||||
Error += test_comp();
|
||||
|
||||
return Error;
|
||||
}
|
||||
96
lib/glm/test/ext/ext_scalar_ulp.cpp
Normal file
96
lib/glm/test/ext/ext_scalar_ulp.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <glm/ext/scalar_ulp.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
|
||||
static int test_ulp_float_dist()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
float A = 1.0f;
|
||||
|
||||
float B = glm::nextFloat(A);
|
||||
Error += glm::notEqual(A, B, 0) ? 0 : 1;
|
||||
float C = glm::prevFloat(B);
|
||||
Error += glm::equal(A, C, 0) ? 0 : 1;
|
||||
|
||||
int D = glm::floatDistance(A, B);
|
||||
Error += D == 1 ? 0 : 1;
|
||||
int E = glm::floatDistance(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::nextFloat(A, i);
|
||||
Error += glm::notEqual(A, B, 0) ? 0 : 1;
|
||||
float C = glm::prevFloat(B, i);
|
||||
Error += glm::equal(A, C, 0) ? 0 : 1;
|
||||
|
||||
int D = glm::floatDistance(A, B);
|
||||
Error += D == i ? 0 : 1;
|
||||
int E = glm::floatDistance(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::nextFloat(A);
|
||||
Error += glm::notEqual(A, B, 0) ? 0 : 1;
|
||||
double C = glm::prevFloat(B);
|
||||
Error += glm::equal(A, C, 0) ? 0 : 1;
|
||||
|
||||
glm::int64 const D = glm::floatDistance(A, B);
|
||||
Error += D == 1 ? 0 : 1;
|
||||
glm::int64 const E = glm::floatDistance(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::nextFloat(A, i);
|
||||
Error += glm::notEqual(A, B, 0) ? 0 : 1;
|
||||
double C = glm::prevFloat(B, i);
|
||||
Error += glm::equal(A, C, 0) ? 0 : 1;
|
||||
|
||||
glm::int64 const D = glm::floatDistance(A, B);
|
||||
Error += D == i ? 0 : 1;
|
||||
glm::int64 const E = glm::floatDistance(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;
|
||||
}
|
||||
157
lib/glm/test/ext/ext_vec1.cpp
Normal file
157
lib/glm/test/ext/ext_vec1.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <vector>
|
||||
|
||||
static glm::vec1 g1;
|
||||
static glm::vec1 g2(1);
|
||||
|
||||
static int test_vec1_operators()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::ivec1 A(1);
|
||||
glm::ivec1 B(1);
|
||||
{
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
A *= 1;
|
||||
B *= 1;
|
||||
A += 1;
|
||||
B += 1;
|
||||
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec1_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
# if GLM_HAS_TRIVIAL_QUERIES
|
||||
// Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
|
||||
// Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
|
||||
Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
|
||||
|
||||
Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
|
||||
# endif
|
||||
|
||||
|
||||
{
|
||||
glm::ivec1 A = glm::vec1(2.0f);
|
||||
|
||||
glm::ivec1 E(glm::dvec1(2.0));
|
||||
Error += A == E ? 0 : 1;
|
||||
|
||||
glm::ivec1 F(glm::ivec1(2));
|
||||
Error += A == F ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec1_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
|
||||
Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
|
||||
Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
|
||||
Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
|
||||
Error += glm::vec1().length() == 1 ? 0 : 1;
|
||||
Error += glm::dvec1().length() == 1 ? 0 : 1;
|
||||
Error += glm::vec1::length() == 1 ? 0 : 1;
|
||||
Error += glm::dvec1::length() == 1 ? 0 : 1;
|
||||
|
||||
GLM_CONSTEXPR std::size_t Length = glm::vec1::length();
|
||||
Error += Length == 1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_vec1_operator_increment()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::ivec1 v0(1);
|
||||
glm::ivec1 v1(v0);
|
||||
glm::ivec1 v2(v0);
|
||||
glm::ivec1 v3 = ++v1;
|
||||
glm::ivec1 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
int i0(1);
|
||||
int i1(i0);
|
||||
int i2(i0);
|
||||
int i3 = ++i1;
|
||||
int i4 = i2++;
|
||||
|
||||
Error += i0 == i4 ? 0 : 1;
|
||||
Error += i1 == i2 ? 0 : 1;
|
||||
Error += i1 == i3 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_bvec1_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::bvec1 const A(true);
|
||||
glm::bvec1 const B(true);
|
||||
glm::bvec1 const C(false);
|
||||
glm::bvec1 const D = A && B;
|
||||
glm::bvec1 const E = A && C;
|
||||
glm::bvec1 const F = A || C;
|
||||
|
||||
Error += D == glm::bvec1(true) ? 0 : 1;
|
||||
Error += E == glm::bvec1(false) ? 0 : 1;
|
||||
Error += F == glm::bvec1(true) ? 0 : 1;
|
||||
|
||||
bool const G = A == C;
|
||||
bool const H = A != C;
|
||||
Error += !G ? 0 : 1;
|
||||
Error += H ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_constexpr()
|
||||
{
|
||||
#if GLM_HAS_CONSTEXPR
|
||||
static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
|
||||
static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_vec1_size();
|
||||
Error += test_vec1_ctor();
|
||||
Error += test_bvec1_ctor();
|
||||
Error += test_vec1_operators();
|
||||
Error += test_vec1_operator_increment();
|
||||
Error += test_constexpr();
|
||||
|
||||
return Error;
|
||||
}
|
||||
104
lib/glm/test/ext/ext_vector_bool1.cpp
Normal file
104
lib/glm/test/ext/ext_vector_bool1.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <glm/ext/vector_bool1.hpp>
|
||||
#include <glm/ext/vector_bool1_precision.hpp>
|
||||
|
||||
template <typename genType>
|
||||
static int test_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType const A(true);
|
||||
genType const B(true);
|
||||
{
|
||||
bool const R = A != B;
|
||||
bool const S = A == B;
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_ctor()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::bvec1 const A = genType(true);
|
||||
|
||||
glm::bvec1 const E(genType(true));
|
||||
Error += A == E ? 0 : 1;
|
||||
|
||||
glm::bvec1 const F(E);
|
||||
Error += A == F ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::bvec1) == sizeof(genType) ? 0 : 1;
|
||||
Error += genType().length() == 1 ? 0 : 1;
|
||||
Error += genType::length() == 1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_relational()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType const A(true);
|
||||
genType const B(true);
|
||||
genType const C(false);
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += (A && B) == A ? 0 : 1;
|
||||
Error += (A || C) == A ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_constexpr()
|
||||
{
|
||||
# if GLM_HAS_CONSTEXPR
|
||||
static_assert(genType::length() == 1, "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_operators<glm::bvec1>();
|
||||
Error += test_operators<glm::lowp_bvec1>();
|
||||
Error += test_operators<glm::mediump_bvec1>();
|
||||
Error += test_operators<glm::highp_bvec1>();
|
||||
|
||||
Error += test_ctor<glm::bvec1>();
|
||||
Error += test_ctor<glm::lowp_bvec1>();
|
||||
Error += test_ctor<glm::mediump_bvec1>();
|
||||
Error += test_ctor<glm::highp_bvec1>();
|
||||
|
||||
Error += test_size<glm::bvec1>();
|
||||
Error += test_size<glm::lowp_bvec1>();
|
||||
Error += test_size<glm::mediump_bvec1>();
|
||||
Error += test_size<glm::highp_bvec1>();
|
||||
|
||||
Error += test_relational<glm::bvec1>();
|
||||
Error += test_relational<glm::lowp_bvec1>();
|
||||
Error += test_relational<glm::mediump_bvec1>();
|
||||
Error += test_relational<glm::highp_bvec1>();
|
||||
|
||||
Error += test_constexpr<glm::bvec1>();
|
||||
Error += test_constexpr<glm::lowp_bvec1>();
|
||||
Error += test_constexpr<glm::mediump_bvec1>();
|
||||
Error += test_constexpr<glm::highp_bvec1>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
250
lib/glm/test/ext/ext_vector_common.cpp
Normal file
250
lib/glm/test/ext/ext_vector_common.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
#include <glm/ext/vector_common.hpp>
|
||||
#include <glm/ext/vector_bool1.hpp>
|
||||
#include <glm/ext/vector_bool1_precision.hpp>
|
||||
#include <glm/ext/vector_bool2.hpp>
|
||||
#include <glm/ext/vector_bool2_precision.hpp>
|
||||
#include <glm/ext/vector_bool3.hpp>
|
||||
#include <glm/ext/vector_bool3_precision.hpp>
|
||||
#include <glm/ext/vector_bool4.hpp>
|
||||
#include <glm/ext/vector_bool4_precision.hpp>
|
||||
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_float1_precision.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float2_precision.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float3_precision.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_float4_precision.hpp>
|
||||
#include <glm/ext/vector_double1.hpp>
|
||||
#include <glm/ext/vector_double1_precision.hpp>
|
||||
#include <glm/ext/vector_double2.hpp>
|
||||
#include <glm/ext/vector_double2_precision.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double3_precision.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <glm/ext/vector_double4_precision.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/common.hpp>
|
||||
|
||||
#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
|
||||
# define GLM_NAN(T) NAN
|
||||
#else
|
||||
# define GLM_NAN(T) (static_cast<T>(0.0f) / static_cast<T>(0.0f))
|
||||
#endif
|
||||
|
||||
template <typename vecType>
|
||||
static int test_min()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const N(static_cast<T>(0));
|
||||
vecType const B(static_cast<T>(1));
|
||||
|
||||
Error += glm::all(glm::equal(glm::min(N, B), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(B, N), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::equal(glm::min(N, B, C), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(B, N, C), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(C, N, B), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(C, B, N), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(B, C, N), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(N, C, B), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += glm::all(glm::equal(glm::min(D, N, B, C), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(B, D, N, C), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(C, N, D, B), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(C, B, D, N), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(B, C, N, D), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::min(N, C, B, D), N, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_min_nan()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const B(static_cast<T>(1));
|
||||
vecType const N(GLM_NAN(T));
|
||||
|
||||
Error += glm::all(glm::isnan(glm::min(N, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(B, N))) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::isnan(glm::min(N, B, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(B, N, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(C, N, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(C, B, N))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(B, C, N))) ? 0 : 1;
|
||||
Error += glm::all(glm::isnan(glm::min(N, C, B))) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += !glm::all(glm::isnan(glm::min(D, N, B, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(B, D, N, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(C, N, D, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(C, B, D, N))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::min(B, C, N, D))) ? 0 : 1;
|
||||
Error += glm::all(glm::isnan(glm::min(N, C, B, D))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_max()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const N(static_cast<T>(0));
|
||||
vecType const B(static_cast<T>(1));
|
||||
Error += glm::all(glm::equal(glm::max(N, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(B, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::equal(glm::max(N, B, C), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(B, N, C), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(C, N, B), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(C, B, N), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(B, C, N), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(N, C, B), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += glm::all(glm::equal(glm::max(D, N, B, C), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(B, D, N, C), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(C, N, D, B), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(C, B, D, N), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(B, C, N, D), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::max(N, C, B, D), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_max_nan()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const B(static_cast<T>(1));
|
||||
vecType const N(GLM_NAN(T));
|
||||
|
||||
Error += glm::all(glm::isnan(glm::max(N, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(B, N))) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::isnan(glm::max(N, B, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(B, N, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(C, N, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(C, B, N))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(B, C, N))) ? 0 : 1;
|
||||
Error += glm::all(glm::isnan(glm::max(N, C, B))) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += !glm::all(glm::isnan(glm::max(D, N, B, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(B, D, N, C))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(C, N, D, B))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(C, B, D, N))) ? 0 : 1;
|
||||
Error += !glm::all(glm::isnan(glm::max(B, C, N, D))) ? 0 : 1;
|
||||
Error += glm::all(glm::isnan(glm::max(N, C, B, D))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_fmin()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const B(static_cast<T>(1));
|
||||
vecType const N(GLM_NAN(T));
|
||||
|
||||
Error += glm::all(glm::equal(glm::fmin(N, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(B, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::equal(glm::fmin(N, B, C), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(B, N, C), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(C, N, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(C, B, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(B, C, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(N, C, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += glm::all(glm::equal(glm::fmin(D, N, B, C), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(B, D, N, C), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(C, N, D, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(C, B, D, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(B, C, N, D), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmin(N, C, B, D), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_fmax()
|
||||
{
|
||||
typedef typename vecType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
vecType const B(static_cast<T>(1));
|
||||
vecType const N(GLM_NAN(T));
|
||||
|
||||
Error += glm::all(glm::equal(glm::fmax(N, B), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(B, N), B, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const C(static_cast<T>(2));
|
||||
Error += glm::all(glm::equal(glm::fmax(N, B, C), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(B, N, C), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(C, N, B), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(C, B, N), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(B, C, N), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(N, C, B), C, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
vecType const D(static_cast<T>(3));
|
||||
Error += glm::all(glm::equal(glm::fmax(D, N, B, C), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(B, D, N, C), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(C, N, D, B), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(C, B, D, N), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(B, C, N, D), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(glm::fmax(N, C, B, D), D, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_min<glm::vec3>();
|
||||
Error += test_min<glm::vec2>();
|
||||
Error += test_min_nan<glm::vec3>();
|
||||
Error += test_min_nan<glm::vec2>();
|
||||
|
||||
Error += test_max<glm::vec3>();
|
||||
Error += test_max<glm::vec2>();
|
||||
Error += test_max_nan<glm::vec3>();
|
||||
Error += test_max_nan<glm::vec2>();
|
||||
|
||||
Error += test_fmin<glm::vec3>();
|
||||
Error += test_fmin<glm::vec2>();
|
||||
|
||||
Error += test_fmax<glm::vec3>();
|
||||
Error += test_fmax<glm::vec2>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
166
lib/glm/test/ext/ext_vector_iec559.cpp
Normal file
166
lib/glm/test/ext/ext_vector_iec559.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/scalar_relational.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_double1.hpp>
|
||||
#include <glm/ext/vector_double1_precision.hpp>
|
||||
#include <glm/ext/vector_double2.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_float1_precision.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
|
||||
template <typename genType>
|
||||
static int test_operators()
|
||||
{
|
||||
typedef typename genType::value_type valType;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
|
||||
genType const C = A + B;
|
||||
Error += glm::all(glm::equal(C, genType(2), glm::epsilon<valType>())) ? 0 : 1;
|
||||
|
||||
genType const D = A - B;
|
||||
Error += glm::all(glm::equal(D, genType(0), glm::epsilon<valType>())) ? 0 : 1;
|
||||
|
||||
genType const E = A * B;
|
||||
Error += glm::all(glm::equal(E, genType(1), glm::epsilon<valType>())) ? 0 : 1;
|
||||
|
||||
genType const F = A / B;
|
||||
Error += glm::all(glm::equal(F, genType(1), glm::epsilon<valType>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_ctor()
|
||||
{
|
||||
typedef typename genType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
glm::vec<1, T> const A = genType(1);
|
||||
|
||||
glm::vec<1, T> const E(genType(1));
|
||||
Error += glm::all(glm::equal(A, E, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
glm::vec<1, T> const F(E);
|
||||
Error += glm::all(glm::equal(A, F, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
genType const B = genType(1);
|
||||
genType const G(glm::vec<2, T>(1));
|
||||
Error += glm::all(glm::equal(B, G, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
genType const H(glm::vec<3, T>(1));
|
||||
Error += glm::all(glm::equal(B, H, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
genType const I(glm::vec<4, T>(1));
|
||||
Error += glm::all(glm::equal(B, I, glm::epsilon<T>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_size()
|
||||
{
|
||||
typedef typename genType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(glm::vec<1, T>) == sizeof(genType) ? 0 : 1;
|
||||
Error += genType().length() == 1 ? 0 : 1;
|
||||
Error += genType::length() == 1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_relational()
|
||||
{
|
||||
typedef typename genType::value_type valType;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
genType const C(0);
|
||||
|
||||
Error += all(equal(A, B, glm::epsilon<valType>())) ? 0 : 1;
|
||||
Error += any(notEqual(A, C, glm::epsilon<valType>())) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_constexpr()
|
||||
{
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
static_assert(genType::length() == 1, "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_operators<glm::dvec1>();
|
||||
Error += test_operators<glm::lowp_dvec1>();
|
||||
Error += test_operators<glm::mediump_dvec1>();
|
||||
Error += test_operators<glm::highp_dvec1>();
|
||||
|
||||
Error += test_ctor<glm::dvec1>();
|
||||
Error += test_ctor<glm::lowp_dvec1>();
|
||||
Error += test_ctor<glm::mediump_dvec1>();
|
||||
Error += test_ctor<glm::highp_dvec1>();
|
||||
|
||||
Error += test_size<glm::dvec1>();
|
||||
Error += test_size<glm::lowp_dvec1>();
|
||||
Error += test_size<glm::mediump_dvec1>();
|
||||
Error += test_size<glm::highp_dvec1>();
|
||||
|
||||
Error += test_relational<glm::dvec1>();
|
||||
Error += test_relational<glm::lowp_dvec1>();
|
||||
Error += test_relational<glm::mediump_dvec1>();
|
||||
Error += test_relational<glm::highp_dvec1>();
|
||||
|
||||
Error += test_constexpr<glm::dvec1>();
|
||||
Error += test_constexpr<glm::lowp_dvec1>();
|
||||
Error += test_constexpr<glm::mediump_dvec1>();
|
||||
Error += test_constexpr<glm::highp_dvec1>();
|
||||
|
||||
Error += test_operators<glm::vec1>();
|
||||
Error += test_operators<glm::lowp_vec1>();
|
||||
Error += test_operators<glm::mediump_vec1>();
|
||||
Error += test_operators<glm::highp_vec1>();
|
||||
|
||||
Error += test_ctor<glm::vec1>();
|
||||
Error += test_ctor<glm::lowp_vec1>();
|
||||
Error += test_ctor<glm::mediump_vec1>();
|
||||
Error += test_ctor<glm::highp_vec1>();
|
||||
|
||||
Error += test_size<glm::vec1>();
|
||||
Error += test_size<glm::lowp_vec1>();
|
||||
Error += test_size<glm::mediump_vec1>();
|
||||
Error += test_size<glm::highp_vec1>();
|
||||
|
||||
Error += test_relational<glm::vec1>();
|
||||
Error += test_relational<glm::lowp_vec1>();
|
||||
Error += test_relational<glm::mediump_vec1>();
|
||||
Error += test_relational<glm::highp_vec1>();
|
||||
|
||||
Error += test_constexpr<glm::vec1>();
|
||||
Error += test_constexpr<glm::lowp_vec1>();
|
||||
Error += test_constexpr<glm::mediump_vec1>();
|
||||
Error += test_constexpr<glm::highp_vec1>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
547
lib/glm/test/ext/ext_vector_integer.cpp
Normal file
547
lib/glm/test/ext/ext_vector_integer.cpp
Normal file
@@ -0,0 +1,547 @@
|
||||
#include <glm/ext/vector_integer.hpp>
|
||||
#include <glm/ext/scalar_int_sized.hpp>
|
||||
#include <glm/ext/scalar_uint_sized.hpp>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
namespace isPowerOfTwo
|
||||
{
|
||||
template<typename genType>
|
||||
struct type
|
||||
{
|
||||
genType Value;
|
||||
bool Return;
|
||||
};
|
||||
|
||||
template <glm::length_t L>
|
||||
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)
|
||||
{
|
||||
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::int16>(Data[i].Value));
|
||||
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <glm::length_t L>
|
||||
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)
|
||||
{
|
||||
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::uint16>(Data[i].Value));
|
||||
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <glm::length_t L>
|
||||
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)
|
||||
{
|
||||
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::int32>(Data[i].Value));
|
||||
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <glm::length_t L>
|
||||
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)
|
||||
{
|
||||
glm::vec<L, bool> const Result = glm::isPowerOfTwo(glm::vec<L, glm::uint32>(Data[i].Value));
|
||||
Error += glm::vec<L, bool>(Data[i].Return) == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_int16<1>();
|
||||
Error += test_int16<2>();
|
||||
Error += test_int16<3>();
|
||||
Error += test_int16<4>();
|
||||
|
||||
Error += test_uint16<1>();
|
||||
Error += test_uint16<2>();
|
||||
Error += test_uint16<3>();
|
||||
Error += test_uint16<4>();
|
||||
|
||||
Error += test_int32<1>();
|
||||
Error += test_int32<2>();
|
||||
Error += test_int32<3>();
|
||||
Error += test_int32<4>();
|
||||
|
||||
Error += test_uint32<1>();
|
||||
Error += test_uint32<2>();
|
||||
Error += test_uint32<3>();
|
||||
Error += test_uint32<4>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//isPowerOfTwo
|
||||
|
||||
namespace prevPowerOfTwo
|
||||
{
|
||||
template <glm::length_t L, typename T>
|
||||
int run()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec<L, T> const A = glm::prevPowerOfTwo(glm::vec<L, T>(7));
|
||||
Error += A == glm::vec<L, T>(4) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const B = glm::prevPowerOfTwo(glm::vec<L, T>(15));
|
||||
Error += B == glm::vec<L, T>(8) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const C = glm::prevPowerOfTwo(glm::vec<L, T>(31));
|
||||
Error += C == glm::vec<L, T>(16) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const D = glm::prevPowerOfTwo(glm::vec<L, T>(32));
|
||||
Error += D == glm::vec<L, T>(32) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<1, glm::int8>();
|
||||
Error += run<2, glm::int8>();
|
||||
Error += run<3, glm::int8>();
|
||||
Error += run<4, glm::int8>();
|
||||
|
||||
Error += run<1, glm::int16>();
|
||||
Error += run<2, glm::int16>();
|
||||
Error += run<3, glm::int16>();
|
||||
Error += run<4, glm::int16>();
|
||||
|
||||
Error += run<1, glm::int32>();
|
||||
Error += run<2, glm::int32>();
|
||||
Error += run<3, glm::int32>();
|
||||
Error += run<4, glm::int32>();
|
||||
|
||||
Error += run<1, glm::int64>();
|
||||
Error += run<2, glm::int64>();
|
||||
Error += run<3, glm::int64>();
|
||||
Error += run<4, glm::int64>();
|
||||
|
||||
Error += run<1, glm::uint8>();
|
||||
Error += run<2, glm::uint8>();
|
||||
Error += run<3, glm::uint8>();
|
||||
Error += run<4, glm::uint8>();
|
||||
|
||||
Error += run<1, glm::uint16>();
|
||||
Error += run<2, glm::uint16>();
|
||||
Error += run<3, glm::uint16>();
|
||||
Error += run<4, glm::uint16>();
|
||||
|
||||
Error += run<1, glm::uint32>();
|
||||
Error += run<2, glm::uint32>();
|
||||
Error += run<3, glm::uint32>();
|
||||
Error += run<4, glm::uint32>();
|
||||
|
||||
Error += run<1, glm::uint64>();
|
||||
Error += run<2, glm::uint64>();
|
||||
Error += run<3, glm::uint64>();
|
||||
Error += run<4, glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace prevPowerOfTwo
|
||||
|
||||
namespace nextPowerOfTwo
|
||||
{
|
||||
template <glm::length_t L, typename T>
|
||||
int run()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec<L, T> const A = glm::nextPowerOfTwo(glm::vec<L, T>(7));
|
||||
Error += A == glm::vec<L, T>(8) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const B = glm::nextPowerOfTwo(glm::vec<L, T>(15));
|
||||
Error += B == glm::vec<L, T>(16) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const C = glm::nextPowerOfTwo(glm::vec<L, T>(31));
|
||||
Error += C == glm::vec<L, T>(32) ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const D = glm::nextPowerOfTwo(glm::vec<L, T>(32));
|
||||
Error += D == glm::vec<L, T>(32) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<1, glm::int8>();
|
||||
Error += run<2, glm::int8>();
|
||||
Error += run<3, glm::int8>();
|
||||
Error += run<4, glm::int8>();
|
||||
|
||||
Error += run<1, glm::int16>();
|
||||
Error += run<2, glm::int16>();
|
||||
Error += run<3, glm::int16>();
|
||||
Error += run<4, glm::int16>();
|
||||
|
||||
Error += run<1, glm::int32>();
|
||||
Error += run<2, glm::int32>();
|
||||
Error += run<3, glm::int32>();
|
||||
Error += run<4, glm::int32>();
|
||||
|
||||
Error += run<1, glm::int64>();
|
||||
Error += run<2, glm::int64>();
|
||||
Error += run<3, glm::int64>();
|
||||
Error += run<4, glm::int64>();
|
||||
|
||||
Error += run<1, glm::uint8>();
|
||||
Error += run<2, glm::uint8>();
|
||||
Error += run<3, glm::uint8>();
|
||||
Error += run<4, glm::uint8>();
|
||||
|
||||
Error += run<1, glm::uint16>();
|
||||
Error += run<2, glm::uint16>();
|
||||
Error += run<3, glm::uint16>();
|
||||
Error += run<4, glm::uint16>();
|
||||
|
||||
Error += run<1, glm::uint32>();
|
||||
Error += run<2, glm::uint32>();
|
||||
Error += run<3, glm::uint32>();
|
||||
Error += run<4, glm::uint32>();
|
||||
|
||||
Error += run<1, glm::uint64>();
|
||||
Error += run<2, glm::uint64>();
|
||||
Error += run<3, glm::uint64>();
|
||||
Error += run<4, glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace nextPowerOfTwo
|
||||
|
||||
namespace prevMultiple
|
||||
{
|
||||
template<typename genIUType>
|
||||
struct type
|
||||
{
|
||||
genIUType Source;
|
||||
genIUType Multiple;
|
||||
genIUType Return;
|
||||
};
|
||||
|
||||
template <glm::length_t L, typename T>
|
||||
int run()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{ 8, 3, 6 },
|
||||
{ 7, 7, 7 }
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
glm::vec<L, T> const Result0 = glm::prevMultiple(glm::vec<L, T>(Data[i].Source), Data[i].Multiple);
|
||||
Error += glm::vec<L, T>(Data[i].Return) == Result0 ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const Result1 = glm::prevMultiple(glm::vec<L, T>(Data[i].Source), glm::vec<L, T>(Data[i].Multiple));
|
||||
Error += glm::vec<L, T>(Data[i].Return) == Result1 ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<1, glm::int8>();
|
||||
Error += run<2, glm::int8>();
|
||||
Error += run<3, glm::int8>();
|
||||
Error += run<4, glm::int8>();
|
||||
|
||||
Error += run<1, glm::int16>();
|
||||
Error += run<2, glm::int16>();
|
||||
Error += run<3, glm::int16>();
|
||||
Error += run<4, glm::int16>();
|
||||
|
||||
Error += run<1, glm::int32>();
|
||||
Error += run<2, glm::int32>();
|
||||
Error += run<3, glm::int32>();
|
||||
Error += run<4, glm::int32>();
|
||||
|
||||
Error += run<1, glm::int64>();
|
||||
Error += run<2, glm::int64>();
|
||||
Error += run<3, glm::int64>();
|
||||
Error += run<4, glm::int64>();
|
||||
|
||||
Error += run<1, glm::uint8>();
|
||||
Error += run<2, glm::uint8>();
|
||||
Error += run<3, glm::uint8>();
|
||||
Error += run<4, glm::uint8>();
|
||||
|
||||
Error += run<1, glm::uint16>();
|
||||
Error += run<2, glm::uint16>();
|
||||
Error += run<3, glm::uint16>();
|
||||
Error += run<4, glm::uint16>();
|
||||
|
||||
Error += run<1, glm::uint32>();
|
||||
Error += run<2, glm::uint32>();
|
||||
Error += run<3, glm::uint32>();
|
||||
Error += run<4, glm::uint32>();
|
||||
|
||||
Error += run<1, glm::uint64>();
|
||||
Error += run<2, glm::uint64>();
|
||||
Error += run<3, glm::uint64>();
|
||||
Error += run<4, glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace prevMultiple
|
||||
|
||||
namespace nextMultiple
|
||||
{
|
||||
template<typename genIUType>
|
||||
struct type
|
||||
{
|
||||
genIUType Source;
|
||||
genIUType Multiple;
|
||||
genIUType Return;
|
||||
};
|
||||
|
||||
template <glm::length_t L, typename T>
|
||||
int run()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{ 3, 4, 4 },
|
||||
{ 6, 3, 6 },
|
||||
{ 5, 3, 6 },
|
||||
{ 7, 7, 7 },
|
||||
{ 0, 1, 0 },
|
||||
{ 8, 3, 9 }
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
glm::vec<L, T> const Result0 = glm::nextMultiple(glm::vec<L, T>(Data[i].Source), glm::vec<L, T>(Data[i].Multiple));
|
||||
Error += glm::vec<L, T>(Data[i].Return) == Result0 ? 0 : 1;
|
||||
|
||||
glm::vec<L, T> const Result1 = glm::nextMultiple(glm::vec<L, T>(Data[i].Source), Data[i].Multiple);
|
||||
Error += glm::vec<L, T>(Data[i].Return) == Result1 ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<1, glm::int8>();
|
||||
Error += run<2, glm::int8>();
|
||||
Error += run<3, glm::int8>();
|
||||
Error += run<4, glm::int8>();
|
||||
|
||||
Error += run<1, glm::int16>();
|
||||
Error += run<2, glm::int16>();
|
||||
Error += run<3, glm::int16>();
|
||||
Error += run<4, glm::int16>();
|
||||
|
||||
Error += run<1, glm::int32>();
|
||||
Error += run<2, glm::int32>();
|
||||
Error += run<3, glm::int32>();
|
||||
Error += run<4, glm::int32>();
|
||||
|
||||
Error += run<1, glm::int64>();
|
||||
Error += run<2, glm::int64>();
|
||||
Error += run<3, glm::int64>();
|
||||
Error += run<4, glm::int64>();
|
||||
|
||||
Error += run<1, glm::uint8>();
|
||||
Error += run<2, glm::uint8>();
|
||||
Error += run<3, glm::uint8>();
|
||||
Error += run<4, glm::uint8>();
|
||||
|
||||
Error += run<1, glm::uint16>();
|
||||
Error += run<2, glm::uint16>();
|
||||
Error += run<3, glm::uint16>();
|
||||
Error += run<4, glm::uint16>();
|
||||
|
||||
Error += run<1, glm::uint32>();
|
||||
Error += run<2, glm::uint32>();
|
||||
Error += run<3, glm::uint32>();
|
||||
Error += run<4, glm::uint32>();
|
||||
|
||||
Error += run<1, glm::uint64>();
|
||||
Error += run<2, glm::uint64>();
|
||||
Error += run<3, glm::uint64>();
|
||||
Error += run<4, glm::uint64>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace nextMultiple
|
||||
|
||||
namespace findNSB
|
||||
{
|
||||
template<typename T>
|
||||
struct type
|
||||
{
|
||||
T Source;
|
||||
int SignificantBitCount;
|
||||
int Return;
|
||||
};
|
||||
|
||||
template <glm::length_t L, typename T>
|
||||
int run()
|
||||
{
|
||||
type<T> const Data[] =
|
||||
{
|
||||
{ 0x00, 1,-1 },
|
||||
{ 0x01, 2,-1 },
|
||||
{ 0x02, 2,-1 },
|
||||
{ 0x06, 3,-1 },
|
||||
{ 0x01, 1, 0 },
|
||||
{ 0x03, 1, 0 },
|
||||
{ 0x03, 2, 1 },
|
||||
{ 0x07, 2, 1 },
|
||||
{ 0x05, 2, 2 },
|
||||
{ 0x0D, 2, 2 }
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
|
||||
for (std::size_t i = 0, n = sizeof(Data) / sizeof(type<T>); i < n; ++i)
|
||||
{
|
||||
glm::vec<L, int> const Result0 = glm::findNSB<L, T, glm::defaultp>(glm::vec<L, T>(Data[i].Source), glm::vec<L, int>(Data[i].SignificantBitCount));
|
||||
Error += glm::vec<L, int>(Data[i].Return) == Result0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += run<1, glm::uint8>();
|
||||
Error += run<2, glm::uint8>();
|
||||
Error += run<3, glm::uint8>();
|
||||
Error += run<4, glm::uint8>();
|
||||
|
||||
Error += run<1, glm::uint16>();
|
||||
Error += run<2, glm::uint16>();
|
||||
Error += run<3, glm::uint16>();
|
||||
Error += run<4, glm::uint16>();
|
||||
|
||||
Error += run<1, glm::uint32>();
|
||||
Error += run<2, glm::uint32>();
|
||||
Error += run<3, glm::uint32>();
|
||||
Error += run<4, glm::uint32>();
|
||||
|
||||
Error += run<1, glm::uint64>();
|
||||
Error += run<2, glm::uint64>();
|
||||
Error += run<3, glm::uint64>();
|
||||
Error += run<4, glm::uint64>();
|
||||
|
||||
Error += run<1, glm::int8>();
|
||||
Error += run<2, glm::int8>();
|
||||
Error += run<3, glm::int8>();
|
||||
Error += run<4, glm::int8>();
|
||||
|
||||
Error += run<1, glm::int16>();
|
||||
Error += run<2, glm::int16>();
|
||||
Error += run<3, glm::int16>();
|
||||
Error += run<4, glm::int16>();
|
||||
|
||||
Error += run<1, glm::int32>();
|
||||
Error += run<2, glm::int32>();
|
||||
Error += run<3, glm::int32>();
|
||||
Error += run<4, glm::int32>();
|
||||
|
||||
Error += run<1, glm::int64>();
|
||||
Error += run<2, glm::int64>();
|
||||
Error += run<3, glm::int64>();
|
||||
Error += run<4, glm::int64>();
|
||||
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace findNSB
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += isPowerOfTwo::test();
|
||||
Error += prevPowerOfTwo::test();
|
||||
Error += nextPowerOfTwo::test();
|
||||
Error += prevMultiple::test();
|
||||
Error += nextMultiple::test();
|
||||
Error += findNSB::test();
|
||||
|
||||
return Error;
|
||||
}
|
||||
206
lib/glm/test/ext/ext_vector_integer_sized.cpp
Normal file
206
lib/glm/test/ext/ext_vector_integer_sized.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#include <glm/ext/vector_integer.hpp>
|
||||
#include <glm/ext/vector_int1.hpp>
|
||||
#include <glm/ext/vector_int1_precision.hpp>
|
||||
#include <glm/ext/vector_uint1.hpp>
|
||||
#include <glm/ext/vector_uint1_precision.hpp>
|
||||
|
||||
template <typename genType>
|
||||
static int test_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
|
||||
bool const R = A != B;
|
||||
bool const S = A == B;
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
|
||||
genType const C = A + B;
|
||||
Error += C == genType(2) ? 0 : 1;
|
||||
|
||||
genType const D = A - B;
|
||||
Error += D == genType(0) ? 0 : 1;
|
||||
|
||||
genType const E = A * B;
|
||||
Error += E == genType(1) ? 0 : 1;
|
||||
|
||||
genType const F = A / B;
|
||||
Error += F == genType(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
genType const A(3);
|
||||
genType const B(2);
|
||||
|
||||
genType const C = A % B;
|
||||
Error += C == genType(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
genType const C(0);
|
||||
|
||||
genType const I = A & B;
|
||||
Error += I == genType(1) ? 0 : 1;
|
||||
genType const D = A & C;
|
||||
Error += D == genType(0) ? 0 : 1;
|
||||
|
||||
genType const E = A | B;
|
||||
Error += E == genType(1) ? 0 : 1;
|
||||
genType const F = A | C;
|
||||
Error += F == genType(1) ? 0 : 1;
|
||||
|
||||
genType const G = A ^ B;
|
||||
Error += G == genType(0) ? 0 : 1;
|
||||
genType const H = A ^ C;
|
||||
Error += H == genType(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
genType const A(0);
|
||||
genType const B(1);
|
||||
genType const C(2);
|
||||
|
||||
genType const D = B << B;
|
||||
Error += D == genType(2) ? 0 : 1;
|
||||
genType const E = C >> B;
|
||||
Error += E == genType(1) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_ctor()
|
||||
{
|
||||
typedef typename genType::value_type T;
|
||||
|
||||
int Error = 0;
|
||||
|
||||
genType const A = genType(1);
|
||||
|
||||
genType const E(genType(1));
|
||||
Error += A == E ? 0 : 1;
|
||||
|
||||
genType const F(E);
|
||||
Error += A == F ? 0 : 1;
|
||||
|
||||
genType const B = genType(1);
|
||||
genType const G(glm::vec<2, T>(1));
|
||||
Error += B == G ? 0 : 1;
|
||||
|
||||
genType const H(glm::vec<3, T>(1));
|
||||
Error += B == H ? 0 : 1;
|
||||
|
||||
genType const I(glm::vec<4, T>(1));
|
||||
Error += B == I ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_size()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += sizeof(typename genType::value_type) == sizeof(genType) ? 0 : 1;
|
||||
Error += genType().length() == 1 ? 0 : 1;
|
||||
Error += genType::length() == 1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_relational()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
genType const A(1);
|
||||
genType const B(1);
|
||||
genType const C(0);
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A != C ? 0 : 1;
|
||||
Error += all(equal(A, B)) ? 0 : 1;
|
||||
Error += any(notEqual(A, C)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType>
|
||||
static int test_constexpr()
|
||||
{
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
static_assert(genType::length() == 1, "GLM: Failed constexpr");
|
||||
static_assert(genType(1)[0] == 1, "GLM: Failed constexpr");
|
||||
static_assert(genType(1) == genType(1), "GLM: Failed constexpr");
|
||||
static_assert(genType(1) != genType(0), "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_operators<glm::ivec1>();
|
||||
Error += test_operators<glm::lowp_ivec1>();
|
||||
Error += test_operators<glm::mediump_ivec1>();
|
||||
Error += test_operators<glm::highp_ivec1>();
|
||||
|
||||
Error += test_ctor<glm::ivec1>();
|
||||
Error += test_ctor<glm::lowp_ivec1>();
|
||||
Error += test_ctor<glm::mediump_ivec1>();
|
||||
Error += test_ctor<glm::highp_ivec1>();
|
||||
|
||||
Error += test_size<glm::ivec1>();
|
||||
Error += test_size<glm::lowp_ivec1>();
|
||||
Error += test_size<glm::mediump_ivec1>();
|
||||
Error += test_size<glm::highp_ivec1>();
|
||||
|
||||
Error += test_relational<glm::ivec1>();
|
||||
Error += test_relational<glm::lowp_ivec1>();
|
||||
Error += test_relational<glm::mediump_ivec1>();
|
||||
Error += test_relational<glm::highp_ivec1>();
|
||||
|
||||
Error += test_constexpr<glm::ivec1>();
|
||||
Error += test_constexpr<glm::lowp_ivec1>();
|
||||
Error += test_constexpr<glm::mediump_ivec1>();
|
||||
Error += test_constexpr<glm::highp_ivec1>();
|
||||
|
||||
Error += test_operators<glm::uvec1>();
|
||||
Error += test_operators<glm::lowp_uvec1>();
|
||||
Error += test_operators<glm::mediump_uvec1>();
|
||||
Error += test_operators<glm::highp_uvec1>();
|
||||
|
||||
Error += test_ctor<glm::uvec1>();
|
||||
Error += test_ctor<glm::lowp_uvec1>();
|
||||
Error += test_ctor<glm::mediump_uvec1>();
|
||||
Error += test_ctor<glm::highp_uvec1>();
|
||||
|
||||
Error += test_size<glm::uvec1>();
|
||||
Error += test_size<glm::lowp_uvec1>();
|
||||
Error += test_size<glm::mediump_uvec1>();
|
||||
Error += test_size<glm::highp_uvec1>();
|
||||
|
||||
Error += test_relational<glm::uvec1>();
|
||||
Error += test_relational<glm::lowp_uvec1>();
|
||||
Error += test_relational<glm::mediump_uvec1>();
|
||||
Error += test_relational<glm::highp_uvec1>();
|
||||
|
||||
Error += test_constexpr<glm::uvec1>();
|
||||
Error += test_constexpr<glm::lowp_uvec1>();
|
||||
Error += test_constexpr<glm::mediump_uvec1>();
|
||||
Error += test_constexpr<glm::highp_uvec1>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
205
lib/glm/test/ext/ext_vector_relational.cpp
Normal file
205
lib/glm/test/ext/ext_vector_relational.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float1.hpp>
|
||||
#include <glm/ext/vector_float1_precision.hpp>
|
||||
#include <glm/ext/vector_float2.hpp>
|
||||
#include <glm/ext/vector_float2_precision.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext/vector_float3_precision.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_float4_precision.hpp>
|
||||
#include <glm/ext/vector_double1.hpp>
|
||||
#include <glm/ext/vector_double1_precision.hpp>
|
||||
#include <glm/ext/vector_double2.hpp>
|
||||
#include <glm/ext/vector_double2_precision.hpp>
|
||||
#include <glm/ext/vector_double3.hpp>
|
||||
#include <glm/ext/vector_double3_precision.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <glm/ext/vector_double4_precision.hpp>
|
||||
#include <glm/ext/vector_ulp.hpp>
|
||||
|
||||
template <typename vecType>
|
||||
static int test_equal()
|
||||
{
|
||||
typedef typename vecType::value_type valType;
|
||||
|
||||
valType const A = static_cast<valType>(1.01f);
|
||||
valType const B = static_cast<valType>(1.02f);
|
||||
valType const Epsilon1 = static_cast<valType>(0.1f);
|
||||
valType const Epsilon2 = static_cast<valType>(0.001f);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::equal(vecType(A), vecType(B), Epsilon1)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(vecType(A), vecType(B), vecType(Epsilon1))) ? 0 : 1;
|
||||
|
||||
Error += !glm::any(glm::equal(vecType(A), vecType(B), Epsilon2)) ? 0 : 1;
|
||||
Error += !glm::any(glm::equal(vecType(A), vecType(B), vecType(Epsilon2))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename vecType>
|
||||
static int test_notEqual()
|
||||
{
|
||||
typedef typename vecType::value_type valType;
|
||||
|
||||
valType const A = static_cast<valType>(1.01f);
|
||||
valType const B = static_cast<valType>(1.02f);
|
||||
valType const Epsilon1 = static_cast<valType>(0.1f);
|
||||
valType const Epsilon2 = static_cast<valType>(0.001f);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::notEqual(vecType(A), vecType(B), Epsilon2)) ? 0 : 1;
|
||||
Error += glm::all(glm::notEqual(vecType(A), vecType(B), vecType(Epsilon2))) ? 0 : 1;
|
||||
|
||||
Error += !glm::any(glm::notEqual(vecType(A), vecType(B), Epsilon1)) ? 0 : 1;
|
||||
Error += !glm::any(glm::notEqual(vecType(A), vecType(B), vecType(Epsilon1))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename genType, typename valType>
|
||||
static int test_constexpr()
|
||||
{
|
||||
# if GLM_CONFIG_CONSTEXP == GLM_ENABLE
|
||||
static_assert(glm::all(glm::equal(genType(static_cast<valType>(1.01f)), genType(static_cast<valType>(1.02f)), static_cast<valType>(0.1f))), "GLM: Failed constexpr");
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_equal_ulps()
|
||||
{
|
||||
typedef glm::vec<4, T, glm::defaultp> vec4;
|
||||
|
||||
T const One(1);
|
||||
vec4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::nextFloat(One);
|
||||
Error += glm::all(glm::equal(Ones, vec4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += !glm::all(glm::equal(Ones, vec4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prevFloat(One);
|
||||
Error += glm::all(glm::equal(Ones, vec4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += !glm::all(glm::equal(Ones, vec4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static int test_notEqual_ulps()
|
||||
{
|
||||
typedef glm::vec<4, T, glm::defaultp> vec4;
|
||||
|
||||
T const One(1);
|
||||
vec4 const Ones(1);
|
||||
|
||||
int Error = 0;
|
||||
|
||||
T const ULP1Plus = glm::nextFloat(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Plus = glm::nextFloat(ULP1Plus);
|
||||
Error += glm::all(glm::notEqual(Ones, vec4(ULP2Plus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP1Minus = glm::prevFloat(One);
|
||||
Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Minus), 1)) ? 0 : 1;
|
||||
|
||||
T const ULP2Minus = glm::prevFloat(ULP1Minus);
|
||||
Error += glm::all(glm::notEqual(Ones, vec4(ULP2Minus), 1)) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_equal_ulps<float>();
|
||||
Error += test_equal_ulps<double>();
|
||||
Error += test_notEqual_ulps<float>();
|
||||
Error += test_notEqual_ulps<double>();
|
||||
|
||||
Error += test_equal<glm::vec1>();
|
||||
Error += test_equal<glm::lowp_vec1>();
|
||||
Error += test_equal<glm::mediump_vec1>();
|
||||
Error += test_equal<glm::highp_vec1>();
|
||||
Error += test_equal<glm::vec2>();
|
||||
Error += test_equal<glm::lowp_vec2>();
|
||||
Error += test_equal<glm::mediump_vec2>();
|
||||
Error += test_equal<glm::highp_vec2>();
|
||||
Error += test_equal<glm::vec3>();
|
||||
Error += test_equal<glm::lowp_vec3>();
|
||||
Error += test_equal<glm::mediump_vec3>();
|
||||
Error += test_equal<glm::highp_vec3>();
|
||||
Error += test_equal<glm::vec4>();
|
||||
Error += test_equal<glm::lowp_vec4>();
|
||||
Error += test_equal<glm::mediump_vec4>();
|
||||
Error += test_equal<glm::highp_vec4>();
|
||||
|
||||
Error += test_equal<glm::dvec1>();
|
||||
Error += test_equal<glm::lowp_dvec1>();
|
||||
Error += test_equal<glm::mediump_dvec1>();
|
||||
Error += test_equal<glm::highp_dvec1>();
|
||||
Error += test_equal<glm::dvec2>();
|
||||
Error += test_equal<glm::lowp_dvec2>();
|
||||
Error += test_equal<glm::mediump_dvec2>();
|
||||
Error += test_equal<glm::highp_dvec2>();
|
||||
Error += test_equal<glm::dvec3>();
|
||||
Error += test_equal<glm::lowp_dvec3>();
|
||||
Error += test_equal<glm::mediump_dvec3>();
|
||||
Error += test_equal<glm::highp_dvec3>();
|
||||
Error += test_equal<glm::dvec4>();
|
||||
Error += test_equal<glm::lowp_dvec4>();
|
||||
Error += test_equal<glm::mediump_dvec4>();
|
||||
Error += test_equal<glm::highp_dvec4>();
|
||||
|
||||
Error += test_notEqual<glm::vec1>();
|
||||
Error += test_notEqual<glm::lowp_vec1>();
|
||||
Error += test_notEqual<glm::mediump_vec1>();
|
||||
Error += test_notEqual<glm::highp_vec1>();
|
||||
Error += test_notEqual<glm::vec2>();
|
||||
Error += test_notEqual<glm::lowp_vec2>();
|
||||
Error += test_notEqual<glm::mediump_vec2>();
|
||||
Error += test_notEqual<glm::highp_vec2>();
|
||||
Error += test_notEqual<glm::vec3>();
|
||||
Error += test_notEqual<glm::lowp_vec3>();
|
||||
Error += test_notEqual<glm::mediump_vec3>();
|
||||
Error += test_notEqual<glm::highp_vec3>();
|
||||
Error += test_notEqual<glm::vec4>();
|
||||
Error += test_notEqual<glm::lowp_vec4>();
|
||||
Error += test_notEqual<glm::mediump_vec4>();
|
||||
Error += test_notEqual<glm::highp_vec4>();
|
||||
|
||||
Error += test_notEqual<glm::dvec1>();
|
||||
Error += test_notEqual<glm::lowp_dvec1>();
|
||||
Error += test_notEqual<glm::mediump_dvec1>();
|
||||
Error += test_notEqual<glm::highp_dvec1>();
|
||||
Error += test_notEqual<glm::dvec2>();
|
||||
Error += test_notEqual<glm::lowp_dvec2>();
|
||||
Error += test_notEqual<glm::mediump_dvec2>();
|
||||
Error += test_notEqual<glm::highp_dvec2>();
|
||||
Error += test_notEqual<glm::dvec3>();
|
||||
Error += test_notEqual<glm::lowp_dvec3>();
|
||||
Error += test_notEqual<glm::mediump_dvec3>();
|
||||
Error += test_notEqual<glm::highp_dvec3>();
|
||||
Error += test_notEqual<glm::dvec4>();
|
||||
Error += test_notEqual<glm::lowp_dvec4>();
|
||||
Error += test_notEqual<glm::mediump_dvec4>();
|
||||
Error += test_notEqual<glm::highp_dvec4>();
|
||||
|
||||
Error += test_constexpr<glm::vec1, float>();
|
||||
Error += test_constexpr<glm::vec2, float>();
|
||||
Error += test_constexpr<glm::vec3, float>();
|
||||
Error += test_constexpr<glm::vec4, float>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
99
lib/glm/test/ext/ext_vector_ulp.cpp
Normal file
99
lib/glm/test/ext/ext_vector_ulp.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <glm/ext/vector_ulp.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <glm/ext/vector_double4.hpp>
|
||||
#include <glm/ext/vector_int4.hpp>
|
||||
|
||||
static int test_ulp_float_dist()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const A(1.0f);
|
||||
|
||||
glm::vec4 const B = glm::nextFloat(A);
|
||||
Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
|
||||
glm::vec4 const C = glm::prevFloat(B);
|
||||
Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
|
||||
|
||||
glm::ivec4 const D = glm::floatDistance(A, B);
|
||||
Error += D == glm::ivec4(1) ? 0 : 1;
|
||||
glm::ivec4 const E = glm::floatDistance(A, C);
|
||||
Error += E == glm::ivec4(0) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ulp_float_step()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::vec4 const A(1.0f);
|
||||
|
||||
for(int i = 10; i < 1000; i *= 10)
|
||||
{
|
||||
glm::vec4 const B = glm::nextFloat(A, i);
|
||||
Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
|
||||
glm::vec4 const C = glm::prevFloat(B, i);
|
||||
Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
|
||||
|
||||
glm::ivec4 const D = glm::floatDistance(A, B);
|
||||
Error += D == glm::ivec4(i) ? 0 : 1;
|
||||
glm::ivec4 const E = glm::floatDistance(A, C);
|
||||
Error += E == glm::ivec4(0) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ulp_double_dist()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::dvec4 const A(1.0);
|
||||
|
||||
glm::dvec4 const B = glm::nextFloat(A);
|
||||
Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
|
||||
glm::dvec4 const C = glm::prevFloat(B);
|
||||
Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
|
||||
|
||||
glm::ivec4 const D(glm::floatDistance(A, B));
|
||||
Error += D == glm::ivec4(1) ? 0 : 1;
|
||||
glm::ivec4 const E = glm::floatDistance(A, C);
|
||||
Error += E == glm::ivec4(0) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static int test_ulp_double_step()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::dvec4 const A(1.0);
|
||||
|
||||
for(int i = 10; i < 1000; i *= 10)
|
||||
{
|
||||
glm::dvec4 const B = glm::nextFloat(A, i);
|
||||
Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1;
|
||||
glm::dvec4 const C = glm::prevFloat(B, i);
|
||||
Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1;
|
||||
|
||||
glm::ivec4 const D(glm::floatDistance(A, B));
|
||||
Error += D == glm::ivec4(i) ? 0 : 1;
|
||||
glm::ivec4 const E(glm::floatDistance(A, C));
|
||||
Error += E == glm::ivec4(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;
|
||||
}
|
||||
6
lib/glm/test/glm.cppcheck
Normal file
6
lib/glm/test/glm.cppcheck
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="1">
|
||||
<includedir>
|
||||
<dir name="../glm"/>
|
||||
</includedir>
|
||||
</project>
|
||||
20
lib/glm/test/gtc/CMakeLists.txt
Normal file
20
lib/glm/test/gtc/CMakeLists.txt
Normal 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)
|
||||
936
lib/glm/test/gtc/gtc_bitfield.cpp
Normal file
936
lib/glm/test/gtc/gtc_bitfield.cpp
Normal file
@@ -0,0 +1,936 @@
|
||||
#include <glm/gtc/bitfield.hpp>
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/integer.hpp>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace mask
|
||||
{
|
||||
template<typename genType>
|
||||
struct type
|
||||
{
|
||||
genType Value;
|
||||
genType Return;
|
||||
};
|
||||
|
||||
inline int mask_zero(int Bits)
|
||||
{
|
||||
return ~((~0) << Bits);
|
||||
}
|
||||
|
||||
inline int mask_mix(int Bits)
|
||||
{
|
||||
return Bits >= sizeof(int) * 8 ? 0xffffffff : (static_cast<int>(1) << Bits) - static_cast<int>(1);
|
||||
}
|
||||
|
||||
inline int mask_half(int Bits)
|
||||
{
|
||||
// We do the shift in two steps because 1 << 32 on an int is undefined.
|
||||
|
||||
int const Half = Bits >> 1;
|
||||
int const Fill = ~0;
|
||||
int const ShiftHaft = (Fill << Half);
|
||||
int const Rest = Bits - Half;
|
||||
int const Reversed = ShiftHaft << Rest;
|
||||
|
||||
return ~Reversed;
|
||||
}
|
||||
|
||||
inline int mask_loop(int Bits)
|
||||
{
|
||||
int Mask = 0;
|
||||
for(int Bit = 0; Bit < Bits; ++Bit)
|
||||
Mask |= (static_cast<int>(1) << Bit);
|
||||
return Mask;
|
||||
}
|
||||
|
||||
int perf()
|
||||
{
|
||||
int const Count = 100000000;
|
||||
|
||||
std::clock_t Timestamp1 = std::clock();
|
||||
|
||||
{
|
||||
std::vector<int> Mask;
|
||||
Mask.resize(Count);
|
||||
for(int i = 0; i < Count; ++i)
|
||||
Mask[i] = mask_mix(i % 32);
|
||||
}
|
||||
|
||||
std::clock_t Timestamp2 = std::clock();
|
||||
|
||||
{
|
||||
std::vector<int> Mask;
|
||||
Mask.resize(Count);
|
||||
for(int i = 0; i < Count; ++i)
|
||||
Mask[i] = mask_loop(i % 32);
|
||||
}
|
||||
|
||||
std::clock_t Timestamp3 = std::clock();
|
||||
|
||||
{
|
||||
std::vector<int> Mask;
|
||||
Mask.resize(Count);
|
||||
for(int i = 0; i < Count; ++i)
|
||||
Mask[i] = glm::mask(i % 32);
|
||||
}
|
||||
|
||||
std::clock_t Timestamp4 = std::clock();
|
||||
|
||||
{
|
||||
std::vector<int> Mask;
|
||||
Mask.resize(Count);
|
||||
for(int i = 0; i < Count; ++i)
|
||||
Mask[i] = mask_zero(i % 32);
|
||||
}
|
||||
|
||||
std::clock_t Timestamp5 = std::clock();
|
||||
|
||||
{
|
||||
std::vector<int> Mask;
|
||||
Mask.resize(Count);
|
||||
for(int i = 0; i < Count; ++i)
|
||||
Mask[i] = mask_half(i % 32);
|
||||
}
|
||||
|
||||
std::clock_t Timestamp6 = std::clock();
|
||||
|
||||
std::clock_t TimeMix = Timestamp2 - Timestamp1;
|
||||
std::clock_t TimeLoop = Timestamp3 - Timestamp2;
|
||||
std::clock_t TimeDefault = Timestamp4 - Timestamp3;
|
||||
std::clock_t TimeZero = Timestamp5 - Timestamp4;
|
||||
std::clock_t TimeHalf = Timestamp6 - Timestamp5;
|
||||
|
||||
std::printf("mask[mix]: %d\n", static_cast<unsigned int>(TimeMix));
|
||||
std::printf("mask[loop]: %d\n", static_cast<unsigned int>(TimeLoop));
|
||||
std::printf("mask[default]: %d\n", static_cast<unsigned int>(TimeDefault));
|
||||
std::printf("mask[zero]: %d\n", static_cast<unsigned int>(TimeZero));
|
||||
std::printf("mask[half]: %d\n", static_cast<unsigned int>(TimeHalf));
|
||||
|
||||
return TimeDefault < TimeLoop ? 0 : 1;
|
||||
}
|
||||
|
||||
int test_uint()
|
||||
{
|
||||
type<glm::uint> const Data[] =
|
||||
{
|
||||
{ 0, 0x00000000},
|
||||
{ 1, 0x00000001},
|
||||
{ 2, 0x00000003},
|
||||
{ 3, 0x00000007},
|
||||
{31, 0x7fffffff},
|
||||
{32, 0xffffffff}
|
||||
};
|
||||
|
||||
int Error = 0;
|
||||
/* mask_zero is sadly not a correct code
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
|
||||
{
|
||||
int Result = mask_zero(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
*/
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
|
||||
{
|
||||
int Result = mask_mix(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
|
||||
{
|
||||
int Result = mask_half(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
|
||||
{
|
||||
int Result = mask_loop(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < sizeof(Data) / sizeof(type<int>); ++i)
|
||||
{
|
||||
int Result = glm::mask(Data[i].Value);
|
||||
Error += Data[i].Return == Result ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_uvec4()
|
||||
{
|
||||
type<glm::ivec4> const Data[] =
|
||||
{
|
||||
{glm::ivec4( 0), glm::ivec4(0x00000000)},
|
||||
{glm::ivec4( 1), glm::ivec4(0x00000001)},
|
||||
{glm::ivec4( 2), glm::ivec4(0x00000003)},
|
||||
{glm::ivec4( 3), glm::ivec4(0x00000007)},
|
||||
{glm::ivec4(31), glm::ivec4(0x7fffffff)},
|
||||
{glm::ivec4(32), glm::ivec4(0xffffffff)}
|
||||
};
|
||||
|
||||
int Error(0);
|
||||
|
||||
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::ivec4>); i < n; ++i)
|
||||
{
|
||||
glm::ivec4 Result = glm::mask(Data[i].Value);
|
||||
Error += glm::all(glm::equal(Data[i].Return, Result)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += test_uint();
|
||||
Error += test_uvec4();
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace mask
|
||||
|
||||
namespace bitfieldInterleave3
|
||||
{
|
||||
template<typename PARAM, typename RET>
|
||||
inline RET refBitfieldInterleave(PARAM x, PARAM y, PARAM z)
|
||||
{
|
||||
RET Result = 0;
|
||||
for(RET i = 0; i < sizeof(PARAM) * 8; ++i)
|
||||
{
|
||||
Result |= ((RET(x) & (RET(1U) << i)) << ((i << 1) + 0));
|
||||
Result |= ((RET(y) & (RET(1U) << i)) << ((i << 1) + 1));
|
||||
Result |= ((RET(z) & (RET(1U) << i)) << ((i << 1) + 2));
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::uint16 x_max = 1 << 11;
|
||||
glm::uint16 y_max = 1 << 11;
|
||||
glm::uint16 z_max = 1 << 11;
|
||||
|
||||
for(glm::uint16 z = 0; z < z_max; z += 27)
|
||||
for(glm::uint16 y = 0; y < y_max; y += 27)
|
||||
for(glm::uint16 x = 0; x < x_max; x += 27)
|
||||
{
|
||||
glm::uint64 ResultA = refBitfieldInterleave<glm::uint16, glm::uint64>(x, y, z);
|
||||
glm::uint64 ResultB = glm::bitfieldInterleave(x, y, z);
|
||||
Error += ResultA == ResultB ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}
|
||||
|
||||
namespace bitfieldInterleave4
|
||||
{
|
||||
template<typename PARAM, typename RET>
|
||||
inline RET loopBitfieldInterleave(PARAM x, PARAM y, PARAM z, PARAM w)
|
||||
{
|
||||
RET const v[4] = {x, y, z, w};
|
||||
RET Result = 0;
|
||||
for(RET i = 0; i < sizeof(PARAM) * 8; i++)
|
||||
{
|
||||
Result |= ((((v[0] >> i) & 1U)) << ((i << 2) + 0));
|
||||
Result |= ((((v[1] >> i) & 1U)) << ((i << 2) + 1));
|
||||
Result |= ((((v[2] >> i) & 1U)) << ((i << 2) + 2));
|
||||
Result |= ((((v[3] >> i) & 1U)) << ((i << 2) + 3));
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::uint16 x_max = 1 << 11;
|
||||
glm::uint16 y_max = 1 << 11;
|
||||
glm::uint16 z_max = 1 << 11;
|
||||
glm::uint16 w_max = 1 << 11;
|
||||
|
||||
for(glm::uint16 w = 0; w < w_max; w += 27)
|
||||
for(glm::uint16 z = 0; z < z_max; z += 27)
|
||||
for(glm::uint16 y = 0; y < y_max; y += 27)
|
||||
for(glm::uint16 x = 0; x < x_max; x += 27)
|
||||
{
|
||||
glm::uint64 ResultA = loopBitfieldInterleave<glm::uint16, glm::uint64>(x, y, z, w);
|
||||
glm::uint64 ResultB = glm::bitfieldInterleave(x, y, z, w);
|
||||
Error += ResultA == ResultB ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}
|
||||
|
||||
namespace bitfieldInterleave
|
||||
{
|
||||
inline glm::uint64 fastBitfieldInterleave(glm::uint32 x, glm::uint32 y)
|
||||
{
|
||||
glm::uint64 REG1;
|
||||
glm::uint64 REG2;
|
||||
|
||||
REG1 = x;
|
||||
REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
|
||||
REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
|
||||
|
||||
REG2 = y;
|
||||
REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
|
||||
REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
|
||||
|
||||
return REG1 | (REG2 << 1);
|
||||
}
|
||||
|
||||
inline glm::uint64 interleaveBitfieldInterleave(glm::uint32 x, glm::uint32 y)
|
||||
{
|
||||
glm::uint64 REG1;
|
||||
glm::uint64 REG2;
|
||||
|
||||
REG1 = x;
|
||||
REG2 = y;
|
||||
|
||||
REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
|
||||
REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
|
||||
REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
|
||||
REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
|
||||
REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
|
||||
|
||||
REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
|
||||
REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
|
||||
|
||||
return REG1 | (REG2 << 1);
|
||||
}
|
||||
/*
|
||||
inline glm::uint64 loopBitfieldInterleave(glm::uint32 x, glm::uint32 y)
|
||||
{
|
||||
static glm::uint64 const Mask[5] =
|
||||
{
|
||||
0x5555555555555555,
|
||||
0x3333333333333333,
|
||||
0x0F0F0F0F0F0F0F0F,
|
||||
0x00FF00FF00FF00FF,
|
||||
0x0000FFFF0000FFFF
|
||||
};
|
||||
|
||||
glm::uint64 REG1 = x;
|
||||
glm::uint64 REG2 = y;
|
||||
for(int i = 4; i >= 0; --i)
|
||||
{
|
||||
REG1 = ((REG1 << (1 << i)) | REG1) & Mask[i];
|
||||
REG2 = ((REG2 << (1 << i)) | REG2) & Mask[i];
|
||||
}
|
||||
|
||||
return REG1 | (REG2 << 1);
|
||||
}
|
||||
*/
|
||||
#if GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
inline glm::uint64 sseBitfieldInterleave(glm::uint32 x, glm::uint32 y)
|
||||
{
|
||||
__m128i const Array = _mm_set_epi32(0, y, 0, x);
|
||||
|
||||
__m128i const Mask4 = _mm_set1_epi32(0x0000FFFF);
|
||||
__m128i const Mask3 = _mm_set1_epi32(0x00FF00FF);
|
||||
__m128i const Mask2 = _mm_set1_epi32(0x0F0F0F0F);
|
||||
__m128i const Mask1 = _mm_set1_epi32(0x33333333);
|
||||
__m128i const Mask0 = _mm_set1_epi32(0x55555555);
|
||||
|
||||
__m128i Reg1;
|
||||
__m128i Reg2;
|
||||
|
||||
// REG1 = x;
|
||||
// REG2 = y;
|
||||
Reg1 = _mm_load_si128(&Array);
|
||||
|
||||
//REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
//REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
Reg2 = _mm_slli_si128(Reg1, 2);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask4);
|
||||
|
||||
//REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
//REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
Reg2 = _mm_slli_si128(Reg1, 1);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask3);
|
||||
|
||||
//REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
//REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 4);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask2);
|
||||
|
||||
//REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
|
||||
//REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 2);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask1);
|
||||
|
||||
//REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
|
||||
//REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 1);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask0);
|
||||
|
||||
//return REG1 | (REG2 << 1);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 1);
|
||||
Reg2 = _mm_srli_si128(Reg2, 8);
|
||||
Reg1 = _mm_or_si128(Reg1, Reg2);
|
||||
|
||||
__m128i Result;
|
||||
_mm_store_si128(&Result, Reg1);
|
||||
return *reinterpret_cast<glm::uint64*>(&Result);
|
||||
}
|
||||
|
||||
inline glm::uint64 sseUnalignedBitfieldInterleave(glm::uint32 x, glm::uint32 y)
|
||||
{
|
||||
__m128i const Array = _mm_set_epi32(0, y, 0, x);
|
||||
|
||||
__m128i const Mask4 = _mm_set1_epi32(0x0000FFFF);
|
||||
__m128i const Mask3 = _mm_set1_epi32(0x00FF00FF);
|
||||
__m128i const Mask2 = _mm_set1_epi32(0x0F0F0F0F);
|
||||
__m128i const Mask1 = _mm_set1_epi32(0x33333333);
|
||||
__m128i const Mask0 = _mm_set1_epi32(0x55555555);
|
||||
|
||||
__m128i Reg1;
|
||||
__m128i Reg2;
|
||||
|
||||
// REG1 = x;
|
||||
// REG2 = y;
|
||||
Reg1 = _mm_loadu_si128(&Array);
|
||||
|
||||
//REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
//REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFF);
|
||||
Reg2 = _mm_slli_si128(Reg1, 2);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask4);
|
||||
|
||||
//REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
//REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FF);
|
||||
Reg2 = _mm_slli_si128(Reg1, 1);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask3);
|
||||
|
||||
//REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
//REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0F);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 4);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask2);
|
||||
|
||||
//REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333);
|
||||
//REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 2);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask1);
|
||||
|
||||
//REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555);
|
||||
//REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 1);
|
||||
Reg1 = _mm_or_si128(Reg2, Reg1);
|
||||
Reg1 = _mm_and_si128(Reg1, Mask0);
|
||||
|
||||
//return REG1 | (REG2 << 1);
|
||||
Reg2 = _mm_slli_epi32(Reg1, 1);
|
||||
Reg2 = _mm_srli_si128(Reg2, 8);
|
||||
Reg1 = _mm_or_si128(Reg1, Reg2);
|
||||
|
||||
__m128i Result;
|
||||
_mm_store_si128(&Result, Reg1);
|
||||
return *reinterpret_cast<glm::uint64*>(&Result);
|
||||
}
|
||||
#endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
/*
|
||||
{
|
||||
for(glm::uint32 y = 0; y < (1 << 10); ++y)
|
||||
for(glm::uint32 x = 0; x < (1 << 10); ++x)
|
||||
{
|
||||
glm::uint64 A = glm::bitfieldInterleave(x, y);
|
||||
glm::uint64 B = fastBitfieldInterleave(x, y);
|
||||
//glm::uint64 C = loopBitfieldInterleave(x, y);
|
||||
glm::uint64 D = interleaveBitfieldInterleave(x, y);
|
||||
|
||||
assert(A == B);
|
||||
//assert(A == C);
|
||||
assert(A == D);
|
||||
|
||||
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
glm::uint64 E = sseBitfieldInterleave(x, y);
|
||||
glm::uint64 F = sseUnalignedBitfieldInterleave(x, y);
|
||||
assert(A == E);
|
||||
assert(A == F);
|
||||
|
||||
__m128i G = glm_i128_interleave(_mm_set_epi32(0, y, 0, x));
|
||||
glm::uint64 Result[2];
|
||||
_mm_storeu_si128((__m128i*)Result, G);
|
||||
assert(A == Result[0]);
|
||||
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
}
|
||||
}
|
||||
*/
|
||||
{
|
||||
for(glm::uint8 y = 0; y < 127; ++y)
|
||||
for(glm::uint8 x = 0; x < 127; ++x)
|
||||
{
|
||||
glm::uint64 A(glm::bitfieldInterleave(glm::u8vec2(x, y)));
|
||||
glm::uint64 B(glm::bitfieldInterleave(glm::u16vec2(x, y)));
|
||||
glm::uint64 C(glm::bitfieldInterleave(glm::u32vec2(x, y)));
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
|
||||
glm::u32vec2 const& D = glm::bitfieldDeinterleave(C);
|
||||
Error += D.x == x ? 0 : 1;
|
||||
Error += D.y == y ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
for(glm::uint8 y = 0; y < 127; ++y)
|
||||
for(glm::uint8 x = 0; x < 127; ++x)
|
||||
{
|
||||
glm::int64 A(glm::bitfieldInterleave(glm::int8(x), glm::int8(y)));
|
||||
glm::int64 B(glm::bitfieldInterleave(glm::int16(x), glm::int16(y)));
|
||||
glm::int64 C(glm::bitfieldInterleave(glm::int32(x), glm::int32(y)));
|
||||
|
||||
Error += A == B ? 0 : 1;
|
||||
Error += A == C ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf()
|
||||
{
|
||||
glm::uint32 x_max = 1 << 11;
|
||||
glm::uint32 y_max = 1 << 10;
|
||||
|
||||
// ALU
|
||||
std::vector<glm::uint64> Data(x_max * y_max);
|
||||
std::vector<glm::u32vec2> Param(x_max * y_max);
|
||||
for(glm::uint32 i = 0; i < Param.size(); ++i)
|
||||
Param[i] = glm::u32vec2(i % x_max, i / y_max);
|
||||
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = glm::bitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("glm::bitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = fastBitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("fastBitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
/*
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = loopBitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("loopBitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
*/
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = interleaveBitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("interleaveBitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
|
||||
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = sseBitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("sseBitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = sseUnalignedBitfieldInterleave(Param[i].x, Param[i].y);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("sseUnalignedBitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
|
||||
{
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < Data.size(); ++i)
|
||||
Data[i] = glm::bitfieldInterleave(Param[i].x, Param[i].y, Param[i].x);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("glm::detail::bitfieldInterleave Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
|
||||
# if(GLM_ARCH & GLM_ARCH_SSE2_BIT && !(GLM_COMPILER & GLM_COMPILER_GCC))
|
||||
{
|
||||
// SIMD
|
||||
std::vector<__m128i> SimdData;
|
||||
SimdData.resize(static_cast<std::size_t>(x_max * y_max));
|
||||
std::vector<__m128i> SimdParam;
|
||||
SimdParam.resize(static_cast<std::size_t>(x_max * y_max));
|
||||
for(std::size_t i = 0; i < SimdParam.size(); ++i)
|
||||
SimdParam[i] = _mm_set_epi32(static_cast<int>(i % static_cast<std::size_t>(x_max)), 0, static_cast<int>(i / static_cast<std::size_t>(y_max)), 0);
|
||||
|
||||
std::clock_t LastTime = std::clock();
|
||||
|
||||
for(std::size_t i = 0; i < SimdData.size(); ++i)
|
||||
SimdData[i] = glm_i128_interleave(SimdParam[i]);
|
||||
|
||||
std::clock_t Time = std::clock() - LastTime;
|
||||
|
||||
std::printf("_mm_bit_interleave_si128 Time %d clocks\n", static_cast<int>(Time));
|
||||
}
|
||||
# endif//GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||
|
||||
return 0;
|
||||
}
|
||||
}//namespace bitfieldInterleave
|
||||
|
||||
namespace bitfieldInterleave5
|
||||
{
|
||||
GLM_FUNC_QUALIFIER glm::uint16 bitfieldInterleave_u8vec2(glm::uint8 x, glm::uint8 y)
|
||||
{
|
||||
glm::uint32 Result = (glm::uint32(y) << 16) | glm::uint32(x);
|
||||
Result = ((Result << 4) | Result) & 0x0F0F0F0F;
|
||||
Result = ((Result << 2) | Result) & 0x33333333;
|
||||
Result = ((Result << 1) | Result) & 0x55555555;
|
||||
return static_cast<glm::uint16>((Result & 0x0000FFFF) | (Result >> 15));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::u8vec2 bitfieldDeinterleave_u8vec2(glm::uint16 InterleavedBitfield)
|
||||
{
|
||||
glm::uint32 Result(InterleavedBitfield);
|
||||
Result = ((Result << 15) | Result) & 0x55555555;
|
||||
Result = ((Result >> 1) | Result) & 0x33333333;
|
||||
Result = ((Result >> 2) | Result) & 0x0F0F0F0F;
|
||||
Result = ((Result >> 4) | Result) & 0x00FF00FF;
|
||||
return glm::u8vec2(Result & 0x0000FFFF, Result >> 16);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u8vec4(glm::uint8 x, glm::uint8 y, glm::uint8 z, glm::uint8 w)
|
||||
{
|
||||
glm::uint64 Result = (glm::uint64(w) << 48) | (glm::uint64(z) << 32) | (glm::uint64(y) << 16) | glm::uint64(x);
|
||||
Result = ((Result << 12) | Result) & 0x000F000F000F000Full;
|
||||
Result = ((Result << 6) | Result) & 0x0303030303030303ull;
|
||||
Result = ((Result << 3) | Result) & 0x1111111111111111ull;
|
||||
|
||||
const glm::uint32 a = static_cast<glm::uint32>((Result & 0x000000000000FFFF) >> ( 0 - 0));
|
||||
const glm::uint32 b = static_cast<glm::uint32>((Result & 0x00000000FFFF0000) >> (16 - 3));
|
||||
const glm::uint32 c = static_cast<glm::uint32>((Result & 0x0000FFFF00000000) >> (32 - 6));
|
||||
const glm::uint32 d = static_cast<glm::uint32>((Result & 0xFFFF000000000000) >> (48 - 12));
|
||||
|
||||
return a | b | c | d;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::u8vec4 bitfieldDeinterleave_u8vec4(glm::uint32 InterleavedBitfield)
|
||||
{
|
||||
glm::uint64 Result(InterleavedBitfield);
|
||||
Result = ((Result << 15) | Result) & 0x9249249249249249ull;
|
||||
Result = ((Result >> 1) | Result) & 0x30C30C30C30C30C3ull;
|
||||
Result = ((Result >> 2) | Result) & 0xF00F00F00F00F00Full;
|
||||
Result = ((Result >> 4) | Result) & 0x00FF0000FF0000FFull;
|
||||
return glm::u8vec4(
|
||||
(Result >> 0) & 0x000000000000FFFFull,
|
||||
(Result >> 16) & 0x00000000FFFF0000ull,
|
||||
(Result >> 32) & 0x0000FFFF00000000ull,
|
||||
(Result >> 48) & 0xFFFF000000000000ull);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave_u16vec2(glm::uint16 x, glm::uint16 y)
|
||||
{
|
||||
glm::uint64 Result = (glm::uint64(y) << 32) | glm::uint64(x);
|
||||
Result = ((Result << 8) | Result) & static_cast<glm::uint32>(0x00FF00FF00FF00FFull);
|
||||
Result = ((Result << 4) | Result) & static_cast<glm::uint32>(0x0F0F0F0F0F0F0F0Full);
|
||||
Result = ((Result << 2) | Result) & static_cast<glm::uint32>(0x3333333333333333ull);
|
||||
Result = ((Result << 1) | Result) & static_cast<glm::uint32>(0x5555555555555555ull);
|
||||
return static_cast<glm::uint32>((Result & 0x00000000FFFFFFFFull) | (Result >> 31));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::u16vec2 bitfieldDeinterleave_u16vec2(glm::uint32 InterleavedBitfield)
|
||||
{
|
||||
glm::uint64 Result(InterleavedBitfield);
|
||||
Result = ((Result << 31) | Result) & 0x5555555555555555ull;
|
||||
Result = ((Result >> 1) | Result) & 0x3333333333333333ull;
|
||||
Result = ((Result >> 2) | Result) & 0x0F0F0F0F0F0F0F0Full;
|
||||
Result = ((Result >> 4) | Result) & 0x00FF00FF00FF00FFull;
|
||||
Result = ((Result >> 8) | Result) & 0x0000FFFF0000FFFFull;
|
||||
return glm::u16vec2(Result & 0x00000000FFFFFFFFull, Result >> 32);
|
||||
}
|
||||
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
{
|
||||
glm::uint16 A = bitfieldInterleave_u8vec2(glm::uint8(i), glm::uint8(j));
|
||||
glm::uint16 B = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j));
|
||||
Error += A == B ? 0 : 1;
|
||||
|
||||
glm::u8vec2 C = bitfieldDeinterleave_u8vec2(A);
|
||||
Error += C.x == glm::uint8(i) ? 0 : 1;
|
||||
Error += C.y == glm::uint8(j) ? 0 : 1;
|
||||
}
|
||||
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
{
|
||||
glm::uint32 A = bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||
glm::uint32 B = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||
Error += A == B ? 0 : 1;
|
||||
/*
|
||||
glm::u8vec4 C = bitfieldDeinterleave_u8vec4(A);
|
||||
Error += C.x == glm::uint8(i) ? 0 : 1;
|
||||
Error += C.y == glm::uint8(j) ? 0 : 1;
|
||||
Error += C.z == glm::uint8(i) ? 0 : 1;
|
||||
Error += C.w == glm::uint8(j) ? 0 : 1;
|
||||
*/
|
||||
}
|
||||
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
{
|
||||
glm::uint32 A = bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j));
|
||||
glm::uint32 B = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
|
||||
Error += A == B ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_old_u8vec2(std::vector<glm::uint16>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("glm::bitfieldInterleave<u8vec2> Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_new_u8vec2(std::vector<glm::uint16>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == bitfieldInterleave_u8vec2(glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("bitfieldInterleave_u8vec2 Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_old_u8vec4(std::vector<glm::uint32>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("glm::bitfieldInterleave<u8vec4> Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_new_u8vec4(std::vector<glm::uint32>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == bitfieldInterleave_u8vec4(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("bitfieldInterleave_u8vec4 Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_old_u16vec2(std::vector<glm::uint32>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("glm::bitfieldInterleave<u16vec2> Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf_new_u16vec2(std::vector<glm::uint32>& Result)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
const std::clock_t BeginTime = std::clock();
|
||||
|
||||
for(glm::size_t k = 0; k < 10000; ++k)
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Error += Result[j * 256 + i] == bitfieldInterleave_u16vec2(glm::uint16(i), glm::uint16(j)) ? 0 : 1;
|
||||
|
||||
const std::clock_t EndTime = std::clock();
|
||||
|
||||
std::printf("bitfieldInterleave_u16vec2 Time %d clocks\n", static_cast<int>(EndTime - BeginTime));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::printf("bitfieldInterleave perf: init\r");
|
||||
|
||||
std::vector<glm::uint16> Result_u8vec2(256 * 256, 0);
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Result_u8vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j));
|
||||
|
||||
Error += perf_old_u8vec2(Result_u8vec2);
|
||||
Error += perf_new_u8vec2(Result_u8vec2);
|
||||
|
||||
std::vector<glm::uint32> Result_u8vec4(256 * 256, 0);
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Result_u8vec4[j * 256 + i] = glm::bitfieldInterleave(glm::uint8(i), glm::uint8(j), glm::uint8(i), glm::uint8(j));
|
||||
|
||||
Error += perf_old_u8vec4(Result_u8vec4);
|
||||
Error += perf_new_u8vec4(Result_u8vec4);
|
||||
|
||||
std::vector<glm::uint32> Result_u16vec2(256 * 256, 0);
|
||||
for(glm::size_t j = 0; j < 256; ++j)
|
||||
for(glm::size_t i = 0; i < 256; ++i)
|
||||
Result_u16vec2[j * 256 + i] = glm::bitfieldInterleave(glm::uint16(i), glm::uint16(j));
|
||||
|
||||
Error += perf_old_u16vec2(Result_u16vec2);
|
||||
Error += perf_new_u16vec2(Result_u16vec2);
|
||||
|
||||
std::printf("bitfieldInterleave perf: %d Errors\n", Error);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
}//namespace bitfieldInterleave5
|
||||
|
||||
static int test_bitfieldRotateRight()
|
||||
{
|
||||
glm::ivec4 const A = glm::bitfieldRotateRight(glm::ivec4(2), 1);
|
||||
glm::ivec4 const B = glm::ivec4(2) >> 1;
|
||||
|
||||
return A == B;
|
||||
}
|
||||
|
||||
static int test_bitfieldRotateLeft()
|
||||
{
|
||||
glm::ivec4 const A = glm::bitfieldRotateLeft(glm::ivec4(2), 1);
|
||||
glm::ivec4 const B = glm::ivec4(2) << 1;
|
||||
|
||||
return A == B;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
/* Tests for a faster and to reserve bitfieldInterleave
|
||||
Error += ::bitfieldInterleave5::test();
|
||||
Error += ::bitfieldInterleave5::perf();
|
||||
*/
|
||||
Error += ::mask::test();
|
||||
Error += ::bitfieldInterleave3::test();
|
||||
Error += ::bitfieldInterleave4::test();
|
||||
Error += ::bitfieldInterleave::test();
|
||||
|
||||
Error += test_bitfieldRotateRight();
|
||||
Error += test_bitfieldRotateLeft();
|
||||
|
||||
# ifdef NDEBUG
|
||||
Error += ::mask::perf();
|
||||
Error += ::bitfieldInterleave::perf();
|
||||
# endif//NDEBUG
|
||||
|
||||
return Error;
|
||||
}
|
||||
78
lib/glm/test/gtc/gtc_color_space.cpp
Normal file
78
lib/glm/test/gtc/gtc_color_space.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <glm/gtc/color_space.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
namespace srgb
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
|
||||
|
||||
{
|
||||
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB);
|
||||
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
|
||||
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
|
||||
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
|
||||
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
|
||||
|
||||
{
|
||||
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
|
||||
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
|
||||
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
|
||||
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
|
||||
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
glm::vec4 const ColorSourceGNI = glm::vec4(107, 107, 104, 131) / glm::vec4(255);
|
||||
|
||||
{
|
||||
glm::vec4 const ColorGNA = glm::convertSRGBToLinear(ColorSourceGNI) * glm::vec4(255);
|
||||
glm::vec4 const ColorGNE = glm::convertLinearToSRGB(ColorSourceGNI) * 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
|
||||
{
|
||||
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
lib/glm/test/gtc/gtc_constants.cpp
Normal file
30
lib/glm/test/gtc/gtc_constants.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
int test_epsilon()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float Test = glm::epsilon<float>();
|
||||
Error += Test > 0.0f ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
double Test = glm::epsilon<double>();
|
||||
Error += Test > 0.0 ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
//float MinHalf = 0.0f;
|
||||
//while (glm::half(MinHalf) == glm::half(0.0f))
|
||||
// MinHalf += std::numeric_limits<float>::epsilon();
|
||||
Error += test_epsilon();
|
||||
|
||||
return Error;
|
||||
}
|
||||
78
lib/glm/test/gtc/gtc_epsilon.cpp
Normal file
78
lib/glm/test/gtc/gtc_epsilon.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
|
||||
int test_defined()
|
||||
{
|
||||
glm::epsilonEqual(glm::vec2(), glm::vec2(), glm::vec2());
|
||||
glm::epsilonEqual(glm::vec3(), glm::vec3(), glm::vec3());
|
||||
glm::epsilonEqual(glm::vec4(), glm::vec4(), glm::vec4());
|
||||
|
||||
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), glm::vec2());
|
||||
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), glm::vec3());
|
||||
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), glm::vec4());
|
||||
|
||||
glm::epsilonEqual(glm::vec2(), glm::vec2(), 0.0f);
|
||||
glm::epsilonEqual(glm::vec3(), glm::vec3(), 0.0f);
|
||||
glm::epsilonEqual(glm::vec4(), glm::vec4(), 0.0f);
|
||||
glm::epsilonEqual(glm::quat(), glm::quat(), 0.0f);
|
||||
|
||||
glm::epsilonNotEqual(glm::vec2(), glm::vec2(), 0.0f);
|
||||
glm::epsilonNotEqual(glm::vec3(), glm::vec3(), 0.0f);
|
||||
glm::epsilonNotEqual(glm::vec4(), glm::vec4(), 0.0f);
|
||||
glm::epsilonNotEqual(glm::quat(), glm::quat(), 0.0f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int test_equal()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
{
|
||||
T A = glm::epsilon<T>();
|
||||
T B = glm::epsilon<T>();
|
||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
T A(0);
|
||||
T B = static_cast<T>(0) + glm::epsilon<T>();
|
||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
T A(0);
|
||||
T B = static_cast<T>(0) - glm::epsilon<T>();
|
||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
T A = static_cast<T>(0) + glm::epsilon<T>();
|
||||
T B = static_cast<T>(0);
|
||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
T A = static_cast<T>(0) - glm::epsilon<T>();
|
||||
T B = static_cast<T>(0);
|
||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += test_defined();
|
||||
Error += test_equal<float>();
|
||||
Error += test_equal<double>();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
|
||||
233
lib/glm/test/gtc/gtc_integer.cpp
Normal file
233
lib/glm/test/gtc/gtc_integer.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#define GLM_FORCE_INLINE
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/integer.hpp>
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <glm/gtx/type_aligned.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
namespace log2_
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
int A0 = static_cast<int>(glm::log2(16.f));
|
||||
glm::ivec1 B0(glm::log2(glm::vec1(16.f)));
|
||||
glm::ivec2 C0(glm::log2(glm::vec2(16.f)));
|
||||
glm::ivec3 D0(glm::log2(glm::vec3(16.f)));
|
||||
glm::ivec4 E0(glm::log2(glm::vec4(16.f)));
|
||||
|
||||
int A1 = glm::log2(int(16));
|
||||
glm::ivec1 B1 = glm::log2(glm::ivec1(16));
|
||||
glm::ivec2 C1 = glm::log2(glm::ivec2(16));
|
||||
glm::ivec3 D1 = glm::log2(glm::ivec3(16));
|
||||
glm::ivec4 E1 = glm::log2(glm::ivec4(16));
|
||||
|
||||
Error += A0 == A1 ? 0 : 1;
|
||||
Error += glm::all(glm::equal(B0, B1)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(C0, C1)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(D0, D1)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(E0, E1)) ? 0 : 1;
|
||||
|
||||
glm::uint64 A2 = glm::log2(glm::uint64(16));
|
||||
glm::u64vec1 B2 = glm::log2(glm::u64vec1(16));
|
||||
glm::u64vec2 C2 = glm::log2(glm::u64vec2(16));
|
||||
glm::u64vec3 D2 = glm::log2(glm::u64vec3(16));
|
||||
glm::u64vec4 E2 = glm::log2(glm::u64vec4(16));
|
||||
|
||||
Error += A2 == glm::uint64(4) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(B2, glm::u64vec1(4))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(C2, glm::u64vec2(4))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(D2, glm::u64vec3(4))) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(E2, glm::u64vec4(4))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int perf(std::size_t Count)
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
std::vector<int> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(int i = 0; i < static_cast<int>(Count); ++i)
|
||||
Result[i] = glm::log2(static_cast<int>(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
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_HAS_BITSCAN_WINDOWS
|
||||
{
|
||||
std::vector<glm::ivec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
glm::vec<4, unsigned long, glm::defaultp> Tmp;
|
||||
_BitScanReverse(&Tmp.x, i);
|
||||
_BitScanReverse(&Tmp.y, i);
|
||||
_BitScanReverse(&Tmp.z, i);
|
||||
_BitScanReverse(&Tmp.w, i);
|
||||
Result[i] = glm::ivec4(Tmp);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
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();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
_BitScanReverse(&Result[i].x, i);
|
||||
_BitScanReverse(&Result[i].y, i);
|
||||
_BitScanReverse(&Result[i].z, i);
|
||||
_BitScanReverse(&Result[i].w, i);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
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();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
{
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].x), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].y), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].z), i);
|
||||
_BitScanReverse(reinterpret_cast<unsigned long*>(&Result[i].w), i);
|
||||
}
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
std::printf("glm::log2<ivec4> reinterpret: %d clocks\n", static_cast<int>(End - Begin));
|
||||
}
|
||||
# endif//GLM_HAS_BITSCAN_WINDOWS
|
||||
|
||||
{
|
||||
std::vector<float> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(std::size_t i = 0; i < Count; ++i)
|
||||
Result[i] = glm::log2(static_cast<float>(i));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
std::printf("glm::log2<float>: %d clocks\n", static_cast<int>(End - Begin));
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<glm::vec4> Result;
|
||||
Result.resize(Count);
|
||||
|
||||
std::clock_t Begin = clock();
|
||||
|
||||
for(int i = 0; i < static_cast<int>(Count); ++i)
|
||||
Result[i] = glm::log2(glm::vec4(static_cast<float>(i)));
|
||||
|
||||
std::clock_t End = clock();
|
||||
|
||||
std::printf("glm::log2<vec4>: %d clocks\n", static_cast<int>(End - Begin));
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace log2_
|
||||
|
||||
namespace iround
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
for(float f = 0.0f; f < 3.1f; f += 0.05f)
|
||||
{
|
||||
int RoundFast = static_cast<int>(glm::iround(f));
|
||||
int RoundSTD = static_cast<int>(glm::round(f));
|
||||
Error += RoundFast == RoundSTD ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace iround
|
||||
|
||||
namespace uround
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
for(float f = 0.0f; f < 3.1f; f += 0.05f)
|
||||
{
|
||||
int RoundFast = static_cast<int>(glm::uround(f));
|
||||
int RoundSTD = static_cast<int>(glm::round(f));
|
||||
Error += RoundFast == RoundSTD ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace uround
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += ::log2_::test();
|
||||
Error += ::iround::test();
|
||||
Error += ::uround::test();
|
||||
|
||||
# ifdef NDEBUG
|
||||
std::size_t const Samples(1000);
|
||||
Error += ::log2_::perf(Samples);
|
||||
# endif//NDEBUG
|
||||
|
||||
return Error;
|
||||
}
|
||||
383
lib/glm/test/gtc/gtc_matrix_access.cpp
Normal file
383
lib/glm/test/gtc/gtc_matrix_access.cpp
Normal 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>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
lib/glm/test/gtc/gtc_matrix_integer.cpp
Normal file
8
lib/glm/test/gtc/gtc_matrix_integer.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <glm/gtc/matrix_integer.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
return Error;
|
||||
}
|
||||
51
lib/glm/test/gtc/gtc_matrix_inverse.cpp
Normal file
51
lib/glm/test/gtc/gtc_matrix_inverse.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
|
||||
int test_affine()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::mat3 const M(
|
||||
2.f, 0.f, 0.f,
|
||||
0.f, 2.f, 0.f,
|
||||
0.f, 0.f, 1.f);
|
||||
glm::mat3 const A = glm::affineInverse(M);
|
||||
glm::mat3 const I = glm::inverse(M);
|
||||
glm::mat3 const R = glm::affineInverse(A);
|
||||
|
||||
for(glm::length_t i = 0; i < A.length(); ++i)
|
||||
{
|
||||
Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
glm::mat4 const M(
|
||||
2.f, 0.f, 0.f, 0.f,
|
||||
0.f, 2.f, 0.f, 0.f,
|
||||
0.f, 0.f, 2.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
glm::mat4 const A = glm::affineInverse(M);
|
||||
glm::mat4 const I = glm::inverse(M);
|
||||
glm::mat4 const R = glm::affineInverse(A);
|
||||
|
||||
for(glm::length_t i = 0; i < A.length(); ++i)
|
||||
{
|
||||
Error += glm::all(glm::epsilonEqual(M[i], R[i], 0.01f)) ? 0 : 1;
|
||||
Error += glm::all(glm::epsilonEqual(A[i], I[i], 0.01f)) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_affine();
|
||||
|
||||
return Error;
|
||||
}
|
||||
55
lib/glm/test/gtc/gtc_matrix_transform.cpp
Normal file
55
lib/glm/test/gtc/gtc_matrix_transform.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/ext/matrix_relational.hpp>
|
||||
|
||||
int test_perspective()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_pick()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4 Pick = glm::pickMatrix(glm::vec2(1, 2), glm::vec2(3, 4), glm::ivec4(0, 0, 320, 240));
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_tweakedInfinitePerspective()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::mat4 ProjectionA = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f);
|
||||
glm::mat4 ProjectionB = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f, 0.001f);
|
||||
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_translate()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::lowp_vec3 v(1.0);
|
||||
glm::lowp_mat4 m(0);
|
||||
glm::lowp_mat4 t = glm::translate(m, v);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_translate();
|
||||
Error += test_tweakedInfinitePerspective();
|
||||
Error += test_pick();
|
||||
Error += test_perspective();
|
||||
|
||||
return Error;
|
||||
}
|
||||
86
lib/glm/test/gtc/gtc_noise.cpp
Normal file
86
lib/glm/test/gtc/gtc_noise.cpp
Normal 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;
|
||||
}
|
||||
878
lib/glm/test/gtc/gtc_packing.cpp
Normal file
878
lib/glm/test/gtc/gtc_packing.cpp
Normal file
@@ -0,0 +1,878 @@
|
||||
#include <glm/packing.hpp>
|
||||
#include <glm/gtc/packing.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/ext/vector_relational.hpp>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
int test_Half1x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<float> Tests;
|
||||
Tests.push_back(0.0f);
|
||||
Tests.push_back(1.0f);
|
||||
Tests.push_back(-1.0f);
|
||||
Tests.push_back(2.0f);
|
||||
Tests.push_back(-2.0f);
|
||||
Tests.push_back(1.9f);
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
|
||||
float v0 = glm::unpackHalf1x16(p0);
|
||||
glm::uint16 p1 = glm::packHalf1x16(v0);
|
||||
float v1 = glm::unpackHalf1x16(p1);
|
||||
Error += glm::epsilonEqual(v0, v1, glm::epsilon<float>()) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_Half4x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> Tests;
|
||||
Tests.push_back(glm::vec4(1.0f));
|
||||
Tests.push_back(glm::vec4(0.0f));
|
||||
Tests.push_back(glm::vec4(2.0f));
|
||||
Tests.push_back(glm::vec4(0.1f));
|
||||
Tests.push_back(glm::vec4(0.5f));
|
||||
Tests.push_back(glm::vec4(-0.9f));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint64 p0 = glm::packHalf4x16(Tests[i]);
|
||||
glm::vec4 v0 = glm::unpackHalf4x16(p0);
|
||||
glm::uint64 p1 = glm::packHalf4x16(v0);
|
||||
glm::vec4 v1 = glm::unpackHalf4x16(p1);
|
||||
glm::u16vec4 p2 = glm::packHalf(v0);
|
||||
glm::vec4 v2 = glm::unpackHalf(p2);
|
||||
|
||||
Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v0, v2, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_I3x10_1x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::ivec4> Tests;
|
||||
Tests.push_back(glm::ivec4(0));
|
||||
Tests.push_back(glm::ivec4(1));
|
||||
Tests.push_back(glm::ivec4(-1));
|
||||
Tests.push_back(glm::ivec4(2));
|
||||
Tests.push_back(glm::ivec4(-2));
|
||||
Tests.push_back(glm::ivec4(3));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packI3x10_1x2(Tests[i]);
|
||||
glm::ivec4 v0 = glm::unpackI3x10_1x2(p0);
|
||||
glm::uint32 p1 = glm::packI3x10_1x2(v0);
|
||||
glm::ivec4 v1 = glm::unpackI3x10_1x2(p1);
|
||||
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_U3x10_1x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::uvec4> Tests;
|
||||
Tests.push_back(glm::uvec4(0));
|
||||
Tests.push_back(glm::uvec4(1));
|
||||
Tests.push_back(glm::uvec4(2));
|
||||
Tests.push_back(glm::uvec4(3));
|
||||
Tests.push_back(glm::uvec4(4));
|
||||
Tests.push_back(glm::uvec4(5));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]);
|
||||
glm::uvec4 v0 = glm::unpackU3x10_1x2(p0);
|
||||
glm::uint32 p1 = glm::packU3x10_1x2(v0);
|
||||
glm::uvec4 v1 = glm::unpackU3x10_1x2(p1);
|
||||
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
|
||||
}
|
||||
|
||||
glm::u8vec4 const v0(0xff, 0x77, 0x0, 0x33);
|
||||
glm::uint32 const p0 = *reinterpret_cast<glm::uint32 const*>(&v0[0]);
|
||||
glm::uint32 const r0 = 0x330077ff;
|
||||
|
||||
Error += p0 == r0 ? 0 : 1;
|
||||
|
||||
glm::uvec4 const v1(0xff, 0x77, 0x0, 0x33);
|
||||
glm::uint32 const p1 = glm::packU3x10_1x2(v1);
|
||||
glm::uint32 const r1 = 0xc001dcff;
|
||||
|
||||
Error += p1 == r1 ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_Snorm3x10_1x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> Tests;
|
||||
Tests.push_back(glm::vec4(1.0f));
|
||||
Tests.push_back(glm::vec4(0.0f));
|
||||
Tests.push_back(glm::vec4(2.0f));
|
||||
Tests.push_back(glm::vec4(0.1f));
|
||||
Tests.push_back(glm::vec4(0.5f));
|
||||
Tests.push_back(glm::vec4(0.9f));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]);
|
||||
glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0);
|
||||
glm::uint32 p1 = glm::packSnorm3x10_1x2(v0);
|
||||
glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1);
|
||||
|
||||
Error += glm::all(glm::epsilonEqual(v0, v1, 0.01f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_Unorm3x10_1x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> Tests;
|
||||
Tests.push_back(glm::vec4(1.0f));
|
||||
Tests.push_back(glm::vec4(0.0f));
|
||||
Tests.push_back(glm::vec4(2.0f));
|
||||
Tests.push_back(glm::vec4(0.1f));
|
||||
Tests.push_back(glm::vec4(0.5f));
|
||||
Tests.push_back(glm::vec4(0.9f));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packUnorm3x10_1x2(Tests[i]);
|
||||
glm::vec4 v0 = glm::unpackUnorm3x10_1x2(p0);
|
||||
glm::uint32 p1 = glm::packUnorm3x10_1x2(v0);
|
||||
glm::vec4 v1 = glm::unpackUnorm3x10_1x2(p1);
|
||||
|
||||
Error += glm::all(glm::epsilonEqual(v0, v1, 0.001f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_F2x11_1x10()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec3> Tests;
|
||||
Tests.push_back(glm::vec3(1.0f));
|
||||
Tests.push_back(glm::vec3(0.0f));
|
||||
Tests.push_back(glm::vec3(2.0f));
|
||||
Tests.push_back(glm::vec3(0.1f));
|
||||
Tests.push_back(glm::vec3(0.5f));
|
||||
Tests.push_back(glm::vec3(0.9f));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]);
|
||||
glm::vec3 v0 = glm::unpackF2x11_1x10(p0);
|
||||
glm::uint32 p1 = glm::packF2x11_1x10(v0);
|
||||
glm::vec3 v1 = glm::unpackF2x11_1x10(p1);
|
||||
Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_F3x9_E1x5()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec3> Tests;
|
||||
Tests.push_back(glm::vec3(1.0f));
|
||||
Tests.push_back(glm::vec3(0.0f));
|
||||
Tests.push_back(glm::vec3(2.0f));
|
||||
Tests.push_back(glm::vec3(0.1f));
|
||||
Tests.push_back(glm::vec3(0.5f));
|
||||
Tests.push_back(glm::vec3(0.9f));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packF3x9_E1x5(Tests[i]);
|
||||
glm::vec3 v0 = glm::unpackF3x9_E1x5(p0);
|
||||
glm::uint32 p1 = glm::packF3x9_E1x5(v0);
|
||||
glm::vec3 v1 = glm::unpackF3x9_E1x5(p1);
|
||||
Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_RGBM()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
for(std::size_t i = 0; i < 1024; ++i)
|
||||
{
|
||||
glm::vec3 const Color(static_cast<float>(i));
|
||||
glm::vec4 const RGBM = glm::packRGBM(Color);
|
||||
glm::vec3 const Result= glm::unpackRGBM(RGBM);
|
||||
|
||||
Error += glm::all(glm::equal(Color, Result, 0.01f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm1x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec1> A;
|
||||
A.push_back(glm::vec1(1.0f));
|
||||
A.push_back(glm::vec1(0.5f));
|
||||
A.push_back(glm::vec1(0.1f));
|
||||
A.push_back(glm::vec1(0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec1 B(A[i]);
|
||||
glm::uint16 C = glm::packUnorm1x16(B.x);
|
||||
glm::vec1 D(glm::unpackUnorm1x16(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm1x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec1> A;
|
||||
A.push_back(glm::vec1( 1.0f));
|
||||
A.push_back(glm::vec1( 0.0f));
|
||||
A.push_back(glm::vec1(-0.5f));
|
||||
A.push_back(glm::vec1(-0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec1 B(A[i]);
|
||||
glm::uint16 C = glm::packSnorm1x16(B.x);
|
||||
glm::vec1 D(glm::unpackSnorm1x16(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2(1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(0.5f, 0.7f));
|
||||
A.push_back(glm::vec2(0.1f, 0.2f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint32 C = glm::packUnorm2x16(B);
|
||||
glm::vec2 D = glm::unpackUnorm2x16(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(-0.5f,-0.7f));
|
||||
A.push_back(glm::vec2(-0.1f, 0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint32 C = glm::packSnorm2x16(B);
|
||||
glm::vec2 D = glm::unpackSnorm2x16(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm4x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4(1.0f));
|
||||
A.push_back(glm::vec4(0.5f));
|
||||
A.push_back(glm::vec4(0.1f));
|
||||
A.push_back(glm::vec4(0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint64 C = glm::packUnorm4x16(B);
|
||||
glm::vec4 D(glm::unpackUnorm4x16(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm4x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4( 1.0f, 0.0f, -0.5f, 0.5f));
|
||||
A.push_back(glm::vec4(-0.3f,-0.7f, 0.3f, 0.7f));
|
||||
A.push_back(glm::vec4(-0.1f, 0.1f, -0.2f, 0.2f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint64 C = glm::packSnorm4x16(B);
|
||||
glm::vec4 D(glm::unpackSnorm4x16(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm1x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec1> A;
|
||||
A.push_back(glm::vec1(1.0f));
|
||||
A.push_back(glm::vec1(0.5f));
|
||||
A.push_back(glm::vec1(0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec1 B(A[i]);
|
||||
glm::uint8 C = glm::packUnorm1x8(B.x);
|
||||
glm::vec1 D(glm::unpackUnorm1x8(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm1x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec1> A;
|
||||
A.push_back(glm::vec1( 1.0f));
|
||||
A.push_back(glm::vec1(-0.7f));
|
||||
A.push_back(glm::vec1(-1.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec1 B(A[i]);
|
||||
glm::uint8 C = glm::packSnorm1x8(B.x);
|
||||
glm::vec1 D(glm::unpackSnorm1x8(C));
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm2x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2(1.0f, 0.7f));
|
||||
A.push_back(glm::vec2(0.5f, 0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint16 C = glm::packUnorm2x8(B);
|
||||
glm::vec2 D = glm::unpackUnorm2x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm2x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(-0.7f,-0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint16 C = glm::packSnorm2x8(B);
|
||||
glm::vec2 D = glm::unpackSnorm2x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
|
||||
A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint32 C = glm::packUnorm4x8(B);
|
||||
glm::vec4 D = glm::unpackUnorm4x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
|
||||
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint32 C = glm::packSnorm4x8(B);
|
||||
glm::vec4 D = glm::unpackSnorm4x8(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2(1.0f, 0.7f));
|
||||
A.push_back(glm::vec2(0.5f, 0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::u16vec2 C = glm::packUnorm<glm::uint16>(B);
|
||||
glm::vec2 D = glm::unpackUnorm<float>(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packSnorm()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||
A.push_back(glm::vec2(-0.5f,-0.7f));
|
||||
A.push_back(glm::vec2(-0.1f, 0.1f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::i16vec2 C = glm::packSnorm<glm::int16>(B);
|
||||
glm::vec2 D = glm::unpackSnorm<float>(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm2x4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec2> A;
|
||||
A.push_back(glm::vec2(1.0f, 0.7f));
|
||||
A.push_back(glm::vec2(0.5f, 0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec2 B(A[i]);
|
||||
glm::uint8 C = glm::packUnorm2x4(B);
|
||||
glm::vec2 D = glm::unpackUnorm2x4(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm4x4()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
|
||||
A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint16 C = glm::packUnorm4x4(B);
|
||||
glm::vec4 D = glm::unpackUnorm4x4(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm3x5_1x1()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec4> A;
|
||||
A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
|
||||
A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec4 B(A[i]);
|
||||
glm::uint16 C = glm::packUnorm3x5_1x1(B);
|
||||
glm::vec4 D = glm::unpackUnorm3x5_1x1(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm1x5_1x6_1x5()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec3> A;
|
||||
A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
|
||||
A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec3 B(A[i]);
|
||||
glm::uint16 C = glm::packUnorm1x5_1x6_1x5(B);
|
||||
glm::vec3 D = glm::unpackUnorm1x5_1x6_1x5(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUnorm2x3_1x2()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
std::vector<glm::vec3> A;
|
||||
A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
|
||||
A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
|
||||
|
||||
for(std::size_t i = 0; i < A.size(); ++i)
|
||||
{
|
||||
glm::vec3 B(A[i]);
|
||||
glm::uint8 C = glm::packUnorm2x3_1x2(B);
|
||||
glm::vec3 D = glm::unpackUnorm2x3_1x2(C);
|
||||
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 3.f)) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUint2x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::u8vec2 const Source(1, 2);
|
||||
|
||||
glm::uint16 const Packed = glm::packUint2x8(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUint4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::u8vec4 const Source(1, 2, 3, 4);
|
||||
|
||||
glm::uint32 const Packed = glm::packUint4x8(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUint2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::u16vec2 const Source(1, 2);
|
||||
|
||||
glm::uint32 const Packed = glm::packUint2x16(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUint4x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::u16vec4 const Source(1, 2, 3, 4);
|
||||
|
||||
glm::uint64 const Packed = glm::packUint4x16(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packUint2x32()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::u32vec2 const Source(1, 2);
|
||||
|
||||
glm::uint64 const Packed = glm::packUint2x32(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packInt2x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::i8vec2 const Source(1, 2);
|
||||
|
||||
glm::int16 const Packed = glm::packInt2x8(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packInt4x8()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::i8vec4 const Source(1, 2, 3, 4);
|
||||
|
||||
glm::int32 const Packed = glm::packInt4x8(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packInt2x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::i16vec2 const Source(1, 2);
|
||||
|
||||
glm::int32 const Packed = glm::packInt2x16(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packInt4x16()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::i16vec4 const Source(1, 2, 3, 4);
|
||||
|
||||
glm::int64 const Packed = glm::packInt4x16(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_packInt2x32()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::i32vec2 const Source(1, 2);
|
||||
|
||||
glm::int64 const Packed = glm::packInt2x32(Source);
|
||||
Error += Packed != 0 ? 0 : 1;
|
||||
|
||||
glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed);
|
||||
Error += Source == Unpacked ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_packUnorm();
|
||||
Error += test_packSnorm();
|
||||
|
||||
Error += test_packSnorm1x16();
|
||||
Error += test_packSnorm2x16();
|
||||
Error += test_packSnorm4x16();
|
||||
|
||||
Error += test_packSnorm1x8();
|
||||
Error += test_packSnorm2x8();
|
||||
Error += test_packSnorm4x8();
|
||||
|
||||
Error += test_packUnorm1x16();
|
||||
Error += test_packUnorm2x16();
|
||||
Error += test_packUnorm4x16();
|
||||
|
||||
Error += test_packUnorm1x8();
|
||||
Error += test_packUnorm2x8();
|
||||
Error += test_packUnorm4x8();
|
||||
|
||||
Error += test_packUnorm2x4();
|
||||
Error += test_packUnorm4x4();
|
||||
Error += test_packUnorm3x5_1x1();
|
||||
Error += test_packUnorm1x5_1x6_1x5();
|
||||
Error += test_packUnorm2x3_1x2();
|
||||
|
||||
Error += test_packUint2x8();
|
||||
Error += test_packUint4x8();
|
||||
Error += test_packUint2x16();
|
||||
Error += test_packUint4x16();
|
||||
Error += test_packUint2x32();
|
||||
|
||||
Error += test_packInt2x8();
|
||||
Error += test_packInt4x8();
|
||||
Error += test_packInt2x16();
|
||||
Error += test_packInt4x16();
|
||||
Error += test_packInt2x32();
|
||||
|
||||
Error += test_F2x11_1x10();
|
||||
Error += test_F3x9_E1x5();
|
||||
Error += test_RGBM();
|
||||
Error += test_Unorm3x10_1x2();
|
||||
Error += test_Snorm3x10_1x2();
|
||||
|
||||
Error += test_I3x10_1x2();
|
||||
Error += test_U3x10_1x2();
|
||||
Error += test_Half1x16();
|
||||
Error += test_Half4x16();
|
||||
|
||||
return Error;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user