Przeglądaj źródła

uniform buffers are now backwards compatible

Benjamin Guignabert 8 lat temu
rodzic
commit
3082b6c21b

Plik diff jest za duży
+ 847 - 843
dist/preview release/babylon.d.ts


Plik diff jest za duży
+ 847 - 843
dist/preview release/babylon.module.d.ts


+ 1 - 0
src/Lights/babylon.directionalLight.ts

@@ -48,6 +48,7 @@ module BABYLON {
              this._uniformBuffer.addUniform("vLightDiffuse", 4);
              this._uniformBuffer.addUniform("vLightSpecular", 3);
              this._uniformBuffer.addUniform("shadowsInfo", 3);
+             this._uniformBuffer.create();
         }
 
         /**

+ 1 - 0
src/Lights/babylon.hemisphericLight.ts

@@ -25,6 +25,7 @@
             this._uniformBuffer.addUniform("vLightSpecular", 3);
             this._uniformBuffer.addUniform("vLightGround", 3);
             this._uniformBuffer.addUniform("shadowsInfo", 3);
+            this._uniformBuffer.create();
         }
 
         /**

+ 1 - 0
src/Lights/babylon.pointLight.ts

@@ -33,6 +33,7 @@
             this._uniformBuffer.addUniform("vLightDiffuse", 4);
             this._uniformBuffer.addUniform("vLightSpecular", 3);
             this._uniformBuffer.addUniform("shadowsInfo", 3);
+            this._uniformBuffer.create();
         }
 
         /**

+ 1 - 0
src/Lights/babylon.spotLight.ts

@@ -49,6 +49,7 @@
             this._uniformBuffer.addUniform("vLightSpecular", 3);
             this._uniformBuffer.addUniform("vLightDirection", 3);
             this._uniformBuffer.addUniform("shadowsInfo", 3);
+            this._uniformBuffer.create();
         }
         
         /**

+ 4 - 3
src/Materials/babylon.effect.ts

@@ -425,12 +425,13 @@
 
                 this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
 
-                for (var i = 0; i < this._uniformBuffersNames.length; i++) {
-                    this.bindUniformBlock(this._uniformBuffersNames[i], i);
+                if (engine.webGLVersion > 1) {
+                    for (var i = 0; i < this._uniformBuffersNames.length; i++) {
+                        this.bindUniformBlock(this._uniformBuffersNames[i], i);
+                    }
                 }
 
                 this._uniforms = engine.getUniforms(this._program, this._uniformsNames);
-
                 this._attributes = engine.getAttributes(this._program, attributesNames);
 
                 var index: number;

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

@@ -308,6 +308,7 @@
             var depthValuesAlreadySet = false;
 
             for (var light of mesh._lightSources) {
+                light._uniformBuffer.bindToEffect(effect, "Light" + lightIndex);
 
                 MaterialHelper.BindLightProperties(light, effect, lightIndex);
 
@@ -323,7 +324,6 @@
                     depthValuesAlreadySet = this.BindLightShadow(light, scene, mesh, lightIndex, effect, depthValuesAlreadySet);
                 }
                 light._uniformBuffer.update();
-                effect.bindUniformBuffer(light._uniformBuffer.getBuffer(), "Light" + lightIndex);
                 lightIndex++;
 
                 if (lightIndex === maxSimultaneousLights)

+ 1 - 1
src/Materials/babylon.pushMaterial.ts

@@ -25,7 +25,7 @@
         }
 
         public bindTransformMatrix(effect: Effect, transformMatrixBuffer: UniformBuffer): void {
-            effect.bindUniformBuffer(transformMatrixBuffer.getBuffer(), "Scene");
+            transformMatrixBuffer.bindToEffect(effect, "Scene");
         }
 
         public bindOnlyWorldMatrix(world: Matrix): void {

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

@@ -780,6 +780,8 @@ module BABYLON {
             this._uniformBuffer.addUniform("vEmissiveColor", 3);
             this._uniformBuffer.addUniform("vDiffuseColor", 4);
             this._uniformBuffer.addUniform("pointSize", 1);
+
+            this._uniformBuffer.create();
         }
 
         public unbind(): void {
@@ -813,6 +815,8 @@ module BABYLON {
             // Bones
             MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._mustRebind(scene, effect)) {
+                this._uniformBuffer.bindToEffect(effect, "Material");
+                
                 if (!this.isFrozen || !this._uniformBuffer.isSync) {
 
                     if (StandardMaterial.FresnelEnabled && defines.FRESNEL) {
@@ -907,8 +911,6 @@ module BABYLON {
                     }
                     this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
                 }
-
-                effect.bindUniformBuffer(this._uniformBuffer.getBuffer(), "Material");
                 
                 // Textures     
                 if (scene.texturesEnabled) {

+ 58 - 2
src/Materials/babylon.uniformBuffer.ts

@@ -15,10 +15,12 @@ module BABYLON {
         private _uniformLocationPointer: number;
         private _needSync: boolean;
         private _cache: Float32Array;
+        private _noUbo: boolean;
+        private _currentEffect: Effect;
 
         constructor(engine: Engine, data?: number[], dynamic?: boolean) {
             this._engine = engine;
-
+            this._noUbo = engine.webGLVersion === 1;
             this._dynamic = dynamic;
 
             this._data = data || [];
@@ -27,8 +29,16 @@ module BABYLON {
             this._uniformSizes = {};
             this._uniformLocationPointer = 0;
             this._needSync = false;
+
+            if (this._noUbo) {
+                this._backPort();
+            }
         }
 
+        private _backPort(): void {
+            
+        }
+        
         public get isSync(): boolean {
             return !this._needSync;
         }
@@ -72,6 +82,10 @@ module BABYLON {
         }
 
         public addUniform(name: string, size: number | number[]) {
+            if (this._noUbo) {
+                return;
+            }
+
             if (this._uniformLocations[name] !== undefined) {
                 // Already existing uniform
                 return;
@@ -152,7 +166,7 @@ module BABYLON {
                 this._buffer = this._engine.createUniformBuffer(this._bufferData);
             }
 
-            this._needSync = false;
+            this._needSync = true;
         } 
 
         public update(): void {
@@ -207,17 +221,32 @@ module BABYLON {
         }
 
         public updateFloat(name: string, x: number) {
+            if (this._noUbo) {
+                this._currentEffect.setFloat(name, x);
+                return;
+            }
+
             _tempBuffer[0] = x;
             this.updateUniform(name, _tempBuffer, 1);
         }
 
         public updateFloat2(name: string, x: number, y: number) {
+            if (this._noUbo) {
+                this._currentEffect.setFloat2(name, x, y);
+                return;
+            }
+
             _tempBuffer[0] = x;
             _tempBuffer[1] = y;
             this.updateUniform(name, _tempBuffer, 2);
         }
 
         public updateFloat3(name: string, x: number, y: number, z: number) {
+            if (this._noUbo) {
+                this._currentEffect.setFloat3(name, x, y, z);
+                return;
+            }
+
             _tempBuffer[0] = x;
             _tempBuffer[1] = y;
             _tempBuffer[2] = z;
@@ -225,6 +254,11 @@ module BABYLON {
         }
 
         public updateFloat4(name: string, x: number, y: number, z: number, w: number) {
+            if (this._noUbo) {
+                this._currentEffect.setFloat4(name, x, y, z, w);
+                return;
+            }
+
             _tempBuffer[0] = x;
             _tempBuffer[1] = y;
             _tempBuffer[2] = z;
@@ -233,20 +267,37 @@ module BABYLON {
         }
 
         public updateMatrix(name: string, mat: Matrix) {
+            if (this._noUbo) {
+                this._currentEffect.setMatrix(name, mat);
+                return;
+            }
+
             this.updateUniform(name, mat.toArray(), 16);
         }
 
         public updateVector3(name: string, vector: Vector3) {
+            if (this._noUbo) {
+                this._currentEffect.setVector3(name, vector);
+                return;
+            }
             vector.toArray(_tempBuffer);
             this.updateUniform(name, _tempBuffer, 3);
         }
 
         public updateColor3(name: string, color: Color3) {
+            if (this._noUbo) {
+                this._currentEffect.setColor3(name, color);
+                return;
+            }
             color.toArray(_tempBuffer);
             this.updateUniform(name, _tempBuffer, 3);
         }
 
         public updateColor4(name: string, color: Color3, alpha: number) {
+            if (this._noUbo) {
+                this._currentEffect.setColor4(name, color, alpha);
+                return;
+            }
             color.toArray(_tempBuffer);
             _tempBuffer[3] = alpha;
             this.updateUniform(name, _tempBuffer, 4);
@@ -258,6 +309,11 @@ module BABYLON {
             this.update();
         }
 
+        public bindToEffect(effect: Effect, name: string): void {
+            this._currentEffect = effect;
+            effect.bindUniformBuffer(this._buffer, name);
+        }
+
         public dispose(): void {
             if (!this._buffer) {
                 return;