|
|
@@ -164,12 +164,12 @@ class XRManager extends EventDispatcher {
|
|
|
this._layers = [];
|
|
|
|
|
|
/**
|
|
|
- * Whether the device has support for all layer types.
|
|
|
+ * Whether the XR session uses layers.
|
|
|
*
|
|
|
* @type {boolean}
|
|
|
* @default false
|
|
|
*/
|
|
|
- this._supportsLayers = false;
|
|
|
+ this._sessionUsesLayers = false;
|
|
|
|
|
|
/**
|
|
|
* Whether the device supports binding gl objects.
|
|
|
@@ -360,13 +360,16 @@ class XRManager extends EventDispatcher {
|
|
|
this._xrFrame = null;
|
|
|
|
|
|
/**
|
|
|
- * Whether to use the WebXR Layers API or not.
|
|
|
+ * Whether the browser supports the APIs necessary to use XRProjectionLayers.
|
|
|
+ *
|
|
|
+ * Note: this does not represent XRSession explicitly requesting
|
|
|
+ * `'layers'` as a feature - see `_sessionUsesLayers` and #30112
|
|
|
*
|
|
|
* @private
|
|
|
* @type {boolean}
|
|
|
* @readonly
|
|
|
*/
|
|
|
- this._useLayers = ( this._supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
|
|
|
+ this._supportsLayers = ( this._supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
|
|
|
|
|
|
/**
|
|
|
* Whether the usage of multiview has been requested by the application or not.
|
|
|
@@ -587,6 +590,27 @@ class XRManager extends EventDispatcher {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Return the current XR binding.
|
|
|
+ *
|
|
|
+ * Creates a new binding if needed and the browser is
|
|
|
+ * capable of doing so.
|
|
|
+ *
|
|
|
+ * @return {?XRWebGLBinding} The XR binding. Returns `null` if a binding cannot be crated.
|
|
|
+ */
|
|
|
+ getBinding() {
|
|
|
+
|
|
|
+ if ( this._glBinding === null && this._supportsGlBinding ) {
|
|
|
+
|
|
|
+ this._glBinding = new XRWebGLBinding( this._session, this._gl );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._glBinding;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the current XR frame.
|
|
|
*
|
|
|
@@ -817,7 +841,7 @@ class XRManager extends EventDispatcher {
|
|
|
layer.renderTarget.isXRRenderTarget = this._session !== null;
|
|
|
layer.renderTarget._hasExternalTextures = layer.renderTarget.isXRRenderTarget;
|
|
|
|
|
|
- if ( layer.renderTarget.isXRRenderTarget && this._supportsLayers ) {
|
|
|
+ if ( layer.renderTarget.isXRRenderTarget && this._sessionUsesLayers ) {
|
|
|
|
|
|
layer.xrlayer.transform = new XRRigidTransform( layer.plane.getWorldPosition( translationObject ), layer.plane.getWorldQuaternion( quaternionObject ) );
|
|
|
|
|
|
@@ -924,16 +948,7 @@ class XRManager extends EventDispatcher {
|
|
|
|
|
|
//
|
|
|
|
|
|
- if ( this._supportsGlBinding ) {
|
|
|
-
|
|
|
- const glBinding = new XRWebGLBinding( session, gl );
|
|
|
- this._glBinding = glBinding;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- if ( this._useLayers === true ) {
|
|
|
+ if ( this._supportsLayers === true ) {
|
|
|
|
|
|
// default path using XRProjectionLayer
|
|
|
|
|
|
@@ -963,6 +978,7 @@ class XRManager extends EventDispatcher {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ this._glBinding = this.getBinding();
|
|
|
const glProjLayer = this._glBinding.createProjectionLayer( projectionlayerInit );
|
|
|
const layersArray = [ glProjLayer ];
|
|
|
|
|
|
@@ -993,11 +1009,11 @@ class XRManager extends EventDispatcher {
|
|
|
this._xrRenderTarget._hasExternalTextures = true;
|
|
|
this._xrRenderTarget.depth = this._useMultiview ? 2 : 1;
|
|
|
|
|
|
- this._supportsLayers = session.enabledFeatures.includes( 'layers' );
|
|
|
+ this._sessionUsesLayers = session.enabledFeatures.includes( 'layers' );
|
|
|
|
|
|
this._referenceSpace = await session.requestReferenceSpace( this.getReferenceSpaceType() );
|
|
|
|
|
|
- if ( this._supportsLayers ) {
|
|
|
+ if ( this._sessionUsesLayers ) {
|
|
|
|
|
|
// switch layers to native
|
|
|
for ( const layer of this._layers ) {
|
|
|
@@ -1366,7 +1382,7 @@ function onSessionEnd() {
|
|
|
this._xrRenderTarget = null;
|
|
|
|
|
|
// switch layers back to emulated
|
|
|
- if ( this._supportsLayers === true ) {
|
|
|
+ if ( this._sessionUsesLayers === true ) {
|
|
|
|
|
|
for ( const layer of this._layers ) {
|
|
|
|
|
|
@@ -1568,7 +1584,7 @@ function onAnimationFrame( time, frame ) {
|
|
|
|
|
|
let viewport;
|
|
|
|
|
|
- if ( this._useLayers === true ) {
|
|
|
+ if ( this._supportsLayers === true ) {
|
|
|
|
|
|
const glSubImage = this._glBinding.getViewSubImage( this._glProjLayer, view );
|
|
|
viewport = glSubImage.viewport;
|