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()
|
---|
21 | {
|
---|
22 | glDeleteQueriesARB(1, &mQueryId);
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 | void OcclusionQuery::BeginQuery() const
|
---|
27 | {
|
---|
28 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryId);
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | void OcclusionQuery::EndQuery() const
|
---|
33 | {
|
---|
34 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | unsigned int OcclusionQuery::GetQueryId() const
|
---|
39 | {
|
---|
40 | return mQueryId;
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | bool OcclusionQuery::ResultAvailable() const
|
---|
45 | {
|
---|
46 | GLuint available = GL_FALSE;
|
---|
47 |
|
---|
48 | glGetQueryObjectuivARB(mQueryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available);
|
---|
49 |
|
---|
50 | return available == GL_TRUE;
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | unsigned int OcclusionQuery::GetQueryResult() const
|
---|
55 | {
|
---|
56 | GLuint sampleCount = 1;
|
---|
57 |
|
---|
58 | glGetQueryObjectuivARB(mQueryId, GL_QUERY_RESULT_ARB, &sampleCount);
|
---|
59 |
|
---|
60 | return sampleCount;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | QueryHandler::QueryHandler(): mCurrentQueryIdx(0)
|
---|
66 | {}
|
---|
67 |
|
---|
68 |
|
---|
69 | OcclusionQuery *QueryHandler::RequestQuery()
|
---|
70 | {
|
---|
71 | OcclusionQuery *query;
|
---|
72 |
|
---|
73 | if (mCurrentQueryIdx == mOcclusionQueries.size())
|
---|
74 | {
|
---|
75 | query = new OcclusionQuery();
|
---|
76 | mOcclusionQueries.push_back(query);
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | query = mOcclusionQueries[mCurrentQueryIdx];
|
---|
81 | query->Reset();
|
---|
82 | }
|
---|
83 |
|
---|
84 | ++ mCurrentQueryIdx;
|
---|
85 |
|
---|
86 | return query;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | void QueryHandler::ResetQueries()
|
---|
91 | {
|
---|
92 | mCurrentQueryIdx = 0;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | void QueryHandler::DestroyQueries()
|
---|
97 | {
|
---|
98 | CLEAR_CONTAINER(mOcclusionQueries);
|
---|
99 | mCurrentQueryIdx = 0;
|
---|
100 | mOcclusionQueries.clear();
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | } // namespace
|
---|