Skip to content

Optimization: double vertex and index buffers usage during Stage.drawToBitmapData #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions starling/src/starling/core/Starling.as
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down Expand Up @@ -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 <code>shareContext</code>.*/
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();
Expand All @@ -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
Expand Down Expand Up @@ -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; }

Expand Down
26 changes: 14 additions & 12 deletions starling/src/starling/display/Stage.as
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down