[Mesa-dev] [PATCH 2/2] Correct clamping of TEXTURE_{MAX, BASE}_LEVEL

Corey Richardson corey at octayn.net
Wed Jul 31 04:19:02 PDT 2013


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, <levels> - 1] and level_max is then clamped to the range [level_base,
> <levels> - 1], where <levels> is the parameter passed the call to
> TexStorage* for the texture object

Signed-off-by: Corey Richardson <corey at octayn.net>
---
 src/mesa/main/texparam.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index 141cbe3..f07d755 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -386,7 +386,14 @@ 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 = (params[0] >= texObj->ImmutableLevels) ?
+            texObj->ImmutableLevels - 1 : params[0];
+      else
+         texObj->BaseLevel = params[0];
+
       return GL_TRUE;
 
    case GL_TEXTURE_MAX_LEVEL:
@@ -399,7 +406,24 @@ 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, <levels> - 1] and level_max is then clamped to
+       * the range [level_base, <levels> - 1], where <levels> is the parameter
+       * passed the call to TexStorage* for the texture object.
+       */
+      if (texObj->Immutable) {
+         if (*params < texObj->BaseLevel)
+            texObj->MaxLevel = texObj->BaseLevel;
+         else if (*params >= texObj->ImmutableLevels)
+            texObj->MaxLevel = texObj->ImmutableLevels - 1;
+         else
+            texObj->MaxLevel = params[0];
+      }
+      else
+         texObj->MaxLevel = params[0];
+
       return GL_TRUE;
 
    case GL_GENERATE_MIPMAP_SGIS:
-- 
1.8.3.4



More information about the mesa-dev mailing list