Skip to content

Commit 297385a

Browse files
authored
WebXRManager: Set glBinding separately from layer creation. (#31443)
* Set `glBinding` separately from layer creation * Implement in XRManager
1 parent cf58904 commit 297385a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/renderers/common/XRManager.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ class XRManager extends EventDispatcher {
171171
*/
172172
this._supportsLayers = false;
173173

174+
/**
175+
* Whether the device supports binding gl objects.
176+
*
177+
* @private
178+
* @type {boolean}
179+
* @readonly
180+
*/
181+
this._supportsGlBinding = typeof XRWebGLBinding !== 'undefined';
182+
174183
this._frameBufferTargets = null;
175184

176185
/**
@@ -357,7 +366,7 @@ class XRManager extends EventDispatcher {
357366
* @type {boolean}
358367
* @readonly
359368
*/
360-
this._useLayers = ( typeof XRWebGLBinding !== 'undefined' && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
369+
this._useLayers = ( this._supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype ); // eslint-disable-line compat/compat
361370

362371
/**
363372
* Whether the usage of multiview has been requested by the application or not.
@@ -915,9 +924,18 @@ class XRManager extends EventDispatcher {
915924

916925
//
917926

927+
if ( this._supportsGlBinding ) {
928+
929+
const glBinding = new XRWebGLBinding( session, gl );
930+
this._glBinding = glBinding;
931+
932+
}
933+
934+
//
935+
918936
if ( this._useLayers === true ) {
919937

920-
// default path using XRWebGLBinding/XRProjectionLayer
938+
// default path using XRProjectionLayer
921939

922940
let depthFormat = null;
923941
let depthType = null;
@@ -945,11 +963,9 @@ class XRManager extends EventDispatcher {
945963

946964
}
947965

948-
const glBinding = new XRWebGLBinding( session, gl );
949-
const glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
966+
const glProjLayer = this._glBinding.createProjectionLayer( projectionlayerInit );
950967
const layersArray = [ glProjLayer ];
951968

952-
this._glBinding = glBinding;
953969
this._glProjLayer = glProjLayer;
954970

955971
renderer.setPixelRatio( 1 );

src/renderers/webxr/WebXRManager.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,15 @@ class WebXRManager extends EventDispatcher {
398398
currentPixelRatio = renderer.getPixelRatio();
399399
renderer.getSize( currentSize );
400400

401+
if ( typeof XRWebGLBinding !== 'undefined' ) {
402+
403+
glBinding = new XRWebGLBinding( session, gl );
404+
405+
}
406+
401407
// Check that the browser implements the necessary APIs to use an
402408
// XRProjectionLayer rather than an XRWebGLLayer
403-
const useLayers = typeof XRWebGLBinding !== 'undefined' && 'createProjectionLayer' in XRWebGLBinding.prototype;
409+
const useLayers = glBinding !== null && 'createProjectionLayer' in XRWebGLBinding.prototype;
404410

405411
if ( ! useLayers ) {
406412

@@ -453,8 +459,6 @@ class WebXRManager extends EventDispatcher {
453459
scaleFactor: framebufferScaleFactor
454460
};
455461

456-
glBinding = new XRWebGLBinding( session, gl );
457-
458462
glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
459463

460464
session.updateRenderState( { layers: [ glProjLayer ] } );

0 commit comments

Comments
 (0)