1 /* $Id: s_tritemp.h,v 1.34 2002/03/01 04:28:32 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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_LAMBDA - if defined, compute lambda value (for mipmapping)
47 * a lambda value for every texture unit
48 * INTERP_FLOAT_RGBA - if defined, interpolate RGBA with floating point
49 * INTERP_FLOAT_SPEC - if defined, interpolate specular with floating point
51 * When one can directly address pixels in the color buffer the following
52 * macros can be defined and used to compute pixel addresses during
53 * rasterization (see pRow):
54 * PIXEL_TYPE - the datatype of a pixel (GLubyte, GLushort, GLuint)
55 * BYTES_PER_ROW - number of bytes per row in the color buffer
56 * PIXEL_ADDRESS(X,Y) - returns the address of pixel at (X,Y) where
57 * Y==0 at bottom of screen and increases upward.
59 * Similarly, for direct depth buffer access, this type is used for depth
61 * DEPTH_TYPE - either GLushort or GLuint
63 * Optionally, one may provide one-time setup code per triangle:
64 * SETUP_CODE - code which is to be executed once per triangle
65 * CLEANUP_CODE - code to execute at end of triangle
67 * The following macro MUST be defined:
68 * RENDER_SPAN(span) - code to write a span of pixels.
70 * This code was designed for the origin to be in the lower-left corner.
72 * Inspired by triangle rasterizer code written by Allen Akin. Thanks Allen!
77 * This is a bit of a hack, but it's a centralized place to enable floating-
78 * point color interpolation when GLchan is actually floating point.
80 #if CHAN_TYPE == GL_FLOAT
82 #if defined(INTERP_RGB)
85 #define INTERP_FLOAT_RGBA
88 #if defined(INTERP_SPEC)
90 #define INTERP_FLOAT_SPEC
96 /*void triangle( GLcontext *ctx, SWvertex *v0, SWvertex *v1, SWvertex *v2 )*/
99 const SWvertex
*v0
, *v1
; /* Y(v0) < Y(v1) */
100 GLfloat dx
; /* X(v1) - X(v0) */
101 GLfloat dy
; /* Y(v1) - Y(v0) */
102 GLfixed fdxdy
; /* dx/dy in fixed-point */
103 GLfixed fsx
; /* first sample point x coord */
105 GLfloat adjy
; /* adjust from v[0]->fy to fsy, scaled */
106 GLint lines
; /* number of lines to be sampled on this edge */
107 GLfixed fx0
; /* fixed pt X of lower endpoint */
111 const GLint depthBits
= ctx
->Visual
.depthBits
;
112 const GLint fixedToDepthShift
= depthBits
<= 16 ? FIXED_SHIFT
: 0;
113 const GLfloat maxDepth
= ctx
->DepthMaxF
;
114 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
116 EdgeT eMaj
, eTop
, eBot
;
118 const SWvertex
*vMin
, *vMid
, *vMax
; /* Y(vMin)<=Y(vMid)<=Y(vMax) */
119 float bf
= SWRAST_CONTEXT(ctx
)->_backface_sign
;
120 const GLint snapMask
= ~((FIXED_ONE
/ 16) - 1); /* for x/y coord snapping */
121 GLfixed vMin_fx
, vMin_fy
, vMid_fx
, vMid_fy
, vMax_fx
, vMax_fy
;
128 (void) fixedToDepthShift
;
132 printf("%s()\n", __FUNCTION__);
133 printf(" %g, %g, %g\n", v0->win[0], v0->win[1], v0->win[2]);
134 printf(" %g, %g, %g\n", v1->win[0], v1->win[1], v1->win[2]);
135 printf(" %g, %g, %g\n", v2->win[0], v2->win[1], v2->win[2]);
138 /* Compute fixed point x,y coords w/ half-pixel offsets and snapping.
139 * And find the order of the 3 vertices along the Y axis.
142 const GLfixed fy0
= FloatToFixed(v0
->win
[1] - 0.5F
) & snapMask
;
143 const GLfixed fy1
= FloatToFixed(v1
->win
[1] - 0.5F
) & snapMask
;
144 const GLfixed fy2
= FloatToFixed(v2
->win
[1] - 0.5F
) & snapMask
;
149 vMin
= v0
; vMid
= v1
; vMax
= v2
;
150 vMin_fy
= fy0
; vMid_fy
= fy1
; vMax_fy
= fy2
;
152 else if (fy2
<= fy0
) {
154 vMin
= v2
; vMid
= v0
; vMax
= v1
;
155 vMin_fy
= fy2
; vMid_fy
= fy0
; vMax_fy
= fy1
;
159 vMin
= v0
; vMid
= v2
; vMax
= v1
;
160 vMin_fy
= fy0
; vMid_fy
= fy2
; vMax_fy
= fy1
;
167 vMin
= v1
; vMid
= v0
; vMax
= v2
;
168 vMin_fy
= fy1
; vMid_fy
= fy0
; vMax_fy
= fy2
;
171 else if (fy2
<= fy1
) {
173 vMin
= v2
; vMid
= v1
; vMax
= v0
;
174 vMin_fy
= fy2
; vMid_fy
= fy1
; vMax_fy
= fy0
;
179 vMin
= v1
; vMid
= v2
; vMax
= v0
;
180 vMin_fy
= fy1
; vMid_fy
= fy2
; vMax_fy
= fy0
;
184 /* fixed point X coords */
185 vMin_fx
= FloatToFixed(vMin
->win
[0] + 0.5F
) & snapMask
;
186 vMid_fx
= FloatToFixed(vMid
->win
[0] + 0.5F
) & snapMask
;
187 vMax_fx
= FloatToFixed(vMax
->win
[0] + 0.5F
) & snapMask
;
190 /* vertex/edge relationship */
191 eMaj
.v0
= vMin
; eMaj
.v1
= vMax
; /*TODO: .v1's not needed */
192 eTop
.v0
= vMid
; eTop
.v1
= vMax
;
193 eBot
.v0
= vMin
; eBot
.v1
= vMid
;
195 /* compute deltas for each edge: vertex[upper] - vertex[lower] */
196 eMaj
.dx
= FixedToFloat(vMax_fx
- vMin_fx
);
197 eMaj
.dy
= FixedToFloat(vMax_fy
- vMin_fy
);
198 eTop
.dx
= FixedToFloat(vMax_fx
- vMid_fx
);
199 eTop
.dy
= FixedToFloat(vMax_fy
- vMid_fy
);
200 eBot
.dx
= FixedToFloat(vMid_fx
- vMin_fx
);
201 eBot
.dy
= FixedToFloat(vMid_fy
- vMin_fy
);
203 /* compute area, oneOverArea and perform backface culling */
205 const GLfloat area
= eMaj
.dx
* eBot
.dy
- eBot
.dx
* eMaj
.dy
;
207 /* Do backface culling */
211 if (area
== 0.0F
|| IS_INF_OR_NAN(area
))
214 oneOverArea
= 1.0F
/ area
;
217 #ifndef DO_OCCLUSION_TEST
218 ctx
->OcclusionResult
= GL_TRUE
;
221 /* Edge setup. For a triangle strip these could be reused... */
223 eMaj
.fsy
= FixedCeil(vMin_fy
);
224 eMaj
.lines
= FixedToInt(FixedCeil(vMax_fy
- eMaj
.fsy
));
225 if (eMaj
.lines
> 0) {
226 GLfloat dxdy
= eMaj
.dx
/ eMaj
.dy
;
227 eMaj
.fdxdy
= SignedFloatToFixed(dxdy
);
228 eMaj
.adjy
= (GLfloat
) (eMaj
.fsy
- vMin_fy
); /* SCALED! */
230 eMaj
.fsx
= eMaj
.fx0
+ (GLfixed
) (eMaj
.adjy
* dxdy
);
236 eTop
.fsy
= FixedCeil(vMid_fy
);
237 eTop
.lines
= FixedToInt(FixedCeil(vMax_fy
- eTop
.fsy
));
238 if (eTop
.lines
> 0) {
239 GLfloat dxdy
= eTop
.dx
/ eTop
.dy
;
240 eTop
.fdxdy
= SignedFloatToFixed(dxdy
);
241 eTop
.adjy
= (GLfloat
) (eTop
.fsy
- vMid_fy
); /* SCALED! */
243 eTop
.fsx
= eTop
.fx0
+ (GLfixed
) (eTop
.adjy
* dxdy
);
246 eBot
.fsy
= FixedCeil(vMin_fy
);
247 eBot
.lines
= FixedToInt(FixedCeil(vMid_fy
- eBot
.fsy
));
248 if (eBot
.lines
> 0) {
249 GLfloat dxdy
= eBot
.dx
/ eBot
.dy
;
250 eBot
.fdxdy
= SignedFloatToFixed(dxdy
);
251 eBot
.adjy
= (GLfloat
) (eBot
.fsy
- vMin_fy
); /* SCALED! */
253 eBot
.fsx
= eBot
.fx0
+ (GLfixed
) (eBot
.adjy
* dxdy
);
258 * Conceptually, we view a triangle as two subtriangles
259 * separated by a perfectly horizontal line. The edge that is
260 * intersected by this line is one with maximal absolute dy; we
261 * call it a ``major'' edge. The other two edges are the
262 * ``top'' edge (for the upper subtriangle) and the ``bottom''
263 * edge (for the lower subtriangle). If either of these two
264 * edges is horizontal or very close to horizontal, the
265 * corresponding subtriangle might cover zero sample points;
266 * we take care to handle such cases, for performance as well
269 * By stepping rasterization parameters along the major edge,
270 * we can avoid recomputing them at the discontinuity where
271 * the top and bottom edges meet. However, this forces us to
272 * be able to scan both left-to-right and right-to-left.
273 * Also, we must determine whether the major edge is at the
274 * left or right side of the triangle. We do this by
275 * computing the magnitude of the cross-product of the major
276 * and top edges. Since this magnitude depends on the sine of
277 * the angle between the two edges, its sign tells us whether
278 * we turn to the left or to the right when travelling along
279 * the major edge to the top edge, and from this we infer
280 * whether the major edge is on the left or the right.
282 * Serendipitously, this cross-product magnitude is also a
283 * value we need to compute the iteration parameter
284 * derivatives for the triangle, and it can be used to perform
285 * backface culling because its sign tells us whether the
286 * triangle is clockwise or counterclockwise. In this code we
287 * refer to it as ``area'' because it's also proportional to
288 * the pixel area of the triangle.
292 GLint scan_from_left_to_right
; /* true if scanning left-to-right */
299 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
304 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
307 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
308 GLfloat dsrdx
, dsrdy
;
309 GLfloat dsgdx
, dsgdy
;
310 GLfloat dsbdx
, dsbdy
;
315 #ifdef INTERP_INT_TEX
325 #ifdef INTERP_MULTITEX
326 GLfloat dsdy
[MAX_TEXTURE_UNITS
];
327 GLfloat dtdy
[MAX_TEXTURE_UNITS
];
328 GLfloat dudy
[MAX_TEXTURE_UNITS
];
329 GLfloat dvdy
[MAX_TEXTURE_UNITS
];
332 #if defined(INTERP_LAMBDA) && !defined(INTERP_TEX) && !defined(INTERP_MULTITEX)
333 #error "Mipmapping without texturing doesn't make sense."
337 * Execute user-supplied setup code
343 scan_from_left_to_right
= (oneOverArea
< 0.0F
);
346 /* compute d?/dx and d?/dy derivatives */
348 span
.interpMask
|= SPAN_Z
;
350 GLfloat eMaj_dz
, eBot_dz
;
351 eMaj_dz
= vMax
->win
[2] - vMin
->win
[2];
352 eBot_dz
= vMid
->win
[2] - vMin
->win
[2];
353 dzdx
= oneOverArea
* (eMaj_dz
* eBot
.dy
- eMaj
.dy
* eBot_dz
);
354 if (dzdx
> maxDepth
|| dzdx
< -maxDepth
) {
355 /* probably a sliver triangle */
360 dzdy
= oneOverArea
* (eMaj
.dx
* eBot_dz
- eMaj_dz
* eBot
.dx
);
363 span
.zStep
= SignedFloatToFixed(dzdx
);
365 span
.zStep
= (GLint
) dzdx
;
369 span
.interpMask
|= SPAN_FOG
;
371 const GLfloat eMaj_dfog
= vMax
->fog
- vMin
->fog
;
372 const GLfloat eBot_dfog
= vMid
->fog
- vMin
->fog
;
373 span
.fogStep
= oneOverArea
* (eMaj_dfog
* eBot
.dy
- eMaj
.dy
* eBot_dfog
);
374 dfogdy
= oneOverArea
* (eMaj
.dx
* eBot_dfog
- eMaj_dfog
* eBot
.dx
);
378 span
.interpMask
|= SPAN_RGBA
;
379 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
380 GLfloat eMaj_dr
, eBot_dr
;
381 GLfloat eMaj_dg
, eBot_dg
;
382 GLfloat eMaj_db
, eBot_db
;
384 GLfloat eMaj_da
, eBot_da
;
386 eMaj_dr
= (GLfloat
) ((GLint
) vMax
->color
[RCOMP
] -
387 (GLint
) vMin
->color
[RCOMP
]);
388 eBot_dr
= (GLfloat
) ((GLint
) vMid
->color
[RCOMP
] -
389 (GLint
) vMin
->color
[RCOMP
]);
390 drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
391 span
.redStep
= SignedFloatToFixed(drdx
);
392 drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
393 eMaj_dg
= (GLfloat
) ((GLint
) vMax
->color
[GCOMP
] -
394 (GLint
) vMin
->color
[GCOMP
]);
395 eBot_dg
= (GLfloat
) ((GLint
) vMid
->color
[GCOMP
] -
396 (GLint
) vMin
->color
[GCOMP
]);
397 dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
398 span
.greenStep
= SignedFloatToFixed(dgdx
);
399 dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
400 eMaj_db
= (GLfloat
) ((GLint
) vMax
->color
[BCOMP
] -
401 (GLint
) vMin
->color
[BCOMP
]);
402 eBot_db
= (GLfloat
) ((GLint
) vMid
->color
[BCOMP
] -
403 (GLint
) vMin
->color
[BCOMP
]);
404 dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
405 span
.blueStep
= SignedFloatToFixed(dbdx
);
406 dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
408 eMaj_da
= (GLfloat
) ((GLint
) vMax
->color
[ACOMP
] -
409 (GLint
) vMin
->color
[ACOMP
]);
410 eBot_da
= (GLfloat
) ((GLint
) vMid
->color
[ACOMP
] -
411 (GLint
) vMin
->color
[ACOMP
]);
412 dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
413 span
.alphaStep
= SignedFloatToFixed(dadx
);
414 dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
418 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
419 span
.interpMask
|= SPAN_FLAT
;
432 #ifdef INTERP_FLOAT_RGBA
433 span
.interpMask
|= SPAN_RGBA
;
434 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
435 GLfloat eMaj_dr
, eBot_dr
;
436 GLfloat eMaj_dg
, eBot_dg
;
437 GLfloat eMaj_db
, eBot_db
;
438 GLfloat eMaj_da
, eBot_da
;
439 eMaj_dr
= vMax
->color
[RCOMP
] - vMin
->color
[RCOMP
];
440 eBot_dr
= vMid
->color
[RCOMP
] - vMin
->color
[RCOMP
];
441 drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
443 drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
444 eMaj_dg
= vMax
->color
[GCOMP
] - vMin
->color
[GCOMP
];
445 eBot_dg
= vMid
->color
[GCOMP
] - vMin
->color
[GCOMP
];
446 dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
447 span
.greenStep
= dgdx
;
448 dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
449 eMaj_db
= vMax
->color
[BCOMP
] - vMin
->color
[BCOMP
];
450 eBot_db
= vMid
->color
[BCOMP
] - vMin
->color
[BCOMP
];
451 dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
452 span
.blueStep
= dbdx
;
453 dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
454 eMaj_da
= vMax
->color
[ACOMP
] - vMin
->color
[ACOMP
];
455 eBot_da
= vMid
->color
[ACOMP
] - vMin
->color
[ACOMP
];
456 dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
457 span
.alphaStep
= dadx
;
458 dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
461 drdx
= drdy
= span
.redStep
= 0.0F
;
462 dgdx
= dgdy
= span
.greenStep
= 0.0F
;
463 dbdx
= dbdy
= span
.blueStep
= 0.0F
;
464 dadx
= dady
= span
.alphaStep
= 0.0F
;
468 span
.interpMask
|= SPAN_SPEC
;
469 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
470 GLfloat eMaj_dsr
, eBot_dsr
;
471 GLfloat eMaj_dsg
, eBot_dsg
;
472 GLfloat eMaj_dsb
, eBot_dsb
;
473 eMaj_dsr
= (GLfloat
) ((GLint
) vMax
->specular
[RCOMP
] -
474 (GLint
) vMin
->specular
[RCOMP
]);
475 eBot_dsr
= (GLfloat
) ((GLint
) vMid
->specular
[RCOMP
] -
476 (GLint
) vMin
->specular
[RCOMP
]);
477 dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
478 span
.specRedStep
= SignedFloatToFixed(dsrdx
);
479 dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
480 eMaj_dsg
= (GLfloat
) ((GLint
) vMax
->specular
[GCOMP
] -
481 (GLint
) vMin
->specular
[GCOMP
]);
482 eBot_dsg
= (GLfloat
) ((GLint
) vMid
->specular
[GCOMP
] -
483 (GLint
) vMin
->specular
[GCOMP
]);
484 dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
485 span
.specGreenStep
= SignedFloatToFixed(dsgdx
);
486 dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
487 eMaj_dsb
= (GLfloat
) ((GLint
) vMax
->specular
[BCOMP
] -
488 (GLint
) vMin
->specular
[BCOMP
]);
489 eBot_dsb
= (GLfloat
) ((GLint
) vMid
->specular
[BCOMP
] -
490 (GLint
) vMin
->specular
[BCOMP
]);
491 dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
492 span
.specBlueStep
= SignedFloatToFixed(dsbdx
);
493 dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
496 dsrdx
= dsrdy
= 0.0F
;
497 dsgdx
= dsgdy
= 0.0F
;
498 dsbdx
= dsbdy
= 0.0F
;
499 span
.specRedStep
= 0;
500 span
.specGreenStep
= 0;
501 span
.specBlueStep
= 0;
504 #ifdef INTERP_FLOAT_SPEC
505 span
.interpMask
|= SPAN_SPEC
;
506 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
507 GLfloat eMaj_dsr
, eBot_dsr
;
508 GLfloat eMaj_dsg
, eBot_dsg
;
509 GLfloat eMaj_dsb
, eBot_dsb
;
510 eMaj_dsr
= vMax
->specular
[RCOMP
] - vMin
->specular
[RCOMP
];
511 eBot_dsr
= vMid
->specular
[RCOMP
] - vMin
->specular
[RCOMP
];
512 dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
513 span
.specRedStep
= dsrdx
;
514 dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
515 eMaj_dsg
= vMax
->specular
[GCOMP
] - vMin
->specular
[GCOMP
];
516 eBot_dsg
= vMid
->specular
[GCOMP
] - vMin
->specular
[GCOMP
];
517 dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
518 span
.specGreenStep
= dsgdx
;
519 dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
520 eMaj_dsb
= vMax
->specular
[BCOMP
] - vMin
->specular
[BCOMP
];
521 eBot_dsb
= vMid
->specular
[BCOMP
] - vMin
->specular
[BCOMP
];
522 dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
523 span
.specBlueStep
= dsbdx
;
524 dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
527 dsrdx
= dsrdy
= span
.specRedStep
= 0;
528 dsgdx
= dsgdy
= span
.specGreenStep
= 0;
529 dsbdx
= dsbdy
= span
.specBlueStep
= 0;
533 span
.interpMask
|= SPAN_INDEX
;
534 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
535 GLfloat eMaj_di
, eBot_di
;
536 eMaj_di
= (GLfloat
) ((GLint
) vMax
->index
- (GLint
) vMin
->index
);
537 eBot_di
= (GLfloat
) ((GLint
) vMid
->index
- (GLint
) vMin
->index
);
538 didx
= oneOverArea
* (eMaj_di
* eBot
.dy
- eMaj
.dy
* eBot_di
);
539 span
.indexStep
= SignedFloatToFixed(didx
);
540 didy
= oneOverArea
* (eMaj
.dx
* eBot_di
- eMaj_di
* eBot
.dx
);
543 span
.interpMask
|= SPAN_FLAT
;
548 #ifdef INTERP_INT_TEX
549 span
.interpMask
|= SPAN_INT_TEXTURE
;
551 GLfloat eMaj_ds
, eBot_ds
;
552 eMaj_ds
= (vMax
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
553 eBot_ds
= (vMid
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
554 dsdx
= oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
555 span
.intTexStep
[0] = SignedFloatToFixed(dsdx
);
556 dsdy
= oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
559 GLfloat eMaj_dt
, eBot_dt
;
560 eMaj_dt
= (vMax
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
561 eBot_dt
= (vMid
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
562 dtdx
= oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
563 span
.intTexStep
[1] = SignedFloatToFixed(dtdx
);
564 dtdy
= oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
569 span
.interpMask
|= SPAN_TEXTURE
;
571 GLfloat wMax
= vMax
->win
[3];
572 GLfloat wMin
= vMin
->win
[3];
573 GLfloat wMid
= vMid
->win
[3];
574 GLfloat eMaj_ds
, eBot_ds
;
575 GLfloat eMaj_dt
, eBot_dt
;
576 GLfloat eMaj_du
, eBot_du
;
577 GLfloat eMaj_dv
, eBot_dv
;
579 eMaj_ds
= vMax
->texcoord
[0][0] * wMax
- vMin
->texcoord
[0][0] * wMin
;
580 eBot_ds
= vMid
->texcoord
[0][0] * wMid
- vMin
->texcoord
[0][0] * wMin
;
581 span
.texStep
[0][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
582 - eMaj
.dy
* eBot_ds
);
583 dsdy
= oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
585 eMaj_dt
= vMax
->texcoord
[0][1] * wMax
- vMin
->texcoord
[0][1] * wMin
;
586 eBot_dt
= vMid
->texcoord
[0][1] * wMid
- vMin
->texcoord
[0][1] * wMin
;
587 span
.texStep
[0][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
588 - eMaj
.dy
* eBot_dt
);
589 dtdy
= oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
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 span
.texStep
[0][2] = oneOverArea
* (eMaj_du
* eBot
.dy
594 - eMaj
.dy
* eBot_du
);
595 dudy
= oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
597 eMaj_dv
= vMax
->texcoord
[0][3] * wMax
- vMin
->texcoord
[0][3] * wMin
;
598 eBot_dv
= vMid
->texcoord
[0][3] * wMid
- vMin
->texcoord
[0][3] * wMin
;
599 span
.texStep
[0][3] = oneOverArea
* (eMaj_dv
* eBot
.dy
600 - eMaj
.dy
* eBot_dv
);
601 dvdy
= oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
603 # ifdef INTERP_LAMBDA
605 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
606 const struct gl_texture_image
*texImage
= obj
->Image
[obj
->BaseLevel
];
607 const GLfloat texWidth
= (GLfloat
) texImage
->Width
;
608 const GLfloat texHeight
= (GLfloat
) texImage
->Height
;
609 GLfloat dudx
= span
.texStep
[0][0] * texWidth
;
610 GLfloat dudy
= dsdy
* texWidth
;
611 GLfloat dvdx
= span
.texStep
[0][1] * texHeight
;
612 GLfloat dvdy
= dtdy
* texHeight
;
613 GLfloat r1
= dudx
* dudx
+ dudy
* dudy
;
614 GLfloat r2
= dvdx
* dvdx
+ dvdy
* dvdy
;
615 span
.rho
[0] = r1
+ r2
; /* was rho2 = MAX2(r1,r2) */
616 span
.interpMask
|= SPAN_LAMBDA
;
620 #ifdef INTERP_MULTITEX
621 span
.interpMask
|= SPAN_TEXTURE
;
622 # ifdef INTERP_LAMBDA
623 span
.interpMask
|= SPAN_LAMBDA
;
626 GLfloat wMax
= vMax
->win
[3];
627 GLfloat wMin
= vMin
->win
[3];
628 GLfloat wMid
= vMid
->win
[3];
630 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
631 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
632 GLfloat eMaj_ds
, eBot_ds
;
633 GLfloat eMaj_dt
, eBot_dt
;
634 GLfloat eMaj_du
, eBot_du
;
635 GLfloat eMaj_dv
, eBot_dv
;
636 eMaj_ds
= vMax
->texcoord
[u
][0] * wMax
637 - vMin
->texcoord
[u
][0] * wMin
;
638 eBot_ds
= vMid
->texcoord
[u
][0] * wMid
639 - vMin
->texcoord
[u
][0] * wMin
;
640 span
.texStep
[u
][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
641 - eMaj
.dy
* eBot_ds
);
642 dsdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
644 eMaj_dt
= vMax
->texcoord
[u
][1] * wMax
645 - vMin
->texcoord
[u
][1] * wMin
;
646 eBot_dt
= vMid
->texcoord
[u
][1] * wMid
647 - vMin
->texcoord
[u
][1] * wMin
;
648 span
.texStep
[u
][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
649 - eMaj
.dy
* eBot_dt
);
650 dtdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
652 eMaj_du
= vMax
->texcoord
[u
][2] * wMax
653 - vMin
->texcoord
[u
][2] * wMin
;
654 eBot_du
= vMid
->texcoord
[u
][2] * wMid
655 - vMin
->texcoord
[u
][2] * wMin
;
656 span
.texStep
[u
][2] = oneOverArea
* (eMaj_du
* eBot
.dy
657 - eMaj
.dy
* eBot_du
);
658 dudy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
660 eMaj_dv
= vMax
->texcoord
[u
][3] * wMax
661 - vMin
->texcoord
[u
][3] * wMin
;
662 eBot_dv
= vMid
->texcoord
[u
][3] * wMid
663 - vMin
->texcoord
[u
][3] * wMin
;
664 span
.texStep
[u
][3] = oneOverArea
* (eMaj_dv
* eBot
.dy
665 - eMaj
.dy
* eBot_dv
);
666 dvdy
[u
] = oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
667 # ifdef INTERP_LAMBDA
669 const struct gl_texture_object
*obj
670 = ctx
->Texture
.Unit
[u
]._Current
;
671 const struct gl_texture_image
*texImage
672 = obj
->Image
[obj
->BaseLevel
];
673 const GLfloat texWidth
= (GLfloat
) texImage
->Width
;
674 const GLfloat texHeight
= (GLfloat
) texImage
->Height
;
675 GLfloat dudx
= span
.texStep
[u
][0] * texWidth
;
676 GLfloat dudy
= dsdy
[u
] * texWidth
;
677 GLfloat dvdx
= span
.texStep
[u
][1] * texHeight
;
678 GLfloat dvdy
= dtdy
[u
] * texHeight
;
679 GLfloat r1
= dudx
* dudx
+ dudy
* dudy
;
680 GLfloat r2
= dvdx
* dvdx
+ dvdy
* dvdy
;
681 span
.rho
[u
] = r1
+ r2
; /* was rho2 = MAX2(r1,r2) */
690 * We always sample at pixel centers. However, we avoid
691 * explicit half-pixel offsets in this code by incorporating
692 * the proper offset in each of x and y during the
693 * transformation to window coordinates.
695 * We also apply the usual rasterization rules to prevent
696 * cracks and overlaps. A pixel is considered inside a
697 * subtriangle if it meets all of four conditions: it is on or
698 * to the right of the left edge, strictly to the left of the
699 * right edge, on or below the top edge, and strictly above
700 * the bottom edge. (Some edges may be degenerate.)
702 * The following discussion assumes left-to-right scanning
703 * (that is, the major edge is on the left); the right-to-left
704 * case is a straightforward variation.
706 * We start by finding the half-integral y coordinate that is
707 * at or below the top of the triangle. This gives us the
708 * first scan line that could possibly contain pixels that are
709 * inside the triangle.
711 * Next we creep down the major edge until we reach that y,
712 * and compute the corresponding x coordinate on the edge.
713 * Then we find the half-integral x that lies on or just
714 * inside the edge. This is the first pixel that might lie in
715 * the interior of the triangle. (We won't know for sure
716 * until we check the other edges.)
718 * As we rasterize the triangle, we'll step down the major
719 * edge. For each step in y, we'll move an integer number
720 * of steps in x. There are two possible x step sizes, which
721 * we'll call the ``inner'' step (guaranteed to land on the
722 * edge or inside it) and the ``outer'' step (guaranteed to
723 * land on the edge or outside it). The inner and outer steps
724 * differ by one. During rasterization we maintain an error
725 * term that indicates our distance from the true edge, and
726 * select either the inner step or the outer step, whichever
727 * gets us to the first pixel that falls inside the triangle.
729 * All parameters (z, red, etc.) as well as the buffer
730 * addresses for color and z have inner and outer step values,
731 * so that we can increment them appropriately. This method
732 * eliminates the need to adjust parameters by creeping a
733 * sub-pixel amount into the triangle at each scanline.
739 GLfixed fxLeftEdge
= 0, fxRightEdge
= 0;
740 GLfixed fdxLeftEdge
= 0, fdxRightEdge
= 0;
744 GLfixed fError
= 0, fdError
= 0;
748 PIXEL_TYPE
*pRow
= NULL
;
749 int dPRowOuter
= 0, dPRowInner
; /* offset in bytes */
753 DEPTH_TYPE
*zRow
= NULL
;
754 int dZRowOuter
= 0, dZRowInner
; /* offset in bytes */
756 GLfixed fz
= 0, fdzOuter
= 0, fdzInner
;
759 GLfloat fogLeft
= 0, dfogOuter
= 0, dfogInner
;
762 GLfixed fr
= 0, fdrOuter
= 0, fdrInner
;
763 GLfixed fg
= 0, fdgOuter
= 0, fdgInner
;
764 GLfixed fb
= 0, fdbOuter
= 0, fdbInner
;
767 GLfixed fa
= 0, fdaOuter
= 0, fdaInner
;
769 #ifdef INTERP_FLOAT_RGBA
770 GLfloat fr
, fdrOuter
, fdrInner
;
771 GLfloat fg
, fdgOuter
, fdgInner
;
772 GLfloat fb
, fdbOuter
, fdbInner
;
773 GLfloat fa
, fdaOuter
, fdaInner
;
776 GLfixed fsr
=0, fdsrOuter
=0, fdsrInner
;
777 GLfixed fsg
=0, fdsgOuter
=0, fdsgInner
;
778 GLfixed fsb
=0, fdsbOuter
=0, fdsbInner
;
780 #ifdef INTERP_FLOAT_SPEC
781 GLfloat fsr
=0, fdsrOuter
=0, fdsrInner
;
782 GLfloat fsg
=0, fdsgOuter
=0, fdsgInner
;
783 GLfloat fsb
=0, fdsbOuter
=0, fdsbInner
;
786 GLfixed fi
=0, fdiOuter
=0, fdiInner
;
788 #ifdef INTERP_INT_TEX
789 GLfixed fs
=0, fdsOuter
=0, fdsInner
;
790 GLfixed ft
=0, fdtOuter
=0, fdtInner
;
793 GLfloat sLeft
=0, dsOuter
=0, dsInner
;
794 GLfloat tLeft
=0, dtOuter
=0, dtInner
;
795 GLfloat uLeft
=0, duOuter
=0, duInner
;
796 GLfloat vLeft
=0, dvOuter
=0, dvInner
;
798 #ifdef INTERP_MULTITEX
799 GLfloat sLeft
[MAX_TEXTURE_UNITS
];
800 GLfloat tLeft
[MAX_TEXTURE_UNITS
];
801 GLfloat uLeft
[MAX_TEXTURE_UNITS
];
802 GLfloat vLeft
[MAX_TEXTURE_UNITS
];
803 GLfloat dsOuter
[MAX_TEXTURE_UNITS
], dsInner
[MAX_TEXTURE_UNITS
];
804 GLfloat dtOuter
[MAX_TEXTURE_UNITS
], dtInner
[MAX_TEXTURE_UNITS
];
805 GLfloat duOuter
[MAX_TEXTURE_UNITS
], duInner
[MAX_TEXTURE_UNITS
];
806 GLfloat dvOuter
[MAX_TEXTURE_UNITS
], dvInner
[MAX_TEXTURE_UNITS
];
809 for (subTriangle
=0; subTriangle
<=1; subTriangle
++) {
810 EdgeT
*eLeft
, *eRight
;
811 int setupLeft
, setupRight
;
814 if (subTriangle
==0) {
816 if (scan_from_left_to_right
) {
819 lines
= eRight
->lines
;
826 lines
= eLeft
->lines
;
833 if (scan_from_left_to_right
) {
836 lines
= eRight
->lines
;
843 lines
= eLeft
->lines
;
851 if (setupLeft
&& eLeft
->lines
> 0) {
852 const SWvertex
*vLower
;
853 GLfixed fsx
= eLeft
->fsx
;
855 fError
= fx
- fsx
- FIXED_ONE
;
856 fxLeftEdge
= fsx
- FIXED_EPSILON
;
857 fdxLeftEdge
= eLeft
->fdxdy
;
858 fdxOuter
= FixedFloor(fdxLeftEdge
- FIXED_EPSILON
);
859 fdError
= fdxOuter
- fdxLeftEdge
+ FIXED_ONE
;
860 idxOuter
= FixedToInt(fdxOuter
);
861 dxOuter
= (float) idxOuter
;
865 span
.y
= FixedToInt(fy
);
867 adjx
= (float)(fx
- eLeft
->fx0
); /* SCALED! */
868 adjy
= eLeft
->adjy
; /* SCALED! */
869 (void) adjx
; /* silence compiler warnings */
870 (void) adjy
; /* silence compiler warnings */
873 (void) vLower
; /* silence compiler warnings */
877 pRow
= (PIXEL_TYPE
*) PIXEL_ADDRESS(FixedToInt(fxLeftEdge
), span
.y
);
878 dPRowOuter
= -((int)BYTES_PER_ROW
) + idxOuter
* sizeof(PIXEL_TYPE
);
879 /* negative because Y=0 at bottom and increases upward */
883 * Now we need the set of parameter (z, color, etc.) values at
884 * the point (fx, fy). This gives us properly-sampled parameter
885 * values that we can step from pixel to pixel. Furthermore,
886 * although we might have intermediate results that overflow
887 * the normal parameter range when we step temporarily outside
888 * the triangle, we shouldn't overflow or underflow for any
889 * pixel that's actually inside the triangle.
894 GLfloat z0
= vLower
->win
[2];
895 if (depthBits
<= 16) {
896 /* interpolate fixed-pt values */
897 GLfloat tmp
= (z0
* FIXED_SCALE
+
898 dzdx
* adjx
+ dzdy
* adjy
) + FIXED_HALF
;
899 if (tmp
< MAX_GLUINT
/ 2)
903 fdzOuter
= SignedFloatToFixed(dzdy
+ dxOuter
* dzdx
);
906 /* interpolate depth values exactly */
907 fz
= (GLint
) (z0
+ dzdx
* FixedToFloat(adjx
)
908 + dzdy
* FixedToFloat(adjy
));
909 fdzOuter
= (GLint
) (dzdy
+ dxOuter
* dzdx
);
912 zRow
= (DEPTH_TYPE
*)
913 _mesa_zbuffer_address(ctx
, FixedToInt(fxLeftEdge
), span
.y
);
914 dZRowOuter
= (ctx
->DrawBuffer
->Width
+ idxOuter
) * sizeof(DEPTH_TYPE
);
919 fogLeft
= vLower
->fog
+ (span
.fogStep
* adjx
+ dfogdy
* adjy
)
920 * (1.0F
/FIXED_SCALE
);
921 dfogOuter
= dfogdy
+ dxOuter
* span
.fogStep
;
924 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
925 fr
= (GLfixed
) (ChanToFixed(vLower
->color
[RCOMP
])
926 + drdx
* adjx
+ drdy
* adjy
) + FIXED_HALF
;
927 fdrOuter
= SignedFloatToFixed(drdy
+ dxOuter
* drdx
);
928 fg
= (GLfixed
) (ChanToFixed(vLower
->color
[GCOMP
])
929 + dgdx
* adjx
+ dgdy
* adjy
) + FIXED_HALF
;
930 fdgOuter
= SignedFloatToFixed(dgdy
+ dxOuter
* dgdx
);
931 fb
= (GLfixed
) (ChanToFixed(vLower
->color
[BCOMP
])
932 + dbdx
* adjx
+ dbdy
* adjy
) + FIXED_HALF
;
933 fdbOuter
= SignedFloatToFixed(dbdy
+ dxOuter
* dbdx
);
935 fa
= (GLfixed
) (ChanToFixed(vLower
->color
[ACOMP
])
936 + dadx
* adjx
+ dady
* adjy
) + FIXED_HALF
;
937 fdaOuter
= SignedFloatToFixed(dady
+ dxOuter
* dadx
);
941 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
942 fr
= ChanToFixed(v2
->color
[RCOMP
]);
943 fg
= ChanToFixed(v2
->color
[GCOMP
]);
944 fb
= ChanToFixed(v2
->color
[BCOMP
]);
945 fdrOuter
= fdgOuter
= fdbOuter
= 0;
947 fa
= ChanToFixed(v2
->color
[ACOMP
]);
952 #ifdef INTERP_FLOAT_RGBA
953 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
954 fr
= vLower
->color
[RCOMP
]
955 + (drdx
* adjx
+ drdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
956 fdrOuter
= drdy
+ dxOuter
* drdx
;
957 fg
= vLower
->color
[GCOMP
]
958 + (dgdx
* adjx
+ dgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
959 fdgOuter
= dgdy
+ dxOuter
* dgdx
;
960 fb
= vLower
->color
[BCOMP
]
961 + (dbdx
* adjx
+ dbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
962 fdbOuter
= dbdy
+ dxOuter
* dbdx
;
963 fa
= vLower
->color
[ACOMP
]
964 + (dadx
* adjx
+ dady
* adjy
) * (1.0F
/ FIXED_SCALE
);
965 fdaOuter
= dady
+ dxOuter
* dadx
;
968 fr
= v2
->color
[RCOMP
];
969 fg
= v2
->color
[GCOMP
];
970 fb
= v2
->color
[BCOMP
];
971 fa
= v2
->color
[ACOMP
];
972 fdrOuter
= fdgOuter
= fdbOuter
= fdaOuter
= 0.0F
;
976 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
977 fsr
= (GLfixed
) (ChanToFixed(vLower
->specular
[RCOMP
])
978 + dsrdx
* adjx
+ dsrdy
* adjy
) + FIXED_HALF
;
979 fdsrOuter
= SignedFloatToFixed(dsrdy
+ dxOuter
* dsrdx
);
980 fsg
= (GLfixed
) (ChanToFixed(vLower
->specular
[GCOMP
])
981 + dsgdx
* adjx
+ dsgdy
* adjy
) + FIXED_HALF
;
982 fdsgOuter
= SignedFloatToFixed(dsgdy
+ dxOuter
* dsgdx
);
983 fsb
= (GLfixed
) (ChanToFixed(vLower
->specular
[BCOMP
])
984 + dsbdx
* adjx
+ dsbdy
* adjy
) + FIXED_HALF
;
985 fdsbOuter
= SignedFloatToFixed(dsbdy
+ dxOuter
* dsbdx
);
988 fsr
= ChanToFixed(v2
->specular
[RCOMP
]);
989 fsg
= ChanToFixed(v2
->specular
[GCOMP
]);
990 fsb
= ChanToFixed(v2
->specular
[BCOMP
]);
991 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0;
994 #ifdef INTERP_FLOAT_SPEC
995 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
996 fsr
= vLower
->specular
[RCOMP
]
997 + (dsrdx
* adjx
+ dsrdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
998 fdsrOuter
= dsrdy
+ dxOuter
* dsrdx
;
999 fsg
= vLower
->specular
[GCOMP
]
1000 + (dsgdx
* adjx
+ dsgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
1001 fdsgOuter
= dsgdy
+ dxOuter
* dsgdx
;
1002 fsb
= vLower
->specular
[BCOMP
]
1003 + (dsbdx
* adjx
+ dsbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
1004 fdsbOuter
= dsbdy
+ dxOuter
* dsbdx
;
1007 fsr
= v2
->specular
[RCOMP
];
1008 fsg
= v2
->specular
[GCOMP
];
1009 fsb
= v2
->specular
[BCOMP
];
1010 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0.0F
;
1014 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1015 fi
= (GLfixed
)(vLower
->index
* FIXED_SCALE
1016 + didx
* adjx
+ didy
* adjy
) + FIXED_HALF
;
1017 fdiOuter
= SignedFloatToFixed(didy
+ dxOuter
* didx
);
1020 fi
= (GLfixed
) (v2
->index
* FIXED_SCALE
);
1024 #ifdef INTERP_INT_TEX
1027 s0
= vLower
->texcoord
[0][0] * S_SCALE
;
1028 fs
= (GLfixed
)(s0
* FIXED_SCALE
+ dsdx
* adjx
1029 + dsdy
* adjy
) + FIXED_HALF
;
1030 fdsOuter
= SignedFloatToFixed(dsdy
+ dxOuter
* dsdx
);
1032 t0
= vLower
->texcoord
[0][1] * T_SCALE
;
1033 ft
= (GLfixed
)(t0
* FIXED_SCALE
+ dtdx
* adjx
1034 + dtdy
* adjy
) + FIXED_HALF
;
1035 fdtOuter
= SignedFloatToFixed(dtdy
+ dxOuter
* dtdx
);
1040 GLfloat invW
= vLower
->win
[3];
1041 GLfloat s0
, t0
, u0
, v0
;
1042 s0
= vLower
->texcoord
[0][0] * invW
;
1043 sLeft
= s0
+ (span
.texStep
[0][0] * adjx
+ dsdy
* adjy
)
1044 * (1.0F
/FIXED_SCALE
);
1045 dsOuter
= dsdy
+ dxOuter
* span
.texStep
[0][0];
1046 t0
= vLower
->texcoord
[0][1] * invW
;
1047 tLeft
= t0
+ (span
.texStep
[0][1] * adjx
+ dtdy
* adjy
)
1048 * (1.0F
/FIXED_SCALE
);
1049 dtOuter
= dtdy
+ dxOuter
* span
.texStep
[0][1];
1050 u0
= vLower
->texcoord
[0][2] * invW
;
1051 uLeft
= u0
+ (span
.texStep
[0][2] * adjx
+ dudy
* adjy
)
1052 * (1.0F
/FIXED_SCALE
);
1053 duOuter
= dudy
+ dxOuter
* span
.texStep
[0][2];
1054 v0
= vLower
->texcoord
[0][3] * invW
;
1055 vLeft
= v0
+ (span
.texStep
[0][3] * adjx
+ dvdy
* adjy
)
1056 * (1.0F
/FIXED_SCALE
);
1057 dvOuter
= dvdy
+ dxOuter
* span
.texStep
[0][3];
1060 #ifdef INTERP_MULTITEX
1063 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1064 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1065 GLfloat invW
= vLower
->win
[3];
1066 GLfloat s0
, t0
, u0
, v0
;
1067 s0
= vLower
->texcoord
[u
][0] * invW
;
1068 sLeft
[u
] = s0
+ (span
.texStep
[u
][0] * adjx
+ dsdy
[u
]
1069 * adjy
) * (1.0F
/FIXED_SCALE
);
1070 dsOuter
[u
] = dsdy
[u
] + dxOuter
* span
.texStep
[u
][0];
1071 t0
= vLower
->texcoord
[u
][1] * invW
;
1072 tLeft
[u
] = t0
+ (span
.texStep
[u
][1] * adjx
+ dtdy
[u
]
1073 * adjy
) * (1.0F
/FIXED_SCALE
);
1074 dtOuter
[u
] = dtdy
[u
] + dxOuter
* span
.texStep
[u
][1];
1075 u0
= vLower
->texcoord
[u
][2] * invW
;
1076 uLeft
[u
] = u0
+ (span
.texStep
[u
][2] * adjx
+ dudy
[u
]
1077 * adjy
) * (1.0F
/FIXED_SCALE
);
1078 duOuter
[u
] = dudy
[u
] + dxOuter
* span
.texStep
[u
][2];
1079 v0
= vLower
->texcoord
[u
][3] * invW
;
1080 vLeft
[u
] = v0
+ (span
.texStep
[u
][3] * adjx
+ dvdy
[u
]
1081 * adjy
) * (1.0F
/FIXED_SCALE
);
1082 dvOuter
[u
] = dvdy
[u
] + dxOuter
* span
.texStep
[u
][3];
1091 if (setupRight
&& eRight
->lines
>0) {
1092 fxRightEdge
= eRight
->fsx
- FIXED_EPSILON
;
1093 fdxRightEdge
= eRight
->fdxdy
;
1101 /* Rasterize setup */
1102 #ifdef PIXEL_ADDRESS
1103 dPRowInner
= dPRowOuter
+ sizeof(PIXEL_TYPE
);
1107 dZRowInner
= dZRowOuter
+ sizeof(DEPTH_TYPE
);
1109 fdzInner
= fdzOuter
+ span
.zStep
;
1112 dfogInner
= dfogOuter
+ span
.fogStep
;
1114 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1115 fdrInner
= fdrOuter
+ span
.redStep
;
1116 fdgInner
= fdgOuter
+ span
.greenStep
;
1117 fdbInner
= fdbOuter
+ span
.blueStep
;
1119 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1120 fdaInner
= fdaOuter
+ span
.alphaStep
;
1122 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1123 fdsrInner
= fdsrOuter
+ span
.specRedStep
;
1124 fdsgInner
= fdsgOuter
+ span
.specGreenStep
;
1125 fdsbInner
= fdsbOuter
+ span
.specBlueStep
;
1128 fdiInner
= fdiOuter
+ span
.indexStep
;
1130 #ifdef INTERP_INT_TEX
1131 fdsInner
= fdsOuter
+ span
.intTexStep
[0];
1132 fdtInner
= fdtOuter
+ span
.intTexStep
[1];
1135 dsInner
= dsOuter
+ span
.texStep
[0][0];
1136 dtInner
= dtOuter
+ span
.texStep
[0][1];
1137 duInner
= duOuter
+ span
.texStep
[0][2];
1138 dvInner
= dvOuter
+ span
.texStep
[0][3];
1140 #ifdef INTERP_MULTITEX
1143 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1144 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1145 dsInner
[u
] = dsOuter
[u
] + span
.texStep
[u
][0];
1146 dtInner
[u
] = dtOuter
[u
] + span
.texStep
[u
][1];
1147 duInner
[u
] = duOuter
[u
] + span
.texStep
[u
][2];
1148 dvInner
[u
] = dvOuter
[u
] + span
.texStep
[u
][3];
1155 /* initialize the span interpolants to the leftmost value */
1156 /* ff = fixed-pt fragment */
1157 const GLint right
= FixedToInt(fxRightEdge
);
1159 span
.x
= FixedToInt(fxLeftEdge
);
1161 if (right
<= span
.x
)
1164 span
.end
= right
- span
.x
;
1172 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1177 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1180 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1182 span
.specGreen
= fsg
;
1183 span
.specBlue
= fsb
;
1188 #ifdef INTERP_INT_TEX
1189 span
.intTex
[0] = fs
;
1190 span
.intTex
[1] = ft
;
1194 span
.tex
[0][0] = sLeft
;
1195 span
.tex
[0][1] = tLeft
;
1196 span
.tex
[0][2] = uLeft
;
1197 span
.tex
[0][3] = vLeft
;
1200 #ifdef INTERP_MULTITEX
1203 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1204 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1205 span
.tex
[u
][0] = sLeft
[u
];
1206 span
.tex
[u
][1] = tLeft
[u
];
1207 span
.tex
[u
][2] = uLeft
[u
];
1208 span
.tex
[u
][3] = vLeft
[u
];
1216 /* need this to accomodate round-off errors */
1217 const GLint len
= right
- span
.x
- 1;
1218 GLfixed ffrend
= span
.red
+ len
* span
.redStep
;
1219 GLfixed ffgend
= span
.green
+ len
* span
.greenStep
;
1220 GLfixed ffbend
= span
.blue
+ len
* span
.blueStep
;
1227 span
.green
-= ffgend
;
1232 span
.blue
-= ffbend
;
1240 const GLint len
= right
- span
.x
- 1;
1241 GLfixed ffaend
= span
.alpha
+ len
* span
.alphaStep
;
1243 span
.alpha
-= ffaend
;
1251 /* need this to accomodate round-off errors */
1252 const GLint len
= right
- span
.x
- 1;
1253 GLfixed ffsrend
= span
.specRed
+ len
* span
.specRedStep
;
1254 GLfixed ffsgend
= span
.specGreen
+ len
* span
.specGreenStep
;
1255 GLfixed ffsbend
= span
.specBlue
+ len
* span
.specBlueStep
;
1257 span
.specRed
-= ffsrend
;
1258 if (span
.specRed
< 0)
1262 span
.specGreen
-= ffsgend
;
1263 if (span
.specGreen
< 0)
1267 span
.specBlue
-= ffsbend
;
1268 if (span
.specBlue
< 0)
1274 if (span
.index
< 0) span
.index
= 0;
1277 /* This is where we actually generate fragments */
1279 RENDER_SPAN( span
);
1283 * Advance to the next scan line. Compute the
1284 * new edge coordinates, and adjust the
1285 * pixel-center x coordinate so that it stays
1286 * on or inside the major edge.
1291 fxLeftEdge
+= fdxLeftEdge
;
1292 fxRightEdge
+= fdxRightEdge
;
1297 fError
-= FIXED_ONE
;
1298 #ifdef PIXEL_ADDRESS
1299 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowOuter
);
1303 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowOuter
);
1308 fogLeft
+= dfogOuter
;
1310 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1315 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1318 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1326 #ifdef INTERP_INT_TEX
1336 #ifdef INTERP_MULTITEX
1339 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1340 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1341 sLeft
[u
] += dsOuter
[u
];
1342 tLeft
[u
] += dtOuter
[u
];
1343 uLeft
[u
] += duOuter
[u
];
1344 vLeft
[u
] += dvOuter
[u
];
1351 #ifdef PIXEL_ADDRESS
1352 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowInner
);
1356 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowInner
);
1361 fogLeft
+= dfogInner
;
1363 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1368 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1371 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1379 #ifdef INTERP_INT_TEX
1389 #ifdef INTERP_MULTITEX
1392 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1393 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1394 sLeft
[u
] += dsInner
[u
];
1395 tLeft
[u
] += dtInner
[u
];
1396 uLeft
[u
] += duInner
[u
];
1397 vLeft
[u
] += dvInner
[u
];
1405 } /* for subTriangle */
1419 #undef BYTES_PER_ROW
1420 #undef PIXEL_ADDRESS
1428 #undef INTERP_INT_TEX
1430 #undef INTERP_MULTITEX
1431 #undef INTERP_LAMBDA
1432 #undef INTERP_FLOAT_RGBA
1433 #undef INTERP_FLOAT_SPEC
1440 #undef DO_OCCLUSION_TEST