mesa: Move compute_num_levels from st_gen_mipmap.c to mipmap.c.
[mesa.git] / src / mesa / state_tracker / st_gen_mipmap.c
index a14bbfabaa31b474e15771787ebe994af345b6d1..f2aa8005a035151065163b2fa337176b5f90906e 100644 (file)
 #include "st_context.h"
 #include "st_texture.h"
 #include "st_gen_mipmap.h"
+#include "st_cb_bitmap.h"
 #include "st_cb_texture.h"
 
 
-/**
- * Compute the expected number of mipmap levels in the texture given
- * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/
- * GL_TEXTURE_MAX_LEVEL settings.  This will tell us how many mipmap
- * levels should be generated.
- */
-static GLuint
-compute_num_levels(struct gl_context *ctx,
-                   struct gl_texture_object *texObj,
-                   GLenum target)
-{
-   const struct gl_texture_image *baseImage;
-   GLuint numLevels;
-
-   baseImage = _mesa_get_tex_image(ctx, texObj, target, texObj->BaseLevel);
-
-   numLevels = texObj->BaseLevel + baseImage->MaxNumLevels;
-   numLevels = MIN2(numLevels, (GLuint) texObj->MaxLevel + 1);
-   if (texObj->Immutable)
-      numLevels = MIN2(numLevels, texObj->NumLevels);
-   assert(numLevels >= 1);
-
-   return numLevels;
-}
-
-
 /**
  * Called via ctx->Driver.GenerateMipmap().
  */
@@ -91,11 +66,14 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
    assert(pt->nr_samples < 2);
 
    /* find expected last mipmap level to generate*/
-   lastLevel = compute_num_levels(ctx, texObj, target) - 1;
+   lastLevel = _mesa_compute_num_levels(ctx, texObj, target) - 1;
 
    if (lastLevel == 0)
       return;
 
+   st_flush_bitmap_cache(st);
+   st_invalidate_readpix_cache(st);
+
    /* The texture isn't in a "complete" state yet so set the expected
     * lastLevel here, since it won't get done in st_finalize_texture().
     */
@@ -121,7 +99,7 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
        *
        * After this, we'll have all mipmap levels in one resource.
        */
-      st_finalize_texture(ctx, st->pipe, texObj);
+      st_finalize_texture(ctx, st->pipe, texObj, 0);
    }
 
    pt = stObj->pt;