OcclusionQueryNode: fix use case of user defined query geometry

The user defined query geometry handling has been broken in several ways.

The previous way of defining a query geometry was using the non const
`getQueryGeometry` method and overriding its members. But then
`OcclusionQueryNode` wasn't aware of the geometry change and couldn't
internally handle it correctly.

The `computeBound` method never considered a user defined query geometry and
always just overrode the vertices of the geometry.

The member `_validQueryGeometry` wasn't correctly set.

This change should fix all this issues by introducing a small backward
compatibility break. The non const `getQueryGeometry` method is removed
forcing the user to use the `setQueryGeometry` method. But then `OcclusionQueryNode`
is aware of the user defined query geometry and can handle it correctly.
This commit is contained in:
Daniel Trstenjak
2019-08-14 11:27:40 +02:00
committed by Julien Valentin
parent 8fb5ba4a3f
commit 817d92b703
2 changed files with 126 additions and 72 deletions

View File

@@ -82,9 +82,9 @@ public:
};
/** 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 );
QueryResult getQueryResult( const osg::Camera* cam ) const;
unsigned int getNumPixels( const osg::Camera* cam );
unsigned int getNumPixels( const osg::Camera* cam ) const;
virtual void releaseGLObjects( osg::State* state = 0 ) const;
@@ -158,8 +158,11 @@ public:
osg::StateSet* getQueryStateSet();
const osg::StateSet* getQueryStateSet() const;
// Get the QueryGeometry object used for occlusion query. Returns 0 if no QueryGeometry is created.
osg::QueryGeometry* getQueryGeometry();
// Set and get the QueryGeometry object used for the occlusion query.
// By default an axis aligned box is used as the query geometry.
// Resetting to the default query geometry is done by setting it to 0.
// Returns 0 if no QueryGeometry is created.
void setQueryGeometry( osg::QueryGeometry* geom );
const osg::QueryGeometry* getQueryGeometry() const;
// Set and get the StateSet used by the OcclusionQueryNode
@@ -189,17 +192,28 @@ public:
static void discardDeletedQueryObjects( unsigned int contextID );
protected:
enum QueryGeometryState {
INVALID,
VALID,
USER_DEFINED
};
virtual ~OcclusionQueryNode();
virtual void createSupportNodes();
bool isQueryGeometryValid() const { return _queryGeometryState != INVALID; }
void setQueryGeometryInternal( osg::QueryGeometry* queryGeom,
osg::Geometry* debugQueryGeom,
QueryGeometryState state );
osg::ref_ptr< osg::Geode > _queryGeode;
osg::ref_ptr< osg::Geode > _debugGeode;
bool _enabled;
// If the box of the query geometry is valid.
mutable bool _validQueryGeometry;
mutable QueryGeometryState _queryGeometryState;
// Tracks the last frame number that we performed a query.
// User can set how many times (See setQueryFrameCount).