swrast: add Alloc/FreeTextureImageBuffer() driver functions
authorBrian Paul <brianp@vmware.com>
Sat, 17 Sep 2011 20:50:48 +0000 (14:50 -0600)
committerBrian Paul <brianp@vmware.com>
Sat, 17 Sep 2011 20:57:40 +0000 (14:57 -0600)
Not called yet.  These will replace the core Mesa functions for allocating
and freeing malloc'd texture memory.

src/mesa/swrast/s_texture.c
src/mesa/swrast/swrast.h

index 184fd952dc5f81e367dbdca1cdfefc18e0f545f5..7e3fc2806d9061a9610e477a641b5b621409aab6 100644 (file)
@@ -58,6 +58,44 @@ _swrast_delete_texture_image(struct gl_context *ctx,
 }
 
 
+/**
+ * Called via ctx->Driver.AllocTextureImageBuffer()
+ */
+GLboolean
+_swrast_alloc_texture_image_buffer(struct gl_context *ctx,
+                                   struct gl_texture_image *texImage,
+                                   gl_format format, GLsizei width,
+                                   GLsizei height, GLsizei depth)
+{
+   GLuint bytes = _mesa_format_image_size(format, width, height, depth);
+
+   /* This _should_ be true (revisit if these ever fail) */
+   assert(texImage->Width == width);
+   assert(texImage->Height == height);
+   assert(texImage->Depth == depth);
+
+   assert(!texImage->Data);
+   texImage->Data = _mesa_align_malloc(bytes, 512);
+
+   return texImage->Data != NULL;
+}
+
+
+/**
+ * Called via ctx->Driver.FreeTextureImageBuffer()
+ */
+void
+_swrast_free_texture_image_buffer(struct gl_context *ctx,
+                                  struct gl_texture_image *texImage)
+{
+   if (texImage->Data && !texImage->IsClientData) {
+      _mesa_align_free(texImage->Data);
+   }
+
+   texImage->Data = NULL;
+}
+
+
 /**
  * Error checking for debugging only.
  */
index d732c31ad148f6543c9bb162a0eaaf09e0954ebb..390b422642b799566cb1a76c4af155286b2111b7 100644 (file)
@@ -189,6 +189,16 @@ extern void
 _swrast_delete_texture_image(struct gl_context *ctx,
                              struct gl_texture_image *texImage);
 
+extern GLboolean
+_swrast_alloc_texture_image_buffer(struct gl_context *ctx,
+                                   struct gl_texture_image *texImage,
+                                   gl_format format, GLsizei width,
+                                   GLsizei height, GLsizei depth);
+
+extern void
+_swrast_free_texture_image_buffer(struct gl_context *ctx,
+                                  struct gl_texture_image *texImage);
+
 extern void
 _swrast_map_teximage(struct gl_context *ctx,
                     struct gl_texture_image *texImage,