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