9
3

packing.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /// @ref core
  2. /// @file glm/packing.hpp
  3. ///
  4. /// @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>
  5. /// @see gtc_packing
  6. ///
  7. /// @defgroup core_func_packing Floating-Point Pack and Unpack Functions
  8. /// @ingroup core
  9. ///
  10. /// Provides GLSL functions to pack and unpack half, single and double-precision floating point values into more compact integer types.
  11. ///
  12. /// These functions do not operate component-wise, rather as described in each case.
  13. ///
  14. /// Include <glm/packing.hpp> to use these core features.
  15. #pragma once
  16. #include "./ext/vector_uint2.hpp"
  17. #include "./ext/vector_float2.hpp"
  18. #include "./ext/vector_float4.hpp"
  19. namespace glm
  20. {
  21. /// @addtogroup core_func_packing
  22. /// @{
  23. /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  24. /// Then, the results are packed into the returned 32-bit unsigned integer.
  25. ///
  26. /// The conversion for component c of v to fixed point is done as follows:
  27. /// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
  28. ///
  29. /// The first component of the vector will be written to the least significant bits of the output;
  30. /// the last component will be written to the most significant bits.
  31. ///
  32. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 man page</a>
  33. /// @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>
  34. GLM_FUNC_DECL uint packUnorm2x16(vec2 const& v);
  35. /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  36. /// Then, the results are packed into the returned 32-bit unsigned integer.
  37. ///
  38. /// The conversion for component c of v to fixed point is done as follows:
  39. /// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
  40. ///
  41. /// The first component of the vector will be written to the least significant bits of the output;
  42. /// the last component will be written to the most significant bits.
  43. ///
  44. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 man page</a>
  45. /// @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>
  46. GLM_FUNC_DECL uint packSnorm2x16(vec2 const& v);
  47. /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  48. /// Then, the results are packed into the returned 32-bit unsigned integer.
  49. ///
  50. /// The conversion for component c of v to fixed point is done as follows:
  51. /// packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
  52. ///
  53. /// The first component of the vector will be written to the least significant bits of the output;
  54. /// the last component will be written to the most significant bits.
  55. ///
  56. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
  57. /// @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>
  58. GLM_FUNC_DECL uint packUnorm4x8(vec4 const& v);
  59. /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
  60. /// Then, the results are packed into the returned 32-bit unsigned integer.
  61. ///
  62. /// The conversion for component c of v to fixed point is done as follows:
  63. /// packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
  64. ///
  65. /// The first component of the vector will be written to the least significant bits of the output;
  66. /// the last component will be written to the most significant bits.
  67. ///
  68. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  69. /// @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>
  70. GLM_FUNC_DECL uint packSnorm4x8(vec4 const& v);
  71. /// 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.
  72. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  73. ///
  74. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  75. /// unpackUnorm2x16: f / 65535.0
  76. ///
  77. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  78. /// the last component will be extracted from the most significant bits.
  79. ///
  80. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a>
  81. /// @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>
  82. GLM_FUNC_DECL vec2 unpackUnorm2x16(uint p);
  83. /// 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.
  84. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  85. ///
  86. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  87. /// unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
  88. ///
  89. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  90. /// the last component will be extracted from the most significant bits.
  91. ///
  92. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 man page</a>
  93. /// @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>
  94. GLM_FUNC_DECL vec2 unpackSnorm2x16(uint p);
  95. /// 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.
  96. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  97. ///
  98. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  99. /// unpackUnorm4x8: f / 255.0
  100. ///
  101. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  102. /// the last component will be extracted from the most significant bits.
  103. ///
  104. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
  105. /// @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>
  106. GLM_FUNC_DECL vec4 unpackUnorm4x8(uint p);
  107. /// 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.
  108. /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
  109. ///
  110. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  111. /// unpackSnorm4x8: clamp(f / 127.0, -1, +1)
  112. ///
  113. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  114. /// the last component will be extracted from the most significant bits.
  115. ///
  116. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
  117. /// @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>
  118. GLM_FUNC_DECL vec4 unpackSnorm4x8(uint p);
  119. /// Returns a double-qualifier value obtained by packing the components of v into a 64-bit value.
  120. /// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified.
  121. /// Otherwise, the bit- level representation of v is preserved.
  122. /// The first vector component specifies the 32 least significant bits;
  123. /// the second component specifies the 32 most significant bits.
  124. ///
  125. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packDouble2x32.xml">GLSL packDouble2x32 man page</a>
  126. /// @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>
  127. GLM_FUNC_DECL double packDouble2x32(uvec2 const& v);
  128. /// Returns a two-component unsigned integer vector representation of v.
  129. /// The bit-level representation of v is preserved.
  130. /// The first component of the vector contains the 32 least significant bits of the double;
  131. /// the second component consists the 32 most significant bits.
  132. ///
  133. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 man page</a>
  134. /// @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>
  135. GLM_FUNC_DECL uvec2 unpackDouble2x32(double v);
  136. /// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
  137. /// to the 16-bit floating-point representation found in the OpenGL Specification,
  138. /// and then packing these two 16- bit integers into a 32-bit unsigned integer.
  139. /// The first vector component specifies the 16 least-significant bits of the result;
  140. /// the second component specifies the 16 most-significant bits.
  141. ///
  142. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
  143. /// @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>
  144. GLM_FUNC_DECL uint packHalf2x16(vec2 const& v);
  145. /// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
  146. /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
  147. /// and converting them to 32-bit floating-point values.
  148. /// The first component of the vector is obtained from the 16 least-significant bits of v;
  149. /// the second component is obtained from the 16 most-significant bits of v.
  150. ///
  151. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 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 vec2 unpackHalf2x16(uint v);
  154. /// @}
  155. }//namespace glm
  156. #include "detail/func_packing.inl"