Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions examples/jsm/loaders/KTX2Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,31 @@ class KTX2Loader extends Loader {

if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {

return createDataTexture( container );
const mipmaps = [];
const pendings = [];

for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) {

pendings.push( createDataTexture( container, levelIndex ).then( function ( dataTexture ) {

mipmaps[ levelIndex ] = dataTexture;

} ) );

}

await Promise.all( pendings );

const texture = mipmaps[ 0 ];
texture.mipmaps = mipmaps.map( dt => {
return {
data: dt.source.data,
width: dt.source.data.width,
height: dt.source.data.height,
depth: dt.source.data.depth
};
} );
return texture;

}

Expand Down Expand Up @@ -706,17 +730,20 @@ const COLOR_SPACE_MAP = {

};

async function createDataTexture( container ) {
async function createDataTexture( container, levelIndex = 0 ) {

const { vkFormat, pixelWidth, pixelHeight, pixelDepth } = container;
const { vkFormat } = container;
const pixelWidth = Math.max( 1, container.pixelWidth >> levelIndex );
const pixelHeight = Math.max( 1, container.pixelHeight >> levelIndex );
const pixelDepth = Math.max( 1, container.pixelDepth >> levelIndex );

if ( FORMAT_MAP[ vkFormat ] === undefined ) {

throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );

}

const level = container.levels[ 0 ];
const level = container.levels[ levelIndex ];

let levelData;
let view;
Expand Down