Skip to content

Commit

Permalink
WebGPUTextures: More refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Sep 18, 2020
1 parent b4d4566 commit 9a6f648
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WebGPUTextureUtils {

}

generateMipmaps( imageBitmap, textureGPU, textureGPUDescriptor ) {
generateMipmaps( textureGPU, textureGPUDescriptor ) {

const pipeline = this.getMipmapPipeline( textureGPUDescriptor.format );

Expand Down
50 changes: 27 additions & 23 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 );

} );

Expand All @@ -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 );

}

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit 9a6f648

Please sign in to comment.