XRRenderState.layers

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.

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

No specification found

No specification data found for api.XRRenderState.layers.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

No compatibility data found for api.XRRenderState.layers.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.

See also