diff options
Diffstat (limited to 'src/mesa/main/state.c')
-rw-r--r-- | src/mesa/main/state.c | 89 |
1 files changed, 62 insertions, 27 deletions
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index e62fbe47d15..e121f59258c 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -842,11 +842,7 @@ update_arrays( GLcontext *ctx ) /* find min of _MaxElement values for all enabled arrays */ /* 0 */ - if (ctx->ShaderObjects._VertexShaderPresent - && ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0].Enabled) { - min = ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC0]._MaxElement; - } - else if (ctx->VertexProgram._Enabled + if (ctx->VertexProgram._Current && ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) { min = ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POS]._MaxElement; } @@ -930,7 +926,7 @@ update_arrays( GLcontext *ctx ) } /* 16..31 */ - if (ctx->ShaderObjects._VertexShaderPresent) { + if (ctx->VertexProgram._Current) { for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) { if (ctx->Array.ArrayObj->VertexAttrib[i].Enabled) { min = MIN2(min, ctx->Array.ArrayObj->VertexAttrib[i]._MaxElement); @@ -953,30 +949,67 @@ update_arrays( GLcontext *ctx ) static void update_program(GLcontext *ctx) { - /* For now, just set the _Enabled (really enabled) flags. - * In the future we may have to check other state to be sure we really - * have a runable program or shader. - */ + const struct gl_linked_program *linked = ctx->ShaderObjects.Linked; + + + /* These _Enabled flags indicate if the program is enabled AND valid. */ ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled && ctx->VertexProgram.Current->Base.Instructions; ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled && ctx->FragmentProgram.Current->Base.Instructions; ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled && ctx->ATIFragmentShader.Current->Instructions; - - ctx->FragmentProgram._Current = ctx->FragmentProgram.Current; - ctx->FragmentProgram._Active = ctx->FragmentProgram._Enabled; - if (ctx->_MaintainTexEnvProgram && !ctx->FragmentProgram._Enabled) { -#if 0 - if (!ctx->_TexEnvProgram) - ctx->_TexEnvProgram = (struct gl_fragment_program *) - ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - ctx->FragmentProgram._Current = ctx->_TexEnvProgram; -#endif + /* + * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current + * pointers to the programs that should be enabled/used. + * + * 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. + */ + + ctx->FragmentProgram._Current = NULL; + + if (linked && linked->LinkStatus) { + /* Use shader programs */ + ctx->VertexProgram._Current = linked->VertexProgram; + ctx->FragmentProgram._Current = linked->FragmentProgram; + } + else { + if (ctx->VertexProgram._Enabled) { + /* use user-defined vertex program */ + ctx->VertexProgram._Current = ctx->VertexProgram.Current; + } + else if (ctx->VertexProgram._MaintainTnlProgram) { + /* Use vertex program generated from fixed-function state. + * The _Current pointer will get set in + * _tnl_UpdateFixedFunctionProgram() later if appropriate. + */ + ctx->VertexProgram._Current = NULL; + } + else { + /* no vertex program */ + ctx->VertexProgram._Current = NULL; + } - if (ctx->_UseTexEnvProgram) - ctx->FragmentProgram._Active = GL_TRUE; + if (ctx->FragmentProgram._Enabled) { + /* use user-defined vertex program */ + ctx->FragmentProgram._Current = ctx->FragmentProgram.Current; + } + else if (ctx->FragmentProgram._MaintainTexEnvProgram) { + /* Use fragment program generated from fixed-function state. + * The _Current pointer will get set in _mesa_UpdateTexEnvProgram() + * later if appropriate. + */ + ctx->FragmentProgram._Current = NULL; + } + else { + /* no fragment program */ + ctx->FragmentProgram._Current = NULL; + } } } @@ -1013,11 +1046,11 @@ update_color(GLcontext *ctx) } + /** - * If __GLcontextRec::NewState is non-zero then this function \b must be called - * before rendering any primitive. Basically, function pointers and - * miscellaneous flags are updated to reflect the current state of the state - * machine. + * Compute derived GL state. + * If __GLcontextRec::NewState is non-zero then this function \b must + * be called before rendering anything. * * Calls dd_function_table::UpdateState to perform any internal state * management necessary. @@ -1076,7 +1109,7 @@ _mesa_update_state_locked( GLcontext *ctx ) if (new_state & _NEW_COLOR) update_color( ctx ); - if (ctx->_MaintainTexEnvProgram) { + if (ctx->FragmentProgram._MaintainTexEnvProgram) { if (new_state & (_NEW_TEXTURE | _DD_NEW_SEPARATE_SPECULAR | _NEW_FOG)) _mesa_UpdateTexEnvProgram(ctx); } @@ -1122,3 +1155,5 @@ _mesa_update_state( GLcontext *ctx ) /*@}*/ + + |