| | 26 | // Create and return a StateSet appropriate for performing an occlusion |
| | 27 | // query test (disable lighting, texture mapping, etc). Probably some |
| | 28 | // room for improvement here. Could disable shaders, for example. |
| | 29 | osg::StateSet* initOQState(); |
| | 30 | |
| | 31 | // Create and return a StateSet for rendering a debug representation of query geometry. |
| | 32 | osg::StateSet* initOQDebugState(); |
| | 33 | |
| | 34 | // TestResult -- stores (per context) results of an occlusion query |
| | 35 | // test performed by QueryGeometry. An OcclusionQueryNode has a |
| | 36 | // Geode owning a single QueryGeometry that |
| | 37 | // draws the occlusion query geometry. QueryGeometry keeps a |
| | 38 | // TestResult per context to store the result/status of each query. |
| | 39 | // Accessed during the cull and draw traversals. |
| | 40 | class TestResult : public osg::Referenced |
| | 41 | { |
| | 42 | public: |
| | 43 | TestResult() : _init( false ), _id( 0 ), _contextID( 0 ), _active( false ), _numPixels( 0 ) {} |
| | 44 | ~TestResult() {} |
| | 45 | |
| | 46 | bool _init; |
| | 47 | |
| | 48 | // Query ID for this context. |
| | 49 | GLuint _id; |
| | 50 | // Context ID owning this query ID. |
| | 51 | unsigned int _contextID; |
| | 52 | |
| | 53 | // Set to true when a query gets issued and set to |
| | 54 | // false when the result is retrieved. |
| | 55 | mutable bool _active; |
| | 56 | |
| | 57 | // Result of last query. |
| | 58 | GLint _numPixels; |
| | 59 | }; |
| | 60 | |
| | 61 | // QueryGeometry -- A Drawable that performs an occlusion query, |
| | 62 | // using its geometric data as the query geometry. |
| | 63 | class QueryGeometry : public osg::Geometry |
| | 64 | { |
| | 65 | public: |
| | 66 | QueryGeometry( const std::string& oqnName=std::string("") ); |
| | 67 | ~QueryGeometry(); |
| | 68 | |
| | 69 | void reset(); |
| | 70 | |
| | 71 | // TBD implement copy constructor |
| | 72 | |
| | 73 | virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; |
| | 74 | |
| | 75 | unsigned int getNumPixels( const osg::Camera* cam ); |
| | 76 | |
| | 77 | |
| | 78 | void releaseGLObjects( osg::State* state = 0 ); |
| | 79 | static void deleteQueryObject( unsigned int contextID, GLuint handle ); |
| | 80 | static void flushDeletedQueryObjects( unsigned int contextID, double currentTime, double& availableTime ); |
| | 81 | static void discardDeletedQueryObjects( unsigned int contextID ); |
| | 82 | |
| | 83 | protected: |
| | 84 | typedef std::map< const osg::Camera*, TestResult > ResultMap; |
| | 85 | mutable ResultMap _results; |
| | 86 | mutable OpenThreads::Mutex _mapMutex; |
| | 87 | |
| | 88 | // Needed for debug only |
| | 89 | std::string _oqnName; |
| | 90 | }; |