glCopyTexSubImage2D Function

Syntax

GL_APICALL void GL_APIENTRY glCopyTexSubImage2D(
     GLenum target,
     GLint level,
     GLint xoffset,
     GLint yoffset,
     GLint x,
     GLint y,
     GLsizei width,
     GLsizei height
);

Parameters

Name Description
in target Target texture.
in level Mipmap level of the data to load.
in xoffset X coordinate at the lower-left corner of the partial texture region to copy to.
in yoffset Y coordinate at the lower-left corner of the partial texture region to copy to.
in x X coordinate at the lower-left corner of the color buffer's copy region.
in y Y coordinate at the lower-left corner of the color buffer's copy region.
in width Width of the region read from the color buffer.
in height Height of the region read from the color buffer.

Return Values

There is no return value.

Description

Partially copies the content of the current color buffer into texture data.

Use this function to copy only a portion of the image processed by the glCopyTexImage2D function. The texture image must be created using the glTexImage2D function before you can call this function.

You can set target to one of the following values.

GL_TEXTURE_2D2D texture.
GL_TEXTURE_CUBE_MAP_NEGATIVE_XFace of a cube-map texture in the negative x direction.
GL_TEXTURE_CUBE_MAP_POSITIVE_XFace of a cube-map texture in the positive x direction.
GL_TEXTURE_CUBE_MAP_NEGATIVE_YFace of a cube-map texture in the negative y direction.
GL_TEXTURE_CUBE_MAP_POSITIVE_YFace of a cube-map texture in the positive y direction.
GL_TEXTURE_CUBE_MAP_NEGATIVE_ZFace of a cube-map texture in the negative z direction.
GL_TEXTURE_CUBE_MAP_POSITIVE_ZFace of a cube-map texture in the positive z direction.

When you specify -2 or less for the level argument, all textures other than for the lowest mipmap level are automatically generated. Automatic mipmap generation is only supported for some texture formats. Also, the minimum generatable texture widths and heights (LOD upper limit) are different for each texture format. The following table shows the supported values for format and type and the minimum generatable sizes.

formattypeMinimum automatically generatable size (in texels)
GL_RGBAGL_UNSIGNED_SHORT_4_4_4_464
GL_RGBAGL_UNSIGNED_SHORT_5_5_5_164
GL_RGBAGL_UNSIGNED_BYTE32
GL_RGBGL_UNSIGNED_SHORT_5_6_564
GL_RGBGL_UNSIGNED_BYTE32
GL_RGBA_NATIVE_DMPGL_UNSIGNED_SHORT_4_4_4_464
GL_RGBA_NATIVE_DMPGL_UNSIGNED_SHORT_5_5_5_164
GL_RGBA_NATIVE_DMPGL_UNSIGNED_BYTE32
GL_RGB_NATIVE_DMPGL_UNSIGNED_SHORT_5_6_564
GL_RGB_NATIVE_DMPGL_UNSIGNED_BYTE32
Specifying a value for level that does not conform to the minimum sizes of the generated mipmaps listed above causes a GL_INVALID_OPERATION error. When GL_GENERATE_MIPMAP is TRUE, you must specify the same value for level as was specified in the previous call to TexImage2D or CopyTexImage2D. Specifying a different value for level causes an error. When GL_GENERATE_MIPMAP is FALSE, you must specify 0 for level. Any other value causes an error.

You must set xoffset, yoffset, x, y, width, and height to multiples of 8.

You can copy the current depth buffer to a texture and use that. Call the glEnable function and specify GL_DEPTH_STENCIL_COPY_DMP to enable the depth stencil copy feature. Call the glDisable function to disable this feature. Call the glIsEnabled function and specify GL_DEPTH_STENCIL_COPY_DMP to find if the depth stencil copy feature is enabled.

The format of the target texture for copying is determined by the format of the current depth buffer. Format conversion when copying is not supported. The format of the current depth buffer corresponds to the format of the target texture for copying as follows.

Depth Buffer FormatDepth Buffer ContentCorresponding Texture Format (Texture Type)
GL_DEPTH24_STENCIL8_EXTR: 8-bit stencil value
G: 24-bit depth value, bits [23:16]
B: 24-bit depth value, bits [15:8]
A: 24-bit depth value, bits [7:0]
GL_RGBA (GL_UNSIGNED_BYTE), GL_RGBA_NATIVE_DMP (GL_UNSIGNED_BYTE)
GL_DEPTH_COMPONENT24_OESR: 24-bit depth value, bits [23:16]
G: 24-bit depth value, bits [15:8]
B: 24-bit depth value, bits [7:0]
GL_RGB (GL_UNSIGNED_BYTE), GL_RGB_NATIVE_DMP (GL_UNSIGNED_BYTE)
GL_DEPTH_COMPONENT16R: 16-bit depth value, bits [15:8]
G: 16-bit depth value, bits [7:0]
GL_HILO8_DMP (GL_UNSIGNED_BYTE), GL_HILO8_NATIVE_DMP (GL_UNSIGNED_BYTE)

The following errors occur in this function.

GL_INVALID_FRAMEBUFFER_OPERATIONA color buffer has not been configured correctly for the current framebuffer.
GL_INVALID_VALUEThe xoffset, yoffset, x, y, width, or height argument was set to an invalid value; the sum of xoffset and width exceeds the width (in pixels) of the color buffer; or the sum of yoffset and height exceeds the height (in pixels) of the color buffer.
GL_INVALID_OPERATIONThe level argument was set to an invalid value.
GL_INVALID_ENUMtarget was set to an invalid value.
GL_INVALID_OPERATIONThis function was called without any command-list objects bound.
GL_INVALID_OPERATIONThis function was called on a texture object with a texture format that does not correspond to the current depth buffer format.

Revision History

2010/09/18
Explained that a texture must first be generated using the glTexImage2D function.
2010/09/15
Added explanation of automatic mipmap generation to the level argument description.
2010/08/12
Explained the depth stencil copy feature.
2010/01/07
Initial version.

CONFIDENTIAL