diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 17aea6026d..d72ffa6c74 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -231,7 +231,7 @@ void ClippingNode::drawFullScreenQuadClearStencil() void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { - if(!_visible) + if (!_visible || !hasContent()) return; uint32_t flags = processParentFlags(parentTransform, parentFlags); @@ -327,6 +327,11 @@ void ClippingNode::setStencil(Node *stencil) _stencil = stencil; } +bool ClippingNode::hasContent() +{ + return _children.size() > 0; +} + GLfloat ClippingNode::getAlphaThreshold() const { return _alphaThreshold; diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index ba9301e590..ad098465f5 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -58,7 +58,14 @@ public: */ Node* getStencil() const; void setStencil(Node *stencil); - + + /** If stencil has no childre it will not be drawn. + If you have custom stencil-based node with stencil drawing mechanics other then children-based, + then this method should return true every time you wish stencil to be visited. + By default returns true if has any children attached. + */ + virtual bool hasContent(); + /** The alpha threshold. The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold. Should be a float between 0 and 1.