
          xrButton.enabled = supported;
        });
      }
    }

    function onRequestSession() {
      if (!xrSession) {
        navigator.xr.requestSession('immersive-vr', {
          requiredFeatures: ['layers'],
        }).then(onSessionStarted);
      } else {
        onEndSession();
      }
    }

    function initGL() {
      if (gl) { return; }
      gl = createWebGLContext({ xrCompatible: true, webgl2: true, });
      document.body.appendChild(gl.canvas);

      function onResize() {
        gl