Merge branch 'texformat-rework'
authorBrian Paul <brianp@vmware.com>
Thu, 29 Oct 2009 03:24:11 +0000 (21:24 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 29 Oct 2009 03:24:11 +0000 (21:24 -0600)
Conflicts:
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/drivers/dri/s3v/s3v_tex.c
src/mesa/drivers/dri/s3v/s3v_xmesa.c
src/mesa/drivers/dri/trident/trident_context.c
src/mesa/main/debug.c
src/mesa/main/mipmap.c
src/mesa/main/texformat.c
src/mesa/main/texgetimage.c

58 files changed:
1  2 
progs/tests/texcmp.c
src/mesa/SConscript
src/mesa/drivers/common/driverfuncs.c
src/mesa/drivers/common/meta.c
src/mesa/drivers/dri/common/drirenderbuffer.h
src/mesa/drivers/dri/i810/i810screen.c
src/mesa/drivers/dri/i915/i830_texstate.c
src/mesa/drivers/dri/i915/i915_texstate.c
src/mesa/drivers/dri/i915/i915_vtbl.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_blit.c
src/mesa/drivers/dri/intel/intel_buffers.c
src/mesa/drivers/dri/intel/intel_context.c
src/mesa/drivers/dri/intel/intel_fbo.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_span.c
src/mesa/drivers/dri/intel/intel_tex.h
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/mach64/mach64_screen.c
src/mesa/drivers/dri/mach64/mach64_tex.c
src/mesa/drivers/dri/mga/mga_xmesa.c
src/mesa/drivers/dri/r128/r128_screen.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/r600/r600_texstate.c
src/mesa/drivers/dri/r600/r700_state.c
src/mesa/drivers/dri/radeon/radeon_fbo.c
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/dri/radeon/radeon_texture.c
src/mesa/drivers/dri/savage/savage_xmesa.c
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/drivers/dri/tdfx/tdfx_screen.c
src/mesa/drivers/dri/unichrome/via_context.c
src/mesa/drivers/dri/unichrome/via_screen.c
src/mesa/main/dd.h
src/mesa/main/debug.c
src/mesa/main/fbobject.c
src/mesa/main/mipmap.c
src/mesa/main/mtypes.h
src/mesa/main/renderbuffer.c
src/mesa/main/texcompress.c
src/mesa/main/texcompress.h
src/mesa/main/texformat.c
src/mesa/main/texgetimage.c
src/mesa/main/teximage.c
src/mesa/main/texobj.c
src/mesa/main/texparam.c
src/mesa/main/texstore.c
src/mesa/sources.mak
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_format.h
src/mesa/state_tracker/st_texture.c
src/mesa/swrast/s_depth.c
windows/VC7/mesa/mesa/mesa.vcproj
windows/VC8/mesa/mesa/mesa.vcproj

Simple merge
Simple merge
Simple merge
index 64b77d864c22490aed5f0e2918301faae026ef85,6b35dbb5ad93b94d474f255b225b643d2c2470ae..22cd6de5640670b6ba147e103b9cde6b749db02f
@@@ -2059,71 -1940,6 +2060,71 @@@ _mesa_meta_Bitmap(GLcontext *ctx
  }
  
  
-    if (!baseImage || baseImage->IsCompressed) {
 +/**
 + * Check if the call to _mesa_meta_GenerateMipmap() will require a
 + * software fallback.  The fallback path will require that the texture
 + * images are mapped.
 + * \return GL_TRUE if a fallback is needed, GL_FALSE otherwise
 + */
 +GLboolean
 +_mesa_meta_check_generate_mipmap_fallback(GLcontext *ctx, GLenum target,
 +                                          struct gl_texture_object *texObj)
 +{
 +   const GLuint fboSave = ctx->DrawBuffer->Name;
 +   struct gen_mipmap_state *mipmap = &ctx->Meta->Mipmap;
 +   struct gl_texture_image *baseImage;
 +   GLuint srcLevel;
 +   GLenum status;
 +
 +   /* check for fallbacks */
 +   if (!ctx->Extensions.EXT_framebuffer_object ||
 +       target == GL_TEXTURE_3D) {
 +      return GL_TRUE;
 +   }
 +
 +   srcLevel = texObj->BaseLevel;
 +   baseImage = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
++   if (!baseImage || _mesa_is_format_compressed(baseImage->TexFormat)) {
 +      return GL_TRUE;
 +   }
 +
 +   /*
 +    * Test that we can actually render in the texture's format.
 +    */
 +   if (!mipmap->FBO)
 +      _mesa_GenFramebuffersEXT(1, &mipmap->FBO);
 +   _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mipmap->FBO);
 +
 +   if (target == GL_TEXTURE_1D) {
 +      _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,
 +                                    GL_COLOR_ATTACHMENT0_EXT,
 +                                    target, texObj->Name, srcLevel);
 +   }
 +   else if (target == GL_TEXTURE_3D) {
 +      GLint zoffset = 0;
 +      _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,
 +                                    GL_COLOR_ATTACHMENT0_EXT,
 +                                    target, texObj->Name, srcLevel, zoffset);
 +   }
 +   else {
 +      /* 2D / cube */
 +      _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
 +                                    GL_COLOR_ATTACHMENT0_EXT,
 +                                    target, texObj->Name, srcLevel);
 +   }
 +
 +   status = _mesa_CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 +
 +   _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSave);
 +
 +   if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
 +      return GL_TRUE;
 +   }
 +
 +   return GL_FALSE;
 +}
 +
 +
  /**
   * Called via ctx->Driver.GenerateMipmap()
   * Note: texture borders and 3D texture support not yet complete.
@@@ -2492,12 -2312,6 +2493,12 @@@ copy_tex_image(GLcontext *ctx, GLuint d
        return;
     }
  
-    if (texImage->TexFormat == &_mesa_null_texformat)
-       texImage->TexFormat = ctx->Driver.ChooseTextureFormat(ctx,
-                                                             internalFormat,
-                                                             format,
-                                                             type);
++   if (texImage->TexFormat == MESA_FORMAT_NONE)
++      texImage->TexFormat = ctx->Driver.ChooseTextureFormat(ctx,
++                                                            internalFormat,
++                                                            format,
++                                                            type);
 +
     _mesa_unlock_texture(ctx, texObj); /* need to unlock first */
  
     /*
index 20ff46b0b0cd1021a3c303b8181482829563beee,98fb853c686325c8a208d86db1b43cbf37360b2e..28263fbe3c65ccac92d9c2dc3e221ab1775f2d0a
@@@ -160,20 -159,13 +159,20 @@@ i830_update_tex_unit(struct intel_conte
  
        pitch = intelObj->pitchOverride;
     } else {
 +      GLuint dst_x, dst_y;
 +
 +      intel_miptree_get_image_offset(intelObj->mt, intelObj->firstLevel, 0, 0,
 +                                   &dst_x, &dst_y);
 +
        dri_bo_reference(intelObj->mt->region->buffer);
        i830->state.tex_buffer[unit] = intelObj->mt->region->buffer;
 -      i830->state.tex_offset[unit] = intel_miptree_image_offset(intelObj->mt,
 -                                                              0, intelObj->
 -                                                              firstLevel);
 +      /* XXX: This calculation is probably broken for tiled images with
 +       * a non-page-aligned offset.
 +       */
 +      i830->state.tex_offset[unit] = (dst_x + dst_y * intelObj->mt->pitch) *
 +       intelObj->mt->cpp;
  
-       format = translate_texture_format(firstImage->TexFormat->MesaFormat,
+       format = translate_texture_format(firstImage->TexFormat,
                                        firstImage->InternalFormat);
        pitch = intelObj->mt->pitch * intelObj->mt->cpp;
     }
index 998a04f7949f05011c4616ea6e623a508116513d,d6bfe5fc7f373b689156f7665f86705c315a2469..3a20e9c3abaa16d12c7faf0f7a3f6d3e9993ad79
@@@ -171,20 -170,13 +170,20 @@@ i915_update_tex_unit(struct intel_conte
  
        pitch = intelObj->pitchOverride;
     } else {
 +      GLuint dst_x, dst_y;
 +
 +      intel_miptree_get_image_offset(intelObj->mt, intelObj->firstLevel, 0, 0,
 +                                   &dst_x, &dst_y);
 +
        dri_bo_reference(intelObj->mt->region->buffer);
        i915->state.tex_buffer[unit] = intelObj->mt->region->buffer;
 -      i915->state.tex_offset[unit] =  intel_miptree_image_offset(intelObj->mt,
 -                                                               0, intelObj->
 -                                                               firstLevel);
 +      /* XXX: This calculation is probably broken for tiled images with
 +       * a non-page-aligned offset.
 +       */
 +      i915->state.tex_offset[unit] = (dst_x + dst_y * intelObj->mt->pitch) *
 +       intelObj->mt->cpp;
  
-       format = translate_texture_format(firstImage->TexFormat->MesaFormat, 
+       format = translate_texture_format(firstImage->TexFormat,
                                        firstImage->InternalFormat,
                                        tObj->DepthMode);
        pitch = intelObj->mt->pitch * intelObj->mt->cpp;
Simple merge
Simple merge
Simple merge
Simple merge
index 24ced0d6c9600cc76c01f3537eb9832989ff1a73,e55c2f02c91ee4485b2e0adea2420834c1f6e6e3..ee8cc29301d8872336bfb8a457741793b525b221
@@@ -27,7 -27,6 +27,8 @@@
  #include "attrib.h"
  #include "colormac.h"
  #include "context.h"
 +#include "enums.h"
++#include "formats.h"
  #include "hash.h"
  #include "imports.h"
  #include "debug.h"
@@@ -376,27 -300,25 +376,28 @@@ static GLuint WriteImages
  
  
  static void
 -dump_texture_cb(GLuint id, void *data, void *userData)
 +dump_texture(struct gl_texture_object *texObj, GLuint writeImages)
  {
 -   struct gl_texture_object *texObj = (struct gl_texture_object *) data;
 -   int i;
 +   const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
     GLboolean written = GL_FALSE;
 -   (void) userData;
 +   GLuint i, j;
  
     _mesa_printf("Texture %u\n", texObj->Name);
 -   _mesa_printf("  Target 0x%x\n", texObj->Target);
 +   _mesa_printf("  Target %s\n", tex_target_name(texObj->Target));
     for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
 -      struct gl_texture_image *texImg = texObj->Image[0][i];
 -      if (texImg) {
 -         _mesa_printf("  Image %u: %d x %d x %d, format %u at %p\n", i,
 -                      texImg->Width, texImg->Height, texImg->Depth,
 -                      texImg->TexFormat, texImg->Data);
 -         if (DumpImages && !written) {
 -            GLuint face = 0;
 -            write_texture_image(texObj, face, i);
 -            written = GL_TRUE;
 +      for (j = 0; j < numFaces; j++) {
 +         struct gl_texture_image *texImg = texObj->Image[j][i];
 +         if (texImg) {
-             _mesa_printf("  Face %u level %u: %d x %d x %d, format %u at %p\n",
++            _mesa_printf("  Face %u level %u: %d x %d x %d, format %s at %p\n",
 +                         j, i,
 +                         texImg->Width, texImg->Height, texImg->Depth,
-                          texImg->TexFormat->MesaFormat, texImg->Data);
++                         _mesa_get_format_name(texImg->TexFormat),
++                         texImg->Data);
 +            if (writeImages == WRITE_ALL ||
 +                (writeImages == WRITE_ONE && !written)) {
 +               write_texture_image(texObj, j, i);
 +               written = GL_TRUE;
 +            }
           }
        }
     }
index 55709ebf9e32f0057715d2aed59e53accfb6da89,c2b7458f5775ce825d8cca14e7ac1f5f8fae3af3..1d6ccf7fdd88df25061fcc8b7114d9076cbe3300
@@@ -34,8 -34,8 +34,9 @@@
  
  #include "buffers.h"
  #include "context.h"
 +#include "enums.h"
  #include "fbobject.h"
+ #include "formats.h"
  #include "framebuffer.h"
  #include "hash.h"
  #include "macros.h"
index c3928fa513f00e06e21a46a4e78d6cdde4a8c8bd,b602d920dfad11f75cc4cd7ab5ec5d542a384969..7350c7a3d2cf3933db86ffd54a182815b8bcb956
@@@ -1508,10 -1510,8 +1509,11 @@@ _mesa_generate_mipmap(GLcontext *ctx, G
     ASSERT(maxLevels > 0);  /* bad target */
  
     /* Find convertFormat - the format that do_row() will process */
-    if (srcImage->IsCompressed) {
++
+    if (_mesa_is_format_compressed(srcImage->TexFormat)) {
 -      /* setup for compressed textures */
 +      /* setup for compressed textures - need to allocate temporary
 +       * image buffers to hold uncompressed images.
 +       */
        GLuint row;
        GLint  components, size;
        GLchan *dst;
Simple merge
Simple merge
index 2cda4dd8598725468581afe297a4a9e18a0edd82,262e8236eddd8152370149a798fd0bf676531438..11f8857fa7cb471cb6cdd6bb88d0a17af214b786
@@@ -313,100 -165,21 +165,71 @@@ _mesa_glenum_to_compressed_format(GLenu
   */
  GLubyte *
  _mesa_compressed_image_address(GLint col, GLint row, GLint img,
-                                GLuint mesaFormat,
+                                gl_format mesaFormat,
                                 GLsizei width, const GLubyte *image)
  {
-    GLubyte *addr;
+    /* XXX only 2D images implemented, not 3D */
+    const GLuint blockSize = _mesa_get_format_bytes(mesaFormat);
+    GLuint bw, bh;
+    GLint offset;
  
-    (void) img;
+    _mesa_get_format_block_size(mesaFormat, &bw, &bh);
  
-    /* We try to spot a "complete" subtexture "above" ROW, COL;
-     * this texture is given by appropriate rounding of WIDTH x ROW.
-     * Then we just add the amount left (usually on the left).
-     *
-     * Example for X*Y microtiles (Z bytes each)
-     * offset = Z * (((width + X - 1) / X) * (row / Y) + col / X);
-     */
+    ASSERT(col % bw == 0);
+    ASSERT(row % bh == 0);
  
-    switch (mesaFormat) {
- #if FEATURE_texture_fxt1
-    case MESA_FORMAT_RGB_FXT1:
-    case MESA_FORMAT_RGBA_FXT1:
-       addr = (GLubyte *) image + 16 * (((width + 7) / 8) * (row / 4) + col / 8);
-       break;
- #endif
- #if FEATURE_texture_s3tc
-    case MESA_FORMAT_RGB_DXT1:
-    case MESA_FORMAT_RGBA_DXT1:
- #if FEATURE_EXT_texture_sRGB
-    case MESA_FORMAT_SRGB_DXT1:
-    case MESA_FORMAT_SRGBA_DXT1:
- #endif
-       addr = (GLubyte *) image + 8 * (((width + 3) / 4) * (row / 4) + col / 4);
-       break;
-    case MESA_FORMAT_RGBA_DXT3:
-    case MESA_FORMAT_RGBA_DXT5:
- #if FEATURE_EXT_texture_sRGB
-    case MESA_FORMAT_SRGBA_DXT3:
-    case MESA_FORMAT_SRGBA_DXT5:
- #endif
-       addr = (GLubyte *) image + 16 * (((width + 3) / 4) * (row / 4) + col / 4);
-       break;
- #endif
-    default:
-       _mesa_problem(NULL, "bad mesaFormat in _mesa_compressed_image_address");
-       addr = NULL;
-    }
+    offset = ((width + bw - 1) / bw) * (row / bh) + col / bw;
+    offset *= blockSize;
  
-    return addr;
+    return (GLubyte *) image + offset;
  }
 +
 +
 +/**
 + * Given a compressed MESA_FORMAT_x value, return the corresponding
 + * GLenum for that format.
 + * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
 + * which must return the specific texture format used when the user might
 + * have originally specified a generic compressed format in their
 + * glTexImage2D() call.
 + * For non-compressed textures, we always return the user-specified
 + * internal format unchanged.
 + */
 +GLenum
 +_mesa_compressed_format_to_glenum(GLcontext *ctx, GLuint mesaFormat)
 +{
 +   switch (mesaFormat) {
 +#if FEATURE_texture_fxt1
 +   case MESA_FORMAT_RGB_FXT1:
 +      return GL_COMPRESSED_RGB_FXT1_3DFX;
 +   case MESA_FORMAT_RGBA_FXT1:
 +      return GL_COMPRESSED_RGBA_FXT1_3DFX;
 +#endif
 +#if FEATURE_texture_s3tc
 +   case MESA_FORMAT_RGB_DXT1:
 +      return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
 +   case MESA_FORMAT_RGBA_DXT1:
 +      return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
 +   case MESA_FORMAT_RGBA_DXT3:
 +      return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
 +   case MESA_FORMAT_RGBA_DXT5:
 +      return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
 +#if FEATURE_EXT_texture_sRGB
 +   case MESA_FORMAT_SRGB_DXT1:
 +      return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
 +   case MESA_FORMAT_SRGBA_DXT1:
 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
 +   case MESA_FORMAT_SRGBA_DXT3:
 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
 +   case MESA_FORMAT_SRGBA_DXT5:
 +      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
 +#endif
 +#endif
 +   default:
 +      _mesa_problem(ctx, "Unexpected mesa texture format in"
 +                    " _mesa_compressed_format_to_glenum()");
 +      return 0;
 +   }
 +}
 +
 +
Simple merge
index 9d5534e39602c076f473038b06e9c32f53317ae5,038dc0bb5066d57a3dc9db1f2c6ccb416f19becc..39c561e2789b5a6c2209e0152178d70cb3a1451e
@@@ -1582,35 -156,35 +156,27 @@@ _mesa_choose_tex_format( GLcontext *ctx
  
     switch (internalFormat) {
        case GL_COMPRESSED_ALPHA_ARB:
-          return &_mesa_texformat_alpha;
+          return MESA_FORMAT_A8;
        case GL_COMPRESSED_LUMINANCE_ARB:
-          return &_mesa_texformat_luminance;
+          return MESA_FORMAT_L8;
        case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
-          return &_mesa_texformat_luminance_alpha;
+          return MESA_FORMAT_AL88;
        case GL_COMPRESSED_INTENSITY_ARB:
-          return &_mesa_texformat_intensity;
+          return MESA_FORMAT_I8;
        case GL_COMPRESSED_RGB_ARB:
 -#if FEATURE_texture_fxt1
 -         if (ctx->Extensions.TDFX_texture_compression_FXT1)
 -            return MESA_FORMAT_RGB_FXT1;
 -#endif
--#if FEATURE_texture_s3tc
           if (ctx->Extensions.EXT_texture_compression_s3tc ||
               ctx->Extensions.S3_s3tc)
-             return &_mesa_texformat_rgb_dxt1;
- #endif
- #if FEATURE_texture_fxt1
+             return MESA_FORMAT_RGB_DXT1;
 -#endif
 +         if (ctx->Extensions.TDFX_texture_compression_FXT1)
-             return &_mesa_texformat_rgb_fxt1;
- #endif
-          return &_mesa_texformat_rgb;
++            return MESA_FORMAT_RGB_FXT1;
+          return MESA_FORMAT_RGB888;
        case GL_COMPRESSED_RGBA_ARB:
 -#if FEATURE_texture_fxt1
 -         if (ctx->Extensions.TDFX_texture_compression_FXT1)
 -            return MESA_FORMAT_RGBA_FXT1;
 -#endif
--#if FEATURE_texture_s3tc
           if (ctx->Extensions.EXT_texture_compression_s3tc ||
               ctx->Extensions.S3_s3tc)
-             return &_mesa_texformat_rgba_dxt5; /* Not rgba_dxt1, see spec */
- #endif
- #if FEATURE_texture_fxt1
+             return MESA_FORMAT_RGBA_DXT3; /* Not rgba_dxt1, see spec */
 -#endif
 +         if (ctx->Extensions.TDFX_texture_compression_FXT1)
-             return &_mesa_texformat_rgba_fxt1;
- #endif
-          return &_mesa_texformat_rgba;
++            return MESA_FORMAT_RGBA_FXT1;
+          return MESA_FORMAT_RGBA8888;
        default:
           ; /* fallthrough */
     }
index 252001992350d85b4545c147ce0b3b9c905a921c,1f0a3d793f7dbc49d35f286667c818daf7ed29ab..1338d4552db8db92b58be9805ab6a1f3b9f69bad
  
  #include "glheader.h"
  #include "bufferobj.h"
 +#include "enums.h"
  #include "context.h"
+ #include "formats.h"
  #include "image.h"
  #include "texcompress.h"
- #include "texformat.h"
  #include "texgetimage.h"
  #include "teximage.h"
  #include "texstate.h"
@@@ -516,17 -518,6 +520,17 @@@ _mesa_GetTexImage( GLenum target, GLin
     texUnit = _mesa_get_current_tex_unit(ctx);
     texObj = _mesa_select_tex_object(ctx, texUnit, target);
  
-       _mesa_debug(ctx, "glGetTexImage(tex %u) format = %d, w=%d, h=%d,"
 +   if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
 +      struct gl_texture_image *texImage =
 +         _mesa_select_tex_image(ctx, texObj, target, level);
-                   texImage->TexFormat->MesaFormat,
++      _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
 +                  " dstFmt=0x%x, dstType=0x%x\n",
 +                  texObj->Name,
++                  _mesa_get_format_name(texImage->TexFormat),
 +                  texImage->Width, texImage->Height,
 +                  format, type);
 +   }
 +
     _mesa_lock_texture(ctx, texObj);
     {
        struct gl_texture_image *texImage =
@@@ -575,81 -543,43 +579,88 @@@ getcompressedteximage_error_check(GLcon
  
     texUnit = _mesa_get_current_tex_unit(ctx);
     texObj = _mesa_select_tex_object(ctx, texUnit, target);
 +
     if (!texObj) {
 -      _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB");
 -      return;
 +      _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
 +      return GL_TRUE;
     }
  
 -   maxLevels = _mesa_max_texture_levels(ctx, target);
 -   ASSERT(maxLevels > 0); /* 0 indicates bad target, caught above */
 +   texImage = _mesa_select_tex_image(ctx, texObj, target, level);
  
 -   if (level < 0 || level >= maxLevels) {
 -      _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)");
 -      return;
 +   if (!texImage) {
 +      /* probably invalid mipmap level */
 +      _mesa_error(ctx, GL_INVALID_VALUE,
 +                  "glGetCompressedTexImageARB(level)");
 +      return GL_TRUE;
     }
  
-    if (!texImage->IsCompressed) {
 -   if (_mesa_is_proxy_texture(target)) {
 -      _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB(target)");
++   if (!_mesa_is_format_compressed(texImage->TexFormat)) {
 +      _mesa_error(ctx, GL_INVALID_OPERATION,
 +                  "glGetCompressedTexImageARB(texture is not compressed)");
 +      return GL_TRUE;
 +   }
 +
 +   if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
++      GLuint compressedSize;
++
 +      /* make sure PBO is not mapped */
 +      if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) {
 +         _mesa_error(ctx, GL_INVALID_OPERATION,
 +                     "glGetCompressedTexImage(PBO is mapped)");
 +         return GL_TRUE;
 +      }
 +
++      compressedSize = _mesa_format_image_size(texImage->TexFormat,
++                                               texImage->Width,
++                                               texImage->Height,
++                                               texImage->Depth);
++
 +      /* do bounds checking on PBO write */
-       if ((const GLubyte *) img + texImage->CompressedSize >
++      if ((const GLubyte *) img + compressedSize >
 +          (const GLubyte *) ctx->Pack.BufferObj->Size) {
 +         _mesa_error(ctx, GL_INVALID_OPERATION,
 +                     "glGetCompressedTexImage(out of bounds PBO write)");
 +         return GL_TRUE;
 +      }
 +   }
 +
 +   return GL_FALSE;
 +}
 +
 +
 +void GLAPIENTRY
 +_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
 +{
 +   const struct gl_texture_unit *texUnit;
 +   struct gl_texture_object *texObj;
 +   GET_CURRENT_CONTEXT(ctx);
 +   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 +
 +   if (getcompressedteximage_error_check(ctx, target, level, img)) {
        return;
     }
  
-                   "glGetCompressedTexImage(tex %u) format = %d, w=%d, h=%d\n",
 +   texUnit = _mesa_get_current_tex_unit(ctx);
 +   texObj = _mesa_select_tex_object(ctx, texUnit, target);
 +
 +   if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
 +      struct gl_texture_image *texImage =
 +         _mesa_select_tex_image(ctx, texObj, target, level);
 +      _mesa_debug(ctx,
-                   texImage->TexFormat->MesaFormat,
++                  "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
 +                  texObj->Name,
++                  _mesa_get_format_name(texImage->TexFormat),
 +                  texImage->Width, texImage->Height);
 +   }
 +
     _mesa_lock_texture(ctx, texObj);
     {
 -      texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 -      if (texImage) {
 -         if (_mesa_is_format_compressed(texImage->TexFormat)) {
 -            /* this typically calls _mesa_get_compressed_teximage() */
 -            ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
 -                                              texObj, texImage);
 -         }
 -         else {
 -            _mesa_error(ctx, GL_INVALID_OPERATION,
 -                        "glGetCompressedTexImageARB");
 -         }
 -      }
 -      else {
 -         /* probably invalid mipmap level */
 -         _mesa_error(ctx, GL_INVALID_VALUE,
 -                     "glGetCompressedTexImageARB(level)");
 -      }
 +      struct gl_texture_image *texImage =
 +         _mesa_select_tex_image(ctx, texObj, target, level);
 +
 +      /* this typically calls _mesa_get_compressed_teximage() */
 +      ctx->Driver.GetCompressedTexImage(ctx, target, level, img,
 +                                        texObj, texImage);
     }
     _mesa_unlock_texture(ctx, texObj);
  }
Simple merge
Simple merge
index 9d1fdd0566402f33e76768284bf202b8546f12d8,afa66f149ce249817bfd684c72773f70799a26a8..42584760921b085276cf4473ffd66906aa5e2c55
@@@ -776,15 -780,7 +780,14 @@@ _mesa_GetTexLevelParameteriv( GLenum ta
           *params = img->Depth;
           break;
        case GL_TEXTURE_INTERNAL_FORMAT:
-          if (img->IsCompressed) {
 -         *params = img->InternalFormat;
++         if (_mesa_is_format_compressed(img->TexFormat)) {
 +            /* need to return the actual compressed format */
-             *params = _mesa_compressed_format_to_glenum(ctx,
-                                           img->TexFormat->MesaFormat);
++            *params = _mesa_compressed_format_to_glenum(ctx, img->TexFormat);
 +         }
 +         else {
 +            /* return the user's requested internal format */
 +            *params = img->InternalFormat;
 +         }
           break;
        case GL_TEXTURE_BORDER:
           *params = img->Border;
Simple merge
Simple merge
Simple merge
Simple merge
index 3e0db374144454f1f9923b3997b35f8056ad680a,aa71b91ec8594bc3568dd419f4865d988c048750..0be273727223fa9375282bf3f2011cd980f937d3
@@@ -713,10 -776,10 +776,10 @@@ st_ChooseTextureFormat(GLcontext *ctx, 
     (void) format;
     (void) type;
  
 -   pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE_2D, 
 -                              PIPE_TEXTURE_USAGE_SAMPLER);
 +   pFormat = st_choose_format(ctx->st->pipe->screen, internalFormat,
 +                              PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
     if (pFormat == PIPE_FORMAT_NONE)
-       return NULL;
+       return MESA_FORMAT_NONE;
  
     return translate_gallium_format_to_mesa_format(pFormat);
  }
index e4a788c89bb2343a712bd36147f9caec6b046ea5,97422bb199fe3342dd5e5f9aac3d7ec5473542c7..7cddf5aa66a7c4fe5e0ea7a2ddb7a000cf627308
@@@ -68,11 -72,10 +72,11 @@@ st_choose_format(struct pipe_screen *sc
                   enum pipe_texture_target target, unsigned tex_usage);
  
  extern enum pipe_format
 -st_choose_renderbuffer_format(struct pipe_context *pipe, GLenum internalFormat);
 +st_choose_renderbuffer_format(struct pipe_screen *screen,
 +                              GLenum internalFormat);
  
  
- extern const struct gl_texture_format *
+ extern gl_format
  st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
                         GLenum format, GLenum type);
  
Simple merge
index 17e00dda4ff49a9134062dbf7b6bec5c4e1e1b68,8073a61197d9265b7c98fbf5078279495f56b795..393590c67344c9156f0a55cee68bd23b2a43be15
  _swrast_read_depth_span_uint( GLcontext *ctx, struct gl_renderbuffer *rb,
                                GLint n, GLint x, GLint y, GLuint depth[] )
  {
+    GLuint depthBits;
     if (!rb) {
        /* really only doing this to prevent FP exceptions later */
 -      _mesa_bzero(depth, n * sizeof(GLfloat));
 +      _mesa_bzero(depth, n * sizeof(GLuint));
 +      return;
     }
  
+    depthBits = _mesa_get_format_bits(rb->Format, GL_DEPTH_BITS);
     ASSERT(rb->_BaseFormat == GL_DEPTH_COMPONENT);
  
     if (y < 0 || y >= (GLint) rb->Height ||
Simple merge
Simple merge