Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Support KTX Compressed texture in the WebGL Backend #27463

Merged
merged 7 commits into from
Dec 31, 2023
Prev Previous commit
Next Next commit
cleanup and add silentError
  • Loading branch information
RenaudRohlinger committed Dec 29, 2023
commit b6be5e157eebc6c937f807cdeb77c0781db14d07
12 changes: 6 additions & 6 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ class KTX2Loader extends Loader {
if ( renderer.isWebGPURenderer === true ) {

this.workerConfig = {
astcSupported: renderer.hasFeature( 'texture-compression-astc' ),
etc1Supported: renderer.hasFeature( 'texture-compression-etc1' ),
etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ),
dxtSupported: renderer.hasFeature( 'texture-compression-bc' ),
bptcSupported: renderer.hasFeature( 'texture-compression-bptc' ),
pvrtcSupported: renderer.hasFeature( 'texture-compression-pvrtc' )
astcSupported: renderer.hasFeature( 'texture-compression-astc', true ),
etc1Supported: renderer.hasFeature( 'texture-compression-etc1', true ),
etc2Supported: renderer.hasFeature( 'texture-compression-etc2', true ),
dxtSupported: renderer.hasFeature( 'texture-compression-bc', true ),
bptcSupported: renderer.hasFeature( 'texture-compression-bptc', true ),
pvrtcSupported: renderer.hasFeature( 'texture-compression-pvrtc', true )
};

} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Backend {

// utils

hasFeature( name ) { } // return Boolean
hasFeature( name, silentError ) { } // return Boolean

getInstanceCount( renderObject ) {

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ class Renderer {

}

hasFeature( name ) {
hasFeature( name, silentError ) {

return this.backend.hasFeature( name );
return this.backend.hasFeature( name, silentError );

}

Expand Down
20 changes: 11 additions & 9 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,26 +833,28 @@ class WebGLBackend extends Backend {

}

hasFeature( name ) {
hasFeature( name, silentError ) {

const feature = GLFeatureName[ name ];
if ( ! feature ) {

console.warn( 'Unknown WebGL feature: ' + name );
return false;
const keysMatching = Object.keys( GLFeatureName ).filter( key => GLFeatureName[ key ] === name );

if ( ! silentError && keysMatching.length === 0 ) {

throw new Error( 'THREE.WebGPURenderer: Unknown WebGPU GPU feature: ' + name );

}

if ( Array.isArray( feature ) ) {
const extensions = this.extensions;

return feature.some( ext => this.extensions.has( ext ) );
for ( let i = 0; i < keysMatching.length; i ++ ) {

} else {

return this.extensions.has( feature );
if ( extensions.has( keysMatching[ i ] ) ) return true;

}

return false;

}


Expand Down
13 changes: 7 additions & 6 deletions examples/jsm/renderers/webgl/utils/WebGLConstants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export const GLFeatureName = {

'texture-compression-astc': 'WEBGL_compressed_texture_astc',
'texture-compression-etc2': 'WEBGL_compressed_texture_etc',
'texture-compression-etc1': 'WEBGL_compressed_texture_etc1',
'texture-compression-pvrtc': [ 'WEBGL_compressed_texture_pvrtc', 'WEBKIT_WEBGL_compressed_texture_pvrtc' ],
'texture-compression-bc': 'WEBGL_compressed_texture_s3tc',
'texture-compression-bptc': 'EXT_texture_compression_bptc',
'WEBGL_compressed_texture_astc': 'texture-compression-astc',
'WEBGL_compressed_texture_etc': 'texture-compression-etc2',
'WEBGL_compressed_texture_etc1': 'texture-compression-etc1',
'WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc',
'WEBKIT_WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc',
'WEBGL_compressed_texture_s3tc': 'texture-compression-bc',
'EXT_texture_compression_bptc': 'texture-compression-bptc',

};
29 changes: 28 additions & 1 deletion examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,34 @@

const mipmap = mipmaps[ i ];
if ( texture.isCompressedArrayTexture ) {
// TODO Handle compressed array textures

const image = options.image;

for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {

mipmap = mipmaps[ i ];
Fixed Show fixed Hide fixed

if ( texture.format !== gl.RGBA ) {

if ( glFormat !== null ) {

gl.compressedTexSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );


} else {

console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );

}

} else {

gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data );

}

}

} else {

if ( glFormat !== null ) {
Expand Down
7 changes: 3 additions & 4 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,17 +1065,16 @@ class WebGPUBackend extends Backend {

}

hasFeature( name ) {
hasFeature( name, silentError ) {

const adapter = this.adapter || _staticAdapter;

//

const features = Object.values( GPUFeatureName );

if ( features.includes( name ) === false ) {
if ( ! silentError && features.includes( name ) === false ) {
RenaudRohlinger marked this conversation as resolved.
Show resolved Hide resolved

console.warn( 'THREE.WebGPURenderer: Unknown WebGPU GPU feature: ' + name );
throw new Error( 'THREE.WebGPURenderer: Unknown WebGPU GPU feature: ' + name );

}

Expand Down