Skip to content

Commit

Permalink
xrCompatible false per default, canvas made compatible on demand (#15027
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RaananW committed May 3, 2024
1 parent 732c8ea commit 31530f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class ThinEngine extends AbstractEngine {
}

if (options.xrCompatible === undefined) {
options.xrCompatible = true;
options.xrCompatible = false;
}

// Exceptions
Expand Down
24 changes: 17 additions & 7 deletions packages/dev/core/src/XR/webXRManagedOutputCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class WebXRManagedOutputCanvas implements WebXRRenderTarget {
*/
public onXRLayerInitObservable: Observable<XRWebGLLayer> = new Observable();

private _canvasCompatiblePromise: Promise<void>;

/**
* Initializes the canvas to be added/removed upon entering/exiting xr
* @param _xrSessionManager The XR Session manager
Expand Down Expand Up @@ -102,6 +104,8 @@ export class WebXRManagedOutputCanvas implements WebXRRenderTarget {
_xrSessionManager.onXRSessionEnded.add(() => {
this._removeCanvas();
});

this._makeCanvasCompatibleAsync();
}

/**
Expand All @@ -112,6 +116,18 @@ export class WebXRManagedOutputCanvas implements WebXRRenderTarget {
this._setManagedOutputCanvas(null);
}

private _makeCanvasCompatibleAsync() {
this._canvasCompatiblePromise = new Promise<void>((resolve) => {
if (this.canvasContext && (this.canvasContext as any).makeXRCompatible) {
(this.canvasContext as any).makeXRCompatible().then(() => {
resolve();
});
} else {
resolve();
}
});
}

/**
* Initializes a XRWebGLLayer to be used as the session's baseLayer.
* @param xrSession xr session
Expand All @@ -125,13 +141,7 @@ export class WebXRManagedOutputCanvas implements WebXRRenderTarget {
return this.xrLayer;
};

// support canvases without makeXRCompatible
if (!(this.canvasContext as any).makeXRCompatible) {
return Promise.resolve(createLayer());
}

return (this.canvasContext as any)
.makeXRCompatible()
return this._canvasCompatiblePromise
.then(
// catch any error and continue. When using the emulator is throws this error for no apparent reason.
() => {},
Expand Down

0 comments on commit 31530f7

Please sign in to comment.