WEBGL_depth_texture
WebGL working group (public_webgl 'at' khronos.org)
Members of the WebGL working group
Florian Bösch (pyalot 'at' gmail.com)
Last modified date: March 15, 2020
Revision: 13
WebGL extension #9
Written against the WebGL API 1.0 specification.
No longer available as of the WebGL API 2.0 specification.
This extension exposes the ANGLE_depth_texture functionality to WebGL. ANGLE_depth_texture provides a subset of the functionality from the OpenGL ES 2.0 extensions OES_depth_texture and OES_packed_depth_stencil, with certain restrictions added for portability reasons. Specifically:
DEPTH24_STENCIL8_OES renderbuffer internal format from the OES_packed_depth_stencil extension. The core WebGL specification already supports allocation of depth/stencil renderbuffers. Consult the Errors section below for specific restrictions.
When this extension is enabled:
texImage2D entry point is extended to accept the
format parameter DEPTH_COMPONENT and
DEPTH_STENCIL
texImage2D entry point is extended to accept the
internalFormat parameter DEPTH_COMPONENT
and DEPTH_STENCIL
texImage2D entry point is extended to accept
the type parameter UNSIGNED_SHORT,
UNSIGNED_INT, and
UNSIGNED_INT_24_8_WEBGL
framebufferTexture2D entry point is extended to
accept the target parameter
DEPTH_ATTACHMENT and
DEPTH_STENCIL_ATTACHMENT
texImage2D entry point is extended to accept
ArrayBufferView of type Uint16Array and
Uint32Array
The WebGL-specific constraints about Framebuffer Object Attachments are extended:
DEPTH_ATTACHMENT attachment point must be allocated with the DEPTH_COMPONENT internal format. DEPTH_STENCIL_ATTACHMENT attachment point must be allocated with the DEPTH_STENCIL internal format. In the WebGL API, it is an error to concurrently attach either renderbuffers or textures to the following combinations of attachment points:
DEPTH_ATTACHMENT + DEPTH_STENCIL_ATTACHMENT STENCIL_ATTACHMENT + DEPTH_STENCIL_ATTACHMENT DEPTH_ATTACHMENT + STENCIL_ATTACHMENT See the section Framebuffer Object Attachments in the WebGL specification for the behavior if these constraints are violated.
As per the OpenGL ES spec, there is no guarantee that the OpenGL ES implementation will use the texture type to determine how to store the depth texture internally. It may choose to downsample the 32-bit depth values to 16-bit or even 24-bit. When a depth or depth/stencil texture is attached to a framebuffer object, calls to getParameter with the DEPTH_BITS and STENCIL_BITS enums return the following:
| Texture Type | DEPTH_BITS (GLint) | STENCIL_BITS (GLint) |
|---|---|---|
| UNSIGNED_SHORT | >= 16 | 0 |
| UNSIGNED_INT | >= 16 | 0 |
| UNSIGNED_INT_24_8_WEBGL | >= 24 | >= 8 |
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
interface WEBGL_depth_texture {
const GLenum UNSIGNED_INT_24_8_WEBGL = 0x84FA;
};
INVALID_OPERATION is generated by
texImage2D if the format parameter is
DEPTH_COMPONENT or DEPTH_STENCIL and the
target is
TEXTURE_CUBE_MAP_{POSITIVE,NEGATIVE}_{X,Y,Z}.
INVALID_OPERATION is generated by
texImage2D if format and
internalformat are DEPTH_COMPONENT and
type is not UNSIGNED_SHORT or
UNSIGNED_INT.
INVALID_OPERATION is generated by
texImage2D if format and
internalformat are not DEPTH_COMPONENT
and type is UNSIGNED_SHORT or
UNSIGNED_INT.
INVALID_OPERATION is generated by
texImage2D if format and
internalformat are DEPTH_STENCIL and
type is not UNSIGNED_INT_24_8_WEBGL.
INVALID_OPERATION is generated by
texImage2D if format and
internalformat are not DEPTH_STENCIL and
type is UNSIGNED_INT_24_8_WEBGL.
INVALID_OPERATION is generated in the following situations:
texImage2D is called with format and
internalformat of DEPTH_COMPONENT or
DEPTH_STENCIL and
target is not TEXTURE_2D, data is not NULL, or level is not zero. texSubImage2D is called with format of
DEPTH_COMPONENT or DEPTH_STENCIL.
copyTexImage2D is called with an
internalformat that has a base internal format of
DEPTH_COMPONENT or DEPTH_STENCIL.
copyTexSubImage2D is called with a target texture
that has a base internal format of DEPTH_COMPONENT
or DEPTH_STENCIL.
generateMipmap is called on a texture that has a
base internal format of DEPTH_COMPONENT or
DEPTH_STENCIL.
As per the ANGLE_depth_texture specification, when a depth
texture is sampled, the value is stored into the RED channel.
The contents of the GREEN, BLUE and ALPHA channels are
implementation dependent. It is therefore recommended to use
only the r component of variables in GLSL shaders
that are used to reference depth textures.
Revision 1, 2012/01/23
Revision 2, 2012/01/25
Revision 3, 2012/02/06
Revision 4, 2012/02/24
Revision 5, 2012/03/01
Revision 6, 2012/06/04
Revision 7, 2012/06/20
Revision 8, 2012/06/27
Revision 9, 2013/01/26
Revision 10, 2013/02/28
Revision 11, 2013/05/15
Revision 12, 2014/07/15
Revision 13, 2020/03/15