s_aaline.c revision eca456b63d41700617987ba45a09e8f2168b9577
17798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 27798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Mesa 3-D graphics library 3dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian * Version: 6.5.3 45e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 5dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 65e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 77798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a 87798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * copy of this software and associated documentation files (the "Software"), 97798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * to deal in the Software without restriction, including without limitation 107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * and/or sell copies of the Software, and to permit persons to whom the 127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Software is furnished to do so, subject to the following conditions: 135e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * The above copyright notice and this permission notice shall be included 157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * in all copies or substantial portions of the Software. 165e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "glheader.h" 2727558a160a9fe91745728d7626995cd88f8fe339Brian Paul#include "imports.h" 28a2da1155c285fde2a5e5824d50ee8a57c6e982f5Brian Paul#include "macros.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" 347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define SUB_PIXEL 4 377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Info about the AA line we're rendering 417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstruct LineInfo 437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat x0, y0; /* start */ 457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat x1, y1; /* end */ 467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dx, dy; /* direction vector */ 477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat len; /* length */ 487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat halfWidth; /* half of line width */ 497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat xAdj, yAdj; /* X and Y adjustment for quad corners around line */ 507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* for coverage computation */ 517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat qx0, qy0; /* quad vertices */ 527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat qx1, qy1; 537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat qx2, qy2; 547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat qx3, qy3; 557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat ex0, ey0; /* quad edge vectors */ 567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat ex1, ey1; 577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat ex2, ey2; 587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat ex3, ey3; 597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* DO_Z */ 617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat zPlane[4]; 627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* DO_FOG */ 637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat fPlane[4]; 647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* DO_RGBA */ 657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4]; 667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* DO_INDEX */ 677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat iPlane[4]; 687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* DO_SPEC */ 697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat srPlane[4], sgPlane[4], sbPlane[4]; 70eca456b63d41700617987ba45a09e8f2168b9577Brian /* DO_ATTRIBS */ 71dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat sPlane[FRAG_ATTRIB_MAX][4]; 72dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat tPlane[FRAG_ATTRIB_MAX][4]; 73dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat uPlane[FRAG_ATTRIB_MAX][4]; 74dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat vPlane[FRAG_ATTRIB_MAX][4]; 75dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat lambda[FRAG_ATTRIB_MAX]; 76dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat texWidth[FRAG_ATTRIB_MAX]; 77dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian GLfloat texHeight[FRAG_ATTRIB_MAX]; 78733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul 79cdb27e8242215271364602995d85607cfc06d441Brian Paul SWspan 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{ 182a20ed720032d1a04a5206374020234140dd5ef08Brian Paul const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2]; 183a20ed720032d1a04a5206374020234140dd5ef08Brian Paul#if CHAN_TYPE == GL_FLOAT 184a20ed720032d1a04a5206374020234140dd5ef08Brian Paul return CLAMP(z, 0.0F, CHAN_MAXF); 185a20ed720032d1a04a5206374020234140dd5ef08Brian Paul#else 186a20ed720032d1a04a5206374020234140dd5ef08Brian Paul if (z < 0) 1877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul return 0; 188a20ed720032d1a04a5206374020234140dd5ef08Brian Paul else if (z > CHAN_MAX) 189a20ed720032d1a04a5206374020234140dd5ef08Brian Paul return CHAN_MAX; 190a20ed720032d1a04a5206374020234140dd5ef08Brian Paul return (GLchan) IROUND_POS(z); 191a20ed720032d1a04a5206374020234140dd5ef08Brian Paul#endif 1927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 1937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 1947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 1957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 1967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute mipmap level of detail. 1977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 1987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic INLINE GLfloat 1997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4], 2007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat invQ, GLfloat width, GLfloat height) 2017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 2027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dudx = sPlane[0] / sPlane[2] * invQ * width; 2037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dudy = sPlane[1] / sPlane[2] * invQ * width; 2047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dvdx = tPlane[0] / tPlane[2] * invQ * height; 2057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dvdy = tPlane[1] / tPlane[2] * invQ * height; 2067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat r1 = dudx * dudx + dudy * dudy; 2077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat r2 = dvdx * dvdx + dvdy * dvdy; 2087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat rho2 = r1 + r2; 2097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* return log base 2 of rho */ 210dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul if (rho2 == 0.0F) 211dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul return 0.0; 212dbed2027444338dc09fc102d6f4bd5c707c238d7Brian Paul else 213b3aefd1cfb6aacd1695c52911dd39da50d893eceBrian Paul return (GLfloat) (LOGF(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */ 2147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 2157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 2207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Fill in the samples[] array with the (x,y) subpixel positions of 2217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * xSamples * ySamples sample positions. 2227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Note that the four corner samples are put into the first four 2237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * positions of the array. This allows us to optimize for the common 2247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * case of all samples being inside the polygon. 2257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 2267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void 2277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulmake_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2]) 2287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 2297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat dx = 1.0F / (GLfloat) xSamples; 2307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat dy = 1.0F / (GLfloat) ySamples; 2317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint x, y; 2327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint i; 2337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul i = 4; 2357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (x = 0; x < xSamples; x++) { 2367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (y = 0; y < ySamples; y++) { 2377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint j; 2387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (x == 0 && y == 0) { 2397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* lower left */ 2407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul j = 0; 2417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else if (x == xSamples - 1 && y == 0) { 2437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* lower right */ 2447798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul j = 1; 2457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else if (x == 0 && y == ySamples - 1) { 2477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* upper left */ 2487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul j = 2; 2497798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else if (x == xSamples - 1 && y == ySamples - 1) { 2517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* upper right */ 2527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul j = 3; 2537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 2557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul j = i++; 2567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2577b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz samples[j][0] = x * dx + 0.5F * dx; 2587b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz samples[j][1] = y * dy + 0.5F * dy; 2597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 2627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 2667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Compute how much of the given pixel's area is inside the rectangle 2677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * defined by vertices v0, v1, v2, v3. 2687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Vertices MUST be specified in counter-clockwise order. 2697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Return: coverage in [0, 1]. 2707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 2717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic GLfloat 2727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulcompute_coveragef(const struct LineInfo *info, 2737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint winx, GLint winy) 2747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 2757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul static GLfloat samples[SUB_PIXEL * SUB_PIXEL][2]; 2767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul static GLboolean haveSamples = GL_FALSE; 2777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat x = (GLfloat) winx; 2787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat y = (GLfloat) winy; 2797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint stop = 4, i; 2807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat insideCount = SUB_PIXEL * SUB_PIXEL; 2817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (!haveSamples) { 2837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul make_sample_table(SUB_PIXEL, SUB_PIXEL, samples); 2847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul haveSamples = GL_TRUE; 2857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#if 0 /*DEBUG*/ 2887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul { 2897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat area = dx0 * dy1 - dx1 * dy0; 2907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul assert(area >= 0.0); 2917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 2927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#endif 2937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 2947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (i = 0; i < stop; i++) { 2957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat sx = x + samples[i][0]; 2967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat sy = y + samples[i][1]; 2977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fx0 = sx - info->qx0; 2987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fy0 = sy - info->qy0; 2997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fx1 = sx - info->qx1; 3007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fy1 = sy - info->qy1; 3017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fx2 = sx - info->qx2; 3027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fy2 = sy - info->qy2; 3037798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fx3 = sx - info->qx3; 3047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat fy3 = sy - info->qy3; 3057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* cross product determines if sample is inside or outside each edge */ 3067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat cross0 = (info->ex0 * fy0 - info->ey0 * fx0); 3077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat cross1 = (info->ex1 * fy1 - info->ey1 * fx1); 3087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat cross2 = (info->ex2 * fy2 - info->ey2 * fx2); 3097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat cross3 = (info->ex3 * fy3 - info->ey3 * fx3); 3107798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* Check if the sample is exactly on an edge. If so, let cross be a 3117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * positive or negative value depending on the direction of the edge. 3127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 3137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (cross0 == 0.0F) 3147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul cross0 = info->ex0 + info->ey0; 3157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (cross1 == 0.0F) 3167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul cross1 = info->ex1 + info->ey1; 3177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (cross2 == 0.0F) 3187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul cross2 = info->ex2 + info->ey2; 3197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (cross3 == 0.0F) 3207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul cross3 = info->ex3 + info->ey3; 3217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (cross0 < 0.0F || cross1 < 0.0F || cross2 < 0.0F || cross3 < 0.0F) { 3227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* point is outside quadrilateral */ 3237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul insideCount -= 1.0F; 3247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul stop = SUB_PIXEL * SUB_PIXEL; 3257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 3267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 3277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (stop == 4) 3287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul return 1.0F; 3297798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else 3307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul return insideCount * (1.0F / (SUB_PIXEL * SUB_PIXEL)); 3317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 3327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3341e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul/** 3351e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul * Compute coverage value for color index mode. 3361e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul * XXX this may not be quite correct. 3371e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul * \return coverage in [0,15]. 3381e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul */ 3391e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paulstatic GLfloat 3401e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paulcompute_coveragei(const struct LineInfo *info, 3411e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul GLint winx, GLint winy) 3421e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul{ 3431e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul return compute_coveragef(info, winx, winy) * 15.0F; 3441e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul} 3451e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul 3461e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul 3477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 348733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paultypedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line, 349733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul int ix, int iy); 350733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul 3517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul/* 3547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul * Draw an AA line segment (called many times per line when stippling) 3557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul */ 3567798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulstatic void 3577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulsegment(GLcontext *ctx, 3587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul struct LineInfo *line, 3597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul plot_func plot, 3607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat t0, GLfloat t1) 3617798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 3627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat absDx = (line->dx < 0.0F) ? -line->dx : line->dx; 3637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat absDy = (line->dy < 0.0F) ? -line->dy : line->dy; 3647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* compute the actual segment's endpoints */ 3657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat x0 = line->x0 + t0 * line->dx; 3667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat y0 = line->y0 + t0 * line->dy; 3677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat x1 = line->x0 + t1 * line->dx; 3687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLfloat y1 = line->y0 + t1 * line->dy; 3697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* compute vertices of the line-aligned quadrilateral */ 3717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qx0 = x0 - line->yAdj; 3727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qy0 = y0 + line->xAdj; 3737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qx1 = x0 + line->yAdj; 3747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qy1 = y0 - line->xAdj; 3757798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qx2 = x1 + line->yAdj; 3767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qy2 = y1 - line->xAdj; 3777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qx3 = x1 - line->yAdj; 3787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->qy3 = y1 + line->xAdj; 3797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* compute the quad's edge vectors (for coverage calc) */ 3807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ex0 = line->qx1 - line->qx0; 3817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ey0 = line->qy1 - line->qy0; 3827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ex1 = line->qx2 - line->qx1; 3837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ey1 = line->qy2 - line->qy1; 3847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ex2 = line->qx3 - line->qx2; 3857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ey2 = line->qy3 - line->qy2; 3867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ex3 = line->qx0 - line->qx3; 3877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul line->ey3 = line->qy0 - line->qy3; 3887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 3897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (absDx > absDy) { 3907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* X-major line */ 3917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dydx = line->dy / line->dx; 3927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat xLeft, xRight, yBot, yTop; 3937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint ix, ixRight; 3947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (x0 < x1) { 3957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xLeft = x0 - line->halfWidth; 3967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xRight = x1 + line->halfWidth; 3977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (line->dy >= 0.0) { 3987b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz yBot = y0 - 3.0F * line->halfWidth; 3997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yTop = y0 + line->halfWidth; 4007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4027798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yBot = y0 - line->halfWidth; 4037b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz yTop = y0 + 3.0F * line->halfWidth; 4047798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4057798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4067798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4077798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xLeft = x1 - line->halfWidth; 4087798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xRight = x0 + line->halfWidth; 4097798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (line->dy <= 0.0) { 4107b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz yBot = y1 - 3.0F * line->halfWidth; 4117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yTop = y1 + line->halfWidth; 4127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yBot = y1 - line->halfWidth; 4157b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz yTop = y1 + 3.0F * line->halfWidth; 4167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* scan along the line, left-to-right */ 4207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul ixRight = (GLint) (xRight + 1.0F); 4217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /*printf("avg span height: %g\n", yTop - yBot);*/ 4237798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (ix = (GLint) xLeft; ix < ixRight; ix++) { 4247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLint iyBot = (GLint) yBot; 4257798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLint iyTop = (GLint) (yTop + 1.0F); 4267798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint iy; 4277798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* scan across the line, bottom-to-top */ 4287798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (iy = iyBot; iy < iyTop; iy++) { 429733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul (*plot)(ctx, line, ix, iy); 4307798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4317798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yBot += dydx; 4327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yTop += dydx; 4337798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* Y-major line */ 4377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat dxdy = line->dx / line->dy; 4387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLfloat yBot, yTop, xLeft, xRight; 4397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint iy, iyTop; 4407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (y0 < y1) { 4417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yBot = y0 - line->halfWidth; 4427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yTop = y1 + line->halfWidth; 4437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (line->dx >= 0.0) { 4447b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz xLeft = x0 - 3.0F * line->halfWidth; 4457798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xRight = x0 + line->halfWidth; 4467798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4477798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4487798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xLeft = x0 - line->halfWidth; 4497b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz xRight = x0 + 3.0F * line->halfWidth; 4507798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4517798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4527798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4537798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yBot = y1 - line->halfWidth; 4547798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul yTop = y0 + line->halfWidth; 4557798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul if (line->dx <= 0.0) { 4567b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz xLeft = x1 - 3.0F * line->halfWidth; 4577798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xRight = x1 + line->halfWidth; 4587798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4597798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 4607798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xLeft = x1 - line->halfWidth; 4617b9fe820a3fba3849864682fbb1cb512362934abKarl Schultz xRight = x1 + 3.0F * line->halfWidth; 4627798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4637798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4647798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4657798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* scan along the line, bottom-to-top */ 4667798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul iyTop = (GLint) (yTop + 1.0F); 4677798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4687798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /*printf("avg span width: %g\n", xRight - xLeft);*/ 4697798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (iy = (GLint) yBot; iy < iyTop; iy++) { 4707798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLint ixLeft = (GLint) xLeft; 4717798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul const GLint ixRight = (GLint) (xRight + 1.0F); 4727798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul GLint ix; 4737798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* scan across the line, left-to-right */ 4747798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul for (ix = ixLeft; ix < ixRight; ix++) { 475733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul (*plot)(ctx, line, ix, iy); 4767798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4777798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xLeft += dxdy; 4787798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul xRight += dxdy; 4797798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4807798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 4817798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 4827798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4837798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4847798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_ci_##x 4857798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z 4867798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG 4877798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_INDEX 4887798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h" 4897798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4907798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4917798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_rgba_##x 4927798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z 4937798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG 4947798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA 4957798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h" 4967798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4977798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 4987798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define NAME(x) aa_tex_rgba_##x 4997798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_Z 5007798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_FOG 5017798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_RGBA 502eca456b63d41700617987ba45a09e8f2168b9577Brian#define DO_ATTRIBS 5036b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#include "s_aalinetemp.h" 5046b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul 5056b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul 5066b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define NAME(x) aa_multitex_spec_##x 5076b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_Z 508733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define DO_FOG 5096b1e4ea5a54ea852a904440cd9fa50251f63f64cBrian Paul#define DO_RGBA 510eca456b63d41700617987ba45a09e8f2168b9577Brian#define DO_ATTRIBS 5117798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#define DO_SPEC 5127798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul#include "s_aalinetemp.h" 5137798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 5147798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 5157798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 5167798374e472a8fa2f8699d38873e6b8490d853a4Brian Paulvoid 5177798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul_swrast_choose_aa_line_function(GLcontext *ctx) 5187798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul{ 5197798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul SWcontext *swrast = SWRAST_CONTEXT(ctx); 5207798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 5217798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul ASSERT(ctx->Line.SmoothFlag); 5227798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul 523b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul if (ctx->Visual.rgbMode) { 5247798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* RGBA */ 525dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian if (ctx->Texture._EnabledCoordUnits != 0 526dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian || ctx->FragmentProgram._Current) { 527dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian 528dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR || 529dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian ctx->Fog.ColorSumEnabled) 530dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian swrast->Line = aa_multitex_spec_line; 531dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian else 5327798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul swrast->Line = aa_tex_rgba_line; 533dd34fe8679fa200e55cfaf8e80bbecdecea084e3Brian 5347798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 5357798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 5367798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul swrast->Line = aa_rgba_line; 5377798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 5387798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 5397798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul else { 5407798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul /* Color Index */ 5417798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul swrast->Line = aa_ci_line; 5427798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul } 5437798374e472a8fa2f8699d38873e6b8490d853a4Brian Paul} 544