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 fe986092db670fdbf4361d0577a2e6cc8bd43b74..237754d4695c480c07588019d20d1065a5129250 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 028b49c14d36e8e9083a886fa4c312f02c5fdd9c..148e8c048c750bf96141cf7cb3ca2047894863b4 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 a206fe6805b97b48b7af9962a30449af062da7aa..66201b1f465f82bf7d284b1c24fb6d8d3e056ec3 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 89037073f84f957fe5940d35812e369cfb6269cd..751ec2c98c278c50a2a21e98f15a09ed23d66742 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 fad3d1cedaf4174ede249dedb7db17cbf2250536..049284ef8c588062d261ddabed6a2e5c826c3351 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 1f7257eaead977355135bf995805165158dc7c61..f6a48b3ae12a7f2fdb448ed4041eb61d9446b182 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 d2010f090741286fd7b4fc3d00e1ff431086b7f8..54073e76918d0b97899ee70d40775fa99a79c8aa 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 888b5064cc2434b20be0d2a3f512b2881e8540af..b0aa04e9aa489107b0c76270f8d2897c9ae49557 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 a22db628d3ed6c53e50c4f8b821b7a5184397409..e50c6658c7f624104cbb5158ed2b8047339c5dd0 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 abaf9d2c353e52d350859f92b75a752a4df3dca3..c0ace3b9eac8d579be5b57230c9c097fb1582b86 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);
-   }
 }