1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_types_struct_h
#define cglm_types_struct_h
#include "types.h"
/*
* Anonymous structs are available since C11, but we'd like to be compatible
* with C99 and C89 too. So let's figure out if we should be using them or not.
* It's simply a convenience feature, you can e.g. build the library with
* anonymous structs and your application without them and they'll still be
* compatible, cglm doesn't use the anonymous structs internally.
*/
#ifndef CGLM_USE_ANONYMOUS_STRUCT
/* If the user doesn't explicitly specify if they want anonymous structs or
* not, then we'll try to intuit an appropriate choice. */
# if defined(CGLM_NO_ANONYMOUS_STRUCT)
/* The user has defined CGLM_NO_ANONYMOUS_STRUCT. This used to be the
* only #define governing the use of anonymous structs, so for backward
* compatibility, we still honor that choice and disable them. */
# define CGLM_USE_ANONYMOUS_STRUCT 0
/* Disable anonymous structs if strict ANSI mode is enabled for C89 or C99 */
# elif defined(__STRICT_ANSI__) && \
(!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L))
/* __STRICT_ANSI__ is defined and we're in C89
* or C99 mode (C11 or later not detected) */
# define CGLM_USE_ANONYMOUS_STRUCT 0
# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
/* We're compiling for C11 or this is the MSVC compiler. In either
* case, anonymous structs are available, so use them. */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
/* GCC 4.6 and onwards support anonymous structs as an extension */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# elif defined(__clang__) && __clang_major__ >= 3
/* Clang 3.0 and onwards support anonymous structs as an extension */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* Visual Studio 2015 */
/* We can support anonymous structs
* since Visual Studio 2015 or 2017 (1910) maybe? */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# else
/* Otherwise, we're presumably building for C99 or C89 and can't rely
* on anonymous structs being available. Turn them off. */
# define CGLM_USE_ANONYMOUS_STRUCT 0
# endif
#endif
typedef union vec2s {
vec2 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
};
struct {
float r;
float i;
};
struct {
float u;
float v;
};
struct {
float s;
float t;
};
#endif
} vec2s;
typedef union vec3s {
vec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
float z;
};
struct {
float r;
float g;
float b;
};
#endif
} vec3s;
typedef union ivec2s {
ivec2 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
};
struct {
int r;
int i;
};
struct {
int u;
int v;
};
struct {
int s;
int t;
};
#endif
} ivec2s;
typedef union ivec3s {
ivec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
int z;
};
struct {
int r;
int g;
int b;
};
#endif
} ivec3s;
typedef union ivec4s {
ivec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
int z;
int w;
};
struct {
int r;
int g;
int b;
int a;
};
#endif
} ivec4s;
typedef union CGLM_ALIGN_IF(16) vec4s {
vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
float z;
float w;
};
struct {
float r;
float g;
float b;
float a;
};
#endif
} vec4s;
typedef union CGLM_ALIGN_IF(16) versors {
vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
float z;
float w;
};
struct {
vec3s imag;
float real;
};
#endif
} versors;
typedef union mat2s {
mat2 raw;
vec2s col[2];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
};
#endif
} mat2s;
typedef union mat2x3s {
mat2x3 raw;
vec3s col[2]; /* [col (2), row (3)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
};
#endif
} mat2x3s;
typedef union mat2x4s {
mat2x4 raw;
vec4s col[2]; /* [col (2), row (4)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
};
#endif
} mat2x4s;
typedef union mat3s {
mat3 raw;
vec3s col[3];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
float m20, m21, m22;
};
#endif
} mat3s;
typedef union mat3x2s {
mat3x2 raw;
vec2s col[3]; /* [col (3), row (2)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
float m20, m21;
};
#endif
} mat3x2s;
typedef union mat3x4s {
mat3x4 raw;
vec4s col[3]; /* [col (3), row (4)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
};
#endif
} mat3x4s;
typedef union CGLM_ALIGN_MAT mat4s {
mat4 raw;
vec4s col[4];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
};
#endif
} mat4s;
typedef union mat4x2s {
mat4x2 raw;
vec2s col[4]; /* [col (4), row (2)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
float m20, m21;
float m30, m31;
};
#endif
} mat4x2s;
typedef union mat4x3s {
mat4x3 raw;
vec3s col[4]; /* [col (4), row (3)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
float m20, m21, m22;
float m30, m31, m32;
};
#endif
} mat4x3s;
#endif /* cglm_types_struct_h */
|