2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Triangle Rasterizer Template
28 * This file is #include'd to generate custom triangle rasterizers.
30 * The following macros may be defined to indicate what auxillary information
31 * must be interplated across the triangle:
32 * INTERP_Z - if defined, interpolate vertex Z values
33 * INTERP_W - if defined, interpolate vertex W values
34 * INTERP_FOG - if defined, interpolate fog values
35 * INTERP_RGB - if defined, interpolate RGB values
36 * INTERP_ALPHA - if defined, interpolate Alpha values (req's INTERP_RGB)
37 * INTERP_SPEC - if defined, interpolate specular RGB values
38 * INTERP_INDEX - if defined, interpolate color index values
39 * INTERP_INT_TEX - if defined, interpolate integer ST texcoords
40 * (fast, simple 2-D texture mapping)
41 * INTERP_TEX - if defined, interpolate set 0 float STRQ texcoords
42 * NOTE: OpenGL STRQ = Mesa STUV (R was taken for red)
43 * INTERP_MULTITEX - if defined, interpolate N units of STRQ texcoords
45 * When one can directly address pixels in the color buffer the following
46 * macros can be defined and used to compute pixel addresses during
47 * rasterization (see pRow):
48 * PIXEL_TYPE - the datatype of a pixel (GLubyte, GLushort, GLuint)
49 * BYTES_PER_ROW - number of bytes per row in the color buffer
50 * PIXEL_ADDRESS(X,Y) - returns the address of pixel at (X,Y) where
51 * Y==0 at bottom of screen and increases upward.
53 * Similarly, for direct depth buffer access, this type is used for depth
55 * DEPTH_TYPE - either GLushort or GLuint
57 * Optionally, one may provide one-time setup code per triangle:
58 * SETUP_CODE - code which is to be executed once per triangle
59 * CLEANUP_CODE - code to execute at end of triangle
61 * The following macro MUST be defined:
62 * RENDER_SPAN(span) - code to write a span of pixels.
64 * This code was designed for the origin to be in the lower-left corner.
66 * Inspired by triangle rasterizer code written by Allen Akin. Thanks Allen!
69 * Some notes on rasterization accuracy:
71 * This code uses fixed point arithmetic (the GLfixed type) to iterate
72 * over the triangle edges and interpolate ancillary data (such as Z,
73 * color, secondary color, etc). The number of fractional bits in
74 * GLfixed and the value of SUB_PIXEL_BITS has a direct bearing on the
75 * accuracy of rasterization.
77 * If SUB_PIXEL_BITS=4 then we'll snap the vertices to the nearest
78 * 1/16 of a pixel. If we're walking up a long, nearly vertical edge
79 * (dx=1/16, dy=1024) we'll need 4 + 10 = 14 fractional bits in
80 * GLfixed to walk the edge without error. If the maximum viewport
81 * height is 4K pixels, then we'll need 4 + 12 = 16 fractional bits.
83 * Historically, Mesa has used 11 fractional bits in GLfixed, snaps
84 * vertices to 1/16 pixel and allowed a maximum viewport height of 2K
85 * pixels. 11 fractional bits is actually insufficient for accurately
86 * rasterizing some triangles. More recently, the maximum viewport
87 * height was increased to 4K pixels. Thus, Mesa should be using 16
88 * fractional bits in GLfixed. Unfortunately, there may be some issues
89 * with setting FIXED_FRAC_BITS=16, such as multiplication overflow.
90 * This will have to be examined in some detail...
92 * For now, if you find rasterization errors, particularly with tall,
93 * sliver triangles, try increasing FIXED_FRAC_BITS and/or decreasing
98 * ColorTemp is used for intermediate color values.
100 #if CHAN_TYPE == GL_FLOAT
101 #define ColorTemp GLfloat
103 #define ColorTemp GLint /* same as GLfixed */
108 * Walk triangle edges with GLfixed or GLdouble
110 #if TRIANGLE_WALK_DOUBLE
111 #define GLinterp GLdouble
112 #define InterpToInt(X) ((GLint) (X))
113 #define INTERP_ONE 1.0
115 #define GLinterp GLfixed
116 #define InterpToInt(X) FixedToInt(X)
117 #define INTERP_ONE FIXED_ONE
122 * Either loop over all texture units, or just use unit zero.
124 #ifdef INTERP_MULTITEX
125 #define TEX_UNIT_LOOP(CODE) \
128 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
129 if (ctx->Texture._EnabledCoordUnits & (1 << u)) { \
135 #elif defined(INTERP_TEX)
136 #define TEX_UNIT_LOOP(CODE) \
138 const GLuint u = 0; \
144 static void NAME(GLcontext
*ctx
, const SWvertex
*v0
,
149 const SWvertex
*v0
, *v1
; /* Y(v0) < Y(v1) */
150 #if TRIANGLE_WALK_DOUBLE
151 GLdouble dx
; /* X(v1) - X(v0) */
152 GLdouble dy
; /* Y(v1) - Y(v0) */
153 GLdouble dxdy
; /* dx/dy */
154 GLdouble adjy
; /* adjust from v[0]->fy to fsy, scaled */
155 GLdouble fsx
; /* first sample point x coord */
157 GLdouble fx0
; /*X of lower endpoint */
159 GLfloat dx
; /* X(v1) - X(v0) */
160 GLfloat dy
; /* Y(v1) - Y(v0) */
161 GLfloat dxdy
; /* dx/dy */
162 GLfixed fdxdy
; /* dx/dy in fixed-point */
163 GLfloat adjy
; /* adjust from v[0]->fy to fsy, scaled */
164 GLfixed fsx
; /* first sample point x coord */
166 GLfixed fx0
; /* fixed pt X of lower endpoint */
168 GLint lines
; /* number of lines to be sampled on this edge */
172 const GLint depthBits
= ctx
->Visual
.depthBits
;
173 const GLint fixedToDepthShift
= depthBits
<= 16 ? FIXED_SHIFT
: 0;
174 const GLfloat maxDepth
= ctx
->DepthMaxF
;
175 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
177 EdgeT eMaj
, eTop
, eBot
;
179 const SWvertex
*vMin
, *vMid
, *vMax
; /* Y(vMin)<=Y(vMid)<=Y(vMax) */
180 GLfloat bf
= SWRAST_CONTEXT(ctx
)->_BackfaceSign
;
181 #if !TRIANGLE_WALK_DOUBLE
182 const GLint snapMask
= ~((FIXED_ONE
/ (1 << SUB_PIXEL_BITS
)) - 1); /* for x/y coord snapping */
184 GLinterp vMin_fx
, vMin_fy
, vMid_fx
, vMid_fy
, vMax_fx
, vMax_fy
;
188 INIT_SPAN(span
, GL_POLYGON
, 0, 0, 0);
191 (void) fixedToDepthShift
;
195 printf("%s()\n", __FUNCTION__);
196 printf(" %g, %g, %g\n", v0->win[0], v0->win[1], v0->win[2]);
197 printf(" %g, %g, %g\n", v1->win[0], v1->win[1], v1->win[2]);
198 printf(" %g, %g, %g\n", v2->win[0], v2->win[1], v2->win[2]);
201 ASSERT(v0->win[2] >= 0.0);
202 ASSERT(v1->win[2] >= 0.0);
203 ASSERT(v2->win[2] >= 0.0);
205 /* Compute fixed point x,y coords w/ half-pixel offsets and snapping.
206 * And find the order of the 3 vertices along the Y axis.
209 #if TRIANGLE_WALK_DOUBLE
210 const GLdouble fy0
= v0
->win
[1] - 0.5;
211 const GLdouble fy1
= v1
->win
[1] - 0.5;
212 const GLdouble fy2
= v2
->win
[1] - 0.5;
214 const GLfixed fy0
= FloatToFixed(v0
->win
[1] - 0.5F
) & snapMask
;
215 const GLfixed fy1
= FloatToFixed(v1
->win
[1] - 0.5F
) & snapMask
;
216 const GLfixed fy2
= FloatToFixed(v2
->win
[1] - 0.5F
) & snapMask
;
221 vMin
= v0
; vMid
= v1
; vMax
= v2
;
222 vMin_fy
= fy0
; vMid_fy
= fy1
; vMax_fy
= fy2
;
224 else if (fy2
<= fy0
) {
226 vMin
= v2
; vMid
= v0
; vMax
= v1
;
227 vMin_fy
= fy2
; vMid_fy
= fy0
; vMax_fy
= fy1
;
231 vMin
= v0
; vMid
= v2
; vMax
= v1
;
232 vMin_fy
= fy0
; vMid_fy
= fy2
; vMax_fy
= fy1
;
239 vMin
= v1
; vMid
= v0
; vMax
= v2
;
240 vMin_fy
= fy1
; vMid_fy
= fy0
; vMax_fy
= fy2
;
243 else if (fy2
<= fy1
) {
245 vMin
= v2
; vMid
= v1
; vMax
= v0
;
246 vMin_fy
= fy2
; vMid_fy
= fy1
; vMax_fy
= fy0
;
251 vMin
= v1
; vMid
= v2
; vMax
= v0
;
252 vMin_fy
= fy1
; vMid_fy
= fy2
; vMax_fy
= fy0
;
256 /* fixed point X coords */
257 #if TRIANGLE_WALK_DOUBLE
258 vMin_fx
= vMin
->win
[0] + 0.5;
259 vMid_fx
= vMid
->win
[0] + 0.5;
260 vMax_fx
= vMax
->win
[0] + 0.5;
262 vMin_fx
= FloatToFixed(vMin
->win
[0] + 0.5F
) & snapMask
;
263 vMid_fx
= FloatToFixed(vMid
->win
[0] + 0.5F
) & snapMask
;
264 vMax_fx
= FloatToFixed(vMax
->win
[0] + 0.5F
) & snapMask
;
268 /* vertex/edge relationship */
269 eMaj
.v0
= vMin
; eMaj
.v1
= vMax
; /*TODO: .v1's not needed */
270 eTop
.v0
= vMid
; eTop
.v1
= vMax
;
271 eBot
.v0
= vMin
; eBot
.v1
= vMid
;
273 /* compute deltas for each edge: vertex[upper] - vertex[lower] */
274 #if TRIANGLE_WALK_DOUBLE
275 eMaj
.dx
= vMax_fx
- vMin_fx
;
276 eMaj
.dy
= vMax_fy
- vMin_fy
;
277 eTop
.dx
= vMax_fx
- vMid_fx
;
278 eTop
.dy
= vMax_fy
- vMid_fy
;
279 eBot
.dx
= vMid_fx
- vMin_fx
;
280 eBot
.dy
= vMid_fy
- vMin_fy
;
282 eMaj
.dx
= FixedToFloat(vMax_fx
- vMin_fx
);
283 eMaj
.dy
= FixedToFloat(vMax_fy
- vMin_fy
);
284 eTop
.dx
= FixedToFloat(vMax_fx
- vMid_fx
);
285 eTop
.dy
= FixedToFloat(vMax_fy
- vMid_fy
);
286 eBot
.dx
= FixedToFloat(vMid_fx
- vMin_fx
);
287 eBot
.dy
= FixedToFloat(vMid_fy
- vMin_fy
);
290 /* compute area, oneOverArea and perform backface culling */
292 #if TRIANGLE_WALK_DOUBLE
293 const GLdouble area
= eMaj
.dx
* eBot
.dy
- eBot
.dx
* eMaj
.dy
;
295 const GLfloat area
= eMaj
.dx
* eBot
.dy
- eBot
.dx
* eMaj
.dy
;
297 /* Do backface culling */
301 if (IS_INF_OR_NAN(area
) || area
== 0.0F
)
304 oneOverArea
= 1.0F
/ area
;
307 span
.facing
= ctx
->_Facing
; /* for 2-sided stencil test */
309 /* Edge setup. For a triangle strip these could be reused... */
311 #if TRIANGLE_WALK_DOUBLE
312 eMaj
.fsy
= CEILF(vMin_fy
);
313 eMaj
.lines
= (GLint
) CEILF(vMax_fy
- eMaj
.fsy
);
315 eMaj
.fsy
= FixedCeil(vMin_fy
);
316 eMaj
.lines
= FixedToInt(FixedCeil(vMax_fy
- eMaj
.fsy
));
318 if (eMaj
.lines
> 0) {
319 eMaj
.dxdy
= eMaj
.dx
/ eMaj
.dy
;
320 #if TRIANGLE_WALK_DOUBLE
321 eMaj
.adjy
= (eMaj
.fsy
- vMin_fy
) * FIXED_SCALE
; /* SCALED! */
323 eMaj
.fsx
= eMaj
.fx0
+ (eMaj
.adjy
* eMaj
.dxdy
) / (GLdouble
) FIXED_SCALE
;
325 eMaj
.fdxdy
= SignedFloatToFixed(eMaj
.dxdy
);
326 eMaj
.adjy
= (GLfloat
) (eMaj
.fsy
- vMin_fy
); /* SCALED! */
328 eMaj
.fsx
= eMaj
.fx0
+ (GLfixed
) (eMaj
.adjy
* eMaj
.dxdy
);
335 #if TRIANGLE_WALK_DOUBLE
336 eTop
.fsy
= CEILF(vMid_fy
);
337 eTop
.lines
= (GLint
) CEILF(vMax_fy
- eTop
.fsy
);
339 eTop
.fsy
= FixedCeil(vMid_fy
);
340 eTop
.lines
= FixedToInt(FixedCeil(vMax_fy
- eTop
.fsy
));
342 if (eTop
.lines
> 0) {
343 eTop
.dxdy
= eTop
.dx
/ eTop
.dy
;
344 #if TRIANGLE_WALK_DOUBLE
345 eTop
.adjy
= (eTop
.fsy
- vMid_fy
) * FIXED_SCALE
; /* SCALED! */
347 eTop
.fsx
= eTop
.fx0
+ (eTop
.adjy
* eTop
.dxdy
) / (GLdouble
) FIXED_SCALE
;
349 eTop
.fdxdy
= SignedFloatToFixed(eTop
.dxdy
);
350 eTop
.adjy
= (GLfloat
) (eTop
.fsy
- vMid_fy
); /* SCALED! */
352 eTop
.fsx
= eTop
.fx0
+ (GLfixed
) (eTop
.adjy
* eTop
.dxdy
);
356 #if TRIANGLE_WALK_DOUBLE
357 eBot
.fsy
= CEILF(vMin_fy
);
358 eBot
.lines
= (GLint
) CEILF(vMid_fy
- eBot
.fsy
);
360 eBot
.fsy
= FixedCeil(vMin_fy
);
361 eBot
.lines
= FixedToInt(FixedCeil(vMid_fy
- eBot
.fsy
));
363 if (eBot
.lines
> 0) {
364 eBot
.dxdy
= eBot
.dx
/ eBot
.dy
;
365 #if TRIANGLE_WALK_DOUBLE
366 eBot
.adjy
= (eBot
.fsy
- vMin_fy
) * FIXED_SCALE
; /* SCALED! */
368 eBot
.fsx
= eBot
.fx0
+ (eBot
.adjy
* eBot
.dxdy
) / (GLdouble
) FIXED_SCALE
;
370 eBot
.fdxdy
= SignedFloatToFixed(eBot
.dxdy
);
371 eBot
.adjy
= (GLfloat
) (eBot
.fsy
- vMin_fy
); /* SCALED! */
373 eBot
.fsx
= eBot
.fx0
+ (GLfixed
) (eBot
.adjy
* eBot
.dxdy
);
379 * Conceptually, we view a triangle as two subtriangles
380 * separated by a perfectly horizontal line. The edge that is
381 * intersected by this line is one with maximal absolute dy; we
382 * call it a ``major'' edge. The other two edges are the
383 * ``top'' edge (for the upper subtriangle) and the ``bottom''
384 * edge (for the lower subtriangle). If either of these two
385 * edges is horizontal or very close to horizontal, the
386 * corresponding subtriangle might cover zero sample points;
387 * we take care to handle such cases, for performance as well
390 * By stepping rasterization parameters along the major edge,
391 * we can avoid recomputing them at the discontinuity where
392 * the top and bottom edges meet. However, this forces us to
393 * be able to scan both left-to-right and right-to-left.
394 * Also, we must determine whether the major edge is at the
395 * left or right side of the triangle. We do this by
396 * computing the magnitude of the cross-product of the major
397 * and top edges. Since this magnitude depends on the sine of
398 * the angle between the two edges, its sign tells us whether
399 * we turn to the left or to the right when travelling along
400 * the major edge to the top edge, and from this we infer
401 * whether the major edge is on the left or the right.
403 * Serendipitously, this cross-product magnitude is also a
404 * value we need to compute the iteration parameter
405 * derivatives for the triangle, and it can be used to perform
406 * backface culling because its sign tells us whether the
407 * triangle is clockwise or counterclockwise. In this code we
408 * refer to it as ``area'' because it's also proportional to
409 * the pixel area of the triangle.
413 GLint scan_from_left_to_right
; /* true if scanning left-to-right */
419 * Execute user-supplied setup code
425 scan_from_left_to_right
= (oneOverArea
< 0.0F
);
428 /* compute d?/dx and d?/dy derivatives */
430 span
.interpMask
|= SPAN_Z
;
432 GLfloat eMaj_dz
= vMax
->win
[2] - vMin
->win
[2];
433 GLfloat eBot_dz
= vMid
->win
[2] - vMin
->win
[2];
434 span
.dzdx
= oneOverArea
* (eMaj_dz
* eBot
.dy
- eMaj
.dy
* eBot_dz
);
435 if (span
.dzdx
> maxDepth
|| span
.dzdx
< -maxDepth
) {
436 /* probably a sliver triangle */
441 span
.dzdy
= oneOverArea
* (eMaj
.dx
* eBot_dz
- eMaj_dz
* eBot
.dx
);
444 span
.zStep
= SignedFloatToFixed(span
.dzdx
);
446 span
.zStep
= (GLint
) span
.dzdx
;
450 span
.interpMask
|= SPAN_W
;
452 const GLfloat eMaj_dw
= vMax
->win
[3] - vMin
->win
[3];
453 const GLfloat eBot_dw
= vMid
->win
[3] - vMin
->win
[3];
454 span
.dwdx
= oneOverArea
* (eMaj_dw
* eBot
.dy
- eMaj
.dy
* eBot_dw
);
455 span
.dwdy
= oneOverArea
* (eMaj
.dx
* eBot_dw
- eMaj_dw
* eBot
.dx
);
459 span
.interpMask
|= SPAN_FOG
;
462 const GLfloat wMax
= vMax
->win
[3], wMin
= vMin
->win
[3], wMid
= vMid
->win
[3];
463 const GLfloat eMaj_dfog
= vMax
->fog
* wMax
- vMin
->fog
* wMin
;
464 const GLfloat eBot_dfog
= vMid
->fog
* wMid
- vMin
->fog
* wMin
;
466 const GLfloat eMaj_dfog
= vMax
->fog
- vMin
->fog
;
467 const GLfloat eBot_dfog
= vMid
->fog
- vMin
->fog
;
469 span
.dfogdx
= oneOverArea
* (eMaj_dfog
* eBot
.dy
- eMaj
.dy
* eBot_dfog
);
470 span
.dfogdy
= oneOverArea
* (eMaj
.dx
* eBot_dfog
- eMaj_dfog
* eBot
.dx
);
471 span
.fogStep
= span
.dfogdx
;
475 span
.interpMask
|= SPAN_RGBA
;
476 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
477 GLfloat eMaj_dr
= (GLfloat
) ((ColorTemp
) vMax
->color
[RCOMP
] - (ColorTemp
) vMin
->color
[RCOMP
]);
478 GLfloat eBot_dr
= (GLfloat
) ((ColorTemp
) vMid
->color
[RCOMP
] - (ColorTemp
) vMin
->color
[RCOMP
]);
479 GLfloat eMaj_dg
= (GLfloat
) ((ColorTemp
) vMax
->color
[GCOMP
] - (ColorTemp
) vMin
->color
[GCOMP
]);
480 GLfloat eBot_dg
= (GLfloat
) ((ColorTemp
) vMid
->color
[GCOMP
] - (ColorTemp
) vMin
->color
[GCOMP
]);
481 GLfloat eMaj_db
= (GLfloat
) ((ColorTemp
) vMax
->color
[BCOMP
] - (ColorTemp
) vMin
->color
[BCOMP
]);
482 GLfloat eBot_db
= (GLfloat
) ((ColorTemp
) vMid
->color
[BCOMP
] - (ColorTemp
) vMin
->color
[BCOMP
]);
484 GLfloat eMaj_da
= (GLfloat
) ((ColorTemp
) vMax
->color
[ACOMP
] - (ColorTemp
) vMin
->color
[ACOMP
]);
485 GLfloat eBot_da
= (GLfloat
) ((ColorTemp
) vMid
->color
[ACOMP
] - (ColorTemp
) vMin
->color
[ACOMP
]);
487 span
.drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
488 span
.drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
489 span
.dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
490 span
.dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
491 span
.dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
492 span
.dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
493 # if CHAN_TYPE == GL_FLOAT
494 span
.redStep
= span
.drdx
;
495 span
.greenStep
= span
.dgdx
;
496 span
.blueStep
= span
.dbdx
;
498 span
.redStep
= SignedFloatToFixed(span
.drdx
);
499 span
.greenStep
= SignedFloatToFixed(span
.dgdx
);
500 span
.blueStep
= SignedFloatToFixed(span
.dbdx
);
501 # endif /* GL_FLOAT */
503 span
.dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
504 span
.dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
505 # if CHAN_TYPE == GL_FLOAT
506 span
.alphaStep
= span
.dadx
;
508 span
.alphaStep
= SignedFloatToFixed(span
.dadx
);
509 # endif /* GL_FLOAT */
510 # endif /* INTERP_ALPHA */
513 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
514 span
.interpMask
|= SPAN_FLAT
;
515 span
.drdx
= span
.drdy
= 0.0F
;
516 span
.dgdx
= span
.dgdy
= 0.0F
;
517 span
.dbdx
= span
.dbdy
= 0.0F
;
518 # if CHAN_TYPE == GL_FLOAT
520 span
.greenStep
= 0.0F
;
521 span
.blueStep
= 0.0F
;
526 # endif /* GL_FLOAT */
528 span
.dadx
= span
.dady
= 0.0F
;
529 # if CHAN_TYPE == GL_FLOAT
530 span
.alphaStep
= 0.0F
;
533 # endif /* GL_FLOAT */
536 #endif /* INTERP_RGB */
538 span
.interpMask
|= SPAN_SPEC
;
539 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
540 GLfloat eMaj_dsr
= (GLfloat
) ((ColorTemp
) vMax
->specular
[RCOMP
] - (ColorTemp
) vMin
->specular
[RCOMP
]);
541 GLfloat eBot_dsr
= (GLfloat
) ((ColorTemp
) vMid
->specular
[RCOMP
] - (ColorTemp
) vMin
->specular
[RCOMP
]);
542 GLfloat eMaj_dsg
= (GLfloat
) ((ColorTemp
) vMax
->specular
[GCOMP
] - (ColorTemp
) vMin
->specular
[GCOMP
]);
543 GLfloat eBot_dsg
= (GLfloat
) ((ColorTemp
) vMid
->specular
[GCOMP
] - (ColorTemp
) vMin
->specular
[GCOMP
]);
544 GLfloat eMaj_dsb
= (GLfloat
) ((ColorTemp
) vMax
->specular
[BCOMP
] - (ColorTemp
) vMin
->specular
[BCOMP
]);
545 GLfloat eBot_dsb
= (GLfloat
) ((ColorTemp
) vMid
->specular
[BCOMP
] - (ColorTemp
) vMin
->specular
[BCOMP
]);
546 span
.dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
547 span
.dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
548 span
.dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
549 span
.dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
550 span
.dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
551 span
.dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
552 # if CHAN_TYPE == GL_FLOAT
553 span
.specRedStep
= span
.dsrdx
;
554 span
.specGreenStep
= span
.dsgdx
;
555 span
.specBlueStep
= span
.dsbdx
;
557 span
.specRedStep
= SignedFloatToFixed(span
.dsrdx
);
558 span
.specGreenStep
= SignedFloatToFixed(span
.dsgdx
);
559 span
.specBlueStep
= SignedFloatToFixed(span
.dsbdx
);
563 span
.dsrdx
= span
.dsrdy
= 0.0F
;
564 span
.dsgdx
= span
.dsgdy
= 0.0F
;
565 span
.dsbdx
= span
.dsbdy
= 0.0F
;
566 # if CHAN_TYPE == GL_FLOAT
567 span
.specRedStep
= 0.0F
;
568 span
.specGreenStep
= 0.0F
;
569 span
.specBlueStep
= 0.0F
;
571 span
.specRedStep
= 0;
572 span
.specGreenStep
= 0;
573 span
.specBlueStep
= 0;
576 #endif /* INTERP_SPEC */
578 span
.interpMask
|= SPAN_INDEX
;
579 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
580 GLfloat eMaj_di
= vMax
->index
- vMin
->index
;
581 GLfloat eBot_di
= vMid
->index
- vMin
->index
;
582 didx
= oneOverArea
* (eMaj_di
* eBot
.dy
- eMaj
.dy
* eBot_di
);
583 didy
= oneOverArea
* (eMaj
.dx
* eBot_di
- eMaj_di
* eBot
.dx
);
584 span
.indexStep
= SignedFloatToFixed(didx
);
587 span
.interpMask
|= SPAN_FLAT
;
592 #ifdef INTERP_INT_TEX
593 span
.interpMask
|= SPAN_INT_TEXTURE
;
595 GLfloat eMaj_ds
= (vMax
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
596 GLfloat eBot_ds
= (vMid
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
597 GLfloat eMaj_dt
= (vMax
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
598 GLfloat eBot_dt
= (vMid
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
599 span
.texStepX
[0][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
600 span
.texStepY
[0][0] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
601 span
.texStepX
[0][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
602 span
.texStepY
[0][1] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
603 span
.intTexStep
[0] = SignedFloatToFixed(span
.texStepX
[0][0]);
604 span
.intTexStep
[1] = SignedFloatToFixed(span
.texStepX
[0][1]);
608 span
.interpMask
|= SPAN_TEXTURE
;
611 const GLfloat wMax
= vMax
->win
[3], wMin
= vMin
->win
[3], wMid
= vMid
->win
[3];
613 GLfloat eMaj_ds
= vMax
->texcoord
[u
][0] * wMax
- vMin
->texcoord
[u
][0] * wMin
;
614 GLfloat eBot_ds
= vMid
->texcoord
[u
][0] * wMid
- vMin
->texcoord
[u
][0] * wMin
;
615 GLfloat eMaj_dt
= vMax
->texcoord
[u
][1] * wMax
- vMin
->texcoord
[u
][1] * wMin
;
616 GLfloat eBot_dt
= vMid
->texcoord
[u
][1] * wMid
- vMin
->texcoord
[u
][1] * wMin
;
617 GLfloat eMaj_du
= vMax
->texcoord
[u
][2] * wMax
- vMin
->texcoord
[u
][2] * wMin
;
618 GLfloat eBot_du
= vMid
->texcoord
[u
][2] * wMid
- vMin
->texcoord
[u
][2] * wMin
;
619 GLfloat eMaj_dv
= vMax
->texcoord
[u
][3] * wMax
- vMin
->texcoord
[u
][3] * wMin
;
620 GLfloat eBot_dv
= vMid
->texcoord
[u
][3] * wMid
- vMin
->texcoord
[u
][3] * wMin
;
621 span
.texStepX
[u
][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
622 span
.texStepY
[u
][0] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
623 span
.texStepX
[u
][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
624 span
.texStepY
[u
][1] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
625 span
.texStepX
[u
][2] = oneOverArea
* (eMaj_du
* eBot
.dy
- eMaj
.dy
* eBot_du
);
626 span
.texStepY
[u
][2] = oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
627 span
.texStepX
[u
][3] = oneOverArea
* (eMaj_dv
* eBot
.dy
- eMaj
.dy
* eBot_dv
);
628 span
.texStepY
[u
][3] = oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
634 * We always sample at pixel centers. However, we avoid
635 * explicit half-pixel offsets in this code by incorporating
636 * the proper offset in each of x and y during the
637 * transformation to window coordinates.
639 * We also apply the usual rasterization rules to prevent
640 * cracks and overlaps. A pixel is considered inside a
641 * subtriangle if it meets all of four conditions: it is on or
642 * to the right of the left edge, strictly to the left of the
643 * right edge, on or below the top edge, and strictly above
644 * the bottom edge. (Some edges may be degenerate.)
646 * The following discussion assumes left-to-right scanning
647 * (that is, the major edge is on the left); the right-to-left
648 * case is a straightforward variation.
650 * We start by finding the half-integral y coordinate that is
651 * at or below the top of the triangle. This gives us the
652 * first scan line that could possibly contain pixels that are
653 * inside the triangle.
655 * Next we creep down the major edge until we reach that y,
656 * and compute the corresponding x coordinate on the edge.
657 * Then we find the half-integral x that lies on or just
658 * inside the edge. This is the first pixel that might lie in
659 * the interior of the triangle. (We won't know for sure
660 * until we check the other edges.)
662 * As we rasterize the triangle, we'll step down the major
663 * edge. For each step in y, we'll move an integer number
664 * of steps in x. There are two possible x step sizes, which
665 * we'll call the ``inner'' step (guaranteed to land on the
666 * edge or inside it) and the ``outer'' step (guaranteed to
667 * land on the edge or outside it). The inner and outer steps
668 * differ by one. During rasterization we maintain an error
669 * term that indicates our distance from the true edge, and
670 * select either the inner step or the outer step, whichever
671 * gets us to the first pixel that falls inside the triangle.
673 * All parameters (z, red, etc.) as well as the buffer
674 * addresses for color and z have inner and outer step values,
675 * so that we can increment them appropriately. This method
676 * eliminates the need to adjust parameters by creeping a
677 * sub-pixel amount into the triangle at each scanline.
682 GLinterp fxLeftEdge
= 0, fxRightEdge
= 0;
683 GLinterp fdxLeftEdge
= 0, fdxRightEdge
= 0;
684 GLinterp fError
= 0, fdError
= 0;
686 PIXEL_TYPE
*pRow
= NULL
;
687 GLint dPRowOuter
= 0, dPRowInner
; /* offset in bytes */
691 DEPTH_TYPE
*zRow
= NULL
;
692 GLint dZRowOuter
= 0, dZRowInner
; /* offset in bytes */
694 GLfixed zLeft
= 0, fdzOuter
= 0, fdzInner
;
697 GLfloat wLeft
= 0, dwOuter
= 0, dwInner
;
700 GLfloat fogLeft
= 0, dfogOuter
= 0, dfogInner
;
703 ColorTemp rLeft
= 0, fdrOuter
= 0, fdrInner
;
704 ColorTemp gLeft
= 0, fdgOuter
= 0, fdgInner
;
705 ColorTemp bLeft
= 0, fdbOuter
= 0, fdbInner
;
708 ColorTemp aLeft
= 0, fdaOuter
= 0, fdaInner
;
711 ColorTemp srLeft
=0, dsrOuter
=0, dsrInner
;
712 ColorTemp sgLeft
=0, dsgOuter
=0, dsgInner
;
713 ColorTemp sbLeft
=0, dsbOuter
=0, dsbInner
;
716 GLfixed iLeft
=0, diOuter
=0, diInner
;
718 #ifdef INTERP_INT_TEX
719 GLfixed sLeft
=0, dsOuter
=0, dsInner
;
720 GLfixed tLeft
=0, dtOuter
=0, dtInner
;
723 GLfloat sLeft
[MAX_TEXTURE_COORD_UNITS
];
724 GLfloat tLeft
[MAX_TEXTURE_COORD_UNITS
];
725 GLfloat uLeft
[MAX_TEXTURE_COORD_UNITS
];
726 GLfloat vLeft
[MAX_TEXTURE_COORD_UNITS
];
727 GLfloat dsOuter
[MAX_TEXTURE_COORD_UNITS
], dsInner
[MAX_TEXTURE_COORD_UNITS
];
728 GLfloat dtOuter
[MAX_TEXTURE_COORD_UNITS
], dtInner
[MAX_TEXTURE_COORD_UNITS
];
729 GLfloat duOuter
[MAX_TEXTURE_COORD_UNITS
], duInner
[MAX_TEXTURE_COORD_UNITS
];
730 GLfloat dvOuter
[MAX_TEXTURE_COORD_UNITS
], dvInner
[MAX_TEXTURE_COORD_UNITS
];
733 for (subTriangle
=0; subTriangle
<=1; subTriangle
++) {
734 EdgeT
*eLeft
, *eRight
;
735 int setupLeft
, setupRight
;
738 if (subTriangle
==0) {
740 if (scan_from_left_to_right
) {
743 lines
= eRight
->lines
;
750 lines
= eLeft
->lines
;
757 if (scan_from_left_to_right
) {
760 lines
= eRight
->lines
;
767 lines
= eLeft
->lines
;
775 if (setupLeft
&& eLeft
->lines
> 0) {
776 const SWvertex
*vLower
= eLeft
->v0
;
777 #if TRIANGLE_WALK_DOUBLE
778 const GLdouble fsy
= eLeft
->fsy
;
779 const GLdouble fsx
= eLeft
->fsx
;
780 const GLdouble fx
= CEILF(fsx
);
781 const GLdouble adjx
= (fx
- eLeft
->fx0
) * FIXED_SCALE
; /* SCALED! */
783 const GLfixed fsy
= eLeft
->fsy
;
784 const GLfixed fsx
= eLeft
->fsx
; /* no fractional part */
785 const GLfixed fx
= FixedCeil(fsx
); /* no fractional part */
786 const GLfixed adjx
= (GLinterp
) (fx
- eLeft
->fx0
); /* SCALED! */
788 const GLinterp adjy
= eLeft
->adjy
; /* SCALED! */
790 #if TRIANGLE_WALK_DOUBLE
793 fError
= fx
- fsx
- 1.0;
795 fdxLeftEdge
= eLeft
->dxdy
;
796 dxOuter
= FLOORF(fdxLeftEdge
);
797 fdError
= dxOuter
- fdxLeftEdge
+ 1.0;
798 idxOuter
= (GLint
) dxOuter
;
799 span
.y
= (GLint
) fsy
;
804 fError
= fx
- fsx
- FIXED_ONE
;
805 fxLeftEdge
= fsx
- FIXED_EPSILON
;
806 fdxLeftEdge
= eLeft
->fdxdy
;
807 fdxOuter
= FixedFloor(fdxLeftEdge
- FIXED_EPSILON
);
808 fdError
= fdxOuter
- fdxLeftEdge
+ FIXED_ONE
;
809 idxOuter
= FixedToInt(fdxOuter
);
810 dxOuter
= (GLfloat
) idxOuter
;
811 span
.y
= FixedToInt(fsy
);
814 /* silence warnings on some compilers */
822 pRow
= (PIXEL_TYPE
*) PIXEL_ADDRESS(InterpToInt(fxLeftEdge
), span
.y
);
823 dPRowOuter
= -((int)BYTES_PER_ROW
) + idxOuter
* sizeof(PIXEL_TYPE
);
824 /* negative because Y=0 at bottom and increases upward */
828 * Now we need the set of parameter (z, color, etc.) values at
829 * the point (fx, fsy). This gives us properly-sampled parameter
830 * values that we can step from pixel to pixel. Furthermore,
831 * although we might have intermediate results that overflow
832 * the normal parameter range when we step temporarily outside
833 * the triangle, we shouldn't overflow or underflow for any
834 * pixel that's actually inside the triangle.
839 GLfloat z0
= vLower
->win
[2];
840 if (depthBits
<= 16) {
841 /* interpolate fixed-pt values */
842 GLfloat tmp
= (z0
* FIXED_SCALE
+ span
.dzdx
* adjx
+ span
.dzdy
* adjy
) + FIXED_HALF
;
843 if (tmp
< MAX_GLUINT
/ 2)
844 zLeft
= (GLfixed
) tmp
;
846 zLeft
= MAX_GLUINT
/ 2;
847 fdzOuter
= SignedFloatToFixed(span
.dzdy
+ dxOuter
* span
.dzdx
);
850 /* interpolate depth values exactly */
851 zLeft
= (GLint
) (z0
+ span
.dzdx
* FixedToFloat(adjx
) + span
.dzdy
* FixedToFloat(adjy
));
852 fdzOuter
= (GLint
) (span
.dzdy
+ dxOuter
* span
.dzdx
);
855 zRow
= (DEPTH_TYPE
*)
856 _swrast_zbuffer_address(ctx
, InterpToInt(fxLeftEdge
), span
.y
);
857 dZRowOuter
= (ctx
->DrawBuffer
->Width
+ idxOuter
) * sizeof(DEPTH_TYPE
);
862 wLeft
= vLower
->win
[3] + (span
.dwdx
* adjx
+ span
.dwdy
* adjy
) * (1.0F
/FIXED_SCALE
);
863 dwOuter
= span
.dwdy
+ dxOuter
* span
.dwdx
;
867 fogLeft
= vLower
->fog
* vLower
->win
[3] + (span
.dfogdx
* adjx
+ span
.dfogdy
* adjy
) * (1.0F
/FIXED_SCALE
);
869 fogLeft
= vLower
->fog
+ (span
.dfogdx
* adjx
+ span
.dfogdy
* adjy
) * (1.0F
/FIXED_SCALE
);
871 dfogOuter
= span
.dfogdy
+ dxOuter
* span
.dfogdx
;
874 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
875 # if CHAN_TYPE == GL_FLOAT
876 rLeft
= vLower
->color
[RCOMP
] + (span
.drdx
* adjx
+ span
.drdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
877 gLeft
= vLower
->color
[GCOMP
] + (span
.dgdx
* adjx
+ span
.dgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
878 bLeft
= vLower
->color
[BCOMP
] + (span
.dbdx
* adjx
+ span
.dbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
879 fdrOuter
= span
.drdy
+ dxOuter
* span
.drdx
;
880 fdgOuter
= span
.dgdy
+ dxOuter
* span
.dgdx
;
881 fdbOuter
= span
.dbdy
+ dxOuter
* span
.dbdx
;
883 rLeft
= (GLint
)(ChanToFixed(vLower
->color
[RCOMP
]) + span
.drdx
* adjx
+ span
.drdy
* adjy
) + FIXED_HALF
;
884 gLeft
= (GLint
)(ChanToFixed(vLower
->color
[GCOMP
]) + span
.dgdx
* adjx
+ span
.dgdy
* adjy
) + FIXED_HALF
;
885 bLeft
= (GLint
)(ChanToFixed(vLower
->color
[BCOMP
]) + span
.dbdx
* adjx
+ span
.dbdy
* adjy
) + FIXED_HALF
;
886 fdrOuter
= SignedFloatToFixed(span
.drdy
+ dxOuter
* span
.drdx
);
887 fdgOuter
= SignedFloatToFixed(span
.dgdy
+ dxOuter
* span
.dgdx
);
888 fdbOuter
= SignedFloatToFixed(span
.dbdy
+ dxOuter
* span
.dbdx
);
891 # if CHAN_TYPE == GL_FLOAT
892 aLeft
= vLower
->color
[ACOMP
] + (span
.dadx
* adjx
+ span
.dady
* adjy
) * (1.0F
/ FIXED_SCALE
);
893 fdaOuter
= span
.dady
+ dxOuter
* span
.dadx
;
895 aLeft
= (GLint
)(ChanToFixed(vLower
->color
[ACOMP
]) + span
.dadx
* adjx
+ span
.dady
* adjy
) + FIXED_HALF
;
896 fdaOuter
= SignedFloatToFixed(span
.dady
+ dxOuter
* span
.dadx
);
901 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
902 # if CHAN_TYPE == GL_FLOAT
903 rLeft
= v2
->color
[RCOMP
];
904 gLeft
= v2
->color
[GCOMP
];
905 bLeft
= v2
->color
[BCOMP
];
906 fdrOuter
= fdgOuter
= fdbOuter
= 0.0F
;
908 rLeft
= ChanToFixed(v2
->color
[RCOMP
]);
909 gLeft
= ChanToFixed(v2
->color
[GCOMP
]);
910 bLeft
= ChanToFixed(v2
->color
[BCOMP
]);
911 fdrOuter
= fdgOuter
= fdbOuter
= 0;
914 # if CHAN_TYPE == GL_FLOAT
915 aLeft
= v2
->color
[ACOMP
];
918 aLeft
= ChanToFixed(v2
->color
[ACOMP
]);
926 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
927 # if CHAN_TYPE == GL_FLOAT
928 srLeft
= vLower
->specular
[RCOMP
] + (span
.dsrdx
* adjx
+ span
.dsrdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
929 sgLeft
= vLower
->specular
[GCOMP
] + (span
.dsgdx
* adjx
+ span
.dsgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
930 sbLeft
= vLower
->specular
[BCOMP
] + (span
.dsbdx
* adjx
+ span
.dsbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
931 dsrOuter
= span
.dsrdy
+ dxOuter
* span
.dsrdx
;
932 dsgOuter
= span
.dsgdy
+ dxOuter
* span
.dsgdx
;
933 dsbOuter
= span
.dsbdy
+ dxOuter
* span
.dsbdx
;
935 srLeft
= (GLfixed
) (ChanToFixed(vLower
->specular
[RCOMP
]) + span
.dsrdx
* adjx
+ span
.dsrdy
* adjy
) + FIXED_HALF
;
936 sgLeft
= (GLfixed
) (ChanToFixed(vLower
->specular
[GCOMP
]) + span
.dsgdx
* adjx
+ span
.dsgdy
* adjy
) + FIXED_HALF
;
937 sbLeft
= (GLfixed
) (ChanToFixed(vLower
->specular
[BCOMP
]) + span
.dsbdx
* adjx
+ span
.dsbdy
* adjy
) + FIXED_HALF
;
938 dsrOuter
= SignedFloatToFixed(span
.dsrdy
+ dxOuter
* span
.dsrdx
);
939 dsgOuter
= SignedFloatToFixed(span
.dsgdy
+ dxOuter
* span
.dsgdx
);
940 dsbOuter
= SignedFloatToFixed(span
.dsbdy
+ dxOuter
* span
.dsbdx
);
944 #if CHAN_TYPE == GL_FLOAT
945 srLeft
= v2
->specular
[RCOMP
];
946 sgLeft
= v2
->specular
[GCOMP
];
947 sbLeft
= v2
->specular
[BCOMP
];
948 dsrOuter
= dsgOuter
= dsbOuter
= 0.0F
;
950 srLeft
= ChanToFixed(v2
->specular
[RCOMP
]);
951 sgLeft
= ChanToFixed(v2
->specular
[GCOMP
]);
952 sbLeft
= ChanToFixed(v2
->specular
[BCOMP
]);
953 dsrOuter
= dsgOuter
= dsbOuter
= 0;
959 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
960 iLeft
= (GLfixed
)(vLower
->index
* FIXED_SCALE
961 + didx
* adjx
+ didy
* adjy
) + FIXED_HALF
;
962 diOuter
= SignedFloatToFixed(didy
+ dxOuter
* didx
);
965 iLeft
= FloatToFixed(v2
->index
);
969 #ifdef INTERP_INT_TEX
972 s0
= vLower
->texcoord
[0][0] * S_SCALE
;
973 sLeft
= (GLfixed
)(s0
* FIXED_SCALE
+ span
.texStepX
[0][0] * adjx
974 + span
.texStepY
[0][0] * adjy
) + FIXED_HALF
;
975 dsOuter
= SignedFloatToFixed(span
.texStepY
[0][0] + dxOuter
* span
.texStepX
[0][0]);
977 t0
= vLower
->texcoord
[0][1] * T_SCALE
;
978 tLeft
= (GLfixed
)(t0
* FIXED_SCALE
+ span
.texStepX
[0][1] * adjx
979 + span
.texStepY
[0][1] * adjy
) + FIXED_HALF
;
980 dtOuter
= SignedFloatToFixed(span
.texStepY
[0][1] + dxOuter
* span
.texStepX
[0][1]);
985 const GLfloat invW
= vLower
->win
[3];
986 const GLfloat s0
= vLower
->texcoord
[u
][0] * invW
;
987 const GLfloat t0
= vLower
->texcoord
[u
][1] * invW
;
988 const GLfloat u0
= vLower
->texcoord
[u
][2] * invW
;
989 const GLfloat v0
= vLower
->texcoord
[u
][3] * invW
;
990 sLeft
[u
] = s0
+ (span
.texStepX
[u
][0] * adjx
+ span
.texStepY
[u
][0] * adjy
) * (1.0F
/FIXED_SCALE
);
991 tLeft
[u
] = t0
+ (span
.texStepX
[u
][1] * adjx
+ span
.texStepY
[u
][1] * adjy
) * (1.0F
/FIXED_SCALE
);
992 uLeft
[u
] = u0
+ (span
.texStepX
[u
][2] * adjx
+ span
.texStepY
[u
][2] * adjy
) * (1.0F
/FIXED_SCALE
);
993 vLeft
[u
] = v0
+ (span
.texStepX
[u
][3] * adjx
+ span
.texStepY
[u
][3] * adjy
) * (1.0F
/FIXED_SCALE
);
994 dsOuter
[u
] = span
.texStepY
[u
][0] + dxOuter
* span
.texStepX
[u
][0];
995 dtOuter
[u
] = span
.texStepY
[u
][1] + dxOuter
* span
.texStepX
[u
][1];
996 duOuter
[u
] = span
.texStepY
[u
][2] + dxOuter
* span
.texStepX
[u
][2];
997 dvOuter
[u
] = span
.texStepY
[u
][3] + dxOuter
* span
.texStepX
[u
][3];
1003 if (setupRight
&& eRight
->lines
>0) {
1004 #if TRIANGLE_WALK_DOUBLE
1005 fxRightEdge
= eRight
->fsx
;
1006 fdxRightEdge
= eRight
->dxdy
;
1008 fxRightEdge
= eRight
->fsx
- FIXED_EPSILON
;
1009 fdxRightEdge
= eRight
->fdxdy
;
1018 /* Rasterize setup */
1019 #ifdef PIXEL_ADDRESS
1020 dPRowInner
= dPRowOuter
+ sizeof(PIXEL_TYPE
);
1024 dZRowInner
= dZRowOuter
+ sizeof(DEPTH_TYPE
);
1026 fdzInner
= fdzOuter
+ span
.zStep
;
1029 dwInner
= dwOuter
+ span
.dwdx
;
1032 dfogInner
= dfogOuter
+ span
.dfogdx
;
1035 fdrInner
= fdrOuter
+ span
.redStep
;
1036 fdgInner
= fdgOuter
+ span
.greenStep
;
1037 fdbInner
= fdbOuter
+ span
.blueStep
;
1040 fdaInner
= fdaOuter
+ span
.alphaStep
;
1043 dsrInner
= dsrOuter
+ span
.specRedStep
;
1044 dsgInner
= dsgOuter
+ span
.specGreenStep
;
1045 dsbInner
= dsbOuter
+ span
.specBlueStep
;
1048 diInner
= diOuter
+ span
.indexStep
;
1050 #ifdef INTERP_INT_TEX
1051 dsInner
= dsOuter
+ span
.intTexStep
[0];
1052 dtInner
= dtOuter
+ span
.intTexStep
[1];
1056 dsInner
[u
] = dsOuter
[u
] + span
.texStepX
[u
][0];
1057 dtInner
[u
] = dtOuter
[u
] + span
.texStepX
[u
][1];
1058 duInner
[u
] = duOuter
[u
] + span
.texStepX
[u
][2];
1059 dvInner
[u
] = dvOuter
[u
] + span
.texStepX
[u
][3];
1064 /* initialize the span interpolants to the leftmost value */
1065 /* ff = fixed-pt fragment */
1066 const GLint right
= InterpToInt(fxRightEdge
);
1067 span
.x
= InterpToInt(fxLeftEdge
);
1069 if (right
<= span
.x
)
1072 span
.end
= right
- span
.x
;
1092 span
.specRed
= srLeft
;
1093 span
.specGreen
= sgLeft
;
1094 span
.specBlue
= sbLeft
;
1099 #ifdef INTERP_INT_TEX
1100 span
.intTex
[0] = sLeft
;
1101 span
.intTex
[1] = tLeft
;
1106 span
.tex
[u
][0] = sLeft
[u
];
1107 span
.tex
[u
][1] = tLeft
[u
];
1108 span
.tex
[u
][2] = uLeft
[u
];
1109 span
.tex
[u
][3] = vLeft
[u
];
1114 /* Under rare circumstances, we might have to fudge the
1115 * colors. XXX does this really happen anymore???
1117 const GLint len
= span
.end
- 1;
1121 GLfixed ffrend
= span
.red
+ len
* span
.redStep
;
1122 GLfixed ffgend
= span
.green
+ len
* span
.greenStep
;
1123 GLfixed ffbend
= span
.blue
+ len
* span
.blueStep
;
1130 span
.green
-= ffgend
;
1135 span
.blue
-= ffbend
;
1143 GLfixed ffaend
= span
.alpha
+ len
* span
.alphaStep
;
1145 span
.alpha
-= ffaend
;
1153 GLfixed ffsrend
= span
.specRed
+ len
* span
.specRedStep
;
1154 GLfixed ffsgend
= span
.specGreen
+ len
* span
.specGreenStep
;
1155 GLfixed ffsbend
= span
.specBlue
+ len
* span
.specBlueStep
;
1157 span
.specRed
-= ffsrend
;
1158 if (span
.specRed
< 0)
1162 span
.specGreen
-= ffsgend
;
1163 if (span
.specGreen
< 0)
1167 span
.specBlue
-= ffsbend
;
1168 if (span
.specBlue
< 0)
1177 } /* span.end > 1 */
1179 /* This is where we actually generate fragments */
1181 RENDER_SPAN( span
);
1185 * Advance to the next scan line. Compute the
1186 * new edge coordinates, and adjust the
1187 * pixel-center x coordinate so that it stays
1188 * on or inside the major edge.
1193 fxLeftEdge
+= fdxLeftEdge
;
1194 fxRightEdge
+= fdxRightEdge
;
1198 fError
-= INTERP_ONE
;
1200 #ifdef PIXEL_ADDRESS
1201 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowOuter
);
1205 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowOuter
);
1213 fogLeft
+= dfogOuter
;
1231 #ifdef INTERP_INT_TEX
1237 sLeft
[u
] += dsOuter
[u
];
1238 tLeft
[u
] += dtOuter
[u
];
1239 uLeft
[u
] += duOuter
[u
];
1240 vLeft
[u
] += dvOuter
[u
];
1245 #ifdef PIXEL_ADDRESS
1246 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowInner
);
1250 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowInner
);
1258 fogLeft
+= dfogInner
;
1276 #ifdef INTERP_INT_TEX
1282 sLeft
[u
] += dsInner
[u
];
1283 tLeft
[u
] += dtInner
[u
];
1284 uLeft
[u
] += duInner
[u
];
1285 vLeft
[u
] += dvInner
[u
];
1291 } /* for subTriangle */
1305 #undef BYTES_PER_ROW
1306 #undef PIXEL_ADDRESS
1315 #undef INTERP_INT_TEX
1317 #undef INTERP_MULTITEX
1318 #undef TEX_UNIT_LOOP