s_context.c revision f386f73f9e4054a750d453fa2f5449c2f1d2e242
1/* $Id: s_context.c,v 1.46 2003/03/14 15:41:00 brianp Exp $ */ 2 3/* 4 * Mesa 3-D graphics library 5 * Version: 5.1 6 * 7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the "Software"), 11 * to deal in the Software without restriction, including without limitation 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 * and/or sell copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Authors: 27 * Keith Whitwell <keith@tungstengraphics.com> 28 * Brian Paul 29 */ 30 31#include "imports.h" 32#include "context.h" 33#include "mtypes.h" 34#include "texobj.h" 35 36#include "swrast.h" 37#include "s_blend.h" 38#include "s_context.h" 39#include "s_lines.h" 40#include "s_points.h" 41#include "s_span.h" 42#include "s_triangle.h" 43#include "s_texture.h" 44 45 46/* 47 * Recompute the value of swrast->_RasterMask, etc. according to 48 * the current context. 49 */ 50static void 51_swrast_update_rasterflags( GLcontext *ctx ) 52{ 53 GLuint RasterMask = 0; 54 55 if (ctx->Color.AlphaEnabled) RasterMask |= ALPHATEST_BIT; 56 if (ctx->Color.BlendEnabled) RasterMask |= BLEND_BIT; 57 if (ctx->Depth.Test) RasterMask |= DEPTH_BIT; 58 if (ctx->Fog.Enabled) RasterMask |= FOG_BIT; 59 if (ctx->Scissor.Enabled) RasterMask |= CLIP_BIT; 60 if (ctx->Stencil.Enabled) RasterMask |= STENCIL_BIT; 61 if (ctx->Visual.rgbMode) { 62 const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); 63 if (colorMask != 0xffffffff) RasterMask |= MASKING_BIT; 64 if (ctx->Color.ColorLogicOpEnabled) RasterMask |= LOGIC_OP_BIT; 65 if (ctx->Texture._EnabledUnits) RasterMask |= TEXTURE_BIT; 66 } 67 else { 68 if (ctx->Color.IndexMask != 0xffffffff) RasterMask |= MASKING_BIT; 69 if (ctx->Color.IndexLogicOpEnabled) RasterMask |= LOGIC_OP_BIT; 70 } 71 72 if (ctx->DrawBuffer->UseSoftwareAlphaBuffers 73 && ctx->Color.ColorMask[ACOMP] 74 && ctx->Color.DrawBuffer != GL_NONE) 75 RasterMask |= ALPHABUF_BIT; 76 77 if ( ctx->Viewport.X < 0 78 || ctx->Viewport.X + ctx->Viewport.Width > (GLint) ctx->DrawBuffer->Width 79 || ctx->Viewport.Y < 0 80 || ctx->Viewport.Y + ctx->Viewport.Height > (GLint) ctx->DrawBuffer->Height) { 81 RasterMask |= CLIP_BIT; 82 } 83 84 if (ctx->Depth.OcclusionTest) 85 RasterMask |= OCCLUSION_BIT; 86 87 88 /* If we're not drawing to exactly one color buffer set the 89 * MULTI_DRAW_BIT flag. Also set it if we're drawing to no 90 * buffers or the RGBA or CI mask disables all writes. 91 */ 92 if (ctx->Color._DrawDestMask != FRONT_LEFT_BIT && 93 ctx->Color._DrawDestMask != BACK_LEFT_BIT && 94 ctx->Color._DrawDestMask != FRONT_RIGHT_BIT && 95 ctx->Color._DrawDestMask != BACK_RIGHT_BIT) { 96 /* more than one color buffer designated for writing (or zero buffers) */ 97 RasterMask |= MULTI_DRAW_BIT; 98 } 99 else if (ctx->Visual.rgbMode && *((GLuint *) ctx->Color.ColorMask) == 0) { 100 RasterMask |= MULTI_DRAW_BIT; /* all RGBA channels disabled */ 101 } 102 else if (!ctx->Visual.rgbMode && ctx->Color.IndexMask==0) { 103 RasterMask |= MULTI_DRAW_BIT; /* all color index bits disabled */ 104 } 105 106 SWRAST_CONTEXT(ctx)->_RasterMask = RasterMask; 107} 108 109 110static void 111_swrast_update_polygon( GLcontext *ctx ) 112{ 113 GLfloat backface_sign = 1; 114 115 if (ctx->Polygon.CullFlag) { 116 backface_sign = 1; 117 switch(ctx->Polygon.CullFaceMode) { 118 case GL_BACK: 119 if(ctx->Polygon.FrontFace==GL_CCW) 120 backface_sign = -1; 121 break; 122 case GL_FRONT: 123 if(ctx->Polygon.FrontFace!=GL_CCW) 124 backface_sign = -1; 125 break; 126 default: 127 case GL_FRONT_AND_BACK: 128 backface_sign = 0; 129 break; 130 } 131 } 132 else { 133 backface_sign = 0; 134 } 135 136 SWRAST_CONTEXT(ctx)->_backface_sign = backface_sign; 137} 138 139 140static void 141_swrast_update_hint( GLcontext *ctx ) 142{ 143 SWcontext *swrast = SWRAST_CONTEXT(ctx); 144 swrast->_PreferPixelFog = (!swrast->AllowVertexFog || 145 (ctx->Hint.Fog == GL_NICEST && 146 swrast->AllowPixelFog)); 147} 148 149 150/* 151 * Update the swrast->_AnyTextureCombine flag. 152 */ 153static void 154_swrast_update_texture_env( GLcontext *ctx ) 155{ 156 SWcontext *swrast = SWRAST_CONTEXT(ctx); 157 GLuint i; 158 swrast->_AnyTextureCombine = GL_FALSE; 159 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) { 160 if (ctx->Texture.Unit[i].EnvMode == GL_COMBINE_EXT || 161 ctx->Texture.Unit[i].EnvMode == GL_COMBINE4_NV) { 162 swrast->_AnyTextureCombine = GL_TRUE; 163 return; 164 } 165 } 166} 167 168 169#define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \ 170 _NEW_TEXTURE | \ 171 _NEW_HINT | \ 172 _NEW_POLYGON ) 173 174/* State referenced by _swrast_choose_triangle, _swrast_choose_line. 175 */ 176#define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \ 177 _NEW_RENDERMODE| \ 178 _NEW_POLYGON| \ 179 _NEW_DEPTH| \ 180 _NEW_STENCIL| \ 181 _NEW_COLOR| \ 182 _NEW_TEXTURE| \ 183 _SWRAST_NEW_RASTERMASK| \ 184 _NEW_LIGHT| \ 185 _NEW_FOG | \ 186 _DD_NEW_SEPARATE_SPECULAR) 187 188#define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \ 189 _NEW_RENDERMODE| \ 190 _NEW_LINE| \ 191 _NEW_TEXTURE| \ 192 _NEW_LIGHT| \ 193 _NEW_FOG| \ 194 _NEW_DEPTH | \ 195 _DD_NEW_SEPARATE_SPECULAR) 196 197#define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \ 198 _NEW_RENDERMODE | \ 199 _NEW_POINT | \ 200 _NEW_TEXTURE | \ 201 _NEW_LIGHT | \ 202 _NEW_FOG | \ 203 _DD_NEW_SEPARATE_SPECULAR) 204 205#define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE 206 207#define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE 208 209#define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR 210 211 212 213/* Stub for swrast->Triangle to select a true triangle function 214 * after a state change. 215 */ 216static void 217_swrast_validate_triangle( GLcontext *ctx, 218 const SWvertex *v0, 219 const SWvertex *v1, 220 const SWvertex *v2 ) 221{ 222 SWcontext *swrast = SWRAST_CONTEXT(ctx); 223 224 _swrast_validate_derived( ctx ); 225 swrast->choose_triangle( ctx ); 226 227 if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) && 228 ctx->Texture._EnabledUnits == 0) { 229 swrast->SpecTriangle = swrast->Triangle; 230 swrast->Triangle = _swrast_add_spec_terms_triangle; 231 } 232 233 swrast->Triangle( ctx, v0, v1, v2 ); 234} 235 236static void 237_swrast_validate_line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) 238{ 239 SWcontext *swrast = SWRAST_CONTEXT(ctx); 240 241 _swrast_validate_derived( ctx ); 242 swrast->choose_line( ctx ); 243 244 if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) && 245 ctx->Texture._EnabledUnits == 0) { 246 swrast->SpecLine = swrast->Line; 247 swrast->Line = _swrast_add_spec_terms_line; 248 } 249 250 251 swrast->Line( ctx, v0, v1 ); 252} 253 254static void 255_swrast_validate_point( GLcontext *ctx, const SWvertex *v0 ) 256{ 257 SWcontext *swrast = SWRAST_CONTEXT(ctx); 258 259 _swrast_validate_derived( ctx ); 260 swrast->choose_point( ctx ); 261 262 if ((ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) && 263 ctx->Texture._EnabledUnits == 0) { 264 swrast->SpecPoint = swrast->Point; 265 swrast->Point = _swrast_add_spec_terms_point; 266 } 267 268 swrast->Point( ctx, v0 ); 269} 270 271 272static void 273_swrast_validate_blend_func( GLcontext *ctx, GLuint n, 274 const GLubyte mask[], 275 GLchan src[][4], 276 CONST GLchan dst[][4] ) 277{ 278 SWcontext *swrast = SWRAST_CONTEXT(ctx); 279 280 _swrast_validate_derived( ctx ); 281 _swrast_choose_blend_func( ctx ); 282 283 swrast->BlendFunc( ctx, n, mask, src, dst ); 284} 285 286 287static void 288_swrast_validate_texture_sample( GLcontext *ctx, GLuint texUnit, 289 const struct gl_texture_object *tObj, 290 GLuint n, const GLfloat texcoords[][4], 291 const GLfloat lambda[], GLchan rgba[][4] ) 292{ 293 SWcontext *swrast = SWRAST_CONTEXT(ctx); 294 295 _swrast_validate_derived( ctx ); 296 297 /* Compute min/mag filter threshold */ 298 if (tObj->MinFilter != tObj->MagFilter) { 299 if (tObj->MagFilter == GL_LINEAR 300 && (tObj->MinFilter == GL_NEAREST_MIPMAP_NEAREST || 301 tObj->MinFilter == GL_NEAREST_MIPMAP_LINEAR)) { 302 swrast->_MinMagThresh[texUnit] = 0.5F; 303 } 304 else { 305 swrast->_MinMagThresh[texUnit] = 0.0F; 306 } 307 } 308 309 if (ctx->FragmentProgram.Enabled) { 310 ASSERT(ctx->FragmentProgram.Current); 311 /* only one target can be referenced per unit per fragment program */ 312 switch (ctx->FragmentProgram.Current->TexturesUsed[texUnit]) { 313 case TEXTURE_1D_BIT: 314 tObj = ctx->Texture.Unit[texUnit].Current1D; 315 break; 316 case TEXTURE_2D_BIT: 317 tObj = ctx->Texture.Unit[texUnit].Current2D; 318 break; 319 case TEXTURE_3D_BIT: 320 tObj = ctx->Texture.Unit[texUnit].Current3D; 321 break; 322 case TEXTURE_CUBE_BIT: 323 tObj = ctx->Texture.Unit[texUnit].CurrentCubeMap; 324 break; 325 case TEXTURE_RECT_BIT: 326 tObj = ctx->Texture.Unit[texUnit].CurrentRect; 327 break; 328 default: 329 _mesa_problem(ctx, "Bad texture in _swrast_validate_texture_sample"); 330 return; 331 } 332 if (!tObj->Complete) { 333 _mesa_test_texobj_completeness(ctx, 334 (struct gl_texture_object *) tObj ); 335 } 336 } 337 338 swrast->TextureSample[texUnit] = 339 _swrast_choose_texture_sample_func( ctx, tObj ); 340 341 swrast->TextureSample[texUnit]( ctx, texUnit, tObj, n, texcoords, 342 lambda, rgba ); 343 344 /* GL_SGI_texture_color_table */ 345 if (ctx->Texture.Unit[texUnit].ColorTableEnabled) { 346 _swrast_texture_table_lookup(&ctx->Texture.Unit[texUnit].ColorTable, n, rgba); 347 } 348} 349 350 351static void 352_swrast_sleep( GLcontext *ctx, GLuint new_state ) 353{ 354} 355 356 357static void 358_swrast_invalidate_state( GLcontext *ctx, GLuint new_state ) 359{ 360 SWcontext *swrast = SWRAST_CONTEXT(ctx); 361 GLuint i; 362 363 swrast->NewState |= new_state; 364 365 /* After 10 statechanges without any swrast functions being called, 366 * put the module to sleep. 367 */ 368 if (++swrast->StateChanges > 10) { 369 swrast->InvalidateState = _swrast_sleep; 370 swrast->NewState = ~0; 371 new_state = ~0; 372 } 373 374 if (new_state & swrast->invalidate_triangle) 375 swrast->Triangle = _swrast_validate_triangle; 376 377 if (new_state & swrast->invalidate_line) 378 swrast->Line = _swrast_validate_line; 379 380 if (new_state & swrast->invalidate_point) 381 swrast->Point = _swrast_validate_point; 382 383 if (new_state & _SWRAST_NEW_BLEND_FUNC) 384 swrast->BlendFunc = _swrast_validate_blend_func; 385 386 if (new_state & _SWRAST_NEW_TEXTURE_SAMPLE_FUNC) 387 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) 388 swrast->TextureSample[i] = _swrast_validate_texture_sample; 389 390 if (ctx->Visual.rgbMode) { 391 ASSERT(swrast->Driver.WriteRGBASpan); 392 ASSERT(swrast->Driver.WriteRGBSpan); 393 ASSERT(swrast->Driver.WriteMonoRGBASpan); 394 ASSERT(swrast->Driver.WriteRGBAPixels); 395 ASSERT(swrast->Driver.WriteMonoRGBAPixels); 396 ASSERT(swrast->Driver.ReadRGBASpan); 397 ASSERT(swrast->Driver.ReadRGBAPixels); 398 } 399 else { 400 ASSERT(swrast->Driver.WriteCI32Span); 401 ASSERT(swrast->Driver.WriteCI8Span); 402 ASSERT(swrast->Driver.WriteMonoCISpan); 403 ASSERT(swrast->Driver.WriteCI32Pixels); 404 ASSERT(swrast->Driver.WriteMonoCIPixels); 405 ASSERT(swrast->Driver.ReadCI32Span); 406 ASSERT(swrast->Driver.ReadCI32Pixels); 407 } 408} 409 410 411void 412_swrast_validate_derived( GLcontext *ctx ) 413{ 414 SWcontext *swrast = SWRAST_CONTEXT(ctx); 415 416 if (swrast->NewState) { 417 if (swrast->NewState & _SWRAST_NEW_RASTERMASK) 418 _swrast_update_rasterflags( ctx ); 419 420 if (swrast->NewState & _NEW_POLYGON) 421 _swrast_update_polygon( ctx ); 422 423 if (swrast->NewState & _NEW_HINT) 424 _swrast_update_hint( ctx ); 425 426 if (swrast->NewState & _SWRAST_NEW_TEXTURE_ENV_MODE) 427 _swrast_update_texture_env( ctx ); 428 429 swrast->NewState = 0; 430 swrast->StateChanges = 0; 431 swrast->InvalidateState = _swrast_invalidate_state; 432 } 433} 434 435#define SWRAST_DEBUG 0 436 437/* Public entrypoints: See also s_accum.c, s_bitmap.c, etc. 438 */ 439void 440_swrast_Quad( GLcontext *ctx, 441 const SWvertex *v0, const SWvertex *v1, 442 const SWvertex *v2, const SWvertex *v3 ) 443{ 444 if (SWRAST_DEBUG) { 445 _mesa_debug(ctx, "_swrast_Quad\n"); 446 _swrast_print_vertex( ctx, v0 ); 447 _swrast_print_vertex( ctx, v1 ); 448 _swrast_print_vertex( ctx, v2 ); 449 _swrast_print_vertex( ctx, v3 ); 450 } 451 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v3 ); 452 SWRAST_CONTEXT(ctx)->Triangle( ctx, v1, v2, v3 ); 453} 454 455void 456_swrast_Triangle( GLcontext *ctx, const SWvertex *v0, 457 const SWvertex *v1, const SWvertex *v2 ) 458{ 459 if (SWRAST_DEBUG) { 460 _mesa_debug(ctx, "_swrast_Triangle\n"); 461 _swrast_print_vertex( ctx, v0 ); 462 _swrast_print_vertex( ctx, v1 ); 463 _swrast_print_vertex( ctx, v2 ); 464 } 465 SWRAST_CONTEXT(ctx)->Triangle( ctx, v0, v1, v2 ); 466} 467 468void 469_swrast_Line( GLcontext *ctx, const SWvertex *v0, const SWvertex *v1 ) 470{ 471 if (SWRAST_DEBUG) { 472 _mesa_debug(ctx, "_swrast_Line\n"); 473 _swrast_print_vertex( ctx, v0 ); 474 _swrast_print_vertex( ctx, v1 ); 475 } 476 SWRAST_CONTEXT(ctx)->Line( ctx, v0, v1 ); 477} 478 479void 480_swrast_Point( GLcontext *ctx, const SWvertex *v0 ) 481{ 482 if (SWRAST_DEBUG) { 483 _mesa_debug(ctx, "_swrast_Point\n"); 484 _swrast_print_vertex( ctx, v0 ); 485 } 486 SWRAST_CONTEXT(ctx)->Point( ctx, v0 ); 487} 488 489void 490_swrast_InvalidateState( GLcontext *ctx, GLuint new_state ) 491{ 492 if (SWRAST_DEBUG) { 493 _mesa_debug(ctx, "_swrast_InvalidateState\n"); 494 } 495 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, new_state ); 496} 497 498void 499_swrast_ResetLineStipple( GLcontext *ctx ) 500{ 501 if (SWRAST_DEBUG) { 502 _mesa_debug(ctx, "_swrast_ResetLineStipple\n"); 503 } 504 SWRAST_CONTEXT(ctx)->StippleCounter = 0; 505} 506 507void 508_swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ) 509{ 510 if (SWRAST_DEBUG) { 511 _mesa_debug(ctx, "_swrast_allow_vertex_fog %d\n", value); 512 } 513 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); 514 SWRAST_CONTEXT(ctx)->AllowVertexFog = value; 515} 516 517void 518_swrast_allow_pixel_fog( GLcontext *ctx, GLboolean value ) 519{ 520 if (SWRAST_DEBUG) { 521 _mesa_debug(ctx, "_swrast_allow_pixel_fog %d\n", value); 522 } 523 SWRAST_CONTEXT(ctx)->InvalidateState( ctx, _NEW_HINT ); 524 SWRAST_CONTEXT(ctx)->AllowPixelFog = value; 525} 526 527 528GLboolean 529_swrast_CreateContext( GLcontext *ctx ) 530{ 531 GLuint i; 532 SWcontext *swrast = (SWcontext *)CALLOC(sizeof(SWcontext)); 533 534 if (SWRAST_DEBUG) { 535 _mesa_debug(ctx, "_swrast_CreateContext\n"); 536 } 537 538 if (!swrast) 539 return GL_FALSE; 540 541 swrast->NewState = ~0; 542 543 swrast->choose_point = _swrast_choose_point; 544 swrast->choose_line = _swrast_choose_line; 545 swrast->choose_triangle = _swrast_choose_triangle; 546 547 swrast->invalidate_point = _SWRAST_NEW_POINT; 548 swrast->invalidate_line = _SWRAST_NEW_LINE; 549 swrast->invalidate_triangle = _SWRAST_NEW_TRIANGLE; 550 551 swrast->Point = _swrast_validate_point; 552 swrast->Line = _swrast_validate_line; 553 swrast->Triangle = _swrast_validate_triangle; 554 swrast->InvalidateState = _swrast_sleep; 555 swrast->BlendFunc = _swrast_validate_blend_func; 556 557 swrast->AllowVertexFog = GL_TRUE; 558 swrast->AllowPixelFog = GL_TRUE; 559 560 if (ctx->Visual.doubleBufferMode) 561 swrast->CurrentBuffer = BACK_LEFT_BIT; 562 else 563 swrast->CurrentBuffer = FRONT_LEFT_BIT; 564 565 /* Optimized Accum buffer */ 566 swrast->_IntegerAccumMode = GL_TRUE; 567 swrast->_IntegerAccumScaler = 0.0; 568 569 for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) 570 swrast->TextureSample[i] = _swrast_validate_texture_sample; 571 572 swrast->SpanArrays = MALLOC_STRUCT(span_arrays); 573 if (!swrast->SpanArrays) { 574 FREE(swrast); 575 return GL_FALSE; 576 } 577 578 /* init point span buffer */ 579 swrast->PointSpan.primitive = GL_POINT; 580 swrast->PointSpan.start = 0; 581 swrast->PointSpan.end = 0; 582 swrast->PointSpan.facing = 0; 583 swrast->PointSpan.array = swrast->SpanArrays; 584 585 assert(ctx->Const.MaxTextureUnits > 0); 586 assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_UNITS); 587 588 swrast->TexelBuffer = (GLchan *) MALLOC(ctx->Const.MaxTextureUnits * 589 MAX_WIDTH * 4 * sizeof(GLchan)); 590 if (!swrast->TexelBuffer) { 591 FREE(swrast->SpanArrays); 592 FREE(swrast); 593 return GL_FALSE; 594 } 595 596 ctx->swrast_context = swrast; 597 598 return GL_TRUE; 599} 600 601void 602_swrast_DestroyContext( GLcontext *ctx ) 603{ 604 SWcontext *swrast = SWRAST_CONTEXT(ctx); 605 606 if (SWRAST_DEBUG) { 607 _mesa_debug(ctx, "_swrast_DestroyContext\n"); 608 } 609 610 FREE( swrast->SpanArrays ); 611 FREE( swrast->TexelBuffer ); 612 FREE( swrast ); 613 614 ctx->swrast_context = 0; 615} 616 617 618struct swrast_device_driver * 619_swrast_GetDeviceDriverReference( GLcontext *ctx ) 620{ 621 SWcontext *swrast = SWRAST_CONTEXT(ctx); 622 return &swrast->Driver; 623} 624 625void 626_swrast_flush( GLcontext *ctx ) 627{ 628 SWcontext *swrast = SWRAST_CONTEXT(ctx); 629 /* flush any pending fragments from rendering points */ 630 if (swrast->PointSpan.end > 0) { 631 if (ctx->Visual.rgbMode) { 632 if (ctx->Texture._EnabledUnits) 633 _mesa_write_texture_span(ctx, &(swrast->PointSpan)); 634 else 635 _mesa_write_rgba_span(ctx, &(swrast->PointSpan)); 636 } 637 else { 638 _mesa_write_index_span(ctx, &(swrast->PointSpan)); 639 } 640 swrast->PointSpan.end = 0; 641 } 642} 643 644void 645_swrast_render_primitive( GLcontext *ctx, GLenum prim ) 646{ 647 SWcontext *swrast = SWRAST_CONTEXT(ctx); 648 if (swrast->Primitive == GL_POINTS && prim != GL_POINTS) { 649 _swrast_flush(ctx); 650 } 651 swrast->Primitive = prim; 652} 653 654 655void 656_swrast_render_start( GLcontext *ctx ) 657{ 658 SWcontext *swrast = SWRAST_CONTEXT(ctx); 659 if (swrast->Driver.SpanRenderStart) 660 swrast->Driver.SpanRenderStart( ctx ); 661 swrast->PointSpan.end = 0; 662} 663 664void 665_swrast_render_finish( GLcontext *ctx ) 666{ 667 SWcontext *swrast = SWRAST_CONTEXT(ctx); 668 if (swrast->Driver.SpanRenderFinish) 669 swrast->Driver.SpanRenderFinish( ctx ); 670 671 _swrast_flush(ctx); 672} 673 674 675#define SWRAST_DEBUG_VERTICES 0 676 677void 678_swrast_print_vertex( GLcontext *ctx, const SWvertex *v ) 679{ 680 GLuint i; 681 682 if (SWRAST_DEBUG_VERTICES) { 683 _mesa_debug(ctx, "win %f %f %f %f\n", 684 v->win[0], v->win[1], v->win[2], v->win[3]); 685 686 for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) 687 if (ctx->Texture.Unit[i]._ReallyEnabled) 688 _mesa_debug(ctx, "texcoord[%d] %f %f %f %f\n", i, 689 v->texcoord[i][0], v->texcoord[i][1], 690 v->texcoord[i][2], v->texcoord[i][3]); 691 692#if CHAN_TYPE == GL_FLOAT 693 _mesa_debug(ctx, "color %f %f %f %f\n", 694 v->color[0], v->color[1], v->color[2], v->color[3]); 695 _mesa_debug(ctx, "spec %f %f %f %f\n", 696 v->specular[0], v->specular[1], 697 v->specular[2], v->specular[3]); 698#else 699 _mesa_debug(ctx, "color %d %d %d %d\n", 700 v->color[0], v->color[1], v->color[2], v->color[3]); 701 _mesa_debug(ctx, "spec %d %d %d %d\n", 702 v->specular[0], v->specular[1], 703 v->specular[2], v->specular[3]); 704#endif 705 _mesa_debug(ctx, "fog %f\n", v->fog); 706 _mesa_debug(ctx, "index %d\n", v->index); 707 _mesa_debug(ctx, "pointsize %f\n", v->pointSize); 708 _mesa_debug(ctx, "\n"); 709 } 710} 711