Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Remove HTMLImage to OffscreenCanvas conversion #27021

Merged
merged 1 commit into from
Oct 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -496,7 +496,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