Compare commits

...

16 Commits

Author SHA1 Message Date
Recep Aslantas
79c44fdbfa drop pedantic from C Flags and allow extensions
this will also suppress warnings on test target
2020-05-29 13:01:36 +03:00
Recep Aslantas
c32e986497 mat2: suppress warnings for initializing mat2 sruct 2020-05-29 12:51:45 +03:00
Recep Aslantas
b953fcf1bd ci, travis: add multiple cpu arch 2020-05-29 00:47:18 +03:00
Recep Aslantas
c0a4c245f0 tests: add test for frustum 2020-05-28 14:19:35 +03:00
Recep Aslantas
acc0885e52 tests: add option to disable colors in test output
* because some terminals may not support colors, in that case, colors can be disabled by defining `GLM_TESTS_NO_COLORFUL_OUTPUT`
2020-05-28 11:47:13 +03:00
Recep Aslantas
f49e8f9991 neon: fix vec4_muladds (critical) 2020-05-26 23:03:32 +03:00
Recep Aslantas
d2e5a3cd5b use epsilon to compare vec2/vec3/vec4_eq_all 2020-05-26 23:02:58 +03:00
Recep Aslantas
a1485a14f6 option to override FLT_EPSILON with GLM_FLT_EPSILON 2020-05-26 23:00:00 +03:00
Recep Aslantas
271e3b15d6 Merge branch 'cmake' 2020-05-25 17:07:46 +03:00
Recep Aslantas
74cf89a82f build, cmake: update cmake to export Config to use find_package() 2020-05-25 17:06:48 +03:00
Recep Aslantas
8698082411 Merge pull request #143 from recp/cmake
Improve CMakeLists.txt
2020-05-22 00:01:42 +03:00
Recep Aslantas
799de548f4 Update CMakeLists.txt 2020-05-18 16:04:15 +03:00
Recep Aslantas
671dae3e22 now working on v0.7.6 2020-05-18 15:55:04 +03:00
Recep Aslantas
7e142132bf win: suppress warning; C4005: '_CRT_SECURE_NO_WARNINGS': macro redefinition 2020-05-17 19:24:48 +03:00
Recep Aslantas
0ccd58da01 docs: add clarification/troubleshooting for a crash type 2020-05-16 22:37:16 +03:00
Recep Aslantas
4211c230cc now working on v0.7.5 2020-05-16 22:11:54 +03:00
21 changed files with 230 additions and 179 deletions

View File

@@ -4,6 +4,12 @@ os:
- linux - linux
- osx - osx
arch:
- amd64
- ppc64le
- s390x
- arm64
sudo: required sudo: required
dist: trusty dist: trusty

View File

@@ -1,8 +1,9 @@
cmake_minimum_required(VERSION 3.8.2) cmake_minimum_required(VERSION 3.8.2)
project(cglm VERSION 0.7.4 LANGUAGES C) project(cglm VERSION 0.7.6 LANGUAGES C)
set(C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(C_STANDARD_REQUIRED YES) set(CMAKE_C_STANDARD_REQUIRED YES)
set(DEFAULT_BUILD_TYPE "Release")
set(CGLM_BUILD) set(CGLM_BUILD)
option(CGLM_SHARED "Shared build" ON) option(CGLM_SHARED "Shared build" ON)
@@ -22,124 +23,26 @@ endif()
if(MSVC) if(MSVC)
add_definitions(-DNDEBUG -D_WINDOWS -D_USRDLL -DCGLM_EXPORTS -DCGLM_DLL) add_definitions(-DNDEBUG -D_WINDOWS -D_USRDLL -DCGLM_EXPORTS -DCGLM_DLL)
add_compile_options("/W3" "/Ox" "/Gy" "/Oi" "/TC" "/analyze") add_compile_options(/W3 /Ox /Gy /Oi /TC)
else() else()
add_compile_options("-Wall" "-Werror" "-std=gnu11" "-O3") add_compile_options(-Wall -Werror -O3)
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
# Currently, nothing special to be seen here.
else()
add_compile_options("-Werror=strict-prototypes")
endif()
endif() endif()
set(HEADERS if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
include/cglm/version.h message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
include/cglm/common.h set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
include/cglm/types.h # Set the possible values of build type for cmake-gui
include/cglm/types-struct.h set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
include/cglm/cglm.h endif()
include/cglm/call.h
include/cglm/struct.h
include/cglm/cam.h
include/cglm/io.h
include/cglm/mat4.h
include/cglm/mat3.h
include/cglm/mat2.h
include/cglm/affine.h
include/cglm/vec2.h
include/cglm/vec2-ext.h
include/cglm/vec3.h
include/cglm/vec3-ext.h
include/cglm/vec4.h
include/cglm/vec4-ext.h
include/cglm/euler.h
include/cglm/util.h
include/cglm/quat.h
include/cglm/affine-mat.h
include/cglm/plane.h
include/cglm/frustum.h
include/cglm/box.h
include/cglm/color.h
include/cglm/project.h
include/cglm/sphere.h
include/cglm/ease.h
include/cglm/curve.h
include/cglm/bezier.h
include/cglm/applesimd.h
include/cglm/ray.h
)
set(HEADERS_CALL include(GNUInstallDirs)
include/cglm/call/mat4.h
include/cglm/call/mat3.h
include/cglm/call/mat2.h
include/cglm/call/vec2.h
include/cglm/call/vec3.h
include/cglm/call/vec4.h
include/cglm/call/affine.h
include/cglm/call/io.h
include/cglm/call/cam.h
include/cglm/call/quat.h
include/cglm/call/euler.h
include/cglm/call/plane.h
include/cglm/call/frustum.h
include/cglm/call/box.h
include/cglm/call/project.h
include/cglm/call/sphere.h
include/cglm/call/ease.h
include/cglm/call/curve.h
include/cglm/call/bezier.h
include/cglm/call/ray.h
)
set(HEADERS_SIMD set(CPACK_PROJECT_NAME ${PROJECT_NAME})
include/cglm/simd/intrin.h set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include/cglm/simd/x86.h include(CPack)
include/cglm/simd/arm.h
)
set(HEADERS_SIMD_SSE2 # Target Start
include/cglm/simd/sse2/affine.h add_library(${PROJECT_NAME}
include/cglm/simd/sse2/mat4.h
include/cglm/simd/sse2/mat3.h
include/cglm/simd/sse2/mat2.h
include/cglm/simd/sse2/quat.h
)
set(HEADERS_SIMD_AVX
include/cglm/simd/avx/mat4.h
include/cglm/simd/avx/affine.h
)
set(HEADERS_SIMD_NEON
include/cglm/simd/neon/mat4.h
)
set(HEADERS_STRUCT
include/cglm/struct/mat4.h
include/cglm/struct/mat3.h
include/cglm/struct/mat2.h
include/cglm/struct/vec2.h
include/cglm/struct/vec2-ext.h
include/cglm/struct/vec3.h
include/cglm/struct/vec3-ext.h
include/cglm/struct/vec4.h
include/cglm/struct/vec4-ext.h
include/cglm/struct/affine.h
include/cglm/struct/io.h
include/cglm/struct/cam.h
include/cglm/struct/quat.h
include/cglm/struct/euler.h
include/cglm/struct/plane.h
include/cglm/struct/frustum.h
include/cglm/struct/box.h
include/cglm/struct/project.h
include/cglm/struct/sphere.h
include/cglm/struct/color.h
include/cglm/struct/curve.h
)
add_library(cglm
${CGLM_BUILD} ${CGLM_BUILD}
src/euler.c src/euler.c
src/affine.c src/affine.c
@@ -163,33 +66,42 @@ add_library(cglm
src/ray.c src/ray.c
) )
set_target_properties(cglm PROPERTIES VERSION ${PROJECT_VERSION} set_target_properties(${PROJECT_NAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}) VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_include_directories(cglm PUBLIC target_include_directories(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/include PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
) )
install(
TARGETS cglm
EXPORT cglm
ARCHIVE DESTINATION lib/ COMPONENT development
LIBRARY DESTINATION lib/ COMPONENT runtime NAMELINK_SKIP
RUNTIME DESTINATION ${CMAKE_INSTALL_NAME_DIR} COMPONENT runtime
)
if(CGLM_SHARED)
install(
TARGETS cglm
EXPORT cglm
LIBRARY DESTINATION include/ COMPONENT development NAMELINK_ONLY
)
endif()
INSTALL(DIRECTORY include/ DESTINATION include)
# Test Configuration # Test Configuration
if(CGLM_USE_TEST) if(CGLM_USE_TEST)
include(CTest)
enable_testing() enable_testing()
add_subdirectory(test) add_subdirectory(test)
endif() endif()
# Install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN ".*" EXCLUDE)
# Config
export(TARGETS ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
)
install(EXPORT ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake)

View File

@@ -12,7 +12,6 @@ AM_CFLAGS = -Wall \
-O3 \ -O3 \
-Wstrict-aliasing=2 \ -Wstrict-aliasing=2 \
-fstrict-aliasing \ -fstrict-aliasing \
-pedantic \
-Werror=strict-prototypes -Werror=strict-prototypes
lib_LTLIBRARIES = libcglm.la lib_LTLIBRARIES = libcglm.la

View File

@@ -179,6 +179,8 @@ target_link_libraries(${LIBRARY_NAME} PRIVATE
cglm) cglm)
add_subdirectory(external/cglm/) add_subdirectory(external/cglm/)
# or you can use find_package to configure cglm
``` ```
### Unix (Autotools) ### Unix (Autotools)

View File

@@ -7,7 +7,7 @@
#***************************************************************************** #*****************************************************************************
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([cglm], [0.7.4], [info@recp.me]) AC_INIT([cglm], [0.7.6], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. # Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.

View File

@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'0.7.4' version = u'0.7.6'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.7.4' release = u'0.7.6'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@@ -80,6 +80,19 @@ So be carefull, when your IDE (Xcode, Visual Studio ...) tried to autocomplete f
**Also implementation may be wrong please let us know by creating an issue on Github.** **Also implementation may be wrong please let us know by creating an issue on Github.**
BAD_ACCESS : Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) or Similar Errors/Crashes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is similar issue with alignment. For instance if you compiled **cglm** with
AVX (**-mavx**, intentionally or not) and if you use **cglm** in an environment that doesn't
support AVX (or if AVX is disabled intentionally) e.g. environment that max support SSE2/3/4,
then you probably get **BAD ACCESS** or similar...
Because if you compile **cglm** with AVX it aligns **mat4** with 32 byte boundary,
and your project aligns that as 16 byte boundary...
Check alignment, supported vector extension or simd in **cglm** and linked projects...
Other Issues? Other Issues?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -8,8 +8,13 @@
#ifndef cglm_common_h #ifndef cglm_common_h
#define cglm_common_h #define cglm_common_h
#define _USE_MATH_DEFINES /* for windows */ #ifndef _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS /* for windows */ # define _USE_MATH_DEFINES /* for windows */
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS /* for windows */
#endif
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -35,4 +40,12 @@
#include "types.h" #include "types.h"
#include "simd/intrin.h" #include "simd/intrin.h"
#ifndef CGLM_USE_DEFAULT_EPSILON
# ifndef GLM_FLT_EPSILON
# define GLM_FLT_EPSILON 1e-6
# endif
#else
# define GLM_FLT_EPSILON FLT_EPSILON
#endif
#endif /* cglm_common_h */ #endif /* cglm_common_h */

View File

@@ -36,8 +36,8 @@
#include "../types-struct.h" #include "../types-struct.h"
#include "../mat2.h" #include "../mat2.h"
#define GLMS_MAT2_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 1.0f} #define GLMS_MAT2_IDENTITY_INIT {GLM_MAT2_IDENTITY_INIT}
#define GLMS_MAT2_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f} #define GLMS_MAT2_ZERO_INIT {GLM_MAT2_ZERO_INIT}
/* for C only */ /* for C only */
#define GLMS_MAT2_IDENTITY ((mat3s)GLMS_MAT2_IDENTITY_INIT) #define GLMS_MAT2_IDENTITY ((mat3s)GLMS_MAT2_IDENTITY_INIT)

View File

@@ -289,7 +289,7 @@ glm_smoothinterpc(float from, float to, float t) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_eq(float a, float b) { glm_eq(float a, float b) {
return fabsf(a - b) <= FLT_EPSILON; return fabsf(a - b) <= GLM_FLT_EPSILON;
} }
/*! /*!

View File

@@ -61,8 +61,8 @@ glm_vec2_eq(vec2 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec2_eq_eps(vec2 v, float val) { glm_vec2_eq_eps(vec2 v, float val) {
return fabsf(v[0] - val) <= FLT_EPSILON return fabsf(v[0] - val) <= GLM_FLT_EPSILON
&& fabsf(v[1] - val) <= FLT_EPSILON; && fabsf(v[1] - val) <= GLM_FLT_EPSILON;
} }
/*! /*!
@@ -73,7 +73,7 @@ glm_vec2_eq_eps(vec2 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec2_eq_all(vec2 v) { glm_vec2_eq_all(vec2 v) {
return v[0] == v[1]; return glm_vec2_eq_eps(v, v[0]);
} }
/*! /*!
@@ -97,8 +97,8 @@ glm_vec2_eqv(vec2 a, vec2 b) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec2_eqv_eps(vec2 a, vec2 b) { glm_vec2_eqv_eps(vec2 a, vec2 b) {
return fabsf(a[0] - b[0]) <= FLT_EPSILON return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON
&& fabsf(a[1] - b[1]) <= FLT_EPSILON; && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON;
} }
/*! /*!

View File

@@ -81,9 +81,9 @@ glm_vec3_eq(vec3 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec3_eq_eps(vec3 v, float val) { glm_vec3_eq_eps(vec3 v, float val) {
return fabsf(v[0] - val) <= FLT_EPSILON return fabsf(v[0] - val) <= GLM_FLT_EPSILON
&& fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= GLM_FLT_EPSILON
&& fabsf(v[2] - val) <= FLT_EPSILON; && fabsf(v[2] - val) <= GLM_FLT_EPSILON;
} }
/*! /*!
@@ -94,7 +94,7 @@ glm_vec3_eq_eps(vec3 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec3_eq_all(vec3 v) { glm_vec3_eq_all(vec3 v) {
return v[0] == v[1] && v[0] == v[2]; return glm_vec3_eq_eps(v, v[0]);
} }
/*! /*!
@@ -120,9 +120,9 @@ glm_vec3_eqv(vec3 a, vec3 b) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec3_eqv_eps(vec3 a, vec3 b) { glm_vec3_eqv_eps(vec3 a, vec3 b) {
return fabsf(a[0] - b[0]) <= FLT_EPSILON return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON
&& fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON
&& fabsf(a[2] - b[2]) <= FLT_EPSILON; && fabsf(a[2] - b[2]) <= GLM_FLT_EPSILON;
} }
/*! /*!

View File

@@ -92,10 +92,10 @@ glm_vec4_eq(vec4 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_eq_eps(vec4 v, float val) { glm_vec4_eq_eps(vec4 v, float val) {
return fabsf(v[0] - val) <= FLT_EPSILON return fabsf(v[0] - val) <= GLM_FLT_EPSILON
&& fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= GLM_FLT_EPSILON
&& fabsf(v[2] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= GLM_FLT_EPSILON
&& fabsf(v[3] - val) <= FLT_EPSILON; && fabsf(v[3] - val) <= GLM_FLT_EPSILON;
} }
/*! /*!
@@ -106,9 +106,7 @@ glm_vec4_eq_eps(vec4 v, float val) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_eq_all(vec4 v) { glm_vec4_eq_all(vec4 v) {
return v[0] == v[1] return glm_vec4_eq_eps(v, v[0]);
&& v[0] == v[2]
&& v[0] == v[3];
} }
/*! /*!
@@ -135,10 +133,10 @@ glm_vec4_eqv(vec4 a, vec4 b) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_eqv_eps(vec4 a, vec4 b) { glm_vec4_eqv_eps(vec4 a, vec4 b) {
return fabsf(a[0] - b[0]) <= FLT_EPSILON return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON
&& fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON
&& fabsf(a[2] - b[2]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= GLM_FLT_EPSILON
&& fabsf(a[3] - b[3]) <= FLT_EPSILON; && fabsf(a[3] - b[3]) <= GLM_FLT_EPSILON;
} }
/*! /*!

View File

@@ -602,7 +602,7 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) {
_mm_set1_ps(s)))); _mm_set1_ps(s))));
#elif defined(CGLM_NEON_FP) #elif defined(CGLM_NEON_FP)
vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), vst1q_f32(dest, vaddq_f32(vld1q_f32(dest),
vsubq_f32(vld1q_f32(a), vmulq_f32(vld1q_f32(a),
vdupq_n_f32(s)))); vdupq_n_f32(s))));
#else #else
dest[0] += a[0] * s; dest[0] += a[0] * s;

View File

@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 7 #define CGLM_VERSION_MINOR 7
#define CGLM_VERSION_PATCH 4 #define CGLM_VERSION_PATCH 6
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -8,8 +8,13 @@
#ifndef tests_common_h #ifndef tests_common_h
#define tests_common_h #define tests_common_h
#define _USE_MATH_DEFINES /* for windows */ #ifndef _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS /* for windows */ # define _USE_MATH_DEFINES /* for windows */
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS /* for windows */
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@@ -33,6 +38,8 @@ typedef struct test_entry_t {
int show_output; int show_output;
} test_entry_t; } test_entry_t;
#ifndef GLM_TESTS_NO_COLORFUL_OUTPUT
#define RESET "\033[0m" #define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */ #define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */ #define RED "\033[31m" /* Red */
@@ -51,6 +58,28 @@ typedef struct test_entry_t {
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */
#else
#define RESET
#define BLACK
#define RED
#define GREEN
#define YELLOW
#define BLUE
#define MAGENTA
#define CYAN
#define WHITE
#define BOLDBLACK
#define BOLDRED
#define BOLDGREEN
#define BOLDYELLOW
#define BOLDBLUE
#define BOLDMAGENTA
#define BOLDCYAN
#define BOLDWHITE
#endif
#define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void); #define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void);
#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 }, #define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 },
#define TEST_LIST static test_entry_t tests[] = #define TEST_LIST static test_entry_t tests[] =

View File

@@ -35,9 +35,9 @@ TEST_IMPL(camera_decomp) {
farVal = 100.0f; farVal = 100.0f;
glm_perspective(fovy, aspect, nearVal, farVal, proj); glm_perspective(fovy, aspect, nearVal, farVal, proj);
ASSERT(fabsf(aspect - glm_persp_aspect(proj)) < FLT_EPSILON) ASSERT(fabsf(aspect - glm_persp_aspect(proj)) < GLM_FLT_EPSILON)
ASSERT(fabsf(fovy - glm_persp_fovy(proj)) < FLT_EPSILON) ASSERT(fabsf(fovy - glm_persp_fovy(proj)) < GLM_FLT_EPSILON)
ASSERT(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < FLT_EPSILON) ASSERT(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < GLM_FLT_EPSILON)
glm_persp_sizes(proj, fovy, sizes); glm_persp_sizes(proj, fovy, sizes);

68
test/src/test_camera.h Normal file
View File

@@ -0,0 +1,68 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#include "test_common.h"
TEST_IMPL(GLM_PREFIX, frustum) {
mat4 proj;
vec4 vp = {0.0f, 0.0f, 800.0f, 600.0f};
float left, right, top, bottom, znear, zfar;
znear = 0.1f;
zfar = 100.0f;
left = -100.0f;
right = 100.0f;
bottom = -100.0f;
top = 100.0f;
GLM(frustum)(left, right, bottom, top, znear, zfar, proj);
ASSERT(test_eq(proj[0][1], 0.0f))
ASSERT(test_eq(proj[0][2], 0.0f))
ASSERT(test_eq(proj[0][3], 0.0f))
ASSERT(test_eq(proj[1][0], 0.0f))
ASSERT(test_eq(proj[1][2], 0.0f))
ASSERT(test_eq(proj[1][3], 0.0f))
ASSERT(test_eq(proj[2][3], -1.0f))
ASSERT(test_eq(proj[3][0], 0.0f))
ASSERT(test_eq(proj[3][1], 0.0f))
ASSERT(test_eq(proj[3][3], 0.0f))
vec4 v1 = {1.0f, 20.0f, znear};
vec4 v2 = {1.0f, 20.0f, zfar};
vec4 v3, v4;
/* perspective test */
GLM(mat4_mulv)(proj, v1, v3);
GLM(project)(v3, proj, vp, v3);
ASSERT(v3[0] > v1[0])
ASSERT(v3[1] > v1[1])
GLM(mat4_mulv)(proj, v2, v4);
GLM(project)(v4, proj, vp, v4);
ASSERT(v4[0] < v3[0])
ASSERT(v4[1] < v3[1])
/* not infinity */
ASSERT(!GLM(vec4_isinf)(proj[0]))
ASSERT(!GLM(vec4_isinf)(proj[1]))
ASSERT(!GLM(vec4_isinf)(proj[2]))
ASSERT(!GLM(vec4_isinf)(proj[3]))
/* not NaN */
ASSERT(!GLM(vec4_isnan)(proj[0]))
ASSERT(!GLM(vec4_isnan)(proj[1]))
ASSERT(!GLM(vec4_isnan)(proj[2]))
ASSERT(!GLM(vec4_isnan)(proj[3]))
TEST_SUCCESS
}

View File

@@ -106,7 +106,7 @@ test_rand_quat(versor q);
CGLM_INLINE CGLM_INLINE
bool bool
test_eq(float a, float b) { test_eq(float a, float b) {
return fabsf(a - b) <= 1e-6; return fabsf(a - b) <= GLM_FLT_EPSILON * 10;
} }
CGLM_INLINE CGLM_INLINE

View File

@@ -24,6 +24,7 @@
#include "test_affine.h" #include "test_affine.h"
#include "test_affine_mat.h" #include "test_affine_mat.h"
#include "test_ray.h" #include "test_ray.h"
#include "test_camera.h"
#undef GLM #undef GLM
#undef GLM_PREFIX #undef GLM_PREFIX
@@ -46,6 +47,7 @@
#include "test_affine.h" #include "test_affine.h"
#include "test_affine_mat.h" #include "test_affine_mat.h"
#include "test_ray.h" #include "test_ray.h"
#include "test_camera.h"
#undef GLM #undef GLM
#undef GLM_PREFIX #undef GLM_PREFIX

View File

@@ -199,6 +199,10 @@ TEST_DECLARE(glmc_mat2_rmc)
TEST_DECLARE(camera_lookat) TEST_DECLARE(camera_lookat)
TEST_DECLARE(camera_decomp) TEST_DECLARE(camera_decomp)
TEST_DECLARE(glm_frustum)
TEST_DECLARE(glmc_frustum)
/* project */ /* project */
TEST_DECLARE(glm_unprojecti) TEST_DECLARE(glm_unprojecti)
TEST_DECLARE(glm_unproject) TEST_DECLARE(glm_unproject)
@@ -890,6 +894,10 @@ TEST_LIST {
TEST_ENTRY(camera_lookat) TEST_ENTRY(camera_lookat)
TEST_ENTRY(camera_decomp) TEST_ENTRY(camera_decomp)
TEST_ENTRY(glm_frustum)
TEST_ENTRY(glmc_frustum)
/* project */ /* project */
TEST_ENTRY(glm_unprojecti) TEST_ENTRY(glm_unprojecti)
TEST_ENTRY(glm_unproject) TEST_ENTRY(glm_unproject)
@@ -992,6 +1000,7 @@ TEST_LIST {
/* bezier */ /* bezier */
TEST_ENTRY(bezier) TEST_ENTRY(bezier)
/* vec2 */
/* Macros */ /* Macros */
TEST_ENTRY(MACRO_GLM_VEC2_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC2_ONE_INIT)
@@ -1070,7 +1079,6 @@ TEST_LIST {
TEST_ENTRY(glmc_vec2_lerp) TEST_ENTRY(glmc_vec2_lerp)
/* vec3 */ /* vec3 */
/* Macros */ /* Macros */
TEST_ENTRY(MACRO_GLM_VEC3_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC3_ONE_INIT)
@@ -1236,7 +1244,8 @@ TEST_LIST {
TEST_ENTRY(glmc_vec3_sqrt) TEST_ENTRY(glmc_vec3_sqrt)
/* vec4 */ /* vec4 */
/* Macros */
TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT)
TEST_ENTRY(MACRO_GLM_VEC4_ZERO_INIT) TEST_ENTRY(MACRO_GLM_VEC4_ZERO_INIT)
TEST_ENTRY(MACRO_GLM_VEC4_ONE) TEST_ENTRY(MACRO_GLM_VEC4_ONE)