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