0.9.6
type_vec4.hpp
Go to the documentation of this file.
1 
33 #pragma once
34 
35 //#include "../fwd.hpp"
36 #include "setup.hpp"
37 #include "type_vec.hpp"
38 #ifdef GLM_SWIZZLE
39 # if GLM_HAS_ANONYMOUS_UNION
40 # include "_swizzle.hpp"
41 # else
42 # include "_swizzle_func.hpp"
43 # endif
44 #endif //GLM_SWIZZLE
45 #include <cstddef>
46 
47 namespace glm{
48 namespace detail
49 {
50  template <typename T>
51  struct simd
52  {
53  typedef T type[4];
54  };
55 
56 # define GLM_NOT_BUGGY_VC32BITS !(GLM_MODEL == GLM_MODEL_32 && GLM_COMPILER & GLM_COMPILER_VC && GLM_COMPILER < GLM_COMPILER_VC2013)
57 
58 # if GLM_ARCH & GLM_ARCH_SSE2 && GLM_NOT_BUGGY_VC32BITS
59  template <>
60  struct simd<float>
61  {
62  typedef __m128 type;
63  };
64 
65  template <>
66  struct simd<int>
67  {
68  typedef __m128i type;
69  };
70 
71  template <>
72  struct simd<unsigned int>
73  {
74  typedef __m128i type;
75  };
76 # endif
77 
78 # if GLM_ARCH & GLM_ARCH_AVX && GLM_NOT_BUGGY_VC32BITS
79  template <>
80  struct simd<double>
81  {
82  typedef __m256d type;
83  };
84 # endif
85 
86 # if GLM_ARCH & GLM_ARCH_AVX2 && GLM_NOT_BUGGY_VC32BITS
87  template <>
88  struct simd<int64>
89  {
90  typedef __m256i type;
91  };
92 
93  template <>
94  struct simd<uint64>
95  {
96  typedef __m256i type;
97  };
98 # endif
99 
100 }//namespace detail
101 
102  template <typename T, precision P = defaultp>
103  struct tvec4
104  {
106  // Implementation detail
107 
108  typedef tvec4<T, P> type;
109  typedef tvec4<bool, P> bool_type;
110  typedef T value_type;
111 
113  // Data
114 
115 # if GLM_HAS_ANONYMOUS_UNION
116  union
117  {
118  typename detail::simd<T>::type data;
119  struct { T r, g, b, a; };
120  struct { T s, t, p, q; };
121  struct { T x, y, z, w;};
122 
123 # ifdef GLM_SWIZZLE
124  _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, x, y, z, w)
125  _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, r, g, b, a)
126  _GLM_SWIZZLE4_2_MEMBERS(T, P, tvec2, s, t, p, q)
127  _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, x, y, z, w)
128  _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, r, g, b, a)
129  _GLM_SWIZZLE4_3_MEMBERS(T, P, tvec3, s, t, p, q)
130  _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, x, y, z, w)
131  _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, r, g, b, a)
132  _GLM_SWIZZLE4_4_MEMBERS(T, P, tvec4, s, t, p, q)
133 # endif//GLM_SWIZZLE
134  };
135 # else
136  union { T x, r, s; };
137  union { T y, g, t; };
138  union { T z, b, p; };
139  union { T w, a, q; };
140 
141 # ifdef GLM_SWIZZLE
142  GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, tvec4, tvec2, tvec3, tvec4)
143 # endif//GLM_SWIZZLE
144 # endif//GLM_LANG
145 
147  // Component accesses
148 
149 # ifdef GLM_FORCE_SIZE_FUNC
150  typedef size_t size_type;
152  GLM_FUNC_DECL GLM_CONSTEXPR size_type size() const;
153 
154  GLM_FUNC_DECL T & operator[](size_type i);
155  GLM_FUNC_DECL T const & operator[](size_type i) const;
156 # else
157  typedef length_t length_type;
159  GLM_FUNC_DECL GLM_CONSTEXPR length_type length() const;
160 
161  GLM_FUNC_DECL T & operator[](length_type i);
162  GLM_FUNC_DECL T const & operator[](length_type i) const;
163 # endif//GLM_FORCE_SIZE_FUNC
164 
166  // Implicit basic constructors
167 
168  GLM_FUNC_DECL tvec4();
169  template <precision Q>
170  GLM_FUNC_DECL tvec4(tvec4<T, Q> const & v);
171 
173  // Explicit basic constructors
174 
175  GLM_FUNC_DECL explicit tvec4(ctor);
176  GLM_FUNC_DECL explicit tvec4(T s);
177  GLM_FUNC_DECL tvec4(T a, T b, T c, T d);
178  GLM_FUNC_DECL ~tvec4(){}
179 
181  // Conversion scalar constructors
182 
184  template <typename A, typename B, typename C, typename D>
185  GLM_FUNC_DECL tvec4(A a, B b, C c, D d);
186  template <typename A, typename B, typename C, typename D>
187  GLM_FUNC_DECL tvec4(tvec1<A, P> const & a, tvec1<B, P> const & b, tvec1<C, P> const & c, tvec1<D, P> const & d);
188 
190  // Conversion vector constructors
191 
193  template <typename A, typename B, typename C, precision Q>
194  GLM_FUNC_DECL explicit tvec4(tvec2<A, Q> const & a, B b, C c);
196  template <typename A, typename B, typename C, precision Q>
197  GLM_FUNC_DECL explicit tvec4(tvec2<A, Q> const & a, tvec1<B, Q> const & b, tvec1<C, Q> const & c);
199  template <typename A, typename B, typename C, precision Q>
200  GLM_FUNC_DECL explicit tvec4(A a, tvec2<B, Q> const & b, C c);
202  template <typename A, typename B, typename C, precision Q>
203  GLM_FUNC_DECL explicit tvec4(tvec1<A, Q> const & a, tvec2<B, Q> const & b, tvec1<C, Q> const & c);
205  template <typename A, typename B, typename C, precision Q>
206  GLM_FUNC_DECL explicit tvec4(A a, B b, tvec2<C, Q> const & c);
208  template <typename A, typename B, typename C, precision Q>
209  GLM_FUNC_DECL explicit tvec4(tvec1<A, Q> const & a, tvec1<B, Q> const & b, tvec2<C, Q> const & c);
211  template <typename A, typename B, precision Q>
212  GLM_FUNC_DECL explicit tvec4(tvec3<A, Q> const & a, B b);
214  template <typename A, typename B, precision Q>
215  GLM_FUNC_DECL explicit tvec4(tvec3<A, Q> const & a, tvec1<B, Q> const & b);
217  template <typename A, typename B, precision Q>
218  GLM_FUNC_DECL explicit tvec4(A a, tvec3<B, Q> const & b);
220  template <typename A, typename B, precision Q>
221  GLM_FUNC_DECL explicit tvec4(tvec1<A, Q> const & a, tvec3<B, Q> const & b);
223  template <typename A, typename B, precision Q>
224  GLM_FUNC_DECL explicit tvec4(tvec2<A, Q> const & a, tvec2<B, Q> const & b);
225 
226 # ifdef GLM_FORCE_EXPLICIT_CTOR
227  template <typename U, precision Q>
229  GLM_FUNC_DECL explicit tvec4(tvec4<U, Q> const & v);
230 # else
231  template <typename U, precision Q>
233  GLM_FUNC_DECL tvec4(tvec4<U, Q> const & v);
234 # endif
235 
237  // Swizzle constructors
238 
239 # if GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)
240  template <int E0, int E1, int E2, int E3>
241  GLM_FUNC_DECL tvec4(detail::_swizzle<4, T, P, tvec4<T, P>, E0, E1, E2, E3> const & that)
242  {
243  *this = that();
244  }
245 
246  template <int E0, int E1, int F0, int F1>
247  GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, detail::_swizzle<2, T, P, tvec2<T, P>, F0, F1, -1, -2> const & u)
248  {
249  *this = tvec4<T, P>(v(), u());
250  }
251 
252  template <int E0, int E1>
253  GLM_FUNC_DECL tvec4(T const & x, T const & y, detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v)
254  {
255  *this = tvec4<T, P>(x, y, v());
256  }
257 
258  template <int E0, int E1>
259  GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & w)
260  {
261  *this = tvec4<T, P>(x, v(), w);
262  }
263 
264  template <int E0, int E1>
265  GLM_FUNC_DECL tvec4(detail::_swizzle<2, T, P, tvec2<T, P>, E0, E1, -1, -2> const & v, T const & z, T const & w)
266  {
267  *this = tvec4<T, P>(v(), z, w);
268  }
269 
270  template <int E0, int E1, int E2>
271  GLM_FUNC_DECL tvec4(detail::_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v, T const & w)
272  {
273  *this = tvec4<T, P>(v(), w);
274  }
275 
276  template <int E0, int E1, int E2>
277  GLM_FUNC_DECL tvec4(T const & x, detail::_swizzle<3, T, P, tvec3<T, P>, E0, E1, E2, -1> const & v)
278  {
279  *this = tvec4<T, P>(x, v());
280  }
281 # endif// GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE)
282 
284  // Unary arithmetic operators
285 
286  template <typename U>
287  GLM_FUNC_DECL tvec4<T, P> & operator=(tvec4<U, P> const & v);
288  template <typename U>
289  GLM_FUNC_DECL tvec4<T, P> & operator+=(U scalar);
290  template <typename U>
291  GLM_FUNC_DECL tvec4<T, P> & operator+=(tvec1<U, P> const & v);
292  template <typename U>
293  GLM_FUNC_DECL tvec4<T, P> & operator+=(tvec4<U, P> const & v);
294  template <typename U>
295  GLM_FUNC_DECL tvec4<T, P> & operator-=(U scalar);
296  template <typename U>
297  GLM_FUNC_DECL tvec4<T, P> & operator-=(tvec1<U, P> const & v);
298  template <typename U>
299  GLM_FUNC_DECL tvec4<T, P> & operator-=(tvec4<U, P> const & v);
300  template <typename U>
301  GLM_FUNC_DECL tvec4<T, P> & operator*=(U scalar);
302  template <typename U>
303  GLM_FUNC_DECL tvec4<T, P> & operator*=(tvec1<U, P> const & v);
304  template <typename U>
305  GLM_FUNC_DECL tvec4<T, P> & operator*=(tvec4<U, P> const & v);
306  template <typename U>
307  GLM_FUNC_DECL tvec4<T, P> & operator/=(U scalar);
308  template <typename U>
309  GLM_FUNC_DECL tvec4<T, P> & operator/=(tvec1<U, P> const & v);
310  template <typename U>
311  GLM_FUNC_DECL tvec4<T, P> & operator/=(tvec4<U, P> const & v);
312 
314  // Increment and decrement operators
315 
316  GLM_FUNC_DECL tvec4<T, P> & operator++();
317  GLM_FUNC_DECL tvec4<T, P> & operator--();
318  GLM_FUNC_DECL tvec4<T, P> operator++(int);
319  GLM_FUNC_DECL tvec4<T, P> operator--(int);
320 
322  // Unary bit operators
323 
324  template <typename U>
325  GLM_FUNC_DECL tvec4<T, P> & operator%=(U scalar);
326  template <typename U>
327  GLM_FUNC_DECL tvec4<T, P> & operator%=(tvec1<U, P> const & v);
328  template <typename U>
329  GLM_FUNC_DECL tvec4<T, P> & operator%=(tvec4<U, P> const & v);
330  template <typename U>
331  GLM_FUNC_DECL tvec4<T, P> & operator&=(U scalar);
332  template <typename U>
333  GLM_FUNC_DECL tvec4<T, P> & operator&=(tvec1<U, P> const & v);
334  template <typename U>
335  GLM_FUNC_DECL tvec4<T, P> & operator&=(tvec4<U, P> const & v);
336  template <typename U>
337  GLM_FUNC_DECL tvec4<T, P> & operator|=(U scalar);
338  template <typename U>
339  GLM_FUNC_DECL tvec4<T, P> & operator|=(tvec1<U, P> const & v);
340  template <typename U>
341  GLM_FUNC_DECL tvec4<T, P> & operator|=(tvec4<U, P> const & v);
342  template <typename U>
343  GLM_FUNC_DECL tvec4<T, P> & operator^=(U scalar);
344  template <typename U>
345  GLM_FUNC_DECL tvec4<T, P> & operator^=(tvec1<U, P> const & v);
346  template <typename U>
347  GLM_FUNC_DECL tvec4<T, P> & operator^=(tvec4<U, P> const & v);
348  template <typename U>
349  GLM_FUNC_DECL tvec4<T, P> & operator<<=(U scalar);
350  template <typename U>
351  GLM_FUNC_DECL tvec4<T, P> & operator<<=(tvec1<U, P> const & v);
352  template <typename U>
353  GLM_FUNC_DECL tvec4<T, P> & operator<<=(tvec4<U, P> const & v);
354  template <typename U>
355  GLM_FUNC_DECL tvec4<T, P> & operator>>=(U scalar);
356  template <typename U>
357  GLM_FUNC_DECL tvec4<T, P> & operator>>=(tvec1<U, P> const & v);
358  template <typename U>
359  GLM_FUNC_DECL tvec4<T, P> & operator>>=(tvec4<U, P> const & v);
360  };
361 
362  template <typename T, precision P>
363  GLM_FUNC_DECL tvec4<T, P> operator+(tvec4<T, P> const & v, T scalar);
364 
365  template <typename T, precision P>
366  GLM_FUNC_DECL tvec4<T, P> operator+(tvec4<T, P> const & v, tvec1<T, P> const & s);
367 
368  template <typename T, precision P>
369  GLM_FUNC_DECL tvec4<T, P> operator+(T scalar, tvec4<T, P> const & v);
370 
371  template <typename T, precision P>
372  GLM_FUNC_DECL tvec4<T, P> operator+(tvec1<T, P> const & s, tvec4<T, P> const & v);
373 
374  template <typename T, precision P>
375  GLM_FUNC_DECL tvec4<T, P> operator+(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
376 
377  template <typename T, precision P>
378  GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v, T scalar);
379 
380  template <typename T, precision P>
381  GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v, tvec1<T, P> const & s);
382 
383  template <typename T, precision P>
384  GLM_FUNC_DECL tvec4<T, P> operator-(T scalar, tvec4<T, P> const & v);
385 
386  template <typename T, precision P>
387  GLM_FUNC_DECL tvec4<T, P> operator-(tvec1<T, P> const & s, tvec4<T, P> const & v);
388 
389  template <typename T, precision P>
390  GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
391 
392  template <typename T, precision P>
393  GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, T scalar);
394 
395  template <typename T, precision P>
396  GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v, tvec1<T, P> const & s);
397 
398  template <typename T, precision P>
399  GLM_FUNC_DECL tvec4<T, P> operator*(T scalar, tvec4<T, P> const & v);
400 
401  template <typename T, precision P>
402  GLM_FUNC_DECL tvec4<T, P> operator*(tvec1<T, P> const & s, tvec4<T, P> const & v);
403 
404  template <typename T, precision P>
405  GLM_FUNC_DECL tvec4<T, P> operator*(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
406 
407  template <typename T, precision P>
408  GLM_FUNC_DECL tvec4<T, P> operator/(tvec4<T, P> const & v, T scalar);
409 
410  template <typename T, precision P>
411  GLM_FUNC_DECL tvec4<T, P> operator/(tvec4<T, P> const & v, tvec1<T, P> const & s);
412 
413  template <typename T, precision P>
414  GLM_FUNC_DECL tvec4<T, P> operator/(T scalar, tvec4<T, P> const & v);
415 
416  template <typename T, precision P>
417  GLM_FUNC_DECL tvec4<T, P> operator/(tvec1<T, P> const & s, tvec4<T, P> const & v);
418 
419  template <typename T, precision P>
420  GLM_FUNC_DECL tvec4<T, P> operator/(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
421 
422  template <typename T, precision P>
423  GLM_FUNC_DECL tvec4<T, P> operator-(tvec4<T, P> const & v);
424 
425  template <typename T, precision P>
426  GLM_FUNC_DECL bool operator==(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
427 
428  template <typename T, precision P>
429  GLM_FUNC_DECL bool operator!=(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
430 
431  template <typename T, precision P>
432  GLM_FUNC_DECL tvec4<T, P> operator%(tvec4<T, P> const & v, T scalar);
433 
434  template <typename T, precision P>
435  GLM_FUNC_DECL tvec4<T, P> operator%(tvec4<T, P> const & v, tvec1<T, P> const & s);
436 
437  template <typename T, precision P>
438  GLM_FUNC_DECL tvec4<T, P> operator%(T scalar, tvec4<T, P> const & v);
439 
440  template <typename T, precision P>
441  GLM_FUNC_DECL tvec4<T, P> operator%(tvec1<T, P> const & s, tvec4<T, P> const & v);
442 
443  template <typename T, precision P>
444  GLM_FUNC_DECL tvec4<T, P> operator%(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
445 
446  template <typename T, precision P>
447  GLM_FUNC_DECL tvec4<T, P> operator&(tvec4<T, P> const & v, T scalar);
448 
449  template <typename T, precision P>
450  GLM_FUNC_DECL tvec4<T, P> operator&(tvec4<T, P> const & v, tvec1<T, P> const & s);
451 
452  template <typename T, precision P>
453  GLM_FUNC_DECL tvec4<T, P> operator&(T scalar, tvec4<T, P> const & v);
454 
455  template <typename T, precision P>
456  GLM_FUNC_DECL tvec4<T, P> operator&(tvec1<T, P> const & s, tvec4<T, P> const & v);
457 
458  template <typename T, precision P>
459  GLM_FUNC_DECL tvec4<T, P> operator&(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
460 
461  template <typename T, precision P>
462  GLM_FUNC_DECL tvec4<T, P> operator|(tvec4<T, P> const & v, T scalar);
463 
464  template <typename T, precision P>
465  GLM_FUNC_DECL tvec4<T, P> operator|(tvec4<T, P> const & v, tvec1<T, P> const & s);
466 
467  template <typename T, precision P>
468  GLM_FUNC_DECL tvec4<T, P> operator|(T scalar, tvec4<T, P> const & v);
469 
470  template <typename T, precision P>
471  GLM_FUNC_DECL tvec4<T, P> operator|(tvec1<T, P> const & s, tvec4<T, P> const & v);
472 
473  template <typename T, precision P>
474  GLM_FUNC_DECL tvec4<T, P> operator|(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
475 
476  template <typename T, precision P>
477  GLM_FUNC_DECL tvec4<T, P> operator^(tvec4<T, P> const & v, T scalar);
478 
479  template <typename T, precision P>
480  GLM_FUNC_DECL tvec4<T, P> operator^(tvec4<T, P> const & v, tvec1<T, P> const & s);
481 
482  template <typename T, precision P>
483  GLM_FUNC_DECL tvec4<T, P> operator^(T scalar, tvec4<T, P> const & v);
484 
485  template <typename T, precision P>
486  GLM_FUNC_DECL tvec4<T, P> operator^(tvec1<T, P> const & s, tvec4<T, P> const & v);
487 
488  template <typename T, precision P>
489  GLM_FUNC_DECL tvec4<T, P> operator^(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
490 
491  template <typename T, precision P>
492  GLM_FUNC_DECL tvec4<T, P> operator<<(tvec4<T, P> const & v, T scalar);
493 
494  template <typename T, precision P>
495  GLM_FUNC_DECL tvec4<T, P> operator<<(tvec4<T, P> const & v, tvec1<T, P> const & s);
496 
497  template <typename T, precision P>
498  GLM_FUNC_DECL tvec4<T, P> operator<<(T scalar, tvec4<T, P> const & v);
499 
500  template <typename T, precision P>
501  GLM_FUNC_DECL tvec4<T, P> operator<<(tvec1<T, P> const & s, tvec4<T, P> const & v);
502 
503  template <typename T, precision P>
504  GLM_FUNC_DECL tvec4<T, P> operator<<(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
505 
506  template <typename T, precision P>
507  GLM_FUNC_DECL tvec4<T, P> operator>>(tvec4<T, P> const & v, T scalar);
508 
509  template <typename T, precision P>
510  GLM_FUNC_DECL tvec4<T, P> operator>>(tvec4<T, P> const & v, tvec1<T, P> const & s);
511 
512  template <typename T, precision P>
513  GLM_FUNC_DECL tvec4<T, P> operator>>(T scalar, tvec4<T, P> const & v);
514 
515  template <typename T, precision P>
516  GLM_FUNC_DECL tvec4<T, P> operator>>(tvec1<T, P> const & s, tvec4<T, P> const & v);
517 
518  template <typename T, precision P>
519  GLM_FUNC_DECL tvec4<T, P> operator>>(tvec4<T, P> const & v1, tvec4<T, P> const & v2);
520 
521  template <typename T, precision P>
522  GLM_FUNC_DECL tvec4<T, P> operator~(tvec4<T, P> const & v);
523 }//namespace glm
524 
525 #ifndef GLM_EXTERNAL_TEMPLATE
526 #include "type_vec4.inl"
527 #endif//GLM_EXTERNAL_TEMPLATE
OpenGL Mathematics (glm.g-truc.net)
GLM_FUNC_DECL T length(vecType< T, P > const &x)
Returns the length of x, i.e., sqrt(x * x).
Definition: _noise.hpp:40
OpenGL Mathematics (glm.g-truc.net)
OpenGL Mathematics (glm.g-truc.net)
OpenGL Mathematics (glm.g-truc.net)