This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The createQuadLayer() method of the XRWebGLBinding interface returns an XRQuadLayer object which is a layer that takes up a flat rectangular space in the virtual environment.
createQuadLayer(options)
optionsAn object to configure the XRQuadLayer. It must have the space, viewPixelHeight, and viewPixelWidth properties. init has the following properties:
colorFormat OptionalA GLenum defining the data type of the color texture data. Possible values:
gl.RGBgl.RGBA Additionally, for contexts with the EXT_sRGB extension enabled:ext.SRGB_EXText.SRGB_ALPHA_EXT Additionally, for WebGL2RenderingContext contexts:gl.RGBA8gl.RGB8gl.SRGB8gl.RGB8_ALPHA8 Additionally, for contexts with the WEBGL_compressed_texture_etc extension enabled:ext.COMPRESSED_RGB8_ETC2ext.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2ext.COMPRESSED_RGBA8_ETC2_EACext.COMPRESSED_SRGB8_ETC2ext.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2ext.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC Additionally, for contexts with the WEBGL_compressed_texture_astc extension enabled:gl.RGBA.depthFormat OptionalA GLenum defining the data type of the depth texture data or 0 indicating that the layer should not provide a depth texture (in that case XRProjectionLayer.ignoreDepthValues will be true). Possible values within WebGLRenderingContext contexts with the WEBGL_depth_texture extension enabled, or within WebGL2RenderingContext contexts (no extension required):
gl.DEPTH_COMPONENTgl.DEPTH_STENCIL Additionally, for WebGL2RenderingContext contexts:gl.DEPTH_COMPONENT24gl.DEPTH24_STENCIL24 The default value is gl.DEPTH_COMPONENT.height OptionalA number specifying the height of the layer in meters. The default value is 1.0.
isStatic OptionalA boolean that, if true, indicates you can only draw to this layer when needsRedraw is true. The default value is false.
layout OptionalA string indicating the layout of the layer. Possible values:
defaultThe layer accommodates all views of the session.
monoA single XRSubImage is allocated and presented to both eyes.
stereoThe user agent decides how it allocates the XRSubImage (one or two) and the layout (top/bottom or left/right).
stereo-left-rightA single XRSubImage is allocated. Left eye gets the left area of the texture, right eye the right.
stereo-top-bottomA single XRSubImage is allocated. Left eye gets the top area of the texture, right eye the bottom. The default value is mono.
mipLevels OptionalA number specifying desired number of mip levels. The default value is 1.
space RequiredAn XRSpace object defining the layer's spatial relationship with the user's physical environment.
textureType OptionalA string defining the type of texture the layer will have. Possible values:
textureThe textures of XRWebGLSubImage will be of type gl.TEXTURE_2D.
texture-arraythe textures of XRWebGLSubImage will be of type gl.TEXTURE_2D_ARRAY (WebGL 2 contexts only). The default value is texture.
transform OptionalAn XRRigidTransform object defining the offset and orientation relative to space.
viewPixelHeight RequiredA number specifying the pixel height of the layer view.
viewPixelWidth RequiredA number specifying the pixel width of the layer view.
width OptionalA number specifying the width of the layer in meters. The default value is 1.0.
An XRQuadLayer object.
XRQuadLayer
Configure the quad layer using the properties listed above in a call to createQuadLayer(). To present layers to the XR device, add them to the layers render state using XRSession.updateRenderState().
function onXRSessionStarted(xrSession) {
const glCanvas = document.createElement("canvas");
const gl = glCanvas.getContext("webgl2", { xrCompatible: true });
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const quadLayer = xrGlBinding.createQuadLayer({
space: xrReferenceSpace,
viewPixelHeight: 512,
viewPixelWidth: 512,
transform: new XRRigidTransform({ z: -2 }),
});
xrSession.updateRenderState({
layers: [quadLayer],
});
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
createQuadLayer |
No | No | No | No | No | No | No | No | No | No | No | No |
© 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/XRWebGLBinding/createQuadLayer