qualifier.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #pragma once
  2. #include "setup.hpp"
  3. namespace glm
  4. {
  5. /// Qualify GLM types in term of alignment (packed, aligned) and precision in term of ULPs (lowp, mediump, highp)
  6. enum qualifier
  7. {
  8. packed_highp, ///< Typed data is tightly packed in memory and operations are executed with high precision in term of ULPs
  9. packed_mediump, ///< Typed data is tightly packed in memory and operations are executed with medium precision in term of ULPs for higher performance
  10. packed_lowp, ///< Typed data is tightly packed in memory and operations are executed with low precision in term of ULPs to maximize performance
  11. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
  12. aligned_highp, ///< Typed data is aligned in memory allowing SIMD optimizations and operations are executed with high precision in term of ULPs
  13. 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
  14. 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
  15. aligned = aligned_highp, ///< By default aligned qualifier is also high precision
  16. # endif
  17. highp = packed_highp, ///< By default highp qualifier is also packed
  18. mediump = packed_mediump, ///< By default mediump qualifier is also packed
  19. lowp = packed_lowp, ///< By default lowp qualifier is also packed
  20. packed = packed_highp, ///< By default packed qualifier is also high precision
  21. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE && defined(GLM_FORCE_DEFAULT_ALIGNED_GENTYPES)
  22. defaultp = aligned_highp
  23. # else
  24. defaultp = highp
  25. # endif
  26. };
  27. typedef qualifier precision;
  28. template<length_t L, typename T, qualifier Q = defaultp> struct vec;
  29. template<length_t C, length_t R, typename T, qualifier Q = defaultp> struct mat;
  30. template<typename T, qualifier Q = defaultp> struct qua;
  31. # if GLM_HAS_TEMPLATE_ALIASES
  32. template <typename T, qualifier Q = defaultp> using tvec1 = vec<1, T, Q>;
  33. template <typename T, qualifier Q = defaultp> using tvec2 = vec<2, T, Q>;
  34. template <typename T, qualifier Q = defaultp> using tvec3 = vec<3, T, Q>;
  35. template <typename T, qualifier Q = defaultp> using tvec4 = vec<4, T, Q>;
  36. template <typename T, qualifier Q = defaultp> using tmat2x2 = mat<2, 2, T, Q>;
  37. template <typename T, qualifier Q = defaultp> using tmat2x3 = mat<2, 3, T, Q>;
  38. template <typename T, qualifier Q = defaultp> using tmat2x4 = mat<2, 4, T, Q>;
  39. template <typename T, qualifier Q = defaultp> using tmat3x2 = mat<3, 2, T, Q>;
  40. template <typename T, qualifier Q = defaultp> using tmat3x3 = mat<3, 3, T, Q>;
  41. template <typename T, qualifier Q = defaultp> using tmat3x4 = mat<3, 4, T, Q>;
  42. template <typename T, qualifier Q = defaultp> using tmat4x2 = mat<4, 2, T, Q>;
  43. template <typename T, qualifier Q = defaultp> using tmat4x3 = mat<4, 3, T, Q>;
  44. template <typename T, qualifier Q = defaultp> using tmat4x4 = mat<4, 4, T, Q>;
  45. template <typename T, qualifier Q = defaultp> using tquat = qua<T, Q>;
  46. # endif
  47. namespace detail
  48. {
  49. template<glm::qualifier P>
  50. struct is_aligned
  51. {
  52. static const bool value = false;
  53. };
  54. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
  55. template<>
  56. struct is_aligned<glm::aligned_lowp>
  57. {
  58. static const bool value = true;
  59. };
  60. template<>
  61. struct is_aligned<glm::aligned_mediump>
  62. {
  63. static const bool value = true;
  64. };
  65. template<>
  66. struct is_aligned<glm::aligned_highp>
  67. {
  68. static const bool value = true;
  69. };
  70. # endif
  71. template<length_t L, typename T, bool is_aligned>
  72. struct storage
  73. {
  74. typedef struct type {
  75. T data[L];
  76. } type;
  77. };
  78. # if GLM_HAS_ALIGNOF
  79. template<length_t L, typename T>
  80. struct storage<L, T, true>
  81. {
  82. typedef struct alignas(L * sizeof(T)) type {
  83. T data[L];
  84. } type;
  85. };
  86. template<typename T>
  87. struct storage<3, T, true>
  88. {
  89. typedef struct alignas(4 * sizeof(T)) type {
  90. T data[4];
  91. } type;
  92. };
  93. # endif
  94. # if GLM_ARCH & GLM_ARCH_SSE2_BIT
  95. template<>
  96. struct storage<4, float, true>
  97. {
  98. typedef glm_f32vec4 type;
  99. };
  100. template<>
  101. struct storage<4, int, true>
  102. {
  103. typedef glm_i32vec4 type;
  104. };
  105. template<>
  106. struct storage<4, unsigned int, true>
  107. {
  108. typedef glm_u32vec4 type;
  109. };
  110. template<>
  111. struct storage<2, double, true>
  112. {
  113. typedef glm_f64vec2 type;
  114. };
  115. template<>
  116. struct storage<2, detail::int64, true>
  117. {
  118. typedef glm_i64vec2 type;
  119. };
  120. template<>
  121. struct storage<2, detail::uint64, true>
  122. {
  123. typedef glm_u64vec2 type;
  124. };
  125. # endif
  126. # if (GLM_ARCH & GLM_ARCH_AVX_BIT)
  127. template<>
  128. struct storage<4, double, true>
  129. {
  130. typedef glm_f64vec4 type;
  131. };
  132. # endif
  133. # if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
  134. template<>
  135. struct storage<4, detail::int64, true>
  136. {
  137. typedef glm_i64vec4 type;
  138. };
  139. template<>
  140. struct storage<4, detail::uint64, true>
  141. {
  142. typedef glm_u64vec4 type;
  143. };
  144. # endif
  145. # if GLM_ARCH & GLM_ARCH_NEON_BIT
  146. template<>
  147. struct storage<4, float, true>
  148. {
  149. typedef glm_f32vec4 type;
  150. };
  151. template<>
  152. struct storage<4, int, true>
  153. {
  154. typedef glm_i32vec4 type;
  155. };
  156. template<>
  157. struct storage<4, unsigned int, true>
  158. {
  159. typedef glm_u32vec4 type;
  160. };
  161. # endif
  162. enum genTypeEnum
  163. {
  164. GENTYPE_VEC,
  165. GENTYPE_MAT,
  166. GENTYPE_QUAT
  167. };
  168. template <typename genType>
  169. struct genTypeTrait
  170. {};
  171. template <length_t C, length_t R, typename T>
  172. struct genTypeTrait<mat<C, R, T> >
  173. {
  174. static const genTypeEnum GENTYPE = GENTYPE_MAT;
  175. };
  176. template<typename genType, genTypeEnum type>
  177. struct init_gentype
  178. {
  179. };
  180. template<typename genType>
  181. struct init_gentype<genType, GENTYPE_QUAT>
  182. {
  183. GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genType identity()
  184. {
  185. return genType(1, 0, 0, 0);
  186. }
  187. };
  188. template<typename genType>
  189. struct init_gentype<genType, GENTYPE_MAT>
  190. {
  191. GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genType identity()
  192. {
  193. return genType(1);
  194. }
  195. };
  196. }//namespace detail
  197. }//namespace glm