GLTEXSUBIMAGE2D(3G)

πŸŽ€ GLTEXSUBIMAGE2D(3G) β€” bestie's guide to 2D texture subimages πŸŽ€

okay so you're on the GLTEXSUBIMAGE2D(3G) page, welcome, hi, sit down, we're doing texel surgery today πŸ’…


✨ NAME ✨

glTexSubImage2D, glTextureSubImage2D β€” specify a two-dimensional texture subimage. that's it. that's the whole vibe. πŸ¦‹


🌸 C SPECIFICATION 🌸

void glTexSubImage2D(GLenum target, GLint level, GLint xoffset,
                     GLint yoffset, GLsizei width, GLsizei height,
                     GLenum format, GLenum type, const GLvoid * pixels);

void glTextureSubImage2D(GLuint texture, GLint level, GLint xoffset,
                         GLint yoffset, GLsizei width, GLsizei height,
                         GLenum format, GLenum type,
                         const void *pixels);

look at them. two icons. 🀝


πŸ’– PARAMETERS πŸ’–

  • target β€” which target the texture is bound to, for glTexSubImage2D. has to be one of GL_TEXTURE_2D, 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_TEXTURE_1D_ARRAY. no substitutes, no vibes-based guessing. πŸ’€
  • texture β€” the texture object name, for glTextureSubImage2D. and its effective target has to be one of the valid target values from up there πŸ‘†
  • level β€” the level-of-detail number. 0 is the base image level, and level n is the *n*th mipmap reduction image. mipmap math, love her. ✨
  • xoffset β€” a texel offset in the x direction, inside the texture array.
  • yoffset β€” a texel offset in the y direction, inside the texture array. yes there's a y, it's 2D, we been knew. πŸ™ˆ
  • width β€” the width of the texture subimage.
  • height β€” the height of the texture subimage.
  • format β€” the format of the pixel data. accepted values: GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_DEPTH_COMPONENT, and GL_STENCIL_INDEX.
  • type β€” the data type of the pixel data. accepted values: GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, 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. that's a lot of names but every single one is valid, no skips. πŸ”₯
  • pixels β€” 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. that's the whole concept, she's serving.

glTexSubImage2D and glTextureSubImage2D redefine a contiguous subregion of an existing two-dimensional or one-dimensional array texture image. the texels that pixels points at replace the portion of the existing texture array with x indices xoffset and xoffset + width - 1, inclusive, and y indices yoffset and yoffset + height - 1, inclusive. inclusive!! both ends!! 🫢

⚠️ this region may not include any texels outside the range of the texture array as it was originally specified. it's giving "don't color outside the lines" and the lines are load-bearing, fr fr.

it is not an error to specify a subtexture with zero width or height, but such a specification has no effect. so like, legal, but nothing happens. ghost behaviour. πŸ‘»

if a non-zero named buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target (see glBindBuffer()) while a texture image is specified, pixels is treated as a byte offset into the buffer object's data store. yes, the pointer becomes an offset. iconic but rude. 😭


🧚 NOTES 🧚

  • glPixelStore() modes affect texture images. like, they matter, don't ignore her.
  • glTexSubImage2D and glTextureSubImage3D specify a two-dimensional subtexture for the current texture unit, specified with glActiveTexture(). (and yeah that says glTextureSubImage3D right there in the notes, that's literally what the page says, I don't make the rules πŸ’€)
  • GL_STENCIL_INDEX is accepted for format only if the GL version is 4.4 or higher. version check first, bestie, always.

πŸ’€ ERRORS πŸ’€

like, the whole list, because we don't gatekeep:

  • GL_INVALID_ENUM is generated if target or the effective target of texture is not GL_TEXTURE_2D, 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_TEXTURE_1D_ARRAY.
  • GL_INVALID_OPERATION is generated by glTextureSubImage2D if texture is not the name of an existing texture object.
  • GL_INVALID_ENUM is generated if format is not an accepted format constant.
  • 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 log 2 max, where max is the returned value of GL_MAX_TEXTURE_SIZE.
  • GL_INVALID_VALUE is generated if xoffset < - b, xoffset + width > w - b, yoffset < - b, or yoffset + height > h - b, where w is the GL_TEXTURE_WIDTH, h is the GL_TEXTURE_HEIGHT, and b is the border width of the texture image being modified. note that w and h include twice the border width. twice!! πŸ“
  • GL_INVALID_VALUE is generated if width or height is less than 0.
  • GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D() operation. you gotta make the texture before you edit the texture, babe.
  • 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 is GL_STENCIL_INDEX and the base internal format is not GL_STENCIL_INDEX.
  • 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 pixels is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.

πŸ” ASSOCIATED GETS πŸ”

  • glGetTexImage()
  • glGet() with argument GL_PIXEL_UNPACK_BUFFER_BINDING

πŸ‘‘ VERSION SUPPORT πŸ‘‘

the table said what it said, so here it is in list form, every version accounted for, no cap:

  • glTexSubImage2D β€” βœ” in OpenGL 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glTextureSubImage2D β€” - in OpenGL 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, and βœ” only in 4.5

so glTexSubImage2D has been that girl since day one, and glTextureSubImage2D showed up late to the party in 4.5 and honestly? worth the wait. 🌈


🌸 SEE ALSO 🌸

glActiveTexture(), glCopyTexImage1D(), glCopyTexImage2D(), glCopyTexSubImage1D(), glCopyTexSubImage2D(), glCopyTexSubImage3D(), glPixelStore(), glTexImage1D(), glTexImage2D(), glTexImage3D(), glTexSubImage1D(), glTexSubImage3D(), glTexParameter()

the whole friend group, go say hi 🫢


Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-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 Β© 2010-2014 Khronos Group

(both copyright blocks stay, because the page says them both twice and we respect the paper trail πŸ’…)


and that's the page!! mwah πŸ’‹ this was GLTEXSUBIMAGE2D(3G) β€” the source line is literally [FIXME: source] (yes, they left a FIXME in, we love a WIP 😭) and the date on it is 08/09/2021. go forth and subimage responsibly, bestie πŸŽ€βœ¨

πŸ“¦ where this page comes from