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