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.
87 * Note that the generic arrays always take precedence over
92 if (ctx
->VertexProgram
._Current
93 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
) {
94 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC0
]);
96 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
) {
97 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_POS
]);
101 if (ctx
->VertexProgram
._Enabled
102 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC1
].Enabled
) {
103 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC1
]);
105 /* no conventional vertex weight array */
108 if (ctx
->VertexProgram
._Enabled
109 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC2
].Enabled
) {
110 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC2
]);
112 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Enabled
) {
113 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_NORMAL
]);
117 if (ctx
->VertexProgram
._Enabled
118 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC3
].Enabled
) {
119 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC3
]);
121 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Enabled
) {
122 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR0
]);
126 if (ctx
->VertexProgram
._Enabled
127 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC4
].Enabled
) {
128 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC4
]);
130 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Enabled
) {
131 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR1
]);
135 if (ctx
->VertexProgram
._Enabled
136 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC5
].Enabled
) {
137 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC5
]);
139 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
].Enabled
) {
140 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_FOG
]);
144 if (ctx
->VertexProgram
._Enabled
145 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC6
].Enabled
) {
146 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC6
]);
148 else if (arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Enabled
) {
149 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
]);
153 if (ctx
->VertexProgram
._Enabled
154 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC7
].Enabled
) {
155 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC7
]);
159 for (i
= 0; i
< VERT_ATTRIB_TEX_MAX
; i
++) {
160 if (ctx
->VertexProgram
._Enabled
161 && arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC8
+ i
].Enabled
) {
162 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC8
+ i
]);
164 else if (i
< ctx
->Const
.MaxTextureCoordUnits
165 && arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)].Enabled
) {
166 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(i
)]);
171 if (ctx
->VertexProgram
._Current
) {
172 for (i
= 0; i
< VERT_ATTRIB_GENERIC_MAX
; i
++) {
173 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)].Enabled
) {
174 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_GENERIC(i
)]);
179 if (arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Enabled
) {
180 min
= update_min(min
, &arrayObj
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
]);
183 /* _MaxElement is one past the last legal array element */
184 arrayObj
->_MaxElement
= min
;
189 * Update the following fields:
190 * ctx->VertexProgram._Enabled
191 * ctx->FragmentProgram._Enabled
192 * ctx->ATIFragmentShader._Enabled
193 * This needs to be done before texture state validation.
196 update_program_enables(struct gl_context
*ctx
)
198 /* These _Enabled flags indicate if the user-defined ARB/NV vertex/fragment
199 * program is enabled AND valid. Similarly for ATI fragment shaders.
200 * GLSL shaders not relevant here.
202 ctx
->VertexProgram
._Enabled
= ctx
->VertexProgram
.Enabled
203 && ctx
->VertexProgram
.Current
->Base
.Instructions
;
204 ctx
->FragmentProgram
._Enabled
= ctx
->FragmentProgram
.Enabled
205 && ctx
->FragmentProgram
.Current
->Base
.Instructions
;
206 ctx
->ATIFragmentShader
._Enabled
= ctx
->ATIFragmentShader
.Enabled
207 && ctx
->ATIFragmentShader
.Current
->Instructions
[0];
212 * Update the ctx->Vertex/Geometry/FragmentProgram._Current pointers to point
213 * to the current/active programs. Then call ctx->Driver.BindProgram() to
214 * tell the driver which programs to use.
216 * Programs may come from 3 sources: GLSL shaders, ARB/NV_vertex/fragment
217 * programs or programs derived from fixed-function state.
219 * This function needs to be called after texture state validation in case
220 * we're generating a fragment program from fixed-function texture state.
222 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
223 * or fragment program is being used.
226 update_program(struct gl_context
*ctx
)
228 const struct gl_shader_program
*vsProg
= ctx
->Shader
.CurrentVertexProgram
;
229 const struct gl_shader_program
*gsProg
= ctx
->Shader
.CurrentGeometryProgram
;
230 const struct gl_shader_program
*fsProg
= ctx
->Shader
.CurrentFragmentProgram
;
231 const struct gl_vertex_program
*prevVP
= ctx
->VertexProgram
._Current
;
232 const struct gl_fragment_program
*prevFP
= ctx
->FragmentProgram
._Current
;
233 const struct gl_geometry_program
*prevGP
= ctx
->GeometryProgram
._Current
;
234 GLbitfield new_state
= 0x0;
237 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
238 * pointers to the programs that should be used for rendering. If either
239 * is NULL, use fixed-function code paths.
241 * These programs may come from several sources. The priority is as
243 * 1. OpenGL 2.0/ARB vertex/fragment shaders
244 * 2. ARB/NV vertex/fragment programs
245 * 3. Programs derived from fixed-function state.
247 * Note: it's possible for a vertex shader to get used with a fragment
248 * program (and vice versa) here, but in practice that shouldn't ever
249 * come up, or matter.
252 if (fsProg
&& fsProg
->LinkStatus
253 && fsProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]) {
254 /* Use GLSL fragment shader */
255 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
256 (struct gl_fragment_program
*)
257 fsProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
);
259 else if (ctx
->FragmentProgram
._Enabled
) {
260 /* Use user-defined fragment program */
261 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
262 ctx
->FragmentProgram
.Current
);
264 else if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
265 /* Use fragment program generated from fixed-function state */
266 struct gl_shader_program
*f
= _mesa_get_fixed_func_fragment_program(ctx
);
268 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
,
269 (struct gl_fragment_program
*)
270 f
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
);
273 /* No fragment program */
274 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
._Current
, NULL
);
277 if (gsProg
&& gsProg
->LinkStatus
278 && gsProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]) {
279 /* Use GLSL geometry shader */
280 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
,
281 (struct gl_geometry_program
*)
282 gsProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]->Program
);
284 /* No geometry program */
285 _mesa_reference_geomprog(ctx
, &ctx
->GeometryProgram
._Current
, NULL
);
288 /* Examine vertex program after fragment program as
289 * _mesa_get_fixed_func_vertex_program() needs to know active
292 if (vsProg
&& vsProg
->LinkStatus
293 && vsProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]) {
294 /* Use GLSL vertex shader */
295 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
296 (struct gl_vertex_program
*)
297 vsProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->Program
);
299 else if (ctx
->VertexProgram
._Enabled
) {
300 /* Use user-defined vertex program */
301 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
302 ctx
->VertexProgram
.Current
);
304 else if (ctx
->VertexProgram
._MaintainTnlProgram
) {
305 /* Use vertex program generated from fixed-function state */
306 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
,
307 _mesa_get_fixed_func_vertex_program(ctx
));
308 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._TnlProgram
,
309 ctx
->VertexProgram
._Current
);
312 /* no vertex program */
313 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
._Current
, NULL
);
316 /* Let the driver know what's happening:
318 if (ctx
->FragmentProgram
._Current
!= prevFP
) {
319 new_state
|= _NEW_PROGRAM
;
320 if (ctx
->Driver
.BindProgram
) {
321 ctx
->Driver
.BindProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
322 (struct gl_program
*) ctx
->FragmentProgram
._Current
);
326 if (ctx
->GeometryProgram
._Current
!= prevGP
) {
327 new_state
|= _NEW_PROGRAM
;
328 if (ctx
->Driver
.BindProgram
) {
329 ctx
->Driver
.BindProgram(ctx
, MESA_GEOMETRY_PROGRAM
,
330 (struct gl_program
*) ctx
->GeometryProgram
._Current
);
334 if (ctx
->VertexProgram
._Current
!= prevVP
) {
335 new_state
|= _NEW_PROGRAM
;
336 if (ctx
->Driver
.BindProgram
) {
337 ctx
->Driver
.BindProgram(ctx
, GL_VERTEX_PROGRAM_ARB
,
338 (struct gl_program
*) ctx
->VertexProgram
._Current
);
347 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
350 update_program_constants(struct gl_context
*ctx
)
352 GLbitfield new_state
= 0x0;
354 if (ctx
->FragmentProgram
._Current
) {
355 const struct gl_program_parameter_list
*params
=
356 ctx
->FragmentProgram
._Current
->Base
.Parameters
;
357 if (params
&& params
->StateFlags
& ctx
->NewState
) {
358 new_state
|= _NEW_PROGRAM_CONSTANTS
;
362 if (ctx
->GeometryProgram
._Current
) {
363 const struct gl_program_parameter_list
*params
=
364 ctx
->GeometryProgram
._Current
->Base
.Parameters
;
365 /*FIXME: StateFlags is always 0 because we have unnamed constant
366 * not state changes */
367 if (params
/*&& params->StateFlags & ctx->NewState*/) {
368 new_state
|= _NEW_PROGRAM_CONSTANTS
;
372 if (ctx
->VertexProgram
._Current
) {
373 const struct gl_program_parameter_list
*params
=
374 ctx
->VertexProgram
._Current
->Base
.Parameters
;
375 if (params
&& params
->StateFlags
& ctx
->NewState
) {
376 new_state
|= _NEW_PROGRAM_CONSTANTS
;
387 update_viewport_matrix(struct gl_context
*ctx
)
389 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
391 ASSERT(depthMax
> 0);
393 /* Compute scale and bias values. This is really driver-specific
394 * and should be maintained elsewhere if at all.
395 * NOTE: RasterPos uses this.
397 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
398 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
399 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
400 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
406 * Update derived multisample state.
409 update_multisample(struct gl_context
*ctx
)
411 ctx
->Multisample
._Enabled
= GL_FALSE
;
412 if (ctx
->Multisample
.Enabled
&&
414 ctx
->DrawBuffer
->Visual
.sampleBuffers
)
415 ctx
->Multisample
._Enabled
= GL_TRUE
;
420 * Update the ctx->Color._ClampFragmentColor field
423 update_clamp_fragment_color(struct gl_context
*ctx
)
425 if (ctx
->Color
.ClampFragmentColor
== GL_FIXED_ONLY_ARB
)
426 ctx
->Color
._ClampFragmentColor
=
427 !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
429 ctx
->Color
._ClampFragmentColor
= ctx
->Color
.ClampFragmentColor
;
434 * Update the ctx->Color._ClampVertexColor field
437 update_clamp_vertex_color(struct gl_context
*ctx
)
439 if (ctx
->Light
.ClampVertexColor
== GL_FIXED_ONLY_ARB
)
440 ctx
->Light
._ClampVertexColor
=
441 !ctx
->DrawBuffer
|| !ctx
->DrawBuffer
->Visual
.floatMode
;
443 ctx
->Light
._ClampVertexColor
= ctx
->Light
.ClampVertexColor
;
448 * Update the ctx->Color._ClampReadColor field
451 update_clamp_read_color(struct gl_context
*ctx
)
453 if (ctx
->Color
.ClampReadColor
== GL_FIXED_ONLY_ARB
)
454 ctx
->Color
._ClampReadColor
=
455 !ctx
->ReadBuffer
|| !ctx
->ReadBuffer
->Visual
.floatMode
;
457 ctx
->Color
._ClampReadColor
= ctx
->Color
.ClampReadColor
;
461 * Update the ctx->VertexProgram._TwoSideEnabled flag.
464 update_twoside(struct gl_context
*ctx
)
466 if (ctx
->Shader
.CurrentVertexProgram
||
467 ctx
->VertexProgram
._Enabled
) {
468 ctx
->VertexProgram
._TwoSideEnabled
= ctx
->VertexProgram
.TwoSideEnabled
;
470 ctx
->VertexProgram
._TwoSideEnabled
= (ctx
->Light
.Enabled
&&
471 ctx
->Light
.Model
.TwoSide
);
477 * Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
478 * in ctx->_TriangleCaps if needed.
481 update_polygon(struct gl_context
*ctx
)
483 ctx
->_TriangleCaps
&= ~(DD_TRI_CULL_FRONT_BACK
| DD_TRI_OFFSET
);
485 if (ctx
->Polygon
.CullFlag
&& ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
486 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
488 if ( ctx
->Polygon
.OffsetPoint
489 || ctx
->Polygon
.OffsetLine
490 || ctx
->Polygon
.OffsetFill
)
491 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
496 * Update the ctx->_TriangleCaps bitfield.
497 * XXX that bitfield should really go away someday!
498 * This function must be called after other update_*() functions since
499 * there are dependencies on some other derived values.
503 update_tricaps(struct gl_context
*ctx
, GLbitfield new_state
)
505 ctx
->_TriangleCaps
= 0;
510 if (1/*new_state & _NEW_POINT*/) {
511 if (ctx
->Point
.SmoothFlag
)
512 ctx
->_TriangleCaps
|= DD_POINT_SMOOTH
;
513 if (ctx
->Point
._Attenuated
)
514 ctx
->_TriangleCaps
|= DD_POINT_ATTEN
;
520 if (1/*new_state & _NEW_LINE*/) {
521 if (ctx
->Line
.SmoothFlag
)
522 ctx
->_TriangleCaps
|= DD_LINE_SMOOTH
;
523 if (ctx
->Line
.StippleFlag
)
524 ctx
->_TriangleCaps
|= DD_LINE_STIPPLE
;
530 if (1/*new_state & _NEW_POLYGON*/) {
531 if (ctx
->Polygon
.SmoothFlag
)
532 ctx
->_TriangleCaps
|= DD_TRI_SMOOTH
;
533 if (ctx
->Polygon
.StippleFlag
)
534 ctx
->_TriangleCaps
|= DD_TRI_STIPPLE
;
535 if (ctx
->Polygon
.FrontMode
!= GL_FILL
536 || ctx
->Polygon
.BackMode
!= GL_FILL
)
537 ctx
->_TriangleCaps
|= DD_TRI_UNFILLED
;
538 if (ctx
->Polygon
.CullFlag
539 && ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
540 ctx
->_TriangleCaps
|= DD_TRI_CULL_FRONT_BACK
;
541 if (ctx
->Polygon
.OffsetPoint
||
542 ctx
->Polygon
.OffsetLine
||
543 ctx
->Polygon
.OffsetFill
)
544 ctx
->_TriangleCaps
|= DD_TRI_OFFSET
;
548 * Lighting and shading
550 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
551 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
552 if (ctx
->Light
.ShadeModel
== GL_FLAT
)
553 ctx
->_TriangleCaps
|= DD_FLATSHADE
;
554 if (_mesa_need_secondary_color(ctx
))
555 ctx
->_TriangleCaps
|= DD_SEPARATE_SPECULAR
;
560 if (ctx
->Stencil
._TestTwoSide
)
561 ctx
->_TriangleCaps
|= DD_TRI_TWOSTENCIL
;
567 * Compute derived GL state.
568 * If __struct gl_contextRec::NewState is non-zero then this function \b must
569 * be called before rendering anything.
571 * Calls dd_function_table::UpdateState to perform any internal state
572 * management necessary.
574 * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
575 * _mesa_update_buffer_bounds(),
576 * _mesa_update_lighting() and _mesa_update_tnl_spaces().
579 _mesa_update_state_locked( struct gl_context
*ctx
)
581 GLbitfield new_state
= ctx
->NewState
;
582 GLbitfield prog_flags
= _NEW_PROGRAM
;
583 GLbitfield new_prog_state
= 0x0;
585 if (new_state
== _NEW_CURRENT_ATTRIB
)
588 if (MESA_VERBOSE
& VERBOSE_STATE
)
589 _mesa_print_state("_mesa_update_state", new_state
);
591 /* Determine which state flags effect vertex/fragment program state */
592 if (ctx
->FragmentProgram
._MaintainTexEnvProgram
) {
593 prog_flags
|= (_NEW_BUFFERS
| _NEW_TEXTURE
| _NEW_FOG
|
594 _NEW_ARRAY
| _NEW_LIGHT
| _NEW_POINT
| _NEW_RENDERMODE
|
595 _NEW_PROGRAM
| _NEW_FRAG_CLAMP
| _NEW_COLOR
);
597 if (ctx
->VertexProgram
._MaintainTnlProgram
) {
598 prog_flags
|= (_NEW_ARRAY
| _NEW_TEXTURE
| _NEW_TEXTURE_MATRIX
|
599 _NEW_TRANSFORM
| _NEW_POINT
|
600 _NEW_FOG
| _NEW_LIGHT
|
601 _MESA_NEW_NEED_EYE_COORDS
);
605 * Now update derived state info
608 if (new_state
& prog_flags
)
609 update_program_enables( ctx
);
611 if (new_state
& (_NEW_MODELVIEW
|_NEW_PROJECTION
))
612 _mesa_update_modelview_project( ctx
, new_state
);
614 if (new_state
& (_NEW_PROGRAM
|_NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
))
615 _mesa_update_texture( ctx
, new_state
);
617 if (new_state
& _NEW_BUFFERS
)
618 _mesa_update_framebuffer(ctx
);
620 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
621 _mesa_update_draw_buffer_bounds( ctx
);
623 if (new_state
& _NEW_POLYGON
)
624 update_polygon( ctx
);
626 if (new_state
& _NEW_LIGHT
)
627 _mesa_update_lighting( ctx
);
629 if (new_state
& (_NEW_LIGHT
| _NEW_PROGRAM
))
630 update_twoside( ctx
);
632 if (new_state
& (_NEW_LIGHT
| _NEW_BUFFERS
))
633 update_clamp_vertex_color(ctx
);
635 if (new_state
& (_NEW_STENCIL
| _NEW_BUFFERS
))
636 _mesa_update_stencil( ctx
);
638 if (new_state
& _NEW_PIXEL
)
639 _mesa_update_pixel( ctx
, new_state
);
641 if (new_state
& _DD_NEW_SEPARATE_SPECULAR
)
642 update_separate_specular( ctx
);
644 if (new_state
& (_NEW_BUFFERS
| _NEW_VIEWPORT
))
645 update_viewport_matrix(ctx
);
647 if (new_state
& (_NEW_MULTISAMPLE
| _NEW_BUFFERS
))
648 update_multisample( ctx
);
650 if (new_state
& (_NEW_COLOR
| _NEW_BUFFERS
))
651 update_clamp_read_color(ctx
);
653 if(new_state
& (_NEW_FRAG_CLAMP
| _NEW_BUFFERS
))
654 update_clamp_fragment_color(ctx
);
657 if (new_state
& (_NEW_POINT
| _NEW_LINE
| _NEW_POLYGON
| _NEW_LIGHT
658 | _NEW_STENCIL
| _DD_NEW_SEPARATE_SPECULAR
))
659 update_tricaps( ctx
, new_state
);
662 /* ctx->_NeedEyeCoords is now up to date.
664 * If the truth value of this variable has changed, update for the
665 * new lighting space and recompute the positions of lights and the
668 * If the lighting space hasn't changed, may still need to recompute
669 * light positions & normal transforms for other reasons.
671 if (new_state
& _MESA_NEW_NEED_EYE_COORDS
)
672 _mesa_update_tnl_spaces( ctx
, new_state
);
674 if (new_state
& prog_flags
) {
675 /* When we generate programs from fixed-function vertex/fragment state
676 * this call may generate/bind a new program. If so, we need to
677 * propogate the _NEW_PROGRAM flag to the driver.
679 new_prog_state
|= update_program( ctx
);
682 if (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
| _NEW_BUFFER_OBJECT
))
683 update_arrays( ctx
);
686 new_prog_state
|= update_program_constants(ctx
);
689 * Give the driver a chance to act upon the new_state flags.
690 * The driver might plug in different span functions, for example.
691 * Also, this is where the driver can invalidate the state of any
692 * active modules (such as swrast_setup, swrast, tnl, etc).
694 * Set ctx->NewState to zero to avoid recursion if
695 * Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
697 new_state
= ctx
->NewState
| new_prog_state
;
699 ctx
->Driver
.UpdateState(ctx
, new_state
);
700 ctx
->Array
.NewState
= 0;
701 if (!ctx
->Array
.RebindArrays
)
702 ctx
->Array
.RebindArrays
= (new_state
& (_NEW_ARRAY
| _NEW_PROGRAM
)) != 0;
706 /* This is the usual entrypoint for state updates:
709 _mesa_update_state( struct gl_context
*ctx
)
711 _mesa_lock_context_textures(ctx
);
712 _mesa_update_state_locked(ctx
);
713 _mesa_unlock_context_textures(ctx
);
720 * Want to figure out which fragment program inputs are actually
721 * constant/current values from ctx->Current. These should be
722 * referenced as a tracked state variable rather than a fragment
723 * program input, to save the overhead of putting a constant value in
724 * every submitted vertex, transferring it to hardware, interpolating
725 * it across the triangle, etc...
727 * When there is a VP bound, just use vp->outputs. But when we're
728 * generating vp from fixed function state, basically want to
731 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
732 * potential_vp_outputs )
734 * Where potential_vp_outputs is calculated by looking at enabled
737 * The generated fragment program should then only declare inputs that
738 * may vary or otherwise differ from the ctx->Current values.
739 * Otherwise, the fp should track them as state values instead.
742 _mesa_set_varying_vp_inputs( struct gl_context
*ctx
,
743 GLbitfield64 varying_inputs
)
745 if (ctx
->varying_vp_inputs
!= varying_inputs
) {
746 ctx
->varying_vp_inputs
= varying_inputs
;
747 ctx
->NewState
|= _NEW_ARRAY
;
748 /*printf("%s %x\n", __FUNCTION__, varying_inputs);*/
754 * Used by drivers to tell core Mesa that the driver is going to
755 * install/ use its own vertex program. In particular, this will
756 * prevent generated fragment programs from using state vars instead
757 * of ordinary varyings/inputs.
760 _mesa_set_vp_override(struct gl_context
*ctx
, GLboolean flag
)
762 if (ctx
->VertexProgram
._Overriden
!= flag
) {
763 ctx
->VertexProgram
._Overriden
= flag
;
765 /* Set one of the bits which will trigger fragment program
768 ctx
->NewState
|= _NEW_PROGRAM
;