Issue with clipping rectangles and back to front rendering

Posted by Milo on Stack Overflow See other posts from Stack Overflow or by Milo
Published on 2010-12-31T20:48:46Z Indexed on 2010/12/31 20:54 UTC
Read the original article Hit count: 368

Filed under:
|
|

Here is my problem. My rendering algorithm renders from back to front. But logically, clipping rectangles need to be applied from front to back.

Hence why the following does not work:

void AguiWidgetManager::recursiveRender(const AguiWidget *root)
{
    //recursively calls itself to render widgets from back to front
    AguiWidget* nonConstRoot = (AguiWidget*)root;
    if(!nonConstRoot->isVisable())
    {
        return;
    }
        //push the clipping rectangle
    if(nonConstRoot->isClippingChildren())
    {
        graphicsContext->pushClippingRect(nonConstRoot->getClippingRectangle());
    }
    if(nonConstRoot->isEnabled())
    {
        nonConstRoot->paint(AguiPaintEventArgs(true,graphicsContext));
        for(std::vector<AguiWidget*>::const_iterator it = 
            root->getPrivateChildBeginIterator();
            it != root->getPrivateChildEndIterator(); ++it)
        {
            recursiveRender(*it);
        }
        for(std::vector<AguiWidget*>::const_iterator it = 
            root->getChildBeginIterator();
            it != root->getChildEndIterator(); ++it)
        {
            recursiveRender(*it);
        }
    }
    else
    {
        nonConstRoot->paint(AguiPaintEventArgs(false,graphicsContext));

        for(std::vector<AguiWidget*>::const_iterator it = 
            root->getPrivateChildBeginIterator();
            it != root->getPrivateChildEndIterator(); ++it)
        {
            recursiveRenderDisabled(*it);
        }
        for(std::vector<AguiWidget*>::const_iterator it = 
            root->getChildBeginIterator();
            it != root->getChildEndIterator(); ++it)
        {
            recursiveRenderDisabled(*it);
        }
    }

         //release clipping rectangle
    if(nonConstRoot->isClippingChildren())
    {
        graphicsContext->popClippingRect();
    }
}

I could ofcourse go to the top of the tree, then apply clipping rectangles inward until I get to the currently rendered widget, but that would involve lots of clipping rectangles @ 60 frames per second. I want to minimize calls to pushing and popping rectangles.

What could I do, Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about game-development