mesa: minor whitespace fixes, line wrapping in texcompress.c
[mesa.git] / src / mesa / main / texstate.c
index 1e90bf87dacb291bcd76a795df8cda2044f1a0b7..8f87cac0ce446a08d54ea05911286e48bfb4803e 100644 (file)
@@ -307,8 +307,6 @@ active_texture(GLenum texture, bool no_error)
       }
    }
 
-   FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);
-
    ctx->Texture.CurrentUnit = texUnit;
    if (ctx->Transform.MatrixMode == GL_TEXTURE) {
       /* update current stack pointer */
@@ -351,7 +349,7 @@ _mesa_ClientActiveTexture(GLenum texture)
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_ARRAY);
+   /* Don't flush vertices. This is a "latched" state. */
    ctx->Array.ActiveTexture = texUnit;
 }
 
@@ -688,8 +686,6 @@ update_single_program_texture_state(struct gl_context *ctx,
    struct gl_texture_object *texObj;
 
    texObj = update_single_program_texture(ctx, prog, unit);
-   if (!texObj)
-      return;
 
    _mesa_reference_texobj(&ctx->Texture.Unit[unit]._Current, texObj);
    BITSET_SET(enabled_texture_units, unit);
@@ -823,6 +819,29 @@ update_ff_texture_state(struct gl_context *ctx,
    }
 }
 
+static void
+fix_missing_textures_for_atifs(struct gl_context *ctx,
+                               struct gl_program *prog,
+                               BITSET_WORD *enabled_texture_units)
+{
+   GLbitfield mask = prog->SamplersUsed;
+
+   while (mask) {
+      const int s = u_bit_scan(&mask);
+      const int unit = prog->SamplerUnits[s];
+      const gl_texture_index target_index = ffs(prog->TexturesUsed[unit]) - 1;
+
+      if (!ctx->Texture.Unit[unit]._Current) {
+         struct gl_texture_object *texObj =
+            _mesa_get_fallback_texture(ctx, target_index);
+         _mesa_reference_texobj(&ctx->Texture.Unit[unit]._Current, texObj);
+         BITSET_SET(enabled_texture_units, unit);
+         ctx->Texture._MaxEnabledTexImageUnit =
+            MAX2(ctx->Texture._MaxEnabledTexImageUnit, (int)unit);
+      }
+   }
+}
+
 /**
  * \note This routine refers to derived texture matrix values to
  * compute the ENABLE_TEXMAT flags, but is only called on
@@ -840,13 +859,7 @@ _mesa_update_texture_state(struct gl_context *ctx)
    int old_max_unit = ctx->Texture._MaxEnabledTexImageUnit;
    BITSET_DECLARE(enabled_texture_units, MAX_COMBINED_TEXTURE_IMAGE_UNITS);
 
-   for (i = 0; i < MESA_SHADER_STAGES; i++) {
-      if (ctx->_Shader->CurrentProgram[i]) {
-         prog[i] = ctx->_Shader->CurrentProgram[i];
-      } else {
-         prog[i] = NULL;
-      }
-   }
+   memcpy(prog, ctx->_Shader->CurrentProgram, sizeof(prog));
 
    if (prog[MESA_SHADER_FRAGMENT] == NULL &&
        _mesa_arb_fragment_program_enabled(ctx)) {
@@ -885,6 +898,13 @@ _mesa_update_texture_state(struct gl_context *ctx)
       _mesa_reference_texobj(&ctx->Texture.Unit[i]._Current, NULL);
    }
 
+   /* add fallback texture for SampleMapATI if there is nothing */
+   if (_mesa_ati_fragment_shader_enabled(ctx) &&
+       ctx->ATIFragmentShader.Current->Program)
+      fix_missing_textures_for_atifs(ctx,
+                                     ctx->ATIFragmentShader.Current->Program,
+                                     enabled_texture_units);
+
    if (!prog[MESA_SHADER_FRAGMENT] || !prog[MESA_SHADER_VERTEX])
       update_texgen(ctx);
 }