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