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.

454 lines
17 KiB

  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_half_float
  24. /// @file glm/gtc/half_float.hpp
  25. /// @date 2009-04-29 / 2012-11-06
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see core (dependence)
  29. ///
  30. /// @defgroup gtc_half_float GLM_GTC_half_float
  31. /// @ingroup gtc
  32. ///
  33. /// Defines the half-precision floating-point type, along with various typedefs for vectors and matrices.
  34. /// <glm/gtc/half_float.hpp> need to be included to use these functionalities.
  35. ///////////////////////////////////////////////////////////////////////////////////
  36. #ifndef GLM_GTC_half_float
  37. #define GLM_GTC_half_float GLM_VERSION
  38. // Dependency:
  39. #include "../glm.hpp"
  40. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  41. # pragma message("GLM: GLM_GTC_half_float extension included")
  42. #endif
  43. namespace glm{
  44. namespace detail
  45. {
  46. #if(GLM_COMPONENT == GLM_COMPONENT_CXX98)
  47. template <>
  48. struct tvec2<half>
  49. {
  50. enum ctor{null};
  51. typedef half value_type;
  52. typedef std::size_t size_type;
  53. GLM_FUNC_DECL size_type length() const;
  54. static GLM_FUNC_DECL size_type value_size();
  55. typedef tvec2<half> type;
  56. typedef tvec2<bool> bool_type;
  57. //////////////////////////////////////
  58. // Data
  59. half x, y;
  60. //////////////////////////////////////
  61. // Accesses
  62. GLM_FUNC_DECL half & operator[](size_type i);
  63. GLM_FUNC_DECL half const & operator[](size_type i) const;
  64. //////////////////////////////////////
  65. // Implicit basic constructors
  66. GLM_FUNC_DECL tvec2();
  67. GLM_FUNC_DECL tvec2(tvec2<half> const & v);
  68. //////////////////////////////////////
  69. // Explicit basic constructors
  70. GLM_FUNC_DECL explicit tvec2(ctor);
  71. GLM_FUNC_DECL explicit tvec2(
  72. half const & s);
  73. GLM_FUNC_DECL explicit tvec2(
  74. half const & s1,
  75. half const & s2);
  76. //////////////////////////////////////
  77. // Swizzle constructors
  78. GLM_FUNC_DECL tvec2(tref2<half> const & r);
  79. //////////////////////////////////////
  80. // Convertion scalar constructors
  81. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  82. template <typename U>
  83. GLM_FUNC_DECL explicit tvec2(U const & x);
  84. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  85. template <typename U, typename V>
  86. GLM_FUNC_DECL explicit tvec2(U const & x, V const & y);
  87. //////////////////////////////////////
  88. // Convertion vector constructors
  89. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  90. template <typename U>
  91. GLM_FUNC_DECL explicit tvec2(tvec2<U> const & v);
  92. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  93. template <typename U>
  94. GLM_FUNC_DECL explicit tvec2(tvec3<U> const & v);
  95. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  96. template <typename U>
  97. GLM_FUNC_DECL explicit tvec2(tvec4<U> const & v);
  98. //////////////////////////////////////
  99. // Unary arithmetic operators
  100. GLM_FUNC_DECL tvec2<half>& operator= (tvec2<half> const & v);
  101. GLM_FUNC_DECL tvec2<half>& operator+=(half const & s);
  102. GLM_FUNC_DECL tvec2<half>& operator+=(tvec2<half> const & v);
  103. GLM_FUNC_DECL tvec2<half>& operator-=(half const & s);
  104. GLM_FUNC_DECL tvec2<half>& operator-=(tvec2<half> const & v);
  105. GLM_FUNC_DECL tvec2<half>& operator*=(half const & s);
  106. GLM_FUNC_DECL tvec2<half>& operator*=(tvec2<half> const & v);
  107. GLM_FUNC_DECL tvec2<half>& operator/=(half const & s);
  108. GLM_FUNC_DECL tvec2<half>& operator/=(tvec2<half> const & v);
  109. GLM_FUNC_DECL tvec2<half>& operator++();
  110. GLM_FUNC_DECL tvec2<half>& operator--();
  111. //////////////////////////////////////
  112. // Swizzle operators
  113. GLM_FUNC_DECL half swizzle(comp X) const;
  114. GLM_FUNC_DECL tvec2<half> swizzle(comp X, comp Y) const;
  115. GLM_FUNC_DECL tvec3<half> swizzle(comp X, comp Y, comp Z) const;
  116. GLM_FUNC_DECL tvec4<half> swizzle(comp X, comp Y, comp Z, comp W) const;
  117. GLM_FUNC_DECL tref2<half> swizzle(comp X, comp Y);
  118. };
  119. template <>
  120. struct tvec3<half>
  121. {
  122. enum ctor{null};
  123. typedef half value_type;
  124. typedef std::size_t size_type;
  125. GLM_FUNC_DECL size_type length() const;
  126. static GLM_FUNC_DECL size_type value_size();
  127. typedef tvec3<half> type;
  128. typedef tvec3<bool> bool_type;
  129. //////////////////////////////////////
  130. // Data
  131. half x, y, z;
  132. //////////////////////////////////////
  133. // Accesses
  134. GLM_FUNC_DECL half & operator[](size_type i);
  135. GLM_FUNC_DECL half const & operator[](size_type i) const;
  136. //////////////////////////////////////
  137. // Implicit basic constructors
  138. GLM_FUNC_DECL tvec3();
  139. GLM_FUNC_DECL tvec3(tvec3<half> const & v);
  140. //////////////////////////////////////
  141. // Explicit basic constructors
  142. GLM_FUNC_DECL explicit tvec3(ctor);
  143. GLM_FUNC_DECL explicit tvec3(
  144. half const & s);
  145. GLM_FUNC_DECL explicit tvec3(
  146. half const & s1,
  147. half const & s2,
  148. half const & s3);
  149. //////////////////////////////////////
  150. // Swizzle constructors
  151. GLM_FUNC_DECL tvec3(tref3<half> const & r);
  152. //////////////////////////////////////
  153. // Convertion scalar constructors
  154. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  155. template <typename U>
  156. GLM_FUNC_DECL explicit tvec3(U const & x);
  157. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  158. template <typename U, typename V, typename W>
  159. GLM_FUNC_DECL explicit tvec3(U const & x, V const & y, W const & z);
  160. //////////////////////////////////////
  161. // Convertion vector constructors
  162. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  163. template <typename A, typename B>
  164. GLM_FUNC_DECL explicit tvec3(tvec2<A> const & v, B const & s);
  165. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  166. template <typename A, typename B>
  167. GLM_FUNC_DECL explicit tvec3(A const & s, tvec2<B> const & v);
  168. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  169. template <typename U>
  170. GLM_FUNC_DECL explicit tvec3(tvec3<U> const & v);
  171. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  172. template <typename U>
  173. GLM_FUNC_DECL explicit tvec3(tvec4<U> const & v);
  174. //////////////////////////////////////
  175. // Unary arithmetic operators
  176. GLM_FUNC_DECL tvec3<half>& operator= (tvec3<half> const & v);
  177. GLM_FUNC_DECL tvec3<half>& operator+=(half const & s);
  178. GLM_FUNC_DECL tvec3<half>& operator+=(tvec3<half> const & v);
  179. GLM_FUNC_DECL tvec3<half>& operator-=(half const & s);
  180. GLM_FUNC_DECL tvec3<half>& operator-=(tvec3<half> const & v);
  181. GLM_FUNC_DECL tvec3<half>& operator*=(half const & s);
  182. GLM_FUNC_DECL tvec3<half>& operator*=(tvec3<half> const & v);
  183. GLM_FUNC_DECL tvec3<half>& operator/=(half const & s);
  184. GLM_FUNC_DECL tvec3<half>& operator/=(tvec3<half> const & v);
  185. GLM_FUNC_DECL tvec3<half>& operator++();
  186. GLM_FUNC_DECL tvec3<half>& operator--();
  187. //////////////////////////////////////
  188. // Swizzle operators
  189. GLM_FUNC_DECL half swizzle(comp X) const;
  190. GLM_FUNC_DECL tvec2<half> swizzle(comp X, comp Y) const;
  191. GLM_FUNC_DECL tvec3<half> swizzle(comp X, comp Y, comp Z) const;
  192. GLM_FUNC_DECL tvec4<half> swizzle(comp X, comp Y, comp Z, comp W) const;
  193. GLM_FUNC_DECL tref3<half> swizzle(comp X, comp Y, comp Z);
  194. };
  195. template <>
  196. struct tvec4<half>
  197. {
  198. enum ctor{null};
  199. typedef half value_type;
  200. typedef std::size_t size_type;
  201. GLM_FUNC_DECL size_type length() const;
  202. static GLM_FUNC_DECL size_type value_size();
  203. typedef tvec4<half> type;
  204. typedef tvec4<bool> bool_type;
  205. //////////////////////////////////////
  206. // Data
  207. half x, y, z, w;
  208. //////////////////////////////////////
  209. // Accesses
  210. GLM_FUNC_DECL half & operator[](size_type i);
  211. GLM_FUNC_DECL half const & operator[](size_type i) const;
  212. //////////////////////////////////////
  213. // Implicit basic constructors
  214. GLM_FUNC_DECL tvec4();
  215. GLM_FUNC_DECL tvec4(tvec4<half> const & v);
  216. //////////////////////////////////////
  217. // Explicit basic constructors
  218. GLM_FUNC_DECL explicit tvec4(ctor);
  219. GLM_FUNC_DECL explicit tvec4(
  220. half const & s);
  221. GLM_FUNC_DECL explicit tvec4(
  222. half const & s0,
  223. half const & s1,
  224. half const & s2,
  225. half const & s3);
  226. //////////////////////////////////////
  227. // Swizzle constructors
  228. GLM_FUNC_DECL tvec4(tref4<half> const & r);
  229. //////////////////////////////////////
  230. // Convertion scalar constructors
  231. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  232. template <typename U>
  233. GLM_FUNC_DECL explicit tvec4(U const & x);
  234. //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  235. template <typename A, typename B, typename C, typename D>
  236. GLM_FUNC_DECL explicit tvec4(A const & x, B const & y, C const & z, D const & w);
  237. //////////////////////////////////////
  238. // Convertion vector constructors
  239. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  240. template <typename A, typename B, typename C>
  241. GLM_FUNC_DECL explicit tvec4(tvec2<A> const & v, B const & s1, C const & s2);
  242. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  243. template <typename A, typename B, typename C>
  244. GLM_FUNC_DECL explicit tvec4(A const & s1, tvec2<B> const & v, C const & s2);
  245. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  246. template <typename A, typename B, typename C>
  247. GLM_FUNC_DECL explicit tvec4(A const & s1, B const & s2, tvec2<C> const & v);
  248. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  249. template <typename A, typename B>
  250. GLM_FUNC_DECL explicit tvec4(tvec3<A> const & v, B const & s);
  251. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  252. template <typename A, typename B>
  253. GLM_FUNC_DECL explicit tvec4(A const & s, tvec3<B> const & v);
  254. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  255. template <typename A, typename B>
  256. GLM_FUNC_DECL explicit tvec4(tvec2<A> const & v1, tvec2<B> const & v2);
  257. //! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
  258. template <typename U>
  259. GLM_FUNC_DECL explicit tvec4(tvec4<U> const & v);
  260. //////////////////////////////////////
  261. // Unary arithmetic operators
  262. GLM_FUNC_DECL tvec4<half>& operator= (tvec4<half> const & v);
  263. GLM_FUNC_DECL tvec4<half>& operator+=(half const & s);
  264. GLM_FUNC_DECL tvec4<half>& operator+=(tvec4<half> const & v);
  265. GLM_FUNC_DECL tvec4<half>& operator-=(half const & s);
  266. GLM_FUNC_DECL tvec4<half>& operator-=(tvec4<half> const & v);
  267. GLM_FUNC_DECL tvec4<half>& operator*=(half const & s);
  268. GLM_FUNC_DECL tvec4<half>& operator*=(tvec4<half> const & v);
  269. GLM_FUNC_DECL tvec4<half>& operator/=(half const & s);
  270. GLM_FUNC_DECL tvec4<half>& operator/=(tvec4<half> const & v);
  271. GLM_FUNC_DECL tvec4<half>& operator++();
  272. GLM_FUNC_DECL tvec4<half>& operator--();
  273. //////////////////////////////////////
  274. // Swizzle operators
  275. GLM_FUNC_DECL half swizzle(comp X) const;
  276. GLM_FUNC_DECL tvec2<half> swizzle(comp X, comp Y) const;
  277. GLM_FUNC_DECL tvec3<half> swizzle(comp X, comp Y, comp Z) const;
  278. GLM_FUNC_DECL tvec4<half> swizzle(comp X, comp Y, comp Z, comp W) const;
  279. GLM_FUNC_DECL tref4<half> swizzle(comp X, comp Y, comp Z, comp W);
  280. };
  281. #endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98)
  282. }
  283. //namespace detail
  284. /// @addtogroup gtc_half_float
  285. /// @{
  286. /// Type for half-precision floating-point numbers.
  287. /// @see gtc_half_float
  288. typedef detail::half half;
  289. /// Vector of 2 half-precision floating-point numbers.
  290. /// @see gtc_half_float
  291. typedef detail::tvec2<detail::half> hvec2;
  292. /// Vector of 3 half-precision floating-point numbers.
  293. /// @see gtc_half_float
  294. typedef detail::tvec3<detail::half> hvec3;
  295. /// Vector of 4 half-precision floating-point numbers.
  296. /// @see gtc_half_float
  297. typedef detail::tvec4<detail::half> hvec4;
  298. /// 2 * 2 matrix of half-precision floating-point numbers.
  299. /// @see gtc_half_float
  300. typedef detail::tmat2x2<detail::half> hmat2;
  301. /// 3 * 3 matrix of half-precision floating-point numbers.
  302. /// @see gtc_half_float
  303. typedef detail::tmat3x3<detail::half> hmat3;
  304. /// 4 * 4 matrix of half-precision floating-point numbers.
  305. /// @see gtc_half_float
  306. typedef detail::tmat4x4<detail::half> hmat4;
  307. /// 2 * 2 matrix of half-precision floating-point numbers.
  308. /// @see gtc_half_float
  309. typedef detail::tmat2x2<detail::half> hmat2x2;
  310. /// 2 * 3 matrix of half-precision floating-point numbers.
  311. /// @see gtc_half_float
  312. typedef detail::tmat2x3<detail::half> hmat2x3;
  313. /// 2 * 4 matrix of half-precision floating-point numbers.
  314. /// @see gtc_half_float
  315. typedef detail::tmat2x4<detail::half> hmat2x4;
  316. /// 3 * 2 matrix of half-precision floating-point numbers.
  317. /// @see gtc_half_float
  318. typedef detail::tmat3x2<detail::half> hmat3x2;
  319. /// 3 * 3 matrix of half-precision floating-point numbers.
  320. /// @see gtc_half_float
  321. typedef detail::tmat3x3<detail::half> hmat3x3;
  322. /// 3 * 4 matrix of half-precision floating-point numbers.
  323. /// @see gtc_half_float
  324. typedef detail::tmat3x4<detail::half> hmat3x4;
  325. /// 4 * 2 matrix of half-precision floating-point numbers.
  326. /// @see gtc_half_float
  327. typedef detail::tmat4x2<detail::half> hmat4x2;
  328. /// 4 * 3 matrix of half-precision floating-point numbers.
  329. /// @see gtc_half_float
  330. typedef detail::tmat4x3<detail::half> hmat4x3;
  331. /// 4 * 4 matrix of half-precision floating-point numbers.
  332. /// @see gtc_half_float
  333. typedef detail::tmat4x4<detail::half> hmat4x4;
  334. /// Returns the absolute value of a half-precision floating-point value
  335. /// @see gtc_half_float
  336. GLM_FUNC_DECL half abs(half const & x);
  337. /// Returns the absolute value of a half-precision floating-point two dimensional vector
  338. /// @see gtc_half_float
  339. GLM_FUNC_DECL hvec2 abs(hvec2 const & x);
  340. /// Returns the absolute value of a half-precision floating-point three dimensional vector
  341. /// @see gtc_half_float
  342. GLM_FUNC_DECL hvec3 abs(hvec3 const & x);
  343. /// Returns the absolute value of a half-precision floating-point four dimensional vector
  344. /// @see gtc_half_float
  345. GLM_FUNC_DECL hvec4 abs(hvec4 const & x);
  346. /// Selects which vector each returned component comes
  347. /// from. For a component of <a> that is false, the
  348. /// corresponding component of x is returned. For a
  349. /// component of a that is true, the corresponding
  350. /// component of y is returned. Components of x and y that
  351. /// are not selected are allowed to be invalid floating point
  352. /// values and will have no effect on the results. Thus, this
  353. /// provides different functionality than
  354. /// genType mix(genType x, genType y, genType(a))
  355. /// where a is a Boolean vector.
  356. ///
  357. /// @see gtc_half_float
  358. GLM_FUNC_DECL half mix(half const & x, half const & y, bool const & a);
  359. /// @}
  360. }// namespace glm
  361. #include "half_float.inl"
  362. #endif//GLM_GTC_half_float