3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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.
46 #include "mfeatures.h"
48 #include "main/dispatch.h"
51 #if FEATURE_evaluators
55 * Return the number of components per control point for any type of
56 * evaluator. Return 0 if bad target.
57 * See table 5.1 in the OpenGL 1.2 spec.
59 GLuint
_mesa_evaluator_components( GLenum target
)
62 case GL_MAP1_VERTEX_3
: return 3;
63 case GL_MAP1_VERTEX_4
: return 4;
64 case GL_MAP1_INDEX
: return 1;
65 case GL_MAP1_COLOR_4
: return 4;
66 case GL_MAP1_NORMAL
: return 3;
67 case GL_MAP1_TEXTURE_COORD_1
: return 1;
68 case GL_MAP1_TEXTURE_COORD_2
: return 2;
69 case GL_MAP1_TEXTURE_COORD_3
: return 3;
70 case GL_MAP1_TEXTURE_COORD_4
: return 4;
71 case GL_MAP2_VERTEX_3
: return 3;
72 case GL_MAP2_VERTEX_4
: return 4;
73 case GL_MAP2_INDEX
: return 1;
74 case GL_MAP2_COLOR_4
: return 4;
75 case GL_MAP2_NORMAL
: return 3;
76 case GL_MAP2_TEXTURE_COORD_1
: return 1;
77 case GL_MAP2_TEXTURE_COORD_2
: return 2;
78 case GL_MAP2_TEXTURE_COORD_3
: return 3;
79 case GL_MAP2_TEXTURE_COORD_4
: return 4;
83 /* XXX need to check for the vertex program extension
84 if (!ctx->Extensions.NV_vertex_program)
88 if (target
>= GL_MAP1_VERTEX_ATTRIB0_4_NV
&&
89 target
<= GL_MAP1_VERTEX_ATTRIB15_4_NV
)
92 if (target
>= GL_MAP2_VERTEX_ATTRIB0_4_NV
&&
93 target
<= GL_MAP2_VERTEX_ATTRIB15_4_NV
)
101 * Return pointer to the gl_1d_map struct for the named target.
103 static struct gl_1d_map
*
104 get_1d_map( struct gl_context
*ctx
, GLenum target
)
107 case GL_MAP1_VERTEX_3
:
108 return &ctx
->EvalMap
.Map1Vertex3
;
109 case GL_MAP1_VERTEX_4
:
110 return &ctx
->EvalMap
.Map1Vertex4
;
112 return &ctx
->EvalMap
.Map1Index
;
113 case GL_MAP1_COLOR_4
:
114 return &ctx
->EvalMap
.Map1Color4
;
116 return &ctx
->EvalMap
.Map1Normal
;
117 case GL_MAP1_TEXTURE_COORD_1
:
118 return &ctx
->EvalMap
.Map1Texture1
;
119 case GL_MAP1_TEXTURE_COORD_2
:
120 return &ctx
->EvalMap
.Map1Texture2
;
121 case GL_MAP1_TEXTURE_COORD_3
:
122 return &ctx
->EvalMap
.Map1Texture3
;
123 case GL_MAP1_TEXTURE_COORD_4
:
124 return &ctx
->EvalMap
.Map1Texture4
;
125 case GL_MAP1_VERTEX_ATTRIB0_4_NV
:
126 case GL_MAP1_VERTEX_ATTRIB1_4_NV
:
127 case GL_MAP1_VERTEX_ATTRIB2_4_NV
:
128 case GL_MAP1_VERTEX_ATTRIB3_4_NV
:
129 case GL_MAP1_VERTEX_ATTRIB4_4_NV
:
130 case GL_MAP1_VERTEX_ATTRIB5_4_NV
:
131 case GL_MAP1_VERTEX_ATTRIB6_4_NV
:
132 case GL_MAP1_VERTEX_ATTRIB7_4_NV
:
133 case GL_MAP1_VERTEX_ATTRIB8_4_NV
:
134 case GL_MAP1_VERTEX_ATTRIB9_4_NV
:
135 case GL_MAP1_VERTEX_ATTRIB10_4_NV
:
136 case GL_MAP1_VERTEX_ATTRIB11_4_NV
:
137 case GL_MAP1_VERTEX_ATTRIB12_4_NV
:
138 case GL_MAP1_VERTEX_ATTRIB13_4_NV
:
139 case GL_MAP1_VERTEX_ATTRIB14_4_NV
:
140 case GL_MAP1_VERTEX_ATTRIB15_4_NV
:
141 if (!ctx
->Extensions
.NV_vertex_program
)
143 return &ctx
->EvalMap
.Map1Attrib
[target
- GL_MAP1_VERTEX_ATTRIB0_4_NV
];
151 * Return pointer to the gl_2d_map struct for the named target.
153 static struct gl_2d_map
*
154 get_2d_map( struct gl_context
*ctx
, GLenum target
)
157 case GL_MAP2_VERTEX_3
:
158 return &ctx
->EvalMap
.Map2Vertex3
;
159 case GL_MAP2_VERTEX_4
:
160 return &ctx
->EvalMap
.Map2Vertex4
;
162 return &ctx
->EvalMap
.Map2Index
;
163 case GL_MAP2_COLOR_4
:
164 return &ctx
->EvalMap
.Map2Color4
;
166 return &ctx
->EvalMap
.Map2Normal
;
167 case GL_MAP2_TEXTURE_COORD_1
:
168 return &ctx
->EvalMap
.Map2Texture1
;
169 case GL_MAP2_TEXTURE_COORD_2
:
170 return &ctx
->EvalMap
.Map2Texture2
;
171 case GL_MAP2_TEXTURE_COORD_3
:
172 return &ctx
->EvalMap
.Map2Texture3
;
173 case GL_MAP2_TEXTURE_COORD_4
:
174 return &ctx
->EvalMap
.Map2Texture4
;
175 case GL_MAP2_VERTEX_ATTRIB0_4_NV
:
176 case GL_MAP2_VERTEX_ATTRIB1_4_NV
:
177 case GL_MAP2_VERTEX_ATTRIB2_4_NV
:
178 case GL_MAP2_VERTEX_ATTRIB3_4_NV
:
179 case GL_MAP2_VERTEX_ATTRIB4_4_NV
:
180 case GL_MAP2_VERTEX_ATTRIB5_4_NV
:
181 case GL_MAP2_VERTEX_ATTRIB6_4_NV
:
182 case GL_MAP2_VERTEX_ATTRIB7_4_NV
:
183 case GL_MAP2_VERTEX_ATTRIB8_4_NV
:
184 case GL_MAP2_VERTEX_ATTRIB9_4_NV
:
185 case GL_MAP2_VERTEX_ATTRIB10_4_NV
:
186 case GL_MAP2_VERTEX_ATTRIB11_4_NV
:
187 case GL_MAP2_VERTEX_ATTRIB12_4_NV
:
188 case GL_MAP2_VERTEX_ATTRIB13_4_NV
:
189 case GL_MAP2_VERTEX_ATTRIB14_4_NV
:
190 case GL_MAP2_VERTEX_ATTRIB15_4_NV
:
191 if (!ctx
->Extensions
.NV_vertex_program
)
193 return &ctx
->EvalMap
.Map2Attrib
[target
- GL_MAP2_VERTEX_ATTRIB0_4_NV
];
200 /**********************************************************************/
201 /*** Copy and deallocate control points ***/
202 /**********************************************************************/
206 * Copy 1-parametric evaluator control points from user-specified
207 * memory space to a buffer of contiguous control points.
208 * \param see glMap1f for details
209 * \return pointer to buffer of contiguous control points or NULL if out
212 GLfloat
*_mesa_copy_map_points1f( GLenum target
, GLint ustride
, GLint uorder
,
213 const GLfloat
*points
)
216 GLint i
, k
, size
= _mesa_evaluator_components(target
);
218 if (!points
|| !size
)
221 buffer
= (GLfloat
*) MALLOC(uorder
* size
* sizeof(GLfloat
));
224 for (i
= 0, p
= buffer
; i
< uorder
; i
++, points
+= ustride
)
225 for (k
= 0; k
< size
; k
++)
234 * Same as above but convert doubles to floats.
236 GLfloat
*_mesa_copy_map_points1d( GLenum target
, GLint ustride
, GLint uorder
,
237 const GLdouble
*points
)
240 GLint i
, k
, size
= _mesa_evaluator_components(target
);
242 if (!points
|| !size
)
245 buffer
= (GLfloat
*) MALLOC(uorder
* size
* sizeof(GLfloat
));
248 for (i
= 0, p
= buffer
; i
< uorder
; i
++, points
+= ustride
)
249 for (k
= 0; k
< size
; k
++)
250 *p
++ = (GLfloat
) points
[k
];
258 * Copy 2-parametric evaluator control points from user-specified
259 * memory space to a buffer of contiguous control points.
260 * Additional memory is allocated to be used by the horner and
261 * de Casteljau evaluation schemes.
263 * \param see glMap2f for details
264 * \return pointer to buffer of contiguous control points or NULL if out
267 GLfloat
*_mesa_copy_map_points2f( GLenum target
,
268 GLint ustride
, GLint uorder
,
269 GLint vstride
, GLint vorder
,
270 const GLfloat
*points
)
273 GLint i
, j
, k
, size
, dsize
, hsize
;
276 size
= _mesa_evaluator_components(target
);
278 if (!points
|| size
==0) {
282 /* max(uorder, vorder) additional points are used in */
283 /* horner evaluation and uorder*vorder additional */
284 /* values are needed for de Casteljau */
285 dsize
= (uorder
== 2 && vorder
== 2)? 0 : uorder
*vorder
;
286 hsize
= (uorder
> vorder
? uorder
: vorder
)*size
;
289 buffer
= (GLfloat
*) MALLOC((uorder
*vorder
*size
+hsize
)*sizeof(GLfloat
));
291 buffer
= (GLfloat
*) MALLOC((uorder
*vorder
*size
+dsize
)*sizeof(GLfloat
));
293 /* compute the increment value for the u-loop */
294 uinc
= ustride
- vorder
*vstride
;
297 for (i
=0, p
=buffer
; i
<uorder
; i
++, points
+= uinc
)
298 for (j
=0; j
<vorder
; j
++, points
+= vstride
)
299 for (k
=0; k
<size
; k
++)
308 * Same as above but convert doubles to floats.
310 GLfloat
*_mesa_copy_map_points2d(GLenum target
,
311 GLint ustride
, GLint uorder
,
312 GLint vstride
, GLint vorder
,
313 const GLdouble
*points
)
316 GLint i
, j
, k
, size
, hsize
, dsize
;
319 size
= _mesa_evaluator_components(target
);
321 if (!points
|| size
==0) {
325 /* max(uorder, vorder) additional points are used in */
326 /* horner evaluation and uorder*vorder additional */
327 /* values are needed for de Casteljau */
328 dsize
= (uorder
== 2 && vorder
== 2)? 0 : uorder
*vorder
;
329 hsize
= (uorder
> vorder
? uorder
: vorder
)*size
;
332 buffer
= (GLfloat
*) MALLOC((uorder
*vorder
*size
+hsize
)*sizeof(GLfloat
));
334 buffer
= (GLfloat
*) MALLOC((uorder
*vorder
*size
+dsize
)*sizeof(GLfloat
));
336 /* compute the increment value for the u-loop */
337 uinc
= ustride
- vorder
*vstride
;
340 for (i
=0, p
=buffer
; i
<uorder
; i
++, points
+= uinc
)
341 for (j
=0; j
<vorder
; j
++, points
+= vstride
)
342 for (k
=0; k
<size
; k
++)
343 *p
++ = (GLfloat
) points
[k
];
351 /**********************************************************************/
352 /*** API entry points ***/
353 /**********************************************************************/
357 * This does the work of glMap1[fd].
360 map1(GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustride
,
361 GLint uorder
, const GLvoid
*points
, GLenum type
)
363 GET_CURRENT_CONTEXT(ctx
);
366 struct gl_1d_map
*map
= NULL
;
368 ASSERT_OUTSIDE_BEGIN_END(ctx
);
369 ASSERT(type
== GL_FLOAT
|| type
== GL_DOUBLE
);
372 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(u1,u2)" );
375 if (uorder
< 1 || uorder
> MAX_EVAL_ORDER
) {
376 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(order)" );
380 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(points)" );
384 k
= _mesa_evaluator_components( target
);
386 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap1(target)" );
390 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap1(stride)" );
394 if (ctx
->Texture
.CurrentUnit
!= 0) {
395 /* See OpenGL 1.2.1 spec, section F.2.13 */
396 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glMap2(ACTIVE_TEXTURE != 0)" );
400 map
= get_1d_map(ctx
, target
);
402 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap1(target)" );
406 /* make copy of the control points */
407 if (type
== GL_FLOAT
)
408 pnts
= _mesa_copy_map_points1f(target
, ustride
, uorder
, (GLfloat
*) points
);
410 pnts
= _mesa_copy_map_points1d(target
, ustride
, uorder
, (GLdouble
*) points
);
413 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
417 map
->du
= 1.0F
/ (u2
- u1
);
425 static void GLAPIENTRY
426 _mesa_Map1f( GLenum target
, GLfloat u1
, GLfloat u2
, GLint stride
,
427 GLint order
, const GLfloat
*points
)
429 map1(target
, u1
, u2
, stride
, order
, points
, GL_FLOAT
);
433 static void GLAPIENTRY
434 _mesa_Map1d( GLenum target
, GLdouble u1
, GLdouble u2
, GLint stride
,
435 GLint order
, const GLdouble
*points
)
437 map1(target
, (GLfloat
) u1
, (GLfloat
) u2
, stride
, order
, points
, GL_DOUBLE
);
442 map2( GLenum target
, GLfloat u1
, GLfloat u2
, GLint ustride
, GLint uorder
,
443 GLfloat v1
, GLfloat v2
, GLint vstride
, GLint vorder
,
444 const GLvoid
*points
, GLenum type
)
446 GET_CURRENT_CONTEXT(ctx
);
449 struct gl_2d_map
*map
= NULL
;
451 ASSERT_OUTSIDE_BEGIN_END(ctx
);
452 ASSERT(type
== GL_FLOAT
|| type
== GL_DOUBLE
);
455 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(u1,u2)" );
460 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(v1,v2)" );
464 if (uorder
<1 || uorder
>MAX_EVAL_ORDER
) {
465 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(uorder)" );
469 if (vorder
<1 || vorder
>MAX_EVAL_ORDER
) {
470 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(vorder)" );
474 k
= _mesa_evaluator_components( target
);
476 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap2(target)" );
480 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(ustride)" );
484 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMap2(vstride)" );
488 if (ctx
->Texture
.CurrentUnit
!= 0) {
489 /* See OpenGL 1.2.1 spec, section F.2.13 */
490 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glMap2(ACTIVE_TEXTURE != 0)" );
494 map
= get_2d_map(ctx
, target
);
496 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMap2(target)" );
500 /* make copy of the control points */
501 if (type
== GL_FLOAT
)
502 pnts
= _mesa_copy_map_points2f(target
, ustride
, uorder
,
503 vstride
, vorder
, (GLfloat
*) points
);
505 pnts
= _mesa_copy_map_points2d(target
, ustride
, uorder
,
506 vstride
, vorder
, (GLdouble
*) points
);
509 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
510 map
->Uorder
= uorder
;
513 map
->du
= 1.0F
/ (u2
- u1
);
514 map
->Vorder
= vorder
;
517 map
->dv
= 1.0F
/ (v2
- v1
);
524 static void GLAPIENTRY
525 _mesa_Map2f( GLenum target
,
526 GLfloat u1
, GLfloat u2
, GLint ustride
, GLint uorder
,
527 GLfloat v1
, GLfloat v2
, GLint vstride
, GLint vorder
,
528 const GLfloat
*points
)
530 map2(target
, u1
, u2
, ustride
, uorder
, v1
, v2
, vstride
, vorder
,
535 static void GLAPIENTRY
536 _mesa_Map2d( GLenum target
,
537 GLdouble u1
, GLdouble u2
, GLint ustride
, GLint uorder
,
538 GLdouble v1
, GLdouble v2
, GLint vstride
, GLint vorder
,
539 const GLdouble
*points
)
541 map2(target
, (GLfloat
) u1
, (GLfloat
) u2
, ustride
, uorder
,
542 (GLfloat
) v1
, (GLfloat
) v2
, vstride
, vorder
, points
, GL_DOUBLE
);
547 static void GLAPIENTRY
548 _mesa_GetMapdv( GLenum target
, GLenum query
, GLdouble
*v
)
550 GET_CURRENT_CONTEXT(ctx
);
551 struct gl_1d_map
*map1d
;
552 struct gl_2d_map
*map2d
;
557 ASSERT_OUTSIDE_BEGIN_END(ctx
);
559 comps
= _mesa_evaluator_components(target
);
561 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapdv(target)" );
565 map1d
= get_1d_map(ctx
, target
);
566 map2d
= get_2d_map(ctx
, target
);
567 ASSERT(map1d
|| map2d
);
572 data
= map1d
->Points
;
573 n
= map1d
->Order
* comps
;
576 data
= map2d
->Points
;
577 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
587 v
[0] = (GLdouble
) map1d
->Order
;
590 v
[0] = (GLdouble
) map2d
->Uorder
;
591 v
[1] = (GLdouble
) map2d
->Vorder
;
596 v
[0] = (GLdouble
) map1d
->u1
;
597 v
[1] = (GLdouble
) map1d
->u2
;
600 v
[0] = (GLdouble
) map2d
->u1
;
601 v
[1] = (GLdouble
) map2d
->u2
;
602 v
[2] = (GLdouble
) map2d
->v1
;
603 v
[3] = (GLdouble
) map2d
->v2
;
607 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapdv(query)" );
612 static void GLAPIENTRY
613 _mesa_GetMapfv( GLenum target
, GLenum query
, GLfloat
*v
)
615 GET_CURRENT_CONTEXT(ctx
);
616 struct gl_1d_map
*map1d
;
617 struct gl_2d_map
*map2d
;
622 ASSERT_OUTSIDE_BEGIN_END(ctx
);
624 comps
= _mesa_evaluator_components(target
);
626 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapfv(target)" );
630 map1d
= get_1d_map(ctx
, target
);
631 map2d
= get_2d_map(ctx
, target
);
632 ASSERT(map1d
|| map2d
);
637 data
= map1d
->Points
;
638 n
= map1d
->Order
* comps
;
641 data
= map2d
->Points
;
642 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
652 v
[0] = (GLfloat
) map1d
->Order
;
655 v
[0] = (GLfloat
) map2d
->Uorder
;
656 v
[1] = (GLfloat
) map2d
->Vorder
;
672 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapfv(query)" );
677 static void GLAPIENTRY
678 _mesa_GetMapiv( GLenum target
, GLenum query
, GLint
*v
)
680 GET_CURRENT_CONTEXT(ctx
);
681 struct gl_1d_map
*map1d
;
682 struct gl_2d_map
*map2d
;
687 ASSERT_OUTSIDE_BEGIN_END(ctx
);
689 comps
= _mesa_evaluator_components(target
);
691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapiv(target)" );
695 map1d
= get_1d_map(ctx
, target
);
696 map2d
= get_2d_map(ctx
, target
);
697 ASSERT(map1d
|| map2d
);
702 data
= map1d
->Points
;
703 n
= map1d
->Order
* comps
;
706 data
= map2d
->Points
;
707 n
= map2d
->Uorder
* map2d
->Vorder
* comps
;
711 v
[i
] = IROUND(data
[i
]);
720 v
[0] = map2d
->Uorder
;
721 v
[1] = map2d
->Vorder
;
726 v
[0] = IROUND(map1d
->u1
);
727 v
[1] = IROUND(map1d
->u2
);
730 v
[0] = IROUND(map2d
->u1
);
731 v
[1] = IROUND(map2d
->u2
);
732 v
[2] = IROUND(map2d
->v1
);
733 v
[3] = IROUND(map2d
->v2
);
737 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMapiv(query)" );
743 static void GLAPIENTRY
744 _mesa_MapGrid1f( GLint un
, GLfloat u1
, GLfloat u2
)
746 GET_CURRENT_CONTEXT(ctx
);
747 ASSERT_OUTSIDE_BEGIN_END(ctx
);
750 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid1f" );
753 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
754 ctx
->Eval
.MapGrid1un
= un
;
755 ctx
->Eval
.MapGrid1u1
= u1
;
756 ctx
->Eval
.MapGrid1u2
= u2
;
757 ctx
->Eval
.MapGrid1du
= (u2
- u1
) / (GLfloat
) un
;
761 static void GLAPIENTRY
762 _mesa_MapGrid1d( GLint un
, GLdouble u1
, GLdouble u2
)
764 _mesa_MapGrid1f( un
, (GLfloat
) u1
, (GLfloat
) u2
);
768 static void GLAPIENTRY
769 _mesa_MapGrid2f( GLint un
, GLfloat u1
, GLfloat u2
,
770 GLint vn
, GLfloat v1
, GLfloat v2
)
772 GET_CURRENT_CONTEXT(ctx
);
773 ASSERT_OUTSIDE_BEGIN_END(ctx
);
776 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid2f(un)" );
780 _mesa_error( ctx
, GL_INVALID_VALUE
, "glMapGrid2f(vn)" );
784 FLUSH_VERTICES(ctx
, _NEW_EVAL
);
785 ctx
->Eval
.MapGrid2un
= un
;
786 ctx
->Eval
.MapGrid2u1
= u1
;
787 ctx
->Eval
.MapGrid2u2
= u2
;
788 ctx
->Eval
.MapGrid2du
= (u2
- u1
) / (GLfloat
) un
;
789 ctx
->Eval
.MapGrid2vn
= vn
;
790 ctx
->Eval
.MapGrid2v1
= v1
;
791 ctx
->Eval
.MapGrid2v2
= v2
;
792 ctx
->Eval
.MapGrid2dv
= (v2
- v1
) / (GLfloat
) vn
;
796 static void GLAPIENTRY
797 _mesa_MapGrid2d( GLint un
, GLdouble u1
, GLdouble u2
,
798 GLint vn
, GLdouble v1
, GLdouble v2
)
800 _mesa_MapGrid2f( un
, (GLfloat
) u1
, (GLfloat
) u2
,
801 vn
, (GLfloat
) v1
, (GLfloat
) v2
);
806 _mesa_install_eval_vtxfmt(struct _glapi_table
*disp
,
807 const GLvertexformat
*vfmt
)
809 SET_EvalCoord1f(disp
, vfmt
->EvalCoord1f
);
810 SET_EvalCoord1fv(disp
, vfmt
->EvalCoord1fv
);
811 SET_EvalCoord2f(disp
, vfmt
->EvalCoord2f
);
812 SET_EvalCoord2fv(disp
, vfmt
->EvalCoord2fv
);
813 SET_EvalPoint1(disp
, vfmt
->EvalPoint1
);
814 SET_EvalPoint2(disp
, vfmt
->EvalPoint2
);
816 SET_EvalMesh1(disp
, vfmt
->EvalMesh1
);
817 SET_EvalMesh2(disp
, vfmt
->EvalMesh2
);
822 _mesa_init_eval_dispatch(struct _glapi_table
*disp
)
824 SET_GetMapdv(disp
, _mesa_GetMapdv
);
825 SET_GetMapfv(disp
, _mesa_GetMapfv
);
826 SET_GetMapiv(disp
, _mesa_GetMapiv
);
827 SET_Map1d(disp
, _mesa_Map1d
);
828 SET_Map1f(disp
, _mesa_Map1f
);
829 SET_Map2d(disp
, _mesa_Map2d
);
830 SET_Map2f(disp
, _mesa_Map2f
);
831 SET_MapGrid1d(disp
, _mesa_MapGrid1d
);
832 SET_MapGrid1f(disp
, _mesa_MapGrid1f
);
833 SET_MapGrid2d(disp
, _mesa_MapGrid2d
);
834 SET_MapGrid2f(disp
, _mesa_MapGrid2f
);
838 #endif /* FEATURE_evaluators */
841 /**********************************************************************/
842 /***** Initialization *****/
843 /**********************************************************************/
846 * Initialize a 1-D evaluator map.
849 init_1d_map( struct gl_1d_map
*map
, int n
, const float *initial
)
854 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
858 map
->Points
[i
] = initial
[i
];
864 * Initialize a 2-D evaluator map
867 init_2d_map( struct gl_2d_map
*map
, int n
, const float *initial
)
875 map
->Points
= (GLfloat
*) MALLOC(n
* sizeof(GLfloat
));
879 map
->Points
[i
] = initial
[i
];
884 void _mesa_init_eval( struct gl_context
*ctx
)
888 /* Evaluators group */
889 ctx
->Eval
.Map1Color4
= GL_FALSE
;
890 ctx
->Eval
.Map1Index
= GL_FALSE
;
891 ctx
->Eval
.Map1Normal
= GL_FALSE
;
892 ctx
->Eval
.Map1TextureCoord1
= GL_FALSE
;
893 ctx
->Eval
.Map1TextureCoord2
= GL_FALSE
;
894 ctx
->Eval
.Map1TextureCoord3
= GL_FALSE
;
895 ctx
->Eval
.Map1TextureCoord4
= GL_FALSE
;
896 ctx
->Eval
.Map1Vertex3
= GL_FALSE
;
897 ctx
->Eval
.Map1Vertex4
= GL_FALSE
;
898 memset(ctx
->Eval
.Map1Attrib
, 0, sizeof(ctx
->Eval
.Map1Attrib
));
899 ctx
->Eval
.Map2Color4
= GL_FALSE
;
900 ctx
->Eval
.Map2Index
= GL_FALSE
;
901 ctx
->Eval
.Map2Normal
= GL_FALSE
;
902 ctx
->Eval
.Map2TextureCoord1
= GL_FALSE
;
903 ctx
->Eval
.Map2TextureCoord2
= GL_FALSE
;
904 ctx
->Eval
.Map2TextureCoord3
= GL_FALSE
;
905 ctx
->Eval
.Map2TextureCoord4
= GL_FALSE
;
906 ctx
->Eval
.Map2Vertex3
= GL_FALSE
;
907 ctx
->Eval
.Map2Vertex4
= GL_FALSE
;
908 memset(ctx
->Eval
.Map2Attrib
, 0, sizeof(ctx
->Eval
.Map2Attrib
));
909 ctx
->Eval
.AutoNormal
= GL_FALSE
;
910 ctx
->Eval
.MapGrid1un
= 1;
911 ctx
->Eval
.MapGrid1u1
= 0.0;
912 ctx
->Eval
.MapGrid1u2
= 1.0;
913 ctx
->Eval
.MapGrid2un
= 1;
914 ctx
->Eval
.MapGrid2vn
= 1;
915 ctx
->Eval
.MapGrid2u1
= 0.0;
916 ctx
->Eval
.MapGrid2u2
= 1.0;
917 ctx
->Eval
.MapGrid2v1
= 0.0;
918 ctx
->Eval
.MapGrid2v2
= 1.0;
922 static GLfloat vertex
[4] = { 0.0, 0.0, 0.0, 1.0 };
923 static GLfloat normal
[3] = { 0.0, 0.0, 1.0 };
924 static GLfloat index
[1] = { 1.0 };
925 static GLfloat color
[4] = { 1.0, 1.0, 1.0, 1.0 };
926 static GLfloat texcoord
[4] = { 0.0, 0.0, 0.0, 1.0 };
927 static GLfloat attrib
[4] = { 0.0, 0.0, 0.0, 1.0 };
929 init_1d_map( &ctx
->EvalMap
.Map1Vertex3
, 3, vertex
);
930 init_1d_map( &ctx
->EvalMap
.Map1Vertex4
, 4, vertex
);
931 init_1d_map( &ctx
->EvalMap
.Map1Index
, 1, index
);
932 init_1d_map( &ctx
->EvalMap
.Map1Color4
, 4, color
);
933 init_1d_map( &ctx
->EvalMap
.Map1Normal
, 3, normal
);
934 init_1d_map( &ctx
->EvalMap
.Map1Texture1
, 1, texcoord
);
935 init_1d_map( &ctx
->EvalMap
.Map1Texture2
, 2, texcoord
);
936 init_1d_map( &ctx
->EvalMap
.Map1Texture3
, 3, texcoord
);
937 init_1d_map( &ctx
->EvalMap
.Map1Texture4
, 4, texcoord
);
938 for (i
= 0; i
< 16; i
++)
939 init_1d_map( ctx
->EvalMap
.Map1Attrib
+ i
, 4, attrib
);
941 init_2d_map( &ctx
->EvalMap
.Map2Vertex3
, 3, vertex
);
942 init_2d_map( &ctx
->EvalMap
.Map2Vertex4
, 4, vertex
);
943 init_2d_map( &ctx
->EvalMap
.Map2Index
, 1, index
);
944 init_2d_map( &ctx
->EvalMap
.Map2Color4
, 4, color
);
945 init_2d_map( &ctx
->EvalMap
.Map2Normal
, 3, normal
);
946 init_2d_map( &ctx
->EvalMap
.Map2Texture1
, 1, texcoord
);
947 init_2d_map( &ctx
->EvalMap
.Map2Texture2
, 2, texcoord
);
948 init_2d_map( &ctx
->EvalMap
.Map2Texture3
, 3, texcoord
);
949 init_2d_map( &ctx
->EvalMap
.Map2Texture4
, 4, texcoord
);
950 for (i
= 0; i
< 16; i
++)
951 init_2d_map( ctx
->EvalMap
.Map2Attrib
+ i
, 4, attrib
);
956 void _mesa_free_eval_data( struct gl_context
*ctx
)
960 /* Free evaluator data */
961 if (ctx
->EvalMap
.Map1Vertex3
.Points
)
962 FREE( ctx
->EvalMap
.Map1Vertex3
.Points
);
963 if (ctx
->EvalMap
.Map1Vertex4
.Points
)
964 FREE( ctx
->EvalMap
.Map1Vertex4
.Points
);
965 if (ctx
->EvalMap
.Map1Index
.Points
)
966 FREE( ctx
->EvalMap
.Map1Index
.Points
);
967 if (ctx
->EvalMap
.Map1Color4
.Points
)
968 FREE( ctx
->EvalMap
.Map1Color4
.Points
);
969 if (ctx
->EvalMap
.Map1Normal
.Points
)
970 FREE( ctx
->EvalMap
.Map1Normal
.Points
);
971 if (ctx
->EvalMap
.Map1Texture1
.Points
)
972 FREE( ctx
->EvalMap
.Map1Texture1
.Points
);
973 if (ctx
->EvalMap
.Map1Texture2
.Points
)
974 FREE( ctx
->EvalMap
.Map1Texture2
.Points
);
975 if (ctx
->EvalMap
.Map1Texture3
.Points
)
976 FREE( ctx
->EvalMap
.Map1Texture3
.Points
);
977 if (ctx
->EvalMap
.Map1Texture4
.Points
)
978 FREE( ctx
->EvalMap
.Map1Texture4
.Points
);
979 for (i
= 0; i
< 16; i
++)
980 FREE((ctx
->EvalMap
.Map1Attrib
[i
].Points
));
982 if (ctx
->EvalMap
.Map2Vertex3
.Points
)
983 FREE( ctx
->EvalMap
.Map2Vertex3
.Points
);
984 if (ctx
->EvalMap
.Map2Vertex4
.Points
)
985 FREE( ctx
->EvalMap
.Map2Vertex4
.Points
);
986 if (ctx
->EvalMap
.Map2Index
.Points
)
987 FREE( ctx
->EvalMap
.Map2Index
.Points
);
988 if (ctx
->EvalMap
.Map2Color4
.Points
)
989 FREE( ctx
->EvalMap
.Map2Color4
.Points
);
990 if (ctx
->EvalMap
.Map2Normal
.Points
)
991 FREE( ctx
->EvalMap
.Map2Normal
.Points
);
992 if (ctx
->EvalMap
.Map2Texture1
.Points
)
993 FREE( ctx
->EvalMap
.Map2Texture1
.Points
);
994 if (ctx
->EvalMap
.Map2Texture2
.Points
)
995 FREE( ctx
->EvalMap
.Map2Texture2
.Points
);
996 if (ctx
->EvalMap
.Map2Texture3
.Points
)
997 FREE( ctx
->EvalMap
.Map2Texture3
.Points
);
998 if (ctx
->EvalMap
.Map2Texture4
.Points
)
999 FREE( ctx
->EvalMap
.Map2Texture4
.Points
);
1000 for (i
= 0; i
< 16; i
++)
1001 FREE((ctx
->EvalMap
.Map2Attrib
[i
].Points
));