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 in Web Workers.
The texStorage2D() method of the WebGL2RenderingContext of the WebGL API specifies all levels of two-dimensional texture storage.
texStorage2D(target, levels, internalformat, width, height)
targetA GLenum specifying 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 GLint specifying the number of texture levels.
internalformatA GLenum specifying 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_STENCIL8Unlike OpenGL 3.0, WebGL 2 doesn't support the following ETC2 and EAC compressed texture formats (see section 5.37 in the WebGL 2 spec). You might be able to enable them via the WEBGL_compressed_texture_etc extension, 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_EACFor the description of these formats, see WebGLRenderingContext.texImage2D(). Because texStorage2D does not actually specify a buffer source, the format and type parameters are irrelevant, and can be considered to be any of the valid values corresponding to the internalformat.
widthA GLsizei specifying the width of the texture in texels.
heightA GLsizei specifying the height of the texture in texels.
None (undefined).
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGB8, 256, 256);
| Specification |
|---|
| WebGL 2.0 Specification> # 3.7.6> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
texStorage2D |
56 | 79 | 51 | 43 | 15 | 58 | 51 | 43 | 15 | 7.0 | 58 | 15 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/texStorage2D