/src/glm/BACKUP/gtc/half_float.hpp

https://github.com/Funto/Tohoku-Engine · C++ Header · 407 lines · 207 code · 89 blank · 111 comment · 0 complexity · f1f21e4fb9963129ca79caacf4b13cd4 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2009 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2009-04-29
  5. // Updated : 2009-04-29
  6. // Licence : This source is under MIT License
  7. // File : glm/gtc/half_float.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef glm_gtc_half_float
  10. #define glm_gtc_half_float
  11. // Dependency:
  12. #include "../glm.hpp"
  13. namespace glm
  14. {
  15. namespace test{
  16. bool main_gtc_half_float();
  17. }//namespace test
  18. namespace detail
  19. {
  20. #ifndef GLM_USE_ANONYMOUS_UNION
  21. template <>
  22. struct tvec2<thalf>
  23. {
  24. //////////////////////////////////////
  25. // Typedef (Implementation details)
  26. typedef thalf value_type;
  27. typedef thalf& value_reference;
  28. typedef thalf* value_pointer;
  29. typedef tvec2<bool> bool_type;
  30. typedef sizeType size_type;
  31. static size_type value_size();
  32. static bool is_vector();
  33. typedef tvec2<thalf> type;
  34. typedef tvec2<thalf>* pointer;
  35. typedef const tvec2<thalf>* const_pointer;
  36. typedef const tvec2<thalf>*const const_pointer_const;
  37. typedef tvec2<thalf>*const pointer_const;
  38. typedef tvec2<thalf>& reference;
  39. typedef const tvec2<thalf>& const_reference;
  40. typedef const tvec2<thalf>& param_type;
  41. //////////////////////////////////////
  42. // Data
  43. thalf x, y;
  44. //////////////////////////////////////
  45. // Accesses
  46. thalf& operator[](size_type i);
  47. thalf operator[](size_type i) const;
  48. //////////////////////////////////////
  49. // Address (Implementation details)
  50. thalf const * const _address() const{return (value_type*)(this);}
  51. thalf * _address(){return (value_type*)(this);}
  52. //////////////////////////////////////
  53. // Implicit basic constructors
  54. tvec2();
  55. tvec2(tvec2<thalf> const & v);
  56. //////////////////////////////////////
  57. // Explicit basic constructors
  58. explicit tvec2(thalf s);
  59. explicit tvec2(thalf s1, thalf s2);
  60. //////////////////////////////////////
  61. // Swizzle constructors
  62. tvec2(tref2<thalf> const & r);
  63. //////////////////////////////////////
  64. // Convertion scalar constructors
  65. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  66. template <typename U>
  67. explicit tvec2(U x);
  68. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  69. template <typename U, typename V>
  70. explicit tvec2(U x, V y);
  71. //////////////////////////////////////
  72. // Convertion vector constructors
  73. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  74. template <typename U>
  75. explicit tvec2(tvec2<U> const & v);
  76. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  77. template <typename U>
  78. explicit tvec2(tvec3<U> const & v);
  79. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  80. template <typename U>
  81. explicit tvec2(tvec4<U> const & v);
  82. //////////////////////////////////////
  83. // Unary arithmetic operators
  84. tvec2<thalf>& operator= (tvec2<thalf> const & v);
  85. tvec2<thalf>& operator+=(thalf s);
  86. tvec2<thalf>& operator+=(tvec2<thalf> const & v);
  87. tvec2<thalf>& operator-=(thalf s);
  88. tvec2<thalf>& operator-=(tvec2<thalf> const & v);
  89. tvec2<thalf>& operator*=(thalf s);
  90. tvec2<thalf>& operator*=(tvec2<thalf> const & v);
  91. tvec2<thalf>& operator/=(thalf s);
  92. tvec2<thalf>& operator/=(tvec2<thalf> const & v);
  93. tvec2<thalf>& operator++();
  94. tvec2<thalf>& operator--();
  95. //////////////////////////////////////
  96. // Swizzle operators
  97. thalf swizzle(comp X) const;
  98. tvec2<thalf> swizzle(comp X, comp Y) const;
  99. tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
  100. tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
  101. tref2<thalf> swizzle(comp X, comp Y);
  102. };
  103. template <>
  104. struct tvec3<thalf>
  105. {
  106. //////////////////////////////////////
  107. // Typedef (Implementation details)
  108. typedef thalf value_type;
  109. typedef thalf& value_reference;
  110. typedef thalf* value_pointer;
  111. typedef tvec3<bool> bool_type;
  112. typedef glm::sizeType size_type;
  113. static size_type value_size();
  114. static bool is_vector();
  115. typedef tvec3<thalf> type;
  116. typedef tvec3<thalf> * pointer;
  117. typedef tvec3<thalf> const * const_pointer;
  118. typedef tvec3<thalf> const * const const_pointer_const;
  119. typedef tvec3<thalf> * const pointer_const;
  120. typedef tvec3<thalf> & reference;
  121. typedef tvec3<thalf> const & const_reference;
  122. typedef tvec3<thalf> const & param_type;
  123. //////////////////////////////////////
  124. // Data
  125. thalf x, y, z;
  126. //////////////////////////////////////
  127. // Accesses
  128. thalf& operator[](size_type i);
  129. thalf operator[](size_type i) const;
  130. //////////////////////////////////////
  131. // Address (Implementation details)
  132. const value_type* _address() const{return (value_type*)(this);}
  133. value_type* _address(){return (value_type*)(this);}
  134. //////////////////////////////////////
  135. // Implicit basic constructors
  136. tvec3();
  137. tvec3(tvec3<thalf> const & v);
  138. //////////////////////////////////////
  139. // Explicit basic constructors
  140. explicit tvec3(thalf s);
  141. explicit tvec3(thalf s1, thalf s2, thalf s3);
  142. //////////////////////////////////////
  143. // Swizzle constructors
  144. tvec3(tref3<thalf> const & r);
  145. //////////////////////////////////////
  146. // Convertion scalar constructors
  147. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  148. template <typename U>
  149. explicit tvec3(U x);
  150. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  151. template <typename U, typename V, typename W>
  152. explicit tvec3(U x, V y, W z);
  153. //////////////////////////////////////
  154. // Convertion vector constructors
  155. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  156. template <typename A, typename B>
  157. explicit tvec3(const tvec2<A>& v, B s);
  158. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  159. template <typename A, typename B>
  160. explicit tvec3(A s, const tvec2<B>& v);
  161. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  162. template <typename U>
  163. explicit tvec3(tvec3<U> const & v);
  164. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  165. template <typename U>
  166. explicit tvec3(tvec4<U> const & v);
  167. //////////////////////////////////////
  168. // Unary arithmetic operators
  169. tvec3<thalf>& operator= (tvec3<thalf> const & v);
  170. tvec3<thalf>& operator+=(thalf s);
  171. tvec3<thalf>& operator+=(tvec3<thalf> const & v);
  172. tvec3<thalf>& operator-=(thalf s);
  173. tvec3<thalf>& operator-=(tvec3<thalf> const & v);
  174. tvec3<thalf>& operator*=(thalf s);
  175. tvec3<thalf>& operator*=(tvec3<thalf> const & v);
  176. tvec3<thalf>& operator/=(thalf s);
  177. tvec3<thalf>& operator/=(tvec3<thalf> const & v);
  178. tvec3<thalf>& operator++();
  179. tvec3<thalf>& operator--();
  180. //////////////////////////////////////
  181. // Swizzle operators
  182. thalf swizzle(comp X) const;
  183. tvec2<thalf> swizzle(comp X, comp Y) const;
  184. tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
  185. tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
  186. tref3<thalf> swizzle(comp X, comp Y, comp Z);
  187. };
  188. template <>
  189. struct tvec4<thalf>
  190. {
  191. //////////////////////////////////////
  192. // Typedef (Implementation details)
  193. typedef thalf value_type;
  194. typedef thalf& value_reference;
  195. typedef thalf* value_pointer;
  196. typedef tvec4<bool> bool_type;
  197. typedef glm::sizeType size_type;
  198. static size_type value_size();
  199. static bool is_vector();
  200. typedef tvec4<thalf> type;
  201. typedef tvec4<thalf> * pointer;
  202. typedef tvec4<thalf> const * const_pointer;
  203. typedef tvec4<thalf> const * const const_pointer_const;
  204. typedef tvec4<thalf> * const pointer_const;
  205. typedef tvec4<thalf> & reference;
  206. typedef tvec4<thalf> const & const_reference;
  207. typedef tvec4<thalf> const & param_type;
  208. //////////////////////////////////////
  209. // Data
  210. thalf x, y, z, w;
  211. //////////////////////////////////////
  212. // Accesses
  213. thalf& operator[](size_type i);
  214. thalf operator[](size_type i) const;
  215. //////////////////////////////////////
  216. // Address (Implementation details)
  217. const value_type* _address() const{return (value_type*)(this);}
  218. value_type* _address(){return (value_type*)(this);}
  219. //////////////////////////////////////
  220. // Implicit basic constructors
  221. tvec4();
  222. tvec4(tvec4<thalf> const & v);
  223. //////////////////////////////////////
  224. // Explicit basic constructors
  225. explicit tvec4(thalf s);
  226. explicit tvec4(thalf s0, thalf s1, thalf s2, thalf s3);
  227. //////////////////////////////////////
  228. // Swizzle constructors
  229. tvec4(tref4<thalf> const & r);
  230. //////////////////////////////////////
  231. // Convertion scalar constructors
  232. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  233. template <typename U>
  234. explicit tvec4(U x);
  235. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  236. template <typename A, typename B, typename C, typename D>
  237. explicit tvec4(A x, B y, C z, D w);
  238. //////////////////////////////////////
  239. // Convertion vector constructors
  240. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  241. template <typename A, typename B, typename C>
  242. explicit tvec4(const tvec2<A>& v, B s1, C s2);
  243. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  244. template <typename A, typename B, typename C>
  245. explicit tvec4(A s1, const tvec2<B>& v, C s2);
  246. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  247. template <typename A, typename B, typename C>
  248. explicit tvec4(A s1, B s2, const tvec2<C>& v);
  249. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  250. template <typename A, typename B>
  251. explicit tvec4(const tvec3<A>& v, B s);
  252. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  253. template <typename A, typename B>
  254. explicit tvec4(A s, const tvec3<B>& v);
  255. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  256. template <typename A, typename B>
  257. explicit tvec4(const tvec2<A>& v1, const tvec2<B>& v2);
  258. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  259. template <typename U>
  260. explicit tvec4(const tvec4<U>& v);
  261. //////////////////////////////////////
  262. // Unary arithmetic operators
  263. tvec4<thalf>& operator= (tvec4<thalf> const & v);
  264. tvec4<thalf>& operator+=(thalf s);
  265. tvec4<thalf>& operator+=(tvec4<thalf> const & v);
  266. tvec4<thalf>& operator-=(thalf s);
  267. tvec4<thalf>& operator-=(tvec4<thalf> const & v);
  268. tvec4<thalf>& operator*=(thalf s);
  269. tvec4<thalf>& operator*=(tvec4<thalf> const & v);
  270. tvec4<thalf>& operator/=(thalf s);
  271. tvec4<thalf>& operator/=(tvec4<thalf> const & v);
  272. tvec4<thalf>& operator++();
  273. tvec4<thalf>& operator--();
  274. //////////////////////////////////////
  275. // Swizzle operators
  276. thalf swizzle(comp X) const;
  277. tvec2<thalf> swizzle(comp X, comp Y) const;
  278. tvec3<thalf> swizzle(comp X, comp Y, comp Z) const;
  279. tvec4<thalf> swizzle(comp X, comp Y, comp Z, comp W) const;
  280. tref4<thalf> swizzle(comp X, comp Y, comp Z, comp W);
  281. };
  282. #endif//GLM_USE_ANONYMOUS_UNION
  283. }
  284. //namespace detail
  285. namespace gtc{
  286. //! GLM_GTC_half_float extension: Add support for half precision floating-point types
  287. namespace half_float
  288. {
  289. //! Type for half-precision floating-point numbers.
  290. //! From GLM_GTC_half_float extension.
  291. typedef detail::thalf half;
  292. //! Vector of 2 half-precision floating-point numbers.
  293. //! From GLM_GTC_half_float extension.
  294. typedef detail::tvec2<detail::thalf> hvec2;
  295. //! Vector of 3 half-precision floating-point numbers.
  296. //! From GLM_GTC_half_float extension.
  297. typedef detail::tvec3<detail::thalf> hvec3;
  298. //! Vector of 4 half-precision floating-point numbers.
  299. //! From GLM_GTC_half_float extension.
  300. typedef detail::tvec4<detail::thalf> hvec4;
  301. //! 2 * 2 matrix of half-precision floating-point numbers.
  302. //! From GLM_GTC_half_float extension.
  303. typedef detail::tmat2x2<detail::thalf> hmat2;
  304. //! 3 * 3 matrix of half-precision floating-point numbers.
  305. //! From GLM_GTC_half_float extension.
  306. typedef detail::tmat3x3<detail::thalf> hmat3;
  307. //! 4 * 4 matrix of half-precision floating-point numbers.
  308. //! From GLM_GTC_half_float extension.
  309. typedef detail::tmat4x4<detail::thalf> hmat4;
  310. }//namespace half_float
  311. }//namespace gtc
  312. }//namespace glm
  313. #define GLM_GTC_half_float namespace gtc::half_float
  314. #ifndef GLM_GTC_GLOBAL
  315. namespace glm {using GLM_GTC_half_float;}
  316. #endif//GLM_GTC_GLOBAL
  317. #include "half_float.inl"
  318. #endif//glm_gtc_half_float