From 9d61668e0464d9a6910ff176a50874e9fc584b39 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 11 Jul 2017 18:05:10 +0300 Subject: [PATCH] re-organise files, remove cglm prefix from file to make them more clean --- include/cglm.h | 22 -- .../{cglm-affine-mat.h => cglm/affine-mat.h} | 15 +- include/{cglm-affine.h => cglm/affine.h} | 8 +- include/{cglm-call.h => cglm/call.h} | 17 +- .../cglmc-affine.h => cglm/call/affine.h} | 0 include/{call/cglmc-cam.h => cglm/call/cam.h} | 0 .../{call/cglmc-euler.h => cglm/call/euler.h} | 0 include/{call/cglmc-io.h => cglm/call/io.h} | 0 .../{call/cglmc-mat3.h => cglm/call/mat3.h} | 0 .../{call/cglmc-mat.h => cglm/call/mat4.h} | 0 .../{call/cglmc-quat.h => cglm/call/quat.h} | 0 .../{call/cglmc-vec.h => cglm/call/vec3.h} | 62 +--- include/cglm/call/vec4.h | 76 +++++ include/{cglm-cam.h => cglm/cam.h} | 2 +- include/cglm/cglm.h | 23 ++ include/{cglm-common.h => cglm/common.h} | 4 +- include/{cglm-euler.h => cglm/euler.h} | 2 +- include/{cglm-io.h => cglm/io.h} | 2 +- include/{cglm-mat3.h => cglm/mat3.h} | 7 +- include/{cglm-mat.h => cglm/mat4.h} | 8 +- include/{cglm-quat.h => cglm/quat.h} | 10 +- .../simd/avx/affine.h} | 4 +- .../simd/avx/mat4.h} | 4 +- .../simd/cglm-intrin.h => cglm/simd/intrin.h} | 1 + include/{arch => cglm}/simd/neon/mat4.h | 4 +- .../simd/sse2/affine.h} | 4 +- .../simd/sse2/mat3.h} | 4 +- .../simd/sse2/mat4.h} | 4 +- .../simd/sse2/quat.h} | 4 +- include/{cglm-types.h => cglm/types.h} | 0 include/{cglm-util.h => cglm/util.h} | 2 +- include/cglm/vec3-ext.h | 163 ++++++++++ include/{cglm-vec.h => cglm/vec3.h} | 275 +---------------- include/{cglm-vec-ext.h => cglm/vec4-ext.h} | 152 +--------- include/cglm/vec4.h | 285 ++++++++++++++++++ include/{cglm-version.h => cglm/version.h} | 0 makefile.am | 92 +++--- src/{clgm-affine.c => affine.c} | 4 +- src/{cglm-cam.c => cam.c} | 4 +- src/{cglm-euler.c => euler.c} | 4 +- src/{cglm-io.c => io.c} | 4 +- src/{cglm-mat3.c => mat3.c} | 4 +- src/{cglm-mat.c => mat4.c} | 4 +- src/{cglm-quat.c => quat.c} | 4 +- src/{cglm-vec.c => vec3.c} | 82 +---- src/vec4.c | 87 ++++++ test/src/test_common.h | 4 +- win/cglm.vcxproj | 95 +++--- win/cglm.vcxproj.filters | 272 +++++++++-------- 49 files changed, 977 insertions(+), 847 deletions(-) delete mode 100644 include/cglm.h rename include/{cglm-affine-mat.h => cglm/affine-mat.h} (94%) rename include/{cglm-affine.h => cglm/affine.h} (99%) rename include/{cglm-call.h => cglm/call.h} (56%) rename include/{call/cglmc-affine.h => cglm/call/affine.h} (100%) rename include/{call/cglmc-cam.h => cglm/call/cam.h} (100%) rename include/{call/cglmc-euler.h => cglm/call/euler.h} (100%) rename include/{call/cglmc-io.h => cglm/call/io.h} (100%) rename include/{call/cglmc-mat3.h => cglm/call/mat3.h} (100%) rename include/{call/cglmc-mat.h => cglm/call/mat4.h} (100%) rename include/{call/cglmc-quat.h => cglm/call/quat.h} (100%) rename include/{call/cglmc-vec.h => cglm/call/vec3.h} (57%) create mode 100644 include/cglm/call/vec4.h rename include/{cglm-cam.h => cglm/cam.h} (99%) create mode 100644 include/cglm/cglm.h rename include/{cglm-common.h => cglm/common.h} (97%) rename include/{cglm-euler.h => cglm/euler.h} (99%) rename include/{cglm-io.h => cglm/io.h} (99%) rename include/{cglm-mat3.h => cglm/mat3.h} (98%) rename include/{cglm-mat.h => cglm/mat4.h} (99%) rename include/{cglm-quat.h => cglm/quat.h} (97%) rename include/{arch/simd/cglm-affine-mat-avx.h => cglm/simd/avx/affine.h} (97%) rename include/{arch/simd/cglm-mat-simd-avx.h => cglm/simd/avx/mat4.h} (97%) rename include/{arch/simd/cglm-intrin.h => cglm/simd/intrin.h} (98%) rename include/{arch => cglm}/simd/neon/mat4.h (96%) rename include/{arch/simd/cglm-affine-mat-sse2.h => cglm/simd/sse2/affine.h} (97%) rename include/{arch/simd/cglm-mat3-simd-sse2.h => cglm/simd/sse2/mat3.h} (96%) rename include/{arch/simd/cglm-mat-simd-sse2.h => cglm/simd/sse2/mat4.h} (99%) rename include/{arch/simd/cglm-quat-simd.h => cglm/simd/sse2/quat.h} (96%) rename include/{cglm-types.h => cglm/types.h} (100%) rename include/{cglm-util.h => cglm/util.h} (97%) create mode 100644 include/cglm/vec3-ext.h rename include/{cglm-vec.h => cglm/vec3.h} (56%) rename include/{cglm-vec-ext.h => cglm/vec4-ext.h} (54%) create mode 100644 include/cglm/vec4.h rename include/{cglm-version.h => cglm/version.h} (100%) rename src/{clgm-affine.c => affine.c} (96%) rename src/{cglm-cam.c => cam.c} (94%) rename src/{cglm-euler.c => euler.c} (93%) rename src/{cglm-io.c => io.c} (92%) rename src/{cglm-mat3.c => mat3.c} (94%) rename src/{cglm-mat.c => mat4.c} (96%) rename src/{cglm-quat.c => quat.c} (94%) rename src/{cglm-vec.c => vec3.c} (59%) create mode 100644 src/vec4.c diff --git a/include/cglm.h b/include/cglm.h deleted file mode 100644 index 8a0b867..0000000 --- a/include/cglm.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -#ifndef cglm_h -#define cglm_h - -#include "cglm-common.h" -#include "cglm-vec.h" -#include "cglm-mat.h" -#include "cglm-mat3.h" -#include "cglm-affine.h" -#include "cglm-cam.h" -#include "cglm-quat.h" -#include "cglm-euler.h" -#include "cglm-util.h" -#include "cglm-io.h" - -#endif /* cglm_h */ diff --git a/include/cglm-affine-mat.h b/include/cglm/affine-mat.h similarity index 94% rename from include/cglm-affine-mat.h rename to include/cglm/affine-mat.h index 9443f81..aa5d560 100644 --- a/include/cglm-affine-mat.h +++ b/include/cglm/affine-mat.h @@ -14,11 +14,16 @@ #ifndef cglm_affine_mat_h #define cglm_affine_mat_h -#include "cglm-common.h" -#include "cglm-mat.h" -#include "cglm-mat3.h" -#include "arch/simd/cglm-affine-mat-sse2.h" -#include "arch/simd/cglm-affine-mat-avx.h" +#include "common.h" +#include "mat4.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/affine.h" +#endif + +#ifdef CGLM_AVX_FP +# include "simd/avx/affine.h" +#endif #include diff --git a/include/cglm-affine.h b/include/cglm/affine.h similarity index 99% rename from include/cglm-affine.h rename to include/cglm/affine.h index 6bb44bf..6cb1f74 100644 --- a/include/cglm-affine.h +++ b/include/cglm/affine.h @@ -33,10 +33,10 @@ #ifndef cglm_affine_h #define cglm_affine_h -#include "cglm-common.h" -#include "cglm-vec.h" -#include "cglm-affine-mat.h" -#include "cglm-util.h" +#include "common.h" +#include "vec4.h" +#include "affine-mat.h" +#include "util.h" CGLM_INLINE void diff --git a/include/cglm-call.h b/include/cglm/call.h similarity index 56% rename from include/cglm-call.h rename to include/cglm/call.h index 58e7ce8..2b8025a 100644 --- a/include/cglm-call.h +++ b/include/cglm/call.h @@ -12,14 +12,15 @@ extern "C" { #endif #include "cglm.h" -#include "call/cglmc-vec.h" -#include "call/cglmc-mat.h" -#include "call/cglmc-mat3.h" -#include "call/cglmc-affine.h" -#include "call/cglmc-cam.h" -#include "call/cglmc-quat.h" -#include "call/cglmc-euler.h" -#include "call/cglmc-io.h" +#include "call/vec3.h" +#include "call/vec4.h" +#include "call/mat4.h" +#include "call/mat3.h" +#include "call/affine.h" +#include "call/cam.h" +#include "call/quat.h" +#include "call/euler.h" +#include "call/io.h" #ifdef __cplusplus } diff --git a/include/call/cglmc-affine.h b/include/cglm/call/affine.h similarity index 100% rename from include/call/cglmc-affine.h rename to include/cglm/call/affine.h diff --git a/include/call/cglmc-cam.h b/include/cglm/call/cam.h similarity index 100% rename from include/call/cglmc-cam.h rename to include/cglm/call/cam.h diff --git a/include/call/cglmc-euler.h b/include/cglm/call/euler.h similarity index 100% rename from include/call/cglmc-euler.h rename to include/cglm/call/euler.h diff --git a/include/call/cglmc-io.h b/include/cglm/call/io.h similarity index 100% rename from include/call/cglmc-io.h rename to include/cglm/call/io.h diff --git a/include/call/cglmc-mat3.h b/include/cglm/call/mat3.h similarity index 100% rename from include/call/cglmc-mat3.h rename to include/cglm/call/mat3.h diff --git a/include/call/cglmc-mat.h b/include/cglm/call/mat4.h similarity index 100% rename from include/call/cglmc-mat.h rename to include/cglm/call/mat4.h diff --git a/include/call/cglmc-quat.h b/include/cglm/call/quat.h similarity index 100% rename from include/call/cglmc-quat.h rename to include/cglm/call/quat.h diff --git a/include/call/cglmc-vec.h b/include/cglm/call/vec3.h similarity index 57% rename from include/call/cglmc-vec.h rename to include/cglm/call/vec3.h index 655ebce..104259f 100644 --- a/include/call/cglmc-vec.h +++ b/include/cglm/call/vec3.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglmc_vec_h -#define cglmc_vec_h +#ifndef cglmc_vec3_h +#define cglmc_vec3_h #ifdef __cplusplus extern "C" { #endif @@ -14,30 +14,16 @@ extern "C" { #include "../cglm.h" /* DEPRECATED! use _copy, _ucopy versions */ -#define glmc_vec_dup(v, dest) glmc_vec_copy(v, dest) -#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) -#define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) +#define glmc_vec_dup(v, dest) glmc_vec_copy(v, dest) CGLM_EXPORT void glmc_vec_copy(vec3 a, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_copy3(vec4 a, vec3 dest); - -CGLM_EXPORT -void -glmc_vec4_copy(vec4 v, vec4 dest); - CGLM_EXPORT float glmc_vec_dot(vec3 a, vec3 b); -CGLM_EXPORT -float -glmc_vec4_dot(vec4 a, vec4 b); - CGLM_EXPORT void glmc_vec_cross(vec3 a, vec3 b, vec3 d); @@ -46,74 +32,38 @@ CGLM_EXPORT float glmc_vec_norm(vec3 vec); -CGLM_EXPORT -float -glmc_vec4_norm(vec4 vec); - CGLM_EXPORT float glmc_vec_norm2(vec3 vec); -CGLM_EXPORT -float -glmc_vec4_norm2(vec4 vec); - CGLM_EXPORT void glmc_vec_normalize_to(vec3 vec, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_normalize_to(vec4 vec, vec4 dest); - CGLM_EXPORT void glmc_vec_normalize(vec3 v); -CGLM_EXPORT -void -glmc_vec4_normalize(vec4 v); - CGLM_EXPORT void glmc_vec_add(vec3 v1, vec3 v2, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest); - CGLM_EXPORT void glmc_vec_sub(vec3 v1, vec3 v2, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest); - CGLM_EXPORT void glmc_vec_scale(vec3 v, float s, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_scale(vec4 v, float s, vec4 dest); - CGLM_EXPORT void glmc_vec_scale_as(vec3 v, float s, vec3 dest); -CGLM_EXPORT -void -glmc_vec4_scale_as(vec3 v, float s, vec3 dest); - CGLM_EXPORT void glmc_vec_flipsign(vec3 v); -CGLM_EXPORT -void -glmc_vec4_flipsign(vec4 v); - CGLM_EXPORT float glmc_vec_angle(vec3 v1, vec3 v2); @@ -138,11 +88,7 @@ CGLM_EXPORT float glmc_vec_distance(vec3 v1, vec3 v2); -CGLM_EXPORT -float -glmc_vec4_distance(vec4 v1, vec4 v2); - #ifdef __cplusplus } #endif -#endif /* cglmc_vec_h */ +#endif /* cglmc_vec3_h */ diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h new file mode 100644 index 0000000..dfb94a9 --- /dev/null +++ b/include/cglm/call/vec4.h @@ -0,0 +1,76 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_vec4_h +#define cglmc_vec4_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) +#define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) + +CGLM_EXPORT +void +glmc_vec4_copy3(vec4 a, vec3 dest); + +CGLM_EXPORT +void +glmc_vec4_copy(vec4 v, vec4 dest); + +CGLM_EXPORT +float +glmc_vec4_dot(vec4 a, vec4 b); + +CGLM_EXPORT +float +glmc_vec4_norm(vec4 vec); + +CGLM_EXPORT +float +glmc_vec4_norm2(vec4 vec); + +CGLM_EXPORT +void +glmc_vec4_normalize_to(vec4 vec, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_normalize(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_scale(vec4 v, float s, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_scale_as(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec4_flipsign(vec4 v); + +CGLM_EXPORT +float +glmc_vec4_distance(vec4 v1, vec4 v2); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_vec4_h */ + diff --git a/include/cglm-cam.h b/include/cglm/cam.h similarity index 99% rename from include/cglm-cam.h rename to include/cglm/cam.h index 9bf32b1..132cc04 100644 --- a/include/cglm-cam.h +++ b/include/cglm/cam.h @@ -36,7 +36,7 @@ #ifndef cglm_vcam_h #define cglm_vcam_h -#include "cglm-common.h" +#include "common.h" /*! * @brief set up perspective peprojection matrix diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h new file mode 100644 index 0000000..1dabb70 --- /dev/null +++ b/include/cglm/cglm.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_h +#define cglm_h + +#include "common.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" +#include "mat3.h" +#include "affine.h" +#include "cam.h" +#include "quat.h" +#include "euler.h" +#include "util.h" +#include "io.h" + +#endif /* cglm_h */ diff --git a/include/cglm-common.h b/include/cglm/common.h similarity index 97% rename from include/cglm-common.h rename to include/cglm/common.h index 6898743..f68908b 100644 --- a/include/cglm-common.h +++ b/include/cglm/common.h @@ -53,7 +53,7 @@ #define glm__memzero(type, dest, size) glm__memset(type, dest, size, 0) -#include "cglm-types.h" -#include "arch/simd/cglm-intrin.h" +#include "types.h" +#include "simd/intrin.h" #endif /* cglm_common_h */ diff --git a/include/cglm-euler.h b/include/cglm/euler.h similarity index 99% rename from include/cglm-euler.h rename to include/cglm/euler.h index 769d05b..bf62bb7 100644 --- a/include/cglm-euler.h +++ b/include/cglm/euler.h @@ -26,7 +26,7 @@ #ifndef cglm_euler_h #define cglm_euler_h -#include "cglm-common.h" +#include "common.h" /*! * if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]... diff --git a/include/cglm-io.h b/include/cglm/io.h similarity index 99% rename from include/cglm-io.h rename to include/cglm/io.h index 293889a..2ee8ee8 100644 --- a/include/cglm-io.h +++ b/include/cglm/io.h @@ -18,7 +18,7 @@ #ifndef cglm_io_h #define cglm_io_h -#include "cglm-common.h" +#include "common.h" #include #include diff --git a/include/cglm-mat3.h b/include/cglm/mat3.h similarity index 98% rename from include/cglm-mat3.h rename to include/cglm/mat3.h index 22163df..9b454ce 100644 --- a/include/cglm-mat3.h +++ b/include/cglm/mat3.h @@ -30,8 +30,11 @@ #ifndef cglm_mat3_h #define cglm_mat3_h -#include "cglm-common.h" -#include "arch/simd/cglm-mat3-simd-sse2.h" +#include "common.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat3.h" +#endif #define GLM_MAT3_IDENTITY_INIT {{1.0f, 0.0f, 0.0f}, \ {0.0f, 1.0f, 0.0f}, \ diff --git a/include/cglm-mat.h b/include/cglm/mat4.h similarity index 99% rename from include/cglm-mat.h rename to include/cglm/mat4.h index c5dad6a..d758cdd 100644 --- a/include/cglm-mat.h +++ b/include/cglm/mat4.h @@ -44,18 +44,18 @@ #ifndef cglm_mat_h #define cglm_mat_h -#include "cglm-common.h" +#include "common.h" #ifdef CGLM_SSE_FP -# include "arch/simd/cglm-mat-simd-sse2.h" +# include "simd/sse2/mat4.h" #endif #ifdef CGLM_AVX_FP -# include "arch/simd/cglm-mat-simd-avx.h" +# include "simd/avx/mat4.h" #endif #ifdef CGLM_NEON_FP -# include "arch/simd/neon/mat4.h" +# include "simd/neon/mat4.h" #endif #include diff --git a/include/cglm-quat.h b/include/cglm/quat.h similarity index 97% rename from include/cglm-quat.h rename to include/cglm/quat.h index 20fd1ad..755b2a7 100644 --- a/include/cglm-quat.h +++ b/include/cglm/quat.h @@ -25,10 +25,12 @@ #ifndef cglm_quat_h #define cglm_quat_h -#include "cglm-common.h" -#include "cglm-vec.h" -#include "arch/simd/cglm-intrin.h" -#include "arch/simd/cglm-quat-simd.h" +#include "common.h" +#include "vec4.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/quat.h" +#endif #define GLM_QUAT_IDENTITY_INIT {0.0f, 0.0f, 0.0f, 1.0f} #define GLM_QUAT_IDENTITY (versor){0.0f, 0.0f, 0.0f, 1.0f} diff --git a/include/arch/simd/cglm-affine-mat-avx.h b/include/cglm/simd/avx/affine.h similarity index 97% rename from include/arch/simd/cglm-affine-mat-avx.h rename to include/cglm/simd/avx/affine.h index 0372f87..1b0dcea 100644 --- a/include/arch/simd/cglm-affine-mat-avx.h +++ b/include/cglm/simd/avx/affine.h @@ -9,8 +9,8 @@ #define cglm_affine_mat_avx_h #ifdef __AVX__ -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" #include diff --git a/include/arch/simd/cglm-mat-simd-avx.h b/include/cglm/simd/avx/mat4.h similarity index 97% rename from include/arch/simd/cglm-mat-simd-avx.h rename to include/cglm/simd/avx/mat4.h index 3a83ad8..e2ef9da 100644 --- a/include/arch/simd/cglm-mat-simd-avx.h +++ b/include/cglm/simd/avx/mat4.h @@ -9,8 +9,8 @@ #define cglm_mat_simd_avx_h #ifdef __AVX__ -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" #include diff --git a/include/arch/simd/cglm-intrin.h b/include/cglm/simd/intrin.h similarity index 98% rename from include/arch/simd/cglm-intrin.h rename to include/cglm/simd/intrin.h index 681fc9b..c0f2e53 100644 --- a/include/arch/simd/cglm-intrin.h +++ b/include/cglm/simd/intrin.h @@ -43,6 +43,7 @@ /* ARM Neon */ #if defined(__ARM_NEON) && defined(__ARM_NEON_FP) +# include # define CGLM_NEON_FP 1 #else # undef CGLM_NEON_FP diff --git a/include/arch/simd/neon/mat4.h b/include/cglm/simd/neon/mat4.h similarity index 96% rename from include/arch/simd/neon/mat4.h rename to include/cglm/simd/neon/mat4.h index 8694ea2..0623dc0 100644 --- a/include/arch/simd/neon/mat4.h +++ b/include/cglm/simd/neon/mat4.h @@ -9,8 +9,8 @@ #define cglm_mat4_neon_h #if defined(__ARM_NEON_FP) -#include "../../../cglm-common.h" -#include +#include "../../common.h" +#include "../intrin.h" CGLM_INLINE void diff --git a/include/arch/simd/cglm-affine-mat-sse2.h b/include/cglm/simd/sse2/affine.h similarity index 97% rename from include/arch/simd/cglm-affine-mat-sse2.h rename to include/cglm/simd/sse2/affine.h index 4ec7b0d..3ec8f5f 100644 --- a/include/arch/simd/cglm-affine-mat-sse2.h +++ b/include/cglm/simd/sse2/affine.h @@ -9,8 +9,8 @@ #define cglm_affine_mat_sse2_h #if defined( __SSE__ ) || defined( __SSE2__ ) -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" CGLM_INLINE void diff --git a/include/arch/simd/cglm-mat3-simd-sse2.h b/include/cglm/simd/sse2/mat3.h similarity index 96% rename from include/arch/simd/cglm-mat3-simd-sse2.h rename to include/cglm/simd/sse2/mat3.h index 7f63ce3..a0dcc02 100644 --- a/include/arch/simd/cglm-mat3-simd-sse2.h +++ b/include/cglm/simd/sse2/mat3.h @@ -9,8 +9,8 @@ #define cglm_mat3_sse_h #if defined( __SSE__ ) || defined( __SSE2__ ) -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" CGLM_INLINE void diff --git a/include/arch/simd/cglm-mat-simd-sse2.h b/include/cglm/simd/sse2/mat4.h similarity index 99% rename from include/arch/simd/cglm-mat-simd-sse2.h rename to include/cglm/simd/sse2/mat4.h index cab8039..c070af9 100644 --- a/include/arch/simd/cglm-mat-simd-sse2.h +++ b/include/cglm/simd/sse2/mat4.h @@ -9,8 +9,8 @@ #define cglm_mat_sse_h #if defined( __SSE__ ) || defined( __SSE2__ ) -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" CGLM_INLINE void diff --git a/include/arch/simd/cglm-quat-simd.h b/include/cglm/simd/sse2/quat.h similarity index 96% rename from include/arch/simd/cglm-quat-simd.h rename to include/cglm/simd/sse2/quat.h index 212c04e..b3420a7 100644 --- a/include/arch/simd/cglm-quat-simd.h +++ b/include/cglm/simd/sse2/quat.h @@ -9,8 +9,8 @@ #define cglm_quat_simd_h #if defined( __SSE__ ) || defined( __SSE2__ ) -#include "../../cglm-common.h" -#include "cglm-intrin.h" +#include "../../common.h" +#include "../intrin.h" CGLM_INLINE void diff --git a/include/cglm-types.h b/include/cglm/types.h similarity index 100% rename from include/cglm-types.h rename to include/cglm/types.h diff --git a/include/cglm-util.h b/include/cglm/util.h similarity index 97% rename from include/cglm-util.h rename to include/cglm/util.h index 79dcb06..d1b62a2 100644 --- a/include/cglm-util.h +++ b/include/cglm/util.h @@ -18,7 +18,7 @@ #ifndef cglm_util_h #define cglm_util_h -#include "cglm-common.h" +#include "common.h" /*! * @brief get sign of 32 bit integer as +1 or -1 diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h new file mode 100644 index 0000000..41c1749 --- /dev/null +++ b/include/cglm/vec3-ext.h @@ -0,0 +1,163 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); + CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); + CGLM_INLINE bool glm_vec_eq(vec3 v, float val); + CGLM_INLINE bool glm_vec_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec_eq_all(vec3 v); + CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); + CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec_max(vec3 v); + CGLM_INLINE float glm_vec_min(vec3 v); + */ + +#ifndef cglm_vec3_ext_h +#define cglm_vec3_ext_h + +#include "common.h" +#include +#include +#include + +/*! + * @brief multiplies individual items, just for convenient like SIMD + * + * @param a vec1 + * @param b vec2 + * @param d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) + */ +CGLM_INLINE +void +glm_vec_mulv(vec3 a, vec3 b, vec3 d) { + d[0] = a[0] * b[0]; + d[1] = a[1] * b[1]; + d[2] = a[2] * b[2]; +} + +/*! + * @brief fill a vector with specified value + * + * @param val value + * @param d dest + */ +CGLM_INLINE +void +glm_vec_broadcast(float val, vec3 d) { + d[0] = d[1] = d[2] = val; +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec_eq(vec3 v, float val) { + return v[0] == val && v[0] == v[1] && v[0] == v[2]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec_eq_eps(vec4 v, float val) { + return fabsf(v[0] - val) <= FLT_EPSILON + && fabsf(v[1] - val) <= FLT_EPSILON + && fabsf(v[2] - val) <= FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param v vector + */ +CGLM_INLINE +bool +glm_vec_eq_all(vec3 v) { + return v[0] == v[1] && v[0] == v[2]; +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec_eqv(vec3 v1, vec3 v2) { + return v1[0] == v2[0] + && v1[1] == v2[1] + && v1[2] == v2[2]; +} + +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param v1 vector + * @param v2 vector + */ +CGLM_INLINE +bool +glm_vec_eqv_eps(vec3 v1, vec3 v2) { + return fabsf(v1[0] - v2[0]) <= FLT_EPSILON + && fabsf(v1[1] - v2[1]) <= FLT_EPSILON + && fabsf(v1[2] - v2[2]) <= FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec_max(vec3 v) { + float max; + + max = v[0]; + if (v[1] > max) + max = v[1]; + if (v[2] > max) + max = v[2]; + + return max; +} + +/*! + * @brief min value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec_min(vec3 v) { + float min; + + min = v[0]; + if (v[1] < min) + min = v[1]; + if (v[2] < min) + min = v[2]; + + return min; +} + +#endif /* cglm_vec3_ext_h */ diff --git a/include/cglm-vec.h b/include/cglm/vec3.h similarity index 56% rename from include/cglm-vec.h rename to include/cglm/vec3.h index 3a4a562..a64afd6 100644 --- a/include/cglm-vec.h +++ b/include/cglm/vec3.h @@ -13,11 +13,8 @@ /* Macros: glm_vec_dup(v, dest) - glm_vec4_dup3(v, dest) - glm_vec4_dup(v, dest) Functions: - vec3: CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); CGLM_INLINE float glm_vec_dot(vec3 a, vec3 b); CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); @@ -36,35 +33,17 @@ CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); CGLM_INLINE void glm_vec_proj(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_center(vec3 v1, vec3 v2, vec3 dest); - - vec4: - CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); - CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest); - CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); - CGLM_INLINE float glm_vec4_norm2(vec4 v); - CGLM_INLINE float glm_vec4_norm(vec4 vec); - CGLM_INLINE void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest); - CGLM_INLINE void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest); - CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest); - CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); - CGLM_INLINE void glm_vec4_flipsign(vec4 v); - CGLM_INLINE void glm_vec4_normalize(vec4 v); - CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); - CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); */ -#ifndef cglm_vec_h -#define cglm_vec_h +#ifndef cglm_vec3_h +#define cglm_vec3_h -#include "cglm-common.h" -#include "cglm-vec-ext.h" -#include "arch/simd/cglm-intrin.h" -#include "cglm-util.h" +#include "common.h" +#include "vec3-ext.h" +#include "util.h" /* DEPRECATED! use _copy, _ucopy versions */ -#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) -#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) -#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) +#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) /*! * @brief copy all members of [a] to [dest] @@ -80,39 +59,6 @@ glm_vec_copy(vec3 a, vec3 dest) { dest[2] = a[2]; } -/*! - * @brief copy first 3 members of [a] to [dest] - * - * @param[in] a source - * @param[out] dest destination - */ -CGLM_INLINE -void -glm_vec4_copy3(vec4 a, vec3 dest) { - dest[0] = a[0]; - dest[1] = a[1]; - dest[2] = a[2]; -} - -/*! - * @brief copy all members of [a] to [dest] - * - * @param[in] v source - * @param[out] dest destination - */ -CGLM_INLINE -void -glm_vec4_copy(vec4 v, vec4 dest) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_load_ps(v)); -#else - dest[0] = v[0]; - dest[1] = v[1]; - dest[2] = v[2]; - dest[3] = v[3]; -#endif -} - /*! * @brief vec3 dot product * @@ -127,20 +73,6 @@ glm_vec_dot(vec3 a, vec3 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } -/*! - * @brief vec4 dot product - * - * @param[in] a vector1 - * @param[in] b vector2 - * - * @return dot product - */ -CGLM_INLINE -float -glm_vec4_dot(vec4 a, vec4 b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; -} - /*! * @brief vec3 cross product * @@ -187,36 +119,6 @@ glm_vec_norm(vec3 vec) { return sqrtf(glm_vec_norm2(vec)); } -/*! - * @brief norm * norm (magnitude) of vec - * - * we can use this func instead of calling norm * norm, because it would call - * sqrtf fuction twice but with this func we can avoid func call, maybe this is - * not good name for this func - * - * @param[in] v vec4 - * - * @return norm * norm - */ -CGLM_INLINE -float -glm_vec4_norm2(vec4 v) { - return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; -} - -/*! - * @brief norm (magnitude) of vec4 - * - * @param[in] vec vector - * - * @return norm - */ -CGLM_INLINE -float -glm_vec4_norm(vec4 vec) { - return sqrtf(glm_vec4_norm2(vec)); -} - /*! * @brief add v2 vector to v1 vector store result in dest * @@ -232,28 +134,6 @@ glm_vec_add(vec3 v1, vec3 v2, vec3 dest) { dest[2] = v1[2] + v2[2]; } -/*! - * @brief add v2 vector to v1 vector store result in dest - * - * @param[in] v1 vector1 - * @param[in] v2 vector2 - * @param[out] dest destination vector - */ -CGLM_INLINE -void -glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_add_ps(_mm_load_ps(v1), - _mm_load_ps(v2))); -#else - dest[0] = v1[0] + v2[0]; - dest[1] = v1[1] + v2[1]; - dest[2] = v1[2] + v2[2]; - dest[3] = v1[3] + v2[3]; -#endif -} - /*! * @brief subtract v2 vector from v1 vector store result in dest * @@ -269,28 +149,6 @@ glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) { dest[2] = v1[2] - v2[2]; } -/*! - * @brief subtract v2 vector from v1 vector store result in dest - * - * @param[in] v1 vector1 - * @param[in] v2 vector2 - * @param[out] dest destination vector - */ -CGLM_INLINE -void -glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_sub_ps(_mm_load_ps(v1), - _mm_load_ps(v2))); -#else - dest[0] = v1[0] - v2[0]; - dest[1] = v1[1] - v2[1]; - dest[2] = v1[2] - v2[2]; - dest[3] = v1[3] - v2[3]; -#endif -} - /*! * @brief multiply/scale vec3 vector with scalar: result = v * s * @@ -306,28 +164,6 @@ glm_vec_scale(vec3 v, float s, vec3 dest) { dest[2] = v[2] * s; } -/*! - * @brief multiply/scale vec4 vector with scalar: result = v * s - * - * @param[in] v vector - * @param[in] s scalar - * @param[out] dest destination vector - */ -CGLM_INLINE -void -glm_vec4_scale(vec4 v, float s, vec4 dest) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_mul_ps(_mm_load_ps(v), - _mm_set1_ps(s))); -#else - dest[0] = v[0] * s; - dest[1] = v[1] * s; - dest[2] = v[2] * s; - dest[3] = v[3] * s; -#endif -} - /*! * @brief make vec3 vector scale as specified: result = unit(v) * s * @@ -349,27 +185,6 @@ glm_vec_scale_as(vec3 v, float s, vec3 dest) { glm_vec_scale(v, s / norm, dest); } -/*! - * @brief make vec4 vector scale as specified: result = unit(v) * s - * - * @param[in] v vector - * @param[in] s scalar - * @param[out] dest destination vector - */ -CGLM_INLINE -void -glm_vec4_scale_as(vec4 v, float s, vec4 dest) { - float norm; - norm = glm_vec4_norm(v); - - if (norm == 0) { - glm_vec4_copy(v, dest); - return; - } - - glm_vec4_scale(v, s / norm, dest); -} - /*! * @brief flip sign of all vec3 members * @@ -383,25 +198,6 @@ glm_vec_flipsign(vec3 v) { v[2] = -v[2]; } -/*! - * @brief flip sign of all vec4 members - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec4_flipsign(vec4 v) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), - _mm_set1_ps(-0.0f))); -#else - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; - v[3] = -v[3]; -#endif -} - /*! * @brief normalize vec3 and store result in same vec * @@ -422,26 +218,6 @@ glm_vec_normalize(vec3 v) { glm_vec_scale(v, 1.0f / norm, v); } -/*! - * @brief normalize vec4 and store result in same vec - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec4_normalize(vec4 v) { - float norm; - - norm = glm_vec4_norm(v); - - if (norm == 0.0f) { - v[0] = v[1] = v[2] = v[3] = 0.0f; - return; - } - - glm_vec4_scale(v, 1.0f / norm, v); -} - /*! * @brief normalize vec3 to dest * @@ -463,27 +239,6 @@ glm_vec_normalize_to(vec3 vec, vec3 dest) { glm_vec_scale(vec, 1.0f / norm, dest); } -/*! - * @brief normalize vec4 to dest - * - * @param[in] vec source - * @param[out] dest destination - */ -CGLM_INLINE -void -glm_vec4_normalize_to(vec4 vec, vec4 dest) { - float norm; - - norm = glm_vec4_norm(vec); - - if (norm == 0.0f) { - dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; - return; - } - - glm_vec4_scale(vec, 1.0f / norm, dest); -} - /*! * @brief angle betwen two vector * @@ -609,20 +364,4 @@ glm_vec_distance(vec3 v1, vec3 v2) { + glm_pow2(v2[2] - v1[2])); } -/** - * @brief distance between two vectors - * - * @param[in] v1 vector1 - * @param[in] v2 vector2 - * @return returns distance - */ -CGLM_INLINE -float -glm_vec4_distance(vec4 v1, vec4 v2) { - return sqrtf(glm_pow2(v2[0] - v1[0]) - + glm_pow2(v2[1] - v1[1]) - + glm_pow2(v2[2] - v1[2]) - + glm_pow2(v2[3] - v1[3])); -} - -#endif /* cglm_vec_h */ +#endif /* cglm_vec3_h */ diff --git a/include/cglm-vec-ext.h b/include/cglm/vec4-ext.h similarity index 54% rename from include/cglm-vec-ext.h rename to include/cglm/vec4-ext.h index ad6ecb4..0e6e59e 100644 --- a/include/cglm-vec-ext.h +++ b/include/cglm/vec4-ext.h @@ -11,18 +11,6 @@ /* Functions: - vec3: - CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); - CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); - CGLM_INLINE bool glm_vec_eq(vec3 v, float val); - CGLM_INLINE bool glm_vec_eq_eps(vec4 v, float val); - CGLM_INLINE bool glm_vec_eq_all(vec3 v); - CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); - CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); - CGLM_INLINE float glm_vec_max(vec3 v); - CGLM_INLINE float glm_vec_min(vec3 v); - - vec4: CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); @@ -34,30 +22,14 @@ CGLM_INLINE float glm_vec4_min(vec4 v); */ -#ifndef cglm_vec_ext_h -#define cglm_vec_ext_h +#ifndef cglm_vec4_ext_h +#define cglm_vec4_ext_h -#include "cglm-common.h" -#include "arch/simd/cglm-intrin.h" +#include "common.h" #include #include #include -/*! - * @brief multiplies individual items, just for convenient like SIMD - * - * @param a vec1 - * @param b vec2 - * @param d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) - */ -CGLM_INLINE -void -glm_vec_mulv(vec3 a, vec3 b, vec3 d) { - d[0] = a[0] * b[0]; - d[1] = a[1] * b[1]; - d[2] = a[2] * b[2]; -} - /*! * @brief multiplies individual items, just for convenient like SIMD * @@ -78,18 +50,6 @@ glm_vec4_mulv(vec4 a, vec4 b, vec4 d) { #endif } -/*! - * @brief fill a vector with specified value - * - * @param val value - * @param d dest - */ -CGLM_INLINE -void -glm_vec_broadcast(float val, vec3 d) { - d[0] = d[1] = d[2] = val; -} - /*! * @brief fill a vector with specified value * @@ -106,71 +66,6 @@ glm_vec4_broadcast(float val, vec4 d) { #endif } -/*! - * @brief check if vector is equal to value (without epsilon) - * - * @param v vector - * @param val value - */ -CGLM_INLINE -bool -glm_vec_eq(vec3 v, float val) { - return v[0] == val && v[0] == v[1] && v[0] == v[2]; -} - -/*! - * @brief check if vector is equal to value (with epsilon) - * - * @param v vector - * @param val value - */ -CGLM_INLINE -bool -glm_vec_eq_eps(vec4 v, float val) { - return fabsf(v[0] - val) <= FLT_EPSILON - && fabsf(v[1] - val) <= FLT_EPSILON - && fabsf(v[2] - val) <= FLT_EPSILON; -} - -/*! - * @brief check if vectors members are equal (without epsilon) - * - * @param v vector - */ -CGLM_INLINE -bool -glm_vec_eq_all(vec3 v) { - return v[0] == v[1] && v[0] == v[2]; -} - -/*! - * @brief check if vector is equal to another (without epsilon) - * - * @param v1 vector - * @param v2 vector - */ -CGLM_INLINE -bool -glm_vec_eqv(vec3 v1, vec3 v2) { - return v1[0] == v2[0] - && v1[1] == v2[1] - && v1[2] == v2[2]; -} - -/*! - * @brief check if vector is equal to another (with epsilon) - * - * @param v1 vector - * @param v2 vector - */ -CGLM_INLINE -bool -glm_vec_eqv_eps(vec3 v1, vec3 v2) { - return fabsf(v1[0] - v2[0]) <= FLT_EPSILON - && fabsf(v1[1] - v2[1]) <= FLT_EPSILON - && fabsf(v1[2] - v2[2]) <= FLT_EPSILON; -} - /*! * @brief check if vector is equal to value (without epsilon) * @@ -244,44 +139,6 @@ glm_vec4_eqv_eps(vec3 v1, vec3 v2) { && fabsf(v1[3] - v2[3]) <= FLT_EPSILON; } -/*! - * @brief max value of vector - * - * @param v vector - */ -CGLM_INLINE -float -glm_vec_max(vec3 v) { - float max; - - max = v[0]; - if (v[1] > max) - max = v[1]; - if (v[2] > max) - max = v[2]; - - return max; -} - -/*! - * @brief min value of vector - * - * @param v vector - */ -CGLM_INLINE -float -glm_vec_min(vec3 v) { - float min; - - min = v[0]; - if (v[1] < min) - min = v[1]; - if (v[2] < min) - min = v[2]; - - return min; -} - /*! * @brief max value of vector * @@ -316,4 +173,5 @@ glm_vec4_min(vec4 v) { return min; } -#endif /* cglm_vec_ext_h */ +#endif /* cglm_vec4_ext_h */ + diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h new file mode 100644 index 0000000..a883922 --- /dev/null +++ b/include/cglm/vec4.h @@ -0,0 +1,285 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot) + * all functions without suffix are vec3 functions + */ + +/* + Macros: + glm_vec4_dup3(v, dest) + glm_vec4_dup(v, dest) + + Functions: + CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); + CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest); + CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); + CGLM_INLINE float glm_vec4_norm2(vec4 v); + CGLM_INLINE float glm_vec4_norm(vec4 vec); + CGLM_INLINE void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_flipsign(vec4 v); + CGLM_INLINE void glm_vec4_normalize(vec4 v); + CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); + CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); + */ + +#ifndef cglm_vec4_h +#define cglm_vec4_h + +#include "common.h" +#include "vec4-ext.h" +#include "util.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) +#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) + +/*! + * @brief copy first 3 members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_copy3(vec4 a, vec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_copy(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_load_ps(v)); +#else + dest[0] = v[0]; + dest[1] = v[1]; + dest[2] = v[2]; + dest[3] = v[3]; +#endif +} + +/*! + * @brief vec4 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec4_dot(vec4 a, vec4 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +} + +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vec4 + * + * @return norm * norm + */ +CGLM_INLINE +float +glm_vec4_norm2(vec4 v) { + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; +} + +/*! + * @brief norm (magnitude) of vec4 + * + * @param[in] vec vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec4_norm(vec4 vec) { + return sqrtf(glm_vec4_norm2(vec)); +} + +/*! + * @brief add v2 vector to v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_add_ps(_mm_load_ps(v1), + _mm_load_ps(v2))); +#else + dest[0] = v1[0] + v2[0]; + dest[1] = v1[1] + v2[1]; + dest[2] = v1[2] + v2[2]; + dest[3] = v1[3] + v2[3]; +#endif +} + +/*! + * @brief subtract v2 vector from v1 vector store result in dest + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_sub_ps(_mm_load_ps(v1), + _mm_load_ps(v2))); +#else + dest[0] = v1[0] - v2[0]; + dest[1] = v1[1] - v2[1]; + dest[2] = v1[2] - v2[2]; + dest[3] = v1[3] - v2[3]; +#endif +} + +/*! + * @brief multiply/scale vec4 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_scale(vec4 v, float s, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, + _mm_mul_ps(_mm_load_ps(v), + _mm_set1_ps(s))); +#else + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; + dest[3] = v[3] * s; +#endif +} + +/*! + * @brief make vec4 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_scale_as(vec4 v, float s, vec4 dest) { + float norm; + norm = glm_vec4_norm(v); + + if (norm == 0) { + glm_vec4_copy(v, dest); + return; + } + + glm_vec4_scale(v, s / norm, dest); +} + +/*! + * @brief flip sign of all vec4 members + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_flipsign(vec4 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), + _mm_set1_ps(-0.0f))); +#else + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; + v[3] = -v[3]; +#endif +} + +/*! + * @brief normalize vec4 and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_normalize(vec4 v) { + float norm; + + norm = glm_vec4_norm(v); + + if (norm == 0.0f) { + v[0] = v[1] = v[2] = v[3] = 0.0f; + return; + } + + glm_vec4_scale(v, 1.0f / norm, v); +} + +/*! + * @brief normalize vec4 to dest + * + * @param[in] vec source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_normalize_to(vec4 vec, vec4 dest) { + float norm; + + norm = glm_vec4_norm(vec); + + if (norm == 0.0f) { + dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; + return; + } + + glm_vec4_scale(vec, 1.0f / norm, dest); +} + +/** + * @brief distance between two vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec4_distance(vec4 v1, vec4 v2) { + return sqrtf(glm_pow2(v2[0] - v1[0]) + + glm_pow2(v2[1] - v1[1]) + + glm_pow2(v2[2] - v1[2]) + + glm_pow2(v2[3] - v1[3])); +} + +#endif /* cglm_vec4_h */ diff --git a/include/cglm-version.h b/include/cglm/version.h similarity index 100% rename from include/cglm-version.h rename to include/cglm/version.h diff --git a/makefile.am b/makefile.am index 4ae93a1..f1dadfc 100644 --- a/makefile.am +++ b/makefile.am @@ -33,50 +33,62 @@ test_tests_LDFLAGS = $(checkLDFLAGS) test_tests_CFLAGS = $(checkCFLAGS) cglmdir=$(includedir)/cglm -cglm_HEADERS = include/cglm-version.h \ - include/cglm.h \ - include/cglm-call.h \ - include/cglm-cam.h \ - include/cglm-io.h \ - include/cglm-mat3.h \ - include/cglm-types.h \ - include/cglm-common.h \ - include/cglm-affine.h \ - include/cglm-vec.h \ - include/cglm-euler.h \ - include/cglm-util.h \ - include/cglm-quat.h \ - include/cglm-mat.h \ - include/cglm-affine-mat.h - -cglm_arch_simddir=$(includedir)/cglm/arch/simd/ -cglm_arch_simd_HEADERS = include/arch/simd/cglm-mat-simd-avx.h \ - include/arch/simd/cglm-affine-mat-avx.h \ - include/arch/simd/cglm-quat-simd.h \ - include/arch/simd/cglm-affine-mat-sse2.h \ - include/arch/simd/cglm-mat3-simd-sse2.h \ - include/arch/simd/cglm-mat-simd-sse2.h \ - include/arch/simd/cglm-intrin.h +cglm_HEADERS = include/cglm/version.h \ + include/cglm/cglm.h \ + include/cglm/call.h \ + include/cglm/cam.h \ + include/cglm/io.h \ + include/cglm/mat4.h \ + include/cglm/mat3.h \ + include/cglm/types.h \ + include/cglm/common.h \ + include/cglm/affine.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 cglm_calldir=$(includedir)/cglm/call -cglm_call_HEADERS = include/call/cglmc-euler.h \ - include/call/cglmc-quat.h \ - include/call/cglmc-cam.h \ - include/call/cglmc-io.h \ - include/call/cglmc-affine.h \ - include/call/cglmc-vec.h \ - include/call/cglmc-mat3.h \ - include/call/cglmc-mat.h +cglm_call_HEADERS = include/cglm/call/mat4.h \ + include/cglm/call/mat3.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 + +cglm_simddir=$(includedir)/cglm/simd +cglm_simd_HEADERS = include/cglm/simd/intrin.h + +cglm_simd_sse2dir=$(includedir)/cglm/simd/sse2 +cglm_simd_sse2_HEADERS = include/cglm/simd/sse2/affine.h \ + include/cglm/simd/sse2/mat4.h \ + include/cglm/simd/sse2/mat3.h \ + include/cglm/simd/sse2/quat.h + +cglm_simd_avxdir=$(includedir)/cglm/simd/avx +cglm_simd_avx_HEADERS = include/cglm/simd/avx/mat4.h \ + include/cglm/simd/avx/affine.h + +cglm_simd_neondir=$(includedir)/cglm/simd/neon +cglm_simd_neon_HEADERS = include/cglm/simd/neon/mat4.h libcglm_la_SOURCES=\ - src/cglm-euler.c \ - src/clgm-affine.c \ - src/cglm-io.c \ - src/cglm-quat.c \ - src/cglm-cam.c \ - src/cglm-vec.c \ - src/cglm-mat3.c \ - src/cglm-mat.c + src/euler.c \ + src/affine.c \ + src/io.c \ + src/quat.c \ + src/cam.c \ + src/vec3.c \ + src/vec4.c \ + src/mat3.c \ + src/mat4.c test_tests_SOURCES=\ test/src/test_common.c \ diff --git a/src/clgm-affine.c b/src/affine.c similarity index 96% rename from src/clgm-affine.c rename to src/affine.c index ec3768c..df591df 100644 --- a/src/clgm-affine.c +++ b/src/affine.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-cam.c b/src/cam.c similarity index 94% rename from src/cglm-cam.c rename to src/cam.c index e242eb8..0dcdc4b 100644 --- a/src/cglm-cam.c +++ b/src/cam.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-euler.c b/src/euler.c similarity index 93% rename from src/cglm-euler.c rename to src/euler.c index 399a6e9..5c945e2 100644 --- a/src/cglm-euler.c +++ b/src/euler.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-io.c b/src/io.c similarity index 92% rename from src/cglm-io.c rename to src/io.c index 9f36ec0..fb2b5a9 100644 --- a/src/cglm-io.c +++ b/src/io.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-mat3.c b/src/mat3.c similarity index 94% rename from src/cglm-mat3.c rename to src/mat3.c index 6ba4231..c39932d 100644 --- a/src/cglm-mat3.c +++ b/src/mat3.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-mat.c b/src/mat4.c similarity index 96% rename from src/cglm-mat.c rename to src/mat4.c index 9025f24..838b52d 100644 --- a/src/cglm-mat.c +++ b/src/mat4.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-quat.c b/src/quat.c similarity index 94% rename from src/cglm-quat.c rename to src/quat.c index 5ca75ab..b26d112 100644 --- a/src/cglm-quat.c +++ b/src/quat.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void diff --git a/src/cglm-vec.c b/src/vec3.c similarity index 59% rename from src/cglm-vec.c rename to src/vec3.c index 124bde5..09f05a1 100644 --- a/src/cglm-vec.c +++ b/src/vec3.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm.h" -#include "../include/cglm-call.h" +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" CGLM_EXPORT void @@ -14,30 +14,12 @@ glmc_vec_copy(vec3 a, vec3 dest) { glm_vec_copy(a, dest); } -CGLM_EXPORT -void -glmc_vec4_copy3(vec4 a, vec3 dest) { - glm_vec4_copy3(a, dest); -} - -CGLM_EXPORT -void -glmc_vec4_copy(vec4 v, vec4 dest) { - glm_vec4_copy(v, dest); -} - CGLM_EXPORT float glmc_vec_dot(vec3 a, vec3 b) { return glm_vec_dot(a, b); } -CGLM_EXPORT -float -glmc_vec4_dot(vec4 a, vec4 b) { - return glm_vec4_dot(a, b); -} - CGLM_EXPORT void glmc_vec_cross(vec3 a, vec3 b, vec3 d) { @@ -50,108 +32,54 @@ glmc_vec_norm(vec3 vec) { return glm_vec_norm(vec); } -CGLM_EXPORT -float -glmc_vec4_norm(vec4 vec) { - return glm_vec4_norm(vec); -} - CGLM_EXPORT void glmc_vec_normalize_to(vec3 vec, vec3 dest) { glm_vec_normalize_to(vec, dest); } -CGLM_EXPORT -void -glmc_vec4_normalize_to(vec4 vec, vec4 dest) { - glm_vec4_normalize_to(vec, dest); -} - CGLM_EXPORT void glmc_vec_normalize(vec3 v) { glm_vec_normalize(v); } -CGLM_EXPORT -void -glmc_vec4_normalize(vec4 v) { - glm_vec4_normalize(v); -} - CGLM_EXPORT float glmc_vec_norm2(vec3 vec) { return glm_vec_norm2(vec); } -CGLM_EXPORT -float -glmc_vec4_norm2(vec4 vec) { - return glm_vec4_norm2(vec); -} - CGLM_EXPORT void glmc_vec_add(vec3 v1, vec3 v2, vec3 dest) { glm_vec_add(v1, v2, dest); } -CGLM_EXPORT -void -glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_add(v1, v2, dest); -} - CGLM_EXPORT void glmc_vec_sub(vec3 v1, vec3 v2, vec3 dest) { glm_vec_sub(v1, v2, dest); } -CGLM_EXPORT -void -glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_sub(v1, v2, dest); -} - CGLM_EXPORT void glmc_vec_scale(vec3 v, float s, vec3 dest) { glm_vec_scale(v, s, dest); } -CGLM_EXPORT -void -glmc_vec4_scale(vec4 v, float s, vec4 dest) { - glm_vec4_scale(v, s, dest); -} - CGLM_EXPORT void glmc_vec_scale_as(vec3 v, float s, vec3 dest) { glm_vec_scale_as(v, s, dest); } -CGLM_EXPORT -void -glmc_vec4_scale_as(vec3 v, float s, vec3 dest) { - glm_vec4_scale_as(v, s, dest); -} - CGLM_EXPORT void glmc_vec_flipsign(vec3 v) { glm_vec_flipsign(v); } -CGLM_EXPORT -void -glmc_vec4_flipsign(vec4 v) { - glm_vec4_flipsign(v); -} - CGLM_EXPORT float glmc_vec_angle(vec3 v1, vec3 v2) { @@ -187,9 +115,3 @@ float glmc_vec_distance(vec3 v1, vec3 v2) { return glm_vec_distance(v1, v2); } - -CGLM_EXPORT -float -glmc_vec4_distance(vec4 v1, vec4 v2) { - return glm_vec4_distance(v1, v2); -} diff --git a/src/vec4.c b/src/vec4.c new file mode 100644 index 0000000..7d72d83 --- /dev/null +++ b/src/vec4.c @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_vec4_copy3(vec4 a, vec3 dest) { + glm_vec4_copy3(a, dest); +} + +CGLM_EXPORT +void +glmc_vec4_copy(vec4 v, vec4 dest) { + glm_vec4_copy(v, dest); +} + +CGLM_EXPORT +float +glmc_vec4_dot(vec4 a, vec4 b) { + return glm_vec4_dot(a, b); +} + +CGLM_EXPORT +float +glmc_vec4_norm(vec4 vec) { + return glm_vec4_norm(vec); +} + +CGLM_EXPORT +void +glmc_vec4_normalize_to(vec4 vec, vec4 dest) { + glm_vec4_normalize_to(vec, dest); +} + +CGLM_EXPORT +void +glmc_vec4_normalize(vec4 v) { + glm_vec4_normalize(v); +} + +CGLM_EXPORT +float +glmc_vec4_norm2(vec4 vec) { + return glm_vec4_norm2(vec); +} + +CGLM_EXPORT +void +glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest) { + glm_vec4_add(v1, v2, dest); +} + +CGLM_EXPORT +void +glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { + glm_vec4_sub(v1, v2, dest); +} + +CGLM_EXPORT +void +glmc_vec4_scale(vec4 v, float s, vec4 dest) { + glm_vec4_scale(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec4_scale_as(vec3 v, float s, vec3 dest) { + glm_vec4_scale_as(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec4_flipsign(vec4 v) { + glm_vec4_flipsign(v); +} + +CGLM_EXPORT +float +glmc_vec4_distance(vec4 v1, vec4 v2) { + return glm_vec4_distance(v1, v2); +} diff --git a/test/src/test_common.h b/test/src/test_common.h index fee9395..88cd335 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include void test_rand_mat4(mat4 dest); diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 1f9e96a..91e8fa5 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -18,6 +18,56 @@ x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 15.0 {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC} @@ -162,51 +212,6 @@ true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 12fd1b4..bed473d 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -16,141 +16,165 @@ {f46634e5-c098-41a0-afb3-45afb6a53593} - - {496b3b53-1258-4efa-87b2-4280ea82f87e} + + {b982cbd3-03d9-4557-bed8-8224e4d95945} - - {28919415-29bd-4edd-8ab1-1ec9a16e46f0} + + {6a2a4ebb-ac68-4ed6-a4a1-f6d2243814e9} - - {792cb1a9-bdc8-4f00-bfde-067750b0ab41} + + {4bcb64d3-e522-48f7-85ef-3ddfacf50874} + + + {ccf6244c-614c-4016-a5d9-8a78ffc7765a} + + + {8607b04c-6eb6-49af-8ac2-e534ba78bf76} + + + {fb97f276-fe14-47ba-8a9f-01032f065a19} - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include - - - include\call - - - include\call - - - include\call - - - include\call - - - include\call - - - include\call - - - include\call - - - include\call - - - include\arch\simd - - - include\arch\simd - - - include\arch\simd - - - include\arch\simd - - - include\arch\simd - - - include\arch\simd - - - include\arch\simd - - - src - - - include - - - - + src - - src - - - src - - - src - - - src - - - src - - - src - - + src src + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + + + src + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\simd\avx + + + include\cglm\simd\avx + + + include\cglm\simd\neon + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + \ No newline at end of file