source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/OcclusionQuery.h @ 2782

Revision 2782, 1.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef _OcclusionQuery_H__
2#define _OcclusionQuery_H__
3
4#include <vector>
5#include "common.h"
6
7
8namespace CHCDemoEngine
9{
10
11class BvhNode;
12
13/** This class is an implementation for single node queries and multiqueries.
14        @remark the class encapsulates hardware occlusion query calls.
15*/
16class OcclusionQuery
17{
18        friend class QueryHandler;
19
20public:
21        /** constructor requesting an opengl occlusion query.
22        */
23        OcclusionQuery();
24
25        virtual ~OcclusionQuery();
26
27        bool ResultAvailable() const;
28       
29        unsigned int GetQueryResult() const;
30       
31        void BeginQuery() const;
32       
33        void EndQuery() const;
34       
35        unsigned int GetQueryId() const;
36        /** Returns the first node of the multiquery
37        */
38        inline BvhNode *GetFrontNode() const { return mNodes[0]; }
39        inline const BvhNodeContainer &GetNodes() const { return mNodes; }
40
41        /** Reset the list of nodes associated with this query.
42        */
43        inline void Reset() { mNodes.clear(); }
44        /** Adds a node to the query.
45        */
46        inline void AddNode(BvhNode *node) { mNodes.push_back(node); }
47        /** Returns the size of the multiquery.
48        */
49        inline int GetSize() const { return (int)mNodes.size();}
50       
51
52protected:
53
54        OcclusionQuery(unsigned int id): mQueryId(id) { }
55
56        ///////
57        //-- members
58
59        /// all nodes that are tested with the same query
60        BvhNodeContainer mNodes;
61        // the query associated with this test
62        unsigned int mQueryId;
63};
64
65
66class QueryHandler
67{
68public:
69
70        QueryHandler();
71        ~QueryHandler() { DestroyQueries(); }
72
73        OcclusionQuery *RequestQuery();
74
75        /** Must be called every frame.
76        */
77        void ResetQueries();
78        /** Destroys all the queries.
79        */
80        void DestroyQueries();
81
82protected:
83       
84        /** allocates n queries in advance
85        */
86        void Allocate(int n);
87
88
89        ////////////////
90
91        int mCurrentQueryIdx;
92
93        QueryContainer mOcclusionQueries;
94};
95
96
97} // namespace
98#endif // OcclusionQuery_H
Note: See TracBrowser for help on using the repository browser.