summaryrefslogtreecommitdiff
path: root/src/mesa/main/state.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/state.c')
-rw-r--r--src/mesa/main/state.c81
1 files changed, 57 insertions, 24 deletions
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index f4f73a5089..6ed7ae6c7d 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -93,7 +93,7 @@
#include "texenvprogram.h"
#endif
#if FEATURE_ARB_shader_objects
-#include "shaderobjects.h"
+#include "shaders.h"
#endif
#include "debug.h"
#include "dispatch.h"
@@ -832,11 +832,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;
}
@@ -920,7 +916,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);
@@ -943,30 +939,66 @@ 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_shader_program *shProg = ctx->Shader.CurrentProgram;
+
+ /* 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.
+ */
- if (ctx->_UseTexEnvProgram)
- ctx->FragmentProgram._Active = GL_TRUE;
+ ctx->FragmentProgram._Current = NULL;
+
+ if (shProg && shProg->LinkStatus) {
+ /* Use shader programs */
+ ctx->VertexProgram._Current = shProg->VertexProgram;
+ ctx->FragmentProgram._Current = shProg->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->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;
+ }
}
}
@@ -1003,6 +1035,7 @@ update_color(GLcontext *ctx)
}
+
/**
* Update the ctx->_TriangleCaps bitfield.
* XXX that bitfield should really go away someday!
@@ -1133,7 +1166,7 @@ _mesa_update_state_locked( GLcontext *ctx )
| _NEW_STENCIL | _DD_NEW_SEPARATE_SPECULAR))
update_tricaps( ctx, new_state );
- if (ctx->_MaintainTexEnvProgram) {
+ if (ctx->FragmentProgram._MaintainTexEnvProgram) {
if (new_state & (_NEW_TEXTURE | _DD_NEW_SEPARATE_SPECULAR | _NEW_FOG))
_mesa_UpdateTexEnvProgram(ctx);
}