GLCOMPRESSEDTEXIMAGE(3G)

πŸ’– glCompressedTexImage2D πŸ’–

okay bestie, so this is the manual page for glCompressedTexImage2D β€” that's the GLCOMPRESSEDTEXIMAGE(3G) page, and yes she's a whole icon in the OpenGL docs. sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ NAME ✨

glCompressedTexImage2D β€” specify a two-dimensional texture image in a compressed format. that's it, that's the whole vibe. πŸŽ€


🌸 C SPECIFICATION 🌸

void glCompressedTexImage2D(GLenum target, GLint level,
                            GLenum internalformat, GLsizei width,
                            GLsizei height, GLint border,
                            GLsizei imageSize, const GLvoid * data);

look at her. eight parameters. main character energy fr fr πŸ‘‘


πŸ¦‹ PARAMETERS πŸ¦‹

  • target β€” which texture slot you're loading into. has to be one of: GL_TEXTURE_2D, GL_PROXY_TEXTURE_2D, GL_TEXTURE_1D_ARRAY, GL_PROXY_TEXTURE_1D_ARRAY, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or GL_PROXY_TEXTURE_CUBE_MAP. no vibes outside that list, periodt.
  • level β€” the level-of-detail number, aka which mipmap step you're on. level 0 is the base image level, and level n is the *n*th mipmap reduction image. little ladder of downscales πŸͺœ
  • internalformat β€” the format of the compressed image data sitting at address data. this is the glow-up spec.
  • width β€” width of the texture image. lowkey reassuring fact: all implementations support 2D texture and cube map texture images that are at least 16384 texels wide. that's a lot of texels bestie.
  • height β€” height of the texture image. same deal: all implementations support 2D texture and cube map texture images that are at least 16384 texels high.
  • border β€” this value must be 0. not "should be", not "maybe" β€” must. 🚨
  • imageSize β€” how many unsigned bytes of image data there are, starting at the address data points to.
  • data β€” a pointer to the compressed image data in memory. the actual payload πŸ’…

πŸ’œ DESCRIPTION πŸ’œ

so texturing lets elements of an image array be read by shaders. iconic behaviour, we love it.

glCompressedTexImage2D loads a previously defined, and retrieved, compressed two-dimensional texture image β€” but only if target is GL_TEXTURE_2D, or one of the cube map faces such as GL_TEXTURE_CUBE_MAP_POSITIVE_X (see glTexImage2D()).

if target is GL_TEXTURE_1D_ARRAY, then data is treated as an array of compressed 1D textures. different flavour, same energy.

if target is GL_PROXY_TEXTURE_2D, GL_PROXY_TEXTURE_1D_ARRAY or GL_PROXY_TEXTURE_CUBE_MAP, then no data is read from data β€” instead all of the texture image state gets recalculated, checked for consistency, and checked against the implementation's capabilities. and if the implementation can't handle a texture of the requested size? it sets all of the image state to 0 but does not generate an error (see glGetError()). so like... it glitches quietly. rude but okay πŸ™ˆ

to query for an entire mipmap array, use an image array level greater than or equal to 1.

internalformat must be a known compressed image format (such as GL_RGTC) or an extension-specified compressed-texture format. here's the lore: when a texture is loaded with glTexImage2D() using a generic compressed texture format (e.g., GL_COMPRESSED_RGB), the GL selects from one of its extensions supporting compressed textures. so if you wanna load that compressed texture image with glCompressedTexImage2D, you query the compressed texture image's size and format using glGetTexLevelParameter(). iykyk πŸ”

if a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target (see glBindBuffer()) while a texture image is specified, then data is treated as a byte offset into the buffer object's data store. sneaky but correct.

🧚 the whole block-size pixel storage situation 🧚

if the compressed data are arranged into fixed-size blocks of texels, the pixel storage modes can be used to select a sub-rectangle from a larger containing rectangle. these pixel storage modes operate in the same way as they do for glTexImage2D(). in the following description, denote by bs, bw, bh, and bd, the values of pixel storage modes GL_UNPACK_COMPRESSED_BLOCK_SIZE, GL_UNPACK_COMPRESSED_BLOCK_WIDTH, GL_UNPACK_COMPRESSED_BLOCK_HEIGHT, and GL_UNPACK_COMPRESSED_BLOCK_DEPTH, respectively. bs is the compressed block size in bytes; bw, bh, and bd are the compressed block width, height, and depth in pixels.

by default the pixel storage modes GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES are ignored for compressed images. to enable GL_UNPACK_SKIP_PIXELS and GL_UNPACK_ROW_LENGTH, bs and bw must both be non-zero. to also enable GL_UNPACK_SKIP_ROWS and GL_UNPACK_IMAGE_HEIGHT, bh must be non-zero. to also enable GL_UNPACK_SKIP_IMAGES, bd must be non-zero. and all parameters must be consistent with the compressed format to produce the desired results β€” no chaotic mismatching, bestie.

when selecting a sub-rectangle from a compressed image:

  • the value of GL_UNPACK_SKIP_PIXELS must be a multiple of bw;
  • the value of GL_UNPACK_SKIP_ROWS must be a multiple of bw.
ok random but real: yes, the manual really does say bw for both of those bullets. not bh. we don't make the rules, we just report them exactly. πŸ’€

imageSize must be equal to:

b s Γ— width b w Γ— height b h

πŸ”₯ NOTES πŸ”₯

the specific compressed internal formats GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_RG11_EAC, and GL_COMPRESSED_SIGNED_RG11_EAC are available only if the GL version is 4.3 or higher. gatekept, honestly. 😀


πŸ’… ERRORS πŸ’…

the ways she can drag you:

  • GL_INVALID_ENUM is generated if internalformat is not one of the specific compressed internal formats: GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_RGBA_BPTC_UNORM, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_RG11_EAC, or GL_COMPRESSED_SIGNED_RG11_EAC.
  • GL_INVALID_VALUE is generated if imageSize is not consistent with the format, dimensions, and contents of the specified compressed image data. math must math ✨
  • GL_INVALID_VALUE is generated if border is not 0. we told you. zero. 🫢
  • GL_INVALID_OPERATION is generated if parameter combinations are not supported by the specific compressed internal format as specified in the specific texture compression extension.
  • GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the buffer object's data store is currently mapped.
  • GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the data would be unpacked from the buffer object such that the memory reads required would exceed the data store size.
🚨 UNDEFINED RESULTS ALERT 🚨 β€” undefined results, including abnormal program termination, are generated if data is not encoded in a manner consistent with the extension specification defining the internal compression format. that's not a typo bestie, that says abnormal program termination. your whole app. gone. encode it right or it's over 😭

πŸŽ€ ASSOCIATED GETS πŸŽ€

the whole friend group you can query alongside her:

  • glGetCompressedTexImage()
  • glGet() with argument GL_TEXTURE_COMPRESSED
  • glGet() with argument GL_PIXEL_UNPACK_BUFFER_BINDING
  • glGetTexLevelParameter() with arguments GL_TEXTURE_INTERNAL_FORMAT and GL_TEXTURE_COMPRESSED_IMAGE_SIZE

🌈 VERSION SUPPORT 🌈

so the original prints this as a big grid, and grids are not the vibe in a terminal chat, so here's the same tea in list form β€” the column headers were the OpenGL versions 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, and the row was the function / feature name glCompressedTexImage2D:

  • 2.0 β€” βœ”
  • 2.1 β€” βœ”
  • 3.0 β€” βœ”
  • 3.1 β€” βœ”
  • 3.2 β€” βœ”
  • 3.3 β€” βœ”
  • 4.0 β€” βœ”
  • 4.1 β€” βœ”
  • 4.2 β€” βœ”
  • 4.3 β€” βœ”
  • 4.4 β€” βœ”
  • 4.5 β€” βœ”

twelve for twelve. she ate and left absolutely no crumbs πŸ‘‘πŸ”₯


⭐ SEE ALSO ⭐

go read these next, bestie:

glActiveTexture(), glCompressedTexImage1D(), glCompressedTexImage3D(), glCompressedTexSubImage1D(), glCompressedTexSubImage2D(), glCompressedTexSubImage3D(), glCopyTexImage1D(), glCopyTexSubImage1D(), glCopyTexSubImage2D(), glCopyTexSubImage3D(), glPixelStore(), glTexImage2D(), glTexImage3D(), glTexSubImage1D(), glTexSubImage2D(), glTexSubImage3D(), glTexParameter()


Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2011-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.


Copyright Β© 1991-2006 Silicon Graphics, Inc.

Copyright Β© 2011-2014 Khronos Group


okay that's the whole page, you're officially smarter than like 90% of people who've ever typed glCompressedTexImage2D and hoped for the best πŸ§šπŸ’œ this was the [FIXME: source] build, dated 08/09/2021, and the manual name is GLCOMPRESSEDTEXIMAGE(3G) β€” mwah, go compress something gorgeous πŸ’–βœ¨

πŸ“¦ where this page comes from