Skip to content

Commit

Permalink
Introduced a QueryGeometry::getQueryResult(const osg::Camera*) method…
Browse files Browse the repository at this point in the history
… as a more informative replacedment for QueryGeometry::getNumPixels().
  • Loading branch information
robertosfield committed Jan 26, 2019
1 parent f21ca61 commit 6eb0da3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 12 additions & 0 deletions include/osg/OcclusionQueryNode
Expand Up @@ -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;
Expand Down
22 changes: 16 additions & 6 deletions src/osg/OcclusionQueryNode.cpp
Expand Up @@ -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;
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6eb0da3

Please sign in to comment.