| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.4.1 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
/* |
| 26 |
* Triangle Rasterizer Template |
| 27 |
* |
| 28 |
* This file is #include'd to generate custom triangle rasterizers. |
| 29 |
* |
| 30 |
* The following macros may be defined to indicate what auxillary information |
| 31 |
* must be interplated across the triangle: |
| 32 |
* INTERP_Z - if defined, interpolate vertex Z values |
| 33 |
* INTERP_W - if defined, interpolate vertex W values |
| 34 |
* INTERP_FOG - if defined, interpolate fog values |
| 35 |
* INTERP_RGB - if defined, interpolate RGB values |
| 36 |
* INTERP_ALPHA - if defined, interpolate Alpha values (req's INTERP_RGB) |
| 37 |
* INTERP_SPEC - if defined, interpolate specular RGB values |
| 38 |
* INTERP_INDEX - if defined, interpolate color index values |
| 39 |
* INTERP_INT_TEX - if defined, interpolate integer ST texcoords |
| 40 |
* (fast, simple 2-D texture mapping) |
| 41 |
* INTERP_TEX - if defined, interpolate set 0 float STRQ texcoords |
| 42 |
* NOTE: OpenGL STRQ = Mesa STUV (R was taken for red) |
| 43 |
* INTERP_MULTITEX - if defined, interpolate N units of STRQ texcoords |
| 44 |
* |
| 45 |
* When one can directly address pixels in the color buffer the following |
| 46 |
* macros can be defined and used to compute pixel addresses during |
| 47 |
* rasterization (see pRow): |
| 48 |
* PIXEL_TYPE - the datatype of a pixel (GLubyte, GLushort, GLuint) |
| 49 |
* BYTES_PER_ROW - number of bytes per row in the color buffer |
| 50 |
* PIXEL_ADDRESS(X,Y) - returns the address of pixel at (X,Y) where |
| 51 |
* Y==0 at bottom of screen and increases upward. |
| 52 |
* |
| 53 |
* Similarly, for direct depth buffer access, this type is used for depth |
| 54 |
* buffer addressing: |
| 55 |
* DEPTH_TYPE - either GLushort or GLuint |
| 56 |
* |
| 57 |
* Optionally, one may provide one-time setup code per triangle: |
| 58 |
* SETUP_CODE - code which is to be executed once per triangle |
| 59 |
* CLEANUP_CODE - code to execute at end of triangle |
| 60 |
* |
| 61 |
* The following macro MUST be defined: |
| 62 |
* RENDER_SPAN(span) - code to write a span of pixels. |
| 63 |
* |
| 64 |
* This code was designed for the origin to be in the lower-left corner. |
| 65 |
* |
| 66 |
* Inspired by triangle rasterizer code written by Allen Akin. Thanks Allen! |
| 67 |
* |
| 68 |
* |
| 69 |
* Some notes on rasterization accuracy: |
| 70 |
* |
| 71 |
* This code uses fixed point arithmetic (the GLfixed type) to iterate |
| 72 |
* over the triangle edges and interpolate ancillary data (such as Z, |
| 73 |
* color, secondary color, etc). The number of fractional bits in |
| 74 |
* GLfixed and the value of SUB_PIXEL_BITS has a direct bearing on the |
| 75 |
* accuracy of rasterization. |
| 76 |
* |
| 77 |
* If SUB_PIXEL_BITS=4 then we'll snap the vertices to the nearest |
| 78 |
* 1/16 of a pixel. If we're walking up a long, nearly vertical edge |
| 79 |
* (dx=1/16, dy=1024) we'll need 4 + 10 = 14 fractional bits in |
| 80 |
* GLfixed to walk the edge without error. If the maximum viewport |
| 81 |
* height is 4K pixels, then we'll need 4 + 12 = 16 fractional bits. |
| 82 |
* |
| 83 |
* Historically, Mesa has used 11 fractional bits in GLfixed, snaps |
| 84 |
* vertices to 1/16 pixel and allowed a maximum viewport height of 2K |
| 85 |
* pixels. 11 fractional bits is actually insufficient for accurately |
| 86 |
* rasterizing some triangles. More recently, the maximum viewport |
| 87 |
* height was increased to 4K pixels. Thus, Mesa should be using 16 |
| 88 |
* fractional bits in GLfixed. Unfortunately, there may be some issues |
| 89 |
* with setting FIXED_FRAC_BITS=16, such as multiplication overflow. |
| 90 |
* This will have to be examined in some detail... |
| 91 |
* |
| 92 |
* For now, if you find rasterization errors, particularly with tall, |
| 93 |
* sliver triangles, try increasing FIXED_FRAC_BITS and/or decreasing |
| 94 |
* SUB_PIXEL_BITS. |
| 95 |
*/ |
| 96 |
|
| 97 |
/* |
| 98 |
* ColorTemp is used for intermediate color values. |
| 99 |
*/ |
| 100 |
#if CHAN_TYPE == GL_FLOAT |
| 101 |
#define ColorTemp GLfloat |
| 102 |
#else |
| 103 |
#define ColorTemp GLint /* same as GLfixed */ |
| 104 |
#endif |
| 105 |
|
| 106 |
|
| 107 |
/* |
| 108 |
* Walk triangle edges with GLfixed or GLdouble |
| 109 |
*/ |
| 110 |
#if TRIANGLE_WALK_DOUBLE |
| 111 |
#define GLinterp GLdouble |
| 112 |
#define InterpToInt(X) ((GLint) (X)) |
| 113 |
#define INTERP_ONE 1.0 |
| 114 |
#else |
| 115 |
#define GLinterp GLfixed |
| 116 |
#define InterpToInt(X) FixedToInt(X) |
| 117 |
#define INTERP_ONE FIXED_ONE |
| 118 |
#endif |
| 119 |
|
| 120 |
|
| 121 |
/* |
| 122 |
* Either loop over all texture units, or just use unit zero. |
| 123 |
*/ |
| 124 |
#ifdef INTERP_MULTITEX |
| 125 |
#define TEX_UNIT_LOOP(CODE) \ |
| 126 |
{ \ |
| 127 |
GLuint u; \ |
| 128 |
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \ |
| 129 |
if (ctx->Texture._EnabledCoordUnits & (1 << u)) { \ |
| 130 |
CODE \ |
| 131 |
} \ |
| 132 |
} \ |
| 133 |
} |
| 134 |
#define INTERP_TEX |
| 135 |
#elif defined(INTERP_TEX) |
| 136 |
#define TEX_UNIT_LOOP(CODE) \ |
| 137 |
{ \ |
| 138 |
const GLuint u = 0; \ |
| 139 |
CODE \ |
| 140 |
} |
| 141 |
#endif |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
/* |
| 146 |
* Some code we unfortunately need to prevent negative interpolated colors. |
| 147 |
*/ |
| 148 |
#ifndef CLAMP_INTERPOLANT |
| 149 |
#define CLAMP_INTERPOLANT(CHANNEL, CHANNELSTEP, LEN) \ |
| 150 |
do { \ |
| 151 |
GLfixed endVal = span.CHANNEL + (LEN) * span.CHANNELSTEP; \ |
| 152 |
if (endVal < 0) { \ |
| 153 |
span.CHANNEL -= endVal; \ |
| 154 |
} \ |
| 155 |
if (span.CHANNEL < 0) { \ |
| 156 |
span.CHANNEL = 0; \ |
| 157 |
} \ |
| 158 |
} while (0) |
| 159 |
#endif |
| 160 |
|
| 161 |
|
| 162 |
static void NAME(GLcontext *ctx, const SWvertex *v0, |
| 163 |
const SWvertex *v1, |
| 164 |
const SWvertex *v2 ) |
| 165 |
{ |
| 166 |
typedef struct { |
| 167 |
const SWvertex *v0, *v1; /* Y(v0) < Y(v1) */ |
| 168 |
#if TRIANGLE_WALK_DOUBLE |
| 169 |
GLdouble dx; /* X(v1) - X(v0) */ |
| 170 |
GLdouble dy; /* Y(v1) - Y(v0) */ |
| 171 |
GLdouble dxdy; /* dx/dy */ |
| 172 |
GLdouble adjy; /* adjust from v[0]->fy to fsy, scaled */ |
| 173 |
GLdouble fsx; /* first sample point x coord */ |
| 174 |
GLdouble fsy; |
| 175 |
GLdouble fx0; /*X of lower endpoint */ |
| 176 |
#else |
| 177 |
GLfloat dx; /* X(v1) - X(v0) */ |
| 178 |
GLfloat dy; /* Y(v1) - Y(v0) */ |
| 179 |
GLfloat dxdy; /* dx/dy */ |
| 180 |
GLfixed fdxdy; /* dx/dy in fixed-point */ |
| 181 |
GLfloat adjy; /* adjust from v[0]->fy to fsy, scaled */ |
| 182 |
GLfixed fsx; /* first sample point x coord */ |
| 183 |
GLfixed fsy; |
| 184 |
GLfixed fx0; /* fixed pt X of lower endpoint */ |
| 185 |
#endif |
| 186 |
GLint lines; /* number of lines to be sampled on this edge */ |
| 187 |
} EdgeT; |
| 188 |
|
| 189 |
#ifdef INTERP_Z |
| 190 |
const GLint depthBits = ctx->DrawBuffer->Visual.depthBits; |
| 191 |
const GLint fixedToDepthShift = depthBits <= 16 ? FIXED_SHIFT : 0; |
| 192 |
const GLfloat maxDepth = ctx->DrawBuffer->_DepthMaxF; |
| 193 |
#define FixedToDepth(F) ((F) >> fixedToDepthShift) |
| 194 |
#endif |
| 195 |
EdgeT eMaj, eTop, eBot; |
| 196 |
GLfloat oneOverArea; |
| 197 |
const SWvertex *vMin, *vMid, *vMax; /* Y(vMin)<=Y(vMid)<=Y(vMax) */ |
| 198 |
GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign; |
| 199 |
#if !TRIANGLE_WALK_DOUBLE |
| 200 |
const GLint snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); /* for x/y coord snapping */ |
| 201 |
#endif |
| 202 |
GLinterp vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy; |
| 203 |
|
| 204 |
struct sw_span span; |
| 205 |
|
| 206 |
INIT_SPAN(span, GL_POLYGON, 0, 0, 0); |
| 207 |
|
| 208 |
#ifdef INTERP_Z |
| 209 |
(void) fixedToDepthShift; |
| 210 |
#endif |
| 211 |
|
| 212 |
/* |
| 213 |
printf("%s()\n", __FUNCTION__); |
| 214 |
printf(" %g, %g, %g\n", v0->win[0], v0->win[1], v0->win[2]); |
| 215 |
printf(" %g, %g, %g\n", v1->win[0], v1->win[1], v1->win[2]); |
| 216 |
printf(" %g, %g, %g\n", v2->win[0], v2->win[1], v2->win[2]); |
| 217 |
*/ |
| 218 |
/* |
| 219 |
ASSERT(v0->win[2] >= 0.0); |
| 220 |
ASSERT(v1->win[2] >= 0.0); |
| 221 |
ASSERT(v2->win[2] >= 0.0); |
| 222 |
*/ |
| 223 |
/* Compute fixed point x,y coords w/ half-pixel offsets and snapping. |
| 224 |
* And find the order of the 3 vertices along the Y axis. |
| 225 |
*/ |
| 226 |
{ |
| 227 |
#if TRIANGLE_WALK_DOUBLE |
| 228 |
const GLdouble fy0 = v0->win[1] - 0.5; |
| 229 |
const GLdouble fy1 = v1->win[1] - 0.5; |
| 230 |
const GLdouble fy2 = v2->win[1] - 0.5; |
| 231 |
#else |
| 232 |
const GLfixed fy0 = FloatToFixed(v0->win[1] - 0.5F) & snapMask; |
| 233 |
const GLfixed fy1 = FloatToFixed(v1->win[1] - 0.5F) & snapMask; |
| 234 |
const GLfixed fy2 = FloatToFixed(v2->win[1] - 0.5F) & snapMask; |
| 235 |
#endif |
| 236 |
if (fy0 <= fy1) { |
| 237 |
if (fy1 <= fy2) { |
| 238 |
/* y0 <= y1 <= y2 */ |
| 239 |
vMin = v0; vMid = v1; vMax = v2; |
| 240 |
vMin_fy = fy0; vMid_fy = fy1; vMax_fy = fy2; |
| 241 |
} |
| 242 |
else if (fy2 <= fy0) { |
| 243 |
/* y2 <= y0 <= y1 */ |
| 244 |
vMin = v2; vMid = v0; vMax = v1; |
| 245 |
vMin_fy = fy2; vMid_fy = fy0; vMax_fy = fy1; |
| 246 |
} |
| 247 |
else { |
| 248 |
/* y0 <= y2 <= y1 */ |
| 249 |
vMin = v0; vMid = v2; vMax = v1; |
| 250 |
vMin_fy = fy0; vMid_fy = fy2; vMax_fy = fy1; |
| 251 |
bf = -bf; |
| 252 |
} |
| 253 |
} |
| 254 |
else { |
| 255 |
if (fy0 <= fy2) { |
| 256 |
/* y1 <= y0 <= y2 */ |
| 257 |
vMin = v1; vMid = v0; vMax = v2; |
| 258 |
vMin_fy = fy1; vMid_fy = fy0; vMax_fy = fy2; |
| 259 |
bf = -bf; |
| 260 |
} |
| 261 |
else if (fy2 <= fy1) { |
| 262 |
/* y2 <= y1 <= y0 */ |
| 263 |
vMin = v2; vMid = v1; vMax = v0; |
| 264 |
vMin_fy = fy2; vMid_fy = fy1; vMax_fy = fy0; |
| 265 |
bf = -bf; |
| 266 |
} |
| 267 |
else { |
| 268 |
/* y1 <= y2 <= y0 */ |
| 269 |
vMin = v1; vMid = v2; vMax = v0; |
| 270 |
vMin_fy = fy1; vMid_fy = fy2; vMax_fy = fy0; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
/* fixed point X coords */ |
| 275 |
#if TRIANGLE_WALK_DOUBLE |
| 276 |
vMin_fx = vMin->win[0] + 0.5; |
| 277 |
vMid_fx = vMid->win[0] + 0.5; |
| 278 |
vMax_fx = vMax->win[0] + 0.5; |
| 279 |
#else |
| 280 |
vMin_fx = FloatToFixed(vMin->win[0] + 0.5F) & snapMask; |
| 281 |
vMid_fx = FloatToFixed(vMid->win[0] + 0.5F) & snapMask; |
| 282 |
vMax_fx = FloatToFixed(vMax->win[0] + 0.5F) & snapMask; |
| 283 |
#endif |
| 284 |
} |
| 285 |
|
| 286 |
/* vertex/edge relationship */ |
| 287 |
eMaj.v0 = vMin; eMaj.v1 = vMax; /*TODO: .v1's not needed */ |
| 288 |
eTop.v0 = vMid; eTop.v1 = vMax; |
| 289 |
eBot.v0 = vMin; eBot.v1 = vMid; |
| 290 |
|
| 291 |
/* compute deltas for each edge: vertex[upper] - vertex[lower] */ |
| 292 |
#if TRIANGLE_WALK_DOUBLE |
| 293 |
eMaj.dx = vMax_fx - vMin_fx; |
| 294 |
eMaj.dy = vMax_fy - vMin_fy; |
| 295 |
eTop.dx = vMax_fx - vMid_fx; |
| 296 |
eTop.dy = vMax_fy - vMid_fy; |
| 297 |
eBot.dx = vMid_fx - vMin_fx; |
| 298 |
eBot.dy = vMid_fy - vMin_fy; |
| 299 |
#else |
| 300 |
eMaj.dx = FixedToFloat(vMax_fx - vMin_fx); |
| 301 |
eMaj.dy = FixedToFloat(vMax_fy - vMin_fy); |
| 302 |
eTop.dx = FixedToFloat(vMax_fx - vMid_fx); |
| 303 |
eTop.dy = FixedToFloat(vMax_fy - vMid_fy); |
| 304 |
eBot.dx = FixedToFloat(vMid_fx - vMin_fx); |
| 305 |
eBot.dy = FixedToFloat(vMid_fy - vMin_fy); |
| 306 |
#endif |
| 307 |
|
| 308 |
/* compute area, oneOverArea and perform backface culling */ |
| 309 |
{ |
| 310 |
#if TRIANGLE_WALK_DOUBLE |
| 311 |
const GLdouble area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; |
| 312 |
#else |
| 313 |
const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; |
| 314 |
#endif |
| 315 |
/* Do backface culling */ |
| 316 |
if (area * bf < 0.0) |
| 317 |
return; |
| 318 |
|
| 319 |
if (IS_INF_OR_NAN(area) || area == 0.0F) |
| 320 |
return; |
| 321 |
|
| 322 |
oneOverArea = 1.0F / area; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
span.facing = ctx->_Facing; /* for 2-sided stencil test */ |
| 327 |
|
| 328 |
/* Edge setup. For a triangle strip these could be reused... */ |
| 329 |
{ |
| 330 |
#if TRIANGLE_WALK_DOUBLE |
| 331 |
eMaj.fsy = CEILF(vMin_fy); |
| 332 |
eMaj.lines = (GLint) CEILF(vMax_fy - eMaj.fsy); |
| 333 |
#else |
| 334 |
eMaj.fsy = FixedCeil(vMin_fy); |
| 335 |
eMaj.lines = FixedToInt(FixedCeil(vMax_fy - eMaj.fsy)); |
| 336 |
#endif |
| 337 |
if (eMaj.lines > 0) { |
| 338 |
eMaj.dxdy = eMaj.dx / eMaj.dy; |
| 339 |
#if TRIANGLE_WALK_DOUBLE |
| 340 |
eMaj.adjy = (eMaj.fsy - vMin_fy) * FIXED_SCALE; /* SCALED! */ |
| 341 |
eMaj.fx0 = vMin_fx; |
| 342 |
eMaj.fsx = eMaj.fx0 + (eMaj.adjy * eMaj.dxdy) / (GLdouble) FIXED_SCALE; |
| 343 |
#else |
| 344 |
eMaj.fdxdy = SignedFloatToFixed(eMaj.dxdy); |
| 345 |
eMaj.adjy = (GLfloat) (eMaj.fsy - vMin_fy); /* SCALED! */ |
| 346 |
eMaj.fx0 = vMin_fx; |
| 347 |
eMaj.fsx = eMaj.fx0 + (GLfixed) (eMaj.adjy * eMaj.dxdy); |
| 348 |
#endif |
| 349 |
} |
| 350 |
else { |
| 351 |
return; /*CULLED*/ |
| 352 |
} |
| 353 |
|
| 354 |
#if TRIANGLE_WALK_DOUBLE |
| 355 |
eTop.fsy = CEILF(vMid_fy); |
| 356 |
eTop.lines = (GLint) CEILF(vMax_fy - eTop.fsy); |
| 357 |
#else |
| 358 |
eTop.fsy = FixedCeil(vMid_fy); |
| 359 |
eTop.lines = FixedToInt(FixedCeil(vMax_fy - eTop.fsy)); |
| 360 |
#endif |
| 361 |
if (eTop.lines > 0) { |
| 362 |
eTop.dxdy = eTop.dx / eTop.dy; |
| 363 |
#if TRIANGLE_WALK_DOUBLE |
| 364 |
eTop.adjy = (eTop.fsy - vMid_fy) * FIXED_SCALE; /* SCALED! */ |
| 365 |
eTop.fx0 = vMid_fx; |
| 366 |
eTop.fsx = eTop.fx0 + (eTop.adjy * eTop.dxdy) / (GLdouble) FIXED_SCALE; |
| 367 |
#else |
| 368 |
eTop.fdxdy = SignedFloatToFixed(eTop.dxdy); |
| 369 |
eTop.adjy = (GLfloat) (eTop.fsy - vMid_fy); /* SCALED! */ |
| 370 |
eTop.fx0 = vMid_fx; |
| 371 |
eTop.fsx = eTop.fx0 + (GLfixed) (eTop.adjy * eTop.dxdy); |
| 372 |
#endif |
| 373 |
} |
| 374 |
|
| 375 |
#if TRIANGLE_WALK_DOUBLE |
| 376 |
eBot.fsy = CEILF(vMin_fy); |
| 377 |
eBot.lines = (GLint) CEILF(vMid_fy - eBot.fsy); |
| 378 |
#else |
| 379 |
eBot.fsy = FixedCeil(vMin_fy); |
| 380 |
eBot.lines = FixedToInt(FixedCeil(vMid_fy - eBot.fsy)); |
| 381 |
#endif |
| 382 |
if (eBot.lines > 0) { |
| 383 |
eBot.dxdy = eBot.dx / eBot.dy; |
| 384 |
#if TRIANGLE_WALK_DOUBLE |
| 385 |
eBot.adjy = (eBot.fsy - vMin_fy) * FIXED_SCALE; /* SCALED! */ |
| 386 |
eBot.fx0 = vMin_fx; |
| 387 |
eBot.fsx = eBot.fx0 + (eBot.adjy * eBot.dxdy) / (GLdouble) FIXED_SCALE; |
| 388 |
#else |
| 389 |
eBot.fdxdy = SignedFloatToFixed(eBot.dxdy); |
| 390 |
eBot.adjy = (GLfloat) (eBot.fsy - vMin_fy); /* SCALED! */ |
| 391 |
eBot.fx0 = vMin_fx; |
| 392 |
eBot.fsx = eBot.fx0 + (GLfixed) (eBot.adjy * eBot.dxdy); |
| 393 |
#endif |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
/* |
| 398 |
* Conceptually, we view a triangle as two subtriangles |
| 399 |
* separated by a perfectly horizontal line. The edge that is |
| 400 |
* intersected by this line is one with maximal absolute dy; we |
| 401 |
* call it a ``major'' edge. The other two edges are the |
| 402 |
* ``top'' edge (for the upper subtriangle) and the ``bottom'' |
| 403 |
* edge (for the lower subtriangle). If either of these two |
| 404 |
* edges is horizontal or very close to horizontal, the |
| 405 |
* corresponding subtriangle might cover zero sample points; |
| 406 |
* we take care to handle such cases, for performance as well |
| 407 |
* as correctness. |
| 408 |
* |
| 409 |
* By stepping rasterization parameters along the major edge, |
| 410 |
* we can avoid recomputing them at the discontinuity where |
| 411 |
* the top and bottom edges meet. However, this forces us to |
| 412 |
* be able to scan both left-to-right and right-to-left. |
| 413 |
* Also, we must determine whether the major edge is at the |
| 414 |
* left or right side of the triangle. We do this by |
| 415 |
* computing the magnitude of the cross-product of the major |
| 416 |
* and top edges. Since this magnitude depends on the sine of |
| 417 |
* the angle between the two edges, its sign tells us whether |
| 418 |
* we turn to the left or to the right when travelling along |
| 419 |
* the major edge to the top edge, and from this we infer |
| 420 |
* whether the major edge is on the left or the right. |
| 421 |
* |
| 422 |
* Serendipitously, this cross-product magnitude is also a |
| 423 |
* value we need to compute the iteration parameter |
| 424 |
* derivatives for the triangle, and it can be used to perform |
| 425 |
* backface culling because its sign tells us whether the |
| 426 |
* triangle is clockwise or counterclockwise. In this code we |
| 427 |
* refer to it as ``area'' because it's also proportional to |
| 428 |
* the pixel area of the triangle. |
| 429 |
*/ |
| 430 |
|
| 431 |
{ |
| 432 |
GLint scan_from_left_to_right; /* true if scanning left-to-right */ |
| 433 |
#ifdef INTERP_INDEX |
| 434 |
GLfloat didx, didy; |
| 435 |
#endif |
| 436 |
|
| 437 |
/* |
| 438 |
* Execute user-supplied setup code |
| 439 |
*/ |
| 440 |
#ifdef SETUP_CODE |
| 441 |
SETUP_CODE |
| 442 |
#endif |
| 443 |
|
| 444 |
scan_from_left_to_right = (oneOverArea < 0.0F); |
| 445 |
|
| 446 |
|
| 447 |
/* compute d?/dx and d?/dy derivatives */ |
| 448 |
#ifdef INTERP_Z |
| 449 |
span.interpMask |= SPAN_Z; |
| 450 |
{ |
| 451 |
GLfloat eMaj_dz = vMax->win[2] - vMin->win[2]; |
| 452 |
GLfloat eBot_dz = vMid->win[2] - vMin->win[2]; |
| 453 |
span.dzdx = oneOverArea * (eMaj_dz * eBot.dy - eMaj.dy * eBot_dz); |
| 454 |
if (span.dzdx > maxDepth || span.dzdx < -maxDepth) { |
| 455 |
/* probably a sliver triangle */ |
| 456 |
span.dzdx = 0.0; |
| 457 |
span.dzdy = 0.0; |
| 458 |
} |
| 459 |
else { |
| 460 |
span.dzdy = oneOverArea * (eMaj.dx * eBot_dz - eMaj_dz * eBot.dx); |
| 461 |
} |
| 462 |
if (depthBits <= 16) |
| 463 |
span.zStep = SignedFloatToFixed(span.dzdx); |
| 464 |
else |
| 465 |
span.zStep = (GLint) span.dzdx; |
| 466 |
} |
| 467 |
#endif |
| 468 |
#ifdef INTERP_W |
| 469 |
span.interpMask |= SPAN_W; |
| 470 |
{ |
| 471 |
const GLfloat eMaj_dw = vMax->win[3] - vMin->win[3]; |
| 472 |
const GLfloat eBot_dw = vMid->win[3] - vMin->win[3]; |
| 473 |
span.dwdx = oneOverArea * (eMaj_dw * eBot.dy - eMaj.dy * eBot_dw); |
| 474 |
span.dwdy = oneOverArea * (eMaj.dx * eBot_dw - eMaj_dw * eBot.dx); |
| 475 |
} |
| 476 |
#endif |
| 477 |
#ifdef INTERP_FOG |
| 478 |
span.interpMask |= SPAN_FOG; |
| 479 |
{ |
| 480 |
# ifdef INTERP_W |
| 481 |
const GLfloat wMax = vMax->win[3], wMin = vMin->win[3], wMid = vMid->win[3]; |
| 482 |
const GLfloat eMaj_dfog = vMax->fog * wMax - vMin->fog * wMin; |
| 483 |
const GLfloat eBot_dfog = vMid->fog * wMid - vMin->fog * wMin; |
| 484 |
# else |
| 485 |
const GLfloat eMaj_dfog = vMax->fog - vMin->fog; |
| 486 |
const GLfloat eBot_dfog = vMid->fog - vMin->fog; |
| 487 |
# endif |
| 488 |
span.dfogdx = oneOverArea * (eMaj_dfog * eBot.dy - eMaj.dy * eBot_dfog); |
| 489 |
span.dfogdy = oneOverArea * (eMaj.dx * eBot_dfog - eMaj_dfog * eBot.dx); |
| 490 |
span.fogStep = span.dfogdx; |
| 491 |
} |
| 492 |
#endif |
| 493 |
#ifdef INTERP_RGB |
| 494 |
span.interpMask |= SPAN_RGBA; |
| 495 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 496 |
GLfloat eMaj_dr = (GLfloat) ((ColorTemp) vMax->color[RCOMP] - (ColorTemp) vMin->color[RCOMP]); |
| 497 |
GLfloat eBot_dr = (GLfloat) ((ColorTemp) vMid->color[RCOMP] - (ColorTemp) vMin->color[RCOMP]); |
| 498 |
GLfloat eMaj_dg = (GLfloat) ((ColorTemp) vMax->color[GCOMP] - (ColorTemp) vMin->color[GCOMP]); |
| 499 |
GLfloat eBot_dg = (GLfloat) ((ColorTemp) vMid->color[GCOMP] - (ColorTemp) vMin->color[GCOMP]); |
| 500 |
GLfloat eMaj_db = (GLfloat) ((ColorTemp) vMax->color[BCOMP] - (ColorTemp) vMin->color[BCOMP]); |
| 501 |
GLfloat eBot_db = (GLfloat) ((ColorTemp) vMid->color[BCOMP] - (ColorTemp) vMin->color[BCOMP]); |
| 502 |
# ifdef INTERP_ALPHA |
| 503 |
GLfloat eMaj_da = (GLfloat) ((ColorTemp) vMax->color[ACOMP] - (ColorTemp) vMin->color[ACOMP]); |
| 504 |
GLfloat eBot_da = (GLfloat) ((ColorTemp) vMid->color[ACOMP] - (ColorTemp) vMin->color[ACOMP]); |
| 505 |
# endif |
| 506 |
span.drdx = oneOverArea * (eMaj_dr * eBot.dy - eMaj.dy * eBot_dr); |
| 507 |
span.drdy = oneOverArea * (eMaj.dx * eBot_dr - eMaj_dr * eBot.dx); |
| 508 |
span.dgdx = oneOverArea * (eMaj_dg * eBot.dy - eMaj.dy * eBot_dg); |
| 509 |
span.dgdy = oneOverArea * (eMaj.dx * eBot_dg - eMaj_dg * eBot.dx); |
| 510 |
span.dbdx = oneOverArea * (eMaj_db * eBot.dy - eMaj.dy * eBot_db); |
| 511 |
span.dbdy = oneOverArea * (eMaj.dx * eBot_db - eMaj_db * eBot.dx); |
| 512 |
# if CHAN_TYPE == GL_FLOAT |
| 513 |
span.redStep = span.drdx; |
| 514 |
span.greenStep = span.dgdx; |
| 515 |
span.blueStep = span.dbdx; |
| 516 |
# else |
| 517 |
span.redStep = SignedFloatToFixed(span.drdx); |
| 518 |
span.greenStep = SignedFloatToFixed(span.dgdx); |
| 519 |
span.blueStep = SignedFloatToFixed(span.dbdx); |
| 520 |
# endif /* GL_FLOAT */ |
| 521 |
# ifdef INTERP_ALPHA |
| 522 |
span.dadx = oneOverArea * (eMaj_da * eBot.dy - eMaj.dy * eBot_da); |
| 523 |
span.dady = oneOverArea * (eMaj.dx * eBot_da - eMaj_da * eBot.dx); |
| 524 |
# if CHAN_TYPE == GL_FLOAT |
| 525 |
span.alphaStep = span.dadx; |
| 526 |
# else |
| 527 |
span.alphaStep = SignedFloatToFixed(span.dadx); |
| 528 |
# endif /* GL_FLOAT */ |
| 529 |
# endif /* INTERP_ALPHA */ |
| 530 |
} |
| 531 |
else { |
| 532 |
ASSERT(ctx->Light.ShadeModel == GL_FLAT); |
| 533 |
span.interpMask |= SPAN_FLAT; |
| 534 |
span.drdx = span.drdy = 0.0F; |
| 535 |
span.dgdx = span.dgdy = 0.0F; |
| 536 |
span.dbdx = span.dbdy = 0.0F; |
| 537 |
# if CHAN_TYPE == GL_FLOAT |
| 538 |
span.redStep = 0.0F; |
| 539 |
span.greenStep = 0.0F; |
| 540 |
span.blueStep = 0.0F; |
| 541 |
# else |
| 542 |
span.redStep = 0; |
| 543 |
span.greenStep = 0; |
| 544 |
span.blueStep = 0; |
| 545 |
# endif /* GL_FLOAT */ |
| 546 |
# ifdef INTERP_ALPHA |
| 547 |
span.dadx = span.dady = 0.0F; |
| 548 |
# if CHAN_TYPE == GL_FLOAT |
| 549 |
span.alphaStep = 0.0F; |
| 550 |
# else |
| 551 |
span.alphaStep = 0; |
| 552 |
# endif /* GL_FLOAT */ |
| 553 |
# endif |
| 554 |
} |
| 555 |
#endif /* INTERP_RGB */ |
| 556 |
#ifdef INTERP_SPEC |
| 557 |
span.interpMask |= SPAN_SPEC; |
| 558 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 559 |
GLfloat eMaj_dsr = (GLfloat) ((ColorTemp) vMax->specular[RCOMP] - (ColorTemp) vMin->specular[RCOMP]); |
| 560 |
GLfloat eBot_dsr = (GLfloat) ((ColorTemp) vMid->specular[RCOMP] - (ColorTemp) vMin->specular[RCOMP]); |
| 561 |
GLfloat eMaj_dsg = (GLfloat) ((ColorTemp) vMax->specular[GCOMP] - (ColorTemp) vMin->specular[GCOMP]); |
| 562 |
GLfloat eBot_dsg = (GLfloat) ((ColorTemp) vMid->specular[GCOMP] - (ColorTemp) vMin->specular[GCOMP]); |
| 563 |
GLfloat eMaj_dsb = (GLfloat) ((ColorTemp) vMax->specular[BCOMP] - (ColorTemp) vMin->specular[BCOMP]); |
| 564 |
GLfloat eBot_dsb = (GLfloat) ((ColorTemp) vMid->specular[BCOMP] - (ColorTemp) vMin->specular[BCOMP]); |
| 565 |
span.dsrdx = oneOverArea * (eMaj_dsr * eBot.dy - eMaj.dy * eBot_dsr); |
| 566 |
span.dsrdy = oneOverArea * (eMaj.dx * eBot_dsr - eMaj_dsr * eBot.dx); |
| 567 |
span.dsgdx = oneOverArea * (eMaj_dsg * eBot.dy - eMaj.dy * eBot_dsg); |
| 568 |
span.dsgdy = oneOverArea * (eMaj.dx * eBot_dsg - eMaj_dsg * eBot.dx); |
| 569 |
span.dsbdx = oneOverArea * (eMaj_dsb * eBot.dy - eMaj.dy * eBot_dsb); |
| 570 |
span.dsbdy = oneOverArea * (eMaj.dx * eBot_dsb - eMaj_dsb * eBot.dx); |
| 571 |
# if CHAN_TYPE == GL_FLOAT |
| 572 |
span.specRedStep = span.dsrdx; |
| 573 |
span.specGreenStep = span.dsgdx; |
| 574 |
span.specBlueStep = span.dsbdx; |
| 575 |
# else |
| 576 |
span.specRedStep = SignedFloatToFixed(span.dsrdx); |
| 577 |
span.specGreenStep = SignedFloatToFixed(span.dsgdx); |
| 578 |
span.specBlueStep = SignedFloatToFixed(span.dsbdx); |
| 579 |
# endif |
| 580 |
} |
| 581 |
else { |
| 582 |
span.dsrdx = span.dsrdy = 0.0F; |
| 583 |
span.dsgdx = span.dsgdy = 0.0F; |
| 584 |
span.dsbdx = span.dsbdy = 0.0F; |
| 585 |
# if CHAN_TYPE == GL_FLOAT |
| 586 |
span.specRedStep = 0.0F; |
| 587 |
span.specGreenStep = 0.0F; |
| 588 |
span.specBlueStep = 0.0F; |
| 589 |
# else |
| 590 |
span.specRedStep = 0; |
| 591 |
span.specGreenStep = 0; |
| 592 |
span.specBlueStep = 0; |
| 593 |
# endif |
| 594 |
} |
| 595 |
#endif /* INTERP_SPEC */ |
| 596 |
#ifdef INTERP_INDEX |
| 597 |
span.interpMask |= SPAN_INDEX; |
| 598 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 599 |
GLfloat eMaj_di = vMax->index - vMin->index; |
| 600 |
GLfloat eBot_di = vMid->index - vMin->index; |
| 601 |
didx = oneOverArea * (eMaj_di * eBot.dy - eMaj.dy * eBot_di); |
| 602 |
didy = oneOverArea * (eMaj.dx * eBot_di - eMaj_di * eBot.dx); |
| 603 |
span.indexStep = SignedFloatToFixed(didx); |
| 604 |
} |
| 605 |
else { |
| 606 |
span.interpMask |= SPAN_FLAT; |
| 607 |
didx = didy = 0.0F; |
| 608 |
span.indexStep = 0; |
| 609 |
} |
| 610 |
#endif |
| 611 |
#ifdef INTERP_INT_TEX |
| 612 |
span.interpMask |= SPAN_INT_TEXTURE; |
| 613 |
{ |
| 614 |
GLfloat eMaj_ds = (vMax->texcoord[0][0] - vMin->texcoord[0][0]) * S_SCALE; |
| 615 |
GLfloat eBot_ds = (vMid->texcoord[0][0] - vMin->texcoord[0][0]) * S_SCALE; |
| 616 |
GLfloat eMaj_dt = (vMax->texcoord[0][1] - vMin->texcoord[0][1]) * T_SCALE; |
| 617 |
GLfloat eBot_dt = (vMid->texcoord[0][1] - vMin->texcoord[0][1]) * T_SCALE; |
| 618 |
span.texStepX[0][0] = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); |
| 619 |
span.texStepY[0][0] = oneOverArea * (eMaj.dx * eBot_ds - eMaj_ds * eBot.dx); |
| 620 |
span.texStepX[0][1] = oneOverArea * (eMaj_dt * eBot.dy - eMaj.dy * eBot_dt); |
| 621 |
span.texStepY[0][1] = oneOverArea * (eMaj.dx * eBot_dt - eMaj_dt * eBot.dx); |
| 622 |
span.intTexStep[0] = SignedFloatToFixed(span.texStepX[0][0]); |
| 623 |
span.intTexStep[1] = SignedFloatToFixed(span.texStepX[0][1]); |
| 624 |
} |
| 625 |
#endif |
| 626 |
#ifdef INTERP_TEX |
| 627 |
span.interpMask |= SPAN_TEXTURE; |
| 628 |
{ |
| 629 |
/* win[3] is 1/W */ |
| 630 |
const GLfloat wMax = vMax->win[3], wMin = vMin->win[3], wMid = vMid->win[3]; |
| 631 |
TEX_UNIT_LOOP( |
| 632 |
GLfloat eMaj_ds = vMax->texcoord[u][0] * wMax - vMin->texcoord[u][0] * wMin; |
| 633 |
GLfloat eBot_ds = vMid->texcoord[u][0] * wMid - vMin->texcoord[u][0] * wMin; |
| 634 |
GLfloat eMaj_dt = vMax->texcoord[u][1] * wMax - vMin->texcoord[u][1] * wMin; |
| 635 |
GLfloat eBot_dt = vMid->texcoord[u][1] * wMid - vMin->texcoord[u][1] * wMin; |
| 636 |
GLfloat eMaj_du = vMax->texcoord[u][2] * wMax - vMin->texcoord[u][2] * wMin; |
| 637 |
GLfloat eBot_du = vMid->texcoord[u][2] * wMid - vMin->texcoord[u][2] * wMin; |
| 638 |
GLfloat eMaj_dv = vMax->texcoord[u][3] * wMax - vMin->texcoord[u][3] * wMin; |
| 639 |
GLfloat eBot_dv = vMid->texcoord[u][3] * wMid - vMin->texcoord[u][3] * wMin; |
| 640 |
span.texStepX[u][0] = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); |
| 641 |
span.texStepY[u][0] = oneOverArea * (eMaj.dx * eBot_ds - eMaj_ds * eBot.dx); |
| 642 |
span.texStepX[u][1] = oneOverArea * (eMaj_dt * eBot.dy - eMaj.dy * eBot_dt); |
| 643 |
span.texStepY[u][1] = oneOverArea * (eMaj.dx * eBot_dt - eMaj_dt * eBot.dx); |
| 644 |
span.texStepX[u][2] = oneOverArea * (eMaj_du * eBot.dy - eMaj.dy * eBot_du); |
| 645 |
span.texStepY[u][2] = oneOverArea * (eMaj.dx * eBot_du - eMaj_du * eBot.dx); |
| 646 |
span.texStepX[u][3] = oneOverArea * (eMaj_dv * eBot.dy - eMaj.dy * eBot_dv); |
| 647 |
span.texStepY[u][3] = oneOverArea * (eMaj.dx * eBot_dv - eMaj_dv * eBot.dx); |
| 648 |
) |
| 649 |
} |
| 650 |
#endif |
| 651 |
|
| 652 |
/* |
| 653 |
* We always sample at pixel centers. However, we avoid |
| 654 |
* explicit half-pixel offsets in this code by incorporating |
| 655 |
* the proper offset in each of x and y during the |
| 656 |
* transformation to window coordinates. |
| 657 |
* |
| 658 |
* We also apply the usual rasterization rules to prevent |
| 659 |
* cracks and overlaps. A pixel is considered inside a |
| 660 |
* subtriangle if it meets all of four conditions: it is on or |
| 661 |
* to the right of the left edge, strictly to the left of the |
| 662 |
* right edge, on or below the top edge, and strictly above |
| 663 |
* the bottom edge. (Some edges may be degenerate.) |
| 664 |
* |
| 665 |
* The following discussion assumes left-to-right scanning |
| 666 |
* (that is, the major edge is on the left); the right-to-left |
| 667 |
* case is a straightforward variation. |
| 668 |
* |
| 669 |
* We start by finding the half-integral y coordinate that is |
| 670 |
* at or below the top of the triangle. This gives us the |
| 671 |
* first scan line that could possibly contain pixels that are |
| 672 |
* inside the triangle. |
| 673 |
* |
| 674 |
* Next we creep down the major edge until we reach that y, |
| 675 |
* and compute the corresponding x coordinate on the edge. |
| 676 |
* Then we find the half-integral x that lies on or just |
| 677 |
* inside the edge. This is the first pixel that might lie in |
| 678 |
* the interior of the triangle. (We won't know for sure |
| 679 |
* until we check the other edges.) |
| 680 |
* |
| 681 |
* As we rasterize the triangle, we'll step down the major |
| 682 |
* edge. For each step in y, we'll move an integer number |
| 683 |
* of steps in x. There are two possible x step sizes, which |
| 684 |
* we'll call the ``inner'' step (guaranteed to land on the |
| 685 |
* edge or inside it) and the ``outer'' step (guaranteed to |
| 686 |
* land on the edge or outside it). The inner and outer steps |
| 687 |
* differ by one. During rasterization we maintain an error |
| 688 |
* term that indicates our distance from the true edge, and |
| 689 |
* select either the inner step or the outer step, whichever |
| 690 |
* gets us to the first pixel that falls inside the triangle. |
| 691 |
* |
| 692 |
* All parameters (z, red, etc.) as well as the buffer |
| 693 |
* addresses for color and z have inner and outer step values, |
| 694 |
* so that we can increment them appropriately. This method |
| 695 |
* eliminates the need to adjust parameters by creeping a |
| 696 |
* sub-pixel amount into the triangle at each scanline. |
| 697 |
*/ |
| 698 |
|
| 699 |
{ |
| 700 |
GLint subTriangle; |
| 701 |
GLinterp fxLeftEdge = 0, fxRightEdge = 0; |
| 702 |
GLinterp fdxLeftEdge = 0, fdxRightEdge = 0; |
| 703 |
GLinterp fError = 0, fdError = 0; |
| 704 |
#ifdef PIXEL_ADDRESS |
| 705 |
PIXEL_TYPE *pRow = NULL; |
| 706 |
GLint dPRowOuter = 0, dPRowInner; /* offset in bytes */ |
| 707 |
#endif |
| 708 |
#ifdef INTERP_Z |
| 709 |
# ifdef DEPTH_TYPE |
| 710 |
struct gl_renderbuffer *zrb |
| 711 |
= ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; |
| 712 |
DEPTH_TYPE *zRow = NULL; |
| 713 |
GLint dZRowOuter = 0, dZRowInner; /* offset in bytes */ |
| 714 |
# endif |
| 715 |
GLfixed zLeft = 0, fdzOuter = 0, fdzInner; |
| 716 |
#endif |
| 717 |
#ifdef INTERP_W |
| 718 |
GLfloat wLeft = 0, dwOuter = 0, dwInner; |
| 719 |
#endif |
| 720 |
#ifdef INTERP_FOG |
| 721 |
GLfloat fogLeft = 0, dfogOuter = 0, dfogInner; |
| 722 |
#endif |
| 723 |
#ifdef INTERP_RGB |
| 724 |
ColorTemp rLeft = 0, fdrOuter = 0, fdrInner; |
| 725 |
ColorTemp gLeft = 0, fdgOuter = 0, fdgInner; |
| 726 |
ColorTemp bLeft = 0, fdbOuter = 0, fdbInner; |
| 727 |
#endif |
| 728 |
#ifdef INTERP_ALPHA |
| 729 |
ColorTemp aLeft = 0, fdaOuter = 0, fdaInner; |
| 730 |
#endif |
| 731 |
#ifdef INTERP_SPEC |
| 732 |
ColorTemp srLeft=0, dsrOuter=0, dsrInner; |
| 733 |
ColorTemp sgLeft=0, dsgOuter=0, dsgInner; |
| 734 |
ColorTemp sbLeft=0, dsbOuter=0, dsbInner; |
| 735 |
#endif |
| 736 |
#ifdef INTERP_INDEX |
| 737 |
GLfixed iLeft=0, diOuter=0, diInner; |
| 738 |
#endif |
| 739 |
#ifdef INTERP_INT_TEX |
| 740 |
GLfixed sLeft=0, dsOuter=0, dsInner; |
| 741 |
GLfixed tLeft=0, dtOuter=0, dtInner; |
| 742 |
#endif |
| 743 |
#ifdef INTERP_TEX |
| 744 |
GLfloat sLeft[MAX_TEXTURE_COORD_UNITS]; |
| 745 |
GLfloat tLeft[MAX_TEXTURE_COORD_UNITS]; |
| 746 |
GLfloat uLeft[MAX_TEXTURE_COORD_UNITS]; |
| 747 |
GLfloat vLeft[MAX_TEXTURE_COORD_UNITS]; |
| 748 |
GLfloat dsOuter[MAX_TEXTURE_COORD_UNITS], dsInner[MAX_TEXTURE_COORD_UNITS]; |
| 749 |
GLfloat dtOuter[MAX_TEXTURE_COORD_UNITS], dtInner[MAX_TEXTURE_COORD_UNITS]; |
| 750 |
GLfloat duOuter[MAX_TEXTURE_COORD_UNITS], duInner[MAX_TEXTURE_COORD_UNITS]; |
| 751 |
GLfloat dvOuter[MAX_TEXTURE_COORD_UNITS], dvInner[MAX_TEXTURE_COORD_UNITS]; |
| 752 |
#endif |
| 753 |
|
| 754 |
for (subTriangle=0; subTriangle<=1; subTriangle++) { |
| 755 |
EdgeT *eLeft, *eRight; |
| 756 |
int setupLeft, setupRight; |
| 757 |
int lines; |
| 758 |
|
| 759 |
if (subTriangle==0) { |
| 760 |
/* bottom half */ |
| 761 |
if (scan_from_left_to_right) { |
| 762 |
eLeft = &eMaj; |
| 763 |
eRight = &eBot; |
| 764 |
lines = eRight->lines; |
| 765 |
setupLeft = 1; |
| 766 |
setupRight = 1; |
| 767 |
} |
| 768 |
else { |
| 769 |
eLeft = &eBot; |
| 770 |
eRight = &eMaj; |
| 771 |
lines = eLeft->lines; |
| 772 |
setupLeft = 1; |
| 773 |
setupRight = 1; |
| 774 |
} |
| 775 |
} |
| 776 |
else { |
| 777 |
/* top half */ |
| 778 |
if (scan_from_left_to_right) { |
| 779 |
eLeft = &eMaj; |
| 780 |
eRight = &eTop; |
| 781 |
lines = eRight->lines; |
| 782 |
setupLeft = 0; |
| 783 |
setupRight = 1; |
| 784 |
} |
| 785 |
else { |
| 786 |
eLeft = &eTop; |
| 787 |
eRight = &eMaj; |
| 788 |
lines = eLeft->lines; |
| 789 |
setupLeft = 1; |
| 790 |
setupRight = 0; |
| 791 |
} |
| 792 |
if (lines == 0) |
| 793 |
return; |
| 794 |
} |
| 795 |
|
| 796 |
if (setupLeft && eLeft->lines > 0) { |
| 797 |
const SWvertex *vLower = eLeft->v0; |
| 798 |
#if TRIANGLE_WALK_DOUBLE |
| 799 |
const GLdouble fsy = eLeft->fsy; |
| 800 |
const GLdouble fsx = eLeft->fsx; |
| 801 |
const GLdouble fx = CEILF(fsx); |
| 802 |
const GLdouble adjx = (fx - eLeft->fx0) * FIXED_SCALE; /* SCALED! */ |
| 803 |
#else |
| 804 |
const GLfixed fsy = eLeft->fsy; |
| 805 |
const GLfixed fsx = eLeft->fsx; /* no fractional part */ |
| 806 |
const GLfixed fx = FixedCeil(fsx); /* no fractional part */ |
| 807 |
const GLfixed adjx = (GLinterp) (fx - eLeft->fx0); /* SCALED! */ |
| 808 |
#endif |
| 809 |
const GLinterp adjy = (GLinterp) eLeft->adjy; /* SCALED! */ |
| 810 |
GLint idxOuter; |
| 811 |
#if TRIANGLE_WALK_DOUBLE |
| 812 |
GLdouble dxOuter; |
| 813 |
|
| 814 |
fError = fx - fsx - 1.0; |
| 815 |
fxLeftEdge = fsx; |
| 816 |
fdxLeftEdge = eLeft->dxdy; |
| 817 |
dxOuter = FLOORF(fdxLeftEdge); |
| 818 |
fdError = dxOuter - fdxLeftEdge + 1.0; |
| 819 |
idxOuter = (GLint) dxOuter; |
| 820 |
span.y = (GLint) fsy; |
| 821 |
#else |
| 822 |
GLfloat dxOuter; |
| 823 |
GLfixed fdxOuter; |
| 824 |
|
| 825 |
fError = fx - fsx - FIXED_ONE; |
| 826 |
fxLeftEdge = fsx - FIXED_EPSILON; |
| 827 |
fdxLeftEdge = eLeft->fdxdy; |
| 828 |
fdxOuter = FixedFloor(fdxLeftEdge - FIXED_EPSILON); |
| 829 |
fdError = fdxOuter - fdxLeftEdge + FIXED_ONE; |
| 830 |
idxOuter = FixedToInt(fdxOuter); |
| 831 |
dxOuter = (GLfloat) idxOuter; |
| 832 |
span.y = FixedToInt(fsy); |
| 833 |
#endif |
| 834 |
|
| 835 |
/* silence warnings on some compilers */ |
| 836 |
(void) dxOuter; |
| 837 |
(void) adjx; |
| 838 |
(void) adjy; |
| 839 |
(void) vLower; |
| 840 |
|
| 841 |
#ifdef PIXEL_ADDRESS |
| 842 |
{ |
| 843 |
pRow = (PIXEL_TYPE *) PIXEL_ADDRESS(InterpToInt(fxLeftEdge), span.y); |
| 844 |
dPRowOuter = -((int)BYTES_PER_ROW) + idxOuter * sizeof(PIXEL_TYPE); |
| 845 |
/* negative because Y=0 at bottom and increases upward */ |
| 846 |
} |
| 847 |
#endif |
| 848 |
/* |
| 849 |
* Now we need the set of parameter (z, color, etc.) values at |
| 850 |
* the point (fx, fsy). This gives us properly-sampled parameter |
| 851 |
* values that we can step from pixel to pixel. Furthermore, |
| 852 |
* although we might have intermediate results that overflow |
| 853 |
* the normal parameter range when we step temporarily outside |
| 854 |
* the triangle, we shouldn't overflow or underflow for any |
| 855 |
* pixel that's actually inside the triangle. |
| 856 |
*/ |
| 857 |
|
| 858 |
#ifdef INTERP_Z |
| 859 |
{ |
| 860 |
GLfloat z0 = vLower->win[2]; |
| 861 |
if (depthBits <= 16) { |
| 862 |
/* interpolate fixed-pt values */ |
| 863 |
GLfloat tmp = (z0 * FIXED_SCALE + span.dzdx * adjx + span.dzdy * adjy) + FIXED_HALF; |
| 864 |
if (tmp < MAX_GLUINT / 2) |
| 865 |
zLeft = (GLfixed) tmp; |
| 866 |
else |
| 867 |
zLeft = MAX_GLUINT / 2; |
| 868 |
fdzOuter = SignedFloatToFixed(span.dzdy + dxOuter * span.dzdx); |
| 869 |
} |
| 870 |
else { |
| 871 |
/* interpolate depth values exactly */ |
| 872 |
zLeft = (GLint) (z0 + span.dzdx * FixedToFloat(adjx) + span.dzdy * FixedToFloat(adjy)); |
| 873 |
fdzOuter = (GLint) (span.dzdy + dxOuter * span.dzdx); |
| 874 |
} |
| 875 |
# ifdef DEPTH_TYPE |
| 876 |
zRow = (DEPTH_TYPE *) |
| 877 |
zrb->GetPointer(ctx, zrb, InterpToInt(fxLeftEdge), span.y); |
| 878 |
dZRowOuter = (ctx->DrawBuffer->Width + idxOuter) * sizeof(DEPTH_TYPE); |
| 879 |
# endif |
| 880 |
} |
| 881 |
#endif |
| 882 |
#ifdef INTERP_W |
| 883 |
wLeft = vLower->win[3] + (span.dwdx * adjx + span.dwdy * adjy) * (1.0F/FIXED_SCALE); |
| 884 |
dwOuter = span.dwdy + dxOuter * span.dwdx; |
| 885 |
#endif |
| 886 |
#ifdef INTERP_FOG |
| 887 |
# ifdef INTERP_W |
| 888 |
fogLeft = vLower->fog * vLower->win[3] + (span.dfogdx * adjx + span.dfogdy * adjy) * (1.0F/FIXED_SCALE); |
| 889 |
# else |
| 890 |
fogLeft = vLower->fog + (span.dfogdx * adjx + span.dfogdy * adjy) * (1.0F/FIXED_SCALE); |
| 891 |
# endif |
| 892 |
dfogOuter = span.dfogdy + dxOuter * span.dfogdx; |
| 893 |
#endif |
| 894 |
#ifdef INTERP_RGB |
| 895 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 896 |
# if CHAN_TYPE == GL_FLOAT |
| 897 |
rLeft = vLower->color[RCOMP] + (span.drdx * adjx + span.drdy * adjy) * (1.0F / FIXED_SCALE); |
| 898 |
gLeft = vLower->color[GCOMP] + (span.dgdx * adjx + span.dgdy * adjy) * (1.0F / FIXED_SCALE); |
| 899 |
bLeft = vLower->color[BCOMP] + (span.dbdx * adjx + span.dbdy * adjy) * (1.0F / FIXED_SCALE); |
| 900 |
fdrOuter = span.drdy + dxOuter * span.drdx; |
| 901 |
fdgOuter = span.dgdy + dxOuter * span.dgdx; |
| 902 |
fdbOuter = span.dbdy + dxOuter * span.dbdx; |
| 903 |
# else |
| 904 |
rLeft = (GLint)(ChanToFixed(vLower->color[RCOMP]) + span.drdx * adjx + span.drdy * adjy) + FIXED_HALF; |
| 905 |
gLeft = (GLint)(ChanToFixed(vLower->color[GCOMP]) + span.dgdx * adjx + span.dgdy * adjy) + FIXED_HALF; |
| 906 |
bLeft = (GLint)(ChanToFixed(vLower->color[BCOMP]) + span.dbdx * adjx + span.dbdy * adjy) + FIXED_HALF; |
| 907 |
fdrOuter = SignedFloatToFixed(span.drdy + dxOuter * span.drdx); |
| 908 |
fdgOuter = SignedFloatToFixed(span.dgdy + dxOuter * span.dgdx); |
| 909 |
fdbOuter = SignedFloatToFixed(span.dbdy + dxOuter * span.dbdx); |
| 910 |
# endif |
| 911 |
# ifdef INTERP_ALPHA |
| 912 |
# if CHAN_TYPE == GL_FLOAT |
| 913 |
aLeft = vLower->color[ACOMP] + (span.dadx * adjx + span.dady * adjy) * (1.0F / FIXED_SCALE); |
| 914 |
fdaOuter = span.dady + dxOuter * span.dadx; |
| 915 |
# else |
| 916 |
aLeft = (GLint)(ChanToFixed(vLower->color[ACOMP]) + span.dadx * adjx + span.dady * adjy) + FIXED_HALF; |
| 917 |
fdaOuter = SignedFloatToFixed(span.dady + dxOuter * span.dadx); |
| 918 |
# endif |
| 919 |
# endif |
| 920 |
} |
| 921 |
else { |
| 922 |
ASSERT(ctx->Light.ShadeModel == GL_FLAT); |
| 923 |
# if CHAN_TYPE == GL_FLOAT |
| 924 |
rLeft = v2->color[RCOMP]; |
| 925 |
gLeft = v2->color[GCOMP]; |
| 926 |
bLeft = v2->color[BCOMP]; |
| 927 |
fdrOuter = fdgOuter = fdbOuter = 0.0F; |
| 928 |
# else |
| 929 |
rLeft = ChanToFixed(v2->color[RCOMP]); |
| 930 |
gLeft = ChanToFixed(v2->color[GCOMP]); |
| 931 |
bLeft = ChanToFixed(v2->color[BCOMP]); |
| 932 |
fdrOuter = fdgOuter = fdbOuter = 0; |
| 933 |
# endif |
| 934 |
# ifdef INTERP_ALPHA |
| 935 |
# if CHAN_TYPE == GL_FLOAT |
| 936 |
aLeft = v2->color[ACOMP]; |
| 937 |
fdaOuter = 0.0F; |
| 938 |
# else |
| 939 |
aLeft = ChanToFixed(v2->color[ACOMP]); |
| 940 |
fdaOuter = 0; |
| 941 |
# endif |
| 942 |
# endif |
| 943 |
} |
| 944 |
#endif /* INTERP_RGB */ |
| 945 |
|
| 946 |
|
| 947 |
#ifdef INTERP_SPEC |
| 948 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 949 |
# if CHAN_TYPE == GL_FLOAT |
| 950 |
srLeft = vLower->specular[RCOMP] + (span.dsrdx * adjx + span.dsrdy * adjy) * (1.0F / FIXED_SCALE); |
| 951 |
sgLeft = vLower->specular[GCOMP] + (span.dsgdx * adjx + span.dsgdy * adjy) * (1.0F / FIXED_SCALE); |
| 952 |
sbLeft = vLower->specular[BCOMP] + (span.dsbdx * adjx + span.dsbdy * adjy) * (1.0F / FIXED_SCALE); |
| 953 |
dsrOuter = span.dsrdy + dxOuter * span.dsrdx; |
| 954 |
dsgOuter = span.dsgdy + dxOuter * span.dsgdx; |
| 955 |
dsbOuter = span.dsbdy + dxOuter * span.dsbdx; |
| 956 |
# else |
| 957 |
srLeft = (GLfixed) (ChanToFixed(vLower->specular[RCOMP]) + span.dsrdx * adjx + span.dsrdy * adjy) + FIXED_HALF; |
| 958 |
sgLeft = (GLfixed) (ChanToFixed(vLower->specular[GCOMP]) + span.dsgdx * adjx + span.dsgdy * adjy) + FIXED_HALF; |
| 959 |
sbLeft = (GLfixed) (ChanToFixed(vLower->specular[BCOMP]) + span.dsbdx * adjx + span.dsbdy * adjy) + FIXED_HALF; |
| 960 |
dsrOuter = SignedFloatToFixed(span.dsrdy + dxOuter * span.dsrdx); |
| 961 |
dsgOuter = SignedFloatToFixed(span.dsgdy + dxOuter * span.dsgdx); |
| 962 |
dsbOuter = SignedFloatToFixed(span.dsbdy + dxOuter * span.dsbdx); |
| 963 |
# endif |
| 964 |
} |
| 965 |
else { |
| 966 |
ASSERT(ctx->Light.ShadeModel == GL_FLAT); |
| 967 |
#if CHAN_TYPE == GL_FLOAT |
| 968 |
srLeft = v2->specular[RCOMP]; |
| 969 |
sgLeft = v2->specular[GCOMP]; |
| 970 |
sbLeft = v2->specular[BCOMP]; |
| 971 |
dsrOuter = dsgOuter = dsbOuter = 0.0F; |
| 972 |
# else |
| 973 |
srLeft = ChanToFixed(v2->specular[RCOMP]); |
| 974 |
sgLeft = ChanToFixed(v2->specular[GCOMP]); |
| 975 |
sbLeft = ChanToFixed(v2->specular[BCOMP]); |
| 976 |
dsrOuter = dsgOuter = dsbOuter = 0; |
| 977 |
# endif |
| 978 |
} |
| 979 |
#endif |
| 980 |
|
| 981 |
#ifdef INTERP_INDEX |
| 982 |
if (ctx->Light.ShadeModel == GL_SMOOTH) { |
| 983 |
iLeft = (GLfixed)(vLower->index * FIXED_SCALE |
| 984 |
+ didx * adjx + didy * adjy) + FIXED_HALF; |
| 985 |
diOuter = SignedFloatToFixed(didy + dxOuter * didx); |
| 986 |
} |
| 987 |
else { |
| 988 |
ASSERT(ctx->Light.ShadeModel == GL_FLAT); |
| 989 |
iLeft = FloatToFixed(v2->index); |
| 990 |
diOuter = 0; |
| 991 |
} |
| 992 |
#endif |
| 993 |
#ifdef INTERP_INT_TEX |
| 994 |
{ |
| 995 |
GLfloat s0, t0; |
| 996 |
s0 = vLower->texcoord[0][0] * S_SCALE; |
| 997 |
sLeft = (GLfixed)(s0 * FIXED_SCALE + span.texStepX[0][0] * adjx |
| 998 |
+ span.texStepY[0][0] * adjy) + FIXED_HALF; |
| 999 |
dsOuter = SignedFloatToFixed(span.texStepY[0][0] + dxOuter * span.texStepX[0][0]); |
| 1000 |
|
| 1001 |
t0 = vLower->texcoord[0][1] * T_SCALE; |
| 1002 |
tLeft = (GLfixed)(t0 * FIXED_SCALE + span.texStepX[0][1] * adjx |
| 1003 |
+ span.texStepY[0][1] * adjy) + FIXED_HALF; |
| 1004 |
dtOuter = SignedFloatToFixed(span.texStepY[0][1] + dxOuter * span.texStepX[0][1]); |
| 1005 |
} |
| 1006 |
#endif |
| 1007 |
#ifdef INTERP_TEX |
| 1008 |
TEX_UNIT_LOOP( |
| 1009 |
const GLfloat invW = vLower->win[3]; |
| 1010 |
const GLfloat s0 = vLower->texcoord[u][0] * invW; |
| 1011 |
const GLfloat t0 = vLower->texcoord[u][1] * invW; |
| 1012 |
const GLfloat u0 = vLower->texcoord[u][2] * invW; |
| 1013 |
const GLfloat v0 = vLower->texcoord[u][3] * invW; |
| 1014 |
sLeft[u] = s0 + (span.texStepX[u][0] * adjx + span.texStepY[u][0] * adjy) * (1.0F/FIXED_SCALE); |
| 1015 |
tLeft[u] = t0 + (span.texStepX[u][1] * adjx + span.texStepY[u][1] * adjy) * (1.0F/FIXED_SCALE); |
| 1016 |
uLeft[u] = u0 + (span.texStepX[u][2] * adjx + span.texStepY[u][2] * adjy) * (1.0F/FIXED_SCALE); |
| 1017 |
vLeft[u] = v0 + (span.texStepX[u][3] * adjx + span.texStepY[u][3] * adjy) * (1.0F/FIXED_SCALE); |
| 1018 |
dsOuter[u] = span.texStepY[u][0] + dxOuter * span.texStepX[u][0]; |
| 1019 |
dtOuter[u] = span.texStepY[u][1] + dxOuter * span.texStepX[u][1]; |
| 1020 |
duOuter[u] = span.texStepY[u][2] + dxOuter * span.texStepX[u][2]; |
| 1021 |
dvOuter[u] = span.texStepY[u][3] + dxOuter * span.texStepX[u][3]; |
| 1022 |
) |
| 1023 |
#endif |
| 1024 |
} /*if setupLeft*/ |
| 1025 |
|
| 1026 |
|
| 1027 |
if (setupRight && eRight->lines>0) { |
| 1028 |
#if TRIANGLE_WALK_DOUBLE |
| 1029 |
fxRightEdge = eRight->fsx; |
| 1030 |
fdxRightEdge = eRight->dxdy; |
| 1031 |
#else |
| 1032 |
fxRightEdge = eRight->fsx - FIXED_EPSILON; |
| 1033 |
fdxRightEdge = eRight->fdxdy; |
| 1034 |
#endif |
| 1035 |
} |
| 1036 |
|
| 1037 |
if (lines==0) { |
| 1038 |
continue; |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
/* Rasterize setup */ |
| 1043 |
#ifdef PIXEL_ADDRESS |
| 1044 |
dPRowInner = dPRowOuter + sizeof(PIXEL_TYPE); |
| 1045 |
#endif |
| 1046 |
#ifdef INTERP_Z |
| 1047 |
# ifdef DEPTH_TYPE |
| 1048 |
dZRowInner = dZRowOuter + sizeof(DEPTH_TYPE); |
| 1049 |
# endif |
| 1050 |
fdzInner = fdzOuter + span.zStep; |
| 1051 |
#endif |
| 1052 |
#ifdef INTERP_W |
| 1053 |
dwInner = dwOuter + span.dwdx; |
| 1054 |
#endif |
| 1055 |
#ifdef INTERP_FOG |
| 1056 |
dfogInner = dfogOuter + span.dfogdx; |
| 1057 |
#endif |
| 1058 |
#ifdef INTERP_RGB |
| 1059 |
fdrInner = fdrOuter + span.redStep; |
| 1060 |
fdgInner = fdgOuter + span.greenStep; |
| 1061 |
fdbInner = fdbOuter + span.blueStep; |
| 1062 |
#endif |
| 1063 |
#ifdef INTERP_ALPHA |
| 1064 |
fdaInner = fdaOuter + span.alphaStep; |
| 1065 |
#endif |
| 1066 |
#ifdef INTERP_SPEC |
| 1067 |
dsrInner = dsrOuter + span.specRedStep; |
| 1068 |
dsgInner = dsgOuter + span.specGreenStep; |
| 1069 |
dsbInner = dsbOuter + span.specBlueStep; |
| 1070 |
#endif |
| 1071 |
#ifdef INTERP_INDEX |
| 1072 |
diInner = diOuter + span.indexStep; |
| 1073 |
#endif |
| 1074 |
#ifdef INTERP_INT_TEX |
| 1075 |
dsInner = dsOuter + span.intTexStep[0]; |
| 1076 |
dtInner = dtOuter + span.intTexStep[1]; |
| 1077 |
#endif |
| 1078 |
#ifdef INTERP_TEX |
| 1079 |
TEX_UNIT_LOOP( |
| 1080 |
dsInner[u] = dsOuter[u] + span.texStepX[u][0]; |
| 1081 |
dtInner[u] = dtOuter[u] + span.texStepX[u][1]; |
| 1082 |
duInner[u] = duOuter[u] + span.texStepX[u][2]; |
| 1083 |
dvInner[u] = dvOuter[u] + span.texStepX[u][3]; |
| 1084 |
) |
| 1085 |
#endif |
| 1086 |
|
| 1087 |
while (lines > 0) { |
| 1088 |
/* initialize the span interpolants to the leftmost value */ |
| 1089 |
/* ff = fixed-pt fragment */ |
| 1090 |
const GLint right = InterpToInt(fxRightEdge); |
| 1091 |
span.x = InterpToInt(fxLeftEdge); |
| 1092 |
if (right <= span.x) |
| 1093 |
span.end = 0; |
| 1094 |
else |
| 1095 |
span.end = right - span.x; |
| 1096 |
|
| 1097 |
#ifdef INTERP_Z |
| 1098 |
span.z = zLeft; |
| 1099 |
#endif |
| 1100 |
#ifdef INTERP_W |
| 1101 |
span.w = wLeft; |
| 1102 |
#endif |
| 1103 |
#ifdef INTERP_FOG |
| 1104 |
span.fog = fogLeft; |
| 1105 |
#endif |
| 1106 |
#ifdef INTERP_RGB |
| 1107 |
span.red = rLeft; |
| 1108 |
span.green = gLeft; |
| 1109 |
span.blue = bLeft; |
| 1110 |
#endif |
| 1111 |
#ifdef INTERP_ALPHA |
| 1112 |
span.alpha = aLeft; |
| 1113 |
#endif |
| 1114 |
#ifdef INTERP_SPEC |
| 1115 |
span.specRed = srLeft; |
| 1116 |
span.specGreen = sgLeft; |
| 1117 |
span.specBlue = sbLeft; |
| 1118 |
#endif |
| 1119 |
#ifdef INTERP_INDEX |
| 1120 |
span.index = iLeft; |
| 1121 |
#endif |
| 1122 |
#ifdef INTERP_INT_TEX |
| 1123 |
span.intTex[0] = sLeft; |
| 1124 |
span.intTex[1] = tLeft; |
| 1125 |
#endif |
| 1126 |
|
| 1127 |
#ifdef INTERP_TEX |
| 1128 |
TEX_UNIT_LOOP( |
| 1129 |
span.tex[u][0] = sLeft[u]; |
| 1130 |
span.tex[u][1] = tLeft[u]; |
| 1131 |
span.tex[u][2] = uLeft[u]; |
| 1132 |
span.tex[u][3] = vLeft[u]; |
| 1133 |
) |
| 1134 |
#endif |
| 1135 |
|
| 1136 |
/* This is where we actually generate fragments */ |
| 1137 |
/* XXX the test for span.y > 0 _shouldn't_ be needed but |
| 1138 |
* it fixes a problem on 64-bit Opterons (bug 4842). |
| 1139 |
*/ |
| 1140 |
if (span.end > 0 && span.y >= 0) { |
| 1141 |
const GLint len = span.end - 1; |
| 1142 |
(void) len; |
| 1143 |
#ifdef INTERP_RGB |
| 1144 |
CLAMP_INTERPOLANT(red, redStep, len); |
| 1145 |
CLAMP_INTERPOLANT(green, greenStep, len); |
| 1146 |
CLAMP_INTERPOLANT(blue, blueStep, len); |
| 1147 |
#endif |
| 1148 |
#ifdef INTERP_ALPHA |
| 1149 |
CLAMP_INTERPOLANT(alpha, alphaStep, len); |
| 1150 |
#endif |
| 1151 |
#ifdef INTERP_SPEC |
| 1152 |
CLAMP_INTERPOLANT(specRed, specRedStep, len); |
| 1153 |
CLAMP_INTERPOLANT(specGreen, specGreenStep, len); |
| 1154 |
CLAMP_INTERPOLANT(specBlue, specBlueStep, len); |
| 1155 |
#endif |
| 1156 |
#ifdef INTERP_INDEX |
| 1157 |
CLAMP_INTERPOLANT(index, indexStep, len); |
| 1158 |
#endif |
| 1159 |
RENDER_SPAN( span ); |
| 1160 |
} |
| 1161 |
|
| 1162 |
/* |
| 1163 |
* Advance to the next scan line. Compute the |
| 1164 |
* new edge coordinates, and adjust the |
| 1165 |
* pixel-center x coordinate so that it stays |
| 1166 |
* on or inside the major edge. |
| 1167 |
*/ |
| 1168 |
span.y++; |
| 1169 |
lines--; |
| 1170 |
|
| 1171 |
fxLeftEdge += fdxLeftEdge; |
| 1172 |
fxRightEdge += fdxRightEdge; |
| 1173 |
|
| 1174 |
fError += fdError; |
| 1175 |
if (fError >= 0) { |
| 1176 |
fError -= INTERP_ONE; |
| 1177 |
|
| 1178 |
#ifdef PIXEL_ADDRESS |
| 1179 |
pRow = (PIXEL_TYPE *) ((GLubyte *) pRow + dPRowOuter); |
| 1180 |
#endif |
| 1181 |
#ifdef INTERP_Z |
| 1182 |
# ifdef DEPTH_TYPE |
| 1183 |
zRow = (DEPTH_TYPE *) ((GLubyte *) zRow + dZRowOuter); |
| 1184 |
# endif |
| 1185 |
zLeft += fdzOuter; |
| 1186 |
#endif |
| 1187 |
#ifdef INTERP_W |
| 1188 |
wLeft += dwOuter; |
| 1189 |
#endif |
| 1190 |
#ifdef INTERP_FOG |
| 1191 |
fogLeft += dfogOuter; |
| 1192 |
#endif |
| 1193 |
#ifdef INTERP_RGB |
| 1194 |
rLeft += fdrOuter; |
| 1195 |
gLeft += fdgOuter; |
| 1196 |
bLeft += fdbOuter; |
| 1197 |
#endif |
| 1198 |
#ifdef INTERP_ALPHA |
| 1199 |
aLeft += fdaOuter; |
| 1200 |
#endif |
| 1201 |
#ifdef INTERP_SPEC |
| 1202 |
srLeft += dsrOuter; |
| 1203 |
sgLeft += dsgOuter; |
| 1204 |
sbLeft += dsbOuter; |
| 1205 |
#endif |
| 1206 |
#ifdef INTERP_INDEX |
| 1207 |
iLeft += diOuter; |
| 1208 |
#endif |
| 1209 |
#ifdef INTERP_INT_TEX |
| 1210 |
sLeft += dsOuter; |
| 1211 |
tLeft += dtOuter; |
| 1212 |
#endif |
| 1213 |
#ifdef INTERP_TEX |
| 1214 |
TEX_UNIT_LOOP( |
| 1215 |
sLeft[u] += dsOuter[u]; |
| 1216 |
tLeft[u] += dtOuter[u]; |
| 1217 |
uLeft[u] += duOuter[u]; |
| 1218 |
vLeft[u] += dvOuter[u]; |
| 1219 |
) |
| 1220 |
#endif |
| 1221 |
} |
| 1222 |
else { |
| 1223 |
#ifdef PIXEL_ADDRESS |
| 1224 |
pRow = (PIXEL_TYPE *) ((GLubyte *) pRow + dPRowInner); |
| 1225 |
#endif |
| 1226 |
#ifdef INTERP_Z |
| 1227 |
# ifdef DEPTH_TYPE |
| 1228 |
zRow = (DEPTH_TYPE *) ((GLubyte *) zRow + dZRowInner); |
| 1229 |
# endif |
| 1230 |
zLeft += fdzInner; |
| 1231 |
#endif |
| 1232 |
#ifdef INTERP_W |
| 1233 |
wLeft += dwInner; |
| 1234 |
#endif |
| 1235 |
#ifdef INTERP_FOG |
| 1236 |
fogLeft += dfogInner; |
| 1237 |
#endif |
| 1238 |
#ifdef INTERP_RGB |
| 1239 |
rLeft += fdrInner; |
| 1240 |
gLeft += fdgInner; |
| 1241 |
bLeft += fdbInner; |
| 1242 |
#endif |
| 1243 |
#ifdef INTERP_ALPHA |
| 1244 |
aLeft += fdaInner; |
| 1245 |
#endif |
| 1246 |
#ifdef INTERP_SPEC |
| 1247 |
srLeft += dsrInner; |
| 1248 |
sgLeft += dsgInner; |
| 1249 |
sbLeft += dsbInner; |
| 1250 |
#endif |
| 1251 |
#ifdef INTERP_INDEX |
| 1252 |
iLeft += diInner; |
| 1253 |
#endif |
| 1254 |
#ifdef INTERP_INT_TEX |
| 1255 |
sLeft += dsInner; |
| 1256 |
tLeft += dtInner; |
| 1257 |
#endif |
| 1258 |
#ifdef INTERP_TEX |
| 1259 |
TEX_UNIT_LOOP( |
| 1260 |
sLeft[u] += dsInner[u]; |
| 1261 |
tLeft[u] += dtInner[u]; |
| 1262 |
uLeft[u] += duInner[u]; |
| 1263 |
vLeft[u] += dvInner[u]; |
| 1264 |
) |
| 1265 |
#endif |
| 1266 |
} |
| 1267 |
} /*while lines>0*/ |
| 1268 |
|
| 1269 |
} /* for subTriangle */ |
| 1270 |
|
| 1271 |
} |
| 1272 |
#ifdef CLEANUP_CODE |
| 1273 |
CLEANUP_CODE |
| 1274 |
#endif |
| 1275 |
} |
| 1276 |
} |
| 1277 |
|
| 1278 |
#undef SETUP_CODE |
| 1279 |
#undef CLEANUP_CODE |
| 1280 |
#undef RENDER_SPAN |
| 1281 |
|
| 1282 |
#undef PIXEL_TYPE |
| 1283 |
#undef BYTES_PER_ROW |
| 1284 |
#undef PIXEL_ADDRESS |
| 1285 |
#undef DEPTH_TYPE |
| 1286 |
|
| 1287 |
#undef INTERP_Z |
| 1288 |
#undef INTERP_W |
| 1289 |
#undef INTERP_FOG |
| 1290 |
#undef INTERP_RGB |
| 1291 |
#undef INTERP_ALPHA |
| 1292 |
#undef INTERP_SPEC |
| 1293 |
#undef INTERP_INDEX |
| 1294 |
#undef INTERP_INT_TEX |
| 1295 |
#undef INTERP_TEX |
| 1296 |
#undef INTERP_MULTITEX |
| 1297 |
#undef TEX_UNIT_LOOP |
| 1298 |
|
| 1299 |
#undef S_SCALE |
| 1300 |
#undef T_SCALE |
| 1301 |
|
| 1302 |
#undef FixedToDepth |
| 1303 |
#undef ColorTemp |
| 1304 |
#undef GLinterp |
| 1305 |
#undef InterpToInt |
| 1306 |
#undef INTERP_ONE |
| 1307 |
|
| 1308 |
#undef NAME |