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

Brian Paul brianp at kemper.freedesktop.org
Sat Sep 17 20:58:38 UTC 2011


Module: Mesa
Branch: master
Commit: 78026b8acef9d6eea4f37d9c5435447944d1befd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=78026b8acef9d6eea4f37d9c5435447944d1befd

Author: Brian Paul <brianp at vmware.com>
Date:   Sat Sep 17 14:50:49 2011 -0600

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

---

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

diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 6dfa423..f170d23 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);
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 2cdc8ed..b958615 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4508,16 +4508,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
@@ -4549,7 +4539,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;
@@ -4558,10 +4547,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;
    }
@@ -4614,7 +4602,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;
@@ -4623,10 +4610,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;
    }
@@ -4678,7 +4664,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;
@@ -4689,13 +4674,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;
    }
 
@@ -4966,10 +4948,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