1 /* $Id: s_triangle.c,v 1.38 2001/09/19 20:30:44 kschultz 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 * When the device driver doesn't implement triangle rasterization it
30 * can hook in _swrast_Triangle, which eventually calls one of these
31 * functions to draw triangles.
40 #include "texformat.h"
44 #include "s_aatriangle.h"
45 #include "s_context.h"
47 #include "s_feedback.h"
49 #include "s_triangle.h"
50 #include "s_trispan.h"
54 GLboolean
_mesa_cull_triangle( GLcontext
*ctx
,
59 GLfloat ex
= v1
->win
[0] - v0
->win
[0];
60 GLfloat ey
= v1
->win
[1] - v0
->win
[1];
61 GLfloat fx
= v2
->win
[0] - v0
->win
[0];
62 GLfloat fy
= v2
->win
[1] - v0
->win
[1];
63 GLfloat c
= ex
*fy
-ey
*fx
;
65 if (c
* SWRAST_CONTEXT(ctx
)->_backface_sign
> 0)
74 * Render a flat-shaded color index triangle.
76 static void flat_ci_triangle( GLcontext
*ctx
,
84 #define RENDER_SPAN( span ) \
85 GLdepth zSpan[MAX_WIDTH]; \
86 GLfloat fogSpan[MAX_WIDTH]; \
88 for (i = 0; i < span.count; i++) { \
89 zSpan[i] = FixedToDepth(span.z); \
90 span.z += span.zStep; \
91 fogSpan[i] = span.fog; \
92 span.fog += span.fogStep; \
94 _mesa_write_monoindex_span(ctx, span.count, span.x, span.y, \
95 zSpan, fogSpan, v0->index, NULL, GL_POLYGON );
97 #include "s_tritemp.h"
103 * Render a smooth-shaded color index triangle.
105 static void smooth_ci_triangle( GLcontext
*ctx
,
112 #define INTERP_INDEX 1
114 #define RENDER_SPAN( span ) \
115 GLdepth zSpan[MAX_WIDTH]; \
116 GLfloat fogSpan[MAX_WIDTH]; \
117 GLuint indexSpan[MAX_WIDTH]; \
119 for (i = 0; i < span.count; i++) { \
120 zSpan[i] = FixedToDepth(span.z); \
121 span.z += span.zStep; \
122 indexSpan[i] = FixedToInt(span.index); \
123 span.index += span.indexStep; \
124 fogSpan[i] = span.fog; \
125 span.fog += span.fogStep; \
127 _mesa_write_index_span(ctx, span.count, span.x, span.y, \
128 zSpan, fogSpan, indexSpan, NULL, GL_POLYGON);
130 #include "s_tritemp.h"
136 * Render a flat-shaded RGBA triangle.
138 static void flat_rgba_triangle( GLcontext
*ctx
,
145 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
147 #define RENDER_SPAN( span ) \
148 GLdepth zSpan[MAX_WIDTH]; \
149 GLfloat fogSpan[MAX_WIDTH]; \
151 for (i = 0; i < span.count; i++) { \
152 zSpan[i] = FixedToDepth(span.z); \
153 span.z += span.zStep; \
154 fogSpan[i] = span.fog; \
155 span.fog += span.fogStep; \
157 _mesa_write_monocolor_span(ctx, span.count, span.x, span.y, zSpan, \
158 fogSpan, v2->color, NULL, GL_POLYGON );
160 #include "s_tritemp.h"
162 ASSERT(!ctx
->Texture
._ReallyEnabled
); /* texturing must be off */
163 ASSERT(ctx
->Light
.ShadeModel
==GL_FLAT
);
169 * Render a smooth-shaded RGBA triangle.
171 static void smooth_rgba_triangle( GLcontext
*ctx
,
179 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
181 #define INTERP_ALPHA 1
183 #define RENDER_SPAN( span ) \
184 GLdepth zSpan[MAX_WIDTH]; \
185 GLchan rgbaSpan[MAX_WIDTH][4]; \
186 GLfloat fogSpan[MAX_WIDTH]; \
188 for (i = 0; i < span.count; i++) { \
189 rgbaSpan[i][RCOMP] = FixedToChan(span.red); \
190 rgbaSpan[i][GCOMP] = FixedToChan(span.green); \
191 rgbaSpan[i][BCOMP] = FixedToChan(span.blue); \
192 rgbaSpan[i][ACOMP] = FixedToChan(span.alpha); \
193 span.red += span.redStep; \
194 span.green += span.greenStep; \
195 span.blue += span.blueStep; \
196 span.alpha += span.alphaStep; \
197 zSpan[i] = FixedToDepth(span.z); \
198 span.z += span.zStep; \
199 fogSpan[i] = span.fog; \
200 span.fog += span.fogStep; \
202 _mesa_write_rgba_span(ctx, span.count, span.x, span.y, \
203 (CONST GLdepth *) zSpan, \
204 fogSpan, rgbaSpan, NULL, GL_POLYGON);
206 #include "s_tritemp.h"
208 ASSERT(!ctx
->Texture
._ReallyEnabled
); /* texturing must be off */
209 ASSERT(ctx
->Light
.ShadeModel
==GL_SMOOTH
);
214 * Render an RGB, GL_DECAL, textured triangle.
215 * Interpolate S,T only w/out mipmapping or perspective correction.
219 static void simple_textured_triangle( GLcontext
*ctx
,
224 #define INTERP_INT_TEX 1
225 #define S_SCALE twidth
226 #define T_SCALE theight
229 SWcontext *swrast = SWRAST_CONTEXT(ctx); \
230 struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \
231 GLint b = obj->BaseLevel; \
232 const GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
233 const GLfloat theight = (GLfloat) obj->Image[b]->Height; \
234 const GLint twidth_log2 = obj->Image[b]->WidthLog2; \
235 const GLchan *texture = (const GLchan *) obj->Image[b]->Data; \
236 const GLint smask = obj->Image[b]->Width - 1; \
237 const GLint tmask = obj->Image[b]->Height - 1; \
239 /* this shouldn't happen */ \
243 #define RENDER_SPAN( span ) \
244 GLchan rgbSpan[MAX_WIDTH][3]; \
246 span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \
247 span.intTex[1] -= FIXED_HALF; \
248 for (i = 0; i < span.count; i++) { \
249 GLint s = FixedToInt(span.intTex[0]) & smask; \
250 GLint t = FixedToInt(span.intTex[1]) & tmask; \
251 GLint pos = (t << twidth_log2) + s; \
252 pos = pos + pos + pos; /* multiply by 3 */ \
253 rgbSpan[i][RCOMP] = texture[pos]; \
254 rgbSpan[i][GCOMP] = texture[pos+1]; \
255 rgbSpan[i][BCOMP] = texture[pos+2]; \
256 span.intTex[0] += span.intTexStep[0]; \
257 span.intTex[1] += span.intTexStep[1]; \
259 (*swrast->Driver.WriteRGBSpan)(ctx, span.count, span.x, span.y, \
260 (CONST GLchan (*)[3]) rgbSpan, NULL );
262 #include "s_tritemp.h"
267 * Render an RGB, GL_DECAL, textured triangle.
268 * Interpolate S,T, GL_LESS depth test, w/out mipmapping or
269 * perspective correction.
273 static void simple_z_textured_triangle( GLcontext
*ctx
,
279 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
280 #define INTERP_INT_TEX 1
281 #define S_SCALE twidth
282 #define T_SCALE theight
285 SWcontext *swrast = SWRAST_CONTEXT(ctx); \
286 struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \
287 GLint b = obj->BaseLevel; \
288 GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
289 GLfloat theight = (GLfloat) obj->Image[b]->Height; \
290 GLint twidth_log2 = obj->Image[b]->WidthLog2; \
291 const GLchan *texture = (const GLchan *) obj->Image[b]->Data; \
292 GLint smask = obj->Image[b]->Width - 1; \
293 GLint tmask = obj->Image[b]->Height - 1; \
295 /* this shouldn't happen */ \
299 #define RENDER_SPAN( span ) \
300 GLchan rgbSpan[MAX_WIDTH][3]; \
301 GLubyte mask[MAX_WIDTH]; \
303 span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \
304 span.intTex[1] -= FIXED_HALF; \
305 for (i = 0; i < span.count; i++) { \
306 const GLdepth z = FixedToDepth(span.z); \
308 GLint s = FixedToInt(span.intTex[0]) & smask; \
309 GLint t = FixedToInt(span.intTex[1]) & tmask; \
310 GLint pos = (t << twidth_log2) + s; \
311 pos = pos + pos + pos; /* multiply by 3 */ \
312 rgbSpan[i][RCOMP] = texture[pos]; \
313 rgbSpan[i][GCOMP] = texture[pos+1]; \
314 rgbSpan[i][BCOMP] = texture[pos+2]; \
321 span.intTex[0] += span.intTexStep[0]; \
322 span.intTex[1] += span.intTexStep[1]; \
323 span.z += span.zStep; \
325 (*swrast->Driver.WriteRGBSpan)(ctx, span.count, span.x, span.y, \
326 (CONST GLchan (*)[3]) rgbSpan, mask );
328 #include "s_tritemp.h"
332 #if CHAN_TYPE != GL_FLOAT
341 const GLchan
*texture
;
342 GLchan er
, eg
, eb
, ea
;
343 GLint tbytesline
, tsize
;
344 GLint fixedToDepthShift
;
348 affine_span(GLcontext
*ctx
, struct triangle_span
*span
,
349 struct affine_info
*info
)
353 /* Instead of defining a function for each mode, a test is done
354 * between the outer and inner loops. This is to reduce code size
355 * and complexity. Observe that an optimizing compiler kills
356 * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
359 #define NEAREST_RGB \
360 tmp_col[RCOMP] = tex00[RCOMP]; \
361 tmp_col[GCOMP] = tex00[GCOMP]; \
362 tmp_col[BCOMP] = tex00[BCOMP]; \
363 tmp_col[ACOMP] = CHAN_MAX
366 tmp_col[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) + \
367 tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT; \
368 tmp_col[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) + \
369 tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT; \
370 tmp_col[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) + \
371 tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT; \
372 tmp_col[ACOMP] = CHAN_MAX
374 #define NEAREST_RGBA COPY_CHAN4(tmp_col, tex00)
376 #define LINEAR_RGBA \
377 tmp_col[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) + \
378 tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;\
379 tmp_col[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) + \
380 tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;\
381 tmp_col[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) + \
382 tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;\
383 tmp_col[ACOMP] = (ti * (si * tex00[3] + sf * tex01[3]) + \
384 tf * (si * tex10[3] + sf * tex11[3])) >> 2 * FIXED_SHIFT
387 dest[RCOMP] = span->red * (tmp_col[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
388 dest[GCOMP] = span->green * (tmp_col[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \
389 dest[BCOMP] = span->blue * (tmp_col[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \
390 dest[ACOMP] = span->alpha * (tmp_col[ACOMP] + 1u) >> (FIXED_SHIFT + 8)
393 dest[RCOMP] = ((CHAN_MAX - tmp_col[ACOMP]) * span->red + \
394 ((tmp_col[ACOMP] + 1) * tmp_col[RCOMP] << FIXED_SHIFT)) \
395 >> (FIXED_SHIFT + 8); \
396 dest[GCOMP] = ((CHAN_MAX - tmp_col[ACOMP]) * span->green + \
397 ((tmp_col[ACOMP] + 1) * tmp_col[GCOMP] << FIXED_SHIFT)) \
398 >> (FIXED_SHIFT + 8); \
399 dest[BCOMP] = ((CHAN_MAX - tmp_col[ACOMP]) * span->blue + \
400 ((tmp_col[ACOMP] + 1) * tmp_col[BCOMP] << FIXED_SHIFT)) \
401 >> (FIXED_SHIFT + 8); \
402 dest[ACOMP] = FixedToInt(span->alpha)
405 dest[RCOMP] = ((CHAN_MAX - tmp_col[RCOMP]) * span->red \
406 + (tmp_col[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8); \
407 dest[GCOMP] = ((CHAN_MAX - tmp_col[GCOMP]) * span->green \
408 + (tmp_col[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8); \
409 dest[BCOMP] = ((CHAN_MAX - tmp_col[BCOMP]) * span->blue \
410 + (tmp_col[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8); \
411 dest[ACOMP] = span->alpha * (tmp_col[ACOMP] + 1) >> (FIXED_SHIFT + 8)
413 #define REPLACE COPY_CHAN4(dest, tmp_col)
415 #define I2CHAN_CLAMP(I) (GLchan) ((I) & CHAN_MAX)
416 /* equivalent to '(GLchan) MIN2((I),CHAN_MAX)' */
419 dest[RCOMP] = MIN2(((span->red << 8) + \
420 (tmp_col[RCOMP] + 1) * info->er) \
421 >> (FIXED_SHIFT + 8), CHAN_MAX); \
422 dest[GCOMP] = MIN2(((span->green << 8) + \
423 (tmp_col[GCOMP] + 1) * info->eg) \
424 >> (FIXED_SHIFT + 8), CHAN_MAX); \
425 dest[RCOMP] = MIN2(((span->blue << 8) + \
426 (tmp_col[BCOMP] + 1) * info->eb) \
427 >> (FIXED_SHIFT + 8), CHAN_MAX); \
428 dest[ACOMP] = span->alpha * (tmp_col[ACOMP] + 1) >> (FIXED_SHIFT + 8)
432 #define NEAREST_RGB_REPLACE NEAREST_RGB;REPLACE
434 #define NEAREST_RGBA_REPLACE COPY_CHAN4(dest, tex00)
436 #define SPAN_NEAREST(DO_TEX,COMP) \
437 for (i = 0; i < span->count; i++) { \
438 /* Isn't it necessary to use FixedFloor below?? */ \
439 GLint s = FixedToInt(span->intTex[0]) & info->smask; \
440 GLint t = FixedToInt(span->intTex[1]) & info->tmask; \
441 GLint pos = (t << info->twidth_log2) + s; \
442 const GLchan *tex00 = info->texture + COMP * pos; \
443 zspan[i] = FixedToDepth(span->z); \
444 fogspan[i] = span->fog; \
446 span->fog += span->fogStep; \
447 span->z += span->zStep; \
448 span->red += span->redStep; \
449 span->green += span->greenStep; \
450 span->blue += span->blueStep; \
451 span->alpha += span->alphaStep; \
452 span->intTex[0] += span->intTexStep[0]; \
453 span->intTex[1] += span->intTexStep[1]; \
457 #define SPAN_LINEAR(DO_TEX,COMP) \
458 for (i = 0; i < span->count; i++) { \
459 /* Isn't it necessary to use FixedFloor below?? */ \
460 GLint s = FixedToInt(span->intTex[0]) & info->smask; \
461 GLint t = FixedToInt(span->intTex[1]) & info->tmask; \
462 GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK; \
463 GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK; \
464 GLfixed si = FIXED_FRAC_MASK - sf; \
465 GLfixed ti = FIXED_FRAC_MASK - tf; \
466 GLint pos = (t << info->twidth_log2) + s; \
467 const GLchan *tex00 = info->texture + COMP * pos; \
468 const GLchan *tex10 = tex00 + info->tbytesline; \
469 const GLchan *tex01 = tex00 + COMP; \
470 const GLchan *tex11 = tex10 + COMP; \
473 if (t == info->tmask) { \
474 tex10 -= info->tsize; \
475 tex11 -= info->tsize; \
477 if (s == info->smask) { \
478 tex01 -= info->tbytesline; \
479 tex11 -= info->tbytesline; \
481 zspan[i] = FixedToDepth(span->z); \
482 fogspan[i] = span->fog; \
484 span->fog += span->fogStep; \
485 span->z += span->zStep; \
486 span->red += span->redStep; \
487 span->green += span->greenStep; \
488 span->blue += span->blueStep; \
489 span->alpha += span->alphaStep; \
490 span->intTex[0] += span->intTexStep[0]; \
491 span->intTex[1] += span->intTexStep[1]; \
495 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
498 GLdepth zspan
[MAX_WIDTH
];
499 GLfloat fogspan
[MAX_WIDTH
];
500 GLchan rgba
[MAX_WIDTH
][4];
501 GLchan
*dest
= rgba
[0];
502 const GLint fixedToDepthShift
= info
->fixedToDepthShift
;
504 span
->intTex
[0] -= FIXED_HALF
;
505 span
->intTex
[1] -= FIXED_HALF
;
506 switch (info
->filter
) {
508 switch (info
->format
) {
510 switch (info
->envmode
) {
512 SPAN_NEAREST(NEAREST_RGB
;MODULATE
,3);
516 SPAN_NEAREST(NEAREST_RGB_REPLACE
,3);
519 SPAN_NEAREST(NEAREST_RGB
;BLEND
,3);
522 SPAN_NEAREST(NEAREST_RGB
;ADD
,3);
529 switch(info
->envmode
) {
531 SPAN_NEAREST(NEAREST_RGBA
;MODULATE
,4);
534 SPAN_NEAREST(NEAREST_RGBA
;DECAL
,4);
537 SPAN_NEAREST(NEAREST_RGBA
;BLEND
,4);
540 SPAN_NEAREST(NEAREST_RGBA
;ADD
,4);
543 SPAN_NEAREST(NEAREST_RGBA_REPLACE
,4);
553 span
->intTex
[0] -= FIXED_HALF
;
554 span
->intTex
[1] -= FIXED_HALF
;
555 switch (info
->format
) {
557 switch (info
->envmode
) {
559 SPAN_LINEAR(LINEAR_RGB
;MODULATE
,3);
563 SPAN_LINEAR(LINEAR_RGB
;REPLACE
,3);
566 SPAN_LINEAR(LINEAR_RGB
;BLEND
,3);
569 SPAN_LINEAR(LINEAR_RGB
;ADD
,3);
576 switch (info
->envmode
) {
578 SPAN_LINEAR(LINEAR_RGBA
;MODULATE
,4);
581 SPAN_LINEAR(LINEAR_RGBA
;DECAL
,4);
584 SPAN_LINEAR(LINEAR_RGBA
;BLEND
,4);
587 SPAN_LINEAR(LINEAR_RGBA
;ADD
,4);
590 SPAN_LINEAR(LINEAR_RGBA
;REPLACE
,4);
598 _mesa_write_rgba_span(ctx
, span
->count
, span
->x
, span
->y
,
599 zspan
, fogspan
, rgba
, NULL
, GL_POLYGON
);
609 * Render an RGB/RGBA textured triangle without perspective correction.
611 static void affine_textured_triangle( GLcontext
*ctx
,
618 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
620 #define INTERP_ALPHA 1
621 #define INTERP_INT_TEX 1
622 #define S_SCALE twidth
623 #define T_SCALE theight
626 struct affine_info info; \
627 struct gl_texture_unit *unit = ctx->Texture.Unit+0; \
628 struct gl_texture_object *obj = unit->Current2D; \
629 GLint b = obj->BaseLevel; \
630 GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
631 GLfloat theight = (GLfloat) obj->Image[b]->Height; \
632 info.fixedToDepthShift = ctx->Visual.depthBits <= 16 ? FIXED_SHIFT : 0;\
633 info.texture = (const GLchan *) obj->Image[b]->Data; \
634 info.twidth_log2 = obj->Image[b]->WidthLog2; \
635 info.smask = obj->Image[b]->Width - 1; \
636 info.tmask = obj->Image[b]->Height - 1; \
637 info.format = obj->Image[b]->Format; \
638 info.filter = obj->MinFilter; \
639 info.envmode = unit->EnvMode; \
641 if (info.envmode == GL_BLEND) { \
642 /* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \
643 info.er = FloatToFixed(unit->EnvColor[RCOMP]); \
644 info.eg = FloatToFixed(unit->EnvColor[GCOMP]); \
645 info.eb = FloatToFixed(unit->EnvColor[BCOMP]); \
646 info.ea = FloatToFixed(unit->EnvColor[ACOMP]); \
648 if (!info.texture) { \
649 /* this shouldn't happen */ \
653 switch (info.format) { \
657 info.tbytesline = obj->Image[b]->Width; \
659 case GL_LUMINANCE_ALPHA: \
660 info.tbytesline = obj->Image[b]->Width * 2; \
663 info.tbytesline = obj->Image[b]->Width * 3; \
666 info.tbytesline = obj->Image[b]->Width * 4; \
669 _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
672 info.tsize = obj->Image[b]->Height * info.tbytesline;
674 #define RENDER_SPAN( span ) affine_span(ctx, &span, &info);
676 #include "s_tritemp.h"
689 const GLchan
*texture
;
690 GLchan er
, eg
, eb
, ea
;
691 GLint tbytesline
, tsize
;
692 GLint fixedToDepthShift
;
697 fast_persp_span(GLcontext
*ctx
, struct triangle_span
*span
,
698 struct persp_info
*info
)
702 /* Instead of defining a function for each mode, a test is done
703 * between the outer and inner loops. This is to reduce code size
704 * and complexity. Observe that an optimizing compiler kills
705 * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
707 #define SPAN_NEAREST(DO_TEX,COMP) \
708 for (i = 0; i < span->count; i++) { \
709 GLdouble invQ = tex_coord[2] ? \
710 (1.0 / tex_coord[2]) : 1.0; \
711 GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \
712 GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \
713 GLint s = IFLOOR(s_tmp) & info->smask; \
714 GLint t = IFLOOR(t_tmp) & info->tmask; \
715 GLint pos = (t << info->twidth_log2) + s; \
716 const GLchan *tex00 = info->texture + COMP * pos; \
717 zspan[i] = FixedToDepth(span->z); \
718 fogspan[i] = span->fog; \
720 span->fog += span->fogStep; \
721 span->z += span->zStep; \
722 span->red += span->redStep; \
723 span->green += span->greenStep; \
724 span->blue += span->blueStep; \
725 span->alpha += span->alphaStep; \
726 tex_coord[0] += tex_step[0]; \
727 tex_coord[1] += tex_step[1]; \
728 tex_coord[2] += tex_step[2]; \
732 #define SPAN_LINEAR(DO_TEX,COMP) \
733 for (i = 0; i < span->count; i++) { \
734 GLdouble invQ = tex_coord[2] ? \
735 (1.0 / tex_coord[2]) : 1.0; \
736 GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \
737 GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \
738 GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF; \
739 GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF; \
740 GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask; \
741 GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask; \
742 GLfixed sf = s_fix & FIXED_FRAC_MASK; \
743 GLfixed tf = t_fix & FIXED_FRAC_MASK; \
744 GLfixed si = FIXED_FRAC_MASK - sf; \
745 GLfixed ti = FIXED_FRAC_MASK - tf; \
746 GLint pos = (t << info->twidth_log2) + s; \
747 const GLchan *tex00 = info->texture + COMP * pos; \
748 const GLchan *tex10 = tex00 + info->tbytesline; \
749 const GLchan *tex01 = tex00 + COMP; \
750 const GLchan *tex11 = tex10 + COMP; \
753 if (t == info->tmask) { \
754 tex10 -= info->tsize; \
755 tex11 -= info->tsize; \
757 if (s == info->smask) { \
758 tex01 -= info->tbytesline; \
759 tex11 -= info->tbytesline; \
761 zspan[i] = FixedToDepth(span->z); \
762 fogspan[i] = span->fog; \
764 span->fog += span->fogStep; \
765 span->z += span->zStep; \
766 span->red += span->redStep; \
767 span->green += span->greenStep; \
768 span->blue += span->blueStep; \
769 span->alpha += span->alphaStep; \
770 tex_coord[0] += tex_step[0]; \
771 tex_coord[1] += tex_step[1]; \
772 tex_coord[2] += tex_step[2]; \
776 #define FixedToDepth(F) ((F) >> fixedToDepthShift)
779 GLdepth zspan
[MAX_WIDTH
];
780 GLfloat tex_coord
[3], tex_step
[3];
781 GLfloat fogspan
[MAX_WIDTH
];
782 GLchan rgba
[MAX_WIDTH
][4];
783 GLchan
*dest
= rgba
[0];
784 const GLint fixedToDepthShift
= info
->fixedToDepthShift
;
786 tex_coord
[0] = span
->tex
[0][0] * (info
->smask
+ 1),
787 tex_step
[0] = span
->texStep
[0][0] * (info
->smask
+ 1);
788 tex_coord
[1] = span
->tex
[0][1] * (info
->tmask
+ 1),
789 tex_step
[1] = span
->texStep
[0][1] * (info
->tmask
+ 1);
790 /* span->tex[0][2] only if 3D-texturing, here only 2D */
791 tex_coord
[2] = span
->tex
[0][3],
792 tex_step
[2] = span
->texStep
[0][3];
794 switch (info
->filter
) {
796 switch (info
->format
) {
798 switch (info
->envmode
) {
800 SPAN_NEAREST(NEAREST_RGB
;MODULATE
,3);
804 SPAN_NEAREST(NEAREST_RGB_REPLACE
,3);
807 SPAN_NEAREST(NEAREST_RGB
;BLEND
,3);
810 SPAN_NEAREST(NEAREST_RGB
;ADD
,3);
817 switch(info
->envmode
) {
819 SPAN_NEAREST(NEAREST_RGBA
;MODULATE
,4);
822 SPAN_NEAREST(NEAREST_RGBA
;DECAL
,4);
825 SPAN_NEAREST(NEAREST_RGBA
;BLEND
,4);
828 SPAN_NEAREST(NEAREST_RGBA
;ADD
,4);
831 SPAN_NEAREST(NEAREST_RGBA_REPLACE
,4);
841 switch (info
->format
) {
843 switch (info
->envmode
) {
845 SPAN_LINEAR(LINEAR_RGB
;MODULATE
,3);
849 SPAN_LINEAR(LINEAR_RGB
;REPLACE
,3);
852 SPAN_LINEAR(LINEAR_RGB
;BLEND
,3);
855 SPAN_LINEAR(LINEAR_RGB
;ADD
,3);
862 switch (info
->envmode
) {
864 SPAN_LINEAR(LINEAR_RGBA
;MODULATE
,4);
867 SPAN_LINEAR(LINEAR_RGBA
;DECAL
,4);
870 SPAN_LINEAR(LINEAR_RGBA
;BLEND
,4);
873 SPAN_LINEAR(LINEAR_RGBA
;ADD
,4);
876 SPAN_LINEAR(LINEAR_RGBA
;REPLACE
,4);
885 /* This does not seem to be necessary, but I don't know !! */
886 /* span->tex[0][0] = tex_coord[0] / (info->smask + 1),
887 span->tex[0][1] = tex_coord[1] / (info->tmask + 1),*/
888 /* span->tex[0][2] only if 3D-texturing, here only 2D */
889 /* span->tex[0][3] = tex_coord[2]; */
891 _mesa_write_rgba_span(ctx
, span
->count
, span
->x
, span
->y
,
892 zspan
, fogspan
, rgba
, NULL
, GL_POLYGON
);
902 * Render an perspective corrected RGB/RGBA textured triangle.
903 * The Q (aka V in Mesa) coordinate must be zero such that the divide
904 * by interpolated Q/W comes out right.
907 static void persp_textured_triangle( GLcontext
*ctx
,
914 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
916 #define INTERP_ALPHA 1
920 struct persp_info info; \
921 struct gl_texture_unit *unit = ctx->Texture.Unit+0; \
922 struct gl_texture_object *obj = unit->Current2D; \
923 GLint b = obj->BaseLevel; \
924 info.fixedToDepthShift = ctx->Visual.depthBits <= 16 ? FIXED_SHIFT : 0;\
925 info.texture = (const GLchan *) obj->Image[b]->Data; \
926 info.twidth_log2 = obj->Image[b]->WidthLog2; \
927 info.smask = obj->Image[b]->Width - 1; \
928 info.tmask = obj->Image[b]->Height - 1; \
929 info.format = obj->Image[b]->Format; \
930 info.filter = obj->MinFilter; \
931 info.envmode = unit->EnvMode; \
933 if (info.envmode == GL_BLEND) { \
934 /* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \
935 info.er = FloatToFixed(unit->EnvColor[RCOMP]); \
936 info.eg = FloatToFixed(unit->EnvColor[GCOMP]); \
937 info.eb = FloatToFixed(unit->EnvColor[BCOMP]); \
938 info.ea = FloatToFixed(unit->EnvColor[ACOMP]); \
940 if (!info.texture) { \
941 /* this shouldn't happen */ \
945 switch (info.format) { \
949 info.tbytesline = obj->Image[b]->Width; \
951 case GL_LUMINANCE_ALPHA: \
952 info.tbytesline = obj->Image[b]->Width * 2; \
955 info.tbytesline = obj->Image[b]->Width * 3; \
958 info.tbytesline = obj->Image[b]->Width * 4; \
961 _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
964 info.tsize = obj->Image[b]->Height * info.tbytesline;
966 #define RENDER_SPAN( span ) fast_persp_span(ctx, &span, &info);
968 #include "s_tritemp.h"
973 #endif /* CHAN_BITS != GL_FLOAT */
977 * Generate arrays of fragment colors, z, fog, texcoords, etc from a
978 * triangle span object. Then call the span/fragment processsing
979 * functions in s_span.[ch]. This is used by a bunch of the textured
980 * triangle functions.
983 rasterize_span(GLcontext
*ctx
, const struct triangle_span
*span
)
985 DEFMARRAY(GLchan
, rgba
, MAX_WIDTH
, 4);
986 DEFMARRAY(GLchan
, spec
, MAX_WIDTH
, 4);
987 DEFARRAY(GLuint
, index
, MAX_WIDTH
);
988 DEFARRAY(GLuint
, z
, MAX_WIDTH
);
989 DEFARRAY(GLfloat
, fog
, MAX_WIDTH
);
990 DEFARRAY(GLfloat
, sTex
, MAX_WIDTH
);
991 DEFARRAY(GLfloat
, tTex
, MAX_WIDTH
);
992 DEFARRAY(GLfloat
, rTex
, MAX_WIDTH
);
993 DEFARRAY(GLfloat
, lambda
, MAX_WIDTH
);
994 DEFMARRAY(GLfloat
, msTex
, MAX_TEXTURE_UNITS
, MAX_WIDTH
);
995 DEFMARRAY(GLfloat
, mtTex
, MAX_TEXTURE_UNITS
, MAX_WIDTH
);
996 DEFMARRAY(GLfloat
, mrTex
, MAX_TEXTURE_UNITS
, MAX_WIDTH
);
997 DEFMARRAY(GLfloat
, mLambda
, MAX_TEXTURE_UNITS
, MAX_WIDTH
);
999 CHECKARRAY(rgba
, return);
1000 CHECKARRAY(spec
, return);
1001 CHECKARRAY(index
, return);
1002 CHECKARRAY(z
, return);
1003 CHECKARRAY(fog
, return);
1004 CHECKARRAY(sTex
, return);
1005 CHECKARRAY(tTex
, return);
1006 CHECKARRAY(rTex
, return);
1007 CHECKARRAY(lambda
, return);
1008 CHECKARRAY(msTex
, return);
1009 CHECKARRAY(mtTex
, return);
1010 CHECKARRAY(mrTex
, return);
1011 CHECKARRAY(mLambda
, return);
1013 if (span
->activeMask
& SPAN_RGBA
) {
1014 if (span
->activeMask
& SPAN_FLAT
) {
1017 color
[RCOMP
] = FixedToChan(span
->red
);
1018 color
[GCOMP
] = FixedToChan(span
->green
);
1019 color
[BCOMP
] = FixedToChan(span
->blue
);
1020 color
[ACOMP
] = FixedToChan(span
->alpha
);
1021 for (i
= 0; i
< span
->count
; i
++) {
1022 COPY_CHAN4(rgba
[i
], color
);
1026 /* smooth interpolation */
1027 #if CHAN_TYPE == GL_FLOAT
1028 GLfloat r
= span
->red
;
1029 GLfloat g
= span
->green
;
1030 GLfloat b
= span
->blue
;
1031 GLfloat a
= span
->alpha
;
1033 GLfixed r
= span
->red
;
1034 GLfixed g
= span
->green
;
1035 GLfixed b
= span
->blue
;
1036 GLfixed a
= span
->alpha
;
1039 for (i
= 0; i
< span
->count
; i
++) {
1040 rgba
[i
][RCOMP
] = FixedToChan(r
);
1041 rgba
[i
][GCOMP
] = FixedToChan(g
);
1042 rgba
[i
][BCOMP
] = FixedToChan(b
);
1043 rgba
[i
][ACOMP
] = FixedToChan(a
);
1045 g
+= span
->greenStep
;
1046 b
+= span
->blueStep
;
1047 a
+= span
->alphaStep
;
1052 if (span
->activeMask
& SPAN_SPEC
) {
1053 if (span
->activeMask
& SPAN_FLAT
) {
1054 const GLchan r
= FixedToChan(span
->specRed
);
1055 const GLchan g
= FixedToChan(span
->specGreen
);
1056 const GLchan b
= FixedToChan(span
->specBlue
);
1058 for (i
= 0; i
< span
->count
; i
++) {
1065 /* smooth interpolation */
1066 #if CHAN_TYPE == GL_FLOAT
1067 GLfloat r
= span
->specRed
;
1068 GLfloat g
= span
->specGreen
;
1069 GLfloat b
= span
->specBlue
;
1071 GLfixed r
= span
->specRed
;
1072 GLfixed g
= span
->specGreen
;
1073 GLfixed b
= span
->specBlue
;
1076 for (i
= 0; i
< span
->count
; i
++) {
1077 spec
[i
][RCOMP
] = FixedToChan(r
);
1078 spec
[i
][GCOMP
] = FixedToChan(g
);
1079 spec
[i
][BCOMP
] = FixedToChan(b
);
1080 r
+= span
->specRedStep
;
1081 g
+= span
->specGreenStep
;
1082 b
+= span
->specBlueStep
;
1087 if (span
->activeMask
& SPAN_INDEX
) {
1088 if (span
->activeMask
& SPAN_FLAT
) {
1090 const GLint indx
= FixedToInt(span
->index
);
1091 for (i
= 0; i
< span
->count
; i
++) {
1096 /* smooth interpolation */
1098 GLfixed ind
= span
->index
;
1099 for (i
= 0; i
< span
->count
; i
++) {
1100 index
[i
] = FixedToInt(ind
);
1101 ind
+= span
->indexStep
;
1106 if (span
->activeMask
& SPAN_Z
) {
1107 if (ctx
->Visual
.depthBits
<= 16) {
1109 GLfixed zval
= span
->z
;
1110 for (i
= 0; i
< span
->count
; i
++) {
1111 z
[i
] = FixedToInt(zval
);
1112 zval
+= span
->zStep
;
1116 /* Deep Z buffer, no fixed->int shift */
1118 GLfixed zval
= span
->z
;
1119 for (i
= 0; i
< span
->count
; i
++) {
1121 zval
+= span
->zStep
;
1125 if (span
->activeMask
& SPAN_FOG
) {
1127 GLfloat f
= span
->fog
;
1128 for (i
= 0; i
< span
->count
; i
++) {
1133 if (span
->activeMask
& SPAN_TEXTURE
) {
1134 if (ctx
->Texture
._ReallyEnabled
& ~TEXTURE0_ANY
) {
1136 if (span
->activeMask
& SPAN_LAMBDA
) {
1139 for (u
= 0; u
< MAX_TEXTURE_UNITS
; u
++) {
1140 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1141 GLfloat s
= span
->tex
[u
][0];
1142 GLfloat t
= span
->tex
[u
][1];
1143 GLfloat r
= span
->tex
[u
][2];
1144 GLfloat q
= span
->tex
[u
][3];
1146 for (i
= 0; i
< span
->count
; i
++) {
1147 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
1148 msTex
[u
][i
] = s
* invQ
;
1149 mtTex
[u
][i
] = t
* invQ
;
1150 mrTex
[u
][i
] = r
* invQ
;
1151 mLambda
[u
][i
] = (GLfloat
)
1152 (log(span
->rho
[u
] * invQ
* invQ
) * 1.442695F
* 0.5F
);
1153 s
+= span
->texStep
[u
][0];
1154 t
+= span
->texStep
[u
][1];
1155 r
+= span
->texStep
[u
][2];
1156 q
+= span
->texStep
[u
][3];
1162 /* without lambda */
1164 for (u
= 0; u
< MAX_TEXTURE_UNITS
; u
++) {
1165 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1166 GLfloat s
= span
->tex
[u
][0];
1167 GLfloat t
= span
->tex
[u
][1];
1168 GLfloat r
= span
->tex
[u
][2];
1169 GLfloat q
= span
->tex
[u
][3];
1171 for (i
= 0; i
< span
->count
; i
++) {
1172 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
1173 msTex
[u
][i
] = s
* invQ
;
1174 mtTex
[u
][i
] = t
* invQ
;
1175 mrTex
[u
][i
] = r
* invQ
;
1176 s
+= span
->texStep
[u
][0];
1177 t
+= span
->texStep
[u
][1];
1178 r
+= span
->texStep
[u
][2];
1179 q
+= span
->texStep
[u
][3];
1186 /* just texture unit 0 */
1187 if (span
->activeMask
& SPAN_LAMBDA
) {
1189 GLfloat s
= span
->tex
[0][0];
1190 GLfloat t
= span
->tex
[0][1];
1191 GLfloat r
= span
->tex
[0][2];
1192 GLfloat q
= span
->tex
[0][3];
1194 for (i
= 0; i
< span
->count
; i
++) {
1195 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
1199 lambda
[i
] = (GLfloat
)
1200 (log(span
->rho
[0] * invQ
* invQ
) * 1.442695F
* 0.5F
);
1201 s
+= span
->texStep
[0][0];
1202 t
+= span
->texStep
[0][1];
1203 r
+= span
->texStep
[0][2];
1204 q
+= span
->texStep
[0][3];
1208 /* without lambda */
1209 GLfloat s
= span
->tex
[0][0];
1210 GLfloat t
= span
->tex
[0][1];
1211 GLfloat r
= span
->tex
[0][2];
1212 GLfloat q
= span
->tex
[0][3];
1214 for (i
= 0; i
< span
->count
; i
++) {
1215 const GLfloat invQ
= (q
== 0.0F
) ? 1.0F
: (1.0F
/ q
);
1219 s
+= span
->texStep
[0][0];
1220 t
+= span
->texStep
[0][1];
1221 r
+= span
->texStep
[0][2];
1222 q
+= span
->texStep
[0][3];
1227 /* XXX keep this? */
1228 if (span
->activeMask
& SPAN_INT_TEXTURE
) {
1229 GLint intTexcoord
[MAX_WIDTH
][2];
1230 GLfixed s
= span
->intTex
[0];
1231 GLfixed t
= span
->intTex
[1];
1233 for (i
= 0; i
< span
->count
; i
++) {
1234 intTexcoord
[i
][0] = FixedToInt(s
);
1235 intTexcoord
[i
][1] = FixedToInt(t
);
1236 s
+= span
->intTexStep
[0];
1237 t
+= span
->intTexStep
[1];
1241 /* examine activeMask and call a s_span.c function */
1242 if (span
->activeMask
& SPAN_TEXTURE
) {
1243 const GLfloat
*fogPtr
;
1244 if (span
->activeMask
& SPAN_FOG
)
1249 if (ctx
->Texture
._ReallyEnabled
& ~TEXTURE0_ANY
) {
1250 if (span
->activeMask
& SPAN_SPEC
) {
1251 _mesa_write_multitexture_span(ctx
, span
->count
, span
->x
, span
->y
,
1253 (const GLfloat (*)[MAX_WIDTH
]) msTex
,
1254 (const GLfloat (*)[MAX_WIDTH
]) mtTex
,
1255 (const GLfloat (*)[MAX_WIDTH
]) mrTex
,
1256 (GLfloat (*)[MAX_WIDTH
]) mLambda
,
1257 rgba
, (CONST
GLchan (*)[4]) spec
,
1261 _mesa_write_multitexture_span(ctx
, span
->count
, span
->x
, span
->y
,
1263 (const GLfloat (*)[MAX_WIDTH
]) msTex
,
1264 (const GLfloat (*)[MAX_WIDTH
]) mtTex
,
1265 (const GLfloat (*)[MAX_WIDTH
]) mrTex
,
1266 (GLfloat (*)[MAX_WIDTH
]) mLambda
,
1267 rgba
, NULL
, NULL
, GL_POLYGON
);
1271 /* single texture */
1272 if (span
->activeMask
& SPAN_SPEC
) {
1273 _mesa_write_texture_span(ctx
, span
->count
, span
->x
, span
->y
,
1274 z
, fogPtr
, sTex
, tTex
, rTex
, lambda
,
1275 rgba
, (CONST
GLchan (*)[4]) spec
,
1279 _mesa_write_texture_span(ctx
, span
->count
, span
->x
, span
->y
,
1280 z
, fogPtr
, sTex
, tTex
, rTex
, lambda
,
1281 rgba
, NULL
, NULL
, GL_POLYGON
);
1286 _mesa_problem(ctx
, "rasterize_span() should only be used for texturing");
1301 UNDEFARRAY(mLambda
);
1308 * Render a smooth-shaded, textured, RGBA triangle.
1309 * Interpolate S,T,R with perspective correction, w/out mipmapping.
1311 static void general_textured_triangle( GLcontext
*ctx
,
1314 const SWvertex
*v2
)
1317 #define INTERP_FOG 1
1318 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1319 #define INTERP_RGB 1
1320 #define INTERP_ALPHA 1
1321 #define INTERP_TEX 1
1323 #define SETUP_CODE \
1324 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1325 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1326 DEFARRAY(GLfloat, sSpan, MAX_WIDTH); /* mac 32k limitation */ \
1327 DEFARRAY(GLfloat, tSpan, MAX_WIDTH); /* mac 32k limitation */ \
1328 DEFARRAY(GLfloat, uSpan, MAX_WIDTH); /* mac 32k limitation */ \
1329 CHECKARRAY(sSpan, return); /* mac 32k limitation */ \
1330 CHECKARRAY(tSpan, return); /* mac 32k limitation */ \
1331 CHECKARRAY(uSpan, return); /* mac 32k limitation */ \
1332 span.texWidth[0] = (GLfloat) texImage->Width; \
1333 span.texHeight[0] = (GLfloat) texImage->Height; \
1334 (void) fixedToDepthShift;
1336 #define RENDER_SPAN( span ) \
1337 GLdepth zSpan[MAX_WIDTH]; \
1338 GLfloat fogSpan[MAX_WIDTH]; \
1339 GLchan rgbaSpan[MAX_WIDTH][4]; \
1341 /* NOTE: we could just call rasterize_span() here instead */ \
1342 for (i = 0; i < span.count; i++) { \
1343 GLdouble invQ = span.tex[0][3] ? (1.0 / span.tex[0][3]) : 1.0; \
1344 zSpan[i] = FixedToDepth(span.z); \
1345 span.z += span.zStep; \
1346 fogSpan[i] = span.fog; \
1347 span.fog += span.fogStep; \
1348 rgbaSpan[i][RCOMP] = FixedToChan(span.red); \
1349 rgbaSpan[i][GCOMP] = FixedToChan(span.green); \
1350 rgbaSpan[i][BCOMP] = FixedToChan(span.blue); \
1351 rgbaSpan[i][ACOMP] = FixedToChan(span.alpha); \
1352 span.red += span.redStep; \
1353 span.green += span.greenStep; \
1354 span.blue += span.blueStep; \
1355 span.alpha += span.alphaStep; \
1356 sSpan[i] = (GLfloat) (span.tex[0][0] * invQ); \
1357 tSpan[i] = (GLfloat) (span.tex[0][1] * invQ); \
1358 uSpan[i] = (GLfloat) (span.tex[0][2] * invQ); \
1359 span.tex[0][0] += span.texStep[0][0]; \
1360 span.tex[0][1] += span.texStep[0][1]; \
1361 span.tex[0][2] += span.texStep[0][2]; \
1362 span.tex[0][3] += span.texStep[0][3]; \
1364 _mesa_write_texture_span(ctx, span.count, span.x, span.y, \
1365 zSpan, fogSpan, sSpan, tSpan, uSpan, \
1366 NULL, rgbaSpan, NULL, NULL, GL_POLYGON );
1368 #define CLEANUP_CODE \
1369 UNDEFARRAY(sSpan); /* mac 32k limitation */ \
1370 UNDEFARRAY(tSpan); \
1373 #include "s_tritemp.h"
1378 * Render a smooth-shaded, textured, RGBA triangle with separate specular
1379 * color interpolation.
1380 * Interpolate texcoords with perspective correction, w/out mipmapping.
1382 static void general_textured_spec_triangle( GLcontext
*ctx
,
1385 const SWvertex
*v2
)
1388 #define INTERP_FOG 1
1389 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1390 #define INTERP_RGB 1
1391 #define INTERP_SPEC 1
1392 #define INTERP_ALPHA 1
1393 #define INTERP_TEX 1
1395 #define SETUP_CODE \
1396 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1397 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1398 span.texWidth[0] = (GLfloat) texImage->Width; \
1399 span.texHeight[0] = (GLfloat) texImage->Height; \
1400 (void) fixedToDepthShift;
1402 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1404 #include "s_tritemp.h"
1409 * Render a smooth-shaded, textured, RGBA triangle.
1410 * Interpolate S,T,R with perspective correction and compute lambda for
1411 * each fragment. Lambda is used to determine whether to use the
1412 * minification or magnification filter. If minification and using
1413 * mipmaps, lambda is also used to select the texture level of detail.
1415 static void lambda_textured_triangle( GLcontext
*ctx
,
1418 const SWvertex
*v2
)
1421 #define INTERP_FOG 1
1422 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1423 #define INTERP_RGB 1
1424 #define INTERP_ALPHA 1
1425 #define INTERP_TEX 1
1426 #define INTERP_LAMBDA 1
1428 #define SETUP_CODE \
1429 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1430 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1431 span.texWidth[0] = (GLfloat) texImage->Width; \
1432 span.texHeight[0] = (GLfloat) texImage->Height; \
1433 (void) fixedToDepthShift;
1435 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1437 #include "s_tritemp.h"
1442 * Render a smooth-shaded, textured, RGBA triangle with separate specular
1444 * Interpolate S,T,R with perspective correction and compute lambda for
1445 * each fragment. Lambda is used to determine whether to use the
1446 * minification or magnification filter. If minification and using
1447 * mipmaps, lambda is also used to select the texture level of detail.
1449 static void lambda_textured_spec_triangle( GLcontext
*ctx
,
1452 const SWvertex
*v2
)
1455 #define INTERP_FOG 1
1456 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1457 #define INTERP_RGB 1
1458 #define INTERP_SPEC 1
1459 #define INTERP_ALPHA 1
1460 #define INTERP_TEX 1
1461 #define INTERP_LAMBDA 1
1463 #define SETUP_CODE \
1464 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1465 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1466 span.texWidth[0] = (GLfloat) texImage->Width; \
1467 span.texHeight[0] = (GLfloat) texImage->Height; \
1468 (void) fixedToDepthShift;
1470 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1472 #include "s_tritemp.h"
1477 * This is the big one!
1478 * Interpolate Z, RGB, Alpha, specular, fog, and N sets of texture coordinates
1479 * with lambda (LOD).
1483 lambda_multitextured_triangle( GLcontext
*ctx
,
1486 const SWvertex
*v2
)
1490 #define INTERP_FOG 1
1491 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1492 #define INTERP_RGB 1
1493 #define INTERP_ALPHA 1
1494 #define INTERP_SPEC 1
1495 #define INTERP_MULTITEX 1
1496 #define INTERP_LAMBDA 1
1498 #define SETUP_CODE \
1500 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
1501 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
1502 const struct gl_texture_object *texObj; \
1503 const struct gl_texture_image *texImage; \
1504 texObj = ctx->Texture.Unit[u]._Current; \
1505 texImage = texObj->Image[texObj->BaseLevel]; \
1506 span.texWidth[u] = (GLfloat) texImage->Width; \
1507 span.texHeight[u] = (GLfloat) texImage->Height; \
1510 (void) fixedToDepthShift;
1512 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1514 #include "s_tritemp.h"
1519 static void occlusion_zless_triangle( GLcontext
*ctx
,
1522 const SWvertex
*v2
)
1524 if (ctx
->OcclusionResult
) {
1528 #define DO_OCCLUSION_TEST
1530 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1532 #define RENDER_SPAN( span ) \
1534 for (i = 0; i < span.count; i++) { \
1535 GLdepth z = FixedToDepth(span.z); \
1536 if (z < zRow[i]) { \
1537 ctx->OcclusionResult = GL_TRUE; \
1540 span.z += span.zStep; \
1543 #include "s_tritemp.h"
1546 static void nodraw_triangle( GLcontext
*ctx
,
1549 const SWvertex
*v2
)
1551 (void) (ctx
&& v0
&& v1
&& v2
);
1554 void _swrast_add_spec_terms_triangle( GLcontext
*ctx
,
1557 const SWvertex
*v2
)
1559 SWvertex
*ncv0
= (SWvertex
*)v0
; /* drop const qualifier */
1560 SWvertex
*ncv1
= (SWvertex
*)v1
;
1561 SWvertex
*ncv2
= (SWvertex
*)v2
;
1563 COPY_CHAN4( c
[0], ncv0
->color
);
1564 COPY_CHAN4( c
[1], ncv1
->color
);
1565 COPY_CHAN4( c
[2], ncv2
->color
);
1566 ACC_3V( ncv0
->color
, ncv0
->specular
);
1567 ACC_3V( ncv1
->color
, ncv1
->specular
);
1568 ACC_3V( ncv2
->color
, ncv2
->specular
);
1569 SWRAST_CONTEXT(ctx
)->SpecTriangle( ctx
, ncv0
, ncv1
, ncv2
);
1570 COPY_CHAN4( ncv0
->color
, c
[0] );
1571 COPY_CHAN4( ncv1
->color
, c
[1] );
1572 COPY_CHAN4( ncv2
->color
, c
[2] );
1579 /* record the current triangle function name */
1580 static const char *triFuncName
= NULL
;
1582 #define USE(triFunc) \
1584 triFuncName = #triFunc; \
1585 /*printf("%s\n", triFuncName);*/ \
1586 swrast->Triangle = triFunc; \
1591 #define USE(triFunc) swrast->Triangle = triFunc;
1599 * Determine which triangle rendering function to use given the current
1600 * rendering context.
1602 * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
1603 * remove tests to this code.
1606 _swrast_choose_triangle( GLcontext
*ctx
)
1608 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1609 const GLboolean rgbmode
= ctx
->Visual
.rgbMode
;
1611 if (ctx
->Polygon
.CullFlag
&&
1612 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
) {
1613 USE(nodraw_triangle
);
1617 if (ctx
->RenderMode
==GL_RENDER
) {
1619 if (ctx
->Polygon
.SmoothFlag
) {
1620 _mesa_set_aa_triangle_function(ctx
);
1621 ASSERT(swrast
->Triangle
);
1625 if (ctx
->Depth
.OcclusionTest
&&
1627 ctx
->Depth
.Mask
== GL_FALSE
&&
1628 ctx
->Depth
.Func
== GL_LESS
&&
1629 !ctx
->Stencil
.Enabled
) {
1631 ctx
->Color
.ColorMask
[0] == 0 &&
1632 ctx
->Color
.ColorMask
[1] == 0 &&
1633 ctx
->Color
.ColorMask
[2] == 0 &&
1634 ctx
->Color
.ColorMask
[3] == 0)
1636 (!rgbmode
&& ctx
->Color
.IndexMask
== 0)) {
1637 USE(occlusion_zless_triangle
);
1642 if (ctx
->Texture
._ReallyEnabled
) {
1643 /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1644 const struct gl_texture_object
*texObj2D
;
1645 const struct gl_texture_image
*texImg
;
1646 GLenum minFilter
, magFilter
, envMode
;
1648 texObj2D
= ctx
->Texture
.Unit
[0].Current2D
;
1649 texImg
= texObj2D
? texObj2D
->Image
[texObj2D
->BaseLevel
] : NULL
;
1650 format
= texImg
? texImg
->TexFormat
->MesaFormat
: -1;
1651 minFilter
= texObj2D
? texObj2D
->MinFilter
: (GLenum
) 0;
1652 magFilter
= texObj2D
? texObj2D
->MagFilter
: (GLenum
) 0;
1653 envMode
= ctx
->Texture
.Unit
[0].EnvMode
;
1655 /* First see if we can used an optimized 2-D texture function */
1656 if (ctx
->Texture
._ReallyEnabled
==TEXTURE0_2D
1657 && texObj2D
->WrapS
==GL_REPEAT
1658 && texObj2D
->WrapT
==GL_REPEAT
1659 && texImg
->Border
==0
1660 && (format
== MESA_FORMAT_RGB
|| format
== MESA_FORMAT_RGBA
)
1661 && minFilter
== magFilter
1662 && ctx
->Light
.Model
.ColorControl
== GL_SINGLE_COLOR
1663 && ctx
->Texture
.Unit
[0].EnvMode
!= GL_COMBINE_EXT
) {
1664 if (ctx
->Hint
.PerspectiveCorrection
==GL_FASTEST
) {
1665 if (minFilter
== GL_NEAREST
1666 && format
== MESA_FORMAT_RGB
1667 && (envMode
== GL_REPLACE
|| envMode
== GL_DECAL
)
1668 && ((swrast
->_RasterMask
== (DEPTH_BIT
| TEXTURE_BIT
)
1669 && ctx
->Depth
.Func
== GL_LESS
1670 && ctx
->Depth
.Mask
== GL_TRUE
)
1671 || swrast
->_RasterMask
== TEXTURE_BIT
)
1672 && ctx
->Polygon
.StippleFlag
== GL_FALSE
) {
1673 if (swrast
->_RasterMask
== (DEPTH_BIT
| TEXTURE_BIT
)) {
1674 USE(simple_z_textured_triangle
);
1677 USE(simple_textured_triangle
);
1681 #if CHAN_TYPE == GL_FLOAT
1682 USE(general_textured_triangle
);
1684 USE(affine_textured_triangle
);
1689 #if CHAN_TYPE == GL_FLOAT
1690 USE(general_textured_triangle
);
1692 USE(persp_textured_triangle
);
1697 /* More complicated textures (mipmap, multi-tex, sep specular) */
1698 GLboolean needLambda
;
1699 /* if mag filter != min filter we need to compute lambda */
1700 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
1701 if (obj
&& obj
->MinFilter
!= obj
->MagFilter
)
1702 needLambda
= GL_TRUE
;
1704 needLambda
= GL_FALSE
;
1705 if (ctx
->Texture
._ReallyEnabled
> TEXTURE0_ANY
) {
1706 USE(lambda_multitextured_triangle
);
1708 else if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) {
1709 /* separate specular color interpolation */
1711 USE(lambda_textured_spec_triangle
);
1714 USE(general_textured_spec_triangle
);
1719 USE(lambda_textured_triangle
);
1722 USE(general_textured_triangle
);
1728 ASSERT(!ctx
->Texture
._ReallyEnabled
);
1729 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
) {
1730 /* smooth shaded, no texturing, stippled or some raster ops */
1732 USE(smooth_rgba_triangle
);
1735 USE(smooth_ci_triangle
);
1739 /* flat shaded, no texturing, stippled or some raster ops */
1741 USE(flat_rgba_triangle
);
1744 USE(flat_ci_triangle
);
1749 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
1750 USE(_mesa_feedback_triangle
);
1753 /* GL_SELECT mode */
1754 USE(_mesa_select_triangle
);