Introduced a QueryGeometry::getQueryResult(const osg::Camera*) method as a more informative replacedment for QueryGeometry::getNumPixels().

This commit is contained in:
Robert Osfield 2019-01-26 16:33:23 +00:00
parent c8521068a5
commit 02d7d980a7
2 changed files with 28 additions and 6 deletions

View File

@ -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;

View File

@ -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<osg::TestResult> 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;