1 /* $Id: s_tritemp.h,v 1.45 2003/03/16 18:42:13 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2003 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
47 * When one can directly address pixels in the color buffer the following
48 * macros can be defined and used to compute pixel addresses during
49 * rasterization (see pRow):
50 * PIXEL_TYPE - the datatype of a pixel (GLubyte, GLushort, GLuint)
51 * BYTES_PER_ROW - number of bytes per row in the color buffer
52 * PIXEL_ADDRESS(X,Y) - returns the address of pixel at (X,Y) where
53 * Y==0 at bottom of screen and increases upward.
55 * Similarly, for direct depth buffer access, this type is used for depth
57 * DEPTH_TYPE - either GLushort or GLuint
59 * Optionally, one may provide one-time setup code per triangle:
60 * SETUP_CODE - code which is to be executed once per triangle
61 * CLEANUP_CODE - code to execute at end of triangle
63 * The following macro MUST be defined:
64 * RENDER_SPAN(span) - code to write a span of pixels.
66 * This code was designed for the origin to be in the lower-left corner.
68 * Inspired by triangle rasterizer code written by Allen Akin. Thanks Allen!
73 * ColorTemp is used for intermediate color values.
75 #if CHAN_TYPE == GL_FLOAT
76 #define ColorTemp GLfloat
78 #define ColorTemp GLint /* same as GLfixed */
83 static void NAME(GLcontext
*ctx
, const SWvertex
*v0
,
88 const SWvertex
*v0
, *v1
; /* Y(v0) < Y(v1) */
89 GLfloat dx
; /* X(v1) - X(v0) */
90 GLfloat dy
; /* Y(v1) - Y(v0) */
91 GLfixed fdxdy
; /* dx/dy in fixed-point */
92 GLfixed fsx
; /* first sample point x coord */
94 GLfloat adjy
; /* adjust from v[0]->fy to fsy, scaled */
95 GLint lines
; /* number of lines to be sampled on this edge */
96 GLfixed fx0
; /* fixed pt X of lower endpoint */
100 const GLint depthBits
= ctx
->Visual
.depthBits
;
101 const GLint fixedToDepthShift
= depthBits
<= 16 ? FIXED_SHIFT
: 0;
102 const GLfloat maxDepth
= ctx
->DepthMaxF
;
103 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
105 EdgeT eMaj
, eTop
, eBot
;
107 const SWvertex
*vMin
, *vMid
, *vMax
; /* Y(vMin)<=Y(vMid)<=Y(vMax) */
108 float bf
= SWRAST_CONTEXT(ctx
)->_backface_sign
;
109 const GLint snapMask
= ~((FIXED_ONE
/ (1 << SUB_PIXEL_BITS
)) - 1); /* for x/y coord snapping */
110 GLfixed vMin_fx
, vMin_fy
, vMid_fx
, vMid_fy
, vMax_fx
, vMax_fy
;
114 INIT_SPAN(span
, GL_POLYGON
, 0, 0, 0);
117 (void) fixedToDepthShift
;
121 printf("%s()\n", __FUNCTION__);
122 printf(" %g, %g, %g\n", v0->win[0], v0->win[1], v0->win[2]);
123 printf(" %g, %g, %g\n", v1->win[0], v1->win[1], v1->win[2]);
124 printf(" %g, %g, %g\n", v2->win[0], v2->win[1], v2->win[2]);
127 /* Compute fixed point x,y coords w/ half-pixel offsets and snapping.
128 * And find the order of the 3 vertices along the Y axis.
131 const GLfixed fy0
= FloatToFixed(v0
->win
[1] - 0.5F
) & snapMask
;
132 const GLfixed fy1
= FloatToFixed(v1
->win
[1] - 0.5F
) & snapMask
;
133 const GLfixed fy2
= FloatToFixed(v2
->win
[1] - 0.5F
) & snapMask
;
138 vMin
= v0
; vMid
= v1
; vMax
= v2
;
139 vMin_fy
= fy0
; vMid_fy
= fy1
; vMax_fy
= fy2
;
141 else if (fy2
<= fy0
) {
143 vMin
= v2
; vMid
= v0
; vMax
= v1
;
144 vMin_fy
= fy2
; vMid_fy
= fy0
; vMax_fy
= fy1
;
148 vMin
= v0
; vMid
= v2
; vMax
= v1
;
149 vMin_fy
= fy0
; vMid_fy
= fy2
; vMax_fy
= fy1
;
156 vMin
= v1
; vMid
= v0
; vMax
= v2
;
157 vMin_fy
= fy1
; vMid_fy
= fy0
; vMax_fy
= fy2
;
160 else if (fy2
<= fy1
) {
162 vMin
= v2
; vMid
= v1
; vMax
= v0
;
163 vMin_fy
= fy2
; vMid_fy
= fy1
; vMax_fy
= fy0
;
168 vMin
= v1
; vMid
= v2
; vMax
= v0
;
169 vMin_fy
= fy1
; vMid_fy
= fy2
; vMax_fy
= fy0
;
173 /* fixed point X coords */
174 vMin_fx
= FloatToFixed(vMin
->win
[0] + 0.5F
) & snapMask
;
175 vMid_fx
= FloatToFixed(vMid
->win
[0] + 0.5F
) & snapMask
;
176 vMax_fx
= FloatToFixed(vMax
->win
[0] + 0.5F
) & snapMask
;
179 /* vertex/edge relationship */
180 eMaj
.v0
= vMin
; eMaj
.v1
= vMax
; /*TODO: .v1's not needed */
181 eTop
.v0
= vMid
; eTop
.v1
= vMax
;
182 eBot
.v0
= vMin
; eBot
.v1
= vMid
;
184 /* compute deltas for each edge: vertex[upper] - vertex[lower] */
185 eMaj
.dx
= FixedToFloat(vMax_fx
- vMin_fx
);
186 eMaj
.dy
= FixedToFloat(vMax_fy
- vMin_fy
);
187 eTop
.dx
= FixedToFloat(vMax_fx
- vMid_fx
);
188 eTop
.dy
= FixedToFloat(vMax_fy
- vMid_fy
);
189 eBot
.dx
= FixedToFloat(vMid_fx
- vMin_fx
);
190 eBot
.dy
= FixedToFloat(vMid_fy
- vMin_fy
);
192 /* compute area, oneOverArea and perform backface culling */
194 const GLfloat area
= eMaj
.dx
* eBot
.dy
- eBot
.dx
* eMaj
.dy
;
196 /* Do backface culling */
200 if (IS_INF_OR_NAN(area
) || area
== 0.0F
)
203 oneOverArea
= 1.0F
/ area
;
206 #ifndef DO_OCCLUSION_TEST
207 ctx
->OcclusionResult
= GL_TRUE
;
209 span
.facing
= ctx
->_Facing
; /* for 2-sided stencil test */
211 /* Edge setup. For a triangle strip these could be reused... */
213 eMaj
.fsy
= FixedCeil(vMin_fy
);
214 eMaj
.lines
= FixedToInt(FixedCeil(vMax_fy
- eMaj
.fsy
));
215 if (eMaj
.lines
> 0) {
216 GLfloat dxdy
= eMaj
.dx
/ eMaj
.dy
;
217 eMaj
.fdxdy
= SignedFloatToFixed(dxdy
);
218 eMaj
.adjy
= (GLfloat
) (eMaj
.fsy
- vMin_fy
); /* SCALED! */
220 eMaj
.fsx
= eMaj
.fx0
+ (GLfixed
) (eMaj
.adjy
* dxdy
);
226 eTop
.fsy
= FixedCeil(vMid_fy
);
227 eTop
.lines
= FixedToInt(FixedCeil(vMax_fy
- eTop
.fsy
));
228 if (eTop
.lines
> 0) {
229 GLfloat dxdy
= eTop
.dx
/ eTop
.dy
;
230 eTop
.fdxdy
= SignedFloatToFixed(dxdy
);
231 eTop
.adjy
= (GLfloat
) (eTop
.fsy
- vMid_fy
); /* SCALED! */
233 eTop
.fsx
= eTop
.fx0
+ (GLfixed
) (eTop
.adjy
* dxdy
);
236 eBot
.fsy
= FixedCeil(vMin_fy
);
237 eBot
.lines
= FixedToInt(FixedCeil(vMid_fy
- eBot
.fsy
));
238 if (eBot
.lines
> 0) {
239 GLfloat dxdy
= eBot
.dx
/ eBot
.dy
;
240 eBot
.fdxdy
= SignedFloatToFixed(dxdy
);
241 eBot
.adjy
= (GLfloat
) (eBot
.fsy
- vMin_fy
); /* SCALED! */
243 eBot
.fsx
= eBot
.fx0
+ (GLfixed
) (eBot
.adjy
* dxdy
);
248 * Conceptually, we view a triangle as two subtriangles
249 * separated by a perfectly horizontal line. The edge that is
250 * intersected by this line is one with maximal absolute dy; we
251 * call it a ``major'' edge. The other two edges are the
252 * ``top'' edge (for the upper subtriangle) and the ``bottom''
253 * edge (for the lower subtriangle). If either of these two
254 * edges is horizontal or very close to horizontal, the
255 * corresponding subtriangle might cover zero sample points;
256 * we take care to handle such cases, for performance as well
259 * By stepping rasterization parameters along the major edge,
260 * we can avoid recomputing them at the discontinuity where
261 * the top and bottom edges meet. However, this forces us to
262 * be able to scan both left-to-right and right-to-left.
263 * Also, we must determine whether the major edge is at the
264 * left or right side of the triangle. We do this by
265 * computing the magnitude of the cross-product of the major
266 * and top edges. Since this magnitude depends on the sine of
267 * the angle between the two edges, its sign tells us whether
268 * we turn to the left or to the right when travelling along
269 * the major edge to the top edge, and from this we infer
270 * whether the major edge is on the left or the right.
272 * Serendipitously, this cross-product magnitude is also a
273 * value we need to compute the iteration parameter
274 * derivatives for the triangle, and it can be used to perform
275 * backface culling because its sign tells us whether the
276 * triangle is clockwise or counterclockwise. In this code we
277 * refer to it as ``area'' because it's also proportional to
278 * the pixel area of the triangle.
282 GLint scan_from_left_to_right
; /* true if scanning left-to-right */
289 #if defined(INTERP_RGB)
294 #if defined(INTERP_ALPHA)
297 #if defined(INTERP_SPEC)
298 GLfloat dsrdx
, dsrdy
;
299 GLfloat dsgdx
, dsgdy
;
300 GLfloat dsbdx
, dsbdy
;
307 * Execute user-supplied setup code
313 scan_from_left_to_right
= (oneOverArea
< 0.0F
);
316 /* compute d?/dx and d?/dy derivatives */
318 span
.interpMask
|= SPAN_Z
;
320 GLfloat eMaj_dz
, eBot_dz
;
321 eMaj_dz
= vMax
->win
[2] - vMin
->win
[2];
322 eBot_dz
= vMid
->win
[2] - vMin
->win
[2];
323 dzdx
= oneOverArea
* (eMaj_dz
* eBot
.dy
- eMaj
.dy
* eBot_dz
);
324 if (dzdx
> maxDepth
|| dzdx
< -maxDepth
) {
325 /* probably a sliver triangle */
330 dzdy
= oneOverArea
* (eMaj
.dx
* eBot_dz
- eMaj_dz
* eBot
.dx
);
333 span
.zStep
= SignedFloatToFixed(dzdx
);
335 span
.zStep
= (GLint
) dzdx
;
339 span
.interpMask
|= SPAN_FOG
;
341 const GLfloat eMaj_dfog
= vMax
->fog
- vMin
->fog
;
342 const GLfloat eBot_dfog
= vMid
->fog
- vMin
->fog
;
343 span
.fogStep
= oneOverArea
* (eMaj_dfog
* eBot
.dy
- eMaj
.dy
* eBot_dfog
);
344 dfogdy
= oneOverArea
* (eMaj
.dx
* eBot_dfog
- eMaj_dfog
* eBot
.dx
);
348 span
.interpMask
|= SPAN_RGBA
;
349 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
350 GLfloat eMaj_dr
= (GLfloat
) ((ColorTemp
) vMax
->color
[RCOMP
] - vMin
->color
[RCOMP
]);
351 GLfloat eBot_dr
= (GLfloat
) ((ColorTemp
) vMid
->color
[RCOMP
] - vMin
->color
[RCOMP
]);
352 GLfloat eMaj_dg
= (GLfloat
) ((ColorTemp
) vMax
->color
[GCOMP
] - vMin
->color
[GCOMP
]);
353 GLfloat eBot_dg
= (GLfloat
) ((ColorTemp
) vMid
->color
[GCOMP
] - vMin
->color
[GCOMP
]);
354 GLfloat eMaj_db
= (GLfloat
) ((ColorTemp
) vMax
->color
[BCOMP
] - vMin
->color
[BCOMP
]);
355 GLfloat eBot_db
= (GLfloat
) ((ColorTemp
) vMid
->color
[BCOMP
] - vMin
->color
[BCOMP
]);
357 GLfloat eMaj_da
= (GLfloat
) ((ColorTemp
) vMax
->color
[ACOMP
] - vMin
->color
[ACOMP
]);
358 GLfloat eBot_da
= (GLfloat
) ((ColorTemp
) vMid
->color
[ACOMP
] - vMin
->color
[ACOMP
]);
360 drdx
= oneOverArea
* (eMaj_dr
* eBot
.dy
- eMaj
.dy
* eBot_dr
);
361 drdy
= oneOverArea
* (eMaj
.dx
* eBot_dr
- eMaj_dr
* eBot
.dx
);
362 dgdx
= oneOverArea
* (eMaj_dg
* eBot
.dy
- eMaj
.dy
* eBot_dg
);
363 dgdy
= oneOverArea
* (eMaj
.dx
* eBot_dg
- eMaj_dg
* eBot
.dx
);
364 dbdx
= oneOverArea
* (eMaj_db
* eBot
.dy
- eMaj
.dy
* eBot_db
);
365 dbdy
= oneOverArea
* (eMaj
.dx
* eBot_db
- eMaj_db
* eBot
.dx
);
366 # if CHAN_TYPE == GL_FLOAT
368 span
.greenStep
= dgdx
;
369 span
.blueStep
= dbdx
;
371 span
.redStep
= SignedFloatToFixed(drdx
);
372 span
.greenStep
= SignedFloatToFixed(dgdx
);
373 span
.blueStep
= SignedFloatToFixed(dbdx
);
374 # endif /* GL_FLOAT */
376 dadx
= oneOverArea
* (eMaj_da
* eBot
.dy
- eMaj
.dy
* eBot_da
);
377 dady
= oneOverArea
* (eMaj
.dx
* eBot_da
- eMaj_da
* eBot
.dx
);
378 # if CHAN_TYPE == GL_FLOAT
379 span
.alphaStep
= dadx
;
381 span
.alphaStep
= SignedFloatToFixed(dadx
);
382 # endif /* GL_FLOAT */
383 # endif /* INTERP_ALPHA */
386 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
387 span
.interpMask
|= SPAN_FLAT
;
388 drdx
= drdy
= span
.redStep
= 0;
389 dgdx
= dgdy
= span
.greenStep
= 0;
390 dbdx
= dbdy
= span
.blueStep
= 0;
392 dadx
= dady
= span
.alphaStep
= 0;
395 #endif /* INTERP_RGB */
397 span
.interpMask
|= SPAN_SPEC
;
398 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
399 GLfloat eMaj_dsr
= (GLfloat
) ((ColorTemp
) vMax
->specular
[RCOMP
] - vMin
->specular
[RCOMP
]);
400 GLfloat eBot_dsr
= (GLfloat
) ((ColorTemp
) vMid
->specular
[RCOMP
] - vMin
->specular
[RCOMP
]);
401 GLfloat eMaj_dsg
= (GLfloat
) ((ColorTemp
) vMax
->specular
[GCOMP
] - vMin
->specular
[GCOMP
]);
402 GLfloat eBot_dsg
= (GLfloat
) ((ColorTemp
) vMid
->specular
[GCOMP
] - vMin
->specular
[GCOMP
]);
403 GLfloat eMaj_dsb
= (GLfloat
) ((ColorTemp
) vMax
->specular
[BCOMP
] - vMin
->specular
[BCOMP
]);
404 GLfloat eBot_dsb
= (GLfloat
) ((ColorTemp
) vMid
->specular
[BCOMP
] - vMin
->specular
[BCOMP
]);
405 dsrdx
= oneOverArea
* (eMaj_dsr
* eBot
.dy
- eMaj
.dy
* eBot_dsr
);
406 dsrdy
= oneOverArea
* (eMaj
.dx
* eBot_dsr
- eMaj_dsr
* eBot
.dx
);
407 dsgdx
= oneOverArea
* (eMaj_dsg
* eBot
.dy
- eMaj
.dy
* eBot_dsg
);
408 dsgdy
= oneOverArea
* (eMaj
.dx
* eBot_dsg
- eMaj_dsg
* eBot
.dx
);
409 dsbdx
= oneOverArea
* (eMaj_dsb
* eBot
.dy
- eMaj
.dy
* eBot_dsb
);
410 dsbdy
= oneOverArea
* (eMaj
.dx
* eBot_dsb
- eMaj_dsb
* eBot
.dx
);
411 # if CHAN_TYPE == GL_FLOAT
412 span
.specRedStep
= dsrdx
;
413 span
.specGreenStep
= dsgdx
;
414 span
.specBlueStep
= dsbdx
;
416 span
.specRedStep
= SignedFloatToFixed(dsrdx
);
417 span
.specGreenStep
= SignedFloatToFixed(dsgdx
);
418 span
.specBlueStep
= SignedFloatToFixed(dsbdx
);
422 dsrdx
= dsrdy
= span
.specRedStep
= 0;
423 dsgdx
= dsgdy
= span
.specGreenStep
= 0;
424 dsbdx
= dsbdy
= span
.specBlueStep
= 0;
426 #endif /* INTERP_SPEC */
428 span
.interpMask
|= SPAN_INDEX
;
429 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
430 GLfloat eMaj_di
= (GLfloat
) ((GLint
) vMax
->index
- (GLint
) vMin
->index
);
431 GLfloat eBot_di
= (GLfloat
) ((GLint
) vMid
->index
- (GLint
) vMin
->index
);
432 didx
= oneOverArea
* (eMaj_di
* eBot
.dy
- eMaj
.dy
* eBot_di
);
433 didy
= oneOverArea
* (eMaj
.dx
* eBot_di
- eMaj_di
* eBot
.dx
);
434 span
.indexStep
= SignedFloatToFixed(didx
);
437 span
.interpMask
|= SPAN_FLAT
;
442 #ifdef INTERP_INT_TEX
443 span
.interpMask
|= SPAN_INT_TEXTURE
;
445 GLfloat eMaj_ds
= (vMax
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
446 GLfloat eBot_ds
= (vMid
->texcoord
[0][0] - vMin
->texcoord
[0][0]) * S_SCALE
;
447 GLfloat eMaj_dt
= (vMax
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
448 GLfloat eBot_dt
= (vMid
->texcoord
[0][1] - vMin
->texcoord
[0][1]) * T_SCALE
;
449 span
.texStepX
[0][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
450 span
.texStepY
[0][0] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
451 span
.texStepX
[0][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
452 span
.texStepY
[0][1] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
453 span
.intTexStep
[0] = SignedFloatToFixed(span
.texStepX
[0][0]);
454 span
.intTexStep
[1] = SignedFloatToFixed(span
.texStepX
[0][1]);
458 span
.interpMask
|= SPAN_TEXTURE
;
460 const GLfloat wMax
= vMax
->win
[3], wMin
= vMin
->win
[3], wMid
= vMid
->win
[3];
461 GLfloat eMaj_ds
= vMax
->texcoord
[0][0] * wMax
- vMin
->texcoord
[0][0] * wMin
;
462 GLfloat eBot_ds
= vMid
->texcoord
[0][0] * wMid
- vMin
->texcoord
[0][0] * wMin
;
463 GLfloat eMaj_dt
= vMax
->texcoord
[0][1] * wMax
- vMin
->texcoord
[0][1] * wMin
;
464 GLfloat eBot_dt
= vMid
->texcoord
[0][1] * wMid
- vMin
->texcoord
[0][1] * wMin
;
465 GLfloat eMaj_du
= vMax
->texcoord
[0][2] * wMax
- vMin
->texcoord
[0][2] * wMin
;
466 GLfloat eBot_du
= vMid
->texcoord
[0][2] * wMid
- vMin
->texcoord
[0][2] * wMin
;
467 GLfloat eMaj_dv
= vMax
->texcoord
[0][3] * wMax
- vMin
->texcoord
[0][3] * wMin
;
468 GLfloat eBot_dv
= vMid
->texcoord
[0][3] * wMid
- vMin
->texcoord
[0][3] * wMin
;
469 span
.texStepX
[0][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
470 span
.texStepY
[0][0] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
471 span
.texStepX
[0][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
472 span
.texStepY
[0][1] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
473 span
.texStepX
[0][2] = oneOverArea
* (eMaj_du
* eBot
.dy
- eMaj
.dy
* eBot_du
);
474 span
.texStepY
[0][2] = oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
475 span
.texStepX
[0][3] = oneOverArea
* (eMaj_dv
* eBot
.dy
- eMaj
.dy
* eBot_dv
);
476 span
.texStepY
[0][3] = oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
479 #ifdef INTERP_MULTITEX
480 span
.interpMask
|= SPAN_TEXTURE
;
482 const GLfloat wMax
= vMax
->win
[3], wMin
= vMin
->win
[3], wMid
= vMid
->win
[3];
484 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
485 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
486 GLfloat eMaj_ds
= vMax
->texcoord
[u
][0] * wMax
- vMin
->texcoord
[u
][0] * wMin
;
487 GLfloat eBot_ds
= vMid
->texcoord
[u
][0] * wMid
- vMin
->texcoord
[u
][0] * wMin
;
488 GLfloat eMaj_dt
= vMax
->texcoord
[u
][1] * wMax
- vMin
->texcoord
[u
][1] * wMin
;
489 GLfloat eBot_dt
= vMid
->texcoord
[u
][1] * wMid
- vMin
->texcoord
[u
][1] * wMin
;
490 GLfloat eMaj_du
= vMax
->texcoord
[u
][2] * wMax
- vMin
->texcoord
[u
][2] * wMin
;
491 GLfloat eBot_du
= vMid
->texcoord
[u
][2] * wMid
- vMin
->texcoord
[u
][2] * wMin
;
492 GLfloat eMaj_dv
= vMax
->texcoord
[u
][3] * wMax
- vMin
->texcoord
[u
][3] * wMin
;
493 GLfloat eBot_dv
= vMid
->texcoord
[u
][3] * wMid
- vMin
->texcoord
[u
][3] * wMin
;
494 span
.texStepX
[u
][0] = oneOverArea
* (eMaj_ds
* eBot
.dy
- eMaj
.dy
* eBot_ds
);
495 span
.texStepY
[u
][0] = oneOverArea
* (eMaj
.dx
* eBot_ds
- eMaj_ds
* eBot
.dx
);
496 span
.texStepX
[u
][1] = oneOverArea
* (eMaj_dt
* eBot
.dy
- eMaj
.dy
* eBot_dt
);
497 span
.texStepY
[u
][1] = oneOverArea
* (eMaj
.dx
* eBot_dt
- eMaj_dt
* eBot
.dx
);
498 span
.texStepX
[u
][2] = oneOverArea
* (eMaj_du
* eBot
.dy
- eMaj
.dy
* eBot_du
);
499 span
.texStepY
[u
][2] = oneOverArea
* (eMaj
.dx
* eBot_du
- eMaj_du
* eBot
.dx
);
500 span
.texStepX
[u
][3] = oneOverArea
* (eMaj_dv
* eBot
.dy
- eMaj
.dy
* eBot_dv
);
501 span
.texStepY
[u
][3] = oneOverArea
* (eMaj
.dx
* eBot_dv
- eMaj_dv
* eBot
.dx
);
508 * We always sample at pixel centers. However, we avoid
509 * explicit half-pixel offsets in this code by incorporating
510 * the proper offset in each of x and y during the
511 * transformation to window coordinates.
513 * We also apply the usual rasterization rules to prevent
514 * cracks and overlaps. A pixel is considered inside a
515 * subtriangle if it meets all of four conditions: it is on or
516 * to the right of the left edge, strictly to the left of the
517 * right edge, on or below the top edge, and strictly above
518 * the bottom edge. (Some edges may be degenerate.)
520 * The following discussion assumes left-to-right scanning
521 * (that is, the major edge is on the left); the right-to-left
522 * case is a straightforward variation.
524 * We start by finding the half-integral y coordinate that is
525 * at or below the top of the triangle. This gives us the
526 * first scan line that could possibly contain pixels that are
527 * inside the triangle.
529 * Next we creep down the major edge until we reach that y,
530 * and compute the corresponding x coordinate on the edge.
531 * Then we find the half-integral x that lies on or just
532 * inside the edge. This is the first pixel that might lie in
533 * the interior of the triangle. (We won't know for sure
534 * until we check the other edges.)
536 * As we rasterize the triangle, we'll step down the major
537 * edge. For each step in y, we'll move an integer number
538 * of steps in x. There are two possible x step sizes, which
539 * we'll call the ``inner'' step (guaranteed to land on the
540 * edge or inside it) and the ``outer'' step (guaranteed to
541 * land on the edge or outside it). The inner and outer steps
542 * differ by one. During rasterization we maintain an error
543 * term that indicates our distance from the true edge, and
544 * select either the inner step or the outer step, whichever
545 * gets us to the first pixel that falls inside the triangle.
547 * All parameters (z, red, etc.) as well as the buffer
548 * addresses for color and z have inner and outer step values,
549 * so that we can increment them appropriately. This method
550 * eliminates the need to adjust parameters by creeping a
551 * sub-pixel amount into the triangle at each scanline.
557 GLfixed fxLeftEdge
= 0, fxRightEdge
= 0;
558 GLfixed fdxLeftEdge
= 0, fdxRightEdge
= 0;
562 GLfixed fError
= 0, fdError
= 0;
566 PIXEL_TYPE
*pRow
= NULL
;
567 int dPRowOuter
= 0, dPRowInner
; /* offset in bytes */
571 DEPTH_TYPE
*zRow
= NULL
;
572 int dZRowOuter
= 0, dZRowInner
; /* offset in bytes */
574 GLfixed fz
= 0, fdzOuter
= 0, fdzInner
;
577 GLfloat fogLeft
= 0, dfogOuter
= 0, dfogInner
;
580 ColorTemp fr
= 0, fdrOuter
= 0, fdrInner
;
581 ColorTemp fg
= 0, fdgOuter
= 0, fdgInner
;
582 ColorTemp fb
= 0, fdbOuter
= 0, fdbInner
;
585 ColorTemp fa
= 0, fdaOuter
= 0, fdaInner
;
588 ColorTemp fsr
=0, fdsrOuter
=0, fdsrInner
;
589 ColorTemp fsg
=0, fdsgOuter
=0, fdsgInner
;
590 ColorTemp fsb
=0, fdsbOuter
=0, fdsbInner
;
593 GLfixed fi
=0, fdiOuter
=0, fdiInner
;
595 #ifdef INTERP_INT_TEX
596 GLfixed fs
=0, fdsOuter
=0, fdsInner
;
597 GLfixed ft
=0, fdtOuter
=0, fdtInner
;
600 GLfloat sLeft
=0, dsOuter
=0, dsInner
;
601 GLfloat tLeft
=0, dtOuter
=0, dtInner
;
602 GLfloat uLeft
=0, duOuter
=0, duInner
;
603 GLfloat vLeft
=0, dvOuter
=0, dvInner
;
605 #ifdef INTERP_MULTITEX
606 GLfloat sLeft
[MAX_TEXTURE_COORD_UNITS
];
607 GLfloat tLeft
[MAX_TEXTURE_COORD_UNITS
];
608 GLfloat uLeft
[MAX_TEXTURE_COORD_UNITS
];
609 GLfloat vLeft
[MAX_TEXTURE_COORD_UNITS
];
610 GLfloat dsOuter
[MAX_TEXTURE_COORD_UNITS
], dsInner
[MAX_TEXTURE_COORD_UNITS
];
611 GLfloat dtOuter
[MAX_TEXTURE_COORD_UNITS
], dtInner
[MAX_TEXTURE_COORD_UNITS
];
612 GLfloat duOuter
[MAX_TEXTURE_COORD_UNITS
], duInner
[MAX_TEXTURE_COORD_UNITS
];
613 GLfloat dvOuter
[MAX_TEXTURE_COORD_UNITS
], dvInner
[MAX_TEXTURE_COORD_UNITS
];
616 for (subTriangle
=0; subTriangle
<=1; subTriangle
++) {
617 EdgeT
*eLeft
, *eRight
;
618 int setupLeft
, setupRight
;
621 if (subTriangle
==0) {
623 if (scan_from_left_to_right
) {
626 lines
= eRight
->lines
;
633 lines
= eLeft
->lines
;
640 if (scan_from_left_to_right
) {
643 lines
= eRight
->lines
;
650 lines
= eLeft
->lines
;
658 if (setupLeft
&& eLeft
->lines
> 0) {
659 const SWvertex
*vLower
;
660 GLfixed fsx
= eLeft
->fsx
;
662 fError
= fx
- fsx
- FIXED_ONE
;
663 fxLeftEdge
= fsx
- FIXED_EPSILON
;
664 fdxLeftEdge
= eLeft
->fdxdy
;
665 fdxOuter
= FixedFloor(fdxLeftEdge
- FIXED_EPSILON
);
666 fdError
= fdxOuter
- fdxLeftEdge
+ FIXED_ONE
;
667 idxOuter
= FixedToInt(fdxOuter
);
668 dxOuter
= (float) idxOuter
;
672 span
.y
= FixedToInt(fy
);
674 adjx
= (float)(fx
- eLeft
->fx0
); /* SCALED! */
675 adjy
= eLeft
->adjy
; /* SCALED! */
677 (void) adjx
; /* silence compiler warnings */
678 (void) adjy
; /* silence compiler warnings */
682 (void) vLower
; /* silence compiler warnings */
687 pRow
= (PIXEL_TYPE
*) PIXEL_ADDRESS(FixedToInt(fxLeftEdge
), span
.y
);
688 dPRowOuter
= -((int)BYTES_PER_ROW
) + idxOuter
* sizeof(PIXEL_TYPE
);
689 /* negative because Y=0 at bottom and increases upward */
693 * Now we need the set of parameter (z, color, etc.) values at
694 * the point (fx, fy). This gives us properly-sampled parameter
695 * values that we can step from pixel to pixel. Furthermore,
696 * although we might have intermediate results that overflow
697 * the normal parameter range when we step temporarily outside
698 * the triangle, we shouldn't overflow or underflow for any
699 * pixel that's actually inside the triangle.
704 GLfloat z0
= vLower
->win
[2];
705 if (depthBits
<= 16) {
706 /* interpolate fixed-pt values */
707 GLfloat tmp
= (z0
* FIXED_SCALE
+ dzdx
* adjx
+ dzdy
* adjy
) + FIXED_HALF
;
708 if (tmp
< MAX_GLUINT
/ 2)
712 fdzOuter
= SignedFloatToFixed(dzdy
+ dxOuter
* dzdx
);
715 /* interpolate depth values exactly */
716 fz
= (GLint
) (z0
+ dzdx
* FixedToFloat(adjx
) + dzdy
* FixedToFloat(adjy
));
717 fdzOuter
= (GLint
) (dzdy
+ dxOuter
* dzdx
);
720 zRow
= (DEPTH_TYPE
*)
721 _mesa_zbuffer_address(ctx
, FixedToInt(fxLeftEdge
), span
.y
);
722 dZRowOuter
= (ctx
->DrawBuffer
->Width
+ idxOuter
) * sizeof(DEPTH_TYPE
);
727 fogLeft
= vLower
->fog
+ (span
.fogStep
* adjx
+ dfogdy
* adjy
)
728 * (1.0F
/FIXED_SCALE
);
729 dfogOuter
= dfogdy
+ dxOuter
* span
.fogStep
;
732 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
733 # if CHAN_TYPE == GL_FLOAT
734 fr
= vLower
->color
[RCOMP
] + (drdx
* adjx
+ drdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
735 fg
= vLower
->color
[GCOMP
] + (dgdx
* adjx
+ dgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
736 fb
= vLower
->color
[BCOMP
] + (dbdx
* adjx
+ dbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
737 fdrOuter
= drdy
+ dxOuter
* drdx
;
738 fdgOuter
= dgdy
+ dxOuter
* dgdx
;
739 fdbOuter
= dbdy
+ dxOuter
* dbdx
;
741 fr
= (ChanToFixed(vLower
->color
[RCOMP
]) + drdx
* adjx
+ drdy
* adjy
) + FIXED_HALF
;
742 fg
= (ChanToFixed(vLower
->color
[GCOMP
]) + dgdx
* adjx
+ dgdy
* adjy
) + FIXED_HALF
;
743 fb
= (ChanToFixed(vLower
->color
[BCOMP
]) + dbdx
* adjx
+ dbdy
* adjy
) + FIXED_HALF
;
744 fdrOuter
= SignedFloatToFixed(drdy
+ dxOuter
* drdx
);
745 fdgOuter
= SignedFloatToFixed(dgdy
+ dxOuter
* dgdx
);
746 fdbOuter
= SignedFloatToFixed(dbdy
+ dxOuter
* dbdx
);
749 # if CHAN_TYPE == GL_FLOAT
750 fa
= vLower
->color
[ACOMP
] + (dadx
* adjx
+ dady
* adjy
) * (1.0F
/ FIXED_SCALE
);
751 fdaOuter
= dady
+ dxOuter
* dadx
;
753 fa
= (ChanToFixed(vLower
->color
[ACOMP
]) + dadx
* adjx
+ dady
* adjy
) + FIXED_HALF
;
754 fdaOuter
= SignedFloatToFixed(dady
+ dxOuter
* dadx
);
759 ASSERT (ctx
->Light
.ShadeModel
== GL_FLAT
);
760 # if CHAN_TYPE == GL_FLOAT
761 fr
= v2
->color
[RCOMP
];
762 fg
= v2
->color
[GCOMP
];
763 fb
= v2
->color
[BCOMP
];
764 fdrOuter
= fdgOuter
= fdbOuter
= 0.0F
;
766 fr
= ChanToFixed(v2
->color
[RCOMP
]);
767 fg
= ChanToFixed(v2
->color
[GCOMP
]);
768 fb
= ChanToFixed(v2
->color
[BCOMP
]);
769 fdrOuter
= fdgOuter
= fdbOuter
= 0;
772 # if CHAN_TYPE == GL_FLOAT
773 fa
= v2
->color
[ACOMP
];
776 fa
= ChanToFixed(v2
->color
[ACOMP
]);
784 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
785 # if CHAN_TYPE == GL_FLOAT
786 fsr
= vLower
->specular
[RCOMP
] + (dsrdx
* adjx
+ dsrdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
787 fsg
= vLower
->specular
[GCOMP
] + (dsgdx
* adjx
+ dsgdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
788 fsb
= vLower
->specular
[BCOMP
] + (dsbdx
* adjx
+ dsbdy
* adjy
) * (1.0F
/ FIXED_SCALE
);
789 fdsrOuter
= dsrdy
+ dxOuter
* dsrdx
;
790 fdsgOuter
= dsgdy
+ dxOuter
* dsgdx
;
791 fdsbOuter
= dsbdy
+ dxOuter
* dsbdx
;
793 fsr
= (GLfixed
) (ChanToFixed(vLower
->specular
[RCOMP
]) + dsrdx
* adjx
+ dsrdy
* adjy
) + FIXED_HALF
;
794 fsg
= (GLfixed
) (ChanToFixed(vLower
->specular
[GCOMP
]) + dsgdx
* adjx
+ dsgdy
* adjy
) + FIXED_HALF
;
795 fsb
= (GLfixed
) (ChanToFixed(vLower
->specular
[BCOMP
]) + dsbdx
* adjx
+ dsbdy
* adjy
) + FIXED_HALF
;
796 fdsrOuter
= SignedFloatToFixed(dsrdy
+ dxOuter
* dsrdx
);
797 fdsgOuter
= SignedFloatToFixed(dsgdy
+ dxOuter
* dsgdx
);
798 fdsbOuter
= SignedFloatToFixed(dsbdy
+ dxOuter
* dsbdx
);
802 #if CHAN_TYPE == GL_FLOAT
803 fsr
= v2
->specular
[RCOMP
];
804 fsg
= v2
->specular
[GCOMP
];
805 fsb
= v2
->specular
[BCOMP
];
806 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0.0F
;
808 fsr
= ChanToFixed(v2
->specular
[RCOMP
]);
809 fsg
= ChanToFixed(v2
->specular
[GCOMP
]);
810 fsb
= ChanToFixed(v2
->specular
[BCOMP
]);
811 fdsrOuter
= fdsgOuter
= fdsbOuter
= 0;
817 if (ctx
->Light
.ShadeModel
== GL_SMOOTH
) {
818 fi
= (GLfixed
)(vLower
->index
* FIXED_SCALE
819 + didx
* adjx
+ didy
* adjy
) + FIXED_HALF
;
820 fdiOuter
= SignedFloatToFixed(didy
+ dxOuter
* didx
);
823 fi
= (GLfixed
) (v2
->index
* FIXED_SCALE
);
827 #ifdef INTERP_INT_TEX
830 s0
= vLower
->texcoord
[0][0] * S_SCALE
;
831 fs
= (GLfixed
)(s0
* FIXED_SCALE
+ span
.texStepX
[0][0] * adjx
832 + span
.texStepY
[0][0] * adjy
) + FIXED_HALF
;
833 fdsOuter
= SignedFloatToFixed(span
.texStepY
[0][0] + dxOuter
* span
.texStepX
[0][0]);
835 t0
= vLower
->texcoord
[0][1] * T_SCALE
;
836 ft
= (GLfixed
)(t0
* FIXED_SCALE
+ span
.texStepX
[0][1] * adjx
837 + span
.texStepY
[0][1] * adjy
) + FIXED_HALF
;
838 fdtOuter
= SignedFloatToFixed(span
.texStepY
[0][1] + dxOuter
* span
.texStepX
[0][1]);
843 const GLfloat invW
= vLower
->win
[3];
844 const GLfloat s0
= vLower
->texcoord
[0][0] * invW
;
845 const GLfloat t0
= vLower
->texcoord
[0][1] * invW
;
846 const GLfloat u0
= vLower
->texcoord
[0][2] * invW
;
847 const GLfloat v0
= vLower
->texcoord
[0][3] * invW
;
848 sLeft
= s0
+ (span
.texStepX
[0][0] * adjx
+ span
.texStepY
[0][0] * adjy
) * (1.0F
/FIXED_SCALE
);
849 tLeft
= t0
+ (span
.texStepX
[0][1] * adjx
+ span
.texStepY
[0][1] * adjy
) * (1.0F
/FIXED_SCALE
);
850 uLeft
= u0
+ (span
.texStepX
[0][2] * adjx
+ span
.texStepY
[0][2] * adjy
) * (1.0F
/FIXED_SCALE
);
851 vLeft
= v0
+ (span
.texStepX
[0][3] * adjx
+ span
.texStepY
[0][3] * adjy
) * (1.0F
/FIXED_SCALE
);
852 dsOuter
= span
.texStepY
[0][0] + dxOuter
* span
.texStepX
[0][0];
853 dtOuter
= span
.texStepY
[0][1] + dxOuter
* span
.texStepX
[0][1];
854 duOuter
= span
.texStepY
[0][2] + dxOuter
* span
.texStepX
[0][2];
855 dvOuter
= span
.texStepY
[0][3] + dxOuter
* span
.texStepX
[0][3];
858 #ifdef INTERP_MULTITEX
861 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
862 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
863 const GLfloat invW
= vLower
->win
[3];
864 const GLfloat s0
= vLower
->texcoord
[u
][0] * invW
;
865 const GLfloat t0
= vLower
->texcoord
[u
][1] * invW
;
866 const GLfloat u0
= vLower
->texcoord
[u
][2] * invW
;
867 const GLfloat v0
= vLower
->texcoord
[u
][3] * invW
;
868 sLeft
[u
] = s0
+ (span
.texStepX
[u
][0] * adjx
+ span
.texStepY
[u
][0] * adjy
) * (1.0F
/FIXED_SCALE
);
869 tLeft
[u
] = t0
+ (span
.texStepX
[u
][1] * adjx
+ span
.texStepY
[u
][1] * adjy
) * (1.0F
/FIXED_SCALE
);
870 uLeft
[u
] = u0
+ (span
.texStepX
[u
][2] * adjx
+ span
.texStepY
[u
][2] * adjy
) * (1.0F
/FIXED_SCALE
);
871 vLeft
[u
] = v0
+ (span
.texStepX
[u
][3] * adjx
+ span
.texStepY
[u
][3] * adjy
) * (1.0F
/FIXED_SCALE
);
872 dsOuter
[u
] = span
.texStepY
[u
][0] + dxOuter
* span
.texStepX
[u
][0];
873 dtOuter
[u
] = span
.texStepY
[u
][1] + dxOuter
* span
.texStepX
[u
][1];
874 duOuter
[u
] = span
.texStepY
[u
][2] + dxOuter
* span
.texStepX
[u
][2];
875 dvOuter
[u
] = span
.texStepY
[u
][3] + dxOuter
* span
.texStepX
[u
][3];
884 if (setupRight
&& eRight
->lines
>0) {
885 fxRightEdge
= eRight
->fsx
- FIXED_EPSILON
;
886 fdxRightEdge
= eRight
->fdxdy
;
894 /* Rasterize setup */
896 dPRowInner
= dPRowOuter
+ sizeof(PIXEL_TYPE
);
900 dZRowInner
= dZRowOuter
+ sizeof(DEPTH_TYPE
);
902 fdzInner
= fdzOuter
+ span
.zStep
;
905 dfogInner
= dfogOuter
+ span
.fogStep
;
907 #if defined(INTERP_RGB)
908 fdrInner
= fdrOuter
+ span
.redStep
;
909 fdgInner
= fdgOuter
+ span
.greenStep
;
910 fdbInner
= fdbOuter
+ span
.blueStep
;
912 #if defined(INTERP_ALPHA)
913 fdaInner
= fdaOuter
+ span
.alphaStep
;
915 #if defined(INTERP_SPEC)
916 fdsrInner
= fdsrOuter
+ span
.specRedStep
;
917 fdsgInner
= fdsgOuter
+ span
.specGreenStep
;
918 fdsbInner
= fdsbOuter
+ span
.specBlueStep
;
921 fdiInner
= fdiOuter
+ span
.indexStep
;
923 #ifdef INTERP_INT_TEX
924 fdsInner
= fdsOuter
+ span
.intTexStep
[0];
925 fdtInner
= fdtOuter
+ span
.intTexStep
[1];
928 dsInner
= dsOuter
+ span
.texStepX
[0][0];
929 dtInner
= dtOuter
+ span
.texStepX
[0][1];
930 duInner
= duOuter
+ span
.texStepX
[0][2];
931 dvInner
= dvOuter
+ span
.texStepX
[0][3];
933 #ifdef INTERP_MULTITEX
936 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
937 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
938 dsInner
[u
] = dsOuter
[u
] + span
.texStepX
[u
][0];
939 dtInner
[u
] = dtOuter
[u
] + span
.texStepX
[u
][1];
940 duInner
[u
] = duOuter
[u
] + span
.texStepX
[u
][2];
941 dvInner
[u
] = dvOuter
[u
] + span
.texStepX
[u
][3];
948 /* initialize the span interpolants to the leftmost value */
949 /* ff = fixed-pt fragment */
950 const GLint right
= FixedToInt(fxRightEdge
);
952 span
.x
= FixedToInt(fxLeftEdge
);
957 span
.end
= right
- span
.x
;
965 #if defined(INTERP_RGB)
970 #if defined(INTERP_ALPHA)
973 #if defined(INTERP_SPEC)
975 span
.specGreen
= fsg
;
981 #ifdef INTERP_INT_TEX
987 span
.tex
[0][0] = sLeft
;
988 span
.tex
[0][1] = tLeft
;
989 span
.tex
[0][2] = uLeft
;
990 span
.tex
[0][3] = vLeft
;
993 #ifdef INTERP_MULTITEX
996 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
997 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
998 span
.tex
[u
][0] = sLeft
[u
];
999 span
.tex
[u
][1] = tLeft
[u
];
1000 span
.tex
[u
][2] = uLeft
[u
];
1001 span
.tex
[u
][3] = vLeft
[u
];
1009 /* need this to accomodate round-off errors */
1010 const GLint len
= right
- span
.x
- 1;
1011 GLfixed ffrend
= span
.red
+ len
* span
.redStep
;
1012 GLfixed ffgend
= span
.green
+ len
* span
.greenStep
;
1013 GLfixed ffbend
= span
.blue
+ len
* span
.blueStep
;
1020 span
.green
-= ffgend
;
1025 span
.blue
-= ffbend
;
1033 const GLint len
= right
- span
.x
- 1;
1034 GLfixed ffaend
= span
.alpha
+ len
* span
.alphaStep
;
1036 span
.alpha
-= ffaend
;
1044 /* need this to accomodate round-off errors */
1045 const GLint len
= right
- span
.x
- 1;
1046 GLfixed ffsrend
= span
.specRed
+ len
* span
.specRedStep
;
1047 GLfixed ffsgend
= span
.specGreen
+ len
* span
.specGreenStep
;
1048 GLfixed ffsbend
= span
.specBlue
+ len
* span
.specBlueStep
;
1050 span
.specRed
-= ffsrend
;
1051 if (span
.specRed
< 0)
1055 span
.specGreen
-= ffsgend
;
1056 if (span
.specGreen
< 0)
1060 span
.specBlue
-= ffsbend
;
1061 if (span
.specBlue
< 0)
1067 if (span
.index
< 0) span
.index
= 0;
1070 /* This is where we actually generate fragments */
1072 RENDER_SPAN( span
);
1076 * Advance to the next scan line. Compute the
1077 * new edge coordinates, and adjust the
1078 * pixel-center x coordinate so that it stays
1079 * on or inside the major edge.
1084 fxLeftEdge
+= fdxLeftEdge
;
1085 fxRightEdge
+= fdxRightEdge
;
1090 fError
-= FIXED_ONE
;
1091 #ifdef PIXEL_ADDRESS
1092 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowOuter
);
1096 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowOuter
);
1101 fogLeft
+= dfogOuter
;
1103 #if defined(INTERP_RGB)
1108 #if defined(INTERP_ALPHA)
1111 #if defined(INTERP_SPEC)
1119 #ifdef INTERP_INT_TEX
1129 #ifdef INTERP_MULTITEX
1132 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1133 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1134 sLeft
[u
] += dsOuter
[u
];
1135 tLeft
[u
] += dtOuter
[u
];
1136 uLeft
[u
] += duOuter
[u
];
1137 vLeft
[u
] += dvOuter
[u
];
1144 #ifdef PIXEL_ADDRESS
1145 pRow
= (PIXEL_TYPE
*) ((GLubyte
*) pRow
+ dPRowInner
);
1149 zRow
= (DEPTH_TYPE
*) ((GLubyte
*) zRow
+ dZRowInner
);
1154 fogLeft
+= dfogInner
;
1156 #if defined(INTERP_RGB)
1161 #if defined(INTERP_ALPHA)
1164 #if defined(INTERP_SPEC)
1172 #ifdef INTERP_INT_TEX
1182 #ifdef INTERP_MULTITEX
1185 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
1186 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1187 sLeft
[u
] += dsInner
[u
];
1188 tLeft
[u
] += dtInner
[u
];
1189 uLeft
[u
] += duInner
[u
];
1190 vLeft
[u
] += dvInner
[u
];
1198 } /* for subTriangle */
1212 #undef BYTES_PER_ROW
1213 #undef PIXEL_ADDRESS
1221 #undef INTERP_INT_TEX
1223 #undef INTERP_MULTITEX
1230 #undef DO_OCCLUSION_TEST