1 | //#include "glInterface.h"
|
---|
2 | #include "OcclusionQuery.h"
|
---|
3 | #include <iostream>
|
---|
4 | //#include <GL/gl.h>
|
---|
5 | //#include <QtOpenGL>
|
---|
6 | #include <glInterface.h>
|
---|
7 |
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 |
|
---|
11 | namespace GtpVisibilityPreprocessor {
|
---|
12 |
|
---|
13 | bool OcclusionQuery::sUseArbQueries = true;
|
---|
14 |
|
---|
15 |
|
---|
16 | OcclusionQuery::OcclusionQuery()
|
---|
17 | {
|
---|
18 | GLuint id;
|
---|
19 |
|
---|
20 | if (sUseArbQueries)
|
---|
21 | {
|
---|
22 | glGenQueriesARB(1, &id);
|
---|
23 | }
|
---|
24 | else
|
---|
25 | {
|
---|
26 | glGenOcclusionQueriesNV(1, &id);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | OcclusionQuery::OcclusionQuery(const unsigned int idx):
|
---|
31 | mId(idx)
|
---|
32 | {}
|
---|
33 |
|
---|
34 |
|
---|
35 | OcclusionQuery::~OcclusionQuery()
|
---|
36 | {
|
---|
37 | if (sUseArbQueries)
|
---|
38 | {
|
---|
39 | glDeleteQueriesARB(1, &mId);
|
---|
40 | }
|
---|
41 | else
|
---|
42 | {
|
---|
43 | glDeleteOcclusionQueriesNV(1, &mId);
|
---|
44 | }
|
---|
45 |
|
---|
46 | }
|
---|
47 | //-----------------------------------------------------------------------
|
---|
48 | void OcclusionQuery::BeginQuery()
|
---|
49 | {
|
---|
50 | if (sUseArbQueries)
|
---|
51 | {
|
---|
52 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId);
|
---|
53 | }
|
---|
54 | else
|
---|
55 | {
|
---|
56 | glBeginOcclusionQueryNV(mId);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | //-----------------------------------------------------------------------
|
---|
60 | void OcclusionQuery::EndQuery()
|
---|
61 | {
|
---|
62 | if (sUseArbQueries)
|
---|
63 | {
|
---|
64 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | glEndOcclusionQueryNV();
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | unsigned int OcclusionQuery::GetQueryId() const
|
---|
74 | {
|
---|
75 | return mId;
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool OcclusionQuery::ResultAvailable() const
|
---|
79 | {
|
---|
80 | GLuint available;
|
---|
81 |
|
---|
82 | if (sUseArbQueries)
|
---|
83 | {
|
---|
84 | //GLint available;
|
---|
85 | glGetQueryObjectuivARB(mId,
|
---|
86 | GL_QUERY_RESULT_AVAILABLE_ARB,
|
---|
87 | &available);
|
---|
88 | return available == GL_TRUE;
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 |
|
---|
93 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available);
|
---|
94 |
|
---|
95 | return available == GL_TRUE;
|
---|
96 | }
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | unsigned int OcclusionQuery::GetQueryResult() const
|
---|
102 | {
|
---|
103 | GLuint sampleCount;
|
---|
104 |
|
---|
105 | if (sUseArbQueries)
|
---|
106 | {
|
---|
107 | // GLint sampleCount;
|
---|
108 | glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount);
|
---|
109 | return sampleCount;
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 |
|
---|
114 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount);
|
---|
115 | return sampleCount;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | void OcclusionQuery::GenQueries(std::vector<OcclusionQuery * > &queries, const int numQueries)
|
---|
121 | {
|
---|
122 | if ((int)queries.size() < numQueries)
|
---|
123 | {
|
---|
124 | const int n = numQueries - (int)queries.size();
|
---|
125 | unsigned int *newQueries = new unsigned int[n];
|
---|
126 |
|
---|
127 |
|
---|
128 | if (sUseArbQueries)
|
---|
129 | {
|
---|
130 | glGenQueriesARB(n, (unsigned int *)newQueries);
|
---|
131 | }
|
---|
132 | else
|
---|
133 | {
|
---|
134 | glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
|
---|
135 | }
|
---|
136 |
|
---|
137 | for (int i = 0; i < n; ++ i)
|
---|
138 | {
|
---|
139 | queries.push_back(new OcclusionQuery(newQueries[i]));
|
---|
140 | //cout << "q: " << i << " id: " << newQueries[i] << endl;
|
---|
141 | }
|
---|
142 |
|
---|
143 | delete [] newQueries;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | } // namespace |
---|