Browse Source

Merge pull request #1244 from sebavan/FixyFixy

Fixy fixy
David Catuhe 9 years ago
parent
commit
1fb588ad20

+ 7 - 1
src/Lights/Shadows/babylon.shadowGenerator.ts

@@ -1,5 +1,11 @@
 module BABYLON {
-    export class ShadowGenerator {
+    export interface IShadowGenerator {
+        getShadowMap(): RenderTargetTexture;
+
+        dispose(): void;
+    }
+
+    export class ShadowGenerator implements IShadowGenerator {
         private static _FILTER_NONE = 0;
         private static _FILTER_VARIANCESHADOWMAP = 1;
         private static _FILTER_POISSONSAMPLING = 2;

+ 3 - 3
src/Lights/babylon.light.ts

@@ -17,7 +17,7 @@
 
         getShadowDirection(faceIndex?: number): Vector3;
 
-        _shadowGenerator: ShadowGenerator;
+        _shadowGenerator: IShadowGenerator;
     }
 
     export class Light extends Node {
@@ -46,7 +46,7 @@
         @serialize()
         public radius = 0.00001;
 
-        public _shadowGenerator: ShadowGenerator;
+        public _shadowGenerator: IShadowGenerator;
         private _parentedWorldMatrix: Matrix;
         public _excludedMeshesIds = new Array<string>();
         public _includedOnlyMeshesIds = new Array<string>();
@@ -73,7 +73,7 @@
             return ret;
         } 
         
-        public getShadowGenerator(): ShadowGenerator {
+        public getShadowGenerator(): IShadowGenerator {
             return this._shadowGenerator;
         }
 

+ 1 - 0
src/Materials/Textures/babylon.colorGradingTexture.ts

@@ -214,6 +214,7 @@ module BABYLON {
             var serializationObject: any = {};
             serializationObject.name = this.name;
             serializationObject.level = this.level;
+            serializationObject.customType = "BABYLON.ColorGradingTexture";
 
             return serializationObject;
         }

+ 1 - 0
src/Materials/Textures/babylon.hdrcubetexture.ts

@@ -410,6 +410,7 @@ module BABYLON {
             serializationObject.generateHarmonics = this._generateHarmonics;
             serializationObject.usePMREMGenerator = this._usePMREMGenerator;
             serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
+            serializationObject.customType = "BABYLON.HDRCubeTexture";
 
             return serializationObject;
         }

+ 4 - 1
src/Materials/Textures/babylon.texture.ts

@@ -273,7 +273,10 @@
             }
 
             var texture = SerializationHelper.Parse(() => {
-                if (parsedTexture.mirrorPlane) {
+                if (parsedTexture.customType) {
+                    var customTexture = Tools.Instantiate(parsedTexture.customType);
+                    return customTexture.Parse(parsedTexture, scene, rootUrl);
+                } else if (parsedTexture.mirrorPlane) {
                     var mirrorTexture = new MirrorTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene);
                     mirrorTexture._waitingRenderList = parsedTexture.renderList;
                     mirrorTexture.mirrorPlane = Plane.FromArray(parsedTexture.mirrorPlane);

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

@@ -491,6 +491,62 @@
             return changed;
         }
 
+        public setIntArray(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray2(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray2(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray3(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray3(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setIntArray4(uniformName: string, array: Int32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setIntArray4(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray2(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray2(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray3(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray3(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
+        public setFloatArray4(uniformName: string, array: Float32Array): Effect {
+            this._valueCache[uniformName] = null;
+            this._engine.setFloatArray4(this.getUniform(uniformName), array);
+
+            return this;
+        }
+
         public setArray(uniformName: string, array: number[]): Effect {
             this._valueCache[uniformName] = null;
             this._engine.setArray(this.getUniform(uniformName), array);

+ 2 - 2
src/Materials/babylon.materialHelper.ts

@@ -74,7 +74,7 @@
 
                 // Shadows
                 if (scene.shadowsEnabled) {
-                    var shadowGenerator = light.getShadowGenerator();
+                    var shadowGenerator = <ShadowGenerator>light.getShadowGenerator();
                     if (mesh && mesh.receiveShadows && shadowGenerator) {
                         if (defines["SHADOW" + lightIndex] === undefined) {
                             needRebuild = true;
@@ -191,7 +191,7 @@
 
         // Bindings
         public static BindLightShadow(light: Light, scene: Scene, mesh: AbstractMesh, lightIndex: number, effect: Effect, depthValuesAlreadySet: boolean): boolean {
-            var shadowGenerator = light.getShadowGenerator();
+            var shadowGenerator = <ShadowGenerator>light.getShadowGenerator();
             if (mesh.receiveShadows && shadowGenerator) {
                 if (!(<any>light).needCube()) {
                     effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());

+ 4 - 2
src/Tools/babylon.sceneSerializer.ts

@@ -334,8 +334,10 @@
             for (index = 0; index < scene.lights.length; index++) {
                 light = scene.lights[index];
 
-                if (light.getShadowGenerator()) {
-                    serializationObject.shadowGenerators.push(light.getShadowGenerator().serialize());
+                let shadowGenerator = light.getShadowGenerator();
+                // Only support serialization for official generator so far.
+                if (shadowGenerator && shadowGenerator instanceof ShadowGenerator) {
+                    serializationObject.shadowGenerators.push(<ShadowGenerator>shadowGenerator.serialize());
                 }
             }
 

+ 64 - 0
src/babylon.engine.ts

@@ -1345,6 +1345,62 @@
             }
         }
 
+        public setIntArray(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1iv(uniform, array);
+        }
+
+        public setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2iv(uniform, array);
+        }
+
+        public setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3iv(uniform, array);
+        }
+
+        public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4iv(uniform, array);
+        }
+
+        public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform)
+                return;
+
+            this._gl.uniform1fv(uniform, array);
+        }
+
+        public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 2 !== 0)
+                return;
+
+            this._gl.uniform2fv(uniform, array);
+        }
+
+        public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 3 !== 0)
+                return;
+
+            this._gl.uniform3fv(uniform, array);
+        }
+
+        public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): void {
+            if (!uniform || array.length % 4 !== 0)
+                return;
+
+            this._gl.uniform4fv(uniform, array);
+        }
+
         public setArray(uniform: WebGLUniformLocation, array: number[]): void {
             if (!uniform)
                 return;
@@ -2588,6 +2644,14 @@
             this._loadingScreen.loadingUIBackgroundColor = color;
         }
 
+        public attachContextLostEvent(callback:((event: WebGLContextEvent) => void)) : void {
+            this._renderingCanvas.addEventListener("webglcontextlost", callback, false);
+        }
+
+        public attachContextRestoredEvent(callback:((event: WebGLContextEvent) => void)) : void {
+            this._renderingCanvas.addEventListener("webglcontextrestored", callback, false);
+        }
+
         // FPS
         public getFps(): number {
             return this.fps;