on onSessionEnded(event) {
      if (event.session.isImmersive) {
        xrButton.setSession(null);
      }
      xrSession = null;
      gl = null;
    }

    function onXRFrame(time, frame) {
      let pose = frame.getViewerPose(xrRefSpace);
      xrSession.requestAnimationFrame(onXRFrame);

      if (quadLayer1 && quadLayer2) {
        xrSession.updateRenderState({ layers: [quadLayer1, quadLayer2, projLayer] });
        if (quadLayer1.needsRedraw) {
          let fb = gl.createFramebuffer();
          l