Skip to content

Commit

Permalink
ix a Type Error exception with the latest version of Safari when usin…
Browse files Browse the repository at this point in the history
…g OffscreenCanvas element as a texture source

- `textImage2D()` won't accept a OffscreenCanvas directly as a texture source
- disable internal use of OffscreenCanvas when drawing font (for now), as with the above changes it produces weird artefacts
  • Loading branch information
obiot committed Mar 30, 2023
1 parent c88d51b commit b9066c1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Fixed
- Renderer: add missing export for the `CanvasTexture` class
- WebGL: fix a Type Error exception with the latest version of Safari when using OffscreenCanvas element as a texture source

## [15.0.0] (melonJS 2) - _2023-03-18_

Expand Down
3 changes: 2 additions & 1 deletion src/text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ const toPX = [12, 24, 0.75, 1];
}

// the canvas Texture used to render this text
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });

// instance to text metrics functions
this.metrics = new TextMetrics(this);
Expand Down
3 changes: 3 additions & 0 deletions src/video/webgl/compositors/quad_compositor.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ var V_ARRAY = [
if (pixels === null || typeof pixels.byteLength !== "undefined") {
// if pixels is undefined, or if it's Uint8Array/Float32Array TypedArray
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels, 0);
} else if (pixels instanceof OffscreenCanvas) {
// convert to ImageBitmap first (else Safari 16.4 and higher will throw an TypeError exception)
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels.transferToImageBitmap());
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
}
Expand Down

0 comments on commit b9066c1

Please sign in to comment.