master
ブランチ master
VulkanExample / dep / include / glm / detail / qualifier.hpp
7 KB、289行 生 Blame 履歴
1#pragma once
2
3#include "setup.hpp"
4
5namespace glm
6{
7 /// Qualify GLM types in term of alignment (packed, aligned) and precision in term of ULPs (lowp, mediump, highp)
8 enum qualifier
9 {
10 packed_highp, ///< Typed data is tightly packed in memory and operations are executed with high precision in term of ULPs
11 packed_mediump, ///< Typed data is tightly packed in memory and operations are executed with medium precision in term of ULPs for higher performance
12 packed_lowp, ///< Typed data is tightly packed in memory and operations are executed with low precision in term of ULPs to maximize performance
13
14# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
15 aligned_highp, ///< Typed data is aligned in memory allowing SIMD optimizations and operations are executed with high precision in term of ULPs
16 aligned_mediump, ///< Typed data is aligned in memory allowing SIMD optimizations and operations are executed with high precision in term of ULPs for higher performance
17 aligned_lowp, // ///< Typed data is aligned in memory allowing SIMD optimizations and operations are executed with high precision in term of ULPs to maximize performance
18 aligned = aligned_highp, ///< By default aligned qualifier is also high precision
19# endif
20
21 highp = packed_highp, ///< By default highp qualifier is also packed
22 mediump = packed_mediump, ///< By default mediump qualifier is also packed
23 lowp = packed_lowp, ///< By default lowp qualifier is also packed
24 packed = packed_highp, ///< By default packed qualifier is also high precision
25
26# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE && defined(GLM_FORCE_DEFAULT_ALIGNED_GENTYPES)
27 defaultp = aligned_highp
28# else
29 defaultp = highp
30# endif
31 };
32
33 typedef qualifier precision;
34
35 template<length_t L, typename T, qualifier Q = defaultp> struct vec;
36 template<length_t C, length_t R, typename T, qualifier Q = defaultp> struct mat;
37 template<typename T, qualifier Q = defaultp> struct qua;
38
39 template <typename T, qualifier Q = defaultp> using tvec1 = vec<1, T, Q>;
40 template <typename T, qualifier Q = defaultp> using tvec2 = vec<2, T, Q>;
41 template <typename T, qualifier Q = defaultp> using tvec3 = vec<3, T, Q>;
42 template <typename T, qualifier Q = defaultp> using tvec4 = vec<4, T, Q>;
43 template <typename T, qualifier Q = defaultp> using tmat2x2 = mat<2, 2, T, Q>;
44 template <typename T, qualifier Q = defaultp> using tmat2x3 = mat<2, 3, T, Q>;
45 template <typename T, qualifier Q = defaultp> using tmat2x4 = mat<2, 4, T, Q>;
46 template <typename T, qualifier Q = defaultp> using tmat3x2 = mat<3, 2, T, Q>;
47 template <typename T, qualifier Q = defaultp> using tmat3x3 = mat<3, 3, T, Q>;
48 template <typename T, qualifier Q = defaultp> using tmat3x4 = mat<3, 4, T, Q>;
49 template <typename T, qualifier Q = defaultp> using tmat4x2 = mat<4, 2, T, Q>;
50 template <typename T, qualifier Q = defaultp> using tmat4x3 = mat<4, 3, T, Q>;
51 template <typename T, qualifier Q = defaultp> using tmat4x4 = mat<4, 4, T, Q>;
52 template <typename T, qualifier Q = defaultp> using tquat = qua<T, Q>;
53
54namespace detail
55{
56 template<glm::qualifier P>
57 struct is_aligned
58 {
59 static const bool value = false;
60 };
61
62# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
63 template<>
64 struct is_aligned<glm::aligned_lowp>
65 {
66 static const bool value = true;
67 };
68
69 template<>
70 struct is_aligned<glm::aligned_mediump>
71 {
72 static const bool value = true;
73 };
74
75 template<>
76 struct is_aligned<glm::aligned_highp>
77 {
78 static const bool value = true;
79 };
80# endif
81
82 template<length_t L, typename T, bool is_aligned>
83 struct storage
84 {
85 typedef struct type {
86 T data[L];
87 } type;
88 };
89
90 template<length_t L, typename T>
91 struct storage<L, T, true>
92 {
93 typedef struct alignas(L * sizeof(T)) type {
94 T data[L];
95 } type;
96 };
97
98 template<typename T>
99 struct storage<3, T, true>
100 {
101 typedef struct alignas(4 * sizeof(T)) type {
102 T data[4];
103 } type;
104 };
105
106# if GLM_ARCH & GLM_ARCH_SSE2_BIT
107 template<>
108 struct storage<4, float, true>
109 {
110 typedef glm_f32vec4 type;
111 };
112
113 template<>
114 struct storage<4, int, true>
115 {
116 typedef glm_i32vec4 type;
117 };
118
119 template<>
120 struct storage<4, unsigned int, true>
121 {
122 typedef glm_u32vec4 type;
123 };
124
125 template<>
126 struct storage<3, float, true>
127 {
128 typedef glm_f32vec4 type;
129 };
130
131 template<>
132 struct storage<3, int, true>
133 {
134 typedef glm_i32vec4 type;
135 };
136
137 template<>
138 struct storage<3, unsigned int, true>
139 {
140 typedef glm_u32vec4 type;
141 };
142
143 template<>
144 struct storage<2, double, true>
145 {
146 typedef glm_f64vec2 type;
147 };
148
149 template<>
150 struct storage<2, detail::int64, true>
151 {
152 typedef glm_i64vec2 type;
153 };
154
155 template<>
156 struct storage<2, detail::uint64, true>
157 {
158 typedef glm_u64vec2 type;
159 };
160
161
162 template<>
163 struct storage<3, detail::uint64, true>
164 {
165 typedef glm_u64vec2 type;
166 };
167
168 template<>
169 struct storage<4, double, true>
170 {
171# if (GLM_ARCH & GLM_ARCH_AVX_BIT)
172 typedef glm_f64vec4 type;
173# else
174 struct type
175 {
176 glm_f64vec2 data[2];
177 GLM_CONSTEXPR glm_f64vec2 getv(int i) const {
178 return data[i];
179 }
180 GLM_CONSTEXPR void setv(int i, const glm_f64vec2& v) {
181 data[i] = v;
182 }
183 };
184# endif
185 };
186
187
188 template<>
189 struct storage<3, double, true> : public storage<4, double, true>
190 {};
191
192# endif
193
194# if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
195 template<>
196 struct storage<4, detail::int64, true>
197 {
198 typedef glm_i64vec4 type;
199 };
200
201 template<>
202 struct storage<4, detail::uint64, true>
203 {
204 typedef glm_u64vec4 type;
205 };
206# endif
207
208# if GLM_ARCH & GLM_ARCH_NEON_BIT
209 template<>
210 struct storage<4, float, true>
211 {
212 typedef glm_f32vec4 type;
213 };
214
215 template<>
216 struct storage<3, float, true> : public storage<4, float, true>
217 {};
218
219 template<>
220 struct storage<4, int, true>
221 {
222 typedef glm_i32vec4 type;
223 };
224
225 template<>
226 struct storage<3, int, true> : public storage<4, int, true>
227 {};
228
229 template<>
230 struct storage<4, unsigned int, true>
231 {
232 typedef glm_u32vec4 type;
233 };
234/* TODO: Duplicate ?
235 template<>
236 struct storage<3, unsigned int, true> : public storage<4, unsigned int, true>
237 {};
238
239 template<>
240 struct storage<3, double, true>
241 {
242 typedef struct alignas(4 * sizeof(double)) type {
243 double data[4];
244 } type;
245 };
246*/
247# endif
248
249 enum genTypeEnum
250 {
251 GENTYPE_VEC,
252 GENTYPE_MAT,
253 GENTYPE_QUAT
254 };
255
256 template <typename genType>
257 struct genTypeTrait
258 {};
259
260 template <length_t C, length_t R, typename T>
261 struct genTypeTrait<mat<C, R, T> >
262 {
263 static const genTypeEnum GENTYPE = GENTYPE_MAT;
264 };
265
266 template<typename genType, genTypeEnum type>
267 struct init_gentype
268 {
269 };
270
271 template<typename genType>
272 struct init_gentype<genType, GENTYPE_QUAT>
273 {
274 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genType identity()
275 {
276 return genType(1, 0, 0, 0);
277 }
278 };
279
280 template<typename genType>
281 struct init_gentype<genType, GENTYPE_MAT>
282 {
283 GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genType identity()
284 {
285 return genType(1);
286 }
287 };
288}//namespace detail
289}//namespace glm