s_triangle.c revision bd3c10c0f0c60ab3421c2da2eab814edc2296cb0
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 */ 52GLboolean 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 rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, NULL); 161 162#include "s_tritemp.h" 163 164 165 166/* 167 * Render an RGB, GL_DECAL, textured triangle. 168 * Interpolate S,T, GL_LESS depth test, w/out mipmapping or 169 * perspective correction. 170 * Depth buffer bits must be <= sizeof(DEFAULT_SOFTWARE_DEPTH_TYPE) 171 * 172 * No fog. 173 */ 174#define NAME simple_z_textured_triangle 175#define INTERP_Z 1 176#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 177#define INTERP_INT_TEX 1 178#define S_SCALE twidth 179#define T_SCALE theight 180 181#define SETUP_CODE \ 182 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; \ 183 const struct gl_texture_object *obj = \ 184 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ 185 const struct gl_texture_image *texImg = \ 186 obj->Image[0][obj->BaseLevel]; \ 187 const struct swrast_texture_image *swImg = \ 188 swrast_texture_image_const(texImg); \ 189 const GLfloat twidth = (GLfloat) texImg->Width; \ 190 const GLfloat theight = (GLfloat) texImg->Height; \ 191 const GLint twidth_log2 = texImg->WidthLog2; \ 192 const GLubyte *texture = (const GLubyte *) swImg->Map; \ 193 const GLint smask = texImg->Width - 1; \ 194 const GLint tmask = texImg->Height - 1; \ 195 ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ 196 if (!rb || !texture) { \ 197 return; \ 198 } 199 200#define RENDER_SPAN( span ) \ 201 GLuint i; \ 202 GLubyte rgba[MAX_WIDTH][4]; \ 203 span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \ 204 span.intTex[1] -= FIXED_HALF; \ 205 for (i = 0; i < span.end; i++) { \ 206 const GLuint z = FixedToDepth(span.z); \ 207 if (z < zRow[i]) { \ 208 GLint s = FixedToInt(span.intTex[0]) & smask; \ 209 GLint t = FixedToInt(span.intTex[1]) & tmask; \ 210 GLint pos = (t << twidth_log2) + s; \ 211 pos = pos + pos + pos; /* multiply by 3 */ \ 212 rgba[i][RCOMP] = texture[pos+2]; \ 213 rgba[i][GCOMP] = texture[pos+1]; \ 214 rgba[i][BCOMP] = texture[pos+0]; \ 215 rgba[i][ACOMP] = 0xff; \ 216 zRow[i] = z; \ 217 span.array->mask[i] = 1; \ 218 } \ 219 else { \ 220 span.array->mask[i] = 0; \ 221 } \ 222 span.intTex[0] += span.intTexStep[0]; \ 223 span.intTex[1] += span.intTexStep[1]; \ 224 span.z += span.zStep; \ 225 } \ 226 rb->PutRow(ctx, rb, span.end, span.x, span.y, rgba, span.array->mask); 227 228#include "s_tritemp.h" 229 230 231#if CHAN_TYPE != GL_FLOAT 232 233struct affine_info 234{ 235 GLenum filter; 236 GLenum format; 237 GLenum envmode; 238 GLint smask, tmask; 239 GLint twidth_log2; 240 const GLchan *texture; 241 GLfixed er, eg, eb, ea; 242 GLint tbytesline, tsize; 243}; 244 245 246static inline GLint 247ilerp(GLint t, GLint a, GLint b) 248{ 249 return a + ((t * (b - a)) >> FIXED_SHIFT); 250} 251 252static inline GLint 253ilerp_2d(GLint ia, GLint ib, GLint v00, GLint v10, GLint v01, GLint v11) 254{ 255 const GLint temp0 = ilerp(ia, v00, v10); 256 const GLint temp1 = ilerp(ia, v01, v11); 257 return ilerp(ib, temp0, temp1); 258} 259 260 261/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA 262 * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD 263 * texture env modes. 264 */ 265static inline void 266affine_span(struct gl_context *ctx, SWspan *span, 267 struct affine_info *info) 268{ 269 GLchan sample[4]; /* the filtered texture sample */ 270 const GLuint texEnableSave = ctx->Texture._EnabledCoordUnits; 271 272 /* Instead of defining a function for each mode, a test is done 273 * between the outer and inner loops. This is to reduce code size 274 * and complexity. Observe that an optimizing compiler kills 275 * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST). 276 */ 277 278#define NEAREST_RGB \ 279 sample[RCOMP] = tex00[2]; \ 280 sample[GCOMP] = tex00[1]; \ 281 sample[BCOMP] = tex00[0]; \ 282 sample[ACOMP] = CHAN_MAX; 283 284#define LINEAR_RGB \ 285 sample[RCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ 286 sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ 287 sample[BCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ 288 sample[ACOMP] = CHAN_MAX; 289 290#define NEAREST_RGBA \ 291 sample[RCOMP] = tex00[3]; \ 292 sample[GCOMP] = tex00[2]; \ 293 sample[BCOMP] = tex00[1]; \ 294 sample[ACOMP] = tex00[0]; 295 296#define LINEAR_RGBA \ 297 sample[RCOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]);\ 298 sample[GCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ 299 sample[BCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ 300 sample[ACOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]) 301 302#define MODULATE \ 303 dest[RCOMP] = span->red * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 304 dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 305 dest[BCOMP] = span->blue * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 306 dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8) 307 308#define DECAL \ 309 dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red + \ 310 ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT)) \ 311 >> (FIXED_SHIFT + 8); \ 312 dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green + \ 313 ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT)) \ 314 >> (FIXED_SHIFT + 8); \ 315 dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue + \ 316 ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT)) \ 317 >> (FIXED_SHIFT + 8); \ 318 dest[ACOMP] = FixedToInt(span->alpha) 319 320#define BLEND \ 321 dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red \ 322 + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8); \ 323 dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green \ 324 + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8); \ 325 dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue \ 326 + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8); \ 327 dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8) 328 329#define REPLACE COPY_CHAN4(dest, sample) 330 331#define ADD \ 332 { \ 333 GLint rSum = FixedToInt(span->red) + (GLint) sample[RCOMP]; \ 334 GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP]; \ 335 GLint bSum = FixedToInt(span->blue) + (GLint) sample[BCOMP]; \ 336 dest[RCOMP] = MIN2(rSum, CHAN_MAX); \ 337 dest[GCOMP] = MIN2(gSum, CHAN_MAX); \ 338 dest[BCOMP] = MIN2(bSum, CHAN_MAX); \ 339 dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \ 340 } 341 342/* shortcuts */ 343 344#define NEAREST_RGB_REPLACE \ 345 NEAREST_RGB; \ 346 dest[0] = sample[0]; \ 347 dest[1] = sample[1]; \ 348 dest[2] = sample[2]; \ 349 dest[3] = FixedToInt(span->alpha); 350 351#define NEAREST_RGBA_REPLACE \ 352 dest[RCOMP] = tex00[3]; \ 353 dest[GCOMP] = tex00[2]; \ 354 dest[BCOMP] = tex00[1]; \ 355 dest[ACOMP] = tex00[0] 356 357#define SPAN_NEAREST(DO_TEX, COMPS) \ 358 for (i = 0; i < span->end; i++) { \ 359 /* Isn't it necessary to use FixedFloor below?? */ \ 360 GLint s = FixedToInt(span->intTex[0]) & info->smask; \ 361 GLint t = FixedToInt(span->intTex[1]) & info->tmask; \ 362 GLint pos = (t << info->twidth_log2) + s; \ 363 const GLchan *tex00 = info->texture + COMPS * pos; \ 364 DO_TEX; \ 365 span->red += span->redStep; \ 366 span->green += span->greenStep; \ 367 span->blue += span->blueStep; \ 368 span->alpha += span->alphaStep; \ 369 span->intTex[0] += span->intTexStep[0]; \ 370 span->intTex[1] += span->intTexStep[1]; \ 371 dest += 4; \ 372 } 373 374#define SPAN_LINEAR(DO_TEX, COMPS) \ 375 for (i = 0; i < span->end; i++) { \ 376 /* Isn't it necessary to use FixedFloor below?? */ \ 377 const GLint s = FixedToInt(span->intTex[0]) & info->smask; \ 378 const GLint t = FixedToInt(span->intTex[1]) & info->tmask; \ 379 const GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK; \ 380 const GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK; \ 381 const GLint pos = (t << info->twidth_log2) + s; \ 382 const GLchan *tex00 = info->texture + COMPS * pos; \ 383 const GLchan *tex10 = tex00 + info->tbytesline; \ 384 const GLchan *tex01 = tex00 + COMPS; \ 385 const GLchan *tex11 = tex10 + COMPS; \ 386 if (t == info->tmask) { \ 387 tex10 -= info->tsize; \ 388 tex11 -= info->tsize; \ 389 } \ 390 if (s == info->smask) { \ 391 tex01 -= info->tbytesline; \ 392 tex11 -= info->tbytesline; \ 393 } \ 394 DO_TEX; \ 395 span->red += span->redStep; \ 396 span->green += span->greenStep; \ 397 span->blue += span->blueStep; \ 398 span->alpha += span->alphaStep; \ 399 span->intTex[0] += span->intTexStep[0]; \ 400 span->intTex[1] += span->intTexStep[1]; \ 401 dest += 4; \ 402 } 403 404 405 GLuint i; 406 GLchan *dest = span->array->rgba[0]; 407 408 /* Disable tex units so they're not re-applied in swrast_write_rgba_span */ 409 ctx->Texture._EnabledCoordUnits = 0x0; 410 411 span->intTex[0] -= FIXED_HALF; 412 span->intTex[1] -= FIXED_HALF; 413 switch (info->filter) { 414 case GL_NEAREST: 415 switch (info->format) { 416 case MESA_FORMAT_RGB888: 417 switch (info->envmode) { 418 case GL_MODULATE: 419 SPAN_NEAREST(NEAREST_RGB;MODULATE,3); 420 break; 421 case GL_DECAL: 422 case GL_REPLACE: 423 SPAN_NEAREST(NEAREST_RGB_REPLACE,3); 424 break; 425 case GL_BLEND: 426 SPAN_NEAREST(NEAREST_RGB;BLEND,3); 427 break; 428 case GL_ADD: 429 SPAN_NEAREST(NEAREST_RGB;ADD,3); 430 break; 431 default: 432 _mesa_problem(ctx, "bad tex env mode in SPAN_LINEAR"); 433 return; 434 } 435 break; 436 case MESA_FORMAT_RGBA8888: 437 switch(info->envmode) { 438 case GL_MODULATE: 439 SPAN_NEAREST(NEAREST_RGBA;MODULATE,4); 440 break; 441 case GL_DECAL: 442 SPAN_NEAREST(NEAREST_RGBA;DECAL,4); 443 break; 444 case GL_BLEND: 445 SPAN_NEAREST(NEAREST_RGBA;BLEND,4); 446 break; 447 case GL_ADD: 448 SPAN_NEAREST(NEAREST_RGBA;ADD,4); 449 break; 450 case GL_REPLACE: 451 SPAN_NEAREST(NEAREST_RGBA_REPLACE,4); 452 break; 453 default: 454 _mesa_problem(ctx, "bad tex env mode (2) in SPAN_LINEAR"); 455 return; 456 } 457 break; 458 } 459 break; 460 461 case GL_LINEAR: 462 span->intTex[0] -= FIXED_HALF; 463 span->intTex[1] -= FIXED_HALF; 464 switch (info->format) { 465 case MESA_FORMAT_RGB888: 466 switch (info->envmode) { 467 case GL_MODULATE: 468 SPAN_LINEAR(LINEAR_RGB;MODULATE,3); 469 break; 470 case GL_DECAL: 471 case GL_REPLACE: 472 SPAN_LINEAR(LINEAR_RGB;REPLACE,3); 473 break; 474 case GL_BLEND: 475 SPAN_LINEAR(LINEAR_RGB;BLEND,3); 476 break; 477 case GL_ADD: 478 SPAN_LINEAR(LINEAR_RGB;ADD,3); 479 break; 480 default: 481 _mesa_problem(ctx, "bad tex env mode (3) in SPAN_LINEAR"); 482 return; 483 } 484 break; 485 case MESA_FORMAT_RGBA8888: 486 switch (info->envmode) { 487 case GL_MODULATE: 488 SPAN_LINEAR(LINEAR_RGBA;MODULATE,4); 489 break; 490 case GL_DECAL: 491 SPAN_LINEAR(LINEAR_RGBA;DECAL,4); 492 break; 493 case GL_BLEND: 494 SPAN_LINEAR(LINEAR_RGBA;BLEND,4); 495 break; 496 case GL_ADD: 497 SPAN_LINEAR(LINEAR_RGBA;ADD,4); 498 break; 499 case GL_REPLACE: 500 SPAN_LINEAR(LINEAR_RGBA;REPLACE,4); 501 break; 502 default: 503 _mesa_problem(ctx, "bad tex env mode (4) in SPAN_LINEAR"); 504 return; 505 } 506 break; 507 } 508 break; 509 } 510 span->interpMask &= ~SPAN_RGBA; 511 ASSERT(span->arrayMask & SPAN_RGBA); 512 513 _swrast_write_rgba_span(ctx, span); 514 515 /* re-enable texture units */ 516 ctx->Texture._EnabledCoordUnits = texEnableSave; 517 518#undef SPAN_NEAREST 519#undef SPAN_LINEAR 520} 521 522 523 524/* 525 * Render an RGB/RGBA textured triangle without perspective correction. 526 */ 527#define NAME affine_textured_triangle 528#define INTERP_Z 1 529#define INTERP_RGB 1 530#define INTERP_ALPHA 1 531#define INTERP_INT_TEX 1 532#define S_SCALE twidth 533#define T_SCALE theight 534 535#define SETUP_CODE \ 536 struct affine_info info; \ 537 struct gl_texture_unit *unit = ctx->Texture.Unit+0; \ 538 const struct gl_texture_object *obj = \ 539 ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ 540 const struct gl_texture_image *texImg = \ 541 obj->Image[0][obj->BaseLevel]; \ 542 const struct swrast_texture_image *swImg = \ 543 swrast_texture_image_const(texImg); \ 544 const GLfloat twidth = (GLfloat) texImg->Width; \ 545 const GLfloat theight = (GLfloat) texImg->Height; \ 546 info.texture = (const GLchan *) swImg->Map; \ 547 info.twidth_log2 = texImg->WidthLog2; \ 548 info.smask = texImg->Width - 1; \ 549 info.tmask = texImg->Height - 1; \ 550 info.format = texImg->TexFormat; \ 551 info.filter = obj->Sampler.MinFilter; \ 552 info.envmode = unit->EnvMode; \ 553 info.er = 0; \ 554 info.eg = 0; \ 555 info.eb = 0; \ 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 589struct 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 602static inline void 603fast_persp_span(struct gl_context *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 const struct swrast_texture_image *swImg = \ 812 swrast_texture_image_const(texImg); \ 813 info.texture = (const GLchan *) swImg->Map; \ 814 info.twidth_log2 = texImg->WidthLog2; \ 815 info.smask = texImg->Width - 1; \ 816 info.tmask = texImg->Height - 1; \ 817 info.format = texImg->TexFormat; \ 818 info.filter = obj->Sampler.MinFilter; \ 819 info.envmode = unit->EnvMode; \ 820 info.er = 0; \ 821 info.eg = 0; \ 822 info.eb = 0; \ 823 \ 824 if (info.envmode == GL_BLEND) { \ 825 /* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \ 826 info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF); \ 827 info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF); \ 828 info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF); \ 829 info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF); \ 830 } \ 831 if (!info.texture) { \ 832 /* this shouldn't happen */ \ 833 return; \ 834 } \ 835 \ 836 switch (info.format) { \ 837 case MESA_FORMAT_RGB888: \ 838 info.tbytesline = texImg->Width * 3; \ 839 break; \ 840 case MESA_FORMAT_RGBA8888: \ 841 info.tbytesline = texImg->Width * 4; \ 842 break; \ 843 default: \ 844 _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\ 845 return; \ 846 } \ 847 info.tsize = texImg->Height * info.tbytesline; 848 849#define RENDER_SPAN( span ) \ 850 span.interpMask &= ~SPAN_RGBA; \ 851 span.arrayMask |= SPAN_RGBA; \ 852 fast_persp_span(ctx, &span, &info); 853 854#include "s_tritemp.h" 855 856#endif /*CHAN_TYPE != GL_FLOAT*/ 857 858 859 860/* 861 * Render an RGBA triangle with arbitrary attributes. 862 */ 863#define NAME general_triangle 864#define INTERP_Z 1 865#define INTERP_RGB 1 866#define INTERP_ALPHA 1 867#define INTERP_ATTRIBS 1 868#define RENDER_SPAN( span ) _swrast_write_rgba_span(ctx, &span); 869#include "s_tritemp.h" 870 871 872 873 874/* 875 * Special tri function for occlusion testing 876 */ 877#define NAME occlusion_zless_16_triangle 878#define INTERP_Z 1 879#define SETUP_CODE \ 880 struct gl_renderbuffer *rb = \ 881 ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; \ 882 struct gl_query_object *q = ctx->Query.CurrentOcclusionObject; \ 883 ASSERT(ctx->Depth.Test); \ 884 ASSERT(!ctx->Depth.Mask); \ 885 ASSERT(ctx->Depth.Func == GL_LESS); \ 886 assert(rb->Format == MESA_FORMAT_Z16); \ 887 if (!q) { \ 888 return; \ 889 } 890#define RENDER_SPAN( span ) \ 891 { \ 892 GLuint i; \ 893 const GLushort *zRow = (const GLushort *) \ 894 _swrast_pixel_address(rb, span.x, span.y); \ 895 for (i = 0; i < span.end; i++) { \ 896 GLuint z = FixedToDepth(span.z); \ 897 if (z < zRow[i]) { \ 898 q->Result++; \ 899 } \ 900 span.z += span.zStep; \ 901 } \ 902 } 903#include "s_tritemp.h" 904 905 906 907static void 908nodraw_triangle( struct gl_context *ctx, 909 const SWvertex *v0, 910 const SWvertex *v1, 911 const SWvertex *v2 ) 912{ 913 (void) (ctx && v0 && v1 && v2); 914} 915 916 917/* 918 * This is used when separate specular color is enabled, but not 919 * texturing. We add the specular color to the primary color, 920 * draw the triangle, then restore the original primary color. 921 * Inefficient, but seldom needed. 922 */ 923void 924_swrast_add_spec_terms_triangle(struct gl_context *ctx, const SWvertex *v0, 925 const SWvertex *v1, const SWvertex *v2) 926{ 927 SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */ 928 SWvertex *ncv1 = (SWvertex *)v1; 929 SWvertex *ncv2 = (SWvertex *)v2; 930 GLfloat rSum, gSum, bSum; 931 GLchan cSave[3][4]; 932 933 /* save original colors */ 934 COPY_CHAN4( cSave[0], ncv0->color ); 935 COPY_CHAN4( cSave[1], ncv1->color ); 936 COPY_CHAN4( cSave[2], ncv2->color ); 937 /* sum v0 */ 938 rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0]; 939 gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1]; 940 bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2]; 941 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum); 942 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum); 943 UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum); 944 /* sum v1 */ 945 rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[FRAG_ATTRIB_COL1][0]; 946 gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[FRAG_ATTRIB_COL1][1]; 947 bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[FRAG_ATTRIB_COL1][2]; 948 UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[0], rSum); 949 UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[1], gSum); 950 UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[2], bSum); 951 /* sum v2 */ 952 rSum = CHAN_TO_FLOAT(ncv2->color[0]) + ncv2->attrib[FRAG_ATTRIB_COL1][0]; 953 gSum = CHAN_TO_FLOAT(ncv2->color[1]) + ncv2->attrib[FRAG_ATTRIB_COL1][1]; 954 bSum = CHAN_TO_FLOAT(ncv2->color[2]) + ncv2->attrib[FRAG_ATTRIB_COL1][2]; 955 UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[0], rSum); 956 UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[1], gSum); 957 UNCLAMPED_FLOAT_TO_CHAN(ncv2->color[2], bSum); 958 /* draw */ 959 SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 ); 960 /* restore original colors */ 961 COPY_CHAN4( ncv0->color, cSave[0] ); 962 COPY_CHAN4( ncv1->color, cSave[1] ); 963 COPY_CHAN4( ncv2->color, cSave[2] ); 964} 965 966 967 968#ifdef DEBUG 969 970/* record the current triangle function name */ 971const char *_mesa_triFuncName = NULL; 972 973#define USE(triFunc) \ 974do { \ 975 _mesa_triFuncName = #triFunc; \ 976 /*printf("%s\n", _mesa_triFuncName);*/ \ 977 swrast->Triangle = triFunc; \ 978} while (0) 979 980#else 981 982#define USE(triFunc) swrast->Triangle = triFunc; 983 984#endif 985 986 987 988 989/* 990 * Determine which triangle rendering function to use given the current 991 * rendering context. 992 * 993 * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or 994 * remove tests to this code. 995 */ 996void 997_swrast_choose_triangle( struct gl_context *ctx ) 998{ 999 SWcontext *swrast = SWRAST_CONTEXT(ctx); 1000 1001 if (ctx->Polygon.CullFlag && 1002 ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { 1003 USE(nodraw_triangle); 1004 return; 1005 } 1006 1007 if (ctx->RenderMode==GL_RENDER) { 1008 struct gl_renderbuffer *depthRb = 1009 ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; 1010 1011 if (ctx->Polygon.SmoothFlag) { 1012 _swrast_set_aa_triangle_function(ctx); 1013 ASSERT(swrast->Triangle); 1014 return; 1015 } 1016 1017 /* special case for occlusion testing */ 1018 if (ctx->Query.CurrentOcclusionObject && 1019 ctx->Depth.Test && 1020 ctx->Depth.Mask == GL_FALSE && 1021 ctx->Depth.Func == GL_LESS && 1022 !ctx->Stencil._Enabled && 1023 depthRb && 1024 depthRb->Format == MESA_FORMAT_Z16) { 1025 if (ctx->Color.ColorMask[0][0] == 0 && 1026 ctx->Color.ColorMask[0][1] == 0 && 1027 ctx->Color.ColorMask[0][2] == 0 && 1028 ctx->Color.ColorMask[0][3] == 0) { 1029 USE(occlusion_zless_16_triangle); 1030 return; 1031 } 1032 } 1033 1034 /* 1035 * XXX should examine swrast->_ActiveAttribMask to determine what 1036 * needs to be interpolated. 1037 */ 1038 if (ctx->Texture._EnabledCoordUnits || 1039 ctx->FragmentProgram._Current || 1040 ctx->ATIFragmentShader._Enabled || 1041 _mesa_need_secondary_color(ctx) || 1042 swrast->_FogEnabled) { 1043 /* Ugh, we do a _lot_ of tests to pick the best textured tri func */ 1044 const struct gl_texture_object *texObj2D; 1045 const struct gl_texture_image *texImg; 1046 const struct swrast_texture_image *swImg; 1047 GLenum minFilter, magFilter, envMode; 1048 gl_format format; 1049 texObj2D = ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; 1050 1051 texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL; 1052 swImg = swrast_texture_image_const(texImg); 1053 1054 format = texImg ? texImg->TexFormat : MESA_FORMAT_NONE; 1055 minFilter = texObj2D ? texObj2D->Sampler.MinFilter : GL_NONE; 1056 magFilter = texObj2D ? texObj2D->Sampler.MagFilter : GL_NONE; 1057 envMode = ctx->Texture.Unit[0].EnvMode; 1058 1059 /* First see if we can use an optimized 2-D texture function */ 1060 if (ctx->Texture._EnabledCoordUnits == 0x1 1061 && !ctx->FragmentProgram._Current 1062 && !ctx->ATIFragmentShader._Enabled 1063 && ctx->Texture._EnabledUnits == 0x1 1064 && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT 1065 && texObj2D->Sampler.WrapS == GL_REPEAT 1066 && texObj2D->Sampler.WrapT == GL_REPEAT 1067 && texObj2D->_Swizzle == SWIZZLE_NOOP 1068 && swImg->_IsPowerOfTwo 1069 && texImg->Border == 0 1070 && texImg->Width == swImg->RowStride 1071 && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888) 1072 && minFilter == magFilter 1073 && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR 1074 && !swrast->_FogEnabled 1075 && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT 1076 && ctx->Texture.Unit[0].EnvMode != GL_COMBINE4_NV) { 1077 if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) { 1078 if (minFilter == GL_NEAREST 1079 && format == MESA_FORMAT_RGB888 1080 && (envMode == GL_REPLACE || envMode == GL_DECAL) 1081 && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT) 1082 && ctx->Depth.Func == GL_LESS 1083 && ctx->Depth.Mask == GL_TRUE) 1084 || swrast->_RasterMask == TEXTURE_BIT) 1085 && ctx->Polygon.StippleFlag == GL_FALSE 1086 && ctx->DrawBuffer->Visual.depthBits <= 16) { 1087 if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) { 1088 USE(simple_z_textured_triangle); 1089 } 1090 else { 1091 USE(simple_textured_triangle); 1092 } 1093 } 1094 else { 1095#if CHAN_BITS != 8 1096 USE(general_triangle); 1097#else 1098 if (format == MESA_FORMAT_RGBA8888 && !_mesa_little_endian()) { 1099 /* We only handle RGBA8888 correctly on little endian 1100 * in the optimized code above. 1101 */ 1102 USE(general_triangle); 1103 } 1104 else { 1105 USE(affine_textured_triangle); 1106 } 1107#endif 1108 } 1109 } 1110 else { 1111#if CHAN_BITS != 8 1112 USE(general_triangle); 1113#else 1114 USE(persp_textured_triangle); 1115#endif 1116 } 1117 } 1118 else { 1119 /* general case textured triangles */ 1120 USE(general_triangle); 1121 } 1122 } 1123 else { 1124 ASSERT(!swrast->_FogEnabled); 1125 ASSERT(!_mesa_need_secondary_color(ctx)); 1126 if (ctx->Light.ShadeModel==GL_SMOOTH) { 1127 /* smooth shaded, no texturing, stippled or some raster ops */ 1128#if CHAN_BITS != 8 1129 USE(general_triangle); 1130#else 1131 USE(smooth_rgba_triangle); 1132#endif 1133 } 1134 else { 1135 /* flat shaded, no texturing, stippled or some raster ops */ 1136#if CHAN_BITS != 8 1137 USE(general_triangle); 1138#else 1139 USE(flat_rgba_triangle); 1140#endif 1141 } 1142 } 1143 } 1144 else if (ctx->RenderMode==GL_FEEDBACK) { 1145 USE(_swrast_feedback_triangle); 1146 } 1147 else { 1148 /* GL_SELECT mode */ 1149 USE(_swrast_select_triangle); 1150 } 1151} 1152