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