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