+static void
+update_ff_texture_state(struct gl_context *ctx,
+ BITSET_WORD *enabled_texture_units)
+{
+ int unit;
+
+ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+ GLbitfield mask;
+ bool complete;
+
+ if (texUnit->Enabled == 0x0)
+ continue;
+
+ /* If a shader already dictated what texture target was used for this
+ * unit, just go along with it.
+ */
+ if (BITSET_TEST(enabled_texture_units, unit))
+ continue;
+
+ /* From the GL 4.4 compat specification, section 16.2 ("Texture Application"):
+ *
+ * "Texturing is enabled or disabled using the generic Enable and
+ * Disable commands, respectively, with the symbolic constants
+ * TEXTURE_1D, TEXTURE_2D, TEXTURE_RECTANGLE, TEXTURE_3D, or
+ * TEXTURE_CUBE_MAP to enable the one-, two-, rectangular,
+ * three-dimensional, or cube map texture, respectively. If more
+ * than one of these textures is enabled, the first one enabled
+ * from the following list is used:
+ *
+ * • cube map texture
+ * • three-dimensional texture
+ * • rectangular texture
+ * • two-dimensional texture
+ * • one-dimensional texture"
+ *
+ * Note that the TEXTURE_x_INDEX values are in high to low priority.
+ * Also:
+ *
+ * "If a texture unit is disabled or has an invalid or incomplete
+ * texture (as defined in section 8.17) bound to it, then blending
+ * is disabled for that texture unit. If the texture environment
+ * for a given enabled texture unit references a disabled texture
+ * unit, or an invalid or incomplete texture that is bound to
+ * another unit, then the results of texture blending are
+ * undefined."
+ */
+ complete = false;
+ mask = texUnit->Enabled;
+ while (mask) {
+ const int texIndex = u_bit_scan(&mask);
+ struct gl_texture_object *texObj = texUnit->CurrentTex[texIndex];
+ struct gl_sampler_object *sampler = texUnit->Sampler ?
+ texUnit->Sampler : &texObj->Sampler;
+
+ if (!_mesa_is_texture_complete(texObj, sampler)) {
+ _mesa_test_texobj_completeness(ctx, texObj);