From abdbd02e5928c881510da0f76b4e49fd92ddfe50 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Wed, 31 Jul 2013 10:46:12 -0400 Subject: [PATCH] Correct clamping of TEXTURE_{MAX, BASE}_LEVEL Previously, if TEXTURE_IMMUTABLE_FORMAT was TRUE, the levels were allowed to be set like usual, but ARB_texture_storage states: > if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is clamped to the range > [0, - 1] and level_max is then clamped to the range [level_base, > - 1], where is the parameter passed the call to > TexStorage* for the texture object Reviewed-by: Matt Turner Signed-off-by: Corey Richardson --- src/mesa/main/texparam.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 32109951cb5..757ae80ec8d 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -386,7 +386,13 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; } incomplete(ctx, texObj); - texObj->BaseLevel = params[0]; + + /** See note about ARB_texture_storage below */ + if (texObj->Immutable) + texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]); + else + texObj->BaseLevel = params[0]; + return GL_TRUE; case GL_TEXTURE_MAX_LEVEL: @@ -399,7 +405,19 @@ set_tex_parameteri(struct gl_context *ctx, return GL_FALSE; } incomplete(ctx, texObj); - texObj->MaxLevel = params[0]; + + /** From ARB_texture_storage: + * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is + * clamped to the range [0, - 1] and level_max is then clamped to + * the range [level_base, - 1], where is the parameter + * passed the call to TexStorage* for the texture object. + */ + if (texObj->Immutable) + texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel, + texObj->ImmutableLevels - 1); + else + texObj->MaxLevel = params[0]; + return GL_TRUE; case GL_GENERATE_MIPMAP_SGIS: -- 2.30.2