diff --git a/include/osg/OcclusionQueryNode b/include/osg/OcclusionQueryNode index c776946df..a2c09cabe 100644 --- a/include/osg/OcclusionQueryNode +++ b/include/osg/OcclusionQueryNode @@ -72,6 +72,18 @@ public: virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; + struct QueryResult + { + QueryResult() : valid(false), numPixels(0) {} + QueryResult(bool v, unsigned int p) : valid(v), numPixels(p) {} + + bool valid; + unsigned int numPixels; + }; + + /** return a QueryResult for specified Camera, where the QueryResult.valid is true when query results are available, and in which case the QueryResult.numPixels provides the num of pixels in the query result.*/ + QueryResult getQueryResult( const osg::Camera* cam ); + unsigned int getNumPixels( const osg::Camera* cam ); virtual void releaseGLObjects( osg::State* state = 0 ) const; diff --git a/src/osg/OcclusionQueryNode.cpp b/src/osg/OcclusionQueryNode.cpp index 34f011fdc..988a5c94d 100644 --- a/src/osg/OcclusionQueryNode.cpp +++ b/src/osg/OcclusionQueryNode.cpp @@ -364,9 +364,7 @@ QueryGeometry::drawImplementation( osg::RenderInfo& renderInfo ) const } - -unsigned int -QueryGeometry::getNumPixels( const osg::Camera* cam ) +QueryGeometry::QueryResult QueryGeometry::getQueryResult( const osg::Camera* cam ) { osg::ref_ptr tr; { @@ -378,9 +376,14 @@ QueryGeometry::getNumPixels( const osg::Camera* cam ) _results[ cam ] = tr; } } - return tr->_numPixels; + return QueryResult((tr->_init && !tr->_active), tr->_numPixels); } +unsigned int +QueryGeometry::getNumPixels( const osg::Camera* cam ) +{ + return getQueryResult(cam).numPixels; +} void QueryGeometry::releaseGLObjects( osg::State* state ) const @@ -513,8 +516,15 @@ bool OcclusionQueryNode::getPassed( const Camera* camera, NodeVisitor& nv ) _passed = ( distance <= 0.0 ); if (!_passed) { - int result = qg->getNumPixels( camera ); - _passed = ( (unsigned int)(result) > _visThreshold ); + QueryGeometry::QueryResult result = qg->getQueryResult( camera ); + if (!result.valid) + { + // The query hasn't finished yet and the result still + // isn't available, return true to traverse the subgraphs. + return true; + } + + _passed = ( result.numPixels > _visThreshold ); } return _passed;