half_float.hpp 13 KB

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