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 createProjectionLayer() method of the XRWebGLBinding interface returns an XRProjectionLayer object which is a layer that fills the entire view of the observer and is refreshed close to the device's native frame rate.
createProjectionLayer(options)
optionsAn object to configure the XRProjectionLayer.
textureType OptionalAn 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.
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 The default value is 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.scaleFactor OptionalA floating-point value which is used to scale the layer during compositing. A value of 1.0 represents the default pixel size for the frame buffer. (See also XRWebGLLayer.getNativeFramebufferScaleFactor().) Unlike other layers, the XRProjectionLayer can't be created with an explicit pixel width and height, because the size is inferred by the hardware. (Projection layers fill the observer's entire view.)
An XRProjectionLayer object.
XRProjectionLayer in a WebGL 2 contextThe textureType option allows allocating a texture array instead, in which every XRView will be rendered into a separate level of the array. This allows for some rendering optimizations, such as the use of the OVR_multiview2 extension available in WebGL 2 contexts.
function onXRSessionStarted(xrSession) {
const glCanvas = document.createElement("canvas");
const gl = glCanvas.getContext("webgl2", { xrCompatible: true });
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const projectionLayer = xrGlBinding.createProjectionLayer({
textureType: "texture-array",
});
xrSession.updateRenderState({
layers: [projectionLayer],
});
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
createProjectionLayer |
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/createProjectionLayer