eval.c revision 01e04c3f
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 "imports.h"
427117f1b4Smrg#include "context.h"
437117f1b4Smrg#include "eval.h"
447117f1b4Smrg#include "macros.h"
457117f1b4Smrg#include "mtypes.h"
46cdc920a0Smrg#include "main/dispatch.h"
474a49301eSmrg
484a49301eSmrg
497117f1b4Smrg/*
507117f1b4Smrg * Return the number of components per control point for any type of
517117f1b4Smrg * evaluator.  Return 0 if bad target.
527117f1b4Smrg * See table 5.1 in the OpenGL 1.2 spec.
537117f1b4Smrg */
547117f1b4SmrgGLuint _mesa_evaluator_components( GLenum target )
557117f1b4Smrg{
567117f1b4Smrg   switch (target) {
577117f1b4Smrg      case GL_MAP1_VERTEX_3:		return 3;
587117f1b4Smrg      case GL_MAP1_VERTEX_4:		return 4;
597117f1b4Smrg      case GL_MAP1_INDEX:		return 1;
607117f1b4Smrg      case GL_MAP1_COLOR_4:		return 4;
617117f1b4Smrg      case GL_MAP1_NORMAL:		return 3;
627117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_1:	return 1;
637117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_2:	return 2;
647117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_3:	return 3;
657117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_4:	return 4;
667117f1b4Smrg      case GL_MAP2_VERTEX_3:		return 3;
677117f1b4Smrg      case GL_MAP2_VERTEX_4:		return 4;
687117f1b4Smrg      case GL_MAP2_INDEX:		return 1;
697117f1b4Smrg      case GL_MAP2_COLOR_4:		return 4;
707117f1b4Smrg      case GL_MAP2_NORMAL:		return 3;
717117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_1:	return 1;
727117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_2:	return 2;
737117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_3:	return 3;
747117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_4:	return 4;
757117f1b4Smrg      default:				break;
767117f1b4Smrg   }
777117f1b4Smrg
787117f1b4Smrg   return 0;
797117f1b4Smrg}
807117f1b4Smrg
817117f1b4Smrg
827117f1b4Smrg/*
837117f1b4Smrg * Return pointer to the gl_1d_map struct for the named target.
847117f1b4Smrg */
857117f1b4Smrgstatic struct gl_1d_map *
863464ebd5Sriastradhget_1d_map( struct gl_context *ctx, GLenum target )
877117f1b4Smrg{
887117f1b4Smrg   switch (target) {
897117f1b4Smrg      case GL_MAP1_VERTEX_3:
907117f1b4Smrg         return &ctx->EvalMap.Map1Vertex3;
917117f1b4Smrg      case GL_MAP1_VERTEX_4:
927117f1b4Smrg         return &ctx->EvalMap.Map1Vertex4;
937117f1b4Smrg      case GL_MAP1_INDEX:
947117f1b4Smrg         return &ctx->EvalMap.Map1Index;
957117f1b4Smrg      case GL_MAP1_COLOR_4:
967117f1b4Smrg         return &ctx->EvalMap.Map1Color4;
977117f1b4Smrg      case GL_MAP1_NORMAL:
987117f1b4Smrg         return &ctx->EvalMap.Map1Normal;
997117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_1:
1007117f1b4Smrg         return &ctx->EvalMap.Map1Texture1;
1017117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_2:
1027117f1b4Smrg         return &ctx->EvalMap.Map1Texture2;
1037117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_3:
1047117f1b4Smrg         return &ctx->EvalMap.Map1Texture3;
1057117f1b4Smrg      case GL_MAP1_TEXTURE_COORD_4:
1067117f1b4Smrg         return &ctx->EvalMap.Map1Texture4;
1077117f1b4Smrg      default:
1087117f1b4Smrg         return NULL;
1097117f1b4Smrg   }
1107117f1b4Smrg}
1117117f1b4Smrg
1127117f1b4Smrg
1137117f1b4Smrg/*
1147117f1b4Smrg * Return pointer to the gl_2d_map struct for the named target.
1157117f1b4Smrg */
1167117f1b4Smrgstatic struct gl_2d_map *
1173464ebd5Sriastradhget_2d_map( struct gl_context *ctx, GLenum target )
1187117f1b4Smrg{
1197117f1b4Smrg   switch (target) {
1207117f1b4Smrg      case GL_MAP2_VERTEX_3:
1217117f1b4Smrg         return &ctx->EvalMap.Map2Vertex3;
1227117f1b4Smrg      case GL_MAP2_VERTEX_4:
1237117f1b4Smrg         return &ctx->EvalMap.Map2Vertex4;
1247117f1b4Smrg      case GL_MAP2_INDEX:
1257117f1b4Smrg         return &ctx->EvalMap.Map2Index;
1267117f1b4Smrg      case GL_MAP2_COLOR_4:
1277117f1b4Smrg         return &ctx->EvalMap.Map2Color4;
1287117f1b4Smrg      case GL_MAP2_NORMAL:
1297117f1b4Smrg         return &ctx->EvalMap.Map2Normal;
1307117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_1:
1317117f1b4Smrg         return &ctx->EvalMap.Map2Texture1;
1327117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_2:
1337117f1b4Smrg         return &ctx->EvalMap.Map2Texture2;
1347117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_3:
1357117f1b4Smrg         return &ctx->EvalMap.Map2Texture3;
1367117f1b4Smrg      case GL_MAP2_TEXTURE_COORD_4:
1377117f1b4Smrg         return &ctx->EvalMap.Map2Texture4;
1387117f1b4Smrg      default:
1397117f1b4Smrg         return NULL;
1407117f1b4Smrg   }
1417117f1b4Smrg}
1427117f1b4Smrg
1437117f1b4Smrg
1447117f1b4Smrg/**********************************************************************/
1457117f1b4Smrg/***            Copy and deallocate control points                  ***/
1467117f1b4Smrg/**********************************************************************/
1477117f1b4Smrg
1487117f1b4Smrg
1497117f1b4Smrg/*
1507117f1b4Smrg * Copy 1-parametric evaluator control points from user-specified
1517117f1b4Smrg * memory space to a buffer of contiguous control points.
1527117f1b4Smrg * \param see glMap1f for details
1537117f1b4Smrg * \return pointer to buffer of contiguous control points or NULL if out
1547117f1b4Smrg *          of memory.
1557117f1b4Smrg */
1567117f1b4SmrgGLfloat *_mesa_copy_map_points1f( GLenum target, GLint ustride, GLint uorder,
1577117f1b4Smrg                                  const GLfloat *points )
1587117f1b4Smrg{
1597117f1b4Smrg   GLfloat *buffer, *p;
1607117f1b4Smrg   GLint i, k, size = _mesa_evaluator_components(target);
1617117f1b4Smrg
1627117f1b4Smrg   if (!points || !size)
1637117f1b4Smrg      return NULL;
1647117f1b4Smrg
165af69d88dSmrg   buffer = malloc(uorder * size * sizeof(GLfloat));
1667117f1b4Smrg
1677117f1b4Smrg   if (buffer)
1687117f1b4Smrg      for (i = 0, p = buffer; i < uorder; i++, points += ustride)
1697117f1b4Smrg	for (k = 0; k < size; k++)
1707117f1b4Smrg	  *p++ = points[k];
1717117f1b4Smrg
1727117f1b4Smrg   return buffer;
1737117f1b4Smrg}
1747117f1b4Smrg
1757117f1b4Smrg
1767117f1b4Smrg
1777117f1b4Smrg/*
1787117f1b4Smrg * Same as above but convert doubles to floats.
1797117f1b4Smrg */
1807117f1b4SmrgGLfloat *_mesa_copy_map_points1d( GLenum target, GLint ustride, GLint uorder,
1817117f1b4Smrg                                  const GLdouble *points )
1827117f1b4Smrg{
1837117f1b4Smrg   GLfloat *buffer, *p;
1847117f1b4Smrg   GLint i, k, size = _mesa_evaluator_components(target);
1857117f1b4Smrg
1867117f1b4Smrg   if (!points || !size)
1877117f1b4Smrg      return NULL;
1887117f1b4Smrg
189af69d88dSmrg   buffer = malloc(uorder * size * sizeof(GLfloat));
1907117f1b4Smrg
1917117f1b4Smrg   if (buffer)
1927117f1b4Smrg      for (i = 0, p = buffer; i < uorder; i++, points += ustride)
1937117f1b4Smrg	for (k = 0; k < size; k++)
1947117f1b4Smrg	  *p++ = (GLfloat) points[k];
1957117f1b4Smrg
1967117f1b4Smrg   return buffer;
1977117f1b4Smrg}
1987117f1b4Smrg
1997117f1b4Smrg
2007117f1b4Smrg
2017117f1b4Smrg/*
2027117f1b4Smrg * Copy 2-parametric evaluator control points from user-specified
2037117f1b4Smrg * memory space to a buffer of contiguous control points.
2047117f1b4Smrg * Additional memory is allocated to be used by the horner and
2057117f1b4Smrg * de Casteljau evaluation schemes.
2067117f1b4Smrg *
2077117f1b4Smrg * \param see glMap2f for details
2087117f1b4Smrg * \return pointer to buffer of contiguous control points or NULL if out
2097117f1b4Smrg *          of memory.
2107117f1b4Smrg */
2117117f1b4SmrgGLfloat *_mesa_copy_map_points2f( GLenum target,
2127117f1b4Smrg                                  GLint ustride, GLint uorder,
2137117f1b4Smrg                                  GLint vstride, GLint vorder,
2147117f1b4Smrg                                  const GLfloat *points )
2157117f1b4Smrg{
2167117f1b4Smrg   GLfloat *buffer, *p;
2177117f1b4Smrg   GLint i, j, k, size, dsize, hsize;
2187117f1b4Smrg   GLint uinc;
2197117f1b4Smrg
2207117f1b4Smrg   size = _mesa_evaluator_components(target);
2217117f1b4Smrg
2227117f1b4Smrg   if (!points || size==0) {
2237117f1b4Smrg      return NULL;
2247117f1b4Smrg   }
2257117f1b4Smrg
2267117f1b4Smrg   /* max(uorder, vorder) additional points are used in      */
2277117f1b4Smrg   /* horner evaluation and uorder*vorder additional */
2287117f1b4Smrg   /* values are needed for de Casteljau                     */
2297117f1b4Smrg   dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
2307117f1b4Smrg   hsize = (uorder > vorder ? uorder : vorder)*size;
2317117f1b4Smrg
2327117f1b4Smrg   if(hsize>dsize)
233af69d88dSmrg     buffer = malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
2347117f1b4Smrg   else
235af69d88dSmrg     buffer = malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
2367117f1b4Smrg
2377117f1b4Smrg   /* compute the increment value for the u-loop */
2387117f1b4Smrg   uinc = ustride - vorder*vstride;
2397117f1b4Smrg
2407117f1b4Smrg   if (buffer)
2417117f1b4Smrg      for (i=0, p=buffer; i<uorder; i++, points += uinc)
2427117f1b4Smrg	 for (j=0; j<vorder; j++, points += vstride)
2437117f1b4Smrg	    for (k=0; k<size; k++)
2447117f1b4Smrg	       *p++ = points[k];
2457117f1b4Smrg
2467117f1b4Smrg   return buffer;
2477117f1b4Smrg}
2487117f1b4Smrg
2497117f1b4Smrg
2507117f1b4Smrg
2517117f1b4Smrg/*
2527117f1b4Smrg * Same as above but convert doubles to floats.
2537117f1b4Smrg */
2547117f1b4SmrgGLfloat *_mesa_copy_map_points2d(GLenum target,
2557117f1b4Smrg                                 GLint ustride, GLint uorder,
2567117f1b4Smrg                                 GLint vstride, GLint vorder,
2577117f1b4Smrg                                 const GLdouble *points )
2587117f1b4Smrg{
2597117f1b4Smrg   GLfloat *buffer, *p;
2607117f1b4Smrg   GLint i, j, k, size, hsize, dsize;
2617117f1b4Smrg   GLint uinc;
2627117f1b4Smrg
2637117f1b4Smrg   size = _mesa_evaluator_components(target);
2647117f1b4Smrg
2657117f1b4Smrg   if (!points || size==0) {
2667117f1b4Smrg      return NULL;
2677117f1b4Smrg   }
2687117f1b4Smrg
2697117f1b4Smrg   /* max(uorder, vorder) additional points are used in      */
2707117f1b4Smrg   /* horner evaluation and uorder*vorder additional */
2717117f1b4Smrg   /* values are needed for de Casteljau                     */
2727117f1b4Smrg   dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
2737117f1b4Smrg   hsize = (uorder > vorder ? uorder : vorder)*size;
2747117f1b4Smrg
2757117f1b4Smrg   if(hsize>dsize)
276af69d88dSmrg     buffer = malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
2777117f1b4Smrg   else
278af69d88dSmrg     buffer = malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
2797117f1b4Smrg
2807117f1b4Smrg   /* compute the increment value for the u-loop */
2817117f1b4Smrg   uinc = ustride - vorder*vstride;
2827117f1b4Smrg
2837117f1b4Smrg   if (buffer)
2847117f1b4Smrg      for (i=0, p=buffer; i<uorder; i++, points += uinc)
2857117f1b4Smrg	 for (j=0; j<vorder; j++, points += vstride)
2867117f1b4Smrg	    for (k=0; k<size; k++)
2877117f1b4Smrg	       *p++ = (GLfloat) points[k];
2887117f1b4Smrg
2897117f1b4Smrg   return buffer;
2907117f1b4Smrg}
2917117f1b4Smrg
2927117f1b4Smrg
2937117f1b4Smrg
2947117f1b4Smrg
2957117f1b4Smrg/**********************************************************************/
2967117f1b4Smrg/***                      API entry points                          ***/
2977117f1b4Smrg/**********************************************************************/
2987117f1b4Smrg
2997117f1b4Smrg
3007117f1b4Smrg/*
3017117f1b4Smrg * This does the work of glMap1[fd].
3027117f1b4Smrg */
3037117f1b4Smrgstatic void
3047117f1b4Smrgmap1(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
3057117f1b4Smrg     GLint uorder, const GLvoid *points, GLenum type )
3067117f1b4Smrg{
3077117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
3087117f1b4Smrg   GLint k;
3097117f1b4Smrg   GLfloat *pnts;
3107117f1b4Smrg   struct gl_1d_map *map = NULL;
3117117f1b4Smrg
31201e04c3fSmrg   assert(type == GL_FLOAT || type == GL_DOUBLE);
3137117f1b4Smrg
3147117f1b4Smrg   if (u1 == u2) {
3157117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(u1,u2)" );
3167117f1b4Smrg      return;
3177117f1b4Smrg   }
3187117f1b4Smrg   if (uorder < 1 || uorder > MAX_EVAL_ORDER) {
3197117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(order)" );
3207117f1b4Smrg      return;
3217117f1b4Smrg   }
3227117f1b4Smrg   if (!points) {
3237117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(points)" );
3247117f1b4Smrg      return;
3257117f1b4Smrg   }
3267117f1b4Smrg
3277117f1b4Smrg   k = _mesa_evaluator_components( target );
3287117f1b4Smrg   if (k == 0) {
3297117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" );
330af69d88dSmrg      return;
3317117f1b4Smrg   }
3327117f1b4Smrg
3337117f1b4Smrg   if (ustride < k) {
3347117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMap1(stride)" );
3357117f1b4Smrg      return;
3367117f1b4Smrg   }
3377117f1b4Smrg
3387117f1b4Smrg   if (ctx->Texture.CurrentUnit != 0) {
3397117f1b4Smrg      /* See OpenGL 1.2.1 spec, section F.2.13 */
3407117f1b4Smrg      _mesa_error( ctx, GL_INVALID_OPERATION, "glMap2(ACTIVE_TEXTURE != 0)" );
3417117f1b4Smrg      return;
3427117f1b4Smrg   }
3437117f1b4Smrg
3447117f1b4Smrg   map = get_1d_map(ctx, target);
3457117f1b4Smrg   if (!map) {
3467117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glMap1(target)" );
3477117f1b4Smrg      return;
3487117f1b4Smrg   }
3497117f1b4Smrg
3507117f1b4Smrg   /* make copy of the control points */
3517117f1b4Smrg   if (type == GL_FLOAT)
3527117f1b4Smrg      pnts = _mesa_copy_map_points1f(target, ustride, uorder, (GLfloat*) points);
3537117f1b4Smrg   else
3547117f1b4Smrg      pnts = _mesa_copy_map_points1d(target, ustride, uorder, (GLdouble*) points);
3557117f1b4Smrg
3567117f1b4Smrg
3577117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_EVAL);
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
4527117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_EVAL);
4537117f1b4Smrg   map->Uorder = uorder;
4547117f1b4Smrg   map->u1 = u1;
4557117f1b4Smrg   map->u2 = u2;
4567117f1b4Smrg   map->du = 1.0F / (u2 - u1);
4577117f1b4Smrg   map->Vorder = vorder;
4587117f1b4Smrg   map->v1 = v1;
4597117f1b4Smrg   map->v2 = v2;
4607117f1b4Smrg   map->dv = 1.0F / (v2 - v1);
461af69d88dSmrg   free(map->Points);
4627117f1b4Smrg   map->Points = pnts;
4637117f1b4Smrg}
4647117f1b4Smrg
4657117f1b4Smrg
466af69d88dSmrgvoid GLAPIENTRY
4677117f1b4Smrg_mesa_Map2f( GLenum target,
4687117f1b4Smrg             GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
4697117f1b4Smrg             GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
4707117f1b4Smrg             const GLfloat *points)
4717117f1b4Smrg{
4727117f1b4Smrg   map2(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder,
4737117f1b4Smrg        points, GL_FLOAT);
4747117f1b4Smrg}
4757117f1b4Smrg
4767117f1b4Smrg
477af69d88dSmrgvoid GLAPIENTRY
4787117f1b4Smrg_mesa_Map2d( GLenum target,
4797117f1b4Smrg             GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
4807117f1b4Smrg             GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
4817117f1b4Smrg             const GLdouble *points )
4827117f1b4Smrg{
4837117f1b4Smrg   map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder,
4847117f1b4Smrg	(GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE);
4857117f1b4Smrg}
4867117f1b4Smrg
4877117f1b4Smrg
4887117f1b4Smrg
489af69d88dSmrgvoid GLAPIENTRY
4903464ebd5Sriastradh_mesa_GetnMapdvARB( GLenum target, GLenum query, GLsizei bufSize, GLdouble *v )
4917117f1b4Smrg{
4927117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
4937117f1b4Smrg   struct gl_1d_map *map1d;
4947117f1b4Smrg   struct gl_2d_map *map2d;
4957117f1b4Smrg   GLint i, n;
4967117f1b4Smrg   GLfloat *data;
4977117f1b4Smrg   GLuint comps;
4983464ebd5Sriastradh   GLsizei numBytes;
4997117f1b4Smrg
5007117f1b4Smrg   comps = _mesa_evaluator_components(target);
5017117f1b4Smrg   if (!comps) {
5027117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(target)" );
5037117f1b4Smrg      return;
5047117f1b4Smrg   }
5057117f1b4Smrg
5067117f1b4Smrg   map1d = get_1d_map(ctx, target);
5077117f1b4Smrg   map2d = get_2d_map(ctx, target);
50801e04c3fSmrg   assert(map1d || map2d);
5097117f1b4Smrg
5107117f1b4Smrg   switch (query) {
5117117f1b4Smrg      case GL_COEFF:
5127117f1b4Smrg         if (map1d) {
5137117f1b4Smrg            data = map1d->Points;
5147117f1b4Smrg            n = map1d->Order * comps;
5157117f1b4Smrg         }
5167117f1b4Smrg         else {
5177117f1b4Smrg            data = map2d->Points;
5187117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
5197117f1b4Smrg         }
5207117f1b4Smrg	 if (data) {
5213464ebd5Sriastradh            numBytes = n * sizeof *v;
5223464ebd5Sriastradh            if (bufSize < numBytes)
5233464ebd5Sriastradh               goto overflow;
5247117f1b4Smrg	    for (i=0;i<n;i++) {
5257117f1b4Smrg	       v[i] = data[i];
5267117f1b4Smrg	    }
5277117f1b4Smrg	 }
5287117f1b4Smrg         break;
5297117f1b4Smrg      case GL_ORDER:
5307117f1b4Smrg         if (map1d) {
5313464ebd5Sriastradh            numBytes = 1 * sizeof *v;
5323464ebd5Sriastradh            if (bufSize < numBytes)
5333464ebd5Sriastradh               goto overflow;
5347117f1b4Smrg            v[0] = (GLdouble) map1d->Order;
5357117f1b4Smrg         }
5367117f1b4Smrg         else {
5373464ebd5Sriastradh            numBytes = 2 * sizeof *v;
5383464ebd5Sriastradh            if (bufSize < numBytes)
5393464ebd5Sriastradh               goto overflow;
5407117f1b4Smrg            v[0] = (GLdouble) map2d->Uorder;
5417117f1b4Smrg            v[1] = (GLdouble) map2d->Vorder;
5427117f1b4Smrg         }
5437117f1b4Smrg         break;
5447117f1b4Smrg      case GL_DOMAIN:
5457117f1b4Smrg         if (map1d) {
5463464ebd5Sriastradh            numBytes = 2 * sizeof *v;
5473464ebd5Sriastradh            if (bufSize < numBytes)
5483464ebd5Sriastradh              goto overflow;
5497117f1b4Smrg            v[0] = (GLdouble) map1d->u1;
5507117f1b4Smrg            v[1] = (GLdouble) map1d->u2;
5517117f1b4Smrg         }
5527117f1b4Smrg         else {
5533464ebd5Sriastradh            numBytes = 4 * sizeof *v;
5543464ebd5Sriastradh            if (bufSize < numBytes)
5553464ebd5Sriastradh               goto overflow;
5567117f1b4Smrg            v[0] = (GLdouble) map2d->u1;
5577117f1b4Smrg            v[1] = (GLdouble) map2d->u2;
5587117f1b4Smrg            v[2] = (GLdouble) map2d->v1;
5597117f1b4Smrg            v[3] = (GLdouble) map2d->v2;
5607117f1b4Smrg         }
5617117f1b4Smrg         break;
5627117f1b4Smrg      default:
5637117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(query)" );
5647117f1b4Smrg   }
5653464ebd5Sriastradh   return;
5663464ebd5Sriastradh
5673464ebd5Sriastradhoverflow:
5683464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
5693464ebd5Sriastradh               "glGetnMapdvARB(out of bounds: bufSize is %d,"
5703464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
5717117f1b4Smrg}
5727117f1b4Smrg
573af69d88dSmrgvoid GLAPIENTRY
5743464ebd5Sriastradh_mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
5753464ebd5Sriastradh{
5763464ebd5Sriastradh   _mesa_GetnMapdvARB(target, query, INT_MAX, v);
5773464ebd5Sriastradh}
5787117f1b4Smrg
579af69d88dSmrgvoid GLAPIENTRY
5803464ebd5Sriastradh_mesa_GetnMapfvARB( GLenum target, GLenum query, GLsizei bufSize, GLfloat *v )
5817117f1b4Smrg{
5827117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
5837117f1b4Smrg   struct gl_1d_map *map1d;
5847117f1b4Smrg   struct gl_2d_map *map2d;
5857117f1b4Smrg   GLint i, n;
5867117f1b4Smrg   GLfloat *data;
5877117f1b4Smrg   GLuint comps;
5883464ebd5Sriastradh   GLsizei numBytes;
5897117f1b4Smrg
5907117f1b4Smrg   comps = _mesa_evaluator_components(target);
5917117f1b4Smrg   if (!comps) {
5927117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(target)" );
5937117f1b4Smrg      return;
5947117f1b4Smrg   }
5957117f1b4Smrg
5967117f1b4Smrg   map1d = get_1d_map(ctx, target);
5977117f1b4Smrg   map2d = get_2d_map(ctx, target);
59801e04c3fSmrg   assert(map1d || map2d);
5997117f1b4Smrg
6007117f1b4Smrg   switch (query) {
6017117f1b4Smrg      case GL_COEFF:
6027117f1b4Smrg         if (map1d) {
6037117f1b4Smrg            data = map1d->Points;
6047117f1b4Smrg            n = map1d->Order * comps;
6057117f1b4Smrg         }
6067117f1b4Smrg         else {
6077117f1b4Smrg            data = map2d->Points;
6087117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
6097117f1b4Smrg         }
6107117f1b4Smrg	 if (data) {
6113464ebd5Sriastradh            numBytes = n * sizeof *v;
6123464ebd5Sriastradh            if (bufSize < numBytes)
6133464ebd5Sriastradh               goto overflow;
6147117f1b4Smrg	    for (i=0;i<n;i++) {
6157117f1b4Smrg	       v[i] = data[i];
6167117f1b4Smrg	    }
6177117f1b4Smrg	 }
6187117f1b4Smrg         break;
6197117f1b4Smrg      case GL_ORDER:
6207117f1b4Smrg         if (map1d) {
6213464ebd5Sriastradh            numBytes = 1 * sizeof *v;
6223464ebd5Sriastradh            if (bufSize < numBytes)
6233464ebd5Sriastradh               goto overflow;
6247117f1b4Smrg            v[0] = (GLfloat) map1d->Order;
6257117f1b4Smrg         }
6267117f1b4Smrg         else {
6273464ebd5Sriastradh            numBytes = 2 * sizeof *v;
6283464ebd5Sriastradh            if (bufSize < numBytes)
6293464ebd5Sriastradh               goto overflow;
6307117f1b4Smrg            v[0] = (GLfloat) map2d->Uorder;
6317117f1b4Smrg            v[1] = (GLfloat) map2d->Vorder;
6327117f1b4Smrg         }
6337117f1b4Smrg         break;
6347117f1b4Smrg      case GL_DOMAIN:
6357117f1b4Smrg         if (map1d) {
6363464ebd5Sriastradh            numBytes = 2 * sizeof *v;
6373464ebd5Sriastradh            if (bufSize < numBytes)
6383464ebd5Sriastradh               goto overflow;
6397117f1b4Smrg            v[0] = map1d->u1;
6407117f1b4Smrg            v[1] = map1d->u2;
6417117f1b4Smrg         }
6427117f1b4Smrg         else {
6433464ebd5Sriastradh            numBytes = 4 * sizeof *v;
6443464ebd5Sriastradh            if (bufSize < numBytes)
6453464ebd5Sriastradh               goto overflow;
6467117f1b4Smrg            v[0] = map2d->u1;
6477117f1b4Smrg            v[1] = map2d->u2;
6487117f1b4Smrg            v[2] = map2d->v1;
6497117f1b4Smrg            v[3] = map2d->v2;
6507117f1b4Smrg         }
6517117f1b4Smrg         break;
6527117f1b4Smrg      default:
6537117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(query)" );
6547117f1b4Smrg   }
6553464ebd5Sriastradh   return;
6563464ebd5Sriastradh
6573464ebd5Sriastradhoverflow:
6583464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
6593464ebd5Sriastradh               "glGetnMapfvARB(out of bounds: bufSize is %d,"
6603464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
6617117f1b4Smrg}
6627117f1b4Smrg
6637117f1b4Smrg
664af69d88dSmrgvoid GLAPIENTRY
6653464ebd5Sriastradh_mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
6663464ebd5Sriastradh{
6673464ebd5Sriastradh   _mesa_GetnMapfvARB(target, query, INT_MAX, v);
6683464ebd5Sriastradh}
6693464ebd5Sriastradh
6703464ebd5Sriastradh
671af69d88dSmrgvoid GLAPIENTRY
6723464ebd5Sriastradh_mesa_GetnMapivARB( GLenum target, GLenum query, GLsizei bufSize, GLint *v )
6737117f1b4Smrg{
6747117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
6757117f1b4Smrg   struct gl_1d_map *map1d;
6767117f1b4Smrg   struct gl_2d_map *map2d;
6777117f1b4Smrg   GLuint i, n;
6787117f1b4Smrg   GLfloat *data;
6797117f1b4Smrg   GLuint comps;
6803464ebd5Sriastradh   GLsizei numBytes;
6817117f1b4Smrg
6827117f1b4Smrg   comps = _mesa_evaluator_components(target);
6837117f1b4Smrg   if (!comps) {
6847117f1b4Smrg      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(target)" );
6857117f1b4Smrg      return;
6867117f1b4Smrg   }
6877117f1b4Smrg
6887117f1b4Smrg   map1d = get_1d_map(ctx, target);
6897117f1b4Smrg   map2d = get_2d_map(ctx, target);
69001e04c3fSmrg   assert(map1d || map2d);
6917117f1b4Smrg
6927117f1b4Smrg   switch (query) {
6937117f1b4Smrg      case GL_COEFF:
6947117f1b4Smrg         if (map1d) {
6957117f1b4Smrg            data = map1d->Points;
6967117f1b4Smrg            n = map1d->Order * comps;
6977117f1b4Smrg         }
6987117f1b4Smrg         else {
6997117f1b4Smrg            data = map2d->Points;
7007117f1b4Smrg            n = map2d->Uorder * map2d->Vorder * comps;
7017117f1b4Smrg         }
7027117f1b4Smrg	 if (data) {
7033464ebd5Sriastradh            numBytes = n * sizeof *v;
7043464ebd5Sriastradh            if (bufSize < numBytes)
7053464ebd5Sriastradh               goto overflow;
7067117f1b4Smrg	    for (i=0;i<n;i++) {
7077117f1b4Smrg	       v[i] = IROUND(data[i]);
7087117f1b4Smrg	    }
7097117f1b4Smrg	 }
7107117f1b4Smrg         break;
7117117f1b4Smrg      case GL_ORDER:
7127117f1b4Smrg         if (map1d) {
7133464ebd5Sriastradh            numBytes = 1 * sizeof *v;
7143464ebd5Sriastradh            if (bufSize < numBytes)
7153464ebd5Sriastradh               goto overflow;
7167117f1b4Smrg            v[0] = map1d->Order;
7177117f1b4Smrg         }
7187117f1b4Smrg         else {
7193464ebd5Sriastradh            numBytes = 2 * sizeof *v;
7203464ebd5Sriastradh            if (bufSize < numBytes)
7213464ebd5Sriastradh               goto overflow;
7227117f1b4Smrg            v[0] = map2d->Uorder;
7237117f1b4Smrg            v[1] = map2d->Vorder;
7247117f1b4Smrg         }
7257117f1b4Smrg         break;
7267117f1b4Smrg      case GL_DOMAIN:
7277117f1b4Smrg         if (map1d) {
7283464ebd5Sriastradh            numBytes = 2 * sizeof *v;
7293464ebd5Sriastradh            if (bufSize < numBytes)
7303464ebd5Sriastradh               goto overflow;
7317117f1b4Smrg            v[0] = IROUND(map1d->u1);
7327117f1b4Smrg            v[1] = IROUND(map1d->u2);
7337117f1b4Smrg         }
7347117f1b4Smrg         else {
7353464ebd5Sriastradh            numBytes = 4 * sizeof *v;
7363464ebd5Sriastradh            if (bufSize < numBytes)
7373464ebd5Sriastradh               goto overflow;
7387117f1b4Smrg            v[0] = IROUND(map2d->u1);
7397117f1b4Smrg            v[1] = IROUND(map2d->u2);
7407117f1b4Smrg            v[2] = IROUND(map2d->v1);
7417117f1b4Smrg            v[3] = IROUND(map2d->v2);
7427117f1b4Smrg         }
7437117f1b4Smrg         break;
7447117f1b4Smrg      default:
7457117f1b4Smrg         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(query)" );
7467117f1b4Smrg   }
7473464ebd5Sriastradh   return;
7483464ebd5Sriastradh
7493464ebd5Sriastradhoverflow:
7503464ebd5Sriastradh   _mesa_error( ctx, GL_INVALID_OPERATION,
7513464ebd5Sriastradh               "glGetnMapivARB(out of bounds: bufSize is %d,"
7523464ebd5Sriastradh               " but %d bytes are required)", bufSize, numBytes );
7537117f1b4Smrg}
7547117f1b4Smrg
7557117f1b4Smrg
756af69d88dSmrgvoid GLAPIENTRY
7573464ebd5Sriastradh_mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
7583464ebd5Sriastradh{
7593464ebd5Sriastradh   _mesa_GetnMapivARB(target, query, INT_MAX, v);
7603464ebd5Sriastradh}
7613464ebd5Sriastradh
7627117f1b4Smrg
763af69d88dSmrgvoid GLAPIENTRY
7647117f1b4Smrg_mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
7657117f1b4Smrg{
7667117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7677117f1b4Smrg
7687117f1b4Smrg   if (un<1) {
7697117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid1f" );
7707117f1b4Smrg      return;
7717117f1b4Smrg   }
7727117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_EVAL);
7737117f1b4Smrg   ctx->Eval.MapGrid1un = un;
7747117f1b4Smrg   ctx->Eval.MapGrid1u1 = u1;
7757117f1b4Smrg   ctx->Eval.MapGrid1u2 = u2;
7767117f1b4Smrg   ctx->Eval.MapGrid1du = (u2 - u1) / (GLfloat) un;
7777117f1b4Smrg}
7787117f1b4Smrg
7797117f1b4Smrg
780af69d88dSmrgvoid GLAPIENTRY
7817117f1b4Smrg_mesa_MapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
7827117f1b4Smrg{
7837117f1b4Smrg   _mesa_MapGrid1f( un, (GLfloat) u1, (GLfloat) u2 );
7847117f1b4Smrg}
7857117f1b4Smrg
7867117f1b4Smrg
787af69d88dSmrgvoid GLAPIENTRY
7887117f1b4Smrg_mesa_MapGrid2f( GLint un, GLfloat u1, GLfloat u2,
7897117f1b4Smrg                 GLint vn, GLfloat v1, GLfloat v2 )
7907117f1b4Smrg{
7917117f1b4Smrg   GET_CURRENT_CONTEXT(ctx);
7927117f1b4Smrg
7937117f1b4Smrg   if (un<1) {
7947117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(un)" );
7957117f1b4Smrg      return;
7967117f1b4Smrg   }
7977117f1b4Smrg   if (vn<1) {
7987117f1b4Smrg      _mesa_error( ctx, GL_INVALID_VALUE, "glMapGrid2f(vn)" );
7997117f1b4Smrg      return;
8007117f1b4Smrg   }
8017117f1b4Smrg
8027117f1b4Smrg   FLUSH_VERTICES(ctx, _NEW_EVAL);
8037117f1b4Smrg   ctx->Eval.MapGrid2un = un;
8047117f1b4Smrg   ctx->Eval.MapGrid2u1 = u1;
8057117f1b4Smrg   ctx->Eval.MapGrid2u2 = u2;
8067117f1b4Smrg   ctx->Eval.MapGrid2du = (u2 - u1) / (GLfloat) un;
8077117f1b4Smrg   ctx->Eval.MapGrid2vn = vn;
8087117f1b4Smrg   ctx->Eval.MapGrid2v1 = v1;
8097117f1b4Smrg   ctx->Eval.MapGrid2v2 = v2;
8107117f1b4Smrg   ctx->Eval.MapGrid2dv = (v2 - v1) / (GLfloat) vn;
8117117f1b4Smrg}
8127117f1b4Smrg
8137117f1b4Smrg
814af69d88dSmrgvoid GLAPIENTRY
8157117f1b4Smrg_mesa_MapGrid2d( GLint un, GLdouble u1, GLdouble u2,
8167117f1b4Smrg                 GLint vn, GLdouble v1, GLdouble v2 )
8177117f1b4Smrg{
8187117f1b4Smrg   _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2,
8197117f1b4Smrg		    vn, (GLfloat) v1, (GLfloat) v2 );
8207117f1b4Smrg}
8217117f1b4Smrg
8227117f1b4Smrg
8234a49301eSmrgvoid
8244a49301eSmrg_mesa_install_eval_vtxfmt(struct _glapi_table *disp,
8254a49301eSmrg                          const GLvertexformat *vfmt)
8264a49301eSmrg{
8274a49301eSmrg   SET_EvalCoord1f(disp, vfmt->EvalCoord1f);
8284a49301eSmrg   SET_EvalCoord1fv(disp, vfmt->EvalCoord1fv);
8294a49301eSmrg   SET_EvalCoord2f(disp, vfmt->EvalCoord2f);
8304a49301eSmrg   SET_EvalCoord2fv(disp, vfmt->EvalCoord2fv);
8314a49301eSmrg   SET_EvalPoint1(disp, vfmt->EvalPoint1);
8324a49301eSmrg   SET_EvalPoint2(disp, vfmt->EvalPoint2);
8334a49301eSmrg}
8344a49301eSmrg
8354a49301eSmrg
8367117f1b4Smrg/**********************************************************************/
8377117f1b4Smrg/*****                      Initialization                        *****/
8387117f1b4Smrg/**********************************************************************/
8397117f1b4Smrg
8407117f1b4Smrg/**
8417117f1b4Smrg * Initialize a 1-D evaluator map.
8427117f1b4Smrg */
8437117f1b4Smrgstatic void
8447117f1b4Smrginit_1d_map( struct gl_1d_map *map, int n, const float *initial )
8457117f1b4Smrg{
8467117f1b4Smrg   map->Order = 1;
8477117f1b4Smrg   map->u1 = 0.0;
8487117f1b4Smrg   map->u2 = 1.0;
849af69d88dSmrg   map->Points = malloc(n * sizeof(GLfloat));
8507117f1b4Smrg   if (map->Points) {
8517117f1b4Smrg      GLint i;
8527117f1b4Smrg      for (i=0;i<n;i++)
8537117f1b4Smrg         map->Points[i] = initial[i];
8547117f1b4Smrg   }
8557117f1b4Smrg}
8567117f1b4Smrg
8577117f1b4Smrg
8587117f1b4Smrg/**
8597117f1b4Smrg * Initialize a 2-D evaluator map
8607117f1b4Smrg */
8617117f1b4Smrgstatic void
8627117f1b4Smrginit_2d_map( struct gl_2d_map *map, int n, const float *initial )
8637117f1b4Smrg{
8647117f1b4Smrg   map->Uorder = 1;
8657117f1b4Smrg   map->Vorder = 1;
8667117f1b4Smrg   map->u1 = 0.0;
8677117f1b4Smrg   map->u2 = 1.0;
8687117f1b4Smrg   map->v1 = 0.0;
8697117f1b4Smrg   map->v2 = 1.0;
870af69d88dSmrg   map->Points = malloc(n * sizeof(GLfloat));
8717117f1b4Smrg   if (map->Points) {
8727117f1b4Smrg      GLint i;
8737117f1b4Smrg      for (i=0;i<n;i++)
8747117f1b4Smrg         map->Points[i] = initial[i];
8757117f1b4Smrg   }
8767117f1b4Smrg}
8777117f1b4Smrg
8787117f1b4Smrg
8793464ebd5Sriastradhvoid _mesa_init_eval( struct gl_context *ctx )
8807117f1b4Smrg{
8817117f1b4Smrg   /* Evaluators group */
8827117f1b4Smrg   ctx->Eval.Map1Color4 = GL_FALSE;
8837117f1b4Smrg   ctx->Eval.Map1Index = GL_FALSE;
8847117f1b4Smrg   ctx->Eval.Map1Normal = GL_FALSE;
8857117f1b4Smrg   ctx->Eval.Map1TextureCoord1 = GL_FALSE;
8867117f1b4Smrg   ctx->Eval.Map1TextureCoord2 = GL_FALSE;
8877117f1b4Smrg   ctx->Eval.Map1TextureCoord3 = GL_FALSE;
8887117f1b4Smrg   ctx->Eval.Map1TextureCoord4 = GL_FALSE;
8897117f1b4Smrg   ctx->Eval.Map1Vertex3 = GL_FALSE;
8907117f1b4Smrg   ctx->Eval.Map1Vertex4 = GL_FALSE;
8917117f1b4Smrg   ctx->Eval.Map2Color4 = GL_FALSE;
8927117f1b4Smrg   ctx->Eval.Map2Index = GL_FALSE;
8937117f1b4Smrg   ctx->Eval.Map2Normal = GL_FALSE;
8947117f1b4Smrg   ctx->Eval.Map2TextureCoord1 = GL_FALSE;
8957117f1b4Smrg   ctx->Eval.Map2TextureCoord2 = GL_FALSE;
8967117f1b4Smrg   ctx->Eval.Map2TextureCoord3 = GL_FALSE;
8977117f1b4Smrg   ctx->Eval.Map2TextureCoord4 = GL_FALSE;
8987117f1b4Smrg   ctx->Eval.Map2Vertex3 = GL_FALSE;
8997117f1b4Smrg   ctx->Eval.Map2Vertex4 = GL_FALSE;
9007117f1b4Smrg   ctx->Eval.AutoNormal = GL_FALSE;
9017117f1b4Smrg   ctx->Eval.MapGrid1un = 1;
9027117f1b4Smrg   ctx->Eval.MapGrid1u1 = 0.0;
9037117f1b4Smrg   ctx->Eval.MapGrid1u2 = 1.0;
9047117f1b4Smrg   ctx->Eval.MapGrid2un = 1;
9057117f1b4Smrg   ctx->Eval.MapGrid2vn = 1;
9067117f1b4Smrg   ctx->Eval.MapGrid2u1 = 0.0;
9077117f1b4Smrg   ctx->Eval.MapGrid2u2 = 1.0;
9087117f1b4Smrg   ctx->Eval.MapGrid2v1 = 0.0;
9097117f1b4Smrg   ctx->Eval.MapGrid2v2 = 1.0;
9107117f1b4Smrg
9117117f1b4Smrg   /* Evaluator data */
9127117f1b4Smrg   {
9137117f1b4Smrg      static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
9147117f1b4Smrg      static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
9157117f1b4Smrg      static GLfloat index[1] = { 1.0 };
9167117f1b4Smrg      static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
9177117f1b4Smrg      static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
9187117f1b4Smrg
9197117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
9207117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
9217117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
9227117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
9237117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
9247117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
9257117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
9267117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
9277117f1b4Smrg      init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
9287117f1b4Smrg
9297117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
9307117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
9317117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
9327117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
9337117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
9347117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
9357117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
9367117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
9377117f1b4Smrg      init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
9387117f1b4Smrg   }
9397117f1b4Smrg}
9407117f1b4Smrg
9417117f1b4Smrg
9423464ebd5Sriastradhvoid _mesa_free_eval_data( struct gl_context *ctx )
9437117f1b4Smrg{
9447117f1b4Smrg   /* Free evaluator data */
945af69d88dSmrg   free(ctx->EvalMap.Map1Vertex3.Points);
946af69d88dSmrg   free(ctx->EvalMap.Map1Vertex4.Points);
947af69d88dSmrg   free(ctx->EvalMap.Map1Index.Points);
948af69d88dSmrg   free(ctx->EvalMap.Map1Color4.Points);
949af69d88dSmrg   free(ctx->EvalMap.Map1Normal.Points);
950af69d88dSmrg   free(ctx->EvalMap.Map1Texture1.Points);
951af69d88dSmrg   free(ctx->EvalMap.Map1Texture2.Points);
952af69d88dSmrg   free(ctx->EvalMap.Map1Texture3.Points);
953af69d88dSmrg   free(ctx->EvalMap.Map1Texture4.Points);
954af69d88dSmrg
955af69d88dSmrg   free(ctx->EvalMap.Map2Vertex3.Points);
956af69d88dSmrg   free(ctx->EvalMap.Map2Vertex4.Points);
957af69d88dSmrg   free(ctx->EvalMap.Map2Index.Points);
958af69d88dSmrg   free(ctx->EvalMap.Map2Color4.Points);
959af69d88dSmrg   free(ctx->EvalMap.Map2Normal.Points);
960af69d88dSmrg   free(ctx->EvalMap.Map2Texture1.Points);
961af69d88dSmrg   free(ctx->EvalMap.Map2Texture2.Points);
962af69d88dSmrg   free(ctx->EvalMap.Map2Texture3.Points);
963af69d88dSmrg   free(ctx->EvalMap.Map2Texture4.Points);
9647117f1b4Smrg}
965