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