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