[osg-users] Robert: I figured it out :-) (was: Is it possible to know when the node-graph is 'dirty'?)

Viggo Løvli vigigio at hotmail.com
Thu Jul 24 04:41:19 PDT 2008

Hi Robert,
I followed your advice added the code into the traverse function of my root node. 
Much of the code could now be removed,  and I got rid of the "0..1 loop"-hack that I had to do earlier.
I think the new code looks very good. Do you see anything you would do differently?
The new code looks like this:
void MyRootNodeClass::traverse( osg::NodeVisitor& nv )
    osg::Group::traverse( nv );
    // Clone render-bin 10 if this is a cull visitor
    if( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
        osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );
        if( cv )
            // Act if we have a RenderStage pointer
            if( osgUtil::RenderStage* renderStage = cv->getRenderStage() )
                // Get the render-bin list
                osgUtil::RenderBin::RenderBinList& binList = renderStage->getRenderBinList();
                if( binList.find(10) != binList.end() )
                    // Clone bin 10
                    osgUtil::RenderBin* clonedBin = new osgUtil::RenderBin( *(binList[10].get()) );
                    // Clone the state-set
                    osg::StateSet* originalStateSet = clonedBin->getStateSet();
                    osg::StateSet* stateSet = (originalStateSet) ? new osg::StateSet( *(originalStateSet) ) : new osg::StateSet();
                    // Ensure the cloned state-set is used in the cloned bin
                    clonedBin->setStateSet( stateSet );
                    // Cloned bin shall not write to the depth-buffer
                    stateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON  | osg::StateAttribute::OVERRIDE );
                    stateSet->setAttributeAndModes( new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
                    // Ensure cloned bin is rendered before bin 10.
                    binList[9] = clonedBin;

Viggo> Date: Thu, 24 Jul 2008 11:19:21 +0100> From: robert.osfield at gmail.com> To: osg-users at lists.openscenegraph.org> Subject: Re: [osg-users] Robert: I figured it out :-) (was: Is it possible to know when the node-graph is 'dirty'?)> > Hi Viggo,> > I'd do this trick using a CullCallback on the topmost node of sub> graph that you won't to repeat rather than a pre draw callback. The> CullVisitor keeps track of the current RenderStage.> > Robert.> 
Hold kontakten med Windows Live Messenger.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080724/65183009/attachment-0003.htm>

More information about the osg-users mailing list