Browse Source

Fix bug when texture binding optimization was off
Better detection of target value for scene optimization classes

David Catuhe 7 years ago
parent
commit
13b9c4f7a5

File diff suppressed because it is too large
+ 7245 - 7319
Playground/babylon.d.txt


File diff suppressed because it is too large
+ 7964 - 8038
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 4 - 4
dist/preview release/babylon.js


+ 47 - 99
dist/preview release/babylon.max.js

@@ -12757,7 +12757,7 @@ var BABYLON;
             this._currentEffect = null;
         };
         Engine.prototype._moveBoundTextureOnTop = function (internalTexture) {
-            if (this._lastBoundInternalTextureTracker.previous === internalTexture) {
+            if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
                 return;
             }
             // Remove
@@ -77326,9 +77326,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        SceneOptimization.prototype.apply = function (scene) {
+        SceneOptimization.prototype.apply = function (scene, optimizer) {
             return true;
         };
         ;
@@ -77379,9 +77380,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        TextureOptimization.prototype.apply = function (scene) {
+        TextureOptimization.prototype.apply = function (scene, optimizer) {
             var allDone = true;
             for (var index = 0; index < scene.textures.length; index++) {
                 var texture = scene.textures[index];
@@ -77446,9 +77448,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        HardwareScalingOptimization.prototype.apply = function (scene) {
+        HardwareScalingOptimization.prototype.apply = function (scene, optimizer) {
             if (this._currentScale === -1) {
                 this._currentScale = scene.getEngine().getHardwareScalingLevel();
                 if (this._currentScale > this.maximumScale) {
@@ -77469,26 +77472,8 @@ var BABYLON;
      */
     var ShadowsOptimization = /** @class */ (function (_super) {
         __extends(ShadowsOptimization, _super);
-        /**
-         * Creates the ShadowsOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.shadowsEnabled property to (false by default)
-         */
-        function ShadowsOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.shadowsEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ShadowsOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77500,10 +77485,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ShadowsOptimization.prototype.apply = function (scene) {
-            scene.shadowsEnabled = this.target;
+        ShadowsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.shadowsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77516,26 +77502,8 @@ var BABYLON;
      */
     var PostProcessesOptimization = /** @class */ (function (_super) {
         __extends(PostProcessesOptimization, _super);
-        /**
-         * Creates the PostProcessesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.postProcessesEnabled property to (false by default)
-         */
-        function PostProcessesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.postProcessesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function PostProcessesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77547,10 +77515,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        PostProcessesOptimization.prototype.apply = function (scene) {
-            scene.postProcessesEnabled = this.target;
+        PostProcessesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.postProcessesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77563,26 +77532,8 @@ var BABYLON;
      */
     var LensFlaresOptimization = /** @class */ (function (_super) {
         __extends(LensFlaresOptimization, _super);
-        /**
-         * Creates the LensFlaresOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.lensFlaresEnabled property to (false by default)
-         */
-        function LensFlaresOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.lensFlaresEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function LensFlaresOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77594,10 +77545,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        LensFlaresOptimization.prototype.apply = function (scene) {
-            scene.lensFlaresEnabled = this.target;
+        LensFlaresOptimization.prototype.apply = function (scene, optimizer) {
+            scene.lensFlaresEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77626,11 +77578,12 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        CustomOptimization.prototype.apply = function (scene) {
+        CustomOptimization.prototype.apply = function (scene, optimizer) {
             if (this.onApply) {
-                return this.onApply(scene);
+                return this.onApply(scene, optimizer);
             }
             return true;
         };
@@ -77644,26 +77597,8 @@ var BABYLON;
      */
     var ParticlesOptimization = /** @class */ (function (_super) {
         __extends(ParticlesOptimization, _super);
-        /**
-         * Creates the ParticlesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.particlesEnabled property to (false by default)
-         */
-        function ParticlesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.particlesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ParticlesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77675,10 +77610,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ParticlesOptimization.prototype.apply = function (scene) {
-            scene.particlesEnabled = this.target;
+        ParticlesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.particlesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77704,10 +77640,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        RenderTargetsOptimization.prototype.apply = function (scene) {
-            scene.renderTargetsEnabled = false;
+        RenderTargetsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.renderTargetsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77769,10 +77706,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @param updateSelectionTree defines that the selection octree has to be updated (false by default)
          * @returns true if everything that can be done was applied
          */
-        MergeMeshesOptimization.prototype.apply = function (scene, updateSelectionTree) {
+        MergeMeshesOptimization.prototype.apply = function (scene, optimizer, updateSelectionTree) {
             var globalPool = scene.meshes.slice(0);
             var globalLength = globalPool.length;
             for (var index = 0; index < globalLength; index++) {
@@ -77860,7 +77798,7 @@ var BABYLON;
         };
         /**
          * Add a new custom optimization
-         * @param onApply defines the callback called to apply the custom optimization.
+         * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
          * @param onGetDescription defines the callback called to get the description attached with the optimization.
          * @param priority defines the priority of this optimization (0 by default which means first in the list)
          * @returns the current SceneOptimizerOptions
@@ -78008,6 +77946,16 @@ var BABYLON;
                 _this.dispose();
             });
         }
+        Object.defineProperty(SceneOptimizer.prototype, "isInImprovementMode", {
+            /**
+             * Gets a boolean indicating if the optimizer is in improvement mode
+             */
+            get: function () {
+                return this._improvementMode;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(SceneOptimizer.prototype, "currentPriorityLevel", {
             /**
              * Gets the current priority level (0 at start)
@@ -78120,7 +78068,7 @@ var BABYLON;
                 var optimization = options.optimizations[index];
                 if (optimization.priority === this._currentPriorityLevel) {
                     noOptimizationApplied = false;
-                    allDone = allDone && optimization.apply(scene);
+                    allDone = allDone && optimization.apply(scene, this);
                     this.onNewOptimizationAppliedObservable.notifyObservers(optimization);
                 }
             }

File diff suppressed because it is too large
+ 4 - 4
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 11890 - 11964
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 4 - 4
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 47 - 99
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -12757,7 +12757,7 @@ var BABYLON;
             this._currentEffect = null;
         };
         Engine.prototype._moveBoundTextureOnTop = function (internalTexture) {
-            if (this._lastBoundInternalTextureTracker.previous === internalTexture) {
+            if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
                 return;
             }
             // Remove
@@ -77120,9 +77120,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        SceneOptimization.prototype.apply = function (scene) {
+        SceneOptimization.prototype.apply = function (scene, optimizer) {
             return true;
         };
         ;
@@ -77173,9 +77174,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        TextureOptimization.prototype.apply = function (scene) {
+        TextureOptimization.prototype.apply = function (scene, optimizer) {
             var allDone = true;
             for (var index = 0; index < scene.textures.length; index++) {
                 var texture = scene.textures[index];
@@ -77240,9 +77242,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        HardwareScalingOptimization.prototype.apply = function (scene) {
+        HardwareScalingOptimization.prototype.apply = function (scene, optimizer) {
             if (this._currentScale === -1) {
                 this._currentScale = scene.getEngine().getHardwareScalingLevel();
                 if (this._currentScale > this.maximumScale) {
@@ -77263,26 +77266,8 @@ var BABYLON;
      */
     var ShadowsOptimization = /** @class */ (function (_super) {
         __extends(ShadowsOptimization, _super);
-        /**
-         * Creates the ShadowsOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.shadowsEnabled property to (false by default)
-         */
-        function ShadowsOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.shadowsEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ShadowsOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77294,10 +77279,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ShadowsOptimization.prototype.apply = function (scene) {
-            scene.shadowsEnabled = this.target;
+        ShadowsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.shadowsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77310,26 +77296,8 @@ var BABYLON;
      */
     var PostProcessesOptimization = /** @class */ (function (_super) {
         __extends(PostProcessesOptimization, _super);
-        /**
-         * Creates the PostProcessesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.postProcessesEnabled property to (false by default)
-         */
-        function PostProcessesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.postProcessesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function PostProcessesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77341,10 +77309,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        PostProcessesOptimization.prototype.apply = function (scene) {
-            scene.postProcessesEnabled = this.target;
+        PostProcessesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.postProcessesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77357,26 +77326,8 @@ var BABYLON;
      */
     var LensFlaresOptimization = /** @class */ (function (_super) {
         __extends(LensFlaresOptimization, _super);
-        /**
-         * Creates the LensFlaresOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.lensFlaresEnabled property to (false by default)
-         */
-        function LensFlaresOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.lensFlaresEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function LensFlaresOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77388,10 +77339,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        LensFlaresOptimization.prototype.apply = function (scene) {
-            scene.lensFlaresEnabled = this.target;
+        LensFlaresOptimization.prototype.apply = function (scene, optimizer) {
+            scene.lensFlaresEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77420,11 +77372,12 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        CustomOptimization.prototype.apply = function (scene) {
+        CustomOptimization.prototype.apply = function (scene, optimizer) {
             if (this.onApply) {
-                return this.onApply(scene);
+                return this.onApply(scene, optimizer);
             }
             return true;
         };
@@ -77438,26 +77391,8 @@ var BABYLON;
      */
     var ParticlesOptimization = /** @class */ (function (_super) {
         __extends(ParticlesOptimization, _super);
-        /**
-         * Creates the ParticlesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.particlesEnabled property to (false by default)
-         */
-        function ParticlesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.particlesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ParticlesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77469,10 +77404,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ParticlesOptimization.prototype.apply = function (scene) {
-            scene.particlesEnabled = this.target;
+        ParticlesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.particlesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77498,10 +77434,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        RenderTargetsOptimization.prototype.apply = function (scene) {
-            scene.renderTargetsEnabled = false;
+        RenderTargetsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.renderTargetsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77563,10 +77500,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @param updateSelectionTree defines that the selection octree has to be updated (false by default)
          * @returns true if everything that can be done was applied
          */
-        MergeMeshesOptimization.prototype.apply = function (scene, updateSelectionTree) {
+        MergeMeshesOptimization.prototype.apply = function (scene, optimizer, updateSelectionTree) {
             var globalPool = scene.meshes.slice(0);
             var globalLength = globalPool.length;
             for (var index = 0; index < globalLength; index++) {
@@ -77654,7 +77592,7 @@ var BABYLON;
         };
         /**
          * Add a new custom optimization
-         * @param onApply defines the callback called to apply the custom optimization.
+         * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
          * @param onGetDescription defines the callback called to get the description attached with the optimization.
          * @param priority defines the priority of this optimization (0 by default which means first in the list)
          * @returns the current SceneOptimizerOptions
@@ -77802,6 +77740,16 @@ var BABYLON;
                 _this.dispose();
             });
         }
+        Object.defineProperty(SceneOptimizer.prototype, "isInImprovementMode", {
+            /**
+             * Gets a boolean indicating if the optimizer is in improvement mode
+             */
+            get: function () {
+                return this._improvementMode;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(SceneOptimizer.prototype, "currentPriorityLevel", {
             /**
              * Gets the current priority level (0 at start)
@@ -77914,7 +77862,7 @@ var BABYLON;
                 var optimization = options.optimizations[index];
                 if (optimization.priority === this._currentPriorityLevel) {
                     noOptimizationApplied = false;
-                    allDone = allDone && optimization.apply(scene);
+                    allDone = allDone && optimization.apply(scene, this);
                     this.onNewOptimizationAppliedObservable.notifyObservers(optimization);
                 }
             }

+ 47 - 99
dist/preview release/customConfigurations/minimalGLTFViewer/es6.js

@@ -12743,7 +12743,7 @@ var BABYLON;
             this._currentEffect = null;
         };
         Engine.prototype._moveBoundTextureOnTop = function (internalTexture) {
-            if (this._lastBoundInternalTextureTracker.previous === internalTexture) {
+            if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
                 return;
             }
             // Remove
@@ -77106,9 +77106,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        SceneOptimization.prototype.apply = function (scene) {
+        SceneOptimization.prototype.apply = function (scene, optimizer) {
             return true;
         };
         ;
@@ -77159,9 +77160,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        TextureOptimization.prototype.apply = function (scene) {
+        TextureOptimization.prototype.apply = function (scene, optimizer) {
             var allDone = true;
             for (var index = 0; index < scene.textures.length; index++) {
                 var texture = scene.textures[index];
@@ -77226,9 +77228,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        HardwareScalingOptimization.prototype.apply = function (scene) {
+        HardwareScalingOptimization.prototype.apply = function (scene, optimizer) {
             if (this._currentScale === -1) {
                 this._currentScale = scene.getEngine().getHardwareScalingLevel();
                 if (this._currentScale > this.maximumScale) {
@@ -77249,26 +77252,8 @@ var BABYLON;
      */
     var ShadowsOptimization = /** @class */ (function (_super) {
         __extends(ShadowsOptimization, _super);
-        /**
-         * Creates the ShadowsOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.shadowsEnabled property to (false by default)
-         */
-        function ShadowsOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.shadowsEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ShadowsOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77280,10 +77265,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ShadowsOptimization.prototype.apply = function (scene) {
-            scene.shadowsEnabled = this.target;
+        ShadowsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.shadowsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77296,26 +77282,8 @@ var BABYLON;
      */
     var PostProcessesOptimization = /** @class */ (function (_super) {
         __extends(PostProcessesOptimization, _super);
-        /**
-         * Creates the PostProcessesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.postProcessesEnabled property to (false by default)
-         */
-        function PostProcessesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.postProcessesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function PostProcessesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77327,10 +77295,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        PostProcessesOptimization.prototype.apply = function (scene) {
-            scene.postProcessesEnabled = this.target;
+        PostProcessesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.postProcessesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77343,26 +77312,8 @@ var BABYLON;
      */
     var LensFlaresOptimization = /** @class */ (function (_super) {
         __extends(LensFlaresOptimization, _super);
-        /**
-         * Creates the LensFlaresOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.lensFlaresEnabled property to (false by default)
-         */
-        function LensFlaresOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.lensFlaresEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function LensFlaresOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77374,10 +77325,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        LensFlaresOptimization.prototype.apply = function (scene) {
-            scene.lensFlaresEnabled = this.target;
+        LensFlaresOptimization.prototype.apply = function (scene, optimizer) {
+            scene.lensFlaresEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77406,11 +77358,12 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        CustomOptimization.prototype.apply = function (scene) {
+        CustomOptimization.prototype.apply = function (scene, optimizer) {
             if (this.onApply) {
-                return this.onApply(scene);
+                return this.onApply(scene, optimizer);
             }
             return true;
         };
@@ -77424,26 +77377,8 @@ var BABYLON;
      */
     var ParticlesOptimization = /** @class */ (function (_super) {
         __extends(ParticlesOptimization, _super);
-        /**
-         * Creates the ParticlesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.particlesEnabled property to (false by default)
-         */
-        function ParticlesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.particlesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ParticlesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77455,10 +77390,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ParticlesOptimization.prototype.apply = function (scene) {
-            scene.particlesEnabled = this.target;
+        ParticlesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.particlesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77484,10 +77420,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        RenderTargetsOptimization.prototype.apply = function (scene) {
-            scene.renderTargetsEnabled = false;
+        RenderTargetsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.renderTargetsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77549,10 +77486,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @param updateSelectionTree defines that the selection octree has to be updated (false by default)
          * @returns true if everything that can be done was applied
          */
-        MergeMeshesOptimization.prototype.apply = function (scene, updateSelectionTree) {
+        MergeMeshesOptimization.prototype.apply = function (scene, optimizer, updateSelectionTree) {
             var globalPool = scene.meshes.slice(0);
             var globalLength = globalPool.length;
             for (var index = 0; index < globalLength; index++) {
@@ -77640,7 +77578,7 @@ var BABYLON;
         };
         /**
          * Add a new custom optimization
-         * @param onApply defines the callback called to apply the custom optimization.
+         * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
          * @param onGetDescription defines the callback called to get the description attached with the optimization.
          * @param priority defines the priority of this optimization (0 by default which means first in the list)
          * @returns the current SceneOptimizerOptions
@@ -77788,6 +77726,16 @@ var BABYLON;
                 _this.dispose();
             });
         }
+        Object.defineProperty(SceneOptimizer.prototype, "isInImprovementMode", {
+            /**
+             * Gets a boolean indicating if the optimizer is in improvement mode
+             */
+            get: function () {
+                return this._improvementMode;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(SceneOptimizer.prototype, "currentPriorityLevel", {
             /**
              * Gets the current priority level (0 at start)
@@ -77900,7 +77848,7 @@ var BABYLON;
                 var optimization = options.optimizations[index];
                 if (optimization.priority === this._currentPriorityLevel) {
                     noOptimizationApplied = false;
-                    allDone = allDone && optimization.apply(scene);
+                    allDone = allDone && optimization.apply(scene, this);
                     this.onNewOptimizationAppliedObservable.notifyObservers(optimization);
                 }
             }

+ 47 - 99
dist/preview release/es6.js

@@ -12743,7 +12743,7 @@ var BABYLON;
             this._currentEffect = null;
         };
         Engine.prototype._moveBoundTextureOnTop = function (internalTexture) {
-            if (this._lastBoundInternalTextureTracker.previous === internalTexture) {
+            if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
                 return;
             }
             // Remove
@@ -77312,9 +77312,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        SceneOptimization.prototype.apply = function (scene) {
+        SceneOptimization.prototype.apply = function (scene, optimizer) {
             return true;
         };
         ;
@@ -77365,9 +77366,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        TextureOptimization.prototype.apply = function (scene) {
+        TextureOptimization.prototype.apply = function (scene, optimizer) {
             var allDone = true;
             for (var index = 0; index < scene.textures.length; index++) {
                 var texture = scene.textures[index];
@@ -77432,9 +77434,10 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        HardwareScalingOptimization.prototype.apply = function (scene) {
+        HardwareScalingOptimization.prototype.apply = function (scene, optimizer) {
             if (this._currentScale === -1) {
                 this._currentScale = scene.getEngine().getHardwareScalingLevel();
                 if (this._currentScale > this.maximumScale) {
@@ -77455,26 +77458,8 @@ var BABYLON;
      */
     var ShadowsOptimization = /** @class */ (function (_super) {
         __extends(ShadowsOptimization, _super);
-        /**
-         * Creates the ShadowsOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.shadowsEnabled property to (false by default)
-         */
-        function ShadowsOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.shadowsEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ShadowsOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77486,10 +77471,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ShadowsOptimization.prototype.apply = function (scene) {
-            scene.shadowsEnabled = this.target;
+        ShadowsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.shadowsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77502,26 +77488,8 @@ var BABYLON;
      */
     var PostProcessesOptimization = /** @class */ (function (_super) {
         __extends(PostProcessesOptimization, _super);
-        /**
-         * Creates the PostProcessesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.postProcessesEnabled property to (false by default)
-         */
-        function PostProcessesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.postProcessesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function PostProcessesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77533,10 +77501,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        PostProcessesOptimization.prototype.apply = function (scene) {
-            scene.postProcessesEnabled = this.target;
+        PostProcessesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.postProcessesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77549,26 +77518,8 @@ var BABYLON;
      */
     var LensFlaresOptimization = /** @class */ (function (_super) {
         __extends(LensFlaresOptimization, _super);
-        /**
-         * Creates the LensFlaresOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.lensFlaresEnabled property to (false by default)
-         */
-        function LensFlaresOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.lensFlaresEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function LensFlaresOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77580,10 +77531,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        LensFlaresOptimization.prototype.apply = function (scene) {
-            scene.lensFlaresEnabled = this.target;
+        LensFlaresOptimization.prototype.apply = function (scene, optimizer) {
+            scene.lensFlaresEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77612,11 +77564,12 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        CustomOptimization.prototype.apply = function (scene) {
+        CustomOptimization.prototype.apply = function (scene, optimizer) {
             if (this.onApply) {
-                return this.onApply(scene);
+                return this.onApply(scene, optimizer);
             }
             return true;
         };
@@ -77630,26 +77583,8 @@ var BABYLON;
      */
     var ParticlesOptimization = /** @class */ (function (_super) {
         __extends(ParticlesOptimization, _super);
-        /**
-         * Creates the ParticlesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.particlesEnabled property to (false by default)
-         */
-        function ParticlesOptimization(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            priority, 
-            /**
-             * Defines the value to set the scene.particlesEnabled property to (false by default)
-             */
-            target) {
-            if (priority === void 0) { priority = 0; }
-            if (target === void 0) { target = false; }
-            var _this = _super.call(this, priority) || this;
-            _this.priority = priority;
-            _this.target = target;
-            return _this;
+        function ParticlesOptimization() {
+            return _super !== null && _super.apply(this, arguments) || this;
         }
         /**
          * Gets a string describing the action executed by the current optimization
@@ -77661,10 +77596,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        ParticlesOptimization.prototype.apply = function (scene) {
-            scene.particlesEnabled = this.target;
+        ParticlesOptimization.prototype.apply = function (scene, optimizer) {
+            scene.particlesEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77690,10 +77626,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        RenderTargetsOptimization.prototype.apply = function (scene) {
-            scene.renderTargetsEnabled = false;
+        RenderTargetsOptimization.prototype.apply = function (scene, optimizer) {
+            scene.renderTargetsEnabled = optimizer.isInImprovementMode;
             return true;
         };
         ;
@@ -77755,10 +77692,11 @@ var BABYLON;
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @param updateSelectionTree defines that the selection octree has to be updated (false by default)
          * @returns true if everything that can be done was applied
          */
-        MergeMeshesOptimization.prototype.apply = function (scene, updateSelectionTree) {
+        MergeMeshesOptimization.prototype.apply = function (scene, optimizer, updateSelectionTree) {
             var globalPool = scene.meshes.slice(0);
             var globalLength = globalPool.length;
             for (var index = 0; index < globalLength; index++) {
@@ -77846,7 +77784,7 @@ var BABYLON;
         };
         /**
          * Add a new custom optimization
-         * @param onApply defines the callback called to apply the custom optimization.
+         * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
          * @param onGetDescription defines the callback called to get the description attached with the optimization.
          * @param priority defines the priority of this optimization (0 by default which means first in the list)
          * @returns the current SceneOptimizerOptions
@@ -77994,6 +77932,16 @@ var BABYLON;
                 _this.dispose();
             });
         }
+        Object.defineProperty(SceneOptimizer.prototype, "isInImprovementMode", {
+            /**
+             * Gets a boolean indicating if the optimizer is in improvement mode
+             */
+            get: function () {
+                return this._improvementMode;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(SceneOptimizer.prototype, "currentPriorityLevel", {
             /**
              * Gets the current priority level (0 at start)
@@ -78106,7 +78054,7 @@ var BABYLON;
                 var optimization = options.optimizations[index];
                 if (optimization.priority === this._currentPriorityLevel) {
                     noOptimizationApplied = false;
-                    allDone = allDone && optimization.apply(scene);
+                    allDone = allDone && optimization.apply(scene, this);
                     this.onNewOptimizationAppliedObservable.notifyObservers(optimization);
                 }
             }

File diff suppressed because it is too large
+ 4 - 4
dist/preview release/viewer/babylon.viewer.js


+ 1 - 1
src/Engine/babylon.engine.ts

@@ -4743,7 +4743,7 @@
         }
 
         private _moveBoundTextureOnTop(internalTexture: InternalTexture): void {
-            if (this._lastBoundInternalTextureTracker.previous === internalTexture) {
+            if (this.disableTextureBindingOptimization || this._lastBoundInternalTextureTracker.previous === internalTexture) {
                 return;
             }
 

+ 37 - 88
src/Tools/babylon.sceneOptimizer.ts

@@ -15,9 +15,10 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
             return true;
         };
 
@@ -72,9 +73,10 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
 
             var allDone = true;
             for (var index = 0; index < scene.textures.length; index++) {
@@ -138,9 +140,10 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
             if (this._currentScale === -1) {
                 this._currentScale = scene.getEngine().getHardwareScalingLevel();
                 if (this._currentScale > this.maximumScale) {
@@ -170,29 +173,13 @@
         }
 
         /**
-         * Creates the ShadowsOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.shadowsEnabled property to (false by default)
-         */
-        constructor(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            public priority: number = 0,
-            /**
-             * Defines the value to set the scene.shadowsEnabled property to (false by default)
-             */
-            public target = false) {
-            super(priority);
-        }
-
-        /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
-            scene.shadowsEnabled = this.target;
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
+            scene.shadowsEnabled = optimizer.isInImprovementMode;
             return true;
         };
     }
@@ -211,29 +198,13 @@
         }
 
         /**
-         * Creates the PostProcessesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.postProcessesEnabled property to (false by default)
-         */
-        constructor(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            public priority: number = 0,
-            /**
-             * Defines the value to set the scene.postProcessesEnabled property to (false by default)
-             */
-            public target = false) {
-            super(priority);
-        }
-
-        /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
-            scene.postProcessesEnabled = this.target;
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
+            scene.postProcessesEnabled = optimizer.isInImprovementMode;
             return true;
         };
     }
@@ -252,29 +223,13 @@
         }
 
         /**
-         * Creates the LensFlaresOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.lensFlaresEnabled property to (false by default)
-         */
-        constructor(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            public priority: number = 0,
-            /**
-             * Defines the value to set the scene.lensFlaresEnabled property to (false by default)
-             */
-            public target = false) {
-            super(priority);
-        }
-
-        /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
-            scene.lensFlaresEnabled = this.target;
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
+            scene.lensFlaresEnabled = optimizer.isInImprovementMode;
             return true;
         };
     }
@@ -287,7 +242,7 @@
         /**
          * Callback called to apply the custom optimization.
          */
-        public onApply: (scene: Scene) => boolean;
+        public onApply: (scene: Scene, optimizer: SceneOptimizer) => boolean;
 
         /**
          * Callback called to get custom description
@@ -309,11 +264,12 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
             if (this.onApply) {
-                return this.onApply(scene);
+                return this.onApply(scene, optimizer);
             }
             return true;
         };
@@ -333,29 +289,13 @@
         }
 
         /**
-         * Creates the ParticlesOptimization object
-         * @param priority defines the priority of this optimization (0 by default which means first in the list)
-         * @param target defines the value to set the scene.particlesEnabled property to (false by default)
-         */
-        constructor(
-            /**
-             * Defines the priority of this optimization (0 by default which means first in the list)
-             */
-            public priority: number = 0,
-            /**
-             * Defines the value to set the scene.particlesEnabled property to (false by default)
-             */
-            public target = false) {
-            super(priority);
-        }
-
-        /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
-            scene.particlesEnabled = this.target;
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
+            scene.particlesEnabled = optimizer.isInImprovementMode;
             return true;
         };
     }
@@ -376,10 +316,11 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene): boolean {
-            scene.renderTargetsEnabled = false;
+        public apply(scene: Scene, optimizer: SceneOptimizer): boolean {
+            scene.renderTargetsEnabled = optimizer.isInImprovementMode;
             return true;
         };
     }
@@ -443,10 +384,11 @@
         /**
          * This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
          * @param scene defines the current scene where to apply this optimization
+         * @param optimizer defines the current optimizer
          * @param updateSelectionTree defines that the selection octree has to be updated (false by default)
          * @returns true if everything that can be done was applied
          */
-        public apply(scene: Scene, updateSelectionTree?: boolean): boolean {
+        public apply(scene: Scene, optimizer: SceneOptimizer, updateSelectionTree?: boolean): boolean {
 
             var globalPool = scene.meshes.slice(0);
             var globalLength = globalPool.length;
@@ -545,12 +487,12 @@
 
         /**
          * Add a new custom optimization
-         * @param onApply defines the callback called to apply the custom optimization.
+         * @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
          * @param onGetDescription defines the callback called to get the description attached with the optimization.
          * @param priority defines the priority of this optimization (0 by default which means first in the list)
          * @returns the current SceneOptimizerOptions
          */
-        public addCustomOptimization(onApply: (scene: Scene) => boolean, onGetDescription: () => string, priority: number = 0): SceneOptimizerOptions {
+        public addCustomOptimization(onApply: (scene: Scene, ) => boolean, onGetDescription: () => string, priority: number = 0): SceneOptimizerOptions {
             let optimization = new CustomOptimization(priority);
             optimization.onApply = onApply;
             optimization.onGetDescription = onGetDescription;
@@ -680,6 +622,13 @@
         public onFailureObservable = new Observable<SceneOptimizer>();
 
         /**
+         * Gets a boolean indicating if the optimizer is in improvement mode
+         */
+        public get isInImprovementMode(): boolean {
+            return this._improvementMode;
+        }
+
+        /**
          * Gets the current priority level (0 at start)
          */
         public get currentPriorityLevel(): number {
@@ -823,7 +772,7 @@
 
                 if (optimization.priority === this._currentPriorityLevel) {
                     noOptimizationApplied = false;
-                    allDone = allDone && optimization.apply(scene);
+                    allDone = allDone && optimization.apply(scene, this);
                     this.onNewOptimizationAppliedObservable.notifyObservers(optimization);
                 }
             }

+ 9 - 3
tests/validation/integration.js

@@ -36,22 +36,28 @@ xhr.addEventListener("load", function () {
                 it(test.title, function (done) {
                     this.timeout(180000);
 
+                    var deferredDone = function() {
+                        setTimeout(function() {
+                            done();
+                        }, 3000);
+                    }
+
                     try {
                         runTest(index, function(result, screenshot) {
                             try {
                                 expect(result).to.be.true; 
-                                done();
+                                deferredDone();
                             }
                             catch (e) {
                                 if (screenshot) {
                                     console.error(screenshot);
                                 }
-                                done(e);
+                                deferredDone(e);
                             }
                         });
                     }
                     catch (e) {
-                        done(e);
+                        deferredDone(e);
                     }
                 });
             };