2001-09-20 05:19:47 +08:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma warning( disable : 4786 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <osg/GeoSet>
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
#include <osgUtil/DisplayRequirementsVisitor>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
using namespace osgUtil;
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
DisplayRequirementsVisitor::DisplayRequirementsVisitor()
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
setTraversalMode(NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
|
|
|
}
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
void DisplayRequirementsVisitor::applyStateSet(StateSet& stateset)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2001-12-22 06:48:19 +08:00
|
|
|
if (!_ds) _ds = new osg::DisplaySettings;
|
2001-12-19 08:38:23 +08:00
|
|
|
|
|
|
|
unsigned int min = 0; // assume stencil not needed by this stateset.
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
if (stateset.getMode(GL_STENCIL_TEST) & StateAttribute::ON)
|
|
|
|
{
|
2001-12-19 08:38:23 +08:00
|
|
|
min = 1; // number stencil bits we need at least.
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stateset.getAttribute(StateAttribute::STENCIL))
|
|
|
|
{
|
2001-12-19 08:38:23 +08:00
|
|
|
min = 1; // number stencil bits we need at least.
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
2001-12-19 08:38:23 +08:00
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
if (min>_ds->getMinimumNumStencilBits())
|
2001-12-19 08:38:23 +08:00
|
|
|
{
|
|
|
|
// only update if new minimum exceeds previous minimum.
|
2001-12-22 06:48:19 +08:00
|
|
|
_ds->setMinimumNumStencilBits(min);
|
2001-12-19 08:38:23 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
void DisplayRequirementsVisitor::apply(Node& node)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
osg::StateSet* stateset = node.getStateSet();
|
|
|
|
if (stateset) applyStateSet(*stateset);
|
|
|
|
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
void DisplayRequirementsVisitor::apply(Geode& geode)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
osg::StateSet* geode_stateset = geode.getStateSet();
|
|
|
|
if (geode_stateset) applyStateSet(*geode_stateset);
|
|
|
|
|
|
|
|
for(int i = 0; i < geode.getNumDrawables(); i++ )
|
|
|
|
{
|
|
|
|
osg::StateSet* stateset = geode.getDrawable(i)->getStateSet();
|
|
|
|
if (stateset) applyStateSet(*stateset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-22 06:48:19 +08:00
|
|
|
void DisplayRequirementsVisitor::apply(Impostor& impostor)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2001-12-22 06:48:19 +08:00
|
|
|
if (!_ds) _ds = new osg::DisplaySettings;
|
2001-12-19 08:38:23 +08:00
|
|
|
|
|
|
|
unsigned int min = 1; // number alpha bits we need at least.
|
2001-12-22 06:48:19 +08:00
|
|
|
if (min>_ds->getMinimumNumAlphaBits())
|
2001-12-19 08:38:23 +08:00
|
|
|
{
|
|
|
|
// only update if new minimum exceeds previous minimum.
|
2001-12-22 06:48:19 +08:00
|
|
|
_ds->setMinimumNumAlphaBits(min);
|
2001-12-19 08:38:23 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
apply((Node&)impostor);
|
|
|
|
}
|