* \return true if no errors, false if errors
*/
static bool
-check_level(struct gl_context *ctx, GLenum target, GLint level,
- const char *caller)
+check_level(struct gl_context *ctx, struct gl_texture_object *texObj,
+ GLenum target, GLint level, const char *caller)
{
- if ((level < 0) ||
- (level >= _mesa_max_texture_levels(ctx, target))) {
+ /* Section 9.2.8 of the OpenGL 4.6 specification says:
+ *
+ * "If texture refers to an immutable-format texture, level must be
+ * greater than or equal to zero and smaller than the value of
+ * TEXTURE_VIEW_NUM_LEVELS for texture."
+ */
+ const int max_levels = texObj->Immutable ? texObj->ImmutableLevels :
+ _mesa_max_texture_levels(ctx, target);
+
+ if (level < 0 || level >= max_levels) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(invalid level %d)", caller, level);
return false;
if ((dims == 3) && !check_layer(ctx, texObj->Target, layer, caller))
return;
- if (!check_level(ctx, textarget, level, caller))
+ if (!check_level(ctx, texObj, textarget, level, caller))
return;
}
return;
}
- if (!check_level(ctx, texObj->Target, level, func))
+ if (!check_level(ctx, texObj, texObj->Target, level, func))
return;
}