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