Popov72 5 лет назад
Родитель
Сommit
2c3f60648a

+ 1 - 1
src/Materials/Textures/Loaders/ktxTextureLoader.ts

@@ -84,7 +84,7 @@ export class _KTXTextureLoader implements IInternalTextureLoader {
         else if (KhronosTextureContainer2.IsValid(data)) {
             const ktx2 = new KhronosTextureContainer2(texture.getEngine());
             ktx2.uploadAsync(data, texture).then(() => {
-                callback(texture.width, texture.height, false, true, () => {}, false);
+                callback(texture.width, texture.height, texture.generateMipMaps, true, () => {}, false);
             }, (error) => {
                 Logger.Warn(`Failed to load KTX2 texture data: ${error.message}`);
                 callback(0, 0, false, false, () => {}, true);

+ 7 - 15
src/Misc/KTX2/khronosTextureContainer2.ts

@@ -121,28 +121,20 @@ export class KhronosTextureContainer2 {
 
             if (data.transcodedFormat === 0x8058 /* RGBA8 */) {
                 // uncompressed RGBA
-                internalTexture.width = internalTexture.baseWidth = mipmap.width;
-                internalTexture.height = internalTexture.baseHeight = mipmap.height;
-
-                internalTexture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE;
-                internalTexture.format = Constants.TEXTUREFORMAT_RGBA;
-
-                const gl = this._engine._gl;
-                //this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);
-                gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-                gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
-                gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, mipmap.width, mipmap.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, mipmap.data);
-                gl.generateMipmap(gl.TEXTURE_2D);
+                internalTexture.width = mipmap.width; // need to set width/height so that the call to _uploadDataToTextureDirectly uses the right dimensions
+                internalTexture.height = mipmap.height;
+
+                this._engine._uploadDataToTextureDirectly(internalTexture, mipmap.data, 0, t, undefined, true);
             } else {
                 this._engine._uploadCompressedDataToTextureDirectly(internalTexture, data.transcodedFormat, mipmap.width, mipmap.height, mipmap.data, 0, t);
             }
         }
 
+        internalTexture.width = data.mipmaps[0].width;
+        internalTexture.height = data.mipmaps[0].height;
+        internalTexture.generateMipMaps = data.mipmaps.length > 1;
         internalTexture.isReady = true;
 
-        internalTexture.width = internalTexture.baseWidth = data.width;
-        internalTexture.height = internalTexture.baseHeight = data.height;
-
         this._engine._bindTextureDirectly(this._engine._gl.TEXTURE_2D, null);
     }