source: GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.cpp @ 2764

Revision 2764, 1.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1#include <iostream>
2#include "OcclusionQuery.h"
3#include "glInterface.h"
4
5using namespace std;
6
7
8namespace CHCDemo
9{
10
11OcclusionQuery::OcclusionQuery()
12{
13        glGenQueriesARB(1, &mQueryId);
14
15        // reverse for multiequeries with 32 nodes
16        mNodes.reserve(32);
17}
18
19
20OcclusionQuery::OcclusionQuery(unsigned int idx):
21mQueryId(idx)
22{
23        // reverse for multiequeries with 32 nodes
24        mNodes.reserve(32);
25}
26
27
28OcclusionQuery::~OcclusionQuery()
29{
30        glDeleteQueriesARB(1, &mQueryId);
31}
32
33
34void OcclusionQuery::BeginQuery()
35{
36        glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryId);
37}
38
39
40void OcclusionQuery::EndQuery()
41{
42        glEndQueryARB(GL_SAMPLES_PASSED_ARB);
43}
44
45
46unsigned int OcclusionQuery::GetQueryId() const
47{
48        return mQueryId;
49}
50
51
52bool OcclusionQuery::ResultAvailable() const
53{
54        GLuint available = GL_FALSE;
55
56        glGetQueryObjectuivARB(mQueryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available);
57
58        return available == GL_TRUE;
59}
60
61
62unsigned int OcclusionQuery::GetQueryResult() const
63{
64        GLuint sampleCount = 1;
65
66        glGetQueryObjectuivARB(mQueryId, GL_QUERY_RESULT_ARB, &sampleCount);
67       
68        return sampleCount;
69}
70
71
72
73QueryHandler::QueryHandler(): mCurrentQueryIdx(0)
74{}
75
76
77OcclusionQuery *QueryHandler::RequestQuery()
78{
79        OcclusionQuery *query;
80
81        if (mCurrentQueryIdx == mOcclusionQueries.size())
82        {
83                query = new OcclusionQuery();
84                mOcclusionQueries.push_back(query);
85        }
86        else
87        {
88                query = mOcclusionQueries[mCurrentQueryIdx];
89        }
90
91        ++ mCurrentQueryIdx;
92
93        return query;
94}
95
96
97void QueryHandler::ResetQueries()
98{
99        mCurrentQueryIdx = 0;
100}
101
102
103void QueryHandler::DestroyQueries()
104{
105        CLEAR_CONTAINER(mOcclusionQueries);
106        mCurrentQueryIdx = 0;
107        mOcclusionQueries.clear();
108}
109
110
111
112} // namespace
Note: See TracBrowser for help on using the repository browser.