@@ -22,7 +22,7 @@ import type { CoreNode } from '../../CoreNode.js';
2222import type { CoreShaderManager } from '../../CoreShaderManager.js' ;
2323import { getRgbaComponents , type RGBA } from '../../lib/utils.js' ;
2424import { SubTexture } from '../../textures/SubTexture.js' ;
25- import type { Texture } from '../../textures/Texture.js' ;
25+ import { TextureType , type Texture } from '../../textures/Texture.js' ;
2626import type { CoreContextTexture } from '../CoreContextTexture.js' ;
2727import {
2828 CoreRenderer ,
@@ -43,6 +43,7 @@ import {
4343 type IParsedColor ,
4444} from './internal/ColorUtils.js' ;
4545import { UnsupportedShader } from './shaders/UnsupportedShader.js' ;
46+ import { assertTruthy } from '../../../utils.js' ;
4647
4748export class CanvasCoreRenderer extends CoreRenderer {
4849 private context : CanvasRenderingContext2D ;
@@ -118,6 +119,17 @@ export class CanvasCoreRenderer extends CoreRenderer {
118119 | { x : number ; y : number ; width : number ; height : number }
119120 | undefined ;
120121
122+ const textureType = texture ?. type ;
123+ assertTruthy ( textureType , 'Texture type is not defined' ) ;
124+
125+ // The Canvas2D renderer only supports image and color textures
126+ if (
127+ textureType !== TextureType . image &&
128+ textureType !== TextureType . color
129+ ) {
130+ return ;
131+ }
132+
121133 if ( texture ) {
122134 if ( texture instanceof SubTexture ) {
123135 frame = texture . props ;
@@ -126,11 +138,9 @@ export class CanvasCoreRenderer extends CoreRenderer {
126138
127139 ctxTexture = texture . ctxTexture as CanvasCoreTexture ;
128140 if ( texture . state === 'freed' ) {
129- // we're going to batch the texture loading so we don't have to wait for
130- // ctxTexture.load();
131141 return ;
132142 }
133- if ( texture . state !== 'loaded' || ! ctxTexture . hasImage ( ) ) {
143+ if ( texture . state !== 'loaded' ) {
134144 return ;
135145 }
136146 }
@@ -175,7 +185,7 @@ export class CanvasCoreRenderer extends CoreRenderer {
175185 ctx . clip ( path ) ;
176186 }
177187
178- if ( ctxTexture ) {
188+ if ( textureType === TextureType . image && ctxTexture ) {
179189 const image = ctxTexture . getImage ( color ) ;
180190 ctx . globalAlpha = color . a ?? alpha ;
181191 if ( frame ) {
@@ -199,7 +209,7 @@ export class CanvasCoreRenderer extends CoreRenderer {
199209 }
200210 }
201211 ctx . globalAlpha = 1 ;
202- } else if ( hasGradient ) {
212+ } else if ( textureType === TextureType . color && hasGradient ) {
203213 let endX : number = tx ;
204214 let endY : number = ty ;
205215 let endColor : IParsedColor ;
@@ -219,7 +229,7 @@ export class CanvasCoreRenderer extends CoreRenderer {
219229 gradient . addColorStop ( 1 , formatRgba ( endColor ) ) ;
220230 ctx . fillStyle = gradient ;
221231 ctx . fillRect ( tx , ty , width , height ) ;
222- } else {
232+ } else if ( textureType === TextureType . color ) {
223233 ctx . fillStyle = formatRgba ( color ) ;
224234 ctx . fillRect ( tx , ty , width , height ) ;
225235 }
0 commit comments