diff --git a/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js b/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js index 08f0bce4b2f67e..c6d2c0197567c4 100644 --- a/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +++ b/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js @@ -90,7 +90,7 @@ class WebGPUTextureUtils { } - generateMipmaps( imageBitmap, textureGPU, textureGPUDescriptor ) { + generateMipmaps( textureGPU, textureGPUDescriptor ) { const pipeline = this.getMipmapPipeline( textureGPUDescriptor.format ); diff --git a/examples/jsm/renderers/webgpu/WebGPUTextures.js b/examples/jsm/renderers/webgpu/WebGPUTextures.js index 46e6e9e48e9802..7caeebcbe6b4f1 100644 --- a/examples/jsm/renderers/webgpu/WebGPUTextures.js +++ b/examples/jsm/renderers/webgpu/WebGPUTextures.js @@ -331,9 +331,11 @@ class WebGPUTextures { this._copyBufferToTexture( image, format, textureGPU ); + if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor ); + } else if ( texture.isCompressedTexture ) { - this._copyCompressedTextureDataToTexture( texture.mipmaps, format, textureGPU ); + this._copyCompressedBufferToTexture( texture.mipmaps, format, textureGPU ); } else { @@ -349,7 +351,9 @@ class WebGPUTextures { createImageBitmap( image, 0, 0, width, height, options ).then( imageBitmap => { - this._copyImageBitmapToTexture( imageBitmap, textureGPU, needsMipmaps, textureGPUDescriptor ); + this._copyImageBitmapToTexture( imageBitmap, textureGPU ); + + if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor ); } ); @@ -359,7 +363,9 @@ class WebGPUTextures { // assume ImageBitmap - this._copyImageBitmapToTexture( image, textureGPU, needsMipmaps, textureGPUDescriptor ); + this._copyImageBitmapToTexture( image, textureGPU ); + + if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureGPUDescriptor ); } @@ -399,37 +405,23 @@ class WebGPUTextures { } - _copyImageBitmapToTexture( imageBitmap, textureGPU, needsMipmaps, textureGPUDescriptor ) { + _copyImageBitmapToTexture( image, textureGPU ) { - const device = this.device; - - device.defaultQueue.copyImageBitmapToTexture( + this.device.defaultQueue.copyImageBitmapToTexture( { - imageBitmap: imageBitmap + imageBitmap: image }, { texture: textureGPU }, { - width: imageBitmap.width, - height: imageBitmap.height, + width: image.width, + height: image.height, depth: 1 } ); - if ( needsMipmaps === true ) { - - if ( this.utils === null ) { - - this.utils = new WebGPUTextureUtils( this.device, this.glslang ); // only create this helper if necessary - - } - - this.utils.generateMipmaps( imageBitmap, textureGPU, textureGPUDescriptor ); - - } - } - _copyCompressedTextureDataToTexture( mipmaps, format, textureGPU ) { + _copyCompressedBufferToTexture( mipmaps, format, textureGPU ) { // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture() @@ -464,6 +456,18 @@ class WebGPUTextures { } + _generateMipmaps( textureGPU, textureGPUDescriptor ) { + + if ( this.utils === null ) { + + this.utils = new WebGPUTextureUtils( this.device, this.glslang ); // only create this helper if necessary + + } + + this.utils.generateMipmaps( textureGPU, textureGPUDescriptor ); + + } + _getBlockData( format ) { if ( format === GPUTextureFormat.BC1RGBAUnorm ) return { byteLength: 8, width: 4, height: 4 };