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

RevLine 
[2753]1#ifndef _OcclusionQuery_H__
2#define _OcclusionQuery_H__
3
4#include <vector>
5#include "common.h"
6
7
[2776]8namespace CHCDemoEngine
[2753]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{
[2781]18        friend class QueryHandler;
19
[2753]20public:
[2773]21        /** constructor requesting an opengl occlusion query.
22        */
[2753]23        OcclusionQuery();
24
25        virtual ~OcclusionQuery();
[3258]26        /** Returns true if the query result is available.
27        */
[2763]28        bool ResultAvailable() const;
[3258]29        /** Returns number of visible pixels.
30        */
[2763]31        unsigned int GetQueryResult() const;
[3258]32        /** Starts the query. Everything drawn inbetween start and end is
33                queried.
34        */
[2773]35        void BeginQuery() const;
[3258]36        /** Ends the query.
37        */
[2773]38        void EndQuery() const;
[3258]39        /** Returns id of this query.
40        */
[2753]41        unsigned int GetQueryId() const;
[2772]42        /** Returns the first node of the multiquery
[2753]43        */
44        inline BvhNode *GetFrontNode() const { return mNodes[0]; }
[3258]45        /** Returns nodes by reference
46        */
[2773]47        inline const BvhNodeContainer &GetNodes() const { return mNodes; }
48        /** Reset the list of nodes associated with this query.
[2753]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); }
[2773]54        /** Returns the size of the multiquery.
[2772]55        */
[3258]56        inline int GetSize() const { return (int)mNodes.size(); }
[2753]57
[3258]58        inline bool IsEmpty() const { return GetSize() == 0; }
59
60
[2753]61protected:
[3258]62        /** Constructor taking an already allocated query id.
63        */
[2781]64        OcclusionQuery(unsigned int id): mQueryId(id) { }
65
[2772]66        ///////
[2753]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
[2763]75
76class QueryHandler
77{
78public:
79
80        QueryHandler();
[2765]81        ~QueryHandler() { DestroyQueries(); }
[2763]82
83        OcclusionQuery *RequestQuery();
84
85        /** Must be called every frame.
86        */
87        void ResetQueries();
[2765]88        /** Destroys all the queries.
89        */
[2763]90        void DestroyQueries();
91
92protected:
[2781]93       
94        /** allocates n queries in advance
95        */
96        void Allocate(int n);
[2763]97
[2781]98
99        ////////////////
100
[2763]101        int mCurrentQueryIdx;
102
103        QueryContainer mOcclusionQueries;
104};
105
106
[2753]107} // namespace
108#endif // OcclusionQuery_H
Note: See TracBrowser for help on using the repository browser.