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