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