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 | /*
|
---|
8 | * This file manages all the client-side state including:
|
---|
9 | * Pixel pack/unpack parameters
|
---|
10 | * Vertex arrays
|
---|
11 | */
|
---|
12 |
|
---|
13 |
|
---|
14 | #include "cr_mem.h"
|
---|
15 | #include "state.h"
|
---|
16 | #include "state/cr_statetypes.h"
|
---|
17 | #include "state/cr_statefuncs.h"
|
---|
18 | #include "state_internals.h"
|
---|
19 |
|
---|
20 | const CRPixelPackState crStateNativePixelPacking = {
|
---|
21 | 0, /* rowLength */
|
---|
22 | 0, /* skipRows */
|
---|
23 | 0, /* skipPixels */
|
---|
24 | 1, /* alignment */
|
---|
25 | 0, /* imageHeight */
|
---|
26 | 0, /* skipImages */
|
---|
27 | GL_FALSE, /* swapBytes */
|
---|
28 | GL_FALSE, /* psLSBFirst */
|
---|
29 | };
|
---|
30 |
|
---|
31 |
|
---|
32 | void crStateClientInitBits (CRClientBits *c)
|
---|
33 | {
|
---|
34 | int i;
|
---|
35 |
|
---|
36 | /* XXX why GLCLIENT_BIT_ALLOC? */
|
---|
37 | c->v = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
38 | c->n = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
39 | c->c = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
40 | c->s = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
41 | c->i = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
42 | for ( i = 0; i < CR_MAX_TEXTURE_UNITS; i++ )
|
---|
43 | c->t[i] = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
44 | c->e = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
45 | c->f = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
46 |
|
---|
47 | #ifdef CR_NV_vertex_program
|
---|
48 | for ( i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++ )
|
---|
49 | c->a[i] = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue));
|
---|
50 | #endif
|
---|
51 | }
|
---|
52 |
|
---|
53 | void crStateClientDestroyBits (CRClientBits *c)
|
---|
54 | {
|
---|
55 | int i;
|
---|
56 |
|
---|
57 | crFree(c->v);
|
---|
58 | crFree(c->n);
|
---|
59 | crFree(c->c);
|
---|
60 | crFree(c->s);
|
---|
61 | crFree(c->i);
|
---|
62 |
|
---|
63 | for ( i = 0; i < CR_MAX_TEXTURE_UNITS; i++ )
|
---|
64 | crFree(c->t[i]);
|
---|
65 |
|
---|
66 | crFree(c->e);
|
---|
67 | crFree(c->f);
|
---|
68 |
|
---|
69 | #ifdef CR_NV_vertex_program
|
---|
70 | for ( i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++ )
|
---|
71 | crFree(c->a[i]);
|
---|
72 | #endif
|
---|
73 | }
|
---|
74 |
|
---|
75 | static void crStateUnlockClientPointer(CRClientPointer* cp, int fFreePointer)
|
---|
76 | {
|
---|
77 | if (cp->locked)
|
---|
78 | {
|
---|
79 | #ifndef IN_GUEST
|
---|
80 | if (cp->p && fFreePointer != 0)
|
---|
81 | {
|
---|
82 | if (cp->fRealPtr)
|
---|
83 | {
|
---|
84 | crFree(cp->p);
|
---|
85 | cp->fRealPtr = 0;
|
---|
86 | }
|
---|
87 | cp->p = NULL;
|
---|
88 | }
|
---|
89 | #else
|
---|
90 | RT_NOREF(fFreePointer);
|
---|
91 | #endif
|
---|
92 | cp->locked = GL_FALSE;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | void crStateClientDestroy(CRContext *g)
|
---|
97 | {
|
---|
98 | CRClientState *c = &(g->client);
|
---|
99 | #ifdef CR_EXT_compiled_vertex_array
|
---|
100 | if (c->array.locked)
|
---|
101 | {
|
---|
102 | unsigned int i;
|
---|
103 |
|
---|
104 | crStateUnlockClientPointer(&c->array.v, 1 /*fFreePointer*/);
|
---|
105 | crStateUnlockClientPointer(&c->array.c, 1 /*fFreePointer*/);
|
---|
106 | crStateUnlockClientPointer(&c->array.f, 1 /*fFreePointer*/);
|
---|
107 | crStateUnlockClientPointer(&c->array.s, 1 /*fFreePointer*/);
|
---|
108 | crStateUnlockClientPointer(&c->array.e, 1 /*fFreePointer*/);
|
---|
109 | crStateUnlockClientPointer(&c->array.i, 1 /*fFreePointer*/);
|
---|
110 | crStateUnlockClientPointer(&c->array.n, 1 /*fFreePointer*/);
|
---|
111 | for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
|
---|
112 | {
|
---|
113 | crStateUnlockClientPointer(&c->array.t[i], 1 /*fFreePointer*/);
|
---|
114 | }
|
---|
115 | for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++)
|
---|
116 | {
|
---|
117 | crStateUnlockClientPointer(&c->array.a[i], 1 /*fFreePointer*/);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | #endif
|
---|
121 | }
|
---|
122 |
|
---|
123 | void crStateClientInit(CRContext *ctx)
|
---|
124 | {
|
---|
125 | CRClientState *c = &(ctx->client);
|
---|
126 | unsigned int i;
|
---|
127 |
|
---|
128 | /* pixel pack/unpack */
|
---|
129 | c->unpack.rowLength = 0;
|
---|
130 | c->unpack.skipRows = 0;
|
---|
131 | c->unpack.skipPixels = 0;
|
---|
132 | c->unpack.skipImages = 0;
|
---|
133 | c->unpack.alignment = 4;
|
---|
134 | c->unpack.imageHeight = 0;
|
---|
135 | c->unpack.swapBytes = GL_FALSE;
|
---|
136 | c->unpack.psLSBFirst = GL_FALSE;
|
---|
137 | c->pack.rowLength = 0;
|
---|
138 | c->pack.skipRows = 0;
|
---|
139 | c->pack.skipPixels = 0;
|
---|
140 | c->pack.skipImages = 0;
|
---|
141 | c->pack.alignment = 4;
|
---|
142 | c->pack.imageHeight = 0;
|
---|
143 | c->pack.swapBytes = GL_FALSE;
|
---|
144 | c->pack.psLSBFirst = GL_FALSE;
|
---|
145 |
|
---|
146 | /* ARB multitexture */
|
---|
147 | c->curClientTextureUnit = 0;
|
---|
148 |
|
---|
149 | #ifdef CR_EXT_compiled_vertex_array
|
---|
150 | c->array.lockFirst = 0;
|
---|
151 | c->array.lockCount = 0;
|
---|
152 | c->array.locked = GL_FALSE;
|
---|
153 | # ifdef IN_GUEST
|
---|
154 | c->array.synced = GL_FALSE;
|
---|
155 | # endif
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | /* vertex array */
|
---|
159 | c->array.v.p = NULL;
|
---|
160 | c->array.v.size = 4;
|
---|
161 | c->array.v.type = GL_FLOAT;
|
---|
162 | c->array.v.stride = 0;
|
---|
163 | c->array.v.enabled = 0;
|
---|
164 | #ifndef IN_GUEST
|
---|
165 | c->array.v.fRealPtr = 0;
|
---|
166 | #endif
|
---|
167 | #ifdef CR_ARB_vertex_buffer_object
|
---|
168 | c->array.v.buffer = ctx->bufferobject.arrayBuffer;
|
---|
169 | if (c->array.v.buffer)
|
---|
170 | ++c->array.v.buffer->refCount;
|
---|
171 | #endif
|
---|
172 | #ifdef CR_EXT_compiled_vertex_array
|
---|
173 | c->array.v.locked = GL_FALSE;
|
---|
174 | c->array.v.prevPtr = NULL;
|
---|
175 | c->array.v.prevStride = 0;
|
---|
176 | # ifndef IN_GUEST
|
---|
177 | c->array.v.fPrevRealPtr = 0;
|
---|
178 | # endif
|
---|
179 | #endif
|
---|
180 |
|
---|
181 | /* color array */
|
---|
182 | c->array.c.p = NULL;
|
---|
183 | c->array.c.size = 4;
|
---|
184 | c->array.c.type = GL_FLOAT;
|
---|
185 | c->array.c.stride = 0;
|
---|
186 | c->array.c.enabled = 0;
|
---|
187 | #ifndef IN_GUEST
|
---|
188 | c->array.c.fRealPtr = 0;
|
---|
189 | #endif
|
---|
190 | #ifdef CR_ARB_vertex_buffer_object
|
---|
191 | c->array.c.buffer = ctx->bufferobject.arrayBuffer;
|
---|
192 | if (c->array.c.buffer)
|
---|
193 | ++c->array.c.buffer->refCount;
|
---|
194 | #endif
|
---|
195 | #ifdef CR_EXT_compiled_vertex_array
|
---|
196 | c->array.c.locked = GL_FALSE;
|
---|
197 | c->array.c.prevPtr = NULL;
|
---|
198 | c->array.c.prevStride = 0;
|
---|
199 | # ifndef IN_GUEST
|
---|
200 | c->array.c.fPrevRealPtr = 0;
|
---|
201 | # endif
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | /* fog array */
|
---|
205 | c->array.f.p = NULL;
|
---|
206 | c->array.f.size = 0;
|
---|
207 | c->array.f.type = GL_FLOAT;
|
---|
208 | c->array.f.stride = 0;
|
---|
209 | c->array.f.enabled = 0;
|
---|
210 | #ifndef IN_GUEST
|
---|
211 | c->array.f.fRealPtr = 0;
|
---|
212 | #endif
|
---|
213 | #ifdef CR_ARB_vertex_buffer_object
|
---|
214 | c->array.f.buffer = ctx->bufferobject.arrayBuffer;
|
---|
215 | if (c->array.f.buffer)
|
---|
216 | ++c->array.f.buffer->refCount;
|
---|
217 | #endif
|
---|
218 | #ifdef CR_EXT_compiled_vertex_array
|
---|
219 | c->array.f.locked = GL_FALSE;
|
---|
220 | c->array.f.prevPtr = NULL;
|
---|
221 | c->array.f.prevStride = 0;
|
---|
222 | # ifndef IN_GUEST
|
---|
223 | c->array.f.fPrevRealPtr = 0;
|
---|
224 | # endif
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | /* secondary color array */
|
---|
228 | c->array.s.p = NULL;
|
---|
229 | c->array.s.size = 3;
|
---|
230 | c->array.s.type = GL_FLOAT;
|
---|
231 | c->array.s.stride = 0;
|
---|
232 | c->array.s.enabled = 0;
|
---|
233 | #ifndef IN_GUEST
|
---|
234 | c->array.s.fRealPtr = 0;
|
---|
235 | #endif
|
---|
236 | #ifdef CR_ARB_vertex_buffer_object
|
---|
237 | c->array.s.buffer = ctx->bufferobject.arrayBuffer;
|
---|
238 | if (c->array.s.buffer)
|
---|
239 | ++c->array.s.buffer->refCount;
|
---|
240 | #endif
|
---|
241 | #ifdef CR_EXT_compiled_vertex_array
|
---|
242 | c->array.s.locked = GL_FALSE;
|
---|
243 | c->array.s.prevPtr = NULL;
|
---|
244 | c->array.s.prevStride = 0;
|
---|
245 | # ifndef IN_GUEST
|
---|
246 | c->array.s.fPrevRealPtr = 0;
|
---|
247 | # endif
|
---|
248 | #endif
|
---|
249 |
|
---|
250 | /* edge flag array */
|
---|
251 | c->array.e.p = NULL;
|
---|
252 | c->array.e.size = 0;
|
---|
253 | c->array.e.type = GL_FLOAT;
|
---|
254 | c->array.e.stride = 0;
|
---|
255 | c->array.e.enabled = 0;
|
---|
256 | #ifndef IN_GUEST
|
---|
257 | c->array.e.fRealPtr = 0;
|
---|
258 | #endif
|
---|
259 | #ifdef CR_ARB_vertex_buffer_object
|
---|
260 | c->array.e.buffer = ctx->bufferobject.arrayBuffer;
|
---|
261 | if (c->array.e.buffer)
|
---|
262 | ++c->array.e.buffer->refCount;
|
---|
263 | #endif
|
---|
264 | #ifdef CR_EXT_compiled_vertex_array
|
---|
265 | c->array.e.locked = GL_FALSE;
|
---|
266 | c->array.e.prevPtr = NULL;
|
---|
267 | c->array.e.prevStride = 0;
|
---|
268 | # ifndef IN_GUEST
|
---|
269 | c->array.e.fPrevRealPtr = 0;
|
---|
270 | # endif
|
---|
271 | #endif
|
---|
272 |
|
---|
273 | /* color index array */
|
---|
274 | c->array.i.p = NULL;
|
---|
275 | c->array.i.size = 0;
|
---|
276 | c->array.i.type = GL_FLOAT;
|
---|
277 | c->array.i.stride = 0;
|
---|
278 | c->array.i.enabled = 0;
|
---|
279 | #ifndef IN_GUEST
|
---|
280 | c->array.i.fRealPtr = 0;
|
---|
281 | #endif
|
---|
282 | #ifdef CR_ARB_vertex_buffer_object
|
---|
283 | c->array.i.buffer = ctx->bufferobject.arrayBuffer;
|
---|
284 | if (c->array.i.buffer)
|
---|
285 | ++c->array.i.buffer->refCount;
|
---|
286 | #endif
|
---|
287 | #ifdef CR_EXT_compiled_vertex_array
|
---|
288 | c->array.i.locked = GL_FALSE;
|
---|
289 | c->array.i.prevPtr = NULL;
|
---|
290 | c->array.i.prevStride = 0;
|
---|
291 | # ifndef IN_GUEST
|
---|
292 | c->array.i.fPrevRealPtr = 0;
|
---|
293 | # endif
|
---|
294 | #endif
|
---|
295 |
|
---|
296 | /* normal array */
|
---|
297 | c->array.n.p = NULL;
|
---|
298 | c->array.n.size = 4;
|
---|
299 | c->array.n.type = GL_FLOAT;
|
---|
300 | c->array.n.stride = 0;
|
---|
301 | c->array.n.enabled = 0;
|
---|
302 | #ifndef IN_GUEST
|
---|
303 | c->array.n.fRealPtr = 0;
|
---|
304 | #endif
|
---|
305 | #ifdef CR_ARB_vertex_buffer_object
|
---|
306 | c->array.n.buffer = ctx->bufferobject.arrayBuffer;
|
---|
307 | if (c->array.n.buffer)
|
---|
308 | ++c->array.n.buffer->refCount;
|
---|
309 | #endif
|
---|
310 | #ifdef CR_EXT_compiled_vertex_array
|
---|
311 | c->array.n.locked = GL_FALSE;
|
---|
312 | c->array.n.prevPtr = NULL;
|
---|
313 | c->array.n.prevStride = 0;
|
---|
314 | # ifndef IN_GUEST
|
---|
315 | c->array.n.fPrevRealPtr = 0;
|
---|
316 | # endif
|
---|
317 | #endif
|
---|
318 |
|
---|
319 | /* texcoord arrays */
|
---|
320 | for (i = 0 ; i < CR_MAX_TEXTURE_UNITS ; i++)
|
---|
321 | {
|
---|
322 | c->array.t[i].p = NULL;
|
---|
323 | c->array.t[i].size = 4;
|
---|
324 | c->array.t[i].type = GL_FLOAT;
|
---|
325 | c->array.t[i].stride = 0;
|
---|
326 | c->array.t[i].enabled = 0;
|
---|
327 | #ifndef IN_GUEST
|
---|
328 | c->array.t[i].fRealPtr = 0;
|
---|
329 | #endif
|
---|
330 | #ifdef CR_ARB_vertex_buffer_object
|
---|
331 | c->array.t[i].buffer = ctx->bufferobject.arrayBuffer;
|
---|
332 | if (c->array.t[i].buffer)
|
---|
333 | ++c->array.t[i].buffer->refCount;
|
---|
334 | #endif
|
---|
335 | #ifdef CR_EXT_compiled_vertex_array
|
---|
336 | c->array.t[i].locked = GL_FALSE;
|
---|
337 | c->array.t[i].prevPtr = NULL;
|
---|
338 | c->array.t[i].prevStride = 0;
|
---|
339 | #endif
|
---|
340 | # ifndef IN_GUEST
|
---|
341 | c->array.t[i].fPrevRealPtr = 0;
|
---|
342 | # endif
|
---|
343 | }
|
---|
344 |
|
---|
345 | /* generic vertex attributes */
|
---|
346 | #ifdef CR_NV_vertex_program
|
---|
347 | for (i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++) {
|
---|
348 | c->array.a[i].enabled = GL_FALSE;
|
---|
349 | c->array.a[i].type = GL_FLOAT;
|
---|
350 | c->array.a[i].size = 4;
|
---|
351 | c->array.a[i].stride = 0;
|
---|
352 | # ifndef IN_GUEST
|
---|
353 | c->array.a[i].fRealPtr = 0;
|
---|
354 | # endif
|
---|
355 | #ifdef CR_ARB_vertex_buffer_object
|
---|
356 | c->array.a[i].buffer = ctx->bufferobject.arrayBuffer;
|
---|
357 | if (c->array.a[i].buffer)
|
---|
358 | ++c->array.a[i].buffer->refCount;
|
---|
359 | #endif
|
---|
360 | #ifdef CR_EXT_compiled_vertex_array
|
---|
361 | c->array.a[i].locked = GL_FALSE;
|
---|
362 | c->array.a[i].prevPtr = NULL;
|
---|
363 | c->array.a[i].prevStride = 0;
|
---|
364 | # ifndef IN_GUEST
|
---|
365 | c->array.a[i].fPrevRealPtr = 0;
|
---|
366 | # endif
|
---|
367 | #endif
|
---|
368 | }
|
---|
369 | #endif
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | /*
|
---|
374 | * PixelStore functions are here, not in state_pixel.c because this
|
---|
375 | * is client-side state, like vertex arrays.
|
---|
376 | */
|
---|
377 |
|
---|
378 | void STATE_APIENTRY crStatePixelStoref (PCRStateTracker pState, GLenum pname, GLfloat param)
|
---|
379 | {
|
---|
380 |
|
---|
381 | /* The GL SPEC says I can do this on page 76. */
|
---|
382 | switch( pname )
|
---|
383 | {
|
---|
384 | case GL_PACK_SWAP_BYTES:
|
---|
385 | case GL_PACK_LSB_FIRST:
|
---|
386 | case GL_UNPACK_SWAP_BYTES:
|
---|
387 | case GL_UNPACK_LSB_FIRST:
|
---|
388 | crStatePixelStorei(pState, pname, param == 0.0f ? 0: 1 );
|
---|
389 | break;
|
---|
390 | default:
|
---|
391 | crStatePixelStorei(pState, pname, (GLint) param );
|
---|
392 | break;
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | void STATE_APIENTRY crStatePixelStorei (PCRStateTracker pState, GLenum pname, GLint param)
|
---|
397 | {
|
---|
398 | CRContext *g = GetCurrentContext(pState);
|
---|
399 | CRClientState *c = &(g->client);
|
---|
400 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
401 | CRClientBits *cb = &(sb->client);
|
---|
402 |
|
---|
403 | if (g->current.inBeginEnd)
|
---|
404 | {
|
---|
405 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "PixelStore{if} called in Begin/End");
|
---|
406 | return;
|
---|
407 | }
|
---|
408 |
|
---|
409 | FLUSH();
|
---|
410 |
|
---|
411 | switch(pname) {
|
---|
412 | case GL_PACK_SWAP_BYTES:
|
---|
413 | c->pack.swapBytes = (GLboolean) param;
|
---|
414 | DIRTY(cb->pack, g->neg_bitid);
|
---|
415 | break;
|
---|
416 | case GL_PACK_LSB_FIRST:
|
---|
417 | c->pack.psLSBFirst = (GLboolean) param;
|
---|
418 | DIRTY(cb->pack, g->neg_bitid);
|
---|
419 | break;
|
---|
420 | case GL_PACK_ROW_LENGTH:
|
---|
421 | if (param < 0.0f)
|
---|
422 | {
|
---|
423 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
|
---|
424 | return;
|
---|
425 | }
|
---|
426 | c->pack.rowLength = param;
|
---|
427 | DIRTY(cb->pack, g->neg_bitid);
|
---|
428 | break;
|
---|
429 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
430 | case GL_PACK_IMAGE_HEIGHT:
|
---|
431 | if (param < 0.0f)
|
---|
432 | {
|
---|
433 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
|
---|
434 | return;
|
---|
435 | }
|
---|
436 | c->pack.imageHeight = param;
|
---|
437 | DIRTY(cb->pack, g->neg_bitid);
|
---|
438 | break;
|
---|
439 | #endif
|
---|
440 | case GL_PACK_SKIP_IMAGES:
|
---|
441 | if (param < 0.0f)
|
---|
442 | {
|
---|
443 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
|
---|
444 | return;
|
---|
445 | }
|
---|
446 | c->pack.skipImages = param;
|
---|
447 | DIRTY(cb->pack, g->neg_bitid);
|
---|
448 | break;
|
---|
449 | case GL_PACK_SKIP_PIXELS:
|
---|
450 | if (param < 0.0f)
|
---|
451 | {
|
---|
452 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
|
---|
453 | return;
|
---|
454 | }
|
---|
455 | c->pack.skipPixels = param;
|
---|
456 | DIRTY(cb->pack, g->neg_bitid);
|
---|
457 | break;
|
---|
458 | case GL_PACK_SKIP_ROWS:
|
---|
459 | if (param < 0.0f)
|
---|
460 | {
|
---|
461 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
|
---|
462 | return;
|
---|
463 | }
|
---|
464 | c->pack.skipRows = param;
|
---|
465 | DIRTY(cb->pack, g->neg_bitid);
|
---|
466 | break;
|
---|
467 | case GL_PACK_ALIGNMENT:
|
---|
468 | if (((GLint) param) != 1 &&
|
---|
469 | ((GLint) param) != 2 &&
|
---|
470 | ((GLint) param) != 4 &&
|
---|
471 | ((GLint) param) != 8)
|
---|
472 | {
|
---|
473 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
|
---|
474 | return;
|
---|
475 | }
|
---|
476 | c->pack.alignment = param;
|
---|
477 | DIRTY(cb->pack, g->neg_bitid);
|
---|
478 | break;
|
---|
479 |
|
---|
480 | case GL_UNPACK_SWAP_BYTES:
|
---|
481 | c->unpack.swapBytes = (GLboolean) param;
|
---|
482 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
483 | break;
|
---|
484 | case GL_UNPACK_LSB_FIRST:
|
---|
485 | c->unpack.psLSBFirst = (GLboolean) param;
|
---|
486 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
487 | break;
|
---|
488 | case GL_UNPACK_ROW_LENGTH:
|
---|
489 | if (param < 0.0f)
|
---|
490 | {
|
---|
491 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Length: %f", param);
|
---|
492 | return;
|
---|
493 | }
|
---|
494 | c->unpack.rowLength = param;
|
---|
495 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
496 | break;
|
---|
497 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
498 | case GL_UNPACK_IMAGE_HEIGHT:
|
---|
499 | if (param < 0.0f)
|
---|
500 | {
|
---|
501 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Image Height: %f", param);
|
---|
502 | return;
|
---|
503 | }
|
---|
504 | c->unpack.imageHeight = param;
|
---|
505 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
506 | break;
|
---|
507 | #endif
|
---|
508 | case GL_UNPACK_SKIP_IMAGES:
|
---|
509 | if (param < 0.0f)
|
---|
510 | {
|
---|
511 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Images: %f", param);
|
---|
512 | return;
|
---|
513 | }
|
---|
514 | c->unpack.skipImages = param;
|
---|
515 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
516 | break;
|
---|
517 | case GL_UNPACK_SKIP_PIXELS:
|
---|
518 | if (param < 0.0f)
|
---|
519 | {
|
---|
520 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Skip Pixels: %f", param);
|
---|
521 | return;
|
---|
522 | }
|
---|
523 | c->unpack.skipPixels = param;
|
---|
524 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
525 | break;
|
---|
526 | case GL_UNPACK_SKIP_ROWS:
|
---|
527 | if (param < 0.0f)
|
---|
528 | {
|
---|
529 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Negative Row Skip: %f", param);
|
---|
530 | return;
|
---|
531 | }
|
---|
532 | c->unpack.skipRows = param;
|
---|
533 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
534 | break;
|
---|
535 | case GL_UNPACK_ALIGNMENT:
|
---|
536 | if (((GLint) param) != 1 &&
|
---|
537 | ((GLint) param) != 2 &&
|
---|
538 | ((GLint) param) != 4 &&
|
---|
539 | ((GLint) param) != 8)
|
---|
540 | {
|
---|
541 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Invalid Alignment: %f", param);
|
---|
542 | return;
|
---|
543 | }
|
---|
544 | c->unpack.alignment = param;
|
---|
545 | DIRTY(cb->unpack, g->neg_bitid);
|
---|
546 | break;
|
---|
547 | default:
|
---|
548 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "Unknown glPixelStore Pname: %d", pname);
|
---|
549 | return;
|
---|
550 | }
|
---|
551 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | static void setClientState(CRContext *g, CRClientState *c, CRClientBits *cb,
|
---|
556 | CRbitvalue *neg_bitid, GLenum array, GLboolean state)
|
---|
557 | {
|
---|
558 | PCRStateTracker pState = g->pStateTracker;
|
---|
559 |
|
---|
560 | switch (array)
|
---|
561 | {
|
---|
562 | #ifdef CR_NV_vertex_program
|
---|
563 | case GL_VERTEX_ATTRIB_ARRAY0_NV:
|
---|
564 | case GL_VERTEX_ATTRIB_ARRAY1_NV:
|
---|
565 | case GL_VERTEX_ATTRIB_ARRAY2_NV:
|
---|
566 | case GL_VERTEX_ATTRIB_ARRAY3_NV:
|
---|
567 | case GL_VERTEX_ATTRIB_ARRAY4_NV:
|
---|
568 | case GL_VERTEX_ATTRIB_ARRAY5_NV:
|
---|
569 | case GL_VERTEX_ATTRIB_ARRAY6_NV:
|
---|
570 | case GL_VERTEX_ATTRIB_ARRAY7_NV:
|
---|
571 | case GL_VERTEX_ATTRIB_ARRAY8_NV:
|
---|
572 | case GL_VERTEX_ATTRIB_ARRAY9_NV:
|
---|
573 | case GL_VERTEX_ATTRIB_ARRAY10_NV:
|
---|
574 | case GL_VERTEX_ATTRIB_ARRAY11_NV:
|
---|
575 | case GL_VERTEX_ATTRIB_ARRAY12_NV:
|
---|
576 | case GL_VERTEX_ATTRIB_ARRAY13_NV:
|
---|
577 | case GL_VERTEX_ATTRIB_ARRAY14_NV:
|
---|
578 | case GL_VERTEX_ATTRIB_ARRAY15_NV:
|
---|
579 | {
|
---|
580 | const GLuint i = array - GL_VERTEX_ATTRIB_ARRAY0_NV;
|
---|
581 | c->array.a[i].enabled = state;
|
---|
582 | }
|
---|
583 | break;
|
---|
584 | #endif
|
---|
585 | case GL_VERTEX_ARRAY:
|
---|
586 | c->array.v.enabled = state;
|
---|
587 | break;
|
---|
588 | case GL_COLOR_ARRAY:
|
---|
589 | c->array.c.enabled = state;
|
---|
590 | break;
|
---|
591 | case GL_NORMAL_ARRAY:
|
---|
592 | c->array.n.enabled = state;
|
---|
593 | break;
|
---|
594 | case GL_INDEX_ARRAY:
|
---|
595 | c->array.i.enabled = state;
|
---|
596 | break;
|
---|
597 | case GL_TEXTURE_COORD_ARRAY:
|
---|
598 | c->array.t[c->curClientTextureUnit].enabled = state;
|
---|
599 | break;
|
---|
600 | case GL_EDGE_FLAG_ARRAY:
|
---|
601 | c->array.e.enabled = state;
|
---|
602 | break;
|
---|
603 | #ifdef CR_EXT_fog_coord
|
---|
604 | case GL_FOG_COORDINATE_ARRAY_EXT:
|
---|
605 | c->array.f.enabled = state;
|
---|
606 | break;
|
---|
607 | #endif
|
---|
608 | #ifdef CR_EXT_secondary_color
|
---|
609 | case GL_SECONDARY_COLOR_ARRAY_EXT:
|
---|
610 | if( g->extensions.EXT_secondary_color ){
|
---|
611 | c->array.s.enabled = state;
|
---|
612 | }
|
---|
613 | else {
|
---|
614 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
|
---|
615 | return;
|
---|
616 | }
|
---|
617 | break;
|
---|
618 | #endif
|
---|
619 | default:
|
---|
620 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to Enable/Disable Client State: 0x%x", array );
|
---|
621 | return;
|
---|
622 | }
|
---|
623 | DIRTY(cb->dirty, neg_bitid);
|
---|
624 | DIRTY(cb->enableClientState, neg_bitid);
|
---|
625 | }
|
---|
626 |
|
---|
627 | void STATE_APIENTRY crStateEnableClientState (PCRStateTracker pState, GLenum array)
|
---|
628 | {
|
---|
629 | CRContext *g = GetCurrentContext(pState);
|
---|
630 | CRClientState *c = &(g->client);
|
---|
631 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
632 | CRClientBits *cb = &(sb->client);
|
---|
633 |
|
---|
634 | FLUSH();
|
---|
635 |
|
---|
636 | setClientState(g, c, cb, g->neg_bitid, array, GL_TRUE);
|
---|
637 | }
|
---|
638 |
|
---|
639 | void STATE_APIENTRY crStateDisableClientState (PCRStateTracker pState, GLenum array)
|
---|
640 | {
|
---|
641 | CRContext *g = GetCurrentContext(pState);
|
---|
642 | CRClientState *c = &(g->client);
|
---|
643 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
644 | CRClientBits *cb = &(sb->client);
|
---|
645 |
|
---|
646 | FLUSH();
|
---|
647 |
|
---|
648 | setClientState(g, c, cb, g->neg_bitid, array, GL_FALSE);
|
---|
649 | }
|
---|
650 |
|
---|
651 | static void
|
---|
652 | crStateClientSetPointer(CRContext *g, CRClientPointer *cp, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
|
---|
653 | const GLvoid *pointer CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
654 | {
|
---|
655 | PCRStateTracker pState = g->pStateTracker;
|
---|
656 |
|
---|
657 | #ifdef CR_EXT_compiled_vertex_array
|
---|
658 | crStateUnlockClientPointer(cp, 0 /*fFreePointer*/);
|
---|
659 | # ifndef IN_GUEST
|
---|
660 | if (cp->prevPtr && cp->fPrevRealPtr)
|
---|
661 | {
|
---|
662 | crFree(cp->prevPtr);
|
---|
663 | cp->fPrevRealPtr = 0;
|
---|
664 | }
|
---|
665 | # endif
|
---|
666 | cp->prevPtr = cp->p;
|
---|
667 | cp->prevStride = cp->stride;
|
---|
668 | # ifndef IN_GUEST
|
---|
669 | cp->fPrevRealPtr = cp->fRealPtr;
|
---|
670 | # endif
|
---|
671 | #endif
|
---|
672 |
|
---|
673 | cp->p = (unsigned char *) pointer;
|
---|
674 | cp->size = size;
|
---|
675 | cp->type = type;
|
---|
676 | cp->normalized = normalized;
|
---|
677 | #ifndef IN_GUEST
|
---|
678 | cp->fRealPtr = fRealPtr;
|
---|
679 | #endif
|
---|
680 |
|
---|
681 | /* Calculate the bytes per index for address calculation */
|
---|
682 | cp->bytesPerIndex = size;
|
---|
683 | switch (type)
|
---|
684 | {
|
---|
685 | case GL_BYTE:
|
---|
686 | case GL_UNSIGNED_BYTE:
|
---|
687 | break;
|
---|
688 | case GL_SHORT:
|
---|
689 | case GL_UNSIGNED_SHORT:
|
---|
690 | cp->bytesPerIndex *= sizeof(GLshort);
|
---|
691 | break;
|
---|
692 | case GL_INT:
|
---|
693 | case GL_UNSIGNED_INT:
|
---|
694 | cp->bytesPerIndex *= sizeof(GLint);
|
---|
695 | break;
|
---|
696 | case GL_FLOAT:
|
---|
697 | cp->bytesPerIndex *= sizeof(GLfloat);
|
---|
698 | break;
|
---|
699 | case GL_DOUBLE:
|
---|
700 | cp->bytesPerIndex *= sizeof(GLdouble);
|
---|
701 | break;
|
---|
702 | default:
|
---|
703 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
704 | "Unknown type of vertex array: %d", type );
|
---|
705 | return;
|
---|
706 | }
|
---|
707 |
|
---|
708 | /*
|
---|
709 | ** Note: If stride==0 then we set the
|
---|
710 | ** stride equal address offset
|
---|
711 | ** therefore stride can never equal
|
---|
712 | ** zero.
|
---|
713 | */
|
---|
714 | if (stride)
|
---|
715 | cp->stride = stride;
|
---|
716 | else
|
---|
717 | cp->stride = cp->bytesPerIndex;
|
---|
718 |
|
---|
719 | #ifdef CR_ARB_vertex_buffer_object
|
---|
720 | if (cp->buffer)
|
---|
721 | {
|
---|
722 | --cp->buffer->refCount;
|
---|
723 | CRASSERT(cp->buffer->refCount && cp->buffer->refCount < UINT32_MAX/2);
|
---|
724 | }
|
---|
725 | cp->buffer = g->bufferobject.arrayBuffer;
|
---|
726 | if (cp->buffer)
|
---|
727 | ++cp->buffer->refCount;
|
---|
728 | #endif
|
---|
729 | }
|
---|
730 |
|
---|
731 | void STATE_APIENTRY crStateVertexPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
732 | {
|
---|
733 | CRContext *g = GetCurrentContext(pState);
|
---|
734 | CRClientState *c = &(g->client);
|
---|
735 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
736 | CRClientBits *cb = &(sb->client);
|
---|
737 |
|
---|
738 | FLUSH();
|
---|
739 |
|
---|
740 | if (size != 2 && size != 3 && size != 4)
|
---|
741 | {
|
---|
742 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: invalid size: %d", size);
|
---|
743 | return;
|
---|
744 | }
|
---|
745 | if (type != GL_SHORT && type != GL_INT &&
|
---|
746 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
747 | {
|
---|
748 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glVertexPointer: invalid type: 0x%x", type);
|
---|
749 | return;
|
---|
750 | }
|
---|
751 | if (stride < 0)
|
---|
752 | {
|
---|
753 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexPointer: stride was negative: %d", stride);
|
---|
754 | return;
|
---|
755 | }
|
---|
756 |
|
---|
757 | crStateClientSetPointer(g, &(c->array.v), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
758 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
759 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
760 | DIRTY(cb->v, g->neg_bitid);
|
---|
761 | }
|
---|
762 |
|
---|
763 | void STATE_APIENTRY crStateColorPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
764 | {
|
---|
765 | CRContext *g = GetCurrentContext(pState);
|
---|
766 | CRClientState *c = &(g->client);
|
---|
767 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
768 | CRClientBits *cb = &(sb->client);
|
---|
769 |
|
---|
770 | FLUSH();
|
---|
771 |
|
---|
772 | if (size != 3 && size != 4)
|
---|
773 | {
|
---|
774 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: invalid size: %d", size);
|
---|
775 | return;
|
---|
776 | }
|
---|
777 | if (type != GL_BYTE && type != GL_UNSIGNED_BYTE &&
|
---|
778 | type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
|
---|
779 | type != GL_INT && type != GL_UNSIGNED_INT &&
|
---|
780 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
781 | {
|
---|
782 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glColorPointer: invalid type: 0x%x", type);
|
---|
783 | return;
|
---|
784 | }
|
---|
785 | if (stride < 0)
|
---|
786 | {
|
---|
787 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glColorPointer: stride was negative: %d", stride);
|
---|
788 | return;
|
---|
789 | }
|
---|
790 |
|
---|
791 | crStateClientSetPointer(g, &(c->array.c), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
792 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
793 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
794 | DIRTY(cb->c, g->neg_bitid);
|
---|
795 | }
|
---|
796 |
|
---|
797 | void STATE_APIENTRY crStateSecondaryColorPointerEXT(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
798 | {
|
---|
799 | CRContext *g = GetCurrentContext(pState);
|
---|
800 | CRClientState *c = &(g->client);
|
---|
801 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
802 | CRClientBits *cb = &(sb->client);
|
---|
803 |
|
---|
804 | FLUSH();
|
---|
805 |
|
---|
806 | if ( !g->extensions.EXT_secondary_color )
|
---|
807 | {
|
---|
808 | crError( "glSecondaryColorPointerEXT called but EXT_secondary_color is disabled." );
|
---|
809 | return;
|
---|
810 | }
|
---|
811 |
|
---|
812 | /*Note: According to opengl spec, only size==3 should be accepted here.
|
---|
813 | *But it turns out that most drivers accept size==4 here as well, and 4th value
|
---|
814 | *could even be accessed in shaders code.
|
---|
815 | *Having a strict check here, leads to difference between guest and host gpu states, which
|
---|
816 | *in turn could lead to crashes when using server side VBOs.
|
---|
817 | *@todo: add error reporting to state's VBO related functions and abort dispatching to
|
---|
818 | *real gpu on any failure to prevent other possible issues.
|
---|
819 | */
|
---|
820 |
|
---|
821 | if ((size != 3) && (size != 4))
|
---|
822 | {
|
---|
823 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: invalid size: %d", size);
|
---|
824 | return;
|
---|
825 | }
|
---|
826 | if (type != GL_BYTE && type != GL_UNSIGNED_BYTE &&
|
---|
827 | type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
|
---|
828 | type != GL_INT && type != GL_UNSIGNED_INT &&
|
---|
829 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
830 | {
|
---|
831 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glSecondaryColorPointerEXT: invalid type: 0x%x", type);
|
---|
832 | return;
|
---|
833 | }
|
---|
834 | if (stride < 0)
|
---|
835 | {
|
---|
836 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glSecondaryColorPointerEXT: stride was negative: %d", stride);
|
---|
837 | return;
|
---|
838 | }
|
---|
839 |
|
---|
840 | crStateClientSetPointer(g, &(c->array.s), size, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
841 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
842 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
843 | DIRTY(cb->s, g->neg_bitid);
|
---|
844 | }
|
---|
845 |
|
---|
846 | void STATE_APIENTRY crStateIndexPointer(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
847 | {
|
---|
848 | CRContext *g = GetCurrentContext(pState);
|
---|
849 | CRClientState *c = &(g->client);
|
---|
850 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
851 | CRClientBits *cb = &(sb->client);
|
---|
852 |
|
---|
853 | FLUSH();
|
---|
854 |
|
---|
855 | if (type != GL_SHORT && type != GL_INT && type != GL_UNSIGNED_BYTE &&
|
---|
856 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
857 | {
|
---|
858 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glIndexPointer: invalid type: 0x%x", type);
|
---|
859 | return;
|
---|
860 | }
|
---|
861 | if (stride < 0)
|
---|
862 | {
|
---|
863 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glIndexPointer: stride was negative: %d", stride);
|
---|
864 | return;
|
---|
865 | }
|
---|
866 |
|
---|
867 | crStateClientSetPointer(g, &(c->array.i), 1, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
868 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
869 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
870 | DIRTY(cb->i, g->neg_bitid);
|
---|
871 | }
|
---|
872 |
|
---|
873 | void STATE_APIENTRY crStateNormalPointer(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
874 | {
|
---|
875 | CRContext *g = GetCurrentContext(pState);
|
---|
876 | CRClientState *c = &(g->client);
|
---|
877 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
878 | CRClientBits *cb = &(sb->client);
|
---|
879 |
|
---|
880 | FLUSH();
|
---|
881 |
|
---|
882 | if (type != GL_BYTE && type != GL_SHORT &&
|
---|
883 | type != GL_INT && type != GL_FLOAT &&
|
---|
884 | type != GL_DOUBLE)
|
---|
885 | {
|
---|
886 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glNormalPointer: invalid type: 0x%x", type);
|
---|
887 | return;
|
---|
888 | }
|
---|
889 | if (stride < 0)
|
---|
890 | {
|
---|
891 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glNormalPointer: stride was negative: %d", stride);
|
---|
892 | return;
|
---|
893 | }
|
---|
894 |
|
---|
895 | crStateClientSetPointer(g, &(c->array.n), 3, type, GL_TRUE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
896 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
897 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
898 | DIRTY(cb->n, g->neg_bitid);
|
---|
899 | }
|
---|
900 |
|
---|
901 | void STATE_APIENTRY crStateTexCoordPointer(PCRStateTracker pState, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
902 | {
|
---|
903 | CRContext *g = GetCurrentContext(pState);
|
---|
904 | CRClientState *c = &(g->client);
|
---|
905 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
906 | CRClientBits *cb = &(sb->client);
|
---|
907 |
|
---|
908 | FLUSH();
|
---|
909 |
|
---|
910 | if (size != 1 && size != 2 && size != 3 && size != 4)
|
---|
911 | {
|
---|
912 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: invalid size: %d", size);
|
---|
913 | return;
|
---|
914 | }
|
---|
915 | if (type != GL_SHORT && type != GL_INT &&
|
---|
916 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
917 | {
|
---|
918 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glTexCoordPointer: invalid type: 0x%x", type);
|
---|
919 | return;
|
---|
920 | }
|
---|
921 | if (stride < 0)
|
---|
922 | {
|
---|
923 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
|
---|
924 | return;
|
---|
925 | }
|
---|
926 |
|
---|
927 | crStateClientSetPointer(g, &(c->array.t[c->curClientTextureUnit]), size, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
928 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
929 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
930 | DIRTY(cb->t[c->curClientTextureUnit], g->neg_bitid);
|
---|
931 | }
|
---|
932 |
|
---|
933 | void STATE_APIENTRY crStateEdgeFlagPointer(PCRStateTracker pState, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
934 | {
|
---|
935 | CRContext *g = GetCurrentContext(pState);
|
---|
936 | CRClientState *c = &(g->client);
|
---|
937 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
938 | CRClientBits *cb = &(sb->client);
|
---|
939 |
|
---|
940 | FLUSH();
|
---|
941 |
|
---|
942 | if (stride < 0)
|
---|
943 | {
|
---|
944 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glTexCoordPointer: stride was negative: %d", stride);
|
---|
945 | return;
|
---|
946 | }
|
---|
947 |
|
---|
948 | crStateClientSetPointer(g, &(c->array.e), 1, GL_UNSIGNED_BYTE, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
949 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
950 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
951 | DIRTY(cb->e, g->neg_bitid);
|
---|
952 | }
|
---|
953 |
|
---|
954 | void STATE_APIENTRY crStateFogCoordPointerEXT(PCRStateTracker pState, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
955 | {
|
---|
956 | CRContext *g = GetCurrentContext(pState);
|
---|
957 | CRClientState *c = &(g->client);
|
---|
958 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
959 | CRClientBits *cb = &(sb->client);
|
---|
960 |
|
---|
961 | FLUSH();
|
---|
962 |
|
---|
963 | if (type != GL_BYTE && type != GL_UNSIGNED_BYTE &&
|
---|
964 | type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
|
---|
965 | type != GL_INT && type != GL_UNSIGNED_INT &&
|
---|
966 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
967 | {
|
---|
968 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glFogCoordPointerEXT: invalid type: 0x%x", type);
|
---|
969 | return;
|
---|
970 | }
|
---|
971 | if (stride < 0)
|
---|
972 | {
|
---|
973 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glFogCoordPointerEXT: stride was negative: %d", stride);
|
---|
974 | return;
|
---|
975 | }
|
---|
976 |
|
---|
977 | crStateClientSetPointer(g, &(c->array.f), 1, type, GL_FALSE, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
978 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
979 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
980 | DIRTY(cb->f, g->neg_bitid);
|
---|
981 | }
|
---|
982 |
|
---|
983 |
|
---|
984 | void STATE_APIENTRY crStateVertexAttribPointerNV(PCRStateTracker pState, GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
985 | {
|
---|
986 | GLboolean normalized = GL_FALSE;
|
---|
987 | /* Extra error checking for NV arrays */
|
---|
988 | if (type != GL_UNSIGNED_BYTE && type != GL_SHORT &&
|
---|
989 | type != GL_FLOAT && type != GL_DOUBLE) {
|
---|
990 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
991 | "glVertexAttribPointerNV: invalid type: 0x%x", type);
|
---|
992 | return;
|
---|
993 | }
|
---|
994 | crStateVertexAttribPointerARB(pState, index, size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
995 | }
|
---|
996 |
|
---|
997 |
|
---|
998 | void STATE_APIENTRY crStateVertexAttribPointerARB(PCRStateTracker pState, GLuint index, GLint size, GLenum type, GLboolean normalized,
|
---|
999 | GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
1000 | {
|
---|
1001 | CRContext *g = GetCurrentContext(pState);
|
---|
1002 | CRClientState *c = &(g->client);
|
---|
1003 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
1004 | CRClientBits *cb = &(sb->client);
|
---|
1005 |
|
---|
1006 | FLUSH();
|
---|
1007 |
|
---|
1008 | if (index >= CR_MAX_VERTEX_ATTRIBS)
|
---|
1009 | {
|
---|
1010 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid index: %d", (int) index);
|
---|
1011 | return;
|
---|
1012 | }
|
---|
1013 | if (size != 1 && size != 2 && size != 3 && size != 4)
|
---|
1014 | {
|
---|
1015 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: invalid size: %d", size);
|
---|
1016 | return;
|
---|
1017 | }
|
---|
1018 | if (type != GL_BYTE && type != GL_UNSIGNED_BYTE &&
|
---|
1019 | type != GL_SHORT && type != GL_UNSIGNED_SHORT &&
|
---|
1020 | type != GL_INT && type != GL_UNSIGNED_INT &&
|
---|
1021 | type != GL_FLOAT && type != GL_DOUBLE)
|
---|
1022 | {
|
---|
1023 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glVertexAttribPointerARB: invalid type: 0x%x", type);
|
---|
1024 | return;
|
---|
1025 | }
|
---|
1026 | if (stride < 0)
|
---|
1027 | {
|
---|
1028 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glVertexAttribPointerARB: stride was negative: %d", stride);
|
---|
1029 | return;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | crStateClientSetPointer(g, &(c->array.a[index]), size, type, normalized, stride, p CRVBOX_HOST_ONLY_PARAM(fRealPtr));
|
---|
1033 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
1034 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
1035 | DIRTY(cb->a[index], g->neg_bitid);
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | void STATE_APIENTRY crStateGetVertexAttribPointervNV(PCRStateTracker pState, GLuint index, GLenum pname, GLvoid **pointer)
|
---|
1040 | {
|
---|
1041 | CRContext *g = GetCurrentContext(pState);
|
---|
1042 |
|
---|
1043 | if (g->current.inBeginEnd) {
|
---|
1044 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1045 | "glGetVertexAttribPointervNV called in Begin/End");
|
---|
1046 | return;
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | if (index >= CR_MAX_VERTEX_ATTRIBS) {
|
---|
1050 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
|
---|
1051 | "glGetVertexAttribPointervNV(index)");
|
---|
1052 | return;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | if (pname != GL_ATTRIB_ARRAY_POINTER_NV) {
|
---|
1056 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
|
---|
1057 | "glGetVertexAttribPointervNV(pname)");
|
---|
1058 | return;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | *pointer = g->client.array.a[index].p;
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 |
|
---|
1065 | void STATE_APIENTRY crStateGetVertexAttribPointervARB(PCRStateTracker pState, GLuint index, GLenum pname, GLvoid **pointer)
|
---|
1066 | {
|
---|
1067 | crStateGetVertexAttribPointervNV(pState, index, pname, pointer);
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 |
|
---|
1071 |
|
---|
1072 | /*
|
---|
1073 | ** Currently I treat Interleaved Arrays as if the
|
---|
1074 | ** user uses them as separate arrays.
|
---|
1075 | ** Certainly not the most efficient method but it
|
---|
1076 | ** lets me use the same glDrawArrays method.
|
---|
1077 | */
|
---|
1078 | void STATE_APIENTRY crStateInterleavedArrays(PCRStateTracker pState, GLenum format, GLsizei stride, const GLvoid *p CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
1079 | {
|
---|
1080 | CRContext *g = GetCurrentContext(pState);
|
---|
1081 | CRClientState *c = &(g->client);
|
---|
1082 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
1083 | CRClientBits *cb = &(sb->client);
|
---|
1084 | CRClientPointer *cp;
|
---|
1085 | unsigned char *base = (unsigned char *) p;
|
---|
1086 |
|
---|
1087 | #ifndef IN_GUEST
|
---|
1088 | RT_NOREF(fRealPtr);
|
---|
1089 | #endif
|
---|
1090 |
|
---|
1091 | if (g->current.inBeginEnd)
|
---|
1092 | {
|
---|
1093 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays called in begin/end");
|
---|
1094 | return;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | FLUSH();
|
---|
1098 |
|
---|
1099 | if (stride < 0)
|
---|
1100 | {
|
---|
1101 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glInterleavedArrays: stride < 0: %d", stride);
|
---|
1102 | return;
|
---|
1103 | }
|
---|
1104 |
|
---|
1105 | switch (format)
|
---|
1106 | {
|
---|
1107 | case GL_T4F_C4F_N3F_V4F:
|
---|
1108 | case GL_T2F_C4F_N3F_V3F:
|
---|
1109 | case GL_C4F_N3F_V3F:
|
---|
1110 | case GL_T4F_V4F:
|
---|
1111 | case GL_T2F_C3F_V3F:
|
---|
1112 | case GL_T2F_N3F_V3F:
|
---|
1113 | case GL_C3F_V3F:
|
---|
1114 | case GL_N3F_V3F:
|
---|
1115 | case GL_T2F_C4UB_V3F:
|
---|
1116 | case GL_T2F_V3F:
|
---|
1117 | case GL_C4UB_V3F:
|
---|
1118 | case GL_V3F:
|
---|
1119 | case GL_C4UB_V2F:
|
---|
1120 | case GL_V2F:
|
---|
1121 | break;
|
---|
1122 | default:
|
---|
1123 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
|
---|
1124 | return;
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
1128 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
1129 |
|
---|
1130 | /* p, size, type, stride, enabled, bytesPerIndex */
|
---|
1131 | /*
|
---|
1132 | ** VertexPointer
|
---|
1133 | */
|
---|
1134 |
|
---|
1135 | cp = &(c->array.v);
|
---|
1136 | cp->type = GL_FLOAT;
|
---|
1137 | cp->enabled = GL_TRUE;
|
---|
1138 |
|
---|
1139 | #ifdef CR_EXT_compiled_vertex_array
|
---|
1140 | crStateUnlockClientPointer(cp, 1 /*fFreePointer*/);
|
---|
1141 | #endif
|
---|
1142 |
|
---|
1143 | switch (format)
|
---|
1144 | {
|
---|
1145 | case GL_T4F_C4F_N3F_V4F:
|
---|
1146 | cp->p = base+4*sizeof(GLfloat)+4*sizeof(GLfloat)+3*sizeof(GLfloat);
|
---|
1147 | cp->size = 4;
|
---|
1148 | break;
|
---|
1149 | case GL_T2F_C4F_N3F_V3F:
|
---|
1150 | cp->p = base+2*sizeof(GLfloat)+4*sizeof(GLfloat)+3*sizeof(GLfloat);
|
---|
1151 | cp->size = 3;
|
---|
1152 | break;
|
---|
1153 | case GL_C4F_N3F_V3F:
|
---|
1154 | cp->p = base+4*sizeof(GLfloat)+3*sizeof(GLfloat);
|
---|
1155 | cp->size = 3;
|
---|
1156 | break;
|
---|
1157 | case GL_T4F_V4F:
|
---|
1158 | cp->p = base+4*sizeof(GLfloat);
|
---|
1159 | cp->size = 4;
|
---|
1160 | break;
|
---|
1161 | case GL_T2F_C3F_V3F:
|
---|
1162 | cp->p = base+2*sizeof(GLfloat)+3*sizeof(GLfloat);
|
---|
1163 | cp->size = 3;
|
---|
1164 | break;
|
---|
1165 | case GL_T2F_N3F_V3F:
|
---|
1166 | cp->p = base+2*sizeof(GLfloat)+3*sizeof(GLfloat);
|
---|
1167 | cp->size = 3;
|
---|
1168 | break;
|
---|
1169 | case GL_C3F_V3F:
|
---|
1170 | cp->p = base+3*sizeof(GLfloat);
|
---|
1171 | cp->size = 3;
|
---|
1172 | break;
|
---|
1173 | case GL_N3F_V3F:
|
---|
1174 | cp->p = base+3*sizeof(GLfloat);
|
---|
1175 | cp->size = 3;
|
---|
1176 | break;
|
---|
1177 | case GL_T2F_C4UB_V3F:
|
---|
1178 | cp->p = base+2*sizeof(GLfloat)+4*sizeof(GLubyte);
|
---|
1179 | cp->size = 3;
|
---|
1180 | break;
|
---|
1181 | case GL_T2F_V3F:
|
---|
1182 | cp->p = base+2*sizeof(GLfloat);
|
---|
1183 | cp->size = 3;
|
---|
1184 | break;
|
---|
1185 | case GL_C4UB_V3F:
|
---|
1186 | cp->p = base+4*sizeof(GLubyte);
|
---|
1187 | cp->size = 3;
|
---|
1188 | break;
|
---|
1189 | case GL_V3F:
|
---|
1190 | cp->p = base;
|
---|
1191 | cp->size = 3;
|
---|
1192 | break;
|
---|
1193 | case GL_C4UB_V2F:
|
---|
1194 | cp->p = base+4*sizeof(GLubyte);
|
---|
1195 | cp->size = 2;
|
---|
1196 | break;
|
---|
1197 | case GL_V2F:
|
---|
1198 | cp->p = base;
|
---|
1199 | cp->size = 2;
|
---|
1200 | break;
|
---|
1201 | default:
|
---|
1202 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
|
---|
1203 | return;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | cp->bytesPerIndex = cp->size * sizeof (GLfloat);
|
---|
1207 |
|
---|
1208 | if (stride==0)
|
---|
1209 | stride = cp->bytesPerIndex + (cp->p - base);
|
---|
1210 | cp->stride = stride;
|
---|
1211 |
|
---|
1212 | /*
|
---|
1213 | ** NormalPointer
|
---|
1214 | */
|
---|
1215 |
|
---|
1216 | cp = &(c->array.n);
|
---|
1217 | cp->enabled = GL_TRUE;
|
---|
1218 | cp->stride = stride;
|
---|
1219 | #ifdef CR_EXT_compiled_vertex_array
|
---|
1220 | crStateUnlockClientPointer(cp, 1 /*fFreePointer*/);
|
---|
1221 | #endif
|
---|
1222 |
|
---|
1223 | switch (format)
|
---|
1224 | {
|
---|
1225 | case GL_T4F_C4F_N3F_V4F:
|
---|
1226 | cp->p = base+4*sizeof(GLfloat)+4*sizeof(GLfloat);
|
---|
1227 | break;
|
---|
1228 | case GL_T2F_C4F_N3F_V3F:
|
---|
1229 | cp->p = base+2*sizeof(GLfloat)+4*sizeof(GLfloat);
|
---|
1230 | break;
|
---|
1231 | case GL_C4F_N3F_V3F:
|
---|
1232 | cp->p = base+4*sizeof(GLfloat);
|
---|
1233 | break;
|
---|
1234 | case GL_T2F_N3F_V3F:
|
---|
1235 | cp->p = base+2*sizeof(GLfloat);
|
---|
1236 | break;
|
---|
1237 | case GL_N3F_V3F:
|
---|
1238 | cp->p = base;
|
---|
1239 | break;
|
---|
1240 | case GL_T4F_V4F:
|
---|
1241 | case GL_T2F_C3F_V3F:
|
---|
1242 | case GL_C3F_V3F:
|
---|
1243 | case GL_T2F_C4UB_V3F:
|
---|
1244 | case GL_T2F_V3F:
|
---|
1245 | case GL_C4UB_V3F:
|
---|
1246 | case GL_V3F:
|
---|
1247 | case GL_C4UB_V2F:
|
---|
1248 | case GL_V2F:
|
---|
1249 | cp->enabled = GL_FALSE;
|
---|
1250 | break;
|
---|
1251 | default:
|
---|
1252 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
|
---|
1253 | return;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | if (cp->enabled)
|
---|
1257 | {
|
---|
1258 | cp->type = GL_FLOAT;
|
---|
1259 | cp->size = 3;
|
---|
1260 | cp->bytesPerIndex = cp->size * sizeof (GLfloat);
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | /*
|
---|
1264 | ** ColorPointer
|
---|
1265 | */
|
---|
1266 |
|
---|
1267 | cp = &(c->array.c);
|
---|
1268 | cp->enabled = GL_TRUE;
|
---|
1269 | cp->stride = stride;
|
---|
1270 | #ifdef CR_EXT_compiled_vertex_array
|
---|
1271 | crStateUnlockClientPointer(cp, 1 /*fFreePointer*/);
|
---|
1272 | #endif
|
---|
1273 |
|
---|
1274 | switch (format)
|
---|
1275 | {
|
---|
1276 | case GL_T4F_C4F_N3F_V4F:
|
---|
1277 | cp->size = 4;
|
---|
1278 | cp->type = GL_FLOAT;
|
---|
1279 | cp->bytesPerIndex = cp->size * sizeof(GLfloat);
|
---|
1280 | cp->p = base+4*sizeof(GLfloat);
|
---|
1281 | break;
|
---|
1282 | case GL_T2F_C4F_N3F_V3F:
|
---|
1283 | cp->size = 4;
|
---|
1284 | cp->type = GL_FLOAT;
|
---|
1285 | cp->bytesPerIndex = cp->size * sizeof(GLfloat);
|
---|
1286 | cp->p = base+2*sizeof(GLfloat);
|
---|
1287 | break;
|
---|
1288 | case GL_C4F_N3F_V3F:
|
---|
1289 | cp->size = 4;
|
---|
1290 | cp->type = GL_FLOAT;
|
---|
1291 | cp->bytesPerIndex = cp->size * sizeof(GLfloat);
|
---|
1292 | cp->p = base;
|
---|
1293 | break;
|
---|
1294 | case GL_T2F_C3F_V3F:
|
---|
1295 | cp->size = 3;
|
---|
1296 | cp->type = GL_FLOAT;
|
---|
1297 | cp->bytesPerIndex = cp->size * sizeof(GLfloat);
|
---|
1298 | cp->p = base+2*sizeof(GLfloat);
|
---|
1299 | break;
|
---|
1300 | case GL_C3F_V3F:
|
---|
1301 | cp->size = 3;
|
---|
1302 | cp->type = GL_FLOAT;
|
---|
1303 | cp->bytesPerIndex = cp->size * sizeof(GLfloat);
|
---|
1304 | cp->p = base;
|
---|
1305 | break;
|
---|
1306 | case GL_T2F_C4UB_V3F:
|
---|
1307 | cp->size = 4;
|
---|
1308 | cp->type = GL_UNSIGNED_BYTE;
|
---|
1309 | cp->bytesPerIndex = cp->size * sizeof(GLubyte);
|
---|
1310 | cp->p = base+2*sizeof(GLfloat);
|
---|
1311 | break;
|
---|
1312 | case GL_C4UB_V3F:
|
---|
1313 | cp->size = 4;
|
---|
1314 | cp->type = GL_UNSIGNED_BYTE;
|
---|
1315 | cp->bytesPerIndex = cp->size * sizeof(GLubyte);
|
---|
1316 | cp->p = base;
|
---|
1317 | break;
|
---|
1318 | case GL_C4UB_V2F:
|
---|
1319 | cp->size = 4;
|
---|
1320 | cp->type = GL_UNSIGNED_BYTE;
|
---|
1321 | cp->bytesPerIndex = cp->size * sizeof(GLubyte);
|
---|
1322 | cp->p = base;
|
---|
1323 | break;
|
---|
1324 | case GL_T2F_N3F_V3F:
|
---|
1325 | case GL_N3F_V3F:
|
---|
1326 | case GL_T4F_V4F:
|
---|
1327 | case GL_T2F_V3F:
|
---|
1328 | case GL_V3F:
|
---|
1329 | case GL_V2F:
|
---|
1330 | cp->enabled = GL_FALSE;
|
---|
1331 | break;
|
---|
1332 | default:
|
---|
1333 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
|
---|
1334 | return;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /*
|
---|
1338 | ** TexturePointer
|
---|
1339 | */
|
---|
1340 |
|
---|
1341 | cp = &(c->array.t[c->curClientTextureUnit]);
|
---|
1342 | cp->enabled = GL_TRUE;
|
---|
1343 | cp->stride = stride;
|
---|
1344 | #ifdef CR_EXT_compiled_vertex_array
|
---|
1345 | crStateUnlockClientPointer(cp, 1 /*fFreePointer*/);
|
---|
1346 | #endif
|
---|
1347 |
|
---|
1348 | switch (format)
|
---|
1349 | {
|
---|
1350 | case GL_T4F_C4F_N3F_V4F:
|
---|
1351 | cp->size = 4;
|
---|
1352 | cp->p = base;
|
---|
1353 | break;
|
---|
1354 | case GL_T2F_C4F_N3F_V3F:
|
---|
1355 | cp->size = 3;
|
---|
1356 | cp->p = base;
|
---|
1357 | break;
|
---|
1358 | case GL_T2F_C3F_V3F:
|
---|
1359 | case GL_T2F_N3F_V3F:
|
---|
1360 | cp->size = 3;
|
---|
1361 | cp->p = base;
|
---|
1362 | break;
|
---|
1363 | case GL_T2F_C4UB_V3F:
|
---|
1364 | cp->size = 3;
|
---|
1365 | cp->p = base;
|
---|
1366 | break;
|
---|
1367 | case GL_T4F_V4F:
|
---|
1368 | cp->size = 4;
|
---|
1369 | cp->p = base;
|
---|
1370 | break;
|
---|
1371 | case GL_T2F_V3F:
|
---|
1372 | cp->size = 3;
|
---|
1373 | cp->p = base;
|
---|
1374 | break;
|
---|
1375 | case GL_C4UB_V3F:
|
---|
1376 | case GL_C4UB_V2F:
|
---|
1377 | case GL_C3F_V3F:
|
---|
1378 | case GL_C4F_N3F_V3F:
|
---|
1379 | case GL_N3F_V3F:
|
---|
1380 | case GL_V3F:
|
---|
1381 | case GL_V2F:
|
---|
1382 | cp->enabled = GL_FALSE;
|
---|
1383 | break;
|
---|
1384 | default:
|
---|
1385 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glInterleavedArrays: Unrecognized format: %d", format);
|
---|
1386 | return;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | if (cp->enabled)
|
---|
1390 | {
|
---|
1391 | cp->type = GL_FLOAT;
|
---|
1392 | cp->bytesPerIndex = cp->size * sizeof (GLfloat);
|
---|
1393 | }
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | void STATE_APIENTRY crStateGetPointerv(PCRStateTracker pState, GLenum pname, GLvoid * * params)
|
---|
1397 | {
|
---|
1398 | CRContext *g = GetCurrentContext(pState);
|
---|
1399 | CRClientState *c = &(g->client);
|
---|
1400 |
|
---|
1401 | if (g->current.inBeginEnd)
|
---|
1402 | {
|
---|
1403 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1404 | "GetPointerv called in begin/end");
|
---|
1405 | return;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | switch (pname)
|
---|
1409 | {
|
---|
1410 | case GL_VERTEX_ARRAY_POINTER:
|
---|
1411 | *params = (GLvoid *) c->array.v.p;
|
---|
1412 | break;
|
---|
1413 | case GL_COLOR_ARRAY_POINTER:
|
---|
1414 | *params = (GLvoid *) c->array.c.p;
|
---|
1415 | break;
|
---|
1416 | case GL_NORMAL_ARRAY_POINTER:
|
---|
1417 | *params = (GLvoid *) c->array.n.p;
|
---|
1418 | break;
|
---|
1419 | case GL_INDEX_ARRAY_POINTER:
|
---|
1420 | *params = (GLvoid *) c->array.i.p;
|
---|
1421 | break;
|
---|
1422 | case GL_TEXTURE_COORD_ARRAY_POINTER:
|
---|
1423 | *params = (GLvoid *) c->array.t[c->curClientTextureUnit].p;
|
---|
1424 | break;
|
---|
1425 | case GL_EDGE_FLAG_ARRAY_POINTER:
|
---|
1426 | *params = (GLvoid *) c->array.e.p;
|
---|
1427 | break;
|
---|
1428 | #ifdef CR_EXT_fog_coord
|
---|
1429 | case GL_FOG_COORDINATE_ARRAY_POINTER_EXT:
|
---|
1430 | *params = (GLvoid *) c->array.f.p;
|
---|
1431 | break;
|
---|
1432 | #endif
|
---|
1433 | #ifdef CR_EXT_secondary_color
|
---|
1434 | case GL_SECONDARY_COLOR_ARRAY_POINTER_EXT:
|
---|
1435 | if( g->extensions.EXT_secondary_color ){
|
---|
1436 | *params = (GLvoid *) c->array.s.p;
|
---|
1437 | }
|
---|
1438 | else {
|
---|
1439 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "Invalid Enum passed to glGetPointerv: SECONDARY_COLOR_ARRAY_EXT - EXT_secondary_color is not enabled." );
|
---|
1440 | return;
|
---|
1441 | }
|
---|
1442 | break;
|
---|
1443 | #endif
|
---|
1444 | case GL_FEEDBACK_BUFFER_POINTER:
|
---|
1445 | case GL_SELECTION_BUFFER_POINTER:
|
---|
1446 | /* do nothing - API switching should pick this up */
|
---|
1447 | break;
|
---|
1448 | default:
|
---|
1449 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1450 | "glGetPointerv: invalid pname: %d", pname);
|
---|
1451 | return;
|
---|
1452 | }
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | void STATE_APIENTRY crStatePushClientAttrib(PCRStateTracker pState, GLbitfield mask )
|
---|
1457 | {
|
---|
1458 | CRContext *g = GetCurrentContext(pState);
|
---|
1459 | CRClientState *c = &(g->client);
|
---|
1460 |
|
---|
1461 | if (g->current.inBeginEnd) {
|
---|
1462 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1463 | "glPushClientAttrib called in Begin/End");
|
---|
1464 | return;
|
---|
1465 | }
|
---|
1466 |
|
---|
1467 | if (c->attribStackDepth == CR_MAX_CLIENT_ATTRIB_STACK_DEPTH - 1) {
|
---|
1468 | crStateError(pState, __LINE__, __FILE__, GL_STACK_OVERFLOW,
|
---|
1469 | "glPushClientAttrib called with a full stack!" );
|
---|
1470 | return;
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | FLUSH();
|
---|
1474 |
|
---|
1475 | c->pushMaskStack[c->attribStackDepth++] = mask;
|
---|
1476 |
|
---|
1477 | if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
|
---|
1478 | c->pixelPackStoreStack[c->pixelStoreStackDepth] = c->pack;
|
---|
1479 | c->pixelUnpackStoreStack[c->pixelStoreStackDepth] = c->unpack;
|
---|
1480 | c->pixelStoreStackDepth++;
|
---|
1481 | }
|
---|
1482 | if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
|
---|
1483 | c->vertexArrayStack[c->vertexArrayStackDepth] = c->array;
|
---|
1484 | c->vertexArrayStackDepth++;
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | /* dirty? - no, because we haven't really changed any state */
|
---|
1488 | }
|
---|
1489 |
|
---|
1490 |
|
---|
1491 | void STATE_APIENTRY crStatePopClientAttrib(PCRStateTracker pState)
|
---|
1492 | {
|
---|
1493 | CRContext *g = GetCurrentContext(pState);
|
---|
1494 | CRClientState *c = &(g->client);
|
---|
1495 | CRStateBits *sb = GetCurrentBits(pState);
|
---|
1496 | CRClientBits *cb = &(sb->client);
|
---|
1497 | CRbitvalue mask;
|
---|
1498 |
|
---|
1499 | if (g->current.inBeginEnd) {
|
---|
1500 | crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
1501 | "glPopClientAttrib called in Begin/End");
|
---|
1502 | return;
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | if (c->attribStackDepth == 0) {
|
---|
1506 | crStateError(pState, __LINE__, __FILE__, GL_STACK_UNDERFLOW,
|
---|
1507 | "glPopClientAttrib called with an empty stack!" );
|
---|
1508 | return;
|
---|
1509 | }
|
---|
1510 |
|
---|
1511 | FLUSH();
|
---|
1512 |
|
---|
1513 | mask = c->pushMaskStack[--c->attribStackDepth];
|
---|
1514 |
|
---|
1515 | if (mask & GL_CLIENT_PIXEL_STORE_BIT) {
|
---|
1516 | if (c->pixelStoreStackDepth == 0) {
|
---|
1517 | crError("bug in glPopClientAttrib (pixel store) ");
|
---|
1518 | return;
|
---|
1519 | }
|
---|
1520 | c->pixelStoreStackDepth--;
|
---|
1521 | c->pack = c->pixelPackStoreStack[c->pixelStoreStackDepth];
|
---|
1522 | c->unpack = c->pixelUnpackStoreStack[c->pixelStoreStackDepth];
|
---|
1523 | DIRTY(cb->pack, g->neg_bitid);
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
|
---|
1527 | if (c->vertexArrayStackDepth == 0) {
|
---|
1528 | crError("bug in glPopClientAttrib (vertex array) ");
|
---|
1529 | return;
|
---|
1530 | }
|
---|
1531 | c->vertexArrayStackDepth--;
|
---|
1532 | c->array = c->vertexArrayStack[c->vertexArrayStackDepth];
|
---|
1533 | DIRTY(cb->clientPointer, g->neg_bitid);
|
---|
1534 | }
|
---|
1535 |
|
---|
1536 | DIRTY(cb->dirty, g->neg_bitid);
|
---|
1537 | }
|
---|
1538 |
|
---|
1539 | static void crStateLockClientPointer(CRClientPointer* cp)
|
---|
1540 | {
|
---|
1541 | crStateUnlockClientPointer(cp, 1 /*fFreePointer*/);
|
---|
1542 | if (cp->enabled)
|
---|
1543 | {
|
---|
1544 | cp->locked = GL_TRUE;
|
---|
1545 | }
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | static GLboolean crStateCanLockClientPointer(CRClientPointer* cp)
|
---|
1549 | {
|
---|
1550 | return !(cp->enabled && cp->buffer && cp->buffer->id);
|
---|
1551 | }
|
---|
1552 |
|
---|
1553 | void STATE_APIENTRY crStateLockArraysEXT(PCRStateTracker pState, GLint first, GLint count)
|
---|
1554 | {
|
---|
1555 | CRContext *g = GetCurrentContext(pState);
|
---|
1556 | CRClientState *c = &(g->client);
|
---|
1557 | int i;
|
---|
1558 |
|
---|
1559 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
1560 | {
|
---|
1561 | if (!crStateCanLockClientPointer(crStateGetClientPointerByIndex(i, &c->array)))
|
---|
1562 | {
|
---|
1563 | break;
|
---|
1564 | }
|
---|
1565 | }
|
---|
1566 | if (i<CRSTATECLIENT_MAX_VERTEXARRAYS)
|
---|
1567 | {
|
---|
1568 | crDebug("crStateLockArraysEXT ignored because array %i have a bound VBO", i);
|
---|
1569 | return;
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | c->array.locked = GL_TRUE;
|
---|
1573 | c->array.lockFirst = first;
|
---|
1574 | c->array.lockCount = count;
|
---|
1575 | #ifdef IN_GUEST
|
---|
1576 | c->array.synced = GL_FALSE;
|
---|
1577 | #endif
|
---|
1578 |
|
---|
1579 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
1580 | {
|
---|
1581 | crStateLockClientPointer(crStateGetClientPointerByIndex(i, &c->array));
|
---|
1582 | }
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | void STATE_APIENTRY crStateUnlockArraysEXT(PCRStateTracker pState)
|
---|
1586 | {
|
---|
1587 | CRContext *g = GetCurrentContext(pState);
|
---|
1588 | CRClientState *c = &(g->client);
|
---|
1589 | int i;
|
---|
1590 |
|
---|
1591 | if (!c->array.locked)
|
---|
1592 | {
|
---|
1593 | crDebug("crStateUnlockArraysEXT ignored because arrays aren't locked");
|
---|
1594 | return;
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | c->array.locked = GL_FALSE;
|
---|
1598 | #ifdef IN_GUEST
|
---|
1599 | c->array.synced = GL_FALSE;
|
---|
1600 | #endif
|
---|
1601 |
|
---|
1602 | for (i=0; i<CRSTATECLIENT_MAX_VERTEXARRAYS; ++i)
|
---|
1603 | {
|
---|
1604 | crStateUnlockClientPointer(crStateGetClientPointerByIndex(i, &c->array), 1 /*fFreePointer*/);
|
---|
1605 | }
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | void STATE_APIENTRY crStateVertexArrayRangeNV(PCRStateTracker pState, GLsizei length, const GLvoid *pointer CRVBOX_HOST_ONLY_PARAM(int fRealPtr))
|
---|
1609 | {
|
---|
1610 | /* XXX todo */
|
---|
1611 | crWarning("crStateVertexArrayRangeNV not implemented");
|
---|
1612 | RT_NOREF(pState); (void)length; (void)pointer CRVBOX_HOST_ONLY_PARAM((void)fRealPtr);
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 |
|
---|
1616 | void STATE_APIENTRY crStateFlushVertexArrayRangeNV(PCRStateTracker pState)
|
---|
1617 | {
|
---|
1618 | /* XXX todo */
|
---|
1619 | crWarning("crStateFlushVertexArrayRangeNV not implemented");
|
---|
1620 | RT_NOREF(pState);
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 | /*Returns if the given clientpointer could be used on server side directly*/
|
---|
1624 | #define CRSTATE_IS_SERVER_CP(cp) (!(cp).enabled || !(cp).p || ((cp).buffer && (cp).buffer->id) || ((cp).locked))
|
---|
1625 |
|
---|
1626 | #if defined(DEBUG) && 0
|
---|
1627 | static void crStateDumpClientPointer(CRClientPointer *cp, const char *name, int i)
|
---|
1628 | {
|
---|
1629 | if (i<0 && cp->enabled)
|
---|
1630 | {
|
---|
1631 | crDebug("CP(%s): enabled:%d ptr:%p buffer:%p buffer.name:%i locked: %i %s",
|
---|
1632 | name, cp->enabled, cp->p, cp->buffer, cp->buffer ? cp->buffer->id : ~(GLuint)0, (int)cp->locked,
|
---|
1633 | CRSTATE_IS_SERVER_CP(*cp) ? "":"!FAIL!");
|
---|
1634 | }
|
---|
1635 | else if (0==i || cp->enabled)
|
---|
1636 | {
|
---|
1637 | crDebug("CP(%s%i): enabled:%d ptr:%p buffer:%p buffer.name:%i locked: %i %s",
|
---|
1638 | name, i, cp->enabled, cp->p, cp->buffer, cp->buffer ? cp->buffer->id : ~(GLuint)0, (int)cp->locked,
|
---|
1639 | CRSTATE_IS_SERVER_CP(*cp) ? "":"!FAIL!");
|
---|
1640 | }
|
---|
1641 | }
|
---|
1642 | #endif
|
---|
1643 |
|
---|
1644 | #ifdef DEBUG_misha
|
---|
1645 | /* debugging */
|
---|
1646 | /*# define CR_NO_SERVER_ARRAYS*/
|
---|
1647 | #endif
|
---|
1648 |
|
---|
1649 | /*
|
---|
1650 | * Determine if the enabled arrays all live on the server
|
---|
1651 | * (via GL_ARB_vertex_buffer_object).
|
---|
1652 | */
|
---|
1653 | GLboolean crStateUseServerArrays(PCRStateTracker pState)
|
---|
1654 | {
|
---|
1655 | #if defined(CR_ARB_vertex_buffer_object) && !defined(CR_NO_SERVER_ARRAYS)
|
---|
1656 | CRContext *g = GetCurrentContext(pState);
|
---|
1657 | CRClientState *c = &(g->client);
|
---|
1658 | int i;
|
---|
1659 | GLboolean res;
|
---|
1660 |
|
---|
1661 | res = CRSTATE_IS_SERVER_CP(c->array.v)
|
---|
1662 | && CRSTATE_IS_SERVER_CP(c->array.n)
|
---|
1663 | && CRSTATE_IS_SERVER_CP(c->array.c)
|
---|
1664 | && CRSTATE_IS_SERVER_CP(c->array.i)
|
---|
1665 | && CRSTATE_IS_SERVER_CP(c->array.e)
|
---|
1666 | && CRSTATE_IS_SERVER_CP(c->array.s)
|
---|
1667 | && CRSTATE_IS_SERVER_CP(c->array.f);
|
---|
1668 |
|
---|
1669 | if (res)
|
---|
1670 | {
|
---|
1671 | for (i = 0; (unsigned int)i < g->limits.maxTextureUnits; i++)
|
---|
1672 | if (!CRSTATE_IS_SERVER_CP(c->array.t[i]))
|
---|
1673 | {
|
---|
1674 | res = GL_FALSE;
|
---|
1675 | break;
|
---|
1676 | }
|
---|
1677 | }
|
---|
1678 |
|
---|
1679 | if (res)
|
---|
1680 | {
|
---|
1681 | for (i = 0; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1682 | if (!CRSTATE_IS_SERVER_CP(c->array.a[i]))
|
---|
1683 | {
|
---|
1684 | res = GL_FALSE;
|
---|
1685 | break;
|
---|
1686 | }
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 | #if defined(DEBUG) && 0
|
---|
1690 | if (!res)
|
---|
1691 | {
|
---|
1692 | crStateDumpClientPointer(&c->array.v, "v", -1);
|
---|
1693 | crStateDumpClientPointer(&c->array.n, "n", -1);
|
---|
1694 | crStateDumpClientPointer(&c->array.c, "c", -1);
|
---|
1695 | crStateDumpClientPointer(&c->array.i, "i", -1);
|
---|
1696 | crStateDumpClientPointer(&c->array.e, "e", -1);
|
---|
1697 | crStateDumpClientPointer(&c->array.s, "s", -1);
|
---|
1698 | crStateDumpClientPointer(&c->array.f, "f", -1);
|
---|
1699 | for (i = 0; (unsigned int)i < g->limits.maxTextureUnits; i++)
|
---|
1700 | crStateDumpClientPointer(&c->array.t[i], "tex", i);
|
---|
1701 | for (i = 0; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1702 | crStateDumpClientPointer(&c->array.a[i], "attrib", i);
|
---|
1703 | crDebug("crStateUseServerArrays->%d", res);
|
---|
1704 | }
|
---|
1705 | #endif
|
---|
1706 |
|
---|
1707 | return res;
|
---|
1708 | #else
|
---|
1709 | return GL_FALSE;
|
---|
1710 | #endif
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | GLuint crStateNeedDummyZeroVertexArray(CRContext *g, CRCurrentStatePointers *current, GLfloat *pZva)
|
---|
1714 | {
|
---|
1715 | #if defined(CR_ARB_vertex_buffer_object)
|
---|
1716 | CRClientState *c = &(g->client);
|
---|
1717 | int i;
|
---|
1718 | GLuint zvMax = 0;
|
---|
1719 |
|
---|
1720 | if (c->array.a[0].enabled)
|
---|
1721 | return 0;
|
---|
1722 |
|
---|
1723 | for (i = 1; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1724 | {
|
---|
1725 | if (c->array.a[i].enabled)
|
---|
1726 | {
|
---|
1727 | if (c->array.a[i].buffer && c->array.a[i].buffer->id)
|
---|
1728 | {
|
---|
1729 | GLuint cElements = c->array.a[i].buffer->size / c->array.a[i].stride;
|
---|
1730 | if (zvMax < cElements)
|
---|
1731 | zvMax = cElements;
|
---|
1732 | }
|
---|
1733 | else
|
---|
1734 | {
|
---|
1735 | zvMax = ~UINT32_C(0);
|
---|
1736 | break;
|
---|
1737 | }
|
---|
1738 | }
|
---|
1739 | }
|
---|
1740 |
|
---|
1741 | if (zvMax)
|
---|
1742 | {
|
---|
1743 | Assert(!c->array.v.enabled);
|
---|
1744 |
|
---|
1745 | crStateCurrentRecoverNew(g, current);
|
---|
1746 |
|
---|
1747 | crMemcpy(pZva, &g->current.vertexAttrib[0][0], sizeof (*pZva) * 4);
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | return zvMax;
|
---|
1751 | #else
|
---|
1752 | return GL_FALSE;
|
---|
1753 | #endif
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 |
|
---|
1757 | /**
|
---|
1758 | * Determine if there's a server-side array element buffer.
|
---|
1759 | * Called by glDrawElements() in packing SPUs to determine if glDrawElements
|
---|
1760 | * should be evaluated (unrolled) locally or if glDrawElements should be
|
---|
1761 | * packed and sent to the server.
|
---|
1762 | */
|
---|
1763 | GLboolean
|
---|
1764 | crStateUseServerArrayElements(PCRStateTracker pState)
|
---|
1765 | {
|
---|
1766 | #ifdef CR_ARB_vertex_buffer_object
|
---|
1767 | CRContext *g = GetCurrentContext(pState);
|
---|
1768 | if (g->bufferobject.elementsBuffer &&
|
---|
1769 | g->bufferobject.elementsBuffer->id > 0)
|
---|
1770 | return GL_TRUE;
|
---|
1771 | else
|
---|
1772 | return GL_FALSE;
|
---|
1773 | #else
|
---|
1774 | return GL_FALSE;
|
---|
1775 | #endif
|
---|
1776 | }
|
---|
1777 |
|
---|
1778 | #define CR_BUFFER_HWID(_p) ((_p) ? (_p)->hwid : 0)
|
---|
1779 |
|
---|
1780 | void
|
---|
1781 | crStateClientDiff(CRClientBits *cb, CRbitvalue *bitID,
|
---|
1782 | CRContext *fromCtx, CRContext *toCtx)
|
---|
1783 | {
|
---|
1784 | PCRStateTracker pState = fromCtx->pStateTracker;
|
---|
1785 | CRClientState *from = &(fromCtx->client);
|
---|
1786 | const CRClientState *to = &(toCtx->client);
|
---|
1787 | GLint curClientTextureUnit = from->curClientTextureUnit;
|
---|
1788 | int i;
|
---|
1789 | GLint idHwArrayBuffer = CR_BUFFER_HWID(toCtx->bufferobject.arrayBuffer);
|
---|
1790 | const GLint idHwInitialBuffer = idHwArrayBuffer;
|
---|
1791 |
|
---|
1792 | CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
|
---|
1793 |
|
---|
1794 | #ifdef DEBUG_misha
|
---|
1795 | {
|
---|
1796 | GLint tstHwBuffer = -1;
|
---|
1797 | pState->diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
|
---|
1798 | CRASSERT(idHwInitialBuffer == tstHwBuffer);
|
---|
1799 | }
|
---|
1800 | #endif
|
---|
1801 |
|
---|
1802 |
|
---|
1803 | if (CHECKDIRTY(cb->clientPointer, bitID)) {
|
---|
1804 | /* one or more vertex pointers is dirty */
|
---|
1805 | if (CHECKDIRTY(cb->v, bitID)) {
|
---|
1806 | if (from->array.v.size != to->array.v.size ||
|
---|
1807 | from->array.v.type != to->array.v.type ||
|
---|
1808 | from->array.v.stride != to->array.v.stride ||
|
---|
1809 | from->array.v.p != to->array.v.p ||
|
---|
1810 | from->array.v.buffer != to->array.v.buffer) {
|
---|
1811 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.v.buffer);
|
---|
1812 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1813 | {
|
---|
1814 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1815 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1816 | }
|
---|
1817 | pState->diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
|
---|
1818 | from->array.v.size = to->array.v.size;
|
---|
1819 | from->array.v.type = to->array.v.type;
|
---|
1820 | from->array.v.stride = to->array.v.stride;
|
---|
1821 | from->array.v.p = to->array.v.p;
|
---|
1822 | from->array.v.buffer = to->array.v.buffer;
|
---|
1823 | }
|
---|
1824 | CLEARDIRTY2(cb->v, bitID);
|
---|
1825 | }
|
---|
1826 | /* normal */
|
---|
1827 | if (CHECKDIRTY(cb->n, bitID)) {
|
---|
1828 | if (from->array.n.type != to->array.n.type ||
|
---|
1829 | from->array.n.stride != to->array.n.stride ||
|
---|
1830 | from->array.n.p != to->array.n.p ||
|
---|
1831 | from->array.n.buffer != to->array.n.buffer) {
|
---|
1832 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.n.buffer);
|
---|
1833 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1834 | {
|
---|
1835 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1836 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1837 | }
|
---|
1838 | pState->diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
|
---|
1839 | from->array.n.type = to->array.n.type;
|
---|
1840 | from->array.n.stride = to->array.n.stride;
|
---|
1841 | from->array.n.p = to->array.n.p;
|
---|
1842 | from->array.n.buffer = to->array.n.buffer;
|
---|
1843 | }
|
---|
1844 | CLEARDIRTY2(cb->n, bitID);
|
---|
1845 | }
|
---|
1846 | /* color */
|
---|
1847 | if (CHECKDIRTY(cb->c, bitID)) {
|
---|
1848 | if (from->array.c.size != to->array.c.size ||
|
---|
1849 | from->array.c.type != to->array.c.type ||
|
---|
1850 | from->array.c.stride != to->array.c.stride ||
|
---|
1851 | from->array.c.p != to->array.c.p ||
|
---|
1852 | from->array.c.buffer != to->array.c.buffer) {
|
---|
1853 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.c.buffer);
|
---|
1854 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1855 | {
|
---|
1856 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1857 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1858 | }
|
---|
1859 | pState->diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
|
---|
1860 | from->array.c.size = to->array.c.size;
|
---|
1861 | from->array.c.type = to->array.c.type;
|
---|
1862 | from->array.c.stride = to->array.c.stride;
|
---|
1863 | from->array.c.p = to->array.c.p;
|
---|
1864 | from->array.c.buffer = to->array.c.buffer;
|
---|
1865 | }
|
---|
1866 | CLEARDIRTY2(cb->c, bitID);
|
---|
1867 | }
|
---|
1868 | /* index */
|
---|
1869 | if (CHECKDIRTY(cb->i, bitID)) {
|
---|
1870 | if (from->array.i.type != to->array.i.type ||
|
---|
1871 | from->array.i.stride != to->array.i.stride ||
|
---|
1872 | from->array.i.p != to->array.i.p ||
|
---|
1873 | from->array.i.buffer != to->array.i.buffer) {
|
---|
1874 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.i.buffer);
|
---|
1875 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1876 | {
|
---|
1877 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1878 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1879 | }
|
---|
1880 | pState->diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
|
---|
1881 | from->array.i.type = to->array.i.type;
|
---|
1882 | from->array.i.stride = to->array.i.stride;
|
---|
1883 | from->array.i.p = to->array.i.p;
|
---|
1884 | from->array.i.buffer = to->array.i.buffer;
|
---|
1885 | }
|
---|
1886 | CLEARDIRTY2(cb->i, bitID);
|
---|
1887 | }
|
---|
1888 | /* texcoords */
|
---|
1889 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
1890 | if (CHECKDIRTY(cb->t[i], bitID)) {
|
---|
1891 | if (from->array.t[i].size != to->array.t[i].size ||
|
---|
1892 | from->array.t[i].type != to->array.t[i].type ||
|
---|
1893 | from->array.t[i].stride != to->array.t[i].stride ||
|
---|
1894 | from->array.t[i].p != to->array.t[i].p ||
|
---|
1895 | from->array.t[i].buffer != to->array.t[i].buffer) {
|
---|
1896 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.t[i].buffer);
|
---|
1897 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1898 | {
|
---|
1899 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1900 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1901 | }
|
---|
1902 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
1903 | curClientTextureUnit = i;
|
---|
1904 | pState->diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
|
---|
1905 | from->array.t[i].size = to->array.t[i].size;
|
---|
1906 | from->array.t[i].type = to->array.t[i].type;
|
---|
1907 | from->array.t[i].stride = to->array.t[i].stride;
|
---|
1908 | from->array.t[i].p = to->array.t[i].p;
|
---|
1909 | from->array.t[i].buffer = to->array.t[i].buffer;
|
---|
1910 | }
|
---|
1911 | CLEARDIRTY2(cb->t[i], bitID);
|
---|
1912 | }
|
---|
1913 | }
|
---|
1914 | /* edge flag */
|
---|
1915 | if (CHECKDIRTY(cb->e, bitID)) {
|
---|
1916 | if (from->array.e.stride != to->array.e.stride ||
|
---|
1917 | from->array.e.p != to->array.e.p ||
|
---|
1918 | from->array.e.buffer != to->array.e.buffer) {
|
---|
1919 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.e.buffer);
|
---|
1920 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1921 | {
|
---|
1922 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1923 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1924 | }
|
---|
1925 | pState->diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
|
---|
1926 | from->array.e.stride = to->array.e.stride;
|
---|
1927 | from->array.e.p = to->array.e.p;
|
---|
1928 | from->array.e.buffer = to->array.e.buffer;
|
---|
1929 | }
|
---|
1930 | CLEARDIRTY2(cb->e, bitID);
|
---|
1931 | }
|
---|
1932 | /* secondary color */
|
---|
1933 | if (CHECKDIRTY(cb->s, bitID)) {
|
---|
1934 | if (from->array.s.size != to->array.s.size ||
|
---|
1935 | from->array.s.type != to->array.s.type ||
|
---|
1936 | from->array.s.stride != to->array.s.stride ||
|
---|
1937 | from->array.s.p != to->array.s.p ||
|
---|
1938 | from->array.s.buffer != to->array.s.buffer) {
|
---|
1939 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.s.buffer);
|
---|
1940 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1941 | {
|
---|
1942 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1943 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1944 | }
|
---|
1945 | pState->diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
|
---|
1946 | from->array.s.size = to->array.s.size;
|
---|
1947 | from->array.s.type = to->array.s.type;
|
---|
1948 | from->array.s.stride = to->array.s.stride;
|
---|
1949 | from->array.s.p = to->array.s.p;
|
---|
1950 | from->array.s.buffer = to->array.s.buffer;
|
---|
1951 | }
|
---|
1952 | CLEARDIRTY2(cb->s, bitID);
|
---|
1953 | }
|
---|
1954 | /* fog coord */
|
---|
1955 | if (CHECKDIRTY(cb->f, bitID)) {
|
---|
1956 | if (from->array.f.type != to->array.f.type ||
|
---|
1957 | from->array.f.stride != to->array.f.stride ||
|
---|
1958 | from->array.f.p != to->array.f.p ||
|
---|
1959 | from->array.f.buffer != to->array.f.buffer) {
|
---|
1960 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.f.buffer);
|
---|
1961 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1962 | {
|
---|
1963 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1964 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1965 | }
|
---|
1966 | pState->diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
|
---|
1967 | from->array.f.type = to->array.f.type;
|
---|
1968 | from->array.f.stride = to->array.f.stride;
|
---|
1969 | from->array.f.p = to->array.f.p;
|
---|
1970 | from->array.f.buffer = to->array.f.buffer;
|
---|
1971 | }
|
---|
1972 | CLEARDIRTY2(cb->f, bitID);
|
---|
1973 | }
|
---|
1974 | #if defined(CR_NV_vertex_program) || defined(CR_ARB_vertex_program)
|
---|
1975 | /* vertex attributes */
|
---|
1976 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
1977 | if (CHECKDIRTY(cb->a[i], bitID)) {
|
---|
1978 | if (from->array.a[i].size != to->array.a[i].size ||
|
---|
1979 | from->array.a[i].type != to->array.a[i].type ||
|
---|
1980 | from->array.a[i].stride != to->array.a[i].stride ||
|
---|
1981 | from->array.a[i].normalized != to->array.a[i].normalized ||
|
---|
1982 | from->array.a[i].p != to->array.a[i].p ||
|
---|
1983 | from->array.a[i].buffer != to->array.a[i].buffer) {
|
---|
1984 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.a[i].buffer);
|
---|
1985 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1986 | {
|
---|
1987 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1988 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1989 | }
|
---|
1990 | pState->diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
|
---|
1991 | to->array.a[i].stride, to->array.a[i].p CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
|
---|
1992 | from->array.a[i].size = to->array.a[i].size;
|
---|
1993 | from->array.a[i].type = to->array.a[i].type;
|
---|
1994 | from->array.a[i].stride = to->array.a[i].stride;
|
---|
1995 | from->array.a[i].normalized = to->array.a[i].normalized;
|
---|
1996 | from->array.a[i].p = to->array.a[i].p;
|
---|
1997 | from->array.a[i].buffer = to->array.a[i].buffer;
|
---|
1998 | }
|
---|
1999 | CLEARDIRTY2(cb->a[i], bitID);
|
---|
2000 | }
|
---|
2001 | }
|
---|
2002 | #endif
|
---|
2003 | }
|
---|
2004 |
|
---|
2005 | if (idHwArrayBuffer != idHwInitialBuffer)
|
---|
2006 | {
|
---|
2007 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
|
---|
2008 | }
|
---|
2009 |
|
---|
2010 | if (CHECKDIRTY(cb->enableClientState, bitID)) {
|
---|
2011 | /* update vertex array enable/disable flags */
|
---|
2012 | glAble able[2];
|
---|
2013 | able[0] = pState->diff_api.DisableClientState;
|
---|
2014 | able[1] = pState->diff_api.EnableClientState;
|
---|
2015 | if (from->array.v.enabled != to->array.v.enabled) {
|
---|
2016 | able[to->array.v.enabled](GL_VERTEX_ARRAY);
|
---|
2017 | from->array.v.enabled = to->array.v.enabled;
|
---|
2018 | }
|
---|
2019 | if (from->array.n.enabled != to->array.n.enabled) {
|
---|
2020 | able[to->array.n.enabled](GL_NORMAL_ARRAY);
|
---|
2021 | from->array.n.enabled = to->array.n.enabled;
|
---|
2022 | }
|
---|
2023 | if (from->array.c.enabled != to->array.c.enabled) {
|
---|
2024 | able[to->array.c.enabled](GL_COLOR_ARRAY);
|
---|
2025 | from->array.c.enabled = to->array.c.enabled;
|
---|
2026 | }
|
---|
2027 | if (from->array.i.enabled != to->array.i.enabled) {
|
---|
2028 | able[to->array.i.enabled](GL_INDEX_ARRAY);
|
---|
2029 | from->array.i.enabled = to->array.i.enabled;
|
---|
2030 | }
|
---|
2031 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
2032 | if (from->array.t[i].enabled != to->array.t[i].enabled) {
|
---|
2033 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
2034 | curClientTextureUnit = i;
|
---|
2035 | able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
|
---|
2036 | from->array.t[i].enabled = to->array.t[i].enabled;
|
---|
2037 | }
|
---|
2038 | }
|
---|
2039 | if (from->array.e.enabled != to->array.e.enabled) {
|
---|
2040 | able[to->array.e.enabled](GL_EDGE_FLAG_ARRAY);
|
---|
2041 | from->array.e.enabled = to->array.e.enabled;
|
---|
2042 | }
|
---|
2043 | if (from->array.s.enabled != to->array.s.enabled) {
|
---|
2044 | able[to->array.s.enabled](GL_SECONDARY_COLOR_ARRAY_EXT);
|
---|
2045 | from->array.s.enabled = to->array.s.enabled;
|
---|
2046 | }
|
---|
2047 | if (from->array.f.enabled != to->array.f.enabled) {
|
---|
2048 | able[to->array.f.enabled](GL_FOG_COORDINATE_ARRAY_EXT);
|
---|
2049 | from->array.f.enabled = to->array.f.enabled;
|
---|
2050 | }
|
---|
2051 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
2052 | if (from->array.a[i].enabled != to->array.a[i].enabled) {
|
---|
2053 | if (to->array.a[i].enabled)
|
---|
2054 | pState->diff_api.EnableVertexAttribArrayARB(i);
|
---|
2055 | else
|
---|
2056 | pState->diff_api.DisableVertexAttribArrayARB(i);
|
---|
2057 | from->array.a[i].enabled = to->array.a[i].enabled;
|
---|
2058 | }
|
---|
2059 | }
|
---|
2060 | CLEARDIRTY2(cb->enableClientState, bitID);
|
---|
2061 | }
|
---|
2062 |
|
---|
2063 | if (to->curClientTextureUnit != curClientTextureUnit)
|
---|
2064 | {
|
---|
2065 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
|
---|
2066 | }
|
---|
2067 | }
|
---|
2068 |
|
---|
2069 |
|
---|
2070 | void
|
---|
2071 | crStateClientSwitch(CRClientBits *cb, CRbitvalue *bitID,
|
---|
2072 | CRContext *fromCtx, CRContext *toCtx)
|
---|
2073 | {
|
---|
2074 | PCRStateTracker pState = fromCtx->pStateTracker;
|
---|
2075 | const CRClientState *from = &(fromCtx->client);
|
---|
2076 | const CRClientState *to = &(toCtx->client);
|
---|
2077 | GLint curClientTextureUnit = from->curClientTextureUnit;
|
---|
2078 | int i;
|
---|
2079 | GLint idHwArrayBuffer = CR_BUFFER_HWID(toCtx->bufferobject.arrayBuffer);
|
---|
2080 | const GLint idHwInitialBuffer = idHwArrayBuffer;
|
---|
2081 |
|
---|
2082 | CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
|
---|
2083 |
|
---|
2084 | #ifdef DEBUG_misha
|
---|
2085 | {
|
---|
2086 | GLint tstHwBuffer = -1;
|
---|
2087 | pState->diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
|
---|
2088 | CRASSERT(idHwInitialBuffer == tstHwBuffer);
|
---|
2089 | }
|
---|
2090 | #endif
|
---|
2091 |
|
---|
2092 | if (CHECKDIRTY(cb->clientPointer, bitID)) {
|
---|
2093 | /* one or more vertex pointers is dirty */
|
---|
2094 | if (CHECKDIRTY(cb->v, bitID)) {
|
---|
2095 | if (from->array.v.size != to->array.v.size ||
|
---|
2096 | from->array.v.type != to->array.v.type ||
|
---|
2097 | from->array.v.stride != to->array.v.stride ||
|
---|
2098 | from->array.v.p != to->array.v.p ||
|
---|
2099 | from->array.v.buffer != to->array.v.buffer) {
|
---|
2100 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.v.buffer);
|
---|
2101 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2102 | {
|
---|
2103 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2104 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2105 | }
|
---|
2106 | pState->diff_api.VertexPointer(to->array.v.size, to->array.v.type, to->array.v.stride, to->array.v.p CRVBOX_HOST_ONLY_PARAM(to->array.v.fRealPtr));
|
---|
2107 | FILLDIRTY(cb->v);
|
---|
2108 | FILLDIRTY(cb->clientPointer);
|
---|
2109 | FILLDIRTY(cb->dirty);
|
---|
2110 | }
|
---|
2111 | CLEARDIRTY2(cb->v, bitID);
|
---|
2112 | }
|
---|
2113 | /* normal */
|
---|
2114 | if (CHECKDIRTY(cb->n, bitID)) {
|
---|
2115 | if (from->array.n.type != to->array.n.type ||
|
---|
2116 | from->array.n.stride != to->array.n.stride ||
|
---|
2117 | from->array.n.p != to->array.n.p ||
|
---|
2118 | from->array.n.buffer != to->array.n.buffer) {
|
---|
2119 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.n.buffer);
|
---|
2120 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2121 | {
|
---|
2122 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2123 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2124 | }
|
---|
2125 | pState->diff_api.NormalPointer(to->array.n.type, to->array.n.stride, to->array.n.p CRVBOX_HOST_ONLY_PARAM(to->array.n.fRealPtr));
|
---|
2126 | FILLDIRTY(cb->n);
|
---|
2127 | FILLDIRTY(cb->clientPointer);
|
---|
2128 | FILLDIRTY(cb->dirty);
|
---|
2129 | }
|
---|
2130 | CLEARDIRTY2(cb->n, bitID);
|
---|
2131 | }
|
---|
2132 | /* color */
|
---|
2133 | if (CHECKDIRTY(cb->c, bitID)) {
|
---|
2134 | if (from->array.c.size != to->array.c.size ||
|
---|
2135 | from->array.c.type != to->array.c.type ||
|
---|
2136 | from->array.c.stride != to->array.c.stride ||
|
---|
2137 | from->array.c.p != to->array.c.p ||
|
---|
2138 | from->array.c.buffer != to->array.c.buffer) {
|
---|
2139 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.c.buffer);
|
---|
2140 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2141 | {
|
---|
2142 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2143 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2144 | }
|
---|
2145 | pState->diff_api.ColorPointer(to->array.c.size, to->array.c.type, to->array.c.stride, to->array.c.p CRVBOX_HOST_ONLY_PARAM(to->array.c.fRealPtr));
|
---|
2146 | FILLDIRTY(cb->c);
|
---|
2147 | FILLDIRTY(cb->clientPointer);
|
---|
2148 | FILLDIRTY(cb->dirty);
|
---|
2149 | }
|
---|
2150 | CLEARDIRTY2(cb->c, bitID);
|
---|
2151 | }
|
---|
2152 | /* index */
|
---|
2153 | if (CHECKDIRTY(cb->i, bitID)) {
|
---|
2154 | if (from->array.i.type != to->array.i.type ||
|
---|
2155 | from->array.i.stride != to->array.i.stride ||
|
---|
2156 | from->array.i.p != to->array.i.p ||
|
---|
2157 | from->array.i.buffer != to->array.i.buffer) {
|
---|
2158 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.i.buffer);
|
---|
2159 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2160 | {
|
---|
2161 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2162 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2163 | }
|
---|
2164 | pState->diff_api.IndexPointer(to->array.i.type, to->array.i.stride, to->array.i.p CRVBOX_HOST_ONLY_PARAM(to->array.i.fRealPtr));
|
---|
2165 | FILLDIRTY(cb->i);
|
---|
2166 | FILLDIRTY(cb->dirty);
|
---|
2167 | FILLDIRTY(cb->clientPointer);
|
---|
2168 | }
|
---|
2169 | CLEARDIRTY2(cb->i, bitID);
|
---|
2170 | }
|
---|
2171 | /* texcoords */
|
---|
2172 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
2173 | if (CHECKDIRTY(cb->t[i], bitID)) {
|
---|
2174 | if (from->array.t[i].size != to->array.t[i].size ||
|
---|
2175 | from->array.t[i].type != to->array.t[i].type ||
|
---|
2176 | from->array.t[i].stride != to->array.t[i].stride ||
|
---|
2177 | from->array.t[i].p != to->array.t[i].p ||
|
---|
2178 | from->array.t[i].buffer != to->array.t[i].buffer) {
|
---|
2179 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.t[i].buffer);
|
---|
2180 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2181 | {
|
---|
2182 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2183 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2184 | }
|
---|
2185 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
2186 | curClientTextureUnit = i;
|
---|
2187 | pState->diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type, to->array.t[i].stride, to->array.t[i].p CRVBOX_HOST_ONLY_PARAM(to->array.t[i].fRealPtr));
|
---|
2188 | FILLDIRTY(cb->t[i]);
|
---|
2189 | FILLDIRTY(cb->clientPointer);
|
---|
2190 | FILLDIRTY(cb->dirty);
|
---|
2191 | }
|
---|
2192 | CLEARDIRTY2(cb->t[i], bitID);
|
---|
2193 | }
|
---|
2194 | }
|
---|
2195 | /* edge flag */
|
---|
2196 | if (CHECKDIRTY(cb->e, bitID)) {
|
---|
2197 | if (from->array.e.stride != to->array.e.stride ||
|
---|
2198 | from->array.e.p != to->array.e.p ||
|
---|
2199 | from->array.e.buffer != to->array.e.buffer) {
|
---|
2200 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.e.buffer);
|
---|
2201 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2202 | {
|
---|
2203 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2204 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2205 | }
|
---|
2206 | pState->diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p CRVBOX_HOST_ONLY_PARAM(to->array.e.fRealPtr));
|
---|
2207 | FILLDIRTY(cb->e);
|
---|
2208 | FILLDIRTY(cb->clientPointer);
|
---|
2209 | FILLDIRTY(cb->dirty);
|
---|
2210 | }
|
---|
2211 | CLEARDIRTY2(cb->e, bitID);
|
---|
2212 | }
|
---|
2213 | /* secondary color */
|
---|
2214 | if (CHECKDIRTY(cb->s, bitID)) {
|
---|
2215 | if (from->array.s.size != to->array.s.size ||
|
---|
2216 | from->array.s.type != to->array.s.type ||
|
---|
2217 | from->array.s.stride != to->array.s.stride ||
|
---|
2218 | from->array.s.p != to->array.s.p ||
|
---|
2219 | from->array.s.buffer != to->array.s.buffer) {
|
---|
2220 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.s.buffer);
|
---|
2221 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2222 | {
|
---|
2223 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2224 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2225 | }
|
---|
2226 | pState->diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type, to->array.s.stride, to->array.s.p CRVBOX_HOST_ONLY_PARAM(to->array.s.fRealPtr));
|
---|
2227 | FILLDIRTY(cb->s);
|
---|
2228 | FILLDIRTY(cb->clientPointer);
|
---|
2229 | FILLDIRTY(cb->dirty);
|
---|
2230 | }
|
---|
2231 | CLEARDIRTY2(cb->s, bitID);
|
---|
2232 | }
|
---|
2233 | /* fog coord */
|
---|
2234 | if (CHECKDIRTY(cb->f, bitID)) {
|
---|
2235 | if (from->array.f.type != to->array.f.type ||
|
---|
2236 | from->array.f.stride != to->array.f.stride ||
|
---|
2237 | from->array.f.p != to->array.f.p ||
|
---|
2238 | from->array.f.buffer != to->array.f.buffer) {
|
---|
2239 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.f.buffer);
|
---|
2240 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2241 | {
|
---|
2242 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2243 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2244 | }
|
---|
2245 | pState->diff_api.FogCoordPointerEXT(to->array.f.type, to->array.f.stride, to->array.f.p CRVBOX_HOST_ONLY_PARAM(to->array.f.fRealPtr));
|
---|
2246 | FILLDIRTY(cb->f);
|
---|
2247 | FILLDIRTY(cb->clientPointer);
|
---|
2248 | FILLDIRTY(cb->dirty);
|
---|
2249 | }
|
---|
2250 | CLEARDIRTY2(cb->f, bitID);
|
---|
2251 | }
|
---|
2252 | #if defined(CR_NV_vertex_program) || defined(CR_ARB_vertex_program)
|
---|
2253 | /* vertex attributes */
|
---|
2254 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
2255 | if (CHECKDIRTY(cb->a[i], bitID)) {
|
---|
2256 | if (from->array.a[i].size != to->array.a[i].size ||
|
---|
2257 | from->array.a[i].type != to->array.a[i].type ||
|
---|
2258 | from->array.a[i].stride != to->array.a[i].stride ||
|
---|
2259 | from->array.a[i].normalized != to->array.a[i].normalized ||
|
---|
2260 | from->array.a[i].p != to->array.a[i].p ||
|
---|
2261 | from->array.a[i].buffer != to->array.a[i].buffer) {
|
---|
2262 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.a[i].buffer);
|
---|
2263 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2264 | {
|
---|
2265 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2266 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2267 | }
|
---|
2268 | pState->diff_api.VertexAttribPointerARB(i, to->array.a[i].size, to->array.a[i].type, to->array.a[i].normalized,
|
---|
2269 | to->array.a[i].stride, to->array.a[i].p CRVBOX_HOST_ONLY_PARAM(to->array.a[i].fRealPtr));
|
---|
2270 | FILLDIRTY(cb->a[i]);
|
---|
2271 | FILLDIRTY(cb->clientPointer);
|
---|
2272 | FILLDIRTY(cb->dirty);
|
---|
2273 | }
|
---|
2274 | CLEARDIRTY2(cb->a[i], bitID);
|
---|
2275 | }
|
---|
2276 | }
|
---|
2277 | #endif
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | if (idHwArrayBuffer != idHwInitialBuffer)
|
---|
2281 | {
|
---|
2282 | pState->diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
|
---|
2283 | }
|
---|
2284 |
|
---|
2285 | if (CHECKDIRTY(cb->enableClientState, bitID)) {
|
---|
2286 | /* update vertex array enable/disable flags */
|
---|
2287 | glAble able[2];
|
---|
2288 | able[0] = pState->diff_api.DisableClientState;
|
---|
2289 | able[1] = pState->diff_api.EnableClientState;
|
---|
2290 | if (from->array.v.enabled != to->array.v.enabled) {
|
---|
2291 | able[to->array.v.enabled](GL_VERTEX_ARRAY);
|
---|
2292 | FILLDIRTY(cb->enableClientState);
|
---|
2293 | FILLDIRTY(cb->dirty);
|
---|
2294 | }
|
---|
2295 | if (from->array.n.enabled != to->array.n.enabled) {
|
---|
2296 | able[to->array.n.enabled](GL_NORMAL_ARRAY);
|
---|
2297 | FILLDIRTY(cb->enableClientState);
|
---|
2298 | FILLDIRTY(cb->dirty);
|
---|
2299 | }
|
---|
2300 | if (from->array.c.enabled != to->array.c.enabled) {
|
---|
2301 | able[to->array.c.enabled](GL_COLOR_ARRAY);
|
---|
2302 | FILLDIRTY(cb->enableClientState);
|
---|
2303 | FILLDIRTY(cb->dirty);
|
---|
2304 | }
|
---|
2305 | if (from->array.i.enabled != to->array.i.enabled) {
|
---|
2306 | able[to->array.i.enabled](GL_INDEX_ARRAY);
|
---|
2307 | FILLDIRTY(cb->enableClientState);
|
---|
2308 | FILLDIRTY(cb->dirty);
|
---|
2309 | }
|
---|
2310 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
2311 | if (from->array.t[i].enabled != to->array.t[i].enabled) {
|
---|
2312 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
2313 | curClientTextureUnit = i;
|
---|
2314 | able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
|
---|
2315 | FILLDIRTY(cb->enableClientState);
|
---|
2316 | FILLDIRTY(cb->dirty);
|
---|
2317 | }
|
---|
2318 | }
|
---|
2319 | if (from->array.e.enabled != to->array.e.enabled) {
|
---|
2320 | able[to->array.e.enabled](GL_EDGE_FLAG_ARRAY);
|
---|
2321 | FILLDIRTY(cb->enableClientState);
|
---|
2322 | FILLDIRTY(cb->dirty);
|
---|
2323 | }
|
---|
2324 | if (from->array.s.enabled != to->array.s.enabled) {
|
---|
2325 | able[to->array.s.enabled](GL_SECONDARY_COLOR_ARRAY_EXT);
|
---|
2326 | FILLDIRTY(cb->enableClientState);
|
---|
2327 | FILLDIRTY(cb->dirty);
|
---|
2328 | }
|
---|
2329 | if (from->array.f.enabled != to->array.f.enabled) {
|
---|
2330 | able[to->array.f.enabled](GL_FOG_COORDINATE_ARRAY_EXT);
|
---|
2331 | FILLDIRTY(cb->enableClientState);
|
---|
2332 | FILLDIRTY(cb->dirty);
|
---|
2333 | }
|
---|
2334 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
2335 | if (from->array.a[i].enabled != to->array.a[i].enabled) {
|
---|
2336 | if (to->array.a[i].enabled)
|
---|
2337 | pState->diff_api.EnableVertexAttribArrayARB(i);
|
---|
2338 | else
|
---|
2339 | pState->diff_api.DisableVertexAttribArrayARB(i);
|
---|
2340 | FILLDIRTY(cb->enableClientState);
|
---|
2341 | FILLDIRTY(cb->dirty);
|
---|
2342 | }
|
---|
2343 | }
|
---|
2344 | CLEARDIRTY2(cb->enableClientState, bitID);
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | if (to->curClientTextureUnit != curClientTextureUnit)
|
---|
2348 | {
|
---|
2349 | pState->diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | if (CHECKDIRTY(cb->unpack, bitID))
|
---|
2353 | {
|
---|
2354 | if (from->unpack.rowLength != to->unpack.rowLength)
|
---|
2355 | {
|
---|
2356 | pState->diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, to->unpack.rowLength);
|
---|
2357 | FILLDIRTY(cb->unpack);
|
---|
2358 | FILLDIRTY(cb->dirty);
|
---|
2359 | }
|
---|
2360 | if (from->unpack.skipRows != to->unpack.skipRows)
|
---|
2361 | {
|
---|
2362 | pState->diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, to->unpack.skipRows);
|
---|
2363 | FILLDIRTY(cb->unpack);
|
---|
2364 | FILLDIRTY(cb->dirty);
|
---|
2365 | }
|
---|
2366 | if (from->unpack.skipPixels != to->unpack.skipPixels)
|
---|
2367 | {
|
---|
2368 | pState->diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, to->unpack.skipPixels);
|
---|
2369 | FILLDIRTY(cb->unpack);
|
---|
2370 | FILLDIRTY(cb->dirty);
|
---|
2371 | }
|
---|
2372 | if (from->unpack.alignment != to->unpack.alignment)
|
---|
2373 | {
|
---|
2374 | pState->diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, to->unpack.alignment);
|
---|
2375 | FILLDIRTY(cb->unpack);
|
---|
2376 | FILLDIRTY(cb->dirty);
|
---|
2377 | }
|
---|
2378 | if (from->unpack.imageHeight != to->unpack.imageHeight)
|
---|
2379 | {
|
---|
2380 | pState->diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, to->unpack.imageHeight);
|
---|
2381 | FILLDIRTY(cb->unpack);
|
---|
2382 | FILLDIRTY(cb->dirty);
|
---|
2383 | }
|
---|
2384 | if (from->unpack.skipImages != to->unpack.skipImages)
|
---|
2385 | {
|
---|
2386 | pState->diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, to->unpack.skipImages);
|
---|
2387 | FILLDIRTY(cb->unpack);
|
---|
2388 | FILLDIRTY(cb->dirty);
|
---|
2389 | }
|
---|
2390 | if (from->unpack.swapBytes != to->unpack.swapBytes)
|
---|
2391 | {
|
---|
2392 | pState->diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, to->unpack.swapBytes);
|
---|
2393 | FILLDIRTY(cb->unpack);
|
---|
2394 | FILLDIRTY(cb->dirty);
|
---|
2395 | }
|
---|
2396 | if (from->unpack.psLSBFirst != to->unpack.psLSBFirst)
|
---|
2397 | {
|
---|
2398 | pState->diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, to->unpack.psLSBFirst);
|
---|
2399 | FILLDIRTY(cb->unpack);
|
---|
2400 | FILLDIRTY(cb->dirty);
|
---|
2401 | }
|
---|
2402 | CLEARDIRTY2(cb->unpack, bitID);
|
---|
2403 | }
|
---|
2404 |
|
---|
2405 | if (CHECKDIRTY(cb->pack, bitID))
|
---|
2406 | {
|
---|
2407 | if (from->pack.rowLength != to->pack.rowLength)
|
---|
2408 | {
|
---|
2409 | pState->diff_api.PixelStorei(GL_PACK_ROW_LENGTH, to->pack.rowLength);
|
---|
2410 | FILLDIRTY(cb->pack);
|
---|
2411 | FILLDIRTY(cb->dirty);
|
---|
2412 | }
|
---|
2413 | if (from->pack.skipRows != to->pack.skipRows)
|
---|
2414 | {
|
---|
2415 | pState->diff_api.PixelStorei(GL_PACK_SKIP_ROWS, to->pack.skipRows);
|
---|
2416 | FILLDIRTY(cb->pack);
|
---|
2417 | FILLDIRTY(cb->dirty);
|
---|
2418 | }
|
---|
2419 | if (from->pack.skipPixels != to->pack.skipPixels)
|
---|
2420 | {
|
---|
2421 | pState->diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, to->pack.skipPixels);
|
---|
2422 | FILLDIRTY(cb->pack);
|
---|
2423 | FILLDIRTY(cb->dirty);
|
---|
2424 | }
|
---|
2425 | if (from->pack.alignment != to->pack.alignment)
|
---|
2426 | {
|
---|
2427 | pState->diff_api.PixelStorei(GL_PACK_ALIGNMENT, to->pack.alignment);
|
---|
2428 | FILLDIRTY(cb->pack);
|
---|
2429 | FILLDIRTY(cb->dirty);
|
---|
2430 | }
|
---|
2431 | if (from->pack.imageHeight != to->pack.imageHeight)
|
---|
2432 | {
|
---|
2433 | pState->diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, to->pack.imageHeight);
|
---|
2434 | FILLDIRTY(cb->pack);
|
---|
2435 | FILLDIRTY(cb->dirty);
|
---|
2436 | }
|
---|
2437 | if (from->pack.skipImages != to->pack.skipImages)
|
---|
2438 | {
|
---|
2439 | pState->diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, to->pack.skipImages);
|
---|
2440 | FILLDIRTY(cb->pack);
|
---|
2441 | FILLDIRTY(cb->dirty);
|
---|
2442 | }
|
---|
2443 | if (from->pack.swapBytes != to->pack.swapBytes)
|
---|
2444 | {
|
---|
2445 | pState->diff_api.PixelStorei(GL_PACK_SWAP_BYTES, to->pack.swapBytes);
|
---|
2446 | FILLDIRTY(cb->pack);
|
---|
2447 | FILLDIRTY(cb->dirty);
|
---|
2448 | }
|
---|
2449 | if (from->pack.psLSBFirst != to->pack.psLSBFirst)
|
---|
2450 | {
|
---|
2451 | pState->diff_api.PixelStorei(GL_PACK_LSB_FIRST, to->pack.psLSBFirst);
|
---|
2452 | FILLDIRTY(cb->pack);
|
---|
2453 | FILLDIRTY(cb->dirty);
|
---|
2454 | }
|
---|
2455 | CLEARDIRTY2(cb->pack, bitID);
|
---|
2456 | }
|
---|
2457 |
|
---|
2458 | CLEARDIRTY2(cb->dirty, bitID);
|
---|
2459 | }
|
---|
2460 |
|
---|
2461 | CRClientPointer* crStateGetClientPointerByIndex(int index, CRVertexArrays *array)
|
---|
2462 | {
|
---|
2463 | CRASSERT(array && index>=0 && index<CRSTATECLIENT_MAX_VERTEXARRAYS);
|
---|
2464 |
|
---|
2465 | if (array == NULL || index < 0 || index >= CRSTATECLIENT_MAX_VERTEXARRAYS)
|
---|
2466 | {
|
---|
2467 | return NULL;
|
---|
2468 | }
|
---|
2469 |
|
---|
2470 | if (index < 7)
|
---|
2471 | {
|
---|
2472 | switch (index)
|
---|
2473 | {
|
---|
2474 | case 0: return &array->v;
|
---|
2475 | case 1: return &array->c;
|
---|
2476 | case 2: return &array->f;
|
---|
2477 | case 3: return &array->s;
|
---|
2478 | case 4: return &array->e;
|
---|
2479 | case 5: return &array->i;
|
---|
2480 | case 6: return &array->n;
|
---|
2481 | }
|
---|
2482 | }
|
---|
2483 | else if (index<(7+CR_MAX_TEXTURE_UNITS))
|
---|
2484 | {
|
---|
2485 | return &array->t[index-7];
|
---|
2486 | }
|
---|
2487 | else
|
---|
2488 | {
|
---|
2489 | return &array->a[index-7-CR_MAX_TEXTURE_UNITS];
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | /*silence the compiler warning*/
|
---|
2493 | CRASSERT(false);
|
---|
2494 | return NULL;
|
---|
2495 | }
|
---|