9
3

packing.hpp 35 KB

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