GLTEXIMAGE3D(3G)

πŸ’– NAME πŸ’–

glTexImage3D β€” specify a three-dimensional texture image ✨

okay so bestie, this is the GLTEXIMAGE3D(3G) page from the [FIXME: manual] manual, and it's literally all about glTexImage3D β€” the function that says β€œhere's a whole 3D texture image, pls take it.” 🫢

✨ C SPECIFICATION ✨

void glTexImage3D(GLenum target, GLint level, GLint internalformat,
                  GLsizei width, GLsizei height, GLsizei depth,
                  GLint border, GLenum format, GLenum type,
                  const GLvoid * data);

πŸŽ€ PARAMETERS πŸŽ€

  • target β€” which texture target you're aiming at, bestie. Must be one of GL_TEXTURE_3D, GL_PROXY_TEXTURE_3D, GL_TEXTURE_2D_ARRAY, or GL_PROXY_TEXTURE_2D_ARRAY. 🎯
  • level β€” the level-of-detail number. Level 0 is the base image level, and level n is the nth mipmap reduction image. no cap. πŸͺœ
  • internalformat β€” specifies the number of color components in the texture. Must be one of the base internal formats given in Table 1, one of the sized internal formats given in Table 2, or one of the compressed internal formats given in Table 3, below. πŸ‘‘
  • width β€” the width of the texture image. All implementations support 3D texture images that are at least 16 texels wide. πŸ“
  • height β€” the height of the texture image. All implementations support 3D texture images that are at least 256 texels high. πŸ“
  • depth β€” the depth of the texture image, or the number of layers in a texture array. All implementations support 3D texture images that are at least 256 texels deep, and texture arrays that are at least 256 layers deep. 🧊
  • border β€” this value must be 0. periodt. 🚫
  • format β€” the format of the pixel data. The following symbolic values are accepted: GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_RED_INTEGER, GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER, GL_RGBA_INTEGER, GL_BGRA_INTEGER, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL. 🎨
  • type β€” the data type of the pixel data. The following symbolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and GL_UNSIGNED_INT_2_10_10_10_REV. 🧬
  • data β€” a pointer to the image data in memory. 🫢

🌸 DESCRIPTION 🌸

Texturing maps a portion of a specified texture image onto each graphical primitive for which texturing is enabled. To enable and disable three-dimensional texturing, call glEnable() and glDisable with argument GL_TEXTURE_3D. πŸŒ€

To define texture images, call glTexImage3D. The arguments describe the parameters of the texture image, such as height, width, depth, width of the border, level-of-detail number (see glTexParameter()), and number of color components provided. The last three arguments describe how the image is represented in memory. 🧠

If target is GL_PROXY_TEXTURE_3D, no data is read from data, but all of the texture image state is recalculated, checked for consistency, and checked against the implementation's capabilities. If the implementation cannot handle a texture of the requested texture size, it sets all of the image state to 0, but does not generate an error (see glGetError()). To query for an entire mipmap array, use an image array level greater than or equal to 1. πŸ‘€

If target is GL_TEXTURE_3D, data is read from data as a sequence of signed or unsigned bytes, shorts, or longs, or single-precision floating-point values, depending on type. These values are grouped into sets of one, two, three, or four values, depending on format, to form elements. Each data byte is treated as eight 1-bit elements, with bit ordering determined by GL_UNPACK_LSB_FIRST (see glPixelStore()). πŸ”₯

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

The first element corresponds to the lower left corner of the texture image. Subsequent elements progress left-to-right through the remaining texels in the lowest row of the texture image, and then in successively higher rows of the texture image. The final element corresponds to the upper right corner of the texture image. 🧚

format determines the composition of each element in data. It can assume one of these symbolic values:

  • GL_RED β€” each element is a single red component. The GL converts it to floating point and assembles it into an RGBA element by attaching 0 for green and blue, and 1 for alpha. Each component is clamped to the range [0,1]. ❀️
  • GL_RG β€” each element is a red and green pair. The GL converts each to floating point and assembles it into an RGBA element by attaching 0 for blue, and 1 for alpha. Each component is clamped to the range [0,1]. πŸ’š
  • GL_RGB, GL_BGR β€” each element is an RGB triple. The GL converts it to floating point and assembles it into an RGBA element by attaching 1 for alpha. Each component is clamped to the range [0,1]. 🌈
  • GL_RGBA, GL_BGRA β€” each element contains all four components. Each component is clamped to the range [0,1]. πŸ’…

If an application wants to store the texture at a certain resolution or in a certain format, it can request the resolution and format with internalformat. The GL will choose an internal representation that closely approximates that requested by internalformat, but it may not match exactly. (The representations specified by GL_RED, GL_RG, GL_RGB, and GL_RGBA must match exactly.) πŸ‘‘

internalformat may be one of the base internal formats shown in Table 1, below 🌟

🌈 Table 1. Base Internal Formats 🌈

  • Base Internal Format: GL_DEPTH_COMPONENT β€” RGBA, Depth and Stencil Values: Depth β€” Internal Components: D
  • Base Internal Format: GL_DEPTH_STENCIL β€” RGBA, Depth and Stencil Values: Depth, Stencil β€” Internal Components: D, S
  • Base Internal Format: GL_RED β€” RGBA, Depth and Stencil Values: Red β€” Internal Components: R
  • Base Internal Format: GL_RG β€” RGBA, Depth and Stencil Values: Red, Green β€” Internal Components: R, G
  • Base Internal Format: GL_RGB β€” RGBA, Depth and Stencil Values: Red, Green, Blue β€” Internal Components: R, G, B
  • Base Internal Format: GL_RGBA β€” RGBA, Depth and Stencil Values: Red, Green, Blue, Alpha β€” Internal Components: R, G, B, A

internalformat may also be one of the sized internal formats shown in Table 2, below 🌸

So this is the big one β€” Table 2. Sized Internal Formats πŸŽ€ and bestie, it's a whole buffet. The columns are: Sized Internal Format, Base Internal Format, Red Bits, Green Bits, Blue Bits, Alpha Bits, and Shared Bits. Heads up: the Shared Bits column is sitting there cute and empty for literally every row in this stretch β€” nobody's using it yet πŸ’…. Also, the s prefix = signed, ui = unsigned integer, f = float. Iykyk.

  • GL_R8 β€” base GL_RED, red bits 8
  • GL_R8_SNORM β€” base GL_RED, red bits s8
  • GL_R16 β€” base GL_RED, red bits 16
  • GL_R16_SNORM β€” base GL_RED, red bits s16
  • GL_RG8 β€” base GL_RG, red bits 8, green bits 8
  • GL_RG8_SNORM β€” base GL_RG, red bits s8, green bits s8
  • GL_RG16 β€” base GL_RG, red bits 16, green bits 16
  • GL_RG16_SNORM β€” base GL_RG, red bits s16, green bits s16
  • GL_R3_G3_B2 β€” base GL_RGB, red bits 3, green bits 3, blue bits 2
  • GL_RGB4 β€” base GL_RGB, red bits 4, green bits 4, blue bits 4
  • GL_RGB5 β€” base GL_RGB, red bits 5, green bits 5, blue bits 5
  • GL_RGB8 β€” base GL_RGB, red bits 8, green bits 8, blue bits 8
  • GL_RGB8_SNORM β€” base GL_RGB, red bits s8, green bits s8, blue bits s8
  • GL_RGB10 β€” base GL_RGB, red bits 10, green bits 10, blue bits 10
  • GL_RGB12 β€” base GL_RGB, red bits 12, green bits 12, blue bits 12
  • GL_RGB16_SNORM β€” base GL_RGB, red bits 16, green bits 16, blue bits 16
  • GL_RGBA2 β€” base GL_RGB, red bits 2, green bits 2, blue bits 2, alpha bits 2
  • GL_RGBA4 β€” base GL_RGB, red bits 4, green bits 4, blue bits 4, alpha bits 4
  • GL_RGB5_A1 β€” base GL_RGBA, red bits 5, green bits 5, blue bits 5, alpha bits 1
  • GL_RGBA8 β€” base GL_RGBA, red bits 8, green bits 8, blue bits 8, alpha bits 8
  • GL_RGBA8_SNORM β€” base GL_RGBA, red bits s8, green bits s8, blue bits s8, alpha bits s8
  • GL_RGB10_A2 β€” base GL_RGBA, red bits 10, green bits 10, blue bits 10, alpha bits 2
  • GL_RGB10_A2UI β€” base GL_RGBA, red bits ui10, green bits ui10, blue bits ui10, alpha bits ui2
  • GL_RGBA12 β€” base GL_RGBA, red bits 12, green bits 12, blue bits 12, alpha bits 12
  • GL_RGBA16 β€” base GL_RGBA, red bits 16, green bits 16, blue bits 16, alpha bits 16
  • GL_SRGB8 β€” base GL_RGB, red bits 8, green bits 8, blue bits 8
  • GL_SRGB8_ALPHA8 β€” base GL_RGBA, red bits 8, green bits 8, blue bits 8, alpha bits 8
  • GL_R16F β€” base GL_RED, red bits f16

…and the sized-format rollout continues, bestie πŸ’… same deal as above: internal format on the left, and then the channel layout it's giving.

  • GL_RG16F β€” base GL_RG Β· red f16 Β· green f16
  • GL_RGB16F β€” base GL_RGB Β· red f16 Β· green f16 Β· blue f16
  • GL_RGBA16F β€” base GL_RGBA Β· red f16 Β· green f16 Β· blue f16 Β· alpha f16
  • GL_R32F β€” base GL_RED Β· red f32 β€” one channel, zero drama 🌸
  • GL_RG32F β€” base GL_RG Β· red f32 Β· green f32
  • GL_RGB32F β€” base GL_RGB Β· red f32 Β· green f32 Β· blue f32
  • GL_RGBA32F β€” base GL_RGBA Β· red f32 Β· green f32 Β· blue f32 Β· alpha f32 β€” the full float squad, iconic πŸ‘‘
  • GL_R11F_G11F_B10F β€” base GL_RGB Β· red f11 Β· green f11 Β· blue f10 β€” yes, the blue one is a whole bit smaller, it's fine, it's fine 😭
  • GL_RGB9_E5 β€” base GL_RGB Β· red 9 Β· green 9 Β· blue 9 Β· shared 5
  • GL_R8I β€” base GL_RED Β· red i8
  • GL_R8UI β€” base GL_RED Β· red ui8
  • GL_R16I β€” base GL_RED Β· red i16
  • GL_R16UI β€” base GL_RED Β· red ui16
  • GL_R32I β€” base GL_RED Β· red i32
  • GL_R32UI β€” base GL_RED Β· red ui32
  • GL_RG8I β€” base GL_RG Β· red i8 Β· green i8
  • GL_RG8UI β€” base GL_RG Β· red ui8 Β· green ui8
  • GL_RG16I β€” base GL_RG Β· red i16 Β· green i16
  • GL_RG16UI β€” base GL_RG Β· red ui16 Β· green ui16
  • GL_RG32I β€” base GL_RG Β· red i32 Β· green i32
  • GL_RG32UI β€” base GL_RG Β· red ui32 Β· green ui32
  • GL_RGB8I β€” base GL_RGB Β· red i8 Β· green i8 Β· blue i8
  • GL_RGB8UI β€” base GL_RGB Β· red ui8 Β· green ui8 Β· blue ui8
  • GL_RGB16I β€” base GL_RGB Β· red i16 Β· green i16 Β· blue i16
  • GL_RGB16UI β€” base GL_RGB Β· red ui16 Β· green ui16 Β· blue ui16
  • GL_RGB32I β€” base GL_RGB Β· red i32 Β· green i32 Β· blue i32
  • GL_RGB32UI β€” base GL_RGB Β· red ui32 Β· green ui32 Β· blue ui32
  • GL_RGBA8I β€” base GL_RGBA Β· red i8 Β· green i8 Β· blue i8 Β· alpha i8
  • GL_RGBA8UI β€” base GL_RGBA Β· red ui8 Β· green ui8 Β· blue ui8 Β· alpha ui8
  • GL_RGBA16I β€” base GL_RGBA Β· red i16 Β· green i16 Β· blue i16 Β· alpha i16
  • GL_RGBA16UI β€” base GL_RGBA Β· red ui16 Β· green ui16 Β· blue ui16 Β· alpha ui16

okay and it literally keeps going, keep scrolling bestie πŸ’œπŸ¦‹

  • GL_RGBA32I β€” base internal format GL_RGBA, and the four components are i32, i32, i32, i32 ✨
  • GL_RGBA32UI β€” base internal format GL_RGBA, components ui32, ui32, ui32, ui32 🫢

And finally, bestie, internalformat can also be one of the generic or compressed texture formats β€” those are all hanging out in Table 3 down below πŸ‘‡

🌈 Table 3. Compressed Internal Formats

  • GL_COMPRESSED_RED β€” base internal format GL_RED, type Generic
  • GL_COMPRESSED_RG β€” base internal format GL_RG, type Generic
  • GL_COMPRESSED_RGB β€” base internal format GL_RGB, type Generic
  • GL_COMPRESSED_RGBA β€” base internal format GL_RGBA, type Generic
  • GL_COMPRESSED_SRGB β€” base internal format GL_RGB, type Generic
  • GL_COMPRESSED_SRGB_ALPHA β€” base internal format GL_RGBA, type Generic
  • GL_COMPRESSED_RED_RGTC1 β€” base internal format GL_RED, type Specific
  • GL_COMPRESSED_SIGNED_RED_RGTC1 β€” base internal format GL_RED, type Specific
  • GL_COMPRESSED_RG_RGTC2 β€” base internal format GL_RG, type Specific
  • GL_COMPRESSED_SIGNED_RG_RGTC2 β€” base internal format GL_RG, type Specific
  • GL_COMPRESSED_RGBA_BPTC_UNORM β€” base internal format GL_RGBA, type Specific
  • GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM β€” base internal format GL_RGBA, type Specific
  • GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT β€” base internal format GL_RGB, type Specific
  • GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT β€” base internal format GL_RGB, type Specific

So here's the tea on the generic ones β˜• β€” if internalformat is one of the generic compressed formats, like GL_COMPRESSED_RED, GL_COMPRESSED_RG, GL_COMPRESSED_RGB, or GL_COMPRESSED_RGBA, then the GL will swap the internal format out for the symbolic constant of a specific internal format and compress the texture before it stores it. Iconic, honestly πŸ’…

But β€” and this is the plot twist β€” if there's no corresponding internal format available, or the GL just can't compress that image for literally any reason, then the internal format gets replaced with a corresponding base internal format instead. No compression for you πŸ₯²


πŸ¦‹ the sRGB situation

If internalformat is GL_SRGB, GL_SRGB8, GL_SRGB_ALPHA, or GL_SRGB8_ALPHA8, the texture gets treated as if the red, green, blue, or luminance components are encoded in the sRGB color space. Any alpha component is left completely unchanged, untouched, unbothered πŸ‘‘

The conversion from an sRGB encoded component c s to a linear component c l is:

c_l = { c_s / 12.92                            if c_s ≀ 0.04045
      { ((c_s + 0.055) / 1.055) ^ 2.4          if c_s > 0.04045

And just so we're clear, assume c s is the sRGB component in the range [0,1] πŸ“


🧚 vibe check: the proxy target

Use the GL_PROXY_TEXTURE_3D target to try out a resolution and format before committing β€” like a fitting room but for textures, lowkey genius πŸ™ˆ The implementation will update and recompute its best match for the requested storage resolution and format. To then query this state, call glGetTexLevelParameter(). And if the texture cannot be accommodated? Texture state is set to 0. Brutal but fair πŸ’€


🌸 how many components, exactly?

Okay so a one-component texture image uses only the red component of the RGBA color extracted from data. A two-component image uses the R and A values. A three-component image uses the R, G, and B values. And a four-component image uses all of the RGBA components. All four. The whole squad 🫢


✨ NOTES ✨

  • The glPixelStore() mode affects texture images. Yes, it really does. Keep an eye on it πŸ‘€
  • data may be a null pointer. In this case, texture memory is allocated to accommodate a texture of width width, height height, and depth depth. You can then download subtextures to initialize this texture memory. The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive β€” so like, don't do that πŸ™ˆ
  • glTexImage3D specifies the three-dimensional texture for the current texture unit, specified with glActiveTexture(). Main character energy ✨
  • GL_STENCIL_INDEX may be used for format only if the GL version is 4.4 or higher. Version gate, bestie 🚧

πŸ’€ ERRORS πŸ’€

Strap in, this is the long one. Here's every way this call can yell at you:

  • GL_INVALID_ENUM is generated if target is not GL_TEXTURE_3D or GL_PROXY_TEXTURE_3D.
  • GL_INVALID_ENUM is generated if format is not an accepted format constant. Format constants other than GL_STENCIL_INDEX and GL_DEPTH_COMPONENT are accepted.
  • GL_INVALID_ENUM is generated if type is not a type constant.
  • GL_INVALID_VALUE is generated if level is less than 0.
  • GL_INVALID_VALUE may be generated if level is greater than log2 of max, where max is the returned value of GL_MAX_TEXTURE_SIZE.
  • GL_INVALID_VALUE is generated if internalformat is not one of the accepted resolution and format symbolic constants.
  • GL_INVALID_VALUE is generated if width, height, or depth is less than 0 or greater than GL_MAX_TEXTURE_SIZE.
  • GL_INVALID_VALUE is generated if border is not 0.
  • GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, GL_UNSIGNED_SHORT_5_6_5, or GL_UNSIGNED_SHORT_5_6_5_REV and format is not GL_RGB.
  • GL_INVALID_OPERATION is generated if type is one of GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, or GL_UNSIGNED_INT_2_10_10_10_REV and format is neither GL_RGBA nor GL_BGRA.
  • GL_INVALID_OPERATION is generated if format or internalformat is GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, or GL_DEPTH_COMPONENT32.
  • 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.
  • GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and data is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.
fr fr, those last three are always about the unpack buffer. It's giving "it's always the buffer" 😭

πŸ”₯ ASSOCIATED GETS πŸ”₯

  • glGetTexImage()
  • glGet() with argument GL_PIXEL_UNPACK_BUFFER_BINDING

These are your receipts, bestie 🌈

✨ VERSION SUPPORT ✨

okay bestie, this is the glow-up chart β€” which OpenGL versions actually show up for you πŸ’… The columns are OpenGL Version, the rows are Function / Feature Name, and here's the tea:

  • glTexImage3D β€” slayed in literally every single one, no skips, no gaps:
    • OpenGL 2.0 β€” βœ”
    • OpenGL 2.1 β€” βœ”
    • OpenGL 3.0 β€” βœ”
    • OpenGL 3.1 β€” βœ”
    • OpenGL 3.2 β€” βœ”
    • OpenGL 3.3 β€” βœ”
    • OpenGL 4.0 β€” βœ”
    • OpenGL 4.1 β€” βœ”
    • OpenGL 4.2 β€” βœ”
    • OpenGL 4.3 β€” βœ”
    • OpenGL 4.4 β€” βœ”
    • OpenGL 4.5 β€” βœ”
  • GL_HALF_FLOAT β€” she was not invited to the early parties, poor thing 😭:
    • OpenGL 2.0 β€” -
    • OpenGL 2.1 β€” -
    • OpenGL 3.0 β€” βœ”
    • OpenGL 3.1 β€” βœ”
    • OpenGL 3.2 β€” βœ”
    • OpenGL 3.3 β€” βœ”
    • OpenGL 4.0 β€” βœ”
    • OpenGL 4.1 β€” βœ”
    • OpenGL 4.2 β€” βœ”
    • OpenGL 4.3 β€” βœ”
    • OpenGL 4.4 β€” βœ”
    • OpenGL 4.5 β€” βœ”

so like, glTexImage3D ate from 2.0 onward and never looked back, but GL_HALF_FLOAT was a late bloomer who showed up in 3.0 and stayed iconic 🌸


πŸ‘€ SEE ALSO

your reading list, bestie β€” go click around, it's giving "study group" energy πŸ“šβœ¨

  • glActiveTexture()
  • glCompressedTexImage1D()
  • glCompressedTexImage2D()
  • glCompressedTexImage3D()
  • glCompressedTexSubImage1D()
  • glCompressedTexSubImage2D()
  • glCompressedTexSubImage3D()
  • glCopyTexImage1D()
  • glCopyTexImage2D()
  • glCopyTexSubImage1D()
  • glCopyTexSubImage2D()
  • glCopyTexSubImage3D()
  • glGetCompressedTexImage()
  • glPixelStore()
  • glTexImage1D()
  • glTexImage2D()
  • 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 Β© 2011-2014 Khronos Group


and that's a wrap on this whole page, bestie πŸŽ€ you made it to the end β€” so proud of you fr fr 🫢 This lil masterpiece was served up from [FIXME: source], dated 08/09/2021, and it lives at GLTEXIMAGE3D(3G) β€” go forth and texture in 3D, you gorgeous main character πŸ‘‘βœ¨

πŸ“¦ where this page comes from