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