mesa: move generate mipmap calls
authorBrian Paul <brianp@vmware.com>
Wed, 16 Sep 2009 00:16:59 +0000 (18:16 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 16 Sep 2009 00:17:43 +0000 (18:17 -0600)
Per the suggestion in the Intel driver, move the calls to
ctx->Driver.GenerateMipmap() into core Mesa so that drivers don't
have to worry about it.

src/mesa/drivers/dri/intel/intel_generatemipmap.c
src/mesa/drivers/dri/intel/intel_tex_copy.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/intel/intel_tex_subimage.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/tdfx/tdfx_tex.c
src/mesa/drivers/dri/unichrome/via_tex.c
src/mesa/main/teximage.c
src/mesa/main/texstore.c
src/mesa/state_tracker/st_cb_texture.c

index fe98609..237754d 100644 (file)
@@ -223,10 +223,6 @@ fail:
  *
  * The texture object's miptree must be mapped.
  *
- * It would be really nice if this was just called by Mesa whenever mipmaps
- * needed to be regenerated, rather than us having to remember to do so in
- * each texture image modification path.
- *
  * This function should also include an accelerated path.
  */
 void
index 028b49c..148e8c0 100644 (file)
@@ -90,7 +90,6 @@ do_copy_texsubimage(struct intel_context *intel,
                     GLint x, GLint y, GLsizei width, GLsizei height)
 {
    GLcontext *ctx = &intel->ctx;
-   struct gl_texture_object *texObj = intelImage->base.TexObject;
    const struct intel_region *src =
       get_teximage_source(intel, internalFormat);
 
@@ -170,11 +169,6 @@ do_copy_texsubimage(struct intel_context *intel,
 
    UNLOCK_HARDWARE(intel);
 
-   /* GL_SGIS_generate_mipmap */
-   if (intelImage->level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      intel_generate_mipmap(ctx, target, texObj);
-   }
-
    return GL_TRUE;
 }
 
index a206fe6..66201b1 100644 (file)
@@ -546,11 +546,6 @@ intelTexImage(GLcontext * ctx,
    }
 
    UNLOCK_HARDWARE(intel);
-
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      intel_generate_mipmap(ctx, target, texObj);
-   }
 }
 
 
index 8903707..751ec2c 100644 (file)
@@ -129,11 +129,6 @@ intelTexSubimage(GLcontext * ctx,
    }
 
    UNLOCK_HARDWARE(intel);
-
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      intel_generate_mipmap(ctx, target, texObj);
-   }
 }
 
 
index fad3d1c..049284e 100644 (file)
@@ -659,11 +659,6 @@ static void radeon_teximage(
                        if (dims == 3)
                                _mesa_free(dstImageOffsets);
                }
-
-               /* SGIS_generate_mipmap */
-               if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-                       radeon_generate_mipmap(ctx, target, texObj);
-               }
        }
 
        _mesa_unmap_teximage_pbo(ctx, packing);
@@ -792,11 +787,6 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, GLenum target, int leve
                                                             format, type, pixels, packing))
                                _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
                }
-
-               /* GL_SGIS_generate_mipmap */
-               if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-                       radeon_generate_mipmap(ctx, target, texObj);
-               }
        }
 
        radeon_teximage_unmap(image);
index 1f7257e..f6a48b3 100644 (file)
@@ -176,6 +176,54 @@ logbase2(int n)
 }
 
 
+static void
+tdfxGenerateMipmap(GLcontext *ctx, GLenum target,
+                   struct gl_texture_object *texObj)
+{
+   GLint mipWidth, mipHeight;
+   tdfxMipMapLevel *mip;
+   struct gl_texture_image *mipImage; /* the new/next image */
+   struct gl_texture_image *texImage;
+   const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
+   GLint level = texObj->BaseLevel;
+   GLsizei width, height, texelBytes;
+   const tdfxMipMapLevel *mml;
+
+   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+   assert(!texImage->IsCompressed);
+
+   mml = TDFX_TEXIMAGE_DATA(texImage);
+
+   width = texImage->Width;
+   height = texImage->Height;
+   while (level < texObj->MaxLevel && level < maxLevels - 1) {
+      mipWidth = width / 2;
+      if (!mipWidth) {
+         mipWidth = 1;
+      }
+      mipHeight = height / 2;
+      if (!mipHeight) {
+         mipHeight = 1;
+      }
+      if ((mipWidth == width) && (mipHeight == height)) {
+         break;
+      }
+      ++level;
+      mipImage = _mesa_select_tex_image(ctx, texObj, target, level);
+      mip = TDFX_TEXIMAGE_DATA(mipImage);
+      _mesa_halve2x2_teximage2d(ctx,
+                                texImage,
+                                texelBytes,
+                                mml->width, mml->height,
+                                texImage->Data, mipImage->Data);
+      texImage = mipImage;
+      mml = mip;
+      width = mipWidth;
+      height = mipHeight;
+   }
+}
+
+
 /*
  * Compute various texture image parameters.
  * Input:  w, h - source texture width and height
@@ -1397,45 +1445,6 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
                                           width, height, 1,
                                           format, type, pixels, packing);
        }
-
-      /* GL_SGIS_generate_mipmap */
-      if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-         GLint mipWidth, mipHeight;
-         tdfxMipMapLevel *mip;
-         struct gl_texture_image *mipImage;
-         const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
-   
-         assert(!texImage->IsCompressed);
-   
-         while (level < texObj->MaxLevel && level < maxLevels - 1) {
-            mipWidth = width / 2;
-            if (!mipWidth) {
-               mipWidth = 1;
-            }
-            mipHeight = height / 2;
-            if (!mipHeight) {
-               mipHeight = 1;
-            }
-            if ((mipWidth == width) && (mipHeight == height)) {
-               break;
-            }
-            _mesa_TexImage2D(target, ++level, internalFormat,
-                             mipWidth, mipHeight, border,
-                             format, type,
-                             NULL);
-            mipImage = _mesa_select_tex_image(ctx, texObj, target, level);
-            mip = TDFX_TEXIMAGE_DATA(mipImage);
-            _mesa_halve2x2_teximage2d(ctx,
-                                      texImage,
-                                      texelBytes,
-                                      mml->width, mml->height,
-                                      texImage->Data, mipImage->Data);
-            texImage = mipImage;
-            mml = mip;
-            width = mipWidth;
-            height = mipHeight;
-         }
-      }
     }
 
     RevalidateTexture(ctx, texObj);
@@ -1507,44 +1516,6 @@ tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
                                         format, type, pixels, packing);
     }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      GLint mipWidth, mipHeight;
-      tdfxMipMapLevel *mip;
-      struct gl_texture_image *mipImage;
-      const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
-
-      assert(!texImage->IsCompressed);
-
-      width = texImage->Width;
-      height = texImage->Height;
-      while (level < texObj->MaxLevel && level < maxLevels - 1) {
-         mipWidth = width / 2;
-         if (!mipWidth) {
-            mipWidth = 1;
-         }
-         mipHeight = height / 2;
-         if (!mipHeight) {
-            mipHeight = 1;
-         }
-         if ((mipWidth == width) && (mipHeight == height)) {
-            break;
-         }
-         ++level;
-         mipImage = _mesa_select_tex_image(ctx, texObj, target, level);
-         mip = TDFX_TEXIMAGE_DATA(mipImage);
-         _mesa_halve2x2_teximage2d(ctx,
-                                   texImage,
-                                   texelBytes,
-                                   mml->width, mml->height,
-                                   texImage->Data, mipImage->Data);
-         texImage = mipImage;
-         mml = mip;
-         width = mipWidth;
-         height = mipHeight;
-      }
-   }
-
     ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
     fxMesa->new_state |= TDFX_NEW_TEXTURE;  /* XXX this might be a bit much */
 }
@@ -1703,11 +1674,6 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
        MEMCPY(texImage->Data, data, texImage->CompressedSize);
     }
 
-    /* GL_SGIS_generate_mipmap */
-    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-       assert(!texImage->IsCompressed);
-    }
-
     RevalidateTexture(ctx, texObj);
 
     ti->reloadImages = GL_TRUE;
@@ -1770,11 +1736,6 @@ tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
                                 texImage->Data);
     }
 
-    /* GL_SGIS_generate_mipmap */
-    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-       assert(!texImage->IsCompressed);
-    }
-
     RevalidateTexture(ctx, texObj);
 
     ti->reloadImages = GL_TRUE;
@@ -1914,4 +1875,5 @@ void tdfxInitTextureFuncs( struct dd_function_table *functions )
    functions->CompressedTexImage2D     = tdfxCompressedTexImage2D;
    functions->CompressedTexSubImage2D  = tdfxCompressedTexSubImage2D;
    functions->UpdateTexturePalette      = tdfxUpdateTexturePalette;
+   functions->GenerateMipmap            = tdfxGenerateMipmap;
 }
index d2010f0..54073e7 100644 (file)
@@ -818,11 +818,6 @@ static void viaTexImage(GLcontext *ctx,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      _mesa_generate_mipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
index 888b506..b0aa04e 100644 (file)
@@ -2075,6 +2075,23 @@ update_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj,
 }
 
 
+/**
+ * If the texture object's GenerateMipmap flag is set and we've
+ * changed the texture base level image, regenerate the rest of the
+ * mipmap levels now.
+ */
+static INLINE void
+check_gen_mipmap(GLcontext *ctx, GLenum target,
+                 struct gl_texture_object *texObj, GLint level)
+{
+   ASSERT(target != GL_TEXTURE_CUBE_MAP);
+   if (texObj->GenerateMipmap && level == texObj->BaseLevel) {
+      ASSERT(ctx->Driver.GenerateMipmap);
+      ctx->Driver.GenerateMipmap(ctx, target, texObj);
+   }
+}
+
+
 /** Debug helper: override the user-requested internal format */
 static GLenum
 override_internal_format(GLenum internalFormat, GLint width, GLint height)
@@ -2182,6 +2199,8 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
 
             ASSERT(texImage->TexFormat);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             update_fbo_texture(ctx, texObj, face, level);
 
             /* state update */
@@ -2287,6 +2306,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
 
             ASSERT(texImage->TexFormat);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             update_fbo_texture(ctx, texObj, face, level);
 
             /* state update */
@@ -2388,6 +2409,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
 
             ASSERT(texImage->TexFormat);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             update_fbo_texture(ctx, texObj, face, level);
 
             /* state update */
@@ -2486,6 +2509,9 @@ _mesa_TexSubImage1D( GLenum target, GLint level,
          ctx->Driver.TexSubImage1D(ctx, target, level, xoffset, width,
                                    format, type, pixels, &ctx->Unpack,
                                    texObj, texImage);
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
          ctx->NewState |= _NEW_TEXTURE;
       }
    }
@@ -2544,6 +2570,9 @@ _mesa_TexSubImage2D( GLenum target, GLint level,
          ctx->Driver.TexSubImage2D(ctx, target, level, xoffset, yoffset,
                                    width, height, format, type, pixels,
                                    &ctx->Unpack, texObj, texImage);
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
          ctx->NewState |= _NEW_TEXTURE;
       }
    }
@@ -2598,6 +2627,9 @@ _mesa_TexSubImage3D( GLenum target, GLint level,
                                    width, height, depth,
                                    format, type, pixels,
                                    &ctx->Unpack, texObj, texImage );
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
          ctx->NewState |= _NEW_TEXTURE;
       }
    }
@@ -2659,6 +2691,8 @@ _mesa_CopyTexImage1D( GLenum target, GLint level,
 
          ASSERT(texImage->TexFormat);
 
+         check_gen_mipmap(ctx, target, texObj, level);
+
          update_fbo_texture(ctx, texObj, face, level);
 
          /* state update */
@@ -2726,6 +2760,8 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
 
          ASSERT(texImage->TexFormat);
 
+         check_gen_mipmap(ctx, target, texObj, level);
+
          update_fbo_texture(ctx, texObj, face, level);
 
          /* state update */
@@ -2784,6 +2820,9 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level,
             ASSERT(ctx->Driver.CopyTexSubImage1D);
             ctx->Driver.CopyTexSubImage1D(ctx, target, level,
                                           xoffset, x, y, width);
+
+            check_gen_mipmap(ctx, target, texObj, level);
+
             ctx->NewState |= _NEW_TEXTURE;
          }
       }
@@ -2841,6 +2880,9 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level,
             ASSERT(ctx->Driver.CopyTexSubImage2D);
             ctx->Driver.CopyTexSubImage2D(ctx, target, level, xoffset, yoffset,
                                           x, y, width, height);
+
+            check_gen_mipmap(ctx, target, texObj, level);
+
             ctx->NewState |= _NEW_TEXTURE;
          }
       }
@@ -2899,6 +2941,9 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
             ctx->Driver.CopyTexSubImage3D(ctx, target, level,
                                           xoffset, yoffset, zoffset,
                                           x, y, width, height);
+
+            check_gen_mipmap(ctx, target, texObj, level);
+
             ctx->NewState |= _NEW_TEXTURE;
          }
       }
@@ -3146,6 +3191,8 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
                                              imageSize, data,
                                              texObj, texImage);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             /* state update */
             texObj->_Complete = GL_FALSE;
             ctx->NewState |= _NEW_TEXTURE;
@@ -3242,6 +3289,8 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
                                              border, imageSize, data,
                                              texObj, texImage);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             /* state update */
             texObj->_Complete = GL_FALSE;
             ctx->NewState |= _NEW_TEXTURE;
@@ -3338,6 +3387,8 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
                                              border, imageSize, data,
                                              texObj, texImage);
 
+            check_gen_mipmap(ctx, target, texObj, level);
+
             /* state update */
             texObj->_Complete = GL_FALSE;
             ctx->NewState |= _NEW_TEXTURE;
@@ -3430,8 +3481,11 @@ _mesa_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
                                                 format, imageSize, data,
                                                 texObj, texImage);
          }
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
+         ctx->NewState |= _NEW_TEXTURE;
       }
-      ctx->NewState |= _NEW_TEXTURE;
    }
    _mesa_unlock_texture(ctx, texObj);
 }
@@ -3485,8 +3539,11 @@ _mesa_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
                                                format, imageSize, data,
                                                texObj, texImage);
          }
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
+         ctx->NewState |= _NEW_TEXTURE;
       }
-      ctx->NewState |= _NEW_TEXTURE;
    }
    _mesa_unlock_texture(ctx, texObj);
 }
@@ -3542,8 +3599,11 @@ _mesa_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
                                                format, imageSize, data,
                                                texObj, texImage);
          }
+
+         check_gen_mipmap(ctx, target, texObj, level);
+
+         ctx->NewState |= _NEW_TEXTURE;
       }
-      ctx->NewState |= _NEW_TEXTURE;
    }
    _mesa_unlock_texture(ctx, texObj);
 }
index a22db62..e50c665 100644 (file)
@@ -3403,11 +3403,6 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3481,11 +3476,6 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3555,11 +3545,6 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3601,11 +3586,6 @@ _mesa_store_texsubimage1d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3654,11 +3634,6 @@ _mesa_store_texsubimage2d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3707,11 +3682,6 @@ _mesa_store_texsubimage3d(GLcontext *ctx, GLenum target, GLint level,
       }
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, packing);
 }
 
@@ -3781,11 +3751,6 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    ASSERT(texImage->CompressedSize == (GLuint) imageSize);
    MEMCPY(texImage->Data, data, imageSize);
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
 }
 
@@ -3891,11 +3856,6 @@ _mesa_store_compressed_texsubimage2d(GLcontext *ctx, GLenum target,
       src += srcRowStride;
    }
 
-   /* GL_SGIS_generate_mipmap */
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
-
    _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
 }
 
index abaf9d2..c0ace3b 100644 (file)
@@ -760,10 +760,6 @@ done:
       st_texture_image_unmap(ctx->st, stImage);
       texImage->Data = NULL;
    }
-
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
 }
 
 
@@ -1134,10 +1130,6 @@ done:
       st_texture_image_unmap(ctx->st, stImage);
       texImage->Data = NULL;
    }
-
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
 }
 
 
@@ -1601,10 +1593,6 @@ st_copy_texsubimage(GLcontext *ctx,
                                 destX, destY, destZ,
                                 srcX, srcY, width, height);
    }
-
-   if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      ctx->Driver.GenerateMipmap(ctx, target, texObj);
-   }
 }