Mesa (map-texture-image-v5): mesa: rework the generate_mipmap_compressed() function

Brian Paul brianp at kemper.freedesktop.org
Wed Aug 31 20:31:00 PDT 2011


Module: Mesa
Branch: map-texture-image-v5
Commit: c305c68c1874fced27f00b015ff00cb24dc791ff
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c305c68c1874fced27f00b015ff00cb24dc791ff

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Aug 31 20:04:15 2011 -0600

mesa: rework the generate_mipmap_compressed() function

Be smarter about choosing the format of the uncompressed base image.
If the compressed format is signed, the decompressed format must be signed
too.  Use the new format helper functions to simplify the code.

---

 src/mesa/main/mipmap.c |   61 ++++++++++++++++++++++--------------------------
 1 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 3880ddb..f170d23 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -1984,44 +1984,40 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
 {
    GLint level;
    gl_format temp_format;
-   GLenum datatype;
-   GLuint comps;
    GLint components;
    GLuint temp_src_stride, temp_dst_stride; /* in bytes */
    GLchan *temp_src = NULL, *temp_dst = NULL;
+   GLenum temp_datatype;
+   GLenum temp_base_format;
 
-   /* Choose the format we will do _mesa_generate_mipmap_level() in,
-    * and uncompress the firstImage into a temporary of that format.
-    */
+   /* only two types of compressed textures at this time */
    assert(texObj->Target == GL_TEXTURE_2D ||
 	  texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
 
-   if (srcImage->_BaseFormat == GL_RGB) {
-      temp_format = MESA_FORMAT_RGB888;
-      components = 3;
-   } else if (srcImage->_BaseFormat == GL_RED) {
-      temp_format = MESA_FORMAT_R8;
-      components = 1;
-   } else if (srcImage->_BaseFormat == GL_RG) {
-      temp_format = MESA_FORMAT_RG88;
-      components = 2;
-   } else if (srcImage->_BaseFormat == GL_RGBA) {
-      temp_format = MESA_FORMAT_RGBA8888;
-      components = 4;
-   } else if (srcImage->_BaseFormat == GL_LUMINANCE) {
-      temp_format = MESA_FORMAT_L8;
-      components = 1;
-   } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
-      temp_format = MESA_FORMAT_AL88;
-      components = 2;
-   } else {
-      _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
-      return;
+   /*
+    * Choose a format for the temporary, uncompressed base image.
+    * Then, get number of components, choose temporary image datatype,
+    * and get base format.
+    */
+   temp_format = _mesa_get_uncompressed_format(srcImage->TexFormat);
+
+   components = _mesa_format_num_components(temp_format);
+
+   /* Revisit this if we get compressed formats with >8 bits per component */
+   if (_mesa_get_format_datatype(srcImage->TexFormat)
+       == GL_SIGNED_NORMALIZED) {
+      temp_datatype = GL_BYTE;
+   }
+   else {
+      temp_datatype = GL_UNSIGNED_BYTE;
    }
 
-   /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
-   temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
+   temp_base_format = _mesa_get_format_base_format(temp_format);
+
+
+   /* allocate storage for the temporary, uncompressed image */
    /* 20 extra bytes, just be safe when calling last FetchTexel */
+   temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
    temp_src = (GLubyte *) malloc(temp_src_stride * srcImage->Height + 20);
    if (!temp_src) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
@@ -2034,15 +2030,15 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
       struct gl_pixelstore_attrib save = ctx->Pack;
       /* use default/tight packing parameters */
       ctx->Pack = ctx->DefaultPacking;
+
       /* Get the uncompressed image */
       ctx->Driver.GetTexImage(ctx, target, texObj->BaseLevel,
-                              srcImage->_BaseFormat, GL_UNSIGNED_BYTE,
+                              temp_base_format, temp_datatype,
                               temp_src, texObj, srcImage);
       /* restore packing mode */
       ctx->Pack = save;
    }
 
-   _mesa_format_to_type_and_comps(temp_format, &datatype, &comps);
 
    for (level = texObj->BaseLevel; level < maxLevel; level++) {
       /* generate image[level+1] from image[level] */
@@ -2086,7 +2082,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
       /* Free old image data */
       ctx->Driver.FreeTextureImageBuffer(ctx, dstImage);
 
-      _mesa_generate_mipmap_level(target, datatype, comps, border,
+      _mesa_generate_mipmap_level(target, temp_datatype, components, border,
                                   srcWidth, srcHeight, srcDepth,
                                   temp_src, temp_src_stride / components,
                                   dstWidth, dstHeight, dstDepth,
@@ -2100,8 +2096,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
       ctx->Driver.TexImage2D(ctx, target, level + 1,
 			     srcImage->InternalFormat,
 			     dstWidth, dstHeight, border,
-			     _mesa_get_format_base_format(temp_format),
-			     GL_UNSIGNED_BYTE,
+			     temp_base_format, temp_datatype,
 			     temp_dst, &ctx->DefaultPacking, texObj, dstImage);
 
       /* swap src and dest pointers */



More information about the mesa-commit mailing list