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)
The 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],
});
}