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