s_aaline.c revision 8afe7de8deaf3c9613fd68b344de8c52b02b1879
18afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul/* $Id: s_aaline.c,v 1.15 2002/06/15 03:03:10 brianp Exp $ */
27798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
37798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
47798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Mesa 3-D graphics library
5733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul * Version:  4.1
65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
7733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
85e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
97798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a
107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * copy of this software and associated documentation files (the "Software"),
117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * to deal in the Software without restriction, including without limitation
127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense,
137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * and/or sell copies of the Software, and to permit persons to whom the
147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Software is furnished to do so, subject to the following conditions:
155e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * The above copyright notice and this permission notice shall be included
177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * in all copies or substantial portions of the Software.
185e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "glheader.h"
297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "swrast/s_aaline.h"
307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "swrast/s_context.h"
31733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#include "swrast/s_span.h"
327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "swrast/swrast.h"
335e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen#include "mtypes.h"
34b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul#include "mmath.h"
357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define SUB_PIXEL 4
387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Info about the AA line we're rendering
427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstruct LineInfo
447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat x0, y0;        /* start */
467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat x1, y1;        /* end */
477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dx, dy;        /* direction vector */
487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat len;           /* length */
497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat halfWidth;     /* half of line width */
507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat xAdj, yAdj;    /* X and Y adjustment for quad corners around line */
517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* for coverage computation */
527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat qx0, qy0;      /* quad vertices */
537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat qx1, qy1;
547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat qx2, qy2;
557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat qx3, qy3;
567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat ex0, ey0;      /* quad edge vectors */
577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat ex1, ey1;
587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat ex2, ey2;
597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat ex3, ey3;
607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_Z */
627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat zPlane[4];
637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_FOG */
647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat fPlane[4];
657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_RGBA */
667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];
677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_INDEX */
687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat iPlane[4];
697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_SPEC */
707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat srPlane[4], sgPlane[4], sbPlane[4];
717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* DO_TEX or DO_MULTITEX */
727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat sPlane[MAX_TEXTURE_UNITS][4];
737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat tPlane[MAX_TEXTURE_UNITS][4];
747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat uPlane[MAX_TEXTURE_UNITS][4];
757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat vPlane[MAX_TEXTURE_UNITS][4];
767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat lambda[MAX_TEXTURE_UNITS];
777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS];
78733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul
79bf80e1ed620836e2ca0dd3f7d2d4cb187d17563dBrian Paul   struct sw_span *span;
807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul};
817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute the equation of a plane used to interpolate line fragment data
867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * such as color, Z, texture coords, etc.
877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Input: (x0, y0) and (x1,y1) are the endpoints of the line.
887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul *        z0, and z1 are the end point values to interpolate.
897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Output:  plane - the plane equation.
907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul *
917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Note: we don't really have enough parameters to specify a plane.
927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * We take the endpoints of the line and compute a plane such that
937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * the cross product of the line vector and the plane normal is
947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * parallel to the projection plane.
957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul              GLfloat z0, GLfloat z1, GLfloat plane[4])
997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#if 0
1017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* original */
1027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat px = x1 - x0;
1037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat py = y1 - y0;
1047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat pz = z1 - z0;
1057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qx = -py;
1067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qy = px;
1077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qz = 0;
1087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat a = py * qz - pz * qy;
1097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat b = pz * qx - px * qz;
1107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat c = px * qy - py * qx;
1117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat d = -(a * x0 + b * y0 + c * z0);
1127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[0] = a;
1137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[1] = b;
1147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[2] = c;
1157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[3] = d;
1167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#else
1177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* simplified */
1187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat px = x1 - x0;
1197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat py = y1 - y0;
1207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat pz = z0 - z1;
1217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat a = pz * px;
1227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat b = pz * py;
1237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat c = px * px + py * py;
1247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat d = -(a * x0 + b * y0 + c * z0);
1256ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   if (a == 0.0 && b == 0.0 && c == 0.0 && d == 0.0) {
1266ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[0] = 0.0;
1276ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[1] = 0.0;
1286ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[2] = 1.0;
1296ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[3] = 0.0;
1306ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   }
1316ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   else {
1326ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[0] = a;
1336ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[1] = b;
1346ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[2] = c;
1356ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[3] = d;
1366ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   }
1377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#endif
1387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE void
1427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulconstant_plane(GLfloat value, GLfloat plane[4])
1437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[0] = 0.0;
1457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[1] = 0.0;
1467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[2] = -1.0;
1477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[3] = value;
1487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
1537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1546ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
1557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   return z;
1567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define SOLVE_PLANE(X, Y, PLANE) \
1597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   ((PLANE[3] + PLANE[0] * (X) + PLANE[1] * (Y)) / -PLANE[2])
1607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Return 1 / solve_plane().
1647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4])
1677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1686ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   const GLfloat denom = plane[3] + plane[0] * x + plane[1] * y;
1696ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   if (denom == 0.0)
1706ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      return 0.0;
1716ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   else
1726ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      return -plane[2] / denom;
1737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Solve plane and return clamped GLchan value.
1787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLchan
1807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4])
1817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2] + 0.5F;
1837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (z < 0.0F)
1847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return 0;
1857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else if (z > CHAN_MAXF)
186b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul      return (GLchan) CHAN_MAXF;
1877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   return (GLchan) (GLint) z;
1887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute mipmap level of detail.
1937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
1967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul               GLfloat invQ, GLfloat width, GLfloat height)
1977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dudx = sPlane[0] / sPlane[2] * invQ * width;
1997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dudy = sPlane[1] / sPlane[2] * invQ * width;
2007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dvdx = tPlane[0] / tPlane[2] * invQ * height;
2017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dvdy = tPlane[1] / tPlane[2] * invQ * height;
2027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat r1 = dudx * dudx + dudy * dudy;
2037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat r2 = dvdx * dvdx + dvdy * dvdy;
2047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat rho2 = r1 + r2;
2057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* return log base 2 of rho */
206dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul   if (rho2 == 0.0F)
207dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul      return 0.0;
208dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul   else
2097b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz      return (GLfloat) (log(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */
2107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
2117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
2167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Fill in the samples[] array with the (x,y) subpixel positions of
2177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * xSamples * ySamples sample positions.
2187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Note that the four corner samples are put into the first four
2197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * positions of the array.  This allows us to optimize for the common
2207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * case of all samples being inside the polygon.
2217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
2227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
2237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulmake_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2])
2247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
2257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat dx = 1.0F / (GLfloat) xSamples;
2267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat dy = 1.0F / (GLfloat) ySamples;
2277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint x, y;
2287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint i;
2297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   i = 4;
2317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   for (x = 0; x < xSamples; x++) {
2327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (y = 0; y < ySamples; y++) {
2337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint j;
2347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (x == 0 && y == 0) {
2357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* lower left */
2367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 0;
2377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == xSamples - 1 && y == 0) {
2397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* lower right */
2407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 1;
2417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == 0 && y == ySamples - 1) {
2437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* upper left */
2447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 2;
2457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == xSamples - 1 && y == ySamples - 1) {
2477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* upper right */
2487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 3;
2497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
2517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = i++;
2527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2537b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz         samples[j][0] = x * dx + 0.5F * dx;
2547b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz         samples[j][1] = y * dy + 0.5F * dy;
2557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
2567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
2587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
2627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute how much of the given pixel's area is inside the rectangle
2637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * defined by vertices v0, v1, v2, v3.
2647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Vertices MUST be specified in counter-clockwise order.
2657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Return:  coverage in [0, 1].
2667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
2677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic GLfloat
2687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_coveragef(const struct LineInfo *info,
2697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul                  GLint winx, GLint winy)
2707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
2717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   static GLfloat samples[SUB_PIXEL * SUB_PIXEL][2];
2727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   static GLboolean haveSamples = GL_FALSE;
2737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x = (GLfloat) winx;
2747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y = (GLfloat) winy;
2757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint stop = 4, i;
2767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat insideCount = SUB_PIXEL * SUB_PIXEL;
2777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (!haveSamples) {
2797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      make_sample_table(SUB_PIXEL, SUB_PIXEL, samples);
2807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      haveSamples = GL_TRUE;
2817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#if 0 /*DEBUG*/
2847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   {
2857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat area = dx0 * dy1 - dx1 * dy0;
2867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      assert(area >= 0.0);
2877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#endif
2897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   for (i = 0; i < stop; i++) {
2917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat sx = x + samples[i][0];
2927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat sy = y + samples[i][1];
2937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx0 = sx - info->qx0;
2947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy0 = sy - info->qy0;
2957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx1 = sx - info->qx1;
2967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy1 = sy - info->qy1;
2977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx2 = sx - info->qx2;
2987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy2 = sy - info->qy2;
2997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx3 = sx - info->qx3;
3007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy3 = sy - info->qy3;
3017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* cross product determines if sample is inside or outside each edge */
3027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross0 = (info->ex0 * fy0 - info->ey0 * fx0);
3037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross1 = (info->ex1 * fy1 - info->ey1 * fx1);
3047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross2 = (info->ex2 * fy2 - info->ey2 * fx2);
3057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross3 = (info->ex3 * fy3 - info->ey3 * fx3);
3067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Check if the sample is exactly on an edge.  If so, let cross be a
3077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul       * positive or negative value depending on the direction of the edge.
3087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul       */
3097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross0 == 0.0F)
3107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross0 = info->ex0 + info->ey0;
3117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross1 == 0.0F)
3127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross1 = info->ex1 + info->ey1;
3137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross2 == 0.0F)
3147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross2 = info->ex2 + info->ey2;
3157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross3 == 0.0F)
3167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross3 = info->ex3 + info->ey3;
3177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross0 < 0.0F || cross1 < 0.0F || cross2 < 0.0F || cross3 < 0.0F) {
3187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* point is outside quadrilateral */
3197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         insideCount -= 1.0F;
3207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         stop = SUB_PIXEL * SUB_PIXEL;
3217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
3227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
3237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (stop == 4)
3247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return 1.0F;
3257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else
3267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return insideCount * (1.0F / (SUB_PIXEL * SUB_PIXEL));
3277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
3287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
331733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paultypedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line,
332733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul                          int ix, int iy);
333733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul
3347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
3377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Draw an AA line segment (called many times per line when stippling)
3387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
3397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
3407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsegment(GLcontext *ctx,
3417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        struct LineInfo *line,
3427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        plot_func plot,
3437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        GLfloat t0, GLfloat t1)
3447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
3457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat absDx = (line->dx < 0.0F) ? -line->dx : line->dx;
3467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat absDy = (line->dy < 0.0F) ? -line->dy : line->dy;
3477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute the actual segment's endpoints */
3487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x0 = line->x0 + t0 * line->dx;
3497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y0 = line->y0 + t0 * line->dy;
3507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x1 = line->x0 + t1 * line->dx;
3517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y1 = line->y0 + t1 * line->dy;
3527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute vertices of the line-aligned quadrilateral */
3547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx0 = x0 - line->yAdj;
3557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy0 = y0 + line->xAdj;
3567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx1 = x0 + line->yAdj;
3577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy1 = y0 - line->xAdj;
3587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx2 = x1 + line->yAdj;
3597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy2 = y1 - line->xAdj;
3607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx3 = x1 - line->yAdj;
3617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy3 = y1 + line->xAdj;
3627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute the quad's edge vectors (for coverage calc) */
3637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex0 = line->qx1 - line->qx0;
3647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey0 = line->qy1 - line->qy0;
3657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex1 = line->qx2 - line->qx1;
3667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey1 = line->qy2 - line->qy1;
3677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex2 = line->qx3 - line->qx2;
3687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey2 = line->qy3 - line->qy2;
3697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex3 = line->qx0 - line->qx3;
3707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey3 = line->qy0 - line->qy3;
3717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (absDx > absDy) {
3737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* X-major line */
3747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat dydx = line->dy / line->dx;
3757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat xLeft, xRight, yBot, yTop;
3767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLint ix, ixRight;
3777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (x0 < x1) {
3787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft = x0 - line->halfWidth;
3797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight = x1 + line->halfWidth;
3807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dy >= 0.0) {
3817b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yBot = y0 - 3.0F * line->halfWidth;
3827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yTop = y0 + line->halfWidth;
3837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
3857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yBot = y0 - line->halfWidth;
3867b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yTop = y0 + 3.0F * line->halfWidth;
3877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
3897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
3907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft = x1 - line->halfWidth;
3917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight = x0 + line->halfWidth;
3927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dy <= 0.0) {
3937b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yBot = y1 - 3.0F * line->halfWidth;
3947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yTop = y1 + line->halfWidth;
3957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
3977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yBot = y1 - line->halfWidth;
3987b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yTop = y1 + 3.0F * line->halfWidth;
3997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* scan along the line, left-to-right */
4037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      ixRight = (GLint) (xRight + 1.0F);
4047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /*printf("avg span height: %g\n", yTop - yBot);*/
4067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (ix = (GLint) xLeft; ix < ixRight; ix++) {
4077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint iyBot = (GLint) yBot;
4087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint iyTop = (GLint) (yTop + 1.0F);
4097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint iy;
4107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* scan across the line, bottom-to-top */
4117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         for (iy = iyBot; iy < iyTop; iy++) {
412733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul            (*plot)(ctx, line, ix, iy);
4137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot += dydx;
4157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop += dydx;
4167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
4187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else {
4197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Y-major line */
4207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat dxdy = line->dx / line->dy;
4217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat yBot, yTop, xLeft, xRight;
4227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLint iy, iyTop;
4237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (y0 < y1) {
4247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot = y0 - line->halfWidth;
4257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop = y1 + line->halfWidth;
4267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dx >= 0.0) {
4277b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xLeft = x0 - 3.0F * line->halfWidth;
4287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xRight = x0 + line->halfWidth;
4297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
4317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xLeft = x0 - line->halfWidth;
4327b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xRight = x0 + 3.0F * line->halfWidth;
4337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
4367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot = y1 - line->halfWidth;
4377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop = y0 + line->halfWidth;
4387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dx <= 0.0) {
4397b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xLeft = x1 - 3.0F * line->halfWidth;
4407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xRight = x1 + line->halfWidth;
4417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
4437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xLeft = x1 - line->halfWidth;
4447b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xRight = x1 + 3.0F * line->halfWidth;
4457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* scan along the line, bottom-to-top */
4497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      iyTop = (GLint) (yTop + 1.0F);
4507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /*printf("avg span width: %g\n", xRight - xLeft);*/
4527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (iy = (GLint) yBot; iy < iyTop; iy++) {
4537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint ixLeft = (GLint) xLeft;
4547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint ixRight = (GLint) (xRight + 1.0F);
4557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint ix;
4567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* scan across the line, left-to-right */
4577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         for (ix = ixLeft; ix < ixRight; ix++) {
458733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul            (*plot)(ctx, line, ix, iy);
4597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft += dxdy;
4617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight += dxdy;
4627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
4647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
4657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_ci_##x
4687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_INDEX
4717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_rgba_##x
4757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x)  aa_tex_rgba_##x
4827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_TEX
4867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x)  aa_multitex_rgba_##x
4907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
491733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define DO_FOG
4927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_MULTITEX
4946b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#include "s_aalinetemp.h"
4956b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul
4966b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul
4976b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define NAME(x)  aa_multitex_spec_##x
4986b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_Z
499733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define DO_FOG
5006b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_RGBA
5016b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_MULTITEX
5027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_SPEC
5037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
5047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulvoid
5087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul_swrast_choose_aa_line_function(GLcontext *ctx)
5097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
5107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   SWcontext *swrast = SWRAST_CONTEXT(ctx);
5117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   ASSERT(ctx->Line.SmoothFlag);
5137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
514b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul   if (ctx->Visual.rgbMode) {
5157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* RGBA */
5168afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      if (ctx->Texture._EnabledUnits != 0) {
5178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul         if (ctx->Texture._EnabledUnits > 1) {
5187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* Multitextured! */
5196b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul            if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR ||
5206b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul                ctx->Fog.ColorSumEnabled)
5216b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul               swrast->Line = aa_multitex_spec_line;
5226b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul            else
5236b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul               swrast->Line = aa_multitex_rgba_line;
5246b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         }
5256b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         else {
5267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            swrast->Line = aa_tex_rgba_line;
5276b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         }
5287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
5297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
5307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         swrast->Line = aa_rgba_line;
5317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
5327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
5337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else {
5347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Color Index */
5357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      swrast->Line = aa_ci_line;
5367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
5377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
538