VirtualBox

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

最後變更 在這個檔案從71997是 69392,由 vboxsync 提交於 7 年 前

GuestHost/OpenGL: scm updates

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 28.1 KB
 
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();
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();
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();
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(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
327 GLint uorder, const GLvoid * points, GLenum type)
328{
329 CRContext *g = GetCurrentContext();
330 CREvaluatorState *e = &(g->eval);
331 CRStateBits *sb = GetCurrentBits();
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(__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(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(u1==u2)");
350 return;
351 }
352 if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
353 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad uorder)");
354 return;
355 }
356 if (!points) {
357 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE,
358 "glMap1d(null points)");
359 return;
360 }
361
362 i = target - GL_MAP1_COLOR_4;
363
364 k = gleval_sizes[i];
365
366 if (k == 0) {
367 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(k=0)");
368 return;
369 }
370
371 if (ustride < k) {
372 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap1d(bad ustride");
373 return;
374 }
375
376 if (t->curTextureUnit != 0) {
377 /* See OpenGL 1.2.1 spec, section F.2.13 */
378 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
379 "glMap1d(current texture unit must be zero)");
380 return;
381 }
382
383 switch (target) {
384 case GL_MAP1_VERTEX_3:
385 case GL_MAP1_VERTEX_4:
386 case GL_MAP1_INDEX:
387 case GL_MAP1_COLOR_4:
388 case GL_MAP1_NORMAL:
389 case GL_MAP1_TEXTURE_COORD_1:
390 case GL_MAP1_TEXTURE_COORD_2:
391 case GL_MAP1_TEXTURE_COORD_3:
392 case GL_MAP1_TEXTURE_COORD_4:
393 break;
394 default:
395 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap1d(bad target)");
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(GLenum target, GLfloat u1, GLfloat u2,
421 GLint stride, GLint order, const GLfloat * points)
422{
423 map1(target, u1, u2, stride, order, points, GL_FLOAT);
424}
425
426void STATE_APIENTRY
427crStateMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
428 GLint order, const GLdouble * points)
429{
430 map1(target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
431}
432
433static void
434map2(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();
439 CRStateBits *sb = GetCurrentBits();
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(__LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
451 return;
452 }
453
454 FLUSH();
455
456 if (u1 == u2) {
457 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
458 return;
459 }
460
461 if (v1 == v2) {
462 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
463 return;
464 }
465
466 if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
467 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
468 return;
469 }
470
471 if (vorder < 1 || vorder > MAX_EVAL_ORDER) {
472 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
473 return;
474 }
475
476 if (g->extensions.NV_vertex_program) {
477/* XXX FIXME */
478 i = target - GL_MAP2_COLOR_4;
479 } else {
480 i = target - GL_MAP2_COLOR_4;
481 }
482
483 k = gleval_sizes[i];
484
485 if (k == 0) {
486 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
487 return;
488 }
489
490 if (ustride < k) {
491 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
492 return;
493 }
494 if (vstride < k) {
495 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMap2d()");
496 return;
497 }
498
499#if 00
500 /* Disable this check for now - it looks like various OpenGL drivers
501 * don't do this error check. So, a bunch of the NVIDIA demos
502 * generate errors/warnings.
503 */
504 if (t->curTextureUnit != 0) {
505 /* See OpenGL 1.2.1 spec, section F.2.13 */
506 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION, "glMap2d()");
507 return;
508 }
509#endif
510
511 switch (target) {
512 case GL_MAP2_VERTEX_3:
513 case GL_MAP2_VERTEX_4:
514 case GL_MAP2_INDEX:
515 case GL_MAP2_COLOR_4:
516 case GL_MAP2_NORMAL:
517 case GL_MAP2_TEXTURE_COORD_1:
518 case GL_MAP2_TEXTURE_COORD_2:
519 case GL_MAP2_TEXTURE_COORD_3:
520 case GL_MAP2_TEXTURE_COORD_4:
521 break;
522 default:
523 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glMap2d()");
524 return;
525 }
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(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(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
558 points, GL_FLOAT);
559}
560
561
562void STATE_APIENTRY
563crStateMap2d(GLenum target, GLdouble u1, GLdouble u2,
564 GLint ustride, GLint uorder,
565 GLdouble v1, GLdouble v2,
566 GLint vstride, GLint vorder, const GLdouble * points)
567{
568 map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
569 (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
570}
571
572void STATE_APIENTRY
573crStateGetMapdv(GLenum target, GLenum query, GLdouble * v)
574{
575 CRContext *g = GetCurrentContext();
576 CRStateBits *sb = GetCurrentBits();
577 CREvaluatorState *e = &(g->eval);
578 GLint size;
579 GLint i, j;
580 (void) sb;
581
582 if (g->current.inBeginEnd) {
583 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
584 "Map1d called in begin/end");
585 return;
586 }
587
588 FLUSH();
589
590 i = target - GL_MAP1_COLOR_4;
591
592 if (i < 0 || i >= GLEVAL_TOT) {
593 i = target - GL_MAP2_COLOR_4;
594
595 if (i < 0 || i >= GLEVAL_TOT) {
596 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
597 "GetMapdv: invalid target: %d", target);
598 return;
599 }
600
601 switch (query) {
602 case GL_COEFF:
603 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
604 for (j = 0; j < size; j++) {
605 v[j] = e->eval2D[i].coeff[j];
606 }
607 break;
608 case GL_ORDER:
609 v[0] = (GLdouble) e->eval2D[i].uorder;
610 v[1] = (GLdouble) e->eval2D[i].vorder;
611 break;
612 case GL_DOMAIN:
613 v[0] = e->eval2D[i].u1;
614 v[1] = e->eval2D[i].u2;
615 v[2] = e->eval2D[i].v1;
616 v[3] = e->eval2D[i].v2;
617 break;
618 default:
619 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
620 "GetMapdv: invalid target: %d", target);
621 return;
622 }
623 }
624 else {
625 switch (query) {
626 case GL_COEFF:
627 size = gleval_sizes[i] * e->eval1D[i].order;
628 for (j = 0; j < size; j++) {
629 v[j] = e->eval1D[i].coeff[j];
630 }
631 break;
632 case GL_ORDER:
633 *v = (GLdouble) e->eval1D[i].order;
634 break;
635 case GL_DOMAIN:
636 v[0] = e->eval1D[i].u1;
637 v[1] = e->eval1D[i].u2;
638 break;
639 default:
640 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
641 "GetMapdv: invalid target: %d", target);
642 return;
643 }
644 }
645}
646
647void STATE_APIENTRY
648crStateGetMapfv(GLenum target, GLenum query, GLfloat * v)
649{
650 CRContext *g = GetCurrentContext();
651 CRStateBits *sb = GetCurrentBits();
652 CREvaluatorState *e = &(g->eval);
653 GLint size;
654 GLint i, j;
655 (void) sb;
656
657 if (g->current.inBeginEnd) {
658 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
659 "Map1d called in begin/end");
660 return;
661 }
662
663 FLUSH();
664
665 i = target - GL_MAP1_COLOR_4;
666 if (i < 0 || i >= GLEVAL_TOT) {
667 i = target - GL_MAP2_COLOR_4;
668 if (i < 0 || i >= GLEVAL_TOT) {
669 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
670 "GetMapfv: invalid target: %d", target);
671 return;
672 }
673 switch (query) {
674 case GL_COEFF:
675 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
676 for (j = 0; j < size; j++) {
677 v[j] = (GLfloat) e->eval2D[i].coeff[j];
678 }
679 break;
680 case GL_ORDER:
681 v[0] = (GLfloat) e->eval2D[i].uorder;
682 v[1] = (GLfloat) e->eval2D[i].vorder;
683 break;
684 case GL_DOMAIN:
685 v[0] = (GLfloat) e->eval2D[i].u1;
686 v[1] = (GLfloat) e->eval2D[i].u2;
687 v[2] = (GLfloat) e->eval2D[i].v1;
688 v[3] = (GLfloat) e->eval2D[i].v2;
689 break;
690 default:
691 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
692 "GetMapfv: invalid target: %d", target);
693 return;
694 }
695 }
696 else {
697 switch (query) {
698 case GL_COEFF:
699 size = gleval_sizes[i] * e->eval1D[i].order;
700 for (j = 0; j < size; j++) {
701 v[j] = (GLfloat) e->eval1D[i].coeff[j];
702 }
703 break;
704 case GL_ORDER:
705 *v = (GLfloat) e->eval1D[i].order;
706 break;
707 case GL_DOMAIN:
708 v[0] = (GLfloat) e->eval1D[i].u1;
709 v[1] = (GLfloat) e->eval1D[i].u2;
710 break;
711 default:
712 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
713 "GetMapfv: invalid target: %d", target);
714 return;
715 }
716 }
717}
718
719void STATE_APIENTRY
720crStateGetMapiv(GLenum target, GLenum query, GLint * v)
721{
722 CRContext *g = GetCurrentContext();
723 CRStateBits *sb = GetCurrentBits();
724 CREvaluatorState *e = &(g->eval);
725 GLint size;
726 GLint i, j;
727 (void) sb;
728
729 if (g->current.inBeginEnd) {
730 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
731 "Map1d called in begin/end");
732 return;
733 }
734
735 FLUSH();
736
737 i = target - GL_MAP1_COLOR_4;
738 if (i < 0 || i >= GLEVAL_TOT) {
739 i = target - GL_MAP2_COLOR_4;
740 if (i < 0 || i >= GLEVAL_TOT) {
741 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
742 "GetMapiv: invalid target: %d", target);
743 return;
744 }
745 switch (query) {
746 case GL_COEFF:
747 size = gleval_sizes[i] * e->eval2D[i].uorder * e->eval2D[i].vorder;
748 for (j = 0; j < size; j++) {
749 v[j] = (GLint) e->eval2D[i].coeff[j];
750 }
751 break;
752 case GL_ORDER:
753 v[0] = e->eval2D[i].uorder;
754 v[1] = e->eval2D[i].vorder;
755 break;
756 case GL_DOMAIN:
757 v[0] = (GLint) e->eval2D[i].u1;
758 v[1] = (GLint) e->eval2D[i].u2;
759 v[2] = (GLint) e->eval2D[i].v1;
760 v[3] = (GLint) e->eval2D[i].v2;
761 break;
762 default:
763 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
764 "GetMapiv: invalid target: %d", target);
765 return;
766 }
767 }
768 else {
769 switch (query) {
770 case GL_COEFF:
771 size = gleval_sizes[i] * e->eval1D[i].order;
772 for (j = 0; j < size; j++) {
773 v[j] = (GLint) e->eval1D[i].coeff[j];
774 }
775 break;
776 case GL_ORDER:
777 *v = e->eval1D[i].order;
778 break;
779 case GL_DOMAIN:
780 v[0] = (GLint) e->eval1D[i].u1;
781 v[1] = (GLint) e->eval1D[i].u2;
782 break;
783 default:
784 crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
785 "GetMapiv: invalid target: %d", target);
786 return;
787 }
788 }
789}
790
791void STATE_APIENTRY
792crStateMapGrid1f(GLint un, GLfloat u1, GLfloat u2)
793{
794 CRContext *g = GetCurrentContext();
795 CRStateBits *sb = GetCurrentBits();
796 CREvaluatorState *e = &(g->eval);
797 CREvaluatorBits *eb = &(sb->eval);
798
799 if (g->current.inBeginEnd) {
800 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
801 "Map1d called in begin/end");
802 return;
803 }
804
805 FLUSH();
806
807 if (un < 1) {
808 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid1f(bad un)");
809 return;
810 }
811
812 e->un1D = un;
813 e->u11D = u1;
814 e->u21D = u2;
815
816 DIRTY(eb->dirty, g->neg_bitid);
817 DIRTY(eb->grid1D, g->neg_bitid);
818}
819
820void STATE_APIENTRY
821crStateMapGrid1d(GLint un, GLdouble u1, GLdouble u2)
822{
823 crStateMapGrid1f(un, (GLfloat) u1, (GLfloat) u2);
824}
825
826
827void STATE_APIENTRY
828crStateMapGrid2f(GLint un, GLfloat u1, GLfloat u2,
829 GLint vn, GLfloat v1, GLfloat v2)
830{
831 CRContext *g = GetCurrentContext();
832 CRStateBits *sb = GetCurrentBits();
833 CREvaluatorState *e = &(g->eval);
834 CREvaluatorBits *eb = &(sb->eval);
835
836 if (g->current.inBeginEnd) {
837 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
838 "Map1d called in begin/end");
839 return;
840 }
841
842 FLUSH();
843
844 if (un < 1) {
845 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad un)");
846 return;
847 }
848 if (vn < 1) {
849 crStateError(__LINE__, __FILE__, GL_INVALID_VALUE, "glMapGrid2f(bad vn)");
850 return;
851 }
852
853 e->un2D = un;
854 e->vn2D = vn;
855 e->u12D = u1;
856 e->u22D = u2;
857 e->v12D = v1;
858 e->v22D = v2;
859
860 DIRTY(eb->dirty, g->neg_bitid);
861 DIRTY(eb->grid2D, g->neg_bitid);
862}
863
864void STATE_APIENTRY
865crStateMapGrid2d(GLint un, GLdouble u1, GLdouble u2,
866 GLint vn, GLdouble v1, GLdouble v2)
867{
868 crStateMapGrid2f(un, (GLfloat) u1, (GLfloat) u2,
869 vn, (GLfloat) v1, (GLfloat) v2);
870}
871
872void
873crStateEvaluatorSwitch(CREvaluatorBits *e, CRbitvalue * bitID,
874 CRContext *fromCtx, CRContext *toCtx)
875{
876 CREvaluatorState *from = &(fromCtx->eval);
877 CREvaluatorState *to = &(toCtx->eval);
878 int i, j;
879 CRbitvalue nbitID[CR_MAX_BITARRAY];
880
881 for (j = 0; j < CR_MAX_BITARRAY; j++)
882 nbitID[j] = ~bitID[j];
883
884 if (CHECKDIRTY(e->enable, bitID)) {
885 if (from->autoNormal != to->autoNormal) {
886 glAble able[2];
887 able[0] = diff_api.Disable;
888 able[1] = diff_api.Enable;
889 able[to->autoNormal] (GL_AUTO_NORMAL);
890 FILLDIRTY(e->enable);
891 FILLDIRTY(e->dirty);
892 }
893 CLEARDIRTY(e->enable, nbitID);
894 }
895 for (i = 0; i < GLEVAL_TOT; i++) {
896 if (CHECKDIRTY(e->eval1D[i], bitID)) {
897 int size = from->eval1D[i].order * gleval_sizes[i] *
898 sizeof(*from->eval1D[i].coeff);
899 if (from->eval1D[i].order != to->eval1D[i].order ||
900 from->eval1D[i].u1 != to->eval1D[i].u1 ||
901 from->eval1D[i].u2 != to->eval1D[i].u2 ||
902 crMemcmp((const void *) from->eval1D[i].coeff,
903 (const void *) to->eval1D[i].coeff, size)) {
904 diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
905 to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
906 to->eval1D[i].coeff);
907 FILLDIRTY(e->dirty);
908 FILLDIRTY(e->eval1D[i]);
909 }
910 CLEARDIRTY(e->eval1D[i], nbitID);
911 }
912 }
913
914 for (i = 0; i < GLEVAL_TOT; i++) {
915 if (CHECKDIRTY(e->eval2D[i], bitID)) {
916 int size = from->eval2D[i].uorder * from->eval2D[i].vorder
917 * gleval_sizes[i] * sizeof(*from->eval2D[i].coeff);
918 if (from->eval2D[i].uorder != to->eval2D[i].uorder ||
919 from->eval2D[i].vorder != to->eval2D[i].vorder ||
920 from->eval2D[i].u1 != to->eval2D[i].u1 ||
921 from->eval2D[i].u2 != to->eval2D[i].u2 ||
922 from->eval2D[i].v1 != to->eval2D[i].v1 ||
923 from->eval2D[i].v2 != to->eval2D[i].v2 ||
924 crMemcmp((const void *) from->eval2D[i].coeff,
925 (const void *) to->eval2D[i].coeff, size)) {
926 diff_api.Map2f(i + GL_MAP2_COLOR_4,
927 to->eval2D[i].u1, to->eval2D[i].u2,
928 gleval_sizes[i], to->eval2D[i].uorder,
929 to->eval2D[i].v1, to->eval2D[i].v2,
930 gleval_sizes[i], to->eval2D[i].vorder,
931 to->eval2D[i].coeff);
932 FILLDIRTY(e->dirty);
933 FILLDIRTY(e->eval2D[i]);
934 }
935 CLEARDIRTY(e->eval2D[i], nbitID);
936 }
937 }
938 if (CHECKDIRTY(e->grid1D, bitID)) {
939 if (from->u11D != to->u11D ||
940 from->u21D != to->u21D ||
941 from->un1D != to->un1D) {
942 diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
943 FILLDIRTY(e->dirty);
944 FILLDIRTY(e->grid1D);
945 }
946 CLEARDIRTY(e->grid1D, nbitID);
947 }
948 if (CHECKDIRTY(e->grid2D, bitID)) {
949 if (from->u12D != to->u12D ||
950 from->u22D != to->u22D ||
951 from->un2D != to->un2D ||
952 from->v12D != to->v12D ||
953 from->v22D != to->v22D ||
954 from->vn2D != to->vn2D) {
955 diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
956 to->vn2D, to->v12D, to->v22D);
957 FILLDIRTY(e->dirty);
958 FILLDIRTY(e->grid1D);
959 }
960 CLEARDIRTY(e->grid1D, nbitID);
961 }
962 CLEARDIRTY(e->dirty, nbitID);
963}
964
965void
966crStateEvaluatorDiff(CREvaluatorBits *e, CRbitvalue *bitID,
967 CRContext *fromCtx, CRContext *toCtx)
968{
969 CREvaluatorState *from = &(fromCtx->eval);
970 CREvaluatorState *to = &(toCtx->eval);
971 glAble able[2];
972 int i, j;
973 CRbitvalue nbitID[CR_MAX_BITARRAY];
974
975 for (j = 0; j < CR_MAX_BITARRAY; j++)
976 nbitID[j] = ~bitID[j];
977
978 able[0] = diff_api.Disable;
979 able[1] = diff_api.Enable;
980
981 if (CHECKDIRTY(e->enable, bitID)) {
982 if (from->autoNormal != to->autoNormal) {
983 able[to->autoNormal] (GL_AUTO_NORMAL);
984 from->autoNormal = to->autoNormal;
985 }
986 CLEARDIRTY(e->enable, nbitID);
987 }
988 for (i = 0; i < GLEVAL_TOT; i++) {
989 if (CHECKDIRTY(e->enable1D[i], bitID)) {
990 if (from->enable1D[i] != to->enable1D[i]) {
991 able[to->enable1D[i]] (i + GL_MAP1_COLOR_4);
992 from->enable1D[i] = to->enable1D[i];
993 }
994 CLEARDIRTY(e->enable1D[i], nbitID);
995 }
996 if (to->enable1D[i] && CHECKDIRTY(e->eval1D[i], bitID)) {
997 int size = from->eval1D[i].order * gleval_sizes[i] *
998 sizeof(*from->eval1D[i].coeff);
999 if (from->eval1D[i].order != to->eval1D[i].order ||
1000 from->eval1D[i].u1 != to->eval1D[i].u1 ||
1001 from->eval1D[i].u2 != to->eval1D[i].u2 ||
1002 crMemcmp((const void *) from->eval1D[i].coeff,
1003 (const void *) to->eval1D[i].coeff, size)) {
1004 diff_api.Map1f(i + GL_MAP1_COLOR_4, to->eval1D[i].u1,
1005 to->eval1D[i].u2, gleval_sizes[i], to->eval1D[i].order,
1006 to->eval1D[i].coeff);
1007 from->eval1D[i].order = to->eval1D[i].order;
1008 from->eval1D[i].u1 = to->eval1D[i].u1;
1009 from->eval1D[i].u2 = to->eval1D[i].u2;
1010 crMemcpy((void *) from->eval1D[i].coeff,
1011 (const void *) to->eval1D[i].coeff, size);
1012 }
1013 CLEARDIRTY(e->eval1D[i], nbitID);
1014 }
1015 }
1016
1017 for (i = 0; i < GLEVAL_TOT; i++) {
1018 if (CHECKDIRTY(e->enable2D[i], bitID)) {
1019 if (from->enable2D[i] != to->enable2D[i]) {
1020 able[to->enable2D[i]] (i + GL_MAP2_COLOR_4);
1021 from->enable2D[i] = to->enable2D[i];
1022 }
1023 CLEARDIRTY(e->enable2D[i], nbitID);
1024 }
1025 if (to->enable2D[i] && CHECKDIRTY(e->eval2D[i], bitID)) {
1026 int size = from->eval2D[i].uorder * from->eval2D[i].vorder
1027 * gleval_sizes[i] * sizeof(*from->eval2D[i].coeff);
1028 if (from->eval2D[i].uorder != to->eval2D[i].uorder ||
1029 from->eval2D[i].vorder != to->eval2D[i].vorder ||
1030 from->eval2D[i].u1 != to->eval2D[i].u1 ||
1031 from->eval2D[i].u2 != to->eval2D[i].u2 ||
1032 from->eval2D[i].v1 != to->eval2D[i].v1 ||
1033 from->eval2D[i].v2 != to->eval2D[i].v2 ||
1034 crMemcmp((const void *) from->eval2D[i].coeff,
1035 (const void *) to->eval2D[i].coeff, size)) {
1036 diff_api.Map2f(i + GL_MAP2_COLOR_4,
1037 to->eval2D[i].u1, to->eval2D[i].u2,
1038 gleval_sizes[i], to->eval2D[i].uorder,
1039 to->eval2D[i].v1, to->eval2D[i].v2,
1040 gleval_sizes[i], to->eval2D[i].vorder,
1041 to->eval2D[i].coeff);
1042 from->eval2D[i].uorder = to->eval2D[i].uorder;
1043 from->eval2D[i].vorder = to->eval2D[i].vorder;
1044 from->eval2D[i].u1 = to->eval2D[i].u1;
1045 from->eval2D[i].u2 = to->eval2D[i].u2;
1046 from->eval2D[i].v1 = to->eval2D[i].v1;
1047 from->eval2D[i].v2 = to->eval2D[i].v2;
1048 crMemcpy((void *) from->eval2D[i].coeff,
1049 (const void *) to->eval2D[i].coeff, size);
1050 }
1051 CLEARDIRTY(e->eval2D[i], nbitID);
1052 }
1053 }
1054 if (CHECKDIRTY(e->grid1D, bitID)) {
1055 if (from->u11D != to->u11D ||
1056 from->u21D != to->u21D ||
1057 from->un1D != to->un1D) {
1058 diff_api.MapGrid1d(to->un1D, to->u11D, to->u21D);
1059 from->u11D = to->u11D;
1060 from->u21D = to->u21D;
1061 from->un1D = to->un1D;
1062 }
1063 CLEARDIRTY(e->grid1D, nbitID);
1064 }
1065 if (CHECKDIRTY(e->grid2D, bitID)) {
1066 if (from->u12D != to->u12D ||
1067 from->u22D != to->u22D ||
1068 from->un2D != to->un2D ||
1069 from->v12D != to->v12D ||
1070 from->v22D != to->v22D ||
1071 from->vn2D != to->vn2D) {
1072 diff_api.MapGrid2d(to->un2D, to->u12D, to->u22D,
1073 to->vn2D, to->v12D, to->v22D);
1074 from->u12D = to->u12D;
1075 from->u22D = to->u22D;
1076 from->un2D = to->un2D;
1077 from->v12D = to->v12D;
1078 from->v22D = to->v22D;
1079 from->vn2D = to->vn2D;
1080 }
1081 CLEARDIRTY(e->grid1D, nbitID);
1082 }
1083 CLEARDIRTY(e->dirty, nbitID);
1084}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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