1 /* $Id: s_triangle.c,v 1.37 2001/09/13 22:12:54 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 * 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 = tex_coord[0] * invQ; \
712 GLfloat t_tmp = 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 = tex_coord[0] * invQ; \
737 GLfloat t_tmp = 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.0 : (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
] = log(span
->rho
[u
] * invQ
* invQ
) * 1.442695F
* 0.5F
;
1152 s
+= span
->texStep
[u
][0];
1153 t
+= span
->texStep
[u
][1];
1154 r
+= span
->texStep
[u
][2];
1155 q
+= span
->texStep
[u
][3];
1161 /* without lambda */
1163 for (u
= 0; u
< MAX_TEXTURE_UNITS
; u
++) {
1164 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
1165 GLfloat s
= span
->tex
[u
][0];
1166 GLfloat t
= span
->tex
[u
][1];
1167 GLfloat r
= span
->tex
[u
][2];
1168 GLfloat q
= span
->tex
[u
][3];
1170 for (i
= 0; i
< span
->count
; i
++) {
1171 const GLfloat invQ
= (q
== 0.0F
) ? 1.0 : (1.0F
/ q
);
1172 msTex
[u
][i
] = s
* invQ
;
1173 mtTex
[u
][i
] = t
* invQ
;
1174 mrTex
[u
][i
] = r
* invQ
;
1175 s
+= span
->texStep
[u
][0];
1176 t
+= span
->texStep
[u
][1];
1177 r
+= span
->texStep
[u
][2];
1178 q
+= span
->texStep
[u
][3];
1185 /* just texture unit 0 */
1186 if (span
->activeMask
& SPAN_LAMBDA
) {
1188 GLfloat s
= span
->tex
[0][0];
1189 GLfloat t
= span
->tex
[0][1];
1190 GLfloat r
= span
->tex
[0][2];
1191 GLfloat q
= span
->tex
[0][3];
1193 for (i
= 0; i
< span
->count
; i
++) {
1194 const GLfloat invQ
= (q
== 0.0F
) ? 1.0 : (1.0F
/ q
);
1198 lambda
[i
] = log(span
->rho
[0] * invQ
* invQ
) * 1.442695F
* 0.5F
;
1199 s
+= span
->texStep
[0][0];
1200 t
+= span
->texStep
[0][1];
1201 r
+= span
->texStep
[0][2];
1202 q
+= span
->texStep
[0][3];
1206 /* without lambda */
1207 GLfloat s
= span
->tex
[0][0];
1208 GLfloat t
= span
->tex
[0][1];
1209 GLfloat r
= span
->tex
[0][2];
1210 GLfloat q
= span
->tex
[0][3];
1212 for (i
= 0; i
< span
->count
; i
++) {
1213 const GLfloat invQ
= (q
== 0.0F
) ? 1.0 : (1.0F
/ q
);
1217 s
+= span
->texStep
[0][0];
1218 t
+= span
->texStep
[0][1];
1219 r
+= span
->texStep
[0][2];
1220 q
+= span
->texStep
[0][3];
1225 /* XXX keep this? */
1226 if (span
->activeMask
& SPAN_INT_TEXTURE
) {
1227 GLint intTexcoord
[MAX_WIDTH
][2];
1228 GLfixed s
= span
->intTex
[0];
1229 GLfixed t
= span
->intTex
[1];
1231 for (i
= 0; i
< span
->count
; i
++) {
1232 intTexcoord
[i
][0] = FixedToInt(s
);
1233 intTexcoord
[i
][1] = FixedToInt(t
);
1234 s
+= span
->intTexStep
[0];
1235 t
+= span
->intTexStep
[1];
1239 /* examine activeMask and call a s_span.c function */
1240 if (span
->activeMask
& SPAN_TEXTURE
) {
1241 const GLfloat
*fogPtr
;
1242 if (span
->activeMask
& SPAN_FOG
)
1247 if (ctx
->Texture
._ReallyEnabled
& ~TEXTURE0_ANY
) {
1248 if (span
->activeMask
& SPAN_SPEC
) {
1249 _mesa_write_multitexture_span(ctx
, span
->count
, span
->x
, span
->y
,
1251 (const GLfloat (*)[MAX_WIDTH
]) msTex
,
1252 (const GLfloat (*)[MAX_WIDTH
]) mtTex
,
1253 (const GLfloat (*)[MAX_WIDTH
]) mrTex
,
1254 (GLfloat (*)[MAX_WIDTH
]) mLambda
,
1255 rgba
, (CONST
GLchan (*)[4]) spec
,
1259 _mesa_write_multitexture_span(ctx
, span
->count
, span
->x
, span
->y
,
1261 (const GLfloat (*)[MAX_WIDTH
]) msTex
,
1262 (const GLfloat (*)[MAX_WIDTH
]) mtTex
,
1263 (const GLfloat (*)[MAX_WIDTH
]) mrTex
,
1264 (GLfloat (*)[MAX_WIDTH
]) mLambda
,
1265 rgba
, NULL
, NULL
, GL_POLYGON
);
1269 /* single texture */
1270 if (span
->activeMask
& SPAN_SPEC
) {
1271 _mesa_write_texture_span(ctx
, span
->count
, span
->x
, span
->y
,
1272 z
, fogPtr
, sTex
, tTex
, rTex
, lambda
,
1273 rgba
, (CONST
GLchan (*)[4]) spec
,
1277 _mesa_write_texture_span(ctx
, span
->count
, span
->x
, span
->y
,
1278 z
, fogPtr
, sTex
, tTex
, rTex
, lambda
,
1279 rgba
, NULL
, NULL
, GL_POLYGON
);
1284 _mesa_problem(ctx
, "rasterize_span() should only be used for texturing");
1299 UNDEFARRAY(mLambda
);
1306 * Render a smooth-shaded, textured, RGBA triangle.
1307 * Interpolate S,T,R with perspective correction, w/out mipmapping.
1309 static void general_textured_triangle( GLcontext
*ctx
,
1312 const SWvertex
*v2
)
1315 #define INTERP_FOG 1
1316 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1317 #define INTERP_RGB 1
1318 #define INTERP_ALPHA 1
1319 #define INTERP_TEX 1
1321 #define SETUP_CODE \
1322 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1323 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1324 DEFARRAY(GLfloat, sSpan, MAX_WIDTH); /* mac 32k limitation */ \
1325 DEFARRAY(GLfloat, tSpan, MAX_WIDTH); /* mac 32k limitation */ \
1326 DEFARRAY(GLfloat, uSpan, MAX_WIDTH); /* mac 32k limitation */ \
1327 CHECKARRAY(sSpan, return); /* mac 32k limitation */ \
1328 CHECKARRAY(tSpan, return); /* mac 32k limitation */ \
1329 CHECKARRAY(uSpan, return); /* mac 32k limitation */ \
1330 span.texWidth[0] = (GLfloat) texImage->Width; \
1331 span.texHeight[0] = (GLfloat) texImage->Height; \
1332 (void) fixedToDepthShift;
1334 #define RENDER_SPAN( span ) \
1335 GLdepth zSpan[MAX_WIDTH]; \
1336 GLfloat fogSpan[MAX_WIDTH]; \
1337 GLchan rgbaSpan[MAX_WIDTH][4]; \
1339 /* NOTE: we could just call rasterize_span() here instead */ \
1340 for (i = 0; i < span.count; i++) { \
1341 GLdouble invQ = span.tex[0][3] ? (1.0 / span.tex[0][3]) : 1.0; \
1342 zSpan[i] = FixedToDepth(span.z); \
1343 span.z += span.zStep; \
1344 fogSpan[i] = span.fog; \
1345 span.fog += span.fogStep; \
1346 rgbaSpan[i][RCOMP] = FixedToChan(span.red); \
1347 rgbaSpan[i][GCOMP] = FixedToChan(span.green); \
1348 rgbaSpan[i][BCOMP] = FixedToChan(span.blue); \
1349 rgbaSpan[i][ACOMP] = FixedToChan(span.alpha); \
1350 span.red += span.redStep; \
1351 span.green += span.greenStep; \
1352 span.blue += span.blueStep; \
1353 span.alpha += span.alphaStep; \
1354 sSpan[i] = span.tex[0][0] * invQ; \
1355 tSpan[i] = span.tex[0][1] * invQ; \
1356 uSpan[i] = span.tex[0][2] * invQ; \
1357 span.tex[0][0] += span.texStep[0][0]; \
1358 span.tex[0][1] += span.texStep[0][1]; \
1359 span.tex[0][2] += span.texStep[0][2]; \
1360 span.tex[0][3] += span.texStep[0][3]; \
1362 _mesa_write_texture_span(ctx, span.count, span.x, span.y, \
1363 zSpan, fogSpan, sSpan, tSpan, uSpan, \
1364 NULL, rgbaSpan, NULL, NULL, GL_POLYGON );
1366 #define CLEANUP_CODE \
1367 UNDEFARRAY(sSpan); /* mac 32k limitation */ \
1368 UNDEFARRAY(tSpan); \
1371 #include "s_tritemp.h"
1376 * Render a smooth-shaded, textured, RGBA triangle with separate specular
1377 * color interpolation.
1378 * Interpolate texcoords with perspective correction, w/out mipmapping.
1380 static void general_textured_spec_triangle( GLcontext
*ctx
,
1383 const SWvertex
*v2
)
1386 #define INTERP_FOG 1
1387 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1388 #define INTERP_RGB 1
1389 #define INTERP_SPEC 1
1390 #define INTERP_ALPHA 1
1391 #define INTERP_TEX 1
1393 #define SETUP_CODE \
1394 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1395 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1396 span.texWidth[0] = (GLfloat) texImage->Width; \
1397 span.texHeight[0] = (GLfloat) texImage->Height; \
1398 (void) fixedToDepthShift;
1400 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1402 #include "s_tritemp.h"
1407 * Render a smooth-shaded, textured, RGBA triangle.
1408 * Interpolate S,T,R with perspective correction and compute lambda for
1409 * each fragment. Lambda is used to determine whether to use the
1410 * minification or magnification filter. If minification and using
1411 * mipmaps, lambda is also used to select the texture level of detail.
1413 static void lambda_textured_triangle( GLcontext
*ctx
,
1416 const SWvertex
*v2
)
1419 #define INTERP_FOG 1
1420 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1421 #define INTERP_RGB 1
1422 #define INTERP_ALPHA 1
1423 #define INTERP_TEX 1
1424 #define INTERP_LAMBDA 1
1426 #define SETUP_CODE \
1427 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1428 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1429 span.texWidth[0] = (GLfloat) texImage->Width; \
1430 span.texHeight[0] = (GLfloat) texImage->Height; \
1431 (void) fixedToDepthShift;
1433 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1435 #include "s_tritemp.h"
1440 * Render a smooth-shaded, textured, RGBA triangle with separate specular
1442 * Interpolate S,T,R with perspective correction and compute lambda for
1443 * each fragment. Lambda is used to determine whether to use the
1444 * minification or magnification filter. If minification and using
1445 * mipmaps, lambda is also used to select the texture level of detail.
1447 static void lambda_textured_spec_triangle( GLcontext
*ctx
,
1450 const SWvertex
*v2
)
1453 #define INTERP_FOG 1
1454 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1455 #define INTERP_RGB 1
1456 #define INTERP_SPEC 1
1457 #define INTERP_ALPHA 1
1458 #define INTERP_TEX 1
1459 #define INTERP_LAMBDA 1
1461 #define SETUP_CODE \
1462 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \
1463 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\
1464 span.texWidth[0] = (GLfloat) texImage->Width; \
1465 span.texHeight[0] = (GLfloat) texImage->Height; \
1466 (void) fixedToDepthShift;
1468 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1470 #include "s_tritemp.h"
1475 * This is the big one!
1476 * Interpolate Z, RGB, Alpha, specular, fog, and N sets of texture coordinates
1477 * with lambda (LOD).
1481 lambda_multitextured_triangle( GLcontext
*ctx
,
1484 const SWvertex
*v2
)
1488 #define INTERP_FOG 1
1489 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1490 #define INTERP_RGB 1
1491 #define INTERP_ALPHA 1
1492 #define INTERP_SPEC 1
1493 #define INTERP_MULTITEX 1
1494 #define INTERP_LAMBDA 1
1496 #define SETUP_CODE \
1498 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
1499 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
1500 const struct gl_texture_object *texObj; \
1501 const struct gl_texture_image *texImage; \
1502 texObj = ctx->Texture.Unit[u]._Current; \
1503 texImage = texObj->Image[texObj->BaseLevel]; \
1504 span.texWidth[u] = (GLfloat) texImage->Width; \
1505 span.texHeight[u] = (GLfloat) texImage->Height; \
1508 (void) fixedToDepthShift;
1510 #define RENDER_SPAN( span ) rasterize_span(ctx, &span);
1512 #include "s_tritemp.h"
1517 static void occlusion_zless_triangle( GLcontext
*ctx
,
1520 const SWvertex
*v2
)
1522 if (ctx
->OcclusionResult
) {
1526 #define DO_OCCLUSION_TEST
1528 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1530 #define RENDER_SPAN( span ) \
1532 for (i = 0; i < span.count; i++) { \
1533 GLdepth z = FixedToDepth(span.z); \
1534 if (z < zRow[i]) { \
1535 ctx->OcclusionResult = GL_TRUE; \
1538 span.z += span.zStep; \
1541 #include "s_tritemp.h"
1544 static void nodraw_triangle( GLcontext
*ctx
,
1547 const SWvertex
*v2
)
1549 (void) (ctx
&& v0
&& v1
&& v2
);
1552 void _swrast_add_spec_terms_triangle( GLcontext
*ctx
,
1555 const SWvertex
*v2
)
1557 SWvertex
*ncv0
= (SWvertex
*)v0
; /* drop const qualifier */
1558 SWvertex
*ncv1
= (SWvertex
*)v1
;
1559 SWvertex
*ncv2
= (SWvertex
*)v2
;
1561 COPY_CHAN4( c
[0], ncv0
->color
);
1562 COPY_CHAN4( c
[1], ncv1
->color
);
1563 COPY_CHAN4( c
[2], ncv2
->color
);
1564 ACC_3V( ncv0
->color
, ncv0
->specular
);
1565 ACC_3V( ncv1
->color
, ncv1
->specular
);
1566 ACC_3V( ncv2
->color
, ncv2
->specular
);
1567 SWRAST_CONTEXT(ctx
)->SpecTriangle( ctx
, ncv0
, ncv1
, ncv2
);
1568 COPY_CHAN4( ncv0
->color
, c
[0] );
1569 COPY_CHAN4( ncv1
->color
, c
[1] );
1570 COPY_CHAN4( ncv2
->color
, c
[2] );
1577 /* record the current triangle function name */
1578 static const char *triFuncName
= NULL
;
1580 #define USE(triFunc) \
1582 triFuncName = #triFunc; \
1583 /*printf("%s\n", triFuncName);*/ \
1584 swrast->Triangle = triFunc; \
1589 #define USE(triFunc) swrast->Triangle = triFunc;
1597 * Determine which triangle rendering function to use given the current
1598 * rendering context.
1600 * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
1601 * remove tests to this code.
1604 _swrast_choose_triangle( GLcontext
*ctx
)
1606 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
1607 const GLboolean rgbmode
= ctx
->Visual
.rgbMode
;
1609 if (ctx
->Polygon
.CullFlag
&&
1610 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
) {
1611 USE(nodraw_triangle
);
1615 if (ctx
->RenderMode
==GL_RENDER
) {
1617 if (ctx
->Polygon
.SmoothFlag
) {
1618 _mesa_set_aa_triangle_function(ctx
);
1619 ASSERT(swrast
->Triangle
);
1623 if (ctx
->Depth
.OcclusionTest
&&
1625 ctx
->Depth
.Mask
== GL_FALSE
&&
1626 ctx
->Depth
.Func
== GL_LESS
&&
1627 !ctx
->Stencil
.Enabled
) {
1629 ctx
->Color
.ColorMask
[0] == 0 &&
1630 ctx
->Color
.ColorMask
[1] == 0 &&
1631 ctx
->Color
.ColorMask
[2] == 0 &&
1632 ctx
->Color
.ColorMask
[3] == 0)
1634 (!rgbmode
&& ctx
->Color
.IndexMask
== 0)) {
1635 USE(occlusion_zless_triangle
);
1640 if (ctx
->Texture
._ReallyEnabled
) {
1641 /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1642 const struct gl_texture_object
*texObj2D
;
1643 const struct gl_texture_image
*texImg
;
1644 GLenum minFilter
, magFilter
, envMode
;
1646 texObj2D
= ctx
->Texture
.Unit
[0].Current2D
;
1647 texImg
= texObj2D
? texObj2D
->Image
[texObj2D
->BaseLevel
] : NULL
;
1648 format
= texImg
? texImg
->TexFormat
->MesaFormat
: -1;
1649 minFilter
= texObj2D
? texObj2D
->MinFilter
: (GLenum
) 0;
1650 magFilter
= texObj2D
? texObj2D
->MagFilter
: (GLenum
) 0;
1651 envMode
= ctx
->Texture
.Unit
[0].EnvMode
;
1653 /* First see if we can used an optimized 2-D texture function */
1654 if (ctx
->Texture
._ReallyEnabled
==TEXTURE0_2D
1655 && texObj2D
->WrapS
==GL_REPEAT
1656 && texObj2D
->WrapT
==GL_REPEAT
1657 && texImg
->Border
==0
1658 && (format
== MESA_FORMAT_RGB
|| format
== MESA_FORMAT_RGBA
)
1659 && minFilter
== magFilter
1660 && ctx
->Light
.Model
.ColorControl
== GL_SINGLE_COLOR
1661 && ctx
->Texture
.Unit
[0].EnvMode
!= GL_COMBINE_EXT
) {
1662 if (ctx
->Hint
.PerspectiveCorrection
==GL_FASTEST
) {
1663 if (minFilter
== GL_NEAREST
1664 && format
== MESA_FORMAT_RGB
1665 && (envMode
== GL_REPLACE
|| envMode
== GL_DECAL
)
1666 && ((swrast
->_RasterMask
== (DEPTH_BIT
| TEXTURE_BIT
)
1667 && ctx
->Depth
.Func
== GL_LESS
1668 && ctx
->Depth
.Mask
== GL_TRUE
)
1669 || swrast
->_RasterMask
== TEXTURE_BIT
)
1670 && ctx
->Polygon
.StippleFlag
== GL_FALSE
) {
1671 if (swrast
->_RasterMask
== (DEPTH_BIT
| TEXTURE_BIT
)) {
1672 USE(simple_z_textured_triangle
);
1675 USE(simple_textured_triangle
);
1679 #if CHAN_TYPE == GL_FLOAT
1680 USE(general_textured_triangle
);
1682 USE(affine_textured_triangle
);
1687 #if CHAN_TYPE == GL_FLOAT
1688 USE(general_textured_triangle
);
1690 USE(persp_textured_triangle
);
1695 /* More complicated textures (mipmap, multi-tex, sep specular) */
1696 GLboolean needLambda
;
1697 /* if mag filter != min filter we need to compute lambda */
1698 const struct gl_texture_object
*obj
= ctx
->Texture
.Unit
[0]._Current
;
1699 if (obj
&& obj
->MinFilter
!= obj
->MagFilter
)
1700 needLambda
= GL_TRUE
;
1702 needLambda
= GL_FALSE
;
1703 if (ctx
->Texture
._ReallyEnabled
> TEXTURE0_ANY
) {
1704 USE(lambda_multitextured_triangle
);
1706 else if (ctx
->_TriangleCaps
& DD_SEPARATE_SPECULAR
) {
1707 /* separate specular color interpolation */
1709 USE(lambda_textured_spec_triangle
);
1712 USE(general_textured_spec_triangle
);
1717 USE(lambda_textured_triangle
);
1720 USE(general_textured_triangle
);
1726 ASSERT(!ctx
->Texture
._ReallyEnabled
);
1727 if (ctx
->Light
.ShadeModel
==GL_SMOOTH
) {
1728 /* smooth shaded, no texturing, stippled or some raster ops */
1730 USE(smooth_rgba_triangle
);
1733 USE(smooth_ci_triangle
);
1737 /* flat shaded, no texturing, stippled or some raster ops */
1739 USE(flat_rgba_triangle
);
1742 USE(flat_ci_triangle
);
1747 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
1748 USE(_mesa_feedback_triangle
);
1751 /* GL_SELECT mode */
1752 USE(_mesa_select_triangle
);