Skip to content

Commit

Permalink
Fix audio engine init issue (#15922)
Browse files Browse the repository at this point in the history
* Fix audio engine init issue

When the `Engine` constructor is called with a `WebGLRenderingContext` or `WebGL2RenderingContext`, the audio engine does not get initialized. This change fixes the issue by calling `Engine._sharedInit` with the WebGL rendering context's canvas.

Note that the WebGL rendering context's canvas may be an `OffscreenCanvas` and its type is cast to `HTMLCanvasElement` for the call to `Engine._sharedInit` because it would be a large change to make `AbstractEngine.__renderingCanvas` support both types. This is done the same way in the `WebGPUEngine` constructor, with the only consequence for the audio engine being that the mute button stays at the top-left of the document instead of automatically repositioning to the top-left of the canvas.

* Call `_sharedInit` from `ThinEngine` instead of `Engine`
  • Loading branch information
docEdub authored Dec 3, 2024
1 parent 8954d4d commit 65aa159
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 0 additions & 6 deletions packages/dev/core/src/Engines/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,6 @@ export class Engine extends ThinEngine {
this._features.supportRenderPasses = true;

options = this._creationOptions;

if ((<any>canvasOrContext).getContext) {
const canvas = <HTMLCanvasElement>canvasOrContext;

this._sharedInit(canvas);
}
}

protected override _initGLContext(): void {
Expand Down
5 changes: 3 additions & 2 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ export class ThinEngine extends AbstractEngine {
let canvas: Nullable<HTMLCanvasElement> = null;
if ((canvasOrContext as any).getContext) {
canvas = <HTMLCanvasElement>canvasOrContext;
this._renderingCanvas = canvas;

if (options.preserveDrawingBuffer === undefined) {
options.preserveDrawingBuffer = false;
Expand Down Expand Up @@ -398,7 +397,7 @@ export class ThinEngine extends AbstractEngine {
}
} else {
this._gl = <WebGL2RenderingContext>canvasOrContext;
this._renderingCanvas = this._gl.canvas as HTMLCanvasElement;
canvas = this._gl.canvas as HTMLCanvasElement;

if ((this._gl as any).renderbufferStorageMultisample) {
this._webGLVersion = 2.0;
Expand All @@ -413,6 +412,8 @@ export class ThinEngine extends AbstractEngine {
}
}

this._sharedInit(canvas);

// Ensures a consistent color space unpacking of textures cross browser.
this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);

Expand Down

0 comments on commit 65aa159

Please sign in to comment.