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