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