Skip to content

Commit b4efcef

Browse files
committed
drop glm__memcpy, glm__memset and glm__memzero
* implement mat3_zero and mat4_zero functions * copy matrix items manually in ucopy functions
1 parent 0d2e5a9 commit b4efcef

File tree

6 files changed

+69
-37
lines changed

6 files changed

+69
-37
lines changed

docs/source/mat3.rst

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Functions:
2121
1. :c:func:`glm_mat3_copy`
2222
#. :c:func:`glm_mat3_identity`
2323
#. :c:func:`glm_mat3_identity_array`
24+
#. :c:func:`glm_mat3_zero`
2425
#. :c:func:`glm_mat3_mul`
2526
#. :c:func:`glm_mat3_transpose_to`
2627
#. :c:func:`glm_mat3_transpose`
@@ -60,6 +61,13 @@ Functions documentation
6061
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
6162
| *[in]* **count** count of matrices
6263
64+
.. c:function:: void glm_mat3_zero(mat3 mat)
65+
66+
make given matrix zero
67+
68+
Parameters:
69+
| *[in,out]* **mat** matrix to
70+
6371
.. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest)
6472
6573
multiply m1 and m2 to dest

docs/source/mat4.rst

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Functions:
2626
#. :c:func:`glm_mat4_copy`
2727
#. :c:func:`glm_mat4_identity`
2828
#. :c:func:`glm_mat4_identity_array`
29+
#. :c:func:`glm_mat4_zero`
2930
#. :c:func:`glm_mat4_pick3`
3031
#. :c:func:`glm_mat4_pick3t`
3132
#. :c:func:`glm_mat4_ins3`
@@ -81,6 +82,13 @@ Functions documentation
8182
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
8283
| *[in]* **count** count of matrices
8384
85+
.. c:function:: void glm_mat4_zero(mat4 mat)
86+
87+
make given matrix zero
88+
89+
Parameters:
90+
| *[in,out]* **mat** matrix to
91+
8492
.. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
8593
8694
copy upper-left of mat4 to mat3

include/cglm/cam.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ glm_frustum(float left,
8484
mat4 dest) {
8585
float rl, tb, fn, nv;
8686

87-
glm__memzero(float, dest, sizeof(mat4));
87+
glm_mat4_zero(dest);
8888

8989
rl = 1.0f / (right - left);
9090
tb = 1.0f / (top - bottom);
@@ -122,7 +122,7 @@ glm_ortho(float left,
122122
mat4 dest) {
123123
float rl, tb, fn;
124124

125-
glm__memzero(float, dest, sizeof(mat4));
125+
glm_mat4_zero(dest);
126126

127127
rl = 1.0f / (right - left);
128128
tb = 1.0f / (top - bottom);
@@ -259,7 +259,7 @@ glm_perspective(float fovy,
259259
mat4 dest) {
260260
float f, fn;
261261

262-
glm__memzero(float, dest, sizeof(mat4));
262+
glm_mat4_zero(dest);
263263

264264
f = 1.0f / tanf(fovy * 0.5f);
265265
fn = 1.0f / (nearVal - farVal);

include/cglm/common.h

-28
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,6 @@
2626
# define CGLM_INLINE static inline __attribute((always_inline))
2727
#endif
2828

29-
#define glm__memcpy(type, dest, src, size) \
30-
do { \
31-
type *srci; \
32-
type *srci_end; \
33-
type *desti; \
34-
\
35-
srci = (type *)src; \
36-
srci_end = (type *)((char *)srci + size); \
37-
desti = (type *)dest; \
38-
\
39-
while (srci != srci_end) \
40-
*desti++ = *srci++; \
41-
} while (0)
42-
43-
#define glm__memset(type, dest, size, val) \
44-
do { \
45-
type *desti; \
46-
type *desti_end; \
47-
\
48-
desti = (type *)dest; \
49-
desti_end = (type *)((char *)desti + size); \
50-
\
51-
while (desti != desti_end) \
52-
*desti++ = val; \
53-
} while (0)
54-
55-
#define glm__memzero(type, dest, size) glm__memset(type, dest, size, 0)
56-
5729
#include "types.h"
5830
#include "simd/intrin.h"
5931

include/cglm/mat3.h

+24-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest);
1818
CGLM_INLINE void glm_mat3_identity(mat3 mat);
1919
CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count);
20+
CGLM_INLINE void glm_mat3_zero(mat3 mat);
2021
CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest);
2122
CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest);
2223
CGLM_INLINE void glm_mat3_transpose(mat3 m);
@@ -65,7 +66,17 @@
6566
CGLM_INLINE
6667
void
6768
glm_mat3_copy(mat3 mat, mat3 dest) {
68-
glm__memcpy(float, dest, mat, sizeof(mat3));
69+
dest[0][0] = mat[0][0];
70+
dest[0][1] = mat[0][1];
71+
dest[0][2] = mat[0][2];
72+
73+
dest[1][0] = mat[1][0];
74+
dest[1][1] = mat[1][1];
75+
dest[1][2] = mat[1][2];
76+
77+
dest[2][0] = mat[2][0];
78+
dest[2][1] = mat[2][1];
79+
dest[2][2] = mat[2][2];
6980
}
7081

7182
/*!
@@ -108,6 +119,18 @@ glm_mat3_identity_array(mat3 * __restrict mat, size_t count) {
108119
}
109120
}
110121

122+
/*!
123+
* @brief make given matrix zero.
124+
*
125+
* @param[in, out] mat matrix
126+
*/
127+
CGLM_INLINE
128+
void
129+
glm_mat3_zero(mat3 mat) {
130+
CGLM_ALIGN_MAT mat3 t = GLM_MAT3_ZERO_INIT;
131+
glm_mat3_copy(t, mat);
132+
}
133+
111134
/*!
112135
* @brief multiply m1 and m2 to dest
113136
*

include/cglm/mat4.h

+26-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest);
2323
CGLM_INLINE void glm_mat4_identity(mat4 mat);
2424
CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count);
25+
CGLM_INLINE void glm_mat4_zero(mat4 mat);
2526
CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest);
2627
CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest);
2728
CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest);
@@ -31,6 +32,7 @@
3132
CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest);
3233
CGLM_INLINE float glm_mat4_trace(mat4 m);
3334
CGLM_INLINE float glm_mat4_trace3(mat4 m);
35+
CGLM_INLINE void glm_mat4_quat(mat4 m, versor dest) ;
3436
CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest);
3537
CGLM_INLINE void glm_mat4_transpose(mat4 m);
3638
CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s);
@@ -40,6 +42,7 @@
4042
CGLM_INLINE void glm_mat4_inv_fast(mat4 mat, mat4 dest);
4143
CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2);
4244
CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2);
45+
CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c);
4346
*/
4447

4548
#ifndef cglm_mat_h
@@ -98,7 +101,15 @@
98101
CGLM_INLINE
99102
void
100103
glm_mat4_ucopy(mat4 mat, mat4 dest) {
101-
glm__memcpy(float, dest, mat, sizeof(mat4));
104+
dest[0][0] = mat[0][0]; dest[1][0] = mat[1][0];
105+
dest[0][1] = mat[0][1]; dest[1][1] = mat[1][1];
106+
dest[0][2] = mat[0][2]; dest[1][2] = mat[1][2];
107+
dest[0][3] = mat[0][3]; dest[1][3] = mat[1][3];
108+
109+
dest[2][0] = mat[2][0]; dest[3][0] = mat[3][0];
110+
dest[2][1] = mat[2][1]; dest[3][1] = mat[3][1];
111+
dest[2][2] = mat[2][2]; dest[3][2] = mat[3][2];
112+
dest[2][3] = mat[2][3]; dest[3][3] = mat[3][3];
102113
}
103114

104115
/*!
@@ -168,6 +179,18 @@ glm_mat4_identity_array(mat4 * __restrict mat, size_t count) {
168179
}
169180
}
170181

182+
/*!
183+
* @brief make given matrix zero.
184+
*
185+
* @param[in, out] mat matrix
186+
*/
187+
CGLM_INLINE
188+
void
189+
glm_mat4_zero(mat4 mat) {
190+
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_ZERO_INIT;
191+
glm_mat4_copy(t, mat);
192+
}
193+
171194
/*!
172195
* @brief copy upper-left of mat4 to mat3
173196
*
@@ -474,10 +497,8 @@ glm_mat4_transpose(mat4 m) {
474497
glm_mat4_transp_sse2(m, m);
475498
#else
476499
mat4 d;
477-
478500
glm_mat4_transpose_to(m, d);
479-
480-
glm__memcpy(float, m, d, sizeof(mat4));
501+
glm_mat4_ucopy(d, m);
481502
#endif
482503
}
483504

@@ -682,7 +703,7 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) {
682703
*
683704
* rmc stands for Row * Matrix * Column
684705
*
685-
* the result is scalar because S * M = Matrix1x4 (row vector),
706+
* the result is scalar because R * M = Matrix1x4 (row vector),
686707
* then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar)
687708
*
688709
* @param[in] r row vector or matrix1x4

0 commit comments

Comments
 (0)