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