Просмотр исходного кода

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

This reverts commit 4273f46f7b69f9b57dcd5cd362a69f5a7fa4c6f6.
Scott Ramsby 7 лет назад
Родитель
Сommit
231c5e1d3a

Разница между файлами не показана из-за своего большого размера
+ 144 - 239
src/Engine/babylon.engine.ts


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

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

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

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

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

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