[Mesa-dev] [PATCH 2/3] mesa: move glGenerateMipmap() code into new genmipmap.c file

Brian Paul brianp at vmware.com
Sat Feb 1 07:59:20 PST 2014


Mipmap generation has nothing to do with FBOs.
---
 src/mesa/Makefile.sources |    1 +
 src/mesa/SConscript       |    1 +
 src/mesa/main/fbobject.c  |   92 -------------------------------
 src/mesa/main/fbobject.h  |    4 --
 src/mesa/main/genmipmap.c |  131 +++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/genmipmap.h |   36 +++++++++++++
 6 files changed, 169 insertions(+), 96 deletions(-)
 create mode 100644 src/mesa/main/genmipmap.c
 create mode 100644 src/mesa/main/genmipmap.h

diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 6a8a045..3cdcae2 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -49,6 +49,7 @@ MAIN_FILES = \
 	$(SRCDIR)main/format_unpack.c \
 	$(SRCDIR)main/framebuffer.c \
 	$(SRCDIR)main/get.c \
+	$(SRCDIR)main/genmipmap.c \
 	$(SRCDIR)main/getstring.c \
 	$(SRCDIR)main/glformats.c \
 	$(SRCDIR)main/hash.c \
diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index 4bc4de4..5b3358d 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -78,6 +78,7 @@ main_sources = [
     'main/format_pack.c',
     'main/format_unpack.c',
     'main/framebuffer.c',
+    'main/genmipmap.c',
     'main/getstring.c',
     'main/glformats.c',
     'main/hash.c',
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 7a1761f..ccfa984 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2973,98 +2973,6 @@ invalid_pname_enum:
 }
 
 
-/**
- * Generate all the mipmap levels below the base level.
- * Note: this GL function would be more useful if one could specify a
- * cube face, a set of array slices, etc.
- */
-void GLAPIENTRY
-_mesa_GenerateMipmap(GLenum target)
-{
-   struct gl_texture_image *srcImage;
-   struct gl_texture_object *texObj;
-   GLboolean error;
-
-   GET_CURRENT_CONTEXT(ctx);
-
-   FLUSH_VERTICES(ctx, 0);
-
-   switch (target) {
-   case GL_TEXTURE_1D:
-      error = _mesa_is_gles(ctx);
-      break;
-   case GL_TEXTURE_2D:
-      error = GL_FALSE;
-      break;
-   case GL_TEXTURE_3D:
-      error = ctx->API == API_OPENGLES;
-      break;
-   case GL_TEXTURE_CUBE_MAP:
-      error = !ctx->Extensions.ARB_texture_cube_map;
-      break;
-   case GL_TEXTURE_1D_ARRAY:
-      error = _mesa_is_gles(ctx) || !ctx->Extensions.EXT_texture_array;
-      break;
-   case GL_TEXTURE_2D_ARRAY:
-      error = (_mesa_is_gles(ctx) && ctx->Version < 30)
-         || !ctx->Extensions.EXT_texture_array;
-      break;
-   default:
-      error = GL_TRUE;
-   }
-
-   if (error) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target=%s)",
-                  _mesa_lookup_enum_by_nr(target));
-      return;
-   }
-
-   texObj = _mesa_get_current_tex_object(ctx, target);
-
-   if (texObj->BaseLevel >= texObj->MaxLevel) {
-      /* nothing to do */
-      return;
-   }
-
-   if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
-       !_mesa_cube_complete(texObj)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerateMipmap(incomplete cube map)");
-      return;
-   }
-
-   _mesa_lock_texture(ctx, texObj);
-
-   srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
-   if (!srcImage) {
-      _mesa_unlock_texture(ctx, texObj);
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerateMipmap(zero size base image)");
-      return;
-   }
-
-   if (_mesa_is_enum_format_integer(srcImage->InternalFormat) ||
-       _mesa_is_depthstencil_format(srcImage->InternalFormat) ||
-       _mesa_is_stencil_format(srcImage->InternalFormat)) {
-      _mesa_unlock_texture(ctx, texObj);
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glGenerateMipmap(invalid internal format)");
-      return;
-   }
-
-   if (target == GL_TEXTURE_CUBE_MAP) {
-      GLuint face;
-      for (face = 0; face < 6; face++)
-	 ctx->Driver.GenerateMipmap(ctx,
-				    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
-				    texObj);
-   }
-   else {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-   _mesa_unlock_texture(ctx, texObj);
-}
-
 static void
 invalidate_framebuffer_storage(GLenum target, GLsizei numAttachments,
                                const GLenum *attachments, GLint x, GLint y,
diff --git a/src/mesa/main/fbobject.h b/src/mesa/main/fbobject.h
index 1f5aa34..cf4bf39 100644
--- a/src/mesa/main/fbobject.h
+++ b/src/mesa/main/fbobject.h
@@ -203,10 +203,6 @@ _mesa_GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment,
                                              GLenum pname, GLint *params);
 
 extern void GLAPIENTRY
-_mesa_GenerateMipmap(GLenum target);
-
-
-extern void GLAPIENTRY
 _mesa_InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments,
                                const GLenum *attachments, GLint x, GLint y,
                                GLsizei width, GLsizei height);
diff --git a/src/mesa/main/genmipmap.c b/src/mesa/main/genmipmap.c
new file mode 100644
index 0000000..dcd482d
--- /dev/null
+++ b/src/mesa/main/genmipmap.c
@@ -0,0 +1,131 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2013  VMware, Inc.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * glGenerateMipmap function
+ */
+
+#include "context.h"
+#include "enums.h"
+#include "genmipmap.h"
+#include "glformats.h"
+#include "macros.h"
+#include "mtypes.h"
+#include "teximage.h"
+#include "texobj.h"
+
+
+/**
+ * Generate all the mipmap levels below the base level.
+ * Note: this GL function would be more useful if one could specify a
+ * cube face, a set of array slices, etc.
+ */
+void GLAPIENTRY
+_mesa_GenerateMipmap(GLenum target)
+{
+   struct gl_texture_image *srcImage;
+   struct gl_texture_object *texObj;
+   GLboolean error;
+
+   GET_CURRENT_CONTEXT(ctx);
+
+   FLUSH_VERTICES(ctx, 0);
+
+   switch (target) {
+   case GL_TEXTURE_1D:
+      error = _mesa_is_gles(ctx);
+      break;
+   case GL_TEXTURE_2D:
+      error = GL_FALSE;
+      break;
+   case GL_TEXTURE_3D:
+      error = ctx->API == API_OPENGLES;
+      break;
+   case GL_TEXTURE_CUBE_MAP:
+      error = !ctx->Extensions.ARB_texture_cube_map;
+      break;
+   case GL_TEXTURE_1D_ARRAY:
+      error = _mesa_is_gles(ctx) || !ctx->Extensions.EXT_texture_array;
+      break;
+   case GL_TEXTURE_2D_ARRAY:
+      error = (_mesa_is_gles(ctx) && ctx->Version < 30)
+         || !ctx->Extensions.EXT_texture_array;
+      break;
+   default:
+      error = GL_TRUE;
+   }
+
+   if (error) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target=%s)",
+                  _mesa_lookup_enum_by_nr(target));
+      return;
+   }
+
+   texObj = _mesa_get_current_tex_object(ctx, target);
+
+   if (texObj->BaseLevel >= texObj->MaxLevel) {
+      /* nothing to do */
+      return;
+   }
+
+   if (texObj->Target == GL_TEXTURE_CUBE_MAP &&
+       !_mesa_cube_complete(texObj)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGenerateMipmap(incomplete cube map)");
+      return;
+   }
+
+   _mesa_lock_texture(ctx, texObj);
+
+   srcImage = _mesa_select_tex_image(ctx, texObj, target, texObj->BaseLevel);
+   if (!srcImage) {
+      _mesa_unlock_texture(ctx, texObj);
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGenerateMipmap(zero size base image)");
+      return;
+   }
+
+   if (_mesa_is_enum_format_integer(srcImage->InternalFormat) ||
+       _mesa_is_depthstencil_format(srcImage->InternalFormat) ||
+       _mesa_is_stencil_format(srcImage->InternalFormat)) {
+      _mesa_unlock_texture(ctx, texObj);
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGenerateMipmap(invalid internal format)");
+      return;
+   }
+
+   if (target == GL_TEXTURE_CUBE_MAP) {
+      GLuint face;
+      for (face = 0; face < 6; face++)
+	 ctx->Driver.GenerateMipmap(ctx,
+				    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + face,
+				    texObj);
+   }
+   else {
+      ctx->Driver.GenerateMipmap(ctx, target, texObj);
+   }
+   _mesa_unlock_texture(ctx, texObj);
+}
diff --git a/src/mesa/main/genmipmap.h b/src/mesa/main/genmipmap.h
new file mode 100644
index 0000000..d546a8d
--- /dev/null
+++ b/src/mesa/main/genmipmap.h
@@ -0,0 +1,36 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef GENMIPMAP_H
+#define GENMIPMAP_H
+
+#include "glheader.h"
+
+
+extern void GLAPIENTRY
+_mesa_GenerateMipmap(GLenum target);
+
+
+#endif /* GENMIPMAP_H */
-- 
1.7.10.4



More information about the mesa-dev mailing list