Bläddra i källkod

Add createCubeTexture for WebGPU

Popov72 5 år sedan
förälder
incheckning
4b3bb55faf

+ 44 - 21
src/Engines/Extensions/engine.cubeTexture.ts

@@ -75,16 +75,22 @@ declare module "../../Engines/thinEngine" {
             format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number): InternalTexture;
 
         /** @hidden */
+        createCubeTextureBase(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean,
+            onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
+            format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number, fallback: Nullable<InternalTexture>,
+            beforeLoadCubeDataCallback: Nullable<(texture: InternalTexture, data: ArrayBufferView | ArrayBufferView[]) => void>, imageHandler: Nullable<(texture: InternalTexture, imgs: HTMLImageElement[]) => void>): InternalTexture;
+
+        /** @hidden */
         _partialLoadFile(url: string, index: number, loadedFiles: ArrayBuffer[], onfinish: (files: ArrayBuffer[]) => void, onErrorCallBack: Nullable<(message?: string, exception?: any) => void>): void;
 
         /** @hidden */
         _cascadeLoadFiles(scene: Nullable<Scene>, onfinish: (images: ArrayBuffer[]) => void, files: string[], onError: Nullable<(message?: string, exception?: any) => void>): void;
 
         /** @hidden */
-        _cascadeLoadImgs(scene: Nullable<Scene>, onfinish: (images: HTMLImageElement[]) => void, files: string[], onError: Nullable<(message?: string, exception?: any) => void>, mimeType?: string): void;
+        _cascadeLoadImgs(scene: Nullable<Scene>, texture: InternalTexture, onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[]) => void>, files: string[], onError: Nullable<(message?: string, exception?: any) => void>, mimeType?: string): void;
 
         /** @hidden */
-        _partialLoadImg(url: string, index: number, loadedImages: HTMLImageElement[], scene: Nullable<Scene>, onfinish: (images: HTMLImageElement[]) => void, onErrorCallBack: Nullable<(message?: string, exception?: any) => void>, mimeType?: string): void;
+        _partialLoadImg(url: string, index: number, loadedImages: HTMLImageElement[], scene: Nullable<Scene>, texture: InternalTexture, onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[]) => void>, onErrorCallBack: Nullable<(message?: string, exception?: any) => void>, mimeType?: string): void;
 
         /**
          * @hidden
@@ -158,19 +164,19 @@ ThinEngine.prototype._cascadeLoadFiles = function(scene: Nullable<Scene>, onfini
     }
 };
 
-ThinEngine.prototype._cascadeLoadImgs = function(scene: Nullable<Scene>,
-    onfinish: (images: HTMLImageElement[]) => void, files: string[], onError: Nullable<(message?: string, exception?: any) => void> = null, mimeType?: string) {
+ThinEngine.prototype._cascadeLoadImgs = function(scene: Nullable<Scene>, texture: InternalTexture, 
+    onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[]) => void>, files: string[], onError: Nullable<(message?: string, exception?: any) => void> = null, mimeType?: string) {
 
     var loadedImages: HTMLImageElement[] = [];
     (<any>loadedImages)._internalCount = 0;
 
     for (let index = 0; index < 6; index++) {
-        this._partialLoadImg(files[index], index, loadedImages, scene, onfinish, onError, mimeType);
+        this._partialLoadImg(files[index], index, loadedImages, scene, texture, onfinish, onError, mimeType);
     }
 };
 
-ThinEngine.prototype._partialLoadImg = function(url: string, index: number, loadedImages: HTMLImageElement[], scene: Nullable<Scene>,
-    onfinish: (images: HTMLImageElement[]) => void, onErrorCallBack: Nullable<(message?: string, exception?: any) => void> = null, mimeType?: string) {
+ThinEngine.prototype._partialLoadImg = function(url: string, index: number, loadedImages: HTMLImageElement[], scene: Nullable<Scene>, texture: InternalTexture,
+    onfinish: Nullable<(texture: InternalTexture, images: HTMLImageElement[]) => void>, onErrorCallBack: Nullable<(message?: string, exception?: any) => void> = null, mimeType?: string) {
 
     var img: Nullable<HTMLImageElement>;
 
@@ -184,8 +190,8 @@ ThinEngine.prototype._partialLoadImg = function(url: string, index: number, load
             }
         }
 
-        if ((<any>loadedImages)._internalCount === 6) {
-            onfinish(loadedImages);
+        if ((<any>loadedImages)._internalCount === 6 && onfinish) {
+            onfinish(texture, loadedImages);
         }
     };
 
@@ -215,9 +221,10 @@ ThinEngine.prototype._setCubeMapTextureParams = function(loadMipmap: boolean): v
     this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
 };
 
-ThinEngine.prototype.createCubeTexture = function(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap?: boolean, onLoad: Nullable<(data?: any) => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, format?: number, forcedExtension: any = null, createPolynomials: boolean = false, lodScale: number = 0, lodOffset: number = 0, fallback: Nullable<InternalTexture> = null): InternalTexture {
-    const gl = this._gl;
-
+ThinEngine.prototype.createCubeTextureBase = function(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap?: boolean, onLoad: Nullable<(data?: any) => void> = null,
+        onError: Nullable<(message?: string, exception?: any) => void> = null, format?: number, forcedExtension: any = null, createPolynomials: boolean = false, lodScale: number = 0, lodOffset: number = 0,
+        fallback: Nullable<InternalTexture> = null, beforeLoadCubeDataCallback: Nullable<(texture: InternalTexture, data: ArrayBufferView | ArrayBufferView[]) => void> = null,
+        imageHandler: Nullable<(texture: InternalTexture, imgs: HTMLImageElement[]) => void> = null): InternalTexture {
     const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);
     texture.isCube = true;
     texture.url = rootUrl;
@@ -255,13 +262,15 @@ ThinEngine.prototype.createCubeTexture = function(rootUrl: string, scene: Nullab
         else {
             // fall back to the original url if the transformed url fails to load
             Logger.Warn(`Failed to load ${rootUrl}, falling back to the ${originalRootUrl}`);
-            this.createCubeTexture(originalRootUrl, scene, files, noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, texture);
+            this.createCubeTextureBase(originalRootUrl, scene, files, !!noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, texture, beforeLoadCubeDataCallback, imageHandler);
         }
     };
 
     if (loader) {
         const onloaddata = (data: ArrayBufferView | ArrayBufferView[]) => {
-            this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
+            if (beforeLoadCubeDataCallback) {
+                beforeLoadCubeDataCallback(texture, data);
+            }
             loader!.loadCubeData(data, texture, createPolynomials, onLoad, onError);
         };
         if (files && files.length === 6) {
@@ -285,7 +294,25 @@ ThinEngine.prototype.createCubeTexture = function(rootUrl: string, scene: Nullab
             throw new Error("Cannot load cubemap because files were not defined");
         }
 
-        this._cascadeLoadImgs(scene, (imgs) => {
+        this._cascadeLoadImgs(scene, texture, (texture: InternalTexture, imgs: HTMLImageElement[]) => {
+            if (imageHandler) {
+                imageHandler(texture, imgs);
+            }
+        }, files, onError);
+    }
+
+    this._internalTexturesCache.push(texture);
+
+    return texture;
+};
+
+ThinEngine.prototype.createCubeTexture = function(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap?: boolean, onLoad: Nullable<(data?: any) => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, format?: number, forcedExtension: any = null, createPolynomials: boolean = false, lodScale: number = 0, lodOffset: number = 0, fallback: Nullable<InternalTexture> = null): InternalTexture {
+    const gl = this._gl;
+
+    return this.createCubeTextureBase(
+        rootUrl, scene, files, !!noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, fallback,
+        (texture: InternalTexture, data: ArrayBufferView | ArrayBufferView[]) => this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true),
+        (texture: InternalTexture, imgs: HTMLImageElement[]) => {
             const width = this.needPOTTextures ? ThinEngine.GetExponentOfTwo(imgs[0].width, this._caps.maxCubemapTextureSize) : imgs[0].width;
             const height = width;
 
@@ -336,10 +363,6 @@ ThinEngine.prototype.createCubeTexture = function(rootUrl: string, scene: Nullab
             if (onLoad) {
                 onLoad();
             }
-        }, files, onError);
-    }
-
-    this._internalTexturesCache.push(texture);
-
-    return texture;
+        }
+    );
 };

+ 2 - 2
src/Engines/WebGPU/webgpuPipelineContext.ts

@@ -419,10 +419,10 @@ export class WebGPUPipelineContext implements IPipelineContext {
     }
 
     public _getVertexShaderCode(): string | null {
-        return this.sources.vertex;
+        return this.sources?.vertex ?? "<vertex shader code not available>";
     }
 
     public _getFragmentShaderCode(): string | null {
-        return this.sources.fragment;
+        return this.sources?.fragment ?? "<fragment shader code not available>";
     }
 }

+ 106 - 27
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -82,44 +82,23 @@ export class GPUTextureHelper {
         });
     }
 
-    async generateTexture(imageBitmap: ImageBitmap, invertY = false): Promise<GPUTexture> {
-       let textureSize = {
-            width: imageBitmap.width,
-            height: imageBitmap.height,
-            depth: 1,
-        };
-
-        if (invertY) {
-            imageBitmap = await createImageBitmap(imageBitmap, { imageOrientation: "flipY" });
-        }
-
-        // Populate the top level of the srcTexture with the imageBitmap.
-        const srcTexture = this.device.createTexture({
-            size: textureSize,
-            format: WebGPUConstants.TextureFormat.RGBA8Unorm,
-            usage: WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled,
-            mipLevelCount: 1
-        });
-
-        this.device.defaultQueue.copyImageBitmapToTexture({ imageBitmap }, { texture: srcTexture }, textureSize);
-
-        return srcTexture;
-    }
-
-    async generateMipmappedTexture(imageBitmap: ImageBitmap, invertY = false): Promise<GPUTexture> {
+    async generateTexture(imageBitmap: ImageBitmap, generateMipmaps = false, invertY = false): Promise<GPUTexture> {
         let textureSize = {
             width: imageBitmap.width,
             height: imageBitmap.height,
             depth: 1,
         };
 
-        const mipLevelCount = Math.floor(Scalar.Log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1;
+        const mipLevelCount = generateMipmaps ? Math.floor(Scalar.Log2(Math.max(imageBitmap.width, imageBitmap.height))) + 1 : 1;
+        const additionalUsages = generateMipmaps ? WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.OutputAttachment : 0;
 
         // Populate the top level of the srcTexture with the imageBitmap.
         const srcTexture = this.device.createTexture({
             size: textureSize,
+            dimension: WebGPUConstants.TextureDimension.E2d,
             format: WebGPUConstants.TextureFormat.RGBA8Unorm,
-            usage: WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled | WebGPUConstants.TextureUsage.OutputAttachment,
+            usage:  WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled | additionalUsages,
+            sampleCount: 1,
             mipLevelCount
         });
 
@@ -129,6 +108,10 @@ export class GPUTextureHelper {
 
         this.device.defaultQueue.copyImageBitmapToTexture({ imageBitmap }, { texture: srcTexture }, textureSize);
 
+        if (!generateMipmaps) {
+            return srcTexture;
+        }
+
         const commandEncoder = this.device.createCommandEncoder({});
 
         const bindGroupLayout = this.mipmapPipeline.getBindGroupLayout(0);
@@ -168,4 +151,100 @@ export class GPUTextureHelper {
 
         return srcTexture;
     }
+
+    async generateCubeTexture(imageBitmaps: ImageBitmap[], generateMipmaps = false, invertY = false): Promise<GPUTexture> {
+        let textureSize = {
+            width: imageBitmaps[0].width,
+            height: imageBitmaps[0].height,
+            depth: 6,
+        };
+
+        const mipLevelCount = generateMipmaps ? Math.floor(Scalar.Log2(Math.max(textureSize.width, textureSize.height))) + 1 : 1;
+        const additionalUsages = generateMipmaps ? WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.OutputAttachment : 0;
+
+        const srcTexture = this.device.createTexture({
+            size: textureSize,
+            dimension: WebGPUConstants.TextureDimension.E2d,
+            format: WebGPUConstants.TextureFormat.RGBA8Unorm,
+            usage: WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled | additionalUsages,
+            sampleCount: 1,
+            mipLevelCount
+        });
+
+        const textureSizeFace = {
+            width: imageBitmaps[0].width,
+            height: imageBitmaps[0].height,
+            depth: 1,
+        };
+
+        const textureView: GPUTextureCopyView = {
+            texture: srcTexture,
+            origin: {
+                x: 0,
+                y: 0,
+                z: 0
+            },
+            mipLevel: 0
+        };
+
+        const faces = [0, 3, 1, 4, 2, 5];
+
+        for (let f = 0; f < faces.length; ++f) {
+            let imageBitmap = imageBitmaps[faces[f]];
+
+            if (invertY) {
+                imageBitmap = await createImageBitmap(imageBitmap, { imageOrientation: "flipY" });
+            }
+
+            (textureView.origin as GPUOrigin3DDict).z = f;
+
+            this.device.defaultQueue.copyImageBitmapToTexture({ imageBitmap }, textureView, textureSizeFace);
+        }
+
+        if (generateMipmaps) {
+            const commandEncoder = this.device.createCommandEncoder({});
+
+            const bindGroupLayout = this.mipmapPipeline.getBindGroupLayout(0);
+
+            for (let i = 1; i < mipLevelCount; ++i) {
+                const passEncoder = commandEncoder.beginRenderPass({
+                    colorAttachments: [{
+                        attachment: srcTexture.createView({
+                            dimension: WebGPUConstants.TextureViewDimension.E2d,
+                            baseMipLevel: i,
+                            mipLevelCount: 1,
+                            arrayLayerCount: 1,
+                        }),
+                        loadValue: { r: 0.0, g: 0.0, b: 0.0, a: 0.0 },
+                    }],
+                });
+
+                const bindGroup = this.device.createBindGroup({
+                    layout: bindGroupLayout,
+                    entries: [{
+                        binding: 0,
+                        resource: this.mipmapSampler,
+                    }, {
+                        binding: 1,
+                        resource: srcTexture.createView({
+                            dimension: WebGPUConstants.TextureViewDimension.E2d,
+                            baseMipLevel: i - 1,
+                            mipLevelCount: 1,
+                            arrayLayerCount: 1,
+                        }),
+                    }],
+                });
+
+                passEncoder.setPipeline(this.mipmapPipeline);
+                passEncoder.setBindGroup(0, bindGroup);
+                passEncoder.draw(4, 1, 0, 0);
+                passEncoder.endPass();
+            }
+
+            this.device.defaultQueue.submit([commandEncoder.finish()]);
+        }
+
+        return srcTexture;
+    }
+
 }

+ 39 - 154
src/Engines/webgpuEngine.ts

@@ -23,6 +23,7 @@ import { WebGPUShaderProcessingContext } from "./WebGPU/webgpuShaderProcessingCo
 import { Tools } from "../Misc/tools";
 import { GPUTextureHelper } from './WebGPU/webgpuTextureHelper';
 import { ISceneLike } from './thinEngine';
+import { Scene } from '../scene';
 
 /**
  * Options to load the associated Glslang library
@@ -1072,6 +1073,7 @@ export class WebGPUEngine extends Engine {
         buffer: Nullable<string | ArrayBuffer | ArrayBufferView | HTMLImageElement | Blob | ImageBitmap> = null, fallback: Nullable<InternalTexture> = null, format: Nullable<number> = null,
         forcedExtension: Nullable<string> = null, mimeType?: string): InternalTexture {
 
+        // TODO WEBGPU. this._options.textureSize
         return this._createTextureBase(
             url, noMipmap, invertY, scene, samplingMode, onLoad, onError,
             (texture: InternalTexture, extension: string, scene: Nullable<ISceneLike>, img: HTMLImageElement | ImageBitmap | { width: number, height: number }, invertY: boolean, noMipmap: boolean, isCompressed: boolean,
@@ -1097,17 +1099,10 @@ export class WebGPUEngine extends Engine {
 
                     promise.then(async (img) => {
                         if (img) {
-                            let gpuTexture: GPUTexture;
-
                             // TODO WEBGPU: handle format if <> 0. Note that it seems "rgb" formats don't exist in WebGPU...
                             //let internalFormat = format ? this._getInternalFormat(format) : ((extension === ".jpg") ? gl.RGB : gl.RGBA);
-                            if (noMipmap) {
-                                gpuTexture = await this._gpuTextureHelper.generateTexture(img, invertY);
-                            } else {
-                                gpuTexture = await this._gpuTextureHelper.generateMipmappedTexture(img, invertY);
-                            }
-                            texture._webGPUTexture = gpuTexture;
-                            texture._webGPUTextureView = gpuTexture.createView();
+                            texture._webGPUTexture = await this._gpuTextureHelper.generateTexture(img, !noMipmap, invertY);
+                            texture._webGPUTextureView = texture._webGPUTexture.createView();
                         }
 
                         if (scene) {
@@ -1125,161 +1120,51 @@ export class WebGPUEngine extends Engine {
         );
     }
 
-    /*public createTexture(urlArg: string, noMipmap: boolean, invertY: boolean, scene: Scene, samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE, onLoad: Nullable<() => void> = null, onError: Nullable<(message: string, exception: any) => void> = null, buffer: Nullable<ArrayBuffer | HTMLImageElement> = null, fallBack?: InternalTexture, format?: number): InternalTexture {
-        const texture = new InternalTexture(this, InternalTextureSource.Url);
-        const url = String(urlArg);
-
-        // TODO WEBGPU. Find a better way.
-        // TODO WEBGPU. this._options.textureSize
-
-        texture.url = url;
-        texture.generateMipMaps = !noMipmap;
-        texture.samplingMode = samplingMode;
-        texture.invertY = invertY;
-
-        if (format) {
-            texture.format = format;
-        }
-
-        let webglEngineTexture: InternalTexture;
-        const onLoadInternal = () => {
-            texture.isReady = webglEngineTexture.isReady;
+    public createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap?: boolean, onLoad: Nullable<(data?: any) => void> = null,
+        onError: Nullable<(message?: string, exception?: any) => void> = null, format?: number, forcedExtension: any = null, createPolynomials: boolean = false, lodScale: number = 0, lodOffset: number = 0, fallback: Nullable<InternalTexture> = null): InternalTexture {
 
-            const width = webglEngineTexture.width;
-            const height = webglEngineTexture.height;
-            texture.width = width;
-            texture.height = height;
-            texture.baseWidth = width;
-            texture.baseHeight = height;
-            texture._isRGBD = texture._isRGBD || webglEngineTexture._isRGBD;
-            texture._sphericalPolynomial = webglEngineTexture._sphericalPolynomial;
+        return this.createCubeTextureBase(
+            rootUrl, scene, files, !!noMipmap, onLoad, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, fallback,
+            null,
+            (texture: InternalTexture, imgs: HTMLImageElement[]) => {
+                const width = imgs[0].width;
+                const height = width;
 
-            let mipMaps = Scalar.Log2(Math.max(width, height));
-            mipMaps = Math.floor(mipMaps);
+                // TODO WEBGPU. Cube Texture Sampling Mode.
+                texture.samplingMode = noMipmap ? Constants.TEXTURE_BILINEAR_SAMPLINGMODE : Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;
 
-            const textureExtent = {
-                width,
-                height,
-                depth: 1
-            };
-            const textureDescriptor: GPUTextureDescriptor = {
-                dimension: WebGPUConstants.TextureDimension.E2d,
-                format: WebGPUConstants.TextureFormat.RGBA8Unorm,
-                mipLevelCount: noMipmap ? 1 : mipMaps + 1,
-                sampleCount: 1,
-                size: textureExtent,
-                usage: WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled
-            };
-
-            const gpuTexture = this._device.createTexture(textureDescriptor);
-            texture._webGPUTexture = gpuTexture;
-
-            if (noMipmap) {
-                this._uploadFromWebglTexture(webglEngineTexture, gpuTexture, width, height, -1);
-            }
-            else {
-                this._uploadMipMapsFromWebglTexture(mipMaps, webglEngineTexture, gpuTexture, width, height, -1);
-            }
-
-            texture._webGPUTextureView = gpuTexture.createView();
-
-            webglEngineTexture.dispose();
-
-            texture.onLoadedObservable.notifyObservers(texture);
-            texture.onLoadedObservable.clear();
-
-            if (onLoad) {
-                onLoad();
-            }
-        };
+                // TODO WEBGPU. handle format if <> 0
+                //const internalFormat = format ? this._getInternalFormat(format) : this._gl.RGBA;
+                const imageBitmapPromises: Array<Promise<ImageBitmap>> = [];
 
-        webglEngineTexture = this._decodeEngine.createTexture(urlArg, noMipmap, invertY, scene, samplingMode,
-            onLoadInternal, onError, buffer, fallBack, format);
+                for (var index = 0; index < 6; index++) {
+                    imageBitmapPromises.push(createImageBitmap(imgs[index]));
+                }
 
-        this._internalTexturesCache.push(texture);
+                Promise.all(imageBitmapPromises).then(async (imageBitmaps) => {
+                    texture._webGPUTexture = await this._gpuTextureHelper.generateCubeTexture(imageBitmaps, !noMipmap);
+                    texture._webGPUTextureView = texture._webGPUTexture.createView({
+                        dimension: WebGPUConstants.TextureViewDimension.Cube
+                    });
 
-        return texture;
-    }*/
-/*
-    public createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap?: boolean, onLoad: Nullable<(data?: any) => void> = null, onError: Nullable<(message?: string, exception?: any) => void> = null, format?: number, forcedExtension: any = null, createPolynomials: boolean = false, lodScale: number = 0, lodOffset: number = 0, fallback: Nullable<InternalTexture> = null): InternalTexture {
-        var texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);
-        texture.isCube = true;
-        texture.url = rootUrl;
-        texture.generateMipMaps = !noMipmap;
-        // TODO WEBGPU. Cube Texture Sampling Mode.
-        texture.samplingMode = noMipmap ? Constants.TEXTURE_BILINEAR_SAMPLINGMODE : Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;
-        texture._lodGenerationScale = lodScale;
-        texture._lodGenerationOffset = lodOffset;
-
-        if (!this._doNotHandleContextLost) {
-            texture._extension = forcedExtension;
-            texture._files = files;
-        }
-
-        let webglEngineTexture: InternalTexture;
-        const onLoadInternal = () => {
-            texture.isReady = webglEngineTexture.isReady;
-
-            const width = webglEngineTexture.width;
-            const height = webglEngineTexture.height;
-            const depth = 1;
-            texture.width = width;
-            texture.height = height;
-            texture.baseWidth = width;
-            texture.baseHeight = height;
-            texture.depth = depth;
-            texture.baseDepth = depth;
-            texture._isRGBD = texture._isRGBD || webglEngineTexture._isRGBD;
-            texture._sphericalPolynomial = webglEngineTexture._sphericalPolynomial;
-
-            let mipMaps = Scalar.Log2(width);
-            mipMaps = Math.round(mipMaps);
-
-            const textureExtent = {
-                width,
-                height,
-                depth: depth * 6,
-            };
-            const textureDescriptor: GPUTextureDescriptor = {
-                dimension: WebGPUConstants.TextureDimension.E2d,
-                format: WebGPUConstants.TextureFormat.RGBA8Unorm,
-                mipLevelCount: noMipmap ? 1 : mipMaps + 1,
-                sampleCount: 1,
-                size: textureExtent,
-                usage: WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.Sampled
-            };
+                    texture.width = width;
+                    texture.height = height;
+                    texture.isReady = true;
+                    if (format) {
+                        texture.format = format;
+                    }
 
-            const gpuTexture = this._device.createTexture(textureDescriptor);
-            texture._webGPUTexture = gpuTexture;
+                    texture.onLoadedObservable.notifyObservers(texture);
+                    texture.onLoadedObservable.clear();
 
-            const faces = [0, 1, 2, 3, 4, 5];
-            for (let face of faces) {
-                if (noMipmap) {
-                    this._uploadFromWebglTexture(webglEngineTexture, gpuTexture, width, height, face);
-                }
-                else {
-                    this._uploadMipMapsFromWebglTexture(mipMaps, webglEngineTexture, gpuTexture, width, height, face);
-                }
+                    if (onLoad) {
+                        onLoad();
+                    }
+                });
             }
-            texture._webGPUTextureView = gpuTexture.createView({
-                dimension: WebGPUConstants.TextureViewDimension.Cube,
-                format: WebGPUConstants.TextureFormat.RGBA8Unorm,
-                mipLevelCount: noMipmap ? 1 : mipMaps + 1,
-                baseArrayLayer: 0,
-                baseMipLevel: 0,
-                aspect: WebGPUConstants.TextureAspect.All
-            } as any);
-            webglEngineTexture.dispose();
-
-            onLoad && onLoad();
-        };
-        webglEngineTexture = this._decodeEngine.createCubeTexture(rootUrl, scene, files, noMipmap, onLoadInternal, onError, format, forcedExtension, createPolynomials, lodScale, lodOffset, fallback);
-
-        this._internalTexturesCache.push(texture);
-
-        return texture;
+        );
     }
-*/
+
     public updateTextureSamplingMode(samplingMode: number, texture: InternalTexture): void {
         texture.samplingMode = samplingMode;
     }