Permalink
Browse files

Introduced a QueryGeometry::getQueryResult(const osg::Camera*) method…

… as a more informative replacedment for QueryGeometry::getNumPixels().
  • Loading branch information...
robertosfield committed Jan 26, 2019
1 parent f21ca61 commit 6eb0da3a16f86c0a78cb6e882baf5522ddba1161
Showing with 28 additions and 6 deletions.
  1. +12 −0 include/osg/OcclusionQueryNode
  2. +16 −6 src/osg/OcclusionQueryNode.cpp
@@ -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;
@@ -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;

0 comments on commit 6eb0da3

Please sign in to comment.