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