2000-02-02 19:15:19 +00:00
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
2008-10-10 13:39:14 -06:00
|
|
|
* Version: 7.3
|
2000-02-02 19:15:19 +00:00
|
|
|
*
|
2008-06-09 14:22:15 -06:00
|
|
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
2000-02-02 19:15:19 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-04-23 14:16:46 +00:00
|
|
|
/**
|
|
|
|
* \file state.c
|
|
|
|
* State management.
|
|
|
|
*
|
2008-06-09 14:49:04 -06:00
|
|
|
* This file manages recalculation of derived values in GLcontext.
|
2004-04-23 14:16:46 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-09 14:49:04 -06:00
|
|
|
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "glheader.h"
|
2008-06-09 14:49:04 -06:00
|
|
|
#include "mtypes.h"
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "context.h"
|
2008-06-09 14:49:04 -06:00
|
|
|
#include "debug.h"
|
|
|
|
#include "macros.h"
|
2008-09-20 08:26:11 -07:00
|
|
|
#include "ffvertex_prog.h"
|
2005-05-04 20:11:35 +00:00
|
|
|
#include "framebuffer.h"
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "light.h"
|
|
|
|
#include "matrix.h"
|
2008-09-21 19:29:15 -07:00
|
|
|
#if FEATURE_pixel_transfer
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "pixel.h"
|
2008-09-21 19:29:15 -07:00
|
|
|
#endif
|
2008-06-09 14:49:04 -06:00
|
|
|
#include "shader/program.h"
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "state.h"
|
|
|
|
#include "stencil.h"
|
2008-06-09 14:49:04 -06:00
|
|
|
#include "texenvprogram.h"
|
2000-02-02 19:15:19 +00:00
|
|
|
#include "texobj.h"
|
|
|
|
#include "texstate.h"
|
2000-11-19 23:10:25 +00:00
|
|
|
|
2000-11-13 20:02:56 +00:00
|
|
|
|
2007-09-27 10:24:17 -06:00
|
|
|
static void
|
|
|
|
update_separate_specular(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
if (NEED_SECONDARY_COLOR(ctx))
|
|
|
|
ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
|
|
|
|
else
|
|
|
|
ctx->_TriangleCaps &= ~DD_SEPARATE_SPECULAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-10 19:08:37 +00:00
|
|
|
/**
|
|
|
|
* Update state dependent on vertex arrays.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_arrays( GLcontext *ctx )
|
|
|
|
{
|
|
|
|
GLuint i, min;
|
|
|
|
|
|
|
|
/* find min of _MaxElement values for all enabled arrays */
|
|
|
|
|
|
|
|
/* 0 */
|
2006-12-15 10:07:26 -07:00
|
|
|
if (ctx->VertexProgram._Current
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) {
|
|
|
|
min = ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS]._MaxElement;
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->Vertex.Enabled) {
|
|
|
|
min = ctx->Array.ArrayObj->Vertex._MaxElement;
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* can't draw anything without vertex positions! */
|
|
|
|
min = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 1 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_WEIGHT]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
/* no conventional vertex weight array */
|
|
|
|
|
|
|
|
/* 2 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->Normal.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->Normal._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 3 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->Color.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->Color._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 4 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR1]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->SecondaryColor.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->SecondaryColor._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 5 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_FOG]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->FogCoord.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->FogCoord._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 6 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_COLOR_INDEX]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
else if (ctx->Array.ArrayObj->Index.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->Index._MaxElement);
|
2006-04-25 00:53:25 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 19:08:37 +00:00
|
|
|
|
|
|
|
/* 7 */
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-10-30 20:16:35 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_EDGEFLAG]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 8..15 */
|
2006-04-11 11:41:11 +00:00
|
|
|
for (i = VERT_ATTRIB_TEX0; i <= VERT_ATTRIB_TEX7; i++) {
|
2004-04-23 14:16:46 +00:00
|
|
|
if (ctx->VertexProgram._Enabled
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->VertexAttrib[i].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[i]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
else if (i - VERT_ATTRIB_TEX0 < ctx->Const.MaxTextureCoordUnits
|
2006-06-12 16:26:29 +00:00
|
|
|
&& ctx->Array.ArrayObj->TexCoord[i - VERT_ATTRIB_TEX0].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->TexCoord[i - VERT_ATTRIB_TEX0]._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-11 11:41:11 +00:00
|
|
|
/* 16..31 */
|
2006-12-15 10:07:26 -07:00
|
|
|
if (ctx->VertexProgram._Current) {
|
2006-04-11 11:41:11 +00:00
|
|
|
for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
|
2006-06-12 16:26:29 +00:00
|
|
|
if (ctx->Array.ArrayObj->VertexAttrib[i].Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[i]._MaxElement);
|
2006-04-11 11:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
if (ctx->Array.ArrayObj->EdgeFlag.Enabled) {
|
|
|
|
min = MIN2(min, ctx->Array.ArrayObj->EdgeFlag._MaxElement);
|
2003-11-10 19:08:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* _MaxElement is one past the last legal array element */
|
|
|
|
ctx->Array._MaxElement = min;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 16:28:25 -07:00
|
|
|
/**
|
|
|
|
* Update the following fields:
|
|
|
|
* ctx->VertexProgram._Enabled
|
|
|
|
* ctx->FragmentProgram._Enabled
|
|
|
|
* ctx->ATIFragmentShader._Enabled
|
|
|
|
* This needs to be done before texture state validation.
|
|
|
|
*/
|
2004-04-23 14:16:46 +00:00
|
|
|
static void
|
2009-02-10 16:28:25 -07:00
|
|
|
update_program_enables(GLcontext *ctx)
|
2004-04-23 14:16:46 +00:00
|
|
|
{
|
2006-12-15 10:07:26 -07:00
|
|
|
/* These _Enabled flags indicate if the program is enabled AND valid. */
|
2004-04-23 14:16:46 +00:00
|
|
|
ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled
|
2005-11-12 17:53:14 +00:00
|
|
|
&& ctx->VertexProgram.Current->Base.Instructions;
|
2004-04-23 14:16:46 +00:00
|
|
|
ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled
|
2005-11-12 17:53:14 +00:00
|
|
|
&& ctx->FragmentProgram.Current->Base.Instructions;
|
2004-12-19 03:06:59 +00:00
|
|
|
ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled
|
2008-04-01 23:24:11 +02:00
|
|
|
&& ctx->ATIFragmentShader.Current->Instructions[0];
|
2009-02-10 16:28:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update vertex/fragment program state. In particular, update these fields:
|
|
|
|
* ctx->VertexProgram._Current
|
|
|
|
* ctx->VertexProgram._TnlProgram,
|
|
|
|
* These point to the highest priority enabled vertex/fragment program or are
|
|
|
|
* NULL if fixed-function processing is to be done.
|
|
|
|
*
|
|
|
|
* This function needs to be called after texture state validation in case
|
|
|
|
* we're generating a fragment program from fixed-function texture state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_program(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
const struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
|
|
|
|
const struct gl_vertex_program *prevVP = ctx->VertexProgram._Current;
|
|
|
|
const struct gl_fragment_program *prevFP = ctx->FragmentProgram._Current;
|
2005-05-04 11:44:44 +00:00
|
|
|
|
2006-12-15 10:07:26 -07:00
|
|
|
/*
|
|
|
|
* Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
|
2008-12-17 18:05:03 -07:00
|
|
|
* pointers to the programs that should be used for rendering. If either
|
|
|
|
* is NULL, use fixed-function code paths.
|
2006-12-15 10:07:26 -07:00
|
|
|
*
|
|
|
|
* These programs may come from several sources. The priority is as
|
|
|
|
* follows:
|
|
|
|
* 1. OpenGL 2.0/ARB vertex/fragment shaders
|
|
|
|
* 2. ARB/NV vertex/fragment programs
|
|
|
|
* 3. Programs derived from fixed-function state.
|
2008-09-20 08:26:11 -07:00
|
|
|
*
|
|
|
|
* Note: it's possible for a vertex shader to get used with a fragment
|
|
|
|
* program (and vice versa) here, but in practice that shouldn't ever
|
|
|
|
* come up, or matter.
|
2006-12-15 10:07:26 -07:00
|
|
|
*/
|
|
|
|
|
2008-11-13 13:16:03 +00:00
|
|
|
if (shProg && shProg->LinkStatus && shProg->FragmentProgram) {
|
2006-12-15 10:07:26 -07:00
|
|
|
/* Use shader programs */
|
2008-05-06 23:08:51 -06:00
|
|
|
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
|
|
|
|
shProg->FragmentProgram);
|
2006-12-15 10:07:26 -07:00
|
|
|
}
|
2008-11-13 13:16:03 +00:00
|
|
|
else if (ctx->FragmentProgram._Enabled) {
|
|
|
|
/* use user-defined vertex program */
|
|
|
|
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
|
|
|
|
ctx->FragmentProgram.Current);
|
|
|
|
}
|
|
|
|
else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
|
|
|
|
/* Use fragment program generated from fixed-function state.
|
|
|
|
*/
|
|
|
|
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
|
|
|
|
_mesa_get_fixed_func_fragment_program(ctx));
|
|
|
|
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
|
|
|
|
ctx->FragmentProgram._Current);
|
|
|
|
}
|
2006-12-15 10:07:26 -07:00
|
|
|
else {
|
2008-11-13 13:16:03 +00:00
|
|
|
/* no fragment program */
|
|
|
|
_mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
|
|
|
|
}
|
2008-09-20 08:26:11 -07:00
|
|
|
|
2008-11-13 13:16:03 +00:00
|
|
|
/* Examine vertex program after fragment program as
|
|
|
|
* _mesa_get_fixed_func_vertex_program() needs to know active
|
|
|
|
* fragprog inputs.
|
|
|
|
*/
|
|
|
|
if (shProg && shProg->LinkStatus && shProg->VertexProgram) {
|
|
|
|
/* Use shader programs */
|
|
|
|
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
|
|
|
|
shProg->VertexProgram);
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram._Enabled) {
|
|
|
|
/* use user-defined vertex program */
|
|
|
|
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
|
|
|
|
ctx->VertexProgram.Current);
|
|
|
|
}
|
|
|
|
else if (ctx->VertexProgram._MaintainTnlProgram) {
|
|
|
|
/* Use vertex program generated from fixed-function state.
|
2008-09-20 08:26:11 -07:00
|
|
|
*/
|
2008-11-13 13:16:03 +00:00
|
|
|
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
|
|
|
|
_mesa_get_fixed_func_vertex_program(ctx));
|
|
|
|
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram,
|
|
|
|
ctx->VertexProgram._Current);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* no vertex program */
|
|
|
|
_mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
|
2005-05-04 11:44:44 +00:00
|
|
|
}
|
2007-03-27 09:51:52 -06:00
|
|
|
|
2008-09-20 08:26:11 -07:00
|
|
|
/* Let the driver know what's happening:
|
|
|
|
*/
|
|
|
|
if (ctx->FragmentProgram._Current != prevFP && ctx->Driver.BindProgram) {
|
|
|
|
ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
(struct gl_program *) ctx->FragmentProgram._Current);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->VertexProgram._Current != prevVP && ctx->Driver.BindProgram) {
|
|
|
|
ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB,
|
|
|
|
(struct gl_program *) ctx->VertexProgram._Current);
|
|
|
|
}
|
2004-04-23 14:16:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 19:08:37 +00:00
|
|
|
|
2006-03-29 03:59:34 +00:00
|
|
|
static void
|
|
|
|
update_viewport_matrix(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
|
|
|
|
|
|
|
|
ASSERT(depthMax > 0);
|
|
|
|
|
|
|
|
/* Compute scale and bias values. This is really driver-specific
|
|
|
|
* and should be maintained elsewhere if at all.
|
|
|
|
* NOTE: RasterPos uses this.
|
|
|
|
*/
|
|
|
|
_math_matrix_viewport(&ctx->Viewport._WindowMap,
|
|
|
|
ctx->Viewport.X, ctx->Viewport.Y,
|
|
|
|
ctx->Viewport.Width, ctx->Viewport.Height,
|
|
|
|
ctx->Viewport.Near, ctx->Viewport.Far,
|
|
|
|
depthMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-02 20:20:33 +02:00
|
|
|
/**
|
|
|
|
* Update derived multisample state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_multisample(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
ctx->Multisample._Enabled = GL_FALSE;
|
2008-09-15 17:10:04 -06:00
|
|
|
if (ctx->Multisample.Enabled &&
|
|
|
|
ctx->DrawBuffer &&
|
|
|
|
ctx->DrawBuffer->Visual.sampleBuffers)
|
|
|
|
ctx->Multisample._Enabled = GL_TRUE;
|
2008-07-02 20:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 19:15:40 +00:00
|
|
|
/**
|
|
|
|
* Update derived color/blend/logicop state.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_color(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
/* This is needed to support 1.1's RGB logic ops AND
|
|
|
|
* 1.0's blending logicops.
|
|
|
|
*/
|
2006-11-02 17:49:47 +00:00
|
|
|
ctx->Color._LogicOpEnabled = RGBA_LOGICOP_ENABLED(ctx);
|
2006-07-18 19:15:40 +00:00
|
|
|
}
|
|
|
|
|
2006-03-29 03:59:34 +00:00
|
|
|
|
2007-09-27 10:24:17 -06:00
|
|
|
/*
|
|
|
|
* Check polygon state and set DD_TRI_CULL_FRONT_BACK and/or DD_TRI_OFFSET
|
|
|
|
* in ctx->_TriangleCaps if needed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_polygon(GLcontext *ctx)
|
|
|
|
{
|
|
|
|
ctx->_TriangleCaps &= ~(DD_TRI_CULL_FRONT_BACK | DD_TRI_OFFSET);
|
|
|
|
|
|
|
|
if (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
|
|
|
|
|
|
|
|
if ( ctx->Polygon.OffsetPoint
|
|
|
|
|| ctx->Polygon.OffsetLine
|
|
|
|
|| ctx->Polygon.OffsetFill)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_OFFSET;
|
|
|
|
}
|
|
|
|
|
2006-12-15 10:07:26 -07:00
|
|
|
|
2005-02-26 17:16:12 +00:00
|
|
|
/**
|
2006-12-13 15:31:14 -07:00
|
|
|
* Update the ctx->_TriangleCaps bitfield.
|
|
|
|
* XXX that bitfield should really go away someday!
|
|
|
|
* This function must be called after other update_*() functions since
|
|
|
|
* there are dependencies on some other derived values.
|
|
|
|
*/
|
2007-09-27 10:24:17 -06:00
|
|
|
#if 0
|
2006-12-13 15:31:14 -07:00
|
|
|
static void
|
|
|
|
update_tricaps(GLcontext *ctx, GLbitfield new_state)
|
|
|
|
{
|
|
|
|
ctx->_TriangleCaps = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Points
|
|
|
|
*/
|
2007-04-26 10:45:44 -06:00
|
|
|
if (1/*new_state & _NEW_POINT*/) {
|
2006-12-13 15:31:14 -07:00
|
|
|
if (ctx->Point.SmoothFlag)
|
|
|
|
ctx->_TriangleCaps |= DD_POINT_SMOOTH;
|
2007-07-21 10:06:18 -06:00
|
|
|
if (ctx->Point.Size != 1.0F)
|
2006-12-13 15:31:14 -07:00
|
|
|
ctx->_TriangleCaps |= DD_POINT_SIZE;
|
|
|
|
if (ctx->Point._Attenuated)
|
|
|
|
ctx->_TriangleCaps |= DD_POINT_ATTEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lines
|
|
|
|
*/
|
2007-04-26 10:45:44 -06:00
|
|
|
if (1/*new_state & _NEW_LINE*/) {
|
2006-12-13 15:31:14 -07:00
|
|
|
if (ctx->Line.SmoothFlag)
|
|
|
|
ctx->_TriangleCaps |= DD_LINE_SMOOTH;
|
|
|
|
if (ctx->Line.StippleFlag)
|
|
|
|
ctx->_TriangleCaps |= DD_LINE_STIPPLE;
|
2007-07-21 10:06:18 -06:00
|
|
|
if (ctx->Line.Width != 1.0)
|
2006-12-13 15:31:14 -07:00
|
|
|
ctx->_TriangleCaps |= DD_LINE_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Polygons
|
|
|
|
*/
|
2007-04-26 10:45:44 -06:00
|
|
|
if (1/*new_state & _NEW_POLYGON*/) {
|
2006-12-13 15:31:14 -07:00
|
|
|
if (ctx->Polygon.SmoothFlag)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_SMOOTH;
|
|
|
|
if (ctx->Polygon.StippleFlag)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_STIPPLE;
|
|
|
|
if (ctx->Polygon.FrontMode != GL_FILL
|
|
|
|
|| ctx->Polygon.BackMode != GL_FILL)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_UNFILLED;
|
|
|
|
if (ctx->Polygon.CullFlag
|
|
|
|
&& ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_CULL_FRONT_BACK;
|
|
|
|
if (ctx->Polygon.OffsetPoint ||
|
|
|
|
ctx->Polygon.OffsetLine ||
|
|
|
|
ctx->Polygon.OffsetFill)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lighting and shading
|
|
|
|
*/
|
|
|
|
if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
|
|
|
|
if (ctx->Light.ShadeModel == GL_FLAT)
|
|
|
|
ctx->_TriangleCaps |= DD_FLATSHADE;
|
|
|
|
if (NEED_SECONDARY_COLOR(ctx))
|
|
|
|
ctx->_TriangleCaps |= DD_SEPARATE_SPECULAR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stencil
|
|
|
|
*/
|
|
|
|
if (ctx->Stencil._TestTwoSide)
|
|
|
|
ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
|
|
|
|
}
|
2007-09-27 10:24:17 -06:00
|
|
|
#endif
|
2006-12-13 15:31:14 -07:00
|
|
|
|
|
|
|
|
2005-02-26 17:16:12 +00:00
|
|
|
/**
|
2006-12-15 10:07:26 -07:00
|
|
|
* Compute derived GL state.
|
|
|
|
* If __GLcontextRec::NewState is non-zero then this function \b must
|
|
|
|
* be called before rendering anything.
|
2000-12-26 05:09:27 +00:00
|
|
|
*
|
2005-02-26 17:16:12 +00:00
|
|
|
* Calls dd_function_table::UpdateState to perform any internal state
|
|
|
|
* management necessary.
|
2003-07-17 13:43:59 +00:00
|
|
|
*
|
|
|
|
* \sa _mesa_update_modelview_project(), _mesa_update_texture(),
|
2006-12-13 15:31:14 -07:00
|
|
|
* _mesa_update_buffer_bounds(),
|
2005-02-26 17:16:12 +00:00
|
|
|
* _mesa_update_lighting() and _mesa_update_tnl_spaces().
|
2000-11-13 20:02:56 +00:00
|
|
|
*/
|
2005-02-26 17:16:12 +00:00
|
|
|
void
|
2006-11-01 14:21:57 +00:00
|
|
|
_mesa_update_state_locked( GLcontext *ctx )
|
2000-11-13 20:02:56 +00:00
|
|
|
{
|
2006-01-09 17:57:47 +00:00
|
|
|
GLbitfield new_state = ctx->NewState;
|
2008-09-20 08:26:11 -07:00
|
|
|
GLbitfield prog_flags = _NEW_PROGRAM;
|
2000-11-13 20:02:56 +00:00
|
|
|
|
2008-10-03 13:55:40 +01:00
|
|
|
if (new_state == _NEW_CURRENT_ATTRIB)
|
|
|
|
goto out;
|
|
|
|
|
2000-11-13 20:02:56 +00:00
|
|
|
if (MESA_VERBOSE & VERBOSE_STATE)
|
2002-04-09 16:56:50 +00:00
|
|
|
_mesa_print_state("_mesa_update_state", new_state);
|
2000-11-13 20:02:56 +00:00
|
|
|
|
2009-02-10 16:28:25 -07:00
|
|
|
/* Determine which state flags effect vertex/fragment program state */
|
2009-02-10 15:35:25 -07:00
|
|
|
if (ctx->FragmentProgram._MaintainTexEnvProgram) {
|
|
|
|
prog_flags |= (_NEW_TEXTURE | _NEW_FOG | _DD_NEW_SEPARATE_SPECULAR);
|
|
|
|
}
|
|
|
|
if (ctx->VertexProgram._MaintainTnlProgram) {
|
|
|
|
prog_flags |= (_NEW_ARRAY | _NEW_TEXTURE | _NEW_TEXTURE_MATRIX |
|
|
|
|
_NEW_TRANSFORM | _NEW_POINT |
|
|
|
|
_NEW_FOG | _NEW_LIGHT |
|
|
|
|
_MESA_NEW_NEED_EYE_COORDS);
|
|
|
|
}
|
2009-02-10 16:28:25 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now update derived state info
|
|
|
|
*/
|
|
|
|
|
2009-02-10 15:35:25 -07:00
|
|
|
if (new_state & prog_flags)
|
2009-02-10 16:28:25 -07:00
|
|
|
update_program_enables( ctx );
|
2009-02-10 15:35:25 -07:00
|
|
|
|
2003-07-17 13:43:59 +00:00
|
|
|
if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
|
|
|
|
_mesa_update_modelview_project( ctx, new_state );
|
2000-11-13 20:02:56 +00:00
|
|
|
|
2004-01-23 14:46:27 +00:00
|
|
|
if (new_state & (_NEW_PROGRAM|_NEW_TEXTURE|_NEW_TEXTURE_MATRIX))
|
2003-07-17 13:43:59 +00:00
|
|
|
_mesa_update_texture( ctx, new_state );
|
2000-02-02 19:15:19 +00:00
|
|
|
|
2007-10-29 17:36:39 -06:00
|
|
|
if (new_state & _NEW_BUFFERS)
|
2005-05-04 20:11:35 +00:00
|
|
|
_mesa_update_framebuffer(ctx);
|
|
|
|
|
2005-10-21 21:39:10 +00:00
|
|
|
if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT))
|
2005-02-26 17:16:12 +00:00
|
|
|
_mesa_update_draw_buffer_bounds( ctx );
|
2000-02-02 19:15:19 +00:00
|
|
|
|
2007-09-27 10:24:17 -06:00
|
|
|
if (new_state & _NEW_POLYGON)
|
|
|
|
update_polygon( ctx );
|
|
|
|
|
2000-11-22 07:32:16 +00:00
|
|
|
if (new_state & _NEW_LIGHT)
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_update_lighting( ctx );
|
2000-02-02 19:15:19 +00:00
|
|
|
|
2009-03-02 11:46:49 -07:00
|
|
|
if (new_state & (_NEW_STENCIL | _NEW_BUFFERS))
|
2005-09-13 02:59:53 +00:00
|
|
|
_mesa_update_stencil( ctx );
|
|
|
|
|
2008-09-21 19:29:15 -07:00
|
|
|
#if FEATURE_pixel_transfer
|
2009-02-10 15:43:05 -07:00
|
|
|
if (new_state & _MESA_NEW_TRANSFER_STATE)
|
2003-07-23 21:21:30 +00:00
|
|
|
_mesa_update_pixel( ctx, new_state );
|
2008-09-21 19:29:15 -07:00
|
|
|
#endif
|
2000-02-02 19:15:19 +00:00
|
|
|
|
2007-09-27 10:24:17 -06:00
|
|
|
if (new_state & _DD_NEW_SEPARATE_SPECULAR)
|
|
|
|
update_separate_specular( ctx );
|
|
|
|
|
2004-01-23 14:46:27 +00:00
|
|
|
if (new_state & (_NEW_ARRAY | _NEW_PROGRAM))
|
2003-11-10 19:08:37 +00:00
|
|
|
update_arrays( ctx );
|
|
|
|
|
2006-03-29 03:59:34 +00:00
|
|
|
if (new_state & (_NEW_BUFFERS | _NEW_VIEWPORT))
|
|
|
|
update_viewport_matrix(ctx);
|
|
|
|
|
2008-07-02 20:20:33 +02:00
|
|
|
if (new_state & _NEW_MULTISAMPLE)
|
|
|
|
update_multisample( ctx );
|
|
|
|
|
2006-07-18 19:15:40 +00:00
|
|
|
if (new_state & _NEW_COLOR)
|
|
|
|
update_color( ctx );
|
|
|
|
|
2007-09-27 10:24:17 -06:00
|
|
|
#if 0
|
2006-12-13 15:31:14 -07:00
|
|
|
if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT
|
|
|
|
| _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR))
|
|
|
|
update_tricaps( ctx, new_state );
|
2007-09-27 10:24:17 -06:00
|
|
|
#endif
|
2006-12-13 15:31:14 -07:00
|
|
|
|
2003-07-23 21:21:30 +00:00
|
|
|
/* ctx->_NeedEyeCoords is now up to date.
|
2000-11-13 20:02:56 +00:00
|
|
|
*
|
2000-12-26 05:09:27 +00:00
|
|
|
* If the truth value of this variable has changed, update for the
|
|
|
|
* new lighting space and recompute the positions of lights and the
|
2000-11-13 20:02:56 +00:00
|
|
|
* normal transform.
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2000-11-13 20:02:56 +00:00
|
|
|
* If the lighting space hasn't changed, may still need to recompute
|
2001-03-12 00:48:37 +00:00
|
|
|
* light positions & normal transforms for other reasons.
|
2000-11-13 20:02:56 +00:00
|
|
|
*/
|
2003-07-17 13:43:59 +00:00
|
|
|
if (new_state & _MESA_NEW_NEED_EYE_COORDS)
|
|
|
|
_mesa_update_tnl_spaces( ctx, new_state );
|
2000-11-13 20:02:56 +00:00
|
|
|
|
2009-02-10 16:28:25 -07:00
|
|
|
if (new_state & prog_flags)
|
|
|
|
update_program( ctx );
|
2008-09-20 08:26:11 -07:00
|
|
|
|
2000-11-16 21:05:34 +00:00
|
|
|
/*
|
2004-01-20 23:55:45 +00:00
|
|
|
* Give the driver a chance to act upon the new_state flags.
|
|
|
|
* The driver might plug in different span functions, for example.
|
|
|
|
* Also, this is where the driver can invalidate the state of any
|
|
|
|
* active modules (such as swrast_setup, swrast, tnl, etc).
|
2000-12-26 05:09:27 +00:00
|
|
|
*
|
|
|
|
* Set ctx->NewState to zero to avoid recursion if
|
|
|
|
* Driver.UpdateState() has to call FLUSH_VERTICES(). (fixed?)
|
2000-11-16 21:05:34 +00:00
|
|
|
*/
|
2008-10-03 13:55:40 +01:00
|
|
|
out:
|
2004-01-23 14:46:27 +00:00
|
|
|
new_state = ctx->NewState;
|
2000-02-02 19:15:19 +00:00
|
|
|
ctx->NewState = 0;
|
2000-12-26 05:09:27 +00:00
|
|
|
ctx->Driver.UpdateState(ctx, new_state);
|
2001-02-16 00:35:34 +00:00
|
|
|
ctx->Array.NewState = 0;
|
2000-02-02 19:15:19 +00:00
|
|
|
}
|
2002-02-13 00:53:19 +00:00
|
|
|
|
2006-11-01 14:21:57 +00:00
|
|
|
|
|
|
|
/* This is the usual entrypoint for state updates:
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_mesa_update_state( GLcontext *ctx )
|
|
|
|
{
|
|
|
|
_mesa_lock_context_textures(ctx);
|
|
|
|
_mesa_update_state_locked(ctx);
|
|
|
|
_mesa_unlock_context_textures(ctx);
|
|
|
|
}
|
2008-10-03 17:30:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-10 13:39:14 -06:00
|
|
|
/**
|
|
|
|
* Want to figure out which fragment program inputs are actually
|
2008-10-03 17:30:59 +01:00
|
|
|
* constant/current values from ctx->Current. These should be
|
|
|
|
* referenced as a tracked state variable rather than a fragment
|
|
|
|
* program input, to save the overhead of putting a constant value in
|
|
|
|
* every submitted vertex, transferring it to hardware, interpolating
|
|
|
|
* it across the triangle, etc...
|
|
|
|
*
|
|
|
|
* When there is a VP bound, just use vp->outputs. But when we're
|
|
|
|
* generating vp from fixed function state, basically want to
|
|
|
|
* calculate:
|
|
|
|
*
|
|
|
|
* vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
|
|
|
|
* potential_vp_outputs )
|
|
|
|
*
|
|
|
|
* Where potential_vp_outputs is calculated by looking at enabled
|
|
|
|
* texgen, etc.
|
|
|
|
*
|
|
|
|
* The generated fragment program should then only declare inputs that
|
|
|
|
* may vary or otherwise differ from the ctx->Current values.
|
|
|
|
* Otherwise, the fp should track them as state values instead.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_mesa_set_varying_vp_inputs( GLcontext *ctx,
|
2008-10-07 11:22:47 -06:00
|
|
|
GLbitfield varying_inputs )
|
2008-10-03 17:30:59 +01:00
|
|
|
{
|
|
|
|
if (ctx->varying_vp_inputs != varying_inputs) {
|
|
|
|
ctx->varying_vp_inputs = varying_inputs;
|
|
|
|
ctx->NewState |= _NEW_ARRAY;
|
2008-10-10 13:39:14 -06:00
|
|
|
/*_mesa_printf("%s %x\n", __FUNCTION__, varying_inputs);*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by drivers to tell core Mesa that the driver is going to
|
|
|
|
* install/ use its own vertex program. In particular, this will
|
|
|
|
* prevent generated fragment programs from using state vars instead
|
|
|
|
* of ordinary varyings/inputs.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_mesa_set_vp_override(GLcontext *ctx, GLboolean flag)
|
|
|
|
{
|
|
|
|
if (ctx->VertexProgram._Overriden != flag) {
|
|
|
|
ctx->VertexProgram._Overriden = flag;
|
|
|
|
|
|
|
|
/* Set one of the bits which will trigger fragment program
|
|
|
|
* regeneration:
|
|
|
|
*/
|
|
|
|
ctx->NewState |= _NEW_ARRAY;
|
2008-10-03 17:30:59 +01:00
|
|
|
}
|
|
|
|
}
|