mesa: new _mesa_valid_to_render() function
[mesa.git] / src / mesa / main / texenvprogram.c
index 4a124bf27e2e4a3ec401db13168abb270b49f27d..3736138b9ed8b6f911163f1adc59a133b3410fa8 100644 (file)
@@ -62,6 +62,18 @@ struct texenvprog_cache_item
    struct texenvprog_cache_item *next;
 };
 
+static GLboolean
+texenv_doing_secondary_color(GLcontext *ctx)
+{
+   if (ctx->Light.Enabled &&
+       (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))
+      return GL_TRUE;
+
+   if (ctx->Fog.ColorSumEnabled)
+      return GL_TRUE;
+
+   return GL_FALSE;
+}
 
 /**
  * Up to nine instructions per tex unit, plus fog, specular color.
@@ -261,7 +273,9 @@ static GLuint translate_tex_src_bit( GLbitfield bit )
  */
 static GLbitfield get_fp_input_mask( GLcontext *ctx )
 {
+   /* _NEW_PROGRAM */
    const GLboolean vertexShader = (ctx->Shader.CurrentProgram &&
+                                  ctx->Shader.CurrentProgram->LinkStatus &&
                                    ctx->Shader.CurrentProgram->VertexProgram);
    const GLboolean vertexProgram = ctx->VertexProgram._Enabled;
    GLbitfield fp_inputs = 0x0;
@@ -274,37 +288,44 @@ static GLbitfield get_fp_input_mask( GLcontext *ctx )
       fp_inputs = ~0;
    }
    else if (ctx->RenderMode == GL_FEEDBACK) {
+      /* _NEW_RENDERMODE */
       fp_inputs = (FRAG_BIT_COL0 | FRAG_BIT_TEX0);
    }
    else if (!(vertexProgram || vertexShader) ||
             !ctx->VertexProgram._Current) {
       /* Fixed function vertex logic */
+      /* _NEW_ARRAY */
       GLbitfield varying_inputs = ctx->varying_vp_inputs;
 
       /* These get generated in the setup routine regardless of the
        * vertex program:
        */
+      /* _NEW_POINT */
       if (ctx->Point.PointSprite)
          varying_inputs |= FRAG_BITS_TEX_ANY;
 
       /* First look at what values may be computed by the generated
        * vertex program:
        */
+      /* _NEW_LIGHT */
       if (ctx->Light.Enabled) {
          fp_inputs |= FRAG_BIT_COL0;
 
-         if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
+         if (texenv_doing_secondary_color(ctx))
             fp_inputs |= FRAG_BIT_COL1;
       }
 
+      /* _NEW_TEXTURE */
       fp_inputs |= (ctx->Texture._TexGenEnabled |
                     ctx->Texture._TexMatEnabled) << FRAG_ATTRIB_TEX0;
 
       /* Then look at what might be varying as a result of enabled
        * arrays, etc:
        */
-      if (varying_inputs & VERT_BIT_COLOR0) fp_inputs |= FRAG_BIT_COL0;
-      if (varying_inputs & VERT_BIT_COLOR1) fp_inputs |= FRAG_BIT_COL1;
+      if (varying_inputs & VERT_BIT_COLOR0)
+         fp_inputs |= FRAG_BIT_COL0;
+      if (varying_inputs & VERT_BIT_COLOR1)
+         fp_inputs |= FRAG_BIT_COL1;
 
       fp_inputs |= (((varying_inputs & VERT_BIT_TEX_ANY) >> VERT_ATTRIB_TEX0) 
                     << FRAG_ATTRIB_TEX0);
@@ -322,18 +343,21 @@ static GLbitfield get_fp_input_mask( GLcontext *ctx )
       if (vertexShader)
          vprog = ctx->Shader.CurrentProgram->VertexProgram;
       else
-         vprog = ctx->VertexProgram._Current;
+         vprog = ctx->VertexProgram.Current;
 
       vp_outputs = vprog->Base.OutputsWritten;
 
       /* These get generated in the setup routine regardless of the
        * vertex program:
        */
+      /* _NEW_POINT */
       if (ctx->Point.PointSprite)
          vp_outputs |= FRAG_BITS_TEX_ANY;
 
-      if (vp_outputs & (1 << VERT_RESULT_COL0)) fp_inputs |= FRAG_BIT_COL0;
-      if (vp_outputs & (1 << VERT_RESULT_COL1)) fp_inputs |= FRAG_BIT_COL1;
+      if (vp_outputs & (1 << VERT_RESULT_COL0))
+         fp_inputs |= FRAG_BIT_COL0;
+      if (vp_outputs & (1 << VERT_RESULT_COL1))
+         fp_inputs |= FRAG_BIT_COL1;
 
       fp_inputs |= (((vp_outputs & VERT_RESULT_TEX_ANY) >> VERT_RESULT_TEX0) 
                     << FRAG_ATTRIB_TEX0);
@@ -355,6 +379,7 @@ static void make_state_key( GLcontext *ctx,  struct state_key *key )
 
    memset(key, 0, sizeof(*key));
 
+   /* _NEW_TEXTURE */
    for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
       const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
       GLenum format;
@@ -408,11 +433,13 @@ static void make_state_key( GLcontext *ctx,  struct state_key *key )
        }
    }
 
-   if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) {
+   /* _NEW_LIGHT | _NEW_FOG */
+   if (texenv_doing_secondary_color(ctx)) {
       key->separate_specular = 1;
       inputs_referenced |= FRAG_BIT_COL1;
    }
 
+   /* _NEW_FOG */
    if (ctx->Fog.Enabled) {
       key->fog_enabled = 1;
       key->fog_mode = translate_fog_mode(ctx->Fog.Mode);
@@ -663,9 +690,8 @@ static void emit_arg( struct prog_src_register *reg,
    reg->File = ureg.file;
    reg->Index = ureg.idx;
    reg->Swizzle = ureg.swz;
-   reg->NegateBase = ureg.negatebase ? 0xf : 0x0;
+   reg->Negate = ureg.negatebase ? NEGATE_XYZW : NEGATE_NONE;
    reg->Abs = ureg.abs;
-   reg->NegateAbs = ureg.negateabs;
 }
 
 static void emit_dst( struct prog_dst_register *dst,
@@ -878,6 +904,7 @@ static struct ureg get_source( struct texenv_fragment_program *p,
 
    default:
       assert(0);
+      return undef;
    }
 }