Fix crash when debug output is enabled and sarea is notset in r200Clear
[mesa.git] / src / mesa / main / eval.c
index 30767a6277e6173f6a032bb794b7b23bb14d99d5..3f89f9c1eae456173fe9b0846770e0dbb93eb78b 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: eval.c,v 1.24 2002/10/24 23:57:20 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -44,7 +43,6 @@
 #include "context.h"
 #include "eval.h"
 #include "macros.h"
-#include "mmath.h"
 #include "mtypes.h"
 
 
@@ -202,8 +200,8 @@ get_2d_map( GLcontext *ctx, GLenum target )
 /*
  * Copy 1-parametric evaluator control points from user-specified
  * memory space to a buffer of contiguous control points.
- * Input:  see glMap1f for details
- * Return:  pointer to buffer of contiguous control points or NULL if out
+ * \param see glMap1f for details
+ * \return pointer to buffer of contiguous control points or NULL if out
  *          of memory.
  */
 GLfloat *_mesa_copy_map_points1f( GLenum target, GLint ustride, GLint uorder,
@@ -257,8 +255,8 @@ GLfloat *_mesa_copy_map_points1d( GLenum target, GLint ustride, GLint uorder,
  * Additional memory is allocated to be used by the horner and
  * de Casteljau evaluation schemes.
  *
- * Input:  see glMap2f for details
- * Return:  pointer to buffer of contiguous control points or NULL if out
+ * \param see glMap2f for details
+ * \return pointer to buffer of contiguous control points or NULL if out
  *          of memory.
  */
 GLfloat *_mesa_copy_map_points2f( GLenum target,
@@ -419,7 +417,7 @@ map1(GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
 
 
 
-void
+void GLAPIENTRY
 _mesa_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
              GLint order, const GLfloat *points )
 {
@@ -427,7 +425,7 @@ _mesa_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Map1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
              GLint order, const GLdouble *points )
 {
@@ -518,7 +516,7 @@ map2( GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Map2f( GLenum target,
              GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
              GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
@@ -529,7 +527,7 @@ _mesa_Map2f( GLenum target,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_Map2d( GLenum target,
              GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
              GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
@@ -541,7 +539,7 @@ _mesa_Map2d( GLenum target,
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -606,7 +604,7 @@ _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -671,7 +669,7 @@ _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -705,7 +703,7 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
          }
         if (data) {
            for (i=0;i<n;i++) {
-              v[i] = ROUNDF(data[i]);
+              v[i] = IROUND(data[i]);
            }
         }
          break;
@@ -720,14 +718,14 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
          break;
       case GL_DOMAIN:
          if (map1d) {
-            v[0] = ROUNDF(map1d->u1);
-            v[1] = ROUNDF(map1d->u2);
+            v[0] = IROUND(map1d->u1);
+            v[1] = IROUND(map1d->u2);
          }
          else {
-            v[0] = ROUNDF(map2d->u1);
-            v[1] = ROUNDF(map2d->u2);
-            v[2] = ROUNDF(map2d->v1);
-            v[3] = ROUNDF(map2d->v2);
+            v[0] = IROUND(map2d->u1);
+            v[1] = IROUND(map2d->u2);
+            v[2] = IROUND(map2d->v1);
+            v[3] = IROUND(map2d->v2);
          }
          break;
       default:
@@ -737,7 +735,7 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
 
 
 
-void
+void GLAPIENTRY
 _mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -755,14 +753,14 @@ _mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_MapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
 {
    _mesa_MapGrid1f( un, (GLfloat) u1, (GLfloat) u2 );
 }
 
 
-void
+void GLAPIENTRY
 _mesa_MapGrid2f( GLint un, GLfloat u1, GLfloat u2,
                  GLint vn, GLfloat v1, GLfloat v2 )
 {
@@ -790,10 +788,175 @@ _mesa_MapGrid2f( GLint un, GLfloat u1, GLfloat u2,
 }
 
 
-void
+void GLAPIENTRY
 _mesa_MapGrid2d( GLint un, GLdouble u1, GLdouble u2,
                  GLint vn, GLdouble v1, GLdouble v2 )
 {
    _mesa_MapGrid2f( un, (GLfloat) u1, (GLfloat) u2, 
                    vn, (GLfloat) v1, (GLfloat) v2 );
 }
+
+
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+/**
+ * Initialize a 1-D evaluator map.
+ */
+static void
+init_1d_map( struct gl_1d_map *map, int n, const float *initial )
+{
+   map->Order = 1;
+   map->u1 = 0.0;
+   map->u2 = 1.0;
+   map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
+   if (map->Points) {
+      GLint i;
+      for (i=0;i<n;i++)
+         map->Points[i] = initial[i];
+   }
+}
+
+
+/**
+ * Initialize a 2-D evaluator map 
+ */
+static void
+init_2d_map( struct gl_2d_map *map, int n, const float *initial )
+{
+   map->Uorder = 1;
+   map->Vorder = 1;
+   map->u1 = 0.0;
+   map->u2 = 1.0;
+   map->v1 = 0.0;
+   map->v2 = 1.0;
+   map->Points = (GLfloat *) MALLOC(n * sizeof(GLfloat));
+   if (map->Points) {
+      GLint i;
+      for (i=0;i<n;i++)
+         map->Points[i] = initial[i];
+   }
+}
+
+
+void _mesa_init_eval( GLcontext *ctx )
+{
+   int i;
+
+   /* Evaluators group */
+   ctx->Eval.Map1Color4 = GL_FALSE;
+   ctx->Eval.Map1Index = GL_FALSE;
+   ctx->Eval.Map1Normal = GL_FALSE;
+   ctx->Eval.Map1TextureCoord1 = GL_FALSE;
+   ctx->Eval.Map1TextureCoord2 = GL_FALSE;
+   ctx->Eval.Map1TextureCoord3 = GL_FALSE;
+   ctx->Eval.Map1TextureCoord4 = GL_FALSE;
+   ctx->Eval.Map1Vertex3 = GL_FALSE;
+   ctx->Eval.Map1Vertex4 = GL_FALSE;
+   MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
+   ctx->Eval.Map2Color4 = GL_FALSE;
+   ctx->Eval.Map2Index = GL_FALSE;
+   ctx->Eval.Map2Normal = GL_FALSE;
+   ctx->Eval.Map2TextureCoord1 = GL_FALSE;
+   ctx->Eval.Map2TextureCoord2 = GL_FALSE;
+   ctx->Eval.Map2TextureCoord3 = GL_FALSE;
+   ctx->Eval.Map2TextureCoord4 = GL_FALSE;
+   ctx->Eval.Map2Vertex3 = GL_FALSE;
+   ctx->Eval.Map2Vertex4 = GL_FALSE;
+   MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
+   ctx->Eval.AutoNormal = GL_FALSE;
+   ctx->Eval.MapGrid1un = 1;
+   ctx->Eval.MapGrid1u1 = 0.0;
+   ctx->Eval.MapGrid1u2 = 1.0;
+   ctx->Eval.MapGrid2un = 1;
+   ctx->Eval.MapGrid2vn = 1;
+   ctx->Eval.MapGrid2u1 = 0.0;
+   ctx->Eval.MapGrid2u2 = 1.0;
+   ctx->Eval.MapGrid2v1 = 0.0;
+   ctx->Eval.MapGrid2v2 = 1.0;
+
+   /* Evaluator data */
+   {
+      static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
+      static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
+      static GLfloat index[1] = { 1.0 };
+      static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
+      static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };
+      static GLfloat attrib[4] = { 0.0, 0.0, 0.0, 1.0 };
+
+      init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
+      init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
+      init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
+      init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
+      init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
+      init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
+      init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
+      init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
+      init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );
+      for (i = 0; i < 16; i++)
+         init_1d_map( ctx->EvalMap.Map1Attrib + i, 4, attrib );
+
+      init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
+      init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
+      init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
+      init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
+      init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
+      init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
+      init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
+      init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
+      init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
+      for (i = 0; i < 16; i++)
+         init_2d_map( ctx->EvalMap.Map2Attrib + i, 4, attrib );
+   }
+}
+
+
+void _mesa_free_eval_data( GLcontext *ctx )
+{
+   int i;
+
+   /* Free evaluator data */
+   if (ctx->EvalMap.Map1Vertex3.Points)
+      FREE( ctx->EvalMap.Map1Vertex3.Points );
+   if (ctx->EvalMap.Map1Vertex4.Points)
+      FREE( ctx->EvalMap.Map1Vertex4.Points );
+   if (ctx->EvalMap.Map1Index.Points)
+      FREE( ctx->EvalMap.Map1Index.Points );
+   if (ctx->EvalMap.Map1Color4.Points)
+      FREE( ctx->EvalMap.Map1Color4.Points );
+   if (ctx->EvalMap.Map1Normal.Points)
+      FREE( ctx->EvalMap.Map1Normal.Points );
+   if (ctx->EvalMap.Map1Texture1.Points)
+      FREE( ctx->EvalMap.Map1Texture1.Points );
+   if (ctx->EvalMap.Map1Texture2.Points)
+      FREE( ctx->EvalMap.Map1Texture2.Points );
+   if (ctx->EvalMap.Map1Texture3.Points)
+      FREE( ctx->EvalMap.Map1Texture3.Points );
+   if (ctx->EvalMap.Map1Texture4.Points)
+      FREE( ctx->EvalMap.Map1Texture4.Points );
+   for (i = 0; i < 16; i++)
+      FREE((ctx->EvalMap.Map1Attrib[i].Points));
+
+   if (ctx->EvalMap.Map2Vertex3.Points)
+      FREE( ctx->EvalMap.Map2Vertex3.Points );
+   if (ctx->EvalMap.Map2Vertex4.Points)
+      FREE( ctx->EvalMap.Map2Vertex4.Points );
+   if (ctx->EvalMap.Map2Index.Points)
+      FREE( ctx->EvalMap.Map2Index.Points );
+   if (ctx->EvalMap.Map2Color4.Points)
+      FREE( ctx->EvalMap.Map2Color4.Points );
+   if (ctx->EvalMap.Map2Normal.Points)
+      FREE( ctx->EvalMap.Map2Normal.Points );
+   if (ctx->EvalMap.Map2Texture1.Points)
+      FREE( ctx->EvalMap.Map2Texture1.Points );
+   if (ctx->EvalMap.Map2Texture2.Points)
+      FREE( ctx->EvalMap.Map2Texture2.Points );
+   if (ctx->EvalMap.Map2Texture3.Points)
+      FREE( ctx->EvalMap.Map2Texture3.Points );
+   if (ctx->EvalMap.Map2Texture4.Points)
+      FREE( ctx->EvalMap.Map2Texture4.Points );
+   for (i = 0; i < 16; i++)
+      FREE((ctx->EvalMap.Map2Attrib[i].Points));
+}