Skip to content

Commit

Permalink
KTX2Exporter: Add support for WebGPURenderer. (#29308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Sep 4, 2024
1 parent 7c5ac38 commit 3b84981
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions examples/jsm/exporters/KTX2Exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ const ERROR_COLOR_SPACE = 'THREE.KTX2Exporter: Supported color spaces are SRGBCo

export class KTX2Exporter {

parse( arg1, arg2 ) {
async parse( arg1, arg2 ) {

let texture;

if ( arg1.isDataTexture || arg1.isData3DTexture ) {

texture = arg1;

} else if ( arg1.isWebGLRenderer && arg2.isWebGLRenderTarget ) {
} else if ( ( arg1.isWebGLRenderer || arg1.isWebGPURenderer ) && arg2.isRenderTarget ) {

texture = toDataTexture( arg1, arg2 );
texture = await toDataTexture( arg1, arg2 );

} else {

Expand Down Expand Up @@ -235,32 +235,40 @@ export class KTX2Exporter {

}

function toDataTexture( renderer, rtt ) {
async function toDataTexture( renderer, rtt ) {

const channelCount = getChannelCount( rtt.texture );

let view;

if ( rtt.texture.type === FloatType ) {
if ( renderer.isWebGLRenderer ) {

view = new Float32Array( rtt.width * rtt.height * channelCount );
if ( rtt.texture.type === FloatType ) {

} else if ( rtt.texture.type === HalfFloatType ) {
view = new Float32Array( rtt.width * rtt.height * channelCount );

view = new Uint16Array( rtt.width * rtt.height * channelCount );
} else if ( rtt.texture.type === HalfFloatType ) {

} else if ( rtt.texture.type === UnsignedByteType ) {
view = new Uint16Array( rtt.width * rtt.height * channelCount );

view = new Uint8Array( rtt.width * rtt.height * channelCount );
} else if ( rtt.texture.type === UnsignedByteType ) {

view = new Uint8Array( rtt.width * rtt.height * channelCount );

} else {

throw new Error( ERROR_TYPE );

}

renderer.readRenderTargetPixels( rtt, 0, 0, rtt.width, rtt.height, view );

} else {

throw new Error( ERROR_TYPE );
view = await renderer.readRenderTargetPixelsAsync( rtt, 0, 0, rtt.width, rtt.height );

}

renderer.readRenderTargetPixels( rtt, 0, 0, rtt.width, rtt.height, view );

return new DataTexture( view, rtt.width, rtt.height, rtt.texture.format, rtt.texture.type );

}
Expand Down

0 comments on commit 3b84981

Please sign in to comment.