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"
46 #include "shaderobj.h"
49 #include "texenvprogram.h"
56 update_separate_specular(struct gl_context
*ctx
)
58 if (_mesa_need_secondary_color(ctx
))
59 ctx
->_TriangleCaps
|= DD_SEPARATE_SPECULAR
;
61 ctx
->_TriangleCaps
&= ~DD_SEPARATE_SPECULAR
;
66 * Helper for update_arrays().
67 * \return min(current min, array->_MaxElement).
70 update_min(GLuint min
, struct gl_client_array
*array
)
72 _mesa_update_array_max_element(array
);
73 return MIN2(min
, array
->_MaxElement
);
78 * Update ctx->Array._MaxElement (the max legal index into all enabled arrays).
79 * Need to do this upon new array state or new buffer object state.
82 update_arrays( struct gl_context
*ctx
)
84 struct gl_array_object
*arrayObj
= ctx
->Array
.ArrayObj
;
87 /* find min of _MaxElement values for all enabled arrays.
88 * Note that the generic arrays always take precedence over
93 if (ctx
->VertexProgram
._Current
94 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
) {
95 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC0
]);
97 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
) {
98 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
102 if (ctx
->VertexProgram
._Enabled
103 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC1
].Enabled
) {
104 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC1
]);
106 /* no conventional vertex weight array */
109 if (ctx
->VertexProgram
._Enabled
110 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC2
].Enabled
) {
111 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC2
]);
113 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
) {
114 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
118 if (ctx
->VertexProgram
._Enabled
119 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC3
].Enabled
) {
120 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC3
]);
122 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
) {
123 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
127 if (ctx
->VertexProgram
._Enabled
128 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC4
].Enabled
) {
129 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC4
]);
131 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
) {
132 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
]);
136 if (ctx
->VertexProgram
._Enabled
137 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC5
].Enabled
) {
138 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC5
]);
140 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
) {
141 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
]);
145 if (ctx
->VertexProgram
._Enabled
146 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC6
].Enabled
) {
147 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC6
]);
149 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
) {
150 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
]);
154 if (ctx
->VertexProgram
._Enabled
155 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC7
].Enabled
) {
156 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC7
]);
160 for (i
= 0; i
< VERT_ATTRIB_TEX_MAX
; i
++) {
161 if (ctx
->VertexProgram
._Enabled
162 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC8
+ i
].Enabled
) {
163 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC8
+ i
]);
165 else if (i
< ctx
->Const
.MaxTextureCoordUnits
166 && arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
) {
167 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
172 if (ctx
->VertexProgram
._Current
) {
173 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
174 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
) {
175 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
180 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
) {
181 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
]);
184 /* _MaxElement is one past the last legal array element */
185 arrayObj
->_MaxElement
= min
;
190 * Update the following fields:
191 * ctx->VertexProgram._Enabled
192 * ctx->FragmentProgram._Enabled
193 * ctx->ATIFragmentShader._Enabled
194 * This needs to be done before texture state validation.
197 update_program_enables(struct gl_context
*ctx
)
199 /* These _Enabled flags indicate if the user-defined ARB/NV vertex/fragment
200 * program is enabled AND valid. Similarly for ATI fragment shaders.
201 * GLSL shaders not relevant here.
203 ctx
->VertexProgram
._Enabled
= ctx
->VertexProgram
.Enabled
204 && ctx
->VertexProgram
.Current
->Base
.Instructions
;
205 ctx
->FragmentProgram
._Enabled
= ctx
->FragmentProgram
.Enabled
206 && ctx
->FragmentProgram
.Current
->Base
.Instructions
;
207 ctx
->ATIFragmentShader
._Enabled
= ctx
->ATIFragmentShader
.Enabled
208 && ctx
->ATIFragmentShader
.Current
->Instructions
[0];
213 * Update the ctx->Vertex/Geometry/FragmentProgram._Current pointers to point
214 * to the current/active programs. Then call ctx->Driver.BindProgram() to
215 * tell the driver which programs to use.
217 * Programs may come from 3 sources: GLSL shaders, ARB/NV_vertex/fragment
218 * programs or programs derived from fixed-function state.
220 * This function needs to be called after texture state validation in case
221 * we're generating a fragment program from fixed-function texture state.
223 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
224 * or fragment program is being used.
227 update_program(struct gl_context
*ctx
)
229 const struct gl_shader_program
*vsProg
= ctx
->Shader
.CurrentVertexProgram
;
230 const struct gl_shader_program
*gsProg
= ctx
->Shader
.CurrentGeometryProgram
;
231 const struct gl_shader_program
*fsProg
= ctx
->Shader
.CurrentFragmentProgram
;
232 const struct gl_vertex_program
*prevVP
= ctx
->VertexProgram
._Current
;
233 const struct gl_fragment_program
*prevFP
= ctx
->FragmentProgram
._Current
;
234 const struct gl_geometry_program
*prevGP
= ctx
->GeometryProgram
._Current
;
235 GLbitfield new_state
= 0x0;
238 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
239 * pointers to the programs that should be used for rendering. If either
240 * is NULL, use fixed-function code paths.
242 * These programs may come from several sources. The priority is as
244 * 1. OpenGL 2.0/ARB vertex/fragment shaders
245 * 2. ARB/NV vertex/fragment programs
246 * 3. Programs derived from fixed-function state.
248 * Note: it's possible for a vertex shader to get used with a fragment
249 * program (and vice versa) here, but in practice that shouldn't ever
250 * come up, or matter.
253 if (fsProg
&& fsProg
->LinkStatus
254 && fsProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]) {
255 /* Use GLSL fragment shader */
256 _mesa_reference_shader_program(ctx
,
257 &ctx
->Shader
._CurrentFragmentProgram
,
259 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
260 (struct gl_fragment_program
*)
261 fsProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
);
263 else if (ctx
->FragmentProgram
._Enabled
) {
264 /* Use user-defined fragment program */
265 _mesa_reference_shader_program(ctx
,
266 &ctx
->Shader
._CurrentFragmentProgram
,
268 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
269 ctx
->FragmentProgram
.Current
);
271 else if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
272 /* Use fragment program generated from fixed-function state */
273 struct gl_shader_program
*f
= _mesa_get_fixed_func_fragment_program(ctx
);
275 _mesa_reference_shader_program(ctx
,
276 &ctx
->Shader
._CurrentFragmentProgram
,
278 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
279 (struct gl_fragment_program
*)
280 f
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
);
283 /* No fragment program */
284 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
, NULL
);
287 if (gsProg
&& gsProg
->LinkStatus
288 && gsProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]) {
289 /* Use GLSL geometry shader */
290 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
,
291 (struct gl_geometry_program
*)
292 gsProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]->Program
);
294 /* No geometry program */
295 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
, NULL
);
298 /* Examine vertex program after fragment program as
299 * _mesa_get_fixed_func_vertex_program() needs to know active
302 if (vsProg
&& vsProg
->LinkStatus
303 && vsProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]) {
304 /* Use GLSL vertex shader */
305 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
306 (struct gl_vertex_program
*)
307 vsProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->Program
);
309 else if (ctx
->VertexProgram
._Enabled
) {
310 /* Use user-defined vertex program */
311 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
312 ctx
->VertexProgram
.Current
);
314 else if (ctx
->VertexProgram
._MaintainTnlProgram
) {
315 /* Use vertex program generated from fixed-function state */
316 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
317 _mesa_get_fixed_func_vertex_program(ctx
));
318 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._TnlProgram
,
319 ctx
->VertexProgram
._Current
);
322 /* no vertex program */
323 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
, NULL
);
326 /* Let the driver know what's happening:
328 if (ctx
->FragmentProgram
._Current
!= prevFP
) {
329 new_state
|= _NEW_PROGRAM
;
330 if (ctx
->Driver
.BindProgram
) {
331 ctx
->Driver
.BindProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
332 (struct gl_program
*) ctx
->FragmentProgram
._Current
);
336 if (ctx
->GeometryProgram
._Current
!= prevGP
) {
337 new_state
|= _NEW_PROGRAM
;
338 if (ctx
->Driver
.BindProgram
) {
339 ctx
->Driver
.BindProgram(ctx
, MESA_GEOMETRY_PROGRAM
,
340 (struct gl_program
*) ctx
->GeometryProgram
._Current
);
344 if (ctx
->VertexProgram
._Current
!= prevVP
) {
345 new_state
|= _NEW_PROGRAM
;
346 if (ctx
->Driver
.BindProgram
) {
347 ctx
->Driver
.BindProgram(ctx
, GL_VERTEX_PROGRAM_ARB
,
348 (struct gl_program
*) ctx
->VertexProgram
._Current
);
357 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
360 update_program_constants(struct gl_context
*ctx
)
362 GLbitfield new_state
= 0x0;
364 if (ctx
->FragmentProgram
._Current
) {
365 const struct gl_program_parameter_list
*params
=
366 ctx
->FragmentProgram
._Current
->Base
.Parameters
;
367 if (params
&& params
->StateFlags
& ctx
->NewState
) {
368 new_state
|= _NEW_PROGRAM_CONSTANTS
;
372 if (ctx
->GeometryProgram
._Current
) {
373 const struct gl_program_parameter_list
*params
=
374 ctx
->GeometryProgram
._Current
->Base
.Parameters
;
375 /*FIXME: StateFlags is always 0 because we have unnamed constant
376 * not state changes */
377 if (params
/*&& params->StateFlags & ctx->NewState*/) {
378 new_state
|= _NEW_PROGRAM_CONSTANTS
;
382 if (ctx
->VertexProgram
._Current
) {
383 const struct gl_program_parameter_list
*params
=
384 ctx
->VertexProgram
._Current
->Base
.Parameters
;
385 if (params
&& params
->StateFlags
& ctx
->NewState
) {
386 new_state
|= _NEW_PROGRAM_CONSTANTS
;
397 update_viewport_matrix(struct gl_context
*ctx
)
399 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
401 ASSERT(depthMax
> 0);
403 /* Compute scale and bias values. This is really driver-specific
404 * and should be maintained elsewhere if at all.
405 * NOTE: RasterPos uses this.
407 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
408 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
409 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
410 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
416 * Update derived multisample state.
419 update_multisample(struct gl_context
*ctx
)
421 ctx
->Multisample
._Enabled
= GL_FALSE
;
422 if (ctx
->Multisample
.Enabled
&&
424 ctx
->DrawBuffer
->Visual
.sampleBuffers
)
425 ctx
->Multisample
._Enabled
= GL_TRUE
;
430 * Update the ctx->Color._ClampFragmentColor field
433 update_clamp_fragment_color(struct gl_context
*ctx
)
435 if (ctx
->Color
.ClampFragmentColor
== GL_FIXED_ONLY_ARB
)
436 ctx
->Color
._ClampFragmentColor
=
437 !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
439 ctx
->Color
._ClampFragmentColor
= ctx
->Color
.ClampFragmentColor
;
444 * Update the ctx->Color._ClampVertexColor field
447 update_clamp_vertex_color(struct gl_context
*ctx
)
449 if (ctx
->Light
.ClampVertexColor
== GL_FIXED_ONLY_ARB
)
450 ctx
->Light
._ClampVertexColor
=
451 !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
453 ctx
->Light
._ClampVertexColor
= ctx
->Light
.ClampVertexColor
;
458 * Update the ctx->Color._ClampReadColor field
461 update_clamp_read_color(struct gl_context
*ctx
)
463 if (ctx
->Color
.ClampReadColor
== GL_FIXED_ONLY_ARB
)
464 ctx
->Color
._ClampReadColor
=
465 !ctx
->ReadBuffer
|| !ctx
->ReadBuffer
->Visual
.floatMode
;
467 ctx
->Color
._ClampReadColor
= ctx
->Color
.ClampReadColor
;
471 * Update the ctx->VertexProgram._TwoSideEnabled flag.
474 update_twoside(struct gl_context
*ctx
)
476 if (ctx
->Shader
.CurrentVertexProgram
||
477 ctx
->VertexProgram
._Enabled
) {
478 ctx
->VertexProgram
._TwoSideEnabled
= ctx
->VertexProgram
.TwoSideEnabled
;
480 ctx
->VertexProgram
._TwoSideEnabled
= (ctx
->Light
.Enabled
&&
481 ctx
->Light
.Model
.TwoSide
);
487 * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
488 * in ctx->_TriangleCaps if needed.
491 update_polygon(struct gl_context
*ctx
)
493 ctx
->_TriangleCaps
&= ~(DD_TRI_CULL_FRONT_BACK
| DD_TRI_OFFSET
);
495 if (ctx
->Polygon
.CullFlag
&& ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
496 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
498 if ( ctx
->Polygon
.OffsetPoint
499 || ctx
->Polygon
.OffsetLine
500 || ctx
->Polygon
.OffsetFill
)
501 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
506 * Update the ctx->_TriangleCaps bitfield.
507 * XXX that bitfield should really go away someday!
508 * This function must be called after other update_*() functions since
509 * there are dependencies on some other derived values.
513 update_tricaps(struct gl_context
*ctx
, GLbitfield new_state
)
515 ctx
->_TriangleCaps
= 0;
520 if (1/*new_state & _NEW_POINT*/) {
521 if (ctx
->Point
.SmoothFlag
)
522 ctx
->_TriangleCaps
|= DD_POINT_SMOOTH
;
523 if (ctx
->Point
._Attenuated
)
524 ctx
->_TriangleCaps
|= DD_POINT_ATTEN
;
530 if (1/*new_state & _NEW_LINE*/) {
531 if (ctx
->Line
.SmoothFlag
)
532 ctx
->_TriangleCaps
|= DD_LINE_SMOOTH
;
533 if (ctx
->Line
.StippleFlag
)
534 ctx
->_TriangleCaps
|= DD_LINE_STIPPLE
;
540 if (1/*new_state & _NEW_POLYGON*/) {
541 if (ctx
->Polygon
.SmoothFlag
)
542 ctx
->_TriangleCaps
|= DD_TRI_SMOOTH
;
543 if (ctx
->Polygon
.StippleFlag
)
544 ctx
->_TriangleCaps
|= DD_TRI_STIPPLE
;
545 if (ctx
->Polygon
.FrontMode
!= GL_FILL
546 || ctx
->Polygon
.BackMode
!= GL_FILL
)
547 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
548 if (ctx
->Polygon
.CullFlag
549 && ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
550 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
551 if (ctx
->Polygon
.OffsetPoint
||
552 ctx
->Polygon
.OffsetLine
||
553 ctx
->Polygon
.OffsetFill
)
554 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
558 * Lighting and shading
560 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
561 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
562 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
563 ctx
->_TriangleCaps
|= DD_FLATSHADE
;
564 if (_mesa_need_secondary_color(ctx
))
565 ctx
->_TriangleCaps
|= DD_SEPARATE_SPECULAR
;
570 if (ctx
->Stencil
._TestTwoSide
)
571 ctx
->_TriangleCaps
|= DD_TRI_TWOSTENCIL
;
577 * Compute derived GL state.
578 * If __struct gl_contextRec::NewState is non-zero then this function \b must
579 * be called before rendering anything.
581 * Calls dd_function_table::UpdateState to perform any internal state
582 * management necessary.
584 * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
585 * _mesa_update_buffer_bounds(),
586 * _mesa_update_lighting() and _mesa_update_tnl_spaces().
589 _mesa_update_state_locked( struct gl_context
*ctx
)
591 GLbitfield new_state
= ctx
->NewState
;
592 GLbitfield prog_flags
= _NEW_PROGRAM
;
593 GLbitfield new_prog_state
= 0x0;
595 if (new_state
== _NEW_CURRENT_ATTRIB
)
598 if (MESA_VERBOSE
& VERBOSE_STATE
)
599 _mesa_print_state("_mesa_update_state", new_state
);
601 /* Determine which state flags effect vertex/fragment program state */
602 if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
603 prog_flags
|= (_NEW_BUFFERS
| _NEW_TEXTURE
| _NEW_FOG
|
604 _NEW_ARRAY
| _NEW_LIGHT
| _NEW_POINT
| _NEW_RENDERMODE
|
605 _NEW_PROGRAM
| _NEW_FRAG_CLAMP
| _NEW_COLOR
);
607 if (ctx
->VertexProgram
._MaintainTnlProgram
) {
608 prog_flags
|= (_NEW_ARRAY
| _NEW_TEXTURE
| _NEW_TEXTURE_MATRIX
|
609 _NEW_TRANSFORM
| _NEW_POINT
|
610 _NEW_FOG
| _NEW_LIGHT
|
611 _MESA_NEW_NEED_EYE_COORDS
);
615 * Now update derived state info
618 if (new_state
& prog_flags
)
619 update_program_enables( ctx
);
621 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
622 _mesa_update_modelview_project( ctx
, new_state
);
624 if (new_state
& (_NEW_PROGRAM
|_NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
))
625 _mesa_update_texture( ctx
, new_state
);
627 if (new_state
& _NEW_BUFFERS
)
628 _mesa_update_framebuffer(ctx
);
630 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
631 _mesa_update_draw_buffer_bounds( ctx
);
633 if (new_state
& _NEW_POLYGON
)
634 update_polygon( ctx
);
636 if (new_state
& _NEW_LIGHT
)
637 _mesa_update_lighting( ctx
);
639 if (new_state
& (_NEW_LIGHT
| _NEW_PROGRAM
))
640 update_twoside( ctx
);
642 if (new_state
& (_NEW_LIGHT
| _NEW_BUFFERS
))
643 update_clamp_vertex_color(ctx
);
645 if (new_state
& (_NEW_STENCIL
| _NEW_BUFFERS
))
646 _mesa_update_stencil( ctx
);
648 if (new_state
& _NEW_PIXEL
)
649 _mesa_update_pixel( ctx
, new_state
);
651 if (new_state
& _DD_NEW_SEPARATE_SPECULAR
)
652 update_separate_specular( ctx
);
654 if (new_state
& (_NEW_BUFFERS
| _NEW_VIEWPORT
))
655 update_viewport_matrix(ctx
);
657 if (new_state
& (_NEW_MULTISAMPLE
| _NEW_BUFFERS
))
658 update_multisample( ctx
);
660 if (new_state
& (_NEW_COLOR
| _NEW_BUFFERS
))
661 update_clamp_read_color(ctx
);
663 if(new_state
& (_NEW_FRAG_CLAMP
| _NEW_BUFFERS
))
664 update_clamp_fragment_color(ctx
);
667 if (new_state
& (_NEW_POINT
| _NEW_LINE
| _NEW_POLYGON
| _NEW_LIGHT
668 | _NEW_STENCIL
| _DD_NEW_SEPARATE_SPECULAR
))
669 update_tricaps( ctx
, new_state
);
672 /* ctx->_NeedEyeCoords is now up to date.
674 * If the truth value of this variable has changed, update for the
675 * new lighting space and recompute the positions of lights and the
678 * If the lighting space hasn't changed, may still need to recompute
679 * light positions & normal transforms for other reasons.
681 if (new_state
& _MESA_NEW_NEED_EYE_COORDS
)
682 _mesa_update_tnl_spaces( ctx
, new_state
);
684 if (new_state
& prog_flags
) {
685 /* When we generate programs from fixed-function vertex/fragment state
686 * this call may generate/bind a new program. If so, we need to
687 * propogate the _NEW_PROGRAM flag to the driver.
689 new_prog_state
|= update_program( ctx
);
692 if (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
| _NEW_BUFFER_OBJECT
))
693 update_arrays( ctx
);
696 new_prog_state
|= update_program_constants(ctx
);
699 * Give the driver a chance to act upon the new_state flags.
700 * The driver might plug in different span functions, for example.
701 * Also, this is where the driver can invalidate the state of any
702 * active modules (such as swrast_setup, swrast, tnl, etc).
704 * Set ctx->NewState to zero to avoid recursion if
705 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
707 new_state
= ctx
->NewState
| new_prog_state
;
709 ctx
->Driver
.UpdateState(ctx
, new_state
);
710 ctx
->Array
.NewState
= 0;
711 if (!ctx
->Array
.RebindArrays
)
712 ctx
->Array
.RebindArrays
= (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
)) != 0;
716 /* This is the usual entrypoint for state updates:
719 _mesa_update_state( struct gl_context
*ctx
)
721 _mesa_lock_context_textures(ctx
);
722 _mesa_update_state_locked(ctx
);
723 _mesa_unlock_context_textures(ctx
);
730 * Want to figure out which fragment program inputs are actually
731 * constant/current values from ctx->Current. These should be
732 * referenced as a tracked state variable rather than a fragment
733 * program input, to save the overhead of putting a constant value in
734 * every submitted vertex, transferring it to hardware, interpolating
735 * it across the triangle, etc...
737 * When there is a VP bound, just use vp->outputs. But when we're
738 * generating vp from fixed function state, basically want to
741 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
742 * potential_vp_outputs )
744 * Where potential_vp_outputs is calculated by looking at enabled
747 * The generated fragment program should then only declare inputs that
748 * may vary or otherwise differ from the ctx->Current values.
749 * Otherwise, the fp should track them as state values instead.
752 _mesa_set_varying_vp_inputs( struct gl_context
*ctx
,
753 GLbitfield64 varying_inputs
)
755 if (ctx
->varying_vp_inputs
!= varying_inputs
) {
756 ctx
->varying_vp_inputs
= varying_inputs
;
757 ctx
->NewState
|= _NEW_ARRAY
;
758 /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/
764 * Used by drivers to tell core Mesa that the driver is going to
765 * install/ use its own vertex program. In particular, this will
766 * prevent generated fragment programs from using state vars instead
767 * of ordinary varyings/inputs.
770 _mesa_set_vp_override(struct gl_context
*ctx
, GLboolean flag
)
772 if (ctx
->VertexProgram
._Overriden
!= flag
) {
773 ctx
->VertexProgram
._Overriden
= flag
;
775 /* Set one of the bits which will trigger fragment program
778 ctx
->NewState
|= _NEW_PROGRAM
;