[Mesa-dev] [PATCH v2 1/2] mesa: Make GenerateMipmap check the target before finding an object.

Kenneth Graunke kenneth at whitecape.org
Sat Mar 5 05:05:55 UTC 2016


If glGenerateMipmap was called with a bogus target, then it would
pass that to _mesa_get_current_tex_object(), which would raise a
_mesa_problem() telling people to file bugs.  We'd then do the
proper error checking, raise an error, and bail.

Doing the check first avoids the _mesa_problem().  The DSA variant
doesn't take a target parameter, so we leave the target validation
exactly as it was in that case.

Fixes one dEQP GLES2 test:
dEQP-GLES2.functional.negative_api.texture.generatemipmap.invalid_target.

v2: Rebase on Antia's recent patch to this area.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Brian Paul <brianp at vmware.com> [v1]
---
 src/mesa/main/genmipmap.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Sorry for the resend - here's basically the same change, but it applies
on master now that ARB_internal_format_query2 has landed.

diff --git a/src/mesa/main/genmipmap.c b/src/mesa/main/genmipmap.c
index f9ef2d1..2a67777 100644
--- a/src/mesa/main/genmipmap.c
+++ b/src/mesa/main/genmipmap.c
@@ -99,12 +99,6 @@ _mesa_generate_texture_mipmap(struct gl_context *ctx,
 
    FLUSH_VERTICES(ctx, 0);
 
-   if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, target)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerate%sMipmap(target=%s)",
-                  suffix, _mesa_enum_to_string(target));
-      return;
-   }
-
    if (texObj->BaseLevel >= texObj->MaxLevel) {
       /* nothing to do */
       return;
@@ -159,6 +153,12 @@ _mesa_GenerateMipmap(GLenum target)
    struct gl_texture_object *texObj;
    GET_CURRENT_CONTEXT(ctx);
 
+   if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, target)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmap(target=%s)",
+                  _mesa_enum_to_string(target));
+      return;
+   }
+
    texObj = _mesa_get_current_tex_object(ctx, target);
    if (!texObj)
       return;
@@ -179,5 +179,11 @@ _mesa_GenerateTextureMipmap(GLuint texture)
    if (!texObj)
       return;
 
+   if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, texObj->Target)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateTextureMipmap(target=%s)",
+                  _mesa_enum_to_string(texObj->Target));
+      return;
+   }
+
    _mesa_generate_texture_mipmap(ctx, texObj, texObj->Target, true);
 }
-- 
2.7.2



More information about the mesa-dev mailing list