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.

- // @public - // - clearFlags:0, + // + //

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.

+ // @public + // + clearFlags: 0, - clearDepthVal:0, - autoDraw:false, + clearDepthVal: 0, + autoDraw: false, - _texture:null, - _pixelFormat:0, + _texture: null, + _pixelFormat: 0, - clearStencilVal:0, - _clearColor:null, + clearStencilVal: 0, + _clearColor: null, - _className:"RenderTexture", + _className: "RenderTexture", /** * creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid @@ -81,28 +81,41 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ this._cascadeColorEnabled = true; this._cascadeOpacityEnabled = true; this._pixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888; - this._clearColor = new cc.Color(0,0,0,255); + this._clearColor = new cc.Color(0, 0, 0, 255); - if(width !== undefined && height !== undefined) { + if (width !== undefined && height !== undefined) { format = format || cc.Texture2D.PIXEL_FORMAT_RGBA8888; depthStencilFormat = depthStencilFormat || 0; this.initWithWidthAndHeight(width, height, format, depthStencilFormat); } - this.setAnchorPoint(0,0); + this.setAnchorPoint(0, 0); }, - _createRenderCmd: function(){ - if(cc._renderType === cc.game.RENDER_TYPE_CANVAS) + _createRenderCmd: function () { + if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) return new cc.RenderTexture.CanvasRenderCmd(this); else return new cc.RenderTexture.WebGLRenderCmd(this); }, + visit: function (parent) { + // quick return if not visible + if (!this._visible) + return; + + var renderer = cc.renderer, cmd = this._renderCmd; + + cmd.visit(parent && parent._renderCmd); + renderer.pushRenderCommand(cmd); + this.sprite.visit(this); + cmd._dirtyFlag = 0; + }, + /** * Clear RenderTexture. * @function */ - cleanup: function(){ + cleanup: function () { _ccsg.Node.prototype.onExit.call(this); this._renderCmd.cleanup(); }, @@ -111,7 +124,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Gets the sprite * @return {_ccsg.Sprite} */ - getSprite:function () { + getSprite: function () { return this.sprite; }, @@ -119,7 +132,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Set the sprite * @param {_ccsg.Sprite} sprite */ - setSprite:function (sprite) { + setSprite: function (sprite) { this.sprite = sprite; }, @@ -129,8 +142,8 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Rect} fullRect * @param {Rect} fullViewport */ - setVirtualViewport: function(rtBegin, fullRect, fullViewport){ - this._renderCmd.setVirtualViewport(rtBegin, fullRect, fullViewport); + setVirtualViewport: function (rtBegin, fullRect, fullViewport) { + this._renderCmd.setVirtualViewport(rtBegin, fullRect, fullViewport); }, /** @@ -142,7 +155,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Number} [depthStencilFormat] * @return {Boolean} */ - initWithWidthAndHeight: function(width, height, format, depthStencilFormat){ + initWithWidthAndHeight: function (width, height, format, depthStencilFormat) { return this._renderCmd.initWithWidthAndHeight(width, height, format, depthStencilFormat); }, @@ -150,7 +163,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * starts grabbing * @function */ - begin: function(){ + begin: function () { cc.renderer._turnToCacheMode(this.__instanceId); this._renderCmd.begin(); }, @@ -164,16 +177,16 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Number} [depthValue=] * @param {Number} [stencilValue=] */ - beginWithClear:function (r, g, b, a, depthValue, stencilValue) { + beginWithClear: function (r, g, b, a, depthValue, stencilValue) { //todo: only for WebGL? var gl = cc._renderContext; depthValue = depthValue || gl.COLOR_BUFFER_BIT; stencilValue = stencilValue || (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); - this._beginWithClear(r , g , b , a , depthValue, stencilValue, (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)); + this._beginWithClear(r, g, b, a, depthValue, stencilValue, (gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)); }, - _beginWithClear: function(r, g, b, a, depthValue, stencilValue, flags){ + _beginWithClear: function (r, g, b, a, depthValue, stencilValue, flags) { this.begin(); this._renderCmd._beginWithClear(r, g, b, a, depthValue, stencilValue, flags); }, @@ -182,7 +195,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * ends grabbing * @function */ - end: function(){ + end: function () { this._renderCmd.end(); }, @@ -193,7 +206,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Number} b blue 0-1 * @param {Number} a alpha 0-1 */ - clear:function (r, g, b, a) { + clear: function (r, g, b, a) { this.beginWithClear(r, g, b, a); this.end(); }, @@ -206,7 +219,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {number} width * @param {number} height */ - clearRect: function(x, y, width, height){ + clearRect: function (x, y, width, height) { this._renderCmd.clearRect(x, y, width, height); }, @@ -215,7 +228,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @function * @param {Number} depthValue */ - clearDepth: function(depthValue){ + clearDepth: function (depthValue) { this._renderCmd.clearDepth(depthValue); }, @@ -224,7 +237,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @function * @param {Number} stencilValue */ - clearStencil: function(stencilValue) { + clearStencil: function (stencilValue) { this._renderCmd.clearStencil(stencilValue); }, @@ -232,7 +245,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Valid flags: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT. They can be OR'ed. Valid when "autoDraw is YES. * @return {Number} */ - getClearFlags:function () { + getClearFlags: function () { return this.clearFlags; }, @@ -240,7 +253,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Set the clearFlags * @param {Number} clearFlags */ - setClearFlags:function (clearFlags) { + setClearFlags: function (clearFlags) { this.clearFlags = clearFlags; }, @@ -249,16 +262,16 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @function * @return {cc.Color} */ - getClearColor:function () { + getClearColor: function () { return this._clearColor; }, - /** - * Set the clear color value. Valid only when "autoDraw" is true. - * @function - * @param {cc.Color} clearColor The clear color - */ - setClearColor: function(clearColor){ + /** + * Set the clear color value. Valid only when "autoDraw" is true. + * @function + * @param {cc.Color} clearColor The clear color + */ + setClearColor: function (clearColor) { var locClearColor = this._clearColor; locClearColor.r = clearColor.r; locClearColor.g = clearColor.g; @@ -271,7 +284,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Value for clearDepth. Valid only when autoDraw is true. * @return {Number} */ - getClearDepth:function () { + getClearDepth: function () { return this.clearDepthVal; }, @@ -279,7 +292,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Set value for clearDepth. Valid only when autoDraw is true. * @param {Number} clearDepth */ - setClearDepth:function (clearDepth) { + setClearDepth: function (clearDepth) { this.clearDepthVal = clearDepth; }, @@ -287,7 +300,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Value for clear Stencil. Valid only when autoDraw is true * @return {Number} */ - getClearStencil:function () { + getClearStencil: function () { return this.clearStencilVal; }, @@ -295,25 +308,25 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Set value for clear Stencil. Valid only when autoDraw is true * @return {Number} */ - setClearStencil:function (clearStencil) { + setClearStencil: function (clearStencil) { this.clearStencilVal = clearStencil; }, /** - * When enabled, it will render its children into the texture automatically. Disabled by default for compatiblity reasons.
+ * When enabled, it will render its children into the texture automatically. Disabled by default for compatibility reasons.
* Will be enabled in the future. * @return {Boolean} */ - isAutoDraw:function () { + isAutoDraw: function () { return this.autoDraw; }, /** - * When enabled, it will render its children into the texture automatically. Disabled by default for compatiblity reasons.
+ * When enabled, it will render its children into the texture automatically. Disabled by default for compatibility reasons.
* Will be enabled in the future. * @return {Boolean} */ - setAutoDraw:function (autoDraw) { + setAutoDraw: function (autoDraw) { this.autoDraw = autoDraw; }, @@ -325,7 +338,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * @param {Number} filePath * @param {Number} format */ - saveToFile:function (filePath, format) { + saveToFile: function (filePath, format) { cc.log("saveToFile isn't supported on Cocos2d-Html5"); }, @@ -333,7 +346,7 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * creates a new CCImage from with the texture's data. Caller is responsible for releasing it by calling delete. * @return {*} */ - newCCImage:function(flipImage){ + newCCImage: function (flipImage) { cc.log("saveToFile isn't supported on cocos2d-html5"); return null; }, @@ -342,13 +355,15 @@ cc.RenderTexture = _ccsg.Node.extend(/** @lends cc.RenderTexture# */{ * Listen "come to background" message, and save render texture. It only has effect on Android. * @param {cc._Class} obj */ - listenToBackground:function (obj) { }, + listenToBackground: function (obj) { + }, /** * Listen "come to foreground" message and restore the frame buffer object. It only has effect on Android. * @param {cc._Class} obj */ - listenToForeground:function (obj) { } + listenToForeground: function (obj) { + } }); var _p = cc.RenderTexture.prototype; diff --git a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js index 1271c845c4..71e1262f75 100644 --- a/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js @@ -86,6 +86,8 @@ proto.end = function(){ var node = this._node; cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId); + var spriteRenderCmd = node.sprite._renderCmd; + spriteRenderCmd._notifyRegionStatus && spriteRenderCmd._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty); }; proto.clearRect = function(x, y, width, height){ @@ -95,10 +97,3 @@ proto.clearRect = function(x, y, width, height){ proto.clearDepth = function(depthValue){ cc.log("clearDepth isn't supported on Cocos2d-Html5"); }; - -proto.visit = function(parentCmd){ - var node = this._node; - this._syncStatus(parentCmd); - node.sprite.visit(this); - this._dirtyFlag = 0; -}; \ No newline at end of file diff --git a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js index d4c031afbc..b348095b6a 100644 --- a/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js +++ b/cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js @@ -101,7 +101,7 @@ proto.rendering = function (ctx) { for (var i = 0; i < locChildren.length; i++) { var getChild = locChildren[i]; if (getChild !== node.sprite){ - getChild._renderCmd.visit(node.sprite._renderCmd); //TODO it's very Strange + getChild.visit(node.sprite); //TODO it's very Strange } } node.end(); @@ -363,29 +363,3 @@ proto.clearDepth = function(depthValue){ gl.clearDepth(depthClearValue); node.end(); }; - -proto.visit = function(parentCmd){ - var node = this._node; - if (!node._visible) - return; - cc.kmGLPushMatrix(); - - //TODO using GridNode - /* var locGrid = this.grid; - if (locGrid && locGrid.isActive()) { - locGrid.beforeDraw(); - this.transformAncestors(); - }*/ - - this._syncStatus(parentCmd); - //this.toRenderer(); - cc.renderer.pushRenderCommand(this); - node.sprite.visit(this); - - //TODO GridNode - /* if (locGrid && locGrid.isActive()) - locGrid.afterDraw(this);*/ - - this._dirtyFlag = 0; - cc.math.glPopMatrix(); -}; diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index f07d728962..e5ef80e436 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -246,6 +246,52 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ return true; }, + 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, + isCanvas = cc._renderType === cc.game.RENDER_TYPE_CANVAS, spTiles = this._spriteTiles; + 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++) { + child = children[i]; + if (isCanvas && + child._localZOrder === 0 && + spTiles[child.tag]) { + if (isNaN(child._customZ)) { + child._vertexZ = renderer.assignedZ; + renderer.assignedZ += renderer.assignedZStep; + } + child._renderCmd.updateStatus(); + continue; + } + child.visit(this); + } + } else { + renderer.pushRenderCommand(cmd); + } + cmd._dirtyFlag = 0; + }, + /** * Gets layer size. * @return {Size} diff --git a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js index fa8e35f7a0..838a74ae8f 100644 --- a/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js +++ b/cocos2d/tilemap/CCTMXLayerCanvasRenderCmd.js @@ -44,62 +44,6 @@ _ccsg.TMXLayer.CanvasRenderCmd = function(renderable){ var proto = _ccsg.TMXLayer.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype); proto.constructor = _ccsg.TMXLayer.CanvasRenderCmd; -proto.visit = function (parentCmd) { - var node = this._node, renderer = cc.renderer; - - parentCmd = parentCmd || this.getParentRenderCmd(); - if (parentCmd) { - this._curLevel = parentCmd._curLevel + 1; - } - 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); - - // Visit children - var children = node._children, child, - spTiles = node._spriteTiles, - i, 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++) { - child = children[i]; - if (child._localZOrder === 0 && spTiles[child.tag]) { - if (isNaN(child._customZ)) { - child._vertexZ = renderer.assignedZ; - renderer.assignedZ += renderer.assignedZStep; - } - child._renderCmd.updateStatus(); - continue; - } - child._renderCmd.visit(this); - } - } else { - renderer.pushRenderCommand(this); - } - this._dirtyFlag = 0; -}; - proto.rendering = function (ctx, scaleX, scaleY) { var node = this._node, hasRotation = (node._rotationX || node._rotationY), layerOrientation = node.layerOrientation, diff --git a/extensions/spine/SGSkeletonCanvasRenderCmd.js b/extensions/spine/SGSkeletonCanvasRenderCmd.js index ce7fc96270..41c1ed6074 100644 --- a/extensions/spine/SGSkeletonCanvasRenderCmd.js +++ b/extensions/spine/SGSkeletonCanvasRenderCmd.js @@ -98,7 +98,7 @@ proto.rendering = function (wrapper, scaleX, scaleY) { }; 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;