PACKUNORM(3G)
π PACKUNORM π (section 3G, bestie)
okay so like. imagine you have a cute little float vector and you need it to become one single unsigned int. that's literally it. that's the whole vibe. this page is from the 3G manual, and it's about the pack family of GLSL functions β packUnorm2x16, packSnorm2x16, packUnorm4x8 and packSnorm4x8. they smoosh floats down into bits. it's giving data compression era. π
β¨ NAME β¨
packUnorm β pack floating-point values into an unsigned integer π«Ά
πΈ DECLARATION πΈ
here's the exact signatures, no cap, copy them character for character:
uint packUnorm2x16(vec2 v);
uint packSnorm2x16(vec2 v);
uint packUnorm4x8(vec4 v);
uint packSnorm4x8(vec4 v);
π¦ PARAMETERS π¦
vβ a vector of values that's getting packed into an unsigned integer. that's the whole parameter list, she's simple like that π
π DESCRIPTION π
so packUnorm2x16, packSnorm2x16, packUnorm4x8 and packSnorm4x8 take each component of the normalized floating-point value v, convert it into an 8-bit or 16-bit integer value, and then pack all those results into a 32-bit unsigned integer. one int, four (or two) floats, iconic behaviour honestly.
the conversion for component c of v into fixed-point goes like this:
packUnorm2x16:round(clamp(c, 0.0, 1.0) * 65535.0)packSnorm2x16:round(clamp(c, -1.0, 1.0) * 32767.0)packUnorm4x8:round(clamp(c, 0.0, 1.0) * 255.0)packSnorm4x8:round(clamp(c, -1.0, 1.0) * 127.0)
and the bit layout bestie? listen. the first component of the vector gets written to the least significant bits of the output, and the last component gets written to the most significant bits. so the order is not reversed, it's justβ¦ bits-first energy. π
π VERSION SUPPORT π
which GLSL versions actually ship each one β the β means it's there, the - means it's not yet, so don't come crying to me when 1.10 doesn't have it:
packUnorm2x16β-for 1.10, 1.20, 1.30, 1.40, 1.50, 3.30, 4.00;βfor 4.10, 4.20, 4.30, 4.40, 4.50packSnorm2x16β-for 1.10, 1.20, 1.30, 1.40, 1.50, 3.30, 4.00, 4.10;βfor 4.20, 4.30, 4.40, 4.50packUnorm4x8β-for 1.10, 1.20, 1.30, 1.40, 1.50, 3.30, 4.00;βfor 4.10, 4.20, 4.30, 4.40, 4.50packSnorm4x8β-for 1.10, 1.20, 1.30, 1.40, 1.50, 3.30, 4.00;βfor 4.10, 4.20, 4.30, 4.40, 4.50
π SEE ALSO π
the reverse girlies, the unpack squad, the ones who undo all of this:
unpackUnorm2x16unpackSnorm2x16unpackUnorm4x8unpackSnorm4x8
π COPYRIGHT π
Copyright Β© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.
Copyright Β© 2011-2014 Khronos Group
okay that's the whole page bestie, go pack some floats, you ate π β¨
this little love letter to packUnorm(3G) came from [FIXME: source] and it's dated 01/03/2018 β mwah, kisses, bye π«ΆπΈ
π¦ where this page comes from
- ubuntu jammy: opengl-4-man-doc 1.0~svn33624-1 Β· SGI-Free-Software-B-License-2
- ubuntu noble: opengl-4-man-doc 1.0~svn33624-1 Β· SGI-Free-Software-B-License-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms