Home | History | Annotate | Download | only in main
      1 /*
      2  * Mesa 3-D graphics library
      3  * Version:  7.7
      4  *
      5  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
      6  * Copyright (c) 2008-2009 VMware, Inc.
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining a
      9  * copy of this software and associated documentation files (the "Software"),
     10  * to deal in the Software without restriction, including without limitation
     11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     12  * and/or sell copies of the Software, and to permit persons to whom the
     13  * Software is furnished to do so, subject to the following conditions:
     14  *
     15  * The above copyright notice and this permission notice shall be included
     16  * in all copies or substantial portions of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     22  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24  */
     25 
     26 
     27 /**
     28  * \file texformat.c
     29  * Texture formats.
     30  *
     31  * \author Gareth Hughes
     32  * \author Brian Paul
     33  */
     34 
     35 
     36 #include "context.h"
     37 #include "enums.h"
     38 #include "mfeatures.h"
     39 #include "mtypes.h"
     40 #include "texcompress.h"
     41 #include "texformat.h"
     42 
     43 #define RETURN_IF_SUPPORTED(f) do {		\
     44    if (ctx->TextureFormatSupported[f])		\
     45       return f;					\
     46 } while (0)
     47 
     48 /**
     49  * Choose an appropriate texture format given the format, type and
     50  * internalFormat parameters passed to glTexImage().
     51  *
     52  * \param ctx  the GL context.
     53  * \param internalFormat  user's prefered internal texture format.
     54  * \param format  incoming image pixel format.
     55  * \param type  incoming image data type.
     56  *
     57  * \return a pointer to a gl_texture_format object which describes the
     58  * choosen texture format, or NULL on failure.
     59  *
     60  * This is called via dd_function_table::ChooseTextureFormat.  Hardware drivers
     61  * will typically override this function with a specialized version.
     62  */
     63 gl_format
     64 _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
     65                         GLint internalFormat, GLenum format, GLenum type)
     66 {
     67    (void) format;
     68    (void) type;
     69 
     70    switch (internalFormat) {
     71       /* shallow RGBA formats */
     72       case 4:
     73       case GL_RGBA:
     74 	 if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
     75 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
     76 	 } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
     77 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
     78 	 }
     79 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
     80 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
     81 	 break;
     82 
     83       case GL_RGBA8:
     84 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
     85 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
     86 	 break;
     87       case GL_RGB5_A1:
     88 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
     89 	 break;
     90       case GL_RGBA2:
     91 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV); /* just to test another format*/
     92 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
     93 	 break;
     94       case GL_RGBA4:
     95 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
     96 	 break;
     97 
     98       /* deep RGBA formats */
     99       case GL_RGB10_A2:
    100 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010);
    101 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    102 	 break;
    103       case GL_RGBA12:
    104       case GL_RGBA16:
    105 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
    106 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
    107 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
    108 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    109 	 break;
    110 
    111       /* shallow RGB formats */
    112       case 3:
    113       case GL_RGB:
    114       case GL_RGB8:
    115 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
    116 	 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
    117 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    118 	 break;
    119       case GL_R3_G3_B2:
    120 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332);
    121 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
    122 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV);
    123 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
    124 	 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
    125 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    126 	 break;
    127       case GL_RGB4:
    128 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV); /* just to test another format */
    129 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
    130 	 break;
    131       case GL_RGB5:
    132 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
    133 	 break;
    134 
    135       /* deep RGB formats */
    136       case GL_RGB10:
    137       case GL_RGB12:
    138       case GL_RGB16:
    139 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
    140 	 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
    141 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    142 	 break;
    143 
    144       /* Alpha formats */
    145       case GL_ALPHA:
    146       case GL_ALPHA4:
    147       case GL_ALPHA8:
    148 	 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
    149 	 break;
    150 
    151       case GL_ALPHA12:
    152       case GL_ALPHA16:
    153 	 RETURN_IF_SUPPORTED(MESA_FORMAT_A16);
    154 	 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
    155 	 break;
    156 
    157       /* Luminance formats */
    158       case 1:
    159       case GL_LUMINANCE:
    160       case GL_LUMINANCE4:
    161       case GL_LUMINANCE8:
    162 	 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
    163 	 break;
    164 
    165       case GL_LUMINANCE12:
    166       case GL_LUMINANCE16:
    167 	 RETURN_IF_SUPPORTED(MESA_FORMAT_L16);
    168 	 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
    169 	 break;
    170 
    171       /* Luminance/Alpha formats */
    172       case GL_LUMINANCE4_ALPHA4:
    173 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL44);
    174 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
    175 	 break;
    176 
    177       case 2:
    178       case GL_LUMINANCE_ALPHA:
    179       case GL_LUMINANCE6_ALPHA2:
    180       case GL_LUMINANCE8_ALPHA8:
    181 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
    182 	 break;
    183 
    184       case GL_LUMINANCE12_ALPHA4:
    185       case GL_LUMINANCE12_ALPHA12:
    186       case GL_LUMINANCE16_ALPHA16:
    187 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616);
    188 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
    189 	 break;
    190 
    191       case GL_INTENSITY:
    192       case GL_INTENSITY4:
    193       case GL_INTENSITY8:
    194 	 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
    195 	 break;
    196 
    197       case GL_INTENSITY12:
    198       case GL_INTENSITY16:
    199 	 RETURN_IF_SUPPORTED(MESA_FORMAT_I16);
    200 	 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
    201 	 break;
    202 
    203       default:
    204          ; /* fallthrough */
    205    }
    206 
    207    if (ctx->Extensions.ARB_depth_texture) {
    208       switch (internalFormat) {
    209          case GL_DEPTH_COMPONENT:
    210          case GL_DEPTH_COMPONENT24:
    211          case GL_DEPTH_COMPONENT32:
    212 	    RETURN_IF_SUPPORTED(MESA_FORMAT_Z32);
    213 	    RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24);
    214 	    RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
    215 	    break;
    216          case GL_DEPTH_COMPONENT16:
    217 	    RETURN_IF_SUPPORTED(MESA_FORMAT_Z16);
    218 	    RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24);
    219 	    RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
    220          default:
    221             ; /* fallthrough */
    222       }
    223    }
    224 
    225    switch (internalFormat) {
    226       case GL_COMPRESSED_ALPHA_ARB:
    227 	 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
    228 	 break;
    229       case GL_COMPRESSED_LUMINANCE_ARB:
    230 	 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
    231 	 break;
    232       case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
    233 	 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
    234 	 break;
    235       case GL_COMPRESSED_INTENSITY_ARB:
    236 	 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
    237 	 break;
    238       case GL_COMPRESSED_RGB_ARB:
    239          /* We don't use texture compression for 1D and 1D array textures.
    240           * For 1D textures, compressions doesn't buy us much.
    241           * For 1D ARRAY textures, there's complicated issues with updating
    242           * sub-regions on non-block boundaries with glCopyTexSubImage, among
    243           * other issues.  FWIW, the GL_EXT_texture_array extension prohibits
    244           * 1D ARRAY textures in S3TC format.
    245           */
    246          if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
    247             if (ctx->Extensions.EXT_texture_compression_s3tc ||
    248                 ctx->Extensions.S3_s3tc)
    249                RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
    250             if (ctx->Extensions.TDFX_texture_compression_FXT1)
    251                RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
    252          }
    253 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
    254 	 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
    255 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    256 	 break;
    257       case GL_COMPRESSED_RGBA_ARB:
    258          /* We don't use texture compression for 1D and 1D array textures. */
    259          if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
    260             if (ctx->Extensions.EXT_texture_compression_s3tc ||
    261                 ctx->Extensions.S3_s3tc)
    262                RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
    263             if (ctx->Extensions.TDFX_texture_compression_FXT1)
    264                RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
    265          }
    266 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
    267 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    268 	 break;
    269       default:
    270          ; /* fallthrough */
    271    }
    272 
    273    if (ctx->Extensions.ARB_ES2_compatibility) {
    274       switch (internalFormat) {
    275          case GL_RGB565:
    276             RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
    277             break;
    278          default:
    279          ; /* fallthrough */
    280       }
    281    }
    282 
    283    if (ctx->Extensions.MESA_ycbcr_texture) {
    284       if (internalFormat == GL_YCBCR_MESA) {
    285          if (type == GL_UNSIGNED_SHORT_8_8_MESA)
    286 	    RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR);
    287          else
    288 	    RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV);
    289       }
    290    }
    291 
    292 #if FEATURE_texture_fxt1
    293    if (ctx->Extensions.TDFX_texture_compression_FXT1) {
    294       switch (internalFormat) {
    295          case GL_COMPRESSED_RGB_FXT1_3DFX:
    296 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
    297 	 break;
    298          case GL_COMPRESSED_RGBA_FXT1_3DFX:
    299 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
    300 	 break;
    301          default:
    302             ; /* fallthrough */
    303       }
    304    }
    305 #endif
    306 
    307 #if FEATURE_texture_s3tc
    308    if (ctx->Extensions.EXT_texture_compression_s3tc) {
    309       switch (internalFormat) {
    310          case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
    311 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
    312 	    break;
    313          case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
    314 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1);
    315 	    break;
    316          case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
    317 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
    318 	    break;
    319          case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
    320 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5);
    321 	    break;
    322          default:
    323             ; /* fallthrough */
    324       }
    325    }
    326 
    327    if (ctx->Extensions.S3_s3tc) {
    328       switch (internalFormat) {
    329          case GL_RGB_S3TC:
    330          case GL_RGB4_S3TC:
    331 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
    332 	    break;
    333          case GL_RGBA_S3TC:
    334          case GL_RGBA4_S3TC:
    335 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
    336 	    break;
    337          default:
    338             ; /* fallthrough */
    339       }
    340    }
    341 #endif
    342 
    343    if (ctx->Extensions.ARB_texture_float) {
    344       switch (internalFormat) {
    345          case GL_ALPHA16F_ARB:
    346 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
    347 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
    348 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    349 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    350 	    break;
    351          case GL_ALPHA32F_ARB:
    352 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
    353 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    354 	    RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16);
    355 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    356 	    break;
    357          case GL_LUMINANCE16F_ARB:
    358 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
    359 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
    360 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    361 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    362 	    break;
    363          case GL_LUMINANCE32F_ARB:
    364 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
    365 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    366 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16);
    367 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    368 	    break;
    369          case GL_LUMINANCE_ALPHA16F_ARB:
    370 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
    371 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
    372 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    373 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    374 	    break;
    375          case GL_LUMINANCE_ALPHA32F_ARB:
    376 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
    377 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    378 	    RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16);
    379 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    380 	    break;
    381          case GL_INTENSITY16F_ARB:
    382 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
    383 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
    384 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    385 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    386 	    break;
    387          case GL_INTENSITY32F_ARB:
    388 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
    389 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    390 	    RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16);
    391 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    392 	    break;
    393          case GL_RGB16F_ARB:
    394 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
    395 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    396 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
    397 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    398 	    break;
    399          case GL_RGB32F_ARB:
    400 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
    401 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    402 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
    403 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    404 	    break;
    405          case GL_RGBA16F_ARB:
    406 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    407 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    408 	    break;
    409          case GL_RGBA32F_ARB:
    410 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    411 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    412 	    break;
    413          default:
    414             ; /* fallthrough */
    415       }
    416    }
    417 
    418    if (ctx->Extensions.EXT_texture_shared_exponent) {
    419       switch (internalFormat) {
    420          case GL_RGB9_E5:
    421             ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_RGB9_E5_FLOAT]);
    422             return MESA_FORMAT_RGB9_E5_FLOAT;
    423          default:
    424             ; /* fallthrough */
    425       }
    426    }
    427 
    428    if (ctx->Extensions.EXT_packed_float) {
    429       switch (internalFormat) {
    430          case GL_R11F_G11F_B10F:
    431             ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_R11_G11_B10_FLOAT]);
    432             return MESA_FORMAT_R11_G11_B10_FLOAT;
    433          default:
    434             ; /* fallthrough */
    435       }
    436    }
    437 
    438    if (ctx->Extensions.EXT_packed_depth_stencil) {
    439       switch (internalFormat) {
    440          case GL_DEPTH_STENCIL_EXT:
    441          case GL_DEPTH24_STENCIL8_EXT:
    442 	    RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8);
    443 	    RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24);
    444 	    break;
    445          default:
    446             ; /* fallthrough */
    447       }
    448    }
    449 
    450    if (ctx->Extensions.ARB_depth_buffer_float) {
    451       switch (internalFormat) {
    452          case GL_DEPTH_COMPONENT32F:
    453             ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT]);
    454             return MESA_FORMAT_Z32_FLOAT;
    455          case GL_DEPTH32F_STENCIL8:
    456             ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_X24S8]);
    457             return MESA_FORMAT_Z32_FLOAT_X24S8;
    458          default:
    459             ; /* fallthrough */
    460       }
    461    }
    462 
    463    if (ctx->Extensions.ATI_envmap_bumpmap) {
    464       switch (internalFormat) {
    465          case GL_DUDV_ATI:
    466          case GL_DU8DV8_ATI:
    467 	    RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8);
    468 	    break;
    469          default:
    470             ; /* fallthrough */
    471       }
    472    }
    473 
    474    if (ctx->Extensions.EXT_texture_snorm) {
    475       switch (internalFormat) {
    476          case GL_RED_SNORM:
    477          case GL_R8_SNORM:
    478 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8);
    479 	    break;
    480          case GL_RG_SNORM:
    481          case GL_RG8_SNORM:
    482 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88_REV);
    483 	    break;
    484          case GL_RGB_SNORM:
    485          case GL_RGB8_SNORM:
    486 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
    487 	    /* FALLTHROUGH */
    488          case GL_RGBA_SNORM:
    489          case GL_RGBA8_SNORM:
    490 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    491 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    492 	    break;
    493          case GL_ALPHA_SNORM:
    494          case GL_ALPHA8_SNORM:
    495             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A8);
    496 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    497 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    498             break;
    499          case GL_LUMINANCE_SNORM:
    500          case GL_LUMINANCE8_SNORM:
    501             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L8);
    502 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
    503 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    504 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    505             break;
    506          case GL_LUMINANCE_ALPHA_SNORM:
    507          case GL_LUMINANCE8_ALPHA8_SNORM:
    508             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL88);
    509 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    510 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    511             break;
    512          case GL_INTENSITY_SNORM:
    513          case GL_INTENSITY8_SNORM:
    514             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I8);
    515 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    516 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    517             break;
    518          case GL_R16_SNORM:
    519 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R16);
    520 	    break;
    521          case GL_RG16_SNORM:
    522 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_GR1616);
    523 	    break;
    524          case GL_RGB16_SNORM:
    525 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
    526 	    /* FALLTHROUGH */
    527          case GL_RGBA16_SNORM:
    528 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
    529 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    530 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    531 	    break;
    532          case GL_ALPHA16_SNORM:
    533             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A16);
    534 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
    535 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    536 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    537             break;
    538          case GL_LUMINANCE16_SNORM:
    539             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L16);
    540 	    /* FALLTHROUGH */
    541          case GL_LUMINANCE16_ALPHA16_SNORM:
    542             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL1616);
    543 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
    544 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    545 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    546             break;
    547          case GL_INTENSITY16_SNORM:
    548             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I16);
    549 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16);
    550 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
    551 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
    552             break;
    553          default:
    554             ; /* fall-through */
    555       }
    556    }
    557 
    558 #if FEATURE_EXT_texture_sRGB
    559    if (ctx->Extensions.EXT_texture_sRGB) {
    560       switch (internalFormat) {
    561          case GL_SRGB_EXT:
    562          case GL_SRGB8_EXT:
    563 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
    564 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    565 	    break;
    566          case GL_SRGB_ALPHA_EXT:
    567          case GL_SRGB8_ALPHA8_EXT:
    568 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
    569 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    570 	    break;
    571          case GL_SLUMINANCE_EXT:
    572          case GL_SLUMINANCE8_EXT:
    573 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
    574 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    575 	    break;
    576          case GL_SLUMINANCE_ALPHA_EXT:
    577          case GL_SLUMINANCE8_ALPHA8_EXT:
    578 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
    579 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    580 	    break;
    581          case GL_COMPRESSED_SLUMINANCE_EXT:
    582 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
    583 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    584 	    break;
    585          case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
    586 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
    587 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    588 	    break;
    589          case GL_COMPRESSED_SRGB_EXT:
    590 #if FEATURE_texture_s3tc
    591             if (ctx->Extensions.EXT_texture_compression_s3tc)
    592 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
    593 #endif
    594 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
    595 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    596 	    break;
    597          case GL_COMPRESSED_SRGB_ALPHA_EXT:
    598 #if FEATURE_texture_s3tc
    599             if (ctx->Extensions.EXT_texture_compression_s3tc)
    600 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
    601 #endif
    602 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
    603 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    604 	    break;
    605 #if FEATURE_texture_s3tc
    606          case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
    607             if (ctx->Extensions.EXT_texture_compression_s3tc)
    608 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
    609 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    610             break;
    611          case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
    612             if (ctx->Extensions.EXT_texture_compression_s3tc)
    613 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT1);
    614 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    615             break;
    616          case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
    617             if (ctx->Extensions.EXT_texture_compression_s3tc)
    618 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3);
    619 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    620             break;
    621          case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
    622             if (ctx->Extensions.EXT_texture_compression_s3tc)
    623 	       RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5);
    624 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
    625             break;
    626 #endif
    627          default:
    628             ; /* fallthrough */
    629       }
    630    }
    631 #endif /* FEATURE_EXT_texture_sRGB */
    632 
    633    if (ctx->Extensions.EXT_texture_integer) {
    634       switch (internalFormat) {
    635       case GL_ALPHA8UI_EXT:
    636          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT8);
    637          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    638          break;
    639       case GL_ALPHA16UI_EXT:
    640          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT16);
    641          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    642          break;
    643       case GL_ALPHA32UI_EXT:
    644          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_UINT32);
    645          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    646          break;
    647       case GL_ALPHA8I_EXT:
    648          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT8);
    649          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    650          break;
    651       case GL_ALPHA16I_EXT:
    652          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT16);
    653          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    654          break;
    655       case GL_ALPHA32I_EXT:
    656          RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_INT32);
    657          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    658          break;
    659       case GL_LUMINANCE8UI_EXT:
    660          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT8);
    661          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    662          break;
    663       case GL_LUMINANCE16UI_EXT:
    664          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT16);
    665          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    666          break;
    667       case GL_LUMINANCE32UI_EXT:
    668          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_UINT32);
    669          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    670          break;
    671       case GL_LUMINANCE8I_EXT:
    672          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT8);
    673          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    674          break;
    675       case GL_LUMINANCE16I_EXT:
    676          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT16);
    677          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    678          break;
    679       case GL_LUMINANCE32I_EXT:
    680          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_INT32);
    681          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    682          break;
    683       case GL_LUMINANCE_ALPHA8UI_EXT:
    684          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT8);
    685          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    686          break;
    687       case GL_LUMINANCE_ALPHA16UI_EXT:
    688          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT16);
    689          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    690          break;
    691       case GL_LUMINANCE_ALPHA32UI_EXT:
    692          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_UINT32);
    693          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    694          break;
    695       case GL_LUMINANCE_ALPHA8I_EXT:
    696          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT8);
    697          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    698          break;
    699       case GL_LUMINANCE_ALPHA16I_EXT:
    700          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT16);
    701          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    702          break;
    703       case GL_LUMINANCE_ALPHA32I_EXT:
    704          RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_INT32);
    705          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    706          break;
    707       case GL_INTENSITY8UI_EXT:
    708          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT8);
    709          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    710          break;
    711       case GL_INTENSITY16UI_EXT:
    712          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT16);
    713          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    714          break;
    715       case GL_INTENSITY32UI_EXT:
    716          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_UINT32);
    717          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    718          break;
    719       case GL_INTENSITY8I_EXT:
    720          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT8);
    721          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    722          break;
    723       case GL_INTENSITY16I_EXT:
    724          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT16);
    725          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    726          break;
    727       case GL_INTENSITY32I_EXT:
    728          RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_INT32);
    729          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    730          break;
    731       }
    732    }
    733 
    734    if (ctx->Version >= 30 ||
    735        ctx->Extensions.EXT_texture_integer) {
    736       switch (internalFormat) {
    737       case GL_RGB8UI_EXT:
    738          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT8);
    739          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    740          break;
    741       case GL_RGB16UI_EXT:
    742          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT16);
    743          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    744          break;
    745       case GL_RGB32UI_EXT:
    746          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT32);
    747          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    748          break;
    749       case GL_RGB8I_EXT:
    750          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT8);
    751          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    752          break;
    753       case GL_RGB16I_EXT:
    754          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT16);
    755          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    756          break;
    757       case GL_RGB32I_EXT:
    758          RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_INT32);
    759          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    760          break;
    761       case GL_RGBA8UI_EXT:
    762          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
    763          break;
    764       case GL_RGBA16UI_EXT:
    765          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
    766          break;
    767       case GL_RGBA32UI_EXT:
    768          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
    769          break;
    770       case GL_RGBA8I_EXT:
    771          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
    772          break;
    773       case GL_RGBA16I_EXT:
    774          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16);
    775          break;
    776       case GL_RGBA32I_EXT:
    777          RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32);
    778          break;
    779       }
    780    }
    781 
    782    if (ctx->Extensions.ARB_texture_rg) {
    783       switch (internalFormat) {
    784       case GL_R8:
    785       case GL_RED:
    786 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
    787 	 break;
    788 
    789       case GL_COMPRESSED_RED:
    790          if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
    791             RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
    792 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
    793 	 break;
    794 
    795       case GL_R16:
    796 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
    797 	 break;
    798 
    799       case GL_RG:
    800       case GL_RG8:
    801 	 RETURN_IF_SUPPORTED(MESA_FORMAT_GR88);
    802 	 break;
    803 
    804       case GL_COMPRESSED_RG:
    805          if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
    806             RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
    807 	 RETURN_IF_SUPPORTED(MESA_FORMAT_GR88);
    808 	 break;
    809 
    810       case GL_RG16:
    811 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
    812 	 break;
    813 
    814       default:
    815          ; /* fallthrough */
    816       }
    817    }
    818 
    819    if (ctx->Extensions.ARB_texture_rg && ctx->Extensions.ARB_texture_float) {
    820       switch (internalFormat) {
    821       case GL_R16F:
    822 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
    823 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
    824 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
    825 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
    826 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    827 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    828 	 break;
    829       case GL_R32F:
    830 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
    831 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
    832 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    833 	 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
    834 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
    835 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    836 	 break;
    837       case GL_RG16F:
    838 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
    839 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
    840 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    841 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    842 	 break;
    843       case GL_RG32F:
    844 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
    845 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
    846 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
    847 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
    848 	 break;
    849 
    850       default:
    851          ; /* fallthrough */
    852       }
    853    }
    854 
    855    if (ctx->Version >= 30 ||
    856        (ctx->Extensions.ARB_texture_rg &&
    857         ctx->Extensions.EXT_texture_integer)) {
    858       switch (internalFormat) {
    859       case GL_R8UI:
    860          RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT8);
    861          break;
    862       case GL_RG8UI:
    863          RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT8);
    864          break;
    865       case GL_R16UI:
    866          RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT16);
    867 	 break;
    868       case GL_RG16UI:
    869 	 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT16);
    870          break;
    871       case GL_R32UI:
    872          RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT32);
    873          break;
    874       case GL_RG32UI:
    875          RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT32);
    876          break;
    877       case GL_R8I:
    878          RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT8);
    879          break;
    880       case GL_RG8I:
    881          RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT8);
    882          break;
    883       case GL_R16I:
    884          RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT16);
    885          break;
    886       case GL_RG16I:
    887          RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT16);
    888          break;
    889       case GL_R32I:
    890          RETURN_IF_SUPPORTED(MESA_FORMAT_R_INT32);
    891          break;
    892       case GL_RG32I:
    893          RETURN_IF_SUPPORTED(MESA_FORMAT_RG_INT32);
    894          break;
    895       default:
    896          break;
    897       }
    898    }
    899 
    900    if (ctx->Extensions.ARB_texture_rgb10_a2ui) {
    901       switch (internalFormat) {
    902       case GL_RGB10_A2UI:
    903          RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT);
    904          RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT);
    905          break;
    906       default:
    907          break;
    908       }
    909    }
    910    /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
    911     */
    912    if (_mesa_is_gles(ctx)) {
    913       switch (internalFormat) {
    914       case GL_BGRA:
    915 	 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
    916 	 break;
    917 
    918       default:
    919          ; /* fallthrough */
    920       }
    921    }
    922 
    923    if (ctx->Extensions.ARB_texture_compression_rgtc) {
    924       switch (internalFormat) {
    925          case GL_COMPRESSED_RED_RGTC1:
    926 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
    927 	    break;
    928          case GL_COMPRESSED_SIGNED_RED_RGTC1:
    929 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RED_RGTC1);
    930 	    break;
    931          case GL_COMPRESSED_RG_RGTC2:
    932 	    RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
    933 	    break;
    934          case GL_COMPRESSED_SIGNED_RG_RGTC2:
    935 	    RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_RGTC2);
    936 	    break;
    937          default:
    938             ; /* fallthrough */
    939       }
    940    }
    941 
    942    if (ctx->Extensions.EXT_texture_compression_latc) {
    943       switch (internalFormat) {
    944          case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
    945             RETURN_IF_SUPPORTED(MESA_FORMAT_L_LATC1);
    946             break;
    947          case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
    948             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L_LATC1);
    949             break;
    950          case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
    951             RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
    952             break;
    953          case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
    954             RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_LA_LATC2);
    955             break;
    956          default:
    957             ; /* fallthrough */
    958       }
    959    }
    960 
    961    if (ctx->Extensions.ATI_texture_compression_3dc) {
    962       switch (internalFormat) {
    963          case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
    964             RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
    965             break;
    966          default:
    967             ; /* fallthrough */
    968       }
    969    }
    970 
    971    if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
    972       switch (internalFormat) {
    973          case GL_ETC1_RGB8_OES:
    974             RETURN_IF_SUPPORTED(MESA_FORMAT_ETC1_RGB8);
    975             break;
    976          default:
    977             ; /* fallthrough */
    978       }
    979    }
    980 
    981    _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
    982                  _mesa_lookup_enum_by_nr(internalFormat));
    983    return MESA_FORMAT_NONE;
    984 }
    985 
    986