浏览代码

misc fixing

Benjamin Guignabert 8 年之前
父节点
当前提交
0abb94114d

+ 8 - 0
Tools/Gulp/config.json

@@ -215,6 +215,10 @@
                 "helperFunctions",
                 "lightFragmentDeclaration",
                 "lightsFragmentFunctions",
+                "lightUboDeclaration",
+                "defaultVertexDeclaration",
+                "defaultFragmentDeclaration",
+                "defaultUboDeclaration",
                 "shadowsFragmentFunctions",
                 "fresnelFunction",
                 "reflectionFunction",
@@ -264,6 +268,10 @@
                 "shadowsVertex",
                 "logDepthVertex",
                 "lightFragmentDeclaration",
+                "lightUboDeclaration",
+                "pbrVertexDeclaration",
+                "pbrFragmentDeclaration",
+                "pbrUboDeclaration",
                 "fresnelFunction",
                 "reflectionFunction",                
                 "colorGradingDefinition",

文件差异内容过多而无法显示
+ 2981 - 2970
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 2981 - 2970
dist/preview release/babylon.module.d.ts


+ 0 - 1
materialsLibrary/src/terrain/babylon.terrainMaterial.ts

@@ -198,7 +198,6 @@ module BABYLON {
                     "vTextureInfos", 
                     "mBones",
                     "vClipPlane", "textureMatrix",
-                    
                     "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
                 ];
                 var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",

+ 2 - 4
src/Lights/babylon.directionalLight.ts

@@ -175,17 +175,15 @@ module BABYLON {
          * Returns the DirectionalLight.  
          */
         public transferToEffect(effect: Effect, lightIndex: number): DirectionalLight {
-            var useUbo = this._uniformBuffer.useUbo;
-
             if (this.parent && this.parent.getWorldMatrix) {
                 if (!this._transformedDirection) {
                     this._transformedDirection = Vector3.Zero();
                 }
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
-                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex, this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1);
+                this._uniformBuffer.updateFloat4("vLightData", this._transformedDirection.x, this._transformedDirection.y, this._transformedDirection.z, 1, lightIndex);
                 return this;
             }
-            this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex, this.direction.x, this.direction.y, this.direction.z, 1);
+            this._uniformBuffer.updateFloat4("vLightData", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);
             return this;
         }
 

+ 4 - 5
src/Lights/babylon.hemisphericLight.ts

@@ -52,15 +52,14 @@
          * Returns the HemisphericLight.  
          */
         public transferToEffect(effect: Effect, lightIndex: number): HemisphericLight {
-            var useUbo = this._uniformBuffer.useUbo;
-
             var normalizeDirection = Vector3.Normalize(this.direction);
-            this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
+            this._uniformBuffer.updateFloat4("vLightData",
                 normalizeDirection.x,
                 normalizeDirection.y,
                 normalizeDirection.z,
-                0.0);
-            this._uniformBuffer.updateColor3(useUbo ? "vLightGround" : "vLightGround" + lightIndex, this.groundColor.scale(this.intensity));
+                0.0,
+                lightIndex);
+            this._uniformBuffer.updateColor3("vLightGround", this.groundColor.scale(this.intensity), lightIndex);
             return this;
         }
 

+ 4 - 4
src/Lights/babylon.pointLight.ts

@@ -70,20 +70,20 @@
          * Returns the PointLight.  
          */
         public transferToEffect(effect: Effect, lightIndex: number): PointLight {
-            var useUbo = this._uniformBuffer.useUbo;
 
             if (this.parent && this.parent.getWorldMatrix) {
                 this.computeTransformedPosition();
 
-                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
-                    0.0); 
+                    0.0,
+                    lightIndex); 
                 return this;
             }
 
-            this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex, this.position.x, this.position.y, this.position.z, 0);
+            this._uniformBuffer.updateFloat4("vLightData", this.position.x, this.position.y, this.position.z, 0, lightIndex);
             return this;
         }
         /**

+ 9 - 8
src/Lights/babylon.spotLight.ts

@@ -130,8 +130,6 @@
          * Return the SpotLight.   
          */
         public transferToEffect(effect: Effect, lightIndex: number): SpotLight {
-            var useUbo = this._uniformBuffer.useUbo;
-
             var normalizeDirection;
 
             if (this.parent && this.parent.getWorldMatrix) {
@@ -143,28 +141,31 @@
                 
                 Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this._transformedDirection);
 
-                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.transformedPosition.x,
                     this.transformedPosition.y,
                     this.transformedPosition.z,
-                    this.exponent);
+                    this.exponent,
+                    lightIndex);
 
                 normalizeDirection = Vector3.Normalize(this._transformedDirection);
             } else {
-                this._uniformBuffer.updateFloat4(useUbo ? "vLightData" : "vLightData" + lightIndex,
+                this._uniformBuffer.updateFloat4("vLightData",
                     this.position.x,
                     this.position.y,
                     this.position.z,
-                    this.exponent);                    
+                    this.exponent,
+                    lightIndex);                    
 
                 normalizeDirection = Vector3.Normalize(this.direction);
             }
 
-            this._uniformBuffer.updateFloat4(useUbo ? "vLightDirection" : "vLightDirection" + lightIndex,
+            this._uniformBuffer.updateFloat4("vLightDirection",
                 normalizeDirection.x,
                 normalizeDirection.y,
                 normalizeDirection.z,
-                Math.cos(this.angle * 0.5));
+                Math.cos(this.angle * 0.5),
+                lightIndex);
             return this;
         }
 

+ 4 - 2
src/Materials/babylon.material.ts

@@ -332,6 +332,7 @@
 
         public _effect: Effect;
         public _wasPreviouslyReady = false;
+        private _useUBO: boolean;
         private _scene: Scene;
         private _fillMode = Material.TriangleFillMode;
         private _cachedDepthWriteState: boolean;
@@ -351,6 +352,7 @@
             }
 
             this._uniformBuffer = new UniformBuffer(this._scene.getEngine());
+            this._useUBO = this.getScene().getEngine().webGLVersion > 1;
 
             if (!doNotAdd) {
                 this._scene.materials.push(this);
@@ -446,7 +448,7 @@
         }
 
         public bindView(effect: Effect): void {
-            if (this.getScene().getEngine().webGLVersion === 1) {
+            if (!this._useUBO) {
                 effect.setMatrix("view", this.getScene().getViewMatrix());
             } else {
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());
@@ -454,7 +456,7 @@
         }
 
         public bindViewProjection(effect: Effect): void {
-            if (this.getScene().getEngine().webGLVersion === 1) {
+            if (!this._useUBO) {
                 effect.setMatrix("viewProjection", this.getScene().getTransformMatrix());
             } else {
                 this.bindSceneUniformBuffer(effect, this.getScene().getSceneUniformBuffer());

+ 3 - 6
src/Materials/babylon.materialHelper.ts

@@ -305,7 +305,6 @@
         // Bindings
         public static BindLightShadow(light: Light, scene: Scene, mesh: AbstractMesh, lightIndex: number, effect: Effect, depthValuesAlreadySet: boolean): boolean {
             var shadowGenerator = <ShadowGenerator>light.getShadowGenerator();
-            var useUbo = light._uniformBuffer.useUbo;
 
             if (mesh.receiveShadows && shadowGenerator) {
                 if (!(<any>light).needCube()) {
@@ -317,7 +316,7 @@
                     }
                 }
                 effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
-                light._uniformBuffer.updateFloat3(useUbo ? "shadowsInfo" : "shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.depthScale);
+                light._uniformBuffer.updateFloat3("shadowsInfo", shadowGenerator.getDarkness(), shadowGenerator.blurScale / shadowGenerator.getShadowMap().getSize().width, shadowGenerator.depthScale, lightIndex);
             }
 
             return depthValuesAlreadySet;
@@ -332,17 +331,15 @@
             var depthValuesAlreadySet = false;
 
             for (var light of mesh._lightSources) {
-                var useUbo = light._uniformBuffer.useUbo;
-
                 light._uniformBuffer.bindToEffect(effect, "Light" + lightIndex);
 
                 MaterialHelper.BindLightProperties(light, effect, lightIndex);
 
                 light.diffuse.scaleToRef(light.intensity, Tmp.Color3[0]);
-                light._uniformBuffer.updateColor4(useUbo ? "vLightDiffuse" : "vLightDiffuse" + lightIndex, Tmp.Color3[0], light.range);
+                light._uniformBuffer.updateColor4("vLightDiffuse", Tmp.Color3[0], light.range, lightIndex);
                 if (defines["SPECULARTERM"]) {
                     light.specular.scaleToRef(light.intensity, Tmp.Color3[1]);
-                    light._uniformBuffer.updateColor3(useUbo ? "vLightSpecular" : "vLightSpecular" + lightIndex, Tmp.Color3[1]);
+                    light._uniformBuffer.updateColor3("vLightSpecular", Tmp.Color3[1], lightIndex);
                 }
 
                 // Shadows

+ 66 - 62
src/Materials/babylon.uniformBuffer.ts

@@ -1,9 +1,5 @@
 module BABYLON {
 
-    // Pool for avoiding memory leaks
-    var MAX_UNIFORM_SIZE = 256;
-    var _tempBuffer = new Float32Array(MAX_UNIFORM_SIZE);
-
     export class UniformBuffer {
         private _engine: Engine;
         private _buffer: WebGLBuffer;
@@ -16,9 +12,13 @@ module BABYLON {
         private _uniformLocationPointer: number;
         private _needSync: boolean;
         private _cache: Float32Array;
-        private _noUbo: boolean;
+        private _noUBO: boolean;
         private _currentEffect: Effect;
 
+        // Pool for avoiding memory leaks
+        private static _MAX_UNIFORM_SIZE = 256;
+        private static _tempBuffer = new Float32Array(UniformBuffer._MAX_UNIFORM_SIZE);
+
         /**
          * Uniform buffer objects.
          * 
@@ -31,7 +31,7 @@ module BABYLON {
          */
         constructor(engine: Engine, data?: number[], dynamic?: boolean) {
             this._engine = engine;
-            this._noUbo = engine.webGLVersion === 1;
+            this._noUBO = engine.webGLVersion === 1;
             this._dynamic = dynamic;
 
             this._data = data || [];
@@ -49,7 +49,7 @@ module BABYLON {
          * or just falling back on setUniformXXX calls.
          */
         public get useUbo(): boolean {
-            return !this._noUbo;
+            return !this._noUBO;
         }
         
         /**
@@ -119,7 +119,7 @@ module BABYLON {
          * @param {number|number[]} size Data size, or data directly.
          */
         public addUniform(name: string, size: number | number[]) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 return;
             }
 
@@ -244,7 +244,7 @@ module BABYLON {
          * Effectively creates the WebGL Uniform Buffer, once layout is completed with `addUniform`.
          */
         public create(): void {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 return;
             }
             if (this._buffer) {
@@ -330,7 +330,7 @@ module BABYLON {
          * @param {Float32Array} matrix
          */
         public updateMatrix3x3(name: string, matrix: Float32Array): Effect {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setMatrix3x3(name, matrix);
                 }
@@ -339,13 +339,13 @@ module BABYLON {
 
             // To match std140, matrix must be realigned
             for (var i = 0; i < 3; i++) {
-                _tempBuffer[i * 4] = matrix[i * 3];
-                _tempBuffer[i * 4 + 1] = matrix[i * 3 + 1];
-                _tempBuffer[i * 4 + 2] = matrix[i * 3 + 2];
-                _tempBuffer[i * 4 + 3] = 0.0;
+                UniformBuffer._tempBuffer[i * 4] = matrix[i * 3];
+                UniformBuffer._tempBuffer[i * 4 + 1] = matrix[i * 3 + 1];
+                UniformBuffer._tempBuffer[i * 4 + 2] = matrix[i * 3 + 2];
+                UniformBuffer._tempBuffer[i * 4 + 3] = 0.0;
             }
 
-            this.updateUniform(name, _tempBuffer, 12);
+            this.updateUniform(name, UniformBuffer._tempBuffer, 12);
         }
 
         /**
@@ -354,7 +354,7 @@ module BABYLON {
          * @param {Float32Array} matrix
          */
         public updateMatrix2x2(name: string, matrix: Float32Array): Effect {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setMatrix2x2(name, matrix);
                 }
@@ -363,13 +363,13 @@ module BABYLON {
 
             // To match std140, matrix must be realigned
             for (var i = 0; i < 2; i++) {
-                _tempBuffer[i * 4] = matrix[i * 2];
-                _tempBuffer[i * 4 + 1] = matrix[i * 2 + 1];
-                _tempBuffer[i * 4 + 2] = 0.0;
-                _tempBuffer[i * 4 + 3] = 0.0;
+                UniformBuffer._tempBuffer[i * 4] = matrix[i * 2];
+                UniformBuffer._tempBuffer[i * 4 + 1] = matrix[i * 2 + 1];
+                UniformBuffer._tempBuffer[i * 4 + 2] = 0.0;
+                UniformBuffer._tempBuffer[i * 4 + 3] = 0.0;
             }
 
-            this.updateUniform(name, _tempBuffer, 8);
+            this.updateUniform(name, UniformBuffer._tempBuffer, 8);
         }
 
         /**
@@ -378,15 +378,15 @@ module BABYLON {
          * @param {number} x
          */
         public updateFloat(name: string, x: number) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setFloat(name, x);
                 }
                 return;
             }
 
-            _tempBuffer[0] = x;
-            this.updateUniform(name, _tempBuffer, 1);
+            UniformBuffer._tempBuffer[0] = x;
+            this.updateUniform(name, UniformBuffer._tempBuffer, 1);
         }
 
         /**
@@ -396,16 +396,16 @@ module BABYLON {
          * @param {number} y
          */
         public updateFloat2(name: string, x: number, y: number) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setFloat2(name, x, y);
                 }
                 return;
             }
 
-            _tempBuffer[0] = x;
-            _tempBuffer[1] = y;
-            this.updateUniform(name, _tempBuffer, 2);
+            UniformBuffer._tempBuffer[0] = x;
+            UniformBuffer._tempBuffer[1] = y;
+            this.updateUniform(name, UniformBuffer._tempBuffer, 2);
         }
 
         /**
@@ -414,19 +414,20 @@ module BABYLON {
          * @param {number} x
          * @param {number} y
          * @param {number} z
+         * @param {string|number} [suffix] Suffix to add to the uniform name.
          */
-        public updateFloat3(name: string, x: number, y: number, z: number) {
-            if (this._noUbo) {
+        public updateFloat3(name: string, x: number, y: number, z: number, suffix?: string | number) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
-                    this._currentEffect.setFloat3(name, x, y, z);
+                    this._currentEffect.setFloat3(name + suffix, x, y, z);
                 }
                 return;
             }
 
-            _tempBuffer[0] = x;
-            _tempBuffer[1] = y;
-            _tempBuffer[2] = z;
-            this.updateUniform(name, _tempBuffer, 3);
+            UniformBuffer._tempBuffer[0] = x;
+            UniformBuffer._tempBuffer[1] = y;
+            UniformBuffer._tempBuffer[2] = z;
+            this.updateUniform(name, UniformBuffer._tempBuffer, 3);
         }
 
         /**
@@ -436,20 +437,21 @@ module BABYLON {
          * @param {number} y
          * @param {number} z
          * @param {number} w
+         * @param {string|number} [suffix] Suffix to add to the uniform name.
          */
-        public updateFloat4(name: string, x: number, y: number, z: number, w: number) {
-            if (this._noUbo) {
+        public updateFloat4(name: string, x: number, y: number, z: number, w: number, suffix?: string | number) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
-                    this._currentEffect.setFloat4(name, x, y, z, w);
+                    this._currentEffect.setFloat4(name + suffix, x, y, z, w);
                 }
                 return;
             }
 
-            _tempBuffer[0] = x;
-            _tempBuffer[1] = y;
-            _tempBuffer[2] = z;
-            _tempBuffer[3] = w;
-            this.updateUniform(name, _tempBuffer, 4);
+            UniformBuffer._tempBuffer[0] = x;
+            UniformBuffer._tempBuffer[1] = y;
+            UniformBuffer._tempBuffer[2] = z;
+            UniformBuffer._tempBuffer[3] = w;
+            this.updateUniform(name, UniformBuffer._tempBuffer, 4);
         }
 
         /**
@@ -458,7 +460,7 @@ module BABYLON {
          * @param {Matrix} A 4x4 matrix.
          */
         public updateMatrix(name: string, mat: Matrix) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setMatrix(name, mat);
                 }
@@ -474,14 +476,14 @@ module BABYLON {
          * @param {Vector3} vector
          */
         public updateVector3(name: string, vector: Vector3) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setVector3(name, vector);
                 }
                 return;
             }
-            vector.toArray(_tempBuffer);
-            this.updateUniform(name, _tempBuffer, 3);
+            vector.toArray(UniformBuffer._tempBuffer);
+            this.updateUniform(name, UniformBuffer._tempBuffer, 3);
         }
 
         /**
@@ -490,30 +492,31 @@ module BABYLON {
          * @param {Vector4} vector
          */
         public updateVector4(name: string, vector: Vector4) {
-            if (this._noUbo) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
                     this._currentEffect.setVector4(name, vector);
                 }
                 return;
             }
-            vector.toArray(_tempBuffer);
-            this.updateUniform(name, _tempBuffer, 4);
+            vector.toArray(UniformBuffer._tempBuffer);
+            this.updateUniform(name, UniformBuffer._tempBuffer, 4);
         }
 
         /**
          * Wrapper for updateUniform.
          * @param {string} name Name of the uniform, as used in the uniform block in the shader.
          * @param {Color3} color
+         * @param {string|number} [suffix] Suffix to add to the uniform name.
          */
-        public updateColor3(name: string, color: Color3) {
-            if (this._noUbo) {
+        public updateColor3(name: string, color: Color3, suffix?: string | number) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
-                    this._currentEffect.setColor3(name, color);
+                    this._currentEffect.setColor3(name + suffix, color);
                 }
                 return;
             }
-            color.toArray(_tempBuffer);
-            this.updateUniform(name, _tempBuffer, 3);
+            color.toArray(UniformBuffer._tempBuffer);
+            this.updateUniform(name, UniformBuffer._tempBuffer, 3);
         }
 
         /**
@@ -521,17 +524,18 @@ module BABYLON {
          * @param {string} name Name of the uniform, as used in the uniform block in the shader.
          * @param {Color3} color
          * @param {number} alpha
+         * @param {string|number} [suffix] Suffix to add to the uniform name.
          */
-        public updateColor4(name: string, color: Color3, alpha: number) {
-            if (this._noUbo) {
+        public updateColor4(name: string, color: Color3, alpha: number, suffix?: string | number) {
+            if (this._noUBO) {
                 if (this._currentEffect) {
-                    this._currentEffect.setColor4(name, color, alpha);
+                    this._currentEffect.setColor4(name + suffix, color, alpha);
                 }
                 return;
             }
-            color.toArray(_tempBuffer);
-            _tempBuffer[3] = alpha;
-            this.updateUniform(name, _tempBuffer, 4);
+            color.toArray(UniformBuffer._tempBuffer);
+            UniformBuffer._tempBuffer[3] = alpha;
+            this.updateUniform(name, UniformBuffer._tempBuffer, 4);
         }
 
         /**
@@ -562,7 +566,7 @@ module BABYLON {
         public bindToEffect(effect: Effect, name: string): void {
             this._currentEffect = effect;
 
-            if (this._noUbo) {
+            if (this._noUBO) {
                 return;
             }
             

+ 12 - 12
src/babylon.engine.ts

@@ -1311,9 +1311,9 @@
             this.bindUniformBuffer(ubo);
 
             if (elements instanceof Float32Array) {
-                this._gl.bufferData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, <Float32Array>elements, this._gl.STATIC_DRAW);
+                this._gl.bufferData(this._gl.UNIFORM_BUFFER, <Float32Array>elements, this._gl.STATIC_DRAW);
             } else {
-                this._gl.bufferData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, new Float32Array(<number[]>elements), this._gl.STATIC_DRAW);
+                this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(<number[]>elements), this._gl.STATIC_DRAW);
             }
 
             this.bindUniformBuffer(null);
@@ -1327,9 +1327,9 @@
             this.bindUniformBuffer(ubo);
 
             if (elements instanceof Float32Array) {
-                this._gl.bufferData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, <Float32Array>elements, this._gl.DYNAMIC_DRAW);
+                this._gl.bufferData(this._gl.UNIFORM_BUFFER, <Float32Array>elements, this._gl.DYNAMIC_DRAW);
             } else {
-                this._gl.bufferData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, new Float32Array(<number[]>elements), this._gl.DYNAMIC_DRAW);
+                this._gl.bufferData(this._gl.UNIFORM_BUFFER, new Float32Array(<number[]>elements), this._gl.DYNAMIC_DRAW);
             }
 
             this.bindUniformBuffer(null);
@@ -1347,15 +1347,15 @@
 
             if (count === undefined) {
                 if (elements instanceof Float32Array) {
-                    this._gl.bufferSubData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, offset, <Float32Array>elements);
+                    this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, <Float32Array>elements);
                 } else {
-                    this._gl.bufferSubData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, offset, new Float32Array(<number[]>elements));
+                    this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, offset, new Float32Array(<number[]>elements));
                 }
             } else {
                 if (elements instanceof Float32Array) {
-                    this._gl.bufferSubData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, 0, <Float32Array>elements.subarray(offset, offset + count));
+                    this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, <Float32Array>elements.subarray(offset, offset + count));
                 } else {
-                    this._gl.bufferSubData((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, 0, new Float32Array(<number[]>elements).subarray(offset, offset + count));
+                    this._gl.bufferSubData(this._gl.UNIFORM_BUFFER, 0, new Float32Array(<number[]>elements).subarray(offset, offset + count));
                 }
             }
 
@@ -1475,17 +1475,17 @@
         }
 
         public bindUniformBuffer(buffer?: WebGLBuffer): void {
-            this._gl.bindBuffer((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, buffer);
+            this._gl.bindBuffer(this._gl.UNIFORM_BUFFER, buffer);
         }
 
         public bindUniformBufferBase(buffer: WebGLBuffer, location: number): void {
-            (<WebGL2RenderingContext>this._gl).bindBufferBase((<WebGL2RenderingContext>this._gl).UNIFORM_BUFFER, location, buffer);
+            this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER, location, buffer);
         }
 
         public bindUniformBlock(shaderProgram: WebGLProgram, blockName: string, index: number): void {
-            var uniformLocation = (<WebGL2RenderingContext>this._gl).getUniformBlockIndex(shaderProgram, blockName);
+            var uniformLocation = this._gl.getUniformBlockIndex(shaderProgram, blockName);
 
-            (<WebGL2RenderingContext>this._gl).uniformBlockBinding(shaderProgram, uniformLocation, index);
+            this._gl.uniformBlockBinding(shaderProgram, uniformLocation, index);
         };
 
         private bindIndexBuffer(buffer: WebGLBuffer): void {

+ 6 - 0
src/babylon.mixins.ts

@@ -40,10 +40,16 @@ interface WebGLRenderingContext {
     blitFramebuffer(srcX0: number, srcY0: number, srcX1: number, srcY1: number, dstX0: number, dstY0: number, dstX1: number, dstY1: number, mask: number, filter: number): void;
     renderbufferStorageMultisample(target: number, samples: number, internalformat: number, width: number, height: number): void;
 
+    bindBufferBase(target: number, index: number, buffer: WebGLBuffer | null): void;
+    getUniformBlockIndex(program: WebGLProgram, uniformBlockName: string): number;
+    uniformBlockBinding(program: WebGLProgram, uniformBlockIndex: number, uniformBlockBinding: number): void;
+
     MAX_SAMPLES: number;
     RGBA8: number;
     READ_FRAMEBUFFER: number;
     DRAW_FRAMEBUFFER: number;
+    UNIFORM_BUFFER: number;
+
 }
 
 interface HTMLURL {