WebGL2RenderingContext: texStorage2D() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
Note: This feature is available inWeb Workers.
ThetexStorage2D() method of theWebGL2RenderingContext of theWebGL API specifies all levels of two-dimensional texture storage.
In this article
Syntax
texStorage2D(target, levels, internalformat, width, height)Parameters
targetA
GLenumspecifying the binding point (target) of the active texture. Possible values:gl.TEXTURE_2D: A two-dimensional texture.gl.TEXTURE_CUBE_MAP: A cube-mapped texture.
levelsA
GLintspecifying the number of texture levels.internalformatA
GLenumspecifying the texture store format. Possible values:gl.R8gl.R8_SNORMgl.R16Fgl.R32Fgl.R8UIgl.R8Igl.R16UIgl.R16Igl.R32UIgl.R32Igl.RG8gl.RG8_SNORMgl.RG16Fgl.RG32Fgl.RG8UIgl.RG8Igl.RG16UIgl.RG16Igl.RG32UIgl.RG32Igl.RGB8gl.SRGB8gl.RGB565gl.RGB8_SNORMgl.R11F_G11F_B10Fgl.RGB9_E5gl.RGB16Fgl.RGB32Fgl.RGB8UIgl.RGB8Igl.RGB16UIgl.RGB16Igl.RGB32UIgl.RGB32Igl.RGBA8gl.SRGB8_ALPHA8gl.RGBA8_SNORMgl.RGB5_A1gl.RGBA4gl.RGB10_A2gl.RGBA16Fgl.RGBA32Fgl.RGBA8UIgl.RGBA8Igl.RGB10_A2UIgl.RGBA16UIgl.RGBA16Igl.RGBA32UIgl.RGBA32Igl.DEPTH_COMPONENT16gl.DEPTH_COMPONENT24gl.DEPTH_COMPONENT32Fgl.DEPTH24_STENCIL8gl.DEPTH32F_STENCIL8
Unlike OpenGL 3.0, WebGL 2doesn't support the following ETC2 and EAC compressed texture formats (seesection 5.37 in the WebGL 2 spec). You might be able to enable them via the
WEBGL_compressed_texture_etcextension, though.gl.COMPRESSED_R11_EACgl.COMPRESSED_SIGNED_R11_EACgl.COMPRESSED_RG11_EACgl.COMPRESSED_SIGNED_RG11_EACgl.COMPRESSED_RGB8_ETC2gl.COMPRESSED_SRGB8_ETC2gl.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2gl.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2gl.COMPRESSED_RGBA8_ETC2_EACgl.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
For the description of these formats, see
WebGLRenderingContext.texImage2D(). BecausetexStorage2Ddoes not actually specify a buffer source, theformatandtypeparameters are irrelevant, and can be considered to be any of the valid values corresponding to theinternalformat.widthA
GLsizeispecifying the width of the texture in texels.heightA
GLsizeispecifying the height of the texture in texels.
Return value
None (undefined).
Examples
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGB8, 256, 256);Specifications
| Specification |
|---|
| WebGL 2.0 Specification> # 3.7.6> |