state.c revision 7cb87dffce2c7a37f960f3a865cf92fd193dd8c5
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.3 4 * 5 * Copyright (C) 1999-2008 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 * \file state.c 28 * State management. 29 * 30 * This file manages recalculation of derived values in struct gl_context. 31 */ 32 33 34#include "glheader.h" 35#include "mtypes.h" 36#include "context.h" 37#include "debug.h" 38#include "macros.h" 39#include "ffvertex_prog.h" 40#include "framebuffer.h" 41#include "light.h" 42#include "matrix.h" 43#include "pixel.h" 44#include "program/program.h" 45#include "program/prog_parameter.h" 46#include "state.h" 47#include "stencil.h" 48#include "texenvprogram.h" 49#include "texobj.h" 50#include "texstate.h" 51 52 53static void 54update_separate_specular(struct gl_context *ctx) 55{ 56 if (_mesa_need_secondary_color(ctx)) 57 ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR; 58 else 59 ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR; 60} 61 62 63/** 64 * Compute the index of the last array element that can be safely accessed 65 * in a vertex array. We can really only do this when the array lives in 66 * a VBO. 67 * The array->_MaxElement field will be updated. 68 * Later in glDrawArrays/Elements/etc we can do some bounds checking. 69 */ 70static void 71compute_max_element(struct gl_client_array *array) 72{ 73 assert(array->Enabled); 74 if (array->BufferObj->Name) { 75 GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr; 76 GLsizeiptrARB obj_size = (GLsizeiptrARB) array->BufferObj->Size; 77 78 if (offset < obj_size) { 79 array->_MaxElement = (obj_size - offset + 80 array->StrideB - 81 array->_ElementSize) / array->StrideB; 82 } else { 83 array->_MaxElement = 0; 84 } 85 } 86 else { 87 /* user-space array, no idea how big it is */ 88 array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */ 89 } 90} 91 92 93/** 94 * Helper for update_arrays(). 95 * \return min(current min, array->_MaxElement). 96 */ 97static GLuint 98update_min(GLuint min, struct gl_client_array *array) 99{ 100 compute_max_element(array); 101 return MIN2(min, array->_MaxElement); 102} 103 104 105/** 106 * Update ctx->Array._MaxElement (the max legal index into all enabled arrays). 107 * Need to do this upon new array state or new buffer object state. 108 */ 109static void 110update_arrays( struct gl_context *ctx ) 111{ 112 struct gl_array_object *arrayObj = ctx->Array.ArrayObj; 113 GLuint i, min = ~0; 114 115 /* find min of _MaxElement values for all enabled arrays */ 116 117 /* 0 */ 118 if (ctx->VertexProgram._Current 119 && arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) { 120 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]); 121 } 122 else if (arrayObj->Vertex.Enabled) { 123 min = update_min(min, &arrayObj->Vertex); 124 } 125 126 /* 1 */ 127 if (ctx->VertexProgram._Enabled 128 && arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT].Enabled) { 129 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT]); 130 } 131 /* no conventional vertex weight array */ 132 133 /* 2 */ 134 if (ctx->VertexProgram._Enabled 135 && arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) { 136 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]); 137 } 138 else if (arrayObj->Normal.Enabled) { 139 min = update_min(min, &arrayObj->Normal); 140 } 141 142 /* 3 */ 143 if (ctx->VertexProgram._Enabled 144 && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) { 145 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]); 146 } 147 else if (arrayObj->Color.Enabled) { 148 min = update_min(min, &arrayObj->Color); 149 } 150 151 /* 4 */ 152 if (ctx->VertexProgram._Enabled 153 && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) { 154 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR1]); 155 } 156 else if (arrayObj->SecondaryColor.Enabled) { 157 min = update_min(min, &arrayObj->SecondaryColor); 158 } 159 160 /* 5 */ 161 if (ctx->VertexProgram._Enabled 162 && arrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) { 163 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_FOG]); 164 } 165 else if (arrayObj->FogCoord.Enabled) { 166 min = update_min(min, &arrayObj->FogCoord); 167 } 168 169 /* 6 */ 170 if (ctx->VertexProgram._Enabled 171 && arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) { 172 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX]); 173 } 174 else if (arrayObj->Index.Enabled) { 175 min = update_min(min, &arrayObj->Index); 176 } 177 178 /* 7 */ 179 if (ctx->VertexProgram._Enabled 180 && arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) { 181 min = update_min(min, &arrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG]); 182 } 183 184 /* 8..15 */ 185 for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) { 186 if (ctx->VertexProgram._Enabled 187 && arrayObj->VertexAttrib[i].Enabled) { 188 min = update_min(min, &arrayObj->VertexAttrib[i]); 189 } 190 else if (i - VERT_ATTRIB_TEX0 < ctx->Const.MaxTextureCoordUnits 191 && arrayObj->TexCoord[i - VERT_ATTRIB_TEX0].Enabled) { 192 min = update_min(min, &arrayObj->TexCoord[i - VERT_ATTRIB_TEX0]); 193 } 194 } 195 196 /* 16..31 */ 197 if (ctx->VertexProgram._Current) { 198 for (i = 0; i < Elements(arrayObj->VertexAttrib); i++) { 199 if (arrayObj->VertexAttrib[i].Enabled) { 200 min = update_min(min, &arrayObj->VertexAttrib[i]); 201 } 202 } 203 } 204 205 if (arrayObj->EdgeFlag.Enabled) { 206 min = update_min(min, &arrayObj->EdgeFlag); 207 } 208 209 /* _MaxElement is one past the last legal array element */ 210 arrayObj->_MaxElement = min; 211} 212 213 214/** 215 * Update the following fields: 216 * ctx->VertexProgram._Enabled 217 * ctx->FragmentProgram._Enabled 218 * ctx->ATIFragmentShader._Enabled 219 * This needs to be done before texture state validation. 220 */ 221static void 222update_program_enables(struct gl_context *ctx) 223{ 224 /* These _Enabled flags indicate if the program is enabled AND valid. */ 225 ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled 226 && ctx->VertexProgram.Current->Base.Instructions; 227 ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled 228 && ctx->FragmentProgram.Current->Base.Instructions; 229 ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled 230 && ctx->ATIFragmentShader.Current->Instructions[0]; 231} 232 233 234/** 235 * Update vertex/fragment program state. In particular, update these fields: 236 * ctx->VertexProgram._Current 237 * ctx->VertexProgram._TnlProgram, 238 * These point to the highest priority enabled vertex/fragment program or are 239 * NULL if fixed-function processing is to be done. 240 * 241 * This function needs to be called after texture state validation in case 242 * we're generating a fragment program from fixed-function texture state. 243 * 244 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex 245 * or fragment program is being used. 246 */ 247static GLbitfield 248update_program(struct gl_context *ctx) 249{ 250 const struct gl_shader_program *vsProg = ctx->Shader.CurrentVertexProgram; 251 const struct gl_shader_program *gsProg = ctx->Shader.CurrentGeometryProgram; 252 const struct gl_shader_program *fsProg = ctx->Shader.CurrentFragmentProgram; 253 const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current; 254 const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current; 255 const struct gl_geometry_program *prevGP = ctx->GeometryProgram._Current; 256 GLbitfield new_state = 0x0; 257 258 /* 259 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current 260 * pointers to the programs that should be used for rendering. If either 261 * is NULL, use fixed-function code paths. 262 * 263 * These programs may come from several sources. The priority is as 264 * follows: 265 * 1. OpenGL 2.0/ARB vertex/fragment shaders 266 * 2. ARB/NV vertex/fragment programs 267 * 3. Programs derived from fixed-function state. 268 * 269 * Note: it's possible for a vertex shader to get used with a fragment 270 * program (and vice versa) here, but in practice that shouldn't ever 271 * come up, or matter. 272 */ 273 274 if (fsProg && fsProg->LinkStatus && fsProg->FragmentProgram) { 275 /* Use shader programs */ 276 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, 277 fsProg->FragmentProgram); 278 } 279 else if (ctx->FragmentProgram._Enabled) { 280 /* use user-defined fragment program */ 281 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, 282 ctx->FragmentProgram.Current); 283 } 284 else if (ctx->FragmentProgram._MaintainTexEnvProgram) { 285 /* Use fragment program generated from fixed-function state. 286 */ 287 struct gl_shader_program *f = _mesa_get_fixed_func_fragment_program(ctx); 288#if 0 289 _mesa_reference_shader_program(ctx, 290 &ctx->Shader.CurrentFragmentProgram, f); 291#endif 292 293 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, 294 f->FragmentProgram); 295 } 296 else { 297 /* no fragment program */ 298 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL); 299 } 300 301 if (gsProg && gsProg->LinkStatus && gsProg->GeometryProgram) { 302 /* Use shader programs */ 303 _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, 304 gsProg->GeometryProgram); 305 } else { 306 /* no fragment program */ 307 _mesa_reference_geomprog(ctx, &ctx->GeometryProgram._Current, NULL); 308 } 309 310 /* Examine vertex program after fragment program as 311 * _mesa_get_fixed_func_vertex_program() needs to know active 312 * fragprog inputs. 313 */ 314 if (vsProg && vsProg->LinkStatus && vsProg->VertexProgram) { 315 /* Use shader programs */ 316 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, 317 vsProg->VertexProgram); 318 } 319 else if (ctx->VertexProgram._Enabled) { 320 /* use user-defined vertex program */ 321 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, 322 ctx->VertexProgram.Current); 323 } 324 else if (ctx->VertexProgram._MaintainTnlProgram) { 325 /* Use vertex program generated from fixed-function state. 326 */ 327 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, 328 _mesa_get_fixed_func_vertex_program(ctx)); 329 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, 330 ctx->VertexProgram._Current); 331 } 332 else { 333 /* no vertex program */ 334 _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL); 335 } 336 337 /* Let the driver know what's happening: 338 */ 339 if (ctx->FragmentProgram._Current != prevFP) { 340 new_state |= _NEW_PROGRAM; 341 if (ctx->Driver.BindProgram) { 342 ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 343 (struct gl_program *) ctx->FragmentProgram._Current); 344 } 345 } 346 347 if (ctx->GeometryProgram._Current != prevGP) { 348 new_state |= _NEW_PROGRAM; 349 if (ctx->Driver.BindProgram) { 350 ctx->Driver.BindProgram(ctx, MESA_GEOMETRY_PROGRAM, 351 (struct gl_program *) ctx->GeometryProgram._Current); 352 } 353 } 354 355 if (ctx->VertexProgram._Current != prevVP) { 356 new_state |= _NEW_PROGRAM; 357 if (ctx->Driver.BindProgram) { 358 ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, 359 (struct gl_program *) ctx->VertexProgram._Current); 360 } 361 } 362 363 return new_state; 364} 365 366 367/** 368 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0. 369 */ 370static GLbitfield 371update_program_constants(struct gl_context *ctx) 372{ 373 GLbitfield new_state = 0x0; 374 375 if (ctx->FragmentProgram._Current) { 376 const struct gl_program_parameter_list *params = 377 ctx->FragmentProgram._Current->Base.Parameters; 378 if (params && params->StateFlags & ctx->NewState) { 379 new_state |= _NEW_PROGRAM_CONSTANTS; 380 } 381 } 382 383 if (ctx->GeometryProgram._Current) { 384 const struct gl_program_parameter_list *params = 385 ctx->GeometryProgram._Current->Base.Parameters; 386 /*FIXME: StateFlags is always 0 because we have unnamed constant 387 * not state changes */ 388 if (params /*&& params->StateFlags & ctx->NewState*/) { 389 new_state |= _NEW_PROGRAM_CONSTANTS; 390 } 391 } 392 393 if (ctx->VertexProgram._Current) { 394 const struct gl_program_parameter_list *params = 395 ctx->VertexProgram._Current->Base.Parameters; 396 if (params && params->StateFlags & ctx->NewState) { 397 new_state |= _NEW_PROGRAM_CONSTANTS; 398 } 399 } 400 401 return new_state; 402} 403 404 405 406 407static void 408update_viewport_matrix(struct gl_context *ctx) 409{ 410 const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF; 411 412 ASSERT(depthMax > 0); 413 414 /* Compute scale and bias values. This is really driver-specific 415 * and should be maintained elsewhere if at all. 416 * NOTE: RasterPos uses this. 417 */ 418 _math_matrix_viewport(&ctx->Viewport._WindowMap, 419 ctx->Viewport.X, ctx->Viewport.Y, 420 ctx->Viewport.Width, ctx->Viewport.Height, 421 ctx->Viewport.Near, ctx->Viewport.Far, 422 depthMax); 423} 424 425 426/** 427 * Update derived multisample state. 428 */ 429static void 430update_multisample(struct gl_context *ctx) 431{ 432 ctx->Multisample._Enabled = GL_FALSE; 433 if (ctx->Multisample.Enabled && 434 ctx->DrawBuffer && 435 ctx->DrawBuffer->Visual.sampleBuffers) 436 ctx->Multisample._Enabled = GL_TRUE; 437} 438 439 440/** 441 * Update derived color/blend/logicop state. 442 */ 443static void 444update_color(struct gl_context *ctx) 445{ 446 /* This is needed to support 1.1's RGB logic ops AND 447 * 1.0's blending logicops. 448 */ 449 ctx->Color._LogicOpEnabled = _mesa_rgba_logicop_enabled(ctx); 450} 451 452 453/* 454 * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET 455 * in ctx->_TriangleCaps if needed. 456 */ 457static void 458update_polygon(struct gl_context *ctx) 459{ 460 ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET); 461 462 if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) 463 ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK; 464 465 if ( ctx->Polygon.OffsetPoint 466 || ctx->Polygon.OffsetLine 467 || ctx->Polygon.OffsetFill) 468 ctx->_TriangleCaps |= DD_TRI_OFFSET; 469} 470 471 472/** 473 * Update the ctx->_TriangleCaps bitfield. 474 * XXX that bitfield should really go away someday! 475 * This function must be called after other update_*() functions since 476 * there are dependencies on some other derived values. 477 */ 478#if 0 479static void 480update_tricaps(struct gl_context *ctx, GLbitfield new_state) 481{ 482 ctx->_TriangleCaps = 0; 483 484 /* 485 * Points 486 */ 487 if (1/*new_state & _NEW_POINT*/) { 488 if (ctx->Point.SmoothFlag) 489 ctx->_TriangleCaps |= DD_POINT_SMOOTH; 490 if (ctx->Point._Attenuated) 491 ctx->_TriangleCaps |= DD_POINT_ATTEN; 492 } 493 494 /* 495 * Lines 496 */ 497 if (1/*new_state & _NEW_LINE*/) { 498 if (ctx->Line.SmoothFlag) 499 ctx->_TriangleCaps |= DD_LINE_SMOOTH; 500 if (ctx->Line.StippleFlag) 501 ctx->_TriangleCaps |= DD_LINE_STIPPLE; 502 } 503 504 /* 505 * Polygons 506 */ 507 if (1/*new_state & _NEW_POLYGON*/) { 508 if (ctx->Polygon.SmoothFlag) 509 ctx->_TriangleCaps |= DD_TRI_SMOOTH; 510 if (ctx->Polygon.StippleFlag) 511 ctx->_TriangleCaps |= DD_TRI_STIPPLE; 512 if (ctx->Polygon.FrontMode != GL_FILL 513 || ctx->Polygon.BackMode != GL_FILL) 514 ctx->_TriangleCaps |= DD_TRI_UNFILLED; 515 if (ctx->Polygon.CullFlag 516 && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) 517 ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK; 518 if (ctx->Polygon.OffsetPoint || 519 ctx->Polygon.OffsetLine || 520 ctx->Polygon.OffsetFill) 521 ctx->_TriangleCaps |= DD_TRI_OFFSET; 522 } 523 524 /* 525 * Lighting and shading 526 */ 527 if (ctx->Light.Enabled && ctx->Light.Model.TwoSide) 528 ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE; 529 if (ctx->Light.ShadeModel == GL_FLAT) 530 ctx->_TriangleCaps |= DD_FLATSHADE; 531 if (_mesa_need_secondary_color(ctx)) 532 ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR; 533 534 /* 535 * Stencil 536 */ 537 if (ctx->Stencil._TestTwoSide) 538 ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL; 539} 540#endif 541 542 543/** 544 * Compute derived GL state. 545 * If __struct gl_contextRec::NewState is non-zero then this function \b must 546 * be called before rendering anything. 547 * 548 * Calls dd_function_table::UpdateState to perform any internal state 549 * management necessary. 550 * 551 * \sa _mesa_update_modelview_project(), _mesa_update_texture(), 552 * _mesa_update_buffer_bounds(), 553 * _mesa_update_lighting() and _mesa_update_tnl_spaces(). 554 */ 555void 556_mesa_update_state_locked( struct gl_context *ctx ) 557{ 558 GLbitfield new_state = ctx->NewState; 559 GLbitfield prog_flags = _NEW_PROGRAM; 560 GLbitfield new_prog_state = 0x0; 561 562 if (new_state == _NEW_CURRENT_ATTRIB) 563 goto out; 564 565 if (MESA_VERBOSE & VERBOSE_STATE) 566 _mesa_print_state("_mesa_update_state", new_state); 567 568 /* Determine which state flags effect vertex/fragment program state */ 569 if (ctx->FragmentProgram._MaintainTexEnvProgram) { 570 prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE | _NEW_FOG | 571 _NEW_ARRAY | _NEW_LIGHT | _NEW_POINT | _NEW_RENDERMODE | 572 _NEW_PROGRAM); 573 } 574 if (ctx->VertexProgram._MaintainTnlProgram) { 575 prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX | 576 _NEW_TRANSFORM | _NEW_POINT | 577 _NEW_FOG | _NEW_LIGHT | 578 _MESA_NEW_NEED_EYE_COORDS); 579 } 580 581 /* 582 * Now update derived state info 583 */ 584 585 if (new_state & prog_flags) 586 update_program_enables( ctx ); 587 588 if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION)) 589 _mesa_update_modelview_project( ctx, new_state ); 590 591 if (new_state & (_NEW_PROGRAM|_NEW_TEXTURE|_NEW_TEXTURE_MATRIX)) 592 _mesa_update_texture( ctx, new_state ); 593 594 if (new_state & _NEW_BUFFERS) 595 _mesa_update_framebuffer(ctx); 596 597 if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT)) 598 _mesa_update_draw_buffer_bounds( ctx ); 599 600 if (new_state & _NEW_POLYGON) 601 update_polygon( ctx ); 602 603 if (new_state & _NEW_LIGHT) 604 _mesa_update_lighting( ctx ); 605 606 if (new_state & (_NEW_STENCIL | _NEW_BUFFERS)) 607 _mesa_update_stencil( ctx ); 608 609 if (new_state & _MESA_NEW_TRANSFER_STATE) 610 _mesa_update_pixel( ctx, new_state ); 611 612 if (new_state & _DD_NEW_SEPARATE_SPECULAR) 613 update_separate_specular( ctx ); 614 615 if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT)) 616 update_viewport_matrix(ctx); 617 618 if (new_state & _NEW_MULTISAMPLE) 619 update_multisample( ctx ); 620 621 if (new_state & _NEW_COLOR) 622 update_color( ctx ); 623 624#if 0 625 if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT 626 | _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR)) 627 update_tricaps( ctx, new_state ); 628#endif 629 630 /* ctx->_NeedEyeCoords is now up to date. 631 * 632 * If the truth value of this variable has changed, update for the 633 * new lighting space and recompute the positions of lights and the 634 * normal transform. 635 * 636 * If the lighting space hasn't changed, may still need to recompute 637 * light positions & normal transforms for other reasons. 638 */ 639 if (new_state & _MESA_NEW_NEED_EYE_COORDS) 640 _mesa_update_tnl_spaces( ctx, new_state ); 641 642 if (new_state & prog_flags) { 643 /* When we generate programs from fixed-function vertex/fragment state 644 * this call may generate/bind a new program. If so, we need to 645 * propogate the _NEW_PROGRAM flag to the driver. 646 */ 647 new_prog_state |= update_program( ctx ); 648 } 649 650 if (new_state & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT)) 651 update_arrays( ctx ); 652 653 out: 654 new_prog_state |= update_program_constants(ctx); 655 656 /* 657 * Give the driver a chance to act upon the new_state flags. 658 * The driver might plug in different span functions, for example. 659 * Also, this is where the driver can invalidate the state of any 660 * active modules (such as swrast_setup, swrast, tnl, etc). 661 * 662 * Set ctx->NewState to zero to avoid recursion if 663 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?) 664 */ 665 new_state = ctx->NewState | new_prog_state; 666 ctx->NewState = 0; 667 ctx->Driver.UpdateState(ctx, new_state); 668 ctx->Array.NewState = 0; 669 if (!ctx->Array.RebindArrays) 670 ctx->Array.RebindArrays = (new_state & (_NEW_ARRAY | _NEW_PROGRAM)) != 0; 671} 672 673 674/* This is the usual entrypoint for state updates: 675 */ 676void 677_mesa_update_state( struct gl_context *ctx ) 678{ 679 _mesa_lock_context_textures(ctx); 680 _mesa_update_state_locked(ctx); 681 _mesa_unlock_context_textures(ctx); 682} 683 684 685 686 687/** 688 * Want to figure out which fragment program inputs are actually 689 * constant/current values from ctx->Current. These should be 690 * referenced as a tracked state variable rather than a fragment 691 * program input, to save the overhead of putting a constant value in 692 * every submitted vertex, transferring it to hardware, interpolating 693 * it across the triangle, etc... 694 * 695 * When there is a VP bound, just use vp->outputs. But when we're 696 * generating vp from fixed function state, basically want to 697 * calculate: 698 * 699 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) | 700 * potential_vp_outputs ) 701 * 702 * Where potential_vp_outputs is calculated by looking at enabled 703 * texgen, etc. 704 * 705 * The generated fragment program should then only declare inputs that 706 * may vary or otherwise differ from the ctx->Current values. 707 * Otherwise, the fp should track them as state values instead. 708 */ 709void 710_mesa_set_varying_vp_inputs( struct gl_context *ctx, 711 GLbitfield varying_inputs ) 712{ 713 if (ctx->varying_vp_inputs != varying_inputs) { 714 ctx->varying_vp_inputs = varying_inputs; 715 ctx->NewState |= _NEW_ARRAY; 716 /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/ 717 } 718} 719 720 721/** 722 * Used by drivers to tell core Mesa that the driver is going to 723 * install/ use its own vertex program. In particular, this will 724 * prevent generated fragment programs from using state vars instead 725 * of ordinary varyings/inputs. 726 */ 727void 728_mesa_set_vp_override(struct gl_context *ctx, GLboolean flag) 729{ 730 if (ctx->VertexProgram._Overriden != flag) { 731 ctx->VertexProgram._Overriden = flag; 732 733 /* Set one of the bits which will trigger fragment program 734 * regeneration: 735 */ 736 ctx->NewState |= _NEW_PROGRAM; 737 } 738} 739