s_triangle.c revision 6e1666437ea091ecc50ab2b56d87129318f641d2
1/* $Id: s_triangle.c,v 1.52 2002/01/28 04:25:56 brianp Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version:  4.1
6 *
7 * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28/*
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.
32 */
33
34#include "glheader.h"
35#include "context.h"
36#include "colormac.h"
37#include "macros.h"
38#include "mem.h"
39#include "mmath.h"
40#include "texformat.h"
41#include "teximage.h"
42#include "texstate.h"
43
44#include "s_aatriangle.h"
45#include "s_context.h"
46#include "s_depth.h"
47#include "s_feedback.h"
48#include "s_span.h"
49#include "s_triangle.h"
50
51
52
53GLboolean _mesa_cull_triangle( GLcontext *ctx,
54			    const SWvertex *v0,
55			    const SWvertex *v1,
56			    const SWvertex *v2 )
57{
58   GLfloat ex = v1->win[0] - v0->win[0];
59   GLfloat ey = v1->win[1] - v0->win[1];
60   GLfloat fx = v2->win[0] - v0->win[0];
61   GLfloat fy = v2->win[1] - v0->win[1];
62   GLfloat c = ex*fy-ey*fx;
63
64   if (c * SWRAST_CONTEXT(ctx)->_backface_sign > 0)
65      return 0;
66
67   return 1;
68}
69
70
71
72/*
73 * Render a flat-shaded color index triangle.
74 */
75static void flat_ci_triangle( GLcontext *ctx,
76			      const SWvertex *v0,
77			      const SWvertex *v1,
78			      const SWvertex *v2 )
79{
80#define INTERP_Z 1
81#define INTERP_FOG 1
82
83#define SETUP_CODE					\
84   span.interpMask |= SPAN_INDEX;			\
85   span.index = IntToFixed(v2->index);			\
86   span.indexStep = 0;
87
88#define RENDER_SPAN( span )  _mesa_write_index_span(ctx, &span, GL_POLYGON )
89
90#include "s_tritemp.h"
91}
92
93
94
95/*
96 * Render a smooth-shaded color index triangle.
97 */
98static void smooth_ci_triangle( GLcontext *ctx,
99				const SWvertex *v0,
100				const SWvertex *v1,
101				const SWvertex *v2 )
102{
103#define INTERP_Z 1
104#define INTERP_FOG 1
105#define INTERP_INDEX 1
106
107#define RENDER_SPAN( span )  _mesa_write_index_span(ctx, &span, GL_POLYGON)
108
109#include "s_tritemp.h"
110}
111
112
113
114/*
115 * Render a flat-shaded RGBA triangle.
116 */
117static void flat_rgba_triangle( GLcontext *ctx,
118				const SWvertex *v0,
119				const SWvertex *v1,
120				const SWvertex *v2 )
121{
122#define INTERP_Z 1
123#define INTERP_FOG 1
124#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
125
126#define SETUP_CODE				\
127   ASSERT(!ctx->Texture._ReallyEnabled);	\
128   ASSERT(ctx->Light.ShadeModel==GL_FLAT);	\
129   span.interpMask |= SPAN_RGBA;		\
130   span.red = ChanToFixed(v2->color[0]);	\
131   span.green = ChanToFixed(v2->color[1]);	\
132   span.blue = ChanToFixed(v2->color[2]);	\
133   span.alpha = ChanToFixed(v2->color[3]);	\
134   span.redStep = 0;				\
135   span.greenStep = 0;				\
136   span.blueStep = 0;				\
137   span.alphaStep = 0;
138
139#define RENDER_SPAN( span )  _mesa_write_rgba_span(ctx, &span, GL_POLYGON )
140
141#include "s_tritemp.h"
142}
143
144
145
146/*
147 * Render a smooth-shaded RGBA triangle.
148 */
149static void smooth_rgba_triangle( GLcontext *ctx,
150				  const SWvertex *v0,
151				  const SWvertex *v1,
152				  const SWvertex *v2 )
153{
154
155#define INTERP_Z 1
156#define INTERP_FOG 1
157#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
158#define INTERP_RGB 1
159#define INTERP_ALPHA 1
160
161#define RENDER_SPAN( span )				\
162   ASSERT(span.interpMask & SPAN_RGBA);			\
163   _mesa_write_rgba_span(ctx, &span, GL_POLYGON);
164
165#include "s_tritemp.h"
166
167   ASSERT(!ctx->Texture._ReallyEnabled);  /* texturing must be off */
168   ASSERT(ctx->Light.ShadeModel==GL_SMOOTH);
169}
170
171
172/*
173 * Render an RGB, GL_DECAL, textured triangle.
174 * Interpolate S,T only w/out mipmapping or perspective correction.
175 *
176 * No fog.
177 */
178static void simple_textured_triangle( GLcontext *ctx,
179				      const SWvertex *v0,
180				      const SWvertex *v1,
181				      const SWvertex *v2 )
182{
183#define INTERP_INT_TEX 1
184#define S_SCALE twidth
185#define T_SCALE theight
186
187#define SETUP_CODE							\
188   SWcontext *swrast = SWRAST_CONTEXT(ctx);                             \
189   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;	\
190   const GLint b = obj->BaseLevel;					\
191   const GLfloat twidth = (GLfloat) obj->Image[b]->Width;		\
192   const GLfloat theight = (GLfloat) obj->Image[b]->Height;		\
193   const GLint twidth_log2 = obj->Image[b]->WidthLog2;			\
194   const GLchan *texture = (const GLchan *) obj->Image[b]->Data;	\
195   const GLint smask = obj->Image[b]->Width - 1;			\
196   const GLint tmask = obj->Image[b]->Height - 1;			\
197   if (!texture) {							\
198      /* this shouldn't happen */					\
199      return;								\
200   }
201
202#define RENDER_SPAN( span  )						\
203   GLuint i;								\
204   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
205   span.intTex[1] -= FIXED_HALF;					\
206   for (i = 0; i < span.end; i++) {					\
207      GLint s = FixedToInt(span.intTex[0]) & smask;			\
208      GLint t = FixedToInt(span.intTex[1]) & tmask;			\
209      GLint pos = (t << twidth_log2) + s;				\
210      pos = pos + pos + pos;  /* multiply by 3 */			\
211      span.color.rgb[i][RCOMP] = texture[pos];				\
212      span.color.rgb[i][GCOMP] = texture[pos+1];			\
213      span.color.rgb[i][BCOMP] = texture[pos+2];			\
214      span.intTex[0] += span.intTexStep[0];				\
215      span.intTex[1] += span.intTexStep[1];				\
216   }									\
217   (*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y,	\
218                                  (CONST GLchan (*)[3]) span.color.rgb,	\
219                                  NULL );
220
221#include "s_tritemp.h"
222}
223
224
225/*
226 * Render an RGB, GL_DECAL, textured triangle.
227 * Interpolate S,T, GL_LESS depth test, w/out mipmapping or
228 * perspective correction.
229 *
230 * No fog.
231 */
232static void simple_z_textured_triangle( GLcontext *ctx,
233					const SWvertex *v0,
234					const SWvertex *v1,
235					const SWvertex *v2 )
236{
237#define INTERP_Z 1
238#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
239#define INTERP_INT_TEX 1
240#define S_SCALE twidth
241#define T_SCALE theight
242
243#define SETUP_CODE							\
244   SWcontext *swrast = SWRAST_CONTEXT(ctx);                             \
245   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;	\
246   const GLint b = obj->BaseLevel;					\
247   const GLfloat twidth = (GLfloat) obj->Image[b]->Width;		\
248   const GLfloat theight = (GLfloat) obj->Image[b]->Height;		\
249   const GLint twidth_log2 = obj->Image[b]->WidthLog2;			\
250   const GLchan *texture = (const GLchan *) obj->Image[b]->Data;	\
251   const GLint smask = obj->Image[b]->Width - 1;			\
252   const GLint tmask = obj->Image[b]->Height - 1;			\
253   if (!texture) {							\
254      /* this shouldn't happen */					\
255      return;								\
256   }
257
258#define RENDER_SPAN( span )						\
259   GLuint i;				    				\
260   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
261   span.intTex[1] -= FIXED_HALF;					\
262   for (i = 0; i < span.end; i++) {					\
263      const GLdepth z = FixedToDepth(span.z);				\
264      if (z < zRow[i]) {						\
265         GLint s = FixedToInt(span.intTex[0]) & smask;			\
266         GLint t = FixedToInt(span.intTex[1]) & tmask;			\
267         GLint pos = (t << twidth_log2) + s;				\
268         pos = pos + pos + pos;  /* multiply by 3 */			\
269         span.color.rgb[i][RCOMP] = texture[pos];			\
270         span.color.rgb[i][GCOMP] = texture[pos+1];			\
271         span.color.rgb[i][BCOMP] = texture[pos+2];			\
272         zRow[i] = z;							\
273         span.mask[i] = 1;						\
274      }									\
275      else {								\
276         span.mask[i] = 0;						\
277      }									\
278      span.intTex[0] += span.intTexStep[0];				\
279      span.intTex[1] += span.intTexStep[1];				\
280      span.z += span.zStep;						\
281   }									\
282   (*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y,	\
283                                  (CONST GLchan (*)[3]) span.color.rgb,	\
284                                  span.mask );
285
286#include "s_tritemp.h"
287}
288
289
290#if CHAN_TYPE != GL_FLOAT
291
292struct affine_info
293{
294   GLenum filter;
295   GLenum format;
296   GLenum envmode;
297   GLint smask, tmask;
298   GLint twidth_log2;
299   const GLchan *texture;
300   GLfixed er, eg, eb, ea;
301   GLint tbytesline, tsize;
302};
303
304
305/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA
306 * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD
307 * texture env modes.
308 */
309static INLINE void
310affine_span(GLcontext *ctx, struct sw_span *span,
311            struct affine_info *info)
312{
313   GLchan sample[4];  /* the filtered texture sample */
314
315   /* Instead of defining a function for each mode, a test is done
316    * between the outer and inner loops. This is to reduce code size
317    * and complexity. Observe that an optimizing compiler kills
318    * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
319    */
320
321#define NEAREST_RGB			\
322   sample[RCOMP] = tex00[RCOMP];	\
323   sample[GCOMP] = tex00[GCOMP];	\
324   sample[BCOMP] = tex00[BCOMP];	\
325   sample[ACOMP] = CHAN_MAX
326
327#define LINEAR_RGB							\
328   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
329             tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;	\
330   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
331             tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;	\
332   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
333             tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;	\
334   sample[ACOMP] = CHAN_MAX
335
336#define NEAREST_RGBA  COPY_CHAN4(sample, tex00)
337
338#define LINEAR_RGBA							\
339   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
340               tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;\
341   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
342               tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;\
343   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
344               tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;\
345   sample[ACOMP] = (ti * (si * tex00[3] + sf * tex01[3]) +		\
346               tf * (si * tex10[3] + sf * tex11[3])) >> 2 * FIXED_SHIFT
347
348#define MODULATE							  \
349   dest[RCOMP] = span->red   * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
350   dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \
351   dest[BCOMP] = span->blue  * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \
352   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8)
353
354#define DECAL								\
355   dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red +		\
356               ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT))	\
357               >> (FIXED_SHIFT + 8);					\
358   dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green +		\
359               ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT))	\
360               >> (FIXED_SHIFT + 8);					\
361   dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue +		\
362               ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT))	\
363               >> (FIXED_SHIFT + 8);					\
364   dest[ACOMP] = FixedToInt(span->alpha)
365
366#define BLEND								\
367   dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red		\
368               + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8);	\
369   dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green		\
370               + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8);	\
371   dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue		\
372               + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8);	\
373   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8)
374
375#define REPLACE  COPY_CHAN4(dest, sample)
376
377#define ADD								\
378   {									\
379      GLint rSum = FixedToInt(span->red)   + (GLint) sample[RCOMP];	\
380      GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP];	\
381      GLint bSum = FixedToInt(span->blue)  + (GLint) sample[BCOMP];	\
382      dest[RCOMP] = MIN2(rSum, CHAN_MAX);				\
383      dest[GCOMP] = MIN2(gSum, CHAN_MAX);				\
384      dest[BCOMP] = MIN2(bSum, CHAN_MAX);				\
385      dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \
386  }
387
388/* shortcuts */
389
390#define NEAREST_RGB_REPLACE		\
391   NEAREST_RGB;				\
392   dest[0] = sample[0];			\
393   dest[1] = sample[1];			\
394   dest[2] = sample[2];			\
395   dest[3] = FixedToInt(span->alpha);
396
397#define NEAREST_RGBA_REPLACE  COPY_CHAN4(dest, tex00)
398
399#define SPAN_NEAREST(DO_TEX,COMP)					\
400	for (i = 0; i < span->end; i++) {				\
401           /* Isn't it necessary to use FixedFloor below?? */		\
402           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
403           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
404           GLint pos = (t << info->twidth_log2) + s;			\
405           const GLchan *tex00 = info->texture + COMP * pos;		\
406           DO_TEX;							\
407           span->red += span->redStep;					\
408	   span->green += span->greenStep;				\
409           span->blue += span->blueStep;				\
410	   span->alpha += span->alphaStep;				\
411	   span->intTex[0] += span->intTexStep[0];			\
412	   span->intTex[1] += span->intTexStep[1];			\
413           dest += 4;							\
414	}
415
416#define SPAN_LINEAR(DO_TEX,COMP)					\
417	for (i = 0; i < span->end; i++) {				\
418           /* Isn't it necessary to use FixedFloor below?? */		\
419           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
420           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
421           GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK;		\
422           GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK;		\
423           GLfixed si = FIXED_FRAC_MASK - sf;				\
424           GLfixed ti = FIXED_FRAC_MASK - tf;				\
425           GLint pos = (t << info->twidth_log2) + s;			\
426           const GLchan *tex00 = info->texture + COMP * pos;		\
427           const GLchan *tex10 = tex00 + info->tbytesline;		\
428           const GLchan *tex01 = tex00 + COMP;				\
429           const GLchan *tex11 = tex10 + COMP;				\
430           (void) ti;							\
431           (void) si;							\
432           if (t == info->tmask) {					\
433              tex10 -= info->tsize;					\
434              tex11 -= info->tsize;					\
435           }								\
436           if (s == info->smask) {					\
437              tex01 -= info->tbytesline;				\
438              tex11 -= info->tbytesline;				\
439           }								\
440           DO_TEX;							\
441           span->red += span->redStep;					\
442	   span->green += span->greenStep;				\
443           span->blue += span->blueStep;				\
444	   span->alpha += span->alphaStep;				\
445	   span->intTex[0] += span->intTexStep[0];			\
446	   span->intTex[1] += span->intTexStep[1];			\
447           dest += 4;							\
448	}
449
450
451   GLuint i;
452   GLchan *dest = span->color.rgba[0];
453
454   span->intTex[0] -= FIXED_HALF;
455   span->intTex[1] -= FIXED_HALF;
456   switch (info->filter) {
457   case GL_NEAREST:
458      switch (info->format) {
459      case GL_RGB:
460         switch (info->envmode) {
461         case GL_MODULATE:
462            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
463            break;
464         case GL_DECAL:
465         case GL_REPLACE:
466            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
467            break;
468         case GL_BLEND:
469            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
470            break;
471         case GL_ADD:
472            SPAN_NEAREST(NEAREST_RGB;ADD,3);
473            break;
474         default:
475            abort();
476         }
477         break;
478      case GL_RGBA:
479         switch(info->envmode) {
480         case GL_MODULATE:
481            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
482            break;
483         case GL_DECAL:
484            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
485            break;
486         case GL_BLEND:
487            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
488            break;
489         case GL_ADD:
490            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
491            break;
492         case GL_REPLACE:
493            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
494            break;
495         default:
496            abort();
497         }
498         break;
499      }
500      break;
501
502   case GL_LINEAR:
503      span->intTex[0] -= FIXED_HALF;
504      span->intTex[1] -= FIXED_HALF;
505      switch (info->format) {
506      case GL_RGB:
507         switch (info->envmode) {
508         case GL_MODULATE:
509            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
510            break;
511         case GL_DECAL:
512         case GL_REPLACE:
513            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
514            break;
515         case GL_BLEND:
516            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
517            break;
518         case GL_ADD:
519            SPAN_LINEAR(LINEAR_RGB;ADD,3);
520            break;
521         default:
522            abort();
523         }
524         break;
525      case GL_RGBA:
526         switch (info->envmode) {
527         case GL_MODULATE:
528            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
529            break;
530         case GL_DECAL:
531            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
532            break;
533         case GL_BLEND:
534            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
535            break;
536         case GL_ADD:
537            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
538            break;
539         case GL_REPLACE:
540            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
541            break;
542         default:
543            abort();
544         }		    break;
545      }
546      break;
547   }
548   ASSERT(span->interpMask & SPAN_RGBA);
549   ASSERT(span->arrayMask & SPAN_RGBA);
550   _mesa_write_rgba_span(ctx, span, GL_POLYGON);
551
552#undef SPAN_NEAREST
553#undef SPAN_LINEAR
554}
555
556
557
558/*
559 * Render an RGB/RGBA textured triangle without perspective correction.
560 */
561static void affine_textured_triangle( GLcontext *ctx,
562				      const SWvertex *v0,
563				      const SWvertex *v1,
564				      const SWvertex *v2 )
565{
566#define INTERP_Z 1
567#define INTERP_FOG 1
568#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
569#define INTERP_RGB 1
570#define INTERP_ALPHA 1
571#define INTERP_INT_TEX 1
572#define S_SCALE twidth
573#define T_SCALE theight
574
575#define SETUP_CODE							\
576   struct affine_info info;						\
577   struct gl_texture_unit *unit = ctx->Texture.Unit+0;			\
578   struct gl_texture_object *obj = unit->Current2D;			\
579   const GLint b = obj->BaseLevel;					\
580   const GLfloat twidth = (GLfloat) obj->Image[b]->Width;		\
581   const GLfloat theight = (GLfloat) obj->Image[b]->Height;		\
582   info.texture = (const GLchan *) obj->Image[b]->Data;			\
583   info.twidth_log2 = obj->Image[b]->WidthLog2;				\
584   info.smask = obj->Image[b]->Width - 1;				\
585   info.tmask = obj->Image[b]->Height - 1;				\
586   info.format = obj->Image[b]->Format;					\
587   info.filter = obj->MinFilter;					\
588   info.envmode = unit->EnvMode;					\
589   span.arrayMask |= SPAN_RGBA;						\
590									\
591   if (info.envmode == GL_BLEND) {					\
592      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
593      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
594      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
595      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
596      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
597   }									\
598   if (!info.texture) {							\
599      /* this shouldn't happen */					\
600      return;								\
601   }									\
602									\
603   switch (info.format) {						\
604   case GL_ALPHA:							\
605   case GL_LUMINANCE:							\
606   case GL_INTENSITY:							\
607      info.tbytesline = obj->Image[b]->Width;				\
608      break;								\
609   case GL_LUMINANCE_ALPHA:						\
610      info.tbytesline = obj->Image[b]->Width * 2;			\
611      break;								\
612   case GL_RGB:								\
613      info.tbytesline = obj->Image[b]->Width * 3;			\
614      break;								\
615   case GL_RGBA:							\
616      info.tbytesline = obj->Image[b]->Width * 4;			\
617      break;								\
618   default:								\
619      _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
620      return;								\
621   }									\
622   info.tsize = obj->Image[b]->Height * info.tbytesline;
623
624#define RENDER_SPAN( span )   affine_span(ctx, &span, &info);
625
626#include "s_tritemp.h"
627
628}
629
630
631
632struct persp_info
633{
634   GLenum filter;
635   GLenum format;
636   GLenum envmode;
637   GLint smask, tmask;
638   GLint twidth_log2;
639   const GLchan *texture;
640   GLfixed er, eg, eb, ea;   /* texture env color */
641   GLint tbytesline, tsize;
642};
643
644
645static INLINE void
646fast_persp_span(GLcontext *ctx, struct sw_span *span,
647		struct persp_info *info)
648{
649   GLchan sample[4];  /* the filtered texture sample */
650
651  /* Instead of defining a function for each mode, a test is done
652   * between the outer and inner loops. This is to reduce code size
653   * and complexity. Observe that an optimizing compiler kills
654   * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
655   */
656#define SPAN_NEAREST(DO_TEX,COMP)					\
657	for (i = 0; i < span->end; i++) {				\
658           GLdouble invQ = tex_coord[2] ?				\
659                                 (1.0 / tex_coord[2]) : 1.0;            \
660           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
661           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
662           GLint s = IFLOOR(s_tmp) & info->smask;	        	\
663           GLint t = IFLOOR(t_tmp) & info->tmask;	        	\
664           GLint pos = (t << info->twidth_log2) + s;			\
665           const GLchan *tex00 = info->texture + COMP * pos;		\
666           DO_TEX;							\
667           span->red += span->redStep;					\
668	   span->green += span->greenStep;				\
669           span->blue += span->blueStep;				\
670	   span->alpha += span->alphaStep;				\
671	   tex_coord[0] += tex_step[0];					\
672	   tex_coord[1] += tex_step[1];					\
673	   tex_coord[2] += tex_step[2];					\
674           dest += 4;							\
675	}
676
677#define SPAN_LINEAR(DO_TEX,COMP)					\
678	for (i = 0; i < span->end; i++) {				\
679           GLdouble invQ = tex_coord[2] ?				\
680                                 (1.0 / tex_coord[2]) : 1.0;            \
681           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
682           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
683           GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF;		\
684           GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF;        	\
685           GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask;	\
686           GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask;	\
687           GLfixed sf = s_fix & FIXED_FRAC_MASK;			\
688           GLfixed tf = t_fix & FIXED_FRAC_MASK;			\
689           GLfixed si = FIXED_FRAC_MASK - sf;				\
690           GLfixed ti = FIXED_FRAC_MASK - tf;				\
691           GLint pos = (t << info->twidth_log2) + s;			\
692           const GLchan *tex00 = info->texture + COMP * pos;		\
693           const GLchan *tex10 = tex00 + info->tbytesline;		\
694           const GLchan *tex01 = tex00 + COMP;				\
695           const GLchan *tex11 = tex10 + COMP;				\
696           (void) ti;							\
697           (void) si;							\
698           if (t == info->tmask) {					\
699              tex10 -= info->tsize;					\
700              tex11 -= info->tsize;					\
701           }								\
702           if (s == info->smask) {					\
703              tex01 -= info->tbytesline;				\
704              tex11 -= info->tbytesline;				\
705           }								\
706           DO_TEX;							\
707           span->red   += span->redStep;				\
708	   span->green += span->greenStep;				\
709           span->blue  += span->blueStep;				\
710	   span->alpha += span->alphaStep;				\
711	   tex_coord[0] += tex_step[0];					\
712	   tex_coord[1] += tex_step[1];					\
713	   tex_coord[2] += tex_step[2];					\
714           dest += 4;							\
715	}
716
717   GLuint i;
718   GLfloat tex_coord[3], tex_step[3];
719   GLchan *dest = span->color.rgba[0];
720
721   tex_coord[0] = span->tex[0][0]  * (info->smask + 1),
722     tex_step[0] = span->texStep[0][0] * (info->smask + 1);
723   tex_coord[1] = span->tex[0][1] * (info->tmask + 1),
724     tex_step[1] = span->texStep[0][1] * (info->tmask + 1);
725   /* span->tex[0][2] only if 3D-texturing, here only 2D */
726   tex_coord[2] = span->tex[0][3],
727     tex_step[2] = span->texStep[0][3];
728
729   switch (info->filter) {
730   case GL_NEAREST:
731      switch (info->format) {
732      case GL_RGB:
733         switch (info->envmode) {
734         case GL_MODULATE:
735            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
736            break;
737         case GL_DECAL:
738         case GL_REPLACE:
739            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
740            break;
741         case GL_BLEND:
742            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
743            break;
744         case GL_ADD:
745            SPAN_NEAREST(NEAREST_RGB;ADD,3);
746            break;
747         default:
748            abort();
749         }
750         break;
751      case GL_RGBA:
752         switch(info->envmode) {
753         case GL_MODULATE:
754            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
755            break;
756         case GL_DECAL:
757            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
758            break;
759         case GL_BLEND:
760            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
761            break;
762         case GL_ADD:
763            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
764            break;
765         case GL_REPLACE:
766            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
767            break;
768         default:
769            abort();
770         }
771         break;
772      }
773      break;
774
775   case GL_LINEAR:
776      switch (info->format) {
777      case GL_RGB:
778         switch (info->envmode) {
779         case GL_MODULATE:
780            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
781            break;
782         case GL_DECAL:
783         case GL_REPLACE:
784            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
785            break;
786         case GL_BLEND:
787            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
788            break;
789         case GL_ADD:
790            SPAN_LINEAR(LINEAR_RGB;ADD,3);
791            break;
792         default:
793            abort();
794         }
795         break;
796      case GL_RGBA:
797         switch (info->envmode) {
798         case GL_MODULATE:
799            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
800            break;
801         case GL_DECAL:
802            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
803            break;
804         case GL_BLEND:
805            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
806            break;
807         case GL_ADD:
808            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
809            break;
810         case GL_REPLACE:
811            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
812            break;
813         default:
814            abort();
815         }
816         break;
817      }
818      break;
819   }
820
821   ASSERT(span->arrayMask & SPAN_RGBA);
822   _mesa_write_rgba_span(ctx, span, GL_POLYGON);
823
824
825#undef SPAN_NEAREST
826#undef SPAN_LINEAR
827}
828
829
830/*
831 * Render an perspective corrected RGB/RGBA textured triangle.
832 * The Q (aka V in Mesa) coordinate must be zero such that the divide
833 * by interpolated Q/W comes out right.
834 *
835 */
836static void persp_textured_triangle( GLcontext *ctx,
837				     const SWvertex *v0,
838				     const SWvertex *v1,
839				     const SWvertex *v2 )
840{
841#define INTERP_Z 1
842#define INTERP_FOG 1
843#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
844#define INTERP_RGB 1
845#define INTERP_ALPHA 1
846#define INTERP_TEX 1
847
848#define SETUP_CODE							\
849   struct persp_info info;						\
850   const struct gl_texture_unit *unit = ctx->Texture.Unit+0;		\
851   const struct gl_texture_object *obj = unit->Current2D;		\
852   const GLint b = obj->BaseLevel;					\
853   info.texture = (const GLchan *) obj->Image[b]->Data;			\
854   info.twidth_log2 = obj->Image[b]->WidthLog2;				\
855   info.smask = obj->Image[b]->Width - 1;				\
856   info.tmask = obj->Image[b]->Height - 1;				\
857   info.format = obj->Image[b]->Format;					\
858   info.filter = obj->MinFilter;					\
859   info.envmode = unit->EnvMode;					\
860									\
861   if (info.envmode == GL_BLEND) {					\
862      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
863      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
864      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
865      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
866      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
867   }									\
868   if (!info.texture) {							\
869      /* this shouldn't happen */					\
870      return;								\
871   }									\
872									\
873   switch (info.format) {						\
874   case GL_ALPHA:							\
875   case GL_LUMINANCE:							\
876   case GL_INTENSITY:							\
877      info.tbytesline = obj->Image[b]->Width;				\
878      break;								\
879   case GL_LUMINANCE_ALPHA:						\
880      info.tbytesline = obj->Image[b]->Width * 2;			\
881      break;								\
882   case GL_RGB:								\
883      info.tbytesline = obj->Image[b]->Width * 3;			\
884      break;								\
885   case GL_RGBA:							\
886      info.tbytesline = obj->Image[b]->Width * 4;			\
887      break;								\
888   default:								\
889      _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
890      return;								\
891   }									\
892   info.tsize = obj->Image[b]->Height * info.tbytesline;
893
894#define RENDER_SPAN( span )			\
895   span.interpMask &= ~SPAN_RGBA;		\
896   span.arrayMask |= SPAN_RGBA;			\
897   fast_persp_span(ctx, &span, &info);
898
899#include "s_tritemp.h"
900
901}
902
903
904#endif /* CHAN_BITS != GL_FLOAT */
905
906
907
908
909/*
910 * Render a smooth-shaded, textured, RGBA triangle.
911 * Interpolate S,T,R with perspective correction, w/out mipmapping.
912 */
913static void general_textured_triangle( GLcontext *ctx,
914				       const SWvertex *v0,
915				       const SWvertex *v1,
916				       const SWvertex *v2 )
917{
918#define INTERP_Z 1
919#define INTERP_FOG 1
920#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
921#define INTERP_RGB 1
922#define INTERP_SPEC 1
923#define INTERP_ALPHA 1
924#define INTERP_TEX 1
925
926#define RENDER_SPAN( span )   _mesa_write_texture_span(ctx, &span, GL_POLYGON);
927
928#include "s_tritemp.h"
929}
930
931
932
933/*
934 * Render a smooth-shaded, textured, RGBA triangle.
935 * Interpolate S,T,R with perspective correction and compute lambda for
936 * each fragment.  Lambda is used to determine whether to use the
937 * minification or magnification filter.  If minification and using
938 * mipmaps, lambda is also used to select the texture level of detail.
939 */
940static void lambda_textured_triangle( GLcontext *ctx,
941				      const SWvertex *v0,
942				      const SWvertex *v1,
943				      const SWvertex *v2 )
944{
945#define INTERP_Z 1
946#define INTERP_FOG 1
947#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
948#define INTERP_RGB 1
949#define INTERP_SPEC 1
950#define INTERP_ALPHA 1
951#define INTERP_TEX 1
952#define INTERP_LAMBDA 1
953
954#define RENDER_SPAN( span )   _mesa_write_texture_span(ctx, &span, GL_POLYGON);
955
956#include "s_tritemp.h"
957}
958
959
960/*
961 * This is the big one!
962 * Interpolate Z, RGB, Alpha, specular, fog, and N sets of texture coordinates
963 * with lambda (LOD).
964 * Yup, it's slow.
965 */
966static void
967lambda_multitextured_triangle( GLcontext *ctx,
968                               const SWvertex *v0,
969                               const SWvertex *v1,
970                               const SWvertex *v2 )
971{
972
973#define INTERP_Z 1
974#define INTERP_FOG 1
975#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
976#define INTERP_RGB 1
977#define INTERP_ALPHA 1
978#define INTERP_SPEC 1
979#define INTERP_MULTITEX 1
980#define INTERP_LAMBDA 1
981
982#define RENDER_SPAN( span )   _mesa_write_texture_span(ctx, &span, GL_POLYGON);
983
984#include "s_tritemp.h"
985
986}
987
988
989static void occlusion_zless_triangle( GLcontext *ctx,
990				      const SWvertex *v0,
991				      const SWvertex *v1,
992				      const SWvertex *v2 )
993{
994   if (ctx->OcclusionResult) {
995      return;
996   }
997
998#define DO_OCCLUSION_TEST
999#define INTERP_Z 1
1000#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
1001
1002#define RENDER_SPAN( span )				\
1003   GLuint i;						\
1004   for (i = 0; i < span.end; i++) {			\
1005      GLdepth z = FixedToDepth(span.z);			\
1006      if (z < zRow[i]) {				\
1007         ctx->OcclusionResult = GL_TRUE;		\
1008         return;					\
1009      }							\
1010      span.z += span.zStep;				\
1011   }
1012
1013#include "s_tritemp.h"
1014}
1015
1016static void nodraw_triangle( GLcontext *ctx,
1017			     const SWvertex *v0,
1018			     const SWvertex *v1,
1019			     const SWvertex *v2 )
1020{
1021   (void) (ctx && v0 && v1 && v2);
1022}
1023
1024
1025/*
1026 * This is used when separate specular color is enabled, but not
1027 * texturing.  We add the specular color to the primary color,
1028 * draw the triangle, then restore the original primary color.
1029 * Inefficient, but seldom needed.
1030 */
1031void _swrast_add_spec_terms_triangle( GLcontext *ctx,
1032				      const SWvertex *v0,
1033				      const SWvertex *v1,
1034				      const SWvertex *v2 )
1035{
1036   SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */
1037   SWvertex *ncv1 = (SWvertex *)v1;
1038   SWvertex *ncv2 = (SWvertex *)v2;
1039#if CHAN_TYPE == GL_FLOAT
1040   GLfloat rSum, gSum, bSum;
1041#else
1042   GLint rSum, gSum, bSum;
1043#endif
1044   GLchan c[3][4];
1045   /* save original colors */
1046   COPY_CHAN4( c[0], ncv0->color );
1047   COPY_CHAN4( c[1], ncv1->color );
1048   COPY_CHAN4( c[2], ncv2->color );
1049   /* sum v0 */
1050   rSum = ncv0->color[0] + ncv0->specular[0];
1051   gSum = ncv0->color[1] + ncv0->specular[1];
1052   bSum = ncv0->color[2] + ncv0->specular[2];
1053   ncv0->color[0] = MIN2(rSum, CHAN_MAX);
1054   ncv0->color[1] = MIN2(gSum, CHAN_MAX);
1055   ncv0->color[2] = MIN2(bSum, CHAN_MAX);
1056   /* sum v1 */
1057   rSum = ncv1->color[0] + ncv1->specular[0];
1058   gSum = ncv1->color[1] + ncv1->specular[1];
1059   bSum = ncv1->color[2] + ncv1->specular[2];
1060   ncv1->color[0] = MIN2(rSum, CHAN_MAX);
1061   ncv1->color[1] = MIN2(gSum, CHAN_MAX);
1062   ncv1->color[2] = MIN2(bSum, CHAN_MAX);
1063   /* sum v2 */
1064   rSum = ncv2->color[0] + ncv2->specular[0];
1065   gSum = ncv2->color[1] + ncv2->specular[1];
1066   bSum = ncv2->color[2] + ncv2->specular[2];
1067   ncv2->color[0] = MIN2(rSum, CHAN_MAX);
1068   ncv2->color[1] = MIN2(gSum, CHAN_MAX);
1069   ncv2->color[2] = MIN2(bSum, CHAN_MAX);
1070   /* draw */
1071   SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 );
1072   /* restore original colors */
1073   COPY_CHAN4( ncv0->color, c[0] );
1074   COPY_CHAN4( ncv1->color, c[1] );
1075   COPY_CHAN4( ncv2->color, c[2] );
1076}
1077
1078
1079
1080#ifdef DEBUG
1081
1082/* record the current triangle function name */
1083const char *_mesa_triFuncName = NULL;
1084
1085#define USE(triFunc)				\
1086do {						\
1087    _mesa_triFuncName = #triFunc;		\
1088    /*printf("%s\n", _mesa_triFuncName);*/	\
1089    swrast->Triangle = triFunc;			\
1090} while (0)
1091
1092#else
1093
1094#define USE(triFunc)  swrast->Triangle = triFunc;
1095
1096#endif
1097
1098
1099
1100
1101/*
1102 * Determine which triangle rendering function to use given the current
1103 * rendering context.
1104 *
1105 * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
1106 * remove tests to this code.
1107 */
1108void
1109_swrast_choose_triangle( GLcontext *ctx )
1110{
1111   SWcontext *swrast = SWRAST_CONTEXT(ctx);
1112   const GLboolean rgbmode = ctx->Visual.rgbMode;
1113
1114   if (ctx->Polygon.CullFlag &&
1115       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
1116      USE(nodraw_triangle);
1117      return;
1118   }
1119
1120   if (ctx->RenderMode==GL_RENDER) {
1121
1122      if (ctx->Polygon.SmoothFlag) {
1123         _mesa_set_aa_triangle_function(ctx);
1124         ASSERT(swrast->Triangle);
1125         return;
1126      }
1127
1128      if (ctx->Depth.OcclusionTest &&
1129          ctx->Depth.Test &&
1130          ctx->Depth.Mask == GL_FALSE &&
1131          ctx->Depth.Func == GL_LESS &&
1132          !ctx->Stencil.Enabled) {
1133         if ((rgbmode &&
1134              ctx->Color.ColorMask[0] == 0 &&
1135              ctx->Color.ColorMask[1] == 0 &&
1136              ctx->Color.ColorMask[2] == 0 &&
1137              ctx->Color.ColorMask[3] == 0)
1138             ||
1139             (!rgbmode && ctx->Color.IndexMask == 0)) {
1140            USE(occlusion_zless_triangle);
1141            return;
1142         }
1143      }
1144
1145      if (ctx->Texture._ReallyEnabled) {
1146         /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1147	 const struct gl_texture_object *texObj2D;
1148         const struct gl_texture_image *texImg;
1149         GLenum minFilter, magFilter, envMode;
1150         GLint format;
1151         texObj2D = ctx->Texture.Unit[0].Current2D;
1152         texImg = texObj2D ? texObj2D->Image[texObj2D->BaseLevel] : NULL;
1153         format = texImg ? texImg->TexFormat->MesaFormat : -1;
1154         minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0;
1155         magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0;
1156         envMode = ctx->Texture.Unit[0].EnvMode;
1157
1158         /* First see if we can used an optimized 2-D texture function */
1159         if (ctx->Texture._ReallyEnabled==TEXTURE0_2D
1160             && texObj2D->WrapS==GL_REPEAT
1161	     && texObj2D->WrapT==GL_REPEAT
1162             && texImg->Border==0
1163             && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA)
1164	     && minFilter == magFilter
1165	     && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
1166	     && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT) {
1167	    if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
1168	       if (minFilter == GL_NEAREST
1169		   && format == MESA_FORMAT_RGB
1170		   && (envMode == GL_REPLACE || envMode == GL_DECAL)
1171		   && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)
1172			&& ctx->Depth.Func == GL_LESS
1173			&& ctx->Depth.Mask == GL_TRUE)
1174		       || swrast->_RasterMask == TEXTURE_BIT)
1175		   && ctx->Polygon.StippleFlag == GL_FALSE) {
1176		  if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) {
1177		     USE(simple_z_textured_triangle);
1178		  }
1179		  else {
1180		     USE(simple_textured_triangle);
1181		  }
1182	       }
1183	       else {
1184#if CHAN_TYPE == GL_FLOAT
1185                  USE(general_textured_triangle);
1186#else
1187                  USE(affine_textured_triangle);
1188#endif
1189	       }
1190	    }
1191	    else {
1192#if CHAN_TYPE == GL_FLOAT
1193               USE(general_textured_triangle);
1194#else
1195               USE(persp_textured_triangle);
1196#endif
1197	    }
1198	 }
1199         else {
1200            /* More complicated textures (mipmap, multi-tex, sep specular) */
1201            GLboolean needLambda;
1202            /* if mag filter != min filter we need to compute lambda */
1203            const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;
1204            if (obj && obj->MinFilter != obj->MagFilter)
1205               needLambda = GL_TRUE;
1206            else
1207               needLambda = GL_FALSE;
1208            if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY) {
1209               USE(lambda_multitextured_triangle);
1210            }
1211            else {
1212               if (needLambda) {
1213		  USE(lambda_textured_triangle);
1214	       }
1215               else {
1216                  USE(general_textured_triangle);
1217	       }
1218            }
1219         }
1220      }
1221      else {
1222         ASSERT(!ctx->Texture._ReallyEnabled);
1223	 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1224	    /* smooth shaded, no texturing, stippled or some raster ops */
1225            if (rgbmode) {
1226	       USE(smooth_rgba_triangle);
1227            }
1228            else {
1229               USE(smooth_ci_triangle);
1230            }
1231	 }
1232	 else {
1233	    /* flat shaded, no texturing, stippled or some raster ops */
1234            if (rgbmode) {
1235	       USE(flat_rgba_triangle);
1236            }
1237            else {
1238               USE(flat_ci_triangle);
1239            }
1240	 }
1241      }
1242   }
1243   else if (ctx->RenderMode==GL_FEEDBACK) {
1244      USE(_mesa_feedback_triangle);
1245   }
1246   else {
1247      /* GL_SELECT mode */
1248      USE(_mesa_select_triangle);
1249   }
1250}
1251