GLGETTEXIMAGE(3G)
π GLGETTEXIMAGE(3G) π
okay so this is the manual page for glGetTexImage, glGetnTexImage and glGetTextureImage from section 3G of the manual, and bestie, it's literally all about pulling a texture image OUT of the GPU and into your own little buffer. no cap, it's giving "give me back my pixels." β¨
πΈ NAME πΈ
glGetTexImage, glGetnTexImage, glGetTextureImage β return a texture image π
π¦ C SPECIFICATION π¦
void glGetTexImage(GLenum target, GLint level, GLenum format,
GLenum type, GLvoid * pixels);
void glGetnTexImage(GLenum target, GLint level, GLenum format,
GLenum type, GLsizei bufSize, void *pixels);
void glGetTextureImage(GLuint texture, GLint level, GLenum format,
GLenum type, GLsizei bufSize, void *pixels);
copy those exactly, okay? character for character. π
β¨ PARAMETERS β¨
targetβ this is the target the texture is bound to, for theglGetTexImageandglGetnTexImagefunctions only. the acceptable values areGL_TEXTURE_1D,GL_TEXTURE_2D,GL_TEXTURE_3D,GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_RECTANGLE,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, andGL_TEXTURE_CUBE_MAP_ARRAY. that's the whole guest list, no plus-ones. π«Άtextureβ specifies the texture object name. yeah, the whole object-name energy. πlevelβ the level-of-detail number of the image you want. level 0 is the base image level. level n is the *n*th mipmap reduction image. so like, level 0 is the main character and every level after is a smaller little redux of it. πformatβ the pixel format for the returned data. supported formats areGL_STENCIL_INDEX,GL_DEPTH_COMPONENT,GL_DEPTH_STENCIL,GL_RED,GL_GREEN,GL_BLUE,GL_RG,GL_RGB,GL_RGBA,GL_BGR,GL_BGRA,GL_RED_INTEGER,GL_GREEN_INTEGER,GL_BLUE_INTEGER,GL_RG_INTEGER,GL_RGB_INTEGER,GL_RGBA_INTEGER,GL_BGR_INTEGER,GL_BGRA_INTEGER. yes that's all of them, don't try to be cute and invent one. πtypeβ the pixel type for the returned data. supported types areGL_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,GL_UNSIGNED_INT_2_10_10_10_REV,GL_UNSIGNED_INT_24_8,GL_UNSIGNED_INT_10F_11F_11F_REV,GL_UNSIGNED_INT_5_9_9_9_REV, andGL_FLOAT_32_UNSIGNED_INT_24_8_REV. that's a lot of types and we respect all of them equally. πbufSizeβ the size of the bufferpixels, for theglGetnTexImageandglGetTextureImagefunctions. it's the vibe check on how much room you actually reserved. πpixelsβ returns the texture image. it should be a pointer to an array of the type specified bytype. this is where the pixels go. this is the whole point. π
π DESCRIPTION π
the glGetTexImage, glGetnTexImage and glGetTextureImage functions return a texture image into pixels. iconic behaviour, honestly.
for glGetTexImage and glGetnTexImage, target specifies whether the desired texture image is one specified by glTexImage1D() (that's GL_TEXTURE_1D), by glTexImage2D() (that's GL_TEXTURE_1D_ARRAY, GL_TEXTURE_RECTANGLE, GL_TEXTURE_2D or any of GL_TEXTURE_CUBE_MAP_*), or by glTexImage3D() (that's GL_TEXTURE_2D_ARRAY, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP_ARRAY). so, yeah, target is basically telling on which function made the texture. π΅οΈββοΈ
for glGetTextureImage, texture specifies the texture object name instead. and on top of the texture types accepted by glGetTexImage and glGetnTexImage, this function also accepts cube map texture objects β with effective target GL_TEXTURE_CUBE_MAP. she's flexible like that. π
level specifies the level-of-detail number of the desired image. format and type specify the format and type of the desired image array. for a description of the acceptable values for the format and type parameters respectively, go peek at the reference page for glTexImage1D(). (yes, respectively. we're being precise today.) π
for the glGetnTexImage and glGetTextureImage functions, bufSize tells you the size of the buffer that receives the retrieved pixel data. and importantly: glGetnTexImage and glGetTextureImage do not write more than bufSize bytes into pixels. they stay in their lane. π₯
ngl the next part is important β if a non-zero named buffer object is bound to theGL_PIXEL_PACK_BUFFERtarget (seeglBindBuffer()) while a texture image is requested, thenpixelsis treated as a byte offset into the buffer object's data store. not a pointer. an offset. don't get it twisted. π
so like, to understand the operation of glGetTexImage, consider the selected internal four-component texture image to be an RGBA color buffer the size of the image. the semantics of glGetTexImage are then identical to those of glReadPixels() β with the one exception that no pixel transfer operations are performed β when called with the same format and type, with x and y set to 0, width set to the width of the texture image, and height set to 1 for 1D images, or to the height of the texture image for 2D images. periodt. β¨
if the selected texture image does not contain four components, these mappings get applied, and honestly it's giving "filling in the blanks":
- single-component textures are treated as RGBA buffers with red set to the single-component value, green set to 0, blue set to 0, and alpha set to 1. π
- two-component textures are treated as RGBA buffers with red set to the value of component zero, alpha set to the value of component one, and green and blue set to 0.
- three-component textures are treated as RGBA buffers with red set to component zero, green set to component one, blue set to component two, and alpha set to 1. πΈ
to determine the required size of pixels, use glGetTexLevelParameter() to determine the dimensions of the internal texture image, then scale the required number of pixels by the storage required for each pixel β based on format and type. and bestie, be sure to take the pixel storage parameters into account, especially GL_PACK_ALIGNMENT. she will absolutely ruin your day if you forget her. π
if glGetTextureImage is used against a cube map texture object, the texture is treated as a three-dimensional image of a depth of 6, where the cube map faces are ordered as image layers, in the order in this little list right here:
- layer 0 β
GL_TEXTURE_CUBE_MAP_POSITIVE_X - layer 1 β
GL_TEXTURE_CUBE_MAP_NEGATIVE_X - layer 2 β
GL_TEXTURE_CUBE_MAP_POSITIVE_Y - layer 3 β
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - layer 4 β
GL_TEXTURE_CUBE_MAP_POSITIVE_Z - layer 5 β
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
six faces, six layers, in that exact order. iykyk. π§
β NOTES β
if an error is generated, no change is made to the contents of pixels. she said "if i can't do it right, i'm not doing it at all." π
glGetTexImage and glGetnTexImage return the texture image for the active texture unit. yes, the one that's currently the main character.
GL_STENCIL_INDEX is accepted for format only if the GL version is 4.4 or greater. do with that what you will. π
π ERRORS π
GL_INVALID_ENUM is generated by the glGetTexImage and glGetnTexImage functions if target is not an accepted value. these include:
GL_TEXTURE_1D,GL_TEXTURE_2D,GL_TEXTURE_3D,GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_CUBE_MAP_ARRAY,GL_TEXTURE_RECTANGLE,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, andGL_TEXTURE_CUBE_MAP_NEGATIVE_Zfor theglGetTexImageandglGetnTexImagefunctions.GL_TEXTURE_1D,GL_TEXTURE_2D,GL_TEXTURE_3D,GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_CUBE_MAP_ARRAY,GL_TEXTURE_RECTANGLE, andGL_TEXTURE_CUBE_MAPfor theglGetTextureImagefunction.
GL_INVALID_OPERATION is generated by glGetTextureImage if texture is not the name of an existing texture object. (she doesn't know her, sorry.)
GL_INVALID_ENUM is generated if format or type is not an accepted value.
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 level is non-zero and the effective target is GL_TEXTURE_RECTANGLE.
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, GL_UNSIGNED_SHORT_5_6_5_REV, or GL_UNSIGNED_INT_10F_11F_11F_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, GL_UNSIGNED_INT_2_10_10_10_REV, or GL_UNSIGNED_INT_5_9_9_9_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 or GL_DEPTH_STENCIL.
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and the buffer object's data store is currently mapped. like, she's busy, come back later. π
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and the data would be packed to the buffer object such that the memory writes required would exceed the data store size. no overflowing, bestie. π«Ά
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_PACK_BUFFER target and pixels is not evenly divisible into the number of bytes needed to store in memory a datum indicated by type.
GL_INVALID_OPERATION is generated by glGetTextureImage and glGetnTexImage if the buffer size required to store the requested data is greater than bufSize. π
π₯ ASSOCIATED GETS π₯
glGetTexLevelParameter() with argument GL_TEXTURE_WIDTH
glGetTexLevelParameter() with argument GL_TEXTURE_HEIGHT
glGetTexLevelParameter() with argument GL_TEXTURE_INTERNAL_FORMAT
glGet() with arguments GL_PACK_ALIGNMENT and others
glGet() with argument GL_PIXEL_PACK_BUFFER_BINDING
okay that's part 1 β part 2 is right behind this one, so don't go anywhere π
β¨ VERSION SUPPORT β¨
Okay bestie, this is the glow-up timeline β which OpenGL version each function actually showed up in. The grid in the original is genuinely giving spreadsheet era, so here it is as vibes-only lists, same facts, no cap π
The columns are 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:
glGetTexImageββin 2.0,βin 2.1,βin 3.0,βin 3.1,βin 3.2,βin 3.3,βin 4.0,βin 4.1,βin 4.2,βin 4.3,βin 4.4,βin 4.5 π«Ά (she's been here since forever, an icon, a legend)glGetTextureImageβ-in 2.0,-in 2.1,-in 3.0,-in 3.1,-in 3.2,-in 3.3,-in 4.0,-in 4.1,-in 4.2,-in 4.3,-in 4.4,βin 4.5 πΈ (late bloomer, arrived in 4.5, we still love her)glGetnTexImageβ-in 2.0,-in 2.1,-in 3.0,-in 3.1,-in 3.2,-in 3.3,-in 4.0,-in 4.1,-in 4.2,-in 4.3,-in 4.4,βin 4.5 π¦ (also a 4.5 girlie, respect)
π SEE ALSO π
Go read these next, they're all connected fr fr π₯
glActiveTexture()glReadPixels()glTexImage1D()glTexImage2D()glTexImage3D()glTexSubImage1D()glTexSubImage2D()glTexSubImage3D()glTexParameter()
π 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 π (yes, again, it's listed twice in the original, so here it is twice in all its glory)
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group
π©· And that's the whole page, bestie! Original footer energy: this one comes from [FIXME: source] (yes, literally, the source field is a FIXME, iconic π), dated 08/09/2021, filed under GLGETTEXIMAGE(3G). Now go forth and glGetTexImage responsibly πβ¨
π¦ 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