Преглед на файлове

better effect onCompile event management

David Catuhe преди 8 години
родител
ревизия
ed52a488a7

Файловите разлики са ограничени, защото са твърде много
+ 4385 - 4381
dist/preview release/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.js


+ 26 - 12
dist/preview release/babylon.max.js

@@ -8731,10 +8731,11 @@ var BABYLON;
             var fragment = baseName.fragmentElement || baseName.fragment || baseName;
             var name = vertex + "+" + fragment + "@" + (defines ? defines : attributesNamesOrOptions.defines);
             if (this._compiledEffects[name]) {
-                if (onCompiled) {
-                    onCompiled(effect);
+                var compiledEffect = this._compiledEffects[name];
+                if (onCompiled && compiledEffect.isReady()) {
+                    onCompiled(compiledEffect);
                 }
-                return this._compiledEffects[name];
+                return compiledEffect;
             }
             var effect = new BABYLON.Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, this, defines, fallbacks, onCompiled, onError, indexParameters);
             effect._key = name;
@@ -22556,6 +22557,8 @@ var BABYLON;
         function Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, engine, defines, fallbacks, onCompiled, onError, indexParameters) {
             var _this = this;
             this.uniqueId = 0;
+            this.onCompileObservable = new BABYLON.Observable();
+            this.onErrorObservable = new BABYLON.Observable();
             this._uniformBuffersNames = {};
             this._isReady = false;
             this._compilationError = "";
@@ -22670,6 +22673,17 @@ var BABYLON;
             return this._evaluateDefinesOnString(this._engine.getFragmentShaderSource(this._program));
         };
         // Methods
+        Effect.prototype.executeWhenCompiled = function (func) {
+            var _this = this;
+            if (this.isReady()) {
+                func(this);
+                return;
+            }
+            var observer = this.onCompileObservable.add(function (effect) {
+                _this.onCompileObservable.remove(observer);
+                func(effect);
+            });
+        };
         Effect.prototype._loadVertexShader = function (vertex, callback) {
             // DOM element ?
             if (vertex instanceof HTMLElement) {
@@ -22903,6 +22917,7 @@ var BABYLON;
                 if (this.onCompiled) {
                     this.onCompiled(this);
                 }
+                this.onCompileObservable.notifyObservers(this);
             }
             catch (e) {
                 this._compilationError = e.message;
@@ -22925,6 +22940,7 @@ var BABYLON;
                     if (this.onError) {
                         this.onError(this, this._compilationError);
                     }
+                    this.onErrorObservable.notifyObservers(this);
                 }
             }
         };
@@ -44096,6 +44112,9 @@ var BABYLON;
         PostProcess.prototype.getEngine = function () {
             return this._engine;
         };
+        PostProcess.prototype.getEffect = function () {
+            return this._effect;
+        };
         PostProcess.prototype.shareOutputWith = function (postProcess) {
             this._disposeTextures();
             this._shareOutputWithPostProcess = postProcess;
@@ -44103,9 +44122,6 @@ var BABYLON;
         };
         PostProcess.prototype.updateEffect = function (defines, uniforms, samplers, indexParameters, onCompiled, onError) {
             this._effect = this._engine.createEffect({ vertex: this._vertexUrl, fragment: this._fragmentUrl }, ["position"], uniforms || this._parameters, samplers || this._samplers, defines !== undefined ? defines : "", null, onCompiled, onError, indexParameters || this._indexParameters);
-            if (onCompiled && this._effect.isReady()) {
-                onCompiled(this._effect);
-            }
         };
         PostProcess.prototype.isReusable = function () {
             return this._reusable;
@@ -44282,10 +44298,9 @@ var BABYLON;
 (function (BABYLON) {
     var PassPostProcess = (function (_super) {
         __extends(PassPostProcess, _super);
-        function PassPostProcess(name, options, camera, samplingMode, engine, reusable, textureType, blockCompilation) {
+        function PassPostProcess(name, options, camera, samplingMode, engine, reusable, textureType) {
             if (textureType === void 0) { textureType = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT; }
-            if (blockCompilation === void 0) { blockCompilation = false; }
-            return _super.call(this, name, "pass", null, null, options, camera, samplingMode, engine, reusable, null, textureType, "postprocess", null, blockCompilation) || this;
+            return _super.call(this, name, "pass", null, null, options, camera, samplingMode, engine, reusable, null, textureType) || this;
         }
         return PassPostProcess;
     }(BABYLON.PostProcess));
@@ -66874,8 +66889,8 @@ var BABYLON;
             rtt.level = texture.level;
             rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;
             rtt._texture.isReady = false;
-            var passPostProcess = new BABYLON.PassPostProcess("pass", 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT, true);
-            passPostProcess.updateEffect(null, null, null, null, function () {
+            var passPostProcess = new BABYLON.PassPostProcess("pass", 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, false, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
+            passPostProcess.getEffect().executeWhenCompiled(function () {
                 passPostProcess.onApply = function (effect) {
                     effect.setTexture("textureSampler", texture);
                 };
@@ -66884,7 +66899,6 @@ var BABYLON;
                 rtt.disposeFramebufferObjects();
                 passPostProcess.dispose();
                 rtt._texture.isReady = true;
-                engine.resetTextureCache();
             });
             return rtt;
         };

Файловите разлики са ограничени, защото са твърде много
+ 4385 - 4381
dist/preview release/babylon.module.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 31 - 31
dist/preview release/babylon.worker.js


+ 16 - 0
src/Materials/babylon.effect.ts

@@ -91,6 +91,8 @@
         public onError: (effect: Effect, errors: string) => void;
         public onBind: (effect: Effect) => void;
         public uniqueId = 0;
+        public onCompileObservable = new Observable<Effect>();
+        public onErrorObservable = new Observable<Effect>();
 
         private static _uniqueIdSeed = 0;
         private _engine: Engine;
@@ -241,6 +243,18 @@
         }
 
         // Methods
+        public executeWhenCompiled(func: (effect: Effect) => void): void {
+            if (this.isReady()) {
+                func(this);
+                return;
+            }
+            
+            var observer = this.onCompileObservable.add((effect) => {
+                this.onCompileObservable.remove(observer);
+                func(effect);
+            });
+        }
+
         public _loadVertexShader(vertex: any, callback: (data: any) => void): void {
             // DOM element ?
             if (vertex instanceof HTMLElement) {
@@ -514,6 +528,7 @@
                 if (this.onCompiled) {
                     this.onCompiled(this);
                 }
+                this.onCompileObservable.notifyObservers(this);
             } catch (e) {
                 this._compilationError = e.message;
 
@@ -537,6 +552,7 @@
                     if (this.onError) {
                         this.onError(this, this._compilationError);
                     }
+                    this.onErrorObservable.notifyObservers(this);
                 }
             }
         }

+ 2 - 2
src/PostProcess/babylon.passPostProcess.ts

@@ -1,7 +1,7 @@
 module BABYLON {
     export class PassPostProcess extends PostProcess {    
-        constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT, blockCompilation = false) {
-            super(name, "pass", null, null, options, camera, samplingMode, engine, reusable, null, textureType, "postprocess", null, blockCompilation);
+        constructor(name: string, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
+            super(name, "pass", null, null, options, camera, samplingMode, engine, reusable, null, textureType);
         }
     }
 } 

+ 5 - 5
src/PostProcess/babylon.postProcess.ts

@@ -172,6 +172,10 @@
             return this._engine;
         }        
 
+        public getEffect(): Effect {
+            return this._effect;
+        }
+
         public shareOutputWith(postProcess: PostProcess): PostProcess {
             this._disposeTextures();
 
@@ -192,11 +196,7 @@
                 onError,
                 indexParameters || this._indexParameters
                 );
-            
-            if (onCompiled && this._effect.isReady()) {
-                onCompiled(this._effect);
-            }
-        }
+         }
 
         public isReusable(): boolean {
             return this._reusable;

+ 2 - 3
src/Tools/babylon.textureTools.ts

@@ -37,8 +37,8 @@
             rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;
 			rtt._texture.isReady = false;
 
-            let passPostProcess = new BABYLON.PassPostProcess("pass", 1, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, Engine.TEXTURETYPE_UNSIGNED_INT, true);
-            passPostProcess.updateEffect(null, null, null, null, () => {
+            let passPostProcess = new BABYLON.PassPostProcess("pass", 1, null, Texture.BILINEAR_SAMPLINGMODE, engine, false, Engine.TEXTURETYPE_UNSIGNED_INT);
+			passPostProcess.getEffect().executeWhenCompiled(() => {
                 passPostProcess.onApply = function (effect) {
                     effect.setTexture("textureSampler", texture);
                 }
@@ -50,7 +50,6 @@
 				passPostProcess.dispose();
 
 				rtt._texture.isReady = true;
-				engine.resetTextureCache();
             });
 
 			return rtt;

+ 4 - 3
src/babylon.engine.ts

@@ -1941,10 +1941,11 @@
 
             var name = vertex + "+" + fragment + "@" + (defines ? defines : (<EffectCreationOptions>attributesNamesOrOptions).defines);
             if (this._compiledEffects[name]) {
-                if (onCompiled) {
-                    onCompiled(effect);
+                var compiledEffect = <Effect>this._compiledEffects[name];
+                if (onCompiled && compiledEffect.isReady()) {
+                    onCompiled(compiledEffect);
                 }
-                return this._compiledEffects[name];
+                return compiledEffect;
             }
 
             var effect = new Effect(baseName, attributesNamesOrOptions, uniformsNamesOrEngine, samplers, this, defines, fallbacks, onCompiled, onError, indexParameters);