1 /* $Id: s_tritemp.h,v 1.42 2003/01/14 04:55:46 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
26 /* $XFree86: xc/extras/Mesa/src/swrast/s_tritemp.h,v 1.2 2002/02/27 21:07:54 tsi Exp $ */
29 * Triangle Rasterizer Template
31 * This file is #include'd to generate custom triangle rasterizers.
33 * The following macros may be defined to indicate what auxillary information
34 * must be interplated across the triangle:
35 * INTERP_Z - if defined, interpolate Z values
36 * INTERP_FOG - if defined, interpolate fog values
37 * INTERP_RGB - if defined, interpolate RGB values
38 * INTERP_ALPHA - if defined, interpolate Alpha values (req's INTERP_RGB)
39 * INTERP_SPEC - if defined, interpolate specular RGB values
40 * INTERP_INDEX - if defined, interpolate color index values
41 * INTERP_INT_TEX - if defined, interpolate integer ST texcoords
42 * (fast, simple 2-D texture mapping)
43 * INTERP_TEX - if defined, interpolate set 0 float STRQ texcoords
44 * NOTE: OpenGL STRQ = Mesa STUV (R was taken for red)
45 * INTERP_MULTITEX - if defined, interpolate N units of STRQ texcoords
46 * INTERP_FLOAT_RGBA - if defined, interpolate RGBA with floating point
47 * INTERP_FLOAT_SPEC - if defined, interpolate specular with floating point
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.
57 * Similarly, for direct depth buffer access, this type is used for depth
59 * DEPTH_TYPE - either GLushort or GLuint
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
65 * The following macro MUST be defined:
66 * RENDER_SPAN(span) - code to write a span of pixels.
68 * This code was designed for the origin to be in the lower-left corner.
70 * Inspired by triangle rasterizer code written by Allen Akin. Thanks Allen!
75 * This is a bit of a hack, but it's a centralized place to enable floating-
76 * point color interpolation when GLchan is actually floating point.
78 #if CHAN_TYPE == GL_FLOAT
80 #if defined(INTERP_RGB)
83 #define INTERP_FLOAT_RGBA
86 #if defined(INTERP_SPEC)
88 #define INTERP_FLOAT_SPEC
91 #endif /* CHAN_TYPE == GL_FLOAT */
95 static void NAME(GLcontext
*ctx
, const SWvertex
*v0
,
100 const SWvertex
*v0
, *v1
; /* Y(v0) < Y(v1) */
101 GLfloat dx
; /* X(v1) - X(v0) */
102 GLfloat dy
; /* Y(v1) - Y(v0) */
103 GLfixed fdxdy
; /* dx/dy in fixed-point */
104 GLfixed fsx
; /* first sample point x coord */
106 GLfloat adjy
; /* adjust from v[0]->fy to fsy, scaled */
107 GLint lines
; /* number of lines to be sampled on this edge */
108 GLfixed fx0
; /* fixed pt X of lower endpoint */
112 const GLint depthBits
= ctx
->Visual
.depthBits
;
113 const GLint fixedToDepthShift
= depthBits
<= 16 ? FIXED_SHIFT
: 0;
114 const GLfloat maxDepth
= ctx
->DepthMaxF
;
115 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
117 EdgeT eMaj
, eTop
, eBot
;
119 const SWvertex
*vMin
, *vMid
, *vMax
; /* Y(vMin)<=Y(vMid)<=Y(vMax) */
120 float bf
= SWRAST_CONTEXT(ctx
)->_backface_sign
;
121 const GLint snapMask
= ~((FIXED_ONE
/ (1 << SUB_PIXEL_BITS
)) - 1); /* for x/y coord snapping */
122 GLfixed vMin_fx
, vMin_fy
, vMid_fx
, vMid_fy
, vMax_fx
, vMax_fy
;
126 INIT_SPAN(span
, GL_POLYGON
, 0, 0, 0);
129 (void) fixedToDepthShift
;
133 printf("%s()\n", __FUNCTION__);
134 printf(" %g, %g, %g\n", v0->win[0], v0->win[1], v0->win[2]);
135 printf(" %g, %g, %g\n", v1->win[0], v1->win[1], v1->win[2]);
136 printf(" %g, %g, %g\n", v2->win[0], v2->win[1], v2->win[2]);
139 /* Compute fixed point x,y coords w/ half-pixel offsets and snapping.
140 * And find the order of the 3 vertices along the Y axis.
143 const GLfixed fy0
= FloatToFixed(v0
->win
[1] - 0.5F
) & snapMask
;
144 const GLfixed fy1
= FloatToFixed(v1
->win
[1] - 0.5F
) & snapMask
;
145 const GLfixed fy2
= FloatToFixed(v2
->win
[1] - 0.5F
) & snapMask
;
150 vMin
= v0
; vMid
= v1
; vMax
= v2
;
151 vMin_fy
= fy0
; vMid_fy
= fy1
; vMax_fy
= fy2
;
153 else if (fy2
<= fy0
) {
155 vMin
= v2
; vMid
= v0
; vMax
= v1
;
156 vMin_fy
= fy2
; vMid_fy
= fy0
; vMax_fy
= fy1
;
160 vMin
= v0
; vMid
= v2
; vMax
= v1
;
161 vMin_fy
= fy0
; vMid_fy
= fy2
; vMax_fy
= fy1
;
168 vMin
= v1
; vMid
= v0
; vMax
= v2
;
169 vMin_fy
= fy1
; vMid_fy
= fy0
; vMax_fy
= fy2
;
172 else if (fy2
<= fy1
) {
174 vMin
= v2
; vMid
= v1
; vMax
= v0
;
175 vMin_fy
= fy2
; vMid_fy
= fy1
; vMax_fy
= fy0
;
180 vMin
= v1
; vMid
= v2
; vMax
= v0
;
181 vMin_fy
= fy1
; vMid_fy
= fy2
; vMax_fy
= fy0
;
185 /* fixed point X coords */
186 vMin_fx
= FloatToFixed(vMin
->win
[0] + 0.5F
) & snapMask
;
187 vMid_fx
= FloatToFixed(vMid
->win
[0] + 0.5F
) & snapMask
;
188 vMax_fx
= FloatToFixed(vMax
->win
[0] + 0.5F
) & snapMask
;
191 /* vertex/edge relationship */
192 eMaj
.v0
= vMin
; eMaj
.v1
= vMax
; /*TODO: .v1's not needed */
193 eTop
.v0
= vMid
; eTop
.v1
= vMax
;
194 eBot
.v0
= vMin
; eBot
.v1
= vMid
;
196 /* compute deltas for each edge: vertex[upper] - vertex[lower] */
197 eMaj
.dx
= FixedToFloat(vMax_fx
- vMin_fx
);
198 eMaj
.dy
= FixedToFloat(vMax_fy
- vMin_fy
);
199 eTop
.dx
= FixedToFloat(vMax_fx
- vMid_fx
);
200 eTop
.dy
= FixedToFloat(vMax_fy
- vMid_fy
);
201 eBot
.dx
= FixedToFloat(vMid_fx
- vMin_fx
);
202 eBot
.dy
= FixedToFloat(vMid_fy
- vMin_fy
);
204 /* compute area, oneOverArea and perform backface culling */
206 const GLfloat area
= eMaj
.dx
* eBot
.dy
- eBot
.dx
* eMaj
.dy
;
208 /* Do backface culling */
212 if (IS_INF_OR_NAN(area
) || area
== 0.0F
)
215 oneOverArea
= 1.0F
/ area
;
218 #ifndef DO_OCCLUSION_TEST
219 ctx
->OcclusionResult
= GL_TRUE
;
221 span
.facing
= ctx
->_Facing
; /* for 2-sided stencil test */
223 /* Edge setup. For a triangle strip these could be reused... */
225 eMaj
.fsy
= FixedCeil(vMin_fy
);
226 eMaj
.lines
= FixedToInt(FixedCeil(vMax_fy
- eMaj
.fsy
));
227 if (eMaj
.lines
> 0) {
228 GLfloat dxdy
= eMaj
.dx
/ eMaj
.dy
;
229 eMaj
.fdxdy
= SignedFloatToFixed(dxdy
);
230 eMaj
.adjy
= (GLfloat
) (eMaj
.fsy
- vMin_fy
); /* SCALED! */
232 eMaj
.fsx
= eMaj
.fx0
+ (GLfixed
) (eMaj
.adjy
* dxdy
);
238 eTop
.fsy
= FixedCeil(vMid_fy
);
239 eTop
.lines
= FixedToInt(FixedCeil(vMax_fy
- eTop
.fsy
));
240 if (eTop
.lines
> 0) {
241 GLfloat dxdy
= eTop
.dx
/ eTop
.dy
;
242 eTop
.fdxdy
= SignedFloatToFixed(dxdy
);
243 eTop
.adjy
= (GLfloat
) (eTop
.fsy
- vMid_fy
); /* SCALED! */
245 eTop
.fsx
= eTop
.fx0
+ (GLfixed
) (eTop
.adjy
* dxdy
);
248 eBot
.fsy
= FixedCeil(vMin_fy
);
249 eBot
.lines
= FixedToInt(FixedCeil(vMid_fy
- eBot
.fsy
));
250 if (eBot
.lines
> 0) {
251 GLfloat dxdy
= eBot
.dx
/ eBot
.dy
;
252 eBot
.fdxdy
= SignedFloatToFixed(dxdy
);
253 eBot
.adjy
= (GLfloat
) (eBot
.fsy
- vMin_fy
); /* SCALED! */
255 eBot
.fsx
= eBot
.fx0
+ (GLfixed
) (eBot
.adjy
* dxdy
);
260 * Conceptually, we view a triangle as two subtriangles
261 * separated by a perfectly horizontal line. The edge that is
262 * intersected by this line is one with maximal absolute dy; we
263 * call it a ``major'' edge. The other two edges are the
264 * ``top'' edge (for the upper subtriangle) and the ``bottom''
265 * edge (for the lower subtriangle). If either of these two
266 * edges is horizontal or very close to horizontal, the
267 * corresponding subtriangle might cover zero sample points;
268 * we take care to handle such cases, for performance as well
271 * By stepping rasterization parameters along the major edge,
272 * we can avoid recomputing them at the discontinuity where
273 * the top and bottom edges meet. However, this forces us to
274 * be able to scan both left-to-right and right-to-left.
275 * Also, we must determine whether the major edge is at the
276 * left or right side of the triangle. We do this by
277 * computing the magnitude of the cross-product of the major
278 * and top edges. Since this magnitude depends on the sine of
279 * the angle between the two edges, its sign tells us whether
280 * we turn to the left or to the right when travelling along
281 * the major edge to the top edge, and from this we infer
282 * whether the major edge is on the left or the right.
284 * Serendipitously, this cross-product magnitude is also a
285 * value we need to compute the iteration parameter
286 * derivatives for the triangle, and it can be used to perform
287 * backface culling because its sign tells us whether the
288 * triangle is clockwise or counterclockwise. In this code we
289 * refer to it as ``area'' because it's also proportional to
290 * the pixel area of the triangle.
294 GLint scan_from_left_to_right
; /* true if scanning left-to-right */
301 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
306 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
309 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
310 GLfloat dsrdx
, dsrdy
;
311 GLfloat dsgdx
, dsgdy
;
312 GLfloat dsbdx
, dsbdy
;
317 #ifdef INTERP_INT_TEX
327 #ifdef INTERP_MULTITEX
328 GLfloat dsdx
[MAX_TEXTURE_COORD_UNITS
], dsdy
[MAX_TEXTURE_COORD_UNITS
];
329 GLfloat dtdx
[MAX_TEXTURE_COORD_UNITS
], dtdy
[MAX_TEXTURE_COORD_UNITS
];
330 GLfloat dudx
[MAX_TEXTURE_COORD_UNITS
], dudy
[MAX_TEXTURE_COORD_UNITS
];
331 GLfloat dvdx
[MAX_TEXTURE_COORD_UNITS
], dvdy
[MAX_TEXTURE_COORD_UNITS
];
335 * Execute user-supplied setup code
341 scan_from_left_to_right
= (oneOverArea
< 0.0F
);
344 /* compute d?/dx and d?/dy derivatives */
346 span
.interpMask
|= SPAN_Z
;
348 GLfloat eMaj_dz
, eBot_dz
;
349 eMaj_dz
= vMax
->win
[2] - vMin
->win
[2];
350 eBot_dz
= vMid
->win
[2] - vMin
->win
[2];
351 dzdx
= oneOverArea
* (eMaj_dz
* eBot
.dy
- eMaj
.dy
* eBot_dz
);
352 if (dzdx
> maxDepth
|| dzdx
< -maxDepth
) {
353 /* probably a sliver triangle */
358 dzdy
= oneOverArea
* (eMaj
.dx
* eBot_dz
- eMaj_dz
* eBot
.dx
);
361 span
.zStep
= SignedFloatToFixed(dzdx
);
363 span
.zStep
= (GLint
) dzdx
;
367 span
.interpMask
|= SPAN_FOG
;
369 const GLfloat eMaj_dfog
= vMax
->fog
- vMin
->fog
;
370 const GLfloat eBot_dfog
= vMid
->fog
- vMin
->fog
;
371 span
.fogStep
= oneOverArea
* (eMaj_dfog
* eBot
.dy
- eMaj
.dy
* eBot_dfog
);
372 dfogdy
= oneOverArea
* (eMaj
.dx
* eBot_dfog
- eMaj_dfog
* eBot
.dx
);
376 span
.interpMask
|= SPAN_RGBA
;
377 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
378 GLfloat eMaj_dr
, eBot_dr
;
379 GLfloat eMaj_dg
, eBot_dg
;
380 GLfloat eMaj_db
, eBot_db
;
382 GLfloat eMaj_da
, eBot_da
;
384 eMaj_dr
= (GLfloat
) ((GLint
) vMax
->color
[RCOMP
] -
385 (GLint
) vMin
->color
[RCOMP
]);
386 eBot_dr
= (GLfloat
) ((GLint
) vMid
->color
[RCOMP
] -
387 (GLint
) vMin
->color
[RCOMP
]);
388 drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
389 span
.redStep
= SignedFloatToFixed(drdx
);
390 drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
391 eMaj_dg
= (GLfloat
) ((GLint
) vMax
->color
[GCOMP
] -
392 (GLint
) vMin
->color
[GCOMP
]);
393 eBot_dg
= (GLfloat
) ((GLint
) vMid
->color
[GCOMP
] -
394 (GLint
) vMin
->color
[GCOMP
]);
395 dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
396 span
.greenStep
= SignedFloatToFixed(dgdx
);
397 dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
398 eMaj_db
= (GLfloat
) ((GLint
) vMax
->color
[BCOMP
] -
399 (GLint
) vMin
->color
[BCOMP
]);
400 eBot_db
= (GLfloat
) ((GLint
) vMid
->color
[BCOMP
] -
401 (GLint
) vMin
->color
[BCOMP
]);
402 dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
403 span
.blueStep
= SignedFloatToFixed(dbdx
);
404 dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
406 eMaj_da
= (GLfloat
) ((GLint
) vMax
->color
[ACOMP
] -
407 (GLint
) vMin
->color
[ACOMP
]);
408 eBot_da
= (GLfloat
) ((GLint
) vMid
->color
[ACOMP
] -
409 (GLint
) vMin
->color
[ACOMP
]);
410 dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
411 span
.alphaStep
= SignedFloatToFixed(dadx
);
412 dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
416 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
417 span
.interpMask
|= SPAN_FLAT
;
430 #ifdef INTERP_FLOAT_RGBA
431 span
.interpMask
|= SPAN_RGBA
;
432 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
433 GLfloat eMaj_dr
, eBot_dr
;
434 GLfloat eMaj_dg
, eBot_dg
;
435 GLfloat eMaj_db
, eBot_db
;
436 GLfloat eMaj_da
, eBot_da
;
437 eMaj_dr
= vMax
->color
[RCOMP
] - vMin
->color
[RCOMP
];
438 eBot_dr
= vMid
->color
[RCOMP
] - vMin
->color
[RCOMP
];
439 drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
441 drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
442 eMaj_dg
= vMax
->color
[GCOMP
] - vMin
->color
[GCOMP
];
443 eBot_dg
= vMid
->color
[GCOMP
] - vMin
->color
[GCOMP
];
444 dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
445 span
.greenStep
= dgdx
;
446 dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
447 eMaj_db
= vMax
->color
[BCOMP
] - vMin
->color
[BCOMP
];
448 eBot_db
= vMid
->color
[BCOMP
] - vMin
->color
[BCOMP
];
449 dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
450 span
.blueStep
= dbdx
;
451 dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
452 eMaj_da
= vMax
->color
[ACOMP
] - vMin
->color
[ACOMP
];
453 eBot_da
= vMid
->color
[ACOMP
] - vMin
->color
[ACOMP
];
454 dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
455 span
.alphaStep
= dadx
;
456 dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
459 drdx
= drdy
= span
.redStep
= 0.0F
;
460 dgdx
= dgdy
= span
.greenStep
= 0.0F
;
461 dbdx
= dbdy
= span
.blueStep
= 0.0F
;
462 dadx
= dady
= span
.alphaStep
= 0.0F
;
466 span
.interpMask
|= SPAN_SPEC
;
467 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
468 GLfloat eMaj_dsr
, eBot_dsr
;
469 GLfloat eMaj_dsg
, eBot_dsg
;
470 GLfloat eMaj_dsb
, eBot_dsb
;
471 eMaj_dsr
= (GLfloat
) ((GLint
) vMax
->specular
[RCOMP
] -
472 (GLint
) vMin
->specular
[RCOMP
]);
473 eBot_dsr
= (GLfloat
) ((GLint
) vMid
->specular
[RCOMP
] -
474 (GLint
) vMin
->specular
[RCOMP
]);
475 dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
476 span
.specRedStep
= SignedFloatToFixed(dsrdx
);
477 dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
478 eMaj_dsg
= (GLfloat
) ((GLint
) vMax
->specular
[GCOMP
] -
479 (GLint
) vMin
->specular
[GCOMP
]);
480 eBot_dsg
= (GLfloat
) ((GLint
) vMid
->specular
[GCOMP
] -
481 (GLint
) vMin
->specular
[GCOMP
]);
482 dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
483 span
.specGreenStep
= SignedFloatToFixed(dsgdx
);
484 dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
485 eMaj_dsb
= (GLfloat
) ((GLint
) vMax
->specular
[BCOMP
] -
486 (GLint
) vMin
->specular
[BCOMP
]);
487 eBot_dsb
= (GLfloat
) ((GLint
) vMid
->specular
[BCOMP
] -
488 (GLint
) vMin
->specular
[BCOMP
]);
489 dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
490 span
.specBlueStep
= SignedFloatToFixed(dsbdx
);
491 dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
494 dsrdx
= dsrdy
= 0.0F
;
495 dsgdx
= dsgdy
= 0.0F
;
496 dsbdx
= dsbdy
= 0.0F
;
497 span
.specRedStep
= 0;
498 span
.specGreenStep
= 0;
499 span
.specBlueStep
= 0;
502 #ifdef INTERP_FLOAT_SPEC
503 span
.interpMask
|= SPAN_SPEC
;
504 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
505 GLfloat eMaj_dsr
, eBot_dsr
;
506 GLfloat eMaj_dsg
, eBot_dsg
;
507 GLfloat eMaj_dsb
, eBot_dsb
;
508 eMaj_dsr
= vMax
->specular
[RCOMP
] - vMin
->specular
[RCOMP
];
509 eBot_dsr
= vMid
->specular
[RCOMP
] - vMin
->specular
[RCOMP
];
510 dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
511 span
.specRedStep
= dsrdx
;
512 dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
513 eMaj_dsg
= vMax
->specular
[GCOMP
] - vMin
->specular
[GCOMP
];
514 eBot_dsg
= vMid
->specular
[GCOMP
] - vMin
->specular
[GCOMP
];
515 dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
516 span
.specGreenStep
= dsgdx
;
517 dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
518 eMaj_dsb
= vMax
->specular
[BCOMP
] - vMin
->specular
[BCOMP
];
519 eBot_dsb
= vMid
->specular
[BCOMP
] - vMin
->specular
[BCOMP
];
520 dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
521 span
.specBlueStep
= dsbdx
;
522 dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
525 dsrdx
= dsrdy
= span
.specRedStep
= 0;
526 dsgdx
= dsgdy
= span
.specGreenStep
= 0;
527 dsbdx
= dsbdy
= span
.specBlueStep
= 0;
531 span
.interpMask
|= SPAN_INDEX
;
532 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
533 GLfloat eMaj_di
, eBot_di
;
534 eMaj_di
= (GLfloat
) ((GLint
) vMax
->index
- (GLint
) vMin
->index
);
535 eBot_di
= (GLfloat
) ((GLint
) vMid
->index
- (GLint
) vMin
->index
);
536 didx
= oneOverArea
* (eMaj_di
* eBot
.dy
- eMaj
.dy
* eBot_di
);
537 span
.indexStep
= SignedFloatToFixed(didx
);
538 didy
= oneOverArea
* (eMaj
.dx
* eBot_di
- eMaj_di
* eBot
.dx
);
541 span
.interpMask
|= SPAN_FLAT
;
546 #ifdef INTERP_INT_TEX
547 span
.interpMask
|= SPAN_INT_TEXTURE
;
549 GLfloat eMaj_ds
, eBot_ds
;
550 eMaj_ds
= (vMax
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
551 eBot_ds
= (vMid
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
552 dsdx
= oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
553 span
.intTexStep
[0] = SignedFloatToFixed(dsdx
);
554 dsdy
= oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
557 GLfloat eMaj_dt
, eBot_dt
;
558 eMaj_dt
= (vMax
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
559 eBot_dt
= (vMid
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
560 dtdx
= oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
561 span
.intTexStep
[1] = SignedFloatToFixed(dtdx
);
562 dtdy
= oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
567 span
.interpMask
|= SPAN_TEXTURE
;
569 GLfloat wMax
= vMax
->win
[3];
570 GLfloat wMin
= vMin
->win
[3];
571 GLfloat wMid
= vMid
->win
[3];
572 GLfloat eMaj_ds
, eBot_ds
;
573 GLfloat eMaj_dt
, eBot_dt
;
574 GLfloat eMaj_du
, eBot_du
;
575 GLfloat eMaj_dv
, eBot_dv
;
577 eMaj_ds
= vMax
->texcoord
[0][0] * wMax
- vMin
->texcoord
[0][0] * wMin
;
578 eBot_ds
= vMid
->texcoord
[0][0] * wMid
- vMin
->texcoord
[0][0] * wMin
;
579 dsdx
= oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
580 dsdy
= oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
581 span
.texStepX
[0][0] = dsdx
;
582 span
.texStepY
[0][0] = dsdy
;
584 eMaj_dt
= vMax
->texcoord
[0][1] * wMax
- vMin
->texcoord
[0][1] * wMin
;
585 eBot_dt
= vMid
->texcoord
[0][1] * wMid
- vMin
->texcoord
[0][1] * wMin
;
586 dtdx
= oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
587 dtdy
= oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
588 span
.texStepX
[0][1] = dtdx
;
589 span
.texStepY
[0][1] = dtdy
;
591 eMaj_du
= vMax
->texcoord
[0][2] * wMax
- vMin
->texcoord
[0][2] * wMin
;
592 eBot_du
= vMid
->texcoord
[0][2] * wMid
- vMin
->texcoord
[0][2] * wMin
;
593 dudx
= oneOverArea
* (eMaj_du
* eBot
.dy
- eMaj
.dy
* eBot_du
);
594 dudy
= oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
595 span
.texStepX
[0][2] = dudx
;
596 span
.texStepY
[0][2] = dudy
;
598 eMaj_dv
= vMax
->texcoord
[0][3] * wMax
- vMin
->texcoord
[0][3] * wMin
;
599 eBot_dv
= vMid
->texcoord
[0][3] * wMid
- vMin
->texcoord
[0][3] * wMin
;
600 dvdx
= oneOverArea
* (eMaj_dv
* eBot
.dy
- eMaj
.dy
* eBot_dv
);
601 dvdy
= oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
602 span
.texStepX
[0][3] = dvdx
;
603 span
.texStepY
[0][3] = dvdy
;
606 #ifdef INTERP_MULTITEX
607 span
.interpMask
|= SPAN_TEXTURE
;
609 GLfloat wMax
= vMax
->win
[3];
610 GLfloat wMin
= vMin
->win
[3];
611 GLfloat wMid
= vMid
->win
[3];
613 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
614 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
615 GLfloat eMaj_ds
, eBot_ds
;
616 GLfloat eMaj_dt
, eBot_dt
;
617 GLfloat eMaj_du
, eBot_du
;
618 GLfloat eMaj_dv
, eBot_dv
;
619 eMaj_ds
= vMax
->texcoord
[u
][0] * wMax
620 - vMin
->texcoord
[u
][0] * wMin
;
621 eBot_ds
= vMid
->texcoord
[u
][0] * wMid
622 - vMin
->texcoord
[u
][0] * wMin
;
623 dsdx
[u
] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
624 dsdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
625 span
.texStepX
[u
][0] = dsdx
[u
];
626 span
.texStepY
[u
][0] = dsdy
[u
];
628 eMaj_dt
= vMax
->texcoord
[u
][1] * wMax
629 - vMin
->texcoord
[u
][1] * wMin
;
630 eBot_dt
= vMid
->texcoord
[u
][1] * wMid
631 - vMin
->texcoord
[u
][1] * wMin
;
632 dtdx
[u
] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
633 dtdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
634 span
.texStepX
[u
][1] = dtdx
[u
];
635 span
.texStepY
[u
][1] = dtdy
[u
];
637 eMaj_du
= vMax
->texcoord
[u
][2] * wMax
638 - vMin
->texcoord
[u
][2] * wMin
;
639 eBot_du
= vMid
->texcoord
[u
][2] * wMid
640 - vMin
->texcoord
[u
][2] * wMin
;
641 dudx
[u
] = oneOverArea
* (eMaj_du
* eBot
.dy
- eMaj
.dy
* eBot_du
);
642 dudy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
643 span
.texStepX
[u
][2] = dudx
[u
];
644 span
.texStepY
[u
][2] = dudy
[u
];
646 eMaj_dv
= vMax
->texcoord
[u
][3] * wMax
647 - vMin
->texcoord
[u
][3] * wMin
;
648 eBot_dv
= vMid
->texcoord
[u
][3] * wMid
649 - vMin
->texcoord
[u
][3] * wMin
;
650 dvdx
[u
] = oneOverArea
* (eMaj_dv
* eBot
.dy
- eMaj
.dy
* eBot_dv
);
651 dvdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
652 span
.texStepX
[u
][3] = dvdx
[u
];
653 span
.texStepY
[u
][3] = dvdy
[u
];
660 * We always sample at pixel centers. However, we avoid
661 * explicit half-pixel offsets in this code by incorporating
662 * the proper offset in each of x and y during the
663 * transformation to window coordinates.
665 * We also apply the usual rasterization rules to prevent
666 * cracks and overlaps. A pixel is considered inside a
667 * subtriangle if it meets all of four conditions: it is on or
668 * to the right of the left edge, strictly to the left of the
669 * right edge, on or below the top edge, and strictly above
670 * the bottom edge. (Some edges may be degenerate.)
672 * The following discussion assumes left-to-right scanning
673 * (that is, the major edge is on the left); the right-to-left
674 * case is a straightforward variation.
676 * We start by finding the half-integral y coordinate that is
677 * at or below the top of the triangle. This gives us the
678 * first scan line that could possibly contain pixels that are
679 * inside the triangle.
681 * Next we creep down the major edge until we reach that y,
682 * and compute the corresponding x coordinate on the edge.
683 * Then we find the half-integral x that lies on or just
684 * inside the edge. This is the first pixel that might lie in
685 * the interior of the triangle. (We won't know for sure
686 * until we check the other edges.)
688 * As we rasterize the triangle, we'll step down the major
689 * edge. For each step in y, we'll move an integer number
690 * of steps in x. There are two possible x step sizes, which
691 * we'll call the ``inner'' step (guaranteed to land on the
692 * edge or inside it) and the ``outer'' step (guaranteed to
693 * land on the edge or outside it). The inner and outer steps
694 * differ by one. During rasterization we maintain an error
695 * term that indicates our distance from the true edge, and
696 * select either the inner step or the outer step, whichever
697 * gets us to the first pixel that falls inside the triangle.
699 * All parameters (z, red, etc.) as well as the buffer
700 * addresses for color and z have inner and outer step values,
701 * so that we can increment them appropriately. This method
702 * eliminates the need to adjust parameters by creeping a
703 * sub-pixel amount into the triangle at each scanline.
709 GLfixed fxLeftEdge
= 0, fxRightEdge
= 0;
710 GLfixed fdxLeftEdge
= 0, fdxRightEdge
= 0;
714 GLfixed fError
= 0, fdError
= 0;
718 PIXEL_TYPE
*pRow
= NULL
;
719 int dPRowOuter
= 0, dPRowInner
; /* offset in bytes */
723 DEPTH_TYPE
*zRow
= NULL
;
724 int dZRowOuter
= 0, dZRowInner
; /* offset in bytes */
726 GLfixed fz
= 0, fdzOuter
= 0, fdzInner
;
729 GLfloat fogLeft
= 0, dfogOuter
= 0, dfogInner
;
732 GLfixed fr
= 0, fdrOuter
= 0, fdrInner
;
733 GLfixed fg
= 0, fdgOuter
= 0, fdgInner
;
734 GLfixed fb
= 0, fdbOuter
= 0, fdbInner
;
737 GLfixed fa
= 0, fdaOuter
= 0, fdaInner
;
739 #ifdef INTERP_FLOAT_RGBA
740 GLfloat fr
, fdrOuter
, fdrInner
;
741 GLfloat fg
, fdgOuter
, fdgInner
;
742 GLfloat fb
, fdbOuter
, fdbInner
;
743 GLfloat fa
, fdaOuter
, fdaInner
;
746 GLfixed fsr
=0, fdsrOuter
=0, fdsrInner
;
747 GLfixed fsg
=0, fdsgOuter
=0, fdsgInner
;
748 GLfixed fsb
=0, fdsbOuter
=0, fdsbInner
;
750 #ifdef INTERP_FLOAT_SPEC
751 GLfloat fsr
=0, fdsrOuter
=0, fdsrInner
;
752 GLfloat fsg
=0, fdsgOuter
=0, fdsgInner
;
753 GLfloat fsb
=0, fdsbOuter
=0, fdsbInner
;
756 GLfixed fi
=0, fdiOuter
=0, fdiInner
;
758 #ifdef INTERP_INT_TEX
759 GLfixed fs
=0, fdsOuter
=0, fdsInner
;
760 GLfixed ft
=0, fdtOuter
=0, fdtInner
;
763 GLfloat sLeft
=0, dsOuter
=0, dsInner
;
764 GLfloat tLeft
=0, dtOuter
=0, dtInner
;
765 GLfloat uLeft
=0, duOuter
=0, duInner
;
766 GLfloat vLeft
=0, dvOuter
=0, dvInner
;
768 #ifdef INTERP_MULTITEX
769 GLfloat sLeft
[MAX_TEXTURE_COORD_UNITS
];
770 GLfloat tLeft
[MAX_TEXTURE_COORD_UNITS
];
771 GLfloat uLeft
[MAX_TEXTURE_COORD_UNITS
];
772 GLfloat vLeft
[MAX_TEXTURE_COORD_UNITS
];
773 GLfloat dsOuter
[MAX_TEXTURE_COORD_UNITS
], dsInner
[MAX_TEXTURE_COORD_UNITS
];
774 GLfloat dtOuter
[MAX_TEXTURE_COORD_UNITS
], dtInner
[MAX_TEXTURE_COORD_UNITS
];
775 GLfloat duOuter
[MAX_TEXTURE_COORD_UNITS
], duInner
[MAX_TEXTURE_COORD_UNITS
];
776 GLfloat dvOuter
[MAX_TEXTURE_COORD_UNITS
], dvInner
[MAX_TEXTURE_COORD_UNITS
];
779 for (subTriangle
=0; subTriangle
<=1; subTriangle
++) {
780 EdgeT
*eLeft
, *eRight
;
781 int setupLeft
, setupRight
;
784 if (subTriangle
==0) {
786 if (scan_from_left_to_right
) {
789 lines
= eRight
->lines
;
796 lines
= eLeft
->lines
;
803 if (scan_from_left_to_right
) {
806 lines
= eRight
->lines
;
813 lines
= eLeft
->lines
;
821 if (setupLeft
&& eLeft
->lines
> 0) {
822 const SWvertex
*vLower
;
823 GLfixed fsx
= eLeft
->fsx
;
825 fError
= fx
- fsx
- FIXED_ONE
;
826 fxLeftEdge
= fsx
- FIXED_EPSILON
;
827 fdxLeftEdge
= eLeft
->fdxdy
;
828 fdxOuter
= FixedFloor(fdxLeftEdge
- FIXED_EPSILON
);
829 fdError
= fdxOuter
- fdxLeftEdge
+ FIXED_ONE
;
830 idxOuter
= FixedToInt(fdxOuter
);
831 dxOuter
= (float) idxOuter
;
835 span
.y
= FixedToInt(fy
);
837 adjx
= (float)(fx
- eLeft
->fx0
); /* SCALED! */
838 adjy
= eLeft
->adjy
; /* SCALED! */
839 (void) adjx
; /* silence compiler warnings */
840 (void) adjy
; /* silence compiler warnings */
843 (void) vLower
; /* silence compiler warnings */
847 pRow
= (PIXEL_TYPE
*) PIXEL_ADDRESS(FixedToInt(fxLeftEdge
), span
.y
);
848 dPRowOuter
= -((int)BYTES_PER_ROW
) + idxOuter
* sizeof(PIXEL_TYPE
);
849 /* negative because Y=0 at bottom and increases upward */
853 * Now we need the set of parameter (z, color, etc.) values at
854 * the point (fx, fy). This gives us properly-sampled parameter
855 * values that we can step from pixel to pixel. Furthermore,
856 * although we might have intermediate results that overflow
857 * the normal parameter range when we step temporarily outside
858 * the triangle, we shouldn't overflow or underflow for any
859 * pixel that's actually inside the triangle.
864 GLfloat z0
= vLower
->win
[2];
865 if (depthBits
<= 16) {
866 /* interpolate fixed-pt values */
867 GLfloat tmp
= (z0
* FIXED_SCALE
+
868 dzdx
* adjx
+ dzdy
* adjy
) + FIXED_HALF
;
869 if (tmp
< MAX_GLUINT
/ 2)
873 fdzOuter
= SignedFloatToFixed(dzdy
+ dxOuter
* dzdx
);
876 /* interpolate depth values exactly */
877 fz
= (GLint
) (z0
+ dzdx
* FixedToFloat(adjx
)
878 + dzdy
* FixedToFloat(adjy
));
879 fdzOuter
= (GLint
) (dzdy
+ dxOuter
* dzdx
);
882 zRow
= (DEPTH_TYPE
*)
883 _mesa_zbuffer_address(ctx
, FixedToInt(fxLeftEdge
), span
.y
);
884 dZRowOuter
= (ctx
->DrawBuffer
->Width
+ idxOuter
) * sizeof(DEPTH_TYPE
);
889 fogLeft
= vLower
->fog
+ (span
.fogStep
* adjx
+ dfogdy
* adjy
)
890 * (1.0F
/FIXED_SCALE
);
891 dfogOuter
= dfogdy
+ dxOuter
* span
.fogStep
;
894 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
895 fr
= (GLfixed
) (ChanToFixed(vLower
->color
[RCOMP
])
896 + drdx
* adjx
+ drdy
* adjy
) + FIXED_HALF
;
897 fdrOuter
= SignedFloatToFixed(drdy
+ dxOuter
* drdx
);
898 fg
= (GLfixed
) (ChanToFixed(vLower
->color
[GCOMP
])
899 + dgdx
* adjx
+ dgdy
* adjy
) + FIXED_HALF
;
900 fdgOuter
= SignedFloatToFixed(dgdy
+ dxOuter
* dgdx
);
901 fb
= (GLfixed
) (ChanToFixed(vLower
->color
[BCOMP
])
902 + dbdx
* adjx
+ dbdy
* adjy
) + FIXED_HALF
;
903 fdbOuter
= SignedFloatToFixed(dbdy
+ dxOuter
* dbdx
);
905 fa
= (GLfixed
) (ChanToFixed(vLower
->color
[ACOMP
])
906 + dadx
* adjx
+ dady
* adjy
) + FIXED_HALF
;
907 fdaOuter
= SignedFloatToFixed(dady
+ dxOuter
* dadx
);
911 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
912 fr
= ChanToFixed(v2
->color
[RCOMP
]);
913 fg
= ChanToFixed(v2
->color
[GCOMP
]);
914 fb
= ChanToFixed(v2
->color
[BCOMP
]);
915 fdrOuter
= fdgOuter
= fdbOuter
= 0;
917 fa
= ChanToFixed(v2
->color
[ACOMP
]);
922 #ifdef INTERP_FLOAT_RGBA
923 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
924 fr
= vLower
->color
[RCOMP
]
925 + (drdx
* adjx
+ drdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
926 fdrOuter
= drdy
+ dxOuter
* drdx
;
927 fg
= vLower
->color
[GCOMP
]
928 + (dgdx
* adjx
+ dgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
929 fdgOuter
= dgdy
+ dxOuter
* dgdx
;
930 fb
= vLower
->color
[BCOMP
]
931 + (dbdx
* adjx
+ dbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
932 fdbOuter
= dbdy
+ dxOuter
* dbdx
;
933 fa
= vLower
->color
[ACOMP
]
934 + (dadx
* adjx
+ dady
* adjy
) * (1.0F
/ FIXED_SCALE
);
935 fdaOuter
= dady
+ dxOuter
* dadx
;
938 fr
= v2
->color
[RCOMP
];
939 fg
= v2
->color
[GCOMP
];
940 fb
= v2
->color
[BCOMP
];
941 fa
= v2
->color
[ACOMP
];
942 fdrOuter
= fdgOuter
= fdbOuter
= fdaOuter
= 0.0F
;
946 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
947 fsr
= (GLfixed
) (ChanToFixed(vLower
->specular
[RCOMP
])
948 + dsrdx
* adjx
+ dsrdy
* adjy
) + FIXED_HALF
;
949 fdsrOuter
= SignedFloatToFixed(dsrdy
+ dxOuter
* dsrdx
);
950 fsg
= (GLfixed
) (ChanToFixed(vLower
->specular
[GCOMP
])
951 + dsgdx
* adjx
+ dsgdy
* adjy
) + FIXED_HALF
;
952 fdsgOuter
= SignedFloatToFixed(dsgdy
+ dxOuter
* dsgdx
);
953 fsb
= (GLfixed
) (ChanToFixed(vLower
->specular
[BCOMP
])
954 + dsbdx
* adjx
+ dsbdy
* adjy
) + FIXED_HALF
;
955 fdsbOuter
= SignedFloatToFixed(dsbdy
+ dxOuter
* dsbdx
);
958 fsr
= ChanToFixed(v2
->specular
[RCOMP
]);
959 fsg
= ChanToFixed(v2
->specular
[GCOMP
]);
960 fsb
= ChanToFixed(v2
->specular
[BCOMP
]);
961 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0;
964 #ifdef INTERP_FLOAT_SPEC
965 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
966 fsr
= vLower
->specular
[RCOMP
]
967 + (dsrdx
* adjx
+ dsrdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
968 fdsrOuter
= dsrdy
+ dxOuter
* dsrdx
;
969 fsg
= vLower
->specular
[GCOMP
]
970 + (dsgdx
* adjx
+ dsgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
971 fdsgOuter
= dsgdy
+ dxOuter
* dsgdx
;
972 fsb
= vLower
->specular
[BCOMP
]
973 + (dsbdx
* adjx
+ dsbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
974 fdsbOuter
= dsbdy
+ dxOuter
* dsbdx
;
977 fsr
= v2
->specular
[RCOMP
];
978 fsg
= v2
->specular
[GCOMP
];
979 fsb
= v2
->specular
[BCOMP
];
980 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0.0F
;
984 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
985 fi
= (GLfixed
)(vLower
->index
* FIXED_SCALE
986 + didx
* adjx
+ didy
* adjy
) + FIXED_HALF
;
987 fdiOuter
= SignedFloatToFixed(didy
+ dxOuter
* didx
);
990 fi
= (GLfixed
) (v2
->index
* FIXED_SCALE
);
994 #ifdef INTERP_INT_TEX
997 s0
= vLower
->texcoord
[0][0] * S_SCALE
;
998 fs
= (GLfixed
)(s0
* FIXED_SCALE
+ dsdx
* adjx
999 + dsdy
* adjy
) + FIXED_HALF
;
1000 fdsOuter
= SignedFloatToFixed(dsdy
+ dxOuter
* dsdx
);
1002 t0
= vLower
->texcoord
[0][1] * T_SCALE
;
1003 ft
= (GLfixed
)(t0
* FIXED_SCALE
+ dtdx
* adjx
1004 + dtdy
* adjy
) + FIXED_HALF
;
1005 fdtOuter
= SignedFloatToFixed(dtdy
+ dxOuter
* dtdx
);
1010 GLfloat invW
= vLower
->win
[3];
1011 GLfloat s0
, t0
, u0
, v0
;
1012 s0
= vLower
->texcoord
[0][0] * invW
;
1013 sLeft
= s0
+ (span
.texStepX
[0][0] * adjx
+ dsdy
* adjy
)
1014 * (1.0F
/FIXED_SCALE
);
1015 dsOuter
= dsdy
+ dxOuter
* span
.texStepX
[0][0];
1016 t0
= vLower
->texcoord
[0][1] * invW
;
1017 tLeft
= t0
+ (span
.texStepX
[0][1] * adjx
+ dtdy
* adjy
)
1018 * (1.0F
/FIXED_SCALE
);
1019 dtOuter
= dtdy
+ dxOuter
* span
.texStepX
[0][1];
1020 u0
= vLower
->texcoord
[0][2] * invW
;
1021 uLeft
= u0
+ (span
.texStepX
[0][2] * adjx
+ dudy
* adjy
)
1022 * (1.0F
/FIXED_SCALE
);
1023 duOuter
= dudy
+ dxOuter
* span
.texStepX
[0][2];
1024 v0
= vLower
->texcoord
[0][3] * invW
;
1025 vLeft
= v0
+ (span
.texStepX
[0][3] * adjx
+ dvdy
* adjy
)
1026 * (1.0F
/FIXED_SCALE
);
1027 dvOuter
= dvdy
+ dxOuter
* span
.texStepX
[0][3];
1030 #ifdef INTERP_MULTITEX
1033 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1034 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1035 GLfloat invW
= vLower
->win
[3];
1036 GLfloat s0
, t0
, u0
, v0
;
1037 s0
= vLower
->texcoord
[u
][0] * invW
;
1038 sLeft
[u
] = s0
+ (span
.texStepX
[u
][0] * adjx
+ dsdy
[u
]
1039 * adjy
) * (1.0F
/FIXED_SCALE
);
1040 dsOuter
[u
] = dsdy
[u
] + dxOuter
* span
.texStepX
[u
][0];
1041 t0
= vLower
->texcoord
[u
][1] * invW
;
1042 tLeft
[u
] = t0
+ (span
.texStepX
[u
][1] * adjx
+ dtdy
[u
]
1043 * adjy
) * (1.0F
/FIXED_SCALE
);
1044 dtOuter
[u
] = dtdy
[u
] + dxOuter
* span
.texStepX
[u
][1];
1045 u0
= vLower
->texcoord
[u
][2] * invW
;
1046 uLeft
[u
] = u0
+ (span
.texStepX
[u
][2] * adjx
+ dudy
[u
]
1047 * adjy
) * (1.0F
/FIXED_SCALE
);
1048 duOuter
[u
] = dudy
[u
] + dxOuter
* span
.texStepX
[u
][2];
1049 v0
= vLower
->texcoord
[u
][3] * invW
;
1050 vLeft
[u
] = v0
+ (span
.texStepX
[u
][3] * adjx
+ dvdy
[u
]
1051 * adjy
) * (1.0F
/FIXED_SCALE
);
1052 dvOuter
[u
] = dvdy
[u
] + dxOuter
* span
.texStepX
[u
][3];
1061 if (setupRight
&& eRight
->lines
>0) {
1062 fxRightEdge
= eRight
->fsx
- FIXED_EPSILON
;
1063 fdxRightEdge
= eRight
->fdxdy
;
1071 /* Rasterize setup */
1072 #ifdef PIXEL_ADDRESS
1073 dPRowInner
= dPRowOuter
+ sizeof(PIXEL_TYPE
);
1077 dZRowInner
= dZRowOuter
+ sizeof(DEPTH_TYPE
);
1079 fdzInner
= fdzOuter
+ span
.zStep
;
1082 dfogInner
= dfogOuter
+ span
.fogStep
;
1084 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1085 fdrInner
= fdrOuter
+ span
.redStep
;
1086 fdgInner
= fdgOuter
+ span
.greenStep
;
1087 fdbInner
= fdbOuter
+ span
.blueStep
;
1089 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1090 fdaInner
= fdaOuter
+ span
.alphaStep
;
1092 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1093 fdsrInner
= fdsrOuter
+ span
.specRedStep
;
1094 fdsgInner
= fdsgOuter
+ span
.specGreenStep
;
1095 fdsbInner
= fdsbOuter
+ span
.specBlueStep
;
1098 fdiInner
= fdiOuter
+ span
.indexStep
;
1100 #ifdef INTERP_INT_TEX
1101 fdsInner
= fdsOuter
+ span
.intTexStep
[0];
1102 fdtInner
= fdtOuter
+ span
.intTexStep
[1];
1105 dsInner
= dsOuter
+ span
.texStepX
[0][0];
1106 dtInner
= dtOuter
+ span
.texStepX
[0][1];
1107 duInner
= duOuter
+ span
.texStepX
[0][2];
1108 dvInner
= dvOuter
+ span
.texStepX
[0][3];
1110 #ifdef INTERP_MULTITEX
1113 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1114 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1115 dsInner
[u
] = dsOuter
[u
] + span
.texStepX
[u
][0];
1116 dtInner
[u
] = dtOuter
[u
] + span
.texStepX
[u
][1];
1117 duInner
[u
] = duOuter
[u
] + span
.texStepX
[u
][2];
1118 dvInner
[u
] = dvOuter
[u
] + span
.texStepX
[u
][3];
1125 /* initialize the span interpolants to the leftmost value */
1126 /* ff = fixed-pt fragment */
1127 const GLint right
= FixedToInt(fxRightEdge
);
1129 span
.x
= FixedToInt(fxLeftEdge
);
1131 if (right
<= span
.x
)
1134 span
.end
= right
- span
.x
;
1142 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1147 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1150 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1152 span
.specGreen
= fsg
;
1153 span
.specBlue
= fsb
;
1158 #ifdef INTERP_INT_TEX
1159 span
.intTex
[0] = fs
;
1160 span
.intTex
[1] = ft
;
1164 span
.tex
[0][0] = sLeft
;
1165 span
.tex
[0][1] = tLeft
;
1166 span
.tex
[0][2] = uLeft
;
1167 span
.tex
[0][3] = vLeft
;
1170 #ifdef INTERP_MULTITEX
1173 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1174 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1175 span
.tex
[u
][0] = sLeft
[u
];
1176 span
.tex
[u
][1] = tLeft
[u
];
1177 span
.tex
[u
][2] = uLeft
[u
];
1178 span
.tex
[u
][3] = vLeft
[u
];
1186 /* need this to accomodate round-off errors */
1187 const GLint len
= right
- span
.x
- 1;
1188 GLfixed ffrend
= span
.red
+ len
* span
.redStep
;
1189 GLfixed ffgend
= span
.green
+ len
* span
.greenStep
;
1190 GLfixed ffbend
= span
.blue
+ len
* span
.blueStep
;
1197 span
.green
-= ffgend
;
1202 span
.blue
-= ffbend
;
1210 const GLint len
= right
- span
.x
- 1;
1211 GLfixed ffaend
= span
.alpha
+ len
* span
.alphaStep
;
1213 span
.alpha
-= ffaend
;
1221 /* need this to accomodate round-off errors */
1222 const GLint len
= right
- span
.x
- 1;
1223 GLfixed ffsrend
= span
.specRed
+ len
* span
.specRedStep
;
1224 GLfixed ffsgend
= span
.specGreen
+ len
* span
.specGreenStep
;
1225 GLfixed ffsbend
= span
.specBlue
+ len
* span
.specBlueStep
;
1227 span
.specRed
-= ffsrend
;
1228 if (span
.specRed
< 0)
1232 span
.specGreen
-= ffsgend
;
1233 if (span
.specGreen
< 0)
1237 span
.specBlue
-= ffsbend
;
1238 if (span
.specBlue
< 0)
1244 if (span
.index
< 0) span
.index
= 0;
1247 /* This is where we actually generate fragments */
1249 RENDER_SPAN( span
);
1253 * Advance to the next scan line. Compute the
1254 * new edge coordinates, and adjust the
1255 * pixel-center x coordinate so that it stays
1256 * on or inside the major edge.
1261 fxLeftEdge
+= fdxLeftEdge
;
1262 fxRightEdge
+= fdxRightEdge
;
1267 fError
-= FIXED_ONE
;
1268 #ifdef PIXEL_ADDRESS
1269 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowOuter
);
1273 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowOuter
);
1278 fogLeft
+= dfogOuter
;
1280 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1285 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1288 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1296 #ifdef INTERP_INT_TEX
1306 #ifdef INTERP_MULTITEX
1309 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1310 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1311 sLeft
[u
] += dsOuter
[u
];
1312 tLeft
[u
] += dtOuter
[u
];
1313 uLeft
[u
] += duOuter
[u
];
1314 vLeft
[u
] += dvOuter
[u
];
1321 #ifdef PIXEL_ADDRESS
1322 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowInner
);
1326 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowInner
);
1331 fogLeft
+= dfogInner
;
1333 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1338 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1341 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1349 #ifdef INTERP_INT_TEX
1359 #ifdef INTERP_MULTITEX
1362 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1363 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1364 sLeft
[u
] += dsInner
[u
];
1365 tLeft
[u
] += dtInner
[u
];
1366 uLeft
[u
] += duInner
[u
];
1367 vLeft
[u
] += dvInner
[u
];
1375 } /* for subTriangle */
1389 #undef BYTES_PER_ROW
1390 #undef PIXEL_ADDRESS
1398 #undef INTERP_INT_TEX
1400 #undef INTERP_MULTITEX
1401 #undef INTERP_FLOAT_RGBA
1402 #undef INTERP_FLOAT_SPEC
1409 #undef DO_OCCLUSION_TEST