diff --git a/DebugInfos.js b/DebugInfos.js index e2d7561f31..f63a7c35b3 100644 --- a/DebugInfos.js +++ b/DebugInfos.js @@ -94,7 +94,7 @@ if (CC_DEV) { "1632": "Node name can not include \'/\'.", //name "1633": "Internal error, should not remove unknown node from parent.", //parent "1634": "addChild: The child to add must be instance of cc.Node, not %s.", //addChild - "1635": "reorderChild: this child is not in children list" // reorderChild + "1635": "reorderChild: this child is not in children list", // reorderChild //AtlasNode: 1700 "1700": "cc.AtlasNode.updateAtlasValues(): Shall be overridden in subclasses", //_updateAtlasValues "1701": "", //_initWithTileFile diff --git a/cocos2d/clipping-nodes/CCClippingNode.js b/cocos2d/clipping-nodes/CCClippingNode.js index f21ed70133..43adb4954c 100644 --- a/cocos2d/clipping-nodes/CCClippingNode.js +++ b/cocos2d/clipping-nodes/CCClippingNode.js @@ -57,24 +57,13 @@ cc.ClippingNode = _ccsg.Node.extend(/** @lends cc.ClippingNode# */{ ctor: function (stencil) { stencil = stencil || null; _ccsg.Node.prototype.ctor.call(this); - this.init(stencil); - }, - - /** - * Initialization of the node, please do not call this function by yourself, you should pass the parameters to constructor to initialize it. - * @function - * @param {_ccsg.Node} [stencil=null] - */ - init: function (stencil) { this._stencil = stencil; if (stencil) { this._originStencilProgram = stencil.getShaderProgram(); } - this.inverted = false; this.alphaThreshold = 1; + this.inverted = false; this._renderCmd.initStencilBits(); - - return true; }, /** @@ -133,6 +122,24 @@ cc.ClippingNode = _ccsg.Node.extend(/** @lends cc.ClippingNode# */{ _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; + }, + /** *
* The alpha threshold.
diff --git a/cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js b/cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
index 6f6f3d2431..7b5d1ecb31 100644
--- a/cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
+++ b/cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
@@ -25,6 +25,7 @@
//-------------------------- 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);
@@ -32,6 +33,8 @@ cc.ClippingNode.CanvasRenderCmd = function(renderable){
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){
@@ -40,16 +43,11 @@ proto.setStencil = function(stencil){
this._node._stencil = stencil;
- if (stencil instanceof cc.DrawNode) {
-
- }else{
+ if (!stencil instanceof cc.DrawNode) {
cc.errorID(6300);
}
};
-// should reset program used by _stencil
-proto.resetProgramByStencil = function () { };
-
proto._restoreCmdCallback = function (ctx) {
var wrapper = ctx || cc._renderContext;
wrapper.restore();
@@ -75,32 +73,32 @@ proto._drawStencilCommand = function (ctx, scaleX, scaleY) {
context.clip();
};
-proto.visit = function(parentCmd){
+proto.clippingVisit = function (parentCmd) {
var node = this._node;
+ parentCmd = parentCmd || this.getParentRenderCmd();
this._propagateFlagsDown(parentCmd);
// quick return if not visible
if (!node._visible)
return;
- parentCmd = parentCmd || this.getParentRenderCmd();
- if( parentCmd)
+ if (parentCmd)
this._curLevel = parentCmd._curLevel + 1;
this._syncStatus(parentCmd);
- if(this._node._stencil) {
+ if (node._stencil) {
cc.renderer.pushRenderCommand(this._rendererClipCmd);
}
- var i, children = node._children;
+ var children = node._children;
- var len = children.length;
+ var i, len = children.length;
if (len > 0) {
node.sortAllChildren();
for (i = 0; i < len; i++)
- children[i]._renderCmd.visit(this);
+ children[i].visit(node);
}
- if(this._node._stencil) {
+ if (node._stencil) {
cc.renderer.pushRenderCommand(this._rendererRestoreCmd);
}
this._dirtyFlag = 0;
-};
\ No newline at end of file
+};
diff --git a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
index 4e207a57b0..3703ad438d 100644
--- a/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
+++ b/cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js
@@ -36,6 +36,7 @@ function setProgram (node, program) {
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);
@@ -60,7 +61,7 @@ cc.ClippingNode.WebGLRenderCmd._init_once = null;
cc.ClippingNode.WebGLRenderCmd._visit_once = null;
cc.ClippingNode.WebGLRenderCmd._layer = -1;
-proto.initStencilBits = function(){
+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) {
@@ -71,34 +72,30 @@ proto.initStencilBits = function(){
}
};
-proto.transform = function(parentCmd, recursive){
+proto.transform = function (parentCmd, recursive) {
var node = this._node;
this.originTransform(parentCmd, recursive);
- if(node._stencil) {
- node._stencil._renderCmd.transform(this, recursive);
+ if (node._stencil) {
+ node._stencil._renderCmd.transform(this, true);
+ node._stencil._dirtyFlag &= ~_ccsg.Node._dirtyFlags.transformDirty;
}
};
-proto.visit = function(parentCmd){
+proto.clippingVisit = function (parentCmd) {
var node = this._node;
- this._propagateFlagsDown(parentCmd);
- // quick return if not visible
- if (!node._visible)
- return;
-
- if( node._parent && node._parent._renderCmd)
- this._curLevel = node._parent._renderCmd._curLevel + 1;
+ parentCmd = parentCmd || this.getParentRenderCmd();
+ this.visit(parentCmd);
// if stencil buffer disabled
if (cc.ClippingNode.stencilBits < 1) {
// draw everything, as if there where no stencil
- this.originVisit(parentCmd);
+ node._visitChildren();
return;
}
if (!node._stencil || !node._stencil.visible) {
if (node.inverted)
- this.originVisit(parentCmd); // draw everything
+ node._visitChildren(); // draw everything
return;
}
@@ -109,19 +106,13 @@ proto.visit = function(parentCmd){
cc.ClippingNode.WebGLRenderCmd._visit_once = false;
}
// draw everything, as if there were no stencil
- this.originVisit(parentCmd);
+ node._visitChildren();
return;
}
cc.renderer.pushRenderCommand(this._beforeVisitCmd);
- //optimize performance for javascript
- var currentStack = cc.current_stack;
- currentStack.stack.push(currentStack.top);
- this._syncStatus(parentCmd);
- currentStack.top = this._stackMatrix;
-
- node._stencil._renderCmd.visit(this);
+ node._stencil.visit(node);
cc.renderer.pushRenderCommand(this._afterDrawStencilCmd);
@@ -132,15 +123,13 @@ proto.visit = function(parentCmd){
node.sortAllChildren();
// draw children zOrder < 0
for (var i = 0; i < childLen; i++) {
- locChildren[i]._renderCmd.visit(this);
+ locChildren[i].visit(node);
}
}
cc.renderer.pushRenderCommand(this._afterVisitCmd);
this._dirtyFlag = 0;
- //optimize performance for javascript
- currentStack.top = currentStack.stack.pop();
};
proto.setStencil = function(stencil){
@@ -223,7 +212,7 @@ proto._onBeforeVisit = function(ctx){
}
};
-proto._onAfterDrawStencil = function(ctx){
+proto._onAfterDrawStencil = function (ctx) {
var gl = ctx || cc._renderContext;
gl.depthMask(this._currentDepthWriteMask);
@@ -231,7 +220,7 @@ proto._onAfterDrawStencil = function(ctx){
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
};
-proto._onAfterVisit = function(ctx){
+proto._onAfterVisit = function (ctx) {
var gl = ctx || cc._renderContext;
if (!this._currentStencilEnabled) {
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index d383194c92..e4a1ebbd97 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -289,7 +289,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
renderer.clearRenderCommands();
cc.renderer.assignedZ = 0;
this._runningScene._renderCmd._curLevel = 0; //level start from 0;
- this._runningScene._renderCmd.visit();
+ this._runningScene.visit();
renderer.resetFlag();
}
else if (renderer.transformDirty()) {
diff --git a/cocos2d/core/base-nodes/CCSGNode.js b/cocos2d/core/base-nodes/CCSGNode.js
index d0e52171ba..e280c6f988 100644
--- a/cocos2d/core/base-nodes/CCSGNode.js
+++ b/cocos2d/core/base-nodes/CCSGNode.js
@@ -129,6 +129,7 @@ _ccsg.Node = cc.Class({
_arrivalOrder: 0,
_reorderChildDirty: false,
_vertexZ: 0.0,
+ _customZ: undefined,
_rotationX: 0,
_rotationY: 0.0,
@@ -163,6 +164,7 @@ _ccsg.Node = cc.Class({
},
ctor: function() {
+ this.__instanceId = cc.ClassManager.getNewInstanceId();
this._renderCmd = this._createRenderCmd();
},
@@ -371,7 +373,7 @@ _ccsg.Node = cc.Class({
* @param {Number} Var
*/
setVertexZ: function (Var) {
- this._vertexZ = Var;
+ this._customZ = this._vertexZ = Var;
},
/**
@@ -1855,8 +1857,38 @@ _ccsg.Node = cc.Class({
* @function
* @param {_ccsg.Node.RenderCmd} parentCmd
*/
- visit: function(parentCmd){
- this._renderCmd.visit(parentCmd);
+ visit: function (parent) {
+ // quick return if not visible
+ if (!this._visible)
+ return;
+
+ var renderer = cc.renderer, cmd = this._renderCmd;
+ cmd.visit(parent && parent._renderCmd);
+
+ var i, children = this._children, len = children.length, child;
+ if (len > 0) {
+ if (this._reorderChildDirty) {
+ this.sortAllChildren();
+ }
+ // draw children zOrder < 0
+ for (i = 0; i < len; i++) {
+ child = children[i];
+ if (child._localZOrder < 0) {
+ child.visit(this);
+ }
+ else {
+ break;
+ }
+ }
+
+ renderer.pushRenderCommand(cmd);
+ for (; i < len; i++) {
+ children[i].visit(this);
+ }
+ } else {
+ renderer.pushRenderCommand(cmd);
+ }
+ cmd._dirtyFlag = 0;
},
/**
diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
index e09a9f9bd6..d6e3b9602b 100644
--- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
+++ b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
@@ -333,17 +333,12 @@ _ccsg.Node.RenderCmd.prototype = {
}
this._propagateFlagsDown(parentCmd);
- // quick return if not visible
- if (!node._visible)
- return;
-
if (isNaN(node._customZ)) {
node._vertexZ = renderer.assignedZ;
renderer.assignedZ += renderer.assignedZStep;
}
this._syncStatus(parentCmd);
- this.visitChildren();
},
_updateDisplayColor: function (parentColor) {
@@ -498,39 +493,12 @@ _ccsg.Node.RenderCmd.prototype = {
if (locFlag & dirtyFlags.transformDirty)
//update the transform
this.transform(parentCmd);
- },
-
- visitChildren: function(){
- var renderer = cc.renderer;
- var node = this._node;
- var i, children = node._children, child;
- var len = children.length;
- if (len > 0) {
- node.sortAllChildren();
- // draw children zOrder < 0
- for (i = 0; i < len; i++) {
- child = children[i];
- if (child._localZOrder < 0) {
- child._renderCmd.visit(this);
- }
- else {
- break;
- }
- }
-
- renderer.pushRenderCommand(this);
- for (; i < len; i++) {
- children[i]._renderCmd.visit(this);
- }
- } else {
- renderer.pushRenderCommand(this);
- }
- this._dirtyFlag = 0;
}
};
-_ccsg.Node.RenderCmd.prototype.originVisit = _ccsg.Node.RenderCmd.prototype.visit;
_ccsg.Node.RenderCmd.prototype.originTransform = _ccsg.Node.RenderCmd.prototype.transform;
+_ccsg.Node.RenderCmd.prototype.originUpdateStatus = _ccsg.Node.RenderCmd.prototype.updateStatus;
+_ccsg.Node.RenderCmd.prototype._originSyncStatus = _ccsg.Node.RenderCmd.prototype._syncStatus;
//-----------------------Canvas ---------------------------
diff --git a/cocos2d/particle/CCParticleBatchNode.js b/cocos2d/particle/CCParticleBatchNode.js
index f7cb63d76f..494dfaa965 100644
--- a/cocos2d/particle/CCParticleBatchNode.js
+++ b/cocos2d/particle/CCParticleBatchNode.js
@@ -140,6 +140,17 @@ cc.ParticleBatchNode = _ccsg.Node.extend(/** @lends cc.ParticleBatchNode# */{
return this.initWithTexture(tex, capacity);
},
+ visit: function (parent) {
+ // quick return if not visible
+ if (!this._visible)
+ return;
+
+ var cmd = this._renderCmd;
+ cmd.visit(parent && parent._renderCmd);
+ cc.renderer.pushRenderCommand(cmd);
+ cmd._dirtyFlag = 0;
+ },
+
/**
* Add a child into the cc.ParticleBatchNode
* @param {ccsg.ParticleSystem} child
diff --git a/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js b/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js
index df6385a079..108f809f43 100644
--- a/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js
+++ b/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js
@@ -27,6 +27,7 @@
*/
cc.ParticleBatchNode.CanvasRenderCmd = function(renderable){
this._rootCtor(renderable);
+ this._needDraw = false;
};
var proto = cc.ParticleBatchNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
diff --git a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
index e5a0cf82b2..f08f16ede3 100644
--- a/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
+++ b/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js
@@ -57,25 +57,3 @@ proto.rendering = function (ctx) {
proto._initWithTexture = function(){
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR);
};
-
-proto.visit = function(parentCmd){
- var node = this._node;
- // CAREFUL:
- // This visit is almost identical to _ccsg.Node#visit
- // with the exception that it doesn't call visit on it's children
- //
- // The alternative is to have a void _ccsg.Sprite#visit, but
- // although this is less mantainable, is faster
- //
- if (!node._visible)
- return;
-
- parentCmd = parentCmd || this.getParentRenderCmd();
- if (parentCmd)
- this._curLevel = parentCmd._curLevel + 1;
- this._syncStatus(parentCmd);
-
- cc.renderer.pushRenderCommand(this);
-
- this._dirtyFlag = 0;
-};
diff --git a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
index 146395ff0b..25112d3d2e 100644
--- a/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
+++ b/cocos2d/particle/CCSGParticleSystemCanvasRenderCmd.js
@@ -94,7 +94,7 @@ proto.getLocalBB = function() {
};
proto.updateStatus = function() {
- _ccsg.Node.CanvasRenderCmd.prototype.updateStatus.call(this);
+ this.originUpdateStatus();
this._updateCurrentRegions();
this._regionFlag = _ccsg.Node.CanvasRenderCmd.RegionStatus.DirtyDouble;
this._dirtyFlag &= ~_ccsg.Node._dirtyFlags.contentDirty;
diff --git a/cocos2d/render-texture/CCRenderTexture.js b/cocos2d/render-texture/CCRenderTexture.js
index f6df090e1e..b952e3c36d 100644
--- a/cocos2d/render-texture/CCRenderTexture.js
+++ b/cocos2d/render-texture/CCRenderTexture.js
@@ -43,26 +43,26 @@
* @property {cc.Color} clearColorVal - Clear color value, valid only when "autoDraw" is true.
*/
cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{
- sprite:null,
+ sprite: null,
- //
- //
Code for "auto" update
- // Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
- // They can be OR'ed. Valid when "autoDraw is YES.
Code for "auto" update
+ // Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
+ // They can be OR'ed. Valid when "autoDraw is YES.