Capítulo 176 de 859

Chapter 176: KTX2Loader

Core Idea

A loader for KTX 2.0 GPU Texture containers.

KTX 2.0 is a container format for various GPU texture formats. The loader supports Basis Universal GPU textures, which can be quickly transcoded to a wide variety of GPU texture compression formats. While KTX 2.0 also allows other hardware-specific formats, this loader does not yet parse them.

This loader parses the KTX 2.0 container and transcodes to a supported GPU compressed texture format. The required WASM transcoder and JS wrapper are available from the examples/jsm/libs/basis directory.

This loader relies on Web Assembly which is not supported in older browsers.

References:

Code Examples

const loader = new KTX2Loader();
loader.setTranscoderPath( 'examples/jsm/libs/basis/' );
loader.detectSupport( renderer );
const texture = loader.loadAsync( 'diffuse.ktx2' );
  • What it demonstrates: Typical usage of KTX2Loader.

Reference Tables

Constructor

Signature
new KTX2Loader( manager : LoadingManager )

Methods

MethodDescription
`.detectSupport( renderer : WebGPURendererWebGLRenderer ) : KTX2Loader`
.detectSupportAsync( renderer : WebGPURenderer ) : Promise (async)Async version of KTX2Loader#detectSupport.
.dispose()Frees internal resources. This method should be called when the loader is no longer required.
.load( url : string, onLoad : function, onProgress : onProgressCallback, onError : onErrorCallback )Starts loading from the given URL and passes the loaded KTX2 texture to the onLoad() callback.
.parse( buffer : ArrayBuffer, onLoad : function, onError : onErrorCallback ) : PromiseParses the given KTX2 data.
.setTranscoderPath( path : string ) : KTX2LoaderSets the transcoder path to optionally set the decoder load path from a CDN.
.setWorkerLimit( workerLimit : number ) : KTX2LoaderSets the maximum number of Web Workers to be allocated by this instance.

Key Takeaways

  1. KTX2Loader extends: Loader
  2. Key methods: detectSupport, detectSupportAsync, dispose, load.

Connects To