Browse Source

Fix dds loading

Popov72 4 years ago
parent
commit
0c686fca69
3 changed files with 11 additions and 17 deletions
  1. 1 0
      src/Engines/WebGPU/webgpuTextureHelper.ts
  2. 7 17
      src/Engines/webgpuEngine.ts
  3. 3 0
      src/Misc/dds.ts

+ 1 - 0
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -305,6 +305,7 @@ export class WebGPUTextureHelper {
         };
 
         if ((imageBitmap as Uint8Array).byteLength !== undefined) {
+            // TODO WEBGPU handle invertY / premultiplyAlpha
             imageBitmap = imageBitmap as Uint8Array;
 
             const aligned = Math.ceil(width * 4 / 256) * 256 === width * 4;

+ 7 - 17
src/Engines/webgpuEngine.ts

@@ -364,10 +364,10 @@ export class WebGPUEngine extends Engine {
             fragmentDepthSupported: false,
             highPrecisionShaderSupported: true,
             colorBufferFloat: false,
-            textureFloat: false,
+            textureFloat: true,
             textureFloatLinearFiltering: false,
             textureFloatRender: false,
-            textureHalfFloat: false,
+            textureHalfFloat: true,
             textureHalfFloatLinearFiltering: false,
             textureHalfFloatRender: false,
             textureLOD: true,
@@ -1267,6 +1267,8 @@ export class WebGPUEngine extends Engine {
                     texture.height = imageBitmap.height;
                     texture.format = format ?? -1;
 
+                    processFunction(texture.width, texture.height, imageBitmap, extension, texture, () => {});
+
                     if (!texture._hardwareTexture?.underlyingResource) { // the texture could have been created before reaching this point so don't recreate it if already existing
                         const gpuTextureWrapper = this._createGPUTextureForInternalTexture(texture, imageBitmap.width, imageBitmap.height);
 
@@ -1284,8 +1286,6 @@ export class WebGPUEngine extends Engine {
                         scene._removePendingData(texture);
                     }
 
-                    processFunction(texture.width, texture.height, imageBitmap, extension, texture, () => {});
-
                     texture.isReady = true;
 
                     texture.onLoadedObservable.notifyObservers(texture);
@@ -1535,12 +1535,7 @@ export class WebGPUEngine extends Engine {
             gpuTextureWrapper = this._createGPUTextureForInternalTexture(texture);
         }
 
-        const imgData = new ImageData(new Uint8ClampedArray(imageData.buffer), width, height);
-
-        // TODO WEBGPU directly pass the Uint8ClampedArray? invertY needs to be handled by updateTexture...
-        createImageBitmap(imgData).then((bitmap) => {
-            this._textureHelper.updateTexture(bitmap, gpuTextureWrapper?.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, xOffset, yOffset, this._uploadEncoder);
-        });
+        this._textureHelper.updateTexture(new Uint8Array(imageData.buffer, imageData.byteOffset, imageData.byteLength), gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, 0, 0, this._uploadEncoder);
     }
 
     public updateVideoTexture(texture: Nullable<InternalTexture>, video: HTMLVideoElement, invertY: boolean): void {
@@ -1581,7 +1576,7 @@ export class WebGPUEngine extends Engine {
             gpuTextureWrapper = this._createGPUTextureForInternalTexture(texture, width, height);
         }
 
-        this._textureHelper.updateTexture(new Uint8Array(data.buffer), gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, 0, 0, this._uploadEncoder);
+        this._textureHelper.updateTexture(new Uint8Array(data.buffer, data.byteOffset, data.byteLength), gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, 0, 0, this._uploadEncoder);
     }
 
     /** @hidden */
@@ -1599,12 +1594,7 @@ export class WebGPUEngine extends Engine {
             gpuTextureWrapper = this._createGPUTextureForInternalTexture(texture, width, height);
         }
 
-        const imgData = new ImageData(new Uint8ClampedArray(imageData.buffer, 0, imageData.byteLength), width, height);
-
-        // TODO WEBGPU don't convert to image bitmap and directly pass the Uint8ClampedArray? updateTexture needs to handle invertY...
-        createImageBitmap(imgData).then((bitmap) => {
-            this._textureHelper.updateTexture(bitmap, gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, 0, 0, this._uploadEncoder);
-        });
+        this._textureHelper.updateTexture(new Uint8Array(imageData.buffer, imageData.byteOffset, imageData.byteLength), gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, 0, 0, this._uploadEncoder);
     }
 
     /** @hidden */

+ 3 - 0
src/Misc/dds.ts

@@ -452,6 +452,9 @@ export class DDSTools {
         }
         var ext = !!engine.getCaps().s3tc;
 
+        // TODO WEBGPU Once generateMipMaps is split into generateMipMaps + hasMipMaps in InternalTexture this line can be removed
+        texture.generateMipMaps = loadMipmaps;
+
         var header = new Int32Array(data.buffer, data.byteOffset, headerLengthInt);
         var fourCC: number, width: number, height: number, dataLength: number = 0, dataOffset: number;
         var byteArray: Uint8Array, mipmapCount: number, mip: number;