Skip to content

Commit

Permalink
WebGPUTextures: Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Sep 18, 2020
1 parent 5e1417c commit fcdfc8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 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 {

}

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

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

Expand Down
47 changes: 23 additions & 24 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class WebGPUTextures {

if ( this.defaultTexture === null ) {

this.defaultTexture = this._createTexture( new Texture() );
const texture = new Texture();
texture.minFilter = NearestFilter;
texture.magFilter = NearestFilter;

this.defaultTexture = this._createTexture( texture );

}

Expand Down Expand Up @@ -243,12 +247,6 @@ class WebGPUTextures {

}

_computeMipLevelCount( width, height ) {

return Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;

}

_convertAddressMode( value ) {

let addressMode = GPUAddressMode.ClampToEdge;
Expand Down Expand Up @@ -341,31 +339,26 @@ class WebGPUTextures {
const height = ( image !== undefined ) ? image.height : 1;

const format = this._convertFormat( texture.format, texture.type );
const needsMipmaps = this._needsMipmaps( texture );

let needsMipmaps;
let mipLevelCount;
let usage = GPUTextureUsage.SAMPLED | GPUTextureUsage.COPY_DST;

if ( texture.isCompressedTexture ) {

mipLevelCount = texture.mipmaps.length;

} else {

needsMipmaps = this._needsMipmaps( texture );

if ( needsMipmaps === true ) {

mipLevelCount = this._computeMipLevelCount( width, height );

}
mipLevelCount = this._getMipLevelCount( width, height );

}
// current mipmap generation requires OUTPUT_ATTACHMENT

let usage = GPUTextureUsage.SAMPLED | GPUTextureUsage.COPY_DST;

if ( needsMipmaps === true ) {
usage |= GPUTextureUsage.OUTPUT_ATTACHMENT;

usage |= GPUTextureUsage.OUTPUT_ATTACHMENT;
}

}

Expand Down Expand Up @@ -481,7 +474,7 @@ class WebGPUTextures {

}

this.utils.generateMipmappedTexture( imageBitmap, textureGPU, textureGPUDescriptor );
this.utils.generateMipmaps( imageBitmap, textureGPU, textureGPUDescriptor );

}

Expand Down Expand Up @@ -522,6 +515,14 @@ class WebGPUTextures {

}

_getBlockData( format ) {

if ( format === GPUTextureFormat.BC1RGBAUnorm ) return { byteLength: 8, width: 4, height: 4 };
if ( format === GPUTextureFormat.BC2RGBAUnorm ) return { byteLength: 16, width: 4, height: 4 };
if ( format === GPUTextureFormat.BC3RGBAUnorm ) return { byteLength: 16, width: 4, height: 4 };

}

_getBytesPerTexel( format ) {

if ( format === GPUTextureFormat.RGBA8Unorm ) return 4;
Expand All @@ -530,17 +531,15 @@ class WebGPUTextures {

}

_getBlockData( format ) {
_getMipLevelCount( width, height ) {

if ( format === GPUTextureFormat.BC1RGBAUnorm ) return { byteLength: 8, width: 4, height: 4 };
if ( format === GPUTextureFormat.BC2RGBAUnorm ) return { byteLength: 16, width: 4, height: 4 };
if ( format === GPUTextureFormat.BC3RGBAUnorm ) return { byteLength: 16, width: 4, height: 4 };
return Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;

}

_needsMipmaps( texture ) {

return ( texture.generateMipmaps === true ) && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
return ( texture.isCompressedTexture !== true ) && ( texture.generateMipmaps === true ) && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );

}

Expand Down

0 comments on commit fcdfc8a

Please sign in to comment.