You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
12 KiB

5 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref gtc_swizzle
  24. /// @file glm/gtc/swizzle.hpp
  25. /// @date 2010-02-20 / 2011-06-05
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see core (dependence)
  29. ///
  30. /// @defgroup gtc_swizzle GLM_GTC_swizzle
  31. /// @ingroup gtc
  32. ///
  33. /// @brief Provide functions to emulate GLSL swizzle operator fonctionalities.
  34. ///
  35. /// <glm/gtc/swizzle.hpp> need to be included to use these functionalities.
  36. ///////////////////////////////////////////////////////////////////////////////////
  37. #ifndef GLM_GTC_swizzle
  38. #define GLM_GTC_swizzle GLM_VERSION
  39. // Dependency:
  40. #include "../glm.hpp"
  41. #include "../gtc/type_precision.hpp"
  42. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  43. # pragma message("GLM: GLM_GTC_swizzle extension included")
  44. #endif
  45. namespace glm
  46. {
  47. /// @addtogroup gtc_swizzle
  48. /// @{
  49. template <typename T, template <typename> class vecType>
  50. T const & swizzle(
  51. vecType<T> const & v,
  52. comp x);
  53. template <typename T, template <typename> class vecType>
  54. detail::tvec2<T> const & swizzle(
  55. vecType<T> const & v,
  56. comp x, comp y);
  57. template <typename T, template <typename> class vecType>
  58. detail::tvec3<T> const & swizzle(
  59. vecType<T> const & v,
  60. comp x, comp y, comp z);
  61. template <typename T, template <typename> class vecType>
  62. detail::tvec4<T> const & swizzle(
  63. vecType<T> const & v,
  64. comp x, comp y, comp z, comp w);
  65. template <typename T, template <typename> class vecType>
  66. T & swizzle(
  67. vecType<T> & v,
  68. comp x);
  69. template <typename T, template <typename> class vecType>
  70. detail::tref2<T> swizzle(
  71. vecType<T> & v,
  72. comp x, comp y);
  73. template <typename T, template <typename> class vecType>
  74. detail::tref3<T> swizzle(
  75. vecType<T> & v,
  76. comp x, comp y, comp z);
  77. template <typename T, template <typename> class vecType>
  78. detail::tref4<T> swizzle(
  79. vecType<T> & v,
  80. comp x, comp y, comp z, comp w);
  81. # define static_swizzle1_const(TYPE, SIZE) \
  82. template <comp x> \
  83. GLM_FUNC_QUALIFIER TYPE swizzle(detail::tvec##SIZE<TYPE> const & v) \
  84. {return v[x];}
  85. # define static_swizzle1_ref(TYPE, SIZE) \
  86. template <comp x> \
  87. GLM_FUNC_QUALIFIER TYPE& swizzle(detail::tvec##SIZE<TYPE> & v) \
  88. {return v[x];}
  89. static_swizzle1_ref(detail::float16, 2)
  90. static_swizzle1_ref(detail::float16, 3)
  91. static_swizzle1_ref(detail::float16, 4)
  92. static_swizzle1_ref(detail::float32, 2)
  93. static_swizzle1_ref(detail::float32, 3)
  94. static_swizzle1_ref(detail::float32, 4)
  95. static_swizzle1_ref(detail::float64, 2)
  96. static_swizzle1_ref(detail::float64, 3)
  97. static_swizzle1_ref(detail::float64, 4)
  98. static_swizzle1_ref(detail::int8, 2)
  99. static_swizzle1_ref(detail::int8, 3)
  100. static_swizzle1_ref(detail::int8, 4)
  101. static_swizzle1_ref(detail::int16, 2)
  102. static_swizzle1_ref(detail::int16, 3)
  103. static_swizzle1_ref(detail::int16, 4)
  104. static_swizzle1_ref(detail::int32, 2)
  105. static_swizzle1_ref(detail::int32, 3)
  106. static_swizzle1_ref(detail::int32, 4)
  107. static_swizzle1_ref(detail::int64, 2)
  108. static_swizzle1_ref(detail::int64, 3)
  109. static_swizzle1_ref(detail::int64, 4)
  110. static_swizzle1_ref(detail::uint8, 2)
  111. static_swizzle1_ref(detail::uint8, 3)
  112. static_swizzle1_ref(detail::uint8, 4)
  113. static_swizzle1_ref(detail::uint16, 2)
  114. static_swizzle1_ref(detail::uint16, 3)
  115. static_swizzle1_ref(detail::uint16, 4)
  116. static_swizzle1_ref(detail::uint32, 2)
  117. static_swizzle1_ref(detail::uint32, 3)
  118. static_swizzle1_ref(detail::uint32, 4)
  119. static_swizzle1_ref(detail::uint64, 2)
  120. static_swizzle1_ref(detail::uint64, 3)
  121. static_swizzle1_ref(detail::uint64, 4)
  122. /*
  123. # define static_swizzle2_const(TYPE) \
  124. template <comp x, comp y> \
  125. GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
  126. {return TYPE(v[x], v[y]);}
  127. # define static_swizzle3_const(TYPE) \
  128. template <comp x, comp y, comp z> \
  129. GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
  130. {return TYPE(v[x], v[y], v[z]);}
  131. # define static_swizzle4_const(TYPE) \
  132. template <comp x, comp y, comp z, comp w> \
  133. GLM_FUNC_QUALIFIER TYPE swizzle(TYPE const & v) \
  134. {return TYPE(v[x], v[y], v[z], v[w]);}
  135. */
  136. # define static_swizzle2_const(TYPE, SIZE) \
  137. template <comp x, comp y> \
  138. GLM_FUNC_QUALIFIER detail::tvec2<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
  139. {return detail::tvec2<TYPE>(v[x], v[y]);}
  140. # define static_swizzle3_const(TYPE, SIZE) \
  141. template <comp x, comp y, comp z> \
  142. GLM_FUNC_QUALIFIER detail::tvec3<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
  143. {return detail::tvec3<TYPE>(v[x], v[y], v[z]);}
  144. # define static_swizzle4_const(TYPE, SIZE) \
  145. template <comp x, comp y, comp z, comp w> \
  146. GLM_FUNC_QUALIFIER detail::tvec4<TYPE> swizzle(detail::tvec##SIZE<TYPE> const & v) \
  147. {return detail::tvec4<TYPE>(v[x], v[y], v[z], v[w]);}
  148. static_swizzle2_const(glm::f16, 2)
  149. static_swizzle2_const(glm::f16, 3)
  150. static_swizzle2_const(glm::f16, 4)
  151. static_swizzle2_const(glm::f32, 2)
  152. static_swizzle2_const(glm::f32, 3)
  153. static_swizzle2_const(glm::f32, 4)
  154. static_swizzle2_const(glm::f64, 2)
  155. static_swizzle2_const(glm::f64, 3)
  156. static_swizzle2_const(glm::f64, 4)
  157. static_swizzle2_const(glm::i8, 2)
  158. static_swizzle2_const(glm::i8, 3)
  159. static_swizzle2_const(glm::i8, 4)
  160. static_swizzle2_const(glm::i16, 2)
  161. static_swizzle2_const(glm::i16, 3)
  162. static_swizzle2_const(glm::i16, 4)
  163. static_swizzle2_const(glm::i32, 2)
  164. static_swizzle2_const(glm::i32, 3)
  165. static_swizzle2_const(glm::i32, 4)
  166. static_swizzle2_const(glm::i64, 2)
  167. static_swizzle2_const(glm::i64, 3)
  168. static_swizzle2_const(glm::i64, 4)
  169. static_swizzle2_const(glm::u8, 2)
  170. static_swizzle2_const(glm::u8, 3)
  171. static_swizzle2_const(glm::u8, 4)
  172. static_swizzle2_const(glm::u16, 2)
  173. static_swizzle2_const(glm::u16, 3)
  174. static_swizzle2_const(glm::u16, 4)
  175. static_swizzle2_const(glm::u32, 2)
  176. static_swizzle2_const(glm::u32, 3)
  177. static_swizzle2_const(glm::u32, 4)
  178. static_swizzle2_const(glm::u64, 2)
  179. static_swizzle2_const(glm::u64, 3)
  180. static_swizzle2_const(glm::u64, 4)
  181. static_swizzle3_const(glm::f16, 2)
  182. static_swizzle3_const(glm::f16, 3)
  183. static_swizzle3_const(glm::f16, 4)
  184. static_swizzle3_const(glm::f32, 2)
  185. static_swizzle3_const(glm::f32, 3)
  186. static_swizzle3_const(glm::f32, 4)
  187. static_swizzle3_const(glm::f64, 2)
  188. static_swizzle3_const(glm::f64, 3)
  189. static_swizzle3_const(glm::f64, 4)
  190. static_swizzle3_const(glm::i8, 2)
  191. static_swizzle3_const(glm::i8, 3)
  192. static_swizzle3_const(glm::i8, 4)
  193. static_swizzle3_const(glm::i16, 2)
  194. static_swizzle3_const(glm::i16, 3)
  195. static_swizzle3_const(glm::i16, 4)
  196. static_swizzle3_const(glm::i32, 2)
  197. static_swizzle3_const(glm::i32, 3)
  198. static_swizzle3_const(glm::i32, 4)
  199. static_swizzle3_const(glm::i64, 2)
  200. static_swizzle3_const(glm::i64, 3)
  201. static_swizzle3_const(glm::i64, 4)
  202. static_swizzle3_const(glm::u8, 2)
  203. static_swizzle3_const(glm::u8, 3)
  204. static_swizzle3_const(glm::u8, 4)
  205. static_swizzle3_const(glm::u16, 2)
  206. static_swizzle3_const(glm::u16, 3)
  207. static_swizzle3_const(glm::u16, 4)
  208. static_swizzle3_const(glm::u32, 2)
  209. static_swizzle3_const(glm::u32, 3)
  210. static_swizzle3_const(glm::u32, 4)
  211. static_swizzle3_const(glm::u64, 2)
  212. static_swizzle3_const(glm::u64, 3)
  213. static_swizzle3_const(glm::u64, 4)
  214. static_swizzle4_const(glm::f16, 2)
  215. static_swizzle4_const(glm::f16, 3)
  216. static_swizzle4_const(glm::f16, 4)
  217. static_swizzle4_const(glm::f32, 2)
  218. static_swizzle4_const(glm::f32, 3)
  219. static_swizzle4_const(glm::f32, 4)
  220. static_swizzle4_const(glm::f64, 2)
  221. static_swizzle4_const(glm::f64, 3)
  222. static_swizzle4_const(glm::f64, 4)
  223. static_swizzle4_const(glm::i8, 2)
  224. static_swizzle4_const(glm::i8, 3)
  225. static_swizzle4_const(glm::i8, 4)
  226. static_swizzle4_const(glm::i16, 2)
  227. static_swizzle4_const(glm::i16, 3)
  228. static_swizzle4_const(glm::i16, 4)
  229. static_swizzle4_const(glm::i32, 2)
  230. static_swizzle4_const(glm::i32, 3)
  231. static_swizzle4_const(glm::i32, 4)
  232. static_swizzle4_const(glm::i64, 2)
  233. static_swizzle4_const(glm::i64, 3)
  234. static_swizzle4_const(glm::i64, 4)
  235. static_swizzle4_const(glm::u8, 2)
  236. static_swizzle4_const(glm::u8, 3)
  237. static_swizzle4_const(glm::u8, 4)
  238. static_swizzle4_const(glm::u16, 2)
  239. static_swizzle4_const(glm::u16, 3)
  240. static_swizzle4_const(glm::u16, 4)
  241. static_swizzle4_const(glm::u32, 2)
  242. static_swizzle4_const(glm::u32, 3)
  243. static_swizzle4_const(glm::u32, 4)
  244. static_swizzle4_const(glm::u64, 2)
  245. static_swizzle4_const(glm::u64, 3)
  246. static_swizzle4_const(glm::u64, 4)
  247. # define static_swizzle2_ref(TYPE, SIZE) \
  248. template <glm::comp x, glm::comp y> \
  249. GLM_FUNC_QUALIFIER glm::detail::tref2<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
  250. {return glm::detail::tref2<TYPE>(v[x], v[y]);}
  251. # define static_swizzle3_ref(TYPE, SIZE) \
  252. template <glm::comp x, glm::comp y, glm::comp z> \
  253. GLM_FUNC_QUALIFIER glm::detail::tref3<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
  254. {return glm::detail::tref3<TYPE>(v[x], v[y], v[z]);}
  255. # define static_swizzle4_ref(TYPE, SIZE) \
  256. template <glm::comp x, glm::comp y, glm::comp z, glm::comp w> \
  257. GLM_FUNC_QUALIFIER glm::detail::tref4<TYPE> swizzle(detail::tvec##SIZE<TYPE> & v) \
  258. {return glm::detail::tref4<TYPE>(v[x], v[y], v[z], v[w]);}
  259. static_swizzle2_ref(glm::f16, 2)
  260. static_swizzle2_ref(glm::f16, 3)
  261. static_swizzle2_ref(glm::f16, 4)
  262. static_swizzle2_ref(glm::f32, 2)
  263. static_swizzle2_ref(glm::f32, 3)
  264. static_swizzle2_ref(glm::f32, 4)
  265. static_swizzle2_ref(glm::f64, 2)
  266. static_swizzle2_ref(glm::f64, 3)
  267. static_swizzle2_ref(glm::f64, 4)
  268. static_swizzle2_ref(glm::i8, 2)
  269. static_swizzle2_ref(glm::i8, 3)
  270. static_swizzle2_ref(glm::i8, 4)
  271. static_swizzle2_ref(glm::i16, 2)
  272. static_swizzle2_ref(glm::i16, 3)
  273. static_swizzle2_ref(glm::i16, 4)
  274. static_swizzle2_ref(glm::i32, 2)
  275. static_swizzle2_ref(glm::i32, 3)
  276. static_swizzle2_ref(glm::i32, 4)
  277. static_swizzle2_ref(glm::i64, 2)
  278. static_swizzle2_ref(glm::i64, 3)
  279. static_swizzle2_ref(glm::i64, 4)
  280. static_swizzle2_ref(glm::u8, 2)
  281. static_swizzle2_ref(glm::u8, 3)
  282. static_swizzle2_ref(glm::u8, 4)
  283. static_swizzle2_ref(glm::u16, 2)
  284. static_swizzle2_ref(glm::u16, 3)
  285. static_swizzle2_ref(glm::u16, 4)
  286. static_swizzle2_ref(glm::u32, 2)
  287. static_swizzle2_ref(glm::u32, 3)
  288. static_swizzle2_ref(glm::u32, 4)
  289. static_swizzle2_ref(glm::u64, 2)
  290. static_swizzle2_ref(glm::u64, 3)
  291. static_swizzle2_ref(glm::u64, 4)
  292. static_swizzle3_ref(glm::f16, 3)
  293. static_swizzle3_ref(glm::f16, 4)
  294. static_swizzle3_ref(glm::f32, 3)
  295. static_swizzle3_ref(glm::f32, 4)
  296. static_swizzle3_ref(glm::f64, 3)
  297. static_swizzle3_ref(glm::f64, 4)
  298. static_swizzle3_ref(glm::i8, 3)
  299. static_swizzle3_ref(glm::i8, 4)
  300. static_swizzle3_ref(glm::i16, 3)
  301. static_swizzle3_ref(glm::i16, 4)
  302. static_swizzle3_ref(glm::i32, 3)
  303. static_swizzle3_ref(glm::i32, 4)
  304. static_swizzle3_ref(glm::i64, 3)
  305. static_swizzle3_ref(glm::i64, 4)
  306. static_swizzle3_ref(glm::u8, 3)
  307. static_swizzle3_ref(glm::u8, 4)
  308. static_swizzle3_ref(glm::u16, 3)
  309. static_swizzle3_ref(glm::u16, 4)
  310. static_swizzle3_ref(glm::u32, 3)
  311. static_swizzle3_ref(glm::u32, 4)
  312. static_swizzle3_ref(glm::u64, 3)
  313. static_swizzle3_ref(glm::u64, 4)
  314. static_swizzle4_ref(glm::f16, 4)
  315. static_swizzle4_ref(glm::f32, 4)
  316. static_swizzle4_ref(glm::f64, 4)
  317. static_swizzle4_ref(glm::i8, 4)
  318. static_swizzle4_ref(glm::i16, 4)
  319. static_swizzle4_ref(glm::i32, 4)
  320. static_swizzle4_ref(glm::i64, 4)
  321. static_swizzle4_ref(glm::u8, 4)
  322. static_swizzle4_ref(glm::u16, 4)
  323. static_swizzle4_ref(glm::u32, 4)
  324. static_swizzle4_ref(glm::u64, 4)
  325. /// @}
  326. }//namespace glm
  327. #include "swizzle.inl"
  328. #endif//GLM_GTC_swizzle