mesa: add generate_texture_mipmap_error() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 18 Jul 2017 19:21:50 +0000 (21:21 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 31 Jul 2017 11:53:39 +0000 (13:53 +0200)
And make generate_texture_mipmap() always inline.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/main/genmipmap.c

index be49136aa89315467d4794b9208e133c59b836fe..9eb83cf85f3d43dd2bb8253a46def8803882e271 100644 (file)
@@ -107,10 +107,10 @@ _mesa_is_valid_generate_texture_mipmap_internalformat(struct gl_context *ctx,
  * Implements glGenerateMipmap and glGenerateTextureMipmap.
  * Generates all the mipmap levels below the base level.
  */
-static void
+static ALWAYS_INLINE void
 generate_texture_mipmap(struct gl_context *ctx,
                         struct gl_texture_object *texObj, GLenum target,
-                        bool dsa)
+                        bool dsa, bool no_error)
 {
    struct gl_texture_image *srcImage;
    const char *suffix = dsa ? "Texture" : "";
@@ -122,7 +122,7 @@ generate_texture_mipmap(struct gl_context *ctx,
       return;
    }
 
-   if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
+   if (!no_error && texObj->Target == GL_TEXTURE_CUBE_MAP &&
        !_mesa_cube_complete(texObj)) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glGenerate%sMipmap(incomplete cube map)", suffix);
@@ -132,20 +132,22 @@ generate_texture_mipmap(struct gl_context *ctx,
    _mesa_lock_texture(ctx, texObj);
 
    srcImage = _mesa_select_tex_image(texObj, target, texObj->BaseLevel);
-   if (!srcImage) {
-      _mesa_unlock_texture(ctx, texObj);
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerate%sMipmap(zero size base image)", suffix);
-      return;
-   }
+   if (!no_error) {
+      if (!srcImage) {
+         _mesa_unlock_texture(ctx, texObj);
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glGenerate%sMipmap(zero size base image)", suffix);
+         return;
+      }
 
-   if (!_mesa_is_valid_generate_texture_mipmap_internalformat(ctx,
-                                                              srcImage->InternalFormat)) {
-      _mesa_unlock_texture(ctx, texObj);
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerate%sMipmap(invalid internal format %s)", suffix,
-                  _mesa_enum_to_string(srcImage->InternalFormat));
-      return;
+      if (!_mesa_is_valid_generate_texture_mipmap_internalformat(ctx,
+                                                                 srcImage->InternalFormat)) {
+         _mesa_unlock_texture(ctx, texObj);
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glGenerate%sMipmap(invalid internal format %s)", suffix,
+                     _mesa_enum_to_string(srcImage->InternalFormat));
+         return;
+      }
    }
 
    if (srcImage->Width == 0 || srcImage->Height == 0) {
@@ -166,6 +168,14 @@ generate_texture_mipmap(struct gl_context *ctx,
    _mesa_unlock_texture(ctx, texObj);
 }
 
+static void
+generate_texture_mipmap_error(struct gl_context *ctx,
+                              struct gl_texture_object *texObj, GLenum target,
+                              bool dsa)
+{
+   generate_texture_mipmap(ctx, texObj, target, dsa, false);
+}
+
 /**
  * Generate all the mipmap levels below the base level.
  * Note: this GL function would be more useful if one could specify a
@@ -187,7 +197,7 @@ _mesa_GenerateMipmap(GLenum target)
    if (!texObj)
       return;
 
-   generate_texture_mipmap(ctx, texObj, target, false);
+   generate_texture_mipmap_error(ctx, texObj, target, false);
 }
 
 /**
@@ -209,5 +219,5 @@ _mesa_GenerateTextureMipmap(GLuint texture)
       return;
    }
 
-   generate_texture_mipmap(ctx, texObj, texObj->Target, true);
+   generate_texture_mipmap_error(ctx, texObj, texObj->Target, true);
 }