home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src / eval2.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  76KB  |  2,896 lines

  1. /* eval2.c */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: eval2.c,v 1.11 1996/02/26 15:06:12 brianp Exp $
  26.  
  27. $Log: eval2.c,v $
  28.  * Revision 1.11  1996/02/26  15:06:12  brianp
  29.  * removed dead code
  30.  *
  31.  * Revision 1.10  1996/02/14  15:40:34  brianp
  32.  * replaced ROUND with ROUNDF
  33.  *
  34.  * Revision 1.9  1995/12/30  17:15:44  brianp
  35.  * produce integer colors and color indexes instead of floats
  36.  *
  37.  * Revision 1.8  1995/11/09  16:57:28  brianp
  38.  * recompute strides in glMap[12][df] functions per Johan Nouvel
  39.  *
  40.  * Revision 1.7  1995/11/03  17:40:12  brianp
  41.  * removed unused variables
  42.  *
  43.  * Revision 1.6  1995/05/30  15:10:25  brianp
  44.  * added glGetMap[dfi]v() functions
  45.  *
  46.  * Revision 1.5  1995/05/29  21:22:57  brianp
  47.  * added glEvalCoord[12][df]v() functions
  48.  *
  49.  * Revision 1.4  1995/05/22  21:02:41  brianp
  50.  * Release 1.2
  51.  *
  52.  * Revision 1.3  1995/05/12  19:26:43  brianp
  53.  * replaced CC.Mode!=0 with INSIDE_BEGIN_END
  54.  *
  55.  * Revision 1.2  1995/03/04  19:29:44  brianp
  56.  * 1.1 beta revision
  57.  *
  58.  * Revision 1.1  1995/03/03  16:03:16  brianp
  59.  * Initial revision
  60.  *
  61.  */
  62.  
  63.  
  64. /*
  65.  * Version 2 of eval.c was written by
  66.  * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and
  67.  * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de).
  68.  *
  69.  * My original implementation of evaluators was simplistic and didn't
  70.  * compute surface normal vectors properly.  Bernd and Volker applied
  71.  * used more sophisticated methods to get better results.
  72.  *
  73.  * Thanks guys!
  74.  */
  75.  
  76.  
  77.  
  78. #include <math.h>
  79. #include <stdlib.h>
  80. #include <string.h>
  81. #include "context.h"
  82. #include "draw.h"
  83. #include "list.h"
  84. #include "macros.h"
  85.  
  86.  
  87. /*
  88.  * Horner scheme for Bezier curves
  89.  * 
  90.  * Bezier curves can be computed via a Horner scheme.
  91.  * Horner is numerically less stable than the de Casteljau
  92.  * algorithm, but it is faster. For curves of degree n 
  93.  * the complexity of Horner is O(n) and de Casteljau is O(n^2).
  94.  * Since stability is not important for displaying curve 
  95.  * points I decided to use the Horner scheme.
  96.  *
  97.  * A cubic Bezier curve with control points b0, b1, b2, b3 can be 
  98.  * written as
  99.  *
  100.  *        (([3]        [3]     )     [3]       )     [3]
  101.  * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3
  102.  *
  103.  *                                           [n]
  104.  * where s=1-t and the binomial coefficients [i]. These can 
  105.  * be computed iteratively using the identity:
  106.  *
  107.  * [n]               [n  ]             [n]
  108.  * [i] = (n-i+1)/i * [i-1]     and     [0] = 1
  109.  */
  110.  
  111. static void
  112. horner_bezier_curve(GLfloat *cp, GLfloat *out, GLfloat t,
  113.                     GLuint dim, GLuint order)
  114. {
  115.   GLfloat s, powert;
  116.   GLuint i, k, bincoeff;
  117.  
  118.   if(order >= 2)
  119.   { 
  120.     bincoeff = order-1;
  121.     s = 1.0-t;
  122.  
  123.     for(k=0; k<dim; k++)
  124.       out[k] = s*cp[k] + bincoeff*t*cp[dim+k];
  125.  
  126.     for(i=2, cp+=2*dim, powert=t*t; i<order; i++, powert*=t, cp +=dim)
  127.     {
  128.       bincoeff *= order-i;
  129.       bincoeff /= i;
  130.  
  131.       for(k=0; k<dim; k++)
  132.         out[k] = s*out[k] + bincoeff*powert*cp[k];
  133.     }
  134.   }
  135.   else /* order=1 -> constant curve */
  136.   { 
  137.     for(k=0; k<dim; k++)
  138.       out[k] = cp[k];
  139.   } 
  140. }
  141.  
  142. /*
  143.  * Tensor product Bezier surfaces
  144.  *
  145.  * Again the Horner scheme is used to compute a point on a 
  146.  * TP Bezier surface. First a control polygon for a curve
  147.  * on the surface in one parameter direction is computed,
  148.  * then the point on the curve for the other parameter 
  149.  * direction is evaluated.
  150.  *
  151.  * To store the curve control polygon additional storage
  152.  * for max(uorder,vorder) points is needed in the 
  153.  * control net cn.
  154.  */
  155.  
  156. static void
  157. horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v,
  158.                    GLuint dim, GLuint uorder, GLuint vorder)
  159. {
  160.   GLfloat *cp = cn + uorder*vorder*dim;
  161.   GLuint i, uinc = vorder*dim;
  162.  
  163.   if(vorder > uorder)
  164.   {
  165.     if(uorder >= 2)
  166.     { 
  167.       GLfloat s, poweru;
  168.       GLuint j, k, bincoeff;
  169.  
  170.       /* Compute the control polygon for the surface-curve in u-direction */
  171.       for(j=0; j<vorder; j++)
  172.       {
  173.         GLfloat *ucp = &cn[j*dim];
  174.  
  175.         /* Each control point is the point for parameter u on a */ 
  176.         /* curve defined by the control polygons in u-direction */
  177.     bincoeff = uorder-1;
  178.     s = 1.0-u;
  179.  
  180.     for(k=0; k<dim; k++)
  181.       cp[j*dim+k] = s*ucp[k] + bincoeff*u*ucp[uinc+k];
  182.  
  183.     for(i=2, ucp+=2*uinc, poweru=u*u; i<uorder; 
  184.             i++, poweru*=u, ucp +=uinc)
  185.     {
  186.       bincoeff *= uorder-i;
  187.           bincoeff /= i;
  188.  
  189.       for(k=0; k<dim; k++)
  190.         cp[j*dim+k] = s*cp[j*dim+k] + bincoeff*poweru*ucp[k];
  191.     }
  192.       }
  193.         
  194.       /* Evaluate curve point in v */
  195.       horner_bezier_curve(cp, out, v, dim, vorder);
  196.     }
  197.     else /* uorder=1 -> cn defines a curve in v */
  198.       horner_bezier_curve(cn, out, v, dim, vorder);
  199.   }
  200.   else /* vorder <= uorder */
  201.   {
  202.     if(vorder > 1)
  203.     {
  204.       GLuint i;
  205.  
  206.       /* Compute the control polygon for the surface-curve in u-direction */
  207.       for(i=0; i<uorder; i++, cn += uinc)
  208.       {
  209.     /* For constant i all cn[i][j] (j=0..vorder) are located */
  210.     /* on consecutive memory locations, so we can use        */
  211.     /* horner_bezier_curve to compute the control points     */
  212.  
  213.     horner_bezier_curve(cn, &cp[i*dim], v, dim, vorder);
  214.       }
  215.  
  216.       /* Evaluate curve point in u */
  217.       horner_bezier_curve(cp, out, u, dim, uorder);
  218.     }
  219.     else  /* vorder=1 -> cn defines a curve in u */
  220.       horner_bezier_curve(cn, out, u, dim, uorder);
  221.   }
  222. }
  223.  
  224. /*
  225.  * The direct de Casteljau algorithm is used when a point on the
  226.  * surface and the tangent directions spanning the tangent plane
  227.  * should be computed (this is needed to compute normals to the
  228.  * surface). In this case the de Casteljau algorithm approach is
  229.  * nicer because a point and the partial derivatives can be computed 
  230.  * at the same time. To get the correct tangent length du and dv
  231.  * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 
  232.  * Since only the directions are needed, this scaling step is omitted.
  233.  *
  234.  * De Casteljau needs additional storage for uorder*vorder
  235.  * values in the control net cn.
  236.  */
  237.  
  238. static void
  239. de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv,
  240.                   GLfloat u, GLfloat v, GLuint dim, 
  241.                   GLuint uorder, GLuint vorder)
  242. {
  243.   GLfloat *dcn = cn + uorder*vorder*dim;
  244.   GLfloat us = 1.0-u, vs = 1.0-v;
  245.   GLuint h, i, j, k;
  246.   GLuint minorder = uorder < vorder ? uorder : vorder;
  247.   GLuint uinc = vorder*dim;
  248.   GLuint dcuinc = vorder;
  249.  
  250.   /* Each component is evaluated separately to save buffer space  */
  251.   /* This does not drasticaly decrease the performance of the     */
  252.   /* algorithm. If additional storage for (uorder-1)*(vorder-1)   */
  253.   /* points would be available, the components could be accessed  */
  254.   /* in the innermost loop which could lead to less cache misses. */
  255.  
  256. #define CN(I,J,K) cn[(I)*uinc+(J)*dim+(K)] 
  257. #define DCN(I, J) dcn[(I)*dcuinc+(J)]
  258.   if(minorder < 3)
  259.   {
  260.     if(uorder==vorder)
  261.     {
  262.       for(k=0; k<dim; k++)
  263.       {
  264.     /* Derivative direction in u */
  265.     du[k] = vs*(CN(1,0,k) - CN(0,0,k)) +
  266.              v*(CN(1,1,k) - CN(0,1,k));
  267.  
  268.     /* Derivative direction in v */
  269.     dv[k] = us*(CN(0,1,k) - CN(0,0,k)) + 
  270.              u*(CN(1,1,k) - CN(1,0,k));
  271.  
  272.     /* bilinear de Casteljau step */
  273.         out[k] =  us*(vs*CN(0,0,k) + v*CN(0,1,k)) +
  274.                u*(vs*CN(1,0,k) + v*CN(1,1,k));
  275.       }
  276.     }
  277.     else if(minorder == uorder)
  278.     {
  279.       for(k=0; k<dim; k++)
  280.       {
  281.     /* bilinear de Casteljau step */
  282.     DCN(1,0) =    CN(1,0,k) -   CN(0,0,k);
  283.     DCN(0,0) = us*CN(0,0,k) + u*CN(1,0,k);
  284.  
  285.     for(j=0; j<vorder-1; j++)
  286.     {
  287.       /* for the derivative in u */
  288.       DCN(1,j+1) =    CN(1,j+1,k) -   CN(0,j+1,k);
  289.       DCN(1,j)   = vs*DCN(1,j)    + v*DCN(1,j+1);
  290.  
  291.       /* for the `point' */
  292.       DCN(0,j+1) = us*CN(0,j+1,k) + u*CN(1,j+1,k);
  293.       DCN(0,j)   = vs*DCN(0,j)    + v*DCN(0,j+1);
  294.     }
  295.         
  296.     /* remaining linear de Casteljau steps until the second last step */
  297.     for(h=minorder; h<vorder-1; h++)
  298.       for(j=0; j<vorder-h; j++)
  299.       {
  300.         /* for the derivative in u */
  301.         DCN(1,j) = vs*DCN(1,j) + v*DCN(1,j+1);
  302.  
  303.         /* for the `point' */
  304.         DCN(0,j) = vs*DCN(0,j) + v*DCN(0,j+1);
  305.       }
  306.  
  307.     /* derivative direction in v */
  308.     dv[k] = DCN(0,1) - DCN(0,0);
  309.  
  310.     /* derivative direction in u */
  311.     du[k] =   vs*DCN(1,0) + v*DCN(1,1);
  312.  
  313.     /* last linear de Casteljau step */
  314.     out[k] =  vs*DCN(0,0) + v*DCN(0,1);
  315.       }
  316.     }
  317.     else /* minorder == vorder */
  318.     {
  319.       for(k=0; k<dim; k++)
  320.       {
  321.     /* bilinear de Casteljau step */
  322.     DCN(0,1) =    CN(0,1,k) -   CN(0,0,k);
  323.     DCN(0,0) = vs*CN(0,0,k) + v*CN(0,1,k);
  324.     for(i=0; i<uorder-1; i++)
  325.     {
  326.       /* for the derivative in v */
  327.       DCN(i+1,1) =    CN(i+1,1,k) -   CN(i+1,0,k);
  328.       DCN(i,1)   = us*DCN(i,1)    + u*DCN(i+1,1);
  329.  
  330.       /* for the `point' */
  331.       DCN(i+1,0) = vs*CN(i+1,0,k) + v*CN(i+1,1,k);
  332.       DCN(i,0)   = us*DCN(i,0)    + u*DCN(i+1,0);
  333.     }
  334.         
  335.     /* remaining linear de Casteljau steps until the second last step */
  336.     for(h=minorder; h<uorder-1; h++)
  337.       for(i=0; i<uorder-h; i++)
  338.       {
  339.         /* for the derivative in v */
  340.         DCN(i,1) = us*DCN(i,1) + u*DCN(i+1,1);
  341.  
  342.         /* for the `point' */
  343.         DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  344.       }
  345.  
  346.     /* derivative direction in u */
  347.     du[k] = DCN(1,0) - DCN(0,0);
  348.  
  349.     /* derivative direction in v */
  350.     dv[k] =   us*DCN(0,1) + u*DCN(1,1);
  351.  
  352.     /* last linear de Casteljau step */
  353.     out[k] =  us*DCN(0,0) + u*DCN(1,0);
  354.       }
  355.     }
  356.   }
  357.   else if(uorder == vorder)
  358.   {
  359.     for(k=0; k<dim; k++)
  360.     {
  361.       /* first bilinear de Casteljau step */
  362.       for(i=0; i<uorder-1; i++)
  363.       {
  364.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  365.     for(j=0; j<vorder-1; j++)
  366.     {
  367.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  368.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  369.     }
  370.       }
  371.  
  372.       /* remaining bilinear de Casteljau steps until the second last step */
  373.       for(h=2; h<minorder-1; h++)
  374.     for(i=0; i<uorder-h; i++)
  375.     {
  376.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  377.       for(j=0; j<vorder-h; j++)
  378.       {
  379.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  380.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  381.       }
  382.     }
  383.  
  384.       /* derivative direction in u */
  385.       du[k] = vs*(DCN(1,0) - DCN(0,0)) +
  386.            v*(DCN(1,1) - DCN(0,1));
  387.  
  388.       /* derivative direction in v */
  389.       dv[k] = us*(DCN(0,1) - DCN(0,0)) + 
  390.            u*(DCN(1,1) - DCN(1,0));
  391.  
  392.       /* last bilinear de Casteljau step */
  393.       out[k] =  us*(vs*DCN(0,0) + v*DCN(0,1)) +
  394.              u*(vs*DCN(1,0) + v*DCN(1,1));
  395.     }
  396.   }
  397.   else if(minorder == uorder)
  398.   {
  399.     for(k=0; k<dim; k++)
  400.     {
  401.       /* first bilinear de Casteljau step */
  402.       for(i=0; i<uorder-1; i++)
  403.       {
  404.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  405.     for(j=0; j<vorder-1; j++)
  406.     {
  407.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  408.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  409.     }
  410.       }
  411.  
  412.       /* remaining bilinear de Casteljau steps until the second last step */
  413.       for(h=2; h<minorder-1; h++)
  414.     for(i=0; i<uorder-h; i++)
  415.     {
  416.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  417.       for(j=0; j<vorder-h; j++)
  418.       {
  419.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  420.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  421.       }
  422.     }
  423.  
  424.       /* last bilinear de Casteljau step */
  425.       DCN(2,0) =    DCN(1,0) -   DCN(0,0);
  426.       DCN(0,0) = us*DCN(0,0) + u*DCN(1,0);
  427.       for(j=0; j<vorder-1; j++)
  428.       {
  429.     /* for the derivative in u */
  430.     DCN(2,j+1) =    DCN(1,j+1) -    DCN(0,j+1);
  431.     DCN(2,j)   = vs*DCN(2,j)    + v*DCN(2,j+1);
  432.     
  433.     /* for the `point' */
  434.     DCN(0,j+1) = us*DCN(0,j+1 ) + u*DCN(1,j+1);
  435.     DCN(0,j)   = vs*DCN(0,j)    + v*DCN(0,j+1);
  436.       }
  437.         
  438.       /* remaining linear de Casteljau steps until the second last step */
  439.       for(h=minorder; h<vorder-1; h++)
  440.     for(j=0; j<vorder-h; j++)
  441.     {
  442.       /* for the derivative in u */
  443.       DCN(2,j) = vs*DCN(2,j) + v*DCN(2,j+1);
  444.       
  445.       /* for the `point' */
  446.       DCN(0,j) = vs*DCN(0,j) + v*DCN(0,j+1);
  447.     }
  448.       
  449.       /* derivative direction in v */
  450.       dv[k] = DCN(0,1) - DCN(0,0);
  451.       
  452.       /* derivative direction in u */
  453.       du[k] =   vs*DCN(2,0) + v*DCN(2,1);
  454.       
  455.       /* last linear de Casteljau step */
  456.       out[k] =  vs*DCN(0,0) + v*DCN(0,1);
  457.     }
  458.   }
  459.   else /* minorder == vorder */
  460.   {
  461.     for(k=0; k<dim; k++)
  462.     {
  463.       /* first bilinear de Casteljau step */
  464.       for(i=0; i<uorder-1; i++)
  465.       {
  466.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  467.     for(j=0; j<vorder-1; j++)
  468.     {
  469.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  470.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  471.     }
  472.       }
  473.  
  474.       /* remaining bilinear de Casteljau steps until the second last step */
  475.       for(h=2; h<minorder-1; h++)
  476.     for(i=0; i<uorder-h; i++)
  477.     {
  478.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  479.       for(j=0; j<vorder-h; j++)
  480.       {
  481.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  482.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  483.       }
  484.     }
  485.  
  486.       /* last bilinear de Casteljau step */
  487.       DCN(0,2) =    DCN(0,1) -   DCN(0,0);
  488.       DCN(0,0) = vs*DCN(0,0) + v*DCN(0,1);
  489.       for(i=0; i<uorder-1; i++)
  490.       {
  491.     /* for the derivative in v */
  492.     DCN(i+1,2) =    DCN(i+1,1)  -   DCN(i+1,0);
  493.     DCN(i,2)   = us*DCN(i,2)    + u*DCN(i+1,2);
  494.     
  495.     /* for the `point' */
  496.     DCN(i+1,0) = vs*DCN(i+1,0)  + v*DCN(i+1,1);
  497.     DCN(i,0)   = us*DCN(i,0)    + u*DCN(i+1,0);
  498.       }
  499.       
  500.       /* remaining linear de Casteljau steps until the second last step */
  501.       for(h=minorder; h<uorder-1; h++)
  502.     for(i=0; i<uorder-h; i++)
  503.     {
  504.       /* for the derivative in v */
  505.       DCN(i,2) = us*DCN(i,2) + u*DCN(i+1,2);
  506.       
  507.       /* for the `point' */
  508.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  509.     }
  510.       
  511.       /* derivative direction in u */
  512.       du[k] = DCN(1,0) - DCN(0,0);
  513.       
  514.       /* derivative direction in v */
  515.       dv[k] =   us*DCN(0,2) + u*DCN(1,2);
  516.       
  517.       /* last linear de Casteljau step */
  518.       out[k] =  us*DCN(0,0) + u*DCN(1,0);
  519.     }
  520.   }
  521. #undef DCN
  522. #undef CN
  523. }
  524.  
  525. /*
  526.  * Return the number of components per control point for any type of
  527.  * evaluator.  Return 0 if bad target.
  528.  */
  529.  
  530. static GLint components( GLenum target )
  531. {
  532.    switch (target) {
  533.       case GL_MAP1_VERTEX_3:        return 3;
  534.       case GL_MAP1_VERTEX_4:        return 4;
  535.       case GL_MAP1_INDEX:        return 1;
  536.       case GL_MAP1_COLOR_4:        return 4;
  537.       case GL_MAP1_NORMAL:        return 3;
  538.       case GL_MAP1_TEXTURE_COORD_1:    return 1;
  539.       case GL_MAP1_TEXTURE_COORD_2:    return 2;
  540.       case GL_MAP1_TEXTURE_COORD_3:    return 3;
  541.       case GL_MAP1_TEXTURE_COORD_4:    return 4;
  542.       case GL_MAP2_VERTEX_3:        return 3;
  543.       case GL_MAP2_VERTEX_4:        return 4;
  544.       case GL_MAP2_INDEX:        return 1;
  545.       case GL_MAP2_COLOR_4:        return 4;
  546.       case GL_MAP2_NORMAL:        return 3;
  547.       case GL_MAP2_TEXTURE_COORD_1:    return 1;
  548.       case GL_MAP2_TEXTURE_COORD_2:    return 2;
  549.       case GL_MAP2_TEXTURE_COORD_3:    return 3;
  550.       case GL_MAP2_TEXTURE_COORD_4:    return 4;
  551.       default:                return 0;
  552.    }
  553. }
  554.  
  555.  
  556.  
  557. /*
  558.  * Copy 1-parametric evaluator control points from user-specified 
  559.  * memory space to a buffer of contiguous control points.
  560.  * Input:  see glMap1f for details
  561.  * Return:  pointer to buffer of contiguous control points or NULL if out
  562.  *          of memory.
  563.  */
  564.  
  565. static GLfloat *copy_points1_f( GLenum target,
  566.                     GLint ustride, GLint uorder,
  567.                     const GLfloat *points )
  568. {
  569.    GLfloat *buffer, *p;
  570.    GLuint i, k, size = components(target);
  571.  
  572.    buffer = (GLfloat *) malloc(uorder * size * sizeof(GLfloat));
  573.  
  574.    if(buffer) 
  575.       for(i=0, p=buffer; i<uorder; i++, points+=ustride)
  576.     for(k=0; k<size; k++)
  577.       *p++ = points[k];
  578.  
  579.    return buffer;
  580. }
  581.  
  582.  
  583.  
  584. /*
  585.  * Same as above but convert doubles to floats.
  586.  */
  587.  
  588. static GLfloat *copy_points1_d( GLenum target,
  589.                     GLint ustride, GLint uorder,
  590.                     const GLdouble *points )
  591. {
  592.    GLfloat *buffer, *p;
  593.    GLuint i, k, size = components(target);
  594.  
  595.    buffer = (GLfloat *) malloc(uorder * size * sizeof(GLfloat));
  596.  
  597.    if(buffer)
  598.       for(i=0, p=buffer; i<uorder; i++, points+=ustride)
  599.     for(k=0; k<size; k++)
  600.       *p++ = (GLfloat) points[k];
  601.  
  602.    return buffer;
  603. }
  604.  
  605. /*
  606.  * Copy 2-parametric evaluator control points from user-specified 
  607.  * memory space to a buffer of contiguous control points.
  608.  * Additional memory is allocated to be used by the horner and
  609.  * de Casteljau evaluation schemes.
  610.  *
  611.  * Input:  see glMap2f for details
  612.  * Return:  pointer to buffer of contiguous control points or NULL if out
  613.  *          of memory.
  614.  */
  615.  
  616. static GLfloat *copy_points2_f( GLenum target,
  617.                     GLint ustride, GLint uorder,
  618.                     GLint vstride, GLint vorder,
  619.                     const GLfloat *points )
  620. {
  621.    GLfloat *buffer, *p;
  622.    GLuint i, j, k, size, dsize, hsize;
  623.    GLint uinc;
  624.  
  625.    size = components(target);
  626.  
  627.    /* max(uorder, vorder) additional points are used in      */
  628.    /* horner evaluation and uorder*vorder additional */
  629.    /* values are needed for de Casteljau                     */
  630.    dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
  631.    hsize = (uorder > vorder ? uorder : vorder)*size;
  632.  
  633.    if(hsize>dsize)
  634.      buffer = (GLfloat *) malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
  635.    else
  636.      buffer = (GLfloat *) malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
  637.  
  638.    /* compute the increment value for the u-loop */
  639.    uinc = ustride - vorder*vstride;
  640.  
  641.    if (buffer) 
  642.       for (i=0, p=buffer; i<uorder; i++, points += uinc)
  643.      for (j=0; j<vorder; j++, points += vstride)
  644.         for (k=0; k<size; k++)
  645.            *p++ = points[k];
  646.  
  647.    return buffer;
  648. }
  649.  
  650.  
  651.  
  652. /*
  653.  * Same as above but convert doubles to floats.
  654.  */
  655.  
  656. static GLfloat *copy_points2_d(GLenum target,
  657.                    GLint ustride, GLint uorder,
  658.                    GLint vstride, GLint vorder,
  659.                    const GLdouble *points )
  660. {
  661.    GLfloat *buffer, *p;
  662.    GLuint i, j, k, size, hsize, dsize;
  663.    GLint uinc;
  664.  
  665.    size = components(target);
  666.  
  667.    /* max(uorder, vorder) additional points are used in      */
  668.    /* horner evaluation and uorder*vorder additional */
  669.    /* values are needed for de Casteljau                     */
  670.    dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
  671.    hsize = (uorder > vorder ? uorder : vorder)*size;
  672.  
  673.    if(hsize>dsize)
  674.      buffer = (GLfloat *) malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
  675.    else
  676.      buffer = (GLfloat *) malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
  677.  
  678.    /* compute the increment value for the u-loop */
  679.    uinc = ustride - vorder*vstride;
  680.  
  681.    if (buffer) 
  682.       for (i=0, p=buffer; i<uorder; i++, points += uinc)
  683.      for (j=0; j<vorder; j++, points += vstride)
  684.         for (k=0; k<size; k++)
  685.            *p++ = (GLfloat) points[k];
  686.  
  687.    return buffer;
  688. }
  689.  
  690. /**********************************************************************/
  691. /*                            Internal                                */
  692. /**********************************************************************/
  693.  
  694.  
  695. /*
  696.  * Do one-time initialization for evaluators.
  697.  */
  698.  
  699. void gl_init_eval( void )
  700. {
  701.   static int init_flag = 0;
  702.  
  703.   /* Compute a table of nCr (combination) values used by the
  704.    * Bernstein polynomial generator.
  705.    */
  706.  
  707.   if (init_flag==0) 
  708.   { /* no initialization needed */ 
  709.   }
  710.  
  711.   init_flag = 1;
  712. }
  713.  
  714.  
  715. /*
  716.  * Control points and info are shared by all contexts in the address space.
  717.  * The discard flag indicates whether the current control point data can be
  718.  * free()'d when new control points are given via glMap[12][fd].  It can't
  719.  * freed be when the current control points are also in a display list.
  720.  */
  721.  
  722.  
  723. /* Map 1, Vertex_3 */
  724. static GLuint Map1Vertex3order;
  725. static GLfloat Map1Vertex3u1, Map1Vertex3u2;
  726. static GLfloat *Map1Vertex3 = NULL;
  727. static GLboolean DiscardMap1Vertex3 = GL_FALSE;
  728.  
  729. /* Map 1, Vertex_4 */
  730. static GLuint Map1Vertex4order;
  731. static GLfloat Map1Vertex4u1, Map1Vertex4u2;
  732. static GLfloat *Map1Vertex4 = NULL;
  733. static GLboolean DiscardMap1Vertex4 = GL_FALSE;
  734.  
  735. /* Map 1, Index */
  736. static GLuint Map1Indexorder;
  737. static GLfloat Map1Indexu1, Map1Indexu2;
  738. static GLfloat *Map1Index = NULL;
  739. static GLboolean DiscardMap1Index = GL_FALSE;
  740.  
  741. /* Map 1, Color_4 */
  742. static GLuint Map1Color4order;
  743. static GLfloat Map1Color4u1, Map1Color4u2;
  744. static GLfloat *Map1Color4 = NULL;
  745. static GLboolean DiscardMap1Color4 = GL_FALSE;
  746.  
  747. /* Map 1, Normal */
  748. static GLuint Map1Normalorder;
  749. static GLfloat Map1Normalu1, Map1Normalu2;
  750. static GLfloat *Map1Normal = NULL;
  751. static GLboolean DiscardMap1Normal = GL_FALSE;
  752.  
  753. /* Map 1, Texture_1 */
  754. static GLuint Map1Texture1order;
  755. static GLfloat Map1Texture1u1, Map1Texture1u2;
  756. static GLfloat *Map1Texture1 = NULL;
  757. static GLboolean DiscardMap1Texture1 = GL_FALSE;
  758.  
  759. /* Map 1, Texture_2 */
  760. static GLuint Map1Texture2order;
  761. static GLfloat Map1Texture2u1, Map1Texture2u2;
  762. static GLfloat *Map1Texture2 = NULL;
  763. static GLboolean DiscardMap1Texture2 = GL_FALSE;
  764.  
  765. /* Map 1, Texture_3 */
  766. static GLuint Map1Texture3order;
  767. static GLfloat Map1Texture3u1, Map1Texture3u2;
  768. static GLfloat *Map1Texture3 = NULL;
  769. static GLboolean DiscardMap1Texture3 = GL_FALSE;
  770.  
  771. /* Map 1, Texture_4 */
  772. static GLuint Map1Texture4order;
  773. static GLfloat Map1Texture4u1, Map1Texture4u2;
  774. static GLfloat *Map1Texture4 = NULL;
  775. static GLboolean DiscardMap1Texture4 = GL_FALSE;
  776.  
  777.  
  778. /* Map 2, Vertex_3 */
  779. static GLuint Map2Vertex3uorder;
  780. static GLuint Map2Vertex3vorder;
  781. static GLfloat Map2Vertex3u1, Map2Vertex3u2;
  782. static GLfloat Map2Vertex3v1, Map2Vertex3v2;
  783. static GLfloat *Map2Vertex3 = NULL;
  784. static GLboolean DiscardMap2Vertex3 = GL_FALSE;
  785.  
  786. /* Map 2, Vertex_4 */
  787. static GLuint Map2Vertex4uorder;
  788. static GLuint Map2Vertex4vorder;
  789. static GLfloat Map2Vertex4u1, Map2Vertex4u2;
  790. static GLfloat Map2Vertex4v1, Map2Vertex4v2;
  791. static GLfloat *Map2Vertex4 = NULL;
  792. static GLboolean DiscardMap2Vertex4 = GL_FALSE;
  793.  
  794. /* Map 2, Index */
  795. static GLuint Map2Indexuorder;
  796. static GLuint Map2Indexvorder;
  797. static GLfloat Map2Indexu1, Map2Indexu2;
  798. static GLfloat Map2Indexv1, Map2Indexv2;
  799. static GLfloat *Map2Index = NULL;
  800. static GLboolean DiscardMap2Index = GL_FALSE;
  801.  
  802. /* Map 2, Color_4 */
  803. static GLuint Map2Color4uorder;
  804. static GLuint Map2Color4vorder;
  805. static GLfloat Map2Color4u1, Map2Color4u2;
  806. static GLfloat Map2Color4v1, Map2Color4v2;
  807. static GLfloat *Map2Color4 = NULL;
  808. static GLboolean DiscardMap2Color4 = GL_FALSE;
  809.  
  810. /* Map 2, Normal */
  811. static GLuint Map2Normaluorder;
  812. static GLuint Map2Normalvorder;
  813. static GLfloat Map2Normalu1, Map2Normalu2;
  814. static GLfloat Map2Normalv1, Map2Normalv2;
  815. static GLfloat *Map2Normal = NULL;
  816. static GLboolean DiscardMap2Normal = GL_FALSE;
  817.  
  818. /* Map 2, Texture_1 */
  819. static GLuint Map2Texture1uorder;
  820. static GLuint Map2Texture1vorder;
  821. static GLfloat Map2Texture1u1, Map2Texture1u2;
  822. static GLfloat Map2Texture1v1, Map2Texture1v2;
  823. static GLfloat *Map2Texture1 = NULL;
  824. static GLboolean DiscardMap2Texture1 = GL_FALSE;
  825.  
  826. /* Map 2, Texture_2 */
  827. static GLuint Map2Texture2uorder;
  828. static GLuint Map2Texture2vorder;
  829. static GLfloat Map2Texture2u1, Map2Texture2u2;
  830. static GLfloat Map2Texture2v1, Map2Texture2v2;
  831. static GLfloat *Map2Texture2 = NULL;
  832. static GLboolean DiscardMap2Texture2 = GL_FALSE;
  833.  
  834. /* Map 2, Texture_3 */
  835. static GLuint Map2Texture3uorder;
  836. static GLuint Map2Texture3vorder;
  837. static GLfloat Map2Texture3u1, Map2Texture3u2;
  838. static GLfloat Map2Texture3v1, Map2Texture3v2;
  839. static GLfloat *Map2Texture3 = NULL;
  840. static GLboolean DiscardMap2Texture3 = GL_FALSE;
  841.  
  842. /* Map 2, Texture_4 */
  843. static GLuint Map2Texture4uorder;
  844. static GLuint Map2Texture4vorder;
  845. static GLfloat Map2Texture4u1, Map2Texture4u2;
  846. static GLfloat Map2Texture4v1, Map2Texture4v2;
  847. static GLfloat *Map2Texture4 = NULL;
  848. static GLboolean DiscardMap2Texture4 = GL_FALSE;
  849.  
  850. /*
  851.  * Given a Map target, return a pointer to the corresponding Discard
  852.  * variable.
  853.  */
  854. static GLboolean *discard_target( GLenum target )
  855. {
  856.    switch (target) {
  857.       case GL_MAP1_VERTEX_3:        return &DiscardMap1Vertex3;
  858.       case GL_MAP1_VERTEX_4:        return &DiscardMap1Vertex4;
  859.       case GL_MAP1_INDEX:        return &DiscardMap1Index;
  860.       case GL_MAP1_COLOR_4:        return &DiscardMap1Color4;
  861.       case GL_MAP1_NORMAL:        return &DiscardMap1Normal;
  862.       case GL_MAP1_TEXTURE_COORD_1:    return &DiscardMap1Texture1;
  863.       case GL_MAP1_TEXTURE_COORD_2:    return &DiscardMap1Texture2;
  864.       case GL_MAP1_TEXTURE_COORD_3:    return &DiscardMap1Texture3;
  865.       case GL_MAP1_TEXTURE_COORD_4:    return &DiscardMap1Texture4;
  866.       case GL_MAP2_VERTEX_3:        return &DiscardMap2Vertex3;
  867.       case GL_MAP2_VERTEX_4:        return &DiscardMap2Vertex4;
  868.       case GL_MAP2_INDEX:        return &DiscardMap2Index;
  869.       case GL_MAP2_COLOR_4:        return &DiscardMap2Color4;
  870.       case GL_MAP2_NORMAL:        return &DiscardMap2Normal;
  871.       case GL_MAP2_TEXTURE_COORD_1:    return &DiscardMap2Texture1;
  872.       case GL_MAP2_TEXTURE_COORD_2:    return &DiscardMap2Texture2;
  873.       case GL_MAP2_TEXTURE_COORD_3:    return &DiscardMap2Texture3;
  874.       case GL_MAP2_TEXTURE_COORD_4:    return &DiscardMap2Texture4;
  875.       default:
  876.      gl_error( GL_INVALID_ENUM, "discard_target" );
  877.      return NULL;
  878.    }
  879. }
  880.  
  881. /**********************************************************************/
  882. /*                              Public                                */
  883. /**********************************************************************/
  884.  
  885. /*
  886.  * This function is called by the display list deallocator function to
  887.  * specify that a given set of control points are no longer needed.
  888.  * Under certain conditions, we can deallocate the control points memory,
  889.  * otherwise, we mark it as discard-able.
  890.  */
  891.  
  892. void gl_free_control_points( GLenum target, GLfloat *data )
  893. {
  894.    switch (target) {
  895.       case GL_MAP1_VERTEX_3:
  896.          if (data==Map1Vertex3) {
  897.         /* The control points in the display list are currently */
  898.         /* being used so we can mark them as discard-able. */
  899.         DiscardMap1Vertex3 = GL_TRUE;
  900.      }
  901.      else {
  902.         /* The control points in the display list are not currently */
  903.         /* being used. */
  904.         free( data );
  905.      }
  906.      break;
  907.       case GL_MAP1_VERTEX_4:
  908.          if (data==Map1Vertex4)
  909.         DiscardMap1Vertex4 = GL_TRUE;
  910.      else
  911.         free( data );
  912.      break;
  913.       case GL_MAP1_INDEX:
  914.          if (data==Map1Index)
  915.         DiscardMap1Index = GL_TRUE;
  916.      else
  917.         free( data );
  918.      break;
  919.       case GL_MAP1_COLOR_4:
  920.          if (data==Map1Vertex4)
  921.         DiscardMap1Vertex4 = GL_TRUE;
  922.      else
  923.         free( data );
  924.      break;
  925.       case GL_MAP1_NORMAL:
  926.          if (data==Map1Normal)
  927.         DiscardMap1Normal = GL_TRUE;
  928.      else
  929.         free( data );
  930.      break;
  931.       case GL_MAP1_TEXTURE_COORD_1:
  932.          if (data==Map1Texture1)
  933.         DiscardMap1Texture1 = GL_TRUE;
  934.      else
  935.         free( data );
  936.      break;
  937.       case GL_MAP1_TEXTURE_COORD_2:
  938.          if (data==Map1Texture2)
  939.         DiscardMap1Texture2 = GL_TRUE;
  940.      else
  941.         free( data );
  942.      break;
  943.       case GL_MAP1_TEXTURE_COORD_3:
  944.          if (data==Map1Texture3)
  945.         DiscardMap1Texture3 = GL_TRUE;
  946.      else
  947.         free( data );
  948.      break;
  949.       case GL_MAP1_TEXTURE_COORD_4:
  950.          if (data==Map1Texture4)
  951.         DiscardMap1Texture4 = GL_TRUE;
  952.      else
  953.         free( data );
  954.      break;
  955.       case GL_MAP2_VERTEX_3:
  956.          if (data==Map2Vertex3)
  957.         DiscardMap2Vertex3 = GL_TRUE;
  958.      else
  959.         free( data );
  960.      break;
  961.       case GL_MAP2_VERTEX_4:
  962.          if (data==Map2Vertex4)
  963.         DiscardMap2Vertex4 = GL_TRUE;
  964.      else
  965.         free( data );
  966.      break;
  967.       case GL_MAP2_INDEX:
  968.          if (data==Map2Index)
  969.         DiscardMap2Index = GL_TRUE;
  970.      else
  971.         free( data );
  972.      break;
  973.       case GL_MAP2_COLOR_4:
  974.          if (data==Map2Color4)
  975.         DiscardMap2Color4 = GL_TRUE;
  976.      else
  977.         free( data );
  978.      break;
  979.       case GL_MAP2_NORMAL:
  980.          if (data==Map2Normal)
  981.         DiscardMap2Normal = GL_TRUE;
  982.      else
  983.         free( data );
  984.      break;
  985.       case GL_MAP2_TEXTURE_COORD_1:
  986.          if (data==Map2Texture1)
  987.         DiscardMap2Texture1 = GL_TRUE;
  988.      else
  989.         free( data );
  990.      break;
  991.       case GL_MAP2_TEXTURE_COORD_2:
  992.          if (data==Map2Texture2)
  993.         DiscardMap2Texture2 = GL_TRUE;
  994.      else
  995.         free( data );
  996.      break;
  997.       case GL_MAP2_TEXTURE_COORD_3:
  998.          if (data==Map2Texture3)
  999.         DiscardMap2Texture3 = GL_TRUE;
  1000.      else
  1001.         free( data );
  1002.      break;
  1003.       case GL_MAP2_TEXTURE_COORD_4:
  1004.          if (data==Map2Texture4)
  1005.         DiscardMap2Texture4 = GL_TRUE;
  1006.      else
  1007.         free( data );
  1008.      break;
  1009.       default:
  1010.      gl_error( GL_INVALID_ENUM, "gl_free_control_points" );
  1011.    }
  1012. }
  1013.  
  1014. /*
  1015.  * Internal glMap1{fd} function.  Note that points must be a contiguous
  1016.  * array of control points.
  1017.  */
  1018.  
  1019. void gl_map1( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
  1020.           GLint order, const GLfloat *points )
  1021. {
  1022.    GLuint k;
  1023.  
  1024.    if (INSIDE_BEGIN_END) {
  1025.       gl_error( GL_INVALID_OPERATION, "glMap1" );
  1026.       return;
  1027.    }
  1028.  
  1029.    if (u1==u2) {
  1030.       gl_error( GL_INVALID_VALUE, "glMap1(u1,u2)" );
  1031.       return;
  1032.    }
  1033.  
  1034.    if (order<1 || order>MAX_EVAL_ORDER) {
  1035.       gl_error( GL_INVALID_VALUE, "glMap1(order)" );
  1036.       return;
  1037.    }
  1038.  
  1039.    k = components( target );
  1040.    if (k==0) {
  1041.       gl_error( GL_INVALID_ENUM, "glMap1(target)" );
  1042.    }
  1043.  
  1044.    if (stride < k) {
  1045.       gl_error( GL_INVALID_VALUE, "glMap1(stride)" );
  1046.       return;
  1047.    }
  1048.  
  1049.    switch (target) {
  1050.       case GL_MAP1_VERTEX_3:
  1051.          Map1Vertex3order = order;
  1052.      Map1Vertex3u1 = u1;
  1053.      Map1Vertex3u2 = u2;
  1054.      if (Map1Vertex3 && DiscardMap1Vertex3) {
  1055.         free( Map1Vertex3 );
  1056.      }
  1057.      DiscardMap1Vertex3 = GL_FALSE;
  1058.      Map1Vertex3 = (GLfloat *) points;
  1059.      break;
  1060.       case GL_MAP1_VERTEX_4:
  1061.          Map1Vertex4order = order;
  1062.      Map1Vertex4u1 = u1;
  1063.      Map1Vertex4u2 = u2;
  1064.      if (Map1Vertex4 && DiscardMap1Vertex4) {
  1065.         free( Map1Vertex4 );
  1066.      }
  1067.      DiscardMap1Vertex4 = GL_FALSE;
  1068.      Map1Vertex4 = (GLfloat *) points;
  1069.      break;
  1070.       case GL_MAP1_INDEX:
  1071.          Map1Indexorder = order;
  1072.      Map1Indexu1 = u1;
  1073.      Map1Indexu2 = u2;
  1074.      if (Map1Index && DiscardMap1Index) {
  1075.         free( Map1Index );
  1076.      }
  1077.      DiscardMap1Index = GL_FALSE;
  1078.      Map1Index = (GLfloat *) points;
  1079.      break;
  1080.       case GL_MAP1_COLOR_4:
  1081.          Map1Color4order = order;
  1082.      Map1Color4u1 = u1;
  1083.      Map1Color4u2 = u2;
  1084.      if (Map1Color4 && DiscardMap1Color4) {
  1085.         free( Map1Color4 );
  1086.      }
  1087.      DiscardMap1Color4 = GL_FALSE;
  1088.      Map1Color4 = (GLfloat *) points;
  1089.      break;
  1090.       case GL_MAP1_NORMAL:
  1091.          Map1Normalorder = order;
  1092.      Map1Normalu1 = u1;
  1093.      Map1Normalu2 = u2;
  1094.      if (Map1Normal && DiscardMap1Normal) {
  1095.         free( Map1Normal );
  1096.      }
  1097.      DiscardMap1Normal = GL_FALSE;
  1098.      Map1Normal = (GLfloat *) points;
  1099.      break;
  1100.       case GL_MAP1_TEXTURE_COORD_1:
  1101.          Map1Texture1order = order;
  1102.      Map1Texture1u1 = u1;
  1103.      Map1Texture1u2 = u2;
  1104.      if (Map1Texture1 && DiscardMap1Texture1) {
  1105.         free( Map1Texture1 );
  1106.      }
  1107.      DiscardMap1Texture1 = GL_FALSE;
  1108.      Map1Texture1 = (GLfloat *) points;
  1109.      break;
  1110.       case GL_MAP1_TEXTURE_COORD_2:
  1111.          Map1Texture2order = order;
  1112.      Map1Texture2u1 = u1;
  1113.      Map1Texture2u2 = u2;
  1114.      if (Map1Texture2 && DiscardMap1Texture2) {
  1115.         free( Map1Texture2 );
  1116.      }
  1117.      DiscardMap1Texture2 = GL_FALSE;
  1118.      Map1Texture2 = (GLfloat *) points;
  1119.      break;
  1120.       case GL_MAP1_TEXTURE_COORD_3:
  1121.          Map1Texture3order = order;
  1122.      Map1Texture3u1 = u1;
  1123.      Map1Texture3u2 = u2;
  1124.      if (Map1Texture3 && DiscardMap1Texture3) {
  1125.         free( Map1Texture3 );
  1126.      }
  1127.      DiscardMap1Texture3 = GL_FALSE;
  1128.      Map1Texture3 = (GLfloat *) points;
  1129.      break;
  1130.       case GL_MAP1_TEXTURE_COORD_4:
  1131.          Map1Texture4order = order;
  1132.      Map1Texture4u1 = u1;
  1133.      Map1Texture4u2 = u2;
  1134.      if (Map1Texture4 && DiscardMap1Texture4) {
  1135.         free( Map1Texture4 );
  1136.      }
  1137.      DiscardMap1Texture4 = GL_FALSE;
  1138.      Map1Texture4 = (GLfloat *) points;
  1139.      break;
  1140.       default:
  1141.          gl_error( GL_INVALID_ENUM, "glMap1(target)" );
  1142.    }
  1143. }
  1144.  
  1145. void glMap1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
  1146.           GLint order, const GLfloat *points )
  1147. {
  1148.    float *p;
  1149.  
  1150.    p = copy_points1_f(target, stride, order, points);
  1151.  
  1152.    if (!p) {
  1153.       gl_error( GL_OUT_OF_MEMORY, "glMap1f" );
  1154.       return;
  1155.    }
  1156.  
  1157.    /* may be a new stride after copying control points */
  1158.    stride = components( target );
  1159.  
  1160.    if (CC.CompileFlag) {
  1161.       gl_save_map1( target, u1, u2, stride, order, p );
  1162.    }
  1163.    if (CC.ExecuteFlag) {
  1164.       gl_map1( target, u1, u2, stride, order, p );
  1165.       if (!CC.CompileFlag) {
  1166.      /* get pointer to the discard flag for the given target */
  1167.      GLboolean *discard = discard_target( target );
  1168.        /* the control points can be discarded when new ones are bound */
  1169.      *discard = GL_TRUE;
  1170.       }
  1171.    }
  1172. }
  1173.  
  1174. void glMap1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
  1175.           GLint order, const GLdouble *points )
  1176. {
  1177.    float *p;
  1178.  
  1179.    p = copy_points1_d(target, stride, order, points);
  1180.  
  1181.    if (!p) {
  1182.       gl_error( GL_OUT_OF_MEMORY, "glMap1d" );
  1183.       return;
  1184.    }
  1185.  
  1186.    /* may be a new stride after copying control points */
  1187.    stride = components( target );
  1188.  
  1189.    if (CC.CompileFlag) {
  1190.       gl_save_map1( target, u1, u2, stride, order, p );
  1191.    }
  1192.    if (CC.ExecuteFlag) {
  1193.       gl_map1( target, u1, u2, stride, order, p );
  1194.       if (!CC.CompileFlag) {
  1195.      /* get pointer to the discard flag for the given target */
  1196.      GLboolean *discard = discard_target( target );
  1197.        /* the control points can be discarded when new ones are bound */
  1198.      *discard = GL_TRUE;
  1199.       }
  1200.    }
  1201. }
  1202.  
  1203.  
  1204.  
  1205.  
  1206. void gl_map2( GLenum target,
  1207.           GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
  1208.           GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
  1209.           const GLfloat *points )
  1210. {
  1211.    GLuint k;
  1212.  
  1213.    if (INSIDE_BEGIN_END) {
  1214.       gl_error( GL_INVALID_OPERATION, "glMap2" );
  1215.       return;
  1216.    }
  1217.  
  1218.    if (u1==u2) {
  1219.       gl_error( GL_INVALID_VALUE, "glMap2(u1,u2)" );
  1220.       return;
  1221.    }
  1222.  
  1223.    if (v1==v2) {
  1224.       gl_error( GL_INVALID_VALUE, "glMap2(v1,v2)" );
  1225.       return;
  1226.    }
  1227.  
  1228.    if (uorder<1 || uorder>MAX_EVAL_ORDER) {
  1229.       gl_error( GL_INVALID_VALUE, "glMap2(uorder)" );
  1230.       return;
  1231.    }
  1232.  
  1233.    if (vorder<1 || vorder>MAX_EVAL_ORDER) {
  1234.       gl_error( GL_INVALID_VALUE, "glMap2(vorder)" );
  1235.       return;
  1236.    }
  1237.  
  1238.    k = components( target );
  1239.    if (k==0) {
  1240.       gl_error( GL_INVALID_ENUM, "glMap2(target)" );
  1241.    }
  1242.  
  1243.    if (ustride < k) {
  1244.       gl_error( GL_INVALID_VALUE, "glMap2(ustride)" );
  1245.       return;
  1246.    }
  1247.    if (vstride < k) {
  1248.       gl_error( GL_INVALID_VALUE, "glMap2(vstride)" );
  1249.       return;
  1250.    }
  1251.  
  1252.    switch (target) {
  1253.       case GL_MAP2_VERTEX_3:
  1254.          Map2Vertex3uorder = uorder;
  1255.      Map2Vertex3u1 = u1;
  1256.      Map2Vertex3u2 = u2;
  1257.          Map2Vertex3vorder = vorder;
  1258.      Map2Vertex3v1 = v1;
  1259.      Map2Vertex3v2 = v2;
  1260.      if (Map2Vertex3 && DiscardMap2Vertex3) {
  1261.         free( Map2Vertex3 );
  1262.      }
  1263.      DiscardMap2Vertex3 = GL_FALSE;
  1264.      Map2Vertex3 = (GLfloat *) points;
  1265.      break;
  1266.       case GL_MAP2_VERTEX_4:
  1267.          Map2Vertex4uorder = uorder;
  1268.      Map2Vertex4u1 = u1;
  1269.      Map2Vertex4u2 = u2;
  1270.          Map2Vertex4vorder = vorder;
  1271.      Map2Vertex4v1 = v1;
  1272.      Map2Vertex4v2 = v2;
  1273.      if (Map2Vertex4 && DiscardMap2Vertex4) {
  1274.         free( Map2Vertex4 );
  1275.      }
  1276.      DiscardMap2Vertex4 = GL_FALSE;
  1277.      Map2Vertex4 = (GLfloat *) points;
  1278.      break;
  1279.       case GL_MAP2_INDEX:
  1280.          Map2Indexuorder = uorder;
  1281.      Map2Indexu1 = u1;
  1282.      Map2Indexu2 = u2;
  1283.          Map2Indexvorder = vorder;
  1284.      Map2Indexv1 = v1;
  1285.      Map2Indexv2 = v2;
  1286.      if (Map2Index && DiscardMap2Index) {
  1287.         free( Map2Index );
  1288.      }
  1289.      DiscardMap2Index = GL_FALSE;
  1290.      Map2Index = (GLfloat *) points;
  1291.      break;
  1292.       case GL_MAP2_COLOR_4:
  1293.          Map2Color4uorder = uorder;
  1294.      Map2Color4u1 = u1;
  1295.      Map2Color4u2 = u2;
  1296.          Map2Color4vorder = vorder;
  1297.      Map2Color4v1 = v1;
  1298.      Map2Color4v2 = v2;
  1299.      if (Map2Color4 && DiscardMap2Color4) {
  1300.         free( Map2Color4 );
  1301.      }
  1302.      DiscardMap2Color4 = GL_FALSE;
  1303.      Map2Color4 = (GLfloat *) points;
  1304.      break;
  1305.       case GL_MAP2_NORMAL:
  1306.          Map2Normaluorder = uorder;
  1307.      Map2Normalu1 = u1;
  1308.      Map2Normalu2 = u2;
  1309.          Map2Normalvorder = vorder;
  1310.      Map2Normalv1 = v1;
  1311.      Map2Normalv2 = v2;
  1312.      if (Map2Normal && DiscardMap2Normal) {
  1313.         free( Map2Normal );
  1314.      }
  1315.      DiscardMap2Normal = GL_FALSE;
  1316.      Map2Normal = (GLfloat *) points;
  1317.      break;
  1318.       case GL_MAP2_TEXTURE_COORD_1:
  1319.          Map2Texture1uorder = uorder;
  1320.      Map2Texture1u1 = u1;
  1321.      Map2Texture1u2 = u2;
  1322.          Map2Texture1vorder = vorder;
  1323.      Map2Texture1v1 = v1;
  1324.      Map2Texture1v2 = v2;
  1325.      if (Map2Texture1 && DiscardMap2Texture1) {
  1326.         free( Map2Texture1 );
  1327.      }
  1328.      DiscardMap2Texture1 = GL_FALSE;
  1329.      Map2Texture1 = (GLfloat *) points;
  1330.      break;
  1331.       case GL_MAP2_TEXTURE_COORD_2:
  1332.          Map2Texture2uorder = uorder;
  1333.      Map2Texture2u1 = u1;
  1334.      Map2Texture2u2 = u2;
  1335.          Map2Texture2vorder = vorder;
  1336.      Map2Texture2v1 = v1;
  1337.      Map2Texture2v2 = v2;
  1338.      if (Map2Texture2 && DiscardMap2Texture2) {
  1339.         free( Map2Texture2 );
  1340.      }
  1341.      DiscardMap2Texture2 = GL_FALSE;
  1342.      Map2Texture2 = (GLfloat *) points;
  1343.      break;
  1344.       case GL_MAP2_TEXTURE_COORD_3:
  1345.          Map2Texture3uorder = uorder;
  1346.      Map2Texture3u1 = u1;
  1347.      Map2Texture3u2 = u2;
  1348.          Map2Texture3vorder = vorder;
  1349.      Map2Texture3v1 = v1;
  1350.      Map2Texture3v2 = v2;
  1351.      if (Map2Texture3 && DiscardMap2Texture3) {
  1352.         free( Map2Texture3 );
  1353.      }
  1354.      DiscardMap2Texture3 = GL_FALSE;
  1355.      Map2Texture3 = (GLfloat *) points;
  1356.      break;
  1357.       case GL_MAP2_TEXTURE_COORD_4:
  1358.          Map2Texture4uorder = uorder;
  1359.      Map2Texture4u1 = u1;
  1360.      Map2Texture4u2 = u2;
  1361.          Map2Texture4vorder = vorder;
  1362.      Map2Texture4v1 = v1;
  1363.      Map2Texture4v2 = v2;
  1364.      if (Map2Texture4 && DiscardMap2Texture4) {
  1365.         free( Map2Texture4 );
  1366.      }
  1367.      DiscardMap2Texture4 = GL_FALSE;
  1368.      Map2Texture4 = (GLfloat *) points;
  1369.      break;
  1370.       default:
  1371.          gl_error( GL_INVALID_ENUM, "glMap1f(target)" );
  1372.    }
  1373.  
  1374. }
  1375.  
  1376.  
  1377.    
  1378. void glMap2f( GLenum target,
  1379.           GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
  1380.           GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
  1381.           const GLfloat *points )
  1382. {
  1383.    GLfloat *p;
  1384.  
  1385.    p = copy_points2_f(target, ustride, uorder, vstride, vorder, points);
  1386.  
  1387.    if (!p) {
  1388.       gl_error( GL_OUT_OF_MEMORY, "glMap2f" );
  1389.       return;
  1390.    }
  1391.  
  1392.    /* may be a new strides after copying control points */
  1393.    vstride = components( target );
  1394.    ustride = vorder * vstride;
  1395.  
  1396.    if (CC.CompileFlag) {
  1397.       gl_save_map2( target, u1, u2, ustride, uorder,
  1398.             v1, v2, vstride, vorder, p );
  1399.    }
  1400.    if (CC.ExecuteFlag) {
  1401.       gl_map2( target, u1, u2, ustride, uorder,
  1402.            v1, v2, vstride, vorder, p );
  1403.       if (!CC.CompileFlag) {
  1404.      /* get pointer to the discard flag for the given target */
  1405.      GLboolean *discard = discard_target( target );
  1406.        /* the control points can be discarded when new ones are bound */
  1407.      *discard = GL_TRUE;
  1408.       }
  1409.    }
  1410. }
  1411.  
  1412.  
  1413.  
  1414. void glMap2d( GLenum target,
  1415.           GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
  1416.           GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
  1417.           const GLdouble *points )
  1418. {
  1419.    GLfloat *p;
  1420.  
  1421.    p = copy_points2_d(target, ustride, uorder, vstride, vorder, points);
  1422.  
  1423.    if (!p) {
  1424.       gl_error( GL_OUT_OF_MEMORY, "glMap2d" );
  1425.       return;
  1426.    }
  1427.  
  1428.    /* may be a new strides after copying control points */
  1429.    vstride = components( target );
  1430.    ustride = vorder * vstride;
  1431.  
  1432.    if (CC.CompileFlag) {
  1433.       gl_save_map2( target, u1, u2, ustride, uorder,
  1434.             v1, v2, vstride, vorder, p );
  1435.    }
  1436.    if (CC.ExecuteFlag) {
  1437.       gl_map2( target, u1, u2, ustride, uorder,
  1438.            v1, v2, vstride, vorder, p );
  1439.       if (!CC.CompileFlag) {
  1440.      /* get pointer to the discard flag for the given target */
  1441.      GLboolean *discard = discard_target( target );
  1442.        /* the control points can be discarded when new ones are bound */
  1443.      *discard = GL_TRUE;
  1444.       }
  1445.    }
  1446. }
  1447.  
  1448.  
  1449.  
  1450. void glGetMapdv( GLenum target, GLenum query, GLdouble *v )
  1451. {
  1452.    GLuint i, n;
  1453.    GLfloat *data;
  1454.  
  1455.    switch (query) {
  1456.       case GL_COEFF:
  1457.      switch (target) {
  1458.         case GL_MAP1_COLOR_4:
  1459.            data = Map1Color4;
  1460.            n = Map1Color4order * 4;
  1461.            break;
  1462.         case GL_MAP1_INDEX:
  1463.            data = Map1Index;
  1464.            n = Map1Indexorder;
  1465.            break;
  1466.         case GL_MAP1_NORMAL:
  1467.            data = Map1Normal;
  1468.            n = Map1Normalorder * 3;
  1469.            break;
  1470.         case GL_MAP1_TEXTURE_COORD_1:
  1471.            data = Map1Texture1;
  1472.            n = Map1Texture1order * 1;
  1473.            break;
  1474.         case GL_MAP1_TEXTURE_COORD_2:
  1475.            data = Map1Texture2;
  1476.            n = Map1Texture2order * 2;
  1477.            break;
  1478.         case GL_MAP1_TEXTURE_COORD_3:
  1479.            data = Map1Texture3;
  1480.            n = Map1Texture3order * 3;
  1481.            break;
  1482.         case GL_MAP1_TEXTURE_COORD_4:
  1483.            data = Map1Texture4;
  1484.            n = Map1Texture4order * 4;
  1485.            break;
  1486.         case GL_MAP1_VERTEX_3:
  1487.            data = Map1Vertex3;
  1488.            n = Map1Vertex3order * 3;
  1489.            break;
  1490.         case GL_MAP1_VERTEX_4:
  1491.            data = Map1Vertex4;
  1492.            n = Map1Vertex4order * 4;
  1493.            break;
  1494.         case GL_MAP2_COLOR_4:
  1495.            data = Map2Color4;
  1496.            n = Map2Color4uorder * Map2Color4vorder * 4;
  1497.            break;
  1498.         case GL_MAP2_INDEX:
  1499.            data = Map2Index;
  1500.            n = Map2Indexuorder * Map2Indexvorder;
  1501.            break;
  1502.         case GL_MAP2_NORMAL:
  1503.            data = Map2Normal;
  1504.            n = Map2Normaluorder * Map2Normalvorder * 3;
  1505.            break;
  1506.         case GL_MAP2_TEXTURE_COORD_1:
  1507.            data = Map2Texture1;
  1508.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  1509.            break;
  1510.         case GL_MAP2_TEXTURE_COORD_2:
  1511.            data = Map2Texture2;
  1512.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  1513.            break;
  1514.         case GL_MAP2_TEXTURE_COORD_3:
  1515.            data = Map2Texture3;
  1516.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  1517.            break;
  1518.         case GL_MAP2_TEXTURE_COORD_4:
  1519.            data = Map2Texture4;
  1520.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  1521.            break;
  1522.         case GL_MAP2_VERTEX_3:
  1523.            data = Map2Vertex3;
  1524.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  1525.            break;
  1526.         case GL_MAP2_VERTEX_4:
  1527.            data = Map2Vertex4;
  1528.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  1529.            break;
  1530.         default:
  1531.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1532.      }
  1533.      if (data) {
  1534.         for (i=0;i<n;i++) {
  1535.            v[i] = data[i];
  1536.         }
  1537.      }
  1538.          break;
  1539.       case GL_ORDER:
  1540.      switch (target) {
  1541.         case GL_MAP1_COLOR_4:
  1542.            *v = Map1Color4order;
  1543.            break;
  1544.         case GL_MAP1_INDEX:
  1545.            *v = Map1Indexorder;
  1546.            break;
  1547.         case GL_MAP1_NORMAL:
  1548.            *v = Map1Normalorder;
  1549.            break;
  1550.         case GL_MAP1_TEXTURE_COORD_1:
  1551.            *v = Map1Texture1order;
  1552.            break;
  1553.         case GL_MAP1_TEXTURE_COORD_2:
  1554.            *v = Map1Texture2order;
  1555.            break;
  1556.         case GL_MAP1_TEXTURE_COORD_3:
  1557.            *v = Map1Texture3order;
  1558.            break;
  1559.         case GL_MAP1_TEXTURE_COORD_4:
  1560.            *v = Map1Texture4order;
  1561.            break;
  1562.         case GL_MAP1_VERTEX_3:
  1563.            *v = Map1Vertex3order;
  1564.            break;
  1565.         case GL_MAP1_VERTEX_4:
  1566.            *v = Map1Vertex4order;
  1567.            break;
  1568.         case GL_MAP2_COLOR_4:
  1569.            v[0] = Map2Color4uorder;
  1570.            v[1] = Map2Color4vorder;
  1571.            break;
  1572.         case GL_MAP2_INDEX:
  1573.            v[0] = Map2Indexuorder;
  1574.            v[1] = Map2Indexvorder;
  1575.            break;
  1576.         case GL_MAP2_NORMAL:
  1577.            v[0] = Map2Normaluorder;
  1578.            v[1] = Map2Normalvorder;
  1579.            break;
  1580.         case GL_MAP2_TEXTURE_COORD_1:
  1581.            v[0] = Map2Texture1uorder;
  1582.            v[1] = Map2Texture1vorder;
  1583.            break;
  1584.         case GL_MAP2_TEXTURE_COORD_2:
  1585.            v[0] = Map2Texture2uorder;
  1586.            v[1] = Map2Texture2vorder;
  1587.            break;
  1588.         case GL_MAP2_TEXTURE_COORD_3:
  1589.            v[0] = Map2Texture3uorder;
  1590.            v[1] = Map2Texture3vorder;
  1591.            break;
  1592.         case GL_MAP2_TEXTURE_COORD_4:
  1593.            v[0] = Map2Texture4uorder;
  1594.            v[1] = Map2Texture4vorder;
  1595.            break;
  1596.         case GL_MAP2_VERTEX_3:
  1597.            v[0] = Map2Vertex3uorder;
  1598.            v[1] = Map2Vertex3vorder;
  1599.            break;
  1600.         case GL_MAP2_VERTEX_4:
  1601.            v[0] = Map2Vertex4uorder;
  1602.            v[1] = Map2Vertex4vorder;
  1603.            break;
  1604.         default:
  1605.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1606.      }
  1607.          break;
  1608.       case GL_DOMAIN:
  1609.      switch (target) {
  1610.         case GL_MAP1_COLOR_4:
  1611.            v[0] = Map1Color4u1;
  1612.            v[1] = Map1Color4u2;
  1613.            break;
  1614.         case GL_MAP1_INDEX:
  1615.            v[0] = Map1Indexu1;
  1616.            v[1] = Map1Indexu2;
  1617.            break;
  1618.         case GL_MAP1_NORMAL:
  1619.            v[0] = Map1Normalu1;
  1620.            v[1] = Map1Normalu2;
  1621.            break;
  1622.         case GL_MAP1_TEXTURE_COORD_1:
  1623.            v[0] = Map1Texture1u1;
  1624.            v[1] = Map1Texture1u2;
  1625.            break;
  1626.         case GL_MAP1_TEXTURE_COORD_2:
  1627.            v[0] = Map1Texture2u1;
  1628.            v[1] = Map1Texture2u2;
  1629.            break;
  1630.         case GL_MAP1_TEXTURE_COORD_3:
  1631.            v[0] = Map1Texture3u1;
  1632.            v[1] = Map1Texture3u2;
  1633.            break;
  1634.         case GL_MAP1_TEXTURE_COORD_4:
  1635.            v[0] = Map1Texture4u1;
  1636.            v[1] = Map1Texture4u2;
  1637.            break;
  1638.         case GL_MAP1_VERTEX_3:
  1639.            v[0] = Map1Vertex3u1;
  1640.            v[1] = Map1Vertex3u2;
  1641.            break;
  1642.         case GL_MAP1_VERTEX_4:
  1643.            v[0] = Map1Vertex4u1;
  1644.            v[1] = Map1Vertex4u2;
  1645.            break;
  1646.         case GL_MAP2_COLOR_4:
  1647.            v[0] = Map2Color4u1;
  1648.            v[1] = Map2Color4u2;
  1649.            v[2] = Map2Color4v1;
  1650.            v[3] = Map2Color4v2;
  1651.            break;
  1652.         case GL_MAP2_INDEX:
  1653.            v[0] = Map2Indexu1;
  1654.            v[1] = Map2Indexu2;
  1655.            v[2] = Map2Indexv1;
  1656.            v[3] = Map2Indexv2;
  1657.            break;
  1658.         case GL_MAP2_NORMAL:
  1659.            v[0] = Map2Normalu1;
  1660.            v[1] = Map2Normalu2;
  1661.            v[2] = Map2Normalv1;
  1662.            v[3] = Map2Normalv2;
  1663.            break;
  1664.         case GL_MAP2_TEXTURE_COORD_1:
  1665.            v[0] = Map2Texture1u1;
  1666.            v[1] = Map2Texture1u2;
  1667.            v[2] = Map2Texture1v1;
  1668.            v[3] = Map2Texture1v2;
  1669.            break;
  1670.         case GL_MAP2_TEXTURE_COORD_2:
  1671.            v[0] = Map2Texture2u1;
  1672.            v[1] = Map2Texture2u2;
  1673.            v[2] = Map2Texture2v1;
  1674.            v[3] = Map2Texture2v2;
  1675.            break;
  1676.         case GL_MAP2_TEXTURE_COORD_3:
  1677.            v[0] = Map2Texture3u1;
  1678.            v[1] = Map2Texture3u2;
  1679.            v[2] = Map2Texture3v1;
  1680.            v[3] = Map2Texture3v2;
  1681.            break;
  1682.         case GL_MAP2_TEXTURE_COORD_4:
  1683.            v[0] = Map2Texture4u1;
  1684.            v[1] = Map2Texture4u2;
  1685.            v[2] = Map2Texture4v1;
  1686.            v[3] = Map2Texture4v2;
  1687.            break;
  1688.         case GL_MAP2_VERTEX_3:
  1689.            v[0] = Map2Vertex3u1;
  1690.            v[1] = Map2Vertex3u2;
  1691.            v[2] = Map2Vertex3v1;
  1692.            v[3] = Map2Vertex3v2;
  1693.            break;
  1694.         case GL_MAP2_VERTEX_4:
  1695.            v[0] = Map2Vertex4u1;
  1696.            v[1] = Map2Vertex4u2;
  1697.            v[2] = Map2Vertex4v1;
  1698.            v[3] = Map2Vertex4v2;
  1699.            break;
  1700.         default:
  1701.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1702.      }
  1703.          break;
  1704.       default:
  1705.          gl_error( GL_INVALID_ENUM, "glGetMapdv(query)" );
  1706.    }
  1707. }
  1708.  
  1709.  
  1710. void glGetMapfv( GLenum target, GLenum query, GLfloat *v )
  1711. {
  1712.    GLuint i, n;
  1713.    GLfloat *data;
  1714.  
  1715.    switch (query) {
  1716.       case GL_COEFF:
  1717.      switch (target) {
  1718.         case GL_MAP1_COLOR_4:
  1719.            data = Map1Color4;
  1720.            n = Map1Color4order * 4;
  1721.            break;
  1722.         case GL_MAP1_INDEX:
  1723.            data = Map1Index;
  1724.            n = Map1Indexorder;
  1725.            break;
  1726.         case GL_MAP1_NORMAL:
  1727.            data = Map1Normal;
  1728.            n = Map1Normalorder * 3;
  1729.            break;
  1730.         case GL_MAP1_TEXTURE_COORD_1:
  1731.            data = Map1Texture1;
  1732.            n = Map1Texture1order * 1;
  1733.            break;
  1734.         case GL_MAP1_TEXTURE_COORD_2:
  1735.            data = Map1Texture2;
  1736.            n = Map1Texture2order * 2;
  1737.            break;
  1738.         case GL_MAP1_TEXTURE_COORD_3:
  1739.            data = Map1Texture3;
  1740.            n = Map1Texture3order * 3;
  1741.            break;
  1742.         case GL_MAP1_TEXTURE_COORD_4:
  1743.            data = Map1Texture4;
  1744.            n = Map1Texture4order * 4;
  1745.            break;
  1746.         case GL_MAP1_VERTEX_3:
  1747.            data = Map1Vertex3;
  1748.            n = Map1Vertex3order * 3;
  1749.            break;
  1750.         case GL_MAP1_VERTEX_4:
  1751.            data = Map1Vertex4;
  1752.            n = Map1Vertex4order * 4;
  1753.            break;
  1754.         case GL_MAP2_COLOR_4:
  1755.            data = Map2Color4;
  1756.            n = Map2Color4uorder * Map2Color4vorder * 4;
  1757.            break;
  1758.         case GL_MAP2_INDEX:
  1759.            data = Map2Index;
  1760.            n = Map2Indexuorder * Map2Indexvorder;
  1761.            break;
  1762.         case GL_MAP2_NORMAL:
  1763.            data = Map2Normal;
  1764.            n = Map2Normaluorder * Map2Normalvorder * 3;
  1765.            break;
  1766.         case GL_MAP2_TEXTURE_COORD_1:
  1767.            data = Map2Texture1;
  1768.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  1769.            break;
  1770.         case GL_MAP2_TEXTURE_COORD_2:
  1771.            data = Map2Texture2;
  1772.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  1773.            break;
  1774.         case GL_MAP2_TEXTURE_COORD_3:
  1775.            data = Map2Texture3;
  1776.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  1777.            break;
  1778.         case GL_MAP2_TEXTURE_COORD_4:
  1779.            data = Map2Texture4;
  1780.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  1781.            break;
  1782.         case GL_MAP2_VERTEX_3:
  1783.            data = Map2Vertex3;
  1784.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  1785.            break;
  1786.         case GL_MAP2_VERTEX_4:
  1787.            data = Map2Vertex4;
  1788.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  1789.            break;
  1790.         default:
  1791.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1792.      }
  1793.      if (data) {
  1794.         for (i=0;i<n;i++) {
  1795.            v[i] = data[i];
  1796.         }
  1797.      }
  1798.          break;
  1799.       case GL_ORDER:
  1800.      switch (target) {
  1801.         case GL_MAP1_COLOR_4:
  1802.            *v = Map1Color4order;
  1803.            break;
  1804.         case GL_MAP1_INDEX:
  1805.            *v = Map1Indexorder;
  1806.            break;
  1807.         case GL_MAP1_NORMAL:
  1808.            *v = Map1Normalorder;
  1809.            break;
  1810.         case GL_MAP1_TEXTURE_COORD_1:
  1811.            *v = Map1Texture1order;
  1812.            break;
  1813.         case GL_MAP1_TEXTURE_COORD_2:
  1814.            *v = Map1Texture2order;
  1815.            break;
  1816.         case GL_MAP1_TEXTURE_COORD_3:
  1817.            *v = Map1Texture3order;
  1818.            break;
  1819.         case GL_MAP1_TEXTURE_COORD_4:
  1820.            *v = Map1Texture4order;
  1821.            break;
  1822.         case GL_MAP1_VERTEX_3:
  1823.            *v = Map1Vertex3order;
  1824.            break;
  1825.         case GL_MAP1_VERTEX_4:
  1826.            *v = Map1Vertex4order;
  1827.            break;
  1828.         case GL_MAP2_COLOR_4:
  1829.            v[0] = Map2Color4uorder;
  1830.            v[1] = Map2Color4vorder;
  1831.            break;
  1832.         case GL_MAP2_INDEX:
  1833.            v[0] = Map2Indexuorder;
  1834.            v[1] = Map2Indexvorder;
  1835.            break;
  1836.         case GL_MAP2_NORMAL:
  1837.            v[0] = Map2Normaluorder;
  1838.            v[1] = Map2Normalvorder;
  1839.            break;
  1840.         case GL_MAP2_TEXTURE_COORD_1:
  1841.            v[0] = Map2Texture1uorder;
  1842.            v[1] = Map2Texture1vorder;
  1843.            break;
  1844.         case GL_MAP2_TEXTURE_COORD_2:
  1845.            v[0] = Map2Texture2uorder;
  1846.            v[1] = Map2Texture2vorder;
  1847.            break;
  1848.         case GL_MAP2_TEXTURE_COORD_3:
  1849.            v[0] = Map2Texture3uorder;
  1850.            v[1] = Map2Texture3vorder;
  1851.            break;
  1852.         case GL_MAP2_TEXTURE_COORD_4:
  1853.            v[0] = Map2Texture4uorder;
  1854.            v[1] = Map2Texture4vorder;
  1855.            break;
  1856.         case GL_MAP2_VERTEX_3:
  1857.            v[0] = Map2Vertex3uorder;
  1858.            v[1] = Map2Vertex3vorder;
  1859.            break;
  1860.         case GL_MAP2_VERTEX_4:
  1861.            v[0] = Map2Vertex4uorder;
  1862.            v[1] = Map2Vertex4vorder;
  1863.            break;
  1864.         default:
  1865.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1866.      }
  1867.          break;
  1868.       case GL_DOMAIN:
  1869.      switch (target) {
  1870.         case GL_MAP1_COLOR_4:
  1871.            v[0] = Map1Color4u1;
  1872.            v[1] = Map1Color4u2;
  1873.            break;
  1874.         case GL_MAP1_INDEX:
  1875.            v[0] = Map1Indexu1;
  1876.            v[1] = Map1Indexu2;
  1877.            break;
  1878.         case GL_MAP1_NORMAL:
  1879.            v[0] = Map1Normalu1;
  1880.            v[1] = Map1Normalu2;
  1881.            break;
  1882.         case GL_MAP1_TEXTURE_COORD_1:
  1883.            v[0] = Map1Texture1u1;
  1884.            v[1] = Map1Texture1u2;
  1885.            break;
  1886.         case GL_MAP1_TEXTURE_COORD_2:
  1887.            v[0] = Map1Texture2u1;
  1888.            v[1] = Map1Texture2u2;
  1889.            break;
  1890.         case GL_MAP1_TEXTURE_COORD_3:
  1891.            v[0] = Map1Texture3u1;
  1892.            v[1] = Map1Texture3u2;
  1893.            break;
  1894.         case GL_MAP1_TEXTURE_COORD_4:
  1895.            v[0] = Map1Texture4u1;
  1896.            v[1] = Map1Texture4u2;
  1897.            break;
  1898.         case GL_MAP1_VERTEX_3:
  1899.            v[0] = Map1Vertex3u1;
  1900.            v[1] = Map1Vertex3u2;
  1901.            break;
  1902.         case GL_MAP1_VERTEX_4:
  1903.            v[0] = Map1Vertex4u1;
  1904.            v[1] = Map1Vertex4u2;
  1905.            break;
  1906.         case GL_MAP2_COLOR_4:
  1907.            v[0] = Map2Color4u1;
  1908.            v[1] = Map2Color4u2;
  1909.            v[2] = Map2Color4v1;
  1910.            v[3] = Map2Color4v2;
  1911.            break;
  1912.         case GL_MAP2_INDEX:
  1913.            v[0] = Map2Indexu1;
  1914.            v[1] = Map2Indexu2;
  1915.            v[2] = Map2Indexv1;
  1916.            v[3] = Map2Indexv2;
  1917.            break;
  1918.         case GL_MAP2_NORMAL:
  1919.            v[0] = Map2Normalu1;
  1920.            v[1] = Map2Normalu2;
  1921.            v[2] = Map2Normalv1;
  1922.            v[3] = Map2Normalv2;
  1923.            break;
  1924.         case GL_MAP2_TEXTURE_COORD_1:
  1925.            v[0] = Map2Texture1u1;
  1926.            v[1] = Map2Texture1u2;
  1927.            v[2] = Map2Texture1v1;
  1928.            v[3] = Map2Texture1v2;
  1929.            break;
  1930.         case GL_MAP2_TEXTURE_COORD_2:
  1931.            v[0] = Map2Texture2u1;
  1932.            v[1] = Map2Texture2u2;
  1933.            v[2] = Map2Texture2v1;
  1934.            v[3] = Map2Texture2v2;
  1935.            break;
  1936.         case GL_MAP2_TEXTURE_COORD_3:
  1937.            v[0] = Map2Texture3u1;
  1938.            v[1] = Map2Texture3u2;
  1939.            v[2] = Map2Texture3v1;
  1940.            v[3] = Map2Texture3v2;
  1941.            break;
  1942.         case GL_MAP2_TEXTURE_COORD_4:
  1943.            v[0] = Map2Texture4u1;
  1944.            v[1] = Map2Texture4u2;
  1945.            v[2] = Map2Texture4v1;
  1946.            v[3] = Map2Texture4v2;
  1947.            break;
  1948.         case GL_MAP2_VERTEX_3:
  1949.            v[0] = Map2Vertex3u1;
  1950.            v[1] = Map2Vertex3u2;
  1951.            v[2] = Map2Vertex3v1;
  1952.            v[3] = Map2Vertex3v2;
  1953.            break;
  1954.         case GL_MAP2_VERTEX_4:
  1955.            v[0] = Map2Vertex4u1;
  1956.            v[1] = Map2Vertex4u2;
  1957.            v[2] = Map2Vertex4v1;
  1958.            v[3] = Map2Vertex4v2;
  1959.            break;
  1960.         default:
  1961.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1962.      }
  1963.          break;
  1964.       default:
  1965.          gl_error( GL_INVALID_ENUM, "glGetMapfv(query)" );
  1966.    }
  1967. }
  1968.  
  1969.  
  1970. void glGetMapiv( GLenum target, GLenum query, GLint *v )
  1971. {
  1972.    GLuint i, n;
  1973.    GLfloat *data;
  1974.  
  1975.    switch (query) {
  1976.       case GL_COEFF:
  1977.      switch (target) {
  1978.         case GL_MAP1_COLOR_4:
  1979.            data = Map1Color4;
  1980.            n = Map1Color4order * 4;
  1981.            break;
  1982.         case GL_MAP1_INDEX:
  1983.            data = Map1Index;
  1984.            n = Map1Indexorder;
  1985.            break;
  1986.         case GL_MAP1_NORMAL:
  1987.            data = Map1Normal;
  1988.            n = Map1Normalorder * 3;
  1989.            break;
  1990.         case GL_MAP1_TEXTURE_COORD_1:
  1991.            data = Map1Texture1;
  1992.            n = Map1Texture1order * 1;
  1993.            break;
  1994.         case GL_MAP1_TEXTURE_COORD_2:
  1995.            data = Map1Texture2;
  1996.            n = Map1Texture2order * 2;
  1997.            break;
  1998.         case GL_MAP1_TEXTURE_COORD_3:
  1999.            data = Map1Texture3;
  2000.            n = Map1Texture3order * 3;
  2001.            break;
  2002.         case GL_MAP1_TEXTURE_COORD_4:
  2003.            data = Map1Texture4;
  2004.            n = Map1Texture4order * 4;
  2005.            break;
  2006.         case GL_MAP1_VERTEX_3:
  2007.            data = Map1Vertex3;
  2008.            n = Map1Vertex3order * 3;
  2009.            break;
  2010.         case GL_MAP1_VERTEX_4:
  2011.            data = Map1Vertex4;
  2012.            n = Map1Vertex4order * 4;
  2013.            break;
  2014.         case GL_MAP2_COLOR_4:
  2015.            data = Map2Color4;
  2016.            n = Map2Color4uorder * Map2Color4vorder * 4;
  2017.            break;
  2018.         case GL_MAP2_INDEX:
  2019.            data = Map2Index;
  2020.            n = Map2Indexuorder * Map2Indexvorder;
  2021.            break;
  2022.         case GL_MAP2_NORMAL:
  2023.            data = Map2Normal;
  2024.            n = Map2Normaluorder * Map2Normalvorder * 3;
  2025.            break;
  2026.         case GL_MAP2_TEXTURE_COORD_1:
  2027.            data = Map2Texture1;
  2028.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  2029.            break;
  2030.         case GL_MAP2_TEXTURE_COORD_2:
  2031.            data = Map2Texture2;
  2032.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  2033.            break;
  2034.         case GL_MAP2_TEXTURE_COORD_3:
  2035.            data = Map2Texture3;
  2036.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  2037.            break;
  2038.         case GL_MAP2_TEXTURE_COORD_4:
  2039.            data = Map2Texture4;
  2040.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  2041.            break;
  2042.         case GL_MAP2_VERTEX_3:
  2043.            data = Map2Vertex3;
  2044.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  2045.            break;
  2046.         case GL_MAP2_VERTEX_4:
  2047.            data = Map2Vertex4;
  2048.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  2049.            break;
  2050.         default:
  2051.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2052.      }
  2053.      if (data) {
  2054.         for (i=0;i<n;i++) {
  2055.            v[i] = ROUNDF(data[i]);
  2056.         }
  2057.      }
  2058.          break;
  2059.       case GL_ORDER:
  2060.      switch (target) {
  2061.         case GL_MAP1_COLOR_4:
  2062.            *v = Map1Color4order;
  2063.            break;
  2064.         case GL_MAP1_INDEX:
  2065.            *v = Map1Indexorder;
  2066.            break;
  2067.         case GL_MAP1_NORMAL:
  2068.            *v = Map1Normalorder;
  2069.            break;
  2070.         case GL_MAP1_TEXTURE_COORD_1:
  2071.            *v = Map1Texture1order;
  2072.            break;
  2073.         case GL_MAP1_TEXTURE_COORD_2:
  2074.            *v = Map1Texture2order;
  2075.            break;
  2076.         case GL_MAP1_TEXTURE_COORD_3:
  2077.            *v = Map1Texture3order;
  2078.            break;
  2079.         case GL_MAP1_TEXTURE_COORD_4:
  2080.            *v = Map1Texture4order;
  2081.            break;
  2082.         case GL_MAP1_VERTEX_3:
  2083.            *v = Map1Vertex3order;
  2084.            break;
  2085.         case GL_MAP1_VERTEX_4:
  2086.            *v = Map1Vertex4order;
  2087.            break;
  2088.         case GL_MAP2_COLOR_4:
  2089.            v[0] = Map2Color4uorder;
  2090.            v[1] = Map2Color4vorder;
  2091.            break;
  2092.         case GL_MAP2_INDEX:
  2093.            v[0] = Map2Indexuorder;
  2094.            v[1] = Map2Indexvorder;
  2095.            break;
  2096.         case GL_MAP2_NORMAL:
  2097.            v[0] = Map2Normaluorder;
  2098.            v[1] = Map2Normalvorder;
  2099.            break;
  2100.         case GL_MAP2_TEXTURE_COORD_1:
  2101.            v[0] = Map2Texture1uorder;
  2102.            v[1] = Map2Texture1vorder;
  2103.            break;
  2104.         case GL_MAP2_TEXTURE_COORD_2:
  2105.            v[0] = Map2Texture2uorder;
  2106.            v[1] = Map2Texture2vorder;
  2107.            break;
  2108.         case GL_MAP2_TEXTURE_COORD_3:
  2109.            v[0] = Map2Texture3uorder;
  2110.            v[1] = Map2Texture3vorder;
  2111.            break;
  2112.         case GL_MAP2_TEXTURE_COORD_4:
  2113.            v[0] = Map2Texture4uorder;
  2114.            v[1] = Map2Texture4vorder;
  2115.            break;
  2116.         case GL_MAP2_VERTEX_3:
  2117.            v[0] = Map2Vertex3uorder;
  2118.            v[1] = Map2Vertex3vorder;
  2119.            break;
  2120.         case GL_MAP2_VERTEX_4:
  2121.            v[0] = Map2Vertex4uorder;
  2122.            v[1] = Map2Vertex4vorder;
  2123.            break;
  2124.         default:
  2125.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2126.      }
  2127.          break;
  2128.       case GL_DOMAIN:
  2129.      switch (target) {
  2130.         case GL_MAP1_COLOR_4:
  2131.            v[0] = ROUNDF(Map1Color4u1);
  2132.            v[1] = ROUNDF(Map1Color4u2);
  2133.            break;
  2134.         case GL_MAP1_INDEX:
  2135.            v[0] = ROUNDF(Map1Indexu1);
  2136.            v[1] = ROUNDF(Map1Indexu2);
  2137.            break;
  2138.         case GL_MAP1_NORMAL:
  2139.            v[0] = ROUNDF(Map1Normalu1);
  2140.            v[1] = ROUNDF(Map1Normalu2);
  2141.            break;
  2142.         case GL_MAP1_TEXTURE_COORD_1:
  2143.            v[0] = ROUNDF(Map1Texture1u1);
  2144.            v[1] = ROUNDF(Map1Texture1u2);
  2145.            break;
  2146.         case GL_MAP1_TEXTURE_COORD_2:
  2147.            v[0] = ROUNDF(Map1Texture2u1);
  2148.            v[1] = ROUNDF(Map1Texture2u2);
  2149.            break;
  2150.         case GL_MAP1_TEXTURE_COORD_3:
  2151.            v[0] = ROUNDF(Map1Texture3u1);
  2152.            v[1] = ROUNDF(Map1Texture3u2);
  2153.            break;
  2154.         case GL_MAP1_TEXTURE_COORD_4:
  2155.            v[0] = ROUNDF(Map1Texture4u1);
  2156.            v[1] = ROUNDF(Map1Texture4u2);
  2157.            break;
  2158.         case GL_MAP1_VERTEX_3:
  2159.            v[0] = ROUNDF(Map1Vertex3u1);
  2160.            v[1] = ROUNDF(Map1Vertex3u2);
  2161.            break;
  2162.         case GL_MAP1_VERTEX_4:
  2163.            v[0] = ROUNDF(Map1Vertex4u1);
  2164.            v[1] = ROUNDF(Map1Vertex4u2);
  2165.            break;
  2166.         case GL_MAP2_COLOR_4:
  2167.            v[0] = ROUNDF(Map2Color4u1);
  2168.            v[1] = ROUNDF(Map2Color4u2);
  2169.            v[2] = ROUNDF(Map2Color4v1);
  2170.            v[3] = ROUNDF(Map2Color4v2);
  2171.            break;
  2172.         case GL_MAP2_INDEX:
  2173.            v[0] = ROUNDF(Map2Indexu1);
  2174.            v[1] = ROUNDF(Map2Indexu2);
  2175.            v[2] = ROUNDF(Map2Indexv1);
  2176.            v[3] = ROUNDF(Map2Indexv2);
  2177.            break;
  2178.         case GL_MAP2_NORMAL:
  2179.            v[0] = ROUNDF(Map2Normalu1);
  2180.            v[1] = ROUNDF(Map2Normalu2);
  2181.            v[2] = ROUNDF(Map2Normalv1);
  2182.            v[3] = ROUNDF(Map2Normalv2);
  2183.            break;
  2184.         case GL_MAP2_TEXTURE_COORD_1:
  2185.            v[0] = ROUNDF(Map2Texture1u1);
  2186.            v[1] = ROUNDF(Map2Texture1u2);
  2187.            v[2] = ROUNDF(Map2Texture1v1);
  2188.            v[3] = ROUNDF(Map2Texture1v2);
  2189.            break;
  2190.         case GL_MAP2_TEXTURE_COORD_2:
  2191.            v[0] = ROUNDF(Map2Texture2u1);
  2192.            v[1] = ROUNDF(Map2Texture2u2);
  2193.            v[2] = ROUNDF(Map2Texture2v1);
  2194.            v[3] = ROUNDF(Map2Texture2v2);
  2195.            break;
  2196.         case GL_MAP2_TEXTURE_COORD_3:
  2197.            v[0] = ROUNDF(Map2Texture3u1);
  2198.            v[1] = ROUNDF(Map2Texture3u2);
  2199.            v[2] = ROUNDF(Map2Texture3v1);
  2200.            v[3] = ROUNDF(Map2Texture3v2);
  2201.            break;
  2202.         case GL_MAP2_TEXTURE_COORD_4:
  2203.            v[0] = ROUNDF(Map2Texture4u1);
  2204.            v[1] = ROUNDF(Map2Texture4u2);
  2205.            v[2] = ROUNDF(Map2Texture4v1);
  2206.            v[3] = ROUNDF(Map2Texture4v2);
  2207.            break;
  2208.         case GL_MAP2_VERTEX_3:
  2209.            v[0] = ROUNDF(Map2Vertex3u1);
  2210.            v[1] = ROUNDF(Map2Vertex3u2);
  2211.            v[2] = ROUNDF(Map2Vertex3v1);
  2212.            v[3] = ROUNDF(Map2Vertex3v2);
  2213.            break;
  2214.         case GL_MAP2_VERTEX_4:
  2215.            v[0] = ROUNDF(Map2Vertex4u1);
  2216.            v[1] = ROUNDF(Map2Vertex4u2);
  2217.            v[2] = ROUNDF(Map2Vertex4v1);
  2218.            v[3] = ROUNDF(Map2Vertex4v2);
  2219.            break;
  2220.         default:
  2221.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2222.      }
  2223.          break;
  2224.       default:
  2225.          gl_error( GL_INVALID_ENUM, "glGetMapiv(query)" );
  2226.    }
  2227. }
  2228.  
  2229.  
  2230.  
  2231. void gl_evalcoord1(GLfloat u)
  2232. {
  2233.   GLfloat vertex[4];
  2234.   GLfloat normal[3];
  2235.   GLfloat fcolor[4];
  2236.   GLint icolor[4];
  2237.   GLint *colorptr;
  2238.   GLfloat texcoord[4];
  2239.   GLuint index;
  2240.   register GLfloat uu;
  2241.  
  2242.   /** Vertex **/
  2243.   if (CC.Eval.Map1Vertex4) 
  2244.   {
  2245.     uu = (u-Map1Vertex4u1) / (Map1Vertex4u2-Map1Vertex4u1);
  2246.     horner_bezier_curve(Map1Vertex4, vertex, uu, 4, Map1Vertex4order);
  2247.   }
  2248.   else if (CC.Eval.Map1Vertex3) 
  2249.   {
  2250.     uu = (u-Map1Vertex3u1) / (Map1Vertex3u2-Map1Vertex3u1);
  2251.     horner_bezier_curve(Map1Vertex3, vertex, uu, 3, Map1Vertex3order);
  2252.  
  2253.     vertex[3] = 1.0;
  2254.   }
  2255.  
  2256.   /** Color Index **/
  2257.   if (CC.Eval.Map1Index) 
  2258.   {
  2259.     GLfloat findex;
  2260.     uu = (u-Map1Indexu1) / (Map1Indexu2-Map1Indexu1);
  2261.     horner_bezier_curve(Map1Index, &findex, uu, 1, Map1Indexorder);
  2262.     index = (GLuint) (GLint) findex;
  2263.   }
  2264.   else 
  2265.     index = CC.Current.Index;
  2266.  
  2267.   /** Color **/
  2268.   if (CC.Eval.Map1Color4) 
  2269.   {
  2270.     uu = (u-Map1Color4u1) / (Map1Color4u2-Map1Color4u1);
  2271.     horner_bezier_curve(Map1Color4, fcolor, uu, 4, Map1Color4order);
  2272.     icolor[0] = (GLint) (fcolor[0] * CC.RedScale);
  2273.     icolor[1] = (GLint) (fcolor[1] * CC.GreenScale);
  2274.     icolor[2] = (GLint) (fcolor[2] * CC.BlueScale);
  2275.     icolor[3] = (GLint) (fcolor[3] * CC.AlphaScale);
  2276.     colorptr = icolor;
  2277.   }
  2278.   else 
  2279.   {
  2280.     colorptr = CC.Current.IntColor;
  2281.   }
  2282.  
  2283.   /** Normal Vector **/
  2284.   if (CC.Eval.Map1Normal) 
  2285.   {
  2286.     uu = (u-Map1Normalu1) / (Map1Normalu2-Map1Normalu1);
  2287.     horner_bezier_curve(Map1Normal, normal, uu, 3, Map1Normalorder);
  2288.   }
  2289.   else 
  2290.   {
  2291.     normal[0] = CC.Current.Normal[0];
  2292.     normal[1] = CC.Current.Normal[1];
  2293.     normal[2] = CC.Current.Normal[2];
  2294.   }
  2295.  
  2296.   /** Texture Coordinates **/
  2297.   if (CC.Eval.Map1TextureCoord4) 
  2298.   {
  2299.     uu = (u-Map1Texture4u1) / (Map1Texture4u2-Map1Texture4u1);
  2300.     horner_bezier_curve(Map1Texture4, texcoord, uu, 4, Map1Texture4order);
  2301.   }
  2302.   else if (CC.Eval.Map1TextureCoord3) 
  2303.   {
  2304.     uu = (u-Map1Texture3u1) / (Map1Texture3u2-Map1Texture3u1);
  2305.     horner_bezier_curve(Map1Texture3, texcoord, uu, 3, Map1Texture3order);
  2306.     texcoord[3] = 1.0;
  2307.   }
  2308.   else if (CC.Eval.Map1TextureCoord2) 
  2309.   {
  2310.     uu = (u-Map1Texture2u1) / (Map1Texture2u2-Map1Texture2u1);
  2311.     horner_bezier_curve(Map1Texture2, texcoord, uu, 2, Map1Texture2order);
  2312.     
  2313.     texcoord[2] = 0.0;
  2314.     texcoord[3] = 1.0;
  2315.   }
  2316.   else if (CC.Eval.Map1TextureCoord1) 
  2317.   {
  2318.     uu = (u-Map1Texture1u1) / (Map1Texture1u2-Map1Texture1u1);
  2319.     horner_bezier_curve(Map1Texture1, texcoord, uu, 1, Map1Texture1order);
  2320.     
  2321.     texcoord[1] = 0.0;
  2322.     texcoord[2] = 0.0;
  2323.     texcoord[3] = 1.0;
  2324.   }
  2325.   else 
  2326.   {
  2327.     texcoord[0] = CC.Current.TexCoord[0];
  2328.     texcoord[1] = CC.Current.TexCoord[1];
  2329.     texcoord[2] = CC.Current.TexCoord[2];
  2330.     texcoord[3] = CC.Current.TexCoord[3];
  2331.   }
  2332.   
  2333.   gl_eval_vertex( vertex, normal, colorptr, index, texcoord );
  2334. }
  2335.  
  2336. void glEvalCoord1f( GLfloat u )
  2337. {
  2338.    if (CC.CompileFlag) {
  2339.       gl_save_evalcoord1( u );
  2340.    }
  2341.    if (CC.ExecuteFlag) {
  2342.       gl_evalcoord1( u );
  2343.    }
  2344. }
  2345.  
  2346.  
  2347. void glEvalCoord1fv( const GLfloat *u )
  2348. {
  2349.    if (CC.CompileFlag) {
  2350.       gl_save_evalcoord1( *u );
  2351.    }
  2352.    if (CC.ExecuteFlag) {
  2353.       gl_evalcoord1( *u );
  2354.    }
  2355. }
  2356.  
  2357.  
  2358. void glEvalCoord1d( GLdouble u )
  2359. {
  2360.    if (CC.CompileFlag) {
  2361.       gl_save_evalcoord1( (GLfloat) u );
  2362.    }
  2363.    if (CC.ExecuteFlag) {
  2364.       gl_evalcoord1( (GLfloat) u );
  2365.    }
  2366. }
  2367.  
  2368.  
  2369. void glEvalCoord1dv( const GLdouble *u )
  2370. {
  2371.    if (CC.CompileFlag) {
  2372.       gl_save_evalcoord1( (GLfloat) *u );
  2373.    }
  2374.    if (CC.ExecuteFlag) {
  2375.       gl_evalcoord1( (GLfloat) *u );
  2376.    }
  2377. }
  2378.  
  2379.  
  2380. void gl_evalcoord2( GLfloat u, GLfloat v )
  2381. {
  2382.    GLfloat vertex[4];
  2383.    GLfloat normal[3];
  2384.    GLfloat fcolor[4];
  2385.    GLint icolor[4];
  2386.    GLint *colorptr;
  2387.    GLfloat texcoord[4];
  2388.    GLuint index;
  2389.    register GLfloat uu, vv;
  2390.  
  2391. #define CROSS_PROD(n, u, v) \
  2392.   (n)[0] = (u)[1]*(v)[2] - (u)[2]*(v)[1]; \
  2393.   (n)[1] = (u)[2]*(v)[0] - (u)[0]*(v)[2]; \
  2394.   (n)[2] = (u)[0]*(v)[1] - (u)[1]*(v)[0]
  2395. #define NORMALIZE(n) \
  2396.   { GLfloat l = sqrt((n)[0]*(n)[0] + (n)[1]*n[1] + (n)[2]*(n)[2]); \
  2397.     if(l > 0.000001) { (n)[0]/=l; (n)[1]/=l; (n)[2]/=l; } }
  2398.  
  2399.    /** Vertex **/
  2400.    if(CC.Eval.Map2Vertex4) 
  2401.    {
  2402.      uu = (u-Map2Vertex4u1) / (Map2Vertex4u2-Map2Vertex4u1);
  2403.      vv = (v-Map2Vertex4v1) / (Map2Vertex4v2-Map2Vertex4v1);
  2404.  
  2405.      if (CC.Eval.AutoNormal)
  2406.      {
  2407.        GLfloat du[4], dv[4];
  2408.  
  2409.        de_casteljau_surf(Map2Vertex4, vertex, du, dv, uu, vv, 4,
  2410.              Map2Vertex4uorder, Map2Vertex4vorder);
  2411.  
  2412.        CROSS_PROD(normal, du, dv);
  2413.        NORMALIZE(normal);
  2414.      }
  2415.      else
  2416.        horner_bezier_surf(Map2Vertex4, vertex, uu, vv, 4,
  2417.               Map2Vertex4uorder, Map2Vertex4vorder);
  2418.    }
  2419.    else if (CC.Eval.Map2Vertex3) 
  2420.    {
  2421.      uu = (u-Map2Vertex3u1) / (Map2Vertex3u2-Map2Vertex3u1);
  2422.      vv = (v-Map2Vertex3v1) / (Map2Vertex3v2-Map2Vertex3v1);
  2423.  
  2424.      if (CC.Eval.AutoNormal)
  2425.      {
  2426.        GLfloat du[3], dv[3];
  2427.        de_casteljau_surf(Map2Vertex3, vertex, du, dv, uu, vv, 3,
  2428.              Map2Vertex3uorder, Map2Vertex3vorder);
  2429.  
  2430.        CROSS_PROD(normal, du, dv);
  2431.        NORMALIZE(normal);
  2432.      }
  2433.      else
  2434.        horner_bezier_surf(Map2Vertex3, vertex, uu, vv, 3,
  2435.               Map2Vertex3uorder, Map2Vertex3vorder);
  2436.  
  2437.      vertex[3] = 1.0;
  2438.    }
  2439. #undef NORMALIZE
  2440. #undef CROSS_PROD
  2441.    
  2442.    /** Color Index **/
  2443.    if (CC.Eval.Map2Index) 
  2444.    {
  2445.      GLfloat findex;
  2446.      uu = (u-Map2Indexu1) / (Map2Indexu2-Map2Indexu1);
  2447.      vv = (v-Map2Indexv1) / (Map2Indexv2-Map2Indexv1);
  2448.  
  2449.      horner_bezier_surf(Map2Index, &findex, uu, vv, 1,
  2450.             Map2Indexuorder, Map2Indexvorder);
  2451.      index = (GLuint) (GLint) findex;
  2452.    }
  2453.    else 
  2454.      index = CC.Current.Index;
  2455.  
  2456.    /** Color **/
  2457.    if (CC.Eval.Map2Color4) 
  2458.    {
  2459.      uu = (u-Map2Color4u1) / (Map2Color4u2-Map2Color4u1);
  2460.      vv = (v-Map2Color4v1) / (Map2Color4v2-Map2Color4v1);
  2461.  
  2462.      horner_bezier_surf(Map2Color4, fcolor, uu, vv, 4,
  2463.             Map2Color4uorder, Map2Color4vorder);
  2464.      icolor[0] = (GLint) (fcolor[0] * CC.RedScale);
  2465.      icolor[1] = (GLint) (fcolor[1] * CC.GreenScale);
  2466.      icolor[2] = (GLint) (fcolor[2] * CC.BlueScale);
  2467.      icolor[3] = (GLint) (fcolor[3] * CC.AlphaScale);
  2468.      colorptr = icolor;
  2469.    }
  2470.    else 
  2471.    {
  2472.       colorptr = CC.Current.IntColor;
  2473.    }
  2474.  
  2475.    /** Normal **/
  2476.    if(!CC.Eval.AutoNormal || (!CC.Eval.Map2Vertex3 && !CC.Eval.Map2Vertex4))
  2477.    {
  2478.      if (CC.Eval.Map2Normal) 
  2479.      {
  2480.        uu = (u-Map2Normalu1) / (Map2Normalu2-Map2Normalu1);
  2481.        vv = (v-Map2Normalv1) / (Map2Normalv2-Map2Normalv1);
  2482.  
  2483.        horner_bezier_surf(Map2Normal, normal, uu, vv, 3,
  2484.               Map2Normaluorder, Map2Normalvorder);
  2485.      }
  2486.      else 
  2487.      {
  2488.        normal[0] = CC.Current.Normal[0];
  2489.        normal[1] = CC.Current.Normal[1];
  2490.        normal[2] = CC.Current.Normal[2];
  2491.      }
  2492.    }
  2493.  
  2494.    /** Texture Coordinates **/
  2495.    if (CC.Eval.Map2TextureCoord4) 
  2496.    {
  2497.      uu = (u-Map2Texture4u1) / (Map2Texture4u2-Map2Texture4u1);
  2498.      vv = (v-Map2Texture4v1) / (Map2Texture4v2-Map2Texture4v1);
  2499.  
  2500.      horner_bezier_surf(Map2Texture4, texcoord, uu, vv, 4,
  2501.             Map2Texture4uorder, Map2Texture4vorder);
  2502.    }
  2503.    else if (CC.Eval.Map2TextureCoord3) 
  2504.    {
  2505.      uu = (u-Map2Texture3u1) / (Map2Texture3u2-Map2Texture3u1);
  2506.      vv = (v-Map2Texture3v1) / (Map2Texture3v2-Map2Texture3v1);
  2507.  
  2508.      horner_bezier_surf(Map2Texture3, texcoord, uu, vv, 3,
  2509.             Map2Texture3uorder, Map2Texture3vorder);
  2510.  
  2511.      texcoord[3] = 1.0;
  2512.    }
  2513.    else if (CC.Eval.Map2TextureCoord2) 
  2514.    {
  2515.      uu = (u-Map2Texture2u1) / (Map2Texture2u2-Map2Texture2u1);
  2516.      vv = (v-Map2Texture2v1) / (Map2Texture2v2-Map2Texture2v1);
  2517.  
  2518.      horner_bezier_surf(Map2Texture2, texcoord, uu, vv, 2,
  2519.             Map2Texture2uorder, Map2Texture2vorder);
  2520.  
  2521.      texcoord[2] = 0.0;
  2522.      texcoord[3] = 1.0;
  2523.    }
  2524.    else if (CC.Eval.Map2TextureCoord1) 
  2525.    {
  2526.      uu = (u-Map2Texture1u1) / (Map2Texture1u2-Map2Texture1u1);
  2527.      vv = (v-Map2Texture1v1) / (Map2Texture1v2-Map2Texture1v1);
  2528.  
  2529.      horner_bezier_surf(Map2Texture1, texcoord, uu, vv, 1,
  2530.             Map2Texture1uorder, Map2Texture1vorder);
  2531.  
  2532.      texcoord[1] = 0.0;
  2533.      texcoord[2] = 0.0;
  2534.      texcoord[3] = 1.0;
  2535.    }
  2536.    else 
  2537.    {
  2538.      texcoord[0] = CC.Current.TexCoord[0];
  2539.      texcoord[1] = CC.Current.TexCoord[1];
  2540.      texcoord[2] = CC.Current.TexCoord[2];
  2541.      texcoord[3] = CC.Current.TexCoord[3];
  2542.    }
  2543.  
  2544.    gl_eval_vertex( vertex, normal, colorptr, index, texcoord );
  2545. }
  2546.  
  2547.  
  2548. void glEvalCoord2f( GLfloat u, GLfloat v )
  2549. {
  2550.    if (CC.CompileFlag) {
  2551.       gl_save_evalcoord2( u, v );
  2552.    }
  2553.    if (CC.ExecuteFlag) {
  2554.       gl_evalcoord2( u, v );
  2555.    }
  2556. }
  2557.  
  2558.  
  2559. void glEvalCoord2fv( const GLfloat *u )
  2560. {
  2561.    if (CC.CompileFlag) {
  2562.       gl_save_evalcoord2( u[0], u[1] );
  2563.    }
  2564.    if (CC.ExecuteFlag) {
  2565.       gl_evalcoord2( u[0], u[1] );
  2566.    }
  2567. }
  2568.  
  2569.  
  2570. void glEvalCoord2d( GLdouble u, GLdouble v )
  2571. {
  2572.    if (CC.CompileFlag) {
  2573.       gl_save_evalcoord2( (GLfloat) u, (GLfloat) v );
  2574.    }
  2575.    if (CC.ExecuteFlag) {
  2576.       gl_evalcoord2( (GLfloat) u, (GLfloat) v );
  2577.    }
  2578. }
  2579.  
  2580.  
  2581. void glEvalCoord2dv( const GLdouble *u )
  2582. {
  2583.    if (CC.CompileFlag) {
  2584.       gl_save_evalcoord2( (GLfloat) u[0], (GLfloat) u[1] );
  2585.    }
  2586.    if (CC.ExecuteFlag) {
  2587.       gl_evalcoord2( (GLfloat) u[0], (GLfloat) u[1] );
  2588.    }
  2589. }
  2590.  
  2591.  
  2592.  
  2593. void gl_mapgrid1( GLint un, GLfloat u1, GLfloat u2 )
  2594. {
  2595.    if (INSIDE_BEGIN_END) {
  2596.       gl_error( GL_INVALID_OPERATION, "glMapGrid1f" );
  2597.       return;
  2598.    }
  2599.    if (un<1) {
  2600.       gl_error( GL_INVALID_VALUE, "glMapGrid1f" );
  2601.       return;
  2602.    }
  2603.    CC.Eval.MapGrid1un = un;
  2604.    CC.Eval.MapGrid1u1 = u1;
  2605.    CC.Eval.MapGrid1u2 = u2;
  2606. }
  2607.  
  2608.  
  2609. void glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
  2610. {
  2611.    if (CC.CompileFlag) {
  2612.       gl_save_mapgrid1( un, u1, u2 );
  2613.    }
  2614.    if (CC.ExecuteFlag) {
  2615.       gl_mapgrid1( un, u1, u2 );
  2616.    }
  2617. }
  2618.  
  2619.  
  2620. void glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
  2621. {
  2622.    if (CC.CompileFlag) {
  2623.       gl_save_mapgrid1( un, (GLfloat) u1, (GLfloat) u2 );
  2624.    }
  2625.    if (CC.ExecuteFlag) {
  2626.       gl_mapgrid1( un, (GLfloat) u1, (GLfloat) u2 );
  2627.    }
  2628. }
  2629.  
  2630.  
  2631.  
  2632. void gl_mapgrid2( GLint un, GLfloat u1, GLfloat u2,
  2633.           GLint vn, GLfloat v1, GLfloat v2 )
  2634. {
  2635.    if (INSIDE_BEGIN_END) {
  2636.       gl_error( GL_INVALID_OPERATION, "glMapGrid2f" );
  2637.       return;
  2638.    }
  2639.    if (un<1) {
  2640.       gl_error( GL_INVALID_VALUE, "glMapGrid2f(un)" );
  2641.       return;
  2642.    }
  2643.    if (vn<1) {
  2644.       gl_error( GL_INVALID_VALUE, "glMapGrid2f(vn)" );
  2645.       return;
  2646.    }
  2647.    CC.Eval.MapGrid2un = un;
  2648.    CC.Eval.MapGrid2u1 = u1;
  2649.    CC.Eval.MapGrid2u2 = u2;
  2650.    CC.Eval.MapGrid2vn = vn;
  2651.    CC.Eval.MapGrid2v1 = v1;
  2652.    CC.Eval.MapGrid2v2 = v2;
  2653. }
  2654.  
  2655.  
  2656. void glMapGrid2f( GLint un, GLfloat u1, GLfloat u2,
  2657.           GLint vn, GLfloat v1, GLfloat v2 )
  2658. {
  2659.    if (CC.CompileFlag) {
  2660.       gl_save_mapgrid2( un, u1, u2, vn, v1, v2 );
  2661.    }
  2662.    if (CC.ExecuteFlag) {
  2663.       gl_mapgrid2( un, u1, u2, vn, v1, v2 );
  2664.    }
  2665. }
  2666.  
  2667.  
  2668. void glMapGrid2d( GLint un, GLdouble u1, GLdouble u2,
  2669.           GLint vn, GLdouble v1, GLdouble v2 )
  2670. {
  2671.    if (CC.CompileFlag) {
  2672.       gl_save_mapgrid2( un, (GLfloat) u1, (GLfloat) u2,
  2673.                 vn, (GLfloat) v1, (GLfloat) v2 );
  2674.    }
  2675.    if (CC.ExecuteFlag) {
  2676.       gl_mapgrid2( un, (GLfloat) u1, (GLfloat) u2,
  2677.            vn, (GLfloat) v1, (GLfloat) v2 );
  2678.    }
  2679. }
  2680.  
  2681.  
  2682.  
  2683. void glEvalPoint1( GLint i )
  2684. {
  2685.    if (CC.CompileFlag) {
  2686.       gl_save_evalpoint1( i );
  2687.    }
  2688.    if (CC.ExecuteFlag) {
  2689.       GLfloat u, du;
  2690.  
  2691.       if (i==0) {
  2692.      u = CC.Eval.MapGrid1u1;
  2693.       }
  2694.       else if (i==CC.Eval.MapGrid1un) {
  2695.      u = CC.Eval.MapGrid1u2;
  2696.       }
  2697.       else {
  2698.      du = (CC.Eval.MapGrid1u2 - CC.Eval.MapGrid1u1)
  2699.           / (GLfloat) CC.Eval.MapGrid1un;
  2700.      u = i * du + CC.Eval.MapGrid1u1;
  2701.       }
  2702.       gl_evalcoord1( u );
  2703.    }
  2704. }
  2705.  
  2706.  
  2707.  
  2708. void glEvalPoint2( GLint i, GLint j )
  2709. {
  2710.    if (CC.CompileFlag) {
  2711.       gl_save_evalpoint2( i, j );
  2712.    }
  2713.    if (CC.ExecuteFlag) {
  2714.       GLfloat u, du;
  2715.       GLfloat v, dv;
  2716.  
  2717.       if (i==0) {
  2718.      u = CC.Eval.MapGrid2u1;
  2719.       }
  2720.       else if (i==CC.Eval.MapGrid2un) {
  2721.      u = CC.Eval.MapGrid2u2;
  2722.       }
  2723.       else {
  2724.      du = (CC.Eval.MapGrid2u2 - CC.Eval.MapGrid2u1)
  2725.            / (GLfloat) CC.Eval.MapGrid2un;
  2726.      u = i * du + CC.Eval.MapGrid2u1;
  2727.       }
  2728.  
  2729.       if (j==0) {
  2730.      v = CC.Eval.MapGrid2v1;
  2731.       }
  2732.       else if (j==CC.Eval.MapGrid2vn) {
  2733.      v = CC.Eval.MapGrid2v2;
  2734.       }
  2735.       else {
  2736.      dv = (CC.Eval.MapGrid2v2 - CC.Eval.MapGrid2v1)
  2737.            / (GLfloat) CC.Eval.MapGrid2vn;
  2738.      v = j * dv + CC.Eval.MapGrid2v1;
  2739.       }
  2740.  
  2741.       gl_evalcoord2( u, v );
  2742.    }
  2743. }
  2744.  
  2745.  
  2746.  
  2747. void glEvalMesh1( GLenum mode, GLint i1, GLint i2 )
  2748. {
  2749.    GLint i;
  2750.    GLfloat u, du;
  2751.    GLenum prim;
  2752.  
  2753.    if (CC.CompileFlag) {
  2754.       gl_save_evalmesh1( mode, i1, i2 );
  2755.    }
  2756.    if (CC.ExecuteFlag) {
  2757.  
  2758.       if (INSIDE_BEGIN_END) {
  2759.      gl_error( GL_INVALID_OPERATION, "glEvalMesh1" );
  2760.      return;
  2761.       }
  2762.  
  2763.       switch (mode) {
  2764.      case GL_POINT:
  2765.         prim = GL_POINTS;
  2766.         break;
  2767.      case GL_LINE:
  2768.         prim = GL_LINE_STRIP;
  2769.         break;
  2770.      default:
  2771.         gl_error( GL_INVALID_ENUM, "glEvalMesh1(mode)" );
  2772.         return;
  2773.       }
  2774.  
  2775.       du = (CC.Eval.MapGrid1u2 - CC.Eval.MapGrid1u1)
  2776.            / (GLfloat) CC.Eval.MapGrid1un;
  2777.  
  2778.       gl_begin( prim );
  2779.       for (i=i1;i<=i2;i++) {
  2780.      if (i==0) {
  2781.         u = CC.Eval.MapGrid1u1;
  2782.      }
  2783.      else if (i==CC.Eval.MapGrid1un) {
  2784.         u = CC.Eval.MapGrid1u2;
  2785.      }
  2786.      else {
  2787.         u = i * du + CC.Eval.MapGrid1u1;
  2788.      }
  2789.      gl_evalcoord1( u );
  2790.       }
  2791.       gl_end();
  2792.    }
  2793. }
  2794.  
  2795.  
  2796.  
  2797. void glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
  2798. {
  2799.    GLint i, j;
  2800.    GLfloat u, du, v, dv, v1, v2;
  2801.  
  2802.    if (CC.CompileFlag) {
  2803.       gl_save_evalmesh2( mode, i1, i2, j1, j2 );
  2804.    }
  2805.    if (CC.ExecuteFlag) {
  2806.  
  2807.       if (INSIDE_BEGIN_END) {
  2808.      gl_error( GL_INVALID_OPERATION, "glEvalMesh2" );
  2809.      return;
  2810.       }
  2811.  
  2812.       du = (CC.Eval.MapGrid2u2 - CC.Eval.MapGrid2u1)
  2813.            / (GLfloat) CC.Eval.MapGrid2un;
  2814.       dv = (CC.Eval.MapGrid2v2 - CC.Eval.MapGrid2v1)
  2815.            / (GLfloat) CC.Eval.MapGrid2vn;
  2816.  
  2817. #define I_TO_U( I, U )                \
  2818.        if ((I)==0) {                   \
  2819.           U = CC.Eval.MapGrid2u1;        \
  2820.        }                    \
  2821.        else if ((I)==CC.Eval.MapGrid2un) {    \
  2822.           U = CC.Eval.MapGrid2u2;        \
  2823.        }                    \
  2824.        else {                \
  2825.           U = (I) * du + CC.Eval.MapGrid2u1;\
  2826.        }
  2827.  
  2828. #define J_TO_V( J, V )                \
  2829.        if ((J)==0) {            \
  2830.           V = CC.Eval.MapGrid2v1;        \
  2831.        }                    \
  2832.        else if ((J)==CC.Eval.MapGrid2vn) {    \
  2833.           V = CC.Eval.MapGrid2v2;        \
  2834.        }                    \
  2835.        else {                \
  2836.           V = (J) * dv + CC.Eval.MapGrid2v1;\
  2837.        }
  2838.  
  2839.       switch (mode) {
  2840.      case GL_POINT:
  2841.         gl_begin( GL_POINTS );
  2842.         for (j=j1;j<=j2;j++) {
  2843.            J_TO_V( j, v );
  2844.            for (i=i1;i<=i2;i++) {
  2845.           I_TO_U( i, u );
  2846.           gl_evalcoord2( u, v );
  2847.            }
  2848.         }
  2849.         gl_end();
  2850.         break;
  2851.      case GL_LINE:
  2852.         for (j=j1;j<=j2;j++) {
  2853.            J_TO_V( j, v );
  2854.            gl_begin( GL_LINE_STRIP );
  2855.            for (i=i1;i<=i2;i++) {
  2856.           I_TO_U( i, u );
  2857.           gl_evalcoord2( u, v );
  2858.            }
  2859.            gl_end();
  2860.         }
  2861.         for (i=i1;i<=i2;i++) {
  2862.            I_TO_U( i, u );
  2863.            gl_begin( GL_LINE_STRIP );
  2864.            for (j=j1;j<=j2;j++) {
  2865.           J_TO_V( j, v );
  2866.           gl_evalcoord2( u, v );
  2867.            }
  2868.            gl_end();
  2869.         }
  2870.         break;
  2871.      case GL_FILL:
  2872.         for (j=j1;j<j2;j++) {
  2873.            /* NOTE: a quad strip can't be used because the four */
  2874.            /* can't be guaranteed to be coplanar! */
  2875.            gl_begin( GL_TRIANGLE_STRIP );
  2876.            J_TO_V( j, v1 );
  2877.            J_TO_V( j+1, v2 );
  2878.            for (i=i1;i<=i2;i++) {
  2879.           I_TO_U( i, u );
  2880.           gl_evalcoord2( u, v1 );
  2881.           gl_evalcoord2( u, v2 );
  2882.            }
  2883.            gl_end();
  2884.         }
  2885.         break;
  2886.      default:
  2887.         gl_error( GL_INVALID_ENUM, "glEvalMesh2(mode)" );
  2888.         return;
  2889.       }
  2890.  
  2891. #undef I_TO_U
  2892. #undef J_TO_V
  2893.    }
  2894. }
  2895.  
  2896.