s_aaline.c revision 13c4c046a5ff6130fa27385bb93d2464e0ff0f83
113c4c046a5ff6130fa27385bb93d2464e0ff0f83Brian Paul/* $Id: s_aaline.c,v 1.18 2003/02/27 23:37:53 brianp Exp $ */
27798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
37798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
47798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Mesa 3-D graphics library
513c4c046a5ff6130fa27385bb93d2464e0ff0f83Brian Paul * Version:  5.0.1
65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen *
713c4c046a5ff6130fa27385bb93d2464e0ff0f83Brian Paul * Copyright (C) 1999-2003  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 */
72610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat sPlane[MAX_TEXTURE_COORD_UNITS][4];
73610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat tPlane[MAX_TEXTURE_COORD_UNITS][4];
74610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat uPlane[MAX_TEXTURE_COORD_UNITS][4];
75610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat vPlane[MAX_TEXTURE_COORD_UNITS][4];
76610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat lambda[MAX_TEXTURE_COORD_UNITS];
77610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat texWidth[MAX_TEXTURE_COORD_UNITS];
78610d59981a9f43fefe29b34ef19c184d28e2bef5Brian Paul   GLfloat texHeight[MAX_TEXTURE_COORD_UNITS];
79733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul
8077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   struct sw_span span;
817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul};
827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute the equation of a plane used to interpolate line fragment data
877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * such as color, Z, texture coords, etc.
887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Input: (x0, y0) and (x1,y1) are the endpoints of the line.
897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul *        z0, and z1 are the end point values to interpolate.
907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Output:  plane - the plane equation.
917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul *
927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Note: we don't really have enough parameters to specify a plane.
937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * We take the endpoints of the line and compute a plane such that
947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * the cross product of the line vector and the plane normal is
957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * parallel to the projection plane.
967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul              GLfloat z0, GLfloat z1, GLfloat plane[4])
1007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#if 0
1027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* original */
1037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat px = x1 - x0;
1047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat py = y1 - y0;
1057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat pz = z1 - z0;
1067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qx = -py;
1077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qy = px;
1087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat qz = 0;
1097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat a = py * qz - pz * qy;
1107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat b = pz * qx - px * qz;
1117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat c = px * qy - py * qx;
1127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat d = -(a * x0 + b * y0 + c * z0);
1137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[0] = a;
1147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[1] = b;
1157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[2] = c;
1167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[3] = d;
1177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#else
1187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* simplified */
1197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat px = x1 - x0;
1207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat py = y1 - y0;
1217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat pz = z0 - z1;
1227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat a = pz * px;
1237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat b = pz * py;
1247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat c = px * px + py * py;
1257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat d = -(a * x0 + b * y0 + c * z0);
1266ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   if (a == 0.0 && b == 0.0 && c == 0.0 && d == 0.0) {
1276ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[0] = 0.0;
1286ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[1] = 0.0;
1296ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[2] = 1.0;
1306ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[3] = 0.0;
1316ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   }
1326ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   else {
1336ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[0] = a;
1346ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[1] = b;
1356ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[2] = c;
1366ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      plane[3] = d;
1376ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   }
1387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#endif
1397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE void
1437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulconstant_plane(GLfloat value, GLfloat plane[4])
1447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[0] = 0.0;
1467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[1] = 0.0;
1477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[2] = -1.0;
1487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   plane[3] = value;
1497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
1547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1556ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
1567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   return z;
1577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define SOLVE_PLANE(X, Y, PLANE) \
1607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   ((PLANE[3] + PLANE[0] * (X) + PLANE[1] * (Y)) / -PLANE[2])
1617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Return 1 / solve_plane().
1657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4])
1687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1696ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   const GLfloat denom = plane[3] + plane[0] * x + plane[1] * y;
1706ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   if (denom == 0.0)
1716ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      return 0.0;
1726ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul   else
1736ac852d45b3a53dc51414773454e6bae7126fe33Brian Paul      return -plane[2] / denom;
1747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Solve plane and return clamped GLchan value.
1797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLchan
1817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsolve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4])
1827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2] + 0.5F;
1847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (z < 0.0F)
1857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return 0;
1867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else if (z > CHAN_MAXF)
187b51b0a847d7e7daaea69f77ab569086ef81c24a2Brian Paul      return (GLchan) CHAN_MAXF;
18813c4c046a5ff6130fa27385bb93d2464e0ff0f83Brian Paul   return (GLchan) z;
1897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
1907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
1927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
1937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute mipmap level of detail.
1947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
1957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat
1967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
1977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul               GLfloat invQ, GLfloat width, GLfloat height)
1987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
1997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dudx = sPlane[0] / sPlane[2] * invQ * width;
2007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dudy = sPlane[1] / sPlane[2] * invQ * width;
2017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dvdx = tPlane[0] / tPlane[2] * invQ * height;
2027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat dvdy = tPlane[1] / tPlane[2] * invQ * height;
2037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat r1 = dudx * dudx + dudy * dudy;
2047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat r2 = dvdx * dvdx + dvdy * dvdy;
2057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat rho2 = r1 + r2;
2067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* return log base 2 of rho */
207dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul   if (rho2 == 0.0F)
208dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul      return 0.0;
209dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul   else
2107b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz      return (GLfloat) (log(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */
2117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
2127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
2177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Fill in the samples[] array with the (x,y) subpixel positions of
2187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * xSamples * ySamples sample positions.
2197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Note that the four corner samples are put into the first four
2207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * positions of the array.  This allows us to optimize for the common
2217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * case of all samples being inside the polygon.
2227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
2237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
2247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulmake_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2])
2257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
2267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat dx = 1.0F / (GLfloat) xSamples;
2277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat dy = 1.0F / (GLfloat) ySamples;
2287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint x, y;
2297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint i;
2307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   i = 4;
2327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   for (x = 0; x < xSamples; x++) {
2337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (y = 0; y < ySamples; y++) {
2347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint j;
2357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (x == 0 && y == 0) {
2367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* lower left */
2377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 0;
2387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == xSamples - 1 && y == 0) {
2407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* lower right */
2417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 1;
2427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == 0 && y == ySamples - 1) {
2447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* upper left */
2457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 2;
2467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else if (x == xSamples - 1 && y == ySamples - 1) {
2487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* upper right */
2497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = 3;
2507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
2527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            j = i++;
2537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
2547b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz         samples[j][0] = x * dx + 0.5F * dx;
2557b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz         samples[j][1] = y * dy + 0.5F * dy;
2567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
2577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
2597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
2637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute how much of the given pixel's area is inside the rectangle
2647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * defined by vertices v0, v1, v2, v3.
2657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Vertices MUST be specified in counter-clockwise order.
2667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Return:  coverage in [0, 1].
2677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
2687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic GLfloat
2697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_coveragef(const struct LineInfo *info,
2707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul                  GLint winx, GLint winy)
2717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
2727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   static GLfloat samples[SUB_PIXEL * SUB_PIXEL][2];
2737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   static GLboolean haveSamples = GL_FALSE;
2747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x = (GLfloat) winx;
2757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y = (GLfloat) winy;
2767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLint stop = 4, i;
2777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   GLfloat insideCount = SUB_PIXEL * SUB_PIXEL;
2787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (!haveSamples) {
2807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      make_sample_table(SUB_PIXEL, SUB_PIXEL, samples);
2817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      haveSamples = GL_TRUE;
2827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#if 0 /*DEBUG*/
2857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   {
2867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat area = dx0 * dy1 - dx1 * dy0;
2877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      assert(area >= 0.0);
2887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
2897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#endif
2907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
2917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   for (i = 0; i < stop; i++) {
2927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat sx = x + samples[i][0];
2937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat sy = y + samples[i][1];
2947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx0 = sx - info->qx0;
2957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy0 = sy - info->qy0;
2967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx1 = sx - info->qx1;
2977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy1 = sy - info->qy1;
2987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx2 = sx - info->qx2;
2997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy2 = sy - info->qy2;
3007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fx3 = sx - info->qx3;
3017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      const GLfloat fy3 = sy - info->qy3;
3027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* cross product determines if sample is inside or outside each edge */
3037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross0 = (info->ex0 * fy0 - info->ey0 * fx0);
3047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross1 = (info->ex1 * fy1 - info->ey1 * fx1);
3057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross2 = (info->ex2 * fy2 - info->ey2 * fx2);
3067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat cross3 = (info->ex3 * fy3 - info->ey3 * fx3);
3077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Check if the sample is exactly on an edge.  If so, let cross be a
3087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul       * positive or negative value depending on the direction of the edge.
3097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul       */
3107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross0 == 0.0F)
3117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross0 = info->ex0 + info->ey0;
3127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross1 == 0.0F)
3137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross1 = info->ex1 + info->ey1;
3147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross2 == 0.0F)
3157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross2 = info->ex2 + info->ey2;
3167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross3 == 0.0F)
3177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         cross3 = info->ex3 + info->ey3;
3187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (cross0 < 0.0F || cross1 < 0.0F || cross2 < 0.0F || cross3 < 0.0F) {
3197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* point is outside quadrilateral */
3207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         insideCount -= 1.0F;
3217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         stop = SUB_PIXEL * SUB_PIXEL;
3227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
3237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
3247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (stop == 4)
3257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return 1.0F;
3267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else
3277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      return insideCount * (1.0F / (SUB_PIXEL * SUB_PIXEL));
3287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
3297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
332733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paultypedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line,
333733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul                          int ix, int iy);
334733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul
3357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/*
3387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Draw an AA line segment (called many times per line when stippling)
3397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */
3407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void
3417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsegment(GLcontext *ctx,
3427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        struct LineInfo *line,
3437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        plot_func plot,
3447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul        GLfloat t0, GLfloat t1)
3457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
3467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat absDx = (line->dx < 0.0F) ? -line->dx : line->dx;
3477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat absDy = (line->dy < 0.0F) ? -line->dy : line->dy;
3487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute the actual segment's endpoints */
3497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x0 = line->x0 + t0 * line->dx;
3507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y0 = line->y0 + t0 * line->dy;
3517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat x1 = line->x0 + t1 * line->dx;
3527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   const GLfloat y1 = line->y0 + t1 * line->dy;
3537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute vertices of the line-aligned quadrilateral */
3557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx0 = x0 - line->yAdj;
3567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy0 = y0 + line->xAdj;
3577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx1 = x0 + line->yAdj;
3587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy1 = y0 - line->xAdj;
3597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx2 = x1 + line->yAdj;
3607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy2 = y1 - line->xAdj;
3617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qx3 = x1 - line->yAdj;
3627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->qy3 = y1 + line->xAdj;
3637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   /* compute the quad's edge vectors (for coverage calc) */
3647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex0 = line->qx1 - line->qx0;
3657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey0 = line->qy1 - line->qy0;
3667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex1 = line->qx2 - line->qx1;
3677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey1 = line->qy2 - line->qy1;
3687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex2 = line->qx3 - line->qx2;
3697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey2 = line->qy3 - line->qy2;
3707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ex3 = line->qx0 - line->qx3;
3717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   line->ey3 = line->qy0 - line->qy3;
3727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
3737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   if (absDx > absDy) {
3747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* X-major line */
3757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat dydx = line->dy / line->dx;
3767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat xLeft, xRight, yBot, yTop;
3777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLint ix, ixRight;
3787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (x0 < x1) {
3797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft = x0 - line->halfWidth;
3807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight = x1 + line->halfWidth;
3817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dy >= 0.0) {
3827b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yBot = y0 - 3.0F * line->halfWidth;
3837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yTop = y0 + line->halfWidth;
3847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
3867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yBot = y0 - line->halfWidth;
3877b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yTop = y0 + 3.0F * line->halfWidth;
3887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
3907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
3917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft = x1 - line->halfWidth;
3927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight = x0 + line->halfWidth;
3937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dy <= 0.0) {
3947b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yBot = y1 - 3.0F * line->halfWidth;
3957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yTop = y1 + line->halfWidth;
3967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
3977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
3987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            yBot = y1 - line->halfWidth;
3997b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            yTop = y1 + 3.0F * line->halfWidth;
4007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* scan along the line, left-to-right */
4047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      ixRight = (GLint) (xRight + 1.0F);
4057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /*printf("avg span height: %g\n", yTop - yBot);*/
4077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (ix = (GLint) xLeft; ix < ixRight; ix++) {
4087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint iyBot = (GLint) yBot;
4097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint iyTop = (GLint) (yTop + 1.0F);
4107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint iy;
4117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* scan across the line, bottom-to-top */
4127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         for (iy = iyBot; iy < iyTop; iy++) {
413733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul            (*plot)(ctx, line, ix, iy);
4147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot += dydx;
4167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop += dydx;
4177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
4197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else {
4207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Y-major line */
4217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat dxdy = line->dx / line->dy;
4227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLfloat yBot, yTop, xLeft, xRight;
4237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      GLint iy, iyTop;
4247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      if (y0 < y1) {
4257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot = y0 - line->halfWidth;
4267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop = y1 + line->halfWidth;
4277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dx >= 0.0) {
4287b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xLeft = x0 - 3.0F * line->halfWidth;
4297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xRight = x0 + line->halfWidth;
4307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
4327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xLeft = x0 - line->halfWidth;
4337b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xRight = x0 + 3.0F * line->halfWidth;
4347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
4377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yBot = y1 - line->halfWidth;
4387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         yTop = y0 + line->halfWidth;
4397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         if (line->dx <= 0.0) {
4407b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xLeft = x1 - 3.0F * line->halfWidth;
4417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xRight = x1 + line->halfWidth;
4427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         else {
4447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            xLeft = x1 - line->halfWidth;
4457b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz            xRight = x1 + 3.0F * line->halfWidth;
4467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* scan along the line, bottom-to-top */
4507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      iyTop = (GLint) (yTop + 1.0F);
4517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /*printf("avg span width: %g\n", xRight - xLeft);*/
4537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      for (iy = (GLint) yBot; iy < iyTop; iy++) {
4547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint ixLeft = (GLint) xLeft;
4557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         const GLint ixRight = (GLint) (xRight + 1.0F);
4567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         GLint ix;
4577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         /* scan across the line, left-to-right */
4587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         for (ix = ixLeft; ix < ixRight; ix++) {
459733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul            (*plot)(ctx, line, ix, iy);
4607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         }
4617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xLeft += dxdy;
4627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         xRight += dxdy;
4637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
4647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
4657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
4667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_ci_##x
4697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_INDEX
4727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_rgba_##x
4767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x)  aa_tex_rgba_##x
4837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
4847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG
4857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_TEX
4877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
4887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
4907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x)  aa_multitex_rgba_##x
4917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z
492733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define DO_FOG
4937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA
4947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_MULTITEX
4956b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#include "s_aalinetemp.h"
4966b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul
4976b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul
4986b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define NAME(x)  aa_multitex_spec_##x
4996b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_Z
500733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define DO_FOG
5016b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_RGBA
5026b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_MULTITEX
5037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_SPEC
5047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h"
5057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulvoid
5097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul_swrast_choose_aa_line_function(GLcontext *ctx)
5107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{
5117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   SWcontext *swrast = SWRAST_CONTEXT(ctx);
5127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
5137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   ASSERT(ctx->Line.SmoothFlag);
5147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul
515b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul   if (ctx->Visual.rgbMode) {
5167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* RGBA */
5178afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul      if (ctx->Texture._EnabledUnits != 0) {
5188afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul         if (ctx->Texture._EnabledUnits > 1) {
5197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            /* Multitextured! */
5206b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul            if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR ||
5216b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul                ctx->Fog.ColorSumEnabled)
5226b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul               swrast->Line = aa_multitex_spec_line;
5236b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul            else
5246b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul               swrast->Line = aa_multitex_rgba_line;
5256b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         }
5266b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         else {
5277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul            swrast->Line = aa_tex_rgba_line;
5286b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul         }
5297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
5307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      else {
5317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul         swrast->Line = aa_rgba_line;
5327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      }
5337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
5347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   else {
5357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      /* Color Index */
5367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul      swrast->Line = aa_ci_line;
5377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul   }
5387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul}
539