1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * 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 #include "vbo/vbo.h"
55 #include "viewport.h"
56 #include "blend.h"
57
58
59 void
_mesa_update_allow_draw_out_of_order(struct gl_context * ctx)60 _mesa_update_allow_draw_out_of_order(struct gl_context *ctx)
61 {
62 /* Out-of-order drawing is useful when vertex array draws and immediate
63 * mode are interleaved.
64 *
65 * Example with 3 draws:
66 * glBegin();
67 * glVertex();
68 * glEnd();
69 * glDrawElements();
70 * glBegin();
71 * glVertex();
72 * glEnd();
73 *
74 * Out-of-order drawing changes the execution order like this:
75 * glDrawElements();
76 * glBegin();
77 * glVertex();
78 * glVertex();
79 * glEnd();
80 *
81 * If out-of-order draws are enabled, immediate mode vertices are not
82 * flushed before glDrawElements, resulting in fewer draws and lower CPU
83 * overhead. This helps workstation applications.
84 *
85 * This is a simplified version of out-of-order determination to catch
86 * common cases.
87 *
88 * RadeonSI has a complete and more complicated out-of-order determination
89 * for driver-internal reasons.
90 */
91 /* Only the compatibility profile with immediate mode needs this. */
92 if (ctx->API != API_OPENGL_COMPAT || !ctx->Const.AllowDrawOutOfOrder)
93 return;
94
95 /* If all of these are NULL, GLSL is disabled. */
96 struct gl_program *vs =
97 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
98 struct gl_program *tcs =
99 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
100 struct gl_program *tes =
101 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
102 struct gl_program *gs =
103 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
104 struct gl_program *fs =
105 ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
106 GLenum16 depth_func = ctx->Depth.Func;
107
108 /* Z fighting and any primitives with equal Z shouldn't be reordered
109 * with LESS/LEQUAL/GREATER/GEQUAL functions.
110 *
111 * When drawing 2 primitive with equal Z:
112 * - with LEQUAL/GEQUAL, the last primitive wins the Z test.
113 * - with LESS/GREATER, the first primitive wins the Z test.
114 *
115 * Here we ignore that on the basis that such cases don't occur in real
116 * apps, and we they do occur, they occur with blending where out-of-order
117 * drawing is always disabled.
118 */
119 bool previous_state = ctx->_AllowDrawOutOfOrder;
120 ctx->_AllowDrawOutOfOrder =
121 ctx->DrawBuffer &&
122 ctx->DrawBuffer->Visual.depthBits &&
123 ctx->Depth.Test &&
124 ctx->Depth.Mask &&
125 (depth_func == GL_NEVER ||
126 depth_func == GL_LESS ||
127 depth_func == GL_LEQUAL ||
128 depth_func == GL_GREATER ||
129 depth_func == GL_GEQUAL) &&
130 (!ctx->DrawBuffer->Visual.stencilBits ||
131 !ctx->Stencil.Enabled) &&
132 (!ctx->Color.ColorMask ||
133 (!ctx->Color.BlendEnabled &&
134 (!ctx->Color.ColorLogicOpEnabled ||
135 ctx->Color._LogicOp == COLOR_LOGICOP_COPY))) &&
136 (!vs || !vs->info.writes_memory) &&
137 (!tes || !tes->info.writes_memory) &&
138 (!tcs || !tcs->info.writes_memory) &&
139 (!gs || !gs->info.writes_memory) &&
140 (!fs || !fs->info.writes_memory || !fs->info.fs.early_fragment_tests);
141
142 /* If we are disabling out-of-order drawing, we need to flush queued
143 * vertices.
144 */
145 if (previous_state && !ctx->_AllowDrawOutOfOrder)
146 FLUSH_VERTICES(ctx, 0);
147 }
148
149
150 /**
151 * Update the ctx->*Program._Current pointers to point to the
152 * current/active programs.
153 *
154 * Programs may come from 3 sources: GLSL shaders, ARB/NV_vertex/fragment
155 * programs or programs derived from fixed-function state.
156 *
157 * This function needs to be called after texture state validation in case
158 * we're generating a fragment program from fixed-function texture state.
159 *
160 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
161 * or fragment program is being used.
162 */
163 static GLbitfield
update_program(struct gl_context * ctx)164 update_program(struct gl_context *ctx)
165 {
166 struct gl_program *vsProg =
167 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
168 struct gl_program *tcsProg =
169 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
170 struct gl_program *tesProg =
171 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
172 struct gl_program *gsProg =
173 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
174 struct gl_program *fsProg =
175 ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
176 struct gl_program *csProg =
177 ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
178 const struct gl_program *prevVP = ctx->VertexProgram._Current;
179 const struct gl_program *prevFP = ctx->FragmentProgram._Current;
180 const struct gl_program *prevGP = ctx->GeometryProgram._Current;
181 const struct gl_program *prevTCP = ctx->TessCtrlProgram._Current;
182 const struct gl_program *prevTEP = ctx->TessEvalProgram._Current;
183 const struct gl_program *prevCP = ctx->ComputeProgram._Current;
184
185 /*
186 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
187 * pointers to the programs that should be used for rendering. If either
188 * is NULL, use fixed-function code paths.
189 *
190 * These programs may come from several sources. The priority is as
191 * follows:
192 * 1. OpenGL 2.0/ARB vertex/fragment shaders
193 * 2. ARB/NV vertex/fragment programs
194 * 3. ATI fragment shader
195 * 4. Programs derived from fixed-function state.
196 *
197 * Note: it's possible for a vertex shader to get used with a fragment
198 * program (and vice versa) here, but in practice that shouldn't ever
199 * come up, or matter.
200 */
201
202 if (fsProg) {
203 /* Use GLSL fragment shader */
204 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current, fsProg);
205 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
206 NULL);
207 }
208 else if (_mesa_arb_fragment_program_enabled(ctx)) {
209 /* Use user-defined fragment program */
210 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
211 ctx->FragmentProgram.Current);
212 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
213 NULL);
214 }
215 else if (_mesa_ati_fragment_shader_enabled(ctx) &&
216 ctx->ATIFragmentShader.Current->Program) {
217 /* Use the enabled ATI fragment shader's associated program */
218 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
219 ctx->ATIFragmentShader.Current->Program);
220 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
221 NULL);
222 }
223 else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
224 /* Use fragment program generated from fixed-function state */
225 struct gl_shader_program *f = _mesa_get_fixed_func_fragment_program(ctx);
226
227 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
228 f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
229 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
230 f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
231 }
232 else {
233 /* No fragment program */
234 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current, NULL);
235 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
236 NULL);
237 }
238
239 if (gsProg) {
240 /* Use GLSL geometry shader */
241 _mesa_reference_program(ctx, &ctx->GeometryProgram._Current, gsProg);
242 } else {
243 /* No geometry program */
244 _mesa_reference_program(ctx, &ctx->GeometryProgram._Current, NULL);
245 }
246
247 if (tesProg) {
248 /* Use GLSL tessellation evaluation shader */
249 _mesa_reference_program(ctx, &ctx->TessEvalProgram._Current, tesProg);
250 }
251 else {
252 /* No tessellation evaluation program */
253 _mesa_reference_program(ctx, &ctx->TessEvalProgram._Current, NULL);
254 }
255
256 if (tcsProg) {
257 /* Use GLSL tessellation control shader */
258 _mesa_reference_program(ctx, &ctx->TessCtrlProgram._Current, tcsProg);
259 }
260 else {
261 /* No tessellation control program */
262 _mesa_reference_program(ctx, &ctx->TessCtrlProgram._Current, NULL);
263 }
264
265 /* Examine vertex program after fragment program as
266 * _mesa_get_fixed_func_vertex_program() needs to know active
267 * fragprog inputs.
268 */
269 if (vsProg) {
270 /* Use GLSL vertex shader */
271 assert(VP_MODE_SHADER == ctx->VertexProgram._VPMode);
272 _mesa_reference_program(ctx, &ctx->VertexProgram._Current, vsProg);
273 }
274 else if (_mesa_arb_vertex_program_enabled(ctx)) {
275 /* Use user-defined vertex program */
276 assert(VP_MODE_SHADER == ctx->VertexProgram._VPMode);
277 _mesa_reference_program(ctx, &ctx->VertexProgram._Current,
278 ctx->VertexProgram.Current);
279 }
280 else if (ctx->VertexProgram._MaintainTnlProgram) {
281 /* Use vertex program generated from fixed-function state */
282 assert(VP_MODE_FF == ctx->VertexProgram._VPMode);
283 _mesa_reference_program(ctx, &ctx->VertexProgram._Current,
284 _mesa_get_fixed_func_vertex_program(ctx));
285 _mesa_reference_program(ctx, &ctx->VertexProgram._TnlProgram,
286 ctx->VertexProgram._Current);
287 }
288 else {
289 /* no vertex program */
290 assert(VP_MODE_FF == ctx->VertexProgram._VPMode);
291 _mesa_reference_program(ctx, &ctx->VertexProgram._Current, NULL);
292 }
293
294 if (csProg) {
295 /* Use GLSL compute shader */
296 _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, csProg);
297 } else {
298 /* no compute program */
299 _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, NULL);
300 }
301
302 /* Let the driver know what's happening:
303 */
304 if (ctx->FragmentProgram._Current != prevFP ||
305 ctx->VertexProgram._Current != prevVP ||
306 ctx->GeometryProgram._Current != prevGP ||
307 ctx->TessEvalProgram._Current != prevTEP ||
308 ctx->TessCtrlProgram._Current != prevTCP ||
309 ctx->ComputeProgram._Current != prevCP)
310 return _NEW_PROGRAM;
311
312 return 0;
313 }
314
315
316 static GLbitfield
update_single_program_constants(struct gl_context * ctx,struct gl_program * prog,gl_shader_stage stage)317 update_single_program_constants(struct gl_context *ctx,
318 struct gl_program *prog,
319 gl_shader_stage stage)
320 {
321 if (prog) {
322 const struct gl_program_parameter_list *params = prog->Parameters;
323 if (params && params->StateFlags & ctx->NewState) {
324 if (ctx->DriverFlags.NewShaderConstants[stage])
325 ctx->NewDriverState |= ctx->DriverFlags.NewShaderConstants[stage];
326 else
327 return _NEW_PROGRAM_CONSTANTS;
328 }
329 }
330 return 0;
331 }
332
333
334 /**
335 * This updates fixed-func state constants such as gl_ModelViewMatrix.
336 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
337 */
338 static GLbitfield
update_program_constants(struct gl_context * ctx)339 update_program_constants(struct gl_context *ctx)
340 {
341 GLbitfield new_state =
342 update_single_program_constants(ctx, ctx->VertexProgram._Current,
343 MESA_SHADER_VERTEX) |
344 update_single_program_constants(ctx, ctx->FragmentProgram._Current,
345 MESA_SHADER_FRAGMENT);
346
347 if (ctx->API == API_OPENGL_COMPAT &&
348 ctx->Const.GLSLVersionCompat >= 150) {
349 new_state |=
350 update_single_program_constants(ctx, ctx->GeometryProgram._Current,
351 MESA_SHADER_GEOMETRY);
352
353 if (_mesa_has_ARB_tessellation_shader(ctx)) {
354 new_state |=
355 update_single_program_constants(ctx, ctx->TessCtrlProgram._Current,
356 MESA_SHADER_TESS_CTRL) |
357 update_single_program_constants(ctx, ctx->TessEvalProgram._Current,
358 MESA_SHADER_TESS_EVAL);
359 }
360 }
361
362 return new_state;
363 }
364
365
366 static void
update_fixed_func_program_usage(struct gl_context * ctx)367 update_fixed_func_program_usage(struct gl_context *ctx)
368 {
369 ctx->FragmentProgram._UsesTexEnvProgram =
370 ctx->FragmentProgram._MaintainTexEnvProgram &&
371 !ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT] && /* GLSL*/
372 !_mesa_arb_fragment_program_enabled(ctx) &&
373 !(_mesa_ati_fragment_shader_enabled(ctx) &&
374 ctx->ATIFragmentShader.Current->Program);
375
376 ctx->VertexProgram._UsesTnlProgram =
377 ctx->VertexProgram._MaintainTnlProgram &&
378 !ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] && /* GLSL */
379 !_mesa_arb_vertex_program_enabled(ctx);
380 }
381
382
383 /**
384 * Compute derived GL state.
385 * If __struct gl_contextRec::NewState is non-zero then this function \b must
386 * be called before rendering anything.
387 *
388 * Calls dd_function_table::UpdateState to perform any internal state
389 * management necessary.
390 *
391 * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
392 * _mesa_update_buffer_bounds(),
393 * _mesa_update_lighting() and _mesa_update_tnl_spaces().
394 */
395 void
_mesa_update_state_locked(struct gl_context * ctx)396 _mesa_update_state_locked( struct gl_context *ctx )
397 {
398 GLbitfield new_state = ctx->NewState;
399 GLbitfield new_prog_state = 0x0;
400 const GLbitfield computed_states = ~(_NEW_CURRENT_ATTRIB | _NEW_LINE);
401
402 /* we can skip a bunch of state validation checks if the dirty
403 * state matches one or more bits in 'computed_states'.
404 */
405 if ((new_state & computed_states) == 0)
406 goto out;
407
408 if (MESA_VERBOSE & VERBOSE_STATE)
409 _mesa_print_state("_mesa_update_state", new_state);
410
411 if (new_state & _NEW_BUFFERS)
412 _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer);
413
414 /* Handle Core and Compatibility contexts separately. */
415 if (ctx->API == API_OPENGL_COMPAT ||
416 ctx->API == API_OPENGLES) {
417 GLbitfield prog_flags = _NEW_PROGRAM;
418
419 if (new_state & _NEW_PROGRAM)
420 update_fixed_func_program_usage(ctx);
421
422 /* Determine which states affect fixed-func vertex/fragment program. */
423 if (ctx->FragmentProgram._UsesTexEnvProgram) {
424 prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE_OBJECT | _NEW_FOG |
425 _NEW_VARYING_VP_INPUTS | _NEW_LIGHT | _NEW_POINT |
426 _NEW_RENDERMODE | _NEW_COLOR | _NEW_TEXTURE_STATE);
427 }
428
429 if (ctx->VertexProgram._UsesTnlProgram) {
430 prog_flags |= (_NEW_VARYING_VP_INPUTS | _NEW_TEXTURE_OBJECT |
431 _NEW_TEXTURE_MATRIX | _NEW_TRANSFORM | _NEW_POINT |
432 _NEW_FOG | _NEW_LIGHT | _NEW_TEXTURE_STATE |
433 _MESA_NEW_NEED_EYE_COORDS);
434 }
435
436 /*
437 * Now update derived state info
438 */
439 if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
440 _mesa_update_modelview_project( ctx, new_state );
441
442 if (new_state & _NEW_TEXTURE_MATRIX)
443 _mesa_update_texture_matrices(ctx);
444
445 if (new_state & (_NEW_TEXTURE_OBJECT | _NEW_TEXTURE_STATE | _NEW_PROGRAM))
446 _mesa_update_texture_state(ctx);
447
448 if (new_state & _NEW_LIGHT)
449 _mesa_update_lighting(ctx);
450
451 if (new_state & _NEW_PIXEL)
452 _mesa_update_pixel( ctx );
453
454 /* ctx->_NeedEyeCoords is now up to date.
455 *
456 * If the truth value of this variable has changed, update for the
457 * new lighting space and recompute the positions of lights and the
458 * normal transform.
459 *
460 * If the lighting space hasn't changed, may still need to recompute
461 * light positions & normal transforms for other reasons.
462 */
463 if (new_state & _MESA_NEW_NEED_EYE_COORDS)
464 _mesa_update_tnl_spaces( ctx, new_state );
465
466 if (new_state & prog_flags) {
467 /* When we generate programs from fixed-function vertex/fragment state
468 * this call may generate/bind a new program. If so, we need to
469 * propogate the _NEW_PROGRAM flag to the driver.
470 */
471 new_prog_state |= update_program(ctx);
472 }
473 } else {
474 /* GL Core and GLES 2/3 contexts */
475 if (new_state & (_NEW_TEXTURE_OBJECT | _NEW_PROGRAM))
476 _mesa_update_texture_state(ctx);
477
478 if (new_state & _NEW_PROGRAM)
479 update_program(ctx);
480 }
481
482 out:
483 new_prog_state |= update_program_constants(ctx);
484
485 ctx->NewState |= new_prog_state;
486
487 /*
488 * Give the driver a chance to act upon the new_state flags.
489 * The driver might plug in different span functions, for example.
490 * Also, this is where the driver can invalidate the state of any
491 * active modules (such as swrast_setup, swrast, tnl, etc).
492 */
493 ctx->Driver.UpdateState(ctx);
494 ctx->NewState = 0;
495 }
496
497
498 /* This is the usual entrypoint for state updates:
499 */
500 void
_mesa_update_state(struct gl_context * ctx)501 _mesa_update_state( struct gl_context *ctx )
502 {
503 _mesa_lock_context_textures(ctx);
504 _mesa_update_state_locked(ctx);
505 _mesa_unlock_context_textures(ctx);
506 }
507
508
509
510
511 /**
512 * Want to figure out which fragment program inputs are actually
513 * constant/current values from ctx->Current. These should be
514 * referenced as a tracked state variable rather than a fragment
515 * program input, to save the overhead of putting a constant value in
516 * every submitted vertex, transferring it to hardware, interpolating
517 * it across the triangle, etc...
518 *
519 * When there is a VP bound, just use vp->outputs. But when we're
520 * generating vp from fixed function state, basically want to
521 * calculate:
522 *
523 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
524 * potential_vp_outputs )
525 *
526 * Where potential_vp_outputs is calculated by looking at enabled
527 * texgen, etc.
528 *
529 * The generated fragment program should then only declare inputs that
530 * may vary or otherwise differ from the ctx->Current values.
531 * Otherwise, the fp should track them as state values instead.
532 */
533 static void
set_varying_vp_inputs(struct gl_context * ctx,GLbitfield varying_inputs)534 set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs)
535 {
536 /*
537 * The gl_context::varying_vp_inputs value is only used when in
538 * VP_MODE_FF mode.
539 */
540 if (VP_MODE_FF != ctx->VertexProgram._VPMode)
541 return;
542
543 /* Only fixed-func generated programs ever uses varying_vp_inputs. */
544 if (!ctx->VertexProgram._MaintainTnlProgram &&
545 !ctx->FragmentProgram._MaintainTexEnvProgram)
546 return;
547
548 if (ctx->varying_vp_inputs != varying_inputs) {
549 ctx->varying_vp_inputs = varying_inputs;
550 ctx->NewState |= _NEW_VARYING_VP_INPUTS;
551 }
552 }
553
554
555 /**
556 * Used by drivers to tell core Mesa that the driver is going to
557 * install/ use its own vertex program. In particular, this will
558 * prevent generated fragment programs from using state vars instead
559 * of ordinary varyings/inputs.
560 */
561 void
_mesa_set_vp_override(struct gl_context * ctx,GLboolean flag)562 _mesa_set_vp_override(struct gl_context *ctx, GLboolean flag)
563 {
564 if (ctx->VertexProgram._Overriden != flag) {
565 ctx->VertexProgram._Overriden = flag;
566
567 /* Set one of the bits which will trigger fragment program
568 * regeneration:
569 */
570 ctx->NewState |= _NEW_PROGRAM;
571 }
572 }
573
574
575 static void
set_vertex_processing_mode(struct gl_context * ctx,gl_vertex_processing_mode m)576 set_vertex_processing_mode(struct gl_context *ctx, gl_vertex_processing_mode m)
577 {
578 if (ctx->VertexProgram._VPMode == m)
579 return;
580
581 /* On change we may get new maps into the current values */
582 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
583
584 /* Finally memorize the value */
585 ctx->VertexProgram._VPMode = m;
586
587 /* Since we only track the varying inputs while being in fixed function
588 * vertex processing mode, we may need to recheck for the
589 * _NEW_VARYING_VP_INPUTS bit.
590 */
591 set_varying_vp_inputs(ctx, ctx->Array._DrawVAOEnabledAttribs);
592 }
593
594
595 /**
596 * Update ctx->VertexProgram._VPMode.
597 * This is to distinguish whether we're running
598 * a vertex program/shader,
599 * a fixed-function TNL program or
600 * a fixed function vertex transformation without any program.
601 */
602 void
_mesa_update_vertex_processing_mode(struct gl_context * ctx)603 _mesa_update_vertex_processing_mode(struct gl_context *ctx)
604 {
605 if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX])
606 set_vertex_processing_mode(ctx, VP_MODE_SHADER);
607 else if (_mesa_arb_vertex_program_enabled(ctx))
608 set_vertex_processing_mode(ctx, VP_MODE_SHADER);
609 else
610 set_vertex_processing_mode(ctx, VP_MODE_FF);
611 }
612
613
614 /**
615 * Set the _DrawVAO and the net enabled arrays.
616 * The vao->_Enabled bitmask is transformed due to position/generic0
617 * as stored in vao->_AttributeMapMode. Then the filter bitmask is applied
618 * to filter out arrays unwanted for the currently executed draw operation.
619 * For example, the generic attributes are masked out form the _DrawVAO's
620 * enabled arrays when a fixed function array draw is executed.
621 */
622 void
_mesa_set_draw_vao(struct gl_context * ctx,struct gl_vertex_array_object * vao,GLbitfield filter)623 _mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao,
624 GLbitfield filter)
625 {
626 struct gl_vertex_array_object **ptr = &ctx->Array._DrawVAO;
627 bool new_array = false;
628 if (*ptr != vao) {
629 _mesa_reference_vao_(ctx, ptr, vao);
630
631 new_array = true;
632 }
633
634 if (vao->NewArrays) {
635 _mesa_update_vao_derived_arrays(ctx, vao);
636 vao->NewArrays = 0;
637
638 new_array = true;
639 }
640
641 /* May shuffle the position and generic0 bits around, filter out unwanted */
642 const GLbitfield enabled = filter & _mesa_get_vao_vp_inputs(vao);
643 if (ctx->Array._DrawVAOEnabledAttribs != enabled)
644 new_array = true;
645
646 if (new_array)
647 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
648
649 ctx->Array._DrawVAOEnabledAttribs = enabled;
650 set_varying_vp_inputs(ctx, enabled);
651 }
652