From Paul Martz, "The osgocclusionquery example contained some duplicate code that was also in the core OSG occlusion query code. This change removes the need for that."

This commit is contained in:
Robert Osfield 2007-12-26 22:00:28 +00:00
parent 532d573a06
commit b222d4201c
4 changed files with 21 additions and 64 deletions

View File

@ -63,66 +63,6 @@
// NodeVisitors and utility functions for OcclusionQueryNode
// Create and return a StateSet appropriate for performing an occlusion
// query test (disable lighting, texture mapping, etc). Probably some
// room for improvement here. Could disable shaders, for example.
osg::StateSet*
initOQState()
{
osg::StateSet* state = new osg::StateSet;
// TBD Possible bug, need to allow user to set render bin number.
state->setRenderBinDetails( 9, "RenderBin" );
state->setMode( GL_LIGHTING, osg::StateAttribute::OFF |
osg::StateAttribute::PROTECTED);
state->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF |
osg::StateAttribute::PROTECTED);
state->setMode( GL_CULL_FACE, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::ColorMask* cm = new osg::ColorMask( false, false, false, false );
state->setAttributeAndModes( cm, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::Depth* d = new osg::Depth( osg::Depth::LEQUAL, 0.f, 1.f, false );
state->setAttributeAndModes( d, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::PolygonMode* pm = new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL );
state->setAttributeAndModes( pm, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. );
state->setAttributeAndModes( po, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
return state;
}
// Create and return a StateSet for rendering a debug representation of query geometry.
osg::StateSet*
initOQDebugState()
{
osg::StateSet* debugState = new osg::StateSet;
debugState->setMode( GL_LIGHTING, osg::StateAttribute::OFF |
osg::StateAttribute::PROTECTED);
debugState->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF |
osg::StateAttribute::PROTECTED);
debugState->setMode( GL_CULL_FACE, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::PolygonMode* pm = new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE );
debugState->setAttributeAndModes( pm, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. );
debugState->setAttributeAndModes( po, osg::StateAttribute::ON |
osg::StateAttribute::PROTECTED);
return debugState;
}
// Use this visitor to insert OcclusionQueryNodes (OQNs) in the
// visited subgraph. Only one OQN will test any particular node
// (no nesting). See also OcclusionQueryNonFlatVisitor.
@ -320,10 +260,15 @@ OcclusionQueryVisitor::OcclusionQueryVisitor()
_nameIdx( 0 ),
_occluderThreshold( 5000 )
{
// Init StateSet for occlusion query geometry.
_state = initOQState();
// Initialize StateSet for debug geometry
_debugState = initOQDebugState();
// Create a dummy OcclusionQueryNode just so we can get its state.
// We'll then share that state between all OQNs we add to the visited scene graph.
osg::ref_ptr<osg::OcclusionQueryNode> oqn = new osg::OcclusionQueryNode;
osg::StateSet* ss( NULL );
osg::StateSet* ssDebug( NULL );
oqn->getQueryStateSets( ss, ssDebug );
_state = ss;
_debugState = ssDebug;
}
OcclusionQueryVisitor::~OcclusionQueryVisitor()

View File

@ -67,6 +67,7 @@ public:
// Set the StateSets used by the OQN when rendering OQ geometry
// or debug bounding geometry.
void setQueryStateSets( osg::StateSet* ss, osg::StateSet* ssDebug );
void getQueryStateSets( osg::StateSet* ss, osg::StateSet* ssDebug );
// For statistics gathering, e.g., by a NodeVisitor.
bool getPassed() const;

View File

@ -626,6 +626,12 @@ OcclusionQueryNode::setQueryStateSets( osg::StateSet* ss, osg::StateSet* ssDebug
_queryGeode->setStateSet( ss );
_debugGeode->setStateSet( ssDebug );
}
void
OcclusionQueryNode::getQueryStateSets( osg::StateSet* ss, osg::StateSet* ssDebug )
{
ss = _queryGeode->getStateSet();
ssDebug = _debugGeode->getStateSet();
}
bool
OcclusionQueryNode::getPassed() const

View File

@ -116,6 +116,11 @@ BEGIN_OBJECT_REFLECTOR(osg::OcclusionQueryNode)
__void__setQueryStateSets__osg_StateSet_P1__osg_StateSet_P1,
"",
"");
I_Method2(void, getQueryStateSets, IN, osg::StateSet *, ss, IN, osg::StateSet *, ssDebug,
Properties::NON_VIRTUAL,
__void__getQueryStateSets__osg_StateSet_P1__osg_StateSet_P1,
"",
"");
I_Method0(bool, getPassed,
Properties::NON_VIRTUAL,
__bool__getPassed,