1 | #ifndef _OcclusionQuery_H__
|
---|
2 | #define _OcclusionQuery_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include "common.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 | class BvhNode;
|
---|
12 |
|
---|
13 | /** This class is an implementation for single node queries and multiqueries.
|
---|
14 | @remark the class encapsulates hardware occlusion query calls.
|
---|
15 | */
|
---|
16 | class OcclusionQuery
|
---|
17 | {
|
---|
18 | friend class QueryHandler;
|
---|
19 |
|
---|
20 | public:
|
---|
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 |
|
---|
52 | protected:
|
---|
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 |
|
---|
66 | class QueryHandler
|
---|
67 | {
|
---|
68 | public:
|
---|
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 |
|
---|
82 | protected:
|
---|
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 |
---|