|
@@ -286,7 +286,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;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -722,9 +746,12 @@ 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 ) {
|
|
|
|
|
@@ -732,7 +759,7 @@ async function createDataTexture( container ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- const level = container.levels[ 0 ];
|
|
|
+ const level = container.levels[ levelIndex ];
|
|
|
|
|
|
let levelData;
|
|
|
let view;
|