Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/core/renderers/canvas/CanvasCoreTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { CoreContextTexture } from '../CoreContextTexture.js';
import { formatRgba, type IParsedColor } from './internal/ColorUtils.js';

export class CanvasCoreTexture extends CoreContextTexture {
protected image: ImageBitmap | HTMLCanvasElement | undefined;
protected image:
| ImageBitmap
| HTMLCanvasElement
| HTMLImageElement
| undefined;
protected tintCache:
| {
key: string;
Expand Down Expand Up @@ -68,7 +72,9 @@ export class CanvasCoreTexture extends CoreContextTexture {
return this.image !== undefined;
}

getImage(color: IParsedColor): ImageBitmap | HTMLCanvasElement {
getImage(
color: IParsedColor,
): ImageBitmap | HTMLCanvasElement | HTMLImageElement {
const image = this.image;
assertTruthy(image, 'Attempt to get unloaded image texture');

Expand All @@ -94,7 +100,7 @@ export class CanvasCoreTexture extends CoreContextTexture {
}

protected tintTexture(
source: ImageBitmap | HTMLCanvasElement,
source: ImageBitmap | HTMLCanvasElement | HTMLImageElement,
color: string,
) {
const { width, height } = source;
Expand Down Expand Up @@ -132,8 +138,8 @@ export class CanvasCoreTexture extends CoreContextTexture {
this.image = canvas;
return { width: data.width, height: data.height };
} else if (
typeof ImageBitmap !== 'undefined' &&
data instanceof ImageBitmap
(typeof ImageBitmap !== 'undefined' && data instanceof ImageBitmap) ||
data instanceof HTMLImageElement
) {
this.image = data;
return { width: data.width, height: data.height };
Expand Down
4 changes: 4 additions & 0 deletions src/core/textures/ImageTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ export class ImageTexture extends Texture {
async loadImageFallback(src: string, hasAlpha: boolean) {
const img = new Image();

if (!src.startsWith('data:')) {
img.crossOrigin = 'Anonymous';
}

return new Promise<{ data: HTMLImageElement; premultiplyAlpha: boolean }>(
(resolve) => {
img.onload = () => {
Expand Down
Loading