1 | #ifndef _OcclusionQuery_H__
|
---|
2 | #define _OcclusionQuery_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include "common.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemo
|
---|
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 | public:
|
---|
19 | /** constructor requesting an opengl occlusion query.
|
---|
20 | */
|
---|
21 | OcclusionQuery();
|
---|
22 |
|
---|
23 | virtual ~OcclusionQuery();
|
---|
24 |
|
---|
25 | bool ResultAvailable() const;
|
---|
26 |
|
---|
27 | unsigned int GetQueryResult() const;
|
---|
28 |
|
---|
29 | void BeginQuery() const;
|
---|
30 |
|
---|
31 | void EndQuery() const;
|
---|
32 |
|
---|
33 | unsigned int GetQueryId() const;
|
---|
34 | /** Returns the first node of the multiquery
|
---|
35 | */
|
---|
36 | inline BvhNode *GetFrontNode() const { return mNodes[0]; }
|
---|
37 | inline const BvhNodeContainer &GetNodes() const { return mNodes; }
|
---|
38 |
|
---|
39 | /** Reset the list of nodes associated with this query.
|
---|
40 | */
|
---|
41 | inline void Reset() { mNodes.clear(); }
|
---|
42 | /** Adds a node to the query.
|
---|
43 | */
|
---|
44 | inline void AddNode(BvhNode *node) { mNodes.push_back(node); }
|
---|
45 | /** Returns the size of the multiquery.
|
---|
46 | */
|
---|
47 | inline int GetSize() const { return (int)mNodes.size();}
|
---|
48 |
|
---|
49 | protected:
|
---|
50 |
|
---|
51 |
|
---|
52 | ///////
|
---|
53 | //-- members
|
---|
54 |
|
---|
55 | /// all nodes that are tested with the same query
|
---|
56 | BvhNodeContainer mNodes;
|
---|
57 | // the query associated with this test
|
---|
58 | unsigned int mQueryId;
|
---|
59 | };
|
---|
60 |
|
---|
61 |
|
---|
62 | class QueryHandler
|
---|
63 | {
|
---|
64 | public:
|
---|
65 |
|
---|
66 | QueryHandler();
|
---|
67 | ~QueryHandler() { DestroyQueries(); }
|
---|
68 |
|
---|
69 | OcclusionQuery *RequestQuery();
|
---|
70 |
|
---|
71 | /** Must be called every frame.
|
---|
72 | */
|
---|
73 | void ResetQueries();
|
---|
74 | /** Destroys all the queries.
|
---|
75 | */
|
---|
76 | void DestroyQueries();
|
---|
77 |
|
---|
78 | protected:
|
---|
79 |
|
---|
80 | int mCurrentQueryIdx;
|
---|
81 |
|
---|
82 | QueryContainer mOcclusionQueries;
|
---|
83 | };
|
---|
84 |
|
---|
85 |
|
---|
86 | } // namespace
|
---|
87 | #endif // OcclusionQuery_H |
---|