packing.hpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /// @ref gtc_packing
  2. /// @file glm/gtc/packing.hpp
  3. ///
  4. /// @see core (dependence)
  5. ///
  6. /// @defgroup gtc_packing GLM_GTC_packing
  7. /// @ingroup gtc
  8. ///
  9. /// Include <glm/gtc/packing.hpp> to use the features of this extension.
  10. ///
  11. /// This extension provides a set of function to convert vertors to packed
  12. /// formats.
  13. #pragma once
  14. // Dependency:
  15. #include "type_precision.hpp"
  16. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  17. # pragma message("GLM: GLM_GTC_packing extension included")
  18. #endif
  19. namespace glm
  20. {
  21. /// @addtogroup gtc_packing
  22. /// @{
  23. /// First, converts the normalized floating-point value v into a 8-bit integer value.
  24. /// Then, the results are packed into the returned 8-bit unsigned integer.
  25. ///
  26. /// The conversion for component c of v to fixed point is done as follows:
  27. /// packUnorm1x8: round(clamp(c, 0, +1) * 255.0)
  28. ///
  29. /// @see gtc_packing
  30. /// @see uint16 packUnorm2x8(vec2 const& v)
  31. /// @see uint32 packUnorm4x8(vec4 const& v)
  32. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 uint8 packUnorm1x8(float v);
  35. /// Convert a single 8-bit integer to a normalized floating-point value.
  36. ///
  37. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  38. /// unpackUnorm4x8: f / 255.0
  39. ///
  40. /// @see gtc_packing
  41. /// @see vec2 unpackUnorm2x8(uint16 p)
  42. /// @see vec4 unpackUnorm4x8(uint32 p)
  43. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
  44. /// @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>
  45. GLM_FUNC_DECL float unpackUnorm1x8(uint8 p);
  46. /// First, converts each component of the normalized floating-point value v into 8-bit integer values.
  47. /// Then, the results are packed into the returned 16-bit unsigned integer.
  48. ///
  49. /// The conversion for component c of v to fixed point is done as follows:
  50. /// packUnorm2x8: round(clamp(c, 0, +1) * 255.0)
  51. ///
  52. /// The first component of the vector will be written to the least significant bits of the output;
  53. /// the last component will be written to the most significant bits.
  54. ///
  55. /// @see gtc_packing
  56. /// @see uint8 packUnorm1x8(float const& v)
  57. /// @see uint32 packUnorm4x8(vec4 const& v)
  58. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
  59. /// @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>
  60. GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const& v);
  61. /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit unsigned integers.
  62. /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
  63. ///
  64. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  65. /// unpackUnorm4x8: f / 255.0
  66. ///
  67. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  68. /// the last component will be extracted from the most significant bits.
  69. ///
  70. /// @see gtc_packing
  71. /// @see float unpackUnorm1x8(uint8 v)
  72. /// @see vec4 unpackUnorm4x8(uint32 p)
  73. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 man page</a>
  74. /// @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>
  75. GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 p);
  76. /// First, converts the normalized floating-point value v into 8-bit integer value.
  77. /// Then, the results are packed into the returned 8-bit unsigned integer.
  78. ///
  79. /// The conversion to fixed point is done as follows:
  80. /// packSnorm1x8: round(clamp(s, -1, +1) * 127.0)
  81. ///
  82. /// @see gtc_packing
  83. /// @see uint16 packSnorm2x8(vec2 const& v)
  84. /// @see uint32 packSnorm4x8(vec4 const& v)
  85. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  86. /// @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>
  87. GLM_FUNC_DECL uint8 packSnorm1x8(float s);
  88. /// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers.
  89. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar.
  90. ///
  91. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  92. /// unpackSnorm1x8: clamp(f / 127.0, -1, +1)
  93. ///
  94. /// @see gtc_packing
  95. /// @see vec2 unpackSnorm2x8(uint16 p)
  96. /// @see vec4 unpackSnorm4x8(uint32 p)
  97. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
  98. /// @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>
  99. GLM_FUNC_DECL float unpackSnorm1x8(uint8 p);
  100. /// First, converts each component of the normalized floating-point value v into 8-bit integer values.
  101. /// Then, the results are packed into the returned 16-bit unsigned integer.
  102. ///
  103. /// The conversion for component c of v to fixed point is done as follows:
  104. /// packSnorm2x8: round(clamp(c, -1, +1) * 127.0)
  105. ///
  106. /// The first component of the vector will be written to the least significant bits of the output;
  107. /// the last component will be written to the most significant bits.
  108. ///
  109. /// @see gtc_packing
  110. /// @see uint8 packSnorm1x8(float const& v)
  111. /// @see uint32 packSnorm4x8(vec4 const& v)
  112. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  113. /// @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>
  114. GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const& v);
  115. /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit signed integers.
  116. /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
  117. ///
  118. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  119. /// unpackSnorm2x8: clamp(f / 127.0, -1, +1)
  120. ///
  121. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  122. /// the last component will be extracted from the most significant bits.
  123. ///
  124. /// @see gtc_packing
  125. /// @see float unpackSnorm1x8(uint8 p)
  126. /// @see vec4 unpackSnorm4x8(uint32 p)
  127. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.xml">GLSL unpackSnorm4x8 man page</a>
  128. /// @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>
  129. GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p);
  130. /// First, converts the normalized floating-point value v into a 16-bit integer value.
  131. /// Then, the results are packed into the returned 16-bit unsigned integer.
  132. ///
  133. /// The conversion for component c of v to fixed point is done as follows:
  134. /// packUnorm1x16: round(clamp(c, 0, +1) * 65535.0)
  135. ///
  136. /// @see gtc_packing
  137. /// @see uint16 packSnorm1x16(float const& v)
  138. /// @see uint64 packSnorm4x16(vec4 const& v)
  139. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
  140. /// @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>
  141. GLM_FUNC_DECL uint16 packUnorm1x16(float v);
  142. /// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers.
  143. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar.
  144. ///
  145. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  146. /// unpackUnorm1x16: f / 65535.0
  147. ///
  148. /// @see gtc_packing
  149. /// @see vec2 unpackUnorm2x16(uint32 p)
  150. /// @see vec4 unpackUnorm4x16(uint64 p)
  151. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 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 float unpackUnorm1x16(uint16 p);
  154. /// First, converts each component of the normalized floating-point value v into 16-bit integer values.
  155. /// Then, the results are packed into the returned 64-bit unsigned integer.
  156. ///
  157. /// The conversion for component c of v to fixed point is done as follows:
  158. /// packUnorm4x16: round(clamp(c, 0, +1) * 65535.0)
  159. ///
  160. /// The first component of the vector will be written to the least significant bits of the output;
  161. /// the last component will be written to the most significant bits.
  162. ///
  163. /// @see gtc_packing
  164. /// @see uint16 packUnorm1x16(float const& v)
  165. /// @see uint32 packUnorm2x16(vec2 const& v)
  166. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 man page</a>
  167. /// @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>
  168. GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const& v);
  169. /// First, unpacks a single 64-bit unsigned integer p into four 16-bit unsigned integers.
  170. /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  171. ///
  172. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  173. /// unpackUnormx4x16: f / 65535.0
  174. ///
  175. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  176. /// the last component will be extracted from the most significant bits.
  177. ///
  178. /// @see gtc_packing
  179. /// @see float unpackUnorm1x16(uint16 p)
  180. /// @see vec2 unpackUnorm2x16(uint32 p)
  181. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 man page</a>
  182. /// @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>
  183. GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 p);
  184. /// First, converts the normalized floating-point value v into 16-bit integer value.
  185. /// Then, the results are packed into the returned 16-bit unsigned integer.
  186. ///
  187. /// The conversion to fixed point is done as follows:
  188. /// packSnorm1x8: round(clamp(s, -1, +1) * 32767.0)
  189. ///
  190. /// @see gtc_packing
  191. /// @see uint32 packSnorm2x16(vec2 const& v)
  192. /// @see uint64 packSnorm4x16(vec4 const& v)
  193. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  194. /// @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>
  195. GLM_FUNC_DECL uint16 packSnorm1x16(float v);
  196. /// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers.
  197. /// Then, each component is converted to a normalized floating-point value to generate the returned scalar.
  198. ///
  199. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  200. /// unpackSnorm1x16: clamp(f / 32767.0, -1, +1)
  201. ///
  202. /// @see gtc_packing
  203. /// @see vec2 unpackSnorm2x16(uint32 p)
  204. /// @see vec4 unpackSnorm4x16(uint64 p)
  205. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm1x16.xml">GLSL unpackSnorm4x8 man page</a>
  206. /// @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>
  207. GLM_FUNC_DECL float unpackSnorm1x16(uint16 p);
  208. /// First, converts each component of the normalized floating-point value v into 16-bit integer values.
  209. /// Then, the results are packed into the returned 64-bit unsigned integer.
  210. ///
  211. /// The conversion for component c of v to fixed point is done as follows:
  212. /// packSnorm2x8: round(clamp(c, -1, +1) * 32767.0)
  213. ///
  214. /// The first component of the vector will be written to the least significant bits of the output;
  215. /// the last component will be written to the most significant bits.
  216. ///
  217. /// @see gtc_packing
  218. /// @see uint16 packSnorm1x16(float const& v)
  219. /// @see uint32 packSnorm2x16(vec2 const& v)
  220. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 man page</a>
  221. /// @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>
  222. GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const& v);
  223. /// First, unpacks a single 64-bit unsigned integer p into four 16-bit signed integers.
  224. /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  225. ///
  226. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  227. /// unpackSnorm4x16: clamp(f / 32767.0, -1, +1)
  228. ///
  229. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  230. /// the last component will be extracted from the most significant bits.
  231. ///
  232. /// @see gtc_packing
  233. /// @see float unpackSnorm1x16(uint16 p)
  234. /// @see vec2 unpackSnorm2x16(uint32 p)
  235. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm4x8 man page</a>
  236. /// @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>
  237. GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 p);
  238. /// Returns an unsigned integer obtained by converting the components of a floating-point scalar
  239. /// to the 16-bit floating-point representation found in the OpenGL Specification,
  240. /// and then packing this 16-bit value into a 16-bit unsigned integer.
  241. ///
  242. /// @see gtc_packing
  243. /// @see uint32 packHalf2x16(vec2 const& v)
  244. /// @see uint64 packHalf4x16(vec4 const& v)
  245. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
  246. /// @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>
  247. GLM_FUNC_DECL uint16 packHalf1x16(float v);
  248. /// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value,
  249. /// interpreted as a 16-bit floating-point number according to the OpenGL Specification,
  250. /// and converting it to 32-bit floating-point values.
  251. ///
  252. /// @see gtc_packing
  253. /// @see vec2 unpackHalf2x16(uint32 const& v)
  254. /// @see vec4 unpackHalf4x16(uint64 const& v)
  255. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
  256. /// @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>
  257. GLM_FUNC_DECL float unpackHalf1x16(uint16 v);
  258. /// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector
  259. /// to the 16-bit floating-point representation found in the OpenGL Specification,
  260. /// and then packing these four 16-bit values into a 64-bit unsigned integer.
  261. /// The first vector component specifies the 16 least-significant bits of the result;
  262. /// the forth component specifies the 16 most-significant bits.
  263. ///
  264. /// @see gtc_packing
  265. /// @see uint16 packHalf1x16(float const& v)
  266. /// @see uint32 packHalf2x16(vec2 const& v)
  267. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
  268. /// @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>
  269. GLM_FUNC_DECL uint64 packHalf4x16(vec4 const& v);
  270. /// Returns a four-component floating-point vector with components obtained by unpacking a 64-bit unsigned integer into four 16-bit values,
  271. /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
  272. /// and converting them to 32-bit floating-point values.
  273. /// The first component of the vector is obtained from the 16 least-significant bits of v;
  274. /// the forth component is obtained from the 16 most-significant bits of v.
  275. ///
  276. /// @see gtc_packing
  277. /// @see float unpackHalf1x16(uint16 const& v)
  278. /// @see vec2 unpackHalf2x16(uint32 const& v)
  279. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
  280. /// @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>
  281. GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 p);
  282. /// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector
  283. /// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification,
  284. /// and then packing these four values into a 32-bit unsigned integer.
  285. /// The first vector component specifies the 10 least-significant bits of the result;
  286. /// the forth component specifies the 2 most-significant bits.
  287. ///
  288. /// @see gtc_packing
  289. /// @see uint32 packI3x10_1x2(uvec4 const& v)
  290. /// @see uint32 packSnorm3x10_1x2(vec4 const& v)
  291. /// @see uint32 packUnorm3x10_1x2(vec4 const& v)
  292. /// @see ivec4 unpackI3x10_1x2(uint32 const& p)
  293. GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const& v);
  294. /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit signed integers.
  295. ///
  296. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  297. /// the last component will be extracted from the most significant bits.
  298. ///
  299. /// @see gtc_packing
  300. /// @see uint32 packU3x10_1x2(uvec4 const& v)
  301. /// @see vec4 unpackSnorm3x10_1x2(uint32 const& p);
  302. /// @see uvec4 unpackI3x10_1x2(uint32 const& p);
  303. GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 p);
  304. /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector
  305. /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification,
  306. /// and then packing these four values into a 32-bit unsigned integer.
  307. /// The first vector component specifies the 10 least-significant bits of the result;
  308. /// the forth component specifies the 2 most-significant bits.
  309. ///
  310. /// @see gtc_packing
  311. /// @see uint32 packI3x10_1x2(ivec4 const& v)
  312. /// @see uint32 packSnorm3x10_1x2(vec4 const& v)
  313. /// @see uint32 packUnorm3x10_1x2(vec4 const& v)
  314. /// @see ivec4 unpackU3x10_1x2(uint32 const& p)
  315. GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const& v);
  316. /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit unsigned integers.
  317. ///
  318. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  319. /// the last component will be extracted from the most significant bits.
  320. ///
  321. /// @see gtc_packing
  322. /// @see uint32 packU3x10_1x2(uvec4 const& v)
  323. /// @see vec4 unpackSnorm3x10_1x2(uint32 const& p);
  324. /// @see uvec4 unpackI3x10_1x2(uint32 const& p);
  325. GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 p);
  326. /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values.
  327. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values.
  328. /// Then, the results are packed into the returned 32-bit unsigned integer.
  329. ///
  330. /// The conversion for component c of v to fixed point is done as follows:
  331. /// packSnorm3x10_1x2(xyz): round(clamp(c, -1, +1) * 511.0)
  332. /// packSnorm3x10_1x2(w): round(clamp(c, -1, +1) * 1.0)
  333. ///
  334. /// The first vector component specifies the 10 least-significant bits of the result;
  335. /// the forth component specifies the 2 most-significant bits.
  336. ///
  337. /// @see gtc_packing
  338. /// @see vec4 unpackSnorm3x10_1x2(uint32 const& p)
  339. /// @see uint32 packUnorm3x10_1x2(vec4 const& v)
  340. /// @see uint32 packU3x10_1x2(uvec4 const& v)
  341. /// @see uint32 packI3x10_1x2(ivec4 const& v)
  342. GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const& v);
  343. /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers.
  344. /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  345. ///
  346. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  347. /// unpackSnorm3x10_1x2(xyz): clamp(f / 511.0, -1, +1)
  348. /// unpackSnorm3x10_1x2(w): clamp(f / 511.0, -1, +1)
  349. ///
  350. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  351. /// the last component will be extracted from the most significant bits.
  352. ///
  353. /// @see gtc_packing
  354. /// @see uint32 packSnorm3x10_1x2(vec4 const& v)
  355. /// @see vec4 unpackUnorm3x10_1x2(uint32 const& p))
  356. /// @see uvec4 unpackI3x10_1x2(uint32 const& p)
  357. /// @see uvec4 unpackU3x10_1x2(uint32 const& p)
  358. GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 p);
  359. /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values.
  360. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values.
  361. /// Then, the results are packed into the returned 32-bit unsigned integer.
  362. ///
  363. /// The conversion for component c of v to fixed point is done as follows:
  364. /// packUnorm3x10_1x2(xyz): round(clamp(c, 0, +1) * 1023.0)
  365. /// packUnorm3x10_1x2(w): round(clamp(c, 0, +1) * 3.0)
  366. ///
  367. /// The first vector component specifies the 10 least-significant bits of the result;
  368. /// the forth component specifies the 2 most-significant bits.
  369. ///
  370. /// @see gtc_packing
  371. /// @see vec4 unpackUnorm3x10_1x2(uint32 const& p)
  372. /// @see uint32 packUnorm3x10_1x2(vec4 const& v)
  373. /// @see uint32 packU3x10_1x2(uvec4 const& v)
  374. /// @see uint32 packI3x10_1x2(ivec4 const& v)
  375. GLM_FUNC_DECL uint32 packUnorm3x10_1x2(vec4 const& v);
  376. /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers.
  377. /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
  378. ///
  379. /// The conversion for unpacked fixed-point value f to floating point is done as follows:
  380. /// unpackSnorm3x10_1x2(xyz): clamp(f / 1023.0, 0, +1)
  381. /// unpackSnorm3x10_1x2(w): clamp(f / 3.0, 0, +1)
  382. ///
  383. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  384. /// the last component will be extracted from the most significant bits.
  385. ///
  386. /// @see gtc_packing
  387. /// @see uint32 packSnorm3x10_1x2(vec4 const& v)
  388. /// @see vec4 unpackInorm3x10_1x2(uint32 const& p))
  389. /// @see uvec4 unpackI3x10_1x2(uint32 const& p)
  390. /// @see uvec4 unpackU3x10_1x2(uint32 const& p)
  391. GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 p);
  392. /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values.
  393. /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value.
  394. /// Then, the results are packed into the returned 32-bit unsigned integer.
  395. ///
  396. /// The first vector component specifies the 11 least-significant bits of the result;
  397. /// the last component specifies the 10 most-significant bits.
  398. ///
  399. /// @see gtc_packing
  400. /// @see vec3 unpackF2x11_1x10(uint32 const& p)
  401. GLM_FUNC_DECL uint32 packF2x11_1x10(vec3 const& v);
  402. /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value .
  403. /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector.
  404. ///
  405. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  406. /// the last component will be extracted from the most significant bits.
  407. ///
  408. /// @see gtc_packing
  409. /// @see uint32 packF2x11_1x10(vec3 const& v)
  410. GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 p);
  411. /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values.
  412. /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value.
  413. /// Then, the results are packed into the returned 32-bit unsigned integer.
  414. ///
  415. /// The first vector component specifies the 11 least-significant bits of the result;
  416. /// the last component specifies the 10 most-significant bits.
  417. ///
  418. /// packF3x9_E1x5 allows encoding into RGBE / RGB9E5 format
  419. ///
  420. /// @see gtc_packing
  421. /// @see vec3 unpackF3x9_E1x5(uint32 const& p)
  422. GLM_FUNC_DECL uint32 packF3x9_E1x5(vec3 const& v);
  423. /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value .
  424. /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector.
  425. ///
  426. /// The first component of the returned vector will be extracted from the least significant bits of the input;
  427. /// the last component will be extracted from the most significant bits.
  428. ///
  429. /// unpackF3x9_E1x5 allows decoding RGBE / RGB9E5 data
  430. ///
  431. /// @see gtc_packing
  432. /// @see uint32 packF3x9_E1x5(vec3 const& v)
  433. GLM_FUNC_DECL vec3 unpackF3x9_E1x5(uint32 p);
  434. /// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
  435. /// to the 16-bit floating-point representation found in the OpenGL Specification.
  436. /// The first vector component specifies the 16 least-significant bits of the result;
  437. /// the forth component specifies the 16 most-significant bits.
  438. ///
  439. /// @see gtc_packing
  440. /// @see vec<3, T, Q> unpackRGBM(vec<4, T, Q> const& p)
  441. /// @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>
  442. template<length_t L, typename T, qualifier Q>
  443. GLM_FUNC_DECL vec<4, T, Q> packRGBM(vec<3, T, Q> const& rgb);
  444. /// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
  445. /// The first component of the vector is obtained from the 16 least-significant bits of v;
  446. /// the forth component is obtained from the 16 most-significant bits of v.
  447. ///
  448. /// @see gtc_packing
  449. /// @see vec<4, T, Q> packRGBM(vec<3, float, Q> const& v)
  450. /// @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>
  451. template<length_t L, typename T, qualifier Q>
  452. GLM_FUNC_DECL vec<3, T, Q> unpackRGBM(vec<4, T, Q> const& rgbm);
  453. /// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
  454. /// to the 16-bit floating-point representation found in the OpenGL Specification.
  455. /// The first vector component specifies the 16 least-significant bits of the result;
  456. /// the forth component specifies the 16 most-significant bits.
  457. ///
  458. /// @see gtc_packing
  459. /// @see vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p)
  460. /// @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>
  461. template<length_t L, qualifier Q>
  462. GLM_FUNC_DECL vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v);
  463. /// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
  464. /// The first component of the vector is obtained from the 16 least-significant bits of v;
  465. /// the forth component is obtained from the 16 most-significant bits of v.
  466. ///
  467. /// @see gtc_packing
  468. /// @see vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
  469. /// @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>
  470. template<length_t L, qualifier Q>
  471. GLM_FUNC_DECL vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p);
  472. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  473. ///
  474. /// @see gtc_packing
  475. /// @see vec<L, floatType, Q> unpackUnorm(vec<L, intType, Q> const& p);
  476. template<typename uintType, length_t L, typename floatType, qualifier Q>
  477. GLM_FUNC_DECL vec<L, uintType, Q> packUnorm(vec<L, floatType, Q> const& v);
  478. /// Convert a packed integer to a normalized floating-point vector.
  479. ///
  480. /// @see gtc_packing
  481. /// @see vec<L, intType, Q> packUnorm(vec<L, floatType, Q> const& v)
  482. template<typename floatType, length_t L, typename uintType, qualifier Q>
  483. GLM_FUNC_DECL vec<L, floatType, Q> unpackUnorm(vec<L, uintType, Q> const& v);
  484. /// Convert each component of the normalized floating-point vector into signed integer values.
  485. ///
  486. /// @see gtc_packing
  487. /// @see vec<L, floatType, Q> unpackSnorm(vec<L, intType, Q> const& p);
  488. template<typename intType, length_t L, typename floatType, qualifier Q>
  489. GLM_FUNC_DECL vec<L, intType, Q> packSnorm(vec<L, floatType, Q> const& v);
  490. /// Convert a packed integer to a normalized floating-point vector.
  491. ///
  492. /// @see gtc_packing
  493. /// @see vec<L, intType, Q> packSnorm(vec<L, floatType, Q> const& v)
  494. template<typename floatType, length_t L, typename intType, qualifier Q>
  495. GLM_FUNC_DECL vec<L, floatType, Q> unpackSnorm(vec<L, intType, Q> const& v);
  496. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  497. ///
  498. /// @see gtc_packing
  499. /// @see vec2 unpackUnorm2x4(uint8 p)
  500. GLM_FUNC_DECL uint8 packUnorm2x4(vec2 const& v);
  501. /// Convert a packed integer to a normalized floating-point vector.
  502. ///
  503. /// @see gtc_packing
  504. /// @see uint8 packUnorm2x4(vec2 const& v)
  505. GLM_FUNC_DECL vec2 unpackUnorm2x4(uint8 p);
  506. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  507. ///
  508. /// @see gtc_packing
  509. /// @see vec4 unpackUnorm4x4(uint16 p)
  510. GLM_FUNC_DECL uint16 packUnorm4x4(vec4 const& v);
  511. /// Convert a packed integer to a normalized floating-point vector.
  512. ///
  513. /// @see gtc_packing
  514. /// @see uint16 packUnorm4x4(vec4 const& v)
  515. GLM_FUNC_DECL vec4 unpackUnorm4x4(uint16 p);
  516. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  517. ///
  518. /// @see gtc_packing
  519. /// @see vec3 unpackUnorm1x5_1x6_1x5(uint16 p)
  520. GLM_FUNC_DECL uint16 packUnorm1x5_1x6_1x5(vec3 const& v);
  521. /// Convert a packed integer to a normalized floating-point vector.
  522. ///
  523. /// @see gtc_packing
  524. /// @see uint16 packUnorm1x5_1x6_1x5(vec3 const& v)
  525. GLM_FUNC_DECL vec3 unpackUnorm1x5_1x6_1x5(uint16 p);
  526. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  527. ///
  528. /// @see gtc_packing
  529. /// @see vec4 unpackUnorm3x5_1x1(uint16 p)
  530. GLM_FUNC_DECL uint16 packUnorm3x5_1x1(vec4 const& v);
  531. /// Convert a packed integer to a normalized floating-point vector.
  532. ///
  533. /// @see gtc_packing
  534. /// @see uint16 packUnorm3x5_1x1(vec4 const& v)
  535. GLM_FUNC_DECL vec4 unpackUnorm3x5_1x1(uint16 p);
  536. /// Convert each component of the normalized floating-point vector into unsigned integer values.
  537. ///
  538. /// @see gtc_packing
  539. /// @see vec3 unpackUnorm2x3_1x2(uint8 p)
  540. GLM_FUNC_DECL uint8 packUnorm2x3_1x2(vec3 const& v);
  541. /// Convert a packed integer to a normalized floating-point vector.
  542. ///
  543. /// @see gtc_packing
  544. /// @see uint8 packUnorm2x3_1x2(vec3 const& v)
  545. GLM_FUNC_DECL vec3 unpackUnorm2x3_1x2(uint8 p);
  546. /// Convert each component from an integer vector into a packed unsigned integer.
  547. ///
  548. /// @see gtc_packing
  549. /// @see i8vec2 unpackInt2x8(int16 p)
  550. GLM_FUNC_DECL int16 packInt2x8(i8vec2 const& v);
  551. /// Convert a packed integer into an integer vector.
  552. ///
  553. /// @see gtc_packing
  554. /// @see int16 packInt2x8(i8vec2 const& v)
  555. GLM_FUNC_DECL i8vec2 unpackInt2x8(int16 p);
  556. /// Convert each component from an integer vector into a packed unsigned integer.
  557. ///
  558. /// @see gtc_packing
  559. /// @see u8vec2 unpackInt2x8(uint16 p)
  560. GLM_FUNC_DECL uint16 packUint2x8(u8vec2 const& v);
  561. /// Convert a packed integer into an integer vector.
  562. ///
  563. /// @see gtc_packing
  564. /// @see uint16 packInt2x8(u8vec2 const& v)
  565. GLM_FUNC_DECL u8vec2 unpackUint2x8(uint16 p);
  566. /// Convert each component from an integer vector into a packed unsigned integer.
  567. ///
  568. /// @see gtc_packing
  569. /// @see i8vec4 unpackInt4x8(int32 p)
  570. GLM_FUNC_DECL int32 packInt4x8(i8vec4 const& v);
  571. /// Convert a packed integer into an integer vector.
  572. ///
  573. /// @see gtc_packing
  574. /// @see int32 packInt2x8(i8vec4 const& v)
  575. GLM_FUNC_DECL i8vec4 unpackInt4x8(int32 p);
  576. /// Convert each component from an integer vector into a packed unsigned integer.
  577. ///
  578. /// @see gtc_packing
  579. /// @see u8vec4 unpackUint4x8(uint32 p)
  580. GLM_FUNC_DECL uint32 packUint4x8(u8vec4 const& v);
  581. /// Convert a packed integer into an integer vector.
  582. ///
  583. /// @see gtc_packing
  584. /// @see uint32 packUint4x8(u8vec2 const& v)
  585. GLM_FUNC_DECL u8vec4 unpackUint4x8(uint32 p);
  586. /// Convert each component from an integer vector into a packed unsigned integer.
  587. ///
  588. /// @see gtc_packing
  589. /// @see i16vec2 unpackInt2x16(int p)
  590. GLM_FUNC_DECL int packInt2x16(i16vec2 const& v);
  591. /// Convert a packed integer into an integer vector.
  592. ///
  593. /// @see gtc_packing
  594. /// @see int packInt2x16(i16vec2 const& v)
  595. GLM_FUNC_DECL i16vec2 unpackInt2x16(int p);
  596. /// Convert each component from an integer vector into a packed unsigned integer.
  597. ///
  598. /// @see gtc_packing
  599. /// @see i16vec4 unpackInt4x16(int64 p)
  600. GLM_FUNC_DECL int64 packInt4x16(i16vec4 const& v);
  601. /// Convert a packed integer into an integer vector.
  602. ///
  603. /// @see gtc_packing
  604. /// @see int64 packInt4x16(i16vec4 const& v)
  605. GLM_FUNC_DECL i16vec4 unpackInt4x16(int64 p);
  606. /// Convert each component from an integer vector into a packed unsigned integer.
  607. ///
  608. /// @see gtc_packing
  609. /// @see u16vec2 unpackUint2x16(uint p)
  610. GLM_FUNC_DECL uint packUint2x16(u16vec2 const& v);
  611. /// Convert a packed integer into an integer vector.
  612. ///
  613. /// @see gtc_packing
  614. /// @see uint packUint2x16(u16vec2 const& v)
  615. GLM_FUNC_DECL u16vec2 unpackUint2x16(uint p);
  616. /// Convert each component from an integer vector into a packed unsigned integer.
  617. ///
  618. /// @see gtc_packing
  619. /// @see u16vec4 unpackUint4x16(uint64 p)
  620. GLM_FUNC_DECL uint64 packUint4x16(u16vec4 const& v);
  621. /// Convert a packed integer into an integer vector.
  622. ///
  623. /// @see gtc_packing
  624. /// @see uint64 packUint4x16(u16vec4 const& v)
  625. GLM_FUNC_DECL u16vec4 unpackUint4x16(uint64 p);
  626. /// Convert each component from an integer vector into a packed unsigned integer.
  627. ///
  628. /// @see gtc_packing
  629. /// @see i32vec2 unpackInt2x32(int p)
  630. GLM_FUNC_DECL int64 packInt2x32(i32vec2 const& v);
  631. /// Convert a packed integer into an integer vector.
  632. ///
  633. /// @see gtc_packing
  634. /// @see int packInt2x16(i32vec2 const& v)
  635. GLM_FUNC_DECL i32vec2 unpackInt2x32(int64 p);
  636. /// Convert each component from an integer vector into a packed unsigned integer.
  637. ///
  638. /// @see gtc_packing
  639. /// @see u32vec2 unpackUint2x32(int p)
  640. GLM_FUNC_DECL uint64 packUint2x32(u32vec2 const& v);
  641. /// Convert a packed integer into an integer vector.
  642. ///
  643. /// @see gtc_packing
  644. /// @see int packUint2x16(u32vec2 const& v)
  645. GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p);
  646. /// @}
  647. }// namespace glm
  648. #include "packing.inl"