mesa: removed gl_texture_image::CompressedSize field
authorBrian Paul <brianp@vmware.com>
Fri, 2 Oct 2009 03:13:25 +0000 (21:13 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 2 Oct 2009 03:13:34 +0000 (21:13 -0600)
Just call ctx->Driver.CompressedTextureSize() when we need to get
the compressed image size.

src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/tdfx/tdfx_tex.c
src/mesa/drivers/dri/unichrome/via_tex.c
src/mesa/main/dd.h
src/mesa/main/mipmap.c
src/mesa/main/mtypes.h
src/mesa/main/teximage.c
src/mesa/main/texstore.c
src/mesa/state_tracker/st_cb_texture.c

index 9e13ba6871a34cf8ef2d74a02a8702915df07e84..dd436becab28976d4a919e5f5ec196a4ab8531c6 100644 (file)
@@ -340,11 +340,8 @@ intelTexImage(GLcontext * ctx,
 
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
       texelBytes = 0;
-      texImage->CompressedSize =
-        ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
-                                          texImage->Height, texImage->Depth,
-                                          texImage->TexFormat);
-   } else {
+   }
+   else {
       texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
       
       /* Minimum pitch of 32 bytes */
@@ -495,7 +492,11 @@ intelTexImage(GLcontext * ctx,
    else {
       /* Allocate regular memory and store the image there temporarily.   */
       if (_mesa_is_format_compressed(texImage->TexFormat)) {
-         sizeInBytes = texImage->CompressedSize;
+         sizeInBytes = ctx->Driver.CompressedTextureSize(ctx,
+                                                         texImage->Width,
+                                                         texImage->Height,
+                                                         texImage->Depth,
+                                                         texImage->TexFormat);
          dstRowStride =
             _mesa_compressed_row_stride(texImage->TexFormat, width);
          assert(dims != 3);
index ce393ffeb6c8c14f98977eaf0864ad04e26a49c8..2c28011057d360d4a723da85ac5be5571881dbc0 100644 (file)
@@ -547,13 +547,7 @@ static void radeon_teximage(
 
        if (_mesa_is_format_compressed(texImage->TexFormat)) {
                texelBytes = 0;
-               texImage->CompressedSize =
-                       ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
-                                          texImage->Height, texImage->Depth,
-                                          texImage->TexFormat);
        } else {
-               texImage->CompressedSize = 0;
-
                texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
                /* Minimum pitch of 32 bytes */
                if (postConvWidth * texelBytes < 32) {
@@ -590,7 +584,12 @@ static void radeon_teximage(
        } else {
                int size;
                if (_mesa_is_format_compressed(texImage->TexFormat)) {
-                       size = texImage->CompressedSize;
+                        size = ctx->Driver.CompressedTextureSize(ctx,
+                                                         texImage->Width,
+                                                         texImage->Height,
+                                                         texImage->Depth,
+                                                         texImage->TexFormat);
+
                } else {
                        size = texImage->Width * texImage->Height * texImage->Depth * _mesa_get_format_bytes(texImage->TexFormat);
                }
index 8b68137eedfa349569feb8b6c4db589289581609..5e9421aa2ac8058eed1762bef86a75f529776101 100644 (file)
@@ -1409,13 +1409,13 @@ tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
     texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
 
     if (_mesa_is_format_compressed(texImage->TexFormat)) {
-       texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
-                                                               mml->width,
-                                                               mml->height,
-                                                               1,
-                                                               mesaFormat);
+       GLuint compressedSize = ctx->Driver.CompressedTextureSize(ctx,
+                                                                 mml->width,
+                                                                 mml->height,
+                                                                 1,
+                                                                 mesaFormat);
        dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat, mml->width);
-       texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
+       texImage->Data = _mesa_alloc_texmemory(compressedSize);
     } else {
        dstRowStride = mml->width * texelBytes;
        texImage->Data = _mesa_alloc_texmemory(mml->width * mml->height * texelBytes);
@@ -1580,7 +1580,8 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
     tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
     tdfxTexInfo *ti;
     tdfxMipMapLevel *mml;
-    GLuint mesaFormat;
+    gl_format mesaFormat;
+    GLuint compressedSize;
 
     if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
         fprintf(stderr, "tdfxCompressedTexImage2D: id=%d int 0x%x  %dx%d\n",
@@ -1637,12 +1638,12 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
 
     /* allocate new storage for texture image, if needed */
     if (!texImage->Data) {
-       texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
-                                                                mml->width,
-                                                                mml->height,
-                                                                1,
-                                                                mesaFormat);
-       texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
+       compressedSize = ctx->Driver.CompressedTextureSize(ctx,
+                                                          mml->width,
+                                                          mml->height,
+                                                          1,
+                                                          mesaFormat);
+       texImage->Data = _mesa_alloc_texmemory(compressedSize);
        if (!texImage->Data) {
           _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
           return;
@@ -1677,7 +1678,7 @@ tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
                                 texImage->Data);
        ti->padded = GL_TRUE;
     } else {
-       MEMCPY(texImage->Data, data, texImage->CompressedSize);
+       MEMCPY(texImage->Data, data, compressedSize);
     }
 
     RevalidateTexture(ctx, texObj);
index 13458aba1c2814ffb12849ab5584cff7d3644cec..a99aa9debc95669d26c0d216c6064afe1c0d1c0b 100644 (file)
@@ -674,6 +674,7 @@ static void viaTexImage(GLcontext *ctx,
    struct via_texture_object *viaObj = (struct via_texture_object *)texObj;
    struct via_texture_image *viaImage = (struct via_texture_image *)texImage;
    int heaps[3], nheaps, i;
+   GLuint compressedSize;
 
    if (!is_empty_list(&vmesa->freed_tex_buffers)) {
       viaCheckBreadcrumb(vmesa, 0);
@@ -697,7 +698,7 @@ static void viaTexImage(GLcontext *ctx,
 
    if (texelBytes == 0) {
       /* compressed format */
-      texImage->CompressedSize =
+      compressedSize =
          ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
                                            texImage->Height, texImage->Depth,
                                            texImage->TexFormat);
@@ -714,7 +715,7 @@ static void viaTexImage(GLcontext *ctx,
 
    /* allocate memory */
    if (_mesa_is_format_compressed(texImage->TexFormat))
-      sizeInBytes = texImage->CompressedSize;
+      sizeInBytes = compressedSize;
    else
       sizeInBytes = postConvWidth * postConvHeight * texelBytes;
 
index 9131f20f5202c70fca1ec1b4211ef80704643bd9..64bf9cba19d1dd8b1da225b059f1ebd454d22600 100644 (file)
@@ -481,7 +481,7 @@ struct dd_function_table {
     */
    GLuint (*CompressedTextureSize)( GLcontext *ctx, GLsizei width,
                                     GLsizei height, GLsizei depth,
-                                    GLenum format );
+                                    GLuint mesaFormat );
    /*@}*/
 
    /**
index f6d6ce33c8645b2669a7b228ec6aff5cd5a5317e..e24e7285c360f8014b1596f46c98eb0a1f01eba3 100644 (file)
@@ -1614,24 +1614,19 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
       dstImage->TexFormat = srcImage->TexFormat;
       dstImage->FetchTexelc = srcImage->FetchTexelc;
       dstImage->FetchTexelf = srcImage->FetchTexelf;
+
+      /* Alloc new teximage data buffer.
+       * Setup src and dest data pointers.
+       */
       if (_mesa_is_format_compressed(dstImage->TexFormat)) {
-         dstImage->CompressedSize
+         GLuint dstCompressedSize
             = ctx->Driver.CompressedTextureSize(ctx, dstImage->Width,
                                               dstImage->Height,
                                               dstImage->Depth,
                                               dstImage->TexFormat);
-         ASSERT(dstImage->CompressedSize > 0);
-      }
-
-      ASSERT(dstImage->TexFormat);
-      ASSERT(dstImage->FetchTexelc);
-      ASSERT(dstImage->FetchTexelf);
+         ASSERT(dstCompressedSize > 0);
 
-      /* Alloc new teximage data buffer.
-       * Setup src and dest data pointers.
-       */
-      if (_mesa_is_format_compressed(dstImage->TexFormat)) {
-         dstImage->Data = _mesa_alloc_texmemory(dstImage->CompressedSize);
+         dstImage->Data = _mesa_alloc_texmemory(dstCompressedSize);
          if (!dstImage->Data) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "generating mipmaps");
             return;
@@ -1653,6 +1648,10 @@ _mesa_generate_mipmap(GLcontext *ctx, GLenum target,
          dstData = (GLubyte *) dstImage->Data;
       }
 
+      ASSERT(dstImage->TexFormat);
+      ASSERT(dstImage->FetchTexelc);
+      ASSERT(dstImage->FetchTexelf);
+
       _mesa_generate_mipmap_level(target, datatype, comps, border,
                                   srcWidth, srcHeight, srcDepth, 
                                   srcData, srcImage->RowStride,
index f084edb8403df1b480d6b15734e50e35ffad9d1f..8e6e0d09beb4e8e6ba5b784a5422c22f7a5e3fea 100644 (file)
@@ -1173,8 +1173,6 @@ struct gl_texture_image
    FetchTexelFuncC FetchTexelc;        /**< GLchan texel fetch function pointer */
    FetchTexelFuncF FetchTexelf;        /**< Float texel fetch function pointer */
 
-   GLuint CompressedSize;      /**< GL_ARB_texture_compression */
-
    GLuint RowStride;           /**< Padded width in units of texels */
    GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
                                      each 2D slice in 'Data', in texels */
index 86f46b9551707f47e7f41a1646bf01ea07c3b524..438a316b9c19f8eb06aa48fd0c5cbdaba17eb2cf 100644 (file)
@@ -903,7 +903,6 @@ clear_teximage_fields(struct gl_texture_image *img)
    img->TexFormat = MESA_FORMAT_NONE;
    img->FetchTexelc = NULL;
    img->FetchTexelf = NULL;
-   img->CompressedSize = 0;
 }
 
 
@@ -966,8 +965,6 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
 
    img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
 
-   img->CompressedSize = 0;
-
    if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
        (height == 1 || _mesa_is_pow_two(img->Height2)) &&
        (depth == 1 || _mesa_is_pow_two(img->Depth2)))
index 0fa8c448176bcda57b21416045e9d4244c18c727..133b0370c8f639d2c89f8def9bf0828bdc98bf59 100644 (file)
@@ -3159,34 +3159,12 @@ _mesa_unmap_teximage_pbo(GLcontext *ctx,
 }
 
 
-static void
-compute_texture_size(GLcontext *ctx, struct gl_texture_image *texImage)
-{
-   if (_mesa_is_format_compressed(texImage->TexFormat)) {
-      texImage->CompressedSize =
-         ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
-                                           texImage->Height, texImage->Depth,
-                                           texImage->TexFormat);
-   }
-   else {
-      /* non-compressed format */
-      texImage->CompressedSize = 0;
-   }
-}
-
-
 /** Return texture size in bytes */
 static GLuint
 texture_size(const struct gl_texture_image *texImage)
 {
-   GLuint sz;
-
-   if (_mesa_is_format_compressed(texImage->TexFormat))
-      sz = texImage->CompressedSize;
-   else
-      sz = texImage->Width * texImage->Height * texImage->Depth *
-         _mesa_get_format_bytes(texImage->TexFormat);
-
+   GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
+                                       texImage->Height, texImage->Depth);
    return sz;
 }
 
@@ -3228,7 +3206,7 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLint sizeInBytes;
+   GLuint sizeInBytes;
    (void) border;
 
    texImage->TexFormat
@@ -3236,11 +3214,9 @@ _mesa_store_teximage1d(GLcontext *ctx, GLenum target, GLint level,
    ASSERT(texImage->TexFormat);
 
    _mesa_set_fetch_functions(texImage, 1);
-   compute_texture_size(ctx, texImage);
 
    /* allocate memory */
    sizeInBytes = texture_size(texImage);
-
    texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
    if (!texImage->Data) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
@@ -3293,7 +3269,7 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLint texelBytes, sizeInBytes;
+   GLuint sizeInBytes;
    (void) border;
 
    texImage->TexFormat
@@ -3301,9 +3277,6 @@ _mesa_store_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    ASSERT(texImage->TexFormat);
 
    _mesa_set_fetch_functions(texImage, 2);
-   compute_texture_size(ctx, texImage);
-
-   texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
 
    /* allocate memory */
    sizeInBytes = texture_size(texImage);
@@ -3355,7 +3328,7 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
                        struct gl_texture_object *texObj,
                        struct gl_texture_image *texImage)
 {
-   GLint texelBytes, sizeInBytes;
+   GLuint sizeInBytes;
    (void) border;
 
    texImage->TexFormat
@@ -3363,9 +3336,6 @@ _mesa_store_teximage3d(GLcontext *ctx, GLenum target, GLint level,
    ASSERT(texImage->TexFormat);
 
    _mesa_set_fetch_functions(texImage, 3);
-   compute_texture_size(ctx, texImage);
-
-   texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
 
    /* allocate memory */
    sizeInBytes = texture_size(texImage);
@@ -3570,7 +3540,6 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
    ASSERT(texImage->TexFormat);
 
    _mesa_set_fetch_functions(texImage, 2);
-   compute_texture_size(ctx, texImage);
 
    /* allocate storage */
    texImage->Data = _mesa_alloc_texmemory(imageSize);
@@ -3586,7 +3555,6 @@ _mesa_store_compressed_teximage2d(GLcontext *ctx, GLenum target, GLint level,
       return;
 
    /* copy the data */
-   ASSERT(texImage->CompressedSize == (GLuint) imageSize);
    MEMCPY(texImage->Data, data, imageSize);
 
    _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
index 2574eeb996ef13b233b51a6e7790020f922b971b..dc3ab61425965e405235c9f4b7c36c50a24dfd65 100644 (file)
@@ -563,10 +563,6 @@ st_TexImage(GLcontext * ctx,
    if (_mesa_is_format_compressed(texImage->TexFormat)) {
       /* must be a compressed format */
       texelBytes = 0;
-      texImage->CompressedSize =
-        ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
-                                          texImage->Height, texImage->Depth,
-                                          texImage->TexFormat);
    }
    else {
       texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
@@ -697,7 +693,11 @@ st_TexImage(GLcontext * ctx,
    else {
       /* Allocate regular memory and store the image there temporarily.   */
       if (_mesa_is_format_compressed(texImage->TexFormat)) {
-         sizeInBytes = texImage->CompressedSize;
+         sizeInBytes = ctx->Driver.CompressedTextureSize(ctx,
+                                                         texImage->Width,
+                                                         texImage->Height,
+                                                         texImage->Depth,
+                                                         texImage->TexFormat);
          dstRowStride =
             _mesa_compressed_row_stride(texImage->TexFormat, width);
          assert(dims != 3);