VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_client.c@ 52350

最後變更 在這個檔案從52350是 51319,由 vboxsync 提交於 11 年 前

crOpenGL: adjusment

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette