1 /* $Id: s_tritemp.h,v 1.33 2002/01/28 04:25:56 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.
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
, fxRightEdge
, fdxLeftEdge
, fdxRightEdge
;
743 GLfixed fError
, fdError
;
748 int dPRowOuter
, dPRowInner
; /* offset in bytes */
753 int dZRowOuter
, dZRowInner
; /* offset in bytes */
755 GLfixed fz
, fdzOuter
, fdzInner
;
758 GLfloat fogLeft
, dfogOuter
, dfogInner
;
761 GLfixed fr
, fdrOuter
, fdrInner
;
762 GLfixed fg
, fdgOuter
, fdgInner
;
763 GLfixed fb
, fdbOuter
, fdbInner
;
766 GLfixed fa
, fdaOuter
, fdaInner
;
768 #ifdef INTERP_FLOAT_RGBA
769 GLfloat fr
, fdrOuter
, fdrInner
;
770 GLfloat fg
, fdgOuter
, fdgInner
;
771 GLfloat fb
, fdbOuter
, fdbInner
;
772 GLfloat fa
, fdaOuter
, fdaInner
;
775 GLfixed fsr
=0, fdsrOuter
=0, fdsrInner
;
776 GLfixed fsg
=0, fdsgOuter
=0, fdsgInner
;
777 GLfixed fsb
=0, fdsbOuter
=0, fdsbInner
;
779 #ifdef INTERP_FLOAT_SPEC
780 GLfloat fsr
=0, fdsrOuter
=0, fdsrInner
;
781 GLfloat fsg
=0, fdsgOuter
=0, fdsgInner
;
782 GLfloat fsb
=0, fdsbOuter
=0, fdsbInner
;
785 GLfixed fi
=0, fdiOuter
=0, fdiInner
;
787 #ifdef INTERP_INT_TEX
788 GLfixed fs
=0, fdsOuter
=0, fdsInner
;
789 GLfixed ft
=0, fdtOuter
=0, fdtInner
;
792 GLfloat sLeft
=0, dsOuter
=0, dsInner
;
793 GLfloat tLeft
=0, dtOuter
=0, dtInner
;
794 GLfloat uLeft
=0, duOuter
=0, duInner
;
795 GLfloat vLeft
=0, dvOuter
=0, dvInner
;
797 #ifdef INTERP_MULTITEX
798 GLfloat sLeft
[MAX_TEXTURE_UNITS
];
799 GLfloat tLeft
[MAX_TEXTURE_UNITS
];
800 GLfloat uLeft
[MAX_TEXTURE_UNITS
];
801 GLfloat vLeft
[MAX_TEXTURE_UNITS
];
802 GLfloat dsOuter
[MAX_TEXTURE_UNITS
], dsInner
[MAX_TEXTURE_UNITS
];
803 GLfloat dtOuter
[MAX_TEXTURE_UNITS
], dtInner
[MAX_TEXTURE_UNITS
];
804 GLfloat duOuter
[MAX_TEXTURE_UNITS
], duInner
[MAX_TEXTURE_UNITS
];
805 GLfloat dvOuter
[MAX_TEXTURE_UNITS
], dvInner
[MAX_TEXTURE_UNITS
];
808 for (subTriangle
=0; subTriangle
<=1; subTriangle
++) {
809 EdgeT
*eLeft
, *eRight
;
810 int setupLeft
, setupRight
;
813 if (subTriangle
==0) {
815 if (scan_from_left_to_right
) {
818 lines
= eRight
->lines
;
825 lines
= eLeft
->lines
;
832 if (scan_from_left_to_right
) {
835 lines
= eRight
->lines
;
842 lines
= eLeft
->lines
;
850 if (setupLeft
&& eLeft
->lines
> 0) {
851 const SWvertex
*vLower
;
852 GLfixed fsx
= eLeft
->fsx
;
854 fError
= fx
- fsx
- FIXED_ONE
;
855 fxLeftEdge
= fsx
- FIXED_EPSILON
;
856 fdxLeftEdge
= eLeft
->fdxdy
;
857 fdxOuter
= FixedFloor(fdxLeftEdge
- FIXED_EPSILON
);
858 fdError
= fdxOuter
- fdxLeftEdge
+ FIXED_ONE
;
859 idxOuter
= FixedToInt(fdxOuter
);
860 dxOuter
= (float) idxOuter
;
864 span
.y
= FixedToInt(fy
);
866 adjx
= (float)(fx
- eLeft
->fx0
); /* SCALED! */
867 adjy
= eLeft
->adjy
; /* SCALED! */
868 (void) adjx
; /* silence compiler warnings */
869 (void) adjy
; /* silence compiler warnings */
872 (void) vLower
; /* silence compiler warnings */
876 pRow
= (PIXEL_TYPE
*) PIXEL_ADDRESS(FixedToInt(fxLeftEdge
), span
.y
);
877 dPRowOuter
= -((int)BYTES_PER_ROW
) + idxOuter
* sizeof(PIXEL_TYPE
);
878 /* negative because Y=0 at bottom and increases upward */
882 * Now we need the set of parameter (z, color, etc.) values at
883 * the point (fx, fy). This gives us properly-sampled parameter
884 * values that we can step from pixel to pixel. Furthermore,
885 * although we might have intermediate results that overflow
886 * the normal parameter range when we step temporarily outside
887 * the triangle, we shouldn't overflow or underflow for any
888 * pixel that's actually inside the triangle.
893 GLfloat z0
= vLower
->win
[2];
894 if (depthBits
<= 16) {
895 /* interpolate fixed-pt values */
896 GLfloat tmp
= (z0
* FIXED_SCALE
+
897 dzdx
* adjx
+ dzdy
* adjy
) + FIXED_HALF
;
898 if (tmp
< MAX_GLUINT
/ 2)
902 fdzOuter
= SignedFloatToFixed(dzdy
+ dxOuter
* dzdx
);
905 /* interpolate depth values exactly */
906 fz
= (GLint
) (z0
+ dzdx
* FixedToFloat(adjx
)
907 + dzdy
* FixedToFloat(adjy
));
908 fdzOuter
= (GLint
) (dzdy
+ dxOuter
* dzdx
);
911 zRow
= (DEPTH_TYPE
*)
912 _mesa_zbuffer_address(ctx
, FixedToInt(fxLeftEdge
), span
.y
);
913 dZRowOuter
= (ctx
->DrawBuffer
->Width
+ idxOuter
) * sizeof(DEPTH_TYPE
);
918 fogLeft
= vLower
->fog
+ (span
.fogStep
* adjx
+ dfogdy
* adjy
)
919 * (1.0F
/FIXED_SCALE
);
920 dfogOuter
= dfogdy
+ dxOuter
* span
.fogStep
;
923 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
924 fr
= (GLfixed
) (ChanToFixed(vLower
->color
[RCOMP
])
925 + drdx
* adjx
+ drdy
* adjy
) + FIXED_HALF
;
926 fdrOuter
= SignedFloatToFixed(drdy
+ dxOuter
* drdx
);
927 fg
= (GLfixed
) (ChanToFixed(vLower
->color
[GCOMP
])
928 + dgdx
* adjx
+ dgdy
* adjy
) + FIXED_HALF
;
929 fdgOuter
= SignedFloatToFixed(dgdy
+ dxOuter
* dgdx
);
930 fb
= (GLfixed
) (ChanToFixed(vLower
->color
[BCOMP
])
931 + dbdx
* adjx
+ dbdy
* adjy
) + FIXED_HALF
;
932 fdbOuter
= SignedFloatToFixed(dbdy
+ dxOuter
* dbdx
);
934 fa
= (GLfixed
) (ChanToFixed(vLower
->color
[ACOMP
])
935 + dadx
* adjx
+ dady
* adjy
) + FIXED_HALF
;
936 fdaOuter
= SignedFloatToFixed(dady
+ dxOuter
* dadx
);
940 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
941 fr
= ChanToFixed(v2
->color
[RCOMP
]);
942 fg
= ChanToFixed(v2
->color
[GCOMP
]);
943 fb
= ChanToFixed(v2
->color
[BCOMP
]);
944 fdrOuter
= fdgOuter
= fdbOuter
= 0;
946 fa
= ChanToFixed(v2
->color
[ACOMP
]);
951 #ifdef INTERP_FLOAT_RGBA
952 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
953 fr
= vLower
->color
[RCOMP
]
954 + (drdx
* adjx
+ drdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
955 fdrOuter
= drdy
+ dxOuter
* drdx
;
956 fg
= vLower
->color
[GCOMP
]
957 + (dgdx
* adjx
+ dgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
958 fdgOuter
= dgdy
+ dxOuter
* dgdx
;
959 fb
= vLower
->color
[BCOMP
]
960 + (dbdx
* adjx
+ dbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
961 fdbOuter
= dbdy
+ dxOuter
* dbdx
;
962 fa
= vLower
->color
[ACOMP
]
963 + (dadx
* adjx
+ dady
* adjy
) * (1.0F
/ FIXED_SCALE
);
964 fdaOuter
= dady
+ dxOuter
* dadx
;
967 fr
= v2
->color
[RCOMP
];
968 fg
= v2
->color
[GCOMP
];
969 fb
= v2
->color
[BCOMP
];
970 fa
= v2
->color
[ACOMP
];
971 fdrOuter
= fdgOuter
= fdbOuter
= fdaOuter
= 0.0F
;
975 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
976 fsr
= (GLfixed
) (ChanToFixed(vLower
->specular
[RCOMP
])
977 + dsrdx
* adjx
+ dsrdy
* adjy
) + FIXED_HALF
;
978 fdsrOuter
= SignedFloatToFixed(dsrdy
+ dxOuter
* dsrdx
);
979 fsg
= (GLfixed
) (ChanToFixed(vLower
->specular
[GCOMP
])
980 + dsgdx
* adjx
+ dsgdy
* adjy
) + FIXED_HALF
;
981 fdsgOuter
= SignedFloatToFixed(dsgdy
+ dxOuter
* dsgdx
);
982 fsb
= (GLfixed
) (ChanToFixed(vLower
->specular
[BCOMP
])
983 + dsbdx
* adjx
+ dsbdy
* adjy
) + FIXED_HALF
;
984 fdsbOuter
= SignedFloatToFixed(dsbdy
+ dxOuter
* dsbdx
);
987 fsr
= ChanToFixed(v2
->specular
[RCOMP
]);
988 fsg
= ChanToFixed(v2
->specular
[GCOMP
]);
989 fsb
= ChanToFixed(v2
->specular
[BCOMP
]);
990 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0;
993 #ifdef INTERP_FLOAT_SPEC
994 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
995 fsr
= vLower
->specular
[RCOMP
]
996 + (dsrdx
* adjx
+ dsrdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
997 fdsrOuter
= dsrdy
+ dxOuter
* dsrdx
;
998 fsg
= vLower
->specular
[GCOMP
]
999 + (dsgdx
* adjx
+ dsgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
1000 fdsgOuter
= dsgdy
+ dxOuter
* dsgdx
;
1001 fsb
= vLower
->specular
[BCOMP
]
1002 + (dsbdx
* adjx
+ dsbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
1003 fdsbOuter
= dsbdy
+ dxOuter
* dsbdx
;
1006 fsr
= v2
->specular
[RCOMP
];
1007 fsg
= v2
->specular
[GCOMP
];
1008 fsb
= v2
->specular
[BCOMP
];
1009 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0.0F
;
1013 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
1014 fi
= (GLfixed
)(vLower
->index
* FIXED_SCALE
1015 + didx
* adjx
+ didy
* adjy
) + FIXED_HALF
;
1016 fdiOuter
= SignedFloatToFixed(didy
+ dxOuter
* didx
);
1019 fi
= (GLfixed
) (v2
->index
* FIXED_SCALE
);
1023 #ifdef INTERP_INT_TEX
1026 s0
= vLower
->texcoord
[0][0] * S_SCALE
;
1027 fs
= (GLfixed
)(s0
* FIXED_SCALE
+ dsdx
* adjx
1028 + dsdy
* adjy
) + FIXED_HALF
;
1029 fdsOuter
= SignedFloatToFixed(dsdy
+ dxOuter
* dsdx
);
1031 t0
= vLower
->texcoord
[0][1] * T_SCALE
;
1032 ft
= (GLfixed
)(t0
* FIXED_SCALE
+ dtdx
* adjx
1033 + dtdy
* adjy
) + FIXED_HALF
;
1034 fdtOuter
= SignedFloatToFixed(dtdy
+ dxOuter
* dtdx
);
1039 GLfloat invW
= vLower
->win
[3];
1040 GLfloat s0
, t0
, u0
, v0
;
1041 s0
= vLower
->texcoord
[0][0] * invW
;
1042 sLeft
= s0
+ (span
.texStep
[0][0] * adjx
+ dsdy
* adjy
)
1043 * (1.0F
/FIXED_SCALE
);
1044 dsOuter
= dsdy
+ dxOuter
* span
.texStep
[0][0];
1045 t0
= vLower
->texcoord
[0][1] * invW
;
1046 tLeft
= t0
+ (span
.texStep
[0][1] * adjx
+ dtdy
* adjy
)
1047 * (1.0F
/FIXED_SCALE
);
1048 dtOuter
= dtdy
+ dxOuter
* span
.texStep
[0][1];
1049 u0
= vLower
->texcoord
[0][2] * invW
;
1050 uLeft
= u0
+ (span
.texStep
[0][2] * adjx
+ dudy
* adjy
)
1051 * (1.0F
/FIXED_SCALE
);
1052 duOuter
= dudy
+ dxOuter
* span
.texStep
[0][2];
1053 v0
= vLower
->texcoord
[0][3] * invW
;
1054 vLeft
= v0
+ (span
.texStep
[0][3] * adjx
+ dvdy
* adjy
)
1055 * (1.0F
/FIXED_SCALE
);
1056 dvOuter
= dvdy
+ dxOuter
* span
.texStep
[0][3];
1059 #ifdef INTERP_MULTITEX
1062 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1063 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1064 GLfloat invW
= vLower
->win
[3];
1065 GLfloat s0
, t0
, u0
, v0
;
1066 s0
= vLower
->texcoord
[u
][0] * invW
;
1067 sLeft
[u
] = s0
+ (span
.texStep
[u
][0] * adjx
+ dsdy
[u
]
1068 * adjy
) * (1.0F
/FIXED_SCALE
);
1069 dsOuter
[u
] = dsdy
[u
] + dxOuter
* span
.texStep
[u
][0];
1070 t0
= vLower
->texcoord
[u
][1] * invW
;
1071 tLeft
[u
] = t0
+ (span
.texStep
[u
][1] * adjx
+ dtdy
[u
]
1072 * adjy
) * (1.0F
/FIXED_SCALE
);
1073 dtOuter
[u
] = dtdy
[u
] + dxOuter
* span
.texStep
[u
][1];
1074 u0
= vLower
->texcoord
[u
][2] * invW
;
1075 uLeft
[u
] = u0
+ (span
.texStep
[u
][2] * adjx
+ dudy
[u
]
1076 * adjy
) * (1.0F
/FIXED_SCALE
);
1077 duOuter
[u
] = dudy
[u
] + dxOuter
* span
.texStep
[u
][2];
1078 v0
= vLower
->texcoord
[u
][3] * invW
;
1079 vLeft
[u
] = v0
+ (span
.texStep
[u
][3] * adjx
+ dvdy
[u
]
1080 * adjy
) * (1.0F
/FIXED_SCALE
);
1081 dvOuter
[u
] = dvdy
[u
] + dxOuter
* span
.texStep
[u
][3];
1090 if (setupRight
&& eRight
->lines
>0) {
1091 fxRightEdge
= eRight
->fsx
- FIXED_EPSILON
;
1092 fdxRightEdge
= eRight
->fdxdy
;
1100 /* Rasterize setup */
1101 #ifdef PIXEL_ADDRESS
1102 dPRowInner
= dPRowOuter
+ sizeof(PIXEL_TYPE
);
1106 dZRowInner
= dZRowOuter
+ sizeof(DEPTH_TYPE
);
1108 fdzInner
= fdzOuter
+ span
.zStep
;
1111 dfogInner
= dfogOuter
+ span
.fogStep
;
1113 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1114 fdrInner
= fdrOuter
+ span
.redStep
;
1115 fdgInner
= fdgOuter
+ span
.greenStep
;
1116 fdbInner
= fdbOuter
+ span
.blueStep
;
1118 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1119 fdaInner
= fdaOuter
+ span
.alphaStep
;
1121 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1122 fdsrInner
= fdsrOuter
+ span
.specRedStep
;
1123 fdsgInner
= fdsgOuter
+ span
.specGreenStep
;
1124 fdsbInner
= fdsbOuter
+ span
.specBlueStep
;
1127 fdiInner
= fdiOuter
+ span
.indexStep
;
1129 #ifdef INTERP_INT_TEX
1130 fdsInner
= fdsOuter
+ span
.intTexStep
[0];
1131 fdtInner
= fdtOuter
+ span
.intTexStep
[1];
1134 dsInner
= dsOuter
+ span
.texStep
[0][0];
1135 dtInner
= dtOuter
+ span
.texStep
[0][1];
1136 duInner
= duOuter
+ span
.texStep
[0][2];
1137 dvInner
= dvOuter
+ span
.texStep
[0][3];
1139 #ifdef INTERP_MULTITEX
1142 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1143 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1144 dsInner
[u
] = dsOuter
[u
] + span
.texStep
[u
][0];
1145 dtInner
[u
] = dtOuter
[u
] + span
.texStep
[u
][1];
1146 duInner
[u
] = duOuter
[u
] + span
.texStep
[u
][2];
1147 dvInner
[u
] = dvOuter
[u
] + span
.texStep
[u
][3];
1154 /* initialize the span interpolants to the leftmost value */
1155 /* ff = fixed-pt fragment */
1156 const GLint right
= FixedToInt(fxRightEdge
);
1158 span
.x
= FixedToInt(fxLeftEdge
);
1160 if (right
<= span
.x
)
1163 span
.end
= right
- span
.x
;
1171 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1176 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1179 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1181 span
.specGreen
= fsg
;
1182 span
.specBlue
= fsb
;
1187 #ifdef INTERP_INT_TEX
1188 span
.intTex
[0] = fs
;
1189 span
.intTex
[1] = ft
;
1193 span
.tex
[0][0] = sLeft
;
1194 span
.tex
[0][1] = tLeft
;
1195 span
.tex
[0][2] = uLeft
;
1196 span
.tex
[0][3] = vLeft
;
1199 #ifdef INTERP_MULTITEX
1202 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1203 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1204 span
.tex
[u
][0] = sLeft
[u
];
1205 span
.tex
[u
][1] = tLeft
[u
];
1206 span
.tex
[u
][2] = uLeft
[u
];
1207 span
.tex
[u
][3] = vLeft
[u
];
1215 /* need this to accomodate round-off errors */
1216 const GLint len
= right
- span
.x
- 1;
1217 GLfixed ffrend
= span
.red
+ len
* span
.redStep
;
1218 GLfixed ffgend
= span
.green
+ len
* span
.greenStep
;
1219 GLfixed ffbend
= span
.blue
+ len
* span
.blueStep
;
1226 span
.green
-= ffgend
;
1231 span
.blue
-= ffbend
;
1239 const GLint len
= right
- span
.x
- 1;
1240 GLfixed ffaend
= span
.alpha
+ len
* span
.alphaStep
;
1242 span
.alpha
-= ffaend
;
1250 /* need this to accomodate round-off errors */
1251 const GLint len
= right
- span
.x
- 1;
1252 GLfixed ffsrend
= span
.specRed
+ len
* span
.specRedStep
;
1253 GLfixed ffsgend
= span
.specGreen
+ len
* span
.specGreenStep
;
1254 GLfixed ffsbend
= span
.specBlue
+ len
* span
.specBlueStep
;
1256 span
.specRed
-= ffsrend
;
1257 if (span
.specRed
< 0)
1261 span
.specGreen
-= ffsgend
;
1262 if (span
.specGreen
< 0)
1266 span
.specBlue
-= ffsbend
;
1267 if (span
.specBlue
< 0)
1273 if (span
.index
< 0) span
.index
= 0;
1276 /* This is where we actually generate fragments */
1278 RENDER_SPAN( span
);
1282 * Advance to the next scan line. Compute the
1283 * new edge coordinates, and adjust the
1284 * pixel-center x coordinate so that it stays
1285 * on or inside the major edge.
1290 fxLeftEdge
+= fdxLeftEdge
;
1291 fxRightEdge
+= fdxRightEdge
;
1296 fError
-= FIXED_ONE
;
1297 #ifdef PIXEL_ADDRESS
1298 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowOuter
);
1302 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowOuter
);
1307 fogLeft
+= dfogOuter
;
1309 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1314 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1317 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1325 #ifdef INTERP_INT_TEX
1335 #ifdef INTERP_MULTITEX
1338 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1339 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1340 sLeft
[u
] += dsOuter
[u
];
1341 tLeft
[u
] += dtOuter
[u
];
1342 uLeft
[u
] += duOuter
[u
];
1343 vLeft
[u
] += dvOuter
[u
];
1350 #ifdef PIXEL_ADDRESS
1351 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowInner
);
1355 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowInner
);
1360 fogLeft
+= dfogInner
;
1362 #if defined(INTERP_RGB) || defined(INTERP_FLOAT_RGBA)
1367 #if defined(INTERP_ALPHA) || defined(INTERP_FLOAT_RGBA)
1370 #if defined(INTERP_SPEC) || defined(INTERP_FLOAT_SPEC)
1378 #ifdef INTERP_INT_TEX
1388 #ifdef INTERP_MULTITEX
1391 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1392 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1393 sLeft
[u
] += dsInner
[u
];
1394 tLeft
[u
] += dtInner
[u
];
1395 uLeft
[u
] += duInner
[u
];
1396 vLeft
[u
] += dvInner
[u
];
1404 } /* for subTriangle */
1418 #undef BYTES_PER_ROW
1419 #undef PIXEL_ADDRESS
1427 #undef INTERP_INT_TEX
1429 #undef INTERP_MULTITEX
1430 #undef INTERP_LAMBDA
1431 #undef INTERP_FLOAT_RGBA
1432 #undef INTERP_FLOAT_SPEC
1439 #undef DO_OCCLUSION_TEST