s_triangle.c revision 30ea34a8d9ad22be626c24aa660a80f2e08c1e24
1/*
2 * Mesa 3-D graphics library
3 * Version:  7.3
4 *
5 * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26/*
27 * When the device driver doesn't implement triangle rasterization it
28 * can hook in _swrast_Triangle, which eventually calls one of these
29 * functions to draw triangles.
30 */
31
32#include "main/glheader.h"
33#include "main/context.h"
34#include "main/colormac.h"
35#include "main/imports.h"
36#include "main/macros.h"
37#include "main/mtypes.h"
38#include "main/state.h"
39#include "program/prog_instruction.h"
40
41#include "s_aatriangle.h"
42#include "s_context.h"
43#include "s_feedback.h"
44#include "s_span.h"
45#include "s_triangle.h"
46
47
48/**
49 * Test if a triangle should be culled.  Used for feedback and selection mode.
50 * \return GL_TRUE if the triangle is to be culled, GL_FALSE otherwise.
51 */
52GLboolean
53_swrast_culltriangle( struct gl_context *ctx,
54                      const SWvertex *v0,
55                      const SWvertex *v1,
56                      const SWvertex *v2 )
57{
58   SWcontext *swrast = SWRAST_CONTEXT(ctx);
59   GLfloat ex = v1->attrib[FRAG_ATTRIB_WPOS][0] - v0->attrib[FRAG_ATTRIB_WPOS][0];
60   GLfloat ey = v1->attrib[FRAG_ATTRIB_WPOS][1] - v0->attrib[FRAG_ATTRIB_WPOS][1];
61   GLfloat fx = v2->attrib[FRAG_ATTRIB_WPOS][0] - v0->attrib[FRAG_ATTRIB_WPOS][0];
62   GLfloat fy = v2->attrib[FRAG_ATTRIB_WPOS][1] - v0->attrib[FRAG_ATTRIB_WPOS][1];
63   GLfloat c = ex*fy-ey*fx;
64
65   if (c * swrast->_BackfaceSign * swrast->_BackfaceCullSign <= 0.0F)
66      return GL_FALSE;
67
68   return GL_TRUE;
69}
70
71
72
73/*
74 * Render a flat-shaded RGBA triangle.
75 */
76#define NAME flat_rgba_triangle
77#define INTERP_Z 1
78#define SETUP_CODE				\
79   ASSERT(ctx->Texture._EnabledCoordUnits == 0);\
80   ASSERT(ctx->Light.ShadeModel==GL_FLAT);	\
81   span.interpMask |= SPAN_RGBA;		\
82   span.red = ChanToFixed(v2->color[0]);	\
83   span.green = ChanToFixed(v2->color[1]);	\
84   span.blue = ChanToFixed(v2->color[2]);	\
85   span.alpha = ChanToFixed(v2->color[3]);	\
86   span.redStep = 0;				\
87   span.greenStep = 0;				\
88   span.blueStep = 0;				\
89   span.alphaStep = 0;
90#define RENDER_SPAN( span )  _swrast_write_rgba_span(ctx, &span);
91#include "s_tritemp.h"
92
93
94
95/*
96 * Render a smooth-shaded RGBA triangle.
97 */
98#define NAME smooth_rgba_triangle
99#define INTERP_Z 1
100#define INTERP_RGB 1
101#define INTERP_ALPHA 1
102#define SETUP_CODE				\
103   {						\
104      /* texturing must be off */		\
105      ASSERT(ctx->Texture._EnabledCoordUnits == 0);	\
106      ASSERT(ctx->Light.ShadeModel==GL_SMOOTH);	\
107   }
108#define RENDER_SPAN( span )  _swrast_write_rgba_span(ctx, &span);
109#include "s_tritemp.h"
110
111
112
113/*
114 * Render an RGB, GL_DECAL, textured triangle.
115 * Interpolate S,T only w/out mipmapping or perspective correction.
116 *
117 * No fog.  No depth testing.
118 */
119#define NAME simple_textured_triangle
120#define INTERP_INT_TEX 1
121#define S_SCALE twidth
122#define T_SCALE theight
123
124#define SETUP_CODE							\
125   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];	\
126   const struct gl_texture_object *obj = 				\
127      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
128   const struct gl_texture_image *texImg =				\
129      obj->Image[0][obj->BaseLevel];					\
130   const struct swrast_texture_image *swImg =				\
131      swrast_texture_image_const(texImg);				\
132   const GLfloat twidth = (GLfloat) texImg->Width;			\
133   const GLfloat theight = (GLfloat) texImg->Height;			\
134   const GLint twidth_log2 = texImg->WidthLog2;				\
135   const GLubyte *texture = (const GLubyte *) swImg->Map;		\
136   const GLint smask = texImg->Width - 1;				\
137   const GLint tmask = texImg->Height - 1;				\
138   ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
139   if (!rb || !texture) {						\
140      return;								\
141   }
142
143#define RENDER_SPAN( span )						\
144   GLuint i;								\
145   GLubyte (*rgba)[4] = swrast->SpanArrays->rgba8;			\
146   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
147   span.intTex[1] -= FIXED_HALF;					\
148   for (i = 0; i < span.end; i++) {					\
149      GLint s = FixedToInt(span.intTex[0]) & smask;			\
150      GLint t = FixedToInt(span.intTex[1]) & tmask;			\
151      GLint pos = (t << twidth_log2) + s;				\
152      pos = pos + pos + pos;  /* multiply by 3 */			\
153      rgba[i][RCOMP] = texture[pos+2];					\
154      rgba[i][GCOMP] = texture[pos+1];					\
155      rgba[i][BCOMP] = texture[pos+0];					\
156      rgba[i][ACOMP] = 0xff;                                            \
157      span.intTex[0] += span.intTexStep[0];				\
158      span.intTex[1] += span.intTexStep[1];				\
159   }									\
160   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE, span.end,                 \
161                   span.x, span.y, rgba, NULL);
162
163#include "s_tritemp.h"
164
165
166
167/*
168 * Render an RGB, GL_DECAL, textured triangle.
169 * Interpolate S,T, GL_LESS depth test, w/out mipmapping or
170 * perspective correction.
171 * Depth buffer bits must be <= sizeof(DEFAULT_SOFTWARE_DEPTH_TYPE)
172 *
173 * No fog.
174 */
175#define NAME simple_z_textured_triangle
176#define INTERP_Z 1
177#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
178#define INTERP_INT_TEX 1
179#define S_SCALE twidth
180#define T_SCALE theight
181
182#define SETUP_CODE							\
183   struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];	\
184   const struct gl_texture_object *obj = 				\
185      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
186   const struct gl_texture_image *texImg = 				\
187       obj->Image[0][obj->BaseLevel]; 					\
188   const struct swrast_texture_image *swImg =				\
189      swrast_texture_image_const(texImg);				\
190   const GLfloat twidth = (GLfloat) texImg->Width;			\
191   const GLfloat theight = (GLfloat) texImg->Height;			\
192   const GLint twidth_log2 = texImg->WidthLog2;				\
193   const GLubyte *texture = (const GLubyte *) swImg->Map;		\
194   const GLint smask = texImg->Width - 1;				\
195   const GLint tmask = texImg->Height - 1;				\
196   ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
197   if (!rb || !texture) {						\
198      return;								\
199   }
200
201#define RENDER_SPAN( span )						\
202   GLuint i;				    				\
203   GLubyte (*rgba)[4] = swrast->SpanArrays->rgba8;			\
204   GLubyte *mask = swrast->SpanArrays->mask;                            \
205   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
206   span.intTex[1] -= FIXED_HALF;					\
207   for (i = 0; i < span.end; i++) {					\
208      const GLuint z = FixedToDepth(span.z);				\
209      if (z < zRow[i]) {						\
210         GLint s = FixedToInt(span.intTex[0]) & smask;			\
211         GLint t = FixedToInt(span.intTex[1]) & tmask;			\
212         GLint pos = (t << twidth_log2) + s;				\
213         pos = pos + pos + pos;  /* multiply by 3 */			\
214         rgba[i][RCOMP] = texture[pos+2];				\
215         rgba[i][GCOMP] = texture[pos+1];				\
216         rgba[i][BCOMP] = texture[pos+0];				\
217         rgba[i][ACOMP] = 0xff;          				\
218         zRow[i] = z;							\
219         mask[i] = 1;							\
220      }									\
221      else {								\
222         mask[i] = 0;							\
223      }									\
224      span.intTex[0] += span.intTexStep[0];				\
225      span.intTex[1] += span.intTexStep[1];				\
226      span.z += span.zStep;						\
227   }									\
228   _swrast_put_row(ctx, rb, GL_UNSIGNED_BYTE,                           \
229                   span.end, span.x, span.y, rgba, mask);
230
231#include "s_tritemp.h"
232
233
234#if CHAN_TYPE != GL_FLOAT
235
236struct affine_info
237{
238   GLenum filter;
239   GLenum format;
240   GLenum envmode;
241   GLint smask, tmask;
242   GLint twidth_log2;
243   const GLchan *texture;
244   GLfixed er, eg, eb, ea;
245   GLint tbytesline, tsize;
246};
247
248
249static inline GLint
250ilerp(GLint t, GLint a, GLint b)
251{
252   return a + ((t * (b - a)) >> FIXED_SHIFT);
253}
254
255static inline GLint
256ilerp_2d(GLint ia, GLint ib, GLint v00, GLint v10, GLint v01, GLint v11)
257{
258   const GLint temp0 = ilerp(ia, v00, v10);
259   const GLint temp1 = ilerp(ia, v01, v11);
260   return ilerp(ib, temp0, temp1);
261}
262
263
264/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA
265 * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD
266 * texture env modes.
267 */
268static inline void
269affine_span(struct gl_context *ctx, SWspan *span,
270            struct affine_info *info)
271{
272   GLchan sample[4];  /* the filtered texture sample */
273   const GLuint texEnableSave = ctx->Texture._EnabledCoordUnits;
274
275   /* Instead of defining a function for each mode, a test is done
276    * between the outer and inner loops. This is to reduce code size
277    * and complexity. Observe that an optimizing compiler kills
278    * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
279    */
280
281#define NEAREST_RGB		\
282   sample[RCOMP] = tex00[2];	\
283   sample[GCOMP] = tex00[1];	\
284   sample[BCOMP] = tex00[0];	\
285   sample[ACOMP] = CHAN_MAX;
286
287#define LINEAR_RGB							\
288   sample[RCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
289   sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\
290   sample[BCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\
291   sample[ACOMP] = CHAN_MAX;
292
293#define NEAREST_RGBA  \
294   sample[RCOMP] = tex00[3];	\
295   sample[GCOMP] = tex00[2];	\
296   sample[BCOMP] = tex00[1];	\
297   sample[ACOMP] = tex00[0];
298
299#define LINEAR_RGBA							\
300   sample[RCOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]);\
301   sample[GCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\
302   sample[BCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\
303   sample[ACOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0])
304
305#define MODULATE							  \
306   dest[RCOMP] = span->red   * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
307   dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \
308   dest[BCOMP] = span->blue  * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \
309   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8)
310
311#define DECAL								\
312   dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red +		\
313               ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT))	\
314               >> (FIXED_SHIFT + 8);					\
315   dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green +		\
316               ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT))	\
317               >> (FIXED_SHIFT + 8);					\
318   dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue +		\
319               ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT))	\
320               >> (FIXED_SHIFT + 8);					\
321   dest[ACOMP] = FixedToInt(span->alpha)
322
323#define BLEND								\
324   dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red		\
325               + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8);	\
326   dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green		\
327               + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8);	\
328   dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue		\
329               + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8);	\
330   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8)
331
332#define REPLACE  COPY_CHAN4(dest, sample)
333
334#define ADD								\
335   {									\
336      GLint rSum = FixedToInt(span->red)   + (GLint) sample[RCOMP];	\
337      GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP];	\
338      GLint bSum = FixedToInt(span->blue)  + (GLint) sample[BCOMP];	\
339      dest[RCOMP] = MIN2(rSum, CHAN_MAX);				\
340      dest[GCOMP] = MIN2(gSum, CHAN_MAX);				\
341      dest[BCOMP] = MIN2(bSum, CHAN_MAX);				\
342      dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \
343  }
344
345/* shortcuts */
346
347#define NEAREST_RGB_REPLACE		\
348   NEAREST_RGB;				\
349   dest[0] = sample[0];			\
350   dest[1] = sample[1];			\
351   dest[2] = sample[2];			\
352   dest[3] = FixedToInt(span->alpha);
353
354#define NEAREST_RGBA_REPLACE  \
355   dest[RCOMP] = tex00[3]; \
356   dest[GCOMP] = tex00[2]; \
357   dest[BCOMP] = tex00[1]; \
358   dest[ACOMP] = tex00[0]
359
360#define SPAN_NEAREST(DO_TEX, COMPS)					\
361	for (i = 0; i < span->end; i++) {				\
362           /* Isn't it necessary to use FixedFloor below?? */		\
363           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
364           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
365           GLint pos = (t << info->twidth_log2) + s;			\
366           const GLchan *tex00 = info->texture + COMPS * pos;		\
367           DO_TEX;							\
368           span->red += span->redStep;					\
369	   span->green += span->greenStep;				\
370           span->blue += span->blueStep;				\
371	   span->alpha += span->alphaStep;				\
372	   span->intTex[0] += span->intTexStep[0];			\
373	   span->intTex[1] += span->intTexStep[1];			\
374           dest += 4;							\
375	}
376
377#define SPAN_LINEAR(DO_TEX, COMPS)					\
378	for (i = 0; i < span->end; i++) {				\
379           /* Isn't it necessary to use FixedFloor below?? */		\
380           const GLint s = FixedToInt(span->intTex[0]) & info->smask;	\
381           const GLint t = FixedToInt(span->intTex[1]) & info->tmask;	\
382           const GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK;	\
383           const GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK;	\
384           const GLint pos = (t << info->twidth_log2) + s;		\
385           const GLchan *tex00 = info->texture + COMPS * pos;		\
386           const GLchan *tex10 = tex00 + info->tbytesline;		\
387           const GLchan *tex01 = tex00 + COMPS;				\
388           const GLchan *tex11 = tex10 + COMPS;				\
389           if (t == info->tmask) {					\
390              tex10 -= info->tsize;					\
391              tex11 -= info->tsize;					\
392           }								\
393           if (s == info->smask) {					\
394              tex01 -= info->tbytesline;				\
395              tex11 -= info->tbytesline;				\
396           }								\
397           DO_TEX;							\
398           span->red += span->redStep;					\
399	   span->green += span->greenStep;				\
400           span->blue += span->blueStep;				\
401	   span->alpha += span->alphaStep;				\
402	   span->intTex[0] += span->intTexStep[0];			\
403	   span->intTex[1] += span->intTexStep[1];			\
404           dest += 4;							\
405	}
406
407
408   GLuint i;
409   GLchan *dest = span->array->rgba[0];
410
411   /* Disable tex units so they're not re-applied in swrast_write_rgba_span */
412   ctx->Texture._EnabledCoordUnits = 0x0;
413
414   span->intTex[0] -= FIXED_HALF;
415   span->intTex[1] -= FIXED_HALF;
416   switch (info->filter) {
417   case GL_NEAREST:
418      switch (info->format) {
419      case MESA_FORMAT_RGB888:
420         switch (info->envmode) {
421         case GL_MODULATE:
422            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
423            break;
424         case GL_DECAL:
425         case GL_REPLACE:
426            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
427            break;
428         case GL_BLEND:
429            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
430            break;
431         case GL_ADD:
432            SPAN_NEAREST(NEAREST_RGB;ADD,3);
433            break;
434         default:
435            _mesa_problem(ctx, "bad tex env mode in SPAN_LINEAR");
436            return;
437         }
438         break;
439      case MESA_FORMAT_RGBA8888:
440         switch(info->envmode) {
441         case GL_MODULATE:
442            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
443            break;
444         case GL_DECAL:
445            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
446            break;
447         case GL_BLEND:
448            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
449            break;
450         case GL_ADD:
451            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
452            break;
453         case GL_REPLACE:
454            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
455            break;
456         default:
457            _mesa_problem(ctx, "bad tex env mode (2) in SPAN_LINEAR");
458            return;
459         }
460         break;
461      }
462      break;
463
464   case GL_LINEAR:
465      span->intTex[0] -= FIXED_HALF;
466      span->intTex[1] -= FIXED_HALF;
467      switch (info->format) {
468      case MESA_FORMAT_RGB888:
469         switch (info->envmode) {
470         case GL_MODULATE:
471            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
472            break;
473         case GL_DECAL:
474         case GL_REPLACE:
475            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
476            break;
477         case GL_BLEND:
478            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
479            break;
480         case GL_ADD:
481            SPAN_LINEAR(LINEAR_RGB;ADD,3);
482            break;
483         default:
484            _mesa_problem(ctx, "bad tex env mode (3) in SPAN_LINEAR");
485            return;
486         }
487         break;
488      case MESA_FORMAT_RGBA8888:
489         switch (info->envmode) {
490         case GL_MODULATE:
491            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
492            break;
493         case GL_DECAL:
494            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
495            break;
496         case GL_BLEND:
497            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
498            break;
499         case GL_ADD:
500            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
501            break;
502         case GL_REPLACE:
503            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
504            break;
505         default:
506            _mesa_problem(ctx, "bad tex env mode (4) in SPAN_LINEAR");
507            return;
508         }
509         break;
510      }
511      break;
512   }
513   span->interpMask &= ~SPAN_RGBA;
514   ASSERT(span->arrayMask & SPAN_RGBA);
515
516   _swrast_write_rgba_span(ctx, span);
517
518   /* re-enable texture units */
519   ctx->Texture._EnabledCoordUnits = texEnableSave;
520
521#undef SPAN_NEAREST
522#undef SPAN_LINEAR
523}
524
525
526
527/*
528 * Render an RGB/RGBA textured triangle without perspective correction.
529 */
530#define NAME affine_textured_triangle
531#define INTERP_Z 1
532#define INTERP_RGB 1
533#define INTERP_ALPHA 1
534#define INTERP_INT_TEX 1
535#define S_SCALE twidth
536#define T_SCALE theight
537
538#define SETUP_CODE							\
539   struct affine_info info;						\
540   struct gl_texture_unit *unit = ctx->Texture.Unit+0;			\
541   const struct gl_texture_object *obj = 				\
542      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
543   const struct gl_texture_image *texImg = 				\
544      obj->Image[0][obj->BaseLevel]; 					\
545   const struct swrast_texture_image *swImg =				\
546      swrast_texture_image_const(texImg);				\
547   const GLfloat twidth = (GLfloat) texImg->Width;			\
548   const GLfloat theight = (GLfloat) texImg->Height;			\
549   info.texture = (const GLchan *) swImg->Map;				\
550   info.twidth_log2 = texImg->WidthLog2;				\
551   info.smask = texImg->Width - 1;					\
552   info.tmask = texImg->Height - 1;					\
553   info.format = texImg->TexFormat;					\
554   info.filter = obj->Sampler.MinFilter;				\
555   info.envmode = unit->EnvMode;					\
556   info.er = 0;					\
557   info.eg = 0;					\
558   info.eb = 0;					\
559   span.arrayMask |= SPAN_RGBA;						\
560									\
561   if (info.envmode == GL_BLEND) {					\
562      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
563      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
564      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
565      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
566      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
567   }									\
568   if (!info.texture) {							\
569      /* this shouldn't happen */					\
570      return;								\
571   }									\
572									\
573   switch (info.format) {						\
574   case MESA_FORMAT_RGB888:						\
575      info.tbytesline = texImg->Width * 3;				\
576      break;								\
577   case MESA_FORMAT_RGBA8888:						\
578      info.tbytesline = texImg->Width * 4;				\
579      break;								\
580   default:								\
581      _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
582      return;								\
583   }									\
584   info.tsize = texImg->Height * info.tbytesline;
585
586#define RENDER_SPAN( span )   affine_span(ctx, &span, &info);
587
588#include "s_tritemp.h"
589
590
591
592struct persp_info
593{
594   GLenum filter;
595   GLenum format;
596   GLenum envmode;
597   GLint smask, tmask;
598   GLint twidth_log2;
599   const GLchan *texture;
600   GLfixed er, eg, eb, ea;   /* texture env color */
601   GLint tbytesline, tsize;
602};
603
604
605static inline void
606fast_persp_span(struct gl_context *ctx, SWspan *span,
607		struct persp_info *info)
608{
609   GLchan sample[4];  /* the filtered texture sample */
610
611  /* Instead of defining a function for each mode, a test is done
612   * between the outer and inner loops. This is to reduce code size
613   * and complexity. Observe that an optimizing compiler kills
614   * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
615   */
616#define SPAN_NEAREST(DO_TEX,COMP)					\
617	for (i = 0; i < span->end; i++) {				\
618           GLdouble invQ = tex_coord[2] ?				\
619                                 (1.0 / tex_coord[2]) : 1.0;            \
620           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
621           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
622           GLint s = IFLOOR(s_tmp) & info->smask;	        	\
623           GLint t = IFLOOR(t_tmp) & info->tmask;	        	\
624           GLint pos = (t << info->twidth_log2) + s;			\
625           const GLchan *tex00 = info->texture + COMP * pos;		\
626           DO_TEX;							\
627           span->red += span->redStep;					\
628	   span->green += span->greenStep;				\
629           span->blue += span->blueStep;				\
630	   span->alpha += span->alphaStep;				\
631	   tex_coord[0] += tex_step[0];					\
632	   tex_coord[1] += tex_step[1];					\
633	   tex_coord[2] += tex_step[2];					\
634           dest += 4;							\
635	}
636
637#define SPAN_LINEAR(DO_TEX,COMP)					\
638	for (i = 0; i < span->end; i++) {				\
639           GLdouble invQ = tex_coord[2] ?				\
640                                 (1.0 / tex_coord[2]) : 1.0;            \
641           const GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);	\
642           const GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);	\
643           const GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF;	\
644           const GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF;      \
645           const GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask;	\
646           const GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask;	\
647           const GLfixed sf = s_fix & FIXED_FRAC_MASK;			\
648           const GLfixed tf = t_fix & FIXED_FRAC_MASK;			\
649           const GLint pos = (t << info->twidth_log2) + s;		\
650           const GLchan *tex00 = info->texture + COMP * pos;		\
651           const GLchan *tex10 = tex00 + info->tbytesline;		\
652           const GLchan *tex01 = tex00 + COMP;				\
653           const GLchan *tex11 = tex10 + COMP;				\
654           if (t == info->tmask) {					\
655              tex10 -= info->tsize;					\
656              tex11 -= info->tsize;					\
657           }								\
658           if (s == info->smask) {					\
659              tex01 -= info->tbytesline;				\
660              tex11 -= info->tbytesline;				\
661           }								\
662           DO_TEX;							\
663           span->red   += span->redStep;				\
664	   span->green += span->greenStep;				\
665           span->blue  += span->blueStep;				\
666	   span->alpha += span->alphaStep;				\
667	   tex_coord[0] += tex_step[0];					\
668	   tex_coord[1] += tex_step[1];					\
669	   tex_coord[2] += tex_step[2];					\
670           dest += 4;							\
671	}
672
673   GLuint i;
674   GLfloat tex_coord[3], tex_step[3];
675   GLchan *dest = span->array->rgba[0];
676
677   const GLuint texEnableSave = ctx->Texture._EnabledCoordUnits;
678   ctx->Texture._EnabledCoordUnits = 0;
679
680   tex_coord[0] = span->attrStart[FRAG_ATTRIB_TEX0][0]  * (info->smask + 1);
681   tex_step[0] = span->attrStepX[FRAG_ATTRIB_TEX0][0] * (info->smask + 1);
682   tex_coord[1] = span->attrStart[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
683   tex_step[1] = span->attrStepX[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
684   /* span->attrStart[FRAG_ATTRIB_TEX0][2] only if 3D-texturing, here only 2D */
685   tex_coord[2] = span->attrStart[FRAG_ATTRIB_TEX0][3];
686   tex_step[2] = span->attrStepX[FRAG_ATTRIB_TEX0][3];
687
688   switch (info->filter) {
689   case GL_NEAREST:
690      switch (info->format) {
691      case MESA_FORMAT_RGB888:
692         switch (info->envmode) {
693         case GL_MODULATE:
694            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
695            break;
696         case GL_DECAL:
697         case GL_REPLACE:
698            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
699            break;
700         case GL_BLEND:
701            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
702            break;
703         case GL_ADD:
704            SPAN_NEAREST(NEAREST_RGB;ADD,3);
705            break;
706         default:
707            _mesa_problem(ctx, "bad tex env mode (5) in SPAN_LINEAR");
708            return;
709         }
710         break;
711      case MESA_FORMAT_RGBA8888:
712         switch(info->envmode) {
713         case GL_MODULATE:
714            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
715            break;
716         case GL_DECAL:
717            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
718            break;
719         case GL_BLEND:
720            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
721            break;
722         case GL_ADD:
723            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
724            break;
725         case GL_REPLACE:
726            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
727            break;
728         default:
729            _mesa_problem(ctx, "bad tex env mode (6) in SPAN_LINEAR");
730            return;
731         }
732         break;
733      }
734      break;
735
736   case GL_LINEAR:
737      switch (info->format) {
738      case MESA_FORMAT_RGB888:
739         switch (info->envmode) {
740         case GL_MODULATE:
741            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
742            break;
743         case GL_DECAL:
744         case GL_REPLACE:
745            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
746            break;
747         case GL_BLEND:
748            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
749            break;
750         case GL_ADD:
751            SPAN_LINEAR(LINEAR_RGB;ADD,3);
752            break;
753         default:
754            _mesa_problem(ctx, "bad tex env mode (7) in SPAN_LINEAR");
755            return;
756         }
757         break;
758      case MESA_FORMAT_RGBA8888:
759         switch (info->envmode) {
760         case GL_MODULATE:
761            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
762            break;
763         case GL_DECAL:
764            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
765            break;
766         case GL_BLEND:
767            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
768            break;
769         case GL_ADD:
770            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
771            break;
772         case GL_REPLACE:
773            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
774            break;
775         default:
776            _mesa_problem(ctx, "bad tex env mode (8) in SPAN_LINEAR");
777            return;
778         }
779         break;
780      }
781      break;
782   }
783
784   ASSERT(span->arrayMask & SPAN_RGBA);
785   _swrast_write_rgba_span(ctx, span);
786
787#undef SPAN_NEAREST
788#undef SPAN_LINEAR
789
790   /* restore state */
791   ctx->Texture._EnabledCoordUnits = texEnableSave;
792}
793
794
795/*
796 * Render an perspective corrected RGB/RGBA textured triangle.
797 * The Q (aka V in Mesa) coordinate must be zero such that the divide
798 * by interpolated Q/W comes out right.
799 *
800 */
801#define NAME persp_textured_triangle
802#define INTERP_Z 1
803#define INTERP_RGB 1
804#define INTERP_ALPHA 1
805#define INTERP_ATTRIBS 1
806
807#define SETUP_CODE							\
808   struct persp_info info;						\
809   const struct gl_texture_unit *unit = ctx->Texture.Unit+0;		\
810   const struct gl_texture_object *obj = 				\
811      ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
812   const struct gl_texture_image *texImg = 				\
813      obj->Image[0][obj->BaseLevel];			 		\
814   const struct swrast_texture_image *swImg =				\
815      swrast_texture_image_const(texImg);				\
816   info.texture = (const GLchan *) swImg->Map;				\
817   info.twidth_log2 = texImg->WidthLog2;				\
818   info.smask = texImg->Width - 1;					\
819   info.tmask = texImg->Height - 1;					\
820   info.format = texImg->TexFormat;					\
821   info.filter = obj->Sampler.MinFilter;				\
822   info.envmode = unit->EnvMode;					\
823   info.er = 0;					\
824   info.eg = 0;					\
825   info.eb = 0;					\
826									\
827   if (info.envmode == GL_BLEND) {					\
828      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
829      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
830      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
831      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
832      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
833   }									\
834   if (!info.texture) {							\
835      /* this shouldn't happen */					\
836      return;								\
837   }									\
838									\
839   switch (info.format) {						\
840   case MESA_FORMAT_RGB888:						\
841      info.tbytesline = texImg->Width * 3;				\
842      break;								\
843   case MESA_FORMAT_RGBA8888:						\
844      info.tbytesline = texImg->Width * 4;				\
845      break;								\
846   default:								\
847      _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
848      return;								\
849   }									\
850   info.tsize = texImg->Height * info.tbytesline;
851
852#define RENDER_SPAN( span )			\
853   span.interpMask &= ~SPAN_RGBA;		\
854   span.arrayMask |= SPAN_RGBA;			\
855   fast_persp_span(ctx, &span, &info);
856
857#include "s_tritemp.h"
858
859#endif /*CHAN_TYPE != GL_FLOAT*/
860
861
862
863/*
864 * Render an RGBA triangle with arbitrary attributes.
865 */
866#define NAME general_triangle
867#define INTERP_Z 1
868#define INTERP_RGB 1
869#define INTERP_ALPHA 1
870#define INTERP_ATTRIBS 1
871#define RENDER_SPAN( span )   _swrast_write_rgba_span(ctx, &span);
872#include "s_tritemp.h"
873
874
875
876
877/*
878 * Special tri function for occlusion testing
879 */
880#define NAME occlusion_zless_16_triangle
881#define INTERP_Z 1
882#define SETUP_CODE							\
883   struct gl_renderbuffer *rb =                                         \
884      ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;           \
885   struct gl_query_object *q = ctx->Query.CurrentOcclusionObject;	\
886   ASSERT(ctx->Depth.Test);						\
887   ASSERT(!ctx->Depth.Mask);						\
888   ASSERT(ctx->Depth.Func == GL_LESS);					\
889   assert(rb->Format == MESA_FORMAT_Z16);                               \
890   if (!q) {								\
891      return;								\
892   }
893#define RENDER_SPAN( span )						\
894   {                                                                    \
895      GLuint i;								\
896      const GLushort *zRow = (const GLushort *)				\
897         _swrast_pixel_address(rb, span.x, span.y);                     \
898      for (i = 0; i < span.end; i++) {					\
899         GLuint z = FixedToDepth(span.z);				\
900         if (z < zRow[i]) {						\
901            q->Result++;						\
902         }								\
903         span.z += span.zStep;						\
904      }									\
905   }
906#include "s_tritemp.h"
907
908
909
910static void
911nodraw_triangle( struct gl_context *ctx,
912                 const SWvertex *v0,
913                 const SWvertex *v1,
914                 const SWvertex *v2 )
915{
916   (void) (ctx && v0 && v1 && v2);
917}
918
919
920/*
921 * This is used when separate specular color is enabled, but not
922 * texturing.  We add the specular color to the primary color,
923 * draw the triangle, then restore the original primary color.
924 * Inefficient, but seldom needed.
925 */
926void
927_swrast_add_spec_terms_triangle(struct gl_context *ctx, const SWvertex *v0,
928                                const SWvertex *v1, const SWvertex *v2)
929{
930   SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */
931   SWvertex *ncv1 = (SWvertex *)v1;
932   SWvertex *ncv2 = (SWvertex *)v2;
933   GLfloat rSum, gSum, bSum;
934   GLchan cSave[3][4];
935
936   /* save original colors */
937   COPY_CHAN4( cSave[0], ncv0->color );
938   COPY_CHAN4( cSave[1], ncv1->color );
939   COPY_CHAN4( cSave[2], ncv2->color );
940   /* sum v0 */
941   rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
942   gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
943   bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
944   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
945   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
946   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
947   /* sum v1 */
948   rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[FRAG_ATTRIB_COL1][0];
949   gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[FRAG_ATTRIB_COL1][1];
950   bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[FRAG_ATTRIB_COL1][2];
951   UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[0], rSum);
952   UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[1], gSum);
953   UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[2], bSum);
954   /* sum v2 */
955   rSum = CHAN_TO_FLOAT(ncv2->color[0]) + ncv2->attrib[FRAG_ATTRIB_COL1][0];
956   gSum = CHAN_TO_FLOAT(ncv2->color[1]) + ncv2->attrib[FRAG_ATTRIB_COL1][1];
957   bSum = CHAN_TO_FLOAT(ncv2->color[2]) + ncv2->attrib[FRAG_ATTRIB_COL1][2];
958   UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[0], rSum);
959   UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[1], gSum);
960   UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[2], bSum);
961   /* draw */
962   SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 );
963   /* restore original colors */
964   COPY_CHAN4( ncv0->color, cSave[0] );
965   COPY_CHAN4( ncv1->color, cSave[1] );
966   COPY_CHAN4( ncv2->color, cSave[2] );
967}
968
969
970
971#ifdef DEBUG
972
973/* record the current triangle function name */
974const char *_mesa_triFuncName = NULL;
975
976#define USE(triFunc)				\
977do {						\
978    _mesa_triFuncName = #triFunc;		\
979    /*printf("%s\n", _mesa_triFuncName);*/	\
980    swrast->Triangle = triFunc;			\
981} while (0)
982
983#else
984
985#define USE(triFunc)  swrast->Triangle = triFunc;
986
987#endif
988
989
990
991
992/*
993 * Determine which triangle rendering function to use given the current
994 * rendering context.
995 *
996 * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
997 * remove tests to this code.
998 */
999void
1000_swrast_choose_triangle( struct gl_context *ctx )
1001{
1002   SWcontext *swrast = SWRAST_CONTEXT(ctx);
1003
1004   if (ctx->Polygon.CullFlag &&
1005       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
1006      USE(nodraw_triangle);
1007      return;
1008   }
1009
1010   if (ctx->RenderMode==GL_RENDER) {
1011      struct gl_renderbuffer *depthRb =
1012         ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
1013
1014      if (ctx->Polygon.SmoothFlag) {
1015         _swrast_set_aa_triangle_function(ctx);
1016         ASSERT(swrast->Triangle);
1017         return;
1018      }
1019
1020      /* special case for occlusion testing */
1021      if (ctx->Query.CurrentOcclusionObject &&
1022          ctx->Depth.Test &&
1023          ctx->Depth.Mask == GL_FALSE &&
1024          ctx->Depth.Func == GL_LESS &&
1025          !ctx->Stencil._Enabled &&
1026          depthRb &&
1027          depthRb->Format == MESA_FORMAT_Z16) {
1028         if (ctx->Color.ColorMask[0][0] == 0 &&
1029	     ctx->Color.ColorMask[0][1] == 0 &&
1030	     ctx->Color.ColorMask[0][2] == 0 &&
1031	     ctx->Color.ColorMask[0][3] == 0) {
1032            USE(occlusion_zless_16_triangle);
1033            return;
1034         }
1035      }
1036
1037      /*
1038       * XXX should examine swrast->_ActiveAttribMask to determine what
1039       * needs to be interpolated.
1040       */
1041      if (ctx->Texture._EnabledCoordUnits ||
1042	  _swrast_use_fragment_program(ctx) ||
1043          ctx->ATIFragmentShader._Enabled ||
1044          _mesa_need_secondary_color(ctx) ||
1045          swrast->_FogEnabled) {
1046         /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1047         const struct gl_texture_object *texObj2D;
1048         const struct gl_texture_image *texImg;
1049         const struct swrast_texture_image *swImg;
1050         GLenum minFilter, magFilter, envMode;
1051         gl_format format;
1052         texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];
1053
1054         texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
1055         swImg = swrast_texture_image_const(texImg);
1056
1057         format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE;
1058         minFilter = texObj2D ? texObj2D->Sampler.MinFilter : GL_NONE;
1059         magFilter = texObj2D ? texObj2D->Sampler.MagFilter : GL_NONE;
1060         envMode = ctx->Texture.Unit[0].EnvMode;
1061
1062         /* First see if we can use an optimized 2-D texture function */
1063         if (ctx->Texture._EnabledCoordUnits == 0x1
1064             && !_swrast_use_fragment_program(ctx)
1065             && !ctx->ATIFragmentShader._Enabled
1066             && ctx->Texture._EnabledUnits == 0x1
1067             && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
1068             && texObj2D->Sampler.WrapS == GL_REPEAT
1069             && texObj2D->Sampler.WrapT == GL_REPEAT
1070             && texObj2D->_Swizzle == SWIZZLE_NOOP
1071             && swImg->_IsPowerOfTwo
1072             && texImg->Border == 0
1073             && texImg->Width == swImg->RowStride
1074             && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
1075             && minFilter == magFilter
1076             && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
1077             && !swrast->_FogEnabled
1078             && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT
1079             && ctx->Texture.Unit[0].EnvMode != GL_COMBINE4_NV) {
1080	    if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
1081	       if (minFilter == GL_NEAREST
1082		   && format == MESA_FORMAT_RGB888
1083		   && (envMode == GL_REPLACE || envMode == GL_DECAL)
1084		   && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)
1085			&& ctx->Depth.Func == GL_LESS
1086			&& ctx->Depth.Mask == GL_TRUE)
1087		       || swrast->_RasterMask == TEXTURE_BIT)
1088		   && ctx->Polygon.StippleFlag == GL_FALSE
1089                   && ctx->DrawBuffer->Visual.depthBits <= 16) {
1090		  if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) {
1091		     USE(simple_z_textured_triangle);
1092		  }
1093		  else {
1094		     USE(simple_textured_triangle);
1095		  }
1096	       }
1097	       else {
1098#if CHAN_BITS != 8
1099                  USE(general_triangle);
1100#else
1101                  if (format == MESA_FORMAT_RGBA8888 && !_mesa_little_endian()) {
1102                     /* We only handle RGBA8888 correctly on little endian
1103                      * in the optimized code above.
1104                      */
1105                     USE(general_triangle);
1106                  }
1107                  else {
1108                     USE(affine_textured_triangle);
1109                 }
1110#endif
1111	       }
1112	    }
1113	    else {
1114#if CHAN_BITS != 8
1115               USE(general_triangle);
1116#else
1117               USE(persp_textured_triangle);
1118#endif
1119	    }
1120	 }
1121         else {
1122            /* general case textured triangles */
1123            USE(general_triangle);
1124         }
1125      }
1126      else {
1127         ASSERT(!swrast->_FogEnabled);
1128         ASSERT(!_mesa_need_secondary_color(ctx));
1129	 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1130	    /* smooth shaded, no texturing, stippled or some raster ops */
1131#if CHAN_BITS != 8
1132               USE(general_triangle);
1133#else
1134               USE(smooth_rgba_triangle);
1135#endif
1136	 }
1137	 else {
1138	    /* flat shaded, no texturing, stippled or some raster ops */
1139#if CHAN_BITS != 8
1140            USE(general_triangle);
1141#else
1142            USE(flat_rgba_triangle);
1143#endif
1144	 }
1145      }
1146   }
1147   else if (ctx->RenderMode==GL_FEEDBACK) {
1148      USE(_swrast_feedback_triangle);
1149   }
1150   else {
1151      /* GL_SELECT mode */
1152      USE(_swrast_select_triangle);
1153   }
1154}
1155