VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_evaluators.c@ 78493

Last change on this file since 78493 was 78375, checked in by vboxsync, 6 years ago

Additions/common/crOpengl,GuestHost/OpenGL,HostServices/SharedOpenGL: Eliminate all global variables from the state tracker library (state_tracker) in preparation of the SPU DLL merging, bugref:9435

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 29.5 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7/*
8 * The majority of this file is pulled from Mesa 4.0.x with the
9 * permission of Brian Paul
10 */
11
12#include <stdio.h>
13#include "cr_mem.h"
14#include "state.h"
15#include "state/cr_statetypes.h"
16#include "state_internals.h"
17
18/* free the 1-D evaluator map */
19static void
20free_1d_map(CRContext *ctx, GLenum map)
21{
22 CREvaluatorState *e = &ctx->eval;
23 const GLint k = map - GL_MAP1_COLOR_4;
24
25 crFree( e->eval1D[k].coeff );
26}
27
28/* free the 2-D evaluator map */
29static void
30free_2d_map(CRContext *ctx, GLenum map)
31{
32 CREvaluatorState *e = &ctx->eval;
33 const GLint k = map - GL_MAP2_COLOR_4;
34
35 crFree( e->eval2D[k].coeff );
36}
37
38/* Initialize a 1-D evaluator map */
39static void
40init_1d_map(CRContext *ctx, GLenum map, int n, const float *initial)
41{
42 CREvaluatorState *e = &ctx->eval;
43 CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
44 CREvaluatorBits *eb = &(sb->eval);
45 GLint i;
46 const GLint k = map - GL_MAP1_COLOR_4;
47 CRASSERT(k >= 0);
48 CRASSERT(k < GLEVAL_TOT);
49 e->eval1D[k].u1 = 0.0;
50 e->eval1D[k].u2 = 1.0;
51 e->eval1D[k].du = 0.0;
52 e->eval1D[k].order = 1;
53 e->eval1D[k].coeff = (GLfloat *) crAlloc(n * sizeof(GLfloat));
54 for (i = 0; i < n; i++)
55 e->eval1D[k].coeff[i] = initial[i];
56 RESET(eb->eval1D[i], ctx->bitid);
57}
58
59
60/* Initialize a 2-D evaluator map */
61static void
62init_2d_map(CRContext *ctx, GLenum map, int n, const float *initial)
63{
64 CREvaluatorState *e = &ctx->eval;
65 CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
66 CREvaluatorBits *eb = &(sb->eval);
67 GLint i;
68 const GLint k = map - GL_MAP2_COLOR_4;
69 CRASSERT(k >= 0);
70 CRASSERT(k < GLEVAL_TOT);
71 e->eval2D[k].u1 = 0.0;
72 e->eval2D[k].u2 = 1.0;
73 e->eval2D[k].du = 0.0;
74 e->eval2D[k].v1 = 0.0;
75 e->eval2D[k].v2 = 1.0;
76 e->eval2D[k].dv = 0.0;
77 e->eval2D[k].uorder = 1;
78 e->eval2D[k].vorder = 1;
79 e->eval2D[k].coeff = (GLfloat *) crAlloc(n * sizeof(GLfloat));
80 for (i = 0; i < n; i++)
81 e->eval2D[k].coeff[i] = initial[i];
82 RESET(eb->eval2D[i], ctx->bitid);
83}
84
85void
86crStateEvaluatorDestroy(CRContext *ctx)
87{
88 free_1d_map(ctx, GL_MAP1_VERTEX_3);
89 free_1d_map(ctx, GL_MAP1_VERTEX_4);
90 free_1d_map(ctx, GL_MAP1_INDEX);
91 free_1d_map(ctx, GL_MAP1_COLOR_4);
92 free_1d_map(ctx, GL_MAP1_NORMAL);
93 free_1d_map(ctx, GL_MAP1_TEXTURE_COORD_1);
94 free_1d_map(ctx, GL_MAP1_TEXTURE_COORD_2);
95 free_1d_map(ctx, GL_MAP1_TEXTURE_COORD_3);
96 free_1d_map(ctx, GL_MAP1_TEXTURE_COORD_4);
97
98 free_2d_map(ctx, GL_MAP2_VERTEX_3);
99 free_2d_map(ctx, GL_MAP2_VERTEX_4);
100 free_2d_map(ctx, GL_MAP2_INDEX);
101 free_2d_map(ctx, GL_MAP2_COLOR_4);
102 free_2d_map(ctx, GL_MAP2_NORMAL);
103 free_2d_map(ctx, GL_MAP2_TEXTURE_COORD_1);
104 free_2d_map(ctx, GL_MAP2_TEXTURE_COORD_2);
105 free_2d_map(ctx, GL_MAP2_TEXTURE_COORD_3);
106 free_2d_map(ctx, GL_MAP2_TEXTURE_COORD_4);
107}
108
109void
110crStateEvaluatorInit(CRContext *ctx)
111{
112 CREvaluatorState *e = &ctx->eval;
113 CRStateBits *sb = GetCurrentBits(ctx->pStateTracker);
114 CREvaluatorBits *eb = &(sb->eval);
115 static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
116 static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
117 static GLfloat index[1] = { 1.0 };
118 static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
119 static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
120
121 e->autoNormal = GL_FALSE;
122 RESET(eb->enable, ctx->bitid);
123
124 init_1d_map(ctx, GL_MAP1_VERTEX_3, 3, vertex);
125 init_1d_map(ctx, GL_MAP1_VERTEX_4, 4, vertex);
126 init_1d_map(ctx, GL_MAP1_INDEX, 1, index);
127 init_1d_map(ctx, GL_MAP1_COLOR_4, 4, color);
128 init_1d_map(ctx, GL_MAP1_NORMAL, 3, normal);
129 init_1d_map(ctx, GL_MAP1_TEXTURE_COORD_1, 1, texcoord);
130 init_1d_map(ctx, GL_MAP1_TEXTURE_COORD_2, 2, texcoord);
131 init_1d_map(ctx, GL_MAP1_TEXTURE_COORD_3, 3, texcoord);
132 init_1d_map(ctx, GL_MAP1_TEXTURE_COORD_4, 4, texcoord);
133
134 init_2d_map(ctx, GL_MAP2_VERTEX_3, 3, vertex);
135 init_2d_map(ctx, GL_MAP2_VERTEX_4, 4, vertex);
136 init_2d_map(ctx, GL_MAP2_INDEX, 1, index);
137 init_2d_map(ctx, GL_MAP2_COLOR_4, 4, color);
138 init_2d_map(ctx, GL_MAP2_NORMAL, 3, normal);
139 init_2d_map(ctx, GL_MAP2_TEXTURE_COORD_1, 1, texcoord);
140 init_2d_map(ctx, GL_MAP2_TEXTURE_COORD_2, 2, texcoord);
141 init_2d_map(ctx, GL_MAP2_TEXTURE_COORD_3, 3, texcoord);
142 init_2d_map(ctx, GL_MAP2_TEXTURE_COORD_4, 4, texcoord);
143
144 e->un1D = 1;
145 e->u11D = 0.0;
146 e->u21D = 1.0;
147 RESET(eb->grid1D, ctx->bitid);
148
149 e->un2D = 1;
150 e->vn2D = 1;
151 e->u12D = 0.0;
152 e->u22D = 1.0;
153 e->v12D = 0.0;
154 e->v22D = 1.0;
155 RESET(eb->grid1D, ctx->bitid);
156
157 RESET(eb->dirty, ctx->bitid);
158}
159
160const int gleval_sizes[] = { 4, 1, 3, 1, 2, 3, 4, 3, 4 };
161
162/**********************************************************************/
163/*** Copy and deallocate control points ***/
164/**********************************************************************/
165
166
167/*
168 * Copy 1-parametric evaluator control points from user-specified
169 * memory space to a buffer of contiguous control points.
170 * Input: see glMap1f for details
171 * Return: pointer to buffer of contiguous control points or NULL if out
172 * of memory.
173 */
174static GLfloat *
175_copy_map_points1f(GLint size, GLint ustride, GLint uorder,
176 const GLfloat * points)
177{
178 GLfloat *buffer, *p;
179 GLint i, k;
180
181 if (!points || size == 0) {
182 return NULL;
183 }
184
185 buffer = (GLfloat *) crAlloc(uorder * size * sizeof(GLfloat));
186
187 if (buffer)
188 for (i = 0, p = buffer; i < uorder; i++, points += ustride)
189 for (k = 0; k < size; k++)
190 *p++ = points[k];
191
192 return buffer;
193}
194
195
196
197/*
198 * Same as above but convert doubles to floats.
199 */
200static GLfloat *
201_copy_map_points1d(GLint size, GLint ustride, GLint uorder,
202 const GLdouble * points)
203{
204 GLfloat *buffer, *p;
205 GLint i, k;
206
207 if (!points || size == 0) {
208 return NULL;
209 }
210
211 buffer = (GLfloat *) crAlloc(uorder * size * sizeof(GLfloat));
212
213 if (buffer)
214 for (i = 0, p = buffer; i < uorder; i++, points += ustride)
215 for (k = 0; k < size; k++)
216 *p++ = (GLfloat) points[k];
217
218 return buffer;
219}
220
221
222
223/*
224 * Copy 2-parametric evaluator control points from user-specified
225 * memory space to a buffer of contiguous control points.
226 * Additional memory is allocated to be used by the Horner and
227 * de Casteljau evaluation schemes.
228 *
229 * Input: see glMap2f for details
230 * Return: pointer to buffer of contiguous control points or NULL if out
231 * of memory.
232 */
233static GLfloat *
234_copy_map_points2f(GLint size,
235 GLint ustride, GLint uorder,
236 GLint vstride, GLint vorder, const GLfloat * points)
237{
238 GLfloat *buffer, *p;
239 GLint i, j, k, dsize, hsize;
240 GLint uinc;
241
242 if (!points || size == 0) {
243 return NULL;
244 }
245
246 /* max(uorder, vorder) additional points are used in */
247 /* Horner evaluation and uorder*vorder additional */
248 /* values are needed for de Casteljau */
249 dsize = (uorder == 2 && vorder == 2) ? 0 : uorder * vorder;
250 hsize = (uorder > vorder ? uorder : vorder) * size;
251
252 if (hsize > dsize)
253 buffer =
254 (GLfloat *) crAlloc((uorder * vorder * size + hsize) * sizeof(GLfloat));
255 else
256 buffer =
257 (GLfloat *) crAlloc((uorder * vorder * size + dsize) * sizeof(GLfloat));
258
259 /* compute the increment value for the u-loop */
260 uinc = ustride - vorder * vstride;
261
262 if (buffer)
263 for (i = 0, p = buffer; i < uorder; i++, points += uinc)
264 for (j = 0; j < vorder; j++, points += vstride)
265 for (k = 0; k < size; k++)
266 *p++ = points[k];
267
268 return buffer;
269}
270
271
272
273/*
274 * Same as above but convert doubles to floats.
275 */
276static GLfloat *
277_copy_map_points2d(GLint size,
278 GLint ustride, GLint uorder,
279 GLint vstride, GLint vorder, const GLdouble * points)
280{
281 GLfloat *buffer, *p;
282 GLint i, j, k, hsize, dsize;
283 GLint uinc;
284
285 if (!points || size == 0) {
286 return NULL;
287 }
288
289 /* max(uorder, vorder) additional points are used in */
290 /* Horner evaluation and uorder*vorder additional */
291 /* values are needed for de Casteljau */
292 dsize = (uorder == 2 && vorder == 2) ? 0 : uorder * vorder;
293 hsize = (uorder > vorder ? uorder : vorder) * size;
294
295 if (hsize > dsize)
296 buffer =
297 (GLfloat *) crAlloc((uorder * vorder * size + hsize) * sizeof(GLfloat));
298 else
299 buffer =
300 (GLfloat *) crAlloc((uorder * vorder * size + dsize) * sizeof(GLfloat));
301
302 /* compute the increment value for the u-loop */
303 uinc = ustride - vorder * vstride;
304
305 if (buffer)
306 for (i = 0, p = buffer; i < uorder; i++, points += uinc)
307 for (j = 0; j < vorder; j++, points += vstride)
308 for (k = 0; k < size; k++)
309 *p++ = (GLfloat) points[k];
310
311 return buffer;
312}
313
314
315
316
317/**********************************************************************/
318/*** API entry points ***/
319/**********************************************************************/
320
321
322/*
323 * This does the work of glMap1[fd].
324 */
325static void
326map1(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
327 GLint uorder, const GLvoid * points, GLenum type)
328{
329 CRContext *g = GetCurrentContext(pState);
330 CREvaluatorState *e = &(g->eval);
331 CRStateBits *sb = GetCurrentBits(pState);
332 CREvaluatorBits *eb = &(sb->eval);
333 CRTextureState *t = &(g->texture);
334 GLint i;
335 GLint k;
336 GLfloat *pnts;
337
338 if (g->current.inBeginEnd) {
339 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
340 "Map1d called in begin/end");
341 return;
342 }
343
344 FLUSH();
345
346 CRASSERT(type == GL_FLOAT || type == GL_DOUBLE);
347
348 if (u1 == u2) {
349 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(u1==u2)");
350 return;
351 }
352 if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
353 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad uorder)");
354 return;
355 }
356 if (!points) {
357 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE,
358 "glMap1d(null points)");
359 return;
360 }
361
362 switch (target) {
363 case GL_MAP1_VERTEX_3:
364 case GL_MAP1_VERTEX_4:
365 case GL_MAP1_INDEX:
366 case GL_MAP1_COLOR_4:
367 case GL_MAP1_NORMAL:
368 case GL_MAP1_TEXTURE_COORD_1:
369 case GL_MAP1_TEXTURE_COORD_2:
370 case GL_MAP1_TEXTURE_COORD_3:
371 case GL_MAP1_TEXTURE_COORD_4:
372 break;
373 default:
374 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(bad target)");
375 return;
376 }
377
378 i = target - GL_MAP1_COLOR_4;
379
380 k = gleval_sizes[i];
381
382 if (k == 0) {
383 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(k=0)");
384 return;
385 }
386
387 if (ustride < k) {
388 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad ustride");
389 return;
390 }
391
392 if (t->curTextureUnit != 0) {
393 /* See OpenGL 1.2.1 spec, section F.2.13 */
394 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
395 "glMap1d(current texture unit must be zero)");
396 return;
397 }
398
399 /* make copy of the control points */
400 if (type == GL_FLOAT)
401 pnts = _copy_map_points1f(k, ustride, uorder, (GLfloat *) points);
402 else
403 pnts = _copy_map_points1d(k, ustride, uorder, (GLdouble *) points);
404
405 e->eval1D[i].order = uorder;
406 e->eval1D[i].u1 = u1;
407 e->eval1D[i].u2 = u2;
408 e->eval1D[i].du = 1.0f / (u2 - u1);
409 if (e->eval1D[i].coeff)
410 crFree(e->eval1D[i].coeff);
411 e->eval1D[i].coeff = pnts;
412
413 DIRTY(eb->dirty, g->neg_bitid);
414 DIRTY(eb->eval1D[i], g->neg_bitid);
415}
416
417
418
419void STATE_APIENTRY
420crStateMap1f(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2,
421 GLint stride, GLint order, const GLfloat * points)
422{
423 map1(pState, target, u1, u2, stride, order, points, GL_FLOAT);
424}
425
426void STATE_APIENTRY
427crStateMap1d(PCRStateTracker pState, GLenum target, GLdouble u1, GLdouble u2, GLint stride,
428 GLint order, const GLdouble * points)
429{
430 map1(pState, target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
431}
432
433static void
434map2(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
435 GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
436 const GLvoid * points, GLenum type)
437{
438 CRContext *g = GetCurrentContext(pState);
439 CRStateBits *sb = GetCurrentBits(pState);
440 CREvaluatorState *e = &(g->eval);
441 CREvaluatorBits *eb = &(sb->eval);
442#if 0
443 CRTextureState *t = &(g->texture);
444#endif
445 GLint i;
446 GLint k;
447 GLfloat *pnts;
448
449 if (g->current.inBeginEnd) {
450 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
451 return;
452 }
453
454 FLUSH();
455
456 if (u1 == u2) {
457 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
458 return;
459 }
460
461 if (v1 == v2) {
462 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
463 return;
464 }
465
466 if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
467 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
468 return;
469 }
470
471 if (vorder < 1 || vorder > MAX_EVAL_ORDER) {
472 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
473 return;
474 }
475
476 switch (target) {
477 case GL_MAP2_VERTEX_3:
478 case GL_MAP2_VERTEX_4:
479 case GL_MAP2_INDEX:
480 case GL_MAP2_COLOR_4:
481 case GL_MAP2_NORMAL:
482 case GL_MAP2_TEXTURE_COORD_1:
483 case GL_MAP2_TEXTURE_COORD_2:
484 case GL_MAP2_TEXTURE_COORD_3:
485 case GL_MAP2_TEXTURE_COORD_4:
486 break;
487 default:
488 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
489 return;
490 }
491
492 if (g->extensions.NV_vertex_program) {
493/* XXX FIXME */
494 i = target - GL_MAP2_COLOR_4;
495 } else {
496 i = target - GL_MAP2_COLOR_4;
497 }
498
499 k = gleval_sizes[i];
500
501 if (k == 0) {
502 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
503 return;
504 }
505
506 if (ustride < k) {
507 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
508 return;
509 }
510 if (vstride < k) {
511 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
512 return;
513 }
514
515#if 00
516 /* Disable this check for now - it looks like various OpenGL drivers
517 * don't do this error check. So, a bunch of the NVIDIA demos
518 * generate errors/warnings.
519 */
520 if (t->curTextureUnit != 0) {
521 /* See OpenGL 1.2.1 spec, section F.2.13 */
522 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
523 return;
524 }
525#endif
526
527 /* make copy of the control points */
528 if (type == GL_FLOAT)
529 pnts = _copy_map_points2f(k, ustride, uorder,
530 vstride, vorder, (GLfloat *) points);
531 else
532 pnts = _copy_map_points2d(k, ustride, uorder,
533 vstride, vorder, (GLdouble *) points);
534
535 e->eval2D[i].uorder = uorder;
536 e->eval2D[i].u1 = u1;
537 e->eval2D[i].u2 = u2;
538 e->eval2D[i].du = 1.0f / (u2 - u1);
539 e->eval2D[i].vorder = vorder;
540 e->eval2D[i].v1 = v1;
541 e->eval2D[i].v2 = v2;
542 e->eval2D[i].dv = 1.0f / (v2 - v1);
543 if (e->eval2D[i].coeff)
544 crFree(e->eval2D[i].coeff);
545 e->eval2D[i].coeff = pnts;
546
547 DIRTY(eb->dirty, g->neg_bitid);
548 DIRTY(eb->eval2D[i], g->neg_bitid);
549}
550
551void STATE_APIENTRY
552crStateMap2f(PCRStateTracker pState, GLenum target, GLfloat u1, GLfloat u2,
553 GLint ustride, GLint uorder,
554 GLfloat v1, GLfloat v2,
555 GLint vstride, GLint vorder, const GLfloat * points)
556{
557 map2(pState, target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points, GL_FLOAT);
558}
559
560
561void STATE_APIENTRY
562crStateMap2d(PCRStateTracker pState, GLenum target, GLdouble u1, GLdouble u2,
563 GLint ustride, GLint uorder,
564 GLdouble v1, GLdouble v2,
565 GLint vstride, GLint vorder, const GLdouble * points)
566{
567 map2(pState, target, (GLfloat) u1, (GLfloat) u2, ustride, uorder, (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
568}
569
570void STATE_APIENTRY
571crStateGetMapdv(PCRStateTracker pState, GLenum target, GLenum query, GLdouble * v)
572{
573 CRContext *g = GetCurrentContext(pState);
574 CRStateBits *sb = GetCurrentBits(pState);
575 CREvaluatorState *e = &(g->eval);
576 GLint size;
577 GLint i, j;
578 (void) sb;
579
580 if (g->current.inBeginEnd) {
581 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
582 "Map1d called in begin/end");
583 return;
584 }
585
586 FLUSH();
587
588 i = target - GL_MAP1_COLOR_4;
589
590 if (i < 0 || i >= GLEVAL_TOT) {
591 i = target - GL_MAP2_COLOR_4;
592
593 if (i < 0 || i >= GLEVAL_TOT) {
594 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
595 "GetMapdv: invalid target: %d", target);
596 return;
597 }
598
599 switch (query) {
600 case GL_COEFF:
601 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
602 for (j = 0; j < size; j++) {
603 v[j] = e->eval2D[i].coeff[j];
604 }
605 break;
606 case GL_ORDER:
607 v[0] = (GLdouble) e->eval2D[i].uorder;
608 v[1] = (GLdouble) e->eval2D[i].vorder;
609 break;
610 case GL_DOMAIN:
611 v[0] = e->eval2D[i].u1;
612 v[1] = e->eval2D[i].u2;
613 v[2] = e->eval2D[i].v1;
614 v[3] = e->eval2D[i].v2;
615 break;
616 default:
617 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
618 "GetMapdv: invalid target: %d", target);
619 return;
620 }
621 }
622 else {
623 switch (query) {
624 case GL_COEFF:
625 size = gleval_sizes[i] * e->eval1D[i].order;
626 for (j = 0; j < size; j++) {
627 v[j] = e->eval1D[i].coeff[j];
628 }
629 break;
630 case GL_ORDER:
631 *v = (GLdouble) e->eval1D[i].order;
632 break;
633 case GL_DOMAIN:
634 v[0] = e->eval1D[i].u1;
635 v[1] = e->eval1D[i].u2;
636 break;
637 default:
638 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
639 "GetMapdv: invalid target: %d", target);
640 return;
641 }
642 }
643}
644
645void STATE_APIENTRY
646crStateGetMapfv(PCRStateTracker pState, GLenum target, GLenum query, GLfloat * v)
647{
648 CRContext *g = GetCurrentContext(pState);
649 CRStateBits *sb = GetCurrentBits(pState);
650 CREvaluatorState *e = &(g->eval);
651 GLint size;
652 GLint i, j;
653 (void) sb;
654
655 if (g->current.inBeginEnd) {
656 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
657 "Map1d called in begin/end");
658 return;
659 }
660
661 FLUSH();
662
663 i = target - GL_MAP1_COLOR_4;
664 if (i < 0 || i >= GLEVAL_TOT) {
665 i = target - GL_MAP2_COLOR_4;
666 if (i < 0 || i >= GLEVAL_TOT) {
667 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
668 "GetMapfv: invalid target: %d", target);
669 return;
670 }
671 switch (query) {
672 case GL_COEFF:
673 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
674 for (j = 0; j < size; j++) {
675 v[j] = (GLfloat) e->eval2D[i].coeff[j];
676 }
677 break;
678 case GL_ORDER:
679 v[0] = (GLfloat) e->eval2D[i].uorder;
680 v[1] = (GLfloat) e->eval2D[i].vorder;
681 break;
682 case GL_DOMAIN:
683 v[0] = (GLfloat) e->eval2D[i].u1;
684 v[1] = (GLfloat) e->eval2D[i].u2;
685 v[2] = (GLfloat) e->eval2D[i].v1;
686 v[3] = (GLfloat) e->eval2D[i].v2;
687 break;
688 default:
689 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
690 "GetMapfv: invalid target: %d", target);
691 return;
692 }
693 }
694 else {
695 switch (query) {
696 case GL_COEFF:
697 size = gleval_sizes[i] * e->eval1D[i].order;
698 for (j = 0; j < size; j++) {
699 v[j] = (GLfloat) e->eval1D[i].coeff[j];
700 }
701 break;
702 case GL_ORDER:
703 *v = (GLfloat) e->eval1D[i].order;
704 break;
705 case GL_DOMAIN:
706 v[0] = (GLfloat) e->eval1D[i].u1;
707 v[1] = (GLfloat) e->eval1D[i].u2;
708 break;
709 default:
710 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
711 "GetMapfv: invalid target: %d", target);
712 return;
713 }
714 }
715}
716
717void STATE_APIENTRY
718crStateGetMapiv(PCRStateTracker pState, GLenum target, GLenum query, GLint * v)
719{
720 CRContext *g = GetCurrentContext(pState);
721 CRStateBits *sb = GetCurrentBits(pState);
722 CREvaluatorState *e = &(g->eval);
723 GLint size;
724 GLint i, j;
725 (void) sb;
726
727 if (g->current.inBeginEnd) {
728 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
729 "Map1d called in begin/end");
730 return;
731 }
732
733 FLUSH();
734
735 i = target - GL_MAP1_COLOR_4;
736 if (i < 0 || i >= GLEVAL_TOT) {
737 i = target - GL_MAP2_COLOR_4;
738 if (i < 0 || i >= GLEVAL_TOT) {
739 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
740 "GetMapiv: invalid target: %d", target);
741 return;
742 }
743 switch (query) {
744 case GL_COEFF:
745 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
746 for (j = 0; j < size; j++) {
747 v[j] = (GLint) e->eval2D[i].coeff[j];
748 }
749 break;
750 case GL_ORDER:
751 v[0] = e->eval2D[i].uorder;
752 v[1] = e->eval2D[i].vorder;
753 break;
754 case GL_DOMAIN:
755 v[0] = (GLint) e->eval2D[i].u1;
756 v[1] = (GLint) e->eval2D[i].u2;
757 v[2] = (GLint) e->eval2D[i].v1;
758 v[3] = (GLint) e->eval2D[i].v2;
759 break;
760 default:
761 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
762 "GetMapiv: invalid target: %d", target);
763 return;
764 }
765 }
766 else {
767 switch (query) {
768 case GL_COEFF:
769 size = gleval_sizes[i] * e->eval1D[i].order;
770 for (j = 0; j < size; j++) {
771 v[j] = (GLint) e->eval1D[i].coeff[j];
772 }
773 break;
774 case GL_ORDER:
775 *v = e->eval1D[i].order;
776 break;
777 case GL_DOMAIN:
778 v[0] = (GLint) e->eval1D[i].u1;
779 v[1] = (GLint) e->eval1D[i].u2;
780 break;
781 default:
782 crStateError(pState, __LINE__, __FILE__, GL_INVALID_ENUM,
783 "GetMapiv: invalid target: %d", target);
784 return;
785 }
786 }
787}
788
789void STATE_APIENTRY
790crStateMapGrid1f(PCRStateTracker pState, GLint un, GLfloat u1, GLfloat u2)
791{
792 CRContext *g = GetCurrentContext(pState);
793 CRStateBits *sb = GetCurrentBits(pState);
794 CREvaluatorState *e = &(g->eval);
795 CREvaluatorBits *eb = &(sb->eval);
796
797 if (g->current.inBeginEnd) {
798 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
799 "Map1d called in begin/end");
800 return;
801 }
802
803 FLUSH();
804
805 if (un < 1) {
806 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid1f(bad un)");
807 return;
808 }
809
810 e->un1D = un;
811 e->u11D = u1;
812 e->u21D = u2;
813
814 DIRTY(eb->dirty, g->neg_bitid);
815 DIRTY(eb->grid1D, g->neg_bitid);
816}
817
818void STATE_APIENTRY
819crStateMapGrid1d(PCRStateTracker pState, GLint un, GLdouble u1, GLdouble u2)
820{
821 crStateMapGrid1f(pState, un, (GLfloat) u1, (GLfloat) u2);
822}
823
824
825void STATE_APIENTRY
826crStateMapGrid2f(PCRStateTracker pState, GLint un, GLfloat u1, GLfloat u2,
827 GLint vn, GLfloat v1, GLfloat v2)
828{
829 CRContext *g = GetCurrentContext(pState);
830 CRStateBits *sb = GetCurrentBits(pState);
831 CREvaluatorState *e = &(g->eval);
832 CREvaluatorBits *eb = &(sb->eval);
833
834 if (g->current.inBeginEnd) {
835 crStateError(pState, __LINE__, __FILE__, GL_INVALID_OPERATION,
836 "Map1d called in begin/end");
837 return;
838 }
839
840 FLUSH();
841
842 if (un < 1) {
843 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad un)");
844 return;
845 }
846 if (vn < 1) {
847 crStateError(pState, __LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad vn)");
848 return;
849 }
850
851 e->un2D = un;
852 e->vn2D = vn;
853 e->u12D = u1;
854 e->u22D = u2;
855 e->v12D = v1;
856 e->v22D = v2;
857
858 DIRTY(eb->dirty, g->neg_bitid);
859 DIRTY(eb->grid2D, g->neg_bitid);
860}
861
862void STATE_APIENTRY
863crStateMapGrid2d(PCRStateTracker pState, GLint un, GLdouble u1, GLdouble u2,
864 GLint vn, GLdouble v1, GLdouble v2)
865{
866 crStateMapGrid2f(pState, un, (GLfloat) u1, (GLfloat) u2,
867 vn, (GLfloat) v1, (GLfloat) v2);
868}
869
870void
871crStateEvaluatorSwitch(CREvaluatorBits *e, CRbitvalue * bitID,
872 CRContext *fromCtx, CRContext *toCtx)
873{
874 PCRStateTracker pState = fromCtx->pStateTracker;
875 CREvaluatorState *from = &(fromCtx->eval);
876 CREvaluatorState *to = &(toCtx->eval);
877 int i, j;
878 CRbitvalue nbitID[CR_MAX_BITARRAY];
879
880 CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
881
882 for (j = 0; j < CR_MAX_BITARRAY; j++)
883 nbitID[j] = ~bitID[j];
884
885 if (CHECKDIRTY(e->enable, bitID)) {
886 if (from->autoNormal != to->autoNormal) {
887 glAble able[2];
888 able[0] = pState->diff_api.Disable;
889 able[1] = pState->diff_api.Enable;
890 able[to->autoNormal] (GL_AUTO_NORMAL);
891 FILLDIRTY(e->enable);
892 FILLDIRTY(e->dirty);
893 }
894 CLEARDIRTY(e->enable, nbitID);
895 }
896 for (i = 0; i < GLEVAL_TOT; i++) {
897 if (CHECKDIRTY(e->eval1D[i], bitID)) {
898 int size = from->eval1D[i].order * gleval_sizes[i] *
899 sizeof(*from->eval1D[i].coeff);
900 if (from->eval1D[i].order != to->eval1D[i].order ||
901 from->eval1D[i].u1 != to->eval1D[i].u1 ||
902 from->eval1D[i].u2 != to->eval1D[i].u2 ||
903 crMemcmp((const void *) from->eval1D[i].coeff,
904 (const void *) to->eval1D[i].coeff, size)) {
905 pState->diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
906 to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
907 to->eval1D[i].coeff);
908 FILLDIRTY(e->dirty);
909 FILLDIRTY(e->eval1D[i]);
910 }
911 CLEARDIRTY(e->eval1D[i], nbitID);
912 }
913 }
914
915 for (i = 0; i < GLEVAL_TOT; i++) {
916 if (CHECKDIRTY(e->eval2D[i], bitID)) {
917 int size = from->eval2D[i].uorder * from->eval2D[i].vorder
918 * gleval_sizes[i] * sizeof(*from->eval2D[i].coeff);
919 if (from->eval2D[i].uorder != to->eval2D[i].uorder ||
920 from->eval2D[i].vorder != to->eval2D[i].vorder ||
921 from->eval2D[i].u1 != to->eval2D[i].u1 ||
922 from->eval2D[i].u2 != to->eval2D[i].u2 ||
923 from->eval2D[i].v1 != to->eval2D[i].v1 ||
924 from->eval2D[i].v2 != to->eval2D[i].v2 ||
925 crMemcmp((const void *) from->eval2D[i].coeff,
926 (const void *) to->eval2D[i].coeff, size)) {
927 pState->diff_api.Map2f(i + GL_MAP2_COLOR_4,
928 to->eval2D[i].u1, to->eval2D[i].u2,
929 gleval_sizes[i], to->eval2D[i].uorder,
930 to->eval2D[i].v1, to->eval2D[i].v2,
931 gleval_sizes[i], to->eval2D[i].vorder,
932 to->eval2D[i].coeff);
933 FILLDIRTY(e->dirty);
934 FILLDIRTY(e->eval2D[i]);
935 }
936 CLEARDIRTY(e->eval2D[i], nbitID);
937 }
938 }
939 if (CHECKDIRTY(e->grid1D, bitID)) {
940 if (from->u11D != to->u11D ||
941 from->u21D != to->u21D ||
942 from->un1D != to->un1D) {
943 pState->diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
944 FILLDIRTY(e->dirty);
945 FILLDIRTY(e->grid1D);
946 }
947 CLEARDIRTY(e->grid1D, nbitID);
948 }
949 if (CHECKDIRTY(e->grid2D, bitID)) {
950 if (from->u12D != to->u12D ||
951 from->u22D != to->u22D ||
952 from->un2D != to->un2D ||
953 from->v12D != to->v12D ||
954 from->v22D != to->v22D ||
955 from->vn2D != to->vn2D) {
956 pState->diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
957 to->vn2D, to->v12D, to->v22D);
958 FILLDIRTY(e->dirty);
959 FILLDIRTY(e->grid1D);
960 }
961 CLEARDIRTY(e->grid1D, nbitID);
962 }
963 CLEARDIRTY(e->dirty, nbitID);
964}
965
966void
967crStateEvaluatorDiff(CREvaluatorBits *e, CRbitvalue *bitID,
968 CRContext *fromCtx, CRContext *toCtx)
969{
970 PCRStateTracker pState = fromCtx->pStateTracker;
971 CREvaluatorState *from = &(fromCtx->eval);
972 CREvaluatorState *to = &(toCtx->eval);
973 glAble able[2];
974 int i, j;
975 CRbitvalue nbitID[CR_MAX_BITARRAY];
976
977 CRASSERT(fromCtx->pStateTracker == toCtx->pStateTracker);
978
979 for (j = 0; j < CR_MAX_BITARRAY; j++)
980 nbitID[j] = ~bitID[j];
981
982 able[0] = pState->diff_api.Disable;
983 able[1] = pState->diff_api.Enable;
984
985 if (CHECKDIRTY(e->enable, bitID)) {
986 if (from->autoNormal != to->autoNormal) {
987 able[to->autoNormal] (GL_AUTO_NORMAL);
988 from->autoNormal = to->autoNormal;
989 }
990 CLEARDIRTY(e->enable, nbitID);
991 }
992 for (i = 0; i < GLEVAL_TOT; i++) {
993 if (CHECKDIRTY(e->enable1D[i], bitID)) {
994 if (from->enable1D[i] != to->enable1D[i]) {
995 able[to->enable1D[i]] (i + GL_MAP1_COLOR_4);
996 from->enable1D[i] = to->enable1D[i];
997 }
998 CLEARDIRTY(e->enable1D[i], nbitID);
999 }
1000 if (to->enable1D[i] && CHECKDIRTY(e->eval1D[i], bitID)) {
1001 int size = from->eval1D[i].order * gleval_sizes[i] *
1002 sizeof(*from->eval1D[i].coeff);
1003 if (from->eval1D[i].order != to->eval1D[i].order ||
1004 from->eval1D[i].u1 != to->eval1D[i].u1 ||
1005 from->eval1D[i].u2 != to->eval1D[i].u2 ||
1006 crMemcmp((const void *) from->eval1D[i].coeff,
1007 (const void *) to->eval1D[i].coeff, size)) {
1008 pState->diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
1009 to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
1010 to->eval1D[i].coeff);
1011 from->eval1D[i].order = to->eval1D[i].order;
1012 from->eval1D[i].u1 = to->eval1D[i].u1;
1013 from->eval1D[i].u2 = to->eval1D[i].u2;
1014 crMemcpy((void *) from->eval1D[i].coeff,
1015 (const void *) to->eval1D[i].coeff, size);
1016 }
1017 CLEARDIRTY(e->eval1D[i], nbitID);
1018 }
1019 }
1020
1021 for (i = 0; i < GLEVAL_TOT; i++) {
1022 if (CHECKDIRTY(e->enable2D[i], bitID)) {
1023 if (from->enable2D[i] != to->enable2D[i]) {
1024 able[to->enable2D[i]] (i + GL_MAP2_COLOR_4);
1025 from->enable2D[i] = to->enable2D[i];
1026 }
1027 CLEARDIRTY(e->enable2D[i], nbitID);
1028 }
1029 if (to->enable2D[i] && CHECKDIRTY(e->eval2D[i], bitID)) {
1030 int size = from->eval2D[i].uorder * from->eval2D[i].vorder
1031 * gleval_sizes[i] * sizeof(*from->eval2D[i].coeff);
1032 if (from->eval2D[i].uorder != to->eval2D[i].uorder ||
1033 from->eval2D[i].vorder != to->eval2D[i].vorder ||
1034 from->eval2D[i].u1 != to->eval2D[i].u1 ||
1035 from->eval2D[i].u2 != to->eval2D[i].u2 ||
1036 from->eval2D[i].v1 != to->eval2D[i].v1 ||
1037 from->eval2D[i].v2 != to->eval2D[i].v2 ||
1038 crMemcmp((const void *) from->eval2D[i].coeff,
1039 (const void *) to->eval2D[i].coeff, size)) {
1040 pState->diff_api.Map2f(i + GL_MAP2_COLOR_4,
1041 to->eval2D[i].u1, to->eval2D[i].u2,
1042 gleval_sizes[i], to->eval2D[i].uorder,
1043 to->eval2D[i].v1, to->eval2D[i].v2,
1044 gleval_sizes[i], to->eval2D[i].vorder,
1045 to->eval2D[i].coeff);
1046 from->eval2D[i].uorder = to->eval2D[i].uorder;
1047 from->eval2D[i].vorder = to->eval2D[i].vorder;
1048 from->eval2D[i].u1 = to->eval2D[i].u1;
1049 from->eval2D[i].u2 = to->eval2D[i].u2;
1050 from->eval2D[i].v1 = to->eval2D[i].v1;
1051 from->eval2D[i].v2 = to->eval2D[i].v2;
1052 crMemcpy((void *) from->eval2D[i].coeff,
1053 (const void *) to->eval2D[i].coeff, size);
1054 }
1055 CLEARDIRTY(e->eval2D[i], nbitID);
1056 }
1057 }
1058 if (CHECKDIRTY(e->grid1D, bitID)) {
1059 if (from->u11D != to->u11D ||
1060 from->u21D != to->u21D ||
1061 from->un1D != to->un1D) {
1062 pState->diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
1063 from->u11D = to->u11D;
1064 from->u21D = to->u21D;
1065 from->un1D = to->un1D;
1066 }
1067 CLEARDIRTY(e->grid1D, nbitID);
1068 }
1069 if (CHECKDIRTY(e->grid2D, bitID)) {
1070 if (from->u12D != to->u12D ||
1071 from->u22D != to->u22D ||
1072 from->un2D != to->un2D ||
1073 from->v12D != to->v12D ||
1074 from->v22D != to->v22D ||
1075 from->vn2D != to->vn2D) {
1076 pState->diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
1077 to->vn2D, to->v12D, to->v22D);
1078 from->u12D = to->u12D;
1079 from->u22D = to->u22D;
1080 from->un2D = to->un2D;
1081 from->v12D = to->v12D;
1082 from->v22D = to->v22D;
1083 from->vn2D = to->vn2D;
1084 }
1085 CLEARDIRTY(e->grid1D, nbitID);
1086 }
1087 CLEARDIRTY(e->dirty, nbitID);
1088}
Note: See TracBrowser for help on using the repository browser.

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