- /* Determine which texture coordinate sets are actually needed */
- if (fprog) {
- const GLuint coordMask = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
- ctx->Texture._EnabledCoordUnits
- = (fprog->InputsRead >> VARYING_SLOT_TEX0) & coordMask;
+ ctx->Texture._GenFlags = 0x0;
+ ctx->Texture._TexMatEnabled = 0x0;
+ ctx->Texture._TexGenEnabled = 0x0;
+ ctx->Texture._MaxEnabledTexImageUnit = -1;
+ ctx->Texture._EnabledCoordUnits = 0x0;
+
+ memset(&enabled_texture_units, 0, sizeof(enabled_texture_units));
+
+ /* First, walk over our programs pulling in all the textures for them.
+ * Programs dictate specific texture targets to be enabled, and for a draw
+ * call to be valid they can't conflict about which texture targets are
+ * used.
+ */
+ update_program_texture_state(ctx, prog, enabled_texture_units);
+
+ /* Also pull in any textures necessary for fixed function fragment shading.
+ */
+ if (!prog[MESA_SHADER_FRAGMENT])
+ update_ff_texture_state(ctx, enabled_texture_units);
+
+ /* Now, clear out the _Current of any disabled texture units. */
+ for (i = 0; i <= ctx->Texture._MaxEnabledTexImageUnit; i++) {
+ if (!BITSET_TEST(enabled_texture_units, i))
+ _mesa_reference_texobj(&ctx->Texture.Unit[i]._Current, NULL);