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

Revision 3258, 2.2 KB checked in by mattausch, 15 years ago (diff)

worked on new method

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        /** Returns true if the query result is available.
27        */
28        bool ResultAvailable() const;
29        /** Returns number of visible pixels.
30        */
31        unsigned int GetQueryResult() const;
32        /** Starts the query. Everything drawn inbetween start and end is
33                queried.
34        */
35        void BeginQuery() const;
36        /** Ends the query.
37        */
38        void EndQuery() const;
39        /** Returns id of this query.
40        */
41        unsigned int GetQueryId() const;
42        /** Returns the first node of the multiquery
43        */
44        inline BvhNode *GetFrontNode() const { return mNodes[0]; }
45        /** Returns nodes by reference
46        */
47        inline const BvhNodeContainer &GetNodes() const { return mNodes; }
48        /** Reset the list of nodes associated with this query.
49        */
50        inline void Reset() { mNodes.clear(); }
51        /** Adds a node to the query.
52        */
53        inline void AddNode(BvhNode *node) { mNodes.push_back(node); }
54        /** Returns the size of the multiquery.
55        */
56        inline int GetSize() const { return (int)mNodes.size(); }
57
58        inline bool IsEmpty() const { return GetSize() == 0; }
59
60
61protected:
62        /** Constructor taking an already allocated query id.
63        */
64        OcclusionQuery(unsigned int id): mQueryId(id) { }
65
66        ///////
67        //-- members
68
69        /// all nodes that are tested with the same query
70        BvhNodeContainer mNodes;
71        // the query associated with this test
72        unsigned int mQueryId;
73};
74
75
76class QueryHandler
77{
78public:
79
80        QueryHandler();
81        ~QueryHandler() { DestroyQueries(); }
82
83        OcclusionQuery *RequestQuery();
84
85        /** Must be called every frame.
86        */
87        void ResetQueries();
88        /** Destroys all the queries.
89        */
90        void DestroyQueries();
91
92protected:
93       
94        /** allocates n queries in advance
95        */
96        void Allocate(int n);
97
98
99        ////////////////
100
101        int mCurrentQueryIdx;
102
103        QueryContainer mOcclusionQueries;
104};
105
106
107} // namespace
108#endif // OcclusionQuery_H
Note: See TracBrowser for help on using the repository browser.