diff --git a/CHANGELOG b/CHANGELOG index 1497c22df8..6ad27e8da2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,11 @@ -cocos2d-x-3.0final ?.? ? +cocos2d-x-3.0beta2 ?.? ? [All] [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] GLCache: glActiveTexture() is cached with GL::activeTexture(). All code MUST call the cached version in order to work correctly [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. [NEW] Label: Integrates LabelAtlas into new Label. + [NEW] Node: Added `setGlobalZOrder()`. Useful to change the Node's render order [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% [NEW] LuaBindings: Bindings-generator supports to bind namespace for lua. diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index b052741ae6..a520602c3d 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -e1e5a1169e92834330092c45165660c6cbd03609 \ No newline at end of file +63e6598ea5798bf42bbd22c2295e65f7c739695a \ No newline at end of file diff --git a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id index bb3a11cb54..eac7e38de9 100644 --- a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -1fa58d8cba77ef923c83d2860d5511d28dad6c27 \ No newline at end of file +447e7ba37294e6da0df2e02f5a62f30fb15e3272 \ No newline at end of file diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 03eb16ba18..15492a651f 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -153,7 +153,7 @@ void AtlasNode::draw(void) auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); _quadCommand.init( - _vertexZ, + _globalZOrder, _textureAtlas->getTexture()->getName(), shader, _blendFunc, diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 55be0ef5a8..f20b4d2778 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -210,12 +210,12 @@ void ClippingNode::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beforeVisitCmd.init(_vertexZ); + _beforeVisitCmd.init(_globalZOrder); _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); renderer->addCommand(&_beforeVisitCmd); if (_alphaThreshold < 1) @@ -238,7 +238,7 @@ void ClippingNode::visit() } _stencil->visit(); - _afterDrawStencilCmd.init(_vertexZ); + _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); renderer->addCommand(&_afterDrawStencilCmd); @@ -268,7 +268,7 @@ void ClippingNode::visit() this->draw(); } - _afterVisitCmd.init(_vertexZ); + _afterVisitCmd.init(_globalZOrder); _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); renderer->addCommand(&_afterVisitCmd); diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 0e28ee554f..003209b6e4 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -241,7 +241,7 @@ void DrawNode::render() void DrawNode::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index c96678fc57..0cac300283 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -666,7 +666,7 @@ void Label::onDraw() void Label::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Label::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 83629a50ec..54b9c48cd9 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -565,7 +565,7 @@ void LayerColor::updateColor() void LayerColor::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 2dc1f49fbb..735a8edae2 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -359,7 +359,7 @@ void MotionStreak::draw() if(_nuPoints <= 1) return; kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(MotionStreak::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 3b7ce1c47c..e631d0f02a 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -108,7 +108,8 @@ Node::Node(void) , _inverseDirty(true) // children (lazy allocs) // lazy alloc -, _ZOrder(0) +, _localZOrder(0) +, _globalZOrder(0) , _parent(nullptr) // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true , _tag(Node::INVALID_TAG) @@ -212,29 +213,22 @@ void Node::setSkewY(float newSkewY) _transformDirty = _inverseDirty = true; } -/// zOrder getter -int Node::getZOrder() const -{ - return _ZOrder; -} /// zOrder setter : private method /// used internally to alter the zOrder variable. DON'T call this method manually -void Node::_setZOrder(int z) +void Node::_setLocalZOrder(int z) { - _ZOrder = z; + _localZOrder = z; } -void Node::setZOrder(int z) +void Node::setLocalZOrder(int z) { + _localZOrder = z; if (_parent) { _parent->reorderChild(this, z); } - // should set "_ZOrder" after reorderChild, because the implementation of reorderChild subclass of Node, such as Sprite, - // will return when _ZOrder value is not changed - _setZOrder(z); - + _eventDispatcher->setDirtyForNode(this); } @@ -246,9 +240,10 @@ float Node::getVertexZ() const /// vertexZ setter -void Node::setVertexZ(float var) +void Node::setVertexZ(float zOrder) { - _vertexZ = var; + _vertexZ = zOrder; + setGlobalZOrder(zOrder); } @@ -650,7 +645,7 @@ void Node::addChild(Node *child, int zOrder) void Node::addChild(Node *child) { CCASSERT( child != nullptr, "Argument must be non-nil"); - this->addChild(child, child->_ZOrder, child->_tag); + this->addChild(child, child->_localZOrder, child->_tag); } void Node::removeFromParent() @@ -767,7 +762,7 @@ void Node::insertChild(Node* child, int z) { _reorderChildDirty = true; _children.pushBack(child); - child->_setZOrder(z); + child->_setLocalZOrder(z); } void Node::reorderChild(Node *child, int zOrder) @@ -775,7 +770,7 @@ void Node::reorderChild(Node *child, int zOrder) CCASSERT( child != nullptr, "Child must be non-nil"); _reorderChildDirty = true; child->setOrderOfArrival(s_globalOrderOfArrival++); - child->_setZOrder(zOrder); + child->_setLocalZOrder(zOrder); } void Node::sortAllChildren() @@ -816,7 +811,7 @@ void Node::visit() { auto node = _children.at(i); - if ( node && node->_ZOrder < 0 ) + if ( node && node->_localZOrder < 0 ) node->visit(); else break; diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 3069fb0a84..0598773a7c 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -161,43 +161,72 @@ public: /// @name Setters & Getters for Graphic Peroperties /** - * Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array. - * - * The Z order of node is relative to its siblings. - * It is not related to the OpenGL's z property. This one only affects the draw order of itself and its siblings. - * Lower Z order number are drawn before higher numbers. - * Please refer to `setVertexZ(float)` for the difference. - * - * @param zOrder Z order of this node. + LocalZOrder is the 'key' used to sort the node relative to its siblings. + + The Node's parent will sort all its children based ont the LocalZOrder value. + If two nodes have the same LocalZOrder, then the node that was added first to the children's array will be in front of the other node in the array. + + Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order ) + And Nodes that have LocalZOder values < 0 are the "left" subtree + While Nodes with LocalZOder >=0 are the "right" subtree. + + @see `setGlobalZOrder` + @see `setVertexZ` */ - virtual void setZOrder(int zOrder); - /* - * Sets the z order which stands for the drawing order - * - * This is an internal method. Don't call it outside the framework. - * The difference between setZOrder(int) and _setOrder(int) is: - * - _setZOrder(int) is a pure setter for _ZOrder memeber variable - * - setZOrder(int) firstly changes _ZOrder, then recorder this node in its parent's chilren array. + virtual void setLocalZOrder(int zOrder); + + CC_DEPRECATED_ATTRIBUTE virtual void setZOrder(int zOrder) { setLocalZOrder(zOrder); } + /* Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing. */ - virtual void _setZOrder(int z); + virtual void _setLocalZOrder(int z); /** - * Gets the Z order of this node. + * Gets the local Z order of this node. * - * @see `setZOrder(int)` + * @see `setLocalZOrder(int)` * - * @return The Z order. + * @return The local (relative to its siblings) Z order. */ - virtual int getZOrder() const; + virtual int getLocalZOrder() const { return _localZOrder; } + CC_DEPRECATED_ATTRIBUTE virtual int getZOrder() const { return getLocalZOrder(); } /** - * Sets the real OpenGL Z vertex. + Defines the oder in which the nodes are renderer. + Nodes that have a Global Z Order lower, are renderer first. + + In case two or more nodes have the same Global Z Order, the oder is not guaranteed. + The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used. + + By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes. + + Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order. + + Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their acenstors. + And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode. + + @see `setLocalZOrder()` + @see `setVertexZ()` + + @since v3.0 + */ + virtual void setGlobalZOrder(float zOrder) { _globalZOrder = zOrder; } + /** + * Returns the Node's Global Z Order. * - * Differences between openGL Z vertex and cocos2d Z order: - * - OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children - * - OpenGL Z might require to set 2D projection - * - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: `vertexZ = 0` + * @see `setGlobalZOrder(int)` * - * @warning Use it at your own risk since it might break the cocos2d parent-children z order + * @return The node's global Z order + */ + virtual float getGlobalZOrder() const { return _globalZOrder; } + + /** + * Sets the 'z' value in the OpenGL Depth Buffer. + * + * The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on + * in order to use this property correctly. + * + * `setVertexZ()` also sets the `setGlobalZValue()` with the vertexZ value. + * + * @see `setGlobalZValue()` * * @param vertexZ OpenGL Z vertex of this node. */ @@ -1411,7 +1440,6 @@ protected: float _scaleX; ///< scaling factor on x-axis float _scaleY; ///< scaling factor on y-axis - float _vertexZ; ///< OpenGL real Z vertex Point _position; ///< position of the node @@ -1433,8 +1461,12 @@ protected: mutable bool _transformDirty; ///< transform dirty flag mutable bool _inverseDirty; ///< inverse transform dirty flag - int _ZOrder; ///< z-order value that affects the draw order - + + int _localZOrder; ///< Local order (relative to its siblings) used to sort the node + float _globalZOrder; ///< Global order used to sort the node + float _vertexZ; ///< OpenGL real Z vertex + + Vector _children; ///< array of children nodes Node *_parent; ///< weak reference to parent node diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 9f359cf778..f8c5d5accb 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -92,7 +92,7 @@ void NodeGrid::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); @@ -104,7 +104,7 @@ void NodeGrid::visit() _nodeGrid->set2DProjection(); } - _gridBeginCommand.init(_vertexZ); + _gridBeginCommand.init(_globalZOrder); _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); renderer->addCommand(&_gridBeginCommand); @@ -152,7 +152,7 @@ void NodeGrid::visit() director->setProjection(beforeProjectionType); } - _gridEndCommand.init(_vertexZ); + _gridEndCommand.init(_globalZOrder); _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); renderer->addCommand(&_gridEndCommand); diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index d64d682ce3..bca1c3eb28 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -197,7 +197,7 @@ int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag) _children.insert(pos, child); child->setTag(aTag); - child->_setZOrder(z); + child->_setLocalZOrder(z); child->setParent(this); @@ -264,7 +264,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder) } } - child->_setZOrder(zOrder); + child->_setLocalZOrder(zOrder); } void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z) @@ -383,7 +383,7 @@ void ParticleBatchNode::draw(void) } _batchCommand.init( - _vertexZ, + _globalZOrder, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc, diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index cf3725e1a2..bd4bef3599 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -439,7 +439,7 @@ void ParticleSystemQuad::draw() auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - _quadCommand.init(_vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); + _quadCommand.init(_globalZOrder, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index b8332e0442..112b34d85b 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -555,7 +555,7 @@ void ProgressTimer::draw() if( ! _vertexData || ! _sprite) return; - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ProgressTimer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 63bc1a596d..57b6a00d24 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -322,7 +322,7 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep this->begin(); //clear screen - _beginWithClearCommand.init(_vertexZ); + _beginWithClearCommand.init(_globalZOrder); _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); } @@ -340,7 +340,7 @@ void RenderTexture::clearDepth(float depthValue) this->begin(); - _clearDepthCommand.init(_vertexZ); + _clearDepthCommand.init(_globalZOrder); _clearDepthCommand.func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); Director::getInstance()->getRenderer()->addCommand(&_clearDepthCommand); @@ -605,7 +605,7 @@ void RenderTexture::draw() begin(); //clear screen - _clearCommand.init(_vertexZ); + _clearCommand.init(_globalZOrder); _clearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_clearCommand); @@ -648,13 +648,13 @@ void RenderTexture::begin() (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 ); kmGLMultMatrix(&orthoMatrix); - _groupCommand.init(_vertexZ); + _groupCommand.init(_globalZOrder); Renderer *renderer = Director::getInstance()->getRenderer(); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beginCommand.init(_vertexZ); + _beginCommand.init(_globalZOrder); _beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this); Director::getInstance()->getRenderer()->addCommand(&_beginCommand); @@ -662,7 +662,7 @@ void RenderTexture::begin() void RenderTexture::end() { - _endCommand.init(_vertexZ); + _endCommand.init(_globalZOrder); _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this); Renderer *renderer = Director::getInstance()->getRenderer(); diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index fafb509a6b..65c7a24b50 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -670,7 +670,7 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { //TODO implement z order - _quadCommand.init(_vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); + _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); // if(culling()) { @@ -769,13 +769,8 @@ void Sprite::addChild(Node *child, int zOrder, int tag) void Sprite::reorderChild(Node *child, int zOrder) { - CCASSERT(child != nullptr, ""); - CCASSERT(_children.contains(child), ""); - - if (zOrder == child->getZOrder()) - { - return; - } + CCASSERT(child != nullptr, "child must be non null"); + CCASSERT(_children.contains(child), "child does not belong to this"); if( _batchNode && ! _reorderChildDirty) { diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 6237f92b19..0526b6768d 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -357,7 +357,7 @@ void SpriteBatchNode::draw() child->updateTransform(); _batchCommand.init( - _vertexZ, + _globalZOrder, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc, diff --git a/cocos/2d/CCTransitionPageTurn.cpp b/cocos/2d/CCTransitionPageTurn.cpp index c42bf6e9d2..7e4102b009 100644 --- a/cocos/2d/CCTransitionPageTurn.cpp +++ b/cocos/2d/CCTransitionPageTurn.cpp @@ -98,23 +98,23 @@ void TransitionPageTurn::draw() if( _isInSceneOnTop ) { _outSceneProxy->visit(); - _enableOffsetCmd.init(_vertexZ); + _enableOffsetCmd.init(_globalZOrder); _enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd); _inSceneProxy->visit(); - _disableOffsetCmd.init(_vertexZ); + _disableOffsetCmd.init(_globalZOrder); _disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd); } else { _inSceneProxy->visit(); - _enableOffsetCmd.init(_vertexZ); + _enableOffsetCmd.init(_globalZOrder); _enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd); _outSceneProxy->visit(); - _disableOffsetCmd.init(_vertexZ); + _disableOffsetCmd.init(_globalZOrder); _disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd); } diff --git a/cocos/2d/renderer/CCBatchCommand.cpp b/cocos/2d/renderer/CCBatchCommand.cpp index 9c60b37455..b9b0c7fab9 100644 --- a/cocos/2d/renderer/CCBatchCommand.cpp +++ b/cocos/2d/renderer/CCBatchCommand.cpp @@ -38,9 +38,9 @@ BatchCommand::BatchCommand() _shader = nullptr; } -void BatchCommand::init(float depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform) +void BatchCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform) { - _depth = depth; + _globalOrder = globalOrder; _textureID = textureID; _blendType = blendType; _shader = shader; @@ -54,7 +54,7 @@ BatchCommand::~BatchCommand() { } -void BatchCommand::execute() const +void BatchCommand::execute() { // Set material _shader->use(); diff --git a/cocos/2d/renderer/CCBatchCommand.h b/cocos/2d/renderer/CCBatchCommand.h index 4ad2e7ae34..9ac5b346ee 100644 --- a/cocos/2d/renderer/CCBatchCommand.h +++ b/cocos/2d/renderer/CCBatchCommand.h @@ -45,7 +45,7 @@ public: void init(float depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform); - void execute() const; + void execute(); protected: int32_t _materialID; diff --git a/cocos/2d/renderer/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index c521928921..c324032116 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -32,9 +32,9 @@ CustomCommand::CustomCommand() _type = RenderCommand::Type::CUSTOM_COMMAND; } -void CustomCommand::init(float depth) +void CustomCommand::init(float globalOrder) { - _depth = depth; + _globalOrder = globalOrder; } CustomCommand::~CustomCommand() @@ -42,7 +42,7 @@ CustomCommand::~CustomCommand() } -void CustomCommand::execute() const +void CustomCommand::execute() { if(func) { diff --git a/cocos/2d/renderer/CCCustomCommand.h b/cocos/2d/renderer/CCCustomCommand.h index 5bf149363e..03fdead69a 100644 --- a/cocos/2d/renderer/CCCustomCommand.h +++ b/cocos/2d/renderer/CCCustomCommand.h @@ -41,7 +41,7 @@ public: void init(float depth); - void execute() const; + void execute(); inline bool isTranslucent() { return true; } std::function func; diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index 70496b5d1d..95b9a5ccb5 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -91,9 +91,9 @@ GroupCommand::GroupCommand() _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); } -void GroupCommand::init(float depth) +void GroupCommand::init(float globalOrder) { - _depth = depth; + _globalOrder = globalOrder; GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID); _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); } diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index 333fd834d2..9cae10d701 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -38,9 +38,9 @@ QuadCommand::QuadCommand() _quads = nullptr; } -void QuadCommand::init(float depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) +void QuadCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) { - _depth = depth; + _globalOrder = globalOrder; _textureID = textureID; _blendType = blendType; _shader = shader; diff --git a/cocos/2d/renderer/CCRenderCommand.cpp b/cocos/2d/renderer/CCRenderCommand.cpp index 64157b4739..578f28d426 100644 --- a/cocos/2d/renderer/CCRenderCommand.cpp +++ b/cocos/2d/renderer/CCRenderCommand.cpp @@ -29,7 +29,7 @@ NS_CC_BEGIN RenderCommand::RenderCommand() : _type(RenderCommand::Type::UNKNOWN_COMMAND) -, _depth(0) +, _globalOrder(0) { } @@ -57,7 +57,7 @@ void printBits(ssize_t const size, void const * const ptr) void RenderCommand::printID() { - printf("Command Depth: %f\n", _depth); + printf("Command Depth: %f\n", _globalOrder); } NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index adb47f2f12..688f65feb7 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -50,7 +50,7 @@ public: }; /** Get Render Command Id */ - inline float getDepth() const { return _depth; } + inline float getGlobalOrder() const { return _globalOrder; } /** Returns the Command type */ inline Type getType() const { return _type; } @@ -65,7 +65,7 @@ protected: Type _type; // commands are sort by depth - float _depth; + float _globalOrder; }; NS_CC_END diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 4a137295fe..6642ddfd6c 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -34,21 +34,21 @@ #include "CCEventDispatcher.h" #include "CCEventListenerCustom.h" #include "CCEventType.h" -#include // for std::stable_sort +#include NS_CC_BEGIN bool compareRenderCommand(RenderCommand* a, RenderCommand* b) { - return a->getDepth() < b->getDepth(); + return a->getGlobalOrder() < b->getGlobalOrder(); } void RenderQueue::push_back(RenderCommand* command) { - float z = command->getDepth(); + float z = command->getGlobalOrder(); if(z < 0) _queueNegZ.push_back(command); - if(z > 0) + else if(z > 0) _queuePosZ.push_back(command); else _queue0.push_back(command); @@ -66,7 +66,7 @@ void RenderQueue::sort() std::sort(std::begin(_queuePosZ), std::end(_queuePosZ), compareRenderCommand); } -const RenderCommand* RenderQueue::operator[](ssize_t index) const +RenderCommand* RenderQueue::operator[](ssize_t index) const { if(index < _queueNegZ.size()) return _queueNegZ[index]; @@ -295,7 +295,7 @@ void Renderer::render() if(commandType == RenderCommand::Type::QUAD_COMMAND) { - auto cmd = static_cast(command); + auto cmd = static_cast(command); ssize_t cmdQuadCount = cmd->getQuadCount(); //Batch quads @@ -317,19 +317,19 @@ void Renderer::render() else if(commandType == RenderCommand::Type::CUSTOM_COMMAND) { flush(); - auto cmd = static_cast(command); + auto cmd = static_cast(command); cmd->execute(); } else if(commandType == RenderCommand::Type::BATCH_COMMAND) { flush(); - auto cmd = static_cast(command); + auto cmd = static_cast(command); cmd->execute(); } else if(commandType == RenderCommand::Type::GROUP_COMMAND) { flush(); - auto cmd = static_cast(command); + auto cmd = static_cast(command); _renderStack.top().currentIndex = i + 1; @@ -467,7 +467,7 @@ void Renderer::drawBatchedQuads() auto command = _renderGroups[_renderStack.top().renderQueueID][i]; if (command->getType() == RenderCommand::Type::QUAD_COMMAND) { - auto cmd = static_cast(command); + auto cmd = static_cast(command); if(_lastMaterialID != cmd->getMaterialID()) { //Draw quads diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index 0921fa6bc7..39511a04f0 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -49,7 +49,7 @@ public: void push_back(RenderCommand* command); ssize_t size() const; void sort(); - const RenderCommand* operator[](ssize_t index) const; + RenderCommand* operator[](ssize_t index) const; void clear(); protected: diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 20f034c35b..752e4911a9 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -156,7 +156,7 @@ void BatchNode::draw() void BatchNode::generateGroupCommand() { Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand->init(_vertexZ); + _groupCommand->init(_globalZOrder); renderer->addCommand(_groupCommand); renderer->pushGroup(_groupCommand->getRenderQueueID()); diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 4bd7883a43..dbaa142020 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -145,7 +145,7 @@ void Bone::setBoneData(BoneData *boneData) } _name = _boneData->name; - _ZOrder = _boneData->zOrder; + _localZOrder = _boneData->zOrder; _displayManager->initDisplayList(boneData); } @@ -283,11 +283,11 @@ void Bone::updateZOrder() if (_dataVersion >= VERSION_COMBINED) { int zorder = _tweenData->zOrder + _boneData->zOrder; - setZOrder(zorder); + setLocalZOrder(zorder); } else { - setZOrder(_tweenData->zOrder); + setLocalZOrder(_tweenData->zOrder); } } @@ -374,10 +374,10 @@ Tween *Bone::getTween() return _tween; } -void Bone::setZOrder(int zOrder) +void Bone::setLocalZOrder(int zOrder) { - if (_ZOrder != zOrder) - Node::setZOrder(zOrder); + if (_localZOrder != zOrder) + Node::setLocalZOrder(zOrder); } kmMat4 Bone::getNodeToArmatureTransform() const diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index db153a1da5..c81583a8c9 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -143,7 +143,7 @@ public: //! Update zorder void updateZOrder(); - virtual void setZOrder(int zOrder) override; + virtual void setLocalZOrder(int zOrder) override; Tween *getTween(); diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 349bba5dfe..a8bd016948 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -331,7 +331,7 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget*widg widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); } int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setZOrder(z); + widget->setLocalZOrder(z); } void WidgetPropertiesReader0250::setColorPropsForWidgetFromJsonDictionary(Widget *widget, const rapidjson::Value&options) @@ -1062,7 +1062,7 @@ void WidgetPropertiesReader0300::setPropsForWidgetFromJsonDictionary(Widget*widg widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); } int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setZOrder(z); + widget->setLocalZOrder(z); bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); if (layout) diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 12b18604ff..e33c4ad86a 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -203,7 +203,7 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d: node->setTag(nTag); int nZorder = DICTOOL->getIntValue_json(root, "zorder"); - node->setZOrder(nZorder); + node->setLocalZOrder(nZorder); float fScaleX = DICTOOL->getFloatValue_json(root, "scalex", 1.0); float fScaleY = DICTOOL->getFloatValue_json(root, "scaley", 1.0); diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 1da40694f7..440ce92159 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -225,7 +225,7 @@ void Skin::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &mv); //TODO implement z order - _quadCommand.init(_vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); + _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index c224e38d4e..82c0ed50cd 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -131,7 +131,7 @@ void Skeleton::draw() kmGLMatrixMode(KM_GL_MODELVIEW); kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Skeleton::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 691fb212a2..8a64ad7ed4 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -210,18 +210,18 @@ void Layout::stencilClippingVisit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beforeVisitCmdStencil.init(_vertexZ); + _beforeVisitCmdStencil.init(_globalZOrder); _beforeVisitCmdStencil.func = CC_CALLBACK_0(Layout::onBeforeVisitStencil, this); renderer->addCommand(&_beforeVisitCmdStencil); _clippingStencil->visit(); - _afterDrawStencilCmd.init(_vertexZ); + _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(Layout::onAfterDrawStencil, this); renderer->addCommand(&_afterDrawStencilCmd); @@ -251,7 +251,7 @@ void Layout::stencilClippingVisit() this->draw(); } - _afterVisitCmdStencil.init(_vertexZ); + _afterVisitCmdStencil.init(_globalZOrder); _afterVisitCmdStencil.func = CC_CALLBACK_0(Layout::onAfterVisitStencil, this); renderer->addCommand(&_afterVisitCmdStencil); @@ -336,13 +336,13 @@ void Layout::scissorClippingVisit() { Renderer* renderer = Director::getInstance()->getRenderer(); - _beforeVisitCmdScissor.init(_vertexZ); + _beforeVisitCmdScissor.init(_globalZOrder); _beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor, this); renderer->addCommand(&_beforeVisitCmdScissor); Node::visit(); - _afterVisitCmdScissor.init(_vertexZ); + _afterVisitCmdScissor.init(_globalZOrder); _afterVisitCmdScissor.func = CC_CALLBACK_0(Layout::onAfterVisitScissor, this); renderer->addCommand(&_afterVisitCmdScissor); } @@ -651,14 +651,14 @@ void Layout::addBackGroundImage() if (_backGroundScale9Enabled) { _backGroundImage = extension::Scale9Sprite::create(); - _backGroundImage->setZOrder(-1); + _backGroundImage->setLocalZOrder(-1); Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); static_cast(_backGroundImage)->setPreferredSize(_size); } else { _backGroundImage = Sprite::create(); - _backGroundImage->setZOrder(-1); + _backGroundImage->setLocalZOrder(-1); Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); } _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index fffb6aaad1..327707d7c8 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -195,7 +195,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -204,7 +204,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index ba6a567aef..8c732f6e70 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -378,7 +378,7 @@ void ListView::refreshView() for (int i=0; isetZOrder(i); + item->setLocalZOrder(i); remedyLayoutParameter(item); } updateInnerContainerSize(); diff --git a/cocos/gui/UIScrollView.h b/cocos/gui/UIScrollView.h index ae49fa02ea..0b196cef55 100644 --- a/cocos/gui/UIScrollView.h +++ b/cocos/gui/UIScrollView.h @@ -242,7 +242,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -251,7 +251,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index e28f4d8db0..d09a8fde39 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -1040,7 +1040,7 @@ void Widget::copyProperties(Widget *widget) setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); _touchPassedEnabled = false; - setZOrder(widget->getZOrder()); + setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); diff --git a/cocos/gui/UIWidget.h b/cocos/gui/UIWidget.h index d07bc4bee8..3827c60db2 100644 --- a/cocos/gui/UIWidget.h +++ b/cocos/gui/UIWidget.h @@ -212,7 +212,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -221,7 +221,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index bf7e667cc2..0c4fbe72a3 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -494,7 +494,7 @@ void ScrollView::addChild(Node * child, int zOrder, int tag) void ScrollView::beforeDraw() { - _beforeDrawCommand.init(_vertexZ); + _beforeDrawCommand.init(_globalZOrder); _beforeDrawCommand.func = CC_CALLBACK_0(ScrollView::onBeforeDraw, this); Director::getInstance()->getRenderer()->addCommand(&_beforeDrawCommand); } @@ -529,7 +529,7 @@ void ScrollView::onBeforeDraw() void ScrollView::afterDraw() { - _afterDrawCommand.init(_vertexZ); + _afterDrawCommand.init(_globalZOrder); _afterDrawCommand.func = CC_CALLBACK_0(ScrollView::onAfterDraw, this); Director::getInstance()->getRenderer()->addCommand(&_afterDrawCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 1fea5ffa2a..b290364d39 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -1314,7 +1314,7 @@ void ActionFollow::onEnter() void ActionFollow::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionFollow::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); @@ -1630,7 +1630,7 @@ void ActionCatmullRomStacked::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -1745,7 +1745,7 @@ void ActionCardinalSplineStacked::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -2107,7 +2107,7 @@ void ActionCatmullRom::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -2207,7 +2207,7 @@ void ActionCardinalSpline::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index 70e55dae5d..2dabe08a75 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -149,7 +149,7 @@ void Box2DTestLayer::draw() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index ed1e08da29..2b05f4a60b 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -211,7 +211,7 @@ void Box2DView::draw() { Layer::draw(); - _customCmd.init(_vertexZ); + _customCmd.init(_globalZOrder); _customCmd.func = CC_CALLBACK_0(Box2DView::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCmd); } diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index b73c205be3..829c8766dc 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -611,7 +611,7 @@ void RawStencilBufferTest::draw() auto iter = _renderCmds.begin(); - iter->init(_vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onEnableStencil, this); renderer->addCommand(&(*iter)); ++iter; @@ -628,7 +628,7 @@ void RawStencilBufferTest::draw() spritePoint.y = 0; _sprites.at(i)->setPosition( spritePoint ); - iter->init(_vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i, stencilPoint); renderer->addCommand(&(*iter)); ++iter; @@ -638,7 +638,7 @@ void RawStencilBufferTest::draw() _sprites.at(i)->visit(); kmGLPopMatrix(); - iter->init(_vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i, winPoint); renderer->addCommand(&(*iter)); ++iter; @@ -649,7 +649,7 @@ void RawStencilBufferTest::draw() kmGLPopMatrix(); } - iter->init(_vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onDisableStencil, this); renderer->addCommand(&(*iter)); diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index 0e693d640a..622220f09d 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -116,7 +116,7 @@ DrawPrimitivesTest::DrawPrimitivesTest() void DrawPrimitivesTest::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 8e2a0119e4..88a63ce1f9 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -503,7 +503,7 @@ void TestChangeZorder::changeZorder(float dt) Node *node = getChildByTag(currentTag); - node->setZOrder(CCRANDOM_0_1() * 3); + node->setLocalZOrder(CCRANDOM_0_1() * 3); currentTag ++; currentTag = currentTag % 3; @@ -637,7 +637,7 @@ void TestParticleDisplay::onEnter() bone->addDisplay(p1, 0); bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); + bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a3"); @@ -645,7 +645,7 @@ void TestParticleDisplay::onEnter() bone->addDisplay(p2, 0); bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); + bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a30"); } @@ -1067,7 +1067,7 @@ void TestColliderDetector::update(float delta) } void TestColliderDetector::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(TestColliderDetector::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -1108,7 +1108,7 @@ std::string TestBoundingBox::title() const } void TestBoundingBox::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index a06f00d592..5253040a66 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -56,7 +56,7 @@ bool UIImageViewTest::init() _uiLayer->addChild(sprite); */ -// imageView->setZOrder(20); +// imageView->setLocalZOrder(20); return true; } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index af89de176c..e09dc7f4fc 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -210,7 +210,7 @@ void Atlas1::draw() // GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // GL_TEXTURE_2D - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Atlas1::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); @@ -526,7 +526,7 @@ Atlas4::Atlas4() void Atlas4::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Atlas4::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -1612,7 +1612,7 @@ std::string LabelBMFontBounds::subtitle() const void LabelBMFontBounds::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index 91be90098d..a3dff56208 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -302,7 +302,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() void LabelFNTSpriteActions::draw() { - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); @@ -912,7 +912,7 @@ std::string LabelFNTBounds::subtitle() const void LabelFNTBounds::draw() { - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index 0cee1ffbd1..194a7bc74c 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -166,11 +166,11 @@ void TouchableSpriteTest::onEnter() target->setOpacity(255); if (target == sprite2) { - sprite1->setZOrder(100); + sprite1->setLocalZOrder(100); } else if(target == sprite1) { - sprite1->setZOrder(0); + sprite1->setLocalZOrder(0); } }; diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp index a0c70d62b5..290366c94c 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp @@ -67,6 +67,7 @@ static std::function createFunctions[] = CL(ConvertToNode), CL(NodeOpaqueTest), CL(NodeNonOpaqueTest), + CL(NodeGlobalZValueTest), }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -905,6 +906,55 @@ std::string NodeNonOpaqueTest::subtitle() const return "Node rendered with GL_BLEND enabled"; } +/// NodeGlobalZValueTest + +NodeGlobalZValueTest::NodeGlobalZValueTest() +{ + Size s = Director::getInstance()->getWinSize(); + for (int i = 0; i < 9; i++) + { + Sprite *sprite; + auto parent = Node::create(); + if(i==4) { + sprite = Sprite::create("Images/grossinis_sister2.png"); + _sprite = sprite; + _sprite->setGlobalZOrder(-1); + } + else + sprite = Sprite::create("Images/grossinis_sister1.png"); + + parent->addChild(sprite); + this->addChild(parent); + + float w = sprite->getContentSize().width; + sprite->setPosition(s.width/2 - w*0.7*(i-5), s.height/2); + } + + this->scheduleUpdate(); +} + +void NodeGlobalZValueTest::update(float dt) +{ + static float accum = 0; + + accum += dt; + if( accum > 1) { + float z = _sprite->getGlobalZOrder(); + _sprite->setGlobalZOrder(-z); + accum = 0; + } +} + +std::string NodeGlobalZValueTest::title() const +{ + return "Global Z Value"; +} + +std::string NodeGlobalZValueTest::subtitle() const +{ + return "Center Sprite should change go from foreground to background"; +} + // // MySprite: Used by CameraTest1 and CameraTest2 @@ -932,7 +982,7 @@ protected: void MySprite::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(MySprite::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h index 2207c65f7c..334e2df08a 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h @@ -249,6 +249,20 @@ protected: NodeNonOpaqueTest(); }; +class NodeGlobalZValueTest : public TestCocosNodeDemo +{ +public: + CREATE_FUNC(NodeGlobalZValueTest); + virtual std::string title() const override; + virtual std::string subtitle() const override; + + virtual void update(float dt) override; + +protected: + NodeGlobalZValueTest(); + Sprite *_sprite; +}; + class CocosNodeTestScene : public TestScene { public: diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index a90ce6aebc..e893f707f7 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -470,19 +470,19 @@ RenderTextureTestDepthStencil::~RenderTextureTestDepthStencil() void RenderTextureTestDepthStencil::draw() { - _renderCmds[0].init(_vertexZ); + _renderCmds[0].init(_globalZOrder); _renderCmds[0].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeClear, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[0]); _rend->beginWithClear(0, 0, 0, 0, 0, 0); - _renderCmds[1].init(_vertexZ); + _renderCmds[1].init(_globalZOrder); _renderCmds[1].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeStencil, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[1]); _spriteDS->visit(); - _renderCmds[2].init(_vertexZ); + _renderCmds[2].init(_globalZOrder); _renderCmds[2].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[2]); @@ -490,7 +490,7 @@ void RenderTextureTestDepthStencil::draw() _rend->end(); - _renderCmds[3].init(_vertexZ); + _renderCmds[3].init(_globalZOrder); _renderCmds[3].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onAfterDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[3]); @@ -638,7 +638,7 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea void SpriteRenderTextureBug::SimpleSprite::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 087644545e..443a24d681 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -193,7 +193,7 @@ void ShaderNode::setPosition(const Point &newPosition) void ShaderNode::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ShaderNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -526,7 +526,7 @@ void SpriteBlur::initProgram() void SpriteBlur::draw() { - _customCommand.init(_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(SpriteBlur::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index 1d76e56892..e8207b4cb4 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -178,7 +178,7 @@ void ShaderSprite::initShader() void ShaderSprite::draw() { - _renderCommand.init(_vertexZ); + _renderCommand.init(_globalZOrder); _renderCommand.func = CC_CALLBACK_0(ShaderSprite::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCommand); diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index 3324802c9d..a4121f8825 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -1794,7 +1794,7 @@ void TextureDrawAtPoint::draw() { TextureDemo::draw(); - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TextureDrawAtPoint::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); @@ -1835,7 +1835,7 @@ void TextureDrawInRect::draw() { TextureDemo::draw(); - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TextureDrawInRect::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp index 68f3cd5d59..1b45442fd5 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp @@ -599,7 +599,7 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest() void TMXOrthoObjectsTest::draw() { - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXOrthoObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -672,7 +672,7 @@ TMXIsoObjectsTest::TMXIsoObjectsTest() void TMXIsoObjectsTest::draw() { - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXIsoObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -1504,7 +1504,7 @@ TMXGIDObjectsTest::TMXGIDObjectsTest() void TMXGIDObjectsTest::draw() { - _renderCmd.init(_vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXGIDObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); }