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