From 4fc9ce75b9b7bd46caaad7a9d9067aefbff67dcb Mon Sep 17 00:00:00 2001 From: aardgoose Date: Tue, 24 Oct 2023 17:42:41 +0100 Subject: [PATCH] remove image -> canvas conversion (#27021) Co-authored-by: aardgoose --- examples/jsm/renderers/common/Textures.js | 36 ++------------------ examples/jsm/renderers/webgl/WebGLBackend.js | 2 +- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/examples/jsm/renderers/common/Textures.js b/examples/jsm/renderers/common/Textures.js index d662c53664789e..71bd98c14f69fe 100644 --- a/examples/jsm/renderers/common/Textures.js +++ b/examples/jsm/renderers/common/Textures.js @@ -191,7 +191,7 @@ class Textures extends DataMap { for ( const image of texture.images ) { - images.push( this._getUploadImage( image ) ); + images.push( image ); } @@ -199,7 +199,7 @@ class Textures extends DataMap { } else { - options.image = this._getUploadImage( image ); + options.image = image; } @@ -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 ); diff --git a/examples/jsm/renderers/webgl/WebGLBackend.js b/examples/jsm/renderers/webgl/WebGLBackend.js index ec80edf0bfa191..9071cc59bb4c16 100644 --- a/examples/jsm/renderers/webgl/WebGLBackend.js +++ b/examples/jsm/renderers/webgl/WebGLBackend.js @@ -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;