'''_glCopyTexSubImage2D:''' copy a two-dimensional texture subimage


{{PageSyntax}}

:  SUB _glCopyTexSubImage2D (BYVAL target AS _UNSIGNED LONG, BYVAL level AS LONG, BYVAL xoffset AS LONG, BYVAL yoffset AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL width AS LONG, BYVAL height AS LONG)

:  void '''_glCopyTexSubImage2D'''(GLenum {{Parameter|target}}, GLint {{Parameter|level}}, GLint {{Parameter|xoffset}}, GLint {{Parameter|yoffset}}, GLint {{Parameter|x}}, GLint {{Parameter|y}}, GLsizei {{Parameter|width}}, GLsizei {{Parameter|height}});


; target
: Specifies the target texture. Must be {{KW|_GL_TEXTURE_2D}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_X}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_X}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_Y}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_Z}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}}, or {{KW|_GL_TEXTURE_1D_ARRAY}}.
; level
: Specifies the level-of-detail number. Level 0 is the base image level. Level ''n'' is the ''n''th mipmap reduction image.
; xoffset
: Specifies a texel offset in the x direction within the texture array.
; yoffset
: Specifies a texel offset in the y direction within the texture array.
; x, y
: Specify the window coordinates of the lower left corner of the rectangular region of pixels to be copied.
; width
: Specifies the width of the texture subimage.
; height
: Specifies the height of the texture subimage.


{{PageDescription}}

'''_glCopyTexSubImage2D''' replaces a rectangular portion of a two-dimensional texture image, cube-map texture image or a linear portion of a number of slices of a one-dimensional array texture with pixels from the current {{KW|_GL_READ_BUFFER}} (rather than from main memory, as is the case for {{KW|_glTexSubImage2D}}).

The screen-aligned pixel rectangle with lower left corner at (''x'', ''y'') and with width {{Parameter|width}} and height {{Parameter|height}} replaces the portion of the texture array with x indices {{Parameter|xoffset}} through ''xoffset + width - 1'', inclusive, and y indices {{Parameter|yoffset}} through ''yoffset + height - 1'', inclusive, at the mipmap level specified by {{Parameter|level}}.

The pixels in the rectangle are processed exactly as if {{KW|_glReadPixels}} had been called, but the process stops just before final conversion. At this point, all pixel component values are clamped to the range [0, 1] and then converted to the texture's internal format for storage in the texel array.

The destination rectangle in the texture array may not include any texels outside the texture array as it was originally specified. It is not an error to specify a subtexture with zero width or height, but such a specification has no effect.

When {{Parameter|target}} is {{KW|_GL_TEXTURE_1D_ARRAY}} then the y coordinate and height are treated as the start slice and number of slices to modify.

If any of the pixels within the specified rectangle of the current {{KW|_GL_READ_BUFFER}} are outside the read window associated with the current rendering context, then the values obtained for those pixels are undefined.

No change is made to the ''internalformat'', ''width'', ''height'', or ''border'' parameters of the specified texture array or to texel values outside the specified subregion.


{{PageNotes}}

{{KW|_glPixelStore}} modes affect texture images.


{{PageErrors}}

{{KW|_GL_INVALID_ENUM}} is generated if {{Parameter|target}} is not {{KW|_GL_TEXTURE_2D}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_X}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_X}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_Y}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y}}, {{KW|_GL_TEXTURE_CUBE_MAP_POSITIVE_Z}}, {{KW|_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}}, or {{KW|_GL_TEXTURE_1D_ARRAY}}.

{{KW|_GL_INVALID_OPERATION}} is generated if the texture array has not been defined by a previous {{KW|_glTexImage2D}} or {{KW|_glCopyTexImage2D}} operation.

{{KW|_GL_INVALID_VALUE}} is generated if {{Parameter|level}} is less than 0.

{{KW|_GL_INVALID_VALUE}} may be generated if ''level'' is greater than log&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;(max), where ''max'' is the returned value of {{KW|_GL_MAX_TEXTURE_SIZE}}.

{{KW|_GL_INVALID_VALUE}} is generated if xoffset &amp;lt; 0, xoffset + width &amp;gt; w, yoffset &amp;lt; 0, or yoffset + height &amp;gt; h, where w is the {{KW|_GL_TEXTURE_WIDTH}} and h is the {{KW|_GL_TEXTURE_HEIGHT}} of the texture image being modified.


{{PageUseWith}}

{{KW|_glGetTexImage}}


{{PageSeeAlso}}

[[_GL|SUB _GL]]
{{KW|_glActiveTexture}}, {{KW|_glBindTexture}}, {{KW|_glBindFramebuffer}}, {{KW|_glCopyImageSubData}}, {{KW|_glCopyTexSubImage1D}}, {{KW|_glCopyTexSubImage3D}}, {{KW|_glCopyTexImage2D}}, {{KW|_glReadBuffer}}


{{PageCopyright}}
