+static struct gl_texture_object *
+update_single_program_texture(struct gl_context *ctx, struct gl_program *prog,
+ int s)
+{
+ gl_texture_index target_index;
+ struct gl_texture_unit *texUnit;
+ struct gl_texture_object *texObj;
+ struct gl_sampler_object *sampler;
+ int unit;
+
+ if (!(prog->SamplersUsed & (1 << s)))
+ return NULL;
+
+ unit = prog->SamplerUnits[s];
+ texUnit = &ctx->Texture.Unit[unit];
+
+ /* Note: If more than one bit was set in TexturesUsed[unit], then we should
+ * have had the draw call rejected already. From the GL 4.4 specification,
+ * section 7.10 ("Samplers"):
+ *
+ * "It is not allowed to have variables of different sampler types
+ * pointing to the same texture image unit within a program
+ * object. This situation can only be detected at the next rendering
+ * command issued which triggers shader invocations, and an
+ * INVALID_OPERATION error will then be generated."
+ */
+ target_index = ffs(prog->TexturesUsed[unit]) - 1;
+ texObj = texUnit->CurrentTex[target_index];
+
+ sampler = texUnit->Sampler ?
+ texUnit->Sampler : &texObj->Sampler;
+
+ if (likely(texObj)) {
+ if (_mesa_is_texture_complete(texObj, sampler))
+ return texObj;
+
+ _mesa_test_texobj_completeness(ctx, texObj);
+ if (_mesa_is_texture_complete(texObj, sampler))
+ return texObj;
+ }
+
+ /* If we've reached this point, we didn't find a complete texture of the
+ * shader's target. From the GL 4.4 core specification, section 11.1.3.5
+ * ("Texture Access"):
+ *
+ * "If a sampler is used in a shader and the sampler’s associated
+ * texture is not complete, as defined in section 8.17, (0, 0, 0, 1)
+ * will be returned for a non-shadow sampler and 0 for a shadow
+ * sampler."
+ *
+ * Mesa implements this by creating a hidden texture object with a pixel of
+ * that value.
+ */
+ texObj = _mesa_get_fallback_texture(ctx, target_index);
+ assert(texObj);
+
+ return texObj;
+}
+