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