Remove CCClippingNode

This commit is contained in:
pandamicro
2017-12-14 17:24:27 +08:00
parent 49bf5d6eaf
commit 31686bbfd0
4 changed files with 0 additions and 588 deletions
-230
View File
@@ -1,230 +0,0 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011-2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies Inc.
Copyright (c) 2012 Pierre-David Bélanger
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/**
* <p>
* cc.ClippingNode is a subclass of ccsg.Node. <br/>
* It draws its content (children) clipped using a stencil. <br/>
* The stencil is an other ccsg.Node that will not be drawn. <br/>
* The clipping is done using the alpha part of the stencil (adjusted with an alphaThreshold).
* </p>
* @class
* @extends _ccsg.Node
* @param {_ccsg.Node} [stencil=null]
*
* @property {Number} alphaThreshold - Threshold for alpha value.
* @property {Boolean} inverted - Indicate whether in inverted mode.
* @property {_ccsg.Node} stencil - he ccsg.Node to use as a stencil to do the clipping.
*/
cc.ClippingNode = _ccsg.Node.extend(/** @lends cc.ClippingNode# */{
inverted: false,
_alphaThreshold: 0,
_stencil: null,
_className: "ClippingNode",
_originStencilProgram: null,
/**
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
* @param {_ccsg.Node} [stencil=null]
*/
ctor: function (stencil) {
stencil = stencil || null;
_ccsg.Node.prototype.ctor.call(this);
this._stencil = stencil;
if (stencil) {
this._originStencilProgram = stencil.getShaderProgram();
}
this.alphaThreshold = 1;
this.inverted = false;
this._renderCmd.initStencilBits();
},
/**
* <p>
* Event callback that is invoked every time when node enters the 'stage'. <br/>
* If the CCNode enters the 'stage' with a transition, this event is called when the transition starts. <br/>
* During onEnter you can't access a "sister/brother" node. <br/>
* If you override onEnter, you must call its parent's onEnter function with this._super().
* </p>
* @function
*/
onEnter: function () {
_ccsg.Node.prototype.onEnter.call(this);
if (this._stencil)
this._stencil.performRecursive(_ccsg.Node.performType.onEnter);
},
/**
* <p>
* Event callback that is invoked when the node enters in the 'stage'. <br/>
* If the node enters the 'stage' with a transition, this event is called when the transition finishes. <br/>
* If you override onEnterTransitionDidFinish, you shall call its parent's onEnterTransitionDidFinish with this._super()
* </p>
* @function
*/
onEnterTransitionDidFinish: function () {
_ccsg.Node.prototype.onEnterTransitionDidFinish.call(this);
if (this._stencil)
this._stencil.performRecursive(_ccsg.Node.performType.onEnterTransitionDidFinish);
},
/**
* <p>
* callback that is called every time the node leaves the 'stage'. <br/>
* If the node leaves the 'stage' with a transition, this callback is called when the transition starts. <br/>
* If you override onExitTransitionDidStart, you shall call its parent's onExitTransitionDidStart with this._super()
* </p>
* @function
*/
onExitTransitionDidStart: function () {
if (this._stencil) {
this._stencil.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
}
_ccsg.Node.prototype.onExitTransitionDidStart.call(this);
},
/**
* <p>
* callback that is called every time the node leaves the 'stage'. <br/>
* If the node leaves the 'stage' with a transition, this callback is called when the transition finishes. <br/>
* During onExit you can't access a sibling node. <br/>
* If you override onExit, you shall call its parent's onExit with this._super().
* </p>
* @function
*/
onExit: function () {
if (this._stencil) {
this._stencil.performRecursive(_ccsg.Node.performType.onExit);
}
_ccsg.Node.prototype.onExit.call(this);
},
visit: function (parent) {
this._renderCmd.clippingVisit(parent && parent._renderCmd);
},
_visitChildren: function () {
if (this._reorderChildDirty) {
this.sortAllChildren();
}
var children = this._children, child;
for (var i = 0, len = children.length; i < len; i++) {
child = children[i];
if (child && child._visible) {
child.visit(this);
}
}
this._renderCmd._dirtyFlag = 0;
},
/**
* <p>
* The alpha threshold. <br/>
* The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold. <br/>
* Should be a float between 0 and 1. <br/>
* This default to 1 (so alpha test is disabled).
* </P>
* @return {Number}
*/
getAlphaThreshold: function () {
return this._alphaThreshold;
},
/**
* set alpha threshold.
* @param {Number} alphaThreshold
*/
setAlphaThreshold: function (alphaThreshold) {
if (alphaThreshold === 1 && alphaThreshold !== this._alphaThreshold) {
// should reset program used by _stencil
this._renderCmd.resetProgramByStencil();
}
this._alphaThreshold = alphaThreshold;
},
/**
* <p>
* Inverted. If this is set to YES, <br/>
* the stencil is inverted, so the content is drawn where the stencil is NOT drawn. <br/>
* This default to NO.
* </p>
* @return {Boolean}
*/
isInverted: function () {
return this.inverted;
},
/**
* set whether or not invert of stencil
* @param {Boolean} inverted
*/
setInverted: function (inverted) {
this.inverted = inverted;
},
/**
* The ccsg.Node to use as a stencil to do the clipping. <br/>
* The stencil node will be retained. This default to nil.
* @return {_ccsg.Node}
*/
getStencil: function () {
return this._stencil;
},
/**
* Set stencil.
* @function
* @param {_ccsg.Node} stencil
*/
setStencil: function (stencil) {
if(this._stencil === stencil)
return;
if (stencil)
this._originStencilProgram = stencil.getShaderProgram();
this._renderCmd.setStencil(stencil);
},
_createRenderCmd: function(){
if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
return new cc.ClippingNode.CanvasRenderCmd(this);
else
return new cc.ClippingNode.WebGLRenderCmd(this);
}
});
cc.ClippingNode.stencilBits = -1;
var _p = cc.ClippingNode.prototype;
// Extended properties
cc.defineGetterSetter(_p, "stencil", _p.getStencil, _p.setStencil);
cc.defineGetterSetter(_p, "alphaThreshold", _p.getAlphaThreshold, _p.setAlphaThreshold);
@@ -1,106 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
require('../shape-nodes/CCDrawNode');
//-------------------------- ClippingNode's canvas render cmd --------------------------------
cc.ClippingNode.CanvasRenderCmd = function(renderable){
this._rootCtor(renderable);
this._needDraw = false;
this._rendererClipCmd = new cc.CustomRenderCmd(this, this._drawStencilCommand);
this._rendererRestoreCmd = new cc.CustomRenderCmd(this, this._restoreCmdCallback);
};
var proto = cc.ClippingNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
proto.constructor = cc.ClippingNode.CanvasRenderCmd;
proto.resetProgramByStencil = function () {};
proto.initStencilBits = function(){};
proto.setStencil = function(stencil){
if(stencil == null)
return;
this._node._stencil = stencil;
if (!(stencil instanceof cc.DrawNode)) {
cc.errorID(6300);
}
};
proto._restoreCmdCallback = function (ctx) {
var wrapper = ctx || cc._renderContext;
wrapper.restore();
};
proto._drawStencilCommand = function (ctx, scaleX, scaleY) {
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
wrapper.save();
context.beginPath(); //save for clip
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
//draw elements
var stencilBuffer = this._node._stencil._buffer;
for(var index = 0; index < stencilBuffer.length; ++index) {
var vertices = stencilBuffer[index].verts;
if(vertices.length < 3) continue;
context.moveTo(vertices[0].x, -vertices[0].y);
for(var vIndex = 1; vIndex < vertices.length; ++vIndex) {
context.lineTo(vertices[vIndex].x, -vertices[vIndex].y);
}
}
//end draw elements
context.clip();
};
proto.clippingVisit = function (parentCmd) {
var node = this._node;
parentCmd = parentCmd || this.getParentRenderCmd();
this._propagateFlagsDown(parentCmd);
// quick return if not visible
if (!node._visible)
return;
if (parentCmd)
this._curLevel = parentCmd._curLevel + 1;
this._syncStatus(parentCmd);
if (node._stencil) {
cc.renderer.pushRenderCommand(this._rendererClipCmd);
}
var children = node._children;
var i, len = children.length;
if (len > 0) {
node.sortAllChildren();
for (i = 0; i < len; i++)
children[i].visit(node);
}
if (node._stencil) {
cc.renderer.pushRenderCommand(this._rendererRestoreCmd);
}
this._dirtyFlag = 0;
};
@@ -1,249 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
require('../core/CCDrawingPrimitives');
// ------------------------------- ClippingNode's WebGL render cmd ------------------------------
function setProgram (node, program) {
node.shaderProgram = program;
var children = node.children;
if (!children)
return;
for (var i = 0; i < children.length; i++)
setProgram(children[i], program);
}
var _currentState = {
stencilEnabled: false,
depthWriteMask: true
};
cc.ClippingNode.WebGLRenderCmd = function(renderable){
this._rootCtor(renderable);
this._needDraw = false;
this._beforeVisitCmd = new cc.CustomRenderCmd(this, this._onBeforeVisit);
this._afterDrawStencilCmd = new cc.CustomRenderCmd(this, this._onAfterDrawStencil);
this._afterVisitCmd = new cc.CustomRenderCmd(this, this._onAfterVisit);
this._previousState = null;
this._state = {
stencilEnabled: true,
stencilWriteMask: 0,
depthWriteMask: false,
stencilFunc: 0,
stencilRef: 0,
stencilValueMask: 0
};
};
var proto = cc.ClippingNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
proto.constructor = cc.ClippingNode.WebGLRenderCmd;
cc.ClippingNode.WebGLRenderCmd._init_once = null;
cc.ClippingNode.WebGLRenderCmd._visit_once = null;
cc.ClippingNode.WebGLRenderCmd._layer = -1;
proto.initStencilBits = function () {
// get (only once) the number of bits of the stencil buffer
cc.ClippingNode.WebGLRenderCmd._init_once = true;
if (cc.ClippingNode.WebGLRenderCmd._init_once) {
cc.ClippingNode.stencilBits = cc._renderContext.getParameter(cc._renderContext.STENCIL_BITS);
if (cc.ClippingNode.stencilBits <= 0)
cc.logID(6301);
cc.ClippingNode.WebGLRenderCmd._init_once = false;
}
};
proto.transform = function (parentCmd, recursive) {
var node = this._node;
this.originTransform(parentCmd, recursive);
if (node._stencil) {
node._stencil._renderCmd.transform(this, true);
node._stencil._dirtyFlag &= ~_ccsg.Node._dirtyFlags.transformDirty;
}
};
proto.clippingVisit = function (parentCmd) {
var node = this._node;
parentCmd = parentCmd || this.getParentRenderCmd();
this.visit(parentCmd);
// if stencil buffer disabled
if (cc.ClippingNode.stencilBits < 1) {
// draw everything, as if there where no stencil
node._visitChildren();
return;
}
if (!node._stencil || !node._stencil.visible) {
if (node.inverted)
node._visitChildren(); // draw everything
return;
}
if (cc.ClippingNode.WebGLRenderCmd._layer + 1 === cc.ClippingNode.stencilBits) {
cc.ClippingNode.WebGLRenderCmd._visit_once = true;
if (cc.ClippingNode.WebGLRenderCmd._visit_once) {
cc.logID(6302, cc.ClippingNode.stencilBits);
cc.ClippingNode.WebGLRenderCmd._visit_once = false;
}
// draw everything, as if there were no stencil
node._visitChildren();
return;
}
cc.renderer.pushRenderCommand(this._beforeVisitCmd);
node._stencil.visit(node);
cc.renderer.pushRenderCommand(this._afterDrawStencilCmd);
// draw (according to the stencil test func) this node and its children
var locChildren = node._children;
if (locChildren && locChildren.length > 0) {
var childLen = locChildren.length;
node.sortAllChildren();
// draw children zOrder < 0
for (var i = 0; i < childLen; i++) {
locChildren[i].visit(node);
}
}
cc.renderer.pushRenderCommand(this._afterVisitCmd);
this._dirtyFlag = 0;
};
proto.setStencil = function(stencil){
var node = this._node;
if(node._stencil)
node._stencil._parent = null;
node._stencil = stencil;
if(node._stencil)
node._stencil._parent = node;
};
proto._drawFullScreenQuadClearStencil = function () {
// draw a fullscreen solid rectangle to clear the stencil buffer
var projStack = cc.math.projection_matrix_stack;
projStack.push();
projStack.top.identity();
var modelViewStack = cc.math.modelview_matrix_stack;
modelViewStack.push();
modelViewStack.top.identity();
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
projStack.pop();
modelViewStack.pop();
};
// should reset program used by _stencil
proto.resetProgramByStencil = function () {
var node = this._node;
if (node._stencil) {
var program = node._originStencilProgram;
setProgram(node._stencil, program);
}
};
proto._onBeforeVisit = function(ctx){
var gl = ctx || cc._renderContext, node = this._node;
cc.ClippingNode.WebGLRenderCmd._layer++;
// mask of the current layer (ie: for layer 3: 00000100)
var mask_layer = 0x1 << cc.ClippingNode.WebGLRenderCmd._layer;
// mask of all layers less than the current (ie: for layer 3: 00000011)
var mask_layer_l = mask_layer - 1;
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
var mask_layer_le = mask_layer | mask_layer_l;
// manually save the stencil state
this._previousState = _currentState;
// enable stencil use
gl.enable(gl.STENCIL_TEST);
gl.stencilMask(mask_layer);
gl.depthMask(false);
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
gl.stencilOp(!this._node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP);
this._drawFullScreenQuadClearStencil();
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
gl.stencilOp(!this._node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
if (node.alphaThreshold < 1) { //TODO desktop
var program = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
// set our alphaThreshold
cc.gl.useProgram(program.getProgram());
program.setUniformLocationWith1f(cc.macro.UNIFORM_ALPHA_TEST_VALUE_S, node.alphaThreshold);
program.setUniformLocationWithMatrix4fv(cc.macro.UNIFORM_MVMATRIX_S, cc.renderer.mat4Identity.mat);
setProgram(node._stencil, program);
}
// Save the current stencil states
this._state.stencilWriteMask = mask_layer;
this._state.stencilRef = this._state.stencilValueMask = mask_layer_le;
this._state.stencilFunc = gl.NEVER;
_currentState = this._state;
};
proto._onAfterDrawStencil = function (ctx) {
var gl = ctx || cc._renderContext;
gl.depthMask(this._previousState.depthWriteMask);
gl.stencilFunc(gl.EQUAL, this._state.stencilRef, this._state.stencilValueMask);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
this._state.stencilFunc = gl.EQUAL;
};
proto._onAfterVisit = function (ctx) {
var gl = ctx || cc._renderContext;
var state = this._previousState;
if (!state.stencilEnabled) {
gl.disable(gl.STENCIL_TEST);
}
else {
gl.stencilFunc(state.stencilFunc, state.stencilRef, state.stencilValueMask);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
gl.stencilMask(state.stencilWriteMask);
}
// restore _currentState, so self states won't affect other nodes any longer
_currentState = this._previousState;
this._previousState = null;
// we are done using this layer, decrement
cc.ClippingNode.WebGLRenderCmd._layer--;
};
-3
View File
@@ -62,9 +62,6 @@ var jsbSkipModules = [
'../../cocos2d/core/graphics/helper.js',
'../../cocos2d/audio/CCAudio',
'../../cocos2d/shape-nodes/CCDrawNode.js',
'../../cocos2d/clipping-nodes/CCClippingNode.js',
'../../cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js',
'../../cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js',
'../../cocos2d/particle/CCSGParticleSystem.js',
'../../cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js',
'../../cocos2d/particle/CCSGParticleSystemWebGLRenderCmd.js',