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