17117f1b4Smrg
27117f1b4Smrg/*
37117f1b4Smrg * Mesa 3-D graphics library
47117f1b4Smrg *
57117f1b4Smrg * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
67117f1b4Smrg *
77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
87117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
97117f1b4Smrg * to deal in the Software without restriction, including without limitation
107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
127117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
137117f1b4Smrg *
147117f1b4Smrg * The above copyright notice and this permission notice shall be included
157117f1b4Smrg * in all copies or substantial portions of the Software.
167117f1b4Smrg *
177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
247117f1b4Smrg */
257117f1b4Smrg
267117f1b4Smrg
277117f1b4Smrg/*
287117f1b4Smrg * eval.c was written by
297117f1b4Smrg * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and
307117f1b4Smrg * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de).
317117f1b4Smrg *
327117f1b4Smrg * My original implementation of evaluators was simplistic and didn't
337117f1b4Smrg * compute surface normal vectors properly.  Bernd and Volker applied
347117f1b4Smrg * used more sophisticated methods to get better results.
357117f1b4Smrg *
367117f1b4Smrg * Thanks guys!
377117f1b4Smrg */
387117f1b4Smrg
397117f1b4Smrg
407117f1b4Smrg#include "glheader.h"
417117f1b4Smrg#include "context.h"
427117f1b4Smrg#include "eval.h"
437117f1b4Smrg#include "macros.h"
447117f1b4Smrg#include "mtypes.h"
45cdc920a0Smrg#include "main/dispatch.h"
464a49301eSmrg
474a49301eSmrg
487117f1b4Smrg/*
497117f1b4Smrg * Return the number of components per control point for any type of
507117f1b4Smrg * evaluator.  Return 0 if bad target.
517117f1b4Smrg * See table 5.1 in the OpenGL 1.2 spec.
527117f1b4Smrg */
537117f1b4SmrgGLuint _mesa_evaluator_components( GLenum target )
547117f1b4Smrg{
557117f1b4Smrg   switch (target) {
567117f1b4Smrg      case GL_MAP1_VERTEX_3:		return 3;
577117f1b4Smrg      case GL_MAP1_VERTEX_4:		return 4;
587117f1b4Smrg      case GL_MAP1_INDEX:		return 1;
597117f1b4Smrg      case GL_MAP1_COLOR_4:		return 4;
607117f1b4Smrg      case GL_MAP1_NORMAL:		return 3;
617117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_1:	return 1;
627117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_2:	return 2;
637117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_3:	return 3;
647117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_4:	return 4;
657117f1b4Smrg      case GL_MAP2_VERTEX_3:		return 3;
667117f1b4Smrg      case GL_MAP2_VERTEX_4:		return 4;
677117f1b4Smrg      case GL_MAP2_INDEX:		return 1;
687117f1b4Smrg      case GL_MAP2_COLOR_4:		return 4;
697117f1b4Smrg      case GL_MAP2_NORMAL:		return 3;
707117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_1:	return 1;
717117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_2:	return 2;
727117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_3:	return 3;
737117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_4:	return 4;
747117f1b4Smrg      default:				break;
757117f1b4Smrg   }
767117f1b4Smrg
777117f1b4Smrg   return 0;
787117f1b4Smrg}
797117f1b4Smrg
807117f1b4Smrg
817117f1b4Smrg/*
827117f1b4Smrg * Return pointer to the gl_1d_map struct for the named target.
837117f1b4Smrg */
847117f1b4Smrgstatic struct gl_1d_map *
853464ebd5Sriastradhget_1d_map( struct gl_context *ctx, GLenum target )
867117f1b4Smrg{
877117f1b4Smrg   switch (target) {
887117f1b4Smrg      case GL_MAP1_VERTEX_3:
897117f1b4Smrg         return &ctx->EvalMap.Map1Vertex3;
907117f1b4Smrg      case GL_MAP1_VERTEX_4:
917117f1b4Smrg         return &ctx->EvalMap.Map1Vertex4;
927117f1b4Smrg      case GL_MAP1_INDEX:
937117f1b4Smrg         return &ctx->EvalMap.Map1Index;
947117f1b4Smrg      case GL_MAP1_COLOR_4:
957117f1b4Smrg         return &ctx->EvalMap.Map1Color4;
967117f1b4Smrg      case GL_MAP1_NORMAL:
977117f1b4Smrg         return &ctx->EvalMap.Map1Normal;
987117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_1:
997117f1b4Smrg         return &ctx->EvalMap.Map1Texture1;
1007117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_2:
1017117f1b4Smrg         return &ctx->EvalMap.Map1Texture2;
1027117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_3:
1037117f1b4Smrg         return &ctx->EvalMap.Map1Texture3;
1047117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_4:
1057117f1b4Smrg         return &ctx->EvalMap.Map1Texture4;
1067117f1b4Smrg      default:
1077117f1b4Smrg         return NULL;
1087117f1b4Smrg   }
1097117f1b4Smrg}
1107117f1b4Smrg
1117117f1b4Smrg
1127117f1b4Smrg/*
1137117f1b4Smrg * Return pointer to the gl_2d_map struct for the named target.
1147117f1b4Smrg */
1157117f1b4Smrgstatic struct gl_2d_map *
1163464ebd5Sriastradhget_2d_map( struct gl_context *ctx, GLenum target )
1177117f1b4Smrg{
1187117f1b4Smrg   switch (target) {
1197117f1b4Smrg      case GL_MAP2_VERTEX_3:
1207117f1b4Smrg         return &ctx->EvalMap.Map2Vertex3;
1217117f1b4Smrg      case GL_MAP2_VERTEX_4:
1227117f1b4Smrg         return &ctx->EvalMap.Map2Vertex4;
1237117f1b4Smrg      case GL_MAP2_INDEX:
1247117f1b4Smrg         return &ctx->EvalMap.Map2Index;
1257117f1b4Smrg      case GL_MAP2_COLOR_4:
1267117f1b4Smrg         return &ctx->EvalMap.Map2Color4;
1277117f1b4Smrg      case GL_MAP2_NORMAL:
1287117f1b4Smrg         return &ctx->EvalMap.Map2Normal;
1297117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_1:
1307117f1b4Smrg         return &ctx->EvalMap.Map2Texture1;
1317117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_2:
1327117f1b4Smrg         return &ctx->EvalMap.Map2Texture2;
1337117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_3:
1347117f1b4Smrg         return &ctx->EvalMap.Map2Texture3;
1357117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_4:
1367117f1b4Smrg         return &ctx->EvalMap.Map2Texture4;
1377117f1b4Smrg      default:
1387117f1b4Smrg         return NULL;
1397117f1b4Smrg   }
1407117f1b4Smrg}
1417117f1b4Smrg
1427117f1b4Smrg
1437117f1b4Smrg/**********************************************************************/
1447117f1b4Smrg/***            Copy and deallocate control points                  ***/
1457117f1b4Smrg/**********************************************************************/
1467117f1b4Smrg
1477117f1b4Smrg
1487117f1b4Smrg/*
1497117f1b4Smrg * Copy 1-parametric evaluator control points from user-specified
1507117f1b4Smrg * memory space to a buffer of contiguous control points.
1517117f1b4Smrg * \param see glMap1f for details
1527117f1b4Smrg * \return pointer to buffer of contiguous control points or NULL if out
1537117f1b4Smrg *          of memory.
1547117f1b4Smrg */
1557117f1b4SmrgGLfloat *_mesa_copy_map_points1f( GLenum target, GLint ustride, GLint uorder,
1567117f1b4Smrg                                  const GLfloat *points )
1577117f1b4Smrg{
1587117f1b4Smrg   GLfloat *buffer, *p;
1597117f1b4Smrg   GLint i, k, size = _mesa_evaluator_components(target);
1607117f1b4Smrg
1617117f1b4Smrg   if (!points || !size)
1627117f1b4Smrg      return NULL;
1637117f1b4Smrg
164af69d88dSmrg   buffer = malloc(uorder * size * sizeof(GLfloat));
1657117f1b4Smrg
1667117f1b4Smrg   if (buffer)
1677117f1b4Smrg      for (i = 0, p = buffer; i < uorder; i++, points += ustride)
1687117f1b4Smrg	for (k = 0; k < size; k++)
1697117f1b4Smrg	  *p++ = points[k];
1707117f1b4Smrg
1717117f1b4Smrg   return buffer;
1727117f1b4Smrg}
1737117f1b4Smrg
1747117f1b4Smrg
1757117f1b4Smrg
1767117f1b4Smrg/*
1777117f1b4Smrg * Same as above but convert doubles to floats.
1787117f1b4Smrg */
1797117f1b4SmrgGLfloat *_mesa_copy_map_points1d( GLenum target, GLint ustride, GLint uorder,
1807117f1b4Smrg                                  const GLdouble *points )
1817117f1b4Smrg{
1827117f1b4Smrg   GLfloat *buffer, *p;
1837117f1b4Smrg   GLint i, k, size = _mesa_evaluator_components(target);
1847117f1b4Smrg
1857117f1b4Smrg   if (!points || !size)
1867117f1b4Smrg      return NULL;
1877117f1b4Smrg
188af69d88dSmrg   buffer = malloc(uorder * size * sizeof(GLfloat));
1897117f1b4Smrg
1907117f1b4Smrg   if (buffer)
1917117f1b4Smrg      for (i = 0, p = buffer; i < uorder; i++, points += ustride)
1927117f1b4Smrg	for (k = 0; k < size; k++)
1937117f1b4Smrg	  *p++ = (GLfloat) points[k];
1947117f1b4Smrg
1957117f1b4Smrg   return buffer;
1967117f1b4Smrg}
1977117f1b4Smrg
1987117f1b4Smrg
1997117f1b4Smrg
2007117f1b4Smrg/*
2017117f1b4Smrg * Copy 2-parametric evaluator control points from user-specified
2027117f1b4Smrg * memory space to a buffer of contiguous control points.
2037117f1b4Smrg * Additional memory is allocated to be used by the horner and
2047117f1b4Smrg * de Casteljau evaluation schemes.
2057117f1b4Smrg *
2067117f1b4Smrg * \param see glMap2f for details
2077117f1b4Smrg * \return pointer to buffer of contiguous control points or NULL if out
2087117f1b4Smrg *          of memory.
2097117f1b4Smrg */
2107117f1b4SmrgGLfloat *_mesa_copy_map_points2f( GLenum target,
2117117f1b4Smrg                                  GLint ustride, GLint uorder,
2127117f1b4Smrg                                  GLint vstride, GLint vorder,
2137117f1b4Smrg                                  const GLfloat *points )
2147117f1b4Smrg{
2157117f1b4Smrg   GLfloat *buffer, *p;
2167117f1b4Smrg   GLint i, j, k, size, dsize, hsize;
2177117f1b4Smrg   GLint uinc;
2187117f1b4Smrg
2197117f1b4Smrg   size = _mesa_evaluator_components(target);
2207117f1b4Smrg
2217117f1b4Smrg   if (!points || size==0) {
2227117f1b4Smrg      return NULL;
2237117f1b4Smrg   }
2247117f1b4Smrg
2257117f1b4Smrg   /* max(uorder, vorder) additional points are used in      */
2267117f1b4Smrg   /* horner evaluation and uorder*vorder additional */
2277117f1b4Smrg   /* values are needed for de Casteljau                     */
2287117f1b4Smrg   dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
2297117f1b4Smrg   hsize = (uorder > vorder ? uorder : vorder)*size;
2307117f1b4Smrg
2317117f1b4Smrg   if(hsize>dsize)
232af69d88dSmrg     buffer = malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
2337117f1b4Smrg   else
234af69d88dSmrg     buffer = malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
2357117f1b4Smrg
2367117f1b4Smrg   /* compute the increment value for the u-loop */
2377117f1b4Smrg   uinc = ustride - vorder*vstride;
2387117f1b4Smrg
2397117f1b4Smrg   if (buffer)
2407117f1b4Smrg      for (i=0, p=buffer; i<uorder; i++, points += uinc)
2417117f1b4Smrg	 for (j=0; j<vorder; j++, points += vstride)
2427117f1b4Smrg	    for (k=0; k<size; k++)
2437117f1b4Smrg	       *p++ = points[k];
2447117f1b4Smrg
2457117f1b4Smrg   return buffer;
2467117f1b4Smrg}
2477117f1b4Smrg
2487117f1b4Smrg
2497117f1b4Smrg
2507117f1b4Smrg/*
2517117f1b4Smrg * Same as above but convert doubles to floats.
2527117f1b4Smrg */
2537117f1b4SmrgGLfloat *_mesa_copy_map_points2d(GLenum target,
2547117f1b4Smrg                                 GLint ustride, GLint uorder,
2557117f1b4Smrg                                 GLint vstride, GLint vorder,
2567117f1b4Smrg                                 const GLdouble *points )
2577117f1b4Smrg{
2587117f1b4Smrg   GLfloat *buffer, *p;
2597117f1b4Smrg   GLint i, j, k, size, hsize, dsize;
2607117f1b4Smrg   GLint uinc;
2617117f1b4Smrg
2627117f1b4Smrg   size = _mesa_evaluator_components(target);
2637117f1b4Smrg
2647117f1b4Smrg   if (!points || size==0) {
2657117f1b4Smrg      return NULL;
2667117f1b4Smrg   }
2677117f1b4Smrg
2687117f1b4Smrg   /* max(uorder, vorder) additional points are used in      */
2697117f1b4Smrg   /* horner evaluation and uorder*vorder additional */
2707117f1b4Smrg   /* values are needed for de Casteljau                     */
2717117f1b4Smrg   dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
2727117f1b4Smrg   hsize = (uorder > vorder ? uorder : vorder)*size;
2737117f1b4Smrg
2747117f1b4Smrg   if(hsize>dsize)
275af69d88dSmrg     buffer = malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
2767117f1b4Smrg   else
277af69d88dSmrg     buffer = malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
2787117f1b4Smrg
2797117f1b4Smrg   /* compute the increment value for the u-loop */
2807117f1b4Smrg   uinc = ustride - vorder*vstride;
2817117f1b4Smrg
2827117f1b4Smrg   if (buffer)
2837117f1b4Smrg      for (i=0, p=buffer; i<uorder; i++, points += uinc)
2847117f1b4Smrg	 for (j=0; j<vorder; j++, points += vstride)
2857117f1b4Smrg	    for (k=0; k<size; k++)
2867117f1b4Smrg	       *p++ = (GLfloat) points[k];
2877117f1b4Smrg
2887117f1b4Smrg   return buffer;
2897117f1b4Smrg}
2907117f1b4Smrg
2917117f1b4Smrg
2927117f1b4Smrg
2937117f1b4Smrg
2947117f1b4Smrg/**********************************************************************/
2957117f1b4Smrg/***                      API entry points                          ***/
2967117f1b4Smrg/**********************************************************************/
2977117f1b4Smrg
2987117f1b4Smrg
2997117f1b4Smrg/*
3007117f1b4Smrg * This does the work of glMap1[fd].
3017117f1b4Smrg */
3027117f1b4Smrgstatic void
3037117f1b4Smrgmap1(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
3047117f1b4Smrg     GLint uorder, const GLvoid *points, GLenum type )
3057117f1b4Smrg{
3067117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3077117f1b4Smrg   GLint k;
3087117f1b4Smrg   GLfloat *pnts;
3097117f1b4Smrg   struct gl_1d_map *map = NULL;
3107117f1b4Smrg
31101e04c3fSmrg   assert(type == GL_FLOAT || type == GL_DOUBLE);
3127117f1b4Smrg
3137117f1b4Smrg   if (u1 == u2) {
3147117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(u1,u2)" );
3157117f1b4Smrg      return;
3167117f1b4Smrg   }
3177117f1b4Smrg   if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
3187117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(order)" );
3197117f1b4Smrg      return;
3207117f1b4Smrg   }
3217117f1b4Smrg   if (!points) {
3227117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(points)" );
3237117f1b4Smrg      return;
3247117f1b4Smrg   }
3257117f1b4Smrg
3267117f1b4Smrg   k = _mesa_evaluator_components( target );
3277117f1b4Smrg   if (k == 0) {
3287117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" );
329af69d88dSmrg      return;
3307117f1b4Smrg   }
3317117f1b4Smrg
3327117f1b4Smrg   if (ustride < k) {
3337117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(stride)" );
3347117f1b4Smrg      return;
3357117f1b4Smrg   }
3367117f1b4Smrg
3377117f1b4Smrg   if (ctx->Texture.CurrentUnit != 0) {
3387117f1b4Smrg      /* See OpenGL 1.2.1 spec, section F.2.13 */
3397117f1b4Smrg      _mesa_error( ctx, GL_INVALID_OPERATION, "glMap2(ACTIVE_TEXTURE != 0)" );
3407117f1b4Smrg      return;
3417117f1b4Smrg   }
3427117f1b4Smrg
3437117f1b4Smrg   map = get_1d_map(ctx, target);
3447117f1b4Smrg   if (!map) {
3457117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" );
3467117f1b4Smrg      return;
3477117f1b4Smrg   }
3487117f1b4Smrg
3497117f1b4Smrg   /* make copy of the control points */
3507117f1b4Smrg   if (type == GL_FLOAT)
3517117f1b4Smrg      pnts = _mesa_copy_map_points1f(target, ustride, uorder, (GLfloat*) points);
3527117f1b4Smrg   else
3537117f1b4Smrg      pnts = _mesa_copy_map_points1d(target, ustride, uorder, (GLdouble*) points);
3547117f1b4Smrg
3557117f1b4Smrg
3567ec681f3Smrg   FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT);
3577ec681f3Smrg   vbo_exec_update_eval_maps(ctx);
3587117f1b4Smrg   map->Order = uorder;
3597117f1b4Smrg   map->u1 = u1;
3607117f1b4Smrg   map->u2 = u2;
3617117f1b4Smrg   map->du = 1.0F / (u2 - u1);
362af69d88dSmrg   free(map->Points);
3637117f1b4Smrg   map->Points = pnts;
3647117f1b4Smrg}
3657117f1b4Smrg
3667117f1b4Smrg
3677117f1b4Smrg
368af69d88dSmrgvoid GLAPIENTRY
3697117f1b4Smrg_mesa_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
3707117f1b4Smrg             GLint order, const GLfloat *points )
3717117f1b4Smrg{
3727117f1b4Smrg   map1(target, u1, u2, stride, order, points, GL_FLOAT);
3737117f1b4Smrg}
3747117f1b4Smrg
3757117f1b4Smrg
376af69d88dSmrgvoid GLAPIENTRY
3777117f1b4Smrg_mesa_Map1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
3787117f1b4Smrg             GLint order, const GLdouble *points )
3797117f1b4Smrg{
3807117f1b4Smrg   map1(target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
3817117f1b4Smrg}
3827117f1b4Smrg
3837117f1b4Smrg
3847117f1b4Smrgstatic void
3857117f1b4Smrgmap2( GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
3867117f1b4Smrg      GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
3877117f1b4Smrg      const GLvoid *points, GLenum type )
3887117f1b4Smrg{
3897117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3907117f1b4Smrg   GLint k;
3917117f1b4Smrg   GLfloat *pnts;
3927117f1b4Smrg   struct gl_2d_map *map = NULL;
3937117f1b4Smrg
39401e04c3fSmrg   assert(type == GL_FLOAT || type == GL_DOUBLE);
3957117f1b4Smrg
3967117f1b4Smrg   if (u1==u2) {
3977117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(u1,u2)" );
3987117f1b4Smrg      return;
3997117f1b4Smrg   }
4007117f1b4Smrg
4017117f1b4Smrg   if (v1==v2) {
4027117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(v1,v2)" );
4037117f1b4Smrg      return;
4047117f1b4Smrg   }
4057117f1b4Smrg
4067117f1b4Smrg   if (uorder<1 || uorder>MAX_EVAL_ORDER) {
4077117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(uorder)" );
4087117f1b4Smrg      return;
4097117f1b4Smrg   }
4107117f1b4Smrg
4117117f1b4Smrg   if (vorder<1 || vorder>MAX_EVAL_ORDER) {
4127117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(vorder)" );
4137117f1b4Smrg      return;
4147117f1b4Smrg   }
4157117f1b4Smrg
4167117f1b4Smrg   k = _mesa_evaluator_components( target );
4177117f1b4Smrg   if (k==0) {
4187117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap2(target)" );
419af69d88dSmrg      return;
4207117f1b4Smrg   }
4217117f1b4Smrg
4227117f1b4Smrg   if (ustride < k) {
4237117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(ustride)" );
4247117f1b4Smrg      return;
4257117f1b4Smrg   }
4267117f1b4Smrg   if (vstride < k) {
4277117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap2(vstride)" );
4287117f1b4Smrg      return;
4297117f1b4Smrg   }
4307117f1b4Smrg
4317117f1b4Smrg   if (ctx->Texture.CurrentUnit != 0) {
4327117f1b4Smrg      /* See OpenGL 1.2.1 spec, section F.2.13 */
4337117f1b4Smrg      _mesa_error( ctx, GL_INVALID_OPERATION, "glMap2(ACTIVE_TEXTURE != 0)" );
4347117f1b4Smrg      return;
4357117f1b4Smrg   }
4367117f1b4Smrg
4377117f1b4Smrg   map = get_2d_map(ctx, target);
4387117f1b4Smrg   if (!map) {
4397117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap2(target)" );
4407117f1b4Smrg      return;
4417117f1b4Smrg   }
4427117f1b4Smrg
4437117f1b4Smrg   /* make copy of the control points */
4447117f1b4Smrg   if (type == GL_FLOAT)
4457117f1b4Smrg      pnts = _mesa_copy_map_points2f(target, ustride, uorder,
4467117f1b4Smrg                                  vstride, vorder, (GLfloat*) points);
4477117f1b4Smrg   else
4487117f1b4Smrg      pnts = _mesa_copy_map_points2d(target, ustride, uorder,
4497117f1b4Smrg                                  vstride, vorder, (GLdouble*) points);
4507117f1b4Smrg
4517117f1b4Smrg
4527ec681f3Smrg   FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT);
4537ec681f3Smrg   vbo_exec_update_eval_maps(ctx);
4547117f1b4Smrg   map->Uorder = uorder;
4557117f1b4Smrg   map->u1 = u1;
4567117f1b4Smrg   map->u2 = u2;
4577117f1b4Smrg   map->du = 1.0F / (u2 - u1);
4587117f1b4Smrg   map->Vorder = vorder;
4597117f1b4Smrg   map->v1 = v1;
4607117f1b4Smrg   map->v2 = v2;
4617117f1b4Smrg   map->dv = 1.0F / (v2 - v1);
462af69d88dSmrg   free(map->Points);
4637117f1b4Smrg   map->Points = pnts;
4647117f1b4Smrg}
4657117f1b4Smrg
4667117f1b4Smrg
467af69d88dSmrgvoid GLAPIENTRY
4687117f1b4Smrg_mesa_Map2f( GLenum target,
4697117f1b4Smrg             GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
4707117f1b4Smrg             GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
4717117f1b4Smrg             const GLfloat *points)
4727117f1b4Smrg{
4737117f1b4Smrg   map2(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
4747117f1b4Smrg        points, GL_FLOAT);
4757117f1b4Smrg}
4767117f1b4Smrg
4777117f1b4Smrg
478af69d88dSmrgvoid GLAPIENTRY
4797117f1b4Smrg_mesa_Map2d( GLenum target,
4807117f1b4Smrg             GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
4817117f1b4Smrg             GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
4827117f1b4Smrg             const GLdouble *points )
4837117f1b4Smrg{
4847ec681f3Smrg   map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
4857117f1b4Smrg	(GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
4867117f1b4Smrg}
4877117f1b4Smrg
4887117f1b4Smrg
4897117f1b4Smrg
490af69d88dSmrgvoid GLAPIENTRY
4913464ebd5Sriastradh_mesa_GetnMapdvARB( GLenum target, GLenum query, GLsizei bufSize, GLdouble *v )
4927117f1b4Smrg{
4937117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
4947117f1b4Smrg   struct gl_1d_map *map1d;
4957117f1b4Smrg   struct gl_2d_map *map2d;
4967117f1b4Smrg   GLint i, n;
4977117f1b4Smrg   GLfloat *data;
4987117f1b4Smrg   GLuint comps;
4993464ebd5Sriastradh   GLsizei numBytes;
5007117f1b4Smrg
5017117f1b4Smrg   comps = _mesa_evaluator_components(target);
5027117f1b4Smrg   if (!comps) {
5037117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(target)" );
5047117f1b4Smrg      return;
5057117f1b4Smrg   }
5067117f1b4Smrg
5077117f1b4Smrg   map1d = get_1d_map(ctx, target);
5087117f1b4Smrg   map2d = get_2d_map(ctx, target);
50901e04c3fSmrg   assert(map1d || map2d);
5107117f1b4Smrg
5117117f1b4Smrg   switch (query) {
5127117f1b4Smrg      case GL_COEFF:
5137117f1b4Smrg         if (map1d) {
5147117f1b4Smrg            data = map1d->Points;
5157117f1b4Smrg            n = map1d->Order * comps;
5167117f1b4Smrg         }
5177117f1b4Smrg         else {
5187117f1b4Smrg            data = map2d->Points;
5197117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
5207117f1b4Smrg         }
5217117f1b4Smrg	 if (data) {
5223464ebd5Sriastradh            numBytes = n * sizeof *v;
5233464ebd5Sriastradh            if (bufSize < numBytes)
5243464ebd5Sriastradh               goto overflow;
5257117f1b4Smrg	    for (i=0;i<n;i++) {
5267117f1b4Smrg	       v[i] = data[i];
5277117f1b4Smrg	    }
5287117f1b4Smrg	 }
5297117f1b4Smrg         break;
5307117f1b4Smrg      case GL_ORDER:
5317117f1b4Smrg         if (map1d) {
5323464ebd5Sriastradh            numBytes = 1 * sizeof *v;
5333464ebd5Sriastradh            if (bufSize < numBytes)
5343464ebd5Sriastradh               goto overflow;
5357117f1b4Smrg            v[0] = (GLdouble) map1d->Order;
5367117f1b4Smrg         }
5377117f1b4Smrg         else {
5383464ebd5Sriastradh            numBytes = 2 * sizeof *v;
5393464ebd5Sriastradh            if (bufSize < numBytes)
5403464ebd5Sriastradh               goto overflow;
5417117f1b4Smrg            v[0] = (GLdouble) map2d->Uorder;
5427117f1b4Smrg            v[1] = (GLdouble) map2d->Vorder;
5437117f1b4Smrg         }
5447117f1b4Smrg         break;
5457117f1b4Smrg      case GL_DOMAIN:
5467117f1b4Smrg         if (map1d) {
5473464ebd5Sriastradh            numBytes = 2 * sizeof *v;
5483464ebd5Sriastradh            if (bufSize < numBytes)
5493464ebd5Sriastradh              goto overflow;
5507117f1b4Smrg            v[0] = (GLdouble) map1d->u1;
5517117f1b4Smrg            v[1] = (GLdouble) map1d->u2;
5527117f1b4Smrg         }
5537117f1b4Smrg         else {
5543464ebd5Sriastradh            numBytes = 4 * sizeof *v;
5553464ebd5Sriastradh            if (bufSize < numBytes)
5563464ebd5Sriastradh               goto overflow;
5577117f1b4Smrg            v[0] = (GLdouble) map2d->u1;
5587117f1b4Smrg            v[1] = (GLdouble) map2d->u2;
5597117f1b4Smrg            v[2] = (GLdouble) map2d->v1;
5607117f1b4Smrg            v[3] = (GLdouble) map2d->v2;
5617117f1b4Smrg         }
5627117f1b4Smrg         break;
5637117f1b4Smrg      default:
5647117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(query)" );
5657117f1b4Smrg   }
5663464ebd5Sriastradh   return;
5673464ebd5Sriastradh
5683464ebd5Sriastradhoverflow:
5693464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
5703464ebd5Sriastradh               "glGetnMapdvARB(out of bounds: bufSize is %d,"
5713464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
5727117f1b4Smrg}
5737117f1b4Smrg
574af69d88dSmrgvoid GLAPIENTRY
5753464ebd5Sriastradh_mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
5763464ebd5Sriastradh{
5773464ebd5Sriastradh   _mesa_GetnMapdvARB(target, query, INT_MAX, v);
5783464ebd5Sriastradh}
5797117f1b4Smrg
580af69d88dSmrgvoid GLAPIENTRY
5813464ebd5Sriastradh_mesa_GetnMapfvARB( GLenum target, GLenum query, GLsizei bufSize, GLfloat *v )
5827117f1b4Smrg{
5837117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
5847117f1b4Smrg   struct gl_1d_map *map1d;
5857117f1b4Smrg   struct gl_2d_map *map2d;
5867117f1b4Smrg   GLint i, n;
5877117f1b4Smrg   GLfloat *data;
5887117f1b4Smrg   GLuint comps;
5893464ebd5Sriastradh   GLsizei numBytes;
5907117f1b4Smrg
5917117f1b4Smrg   comps = _mesa_evaluator_components(target);
5927117f1b4Smrg   if (!comps) {
5937117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(target)" );
5947117f1b4Smrg      return;
5957117f1b4Smrg   }
5967117f1b4Smrg
5977117f1b4Smrg   map1d = get_1d_map(ctx, target);
5987117f1b4Smrg   map2d = get_2d_map(ctx, target);
59901e04c3fSmrg   assert(map1d || map2d);
6007117f1b4Smrg
6017117f1b4Smrg   switch (query) {
6027117f1b4Smrg      case GL_COEFF:
6037117f1b4Smrg         if (map1d) {
6047117f1b4Smrg            data = map1d->Points;
6057117f1b4Smrg            n = map1d->Order * comps;
6067117f1b4Smrg         }
6077117f1b4Smrg         else {
6087117f1b4Smrg            data = map2d->Points;
6097117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
6107117f1b4Smrg         }
6117117f1b4Smrg	 if (data) {
6123464ebd5Sriastradh            numBytes = n * sizeof *v;
6133464ebd5Sriastradh            if (bufSize < numBytes)
6143464ebd5Sriastradh               goto overflow;
6157117f1b4Smrg	    for (i=0;i<n;i++) {
6167117f1b4Smrg	       v[i] = data[i];
6177117f1b4Smrg	    }
6187117f1b4Smrg	 }
6197117f1b4Smrg         break;
6207117f1b4Smrg      case GL_ORDER:
6217117f1b4Smrg         if (map1d) {
6223464ebd5Sriastradh            numBytes = 1 * sizeof *v;
6233464ebd5Sriastradh            if (bufSize < numBytes)
6243464ebd5Sriastradh               goto overflow;
6257117f1b4Smrg            v[0] = (GLfloat) map1d->Order;
6267117f1b4Smrg         }
6277117f1b4Smrg         else {
6283464ebd5Sriastradh            numBytes = 2 * sizeof *v;
6293464ebd5Sriastradh            if (bufSize < numBytes)
6303464ebd5Sriastradh               goto overflow;
6317117f1b4Smrg            v[0] = (GLfloat) map2d->Uorder;
6327117f1b4Smrg            v[1] = (GLfloat) map2d->Vorder;
6337117f1b4Smrg         }
6347117f1b4Smrg         break;
6357117f1b4Smrg      case GL_DOMAIN:
6367117f1b4Smrg         if (map1d) {
6373464ebd5Sriastradh            numBytes = 2 * sizeof *v;
6383464ebd5Sriastradh            if (bufSize < numBytes)
6393464ebd5Sriastradh               goto overflow;
6407117f1b4Smrg            v[0] = map1d->u1;
6417117f1b4Smrg            v[1] = map1d->u2;
6427117f1b4Smrg         }
6437117f1b4Smrg         else {
6443464ebd5Sriastradh            numBytes = 4 * sizeof *v;
6453464ebd5Sriastradh            if (bufSize < numBytes)
6463464ebd5Sriastradh               goto overflow;
6477117f1b4Smrg            v[0] = map2d->u1;
6487117f1b4Smrg            v[1] = map2d->u2;
6497117f1b4Smrg            v[2] = map2d->v1;
6507117f1b4Smrg            v[3] = map2d->v2;
6517117f1b4Smrg         }
6527117f1b4Smrg         break;
6537117f1b4Smrg      default:
6547117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(query)" );
6557117f1b4Smrg   }
6563464ebd5Sriastradh   return;
6573464ebd5Sriastradh
6583464ebd5Sriastradhoverflow:
6593464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
6603464ebd5Sriastradh               "glGetnMapfvARB(out of bounds: bufSize is %d,"
6613464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
6627117f1b4Smrg}
6637117f1b4Smrg
6647117f1b4Smrg
665af69d88dSmrgvoid GLAPIENTRY
6663464ebd5Sriastradh_mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
6673464ebd5Sriastradh{
6683464ebd5Sriastradh   _mesa_GetnMapfvARB(target, query, INT_MAX, v);
6693464ebd5Sriastradh}
6703464ebd5Sriastradh
6713464ebd5Sriastradh
672af69d88dSmrgvoid GLAPIENTRY
6733464ebd5Sriastradh_mesa_GetnMapivARB( GLenum target, GLenum query, GLsizei bufSize, GLint *v )
6747117f1b4Smrg{
6757117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
6767117f1b4Smrg   struct gl_1d_map *map1d;
6777117f1b4Smrg   struct gl_2d_map *map2d;
6787117f1b4Smrg   GLuint i, n;
6797117f1b4Smrg   GLfloat *data;
6807117f1b4Smrg   GLuint comps;
6813464ebd5Sriastradh   GLsizei numBytes;
6827117f1b4Smrg
6837117f1b4Smrg   comps = _mesa_evaluator_components(target);
6847117f1b4Smrg   if (!comps) {
6857117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(target)" );
6867117f1b4Smrg      return;
6877117f1b4Smrg   }
6887117f1b4Smrg
6897117f1b4Smrg   map1d = get_1d_map(ctx, target);
6907117f1b4Smrg   map2d = get_2d_map(ctx, target);
69101e04c3fSmrg   assert(map1d || map2d);
6927117f1b4Smrg
6937117f1b4Smrg   switch (query) {
6947117f1b4Smrg      case GL_COEFF:
6957117f1b4Smrg         if (map1d) {
6967117f1b4Smrg            data = map1d->Points;
6977117f1b4Smrg            n = map1d->Order * comps;
6987117f1b4Smrg         }
6997117f1b4Smrg         else {
7007117f1b4Smrg            data = map2d->Points;
7017117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
7027117f1b4Smrg         }
7037117f1b4Smrg	 if (data) {
7043464ebd5Sriastradh            numBytes = n * sizeof *v;
7053464ebd5Sriastradh            if (bufSize < numBytes)
7063464ebd5Sriastradh               goto overflow;
7077117f1b4Smrg	    for (i=0;i<n;i++) {
7087ec681f3Smrg	       v[i] = lroundf(data[i]);
7097117f1b4Smrg	    }
7107117f1b4Smrg	 }
7117117f1b4Smrg         break;
7127117f1b4Smrg      case GL_ORDER:
7137117f1b4Smrg         if (map1d) {
7143464ebd5Sriastradh            numBytes = 1 * sizeof *v;
7153464ebd5Sriastradh            if (bufSize < numBytes)
7163464ebd5Sriastradh               goto overflow;
7177117f1b4Smrg            v[0] = map1d->Order;
7187117f1b4Smrg         }
7197117f1b4Smrg         else {
7203464ebd5Sriastradh            numBytes = 2 * sizeof *v;
7213464ebd5Sriastradh            if (bufSize < numBytes)
7223464ebd5Sriastradh               goto overflow;
7237117f1b4Smrg            v[0] = map2d->Uorder;
7247117f1b4Smrg            v[1] = map2d->Vorder;
7257117f1b4Smrg         }
7267117f1b4Smrg         break;
7277117f1b4Smrg      case GL_DOMAIN:
7287117f1b4Smrg         if (map1d) {
7293464ebd5Sriastradh            numBytes = 2 * sizeof *v;
7303464ebd5Sriastradh            if (bufSize < numBytes)
7313464ebd5Sriastradh               goto overflow;
7327ec681f3Smrg            v[0] = lroundf(map1d->u1);
7337ec681f3Smrg            v[1] = lroundf(map1d->u2);
7347117f1b4Smrg         }
7357117f1b4Smrg         else {
7363464ebd5Sriastradh            numBytes = 4 * sizeof *v;
7373464ebd5Sriastradh            if (bufSize < numBytes)
7383464ebd5Sriastradh               goto overflow;
7397ec681f3Smrg            v[0] = lroundf(map2d->u1);
7407ec681f3Smrg            v[1] = lroundf(map2d->u2);
7417ec681f3Smrg            v[2] = lroundf(map2d->v1);
7427ec681f3Smrg            v[3] = lroundf(map2d->v2);
7437117f1b4Smrg         }
7447117f1b4Smrg         break;
7457117f1b4Smrg      default:
7467117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(query)" );
7477117f1b4Smrg   }
7483464ebd5Sriastradh   return;
7493464ebd5Sriastradh
7503464ebd5Sriastradhoverflow:
7513464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
7523464ebd5Sriastradh               "glGetnMapivARB(out of bounds: bufSize is %d,"
7533464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
7547117f1b4Smrg}
7557117f1b4Smrg
7567117f1b4Smrg
757af69d88dSmrgvoid GLAPIENTRY
7583464ebd5Sriastradh_mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
7593464ebd5Sriastradh{
7603464ebd5Sriastradh   _mesa_GetnMapivARB(target, query, INT_MAX, v);
7613464ebd5Sriastradh}
7623464ebd5Sriastradh
7637117f1b4Smrg
764af69d88dSmrgvoid GLAPIENTRY
7657117f1b4Smrg_mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
7667117f1b4Smrg{
7677117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7687117f1b4Smrg
7697117f1b4Smrg   if (un<1) {
7707117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid1f" );
7717117f1b4Smrg      return;
7727117f1b4Smrg   }
7737ec681f3Smrg   FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT);
7747ec681f3Smrg   vbo_exec_update_eval_maps(ctx);
7757117f1b4Smrg   ctx->Eval.MapGrid1un = un;
7767117f1b4Smrg   ctx->Eval.MapGrid1u1 = u1;
7777117f1b4Smrg   ctx->Eval.MapGrid1u2 = u2;
7787117f1b4Smrg   ctx->Eval.MapGrid1du = (u2 - u1) / (GLfloat) un;
7797117f1b4Smrg}
7807117f1b4Smrg
7817117f1b4Smrg
782af69d88dSmrgvoid GLAPIENTRY
7837117f1b4Smrg_mesa_MapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
7847117f1b4Smrg{
7857117f1b4Smrg   _mesa_MapGrid1f( un, (GLfloat) u1, (GLfloat) u2 );
7867117f1b4Smrg}
7877117f1b4Smrg
7887117f1b4Smrg
789af69d88dSmrgvoid GLAPIENTRY
7907117f1b4Smrg_mesa_MapGrid2f( GLint un, GLfloat u1, GLfloat u2,
7917117f1b4Smrg                 GLint vn, GLfloat v1, GLfloat v2 )
7927117f1b4Smrg{
7937117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7947117f1b4Smrg
7957117f1b4Smrg   if (un<1) {
7967117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(un)" );
7977117f1b4Smrg      return;
7987117f1b4Smrg   }
7997117f1b4Smrg   if (vn<1) {
8007117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(vn)" );
8017117f1b4Smrg      return;
8027117f1b4Smrg   }
8037117f1b4Smrg
8047ec681f3Smrg   FLUSH_VERTICES(ctx, 0, GL_EVAL_BIT);
8057ec681f3Smrg   vbo_exec_update_eval_maps(ctx);
8067117f1b4Smrg   ctx->Eval.MapGrid2un = un;
8077117f1b4Smrg   ctx->Eval.MapGrid2u1 = u1;
8087117f1b4Smrg   ctx->Eval.MapGrid2u2 = u2;
8097117f1b4Smrg   ctx->Eval.MapGrid2du = (u2 - u1) / (GLfloat) un;
8107117f1b4Smrg   ctx->Eval.MapGrid2vn = vn;
8117117f1b4Smrg   ctx->Eval.MapGrid2v1 = v1;
8127117f1b4Smrg   ctx->Eval.MapGrid2v2 = v2;
8137117f1b4Smrg   ctx->Eval.MapGrid2dv = (v2 - v1) / (GLfloat) vn;
8147117f1b4Smrg}
8157117f1b4Smrg
8167117f1b4Smrg
817af69d88dSmrgvoid GLAPIENTRY
8187117f1b4Smrg_mesa_MapGrid2d( GLint un, GLdouble u1, GLdouble u2,
8197117f1b4Smrg                 GLint vn, GLdouble v1, GLdouble v2 )
8207117f1b4Smrg{
8217ec681f3Smrg   _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2,
8227117f1b4Smrg		    vn, (GLfloat) v1, (GLfloat) v2 );
8237117f1b4Smrg}
8247117f1b4Smrg
8257117f1b4Smrg
8264a49301eSmrgvoid
8274a49301eSmrg_mesa_install_eval_vtxfmt(struct _glapi_table *disp,
8284a49301eSmrg                          const GLvertexformat *vfmt)
8294a49301eSmrg{
8304a49301eSmrg   SET_EvalCoord1f(disp, vfmt->EvalCoord1f);
8314a49301eSmrg   SET_EvalCoord1fv(disp, vfmt->EvalCoord1fv);
8324a49301eSmrg   SET_EvalCoord2f(disp, vfmt->EvalCoord2f);
8334a49301eSmrg   SET_EvalCoord2fv(disp, vfmt->EvalCoord2fv);
8344a49301eSmrg   SET_EvalPoint1(disp, vfmt->EvalPoint1);
8354a49301eSmrg   SET_EvalPoint2(disp, vfmt->EvalPoint2);
8364a49301eSmrg}
8374a49301eSmrg
8384a49301eSmrg
8397117f1b4Smrg/**********************************************************************/
8407117f1b4Smrg/*****                      Initialization                        *****/
8417117f1b4Smrg/**********************************************************************/
8427117f1b4Smrg
8437117f1b4Smrg/**
8447117f1b4Smrg * Initialize a 1-D evaluator map.
8457117f1b4Smrg */
8467117f1b4Smrgstatic void
8477117f1b4Smrginit_1d_map( struct gl_1d_map *map, int n, const float *initial )
8487117f1b4Smrg{
8497117f1b4Smrg   map->Order = 1;
8507117f1b4Smrg   map->u1 = 0.0;
8517117f1b4Smrg   map->u2 = 1.0;
852af69d88dSmrg   map->Points = malloc(n * sizeof(GLfloat));
8537117f1b4Smrg   if (map->Points) {
8547117f1b4Smrg      GLint i;
8557117f1b4Smrg      for (i=0;i<n;i++)
8567117f1b4Smrg         map->Points[i] = initial[i];
8577117f1b4Smrg   }
8587117f1b4Smrg}
8597117f1b4Smrg
8607117f1b4Smrg
8617117f1b4Smrg/**
8627ec681f3Smrg * Initialize a 2-D evaluator map
8637117f1b4Smrg */
8647117f1b4Smrgstatic void
8657117f1b4Smrginit_2d_map( struct gl_2d_map *map, int n, const float *initial )
8667117f1b4Smrg{
8677117f1b4Smrg   map->Uorder = 1;
8687117f1b4Smrg   map->Vorder = 1;
8697117f1b4Smrg   map->u1 = 0.0;
8707117f1b4Smrg   map->u2 = 1.0;
8717117f1b4Smrg   map->v1 = 0.0;
8727117f1b4Smrg   map->v2 = 1.0;
873af69d88dSmrg   map->Points = malloc(n * sizeof(GLfloat));
8747117f1b4Smrg   if (map->Points) {
8757117f1b4Smrg      GLint i;
8767117f1b4Smrg      for (i=0;i<n;i++)
8777117f1b4Smrg         map->Points[i] = initial[i];
8787117f1b4Smrg   }
8797117f1b4Smrg}
8807117f1b4Smrg
8817117f1b4Smrg
8823464ebd5Sriastradhvoid _mesa_init_eval( struct gl_context *ctx )
8837117f1b4Smrg{
8847117f1b4Smrg   /* Evaluators group */
8857117f1b4Smrg   ctx->Eval.Map1Color4 = GL_FALSE;
8867117f1b4Smrg   ctx->Eval.Map1Index = GL_FALSE;
8877117f1b4Smrg   ctx->Eval.Map1Normal = GL_FALSE;
8887117f1b4Smrg   ctx->Eval.Map1TextureCoord1 = GL_FALSE;
8897117f1b4Smrg   ctx->Eval.Map1TextureCoord2 = GL_FALSE;
8907117f1b4Smrg   ctx->Eval.Map1TextureCoord3 = GL_FALSE;
8917117f1b4Smrg   ctx->Eval.Map1TextureCoord4 = GL_FALSE;
8927117f1b4Smrg   ctx->Eval.Map1Vertex3 = GL_FALSE;
8937117f1b4Smrg   ctx->Eval.Map1Vertex4 = GL_FALSE;
8947117f1b4Smrg   ctx->Eval.Map2Color4 = GL_FALSE;
8957117f1b4Smrg   ctx->Eval.Map2Index = GL_FALSE;
8967117f1b4Smrg   ctx->Eval.Map2Normal = GL_FALSE;
8977117f1b4Smrg   ctx->Eval.Map2TextureCoord1 = GL_FALSE;
8987117f1b4Smrg   ctx->Eval.Map2TextureCoord2 = GL_FALSE;
8997117f1b4Smrg   ctx->Eval.Map2TextureCoord3 = GL_FALSE;
9007117f1b4Smrg   ctx->Eval.Map2TextureCoord4 = GL_FALSE;
9017117f1b4Smrg   ctx->Eval.Map2Vertex3 = GL_FALSE;
9027117f1b4Smrg   ctx->Eval.Map2Vertex4 = GL_FALSE;
9037117f1b4Smrg   ctx->Eval.AutoNormal = GL_FALSE;
9047117f1b4Smrg   ctx->Eval.MapGrid1un = 1;
9057117f1b4Smrg   ctx->Eval.MapGrid1u1 = 0.0;
9067117f1b4Smrg   ctx->Eval.MapGrid1u2 = 1.0;
9077117f1b4Smrg   ctx->Eval.MapGrid2un = 1;
9087117f1b4Smrg   ctx->Eval.MapGrid2vn = 1;
9097117f1b4Smrg   ctx->Eval.MapGrid2u1 = 0.0;
9107117f1b4Smrg   ctx->Eval.MapGrid2u2 = 1.0;
9117117f1b4Smrg   ctx->Eval.MapGrid2v1 = 0.0;
9127117f1b4Smrg   ctx->Eval.MapGrid2v2 = 1.0;
9137117f1b4Smrg
9147117f1b4Smrg   /* Evaluator data */
9157117f1b4Smrg   {
9167117f1b4Smrg      static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
9177117f1b4Smrg      static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
9187117f1b4Smrg      static GLfloat index[1] = { 1.0 };
9197117f1b4Smrg      static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
9207117f1b4Smrg      static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
9217117f1b4Smrg
9227117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
9237117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
9247117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
9257117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
9267117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
9277117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
9287117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
9297117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
9307117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
9317117f1b4Smrg
9327117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
9337117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
9347117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
9357117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
9367117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
9377117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
9387117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
9397117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
9407117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
9417117f1b4Smrg   }
9427117f1b4Smrg}
9437117f1b4Smrg
9447117f1b4Smrg
9453464ebd5Sriastradhvoid _mesa_free_eval_data( struct gl_context *ctx )
9467117f1b4Smrg{
9477117f1b4Smrg   /* Free evaluator data */
948af69d88dSmrg   free(ctx->EvalMap.Map1Vertex3.Points);
949af69d88dSmrg   free(ctx->EvalMap.Map1Vertex4.Points);
950af69d88dSmrg   free(ctx->EvalMap.Map1Index.Points);
951af69d88dSmrg   free(ctx->EvalMap.Map1Color4.Points);
952af69d88dSmrg   free(ctx->EvalMap.Map1Normal.Points);
953af69d88dSmrg   free(ctx->EvalMap.Map1Texture1.Points);
954af69d88dSmrg   free(ctx->EvalMap.Map1Texture2.Points);
955af69d88dSmrg   free(ctx->EvalMap.Map1Texture3.Points);
956af69d88dSmrg   free(ctx->EvalMap.Map1Texture4.Points);
957af69d88dSmrg
958af69d88dSmrg   free(ctx->EvalMap.Map2Vertex3.Points);
959af69d88dSmrg   free(ctx->EvalMap.Map2Vertex4.Points);
960af69d88dSmrg   free(ctx->EvalMap.Map2Index.Points);
961af69d88dSmrg   free(ctx->EvalMap.Map2Color4.Points);
962af69d88dSmrg   free(ctx->EvalMap.Map2Normal.Points);
963af69d88dSmrg   free(ctx->EvalMap.Map2Texture1.Points);
964af69d88dSmrg   free(ctx->EvalMap.Map2Texture2.Points);
965af69d88dSmrg   free(ctx->EvalMap.Map2Texture3.Points);
966af69d88dSmrg   free(ctx->EvalMap.Map2Texture4.Points);
9677117f1b4Smrg}
968