Skip to content

Commit

Permalink
remove image -> canvas conversion (#27021)
Browse files Browse the repository at this point in the history
Co-authored-by: aardgoose <[email protected]>
  • Loading branch information
aardgoose and aardgoose authored Oct 24, 2023
1 parent 25ce027 commit 4fc9ce7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
36 changes: 2 additions & 34 deletions examples/jsm/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ class Textures extends DataMap {

for ( const image of texture.images ) {

images.push( this._getUploadImage( image ) );
images.push( image );

}

options.images = images;

} else {

options.image = this._getUploadImage( image );
options.image = image;

}

Expand Down Expand Up @@ -317,38 +317,6 @@ class Textures extends DataMap {

}

_getUploadImage( image ) {

if ( this._isHTMLImage( image ) ) {

return this._imageToCanvas( image );

}

return image;

}

_imageToCanvas( image ) {

const { width, height } = image;

// eslint-disable-next-line compat/compat
const canvas = new OffscreenCanvas( width, height );

const context = canvas.getContext( '2d' );
context.drawImage( image, 0, 0, width, height );

return canvas;

}

_isHTMLImage( image ) {

return ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement );

}

_destroyTexture( texture ) {

this.backend.destroySampler( texture );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class WebGLBackend extends Backend {

return source.image.data;

} else if ( source instanceof ImageBitmap || source instanceof OffscreenCanvas ) {
} else if ( source instanceof ImageBitmap || source instanceof OffscreenCanvas || source instanceof HTMLImageElement || source instanceof HTMLCanvasElement ) {

return source;

Expand Down

0 comments on commit 4fc9ce7

Please sign in to comment.