Skip to content

Commit

Permalink
WebGPUTextures: Clarify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Sep 19, 2020
1 parent 1af599c commit c9a8edc
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,43 +301,18 @@ class WebGPUTextures {
const device = this.device;
const image = texture.image;

let width, height, depth;

if ( texture.isCubeTexture ) {

width = ( image.length > 0 ) ? image[ 0 ].width : 1;
height = ( image.length > 0 ) ? image[ 0 ].height : 1;
depth = 6;

} else {

width = ( image !== undefined ) ? image.width : 1;
height = ( image !== undefined ) ? image.height : 1;
depth = 1;

}

const format = this._getFormat( texture );
const { width, height, depth } = this._getSize( texture );
const needsMipmaps = this._needsMipmaps( texture );
const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
const format = this._getFormat( texture );

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

if ( texture.isCompressedTexture ) {

mipLevelCount = texture.mipmaps.length;

} else {

if ( needsMipmaps === true ) {
if ( needsMipmaps === true ) {

mipLevelCount = this._getMipLevelCount( width, height );
// current mipmap generation requires OUTPUT_ATTACHMENT

// current mipmap generation requires OUTPUT_ATTACHMENT

usage |= GPUTextureUsage.OUTPUT_ATTACHMENT;

}
usage |= GPUTextureUsage.OUTPUT_ATTACHMENT;

}

Expand Down Expand Up @@ -598,9 +573,49 @@ class WebGPUTextures {

}

_getMipLevelCount( width, height ) {
_getMipLevelCount( texture, width, height, needsMipmaps ) {

let mipLevelCount;

if ( texture.isCompressedTexture ) {

mipLevelCount = texture.mipmaps.length;

} else if ( needsMipmaps === true ) {

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

} else {

mipLevelCount = 1; // a texture without mipmaps has a base mip (mipLevel 0)

}

return mipLevelCount;

}

_getSize( texture ) {

const image = texture.image;

let width, height, depth;

if ( texture.isCubeTexture ) {

width = ( image.length > 0 ) ? image[ 0 ].width : 1;
height = ( image.length > 0 ) ? image[ 0 ].height : 1;
depth = 6; // one image for each side of the cube map

} else {

width = ( image !== undefined ) ? image.width : 1;
height = ( image !== undefined ) ? image.height : 1;
depth = 1;

}

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

}

Expand Down

0 comments on commit c9a8edc

Please sign in to comment.