W3cubDocs

/Web APIs

XRRenderState: layers property

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The read-only layers property of the XRRenderState interface is an ordered array containing XRLayer objects that are displayed by the XR compositor.

Value

An ordered array containing XRLayer objects. The order of the layers is "back-to-front".

Examples

Getting render state layers

To read the WebXR layers array, use the layers property on XRRenderState. Layers can be set using the XRSession.updateRenderState() method.

js

const xrSession = navigator.xr.requestSession("immersive-ar", {
  optionalFeatures: ["layers"],
});

function onXRSessionStarted(xrSession) {
  const glCanvas = document.createElement("canvas");
  const gl = glCanvas.getContext("webgl", { xrCompatible: true });
  const xrGlBinding = new XRWebGLBinding(xrSession, gl);
  const projectionLayer = new XRWebGLLayer(xrSession, gl);
  const quadLayer = xrGlBinding.createQuadLayer({
    pixelWidth: 1024,
    pixelHeight: 1024,
  });

  xrSession.updateRenderState({
    layers: [projectionLayer, quadLayer],
  });

  xrSession.renderState.layers; // [projectionLayer, quadLayer]
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
layers No No No No No No No No No No No No

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XRRenderState/layers