From b222d4201c3d93b285f065cd008a0d45c542e9d2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 26 Dec 2007 22:00:28 +0000 Subject: [PATCH] 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." --- .../osgocclusionquery/osgocclusionquery.cpp | 73 +++---------------- include/osg/OcclusionQueryNode | 1 + src/osg/OcclusionQueryNode.cpp | 6 ++ src/osgWrappers/osg/OcclusionQueryNode.cpp | 5 ++ 4 files changed, 21 insertions(+), 64 deletions(-) diff --git a/examples/osgocclusionquery/osgocclusionquery.cpp b/examples/osgocclusionquery/osgocclusionquery.cpp index 35133d81e..ae0f530cc 100644 --- a/examples/osgocclusionquery/osgocclusionquery.cpp +++ b/examples/osgocclusionquery/osgocclusionquery.cpp @@ -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 oqn = new osg::OcclusionQueryNode; + + osg::StateSet* ss( NULL ); + osg::StateSet* ssDebug( NULL ); + oqn->getQueryStateSets( ss, ssDebug ); + _state = ss; + _debugState = ssDebug; } OcclusionQueryVisitor::~OcclusionQueryVisitor() diff --git a/include/osg/OcclusionQueryNode b/include/osg/OcclusionQueryNode index ba1c54901..a505e91a0 100644 --- a/include/osg/OcclusionQueryNode +++ b/include/osg/OcclusionQueryNode @@ -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; diff --git a/src/osg/OcclusionQueryNode.cpp b/src/osg/OcclusionQueryNode.cpp index a137adf14..41574fd72 100644 --- a/src/osg/OcclusionQueryNode.cpp +++ b/src/osg/OcclusionQueryNode.cpp @@ -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 diff --git a/src/osgWrappers/osg/OcclusionQueryNode.cpp b/src/osgWrappers/osg/OcclusionQueryNode.cpp index 38d25713e..0dc617a00 100644 --- a/src/osgWrappers/osg/OcclusionQueryNode.cpp +++ b/src/osgWrappers/osg/OcclusionQueryNode.cpp @@ -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,