diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index fba3c00deb..53ed6797bb 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -261,6 +261,7 @@ void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32 renderer->addCommand(&_afterDrawStencilCmd); int i = 0; + bool visibleByCamera = checkCameraMask(); if(!_children.empty()) { @@ -276,12 +277,13 @@ void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32 break; } // self draw - this->draw(renderer, _modelViewTransform, flags); + if (visibleByCamera) + this->draw(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); } - else + else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index ab0b98023c..d0242c1fc2 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1053,7 +1053,7 @@ void Label::drawTextSprite(Renderer *renderer, uint32_t parentFlags) void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { - if (! _visible || _originalUTF8String.empty()) + if (! _visible || _originalUTF8String.empty() || !checkCameraMask()) { return; } diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index a83d9e0a3d..81290f2327 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -1225,6 +1225,13 @@ uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFl return flags; } +bool Node::checkCameraMask() const +{ + auto camera = Camera::getVisitingCamera(); + bool visibleByCamera = camera ? (unsigned short)camera->getCameraFlag() & _cameraMask : true; + return visibleByCamera; +} + void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. @@ -1242,8 +1249,7 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); - auto camera = Camera::getVisitingCamera(); - bool visibleByCamera = camera ? (unsigned short)camera->getCameraFlag() & _cameraMask : true; + bool visibleByCamera = checkCameraMask(); int i = 0; @@ -1267,10 +1273,9 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); } - else + else if (visibleByCamera) { - if (visibleByCamera) - this->draw(renderer, _modelViewTransform, flags); + this->draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index e907d06c1d..6d0f788104 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1521,6 +1521,9 @@ protected: bool doEnumerate(std::string name, std::function callback) const; bool doEnumerateRecursive(const Node* node, const std::string &name, std::function callback) const; + //check whether this camera mask is visible by the current visiting camera + bool checkCameraMask() const; + #if CC_USE_PHYSICS void updatePhysicsBodyTransform(Scene* layer); virtual void updatePhysicsBodyPosition(Scene* layer); diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index b2ed64a5c7..ee86daa2e4 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -126,6 +126,7 @@ void NodeGrid::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t p } int i = 0; + bool visibleByCamera = checkCameraMask(); if(!_children.empty()) { @@ -141,13 +142,14 @@ void NodeGrid::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t p break; } // self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command - this->draw(renderer, _modelViewTransform, dirty); + if (visibleByCamera) + this->draw(renderer, _modelViewTransform, dirty); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) { (*it)->visit(renderer, _modelViewTransform, dirty); } } - else + else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, dirty); } diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 72a0646284..eb24526f82 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -130,7 +130,7 @@ void ParticleBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, u // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // - if (!_visible) + if (!_visible || !checkCameraMask()) { return; } diff --git a/cocos/2d/CCProtectedNode.cpp b/cocos/2d/CCProtectedNode.cpp index de9bbc8bc0..5cf53729e6 100644 --- a/cocos/2d/CCProtectedNode.cpp +++ b/cocos/2d/CCProtectedNode.cpp @@ -318,7 +318,8 @@ void ProtectedNode::visit(Renderer* renderer, const Mat4 &parentTransform, uint3 // // draw self // - this->draw(renderer, _modelViewTransform, flags); + if (checkCameraMask()) + this->draw(renderer, _modelViewTransform, flags); // // draw children and protectedChildren zOrder >= 0 diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 8a60335503..7cb4cf9e12 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -393,7 +393,7 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3 { // override visit. // Don't call visit on its children - if (!_visible) + if (!_visible || !checkCameraMask()) { return; } diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 201d335f3f..df68d82b26 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -147,7 +147,7 @@ void SpriteBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uin // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // - if (! _visible) + if (! _visible || !checkCameraMask()) { return; } diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 5a35a80c27..ed11c16734 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -467,7 +467,7 @@ void Armature::onExit() void Armature::visit(cocos2d::Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. - if (!_visible) + if (!_visible || !checkCameraMask()) { return; } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index f11e38affc..ab64329483 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -108,7 +108,7 @@ void BatchNode::removeChild(Node* child, bool cleanup) void BatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. - if (!_visible) + if (!_visible || !checkCameraMask()) { return; } diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 4cabd4dad3..3d31885daa 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -774,7 +774,8 @@ y+=ytranslate; \ // // draw self // - this->draw(renderer, _modelViewTransform, flags); + if (checkCameraMask()) + this->draw(renderer, _modelViewTransform, flags); // // draw children and protectedChildren zOrder >= 0 diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 01abe5ca06..f864ba1a79 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -581,6 +581,7 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); this->beforeDraw(); + bool visibleByCamera = checkCameraMask(); if (!_children.empty()) { @@ -601,7 +602,8 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t } // this draw - this->draw(renderer, _modelViewTransform, flags); + if (visibleByCamera) + this->draw(renderer, _modelViewTransform, flags); // draw children zOrder >= 0 for( ; i < _children.size(); i++ ) @@ -611,7 +613,7 @@ void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t } } - else + else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); }