1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef STATE_H
27bf215546Sopenharmony_ci#define STATE_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "mtypes.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ciextern void
32bf215546Sopenharmony_ci_mesa_update_allow_draw_out_of_order(struct gl_context *ctx);
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ciextern void
35bf215546Sopenharmony_ci_mesa_update_state(struct gl_context *ctx);
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci/* As above but can only be called between _mesa_lock_context_textures() and
38bf215546Sopenharmony_ci * _mesa_unlock_context_textures().
39bf215546Sopenharmony_ci */
40bf215546Sopenharmony_ciextern void
41bf215546Sopenharmony_ci_mesa_update_state_locked(struct gl_context *ctx);
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ciextern void
45bf215546Sopenharmony_ci_mesa_set_vp_override(struct gl_context *ctx, GLboolean flag);
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci/**
49bf215546Sopenharmony_ci * Update ctx->VertexProgram._VPMode.
50bf215546Sopenharmony_ci */
51bf215546Sopenharmony_ciextern void
52bf215546Sopenharmony_ci_mesa_update_vertex_processing_mode(struct gl_context *ctx);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ciextern void
55bf215546Sopenharmony_ci_mesa_reset_vertex_processing_mode(struct gl_context *ctx);
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cistatic inline bool
59bf215546Sopenharmony_ci_mesa_ati_fragment_shader_enabled(const struct gl_context *ctx)
60bf215546Sopenharmony_ci{
61bf215546Sopenharmony_ci   return ctx->ATIFragmentShader.Enabled &&
62bf215546Sopenharmony_ci          ctx->ATIFragmentShader.Current->Instructions[0];
63bf215546Sopenharmony_ci}
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci/**
66bf215546Sopenharmony_ci * Is the secondary color needed?
67bf215546Sopenharmony_ci */
68bf215546Sopenharmony_cistatic inline GLboolean
69bf215546Sopenharmony_ci_mesa_need_secondary_color(const struct gl_context *ctx)
70bf215546Sopenharmony_ci{
71bf215546Sopenharmony_ci   if (ctx->Light.Enabled &&
72bf215546Sopenharmony_ci       ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
73bf215546Sopenharmony_ci       return GL_TRUE;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   if (ctx->Fog.ColorSumEnabled)
76bf215546Sopenharmony_ci      return GL_TRUE;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   if (ctx->VertexProgram._Current &&
79bf215546Sopenharmony_ci       (ctx->VertexProgram._Current != ctx->VertexProgram._TnlProgram) &&
80bf215546Sopenharmony_ci       (ctx->VertexProgram._Current->info.inputs_read & VERT_BIT_COLOR1))
81bf215546Sopenharmony_ci      return GL_TRUE;
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   if (ctx->FragmentProgram._Current &&
84bf215546Sopenharmony_ci       (ctx->FragmentProgram._Current != ctx->FragmentProgram._TexEnvProgram) &&
85bf215546Sopenharmony_ci       (ctx->FragmentProgram._Current->info.inputs_read & VARYING_BIT_COL1))
86bf215546Sopenharmony_ci      return GL_TRUE;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   if (_mesa_ati_fragment_shader_enabled(ctx))
89bf215546Sopenharmony_ci      return GL_TRUE;
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci   return GL_FALSE;
92bf215546Sopenharmony_ci}
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_cistatic inline bool
95bf215546Sopenharmony_ci_mesa_arb_vertex_program_enabled(const struct gl_context *ctx)
96bf215546Sopenharmony_ci{
97bf215546Sopenharmony_ci   return ctx->VertexProgram.Enabled &&
98bf215546Sopenharmony_ci          ctx->VertexProgram.Current->arb.Instructions;
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci/** Compute two sided lighting state for fixed function or programs. */
102bf215546Sopenharmony_cistatic inline bool
103bf215546Sopenharmony_ci_mesa_vertex_program_two_side_enabled(const struct gl_context *ctx)
104bf215546Sopenharmony_ci{
105bf215546Sopenharmony_ci   if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] ||
106bf215546Sopenharmony_ci       _mesa_arb_vertex_program_enabled(ctx))
107bf215546Sopenharmony_ci      return ctx->VertexProgram.TwoSideEnabled;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   return ctx->Light.Enabled && ctx->Light.Model.TwoSide;
110bf215546Sopenharmony_ci}
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci/** Return 0=GL_CCW or 1=GL_CW */
113bf215546Sopenharmony_cistatic inline bool
114bf215546Sopenharmony_ci_mesa_polygon_get_front_bit(const struct gl_context *ctx)
115bf215546Sopenharmony_ci{
116bf215546Sopenharmony_ci   if (ctx->Transform.ClipOrigin == GL_LOWER_LEFT)
117bf215546Sopenharmony_ci      return ctx->Polygon.FrontFace == GL_CW;
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   return ctx->Polygon.FrontFace == GL_CCW;
120bf215546Sopenharmony_ci}
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_cistatic inline bool
123bf215546Sopenharmony_ci_mesa_arb_fragment_program_enabled(const struct gl_context *ctx)
124bf215546Sopenharmony_ci{
125bf215546Sopenharmony_ci   return ctx->FragmentProgram.Enabled &&
126bf215546Sopenharmony_ci          ctx->FragmentProgram.Current->arb.Instructions;
127bf215546Sopenharmony_ci}
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci#endif
130