Fix stencil inverted rendering issue (#3200)

This commit is contained in:
pandamicro
2018-09-05 18:43:59 +08:00
committed by GitHub
parent 6f15658efe
commit 2461c0f8cf
2 changed files with 18 additions and 14 deletions
@@ -35,6 +35,7 @@ const graphicsAssembler = require('./graphics');
let _stencilMgr = StencilManager.sharedManager;
// for nested mask, we might need multiple graphics component to avoid data conflict
let _graphicsPool = [];
let _graphicsUsing = [];
function getGraphics () {
let graphics = _graphicsPool.pop();
@@ -117,9 +118,17 @@ let maskEndAssembler = {
if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) {
// HACK: Must pop mask after batch, so we can only put this logic in fillBuffers
_stencilMgr.exitMask();
_graphicsPool.push(mask._clearGraphics);
_graphicsUsing.push(mask._clearGraphics);
mask._clearGraphics = null;
// Clear graphics can only be recycled after the mask stack exits entirely.
if (_stencilMgr.stage === StencilManager.Stage.DISABLED) {
for (let i = 0; i < _graphicsUsing.length; i++) {
_graphicsPool.push(_graphicsUsing[i]);
}
_graphicsUsing.length = 0;
}
}
mask.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
+7 -12
View File
@@ -77,37 +77,32 @@ StencilManager.prototype = {
zPassOp = gfx.STENCIL_OP_KEEP;
if (this.stage === Stage.ENABLED) {
func = gfx.DS_FUNC_EQUAL;
mask = this._maskStack[this._maskStack.length - 1];
if (mask.inverted) {
ref = this.getInvertedRef();
stencilMask = this.getStencilRef();
}
else {
ref = this.getStencilRef();
stencilMask = ref;
}
func = gfx.DS_FUNC_EQUAL;
failOp = gfx.STENCIL_OP_KEEP;
ref = this.getStencilRef();
stencilMask = ref;
writeMask = this.getWriteMask();
}
else {
if (this.stage === Stage.CLEAR) {
mask = this._maskStack[this._maskStack.length - 1];
func = gfx.DS_FUNC_NEVER;
failOp = mask.inverted ? gfx.STENCIL_OP_REPLACE : gfx.STENCIL_OP_ZERO;
ref = this.getWriteMask();
stencilMask = ref;
writeMask = ref;
failOp = mask.inverted ? gfx.STENCIL_OP_REPLACE : gfx.STENCIL_OP_ZERO;
}
else if (this.stage === Stage.ENTER_LEVEL) {
mask = this._maskStack[this._maskStack.length - 1];
this.stage = Stage.ENABLED;
// Fill stencil mask
func = gfx.DS_FUNC_NEVER;
failOp = mask.inverted ? gfx.STENCIL_OP_ZERO : gfx.STENCIL_OP_REPLACE;
ref = this.getWriteMask();
stencilMask = ref;
writeMask = ref;
failOp = mask.inverted ? gfx.STENCIL_OP_ZERO : gfx.STENCIL_OP_REPLACE;
this.stage = Stage.ENABLED;
}
}