swizzle.hpp
Go to the documentation of this file.
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 #ifndef GLM_GTC_swizzle
39 #define GLM_GTC_swizzle GLM_VERSION
40 
41 // Dependency:
42 #include "../glm.hpp"
43 #include "../gtc/type_precision.hpp"
44 
45 #if(defined(GLM_MESSAGES) && !defined(glm_ext))
46 # pragma message("GLM: GLM_GTC_swizzle extension included")
47 #endif
48 
49 namespace glm
50 {
53 
54  template <typename T, template <typename> class vecType>
55  T const & swizzle(
56  vecType<T> const & v,
57  comp x);
58 
59  template <typename T, template <typename> class vecType>
60  detail::tvec2<T> const & swizzle(
61  vecType<T> const & v,
62  comp x, comp y);
63 
64  template <typename T, template <typename> class vecType>
65  detail::tvec3<T> const & swizzle(
66  vecType<T> const & v,
67  comp x, comp y, comp z);
68 
69  template <typename T, template <typename> class vecType>
70  detail::tvec4<T> const & swizzle(
71  vecType<T> const & v,
72  comp x, comp y, comp z, comp w);
73 
74  template <typename T, template <typename> class vecType>
75  T & swizzle(
76  vecType<T> & v,
77  comp x);
78 
79  template <typename T, template <typename> class vecType>
80  detail::tref2<T> swizzle(
81  vecType<T> & v,
82  comp x, comp y);
83 
84  template <typename T, template <typename> class vecType>
85  detail::tref3<T> swizzle(
86  vecType<T> & v,
87  comp x, comp y, comp z);
88 
89  template <typename T, template <typename> class vecType>
90  detail::tref4<T> swizzle(
91  vecType<T> & v,
92  comp x, comp y, comp z, comp w);
93 
94 # define static_swizzle1_const(TYPE, SIZE) \
95  template <comp x> \
96  GLM_FUNC_QUALIFIER TYPE swizzle(detail::tvec##SIZE<TYPE> const & v) \
97  {return v[x];}
98 
99 # define static_swizzle1_ref(TYPE, SIZE) \
100  template <comp x> \
101  GLM_FUNC_QUALIFIER TYPE& swizzle(detail::tvec##SIZE<TYPE> & v) \
102  {return v[x];}
103 
104  static_swizzle1_ref(detail::float16, 2)
105  static_swizzle1_ref(detail::float16, 3)
106  static_swizzle1_ref(detail::float16, 4)
107  static_swizzle1_ref(detail::float32, 2)
108  static_swizzle1_ref(detail::float32, 3)
109  static_swizzle1_ref(detail::float32, 4)
110  static_swizzle1_ref(detail::float64, 2)
111  static_swizzle1_ref(detail::float64, 3)
112  static_swizzle1_ref(detail::float64, 4)
113 
114  static_swizzle1_ref(detail::int8, 2)
115  static_swizzle1_ref(detail::int8, 3)
116  static_swizzle1_ref(detail::int8, 4)
117  static_swizzle1_ref(detail::int16, 2)
118  static_swizzle1_ref(detail::int16, 3)
119  static_swizzle1_ref(detail::int16, 4)
120  static_swizzle1_ref(detail::int32, 2)
121  static_swizzle1_ref(detail::int32, 3)
122  static_swizzle1_ref(detail::int32, 4)
123  static_swizzle1_ref(detail::int64, 2)
124  static_swizzle1_ref(detail::int64, 3)
125  static_swizzle1_ref(detail::int64, 4)
126 
127  static_swizzle1_ref(detail::uint8, 2)
128  static_swizzle1_ref(detail::uint8, 3)
129  static_swizzle1_ref(detail::uint8, 4)
130  static_swizzle1_ref(detail::uint16, 2)
131  static_swizzle1_ref(detail::uint16, 3)
132  static_swizzle1_ref(detail::uint16, 4)
133  static_swizzle1_ref(detail::uint32, 2)
134  static_swizzle1_ref(detail::uint32, 3)
135  static_swizzle1_ref(detail::uint32, 4)
136  static_swizzle1_ref(detail::uint64, 2)
137  static_swizzle1_ref(detail::uint64, 3)
138  static_swizzle1_ref(detail::uint64, 4)
139 /*
140 # define static_swizzle2_const(TYPE) \
141  template <comp x, comp y> \
142  GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
143  {return TYPE(v[x], v[y]);}
144 
145 # define static_swizzle3_const(TYPE) \
146  template <comp x, comp y, comp z> \
147  GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
148  {return TYPE(v[x], v[y], v[z]);}
149 
150 # define static_swizzle4_const(TYPE) \
151  template <comp x, comp y, comp z, comp w> \
152  GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
153  {return TYPE(v[x], v[y], v[z], v[w]);}
154 */
155 
156 # define static_swizzle2_const(TYPE, SIZE) \
157  template <comp x, comp y> \
158  GLM_FUNC_QUALIFIER detail::tvec2<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
159  {return detail::tvec2<TYPE>(v[x], v[y]);}
160 
161 # define static_swizzle3_const(TYPE, SIZE) \
162  template <comp x, comp y, comp z> \
163  GLM_FUNC_QUALIFIER detail::tvec3<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
164  {return detail::tvec3<TYPE>(v[x], v[y], v[z]);}
165 
166 # define static_swizzle4_const(TYPE, SIZE) \
167  template <comp x, comp y, comp z, comp w> \
168  GLM_FUNC_QUALIFIER detail::tvec4<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
169  {return detail::tvec4<TYPE>(v[x], v[y], v[z], v[w]);}
170 
171 
172  static_swizzle2_const(glm::f16, 2)
173  static_swizzle2_const(glm::f16, 3)
174  static_swizzle2_const(glm::f16, 4)
175  static_swizzle2_const(glm::f32, 2)
176  static_swizzle2_const(glm::f32, 3)
177  static_swizzle2_const(glm::f32, 4)
178  static_swizzle2_const(glm::f64, 2)
179  static_swizzle2_const(glm::f64, 3)
180  static_swizzle2_const(glm::f64, 4)
181 
182  static_swizzle2_const(glm::i8, 2)
183  static_swizzle2_const(glm::i8, 3)
184  static_swizzle2_const(glm::i8, 4)
185  static_swizzle2_const(glm::i16, 2)
186  static_swizzle2_const(glm::i16, 3)
187  static_swizzle2_const(glm::i16, 4)
188  static_swizzle2_const(glm::i32, 2)
189  static_swizzle2_const(glm::i32, 3)
190  static_swizzle2_const(glm::i32, 4)
191  static_swizzle2_const(glm::i64, 2)
192  static_swizzle2_const(glm::i64, 3)
193  static_swizzle2_const(glm::i64, 4)
194 
195  static_swizzle2_const(glm::u8, 2)
196  static_swizzle2_const(glm::u8, 3)
197  static_swizzle2_const(glm::u8, 4)
198  static_swizzle2_const(glm::u16, 2)
199  static_swizzle2_const(glm::u16, 3)
200  static_swizzle2_const(glm::u16, 4)
201  static_swizzle2_const(glm::u32, 2)
202  static_swizzle2_const(glm::u32, 3)
203  static_swizzle2_const(glm::u32, 4)
204  static_swizzle2_const(glm::u64, 2)
205  static_swizzle2_const(glm::u64, 3)
206  static_swizzle2_const(glm::u64, 4)
207 
208  static_swizzle3_const(glm::f16, 2)
209  static_swizzle3_const(glm::f16, 3)
210  static_swizzle3_const(glm::f16, 4)
211  static_swizzle3_const(glm::f32, 2)
212  static_swizzle3_const(glm::f32, 3)
213  static_swizzle3_const(glm::f32, 4)
214  static_swizzle3_const(glm::f64, 2)
215  static_swizzle3_const(glm::f64, 3)
216  static_swizzle3_const(glm::f64, 4)
217 
218  static_swizzle3_const(glm::i8, 2)
219  static_swizzle3_const(glm::i8, 3)
220  static_swizzle3_const(glm::i8, 4)
221  static_swizzle3_const(glm::i16, 2)
222  static_swizzle3_const(glm::i16, 3)
223  static_swizzle3_const(glm::i16, 4)
224  static_swizzle3_const(glm::i32, 2)
225  static_swizzle3_const(glm::i32, 3)
226  static_swizzle3_const(glm::i32, 4)
227  static_swizzle3_const(glm::i64, 2)
228  static_swizzle3_const(glm::i64, 3)
229  static_swizzle3_const(glm::i64, 4)
230 
231  static_swizzle3_const(glm::u8, 2)
232  static_swizzle3_const(glm::u8, 3)
233  static_swizzle3_const(glm::u8, 4)
234  static_swizzle3_const(glm::u16, 2)
235  static_swizzle3_const(glm::u16, 3)
236  static_swizzle3_const(glm::u16, 4)
237  static_swizzle3_const(glm::u32, 2)
238  static_swizzle3_const(glm::u32, 3)
239  static_swizzle3_const(glm::u32, 4)
240  static_swizzle3_const(glm::u64, 2)
241  static_swizzle3_const(glm::u64, 3)
242  static_swizzle3_const(glm::u64, 4)
243 
244  static_swizzle4_const(glm::f16, 2)
245  static_swizzle4_const(glm::f16, 3)
246  static_swizzle4_const(glm::f16, 4)
247  static_swizzle4_const(glm::f32, 2)
248  static_swizzle4_const(glm::f32, 3)
249  static_swizzle4_const(glm::f32, 4)
250  static_swizzle4_const(glm::f64, 2)
251  static_swizzle4_const(glm::f64, 3)
252  static_swizzle4_const(glm::f64, 4)
253 
254  static_swizzle4_const(glm::i8, 2)
255  static_swizzle4_const(glm::i8, 3)
256  static_swizzle4_const(glm::i8, 4)
257  static_swizzle4_const(glm::i16, 2)
258  static_swizzle4_const(glm::i16, 3)
259  static_swizzle4_const(glm::i16, 4)
260  static_swizzle4_const(glm::i32, 2)
261  static_swizzle4_const(glm::i32, 3)
262  static_swizzle4_const(glm::i32, 4)
263  static_swizzle4_const(glm::i64, 2)
264  static_swizzle4_const(glm::i64, 3)
265  static_swizzle4_const(glm::i64, 4)
266 
267  static_swizzle4_const(glm::u8, 2)
268  static_swizzle4_const(glm::u8, 3)
269  static_swizzle4_const(glm::u8, 4)
270  static_swizzle4_const(glm::u16, 2)
271  static_swizzle4_const(glm::u16, 3)
272  static_swizzle4_const(glm::u16, 4)
273  static_swizzle4_const(glm::u32, 2)
274  static_swizzle4_const(glm::u32, 3)
275  static_swizzle4_const(glm::u32, 4)
276  static_swizzle4_const(glm::u64, 2)
277  static_swizzle4_const(glm::u64, 3)
278  static_swizzle4_const(glm::u64, 4)
279 
280 # define static_swizzle2_ref(TYPE, SIZE) \
281  template <glm::comp x, glm::comp y> \
282  GLM_FUNC_QUALIFIER glm::detail::tref2<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
283  {return glm::detail::tref2<TYPE>(v[x], v[y]);}
284 
285 # define static_swizzle3_ref(TYPE, SIZE) \
286  template <glm::comp x, glm::comp y, glm::comp z> \
287  GLM_FUNC_QUALIFIER glm::detail::tref3<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
288  {return glm::detail::tref3<TYPE>(v[x], v[y], v[z]);}
289 
290 # define static_swizzle4_ref(TYPE, SIZE) \
291  template <glm::comp x, glm::comp y, glm::comp z, glm::comp w> \
292  GLM_FUNC_QUALIFIER glm::detail::tref4<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
293  {return glm::detail::tref4<TYPE>(v[x], v[y], v[z], v[w]);}
294 
295  static_swizzle2_ref(glm::f16, 2)
296  static_swizzle2_ref(glm::f16, 3)
297  static_swizzle2_ref(glm::f16, 4)
298  static_swizzle2_ref(glm::f32, 2)
299  static_swizzle2_ref(glm::f32, 3)
300  static_swizzle2_ref(glm::f32, 4)
301  static_swizzle2_ref(glm::f64, 2)
302  static_swizzle2_ref(glm::f64, 3)
303  static_swizzle2_ref(glm::f64, 4)
304 
305  static_swizzle2_ref(glm::i8, 2)
306  static_swizzle2_ref(glm::i8, 3)
307  static_swizzle2_ref(glm::i8, 4)
308  static_swizzle2_ref(glm::i16, 2)
309  static_swizzle2_ref(glm::i16, 3)
310  static_swizzle2_ref(glm::i16, 4)
311  static_swizzle2_ref(glm::i32, 2)
312  static_swizzle2_ref(glm::i32, 3)
313  static_swizzle2_ref(glm::i32, 4)
314  static_swizzle2_ref(glm::i64, 2)
315  static_swizzle2_ref(glm::i64, 3)
316  static_swizzle2_ref(glm::i64, 4)
317 
318  static_swizzle2_ref(glm::u8, 2)
319  static_swizzle2_ref(glm::u8, 3)
320  static_swizzle2_ref(glm::u8, 4)
321  static_swizzle2_ref(glm::u16, 2)
322  static_swizzle2_ref(glm::u16, 3)
323  static_swizzle2_ref(glm::u16, 4)
324  static_swizzle2_ref(glm::u32, 2)
325  static_swizzle2_ref(glm::u32, 3)
326  static_swizzle2_ref(glm::u32, 4)
327  static_swizzle2_ref(glm::u64, 2)
328  static_swizzle2_ref(glm::u64, 3)
329  static_swizzle2_ref(glm::u64, 4)
330 
331  static_swizzle3_ref(glm::f16, 3)
332  static_swizzle3_ref(glm::f16, 4)
333  static_swizzle3_ref(glm::f32, 3)
334  static_swizzle3_ref(glm::f32, 4)
335  static_swizzle3_ref(glm::f64, 3)
336  static_swizzle3_ref(glm::f64, 4)
337 
338  static_swizzle3_ref(glm::i8, 3)
339  static_swizzle3_ref(glm::i8, 4)
340  static_swizzle3_ref(glm::i16, 3)
341  static_swizzle3_ref(glm::i16, 4)
342  static_swizzle3_ref(glm::i32, 3)
343  static_swizzle3_ref(glm::i32, 4)
344  static_swizzle3_ref(glm::i64, 3)
345  static_swizzle3_ref(glm::i64, 4)
346 
347  static_swizzle3_ref(glm::u8, 3)
348  static_swizzle3_ref(glm::u8, 4)
349  static_swizzle3_ref(glm::u16, 3)
350  static_swizzle3_ref(glm::u16, 4)
351  static_swizzle3_ref(glm::u32, 3)
352  static_swizzle3_ref(glm::u32, 4)
353  static_swizzle3_ref(glm::u64, 3)
354  static_swizzle3_ref(glm::u64, 4)
355 
356  static_swizzle4_ref(glm::f16, 4)
357  static_swizzle4_ref(glm::f32, 4)
358  static_swizzle4_ref(glm::f64, 4)
359 
360  static_swizzle4_ref(glm::i8, 4)
361  static_swizzle4_ref(glm::i16, 4)
362  static_swizzle4_ref(glm::i32, 4)
363  static_swizzle4_ref(glm::i64, 4)
364 
365  static_swizzle4_ref(glm::u8, 4)
366  static_swizzle4_ref(glm::u16, 4)
367  static_swizzle4_ref(glm::u32, 4)
368  static_swizzle4_ref(glm::u64, 4)
369 
371 }//namespace glm
372 
373 #include "swizzle.inl"
374 
375 #endif//GLM_GTC_swizzle