mesa/drivers: use _mesa_get_format_bytes()
authorBrian Paul <brianp@vmware.com>
Mon, 28 Sep 2009 02:24:59 +0000 (20:24 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 28 Sep 2009 02:24:59 +0000 (20:24 -0600)
14 files changed:
src/mesa/drivers/dri/i810/i810texmem.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/intel/intel_tex_validate.c
src/mesa/drivers/dri/mach64/mach64_texmem.c
src/mesa/drivers/dri/mach64/mach64_texstate.c
src/mesa/drivers/dri/mga/mga_texstate.c
src/mesa/drivers/dri/r128/r128_texmem.c
src/mesa/drivers/dri/r128/r128_texstate.c
src/mesa/drivers/dri/r200/r200_texstate.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
src/mesa/drivers/dri/radeon/radeon_texstate.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/sis/sis_tex.c

index 5ad66dbf5cb1e38d6066227757c4fab98833b412..8cbe38f5fcb88e3ca5fab971abd77bd3190c711b 100644 (file)
@@ -92,44 +92,47 @@ static void i810UploadTexLevel( i810ContextPtr imesa,
 {
    const struct gl_texture_image *image = t->image[hwlevel].image;
    int j;
+   GLuint texelBytes;
 
    if (!image || !image->Data)
       return;
 
-   if (image->Width * image->TexFormat->TexelBytes == t->Pitch) {
+   texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
+
+   if (image->Width * texelBytes == t->Pitch) {
         GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
         GLubyte *src = (GLubyte *)image->Data;
         
         memcpy( dst, src, t->Pitch * image->Height );
    }
-   else switch (image->TexFormat->TexelBytes) {
-   case 1:
-      {
-        GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
-        GLubyte *src = (GLubyte *)image->Data;
-
-        for (j = 0 ; j < image->Height ; j++, dst += t->Pitch) {
-           __memcpy(dst, src, image->Width );
-           src += image->Width;
-        }
+   else {
+      switch (texelBytes) {
+      case 1:
+         {
+            GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
+            GLubyte *src = (GLubyte *)image->Data;
+
+            for (j = 0 ; j < image->Height ; j++, dst += t->Pitch) {
+               __memcpy(dst, src, image->Width );
+               src += image->Width;
+            }
+         }
+         break;
+      case 2:
+         {
+            GLushort *dst = (GLushort *)(t->BufAddr + t->image[hwlevel].offset);
+            GLushort *src = (GLushort *)image->Data;
+
+            for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/2)) {
+               __memcpy(dst, src, image->Width * 2 );
+               src += image->Width;
+            }
+         }
+         break;
+      default:
+         fprintf(stderr, "%s: Not supported texel size %d\n",
+                 __FUNCTION__, texelBytes);
       }
-      break;
-
-   case 2:
-      {
-        GLushort *dst = (GLushort *)(t->BufAddr + t->image[hwlevel].offset);
-        GLushort *src = (GLushort *)image->Data;
-
-        for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/2)) {
-           __memcpy(dst, src, image->Width * 2 );
-           src += image->Width;
-        }
-      }
-      break;
-
-   default:
-      fprintf(stderr, "%s: Not supported texel size %d\n",
-             __FUNCTION__, image->TexFormat->TexelBytes);
    }
 }
 
index c985da5aa25d90e9daf695dafe4a17a616beb8e1..188333c75f763d50b43630183bb6036383791b5f 100644 (file)
@@ -307,7 +307,7 @@ intel_miptree_match_image(struct intel_mipmap_tree *mt,
 
    if (!image->IsCompressed &&
        !mt->compressed &&
-       image->TexFormat->TexelBytes != mt->cpp)
+       _mesa_get_format_bytes(image->TexFormat->MesaFormat) != mt->cpp)
       return GL_FALSE;
 
    /* Test image dimensions against the base level image adjusted for
index 5c98860cdadb983acd71bb86128aedff48049d98..3bafbba3718361edce278deed4699f22afddf9e5 100644 (file)
@@ -70,6 +70,7 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
    GLuint depth = intelImage->base.Depth;
    GLuint l2width, l2height, l2depth;
    GLuint i, comp_byte = 0;
+   GLuint texelBytes;
 
    DBG("%s\n", __FUNCTION__);
 
@@ -126,6 +127,9 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
    assert(!intelObj->mt);
    if (intelImage->base.IsCompressed)
       comp_byte = intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
+
+   texelBytes = _mesa_get_format_bytes(intelImage->base.TexFormat->MesaFormat);
+
    intelObj->mt = intel_miptree_create(intel,
                                        intelObj->base.Target,
                                        intelImage->base._BaseFormat,
@@ -135,7 +139,7 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
                                        width,
                                        height,
                                        depth,
-                                       intelImage->base.TexFormat->TexelBytes,
+                                       texelBytes,
                                        comp_byte,
                                       expect_accelerated_upload);
 
@@ -399,12 +403,14 @@ intelTexImage(GLcontext * ctx,
       assert(intelImage->mt);
    } else if (intelImage->base.Border == 0) {
       int comp_byte = 0;
+      GLuint texelBytes = _mesa_get_format_bytes(intelImage->base.TexFormat->MesaFormat);
 
       if (intelImage->base.IsCompressed) {
         comp_byte =
            intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
       }
 
+
       /* Didn't fit in the object miptree, but it's suitable for inclusion in
        * a miptree, so create one just for our level and store it in the image.
        * It'll get moved into the object miptree at validate time.
@@ -414,7 +420,7 @@ intelTexImage(GLcontext * ctx,
                                            internalFormat,
                                            level, level,
                                            width, height, depth,
-                                           intelImage->base.TexFormat->TexelBytes,
+                                           texelBytes,
                                            comp_byte, pixels == NULL);
 
    }
index a284d5475f4bce9227fa5844954e8b46b2b88406..0393d7915abbaf263082903c375cd1b6bcf7daa5 100644 (file)
@@ -169,7 +169,8 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
       comp_byte = intel_compressed_num_bytes(firstImage->base.TexFormat->MesaFormat);
       cpp = comp_byte;
    }
-   else cpp = firstImage->base.TexFormat->TexelBytes;
+   else
+      cpp = _mesa_get_format_bytes(firstImage->base.TexFormat->MesaFormat);
 
    /* Check tree can hold all active levels.  Check tree matches
     * target, imageFormat, etc.
index 734e547952ec063aee6734f64328d8acbc015a69..843b2310517ea93726cf76352c3d7dc180c36af1 100644 (file)
@@ -76,6 +76,7 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
    struct gl_texture_image *image;
    int texelsPerDword = 0;
    int dwords;
+   GLuint texelBytes;
 
    /* Ensure we have a valid texture to upload */
    if ( ( level < 0 ) || ( level > mmesa->glCtx->Const.MaxTextureLevels ) )
@@ -85,7 +86,9 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
    if ( !image )
       return;
 
-   switch ( image->TexFormat->TexelBytes ) {
+   texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
+
+   switch ( texelBytes ) {
    case 1: texelsPerDword = 4; break;
    case 2: texelsPerDword = 2; break;
    case 4: texelsPerDword = 1; break;
@@ -118,8 +121,8 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
    {
       CARD32 *dst = (CARD32 *)((char *)mach64Screen->agpTextures.map + t->base.memBlock->ofs);
       const GLubyte *src = (const GLubyte *) image->Data +
-        (y * image->Width + x) * image->TexFormat->TexelBytes;
-      const GLuint bytes = width * height * image->TexFormat->TexelBytes;
+        (y * image->Width + x) * texelBytes;
+      const GLuint bytes = width * height * texelBytes;
       memcpy(dst, src, bytes);
    }
 
@@ -140,6 +143,7 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
    const int maxdwords = (MACH64_BUFFER_MAX_DWORDS - (MACH64_HOSTDATA_BLIT_OFFSET / 4));
    CARD32 pitch, offset;
    int i;
+   GLuint texelBytes;
 
    /* Ensure we have a valid texture to upload */
    if ( ( level < 0 ) || ( level > mmesa->glCtx->Const.MaxTextureLevels ) )
@@ -149,7 +153,9 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
    if ( !image )
       return;
 
-   switch ( image->TexFormat->TexelBytes ) {
+   texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
+
+   switch ( texelBytes ) {
    case 1: texelsPerDword = 4; break;
    case 2: texelsPerDword = 2; break;
    case 4: texelsPerDword = 1; break;
@@ -259,7 +265,7 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
 
        {
           const GLubyte *src = (const GLubyte *) image->Data +
-             (y * image->Width + x) * image->TexFormat->TexelBytes;
+             (y * image->Width + x) * texelBytes;
 
           mach64FireBlitLocked( mmesa, (void *)src, offset, pitch, format,
                                x, y, width, height );
index fd2369dd882f18cc9fc7783a0f871ec5f1b0a1a7..ff03b0c40aba96258d3a6be8eb92da7e9c886c67 100644 (file)
@@ -89,7 +89,7 @@ static void mach64SetTexImages( mach64ContextPtr mmesa,
 
    totalSize = ( baseImage->Height *
                 baseImage->Width *
-                baseImage->TexFormat->TexelBytes );
+                _mesa_get_format_bytes(baseImage->TexFormat->MesaFormat) );
 
    totalSize = (totalSize + 31) & ~31;
 
index ad765d1dd76f5ae29d80220b2a1b7ab6e0bd8bce..8f78ab9bd4aaf33ad3f896e02e132591363fbe9b 100644 (file)
@@ -131,7 +131,7 @@ mgaSetTexImages( mgaContextPtr mmesa,
         break;
 
       size = texImage->Width * texImage->Height *
-         baseImage->TexFormat->TexelBytes;
+         _mesa_get_format_bytes(baseImage->TexFormat->MesaFormat);
 
       t->offsets[i] = totalSize;
       t->base.dirty_images[0] |= (1<<i);
index 111fe1fd7424a8746d45f2668e2ea238c297bbdd..c369e14bd50da0861c3e89869e825b437d8fd5f3 100644 (file)
@@ -95,7 +95,7 @@ static void uploadSubImage( r128ContextPtr rmesa, r128TexObjPtr t,
    if ( !image )
       return;
 
-   switch ( image->TexFormat->TexelBytes ) {
+   switch ( _mesa_get_format_bytes(image->TexFormat->MesaFormat) ) {
    case 1: texelsPerDword = 4; break;
    case 2: texelsPerDword = 2; break;
    case 4: texelsPerDword = 1; break;
@@ -215,9 +215,11 @@ static void uploadSubImage( r128ContextPtr rmesa, r128TexObjPtr t,
 
       /* Copy the next chunck of the texture image into the blit buffer */
       {
+         const GLuint texelBytes =
+            _mesa_get_format_bytes(image->TexFormat->MesaFormat);
          const GLubyte *src = (const GLubyte *) image->Data +
-            (y * image->Width + x) * image->TexFormat->TexelBytes;
-         const GLuint bytes = width * height * image->TexFormat->TexelBytes;
+            (y * image->Width + x) * texelBytes;            
+         const GLuint bytes = width * height * texelBytes;
          memcpy(dst, src, bytes);
       }
 
index a9c9568003b851789e14cdc0dfd3fd7f2cd8ec74..9f4f9aea2db26be929239c2c45c0db72a13ae4e3 100644 (file)
@@ -123,7 +123,7 @@ static void r128SetTexImages( r128ContextPtr rmesa,
 
       totalSize += (tObj->Image[0][i]->Height *
                    tObj->Image[0][i]->Width *
-                   tObj->Image[0][i]->TexFormat->TexelBytes);
+                   _mesa_get_format_bytes(tObj->Image[0][i]->TexFormat->MesaFormat));
 
       /* Offsets must be 32-byte aligned for host data blits and tiling */
       totalSize = (totalSize + 31) & ~31;
index c94834752edca6bb5659c47bc1d30f0b6f5f9d97..03f0613e7a1da9a52a2ce603e3c2efafdb14426c 100644 (file)
@@ -1437,7 +1437,7 @@ static void setup_hardware_state(r200ContextPtr rmesa, radeonTexObj *t)
    log2Width  = firstImage->WidthLog2;
    log2Height = firstImage->HeightLog2;
    log2Depth  = firstImage->DepthLog2;
-   texelBytes = firstImage->TexFormat->TexelBytes;
+   texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
 
 
    if (!t->image_override) {
index 11c21037c4494ea7db70705da972004946bc5f45..851474f871603d5500b94dac2a217abaed55d88e 100644 (file)
@@ -347,6 +347,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
        GLuint compressed;
        GLuint numfaces = 1;
        GLuint firstLevel, lastLevel;
+       GLuint texelBytes;
 
        calculate_first_last_level(texObj, &firstLevel, &lastLevel, 0, texObj->BaseLevel);
        if (texObj->Target == GL_TEXTURE_CUBE_MAP)
@@ -354,6 +355,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
 
        firstImage = texObj->Image[0][firstLevel];
        compressed = firstImage->IsCompressed ? firstImage->TexFormat->MesaFormat : 0;
+       texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
 
        return (mt->firstLevel == firstLevel &&
                mt->lastLevel == lastLevel &&
@@ -361,7 +363,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
                mt->height0 == firstImage->Height &&
                mt->depth0 == firstImage->Depth &&
                mt->compressed == compressed &&
-               (!mt->compressed ? (mt->bpp == firstImage->TexFormat->TexelBytes) : 1));
+               (!mt->compressed ? (mt->bpp == texelBytes) : 1));
 }
 
 
@@ -375,6 +377,7 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
        GLuint compressed = image->base.IsCompressed ? image->base.TexFormat->MesaFormat : 0;
        GLuint numfaces = 1;
        GLuint firstLevel, lastLevel;
+       GLuint texelBytes;
 
        assert(!t->mt);
 
@@ -385,11 +388,13 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
        if (level != firstLevel || face >= numfaces)
                return;
 
+       texelBytes = _mesa_get_format_bytes(image->base.TexFormat->MesaFormat);
+
        t->mt = radeon_miptree_create(rmesa, t, t->base.Target,
                image->base.InternalFormat,
                firstLevel, lastLevel,
                image->base.Width, image->base.Height, image->base.Depth,
-               image->base.TexFormat->TexelBytes, t->tile_bits, compressed);
+               texelBytes, t->tile_bits, compressed);
 }
 
 /* Although we use the image_offset[] array to store relative offsets
index ae41b90efe5d2be008e9064250151cc5793c8bba..a00497a8f9493c848efb0fb1a3674f595a12a824 100644 (file)
@@ -1031,7 +1031,7 @@ static GLboolean setup_hardware_state(r100ContextPtr rmesa, radeonTexObj *t, int
    log2Width  = firstImage->WidthLog2;
    log2Height = firstImage->HeightLog2;
    log2Depth  = firstImage->DepthLog2;
-   texelBytes = firstImage->TexFormat->TexelBytes;
+   texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
 
    if (!t->image_override) {
       if (VALID_FORMAT(firstImage->TexFormat->MesaFormat)) {
index a35c783d2ee44ee10f29489082d7256d54978446..416ca1974b16765fb32be778b86df2f27bf0bcf1 100644 (file)
@@ -900,7 +900,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt, radeon_texture_imag
                        srcrowstride = _mesa_compressed_row_stride(image->base.TexFormat->MesaFormat, image->base.Width);
                } else {
                        height = image->base.Height * image->base.Depth;
-                       srcrowstride = image->base.Width * image->base.TexFormat->TexelBytes;
+                       srcrowstride = image->base.Width * _mesa_get_format_bytes(image->base.TexFormat->MesaFormat);
                }
 
 //             if (mt->tilebits)
index f40a8732098a8bce49332c94b8724bf759706333..38a309d41fc05a9963c4848fb046089a96f627c9 100644 (file)
@@ -107,7 +107,7 @@ sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
    }
    assert(t->format == image->_BaseFormat);
 
-   texel_size = image->TexFormat->TexelBytes;
+   texel_size = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
    size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS;
 
    addr = sisAllocFB( smesa, size, &t->image[level].handle );