This documentation is archived and is not being maintained.
This documentation is archived and is not being maintained.
copyTexImage2D method
Copies a rectangle of pixels from the current WebGLFramebuffer into a texture image.
Syntax
WebGLRenderingContext.copyTexImage2D(target, level, format, x, y, width, height, border);
Parameters
target [in]
Type: Number
One of the following:
Value
Meaning
gl.TEXTURE_2D
Uses a 2D image.
gl.TEXTURE_CUBE_MAP_POSITIVE_X
Image for the positive X face of the cube.
gl.TEXTURE_CUBE_MAP_NEGATIVE_X
Image for the negative X face of the cube.
gl.TEXTURE_CUBE_MAP_POSITIVE_Y
Image for the positive Y face of the cube.
gl.TEXTURE_CUBE_MAP_NEGATIVE_Y
Image for the negative Y face of the cube.
gl.TEXTURE_CUBE_MAP_POSITIVE_Z
Image for the positive Z face of the cube.
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
Image for the negative Z face of the cube.
level [in]
Type: Number
The level of detail. Level 0 equals the base image level. Additional levels (n) equal the nth mipmap reduction image. See generateMipmap to create mipmaps.
format [in]
Type: Number
Specifies the internal format of the texture.
Value
Meaning
gl.ALPHA
Each element is a single alpha component. The system converts it to floating point, clamped to the range [0, 1], and assembles it into an RGBA element by placing attaching 0.0 to the red, green and blue channels.
gl.LUMINANCE
Each element is a single luminance component. The system converts it to floating point value, clamped to the range [0, 1], and assembles it into an RGBA element by placing the luminance value in the red, green and blue channels, and attaching 1.0 to the alpha channel.
gl.LUMINANCE_ALPHA
Each element is an luminance/alpha double. The systems converts each component to floating point, clamped to the range [0, 1], and assembles them into an RGBA element by placing the luminance value in the red, green and blue channels.
gl.RGB
Red, green, and blue channels.
gl.RGBA
Red, green, blue, and alpha (transparency) channels.
x [in]
Type: Number
Horizontal coordinate of the lower left corner of the pixels to copy.
y [in]
Type: Number
Vertical coordinate of the lower left corner of the pixels to copy.
width [in]
Type: Number
The width of the rectangle or box you want to copy from. A 2D texture image needs to be at least 64 texels wide, and cube-mapped texture images should be 16 texels wide.
height [in]
Type: Number
The height of the rectangle or box you want to copy from. A 2D texture image needs to be at least 64 texels high, and cube-mapped texture images should be 16 texels high.
border [in]
Type: Number
Width of border. Always 0.
Return value
This method does not return a value.
Remarks
CopyTexImage2D doesn't support floating point texture sources or destinations.
WebGL error
Description
gl.INVALID_ENUM
Value of target is not one of the specified constants.
gl.INVALID_VALUE
The value of level is < 0.
If xoffset is < 0.
If yoffset is < 0.
If xoffset + width is greater than the width of the image being modified.
If yoffset + height is greater than the height of the image being modified.