VirtualBox

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

Last change on this file since 27159 was 26407, checked in by vboxsync, 15 years ago

crOpenGL: fix host gpu crashes when running realflight3d g4 demo in guest

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

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