浏览代码

Merge pull request #7787 from sebavan/master

Revert "Merge pull request #7786 from bghgary/texture-select"
sebavan 5 年之前
父节点
当前提交
4767f1399e

+ 0 - 1
dist/preview release/what's new.md

@@ -15,7 +15,6 @@
 ### Engine
 ### Engine
 
 
 - Allow logging of shader code when a compilation error occurs ([Popov72](https://github.com/Popov72))
 - Allow logging of shader code when a compilation error occurs ([Popov72](https://github.com/Popov72))
-- Add back support for selecting textures based on engine capabilities ([bghgary](https://github.com/bghgary))
 
 
 ### Inspector
 ### Inspector
 
 

+ 11 - 15
src/Engines/Extensions/engine.cubeTexture.ts

@@ -21,7 +21,7 @@ declare module "../../Engines/thinEngine" {
 
 
         /**
         /**
          * Creates a cube texture
          * Creates a cube texture
-         * @param url defines the url where the files to load is located
+         * @param rootUrl defines the url where the files to load is located
          * @param scene defines the current scene
          * @param scene defines the current scene
          * @param files defines the list of files to load (1 per face)
          * @param files defines the list of files to load (1 per face)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
@@ -35,13 +35,13 @@ declare module "../../Engines/thinEngine" {
          * @param fallback defines texture to use while falling back when (compressed) texture file not found.
          * @param fallback defines texture to use while falling back when (compressed) texture file not found.
          * @returns the cube texture as an InternalTexture
          * @returns the cube texture as an InternalTexture
          */
          */
-        createCubeTexture(url: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean | undefined,
+        createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean | undefined,
             onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
             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>): InternalTexture;
             format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number, fallback: Nullable<InternalTexture>): InternalTexture;
 
 
         /**
         /**
          * Creates a cube texture
          * Creates a cube texture
-         * @param url defines the url where the files to load is located
+         * @param rootUrl defines the url where the files to load is located
          * @param scene defines the current scene
          * @param scene defines the current scene
          * @param files defines the list of files to load (1 per face)
          * @param files defines the list of files to load (1 per face)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
@@ -51,13 +51,13 @@ declare module "../../Engines/thinEngine" {
          * @param forcedExtension defines the extension to use to pick the right loader
          * @param forcedExtension defines the extension to use to pick the right loader
          * @returns the cube texture as an InternalTexture
          * @returns the cube texture as an InternalTexture
          */
          */
-        createCubeTexture(url: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean,
+        createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean,
             onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
             onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
             format: number | undefined, forcedExtension: any): InternalTexture;
             format: number | undefined, forcedExtension: any): InternalTexture;
 
 
         /**
         /**
          * Creates a cube texture
          * Creates a cube texture
-         * @param url defines the url where the files to load is located
+         * @param rootUrl defines the url where the files to load is located
          * @param scene defines the current scene
          * @param scene defines the current scene
          * @param files defines the list of files to load (1 per face)
          * @param files defines the list of files to load (1 per face)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
          * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
@@ -70,7 +70,7 @@ declare module "../../Engines/thinEngine" {
          * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
          * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
          * @returns the cube texture as an InternalTexture
          * @returns the cube texture as an InternalTexture
          */
          */
-        createCubeTexture(url: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean,
+        createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean,
             onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
             onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>,
             format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number): InternalTexture;
             format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number): InternalTexture;
 
 
@@ -215,12 +215,12 @@ ThinEngine.prototype._setCubeMapTextureParams = function(loadMipmap: boolean): v
     this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
     this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
 };
 };
 
 
-ThinEngine.prototype.createCubeTexture = function(url: 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 {
+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 {
     var gl = this._gl;
     var gl = this._gl;
 
 
     var texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);
     var texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube);
     texture.isCube = true;
     texture.isCube = true;
-    texture.url = url;
+    texture.url = rootUrl;
     texture.generateMipMaps = !noMipmap;
     texture.generateMipMaps = !noMipmap;
     texture._lodGenerationScale = lodScale;
     texture._lodGenerationScale = lodScale;
     texture._lodGenerationOffset = lodOffset;
     texture._lodGenerationOffset = lodOffset;
@@ -230,12 +230,8 @@ ThinEngine.prototype.createCubeTexture = function(url: string, scene: Nullable<S
         texture._files = files;
         texture._files = files;
     }
     }
 
 
-    if (this._transformTextureUrl) {
-        url = this._transformTextureUrl(url);
-    }
-
-    var lastDot = url.lastIndexOf('.');
-    var extension = forcedExtension ? forcedExtension : (lastDot > -1 ? url.substring(lastDot).toLowerCase() : "");
+    var lastDot = rootUrl.lastIndexOf('.');
+    var extension = forcedExtension ? forcedExtension : (lastDot > -1 ? rootUrl.substring(lastDot).toLowerCase() : "");
 
 
     let loader: Nullable<IInternalTextureLoader> = null;
     let loader: Nullable<IInternalTextureLoader> = null;
     for (let availableLoader of ThinEngine._TextureLoaders) {
     for (let availableLoader of ThinEngine._TextureLoaders) {
@@ -269,7 +265,7 @@ ThinEngine.prototype.createCubeTexture = function(url: string, scene: Nullable<S
             }
             }
         }
         }
         else {
         else {
-            this._loadFile(url, (data) => onloaddata(new Uint8Array(data as ArrayBuffer)), undefined, undefined, true, onInternalError);
+            this._loadFile(rootUrl, (data) => onloaddata(new Uint8Array(data as ArrayBuffer)), undefined, undefined, true, onInternalError);
         }
         }
     }
     }
     else {
     else {

+ 0 - 114
src/Engines/Extensions/engine.textureSelector.ts

@@ -1,114 +0,0 @@
-import { Nullable } from '../../types';
-import { Engine } from '../engine';
-
-declare module "../../Engines/engine" {
-    export interface Engine {
-        /** @hidden */
-        _excludedCompressedTextures: string[];
-
-        /** @hidden */
-        _textureFormatInUse: string;
-
-        /**
-         * Gets the list of texture formats supported
-         */
-        readonly texturesSupported: Array<string>;
-
-        /**
-         * Gets the texture format in use
-         */
-        readonly textureFormatInUse: Nullable<string>;
-
-        /**
-         * Set the compressed texture extensions or file names to skip.
-         *
-         * @param skippedFiles defines the list of those texture files you want to skip
-         * Example: [".dds", ".env", "myfile.png"]
-         */
-        setCompressedTextureExclusions(skippedFiles: Array<string>): void;
-
-        /**
-         * Set the compressed texture format to use, based on the formats you have, and the formats
-         * supported by the hardware / browser.
-         *
-         * Khronos Texture Container (.ktx) files are used to support this.  This format has the
-         * advantage of being specifically designed for OpenGL.  Header elements directly correspond
-         * to API arguments needed to compressed textures.  This puts the burden on the container
-         * generator to house the arcane code for determining these for current & future formats.
-         *
-         * for description see https://www.khronos.org/opengles/sdk/tools/KTX/
-         * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
-         *
-         * Note: The result of this call is not taken into account when a texture is base64.
-         *
-         * @param formatsAvailable defines the list of those format families you have created
-         * on your server.  Syntax: '-' + format family + '.ktx'.  (Case and order do not matter.)
-         *
-         * Current families are astc, dxt, pvrtc, etc2, & etc1.
-         * @returns The extension selected.
-         */
-        setTextureFormatToUse(formatsAvailable: Array<string>): Nullable<string>;
-    }
-}
-
-function transformTextureUrl(this: Engine, url: string): string {
-    const excludeFn = (entry: string) => {
-        const strRegExPattern: string = '\\b' + entry + '\\b';
-        return (url && (url === entry || url.match(new RegExp(strRegExPattern, 'g'))));
-    };
-
-    if (this._excludedCompressedTextures && this._excludedCompressedTextures.some(excludeFn)) {
-        return url;
-    }
-
-    const lastDot = url.lastIndexOf('.');
-    return (lastDot > -1 ? url.substring(0, lastDot) : url) + this._textureFormatInUse;
-}
-
-Object.defineProperty(Engine.prototype, "texturesSupported", {
-    get: function(this: Engine) {
-        // Intelligently add supported compressed formats in order to check for.
-        // Check for ASTC support first as it is most powerful and to be very cross platform.
-        // Next PVRTC & DXT, which are probably superior to ETC1/2.
-        // Likely no hardware which supports both PVR & DXT, so order matters little.
-        // ETC2 is newer and handles ETC1 (no alpha capability), so check for first.
-        const texturesSupported = new Array<string>();
-        if (this._caps.astc) { texturesSupported.push('-astc.ktx'); }
-        if (this._caps.s3tc) { texturesSupported.push('-dxt.ktx'); }
-        if (this._caps.pvrtc) { texturesSupported.push('-pvrtc.ktx'); }
-        if (this._caps.etc2) { texturesSupported.push('-etc2.ktx'); }
-        if (this._caps.etc1) { texturesSupported.push('-etc1.ktx'); }
-        return texturesSupported;
-    },
-    enumerable: true,
-    configurable: true
-});
-
-Object.defineProperty(Engine.prototype, "textureFormatInUse", {
-    get: function(this: Engine) {
-        return this._textureFormatInUse || null;
-    },
-    enumerable: true,
-    configurable: true
-});
-
-Engine.prototype.setCompressedTextureExclusions = function(skippedFiles: Array<string>): void {
-    this._excludedCompressedTextures = skippedFiles;
-};
-
-Engine.prototype.setTextureFormatToUse = function(formatsAvailable: Array<string>): Nullable<string> {
-    const texturesSupported = this.texturesSupported;
-    for (let i = 0, len1 = texturesSupported.length; i < len1; i++) {
-        for (let j = 0, len2 = formatsAvailable.length; j < len2; j++) {
-            if (texturesSupported[i] === formatsAvailable[j].toLowerCase()) {
-                this._transformTextureUrl = transformTextureUrl.bind(this);
-                return this._textureFormatInUse = texturesSupported[i];
-            }
-        }
-    }
-    // actively set format to nothing, to allow this to be called more than once
-    // and possibly fail the 2nd time
-    delete this._textureFormatInUse;
-    delete this._transformTextureUrl;
-    return null;
-};

+ 1 - 2
src/Engines/Extensions/index.ts

@@ -11,5 +11,4 @@ export * from "./engine.renderTarget";
 export * from "./engine.renderTargetCube";
 export * from "./engine.renderTargetCube";
 export * from "./engine.webVR";
 export * from "./engine.webVR";
 export * from "./engine.uniformBuffer";
 export * from "./engine.uniformBuffer";
-export * from "./engine.views";
-export * from "./engine.textureSelector";
+export * from "./engine.views";

+ 30 - 6
src/Engines/thinEngine.ts

@@ -380,8 +380,11 @@ export class ThinEngine {
 
 
     private _activeRequests = new Array<IFileRequest>();
     private _activeRequests = new Array<IFileRequest>();
 
 
+    // Hardware supported Compressed Textures
+    protected _texturesSupported = new Array<string>();
+
     /** @hidden */
     /** @hidden */
-    public _transformTextureUrl: (url: string) => string;
+    public _textureFormatInUse: Nullable<string>;
 
 
     protected get _supportsHardwareTextureRescaling() {
     protected get _supportsHardwareTextureRescaling() {
         return false;
         return false;
@@ -399,6 +402,20 @@ export class ThinEngine {
     }
     }
 
 
     /**
     /**
+     * Gets the list of texture formats supported
+     */
+    public get texturesSupported(): Array<string> {
+        return this._texturesSupported;
+    }
+
+    /**
+     * Gets the list of texture formats in use
+     */
+    public get textureFormatInUse(): Nullable<string> {
+        return this._textureFormatInUse;
+    }
+
+    /**
      * Gets the current viewport
      * Gets the current viewport
      */
      */
     public get currentViewport(): Nullable<IViewportLike> {
     public get currentViewport(): Nullable<IViewportLike> {
@@ -713,7 +730,7 @@ export class ThinEngine {
         }
         }
     }
     }
 
 
-    protected _initGLContext(): void {
+    private _initGLContext(): void {
         // Caps
         // Caps
         this._caps = {
         this._caps = {
             maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),
             maxTexturesImageUnits: this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),
@@ -869,6 +886,17 @@ export class ThinEngine {
             }
             }
         }
         }
 
 
+        // Intelligently add supported compressed formats in order to check for.
+        // Check for ASTC support first as it is most powerful and to be very cross platform.
+        // Next PVRTC & DXT, which are probably superior to ETC1/2.
+        // Likely no hardware which supports both PVR & DXT, so order matters little.
+        // ETC2 is newer and handles ETC1 (no alpha capability), so check for first.
+        if (this._caps.astc) { this.texturesSupported.push('-astc.ktx'); }
+        if (this._caps.s3tc) { this.texturesSupported.push('-dxt.ktx'); }
+        if (this._caps.pvrtc) { this.texturesSupported.push('-pvrtc.ktx'); }
+        if (this._caps.etc2) { this.texturesSupported.push('-etc2.ktx'); }
+        if (this._caps.etc1) { this.texturesSupported.push('-etc1.ktx'); }
+
         if (this._gl.getShaderPrecisionFormat) {
         if (this._gl.getShaderPrecisionFormat) {
             var vertex_highp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT);
             var vertex_highp = this._gl.getShaderPrecisionFormat(this._gl.VERTEX_SHADER, this._gl.HIGH_FLOAT);
             var fragment_highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
             var fragment_highp = this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER, this._gl.HIGH_FLOAT);
@@ -2768,10 +2796,6 @@ export class ThinEngine {
 
 
         let texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Url);
         let texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Url);
 
 
-        if (this._transformTextureUrl) {
-            url = this._transformTextureUrl(url);
-        }
-
         // establish the file extension, if possible
         // establish the file extension, if possible
         var lastDot = url.lastIndexOf('.');
         var lastDot = url.lastIndexOf('.');
         var extension = forcedExtension ? forcedExtension : (lastDot > -1 ? url.substring(lastDot).toLowerCase() : "");
         var extension = forcedExtension ? forcedExtension : (lastDot > -1 ? url.substring(lastDot).toLowerCase() : "");