浏览代码

Refactor engine state application code to call back into Engine for WebGL calls

Scott Ramsby 7 年之前
父节点
当前提交
4273f46f7b

文件差异内容过多而无法显示
+ 239 - 144
src/Engine/babylon.engine.ts


+ 5 - 11
src/States/babylon.alphaCullingState.ts

@@ -107,38 +107,32 @@
             this._isBlendConstantsDirty = false;
         }
 
-        public apply(gl: WebGLRenderingContext) {
-
+        public apply(engine: Engine) {
             if (!this.isDirty) {
                 return;
             }
 
             // Alpha blend
             if (this._isAlphaBlendDirty) {
-                if (this._alphaBlend) {
-                    gl.enable(gl.BLEND);
-                } else {
-                    gl.disable(gl.BLEND);
-                }
-
+                engine._applyAlphaBlend(this._alphaBlend);
                 this._isAlphaBlendDirty = false;
             }
 
             // Alpha function
             if (this._isBlendFunctionParametersDirty) {
-                gl.blendFuncSeparate(<number>this._blendFunctionParameters[0], <number>this._blendFunctionParameters[1], <number>this._blendFunctionParameters[2], <number>this._blendFunctionParameters[3]);
+                engine._applAlphaBlendFunctionParameters(this._blendFunctionParameters)
                 this._isBlendFunctionParametersDirty = false;
             }
 
             // Alpha equation
             if (this._isBlendEquationParametersDirty) {
-                gl.blendEquationSeparate((<any>this._isBlendEquationParametersDirty)[0], (<any>this._isBlendEquationParametersDirty)[1]);
+                engine._applyAlphaEquationParameters(this._blendEquationParameters);
                 this._isBlendEquationParametersDirty = false;
             }
 
             // Constants
             if (this._isBlendConstantsDirty) {
-                gl.blendColor(<number>this._blendConstants[0], <number>this._blendConstants[1], <number>this._blendConstants[2], <number>this._blendConstants[3]);
+                engine._applyAlphaBlendConstants(this._blendConstants);
                 this._isBlendConstantsDirty = false;
             }
         }

+ 8 - 25
src/States/babylon.depthCullingState.ts

@@ -139,66 +139,49 @@
             this._isFrontFaceDirty = false;
         }
 
-        public apply(gl: WebGLRenderingContext) {
-
+        public apply(engine: Engine) {
             if (!this.isDirty) {
                 return;
             }
 
             // Cull
             if (this._isCullDirty) {
-                if (this.cull) {
-                    gl.enable(gl.CULL_FACE);
-                } else {
-                    gl.disable(gl.CULL_FACE);
-                }
-
+                engine._applyCull(this.cull);
                 this._isCullDirty = false;
             }
 
             // Cull face
             if (this._isCullFaceDirty) {
-                gl.cullFace(<number>this.cullFace);
+                engine._applyCullFace(this.cullFace);
                 this._isCullFaceDirty = false;
             }
 
             // Depth mask
             if (this._isDepthMaskDirty) {
-                gl.depthMask(this.depthMask);
+                engine._applyDepthMask(this.depthMask);
                 this._isDepthMaskDirty = false;
             }
 
             // Depth test
             if (this._isDepthTestDirty) {
-                if (this.depthTest) {
-                    gl.enable(gl.DEPTH_TEST);
-                } else {
-                    gl.disable(gl.DEPTH_TEST);
-                }
+                engine._applyDepthTest(this.depthTest);
                 this._isDepthTestDirty = false;
             }
 
             // Depth func
             if (this._isDepthFuncDirty) {
-                gl.depthFunc(<number>this.depthFunc);
-                this._isDepthFuncDirty = false;
+                engine._applyDepthFunc(this.depthFunc);
             }
 
             // zOffset
             if (this._isZOffsetDirty) {
-                if (this.zOffset) {
-                    gl.enable(gl.POLYGON_OFFSET_FILL);
-                    gl.polygonOffset(this.zOffset, 0);
-                } else {
-                    gl.disable(gl.POLYGON_OFFSET_FILL);
-                }
-
+                engine._applyZOffset(this.zOffset);
                 this._isZOffsetDirty = false;
             }
 
             // Front face
             if (this._isFrontFaceDirty) {
-                gl.frontFace(<number>this.frontFace);
+                engine._applyFrontFace(this.frontFace);
                 this._isFrontFaceDirty = false;
             }
         }

+ 5 - 9
src/States/babylon.stencilState.ts

@@ -150,36 +150,32 @@
             this._isStencilOpDirty = true;
         }
 
-        public apply(gl: WebGLRenderingContext) {
+        public apply(engine: Engine) {
             if (!this.isDirty) {
                 return;
             }
 
             // Stencil test
             if (this._isStencilTestDirty) {
-                if (this.stencilTest) {
-                    gl.enable(gl.STENCIL_TEST);
-                } else {
-                    gl.disable(gl.STENCIL_TEST);
-                }
+                engine._applyStencilTest(this.stencilTest);
                 this._isStencilTestDirty = false;
             }
 
             // Stencil mask
             if (this._isStencilMaskDirty) {
-                gl.stencilMask(this.stencilMask);
+                engine._applyStencilMask(this.stencilMask);
                 this._isStencilMaskDirty = false;
             }
 
             // Stencil func
             if (this._isStencilFuncDirty) {
-                gl.stencilFunc(this.stencilFunc, this.stencilFuncRef, this.stencilFuncMask);
+                engine._applyStencilFunc(this.stencilFunc, this.stencilFuncRef, this.stencilFuncMask)
                 this._isStencilFuncDirty = false;
             }
 
             // Stencil op
             if (this._isStencilOpDirty) {
-                gl.stencilOp(this.stencilOpStencilFail, this.stencilOpDepthFail, this.stencilOpStencilDepthPass);
+                engine._applyStencilOp(this.stencilOpStencilFail, this.stencilOpDepthFail, this.stencilOpStencilDepthPass);
                 this._isStencilOpDirty = false;
             }
         }