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 | (void)length; (void)pointer;
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 |
|
---|
1541 | void STATE_APIENTRY crStateFlushVertexArrayRangeNV(void)
|
---|
1542 | {
|
---|
1543 | /* XXX todo */
|
---|
1544 | crWarning("crStateFlushVertexArrayRangeNV not implemented");
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | /*Returns if the given clientpointer could be used on server side directly*/
|
---|
1548 | #define CRSTATE_IS_SERVER_CP(cp) (!(cp).enabled || !(cp).p || ((cp).buffer && (cp).buffer->id) || ((cp).locked))
|
---|
1549 |
|
---|
1550 | #if defined(DEBUG) && 0
|
---|
1551 | static void crStateDumpClientPointer(CRClientPointer *cp, const char *name, int i)
|
---|
1552 | {
|
---|
1553 | if (i<0 && cp->enabled)
|
---|
1554 | {
|
---|
1555 | crDebug("CP(%s): enabled:%d ptr:%p buffer:%p buffer.name:%i locked: %i %s",
|
---|
1556 | name, cp->enabled, cp->p, cp->buffer, cp->buffer ? cp->buffer->id : ~(GLuint)0, (int)cp->locked,
|
---|
1557 | CRSTATE_IS_SERVER_CP(*cp) ? "":"!FAIL!");
|
---|
1558 | }
|
---|
1559 | else if (0==i || cp->enabled)
|
---|
1560 | {
|
---|
1561 | crDebug("CP(%s%i): enabled:%d ptr:%p buffer:%p buffer.name:%i locked: %i %s",
|
---|
1562 | name, i, cp->enabled, cp->p, cp->buffer, cp->buffer ? cp->buffer->id : ~(GLuint)0, (int)cp->locked,
|
---|
1563 | CRSTATE_IS_SERVER_CP(*cp) ? "":"!FAIL!");
|
---|
1564 | }
|
---|
1565 | }
|
---|
1566 | #endif
|
---|
1567 |
|
---|
1568 | #ifdef DEBUG_misha
|
---|
1569 | /* debugging */
|
---|
1570 | /*# define CR_NO_SERVER_ARRAYS*/
|
---|
1571 | #endif
|
---|
1572 |
|
---|
1573 | /*
|
---|
1574 | * Determine if the enabled arrays all live on the server
|
---|
1575 | * (via GL_ARB_vertex_buffer_object).
|
---|
1576 | */
|
---|
1577 | GLboolean crStateUseServerArrays(void)
|
---|
1578 | {
|
---|
1579 | #if defined(CR_ARB_vertex_buffer_object) && !defined(CR_NO_SERVER_ARRAYS)
|
---|
1580 | CRContext *g = GetCurrentContext();
|
---|
1581 | CRClientState *c = &(g->client);
|
---|
1582 | int i;
|
---|
1583 | GLboolean res;
|
---|
1584 |
|
---|
1585 | res = CRSTATE_IS_SERVER_CP(c->array.v)
|
---|
1586 | && CRSTATE_IS_SERVER_CP(c->array.n)
|
---|
1587 | && CRSTATE_IS_SERVER_CP(c->array.c)
|
---|
1588 | && CRSTATE_IS_SERVER_CP(c->array.i)
|
---|
1589 | && CRSTATE_IS_SERVER_CP(c->array.e)
|
---|
1590 | && CRSTATE_IS_SERVER_CP(c->array.s)
|
---|
1591 | && CRSTATE_IS_SERVER_CP(c->array.f);
|
---|
1592 |
|
---|
1593 | if (res)
|
---|
1594 | {
|
---|
1595 | for (i = 0; (unsigned int)i < g->limits.maxTextureUnits; i++)
|
---|
1596 | if (!CRSTATE_IS_SERVER_CP(c->array.t[i]))
|
---|
1597 | {
|
---|
1598 | res = GL_FALSE;
|
---|
1599 | break;
|
---|
1600 | }
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | if (res)
|
---|
1604 | {
|
---|
1605 | for (i = 0; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1606 | if (!CRSTATE_IS_SERVER_CP(c->array.a[i]))
|
---|
1607 | {
|
---|
1608 | res = GL_FALSE;
|
---|
1609 | break;
|
---|
1610 | }
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | #if defined(DEBUG) && 0
|
---|
1614 | if (!res)
|
---|
1615 | {
|
---|
1616 | crStateDumpClientPointer(&c->array.v, "v", -1);
|
---|
1617 | crStateDumpClientPointer(&c->array.n, "n", -1);
|
---|
1618 | crStateDumpClientPointer(&c->array.c, "c", -1);
|
---|
1619 | crStateDumpClientPointer(&c->array.i, "i", -1);
|
---|
1620 | crStateDumpClientPointer(&c->array.e, "e", -1);
|
---|
1621 | crStateDumpClientPointer(&c->array.s, "s", -1);
|
---|
1622 | crStateDumpClientPointer(&c->array.f, "f", -1);
|
---|
1623 | for (i = 0; (unsigned int)i < g->limits.maxTextureUnits; i++)
|
---|
1624 | crStateDumpClientPointer(&c->array.t[i], "tex", i);
|
---|
1625 | for (i = 0; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1626 | crStateDumpClientPointer(&c->array.a[i], "attrib", i);
|
---|
1627 | crDebug("crStateUseServerArrays->%d", res);
|
---|
1628 | }
|
---|
1629 | #endif
|
---|
1630 |
|
---|
1631 | return res;
|
---|
1632 | #else
|
---|
1633 | return GL_FALSE;
|
---|
1634 | #endif
|
---|
1635 | }
|
---|
1636 |
|
---|
1637 | GLuint crStateNeedDummyZeroVertexArray(CRContext *g, CRCurrentStatePointers *current, GLfloat *pZva)
|
---|
1638 | {
|
---|
1639 | #if defined(CR_ARB_vertex_buffer_object)
|
---|
1640 | CRClientState *c = &(g->client);
|
---|
1641 | int i;
|
---|
1642 | GLuint zvMax = 0;
|
---|
1643 |
|
---|
1644 | if (c->array.a[0].enabled)
|
---|
1645 | return 0;
|
---|
1646 |
|
---|
1647 | for (i = 1; (unsigned int)i < g->limits.maxVertexProgramAttribs; i++)
|
---|
1648 | {
|
---|
1649 | if (c->array.a[i].enabled)
|
---|
1650 | {
|
---|
1651 | if (c->array.a[i].buffer && c->array.a[i].buffer->id)
|
---|
1652 | {
|
---|
1653 | GLuint cElements = c->array.a[i].buffer->size / c->array.a[i].stride;
|
---|
1654 | if (zvMax < cElements)
|
---|
1655 | zvMax = cElements;
|
---|
1656 | }
|
---|
1657 | else
|
---|
1658 | {
|
---|
1659 | zvMax = ~0;
|
---|
1660 | break;
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 | }
|
---|
1664 |
|
---|
1665 | if (zvMax)
|
---|
1666 | {
|
---|
1667 | Assert(!c->array.v.enabled);
|
---|
1668 |
|
---|
1669 | crStateCurrentRecoverNew(g, current);
|
---|
1670 |
|
---|
1671 | crMemcpy(pZva, &g->current.vertexAttrib[0][0], sizeof (*pZva) * 4);
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | return zvMax;
|
---|
1675 | #else
|
---|
1676 | return GL_FALSE;
|
---|
1677 | #endif
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 |
|
---|
1681 | /**
|
---|
1682 | * Determine if there's a server-side array element buffer.
|
---|
1683 | * Called by glDrawElements() in packing SPUs to determine if glDrawElements
|
---|
1684 | * should be evaluated (unrolled) locally or if glDrawElements should be
|
---|
1685 | * packed and sent to the server.
|
---|
1686 | */
|
---|
1687 | GLboolean
|
---|
1688 | crStateUseServerArrayElements(void)
|
---|
1689 | {
|
---|
1690 | #ifdef CR_ARB_vertex_buffer_object
|
---|
1691 | CRContext *g = GetCurrentContext();
|
---|
1692 | if (g->bufferobject.elementsBuffer &&
|
---|
1693 | g->bufferobject.elementsBuffer->id > 0)
|
---|
1694 | return GL_TRUE;
|
---|
1695 | else
|
---|
1696 | return GL_FALSE;
|
---|
1697 | #else
|
---|
1698 | return GL_FALSE;
|
---|
1699 | #endif
|
---|
1700 | }
|
---|
1701 |
|
---|
1702 | #define CR_BUFFER_HWID(_p) ((_p) ? (_p)->hwid : 0)
|
---|
1703 |
|
---|
1704 | void
|
---|
1705 | crStateClientDiff(CRClientBits *cb, CRbitvalue *bitID,
|
---|
1706 | CRContext *fromCtx, CRContext *toCtx)
|
---|
1707 | {
|
---|
1708 | CRClientState *from = &(fromCtx->client);
|
---|
1709 | const CRClientState *to = &(toCtx->client);
|
---|
1710 | GLint curClientTextureUnit = from->curClientTextureUnit;
|
---|
1711 | int i;
|
---|
1712 | GLint idHwArrayBuffer = CR_BUFFER_HWID(toCtx->bufferobject.arrayBuffer);
|
---|
1713 | const GLint idHwInitialBuffer = idHwArrayBuffer;
|
---|
1714 |
|
---|
1715 | #ifdef DEBUG_misha
|
---|
1716 | {
|
---|
1717 | GLint tstHwBuffer = -1;
|
---|
1718 | diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
|
---|
1719 | CRASSERT(idHwInitialBuffer == tstHwBuffer);
|
---|
1720 | }
|
---|
1721 | #endif
|
---|
1722 |
|
---|
1723 |
|
---|
1724 | if (CHECKDIRTY(cb->clientPointer, bitID)) {
|
---|
1725 | /* one or more vertex pointers is dirty */
|
---|
1726 | if (CHECKDIRTY(cb->v, bitID)) {
|
---|
1727 | if (from->array.v.size != to->array.v.size ||
|
---|
1728 | from->array.v.type != to->array.v.type ||
|
---|
1729 | from->array.v.stride != to->array.v.stride ||
|
---|
1730 | from->array.v.p != to->array.v.p ||
|
---|
1731 | from->array.v.buffer != to->array.v.buffer) {
|
---|
1732 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.v.buffer);
|
---|
1733 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1734 | {
|
---|
1735 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1736 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1737 | }
|
---|
1738 | diff_api.VertexPointer(to->array.v.size, to->array.v.type,
|
---|
1739 | to->array.v.stride, to->array.v.p);
|
---|
1740 | from->array.v.size = to->array.v.size;
|
---|
1741 | from->array.v.type = to->array.v.type;
|
---|
1742 | from->array.v.stride = to->array.v.stride;
|
---|
1743 | from->array.v.p = to->array.v.p;
|
---|
1744 | from->array.v.buffer = to->array.v.buffer;
|
---|
1745 | }
|
---|
1746 | CLEARDIRTY2(cb->v, bitID);
|
---|
1747 | }
|
---|
1748 | /* normal */
|
---|
1749 | if (CHECKDIRTY(cb->n, bitID)) {
|
---|
1750 | if (from->array.n.type != to->array.n.type ||
|
---|
1751 | from->array.n.stride != to->array.n.stride ||
|
---|
1752 | from->array.n.p != to->array.n.p ||
|
---|
1753 | from->array.n.buffer != to->array.n.buffer) {
|
---|
1754 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.n.buffer);
|
---|
1755 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1756 | {
|
---|
1757 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1758 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1759 | }
|
---|
1760 | diff_api.NormalPointer(to->array.n.type,
|
---|
1761 | to->array.n.stride, to->array.n.p);
|
---|
1762 | from->array.n.type = to->array.n.type;
|
---|
1763 | from->array.n.stride = to->array.n.stride;
|
---|
1764 | from->array.n.p = to->array.n.p;
|
---|
1765 | from->array.n.buffer = to->array.n.buffer;
|
---|
1766 | }
|
---|
1767 | CLEARDIRTY2(cb->n, bitID);
|
---|
1768 | }
|
---|
1769 | /* color */
|
---|
1770 | if (CHECKDIRTY(cb->c, bitID)) {
|
---|
1771 | if (from->array.c.size != to->array.c.size ||
|
---|
1772 | from->array.c.type != to->array.c.type ||
|
---|
1773 | from->array.c.stride != to->array.c.stride ||
|
---|
1774 | from->array.c.p != to->array.c.p ||
|
---|
1775 | from->array.c.buffer != to->array.c.buffer) {
|
---|
1776 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.c.buffer);
|
---|
1777 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1778 | {
|
---|
1779 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1780 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1781 | }
|
---|
1782 | diff_api.ColorPointer(to->array.c.size, to->array.c.type,
|
---|
1783 | to->array.c.stride, to->array.c.p);
|
---|
1784 | from->array.c.size = to->array.c.size;
|
---|
1785 | from->array.c.type = to->array.c.type;
|
---|
1786 | from->array.c.stride = to->array.c.stride;
|
---|
1787 | from->array.c.p = to->array.c.p;
|
---|
1788 | from->array.c.buffer = to->array.c.buffer;
|
---|
1789 | }
|
---|
1790 | CLEARDIRTY2(cb->c, bitID);
|
---|
1791 | }
|
---|
1792 | /* index */
|
---|
1793 | if (CHECKDIRTY(cb->i, bitID)) {
|
---|
1794 | if (from->array.i.type != to->array.i.type ||
|
---|
1795 | from->array.i.stride != to->array.i.stride ||
|
---|
1796 | from->array.i.p != to->array.i.p ||
|
---|
1797 | from->array.i.buffer != to->array.i.buffer) {
|
---|
1798 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.i.buffer);
|
---|
1799 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1800 | {
|
---|
1801 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1802 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1803 | }
|
---|
1804 | diff_api.IndexPointer(to->array.i.type,
|
---|
1805 | to->array.i.stride, to->array.i.p);
|
---|
1806 | from->array.i.type = to->array.i.type;
|
---|
1807 | from->array.i.stride = to->array.i.stride;
|
---|
1808 | from->array.i.p = to->array.i.p;
|
---|
1809 | from->array.i.buffer = to->array.i.buffer;
|
---|
1810 | }
|
---|
1811 | CLEARDIRTY2(cb->i, bitID);
|
---|
1812 | }
|
---|
1813 | /* texcoords */
|
---|
1814 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
1815 | if (CHECKDIRTY(cb->t[i], bitID)) {
|
---|
1816 | if (from->array.t[i].size != to->array.t[i].size ||
|
---|
1817 | from->array.t[i].type != to->array.t[i].type ||
|
---|
1818 | from->array.t[i].stride != to->array.t[i].stride ||
|
---|
1819 | from->array.t[i].p != to->array.t[i].p ||
|
---|
1820 | from->array.t[i].buffer != to->array.t[i].buffer) {
|
---|
1821 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.t[i].buffer);
|
---|
1822 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1823 | {
|
---|
1824 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1825 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1826 | }
|
---|
1827 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
1828 | curClientTextureUnit = i;
|
---|
1829 | diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type,
|
---|
1830 | to->array.t[i].stride, to->array.t[i].p);
|
---|
1831 | from->array.t[i].size = to->array.t[i].size;
|
---|
1832 | from->array.t[i].type = to->array.t[i].type;
|
---|
1833 | from->array.t[i].stride = to->array.t[i].stride;
|
---|
1834 | from->array.t[i].p = to->array.t[i].p;
|
---|
1835 | from->array.t[i].buffer = to->array.t[i].buffer;
|
---|
1836 | }
|
---|
1837 | CLEARDIRTY2(cb->t[i], bitID);
|
---|
1838 | }
|
---|
1839 | }
|
---|
1840 | /* edge flag */
|
---|
1841 | if (CHECKDIRTY(cb->e, bitID)) {
|
---|
1842 | if (from->array.e.stride != to->array.e.stride ||
|
---|
1843 | from->array.e.p != to->array.e.p ||
|
---|
1844 | from->array.e.buffer != to->array.e.buffer) {
|
---|
1845 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.e.buffer);
|
---|
1846 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1847 | {
|
---|
1848 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1849 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1850 | }
|
---|
1851 | diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p);
|
---|
1852 | from->array.e.stride = to->array.e.stride;
|
---|
1853 | from->array.e.p = to->array.e.p;
|
---|
1854 | from->array.e.buffer = to->array.e.buffer;
|
---|
1855 | }
|
---|
1856 | CLEARDIRTY2(cb->e, bitID);
|
---|
1857 | }
|
---|
1858 | /* secondary color */
|
---|
1859 | if (CHECKDIRTY(cb->s, bitID)) {
|
---|
1860 | if (from->array.s.size != to->array.s.size ||
|
---|
1861 | from->array.s.type != to->array.s.type ||
|
---|
1862 | from->array.s.stride != to->array.s.stride ||
|
---|
1863 | from->array.s.p != to->array.s.p ||
|
---|
1864 | from->array.s.buffer != to->array.s.buffer) {
|
---|
1865 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.s.buffer);
|
---|
1866 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1867 | {
|
---|
1868 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1869 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1870 | }
|
---|
1871 | diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type,
|
---|
1872 | to->array.s.stride, to->array.s.p);
|
---|
1873 | from->array.s.size = to->array.s.size;
|
---|
1874 | from->array.s.type = to->array.s.type;
|
---|
1875 | from->array.s.stride = to->array.s.stride;
|
---|
1876 | from->array.s.p = to->array.s.p;
|
---|
1877 | from->array.s.buffer = to->array.s.buffer;
|
---|
1878 | }
|
---|
1879 | CLEARDIRTY2(cb->s, bitID);
|
---|
1880 | }
|
---|
1881 | /* fog coord */
|
---|
1882 | if (CHECKDIRTY(cb->f, bitID)) {
|
---|
1883 | if (from->array.f.type != to->array.f.type ||
|
---|
1884 | from->array.f.stride != to->array.f.stride ||
|
---|
1885 | from->array.f.p != to->array.f.p ||
|
---|
1886 | from->array.f.buffer != to->array.f.buffer) {
|
---|
1887 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.f.buffer);
|
---|
1888 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1889 | {
|
---|
1890 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1891 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1892 | }
|
---|
1893 | diff_api.FogCoordPointerEXT(to->array.f.type,
|
---|
1894 | to->array.f.stride, to->array.f.p);
|
---|
1895 | from->array.f.type = to->array.f.type;
|
---|
1896 | from->array.f.stride = to->array.f.stride;
|
---|
1897 | from->array.f.p = to->array.f.p;
|
---|
1898 | from->array.f.buffer = to->array.f.buffer;
|
---|
1899 | }
|
---|
1900 | CLEARDIRTY2(cb->f, bitID);
|
---|
1901 | }
|
---|
1902 | #if defined(CR_NV_vertex_program) || defined(CR_ARB_vertex_program)
|
---|
1903 | /* vertex attributes */
|
---|
1904 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
1905 | if (CHECKDIRTY(cb->a[i], bitID)) {
|
---|
1906 | if (from->array.a[i].size != to->array.a[i].size ||
|
---|
1907 | from->array.a[i].type != to->array.a[i].type ||
|
---|
1908 | from->array.a[i].stride != to->array.a[i].stride ||
|
---|
1909 | from->array.a[i].normalized != to->array.a[i].normalized ||
|
---|
1910 | from->array.a[i].p != to->array.a[i].p ||
|
---|
1911 | from->array.a[i].buffer != to->array.a[i].buffer) {
|
---|
1912 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.a[i].buffer);
|
---|
1913 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
1914 | {
|
---|
1915 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
1916 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
1917 | }
|
---|
1918 | diff_api.VertexAttribPointerARB(i, to->array.a[i].size,
|
---|
1919 | to->array.a[i].type,
|
---|
1920 | to->array.a[i].normalized,
|
---|
1921 | to->array.a[i].stride,
|
---|
1922 | to->array.a[i].p);
|
---|
1923 | from->array.a[i].size = to->array.a[i].size;
|
---|
1924 | from->array.a[i].type = to->array.a[i].type;
|
---|
1925 | from->array.a[i].stride = to->array.a[i].stride;
|
---|
1926 | from->array.a[i].normalized = to->array.a[i].normalized;
|
---|
1927 | from->array.a[i].p = to->array.a[i].p;
|
---|
1928 | from->array.a[i].buffer = to->array.a[i].buffer;
|
---|
1929 | }
|
---|
1930 | CLEARDIRTY2(cb->a[i], bitID);
|
---|
1931 | }
|
---|
1932 | }
|
---|
1933 | #endif
|
---|
1934 | }
|
---|
1935 |
|
---|
1936 | if (idHwArrayBuffer != idHwInitialBuffer)
|
---|
1937 | {
|
---|
1938 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
|
---|
1939 | }
|
---|
1940 |
|
---|
1941 | if (CHECKDIRTY(cb->enableClientState, bitID)) {
|
---|
1942 | /* update vertex array enable/disable flags */
|
---|
1943 | glAble able[2];
|
---|
1944 | able[0] = diff_api.DisableClientState;
|
---|
1945 | able[1] = diff_api.EnableClientState;
|
---|
1946 | if (from->array.v.enabled != to->array.v.enabled) {
|
---|
1947 | able[to->array.v.enabled](GL_VERTEX_ARRAY);
|
---|
1948 | from->array.v.enabled = to->array.v.enabled;
|
---|
1949 | }
|
---|
1950 | if (from->array.n.enabled != to->array.n.enabled) {
|
---|
1951 | able[to->array.n.enabled](GL_NORMAL_ARRAY);
|
---|
1952 | from->array.n.enabled = to->array.n.enabled;
|
---|
1953 | }
|
---|
1954 | if (from->array.c.enabled != to->array.c.enabled) {
|
---|
1955 | able[to->array.c.enabled](GL_COLOR_ARRAY);
|
---|
1956 | from->array.c.enabled = to->array.c.enabled;
|
---|
1957 | }
|
---|
1958 | if (from->array.i.enabled != to->array.i.enabled) {
|
---|
1959 | able[to->array.i.enabled](GL_INDEX_ARRAY);
|
---|
1960 | from->array.i.enabled = to->array.i.enabled;
|
---|
1961 | }
|
---|
1962 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
1963 | if (from->array.t[i].enabled != to->array.t[i].enabled) {
|
---|
1964 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
1965 | curClientTextureUnit = i;
|
---|
1966 | able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
|
---|
1967 | from->array.t[i].enabled = to->array.t[i].enabled;
|
---|
1968 | }
|
---|
1969 | }
|
---|
1970 | if (from->array.e.enabled != to->array.e.enabled) {
|
---|
1971 | able[to->array.e.enabled](GL_EDGE_FLAG_ARRAY);
|
---|
1972 | from->array.e.enabled = to->array.e.enabled;
|
---|
1973 | }
|
---|
1974 | if (from->array.s.enabled != to->array.s.enabled) {
|
---|
1975 | able[to->array.s.enabled](GL_SECONDARY_COLOR_ARRAY_EXT);
|
---|
1976 | from->array.s.enabled = to->array.s.enabled;
|
---|
1977 | }
|
---|
1978 | if (from->array.f.enabled != to->array.f.enabled) {
|
---|
1979 | able[to->array.f.enabled](GL_FOG_COORDINATE_ARRAY_EXT);
|
---|
1980 | from->array.f.enabled = to->array.f.enabled;
|
---|
1981 | }
|
---|
1982 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
1983 | if (from->array.a[i].enabled != to->array.a[i].enabled) {
|
---|
1984 | if (to->array.a[i].enabled)
|
---|
1985 | diff_api.EnableVertexAttribArrayARB(i);
|
---|
1986 | else
|
---|
1987 | diff_api.DisableVertexAttribArrayARB(i);
|
---|
1988 | from->array.a[i].enabled = to->array.a[i].enabled;
|
---|
1989 | }
|
---|
1990 | }
|
---|
1991 | CLEARDIRTY2(cb->enableClientState, bitID);
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | if (to->curClientTextureUnit != curClientTextureUnit)
|
---|
1995 | {
|
---|
1996 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
|
---|
1997 | }
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 |
|
---|
2001 | void
|
---|
2002 | crStateClientSwitch(CRClientBits *cb, CRbitvalue *bitID,
|
---|
2003 | CRContext *fromCtx, CRContext *toCtx)
|
---|
2004 | {
|
---|
2005 | const CRClientState *from = &(fromCtx->client);
|
---|
2006 | const CRClientState *to = &(toCtx->client);
|
---|
2007 | GLint curClientTextureUnit = from->curClientTextureUnit;
|
---|
2008 | int i;
|
---|
2009 | GLint idHwArrayBuffer = CR_BUFFER_HWID(toCtx->bufferobject.arrayBuffer);
|
---|
2010 | const GLint idHwInitialBuffer = idHwArrayBuffer;
|
---|
2011 |
|
---|
2012 | #ifdef DEBUG_misha
|
---|
2013 | {
|
---|
2014 | GLint tstHwBuffer = -1;
|
---|
2015 | diff_api.GetIntegerv(GL_ARRAY_BUFFER_BINDING, &tstHwBuffer);
|
---|
2016 | CRASSERT(idHwInitialBuffer == tstHwBuffer);
|
---|
2017 | }
|
---|
2018 | #endif
|
---|
2019 |
|
---|
2020 | if (CHECKDIRTY(cb->clientPointer, bitID)) {
|
---|
2021 | /* one or more vertex pointers is dirty */
|
---|
2022 | if (CHECKDIRTY(cb->v, bitID)) {
|
---|
2023 | if (from->array.v.size != to->array.v.size ||
|
---|
2024 | from->array.v.type != to->array.v.type ||
|
---|
2025 | from->array.v.stride != to->array.v.stride ||
|
---|
2026 | from->array.v.p != to->array.v.p ||
|
---|
2027 | from->array.v.buffer != to->array.v.buffer) {
|
---|
2028 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.v.buffer);
|
---|
2029 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2030 | {
|
---|
2031 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2032 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2033 | }
|
---|
2034 | diff_api.VertexPointer(to->array.v.size, to->array.v.type,
|
---|
2035 | to->array.v.stride, to->array.v.p);
|
---|
2036 | FILLDIRTY(cb->v);
|
---|
2037 | FILLDIRTY(cb->clientPointer);
|
---|
2038 | FILLDIRTY(cb->dirty);
|
---|
2039 | }
|
---|
2040 | CLEARDIRTY2(cb->v, bitID);
|
---|
2041 | }
|
---|
2042 | /* normal */
|
---|
2043 | if (CHECKDIRTY(cb->n, bitID)) {
|
---|
2044 | if (from->array.n.type != to->array.n.type ||
|
---|
2045 | from->array.n.stride != to->array.n.stride ||
|
---|
2046 | from->array.n.p != to->array.n.p ||
|
---|
2047 | from->array.n.buffer != to->array.n.buffer) {
|
---|
2048 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.n.buffer);
|
---|
2049 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2050 | {
|
---|
2051 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2052 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2053 | }
|
---|
2054 | diff_api.NormalPointer(to->array.n.type,
|
---|
2055 | to->array.n.stride, to->array.n.p);
|
---|
2056 | FILLDIRTY(cb->n);
|
---|
2057 | FILLDIRTY(cb->clientPointer);
|
---|
2058 | FILLDIRTY(cb->dirty);
|
---|
2059 | }
|
---|
2060 | CLEARDIRTY2(cb->n, bitID);
|
---|
2061 | }
|
---|
2062 | /* color */
|
---|
2063 | if (CHECKDIRTY(cb->c, bitID)) {
|
---|
2064 | if (from->array.c.size != to->array.c.size ||
|
---|
2065 | from->array.c.type != to->array.c.type ||
|
---|
2066 | from->array.c.stride != to->array.c.stride ||
|
---|
2067 | from->array.c.p != to->array.c.p ||
|
---|
2068 | from->array.c.buffer != to->array.c.buffer) {
|
---|
2069 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.c.buffer);
|
---|
2070 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2071 | {
|
---|
2072 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2073 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2074 | }
|
---|
2075 | diff_api.ColorPointer(to->array.c.size, to->array.c.type,
|
---|
2076 | to->array.c.stride, to->array.c.p);
|
---|
2077 | FILLDIRTY(cb->c);
|
---|
2078 | FILLDIRTY(cb->clientPointer);
|
---|
2079 | FILLDIRTY(cb->dirty);
|
---|
2080 | }
|
---|
2081 | CLEARDIRTY2(cb->c, bitID);
|
---|
2082 | }
|
---|
2083 | /* index */
|
---|
2084 | if (CHECKDIRTY(cb->i, bitID)) {
|
---|
2085 | if (from->array.i.type != to->array.i.type ||
|
---|
2086 | from->array.i.stride != to->array.i.stride ||
|
---|
2087 | from->array.i.p != to->array.i.p ||
|
---|
2088 | from->array.i.buffer != to->array.i.buffer) {
|
---|
2089 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.i.buffer);
|
---|
2090 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2091 | {
|
---|
2092 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2093 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2094 | }
|
---|
2095 | diff_api.IndexPointer(to->array.i.type,
|
---|
2096 | to->array.i.stride, to->array.i.p);
|
---|
2097 | FILLDIRTY(cb->i);
|
---|
2098 | FILLDIRTY(cb->dirty);
|
---|
2099 | FILLDIRTY(cb->clientPointer);
|
---|
2100 | }
|
---|
2101 | CLEARDIRTY2(cb->i, bitID);
|
---|
2102 | }
|
---|
2103 | /* texcoords */
|
---|
2104 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
2105 | if (CHECKDIRTY(cb->t[i], bitID)) {
|
---|
2106 | if (from->array.t[i].size != to->array.t[i].size ||
|
---|
2107 | from->array.t[i].type != to->array.t[i].type ||
|
---|
2108 | from->array.t[i].stride != to->array.t[i].stride ||
|
---|
2109 | from->array.t[i].p != to->array.t[i].p ||
|
---|
2110 | from->array.t[i].buffer != to->array.t[i].buffer) {
|
---|
2111 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.t[i].buffer);
|
---|
2112 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2113 | {
|
---|
2114 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2115 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2116 | }
|
---|
2117 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
2118 | curClientTextureUnit = i;
|
---|
2119 | diff_api.TexCoordPointer(to->array.t[i].size, to->array.t[i].type,
|
---|
2120 | to->array.t[i].stride, to->array.t[i].p);
|
---|
2121 | FILLDIRTY(cb->t[i]);
|
---|
2122 | FILLDIRTY(cb->clientPointer);
|
---|
2123 | FILLDIRTY(cb->dirty);
|
---|
2124 | }
|
---|
2125 | CLEARDIRTY2(cb->t[i], bitID);
|
---|
2126 | }
|
---|
2127 | }
|
---|
2128 | /* edge flag */
|
---|
2129 | if (CHECKDIRTY(cb->e, bitID)) {
|
---|
2130 | if (from->array.e.stride != to->array.e.stride ||
|
---|
2131 | from->array.e.p != to->array.e.p ||
|
---|
2132 | from->array.e.buffer != to->array.e.buffer) {
|
---|
2133 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.e.buffer);
|
---|
2134 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2135 | {
|
---|
2136 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2137 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2138 | }
|
---|
2139 | diff_api.EdgeFlagPointer(to->array.e.stride, to->array.e.p);
|
---|
2140 | FILLDIRTY(cb->e);
|
---|
2141 | FILLDIRTY(cb->clientPointer);
|
---|
2142 | FILLDIRTY(cb->dirty);
|
---|
2143 | }
|
---|
2144 | CLEARDIRTY2(cb->e, bitID);
|
---|
2145 | }
|
---|
2146 | /* secondary color */
|
---|
2147 | if (CHECKDIRTY(cb->s, bitID)) {
|
---|
2148 | if (from->array.s.size != to->array.s.size ||
|
---|
2149 | from->array.s.type != to->array.s.type ||
|
---|
2150 | from->array.s.stride != to->array.s.stride ||
|
---|
2151 | from->array.s.p != to->array.s.p ||
|
---|
2152 | from->array.s.buffer != to->array.s.buffer) {
|
---|
2153 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.s.buffer);
|
---|
2154 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2155 | {
|
---|
2156 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2157 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2158 | }
|
---|
2159 | diff_api.SecondaryColorPointerEXT(to->array.s.size, to->array.s.type,
|
---|
2160 | to->array.s.stride, to->array.s.p);
|
---|
2161 | FILLDIRTY(cb->s);
|
---|
2162 | FILLDIRTY(cb->clientPointer);
|
---|
2163 | FILLDIRTY(cb->dirty);
|
---|
2164 | }
|
---|
2165 | CLEARDIRTY2(cb->s, bitID);
|
---|
2166 | }
|
---|
2167 | /* fog coord */
|
---|
2168 | if (CHECKDIRTY(cb->f, bitID)) {
|
---|
2169 | if (from->array.f.type != to->array.f.type ||
|
---|
2170 | from->array.f.stride != to->array.f.stride ||
|
---|
2171 | from->array.f.p != to->array.f.p ||
|
---|
2172 | from->array.f.buffer != to->array.f.buffer) {
|
---|
2173 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.f.buffer);
|
---|
2174 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2175 | {
|
---|
2176 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2177 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2178 | }
|
---|
2179 | diff_api.FogCoordPointerEXT(to->array.f.type,
|
---|
2180 | to->array.f.stride, to->array.f.p);
|
---|
2181 | FILLDIRTY(cb->f);
|
---|
2182 | FILLDIRTY(cb->clientPointer);
|
---|
2183 | FILLDIRTY(cb->dirty);
|
---|
2184 | }
|
---|
2185 | CLEARDIRTY2(cb->f, bitID);
|
---|
2186 | }
|
---|
2187 | #if defined(CR_NV_vertex_program) || defined(CR_ARB_vertex_program)
|
---|
2188 | /* vertex attributes */
|
---|
2189 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
2190 | if (CHECKDIRTY(cb->a[i], bitID)) {
|
---|
2191 | if (from->array.a[i].size != to->array.a[i].size ||
|
---|
2192 | from->array.a[i].type != to->array.a[i].type ||
|
---|
2193 | from->array.a[i].stride != to->array.a[i].stride ||
|
---|
2194 | from->array.a[i].normalized != to->array.a[i].normalized ||
|
---|
2195 | from->array.a[i].p != to->array.a[i].p ||
|
---|
2196 | from->array.a[i].buffer != to->array.a[i].buffer) {
|
---|
2197 | GLint idHwArrayBufferUsed = CR_BUFFER_HWID(to->array.a[i].buffer);
|
---|
2198 | if (idHwArrayBufferUsed != idHwArrayBuffer)
|
---|
2199 | {
|
---|
2200 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwArrayBufferUsed);
|
---|
2201 | idHwArrayBuffer = idHwArrayBufferUsed;
|
---|
2202 | }
|
---|
2203 | diff_api.VertexAttribPointerARB(i, to->array.a[i].size,
|
---|
2204 | to->array.a[i].type,
|
---|
2205 | to->array.a[i].normalized,
|
---|
2206 | to->array.a[i].stride,
|
---|
2207 | to->array.a[i].p);
|
---|
2208 | FILLDIRTY(cb->a[i]);
|
---|
2209 | FILLDIRTY(cb->clientPointer);
|
---|
2210 | FILLDIRTY(cb->dirty);
|
---|
2211 | }
|
---|
2212 | CLEARDIRTY2(cb->a[i], bitID);
|
---|
2213 | }
|
---|
2214 | }
|
---|
2215 | #endif
|
---|
2216 | }
|
---|
2217 |
|
---|
2218 | if (idHwArrayBuffer != idHwInitialBuffer)
|
---|
2219 | {
|
---|
2220 | diff_api.BindBufferARB(GL_ARRAY_BUFFER_ARB, idHwInitialBuffer);
|
---|
2221 | }
|
---|
2222 |
|
---|
2223 | if (CHECKDIRTY(cb->enableClientState, bitID)) {
|
---|
2224 | /* update vertex array enable/disable flags */
|
---|
2225 | glAble able[2];
|
---|
2226 | able[0] = diff_api.DisableClientState;
|
---|
2227 | able[1] = diff_api.EnableClientState;
|
---|
2228 | if (from->array.v.enabled != to->array.v.enabled) {
|
---|
2229 | able[to->array.v.enabled](GL_VERTEX_ARRAY);
|
---|
2230 | FILLDIRTY(cb->enableClientState);
|
---|
2231 | FILLDIRTY(cb->dirty);
|
---|
2232 | }
|
---|
2233 | if (from->array.n.enabled != to->array.n.enabled) {
|
---|
2234 | able[to->array.n.enabled](GL_NORMAL_ARRAY);
|
---|
2235 | FILLDIRTY(cb->enableClientState);
|
---|
2236 | FILLDIRTY(cb->dirty);
|
---|
2237 | }
|
---|
2238 | if (from->array.c.enabled != to->array.c.enabled) {
|
---|
2239 | able[to->array.c.enabled](GL_COLOR_ARRAY);
|
---|
2240 | FILLDIRTY(cb->enableClientState);
|
---|
2241 | FILLDIRTY(cb->dirty);
|
---|
2242 | }
|
---|
2243 | if (from->array.i.enabled != to->array.i.enabled) {
|
---|
2244 | able[to->array.i.enabled](GL_INDEX_ARRAY);
|
---|
2245 | FILLDIRTY(cb->enableClientState);
|
---|
2246 | FILLDIRTY(cb->dirty);
|
---|
2247 | }
|
---|
2248 | for (i = 0; (unsigned int)i < toCtx->limits.maxTextureUnits; i++) {
|
---|
2249 | if (from->array.t[i].enabled != to->array.t[i].enabled) {
|
---|
2250 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + i);
|
---|
2251 | curClientTextureUnit = i;
|
---|
2252 | able[to->array.t[i].enabled](GL_TEXTURE_COORD_ARRAY);
|
---|
2253 | FILLDIRTY(cb->enableClientState);
|
---|
2254 | FILLDIRTY(cb->dirty);
|
---|
2255 | }
|
---|
2256 | }
|
---|
2257 | if (from->array.e.enabled != to->array.e.enabled) {
|
---|
2258 | able[to->array.e.enabled](GL_EDGE_FLAG_ARRAY);
|
---|
2259 | FILLDIRTY(cb->enableClientState);
|
---|
2260 | FILLDIRTY(cb->dirty);
|
---|
2261 | }
|
---|
2262 | if (from->array.s.enabled != to->array.s.enabled) {
|
---|
2263 | able[to->array.s.enabled](GL_SECONDARY_COLOR_ARRAY_EXT);
|
---|
2264 | FILLDIRTY(cb->enableClientState);
|
---|
2265 | FILLDIRTY(cb->dirty);
|
---|
2266 | }
|
---|
2267 | if (from->array.f.enabled != to->array.f.enabled) {
|
---|
2268 | able[to->array.f.enabled](GL_FOG_COORDINATE_ARRAY_EXT);
|
---|
2269 | FILLDIRTY(cb->enableClientState);
|
---|
2270 | FILLDIRTY(cb->dirty);
|
---|
2271 | }
|
---|
2272 | for (i = 0; (unsigned int)i < toCtx->limits.maxVertexProgramAttribs; i++) {
|
---|
2273 | if (from->array.a[i].enabled != to->array.a[i].enabled) {
|
---|
2274 | if (to->array.a[i].enabled)
|
---|
2275 | diff_api.EnableVertexAttribArrayARB(i);
|
---|
2276 | else
|
---|
2277 | diff_api.DisableVertexAttribArrayARB(i);
|
---|
2278 | FILLDIRTY(cb->enableClientState);
|
---|
2279 | FILLDIRTY(cb->dirty);
|
---|
2280 | }
|
---|
2281 | }
|
---|
2282 | CLEARDIRTY2(cb->enableClientState, bitID);
|
---|
2283 | }
|
---|
2284 |
|
---|
2285 | if (to->curClientTextureUnit != curClientTextureUnit)
|
---|
2286 | {
|
---|
2287 | diff_api.ClientActiveTextureARB(GL_TEXTURE0_ARB + to->curClientTextureUnit);
|
---|
2288 | }
|
---|
2289 |
|
---|
2290 | if (CHECKDIRTY(cb->unpack, bitID))
|
---|
2291 | {
|
---|
2292 | if (from->unpack.rowLength != to->unpack.rowLength)
|
---|
2293 | {
|
---|
2294 | diff_api.PixelStorei(GL_UNPACK_ROW_LENGTH, to->unpack.rowLength);
|
---|
2295 | FILLDIRTY(cb->unpack);
|
---|
2296 | FILLDIRTY(cb->dirty);
|
---|
2297 | }
|
---|
2298 | if (from->unpack.skipRows != to->unpack.skipRows)
|
---|
2299 | {
|
---|
2300 | diff_api.PixelStorei(GL_UNPACK_SKIP_ROWS, to->unpack.skipRows);
|
---|
2301 | FILLDIRTY(cb->unpack);
|
---|
2302 | FILLDIRTY(cb->dirty);
|
---|
2303 | }
|
---|
2304 | if (from->unpack.skipPixels != to->unpack.skipPixels)
|
---|
2305 | {
|
---|
2306 | diff_api.PixelStorei(GL_UNPACK_SKIP_PIXELS, to->unpack.skipPixels);
|
---|
2307 | FILLDIRTY(cb->unpack);
|
---|
2308 | FILLDIRTY(cb->dirty);
|
---|
2309 | }
|
---|
2310 | if (from->unpack.alignment != to->unpack.alignment)
|
---|
2311 | {
|
---|
2312 | diff_api.PixelStorei(GL_UNPACK_ALIGNMENT, to->unpack.alignment);
|
---|
2313 | FILLDIRTY(cb->unpack);
|
---|
2314 | FILLDIRTY(cb->dirty);
|
---|
2315 | }
|
---|
2316 | if (from->unpack.imageHeight != to->unpack.imageHeight)
|
---|
2317 | {
|
---|
2318 | diff_api.PixelStorei(GL_UNPACK_IMAGE_HEIGHT, to->unpack.imageHeight);
|
---|
2319 | FILLDIRTY(cb->unpack);
|
---|
2320 | FILLDIRTY(cb->dirty);
|
---|
2321 | }
|
---|
2322 | if (from->unpack.skipImages != to->unpack.skipImages)
|
---|
2323 | {
|
---|
2324 | diff_api.PixelStorei(GL_UNPACK_SKIP_IMAGES, to->unpack.skipImages);
|
---|
2325 | FILLDIRTY(cb->unpack);
|
---|
2326 | FILLDIRTY(cb->dirty);
|
---|
2327 | }
|
---|
2328 | if (from->unpack.swapBytes != to->unpack.swapBytes)
|
---|
2329 | {
|
---|
2330 | diff_api.PixelStorei(GL_UNPACK_SWAP_BYTES, to->unpack.swapBytes);
|
---|
2331 | FILLDIRTY(cb->unpack);
|
---|
2332 | FILLDIRTY(cb->dirty);
|
---|
2333 | }
|
---|
2334 | if (from->unpack.psLSBFirst != to->unpack.psLSBFirst)
|
---|
2335 | {
|
---|
2336 | diff_api.PixelStorei(GL_UNPACK_LSB_FIRST, to->unpack.psLSBFirst);
|
---|
2337 | FILLDIRTY(cb->unpack);
|
---|
2338 | FILLDIRTY(cb->dirty);
|
---|
2339 | }
|
---|
2340 | CLEARDIRTY2(cb->unpack, bitID);
|
---|
2341 | }
|
---|
2342 |
|
---|
2343 | if (CHECKDIRTY(cb->pack, bitID))
|
---|
2344 | {
|
---|
2345 | if (from->pack.rowLength != to->pack.rowLength)
|
---|
2346 | {
|
---|
2347 | diff_api.PixelStorei(GL_PACK_ROW_LENGTH, to->pack.rowLength);
|
---|
2348 | FILLDIRTY(cb->pack);
|
---|
2349 | FILLDIRTY(cb->dirty);
|
---|
2350 | }
|
---|
2351 | if (from->pack.skipRows != to->pack.skipRows)
|
---|
2352 | {
|
---|
2353 | diff_api.PixelStorei(GL_PACK_SKIP_ROWS, to->pack.skipRows);
|
---|
2354 | FILLDIRTY(cb->pack);
|
---|
2355 | FILLDIRTY(cb->dirty);
|
---|
2356 | }
|
---|
2357 | if (from->pack.skipPixels != to->pack.skipPixels)
|
---|
2358 | {
|
---|
2359 | diff_api.PixelStorei(GL_PACK_SKIP_PIXELS, to->pack.skipPixels);
|
---|
2360 | FILLDIRTY(cb->pack);
|
---|
2361 | FILLDIRTY(cb->dirty);
|
---|
2362 | }
|
---|
2363 | if (from->pack.alignment != to->pack.alignment)
|
---|
2364 | {
|
---|
2365 | diff_api.PixelStorei(GL_PACK_ALIGNMENT, to->pack.alignment);
|
---|
2366 | FILLDIRTY(cb->pack);
|
---|
2367 | FILLDIRTY(cb->dirty);
|
---|
2368 | }
|
---|
2369 | if (from->pack.imageHeight != to->pack.imageHeight)
|
---|
2370 | {
|
---|
2371 | diff_api.PixelStorei(GL_PACK_IMAGE_HEIGHT, to->pack.imageHeight);
|
---|
2372 | FILLDIRTY(cb->pack);
|
---|
2373 | FILLDIRTY(cb->dirty);
|
---|
2374 | }
|
---|
2375 | if (from->pack.skipImages != to->pack.skipImages)
|
---|
2376 | {
|
---|
2377 | diff_api.PixelStorei(GL_PACK_SKIP_IMAGES, to->pack.skipImages);
|
---|
2378 | FILLDIRTY(cb->pack);
|
---|
2379 | FILLDIRTY(cb->dirty);
|
---|
2380 | }
|
---|
2381 | if (from->pack.swapBytes != to->pack.swapBytes)
|
---|
2382 | {
|
---|
2383 | diff_api.PixelStorei(GL_PACK_SWAP_BYTES, to->pack.swapBytes);
|
---|
2384 | FILLDIRTY(cb->pack);
|
---|
2385 | FILLDIRTY(cb->dirty);
|
---|
2386 | }
|
---|
2387 | if (from->pack.psLSBFirst != to->pack.psLSBFirst)
|
---|
2388 | {
|
---|
2389 | diff_api.PixelStorei(GL_PACK_LSB_FIRST, to->pack.psLSBFirst);
|
---|
2390 | FILLDIRTY(cb->pack);
|
---|
2391 | FILLDIRTY(cb->dirty);
|
---|
2392 | }
|
---|
2393 | CLEARDIRTY2(cb->pack, bitID);
|
---|
2394 | }
|
---|
2395 |
|
---|
2396 | CLEARDIRTY2(cb->dirty, bitID);
|
---|
2397 | }
|
---|
2398 |
|
---|
2399 | CRClientPointer* crStateGetClientPointerByIndex(int index, CRVertexArrays *array)
|
---|
2400 | {
|
---|
2401 | CRASSERT(array && index>=0 && index<CRSTATECLIENT_MAX_VERTEXARRAYS);
|
---|
2402 |
|
---|
2403 | if (array == NULL || index < 0 || index >= CRSTATECLIENT_MAX_VERTEXARRAYS)
|
---|
2404 | {
|
---|
2405 | return NULL;
|
---|
2406 | }
|
---|
2407 |
|
---|
2408 | if (index < 7)
|
---|
2409 | {
|
---|
2410 | switch (index)
|
---|
2411 | {
|
---|
2412 | case 0: return &array->v;
|
---|
2413 | case 1: return &array->c;
|
---|
2414 | case 2: return &array->f;
|
---|
2415 | case 3: return &array->s;
|
---|
2416 | case 4: return &array->e;
|
---|
2417 | case 5: return &array->i;
|
---|
2418 | case 6: return &array->n;
|
---|
2419 | }
|
---|
2420 | }
|
---|
2421 | else if (index<(7+CR_MAX_TEXTURE_UNITS))
|
---|
2422 | {
|
---|
2423 | return &array->t[index-7];
|
---|
2424 | }
|
---|
2425 | else
|
---|
2426 | {
|
---|
2427 | return &array->a[index-7-CR_MAX_TEXTURE_UNITS];
|
---|
2428 | }
|
---|
2429 |
|
---|
2430 | /*silence the compiler warning*/
|
---|
2431 | CRASSERT(false);
|
---|
2432 | return NULL;
|
---|
2433 | }
|
---|