1 | #include <iostream>
|
---|
2 | #include "OcclusionQuery.h"
|
---|
3 | #include "glInterface.h"
|
---|
4 |
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemo
|
---|
9 | {
|
---|
10 |
|
---|
11 | OcclusionQuery::OcclusionQuery()
|
---|
12 | {
|
---|
13 | glGenQueriesARB(1, &mQueryId);
|
---|
14 |
|
---|
15 | // reverse for multiequeries with 32 nodes
|
---|
16 | mNodes.reserve(32);
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | OcclusionQuery::OcclusionQuery(unsigned int idx):
|
---|
21 | mQueryId(idx)
|
---|
22 | {
|
---|
23 | // reverse for multiequeries with 32 nodes
|
---|
24 | mNodes.reserve(32);
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | OcclusionQuery::~OcclusionQuery()
|
---|
29 | {
|
---|
30 | glDeleteQueriesARB(1, &mQueryId);
|
---|
31 | }
|
---|
32 |
|
---|
33 |
|
---|
34 | void OcclusionQuery::BeginQuery()
|
---|
35 | {
|
---|
36 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryId);
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | void OcclusionQuery::EndQuery()
|
---|
41 | {
|
---|
42 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | unsigned int OcclusionQuery::GetQueryId() const
|
---|
47 | {
|
---|
48 | return mQueryId;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | bool 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 |
|
---|
62 | unsigned 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 |
|
---|
73 | QueryHandler::QueryHandler(): mCurrentQueryIdx(0)
|
---|
74 | {}
|
---|
75 |
|
---|
76 |
|
---|
77 | OcclusionQuery *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 | query = mOcclusionQueries[mCurrentQueryIdx];
|
---|
88 |
|
---|
89 | return query;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | void QueryHandler::ResetQueries()
|
---|
94 | {
|
---|
95 | mCurrentQueryIdx = 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | void QueryHandler::DestroyQueries()
|
---|
100 | {
|
---|
101 | CLEAR_CONTAINER(mOcclusionQueries);
|
---|
102 | mCurrentQueryIdx = 0;
|
---|
103 | mOcclusionQueries.clear();
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | } // namespace
|
---|