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