Skip to content

Commit

Permalink
WebGPUTextures: Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Sep 18, 2020
1 parent 6246c13 commit ade8cd9
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,57 +279,6 @@ class WebGPUTextures {

}

_convertFormat( format, type ) {

let formatGPU;

switch ( format ) {

case RGBA_S3TC_DXT1_Format:
formatGPU = GPUTextureFormat.BC1RGBAUnorm;
break;

case RGBA_S3TC_DXT3_Format:
formatGPU = GPUTextureFormat.BC2RGBAUnorm;
break;

case RGBA_S3TC_DXT5_Format:
formatGPU = GPUTextureFormat.BC3RGBAUnorm;
break;

case RGBFormat:
case RGBAFormat:

switch ( type ) {

case UnsignedByteType:
formatGPU = GPUTextureFormat.RGBA8Unorm;
break;

case FloatType:
formatGPU = GPUTextureFormat.RGBA32Float;
break;

case HalfFloatType:
formatGPU = GPUTextureFormat.RGBA16Float;
break;

default:
console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );

}

break;

default:
console.error( 'WebGPURenderer: Unsupported texture format.', format );

}

return formatGPU;

}

_createTexture( texture ) {

const device = this.device;
Expand All @@ -338,7 +287,7 @@ class WebGPUTextures {
const width = ( image !== undefined ) ? image.width : 1;
const height = ( image !== undefined ) ? image.height : 1;

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

let mipLevelCount;
Expand Down Expand Up @@ -531,6 +480,60 @@ class WebGPUTextures {

}

_getFormat( texture ) {

const format = texture.format;
const type = texture.type;

let formatGPU;

switch ( format ) {

case RGBA_S3TC_DXT1_Format:
formatGPU = GPUTextureFormat.BC1RGBAUnorm;
break;

case RGBA_S3TC_DXT3_Format:
formatGPU = GPUTextureFormat.BC2RGBAUnorm;
break;

case RGBA_S3TC_DXT5_Format:
formatGPU = GPUTextureFormat.BC3RGBAUnorm;
break;

case RGBFormat:
case RGBAFormat:

switch ( type ) {

case UnsignedByteType:
formatGPU = GPUTextureFormat.RGBA8Unorm;
break;

case FloatType:
formatGPU = GPUTextureFormat.RGBA32Float;
break;

case HalfFloatType:
formatGPU = GPUTextureFormat.RGBA16Float;
break;

default:
console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );

}

break;

default:
console.error( 'WebGPURenderer: Unsupported texture format.', format );

}

return formatGPU;

}

_getMipLevelCount( width, height ) {

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

0 comments on commit ade8cd9

Please sign in to comment.