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