From bb5e1fcbbb84f86ba37b1381b00fbb5df205dc96 Mon Sep 17 00:00:00 2001 From: stepan-beresnev Date: Tue, 4 Nov 2014 12:31:16 +0000 Subject: [PATCH] Optimization: double vertex and index buffers usage during Stage.drawToBitmapData --- starling/src/starling/core/Starling.as | 36 +++++++++++++++++--------- starling/src/starling/display/Stage.as | 26 ++++++++++--------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/starling/src/starling/core/Starling.as b/starling/src/starling/core/Starling.as index ae884a7af..a8fff444c 100644 --- a/starling/src/starling/core/Starling.as +++ b/starling/src/starling/core/Starling.as @@ -52,6 +52,8 @@ package starling.core import starling.utils.VAlign; import starling.utils.execute; + use namespace starling_internal; + /** Dispatched when a new render context is created. The 'data' property references the context. */ [Event(name="context3DCreate", type="starling.events.Event")] @@ -486,9 +488,27 @@ package starling.core /** Renders the complete display list. Before rendering, the context is cleared; afterwards, * it is presented. This can be avoided by enabling shareContext.*/ public function render():void + { + if (prerender()) + { + if (!mShareContext) + RenderSupport.clear(mStage.color, 1.0); + + mStage.render(mSupport, 1.0); + mSupport.finishQuadBatch(); + + if (mStatsDisplay) + mStatsDisplay.drawCount = mSupport.drawCount; + + if (!mShareContext) + mContext.present(); + } + } + + starling_internal function prerender():Boolean { if (!contextValid) - return; + return false; makeCurrent(); updateViewPort(); @@ -509,17 +529,7 @@ package starling.core mClippedViewPort.height / scaleY, mStage.stageWidth, mStage.stageHeight, mStage.cameraPosition); - if (!mShareContext) - RenderSupport.clear(mStage.color, 1.0); - - mStage.render(mSupport, 1.0); - mSupport.finishQuadBatch(); - - if (mStatsDisplay) - mStatsDisplay.drawCount = mSupport.drawCount; - - if (!mShareContext) - mContext.present(); + return true; } private function updateViewPort(forceUpdate:Boolean=false):void @@ -1014,6 +1024,8 @@ package starling.core } } + starling_internal function get support():RenderSupport { return mSupport; } + /** The Starling stage object, which is the root of the display tree that is rendered. */ public function get stage():Stage { return mStage; } diff --git a/starling/src/starling/display/Stage.as b/starling/src/starling/display/Stage.as index a6d8b45db..cae203f95 100644 --- a/starling/src/starling/display/Stage.as +++ b/starling/src/starling/display/Stage.as @@ -123,23 +123,25 @@ package starling.display public function drawToBitmapData(destination:BitmapData=null, transparent:Boolean=true):BitmapData { - var support:RenderSupport = new RenderSupport(); var star:Starling = Starling.current; + var prendered:Boolean = star.prerender(); if (destination == null) destination = new BitmapData(star.backBufferWidth, star.backBufferHeight, transparent); - support.renderTarget = null; - support.setProjectionMatrix(0, 0, mWidth, mHeight, mWidth, mHeight, cameraPosition); - - if (transparent) support.clear(); - else support.clear(mColor, 1); - - render(support, 1.0); - support.finishQuadBatch(); - - Starling.current.context.drawToBitmapData(destination); - Starling.current.context.present(); // required on some platforms to avoid flickering + if (prendered) + { + var support:RenderSupport = star.support; + + if (transparent) support.clear(); + else support.clear(mColor, 1); + + render(support, 1.0); + support.finishQuadBatch(); + + star.context.drawToBitmapData(destination); + star.context.present(); // required on some platforms to avoid flickering + } return destination; }