s/BlendEquatioRGB/BlendEquationRGB/
[mesa.git] / src / mesa / swrast / s_aatritemp.h
index 060f7d988fcf6af92811fe96e1a7040ccf3ad939..61ee6f2fbfd4007d0cc960108983553d60da1fd9 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: s_aatritemp.h,v 1.19 2001/07/13 20:07:37 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  5.1
  *
- * Copyright (C) 1999-2001  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"),
    const GLfloat *p1 = v1->win;
    const GLfloat *p2 = v2->win;
    const SWvertex *vMin, *vMid, *vMax;
-   GLfloat xMin, yMin, xMid, yMid, xMax, yMax;
-   GLfloat majDx, majDy, botDx, botDy, topDx, topDy;
-   GLfloat area;
-   GLboolean majorOnLeft;
-   GLfloat bf = SWRAST_CONTEXT(ctx)->_backface_sign;
-
+   GLint iyMin, iyMax;
+   GLfloat yMin, yMax;
+   GLboolean ltor;
+   GLfloat majDx, majDy;  /* major (i.e. long) edge dx and dy */
+   
+   struct sw_span span;
+   
 #ifdef DO_Z
    GLfloat zPlane[4];
-   GLdepth z[MAX_WIDTH];
 #endif
 #ifdef DO_FOG
    GLfloat fogPlane[4];
-   GLfloat fog[MAX_WIDTH];
 #else
    GLfloat *fog = NULL;
 #endif
 #ifdef DO_RGBA
    GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];
-   DEFMARRAY(GLchan, rgba, MAX_WIDTH, 4);  /* mac 32k limitation */
 #endif
 #ifdef DO_INDEX
    GLfloat iPlane[4];
-   GLuint index[MAX_WIDTH];
-   GLint icoverageSpan[MAX_WIDTH];
-   GLfloat coverageSpan[MAX_WIDTH];
-#else
-   GLfloat coverageSpan[MAX_WIDTH];
 #endif
 #ifdef DO_SPEC
    GLfloat srPlane[4], sgPlane[4], sbPlane[4];
-   DEFMARRAY(GLchan, spec, MAX_WIDTH, 4);
 #endif
 #ifdef DO_TEX
    GLfloat sPlane[4], tPlane[4], uPlane[4], vPlane[4];
    GLfloat texWidth, texHeight;
-   DEFARRAY(GLfloat, s, MAX_WIDTH);  /* mac 32k limitation */
-   DEFARRAY(GLfloat, t, MAX_WIDTH);
-   DEFARRAY(GLfloat, u, MAX_WIDTH);
-   DEFARRAY(GLfloat, lambda, MAX_WIDTH);
 #elif defined(DO_MULTITEX)
-   GLfloat sPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat tPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat uPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat vPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS];
-   DEFMARRAY(GLfloat, s, MAX_TEXTURE_UNITS, MAX_WIDTH);  /* mac 32k limit */
-   DEFMARRAY(GLfloat, t, MAX_TEXTURE_UNITS, MAX_WIDTH);
-   DEFMARRAY(GLfloat, u, MAX_TEXTURE_UNITS, MAX_WIDTH);
-   DEFMARRAY(GLfloat, lambda, MAX_TEXTURE_UNITS, MAX_WIDTH);
-#endif
-
-#ifdef DO_RGBA
-   CHECKARRAY(rgba, return);  /* mac 32k limitation */
-#endif
-#ifdef DO_SPEC
-   CHECKARRAY(spec, return);
-#endif
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-   CHECKARRAY(s, return);
-   CHECKARRAY(t, return);
-   CHECKARRAY(u, return);
-   CHECKARRAY(lambda, return);
-#endif
+   GLfloat sPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture S */
+   GLfloat tPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture T */
+   GLfloat uPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture R */
+   GLfloat vPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture Q */
+   GLfloat texWidth[MAX_TEXTURE_COORD_UNITS];
+   GLfloat texHeight[MAX_TEXTURE_COORD_UNITS];
+#endif
+   GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign;
+   
+   
+   INIT_SPAN(span, GL_POLYGON, 0, 0, SPAN_COVERAGE);
 
    /* determine bottom to top order of vertices */
    {
       }
    }
 
-   xMin = vMin->win[0];  yMin = vMin->win[1];
-   xMid = vMid->win[0];  yMid = vMid->win[1];
-   xMax = vMax->win[0];  yMax = vMax->win[1];
+   majDx = vMax->win[0] - vMin->win[0];
+   majDy = vMax->win[1] - vMin->win[1];
 
-   /* the major edge is between the top and bottom vertices */
-   majDx = xMax - xMin;
-   majDy = yMax - yMin;
-   /* the bottom edge is between the bottom and mid vertices */
-   botDx = xMid - xMin;
-   botDy = yMid - yMin;
-   /* the top edge is between the top and mid vertices */
-   topDx = xMax - xMid;
-   topDy = yMax - yMid;
-
-   /* compute clockwise / counter-clockwise orientation and do BF culling */
-   area = majDx * botDy - botDx * majDy;
-   /* Do backface culling */
-   if (area * bf < 0 || area * area < .0025)
-      return;
-   majorOnLeft = (GLboolean) (area < 0.0F);
+   {
+      const GLfloat botDx = vMid->win[0] - vMin->win[0];
+      const GLfloat botDy = vMid->win[1] - vMin->win[1];
+      const GLfloat area = majDx * botDy - botDx * majDy;
+      /* Do backface culling */
+      if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area))
+        return;
+      ltor = (GLboolean) (area < 0.0F);
+   }
 
 #ifndef DO_OCCLUSION_TEST
    ctx->OcclusionResult = GL_TRUE;
 #endif
 
-   assert(majDy > 0.0F);
-
    /* Plane equation setup:
     * We evaluate plane equations at window (x,y) coordinates in order
     * to compute color, Z, fog, texcoords, etc.  This isn't terribly
-    * efficient but it's easy and reliable.  It also copes with computing
-    * interpolated data just outside the triangle's edges.
+    * efficient but it's easy and reliable.
     */
 #ifdef DO_Z
    compute_plane(p0, p1, p2, p0[2], p1[2], p2[2], zPlane);
+   span.arrayMask |= SPAN_Z;
 #endif
 #ifdef DO_FOG
    compute_plane(p0, p1, p2, v0->fog, v1->fog, v2->fog, fogPlane);
+   span.arrayMask |= SPAN_FOG;
 #endif
 #ifdef DO_RGBA
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      compute_plane(p0, p1, p2, v0->color[0], v1->color[0], v2->color[0], rPlane);
-      compute_plane(p0, p1, p2, v0->color[1], v1->color[1], v2->color[1], gPlane);
-      compute_plane(p0, p1, p2, v0->color[2], v1->color[2], v2->color[2], bPlane);
-      compute_plane(p0, p1, p2, v0->color[3], v1->color[3], v2->color[3], aPlane);
+      compute_plane(p0, p1, p2, v0->color[RCOMP], v1->color[RCOMP], v2->color[RCOMP], rPlane);
+      compute_plane(p0, p1, p2, v0->color[GCOMP], v1->color[GCOMP], v2->color[GCOMP], gPlane);
+      compute_plane(p0, p1, p2, v0->color[BCOMP], v1->color[BCOMP], v2->color[BCOMP], bPlane);
+      compute_plane(p0, p1, p2, v0->color[ACOMP], v1->color[ACOMP], v2->color[ACOMP], aPlane);
    }
    else {
       constant_plane(v2->color[RCOMP], rPlane);
       constant_plane(v2->color[BCOMP], bPlane);
       constant_plane(v2->color[ACOMP], aPlane);
    }
+   span.arrayMask |= SPAN_RGBA;
 #endif
 #ifdef DO_INDEX
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      compute_plane(p0, p1, p2, v0->index,
-                    v1->index, v2->index, iPlane);
+      compute_plane(p0, p1, p2, (GLfloat) v0->index,
+                    (GLfloat) v1->index, (GLfloat) v2->index, iPlane);
    }
    else {
-      constant_plane(v2->index, iPlane);
+      constant_plane((GLfloat) v2->index, iPlane);
    }
+   span.arrayMask |= SPAN_INDEX;
 #endif
 #ifdef DO_SPEC
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      compute_plane(p0, p1, p2, v0->specular[0], v1->specular[0], v2->specular[0],srPlane);
-      compute_plane(p0, p1, p2, v0->specular[1], v1->specular[1], v2->specular[1],sgPlane);
-      compute_plane(p0, p1, p2, v0->specular[2], v1->specular[2], v2->specular[2],sbPlane);
+      compute_plane(p0, p1, p2, v0->specular[RCOMP], v1->specular[RCOMP], v2->specular[RCOMP], srPlane);
+      compute_plane(p0, p1, p2, v0->specular[GCOMP], v1->specular[GCOMP], v2->specular[GCOMP], sgPlane);
+      compute_plane(p0, p1, p2, v0->specular[BCOMP], v1->specular[BCOMP], v2->specular[BCOMP], sbPlane);
    }
    else {
       constant_plane(v2->specular[RCOMP], srPlane);
       constant_plane(v2->specular[GCOMP], sgPlane);
       constant_plane(v2->specular[BCOMP], sbPlane);
    }
+   span.arrayMask |= SPAN_SPEC;
 #endif
 #ifdef DO_TEX
    {
       const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;
-      const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];
+      const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
       const GLfloat invW0 = v0->win[3];
       const GLfloat invW1 = v1->win[3];
       const GLfloat invW2 = v2->win[3];
       texWidth = (GLfloat) texImage->Width;
       texHeight = (GLfloat) texImage->Height;
    }
+   span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
 #elif defined(DO_MULTITEX)
    {
       GLuint u;
       for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
          if (ctx->Texture.Unit[u]._ReallyEnabled) {
             const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
-            const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];
+            const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
             const GLfloat invW0 = v0->win[3];
             const GLfloat invW1 = v1->win[3];
             const GLfloat invW2 = v2->win[3];
          }
       }
    }
+   span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
 #endif
 
    /* Begin bottom-to-top scan over the triangle.
     * edges, stopping when we find that coverage = 0.  If the long edge
     * is on the left we scan left-to-right.  Else, we scan right-to-left.
     */
-   {
-      const GLint iyMin = (GLint) yMin;
-      const GLint iyMax = (GLint) yMax + 1;
-      /* upper edge and lower edge derivatives */
-      const GLfloat topDxDy = (topDy != 0.0F) ? topDx / topDy : 0.0F;
-      const GLfloat botDxDy = (botDy != 0.0F) ? botDx / botDy : 0.0F;
-      const GLfloat *pA, *pB, *pC;
-      const GLfloat majDxDy = majDx / majDy;
-      const GLfloat absMajDxDy = FABSF(majDxDy);
-      const GLfloat absTopDxDy = FABSF(topDxDy);
-      const GLfloat absBotDxDy = FABSF(botDxDy);
-#if 0
-      GLfloat xMaj = xMin - (yMin - (GLfloat) iyMin) * majDxDy;
-      GLfloat xBot = xMaj;
-      GLfloat xTop = xMid - (yMid - (GLint) yMid) * topDxDy;
-#else
-      GLfloat xMaj;
-      GLfloat xBot;
-      GLfloat xTop;
-#endif
+   yMin = vMin->win[1];
+   yMax = vMax->win[1];
+   iyMin = (GLint) yMin;
+   iyMax = (GLint) yMax + 1;
+
+   if (ltor) {
+      /* scan left to right */
+      const GLfloat *pMin = vMin->win;
+      const GLfloat *pMid = vMid->win;
+      const GLfloat *pMax = vMax->win;
+      const GLfloat dxdy = majDx / majDy;
+      const GLfloat xAdj = dxdy < 0.0F ? -dxdy : 0.0F;
+      GLfloat x = pMin[0] - (yMin - iyMin) * dxdy;
       GLint iy;
-      GLint k;
-
-      /* pA, pB, pC are the vertices in counter-clockwise order */
-      if (majorOnLeft) {
-         pA = vMin->win;
-         pB = vMid->win;
-         pC = vMax->win;
-         xMaj = xMin - absMajDxDy - 1.0;
-         xBot = xMin + absBotDxDy + 1.0;
-         xTop = xMid + absTopDxDy + 1.0;
-      }
-      else {
-         pA = vMin->win;
-         pB = vMax->win;
-         pC = vMid->win;
-         xMaj = xMin + absMajDxDy + 1.0;
-         xBot = xMin - absBotDxDy - 1.0;
-         xTop = xMid - absTopDxDy - 1.0;
-      }
-
-      /* Scan from bottom to top */
-      for (iy = iyMin; iy < iyMax; iy++, xMaj += majDxDy) {
-         GLint ix, i, j, len;
-         GLint iRight, iLeft;
+      for (iy = iyMin; iy < iyMax; iy++, x += dxdy) {
+         GLint ix, startX = (GLint) (x - xAdj);
+         GLuint count;
          GLfloat coverage = 0.0F;
 
-         if (majorOnLeft) {
-            iLeft = (GLint) (xMaj + 0.0);
-            /* compute right */
-            if (iy <= yMid) {
-               /* we're in the lower part */
-               iRight = (GLint) (xBot + 0.0);
-               xBot += botDxDy;
-            }
-            else {
-               /* we're in the upper part */
-               iRight = (GLint) (xTop + 0.0);
-               xTop += topDxDy;
-            }
-         }
-         else {
-            iRight = (GLint) (xMaj + 0.0);
-            /* compute left */
-            if (iy <= yMid) {
-               /* we're in the lower part */
-               iLeft = (GLint) (xBot - 0.0);
-               xBot += botDxDy;
-            }
-            else {
-               /* we're in the upper part */
-               iLeft = (GLint) (xTop - 0.0);
-               xTop += topDxDy;
-            }
+         /* skip over fragments with zero coverage */
+         while (startX < MAX_WIDTH) {
+            coverage = compute_coveragef(pMin, pMid, pMax, startX, iy);
+            if (coverage > 0.0F)
+               break;
+            startX++;
          }
 
-#ifdef DEBUG
-         for (i = 0; i < MAX_WIDTH; i++) {
-            coverageSpan[i] = -1.0;
-         }
-#endif
-
-         if (iLeft < 0)
-            iLeft = 0;
-         if (iRight >= ctx->DrawBuffer->_Xmax)
-            iRight = ctx->DrawBuffer->_Xmax - 1;
-
-         /*printf("%d: iLeft = %d  iRight = %d\n", iy, iLeft, iRight);*/
-
-         /* The pixels at y in [iLeft, iRight] (inclusive) are candidates */
-
-         /* scan left to right until we hit 100% coverage or the right edge */
-         i = iLeft;
-         while (i < iRight) {
-            coverage = compute_coveragef(pA, pB, pC, i, iy);
-            if (coverage == 0.0F) {
-               if (i == iLeft)
-                  iLeft++;  /* skip zero coverage pixels */
-               else {
-                  iRight = i;
-                  i--;
-                  break;  /* went past right edge */
-               }
-            }
-            else {
-               coverageSpan[i - iLeft] = coverage;
-               if (coverage == 1.0F)
-                  break;
-            }
-            i++;
-         }
-
-         assert(coverageSpan[i-iLeft] > 0.0 || iLeft == iRight);
-
-         assert(i == iRight || coverage == 1.0 || coverage == 0.0);
-
-         /* scan right to left until we hit 100% coverage or the left edge */
-         j = iRight;
-         assert(j - iLeft >= 0);
-         while (1) {
-            coverage = compute_coveragef(pA, pB, pC, j, iy);
-            if (coverage == 0.0F) {
-               if (j == iRight && j > i)
-                  iRight--;  /* skip zero coverage pixels */
-               else
-                  break;
-            }
-            else {
-               if (j <= i)
-                  break;
-               assert(j - iLeft >= 0);
-               coverageSpan[j - iLeft] = coverage;
-               if (coverage == 1.0F)
-                  break;
-            }
-            /*printf("%d: coverage[%d]' = %g\n", iy, j-iLeft, coverage);*/
-            j--;
-         }
-
-         assert(coverageSpan[j-iLeft] > 0.0 || iRight <= iLeft);
-
-         printf("iLeft=%d i=%d j=%d iRight=%d\n", iLeft, i, j, iRight);
-
-         assert(iLeft >= 0);
-         assert(iLeft < ctx->DrawBuffer->_Xmax);
-         assert(iRight >= 0);
-         assert(iRight < ctx->DrawBuffer->_Xmax);
-         assert(iRight >= iLeft);
-
-
-         /* any pixels left in between must have 100% coverage */
-         k = i + 1;
-         while (k < j) {
-            coverageSpan[k - iLeft] = 1.0F;
-            k++;
-         }
-
-         len = iRight - iLeft;
-         /*printf("len = %d\n", len);*/
-         assert(len >= 0);
-         assert(len < MAX_WIDTH);
-
-         if (len == 0)
-            continue;
-
-#ifdef DEBUG
-         for (k = 0; k < len; k++) {
-            assert(coverageSpan[k] > 0.0);
-         }
+         /* enter interior of triangle */
+         ix = startX;
+         count = 0;
+         while (coverage > 0.0F) {
+            /* (cx,cy) = center of fragment */
+            const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
+            struct span_arrays *array = span.array;
+#ifdef DO_INDEX
+            array->coverage[count] = (GLfloat) compute_coveragei(pMin, pMid, pMax, ix, iy);
+#else
+            array->coverage[count] = coverage;
 #endif
-
-         /*
-          * Compute color, texcoords, etc for the span
-          */
-         {
-            const GLfloat cx = iLeft + 0.5F, cy = iy + 0.5F;
 #ifdef DO_Z
-            GLfloat zFrag = solve_plane(cx, cy, zPlane);
-            const GLfloat zStep = -zPlane[0] / zPlane[2];
+            array->z[count] = (GLdepth) IROUND(solve_plane(cx, cy, zPlane));
 #endif
 #ifdef DO_FOG
-            GLfloat fogFrag = solve_plane(cx, cy, fogPlane);
-            const GLfloat fogStep = -fogPlane[0] / fogPlane[2];
+           array->fog[count] = solve_plane(cx, cy, fogPlane);
 #endif
 #ifdef DO_RGBA
-            /* to do */
+            array->rgba[count][RCOMP] = solve_plane_chan(cx, cy, rPlane);
+            array->rgba[count][GCOMP] = solve_plane_chan(cx, cy, gPlane);
+            array->rgba[count][BCOMP] = solve_plane_chan(cx, cy, bPlane);
+            array->rgba[count][ACOMP] = solve_plane_chan(cx, cy, aPlane);
 #endif
 #ifdef DO_INDEX
-            /* to do */
+            array->index[count] = (GLint) solve_plane(cx, cy, iPlane);
 #endif
 #ifdef DO_SPEC
-            /* to do */
+            array->spec[count][RCOMP] = solve_plane_chan(cx, cy, srPlane);
+            array->spec[count][GCOMP] = solve_plane_chan(cx, cy, sgPlane);
+            array->spec[count][BCOMP] = solve_plane_chan(cx, cy, sbPlane);
 #endif
 #ifdef DO_TEX
-            GLfloat sFrag = solve_plane(cx, cy, sPlane);
-            GLfloat tFrag = solve_plane(cx, cy, tPlane);
-            GLfloat uFrag = solve_plane(cx, cy, uPlane);
-            GLfloat vFrag = solve_plane(cx, cy, vPlane);
-            const GLfloat sStep = -sPlane[0] / sPlane[2];
-            const GLfloat tStep = -tPlane[0] / tPlane[2];
-            const GLfloat uStep = -uPlane[0] / uPlane[2];
-            const GLfloat vStep = -vPlane[0] / vPlane[2];
+            {
+               const GLfloat invQ = solve_plane_recip(cx, cy, vPlane);
+               array->texcoords[0][count][0] = solve_plane(cx, cy, sPlane) * invQ;
+               array->texcoords[0][count][1] = solve_plane(cx, cy, tPlane) * invQ;
+               array->texcoords[0][count][2] = solve_plane(cx, cy, uPlane) * invQ;
+               array->lambda[0][count] = compute_lambda(sPlane, tPlane, vPlane,
+                                                      cx, cy, invQ,
+                                                      texWidth, texHeight);
+            }
 #elif defined(DO_MULTITEX)
-            /* to do */
+            {
+               GLuint unit;
+               for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+                  if (ctx->Texture.Unit[unit]._ReallyEnabled) {
+                     GLfloat invQ = solve_plane_recip(cx, cy, vPlane[unit]);
+                     array->texcoords[unit][count][0] = solve_plane(cx, cy, sPlane[unit]) * invQ;
+                     array->texcoords[unit][count][1] = solve_plane(cx, cy, tPlane[unit]) * invQ;
+                     array->texcoords[unit][count][2] = solve_plane(cx, cy, uPlane[unit]) * invQ;
+                     array->lambda[unit][count] = compute_lambda(sPlane[unit],
+                                      tPlane[unit], vPlane[unit], cx, cy, invQ,
+                                      texWidth[unit], texHeight[unit]);
+                  }
+               }
+            }
 #endif
+            ix++;
+            count++;
+            coverage = compute_coveragef(pMin, pMid, pMax, ix, iy);
+         }
+         
+         if (ix <= startX)
+            continue;
+         
+         span.x = startX;
+         span.y = iy;
+         span.end = (GLuint) ix - (GLuint) startX;
+         ASSERT(span.interpMask == 0);
+#if defined(DO_MULTITEX) || defined(DO_TEX)
+         _swrast_write_texture_span(ctx, &span);
+#elif defined(DO_RGBA)
+         _swrast_write_rgba_span(ctx, &span);
+#elif defined(DO_INDEX)
+         _swrast_write_index_span(ctx, &span);
+#endif
+      }
+   }
+   else {
+      /* scan right to left */
+      const GLfloat *pMin = vMin->win;
+      const GLfloat *pMid = vMid->win;
+      const GLfloat *pMax = vMax->win;
+      const GLfloat dxdy = majDx / majDy;
+      const GLfloat xAdj = dxdy > 0 ? dxdy : 0.0F;
+      GLfloat x = pMin[0] - (yMin - iyMin) * dxdy;
+      GLint iy;
+      for (iy = iyMin; iy < iyMax; iy++, x += dxdy) {
+         GLint ix, left, startX = (GLint) (x + xAdj);
+         GLuint count, n;
+         GLfloat coverage = 0.0F;
+         
+         /* make sure we're not past the window edge */
+         if (startX >= ctx->DrawBuffer->_Xmax) {
+            startX = ctx->DrawBuffer->_Xmax - 1;
+         }
 
-            for (ix = iLeft; ix < iRight; ix++) {
-               const GLint k = ix - iLeft;
-               const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
-
+         /* skip fragments with zero coverage */
+         while (startX >= 0) {
+            coverage = compute_coveragef(pMin, pMax, pMid, startX, iy);
+            if (coverage > 0.0F)
+               break;
+            startX--;
+         }
+         
+         /* enter interior of triangle */
+         ix = startX;
+         count = 0;
+         while (coverage > 0.0F) {
+            /* (cx,cy) = center of fragment */
+            const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
+            struct span_arrays *array = span.array;
+#ifdef DO_INDEX
+            array->coverage[ix] = (GLfloat) compute_coveragei(pMin, pMax, pMid, ix, iy);
+#else
+            array->coverage[ix] = coverage;
+#endif
 #ifdef DO_Z
-               z[k] = zFrag;  zFrag += zStep;
+            array->z[ix] = (GLdepth) IROUND(solve_plane(cx, cy, zPlane));
 #endif
 #ifdef DO_FOG
-               fog[k] = fogFrag;  fogFrag += fogStep;
+            array->fog[ix] = solve_plane(cx, cy, fogPlane);
 #endif
 #ifdef DO_RGBA
-               rgba[k][RCOMP] = solve_plane_chan(cx, cy, rPlane);
-               rgba[k][GCOMP] = solve_plane_chan(cx, cy, gPlane);
-               rgba[k][BCOMP] = solve_plane_chan(cx, cy, bPlane);
-               rgba[k][ACOMP] = solve_plane_chan(cx, cy, aPlane);
+            array->rgba[ix][RCOMP] = solve_plane_chan(cx, cy, rPlane);
+            array->rgba[ix][GCOMP] = solve_plane_chan(cx, cy, gPlane);
+            array->rgba[ix][BCOMP] = solve_plane_chan(cx, cy, bPlane);
+            array->rgba[ix][ACOMP] = solve_plane_chan(cx, cy, aPlane);
 #endif
 #ifdef DO_INDEX
-               index[k] = (GLint) solve_plane(cx, cy, iPlane);
+            array->index[ix] = (GLint) solve_plane(cx, cy, iPlane);
 #endif
 #ifdef DO_SPEC
-               spec[k][RCOMP] = solve_plane_chan(cx, cy, srPlane);
-               spec[k][GCOMP] = solve_plane_chan(cx, cy, sgPlane);
-               spec[k][BCOMP] = solve_plane_chan(cx, cy, sbPlane);
+            array->spec[ix][RCOMP] = solve_plane_chan(cx, cy, srPlane);
+            array->spec[ix][GCOMP] = solve_plane_chan(cx, cy, sgPlane);
+            array->spec[ix][BCOMP] = solve_plane_chan(cx, cy, sbPlane);
 #endif
 #ifdef DO_TEX
-               s[k] = sFrag / vFrag;
-               t[k] = tFrag / vFrag;
-               u[k] = uFrag / vFrag;
-               lambda[k] = compute_lambda(sPlane, tPlane, 1.0F / vFrag,
-                                          texWidth, texHeight);
-               sFrag += sStep;
-               tFrag += tStep;
-               uFrag += uStep;
-               vFrag += vStep;
+            {
+               const GLfloat invQ = solve_plane_recip(cx, cy, vPlane);
+               array->texcoords[0][ix][0] = solve_plane(cx, cy, sPlane) * invQ;
+               array->texcoords[0][ix][1] = solve_plane(cx, cy, tPlane) * invQ;
+               array->texcoords[0][ix][2] = solve_plane(cx, cy, uPlane) * invQ;
+               array->lambda[0][ix] = compute_lambda(sPlane, tPlane, vPlane,
+                                          cx, cy, invQ, texWidth, texHeight);
+            }
 #elif defined(DO_MULTITEX)
-               {
-                  GLuint unit;
-                  for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
-                     if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-                        GLfloat invQ = solve_plane_recip(cx, cy, vPlane[unit]);
-                        s[unit][k] = solve_plane(cx, cy, sPlane[unit]) * invQ;
-                        t[unit][k] = solve_plane(cx, cy, tPlane[unit]) * invQ;
-                        u[unit][k] = solve_plane(cx, cy, uPlane[unit]) * invQ;
-                        lambda[unit][k] = compute_lambda(sPlane[unit],
-                          tPlane[unit], invQ, texWidth[unit], texHeight[unit]);
-                     }
+            {
+               GLuint unit;
+               for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+                  if (ctx->Texture.Unit[unit]._ReallyEnabled) {
+                     GLfloat invQ = solve_plane_recip(cx, cy, vPlane[unit]);
+                     array->texcoords[unit][ix][0] = solve_plane(cx, cy, sPlane[unit]) * invQ;
+                     array->texcoords[unit][ix][1] = solve_plane(cx, cy, tPlane[unit]) * invQ;
+                     array->texcoords[unit][ix][2] = solve_plane(cx, cy, uPlane[unit]) * invQ;
+                     array->lambda[unit][ix] = compute_lambda(sPlane[unit],
+                                                            tPlane[unit],
+                                                            vPlane[unit],
+                                                            cx, cy, invQ,
+                                                            texWidth[unit],
+                                                            texHeight[unit]);
                   }
                }
+            }
 #endif
-            } /* for ix */
+            ix--;
+            count++;
+            coverage = compute_coveragef(pMin, pMax, pMid, ix, iy);
          }
+         
+         if (startX <= ix)
+            continue;
 
-         /*
-          * Write/process the span of fragments.
-          */
-#ifdef DO_MULTITEX
-         _mesa_write_multitexture_span(ctx, len, iLeft, iy, z, fog,
-                                       (const GLfloat (*)[MAX_WIDTH]) s,
-                                       (const GLfloat (*)[MAX_WIDTH]) t,
-                                       (const GLfloat (*)[MAX_WIDTH]) u,
-                                       (GLfloat (*)[MAX_WIDTH]) lambda,
-                                       rgba,
-#  ifdef DO_SPEC
-                                       (const GLchan (*)[4]) spec,
-#  else
-                                       NULL,
-#  endif
-                                       coverageSpan,  GL_POLYGON);
-#elif defined(DO_TEX)
-         _mesa_write_texture_span(ctx, len, iLeft, iy, z, fog,
-                                  s, t, u, lambda, rgba,
-#  ifdef DO_SPEC
-                                  (const GLchan (*)[4]) spec,
-#  else
-                                  NULL,
-#  endif
-                                  coverageSpan, GL_POLYGON);
-#elif defined(DO_RGBA)
-         _mesa_write_rgba_span(ctx, len, iLeft, iy, z, fog, rgba,
-                               coverageSpan, GL_POLYGON);
-#elif defined(DO_INDEX)
-         _mesa_write_index_span(ctx, len, iLeft, iy, z, fog, index,
-                                icoverageSpan, GL_POLYGON);
-#endif
-
-      } /* for iy */
-   }
+         n = (GLuint) startX - (GLuint) ix;
 
+         left = ix + 1;
 
+         /* shift all values to the left */
+         /* XXX this is temporary */
+         {
+            struct span_arrays *array = span.array;
+            GLint j;
+            for (j = 0; j < (GLint) n; j++) {
 #ifdef DO_RGBA
-   UNDEFARRAY(rgba);  /* mac 32k limitation */
+               COPY_CHAN4(array->rgba[j], array->rgba[j + left]);
 #endif
 #ifdef DO_SPEC
-   UNDEFARRAY(spec);
+               COPY_CHAN4(array->spec[j], array->spec[j + left]);
+#endif
+#ifdef DO_INDEX
+               array->index[j] = array->index[j + left];
+#endif
+#ifdef DO_Z
+               array->z[j] = array->z[j + left];
+#endif
+#ifdef DO_FOG
+               array->fog[j] = array->fog[j + left];
 #endif
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-   UNDEFARRAY(s);
-   UNDEFARRAY(t);
-   UNDEFARRAY(u);
-   UNDEFARRAY(lambda);
+#ifdef DO_TEX
+               COPY_4V(array->texcoords[0][j], array->texcoords[0][j + left]);
 #endif
+#if defined(DO_MULTITEX) || defined(DO_TEX)
+               array->lambda[0][j] = array->lambda[0][j + left];
+#endif
+               array->coverage[j] = array->coverage[j + left];
+            }
+         }
+#ifdef DO_MULTITEX
+         /* shift texcoords */
+         {
+            struct span_arrays *array = span.array;
+            GLuint unit;
+            for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+               if (ctx->Texture.Unit[unit]._ReallyEnabled) {
+                  GLint j;
+                  for (j = 0; j < (GLint) n; j++) {
+                    array->texcoords[unit][j][0] = array->texcoords[unit][j + left][0];
+                     array->texcoords[unit][j][1] = array->texcoords[unit][j + left][1];
+                     array->texcoords[unit][j][2] = array->texcoords[unit][j + left][2];
+                     array->lambda[unit][j] = array->lambda[unit][j + left];
+                  }
+               }
+            }
+         }
+#endif
+
+         span.x = left;
+         span.y = iy;
+         span.end = n;
+         ASSERT(span.interpMask == 0);
+#if defined(DO_MULTITEX) || defined(DO_TEX)
+         _swrast_write_texture_span(ctx, &span);
+#elif defined(DO_RGBA)
+         _swrast_write_rgba_span(ctx, &span);
+#elif defined(DO_INDEX)
+         _swrast_write_index_span(ctx, &span);
+#endif
+      }
+   }
 }