From daac30c68e8844fb9bf04c67fd49c3975503ce46 Mon Sep 17 00:00:00 2001 From: Yaski Date: Thu, 17 May 2012 17:48:10 +0600 Subject: [PATCH] Call times of setProgram(), setBlendMode, setCulling() reduced --- src/alternativa/engine3d/core/Renderer.as | 16 +++++++++++++--- .../engine3d/core/RendererContext3DProperties.as | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/alternativa/engine3d/core/Renderer.as b/src/alternativa/engine3d/core/Renderer.as index 0dec821..27bb6af 100644 --- a/src/alternativa/engine3d/core/Renderer.as +++ b/src/alternativa/engine3d/core/Renderer.as @@ -121,8 +121,15 @@ package alternativa.engine3d.core { } protected function renderDrawUnit(drawUnit:DrawUnit, context:Context3D, camera:Camera3D):void { - context.setBlendFactors(drawUnit.blendSource, drawUnit.blendDestination); - context.setCulling(drawUnit.culling); + if (_contextProperties.blendSource != drawUnit.blendSource || _contextProperties.blendDestination != drawUnit.blendDestination) { + context.setBlendFactors(drawUnit.blendSource, drawUnit.blendDestination); + _contextProperties.blendSource = drawUnit.blendSource; + _contextProperties.blendDestination = drawUnit.blendDestination; + } + if (_contextProperties.culling != drawUnit.culling) { + context.setCulling(drawUnit.culling); + _contextProperties.culling = drawUnit.culling; + } var _usedBuffers:uint = _contextProperties.usedBuffers; var _usedTextures:uint = _contextProperties.usedTextures; @@ -152,7 +159,10 @@ package alternativa.engine3d.core { _usedTextures &= ~textureBit; context.setTextureAt(textureSampler, drawUnit.textures[i]); } - context.setProgram(drawUnit.program); + if (_contextProperties.program != drawUnit.program) { + context.setProgram(drawUnit.program); + _contextProperties.program = drawUnit.program; + } for (bufferIndex = 0; _usedBuffers > 0; bufferIndex++) { bufferBit = _usedBuffers & 1; _usedBuffers >>= 1; diff --git a/src/alternativa/engine3d/core/RendererContext3DProperties.as b/src/alternativa/engine3d/core/RendererContext3DProperties.as index c92353f..a92aad0 100644 --- a/src/alternativa/engine3d/core/RendererContext3DProperties.as +++ b/src/alternativa/engine3d/core/RendererContext3DProperties.as @@ -8,6 +8,8 @@ package alternativa.engine3d.core { + import flash.display3D.Program3D; + /** * @private * Stores settings of context. @@ -17,5 +19,10 @@ package alternativa.engine3d.core { public var usedBuffers:uint = 0; public var usedTextures:uint = 0; + public var program:Program3D; + public var culling:String; + public var blendSource:String; + public var blendDestination:String; + } }