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.

193 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 core
  24. /// @file glm/core/func_packing.hpp
  25. /// @date 2010-03-17 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  29. ///
  30. /// @defgroup core_func_packing Floating-Point Pack and Unpack Functions
  31. /// @ingroup core
  32. ///
  33. /// These functions do not operate component-wise, rather as described in each case.
  34. ///////////////////////////////////////////////////////////////////////////////////
  35. #ifndef GLM_CORE_func_packing
  36. #define GLM_CORE_func_packing GLM_VERSION
  37. namespace glm
  38. {
  39. /// @addtogroup core_func_packing
  40. /// @{
  41. //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  42. //! Then, the results are packed into the returned 32-bit unsigned integer.
  43. //!
  44. //! The conversion for component c of v to fixed point is done as follows:
  45. //! packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
  46. //!
  47. //! The first component of the vector will be written to the least significant bits of the output;
  48. //! the last component will be written to the most significant bits.
  49. //!
  50. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 man page</a>
  51. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  52. GLM_FUNC_DECL detail::uint32 packUnorm2x16(detail::tvec2<detail::float32> const & v);
  53. //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  54. //! Then, the results are packed into the returned 32-bit unsigned integer.
  55. //!
  56. //! The conversion for component c of v to fixed point is done as follows:
  57. //! packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
  58. //!
  59. //! The first component of the vector will be written to the least significant bits of the output;
  60. //! the last component will be written to the most significant bits.
  61. //!
  62. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 man page</a>
  63. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  64. GLM_FUNC_DECL detail::uint32 packSnorm2x16(detail::tvec2<detail::float32> const & v);
  65. //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  66. //! Then, the results are packed into the returned 32-bit unsigned integer.
  67. //!
  68. //! The conversion for component c of v to fixed point is done as follows:
  69. //! packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
  70. //!
  71. //! The first component of the vector will be written to the least significant bits of the output;
  72. //! the last component will be written to the most significant bits.
  73. //!
  74. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
  75. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  76. GLM_FUNC_DECL detail::uint32 packUnorm4x8(detail::tvec4<detail::float32> const & v);
  77. //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  78. //! Then, the results are packed into the returned 32-bit unsigned integer.
  79. //!
  80. //! The conversion for component c of v to fixed point is done as follows:
  81. //! packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
  82. //!
  83. //! The first component of the vector will be written to the least significant bits of the output;
  84. //! the last component will be written to the most significant bits.
  85. //!
  86. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  87. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  88. GLM_FUNC_DECL detail::uint32 packSnorm4x8(detail::tvec4<detail::float32> const & v);
  89. //! First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
  90. //! Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  91. //!
  92. //! The conversion for unpacked fixed-point value f to floating point is done as follows:
  93. //! unpackUnorm2x16: f / 65535.0
  94. //!
  95. //! The first component of the returned vector will be extracted from the least significant bits of the input;
  96. //! the last component will be extracted from the most significant bits.
  97. //!
  98. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a>
  99. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  100. GLM_FUNC_DECL detail::tvec2<detail::float32> unpackUnorm2x16(detail::uint32 const & p);
  101. //! First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
  102. //! Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  103. //!
  104. //! The conversion for unpacked fixed-point value f to floating point is done as follows:
  105. //! unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
  106. //!
  107. //! The first component of the returned vector will be extracted from the least significant bits of the input;
  108. //! the last component will be extracted from the most significant bits.
  109. //!
  110. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 man page</a>
  111. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  112. GLM_FUNC_DECL detail::tvec2<detail::float32> unpackSnorm2x16(detail::uint32 const & p);
  113. /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
  114. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  115. ///
  116. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  117. /// unpackUnorm4x8: f / 255.0
  118. ///
  119. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  120. /// the last component will be extracted from the most significant bits.
  121. ///
  122. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
  123. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  124. GLM_FUNC_DECL detail::tvec4<detail::float32> unpackUnorm4x8(detail::uint32 const & p);
  125. /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
  126. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  127. ///
  128. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  129. /// unpackSnorm4x8: clamp(f / 127.0, -1, +1)
  130. ///
  131. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  132. /// the last component will be extracted from the most significant bits.
  133. ///
  134. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
  135. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  136. GLM_FUNC_DECL detail::tvec4<detail::float32> unpackSnorm4x8(detail::uint32 const & p);
  137. /// Returns a double-precision value obtained by packing the components of v into a 64-bit value.
  138. /// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified.
  139. /// Otherwise, the bit- level representation of v is preserved.
  140. /// The first vector component specifies the 32 least significant bits;
  141. /// the second component specifies the 32 most significant bits.
  142. ///
  143. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packDouble2x32.xml">GLSL packDouble2x32 man page</a>
  144. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  145. GLM_FUNC_DECL double packDouble2x32(detail::tvec2<detail::uint32> const & v);
  146. /// Returns a two-component unsigned integer vector representation of v.
  147. /// The bit-level representation of v is preserved.
  148. /// The first component of the vector contains the 32 least significant bits of the double;
  149. /// the second component consists the 32 most significant bits.
  150. ///
  151. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 man page</a>
  152. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  153. GLM_FUNC_DECL detail::tvec2<detail::uint32> unpackDouble2x32(double const & v);
  154. /// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
  155. /// to the 16-bit floating-point representation found in the OpenGL Specification,
  156. /// and then packing these two 16- bit integers into a 32-bit unsigned integer.
  157. /// The first vector component specifies the 16 least-significant bits of the result;
  158. /// the second component specifies the 16 most-significant bits.
  159. ///
  160. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
  161. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  162. GLM_FUNC_DECL uint packHalf2x16(vec2 const & v);
  163. /// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
  164. /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
  165. /// and converting them to 32-bit floating-point values.
  166. /// The first component of the vector is obtained from the 16 least-significant bits of v;
  167. /// the second component is obtained from the 16 most-significant bits of v.
  168. ///
  169. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
  170. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
  171. GLM_FUNC_DECL vec2 unpackHalf2x16(uint const & v);
  172. /// @}
  173. }//namespace glm
  174. #include "func_packing.inl"
  175. #endif//GLM_CORE_func_packing