void ClippingRectangleNode::onBeforeVisitScissor()
{
    if (_clippingEnabled) {
        // record old ClipRegion
        GLView* glView = Director::getInstance()->getOpenGLView();
        if (glView->isScissorEnabled()) {
            _preClipRegion = glView->getScissorRect();
        } else {
            _preClipRegion = Rect::ZERO;
        }
        glEnable(GL_SCISSOR_TEST);
        
        float scaleX = _scaleX;
        float scaleY = _scaleY;
        Node *parent = this->getParent();
        while (parent) {
            scaleX *= parent->getScaleX();
            scaleY *= parent->getScaleY();
            parent = parent->getParent();
        }
        
        // push this ClipRegion
        const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
        glView->setScissorInPoints(pos.x,
                                   pos.y,
                                   _clippingRegion.size.width * scaleX,
                                   _clippingRegion.size.height * scaleY);
    }
}
void ClippingRectangleNode::onAfterVisitScissor()
{
    if (_clippingEnabled)
    {
        // rollback to old ClipRegion
        if (_preClipRegion.size.width > 0) {
            GLView* glView = Director::getInstance()->getOpenGLView();
            glView->setScissorInPoints(_preClipRegion.origin.x,
                                       _preClipRegion.origin.y,
                                       _preClipRegion.size.width,
                                       _preClipRegion.size.height);
        } else {
            glDisable(GL_SCISSOR_TEST);
        }
    }
}
void ClippingRectangleNode::onBeforeVisitScissor()
{
    if (_clippingEnabled) {
        glEnable(GL_SCISSOR_TEST);

        float scaleX = _scaleX;
        float scaleY = _scaleY;
        Node *parent = this->getParent();
        while (parent) {
            scaleX *= parent->getScaleX();
            scaleY *= parent->getScaleY();
            parent = parent->getParent();
        }
        
        const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
        GLView* glView = Director::getInstance()->getOpenGLView();
        glView->setScissorInPoints(pos.x,
                                   pos.y,
                                   _clippingRegion.size.width * scaleX,
                                   _clippingRegion.size.height * scaleY);
    }
}