1848b8605Smrg/* 2848b8605Smrg * Mesa 3-D graphics library 3848b8605Smrg * 4848b8605Smrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the "Software"), 8848b8605Smrg * to deal in the Software without restriction, including without limitation 9848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 11848b8605Smrg * Software is furnished to do so, subject to the following conditions: 12848b8605Smrg * 13848b8605Smrg * The above copyright notice and this permission notice shall be included 14848b8605Smrg * in all copies or substantial portions of the Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg 26848b8605Smrg#ifndef STATE_H 27848b8605Smrg#define STATE_H 28848b8605Smrg 29848b8605Smrg#include "mtypes.h" 30848b8605Smrg 31848b8605Smrgextern void 32848b8605Smrg_mesa_update_state(struct gl_context *ctx); 33848b8605Smrg 34848b8605Smrg/* As above but can only be called between _mesa_lock_context_textures() and 35848b8605Smrg * _mesa_unlock_context_textures(). 36848b8605Smrg */ 37848b8605Smrgextern void 38848b8605Smrg_mesa_update_state_locked(struct gl_context *ctx); 39848b8605Smrg 40848b8605Smrg 41848b8605Smrgextern void 42b8e80941Smrg_mesa_set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs); 43848b8605Smrg 44848b8605Smrg 45848b8605Smrgextern void 46848b8605Smrg_mesa_set_vp_override(struct gl_context *ctx, GLboolean flag); 47848b8605Smrg 48848b8605Smrg 49b8e80941Smrg/** 50b8e80941Smrg * Update ctx->VertexProgram._VertexProgramMode. 51b8e80941Smrg */ 52b8e80941Smrgextern void 53b8e80941Smrg_mesa_update_vertex_processing_mode(struct gl_context *ctx); 54b8e80941Smrg 55b8e80941Smrg 56b8e80941Smrg/** 57b8e80941Smrg * Set the _DrawVAO and the net enabled arrays. 58b8e80941Smrg */ 59b8e80941Smrgvoid 60b8e80941Smrg_mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao, 61b8e80941Smrg GLbitfield filter); 62b8e80941Smrg 63b8e80941Smrg 64b8e80941Smrgstatic inline bool 65b8e80941Smrg_mesa_ati_fragment_shader_enabled(const struct gl_context *ctx) 66b8e80941Smrg{ 67b8e80941Smrg return ctx->ATIFragmentShader.Enabled && 68b8e80941Smrg ctx->ATIFragmentShader.Current->Instructions[0]; 69b8e80941Smrg} 70b8e80941Smrg 71848b8605Smrg/** 72848b8605Smrg * Is the secondary color needed? 73848b8605Smrg */ 74848b8605Smrgstatic inline GLboolean 75848b8605Smrg_mesa_need_secondary_color(const struct gl_context *ctx) 76848b8605Smrg{ 77848b8605Smrg if (ctx->Light.Enabled && 78848b8605Smrg ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) 79848b8605Smrg return GL_TRUE; 80848b8605Smrg 81848b8605Smrg if (ctx->Fog.ColorSumEnabled) 82848b8605Smrg return GL_TRUE; 83848b8605Smrg 84848b8605Smrg if (ctx->VertexProgram._Current && 85848b8605Smrg (ctx->VertexProgram._Current != ctx->VertexProgram._TnlProgram) && 86b8e80941Smrg (ctx->VertexProgram._Current->info.inputs_read & VERT_BIT_COLOR1)) 87848b8605Smrg return GL_TRUE; 88848b8605Smrg 89848b8605Smrg if (ctx->FragmentProgram._Current && 90848b8605Smrg (ctx->FragmentProgram._Current != ctx->FragmentProgram._TexEnvProgram) && 91b8e80941Smrg (ctx->FragmentProgram._Current->info.inputs_read & VARYING_BIT_COL1)) 92b8e80941Smrg return GL_TRUE; 93b8e80941Smrg 94b8e80941Smrg if (_mesa_ati_fragment_shader_enabled(ctx)) 95848b8605Smrg return GL_TRUE; 96848b8605Smrg 97848b8605Smrg return GL_FALSE; 98848b8605Smrg} 99848b8605Smrg 100b8e80941Smrgstatic inline bool 101b8e80941Smrg_mesa_arb_vertex_program_enabled(const struct gl_context *ctx) 102b8e80941Smrg{ 103b8e80941Smrg return ctx->VertexProgram.Enabled && 104b8e80941Smrg ctx->VertexProgram.Current->arb.Instructions; 105b8e80941Smrg} 106b8e80941Smrg 107b8e80941Smrg/** Compute two sided lighting state for fixed function or programs. */ 108b8e80941Smrgstatic inline bool 109b8e80941Smrg_mesa_vertex_program_two_side_enabled(const struct gl_context *ctx) 110b8e80941Smrg{ 111b8e80941Smrg if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] || 112b8e80941Smrg _mesa_arb_vertex_program_enabled(ctx)) 113b8e80941Smrg return ctx->VertexProgram.TwoSideEnabled; 114b8e80941Smrg 115b8e80941Smrg return ctx->Light.Enabled && ctx->Light.Model.TwoSide; 116b8e80941Smrg} 117b8e80941Smrg 118b8e80941Smrg/** Return 0=GL_CCW or 1=GL_CW */ 119b8e80941Smrgstatic inline bool 120b8e80941Smrg_mesa_polygon_get_front_bit(const struct gl_context *ctx) 121b8e80941Smrg{ 122b8e80941Smrg if (ctx->Transform.ClipOrigin == GL_LOWER_LEFT) 123b8e80941Smrg return ctx->Polygon.FrontFace == GL_CW; 124b8e80941Smrg 125b8e80941Smrg return ctx->Polygon.FrontFace == GL_CCW; 126b8e80941Smrg} 127b8e80941Smrg 128b8e80941Smrgstatic inline bool 129b8e80941Smrg_mesa_arb_fragment_program_enabled(const struct gl_context *ctx) 130b8e80941Smrg{ 131b8e80941Smrg return ctx->FragmentProgram.Enabled && 132b8e80941Smrg ctx->FragmentProgram.Current->arb.Instructions; 133b8e80941Smrg} 134b8e80941Smrg 135848b8605Smrg#endif 136