1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "state.h"
|
---|
8 | #include "state/cr_statetypes.h"
|
---|
9 | #include "state/cr_statefuncs.h"
|
---|
10 | #include "state_internals.h"
|
---|
11 | #include "cr_mem.h"
|
---|
12 |
|
---|
13 |
|
---|
14 | void
|
---|
15 | crStateOcclusionInit(CRContext *ctx)
|
---|
16 | {
|
---|
17 | CROcclusionState *o = &ctx->occlusion;
|
---|
18 |
|
---|
19 | o->objects = crAllocHashtable();
|
---|
20 | o->currentQueryObject = 0;
|
---|
21 | }
|
---|
22 |
|
---|
23 |
|
---|
24 | void
|
---|
25 | crStateOcclusionDestroy(CRContext *ctx)
|
---|
26 | {
|
---|
27 | CROcclusionState *o = &(ctx->occlusion);
|
---|
28 | crFreeHashtable(o->objects, crFree);
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | static CROcclusionObject *
|
---|
33 | NewQueryObject(GLenum target, GLuint id)
|
---|
34 | {
|
---|
35 | CROcclusionObject *q = (CROcclusionObject *) crAlloc(sizeof(CROcclusionObject));
|
---|
36 | if (q) {
|
---|
37 | q->target = target;
|
---|
38 | q->name = id;
|
---|
39 | q->passedCounter = 0;
|
---|
40 | q->active = GL_FALSE;
|
---|
41 | }
|
---|
42 | return q;
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | void STATE_APIENTRY
|
---|
47 | crStateDeleteQueriesARB(GLsizei n, const GLuint *ids)
|
---|
48 | {
|
---|
49 | CRContext *g = GetCurrentContext();
|
---|
50 | CROcclusionState *o = &(g->occlusion);
|
---|
51 | /*CRStateBits *sb = GetCurrentBits();*/
|
---|
52 | /*CROcclusionBits *bb = &(sb->occlusion);*/
|
---|
53 | int i;
|
---|
54 |
|
---|
55 | FLUSH();
|
---|
56 |
|
---|
57 | if (g->current.inBeginEnd) {
|
---|
58 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
59 | "glDeleteQueriesARB called in Begin/End");
|
---|
60 | return;
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (n < 0) {
|
---|
64 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
65 | "glDeleteQueriesARB(n < 0)");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | for (i = 0; i < n; i++) {
|
---|
70 | if (ids[i]) {
|
---|
71 | CROcclusionObject *q = (CROcclusionObject *)
|
---|
72 | crHashtableSearch(o->objects, ids[i]);
|
---|
73 | if (q) {
|
---|
74 | crHashtableDelete(o->objects, ids[i], crFree);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | void STATE_APIENTRY
|
---|
82 | crStateGenQueriesARB(GLsizei n, GLuint * queries)
|
---|
83 | {
|
---|
84 | CRContext *g = GetCurrentContext();
|
---|
85 | CROcclusionState *o = &(g->occlusion);
|
---|
86 | GLint start;
|
---|
87 |
|
---|
88 | FLUSH();
|
---|
89 |
|
---|
90 | if (g->current.inBeginEnd) {
|
---|
91 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
92 | "glGenQueriesARB called in Begin/End");
|
---|
93 | return;
|
---|
94 | }
|
---|
95 |
|
---|
96 | if (n < 0) {
|
---|
97 | crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
98 | "glGenQueriesARB(n < 0)");
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | start = crHashtableAllocKeys(o->objects, n);
|
---|
103 | if (start) {
|
---|
104 | GLint i;
|
---|
105 | for (i = 0; i < n; i++)
|
---|
106 | queries[i] = (GLuint) (start + i);
|
---|
107 | }
|
---|
108 | else {
|
---|
109 | crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glGenQueriesARB");
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | GLboolean STATE_APIENTRY
|
---|
115 | crStateIsQueryARB(GLuint id)
|
---|
116 | {
|
---|
117 | CRContext *g = GetCurrentContext();
|
---|
118 | CROcclusionState *o = &(g->occlusion);
|
---|
119 |
|
---|
120 | FLUSH();
|
---|
121 |
|
---|
122 | if (g->current.inBeginEnd) {
|
---|
123 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
124 | "glIsQueryARB called in begin/end");
|
---|
125 | return GL_FALSE;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (id && crHashtableIsKeyUsed(o->objects, id))
|
---|
129 | return GL_TRUE;
|
---|
130 | else
|
---|
131 | return GL_FALSE;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | void STATE_APIENTRY
|
---|
136 | crStateGetQueryivARB(GLenum target, GLenum pname, GLint *params)
|
---|
137 | {
|
---|
138 | CRContext *g = GetCurrentContext();
|
---|
139 | CROcclusionState *o = &(g->occlusion);
|
---|
140 | (void)target;
|
---|
141 |
|
---|
142 | FLUSH();
|
---|
143 |
|
---|
144 | if (g->current.inBeginEnd) {
|
---|
145 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
146 | "glGetGetQueryivARB called in begin/end");
|
---|
147 | return;
|
---|
148 | }
|
---|
149 |
|
---|
150 | switch (pname) {
|
---|
151 | case GL_QUERY_COUNTER_BITS_ARB:
|
---|
152 | *params = 8 * sizeof(GLuint);
|
---|
153 | break;
|
---|
154 | case GL_CURRENT_QUERY_ARB:
|
---|
155 | *params = o->currentQueryObject;
|
---|
156 | break;
|
---|
157 | default:
|
---|
158 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
159 | "glGetGetQueryivARB(pname)");
|
---|
160 | return;
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | void STATE_APIENTRY
|
---|
166 | crStateGetQueryObjectivARB(GLuint id, GLenum pname, GLint *params)
|
---|
167 | {
|
---|
168 | CRContext *g = GetCurrentContext();
|
---|
169 | CROcclusionState *o = &(g->occlusion);
|
---|
170 | CROcclusionObject *q;
|
---|
171 |
|
---|
172 | FLUSH();
|
---|
173 |
|
---|
174 | if (g->current.inBeginEnd) {
|
---|
175 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
176 | "glGetGetQueryObjectivARB called in begin/end");
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
|
---|
181 | if (!q || q->active) {
|
---|
182 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
183 | "glGetQueryObjectivARB");
|
---|
184 | return;
|
---|
185 | }
|
---|
186 |
|
---|
187 | switch (pname) {
|
---|
188 | case GL_QUERY_RESULT_ARB:
|
---|
189 | *params = q->passedCounter;
|
---|
190 | break;
|
---|
191 | case GL_QUERY_RESULT_AVAILABLE_ARB:
|
---|
192 | *params = GL_TRUE;
|
---|
193 | break;
|
---|
194 | default:
|
---|
195 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
196 | "glGetQueryObjectivARB(pname)");
|
---|
197 | return;
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | void STATE_APIENTRY
|
---|
203 | crStateGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params)
|
---|
204 | {
|
---|
205 | CRContext *g = GetCurrentContext();
|
---|
206 | CROcclusionState *o = &(g->occlusion);
|
---|
207 | CROcclusionObject *q;
|
---|
208 |
|
---|
209 | FLUSH();
|
---|
210 |
|
---|
211 | if (g->current.inBeginEnd) {
|
---|
212 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
213 | "glGetGetQueryObjectuivARB called in begin/end");
|
---|
214 | return;
|
---|
215 | }
|
---|
216 |
|
---|
217 | q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
|
---|
218 | if (!q || q->active) {
|
---|
219 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
220 | "glGetQueryObjectuivARB");
|
---|
221 | return;
|
---|
222 | }
|
---|
223 |
|
---|
224 | switch (pname) {
|
---|
225 | case GL_QUERY_RESULT_ARB:
|
---|
226 | *params = q->passedCounter;
|
---|
227 | break;
|
---|
228 | case GL_QUERY_RESULT_AVAILABLE_ARB:
|
---|
229 | /* XXX revisit when we have a hardware implementation! */
|
---|
230 | *params = GL_TRUE;
|
---|
231 | break;
|
---|
232 | default:
|
---|
233 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
234 | "glGetQueryObjectuivARB(pname)");
|
---|
235 | return;
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | void STATE_APIENTRY
|
---|
241 | crStateBeginQueryARB(GLenum target, GLuint id)
|
---|
242 | {
|
---|
243 | CRContext *g = GetCurrentContext();
|
---|
244 | CROcclusionState *o = &(g->occlusion);
|
---|
245 | CROcclusionObject *q;
|
---|
246 |
|
---|
247 | FLUSH();
|
---|
248 |
|
---|
249 | if (g->current.inBeginEnd) {
|
---|
250 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
251 | "glGetGetQueryObjectuivARB called in begin/end");
|
---|
252 | return;
|
---|
253 | }
|
---|
254 |
|
---|
255 | if (target != GL_SAMPLES_PASSED_ARB) {
|
---|
256 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
257 | "glBeginQueryARB(target)");
|
---|
258 | return;
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (o->currentQueryObject) {
|
---|
262 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
263 | "glBeginQueryARB(target)");
|
---|
264 | return;
|
---|
265 | }
|
---|
266 |
|
---|
267 | q = (CROcclusionObject *) crHashtableSearch(o->objects, id);
|
---|
268 | if (q && q->active) {
|
---|
269 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glBeginQueryARB");
|
---|
270 | return;
|
---|
271 | }
|
---|
272 | else if (!q) {
|
---|
273 | q = NewQueryObject(target, id);
|
---|
274 | if (!q) {
|
---|
275 | crStateError(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "glBeginQueryARB");
|
---|
276 | return;
|
---|
277 | }
|
---|
278 | crHashtableAdd(o->objects, id, q);
|
---|
279 | }
|
---|
280 |
|
---|
281 | q->active = GL_TRUE;
|
---|
282 | q->passedCounter = 0;
|
---|
283 | q->active = GL_TRUE;
|
---|
284 | q->passedCounter = 0;
|
---|
285 | o->currentQueryObject = id;
|
---|
286 | }
|
---|
287 |
|
---|
288 |
|
---|
289 | void STATE_APIENTRY
|
---|
290 | crStateEndQueryARB(GLenum target)
|
---|
291 | {
|
---|
292 | CRContext *g = GetCurrentContext();
|
---|
293 | CROcclusionState *o = &(g->occlusion);
|
---|
294 | CROcclusionObject *q;
|
---|
295 |
|
---|
296 | FLUSH();
|
---|
297 |
|
---|
298 | if (g->current.inBeginEnd) {
|
---|
299 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
300 | "glGetGetQueryObjectuivARB called in begin/end");
|
---|
301 | return;
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (target != GL_SAMPLES_PASSED_ARB) {
|
---|
305 | crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glEndQueryARB(target)");
|
---|
306 | return;
|
---|
307 | }
|
---|
308 |
|
---|
309 | q = (CROcclusionObject *) crHashtableSearch(o->objects, o->currentQueryObject);
|
---|
310 | if (!q || !q->active) {
|
---|
311 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
312 | "glEndQueryARB with glBeginQueryARB");
|
---|
313 | return;
|
---|
314 | }
|
---|
315 |
|
---|
316 | q->passedCounter = 0;
|
---|
317 | q->active = GL_FALSE;
|
---|
318 | o->currentQueryObject = 0;
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | void crStateOcclusionDiff(CROcclusionBits *bb, CRbitvalue *bitID,
|
---|
323 | CRContext *fromCtx, CRContext *toCtx)
|
---|
324 | {
|
---|
325 | /* Apparently, no occlusion state differencing needed */
|
---|
326 | (void)bb; (void)bitID; (void)fromCtx; (void)toCtx;
|
---|
327 | }
|
---|
328 |
|
---|
329 |
|
---|
330 | /*
|
---|
331 | * XXX this function might need some testing/fixing.
|
---|
332 | */
|
---|
333 | void crStateOcclusionSwitch(CROcclusionBits *bb, CRbitvalue *bitID,
|
---|
334 | CRContext *fromCtx, CRContext *toCtx)
|
---|
335 | {
|
---|
336 | /* Apparently, no occlusion state switching needed */
|
---|
337 | /* Note: we better not do a switch while we're inside a glBeginQuery/
|
---|
338 | * glEndQuery sequence.
|
---|
339 | */
|
---|
340 | (void)bb; (void)bitID; (void)fromCtx; (void)toCtx;
|
---|
341 | CRASSERT(!fromCtx->occlusion.currentQueryObject);
|
---|
342 | }
|
---|