2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
30 * This file manages recalculation of derived values in struct gl_context.
39 #include "ffvertex_prog.h"
40 #include "framebuffer.h"
44 #include "program/program.h"
45 #include "program/prog_parameter.h"
48 #include "texenvprogram.h"
55 update_separate_specular(struct gl_context
*ctx
)
57 if (_mesa_need_secondary_color(ctx
))
58 ctx
->_TriangleCaps
|= DD_SEPARATE_SPECULAR
;
60 ctx
->_TriangleCaps
&= ~DD_SEPARATE_SPECULAR
;
65 * Helper for update_arrays().
66 * \return min(current min, array->_MaxElement).
69 update_min(GLuint min
, struct gl_client_array
*array
)
71 _mesa_update_array_max_element(array
);
72 return MIN2(min
, array
->_MaxElement
);
77 * Update ctx->Array._MaxElement (the max legal index into all enabled arrays).
78 * Need to do this upon new array state or new buffer object state.
81 update_arrays( struct gl_context
*ctx
)
83 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
86 /* find min of _MaxElement values for all enabled arrays */
89 if (ctx
->VertexProgram
._Current
90 && arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
) {
91 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
93 else if (arrayObj
->Vertex
.Enabled
) {
94 min
= update_min(min
, &arrayObj
->Vertex
);
98 if (ctx
->VertexProgram
._Enabled
99 && arrayObj
->VertexAttrib
[VERT_ATTRIB_WEIGHT
].Enabled
) {
100 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_WEIGHT
]);
102 /* no conventional vertex weight array */
105 if (ctx
->VertexProgram
._Enabled
106 && arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
) {
107 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
109 else if (arrayObj
->Normal
.Enabled
) {
110 min
= update_min(min
, &arrayObj
->Normal
);
114 if (ctx
->VertexProgram
._Enabled
115 && arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
) {
116 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
118 else if (arrayObj
->Color
.Enabled
) {
119 min
= update_min(min
, &arrayObj
->Color
);
123 if (ctx
->VertexProgram
._Enabled
124 && arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
) {
125 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
]);
127 else if (arrayObj
->SecondaryColor
.Enabled
) {
128 min
= update_min(min
, &arrayObj
->SecondaryColor
);
132 if (ctx
->VertexProgram
._Enabled
133 && arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
) {
134 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
]);
136 else if (arrayObj
->FogCoord
.Enabled
) {
137 min
= update_min(min
, &arrayObj
->FogCoord
);
141 if (ctx
->VertexProgram
._Enabled
142 && arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
) {
143 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
]);
145 else if (arrayObj
->Index
.Enabled
) {
146 min
= update_min(min
, &arrayObj
->Index
);
150 if (ctx
->VertexProgram
._Enabled
151 && arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
) {
152 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
]);
156 for (i
= VERT_ATTRIB_TEX0
; i
<= VERT_ATTRIB_TEX7
; i
++) {
157 if (ctx
->VertexProgram
._Enabled
158 && arrayObj
->VertexAttrib
[i
].Enabled
) {
159 min
= update_min(min
, &arrayObj
->VertexAttrib
[i
]);
161 else if (i
- VERT_ATTRIB_TEX0
< ctx
->Const
.MaxTextureCoordUnits
162 && arrayObj
->TexCoord
[i
- VERT_ATTRIB_TEX0
].Enabled
) {
163 min
= update_min(min
, &arrayObj
->TexCoord
[i
- VERT_ATTRIB_TEX0
]);
168 if (ctx
->VertexProgram
._Current
) {
169 for (i
= 0; i
< Elements(arrayObj
->VertexAttrib
); i
++) {
170 if (arrayObj
->VertexAttrib
[i
].Enabled
) {
171 min
= update_min(min
, &arrayObj
->VertexAttrib
[i
]);
176 if (arrayObj
->EdgeFlag
.Enabled
) {
177 min
= update_min(min
, &arrayObj
->EdgeFlag
);
180 /* _MaxElement is one past the last legal array element */
181 arrayObj
->_MaxElement
= min
;
186 * Update the following fields:
187 * ctx->VertexProgram._Enabled
188 * ctx->FragmentProgram._Enabled
189 * ctx->ATIFragmentShader._Enabled
190 * This needs to be done before texture state validation.
193 update_program_enables(struct gl_context
*ctx
)
195 /* These _Enabled flags indicate if the program is enabled AND valid. */
196 ctx
->VertexProgram
._Enabled
= ctx
->VertexProgram
.Enabled
197 && ctx
->VertexProgram
.Current
->Base
.Instructions
;
198 ctx
->FragmentProgram
._Enabled
= ctx
->FragmentProgram
.Enabled
199 && ctx
->FragmentProgram
.Current
->Base
.Instructions
;
200 ctx
->ATIFragmentShader
._Enabled
= ctx
->ATIFragmentShader
.Enabled
201 && ctx
->ATIFragmentShader
.Current
->Instructions
[0];
206 * Update vertex/fragment program state. In particular, update these fields:
207 * ctx->VertexProgram._Current
208 * ctx->VertexProgram._TnlProgram,
209 * These point to the highest priority enabled vertex/fragment program or are
210 * NULL if fixed-function processing is to be done.
212 * This function needs to be called after texture state validation in case
213 * we're generating a fragment program from fixed-function texture state.
215 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
216 * or fragment program is being used.
219 update_program(struct gl_context
*ctx
)
221 const struct gl_shader_program
*vsProg
= ctx
->Shader
.CurrentVertexProgram
;
222 const struct gl_shader_program
*gsProg
= ctx
->Shader
.CurrentGeometryProgram
;
223 const struct gl_shader_program
*fsProg
= ctx
->Shader
.CurrentFragmentProgram
;
224 const struct gl_vertex_program
*prevVP
= ctx
->VertexProgram
._Current
;
225 const struct gl_fragment_program
*prevFP
= ctx
->FragmentProgram
._Current
;
226 const struct gl_geometry_program
*prevGP
= ctx
->GeometryProgram
._Current
;
227 GLbitfield new_state
= 0x0;
230 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
231 * pointers to the programs that should be used for rendering. If either
232 * is NULL, use fixed-function code paths.
234 * These programs may come from several sources. The priority is as
236 * 1. OpenGL 2.0/ARB vertex/fragment shaders
237 * 2. ARB/NV vertex/fragment programs
238 * 3. Programs derived from fixed-function state.
240 * Note: it's possible for a vertex shader to get used with a fragment
241 * program (and vice versa) here, but in practice that shouldn't ever
242 * come up, or matter.
245 if (fsProg
&& fsProg
->LinkStatus
&& fsProg
->FragmentProgram
) {
246 /* Use shader programs */
247 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
248 fsProg
->FragmentProgram
);
250 else if (ctx
->FragmentProgram
._Enabled
) {
251 /* use user-defined vertex program */
252 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
253 ctx
->FragmentProgram
.Current
);
255 else if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
256 /* Use fragment program generated from fixed-function state.
258 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
259 _mesa_get_fixed_func_fragment_program(ctx
));
260 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._TexEnvProgram
,
261 ctx
->FragmentProgram
._Current
);
264 /* no fragment program */
265 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
, NULL
);
268 if (gsProg
&& gsProg
->LinkStatus
&& gsProg
->GeometryProgram
) {
269 /* Use shader programs */
270 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
,
271 gsProg
->GeometryProgram
);
273 /* no fragment program */
274 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
, NULL
);
277 /* Examine vertex program after fragment program as
278 * _mesa_get_fixed_func_vertex_program() needs to know active
281 if (vsProg
&& vsProg
->LinkStatus
&& vsProg
->VertexProgram
) {
282 /* Use shader programs */
283 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
284 vsProg
->VertexProgram
);
286 else if (ctx
->VertexProgram
._Enabled
) {
287 /* use user-defined vertex program */
288 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
289 ctx
->VertexProgram
.Current
);
291 else if (ctx
->VertexProgram
._MaintainTnlProgram
) {
292 /* Use vertex program generated from fixed-function state.
294 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
295 _mesa_get_fixed_func_vertex_program(ctx
));
296 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._TnlProgram
,
297 ctx
->VertexProgram
._Current
);
300 /* no vertex program */
301 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
, NULL
);
304 /* Let the driver know what's happening:
306 if (ctx
->FragmentProgram
._Current
!= prevFP
) {
307 new_state
|= _NEW_PROGRAM
;
308 if (ctx
->Driver
.BindProgram
) {
309 ctx
->Driver
.BindProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
310 (struct gl_program
*) ctx
->FragmentProgram
._Current
);
314 if (ctx
->GeometryProgram
._Current
!= prevGP
) {
315 new_state
|= _NEW_PROGRAM
;
316 if (ctx
->Driver
.BindProgram
) {
317 ctx
->Driver
.BindProgram(ctx
, MESA_GEOMETRY_PROGRAM
,
318 (struct gl_program
*) ctx
->GeometryProgram
._Current
);
322 if (ctx
->VertexProgram
._Current
!= prevVP
) {
323 new_state
|= _NEW_PROGRAM
;
324 if (ctx
->Driver
.BindProgram
) {
325 ctx
->Driver
.BindProgram(ctx
, GL_VERTEX_PROGRAM_ARB
,
326 (struct gl_program
*) ctx
->VertexProgram
._Current
);
335 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
338 update_program_constants(struct gl_context
*ctx
)
340 GLbitfield new_state
= 0x0;
342 if (ctx
->FragmentProgram
._Current
) {
343 const struct gl_program_parameter_list
*params
=
344 ctx
->FragmentProgram
._Current
->Base
.Parameters
;
345 if (params
&& params
->StateFlags
& ctx
->NewState
) {
346 new_state
|= _NEW_PROGRAM_CONSTANTS
;
350 if (ctx
->GeometryProgram
._Current
) {
351 const struct gl_program_parameter_list
*params
=
352 ctx
->GeometryProgram
._Current
->Base
.Parameters
;
353 /*FIXME: StateFlags is always 0 because we have unnamed constant
354 * not state changes */
355 if (params
/*&& params->StateFlags & ctx->NewState*/) {
356 new_state
|= _NEW_PROGRAM_CONSTANTS
;
360 if (ctx
->VertexProgram
._Current
) {
361 const struct gl_program_parameter_list
*params
=
362 ctx
->VertexProgram
._Current
->Base
.Parameters
;
363 if (params
&& params
->StateFlags
& ctx
->NewState
) {
364 new_state
|= _NEW_PROGRAM_CONSTANTS
;
375 update_viewport_matrix(struct gl_context
*ctx
)
377 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
379 ASSERT(depthMax
> 0);
381 /* Compute scale and bias values. This is really driver-specific
382 * and should be maintained elsewhere if at all.
383 * NOTE: RasterPos uses this.
385 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
386 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
387 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
388 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
394 * Update derived multisample state.
397 update_multisample(struct gl_context
*ctx
)
399 ctx
->Multisample
._Enabled
= GL_FALSE
;
400 if (ctx
->Multisample
.Enabled
&&
402 ctx
->DrawBuffer
->Visual
.sampleBuffers
)
403 ctx
->Multisample
._Enabled
= GL_TRUE
;
408 * Update derived color/blend/logicop state.
411 update_color(struct gl_context
*ctx
)
413 /* This is needed to support 1.1's RGB logic ops AND
414 * 1.0's blending logicops.
416 ctx
->Color
._LogicOpEnabled
= _mesa_rgba_logicop_enabled(ctx
);
420 update_clamp_fragment_color(struct gl_context
*ctx
)
422 if(ctx
->Color
.ClampFragmentColor
== GL_FIXED_ONLY_ARB
)
423 ctx
->Color
._ClampFragmentColor
= !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
425 ctx
->Color
._ClampFragmentColor
= ctx
->Color
.ClampFragmentColor
;
429 update_clamp_vertex_color(struct gl_context
*ctx
)
431 if(ctx
->Light
.ClampVertexColor
== GL_FIXED_ONLY_ARB
)
432 ctx
->Light
._ClampVertexColor
= !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
434 ctx
->Light
._ClampVertexColor
= ctx
->Light
.ClampVertexColor
;
438 update_clamp_read_color(struct gl_context
*ctx
)
440 if(ctx
->Color
.ClampReadColor
== GL_FIXED_ONLY_ARB
)
441 ctx
->Color
._ClampReadColor
= !ctx
->ReadBuffer
|| !ctx
->ReadBuffer
->Visual
.floatMode
;
443 ctx
->Color
._ClampReadColor
= ctx
->Color
.ClampReadColor
;
450 * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
451 * in ctx->_TriangleCaps if needed.
454 update_polygon(struct gl_context
*ctx
)
456 ctx
->_TriangleCaps
&= ~(DD_TRI_CULL_FRONT_BACK
| DD_TRI_OFFSET
);
458 if (ctx
->Polygon
.CullFlag
&& ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
459 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
461 if ( ctx
->Polygon
.OffsetPoint
462 || ctx
->Polygon
.OffsetLine
463 || ctx
->Polygon
.OffsetFill
)
464 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
469 * Update the ctx->_TriangleCaps bitfield.
470 * XXX that bitfield should really go away someday!
471 * This function must be called after other update_*() functions since
472 * there are dependencies on some other derived values.
476 update_tricaps(struct gl_context
*ctx
, GLbitfield new_state
)
478 ctx
->_TriangleCaps
= 0;
483 if (1/*new_state & _NEW_POINT*/) {
484 if (ctx
->Point
.SmoothFlag
)
485 ctx
->_TriangleCaps
|= DD_POINT_SMOOTH
;
486 if (ctx
->Point
._Attenuated
)
487 ctx
->_TriangleCaps
|= DD_POINT_ATTEN
;
493 if (1/*new_state & _NEW_LINE*/) {
494 if (ctx
->Line
.SmoothFlag
)
495 ctx
->_TriangleCaps
|= DD_LINE_SMOOTH
;
496 if (ctx
->Line
.StippleFlag
)
497 ctx
->_TriangleCaps
|= DD_LINE_STIPPLE
;
503 if (1/*new_state & _NEW_POLYGON*/) {
504 if (ctx
->Polygon
.SmoothFlag
)
505 ctx
->_TriangleCaps
|= DD_TRI_SMOOTH
;
506 if (ctx
->Polygon
.StippleFlag
)
507 ctx
->_TriangleCaps
|= DD_TRI_STIPPLE
;
508 if (ctx
->Polygon
.FrontMode
!= GL_FILL
509 || ctx
->Polygon
.BackMode
!= GL_FILL
)
510 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
511 if (ctx
->Polygon
.CullFlag
512 && ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
513 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
514 if (ctx
->Polygon
.OffsetPoint
||
515 ctx
->Polygon
.OffsetLine
||
516 ctx
->Polygon
.OffsetFill
)
517 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
521 * Lighting and shading
523 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
524 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
525 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
526 ctx
->_TriangleCaps
|= DD_FLATSHADE
;
527 if (_mesa_need_secondary_color(ctx
))
528 ctx
->_TriangleCaps
|= DD_SEPARATE_SPECULAR
;
533 if (ctx
->Stencil
._TestTwoSide
)
534 ctx
->_TriangleCaps
|= DD_TRI_TWOSTENCIL
;
540 * Compute derived GL state.
541 * If __struct gl_contextRec::NewState is non-zero then this function \b must
542 * be called before rendering anything.
544 * Calls dd_function_table::UpdateState to perform any internal state
545 * management necessary.
547 * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
548 * _mesa_update_buffer_bounds(),
549 * _mesa_update_lighting() and _mesa_update_tnl_spaces().
552 _mesa_update_state_locked( struct gl_context
*ctx
)
554 GLbitfield new_state
= ctx
->NewState
;
555 GLbitfield prog_flags
= _NEW_PROGRAM
;
556 GLbitfield new_prog_state
= 0x0;
558 if (new_state
== _NEW_CURRENT_ATTRIB
)
561 if (MESA_VERBOSE
& VERBOSE_STATE
)
562 _mesa_print_state("_mesa_update_state", new_state
);
564 /* Determine which state flags effect vertex/fragment program state */
565 if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
566 prog_flags
|= (_NEW_BUFFERS
| _NEW_TEXTURE
| _NEW_FOG
|
567 _NEW_ARRAY
| _NEW_LIGHT
| _NEW_POINT
| _NEW_RENDERMODE
|
568 _NEW_PROGRAM
| _NEW_FRAG_CLAMP
);
570 if (ctx
->VertexProgram
._MaintainTnlProgram
) {
571 prog_flags
|= (_NEW_ARRAY
| _NEW_TEXTURE
| _NEW_TEXTURE_MATRIX
|
572 _NEW_TRANSFORM
| _NEW_POINT
|
573 _NEW_FOG
| _NEW_LIGHT
|
574 _MESA_NEW_NEED_EYE_COORDS
);
578 * Now update derived state info
581 if (new_state
& prog_flags
)
582 update_program_enables( ctx
);
584 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
585 _mesa_update_modelview_project( ctx
, new_state
);
587 if (new_state
& (_NEW_PROGRAM
|_NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
))
588 _mesa_update_texture( ctx
, new_state
);
590 if (new_state
& _NEW_BUFFERS
)
591 _mesa_update_framebuffer(ctx
);
593 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
594 _mesa_update_draw_buffer_bounds( ctx
);
596 if (new_state
& _NEW_POLYGON
)
597 update_polygon( ctx
);
599 if (new_state
& _NEW_LIGHT
)
600 _mesa_update_lighting( ctx
);
602 if (new_state
& (_NEW_LIGHT
| _NEW_BUFFERS
))
603 update_clamp_vertex_color(ctx
);
605 if (new_state
& (_NEW_STENCIL
| _NEW_BUFFERS
))
606 _mesa_update_stencil( ctx
);
608 if (new_state
& _NEW_PIXEL
)
609 _mesa_update_pixel( ctx
, new_state
);
611 if (new_state
& _DD_NEW_SEPARATE_SPECULAR
)
612 update_separate_specular( ctx
);
614 if (new_state
& (_NEW_BUFFERS
| _NEW_VIEWPORT
))
615 update_viewport_matrix(ctx
);
617 if (new_state
& _NEW_MULTISAMPLE
)
618 update_multisample( ctx
);
620 if (new_state
& _NEW_COLOR
)
623 if (new_state
& (_NEW_COLOR
| _NEW_BUFFERS
))
624 update_clamp_read_color(ctx
);
626 if(new_state
& (_NEW_FRAG_CLAMP
| _NEW_BUFFERS
))
627 update_clamp_fragment_color(ctx
);
630 if (new_state
& (_NEW_POINT
| _NEW_LINE
| _NEW_POLYGON
| _NEW_LIGHT
631 | _NEW_STENCIL
| _DD_NEW_SEPARATE_SPECULAR
))
632 update_tricaps( ctx
, new_state
);
635 /* ctx->_NeedEyeCoords is now up to date.
637 * If the truth value of this variable has changed, update for the
638 * new lighting space and recompute the positions of lights and the
641 * If the lighting space hasn't changed, may still need to recompute
642 * light positions & normal transforms for other reasons.
644 if (new_state
& _MESA_NEW_NEED_EYE_COORDS
)
645 _mesa_update_tnl_spaces( ctx
, new_state
);
647 if (new_state
& prog_flags
) {
648 /* When we generate programs from fixed-function vertex/fragment state
649 * this call may generate/bind a new program. If so, we need to
650 * propogate the _NEW_PROGRAM flag to the driver.
652 new_prog_state
|= update_program( ctx
);
655 if (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
| _NEW_BUFFER_OBJECT
))
656 update_arrays( ctx
);
659 new_prog_state
|= update_program_constants(ctx
);
662 * Give the driver a chance to act upon the new_state flags.
663 * The driver might plug in different span functions, for example.
664 * Also, this is where the driver can invalidate the state of any
665 * active modules (such as swrast_setup, swrast, tnl, etc).
667 * Set ctx->NewState to zero to avoid recursion if
668 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
670 new_state
= ctx
->NewState
| new_prog_state
;
672 ctx
->Driver
.UpdateState(ctx
, new_state
);
673 ctx
->Array
.NewState
= 0;
674 if (!ctx
->Array
.RebindArrays
)
675 ctx
->Array
.RebindArrays
= (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
)) != 0;
679 /* This is the usual entrypoint for state updates:
682 _mesa_update_state( struct gl_context
*ctx
)
684 _mesa_lock_context_textures(ctx
);
685 _mesa_update_state_locked(ctx
);
686 _mesa_unlock_context_textures(ctx
);
693 * Want to figure out which fragment program inputs are actually
694 * constant/current values from ctx->Current. These should be
695 * referenced as a tracked state variable rather than a fragment
696 * program input, to save the overhead of putting a constant value in
697 * every submitted vertex, transferring it to hardware, interpolating
698 * it across the triangle, etc...
700 * When there is a VP bound, just use vp->outputs. But when we're
701 * generating vp from fixed function state, basically want to
704 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
705 * potential_vp_outputs )
707 * Where potential_vp_outputs is calculated by looking at enabled
710 * The generated fragment program should then only declare inputs that
711 * may vary or otherwise differ from the ctx->Current values.
712 * Otherwise, the fp should track them as state values instead.
715 _mesa_set_varying_vp_inputs( struct gl_context
*ctx
,
716 GLbitfield varying_inputs
)
718 if (ctx
->varying_vp_inputs
!= varying_inputs
) {
719 ctx
->varying_vp_inputs
= varying_inputs
;
720 ctx
->NewState
|= _NEW_ARRAY
;
721 /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/
727 * Used by drivers to tell core Mesa that the driver is going to
728 * install/ use its own vertex program. In particular, this will
729 * prevent generated fragment programs from using state vars instead
730 * of ordinary varyings/inputs.
733 _mesa_set_vp_override(struct gl_context
*ctx
, GLboolean flag
)
735 if (ctx
->VertexProgram
._Overriden
!= flag
) {
736 ctx
->VertexProgram
._Overriden
= flag
;
738 /* Set one of the bits which will trigger fragment program
741 ctx
->NewState
|= _NEW_PROGRAM
;