3 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * eval.c was written by
29 * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and
30 * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de).
32 * My original implementation of evaluators was simplistic and didn't
33 * compute surface normal vectors properly. Bernd and Volker applied
34 * used more sophisticated methods to get better results.
47 #include "main/dispatch.h"
51 * Return the number of components per control point for any type of
52 * evaluator. Return 0 if bad target.
53 * See table 5.1 in the OpenGL 1.2 spec.
55 GLuint
_mesa_evaluator_components( GLenum target
)
58 case GL_MAP1_VERTEX_3
: return 3;
59 case GL_MAP1_VERTEX_4
: return 4;
60 case GL_MAP1_INDEX
: return 1;
61 case GL_MAP1_COLOR_4
: return 4;
62 case GL_MAP1_NORMAL
: return 3;
63 case GL_MAP1_TEXTURE_COORD_1
: return 1;
64 case GL_MAP1_TEXTURE_COORD_2
: return 2;
65 case GL_MAP1_TEXTURE_COORD_3
: return 3;
66 case GL_MAP1_TEXTURE_COORD_4
: return 4;
67 case GL_MAP2_VERTEX_3
: return 3;
68 case GL_MAP2_VERTEX_4
: return 4;
69 case GL_MAP2_INDEX
: return 1;
70 case GL_MAP2_COLOR_4
: return 4;
71 case GL_MAP2_NORMAL
: return 3;
72 case GL_MAP2_TEXTURE_COORD_1
: return 1;
73 case GL_MAP2_TEXTURE_COORD_2
: return 2;
74 case GL_MAP2_TEXTURE_COORD_3
: return 3;
75 case GL_MAP2_TEXTURE_COORD_4
: return 4;
84 * Return pointer to the gl_1d_map struct for the named target.
86 static struct gl_1d_map
*
87 get_1d_map( struct gl_context
*ctx
, GLenum target
)
90 case GL_MAP1_VERTEX_3
:
91 return &ctx
->EvalMap
.Map1Vertex3
;
92 case GL_MAP1_VERTEX_4
:
93 return &ctx
->EvalMap
.Map1Vertex4
;
95 return &ctx
->EvalMap
.Map1Index
;
97 return &ctx
->EvalMap
.Map1Color4
;
99 return &ctx
->EvalMap
.Map1Normal
;
100 case GL_MAP1_TEXTURE_COORD_1
:
101 return &ctx
->EvalMap
.Map1Texture1
;
102 case GL_MAP1_TEXTURE_COORD_2
:
103 return &ctx
->EvalMap
.Map1Texture2
;
104 case GL_MAP1_TEXTURE_COORD_3
:
105 return &ctx
->EvalMap
.Map1Texture3
;
106 case GL_MAP1_TEXTURE_COORD_4
:
107 return &ctx
->EvalMap
.Map1Texture4
;
115 * Return pointer to the gl_2d_map struct for the named target.
117 static struct gl_2d_map
*
118 get_2d_map( struct gl_context
*ctx
, GLenum target
)
121 case GL_MAP2_VERTEX_3
:
122 return &ctx
->EvalMap
.Map2Vertex3
;
123 case GL_MAP2_VERTEX_4
:
124 return &ctx
->EvalMap
.Map2Vertex4
;
126 return &ctx
->EvalMap
.Map2Index
;
127 case GL_MAP2_COLOR_4
:
128 return &ctx
->EvalMap
.Map2Color4
;
130 return &ctx
->EvalMap
.Map2Normal
;
131 case GL_MAP2_TEXTURE_COORD_1
:
132 return &ctx
->EvalMap
.Map2Texture1
;
133 case GL_MAP2_TEXTURE_COORD_2
:
134 return &ctx
->EvalMap
.Map2Texture2
;
135 case GL_MAP2_TEXTURE_COORD_3
:
136 return &ctx
->EvalMap
.Map2Texture3
;
137 case GL_MAP2_TEXTURE_COORD_4
:
138 return &ctx
->EvalMap
.Map2Texture4
;
145 /**********************************************************************/
146 /*** Copy and deallocate control points ***/
147 /**********************************************************************/
151 * Copy 1-parametric evaluator control points from user-specified
152 * memory space to a buffer of contiguous control points.
153 * \param see glMap1f for details
154 * \return pointer to buffer of contiguous control points or NULL if out
157 GLfloat
*_mesa_copy_map_points1f( GLenum target
, GLint ustride
, GLint uorder
,
158 const GLfloat
*points
)
161 GLint i
, k
, size
= _mesa_evaluator_components(target
);
163 if (!points
|| !size
)
166 buffer
= malloc(uorder
* size
* sizeof(GLfloat
));
169 for (i
= 0, p
= buffer
; i
< uorder
; i
++, points
+= ustride
)
170 for (k
= 0; k
< size
; k
++)
179 * Same as above but convert doubles to floats.
181 GLfloat
*_mesa_copy_map_points1d( GLenum target
, GLint ustride
, GLint uorder
,
182 const GLdouble
*points
)
185 GLint i
, k
, size
= _mesa_evaluator_components(target
);
187 if (!points
|| !size
)
190 buffer
= malloc(uorder
* size
* sizeof(GLfloat
));
193 for (i
= 0, p
= buffer
; i
< uorder
; i
++, points
+= ustride
)
194 for (k
= 0; k
< size
; k
++)
195 *p
++ = (GLfloat
) points
[k
];
203 * Copy 2-parametric evaluator control points from user-specified
204 * memory space to a buffer of contiguous control points.
205 * Additional memory is allocated to be used by the horner and
206 * de Casteljau evaluation schemes.
208 * \param see glMap2f for details
209 * \return pointer to buffer of contiguous control points or NULL if out
212 GLfloat
*_mesa_copy_map_points2f( GLenum target
,
213 GLint ustride
, GLint uorder
,
214 GLint vstride
, GLint vorder
,
215 const GLfloat
*points
)
218 GLint i
, j
, k
, size
, dsize
, hsize
;
221 size
= _mesa_evaluator_components(target
);
223 if (!points
|| size
==0) {
227 /* max(uorder, vorder) additional points are used in */
228 /* horner evaluation and uorder*vorder additional */
229 /* values are needed for de Casteljau */
230 dsize
= (uorder
== 2 && vorder
== 2)? 0 : uorder
*vorder
;
231 hsize
= (uorder
> vorder
? uorder
: vorder
)*size
;
234 buffer
= malloc((uorder
*vorder
*size
+hsize
)*sizeof(GLfloat
));
236 buffer
= malloc((uorder
*vorder
*size
+dsize
)*sizeof(GLfloat
));
238 /* compute the increment value for the u-loop */
239 uinc
= ustride
- vorder
*vstride
;
242 for (i
=0, p
=buffer
; i
<uorder
; i
++, points
+= uinc
)
243 for (j
=0; j
<vorder
; j
++, points
+= vstride
)
244 for (k
=0; k
<size
; k
++)
253 * Same as above but convert doubles to floats.
255 GLfloat
*_mesa_copy_map_points2d(GLenum target
,
256 GLint ustride
, GLint uorder
,
257 GLint vstride
, GLint vorder
,
258 const GLdouble
*points
)
261 GLint i
, j
, k
, size
, hsize
, dsize
;
264 size
= _mesa_evaluator_components(target
);
266 if (!points
|| size
==0) {
270 /* max(uorder, vorder) additional points are used in */
271 /* horner evaluation and uorder*vorder additional */
272 /* values are needed for de Casteljau */
273 dsize
= (uorder
== 2 && vorder
== 2)? 0 : uorder
*vorder
;
274 hsize
= (uorder
> vorder
? uorder
: vorder
)*size
;
277 buffer
= malloc((uorder
*vorder
*size
+hsize
)*sizeof(GLfloat
));
279 buffer
= malloc((uorder
*vorder
*size
+dsize
)*sizeof(GLfloat
));
281 /* compute the increment value for the u-loop */
282 uinc
= ustride
- vorder
*vstride
;
285 for (i
=0, p
=buffer
; i
<uorder
; i
++, points
+= uinc
)
286 for (j
=0; j
<vorder
; j
++, points
+= vstride
)
287 for (k
=0; k
<size
; k
++)
288 *p
++ = (GLfloat
) points
[k
];
296 /**********************************************************************/
297 /*** API entry points ***/
298 /**********************************************************************/
302 * This does the work of glMap1[fd].
305 map1(GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustride
,
306 GLint uorder
, const GLvoid
*points
, GLenum type
)
308 GET_CURRENT_CONTEXT(ctx
);
311 struct gl_1d_map
*map
= NULL
;
313 ASSERT(type
== GL_FLOAT
|| type
== GL_DOUBLE
);
316 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(u1,u2)" );
319 if (uorder
< 1 || uorder
> MAX_EVAL_ORDER
) {
320 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(order)" );
324 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(points)" );
328 k
= _mesa_evaluator_components( target
);
330 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap1(target)" );
335 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(stride)" );
339 if (ctx
->Texture
.CurrentUnit
!= 0) {
340 /* See OpenGL 1.2.1 spec, section F.2.13 */
341 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glMap2(ACTIVE_TEXTURE != 0)" );
345 map
= get_1d_map(ctx
, target
);
347 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap1(target)" );
351 /* make copy of the control points */
352 if (type
== GL_FLOAT
)
353 pnts
= _mesa_copy_map_points1f(target
, ustride
, uorder
, (GLfloat
*) points
);
355 pnts
= _mesa_copy_map_points1d(target
, ustride
, uorder
, (GLdouble
*) points
);
358 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
362 map
->du
= 1.0F
/ (u2
- u1
);
370 _mesa_Map1f( GLenum target
, GLfloat u1
, GLfloat u2
, GLint stride
,
371 GLint order
, const GLfloat
*points
)
373 map1(target
, u1
, u2
, stride
, order
, points
, GL_FLOAT
);
378 _mesa_Map1d( GLenum target
, GLdouble u1
, GLdouble u2
, GLint stride
,
379 GLint order
, const GLdouble
*points
)
381 map1(target
, (GLfloat
) u1
, (GLfloat
) u2
, stride
, order
, points
, GL_DOUBLE
);
386 map2( GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustride
, GLint uorder
,
387 GLfloat v1
, GLfloat v2
, GLint vstride
, GLint vorder
,
388 const GLvoid
*points
, GLenum type
)
390 GET_CURRENT_CONTEXT(ctx
);
393 struct gl_2d_map
*map
= NULL
;
395 ASSERT(type
== GL_FLOAT
|| type
== GL_DOUBLE
);
398 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(u1,u2)" );
403 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(v1,v2)" );
407 if (uorder
<1 || uorder
>MAX_EVAL_ORDER
) {
408 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(uorder)" );
412 if (vorder
<1 || vorder
>MAX_EVAL_ORDER
) {
413 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(vorder)" );
417 k
= _mesa_evaluator_components( target
);
419 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap2(target)" );
424 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(ustride)" );
428 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(vstride)" );
432 if (ctx
->Texture
.CurrentUnit
!= 0) {
433 /* See OpenGL 1.2.1 spec, section F.2.13 */
434 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glMap2(ACTIVE_TEXTURE != 0)" );
438 map
= get_2d_map(ctx
, target
);
440 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap2(target)" );
444 /* make copy of the control points */
445 if (type
== GL_FLOAT
)
446 pnts
= _mesa_copy_map_points2f(target
, ustride
, uorder
,
447 vstride
, vorder
, (GLfloat
*) points
);
449 pnts
= _mesa_copy_map_points2d(target
, ustride
, uorder
,
450 vstride
, vorder
, (GLdouble
*) points
);
453 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
454 map
->Uorder
= uorder
;
457 map
->du
= 1.0F
/ (u2
- u1
);
458 map
->Vorder
= vorder
;
461 map
->dv
= 1.0F
/ (v2
- v1
);
468 _mesa_Map2f( GLenum target
,
469 GLfloat u1
, GLfloat u2
, GLint ustride
, GLint uorder
,
470 GLfloat v1
, GLfloat v2
, GLint vstride
, GLint vorder
,
471 const GLfloat
*points
)
473 map2(target
, u1
, u2
, ustride
, uorder
, v1
, v2
, vstride
, vorder
,
479 _mesa_Map2d( GLenum target
,
480 GLdouble u1
, GLdouble u2
, GLint ustride
, GLint uorder
,
481 GLdouble v1
, GLdouble v2
, GLint vstride
, GLint vorder
,
482 const GLdouble
*points
)
484 map2(target
, (GLfloat
) u1
, (GLfloat
) u2
, ustride
, uorder
,
485 (GLfloat
) v1
, (GLfloat
) v2
, vstride
, vorder
, points
, GL_DOUBLE
);
491 _mesa_GetnMapdvARB( GLenum target
, GLenum query
, GLsizei bufSize
, GLdouble
*v
)
493 GET_CURRENT_CONTEXT(ctx
);
494 struct gl_1d_map
*map1d
;
495 struct gl_2d_map
*map2d
;
501 comps
= _mesa_evaluator_components(target
);
503 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapdv(target)" );
507 map1d
= get_1d_map(ctx
, target
);
508 map2d
= get_2d_map(ctx
, target
);
509 ASSERT(map1d
|| map2d
);
514 data
= map1d
->Points
;
515 n
= map1d
->Order
* comps
;
518 data
= map2d
->Points
;
519 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
522 numBytes
= n
* sizeof *v
;
523 if (bufSize
< numBytes
)
532 numBytes
= 1 * sizeof *v
;
533 if (bufSize
< numBytes
)
535 v
[0] = (GLdouble
) map1d
->Order
;
538 numBytes
= 2 * sizeof *v
;
539 if (bufSize
< numBytes
)
541 v
[0] = (GLdouble
) map2d
->Uorder
;
542 v
[1] = (GLdouble
) map2d
->Vorder
;
547 numBytes
= 2 * sizeof *v
;
548 if (bufSize
< numBytes
)
550 v
[0] = (GLdouble
) map1d
->u1
;
551 v
[1] = (GLdouble
) map1d
->u2
;
554 numBytes
= 4 * sizeof *v
;
555 if (bufSize
< numBytes
)
557 v
[0] = (GLdouble
) map2d
->u1
;
558 v
[1] = (GLdouble
) map2d
->u2
;
559 v
[2] = (GLdouble
) map2d
->v1
;
560 v
[3] = (GLdouble
) map2d
->v2
;
564 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapdv(query)" );
569 _mesa_error( ctx
, GL_INVALID_OPERATION
,
570 "glGetnMapdvARB(out of bounds: bufSize is %d,"
571 " but %d bytes are required)", bufSize
, numBytes
);
575 _mesa_GetMapdv( GLenum target
, GLenum query
, GLdouble
*v
)
577 _mesa_GetnMapdvARB(target
, query
, INT_MAX
, v
);
581 _mesa_GetnMapfvARB( GLenum target
, GLenum query
, GLsizei bufSize
, GLfloat
*v
)
583 GET_CURRENT_CONTEXT(ctx
);
584 struct gl_1d_map
*map1d
;
585 struct gl_2d_map
*map2d
;
591 comps
= _mesa_evaluator_components(target
);
593 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapfv(target)" );
597 map1d
= get_1d_map(ctx
, target
);
598 map2d
= get_2d_map(ctx
, target
);
599 ASSERT(map1d
|| map2d
);
604 data
= map1d
->Points
;
605 n
= map1d
->Order
* comps
;
608 data
= map2d
->Points
;
609 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
612 numBytes
= n
* sizeof *v
;
613 if (bufSize
< numBytes
)
622 numBytes
= 1 * sizeof *v
;
623 if (bufSize
< numBytes
)
625 v
[0] = (GLfloat
) map1d
->Order
;
628 numBytes
= 2 * sizeof *v
;
629 if (bufSize
< numBytes
)
631 v
[0] = (GLfloat
) map2d
->Uorder
;
632 v
[1] = (GLfloat
) map2d
->Vorder
;
637 numBytes
= 2 * sizeof *v
;
638 if (bufSize
< numBytes
)
644 numBytes
= 4 * sizeof *v
;
645 if (bufSize
< numBytes
)
654 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapfv(query)" );
659 _mesa_error( ctx
, GL_INVALID_OPERATION
,
660 "glGetnMapfvARB(out of bounds: bufSize is %d,"
661 " but %d bytes are required)", bufSize
, numBytes
);
666 _mesa_GetMapfv( GLenum target
, GLenum query
, GLfloat
*v
)
668 _mesa_GetnMapfvARB(target
, query
, INT_MAX
, v
);
673 _mesa_GetnMapivARB( GLenum target
, GLenum query
, GLsizei bufSize
, GLint
*v
)
675 GET_CURRENT_CONTEXT(ctx
);
676 struct gl_1d_map
*map1d
;
677 struct gl_2d_map
*map2d
;
683 comps
= _mesa_evaluator_components(target
);
685 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapiv(target)" );
689 map1d
= get_1d_map(ctx
, target
);
690 map2d
= get_2d_map(ctx
, target
);
691 ASSERT(map1d
|| map2d
);
696 data
= map1d
->Points
;
697 n
= map1d
->Order
* comps
;
700 data
= map2d
->Points
;
701 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
704 numBytes
= n
* sizeof *v
;
705 if (bufSize
< numBytes
)
708 v
[i
] = IROUND(data
[i
]);
714 numBytes
= 1 * sizeof *v
;
715 if (bufSize
< numBytes
)
720 numBytes
= 2 * sizeof *v
;
721 if (bufSize
< numBytes
)
723 v
[0] = map2d
->Uorder
;
724 v
[1] = map2d
->Vorder
;
729 numBytes
= 2 * sizeof *v
;
730 if (bufSize
< numBytes
)
732 v
[0] = IROUND(map1d
->u1
);
733 v
[1] = IROUND(map1d
->u2
);
736 numBytes
= 4 * sizeof *v
;
737 if (bufSize
< numBytes
)
739 v
[0] = IROUND(map2d
->u1
);
740 v
[1] = IROUND(map2d
->u2
);
741 v
[2] = IROUND(map2d
->v1
);
742 v
[3] = IROUND(map2d
->v2
);
746 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapiv(query)" );
751 _mesa_error( ctx
, GL_INVALID_OPERATION
,
752 "glGetnMapivARB(out of bounds: bufSize is %d,"
753 " but %d bytes are required)", bufSize
, numBytes
);
758 _mesa_GetMapiv( GLenum target
, GLenum query
, GLint
*v
)
760 _mesa_GetnMapivARB(target
, query
, INT_MAX
, v
);
765 _mesa_MapGrid1f( GLint un
, GLfloat u1
, GLfloat u2
)
767 GET_CURRENT_CONTEXT(ctx
);
770 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid1f" );
773 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
774 ctx
->Eval
.MapGrid1un
= un
;
775 ctx
->Eval
.MapGrid1u1
= u1
;
776 ctx
->Eval
.MapGrid1u2
= u2
;
777 ctx
->Eval
.MapGrid1du
= (u2
- u1
) / (GLfloat
) un
;
782 _mesa_MapGrid1d( GLint un
, GLdouble u1
, GLdouble u2
)
784 _mesa_MapGrid1f( un
, (GLfloat
) u1
, (GLfloat
) u2
);
789 _mesa_MapGrid2f( GLint un
, GLfloat u1
, GLfloat u2
,
790 GLint vn
, GLfloat v1
, GLfloat v2
)
792 GET_CURRENT_CONTEXT(ctx
);
795 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid2f(un)" );
799 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid2f(vn)" );
803 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
804 ctx
->Eval
.MapGrid2un
= un
;
805 ctx
->Eval
.MapGrid2u1
= u1
;
806 ctx
->Eval
.MapGrid2u2
= u2
;
807 ctx
->Eval
.MapGrid2du
= (u2
- u1
) / (GLfloat
) un
;
808 ctx
->Eval
.MapGrid2vn
= vn
;
809 ctx
->Eval
.MapGrid2v1
= v1
;
810 ctx
->Eval
.MapGrid2v2
= v2
;
811 ctx
->Eval
.MapGrid2dv
= (v2
- v1
) / (GLfloat
) vn
;
816 _mesa_MapGrid2d( GLint un
, GLdouble u1
, GLdouble u2
,
817 GLint vn
, GLdouble v1
, GLdouble v2
)
819 _mesa_MapGrid2f( un
, (GLfloat
) u1
, (GLfloat
) u2
,
820 vn
, (GLfloat
) v1
, (GLfloat
) v2
);
825 _mesa_install_eval_vtxfmt(struct _glapi_table
*disp
,
826 const GLvertexformat
*vfmt
)
828 SET_EvalCoord1f(disp
, vfmt
->EvalCoord1f
);
829 SET_EvalCoord1fv(disp
, vfmt
->EvalCoord1fv
);
830 SET_EvalCoord2f(disp
, vfmt
->EvalCoord2f
);
831 SET_EvalCoord2fv(disp
, vfmt
->EvalCoord2fv
);
832 SET_EvalPoint1(disp
, vfmt
->EvalPoint1
);
833 SET_EvalPoint2(disp
, vfmt
->EvalPoint2
);
837 /**********************************************************************/
838 /***** Initialization *****/
839 /**********************************************************************/
842 * Initialize a 1-D evaluator map.
845 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
850 map
->Points
= malloc(n
* sizeof(GLfloat
));
854 map
->Points
[i
] = initial
[i
];
860 * Initialize a 2-D evaluator map
863 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
871 map
->Points
= malloc(n
* sizeof(GLfloat
));
875 map
->Points
[i
] = initial
[i
];
880 void _mesa_init_eval( struct gl_context
*ctx
)
882 /* Evaluators group */
883 ctx
->Eval
.Map1Color4
= GL_FALSE
;
884 ctx
->Eval
.Map1Index
= GL_FALSE
;
885 ctx
->Eval
.Map1Normal
= GL_FALSE
;
886 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
887 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
888 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
889 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
890 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
891 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
892 ctx
->Eval
.Map2Color4
= GL_FALSE
;
893 ctx
->Eval
.Map2Index
= GL_FALSE
;
894 ctx
->Eval
.Map2Normal
= GL_FALSE
;
895 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
896 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
897 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
898 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
899 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
900 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
901 ctx
->Eval
.AutoNormal
= GL_FALSE
;
902 ctx
->Eval
.MapGrid1un
= 1;
903 ctx
->Eval
.MapGrid1u1
= 0.0;
904 ctx
->Eval
.MapGrid1u2
= 1.0;
905 ctx
->Eval
.MapGrid2un
= 1;
906 ctx
->Eval
.MapGrid2vn
= 1;
907 ctx
->Eval
.MapGrid2u1
= 0.0;
908 ctx
->Eval
.MapGrid2u2
= 1.0;
909 ctx
->Eval
.MapGrid2v1
= 0.0;
910 ctx
->Eval
.MapGrid2v2
= 1.0;
914 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
915 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
916 static GLfloat index
[1] = { 1.0 };
917 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
918 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
920 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
921 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
922 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
923 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
924 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
925 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
926 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
927 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
928 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
930 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
931 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
932 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
933 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
934 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
935 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
936 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
937 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
938 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
943 void _mesa_free_eval_data( struct gl_context
*ctx
)
945 /* Free evaluator data */
946 free(ctx
->EvalMap
.Map1Vertex3
.Points
);
947 free(ctx
->EvalMap
.Map1Vertex4
.Points
);
948 free(ctx
->EvalMap
.Map1Index
.Points
);
949 free(ctx
->EvalMap
.Map1Color4
.Points
);
950 free(ctx
->EvalMap
.Map1Normal
.Points
);
951 free(ctx
->EvalMap
.Map1Texture1
.Points
);
952 free(ctx
->EvalMap
.Map1Texture2
.Points
);
953 free(ctx
->EvalMap
.Map1Texture3
.Points
);
954 free(ctx
->EvalMap
.Map1Texture4
.Points
);
956 free(ctx
->EvalMap
.Map2Vertex3
.Points
);
957 free(ctx
->EvalMap
.Map2Vertex4
.Points
);
958 free(ctx
->EvalMap
.Map2Index
.Points
);
959 free(ctx
->EvalMap
.Map2Color4
.Points
);
960 free(ctx
->EvalMap
.Map2Normal
.Points
);
961 free(ctx
->EvalMap
.Map2Texture1
.Points
);
962 free(ctx
->EvalMap
.Map2Texture2
.Points
);
963 free(ctx
->EvalMap
.Map2Texture3
.Points
);
964 free(ctx
->EvalMap
.Map2Texture4
.Points
);