Skip to content

Commit

Permalink
fixed mask problems when resizing the viewPort while sharing the rend…
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimaryFeather committed May 11, 2016
1 parent 7a4d9e5 commit 3e3ef82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
24 changes: 9 additions & 15 deletions starling/src/starling/core/Starling.as
Expand Up @@ -44,6 +44,7 @@ package starling.core
import starling.events.TouchProcessor;
import starling.rendering.Painter;
import starling.utils.Align;
import starling.utils.RectangleUtil;
import starling.utils.SystemUtil;

/** Dispatched when a new render context is created. The 'data' property references the context. */
Expand Down Expand Up @@ -454,29 +455,22 @@ package starling.core
// the last set viewport is stored in a variable; that way, people can modify the
// viewPort directly (without a copy) and we still know if it has changed.

if (forceUpdate ||
_previousViewPort.width != _viewPort.width ||
_previousViewPort.height != _viewPort.height ||
_previousViewPort.x != _viewPort.x ||
_previousViewPort.y != _viewPort.y)
if (forceUpdate || !RectangleUtil.compare(_viewPort, _previousViewPort))
{
_previousViewPort.setTo(_viewPort.x, _viewPort.y, _viewPort.width, _viewPort.height);

// Constrained mode requires that the viewport is within the native stage bounds;
// thus, we use a clipped viewport when configuring the back buffer. (In baseline
// mode, that's not necessary, but it does not hurt either.)

_clippedViewPort = _viewPort.intersection(
new Rectangle(0, 0, _nativeStage.stageWidth, _nativeStage.stageHeight));

if (!shareContext)
{
var contentScaleFactor:Number =
_supportHighResolutions ? _nativeStage.contentsScaleFactor : 1.0;

_painter.configureBackBuffer(_clippedViewPort, contentScaleFactor,
_antiAliasing, true);
}
var contentScaleFactor:Number =
_supportHighResolutions ? _nativeStage.contentsScaleFactor : 1.0;

_painter.configureBackBuffer(_clippedViewPort, contentScaleFactor,
_antiAliasing, true);
}
}

Expand Down
37 changes: 22 additions & 15 deletions starling/src/starling/rendering/Painter.as
Expand Up @@ -186,6 +186,10 @@ package starling.rendering
/** Sets the viewport dimensions and other attributes of the rendering buffer.
* Starling will call this method internally, so most apps won't need to mess with this.
*
* <p>Beware: if <code>shareContext</code> is enabled, the method will only update the
* painter's context-related information (like the size of the back buffer), but won't
* make any actual changes to the context.</p>
*
* @param viewPort the position and size of the area that should be rendered
* into, in pixels.
* @param contentScaleFactor only relevant for Desktop (!) HiDPI screens. If you want
Expand All @@ -200,28 +204,31 @@ package starling.rendering
public function configureBackBuffer(viewPort:Rectangle, contentScaleFactor:Number,
antiAlias:int, enableDepthAndStencil:Boolean):void
{
enableDepthAndStencil &&= SystemUtil.supportsDepthAndStencil;
if (!_shareContext)
{
enableDepthAndStencil &&= SystemUtil.supportsDepthAndStencil;

// Changing the stage3D position might move the back buffer to invalid bounds
// temporarily. To avoid problems, we set it to the smallest possible size first.
// Changing the stage3D position might move the back buffer to invalid bounds
// temporarily. To avoid problems, we set it to the smallest possible size first.

if (_context.profile == "baselineConstrained")
_context.configureBackBuffer(32, 32, antiAlias, enableDepthAndStencil);
if (_context.profile == "baselineConstrained")
_context.configureBackBuffer(32, 32, antiAlias, enableDepthAndStencil);

// If supporting HiDPI mode would exceed the maximum buffer size
// (can happen e.g in software mode), we stick to the low resolution.
// If supporting HiDPI mode would exceed the maximum buffer size
// (can happen e.g in software mode), we stick to the low resolution.

if (viewPort.width * contentScaleFactor > _context.maxBackBufferWidth ||
viewPort.height * contentScaleFactor > _context.maxBackBufferHeight)
{
contentScaleFactor = 1.0;
}
if (viewPort.width * contentScaleFactor > _context.maxBackBufferWidth ||
viewPort.height * contentScaleFactor > _context.maxBackBufferHeight)
{
contentScaleFactor = 1.0;
}

_stage3D.x = viewPort.x;
_stage3D.y = viewPort.y;
_stage3D.x = viewPort.x;
_stage3D.y = viewPort.y;

_context.configureBackBuffer(viewPort.width, viewPort.height,
_context.configureBackBuffer(viewPort.width, viewPort.height,
antiAlias, enableDepthAndStencil, contentScaleFactor != 1.0);
}

_backBufferWidth = viewPort.width;
_backBufferHeight = viewPort.height;
Expand Down

2 comments on commit 3e3ef82

@DawnKing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's right.
And I test the blend mode, it's right too.

@PrimaryFeather
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks for trying it out!

Please sign in to comment.