Skip to content

Commit

Permalink
fixed that masking a filtered object with a clipRect did not work
Browse files Browse the repository at this point in the history
It worked with stencil masks, but the clipRect-fallback sometimes used the wrong bounds.
  • Loading branch information
PrimaryFeather committed Oct 11, 2016
1 parent bf41d75 commit 9e229e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 20 additions & 2 deletions starling/src/starling/filters/FilterHelper.as
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package starling.filters
import starling.textures.SubTexture;
import starling.textures.Texture;
import starling.utils.MathUtil;
import starling.utils.Pool;

use namespace starling_internal;

Expand All @@ -45,6 +46,7 @@ package starling.filters
private var _renderTarget:Texture;
private var _targetBounds:Rectangle;
private var _target:DisplayObject;
private var _clipRect:Rectangle;

// helpers
private var sRegion:Rectangle = new Rectangle();
Expand All @@ -66,6 +68,9 @@ package starling.filters
/** Purges the pool. */
public function dispose():void
{
Pool.putRectangle(_clipRect);
_clipRect = null;

purge();
}

Expand Down Expand Up @@ -184,9 +189,22 @@ package starling.filters

/** The render target that was active when the filter started processing. */
public function get renderTarget():Texture { return _renderTarget; }
public function set renderTarget(value:Texture):void
public function set renderTarget(value:Texture):void { _renderTarget = value; }

/** The clipping rectangle that was active when the filter started processing. */
public function get clipRect():Rectangle { return _clipRect; }
public function set clipRect(value:Rectangle):void
{
_renderTarget = value;
if (value)
{
if (_clipRect) _clipRect.copyFrom(value);
else _clipRect = Pool.getRectangle(value.x, value.y, value.width, value.height);
}
else if (_clipRect)
{
Pool.putRectangle(_clipRect);
_clipRect = null;
}
}

/** @inheritDoc */
Expand Down
7 changes: 6 additions & 1 deletion starling/src/starling/filters/FragmentFilter.as
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ package starling.filters
_helper.textureScale = Starling.contentScaleFactor * _resolution;
_helper.projectionMatrix3D = painter.state.projectionMatrix3D;
_helper.renderTarget = painter.state.renderTarget;
_helper.clipRect = painter.state.clipRect;
_helper.targetBounds = bounds;
_helper.target = _target;
_helper.start(numPasses, drawLastPassToBackBuffer);
Expand All @@ -242,6 +243,7 @@ package starling.filters
painter.cacheEnabled = false; // -> what follows should not be cached
painter.pushState();
painter.state.alpha = 1.0;
painter.state.clipRect = null;
painter.state.renderTarget = input;
painter.state.setProjectionMatrix(bounds.x, bounds.y,
input.root.width, input.root.height,
Expand All @@ -251,7 +253,6 @@ package starling.filters

painter.finishMeshBatch();
painter.state.setModelviewMatricesToIdentity();
painter.state.clipRect = null;

output = process(painter, _helper, input); // -> feed 'input' to actual filter code

Expand Down Expand Up @@ -318,6 +319,10 @@ package starling.filters
renderTarget = (helper as FilterHelper).renderTarget;
projectionMatrix = (helper as FilterHelper).projectionMatrix3D;
effect.textureSmoothing = _textureSmoothing;

// restore clipRect (projection matrix influences clipRect!)
painter.state.clipRect = (helper as FilterHelper).clipRect;
painter.state.projectionMatrix3D.copyFrom(projectionMatrix);
}

painter.state.renderTarget = renderTarget;
Expand Down

0 comments on commit 9e229e7

Please sign in to comment.