From f708240ad341963c8c5dcee0ad411d53e745b621 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 11 Sep 2016 13:07:39 +0300 Subject: [PATCH] update mat4 and mat4 mul because m1 and m2 could be same matrix e.g dest = m1*m1 --- include/cglm-mat.h | 26 +++++++++++++++++++++----- include/cglm.h | 8 ++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/cglm-mat.h b/include/cglm-mat.h index 330cd83..566adf9 100644 --- a/include/cglm-mat.h +++ b/include/cglm-mat.h @@ -33,14 +33,30 @@ CGLM_INLINE void -glm_mat_mul4(float * __restrict m1, - float * __restrict m2, - float * __restrict dest) { +glm_mat_mul4(mat4 m1, mat4 m2, mat4 dest) { + float * __restrict d; + float * __restrict l; + + d = (float *)dest; + l = (float *)m1; + + if (m1 != m2) { + float * __restrict r; + + r = (float *)m2; + #if defined( __SSE__ ) || defined( __SSE2__ ) - CGLM_MAT_MUL_SSE_4x4f(m1, m2, dest); + CGLM_MAT_MUL_SSE_4x4f(l, r, d); #else - glm_mat_mul4_impl(m1, m2, dest); + glm_mat_mul4_impl(l, r, d); #endif + } else { +#if defined( __SSE__ ) || defined( __SSE2__ ) + CGLM_MAT_MUL_SSE_4x4f(l, l, d); +#else + glm_mat_mul4_impl(l, l, d); +#endif + } } #endif /* cglm_mat_h */ diff --git a/include/cglm.h b/include/cglm.h index 27f8ea3..024dff6 100644 --- a/include/cglm.h +++ b/include/cglm.h @@ -14,13 +14,13 @@ typedef float vec3[3]; typedef float vec4[4]; typedef float mat3[3]; -typedef float mat4[16]; +typedef vec4 mat4[4]; CGLM_INLINE void -glm_mat_mul4(float * __restrict m1, - float * __restrict m2, - float * __restrict dest); +glm_mat_mul4(mat4 m1, + mat4 m2, + mat4 dest); #include "cglm-vec.h" #include "cglm-mat.h"