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