Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrCompatible false per default, canvas made compatible on demand #15027

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
RaananW marked this conversation as resolved.
Show resolved Hide resolved
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