root/OpenSceneGraph/trunk/include/osg/OcclusionQueryNode @ 11127

Revision 11127, 4.9 kB (checked in by robert, 4 years ago)

From Paul Martz, "The changes are very similar to Magne's, except they now take the near plane into account. The changes are:

  • Change OcclusionQueryNode::getPassed to take a NodeVisitor? rather than the distance from BS center to the eye point. Change where CullVisitor? calls this method to use the new parameters.
  • getPassed now exits early and returns true to avoid blinking / blink-in of geometry for the first frame or for out-of-range LOD children coming back into view.
  • getPassed now considers the distance from the near plane to the bounding sphere (rather than eye point to bounding sphere) when determining if the viewer is "inside" the bounding sphere or not."
RevLine 
[7731]1//
2// Copyright (C) 2007 Skew Matrix Software LLC (http://www.skew-matrix.com)
3//
4// This library is open source and may be redistributed and/or modified under 
5// the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6// (at your option) any later version.  The full license is in LICENSE file
7// included with this distribution, and on the openscenegraph.org website.
8//
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// OpenSceneGraph Public License for more details.
13//
14
15#ifndef OSG_OCCLUSION_QUERY_NODE
16#define OSG_OCCLUSION_QUERY_NODE 1
17
18#include <osg/Export>
19#include <osg/CopyOp>
20#include <osg/Group>
21
22
23
24namespace osg {
25
26
27// This Node performs occlusion query testing on its children.
28//   You can use it directly to occlusion query test a portion
29//   of your scene graph, or you can use it implicitly with an
30//   OcclusionQueryRoot, which places OcclusionQueryNodes where
31//   needed and acts as a master control.
32class OSG_EXPORT OcclusionQueryNode : public osg::Group
33{
34public:
35    OcclusionQueryNode();
36
37    // Copy constructor using CopyOp to manage deep vs shallow copy.
38    OcclusionQueryNode( const OcclusionQueryNode& oqn, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY );
39
40    META_Node( osg, OcclusionQueryNode );
41
42    virtual osg::BoundingSphere computeBound() const;
43
[7790]44    virtual void releaseGLObjects( osg::State* state = 0 ) const;
45   
46   
[7731]47    // When disabled, OQN doesn't perform occlusion queries, and simply
48    //   renders its children.
49    void setQueriesEnabled( bool enable=true );
50    bool getQueriesEnabled() const { return _enabled; }
51
52
53    // Sets/gets the visibility threshold. If the test indicates that
54    //   the number of visible pixels is less than the specified
55    //   threshold, don't draw the actual geometry.
56    void setVisibilityThreshold( unsigned int pixels ) { _visThreshold = pixels; }
57    unsigned int getVisibilityThreshold() const { return _visThreshold; }
58
59    // Specifies how many frames to wait before issuing another query.
60    void setQueryFrameCount( int frames ) { _queryFrameCount = frames; }
61    int getQueryFrameCount() const { return _queryFrameCount; }
62
63    // Indicate whether or not the bounding box used in the occlusion query test
64    //   should be rendered. Handy for debugging and development.
65    // Should only be called outside of cull/draw. No thread issues.
66    void setDebugDisplay( bool enable );
67    bool getDebugDisplay() const;
68
69
[7889]70    // Set and get the StateSet used by the OcclusionQueryNode
71    //   when rendering the query geometry. OQN creates its own by
72    //   default, but if you use many OQNs you might want to use
73    //   this method to set all OQNs to use the same StateSet
74    //   for more efficient processing.
75    void setQueryStateSet( osg::StateSet* ss );
76    osg::StateSet* getQueryStateSet();
77    const osg::StateSet* getQueryStateSet() const;
[7731]78
[7889]79    // Set and get the StateSet used by the OcclusionQueryNode
80    //   when rendering the debug query geometry (see setDebugDisplay).
81    void setDebugStateSet( osg::StateSet* ss );
82    osg::StateSet* getDebugStateSet();
83    const osg::StateSet* getDebugStateSet() const;
84
[7731]85    // For statistics gathering, e.g., by a NodeVisitor.
86    bool getPassed() const;
87   
88   
89    // These methods are public so that osgUtil::CullVisitor can access them.
90    // Not intended for application use.
[11127]91    bool getPassed( const osg::Camera* camera, osg::NodeVisitor& nv );
[7731]92    void traverseQuery( const osg::Camera* camera, osg::NodeVisitor& nv );
93    void traverseDebug( osg::NodeVisitor& nv );
94
[7790]95
96    // Delete unused query IDs for this contextID.
97    static void flushDeletedQueryObjects( unsigned int contextID, double currentTime, double& availableTime );
98
99    // discard all the cached query objects which need to be deleted
100    // in the OpenGL context related to contextID.
101    // Note, unlike flush no OpenGL calls are made, instead the handles are all removed.
102    // this call is useful for when an OpenGL context has been destroyed.
103    static void discardDeletedQueryObjects( unsigned int contextID );
104
[7731]105protected:
106    virtual ~OcclusionQueryNode();
107
108    void createSupportNodes();
109
110    osg::ref_ptr< osg::Geode > _queryGeode;
111    osg::ref_ptr< osg::Geode > _debugGeode;
112
113    bool _enabled;
114
115    // Tracks the last frame number that we performed a query.
116    // User can set how many times  (See setQueryFrameCount).
117    typedef std::map< const osg::Camera*, int > FrameCountMap;
118    FrameCountMap _frameCountMap;
119    mutable OpenThreads::Mutex _frameCountMutex;
120
121    // For statistics gathering
122    bool _passed;
123
124    // User-settable variables
125    unsigned int _visThreshold;
126    int _queryFrameCount;
127    bool _debugBB;
128
129
130    // Required to ensure that computeBound() is thread-safe.
131    mutable OpenThreads::Mutex _computeBoundMutex;
132};
133
134}
135
136
137#endif
Note: See TracBrowser for help on using the browser.