Mesa (map-texture-image-v5): mesa: use ctx->Driver.AllocTextureImageBuffer( ) to alloc texture memory

Brian Paul brianp at kemper.freedesktop.org
Mon Aug 29 20:37:58 PDT 2011


Module: Mesa
Branch: map-texture-image-v5
Commit: 9c1ad1783511cb5a70995b25b5f3c401d5fa2dcb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9c1ad1783511cb5a70995b25b5f3c401d5fa2dcb

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Aug 29 21:23:21 2011 -0600

mesa: use ctx->Driver.AllocTextureImageBuffer() to alloc texture memory

---

 src/mesa/main/mipmap.c   |   19 ++++++++++---------
 src/mesa/main/texstore.c |   46 ++++++++++++++--------------------------------
 2 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index cdb7144..3880ddb 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -1956,15 +1956,13 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target,
                                  srcImage->TexFormat);
       dstImage->DriverData = NULL;
 
-      /* Alloc new teximage data buffer */
-      {
-         GLuint size = _mesa_format_image_size(dstImage->TexFormat,
-                                               dstWidth, dstHeight, dstDepth);
-         dstImage->Data = _mesa_alloc_texmemory(size);
-         if (!dstImage->Data) {
-            _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
-            return;
-         }
+      /* Alloc storage for new texture image */
+      if (!ctx->Driver.AllocTextureImageBuffer(ctx, dstImage,
+                                               dstImage->TexFormat,
+                                               dstWidth, dstHeight,
+                                               dstDepth)) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
+         return;
       }
 
       ASSERT(dstImage->TexFormat);
@@ -2085,6 +2083,9 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
          return;
       }
 
+      /* Free old image data */
+      ctx->Driver.FreeTextureImageBuffer(ctx, dstImage);
+
       _mesa_generate_mipmap_level(target, datatype, comps, border,
                                   srcWidth, srcHeight, srcDepth,
                                   temp_src, temp_src_stride / components,
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index e9915a7..d4bac0b 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4510,16 +4510,6 @@ _mesa_texstore(TEXSTORE_PARAMS)
 }
 
 
-/** Return texture size in bytes */
-static GLuint
-texture_size(const struct gl_texture_image *texImage)
-{
-   GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
-                                       texImage->Height, texImage->Depth);
-   return sz;
-}
-
-
 /**
  * Normally, we'll only _write_ texel data to a texture when we map it.
  * But if the user is providing depth or stencil values and the texture
@@ -4551,7 +4541,6 @@ _mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLuint sizeInBytes;
    const GLbitfield rwMode = get_read_write_mode(format, texImage->TexFormat);
    const GLuint zeroImageOffset = 0;
    GLubyte *dstMap;
@@ -4560,10 +4549,9 @@ _mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
 
    (void) border;
 
-   /* allocate memory */
-   sizeInBytes = texture_size(texImage);
-   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
-   if (!texImage->Data) {
+   /* allocate storage for texture data */
+   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
+                                            width, 1, 1)) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
       return;
    }
@@ -4616,7 +4604,6 @@ _mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLuint sizeInBytes;
    const GLbitfield rwMode = get_read_write_mode(format, texImage->TexFormat);
    const GLuint zeroImageOffset = 0;
    GLubyte *dstMap;
@@ -4625,10 +4612,9 @@ _mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
 
    (void) border;
 
-   /* allocate memory */
-   sizeInBytes = texture_size(texImage);
-   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
-   if (!texImage->Data) {
+   /* allocate storage for texture data */
+   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
+                                            width, height, 1)) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
       return;
    }
@@ -4680,7 +4666,6 @@ _mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLuint sizeInBytes;
    const GLbitfield rwMode = get_read_write_mode(format, texImage->TexFormat);
    GLboolean success;
    GLint slice;
@@ -4691,13 +4676,10 @@ _mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
 
    (void) border;
 
-   /* allocate memory */
-   sizeInBytes = texture_size(texImage);
-   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
-   if (!texImage->Data) {
-      /* Note: we check for a NULL image pointer here, _after_ we allocated
-       * memory for the texture.  That's what the GL spec calls for.
-       */
+   /* allocate storage for texture data */
+   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
+                                            width, height, depth)) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
       return;
    }
 
@@ -4968,10 +4950,10 @@ _mesa_store_compressed_teximage2d(struct gl_context *ctx,
    ASSERT(texImage->Depth == 1);
    ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
 
-   /* allocate storage */
-   texImage->Data = _mesa_alloc_texmemory(imageSize);
-   if (!texImage->Data) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
+   /* allocate storage for texture data */
+   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
+                                            width, height, 1)) {
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
       return;
    }
 



More information about the mesa-commit mailing list