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, forglTexSubImage2D. has to be one ofGL_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, orGL_TEXTURE_1D_ARRAY. no substitutes, no vibes-based guessing. πtextureβ the texture object name, forglTextureSubImage2D. and its effective target has to be one of the valid target values from up there πlevelβ the level-of-detail number.0is 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, andGL_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, andGL_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.glTexSubImage2DandglTextureSubImage3Dspecify a two-dimensional subtexture for the current texture unit, specified withglActiveTexture(). (and yeah that saysglTextureSubImage3Dright there in the notes, that's literally what the page says, I don't make the rules π)GL_STENCIL_INDEXis accepted forformatonly if the GL version is4.4or higher. version check first, bestie, always.
π ERRORS π
like, the whole list, because we don't gatekeep:
GL_INVALID_ENUMis generated iftargetor the effective target oftextureis notGL_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, orGL_TEXTURE_1D_ARRAY.GL_INVALID_OPERATIONis generated byglTextureSubImage2Diftextureis not the name of an existing texture object.GL_INVALID_ENUMis generated ifformatis not an accepted format constant.GL_INVALID_ENUMis generated iftypeis not a type constant.GL_INVALID_VALUEis generated iflevelis less than0.GL_INVALID_VALUEmay be generated iflevelis greater than log 2 max, where max is the returned value ofGL_MAX_TEXTURE_SIZE.GL_INVALID_VALUEis generated ifxoffset < - b,xoffset + width > w - b,yoffset < - b, oryoffset + height > h - b, where w is theGL_TEXTURE_WIDTH, h is theGL_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_VALUEis generated ifwidthorheightis less than0.GL_INVALID_OPERATIONis generated if the texture array has not been defined by a previousglTexImage2D()operation. you gotta make the texture before you edit the texture, babe.GL_INVALID_OPERATIONis generated iftypeis one ofGL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5, orGL_UNSIGNED_SHORT_5_6_5_REVandformatis notGL_RGB.GL_INVALID_OPERATIONis generated iftypeis one ofGL_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, orGL_UNSIGNED_INT_2_10_10_10_REVandformatis neitherGL_RGBAnorGL_BGRA.GL_INVALID_OPERATIONis generated ifformatisGL_STENCIL_INDEXand the base internal format is notGL_STENCIL_INDEX.GL_INVALID_OPERATIONis generated if a non-zero buffer object name is bound to theGL_PIXEL_UNPACK_BUFFERtarget and the buffer object's data store is currently mapped.GL_INVALID_OPERATIONis generated if a non-zero buffer object name is bound to theGL_PIXEL_UNPACK_BUFFERtarget and the data would be unpacked from the buffer object such that the memory reads required would exceed the data store size.GL_INVALID_OPERATIONis generated if a non-zero buffer object name is bound to theGL_PIXEL_UNPACK_BUFFERtarget andpixelsis not evenly divisible into the number of bytes needed to store in memory a datum indicated bytype.
π ASSOCIATED GETS π
glGetTexImage()glGet()with argumentGL_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 OpenGL2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3,4.4,4.5glTextureSubImage2Dβ-in OpenGL2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3,4.4, and β only in4.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 π
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
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms