Mesa (7.9): mesa: test for cube map completeness in glGenerateMipmap()

Brian Paul brianp at kemper.freedesktop.org
Tue Dec 14 23:32:19 UTC 2010


Module: Mesa
Branch: 7.9
Commit: 1ee289960f2b3dd93f44957d8a78a2bd4ac7985e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1ee289960f2b3dd93f44957d8a78a2bd4ac7985e

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Dec 14 16:28:14 2010 -0700

mesa: test for cube map completeness in glGenerateMipmap()

The texture is not cube complete if the base level images aren't of
the same size and format.

NOTE: This is a candidate for the 7.9 branch.

(cherry picked from commit ecb7cc3319a74bda1edc226a1103f0e1a86d92a9)

---

 src/mesa/main/fbobject.c |    8 ++++++++
 src/mesa/main/texobj.c   |   38 ++++++++++++++++++++++++++++++++++++++
 src/mesa/main/texobj.h   |    3 +++
 3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 3740168..a946e3f 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2103,6 +2103,7 @@ _mesa_GenerateMipmapEXT(GLenum target)
       /* OK, legal value */
       break;
    default:
+      /* XXX need to implement GL_TEXTURE_1D_ARRAY and GL_TEXTURE_2D_ARRAY */
       _mesa_error(ctx, GL_INVALID_ENUM, "glGenerateMipmapEXT(target)");
       return;
    }
@@ -2114,6 +2115,13 @@ _mesa_GenerateMipmapEXT(GLenum target)
       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);
    if (target == GL_TEXTURE_CUBE_MAP) {
       GLuint face;
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 1df165c..89e2892 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -687,6 +687,44 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
 
 
 /**
+ * Check if the given cube map texture is "cube complete" as defined in
+ * the OpenGL specification.
+ */
+GLboolean
+_mesa_cube_complete(const struct gl_texture_object *texObj)
+{
+   const GLint baseLevel = texObj->BaseLevel;
+   const struct gl_texture_image *img0, *img;
+   GLuint face;
+
+   if (texObj->Target != GL_TEXTURE_CUBE_MAP)
+      return GL_FALSE;
+
+   if ((baseLevel < 0) || (baseLevel >= MAX_TEXTURE_LEVELS))
+      return GL_FALSE;
+
+   /* check first face */
+   img0 = texObj->Image[0][baseLevel];
+   if (!img0 ||
+       img0->Width < 1 ||
+       img0->Width != img0->Height)
+      return GL_FALSE;
+
+   /* check remaining faces vs. first face */
+   for (face = 1; face < 6; face++) {
+      img = texObj->Image[face][baseLevel];
+      if (!img ||
+          img->Width != img0->Width ||
+          img->Height != img0->Height ||
+          img->TexFormat != img0->TexFormat)
+         return GL_FALSE;
+   }
+
+   return GL_TRUE;
+}
+
+
+/**
  * Mark a texture object dirty.  It forces the object to be incomplete
  * and optionally forces the context to re-validate its state.
  *
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 9bfebd4..e42d91d 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -68,6 +68,9 @@ extern void
 _mesa_test_texobj_completeness( const GLcontext *ctx,
                                 struct gl_texture_object *obj );
 
+extern GLboolean
+_mesa_cube_complete(const struct gl_texture_object *texObj);
+
 extern void
 _mesa_dirty_texobj(GLcontext *ctx, struct gl_texture_object *texObj,
                    GLboolean invalidate_state);




More information about the mesa-commit mailing list