i915: Bug #14313: Fix accelerated (PBO) ReadPixels.
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex.c
index e02972ec637bfdfe769e0773b3df497fc40761c6..f1d6a6dbfc0310fa03ea592fb83d9c23a3f18f2a 100644 (file)
@@ -1,5 +1,7 @@
 #include "swrast/swrast.h"
 #include "texobj.h"
+#include "teximage.h"
+#include "mipmap.h"
 #include "intel_context.h"
 #include "intel_mipmap_tree.h"
 #include "intel_tex.h"
@@ -70,7 +72,7 @@ intelFreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
    }
 
    if (texImage->Data) {
-      free(texImage->Data);
+      _mesa_free_texmemory(texImage->Data);
       texImage->Data = NULL;
    }
 }
@@ -99,7 +101,7 @@ do_memcpy(void *dest, const void *src, size_t n)
 }
 
 
-#if DO_DEBUG
+#if DO_DEBUG && !defined(__ia64__)
 
 #ifndef __x86_64__
 static unsigned
@@ -156,6 +158,54 @@ timed_memcpy(void *dest, const void *src, size_t n)
 }
 #endif /* DO_DEBUG */
 
+/**
+ * Generate new mipmap data from BASE+1 to BASE+p (the minimally-sized mipmap
+ * level).
+ *
+ * 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
+intel_generate_mipmap(GLcontext *ctx, GLenum target,
+                      struct gl_texture_object *texObj)
+{
+   struct intel_texture_object *intelObj = intel_texture_object(texObj);
+   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   int face, i;
+
+   _mesa_generate_mipmap(ctx, target, texObj);
+
+   /* Update the level information in our private data in the new images, since
+    * it didn't get set as part of a normal TexImage path.
+    */
+   for (face = 0; face < nr_faces; face++) {
+      for (i = texObj->BaseLevel + 1; i < texObj->MaxLevel; i++) {
+         struct intel_texture_image *intelImage;
+
+        intelImage = intel_texture_image(texObj->Image[face][i]);
+        if (intelImage == NULL)
+           break;
+
+        intelImage->level = i;
+        intelImage->face = face;
+      }
+   }
+}
+
+static void intelGenerateMipmap(GLcontext *ctx, GLenum target, struct gl_texture_object *texObj)
+{
+   struct intel_context *intel = intel_context(ctx);
+   struct intel_texture_object *intelObj = intel_texture_object(texObj);
+
+   intel_tex_map_images(intel, intelObj);
+   intel_generate_mipmap(ctx, target, texObj);
+   intel_tex_unmap_images(intel, intelObj);
+}
 
 void
 intelInitTextureFuncs(struct dd_function_table *functions)
@@ -179,6 +229,7 @@ intelInitTextureFuncs(struct dd_function_table *functions)
    functions->CopyTexSubImage2D = _swrast_copy_texsubimage2d;
 #endif
    functions->GetTexImage = intelGetTexImage;
+   functions->GenerateMipmap = intelGenerateMipmap;
 
    /* compressed texture functions */
    functions->CompressedTexImage2D = intelCompressedTexImage2D;
@@ -191,7 +242,7 @@ intelInitTextureFuncs(struct dd_function_table *functions)
    functions->UpdateTexturePalette = 0;
    functions->IsTextureResident = intelIsTextureResident;
 
-#if DO_DEBUG
+#if DO_DEBUG && !defined(__ia64__)
    if (INTEL_DEBUG & DEBUG_BUFMGR)
       functions->TextureMemCpy = timed_memcpy;
    else