mesa: remove array size so the static assert can work
[mesa.git] / src / mesa / main / texformat.c
index c85a7c0503024e2bfa37b53849206c54840dfcb5..f0bc7fdb93b9bc06dbd8f895fa317347ce162291 100644 (file)
@@ -34,6 +34,7 @@
 
 
 #include "context.h"
+#include "enums.h"
 #include "mfeatures.h"
 #include "mtypes.h"
 #include "texcompress.h"
@@ -60,8 +61,8 @@
  * will typically override this function with a specialized version.
  */
 gl_format
-_mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
-                         GLenum format, GLenum type )
+_mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
+                        GLint internalFormat, GLenum format, GLenum type)
 {
    (void) format;
    (void) type;
@@ -117,6 +118,8 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
         break;
       case GL_R3_G3_B2:
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
         RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
@@ -197,16 +200,6 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
         RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
         break;
 
-      case GL_COLOR_INDEX:
-      case GL_COLOR_INDEX1_EXT:
-      case GL_COLOR_INDEX2_EXT:
-      case GL_COLOR_INDEX4_EXT:
-      case GL_COLOR_INDEX12_EXT:
-      case GL_COLOR_INDEX16_EXT:
-      case GL_COLOR_INDEX8_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_CI8);
-        break;
-
       default:
          ; /* fallthrough */
    }
@@ -217,10 +210,12 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          case GL_DEPTH_COMPONENT24:
          case GL_DEPTH_COMPONENT32:
            RETURN_IF_SUPPORTED(MESA_FORMAT_Z32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24);
            RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
            break;
          case GL_DEPTH_COMPONENT16:
            RETURN_IF_SUPPORTED(MESA_FORMAT_Z16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24);
            RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
          default:
             ; /* fallthrough */
@@ -241,21 +236,33 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
         RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
         break;
       case GL_COMPRESSED_RGB_ARB:
-         if (ctx->Extensions.EXT_texture_compression_s3tc ||
-             ctx->Extensions.S3_s3tc)
-           RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
-         if (ctx->Extensions.TDFX_texture_compression_FXT1)
-           RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
+         /* We don't use texture compression for 1D and 1D array textures.
+          * For 1D textures, compressions doesn't buy us much.
+          * For 1D ARRAY textures, there's complicated issues with updating
+          * sub-regions on non-block boundaries with glCopyTexSubImage, among
+          * other issues.  FWIW, the GL_EXT_texture_array extension prohibits
+          * 1D ARRAY textures in S3TC format.
+          */
+         if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
+            if (ctx->Extensions.EXT_texture_compression_s3tc ||
+                ctx->Extensions.S3_s3tc)
+               RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
+            if (ctx->Extensions.TDFX_texture_compression_FXT1)
+               RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
+         }
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
         RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
         break;
       case GL_COMPRESSED_RGBA_ARB:
-         if (ctx->Extensions.EXT_texture_compression_s3tc ||
-             ctx->Extensions.S3_s3tc)
-           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
-         if (ctx->Extensions.TDFX_texture_compression_FXT1)
-           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
+         /* We don't use texture compression for 1D and 1D array textures. */
+         if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
+            if (ctx->Extensions.EXT_texture_compression_s3tc ||
+                ctx->Extensions.S3_s3tc)
+               RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
+            if (ctx->Extensions.TDFX_texture_compression_FXT1)
+               RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
+         }
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
         break;
@@ -263,6 +270,16 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
          ; /* fallthrough */
    }
 
+   if (ctx->Extensions.ARB_ES2_compatibility) {
+      switch (internalFormat) {
+         case GL_RGB565:
+            RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
+            break;
+         default:
+         ; /* fallthrough */
+      }
+   }
+
    if (ctx->Extensions.MESA_ycbcr_texture) {
       if (internalFormat == GL_YCBCR_MESA) {
          if (type == GL_UNSIGNED_SHORT_8_8_MESA)
@@ -272,7 +289,6 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
-#if FEATURE_texture_fxt1
    if (ctx->Extensions.TDFX_texture_compression_FXT1) {
       switch (internalFormat) {
          case GL_COMPRESSED_RGB_FXT1_3DFX:
@@ -285,10 +301,10 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
             ; /* fallthrough */
       }
    }
-#endif
 
-#if FEATURE_texture_s3tc
-   if (ctx->Extensions.EXT_texture_compression_s3tc) {
+   if (ctx->Extensions.EXT_texture_compression_s3tc ||
+       (ctx->API == API_OPENGLES2 &&
+       ctx->Extensions.ANGLE_texture_compression_dxt)) {
       switch (internalFormat) {
          case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
@@ -321,54 +337,68 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
             ; /* fallthrough */
       }
    }
-#endif
 
    if (ctx->Extensions.ARB_texture_float) {
       switch (internalFormat) {
          case GL_ALPHA16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
            break;
          case GL_ALPHA32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          case GL_LUMINANCE16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
            break;
          case GL_LUMINANCE32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          case GL_LUMINANCE_ALPHA16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
            break;
          case GL_LUMINANCE_ALPHA32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          case GL_INTENSITY16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
            break;
          case GL_INTENSITY32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          case GL_RGB16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
            break;
          case GL_RGB32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          case GL_RGBA16F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
@@ -376,12 +406,33 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
            break;
          case GL_RGBA32F_ARB:
            RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+           RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
            break;
          default:
             ; /* fallthrough */
       }
    }
 
+   if (ctx->Extensions.EXT_texture_shared_exponent) {
+      switch (internalFormat) {
+         case GL_RGB9_E5:
+            ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_RGB9_E5_FLOAT]);
+            return MESA_FORMAT_RGB9_E5_FLOAT;
+         default:
+            ; /* fallthrough */
+      }
+   }
+
+   if (ctx->Extensions.EXT_packed_float) {
+      switch (internalFormat) {
+         case GL_R11F_G11F_B10F:
+            ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_R11_G11_B10_FLOAT]);
+            return MESA_FORMAT_R11_G11_B10_FLOAT;
+         default:
+            ; /* fallthrough */
+      }
+   }
+
    if (ctx->Extensions.EXT_packed_depth_stencil) {
       switch (internalFormat) {
          case GL_DEPTH_STENCIL_EXT:
@@ -394,6 +445,19 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
+   if (ctx->Extensions.ARB_depth_buffer_float) {
+      switch (internalFormat) {
+         case GL_DEPTH_COMPONENT32F:
+            ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT]);
+            return MESA_FORMAT_Z32_FLOAT;
+         case GL_DEPTH32F_STENCIL8:
+            ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_X24S8]);
+            return MESA_FORMAT_Z32_FLOAT_X24S8;
+         default:
+            ; /* fallthrough */
+      }
+   }
+
    if (ctx->Extensions.ATI_envmap_bumpmap) {
       switch (internalFormat) {
          case GL_DUDV_ATI:
@@ -489,7 +553,6 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
-#if FEATURE_EXT_texture_sRGB
    if (ctx->Extensions.EXT_texture_sRGB) {
       switch (internalFormat) {
          case GL_SRGB_EXT:
@@ -521,22 +584,17 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
            break;
          case GL_COMPRESSED_SRGB_EXT:
-#if FEATURE_texture_s3tc
             if (ctx->Extensions.EXT_texture_compression_s3tc)
               RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
-#endif
            RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
            break;
          case GL_COMPRESSED_SRGB_ALPHA_EXT:
-#if FEATURE_texture_s3tc
             if (ctx->Extensions.EXT_texture_compression_s3tc)
               RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
-#endif
            RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
            break;
-#if FEATURE_texture_s3tc
          case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
             if (ctx->Extensions.EXT_texture_compression_s3tc)
               RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
@@ -548,72 +606,170 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
             break;
          case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
-            if (ctx->Extensions.EXT_texture_compression_s3tc)
+            if (ctx->Extensions.EXT_texture_compression_s3tc ||
+               (ctx->API == API_OPENGLES2 &&
+                ctx->Extensions.ANGLE_texture_compression_dxt))
               RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3);
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
             break;
          case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
-            if (ctx->Extensions.EXT_texture_compression_s3tc)
+            if (ctx->Extensions.EXT_texture_compression_s3tc ||
+               (ctx->API == API_OPENGLES2 &&
+                ctx->Extensions.ANGLE_texture_compression_dxt))
               RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5);
            RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
             break;
-#endif
          default:
             ; /* fallthrough */
       }
    }
-#endif /* FEATURE_EXT_texture_sRGB */
 
    if (ctx->Extensions.EXT_texture_integer) {
       switch (internalFormat) {
-      case GL_RGBA32UI_EXT:
-      case GL_RGB32UI_EXT:
-      case GL_ALPHA32UI_EXT:
-      case GL_INTENSITY32UI_EXT:
-      case GL_LUMINANCE32UI_EXT:
-      case GL_LUMINANCE_ALPHA32UI_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
-        break;
-      case GL_RGBA16UI_EXT:
-      case GL_RGB16UI_EXT:
+      case GL_ALPHA8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
       case GL_ALPHA16UI_EXT:
-      case GL_INTENSITY16UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_ALPHA32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
+      case GL_ALPHA8I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
+      case GL_ALPHA16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
+      case GL_ALPHA32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
+      case GL_LUMINANCE8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
       case GL_LUMINANCE16UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_LUMINANCE32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
+      case GL_LUMINANCE8I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
+      case GL_LUMINANCE16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
+      case GL_LUMINANCE32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
+      case GL_LUMINANCE_ALPHA8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
       case GL_LUMINANCE_ALPHA16UI_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
-        break;
-      case GL_RGBA8UI_EXT:
-      case GL_RGB8UI_EXT:
-      case GL_ALPHA8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_LUMINANCE_ALPHA32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
+      case GL_LUMINANCE_ALPHA8I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
+      case GL_LUMINANCE_ALPHA16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
+      case GL_LUMINANCE_ALPHA32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
       case GL_INTENSITY8UI_EXT:
-      case GL_LUMINANCE8UI_EXT:
-      case GL_LUMINANCE_ALPHA8UI_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
-        break;
-      case GL_RGBA32I_EXT:
-      case GL_RGB32I_EXT:
-      case GL_ALPHA32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
+      case GL_INTENSITY16UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_INTENSITY32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
+      case GL_INTENSITY8I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
+      case GL_INTENSITY16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
       case GL_INTENSITY32I_EXT:
-      case GL_LUMINANCE32I_EXT:
-      case GL_LUMINANCE_ALPHA32I_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
-        break;
-      case GL_RGBA16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
+      }
+   }
+
+   if (ctx->Version >= 30 ||
+       ctx->Extensions.EXT_texture_integer) {
+      switch (internalFormat) {
+      case GL_RGB8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
+      case GL_RGB16UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_RGB32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
+      case GL_RGB8I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT8);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
       case GL_RGB16I_EXT:
-      case GL_ALPHA16I_EXT:
-      case GL_INTENSITY16I_EXT:
-      case GL_LUMINANCE16I_EXT:
-      case GL_LUMINANCE_ALPHA16I_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
-        break;
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT16);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
+      case GL_RGB32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT32);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
+      case GL_RGBA8UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
+         break;
+      case GL_RGBA16UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
+         break;
+      case GL_RGBA32UI_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
+         break;
       case GL_RGBA8I_EXT:
-      case GL_RGB8I_EXT:
-      case GL_ALPHA8I_EXT:
-      case GL_INTENSITY8I_EXT:
-      case GL_LUMINANCE8I_EXT:
-      case GL_LUMINANCE_ALPHA8I_EXT:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
-        break;
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
+         break;
+      case GL_RGBA16I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
+         break;
+      case GL_RGBA32I_EXT:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
+         break;
       }
    }
 
@@ -621,7 +777,12 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       switch (internalFormat) {
       case GL_R8:
       case GL_RED:
+        RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
+        break;
+
       case GL_COMPRESSED_RED:
+         if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
+            RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
         RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
         break;
 
@@ -631,8 +792,13 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
 
       case GL_RG:
       case GL_RG8:
+        RETURN_IF_SUPPORTED(MESA_FORMAT_GR88);
+        break;
+
       case GL_COMPRESSED_RG:
-        RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
+         if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
+            RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_GR88);
         break;
 
       case GL_RG16:
@@ -648,21 +814,31 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       switch (internalFormat) {
       case GL_R16F:
         RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
         RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
         break;
       case GL_R32F:
         RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
         break;
       case GL_RG16F:
         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
         break;
       case GL_RG32F:
         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
         break;
 
       default:
@@ -670,7 +846,64 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
-   if (ctx->Extensions.EXT_texture_format_BGRA8888) {
+   if (ctx->Version >= 30 ||
+       (ctx->Extensions.ARB_texture_rg &&
+        ctx->Extensions.EXT_texture_integer)) {
+      switch (internalFormat) {
+      case GL_R8UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT8);
+         break;
+      case GL_RG8UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT8);
+         break;
+      case GL_R16UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT16);
+        break;
+      case GL_RG16UI:
+        RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT16);
+         break;
+      case GL_R32UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT32);
+         break;
+      case GL_RG32UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT32);
+         break;
+      case GL_R8I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT8);
+         break;
+      case GL_RG8I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT8);
+         break;
+      case GL_R16I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT16);
+         break;
+      case GL_RG16I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT16);
+         break;
+      case GL_R32I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT32);
+         break;
+      case GL_RG32I:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT32);
+         break;
+      default:
+         break;
+      }
+   }
+
+   if (ctx->Extensions.ARB_texture_rgb10_a2ui) {
+      switch (internalFormat) {
+      case GL_RGB10_A2UI:
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT);
+         break;
+      default:
+         break;
+      }
+   }
+   /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
+    */
+   if (_mesa_is_gles(ctx)) {
       switch (internalFormat) {
       case GL_BGRA:
         RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
@@ -729,7 +962,18 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       }
    }
 
-   _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
+   if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
+      switch (internalFormat) {
+         case GL_ETC1_RGB8_OES:
+            RETURN_IF_SUPPORTED(MESA_FORMAT_ETC1_RGB8);
+            break;
+         default:
+            ; /* fallthrough */
+      }
+   }
+
+   _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
+                 _mesa_lookup_enum_by_nr(internalFormat));
    return MESA_FORMAT_NONE;
 }