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