st_format.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 
00034 #include "main/imports.h"
00035 #include "main/context.h"
00036 #include "main/texstore.h"
00037 #include "main/texformat.h"
00038 #include "main/enums.h"
00039 #include "main/macros.h"
00040 
00041 #include "pipe/p_context.h"
00042 #include "pipe/p_defines.h"
00043 #include "pipe/p_screen.h"
00044 #include "st_context.h"
00045 #include "st_format.h"
00046 
00047 static GLuint
00048 format_bits(
00049    pipe_format_rgbazs_t  info,
00050    GLuint comp )
00051 {
00052    return pf_get_component_bits( (enum pipe_format) info, comp );
00053 }
00054 
00055 static GLuint
00056 format_max_bits(
00057    pipe_format_rgbazs_t  info )
00058 {
00059    GLuint   size = format_bits( info, PIPE_FORMAT_COMP_R );
00060 
00061    size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_G ) );
00062    size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_B ) );
00063    size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_A ) );
00064    size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_Z ) );
00065    size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_S ) );
00066    return size;
00067 }
00068 
00069 static GLuint
00070 format_size(
00071    pipe_format_rgbazs_t  info )
00072 {
00073    return
00074       format_bits( info, PIPE_FORMAT_COMP_R ) +
00075       format_bits( info, PIPE_FORMAT_COMP_G ) +
00076       format_bits( info, PIPE_FORMAT_COMP_B ) +
00077       format_bits( info, PIPE_FORMAT_COMP_A ) +
00078       format_bits( info, PIPE_FORMAT_COMP_Z ) +
00079       format_bits( info, PIPE_FORMAT_COMP_S );
00080 }
00081 
00082 /*
00083  * XXX temporary here
00084  */
00085 GLboolean
00086 st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo)
00087 {
00088    if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) {
00089       pipe_format_rgbazs_t info;
00090 
00091       info = format;
00092 
00093 #if 0
00094       printf("%s\n", pf_name( format ) );
00095 #endif
00096 
00097       /* Data type */
00098       if (format == PIPE_FORMAT_A1R5G5B5_UNORM || format == PIPE_FORMAT_R5G6B5_UNORM) {
00099          pinfo->datatype = GL_UNSIGNED_SHORT;
00100       }
00101       else {
00102          GLuint size;
00103 
00104          size = format_max_bits( info );
00105          if (size == 8) {
00106             if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
00107                pinfo->datatype = GL_UNSIGNED_BYTE;
00108             else
00109                pinfo->datatype = GL_BYTE;
00110          }
00111          else if (size == 16) {
00112             if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
00113                pinfo->datatype = GL_UNSIGNED_SHORT;
00114             else
00115                pinfo->datatype = GL_SHORT;
00116          }
00117          else {
00118             assert( size <= 32 );
00119             if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
00120                pinfo->datatype = GL_UNSIGNED_INT;
00121             else
00122                pinfo->datatype = GL_INT;
00123          }
00124       }
00125 
00126       /* Component bits */
00127       pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R );
00128       pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G );
00129       pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B );
00130       pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A );
00131       pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z );
00132       pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S );
00133       pinfo->luminance_bits = 0;
00134       pinfo->intensity_bits = 0;
00135 
00136       /* Format size */
00137       pinfo->size = format_size( info ) / 8;
00138 
00139       /* Luminance & Intensity bits */
00140       if( pf_swizzle_x(info) == PIPE_FORMAT_COMP_R &&
00141           pf_swizzle_y(info) == PIPE_FORMAT_COMP_R &&
00142           pf_swizzle_z(info) == PIPE_FORMAT_COMP_R ) {
00143          if( pf_swizzle_w(info) == PIPE_FORMAT_COMP_R ) {
00144             pinfo->intensity_bits = pinfo->red_bits;
00145          }
00146          else {
00147             pinfo->luminance_bits = pinfo->red_bits;
00148          }
00149          pinfo->red_bits = 0;
00150       }
00151 
00152       /* Base format */
00153       if (pinfo->depth_bits) {
00154          if (pinfo->stencil_bits) {
00155             pinfo->base_format = GL_DEPTH_STENCIL_EXT;
00156          }
00157          else {
00158             pinfo->base_format = GL_DEPTH_COMPONENT;
00159          }
00160       }
00161       else if (pinfo->stencil_bits) {
00162          pinfo->base_format = GL_STENCIL_INDEX;
00163       }
00164       else {
00165          pinfo->base_format = GL_RGBA;
00166       }
00167    }
00168    else if (pf_layout(format) == PIPE_FORMAT_LAYOUT_YCBCR) {
00169       pinfo->base_format = GL_YCBCR_MESA;
00170       pinfo->datatype = GL_UNSIGNED_SHORT;
00171       pinfo->size = 2; /* two bytes per "texel" */
00172    }
00173    else {
00174       /* compressed format? */
00175       assert(0);
00176    }
00177 
00178 #if 0
00179    printf(
00180       "ST_FORMAT: R(%u), G(%u), B(%u), A(%u), Z(%u), S(%u)\n",
00181       pinfo->red_bits,
00182       pinfo->green_bits,
00183       pinfo->blue_bits,
00184       pinfo->alpha_bits,
00185       pinfo->depth_bits,
00186       pinfo->stencil_bits );
00187 #endif
00188 
00189    pinfo->format = format;
00190 
00191    return GL_TRUE;
00192 }
00193 
00194 
00198 GLuint
00199 st_sizeof_format(enum pipe_format format)
00200 {
00201    struct pipe_format_info info;
00202    if (!st_get_format_info( format, &info )) {
00203       assert( 0 );
00204       return 0;
00205    }
00206    return info.size;
00207 }
00208 
00209 
00213 GLenum
00214 st_format_datatype(enum pipe_format format)
00215 {
00216    struct pipe_format_info info;
00217    if (!st_get_format_info( format, &info )) {
00218       assert( 0 );
00219       return 0;
00220    }
00221    return info.datatype;
00222 }
00223 
00224 
00225 enum pipe_format
00226 st_mesa_format_to_pipe_format(GLuint mesaFormat)
00227 {
00228    switch (mesaFormat) {
00229       /* fix this */
00230    case MESA_FORMAT_ARGB8888_REV:
00231    case MESA_FORMAT_ARGB8888:
00232       return PIPE_FORMAT_A8R8G8B8_UNORM;
00233    case MESA_FORMAT_ARGB1555:
00234       return PIPE_FORMAT_A1R5G5B5_UNORM;
00235    case MESA_FORMAT_ARGB4444:
00236       return PIPE_FORMAT_A4R4G4B4_UNORM;
00237    case MESA_FORMAT_RGB565:
00238       return PIPE_FORMAT_R5G6B5_UNORM;
00239    case MESA_FORMAT_AL88:
00240       return PIPE_FORMAT_A8L8_UNORM;
00241    case MESA_FORMAT_A8:
00242       return PIPE_FORMAT_A8_UNORM;
00243    case MESA_FORMAT_L8:
00244       return PIPE_FORMAT_L8_UNORM;
00245    case MESA_FORMAT_I8:
00246       return PIPE_FORMAT_I8_UNORM;
00247    case MESA_FORMAT_Z16:
00248       return PIPE_FORMAT_Z16_UNORM;
00249    case MESA_FORMAT_Z32:
00250       return PIPE_FORMAT_Z32_UNORM;
00251    case MESA_FORMAT_Z24_S8:
00252       return PIPE_FORMAT_Z24S8_UNORM;
00253    case MESA_FORMAT_S8_Z24:
00254       return PIPE_FORMAT_S8Z24_UNORM;
00255    case MESA_FORMAT_YCBCR:
00256       return PIPE_FORMAT_YCBCR;
00257 #if FEATURE_texture_s3tc
00258    case MESA_FORMAT_RGB_DXT1:
00259       return PIPE_FORMAT_DXT1_RGB;
00260    case MESA_FORMAT_RGBA_DXT1:
00261       return PIPE_FORMAT_DXT1_RGBA;
00262    case MESA_FORMAT_RGBA_DXT3:
00263       return PIPE_FORMAT_DXT3_RGBA;
00264    case MESA_FORMAT_RGBA_DXT5:
00265       return PIPE_FORMAT_DXT5_RGBA;
00266 #endif
00267    default:
00268       assert(0);
00269       return 0;
00270    }
00271 }
00272 
00276 static enum pipe_format
00277 default_rgba_format(struct pipe_screen *screen, 
00278                     enum pipe_texture_target target,
00279                     unsigned tex_usage, 
00280                     unsigned geom_flags)
00281 {
00282    static const enum pipe_format colorFormats[] = {
00283       PIPE_FORMAT_A8R8G8B8_UNORM,
00284       PIPE_FORMAT_B8G8R8A8_UNORM,
00285       PIPE_FORMAT_R8G8B8A8_UNORM,
00286       PIPE_FORMAT_R5G6B5_UNORM
00287    };
00288    uint i;
00289    for (i = 0; i < Elements(colorFormats); i++) {
00290       if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) {
00291          return colorFormats[i];
00292       }
00293    }
00294    return PIPE_FORMAT_NONE;
00295 }
00296 
00297 
00301 static enum pipe_format
00302 default_deep_rgba_format(struct pipe_screen *screen, 
00303                          enum pipe_texture_target target,
00304                          unsigned tex_usage, 
00305                          unsigned geom_flags)
00306 {
00307    if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, target, tex_usage, geom_flags)) {
00308       return PIPE_FORMAT_R16G16B16A16_SNORM;
00309    }
00310    if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
00311       return default_rgba_format(screen, target, tex_usage, geom_flags);
00312    else
00313       return PIPE_FORMAT_NONE;
00314 }
00315 
00316 
00320 static enum pipe_format
00321 default_depth_format(struct pipe_screen *screen, 
00322                      enum pipe_texture_target target,
00323                      unsigned tex_usage, 
00324                      unsigned geom_flags)
00325 {
00326    static const enum pipe_format zFormats[] = {
00327       PIPE_FORMAT_Z16_UNORM,
00328       PIPE_FORMAT_Z32_UNORM,
00329       PIPE_FORMAT_S8Z24_UNORM,
00330       PIPE_FORMAT_Z24S8_UNORM
00331    };
00332    uint i;
00333    for (i = 0; i < Elements(zFormats); i++) {
00334       if (screen->is_format_supported( screen, zFormats[i], target, tex_usage, geom_flags )) {
00335          return zFormats[i];
00336       }
00337    }
00338    return PIPE_FORMAT_NONE;
00339 }
00340 
00341 
00349 enum pipe_format
00350 st_choose_format(struct pipe_context *pipe, GLint internalFormat,
00351                  enum pipe_texture_target target, unsigned tex_usage)
00352 {
00353    struct pipe_screen *screen = pipe->screen;
00354    unsigned geom_flags = 0;
00355 
00356    switch (internalFormat) {
00357    case 4:
00358    case GL_RGBA:
00359    case GL_COMPRESSED_RGBA:
00360    case 3:
00361    case GL_RGB:
00362    case GL_COMPRESSED_RGB:
00363    case GL_RGBA8:
00364    case GL_RGB10_A2:
00365    case GL_RGBA12:
00366       return default_rgba_format( screen, target, tex_usage, geom_flags );
00367    case GL_RGBA16:
00368       if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
00369          return default_deep_rgba_format( screen, target, tex_usage, geom_flags );
00370       else
00371          return default_rgba_format( screen, target, tex_usage, geom_flags );
00372 
00373    case GL_RGBA4:
00374    case GL_RGBA2:
00375       if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, target, tex_usage, geom_flags ))
00376          return PIPE_FORMAT_A4R4G4B4_UNORM;
00377       return default_rgba_format( screen, target, tex_usage, geom_flags );
00378 
00379    case GL_RGB5_A1:
00380       if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags ))
00381          return PIPE_FORMAT_A1R5G5B5_UNORM;
00382       return default_rgba_format( screen, target, tex_usage, geom_flags );
00383 
00384    case GL_RGB8:
00385    case GL_RGB10:
00386    case GL_RGB12:
00387    case GL_RGB16:
00388       return default_rgba_format( screen, target, tex_usage, geom_flags );
00389 
00390    case GL_RGB5:
00391    case GL_RGB4:
00392    case GL_R3_G3_B2:
00393       if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags ))
00394          return PIPE_FORMAT_A1R5G5B5_UNORM;
00395       if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, target, tex_usage, geom_flags ))
00396          return PIPE_FORMAT_R5G6B5_UNORM;
00397       return default_rgba_format( screen, target, tex_usage, geom_flags );
00398 
00399    case GL_ALPHA:
00400    case GL_ALPHA4:
00401    case GL_ALPHA8:
00402    case GL_ALPHA12:
00403    case GL_ALPHA16:
00404    case GL_COMPRESSED_ALPHA:
00405       if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target, tex_usage, geom_flags ))
00406          return PIPE_FORMAT_A8_UNORM;
00407       return default_rgba_format( screen, target, tex_usage, geom_flags );
00408 
00409    case 1:
00410    case GL_LUMINANCE:
00411    case GL_LUMINANCE4:
00412    case GL_LUMINANCE8:
00413    case GL_LUMINANCE12:
00414    case GL_LUMINANCE16:
00415    case GL_COMPRESSED_LUMINANCE:
00416       if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target, tex_usage, geom_flags ))
00417          return PIPE_FORMAT_L8_UNORM;
00418       return default_rgba_format( screen, target, tex_usage, geom_flags );
00419 
00420    case 2:
00421    case GL_LUMINANCE_ALPHA:
00422    case GL_LUMINANCE4_ALPHA4:
00423    case GL_LUMINANCE6_ALPHA2:
00424    case GL_LUMINANCE8_ALPHA8:
00425    case GL_LUMINANCE12_ALPHA4:
00426    case GL_LUMINANCE12_ALPHA12:
00427    case GL_LUMINANCE16_ALPHA16:
00428    case GL_COMPRESSED_LUMINANCE_ALPHA:
00429       if (screen->is_format_supported( screen, PIPE_FORMAT_A8L8_UNORM, target, tex_usage, geom_flags ))
00430          return PIPE_FORMAT_A8L8_UNORM;
00431       return default_rgba_format( screen, target, tex_usage, geom_flags );
00432 
00433    case GL_INTENSITY:
00434    case GL_INTENSITY4:
00435    case GL_INTENSITY8:
00436    case GL_INTENSITY12:
00437    case GL_INTENSITY16:
00438    case GL_COMPRESSED_INTENSITY:
00439       if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target, tex_usage, geom_flags ))
00440          return PIPE_FORMAT_I8_UNORM;
00441       return default_rgba_format( screen, target, tex_usage, geom_flags );
00442 
00443    case GL_YCBCR_MESA:
00444       if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR,
00445                                       target, tex_usage, geom_flags)) {
00446          return PIPE_FORMAT_YCBCR;
00447       }
00448       if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV,
00449                                       target, tex_usage, geom_flags)) {
00450          return PIPE_FORMAT_YCBCR_REV;
00451       }
00452       return PIPE_FORMAT_NONE;
00453 
00454    case GL_RGB_S3TC:
00455    case GL_RGB4_S3TC:
00456    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
00457       return PIPE_FORMAT_DXT1_RGB;
00458 
00459    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
00460       return PIPE_FORMAT_DXT1_RGBA;
00461 
00462    case GL_RGBA_S3TC:
00463    case GL_RGBA4_S3TC:
00464    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
00465       return PIPE_FORMAT_DXT3_RGBA;
00466 
00467    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
00468       return PIPE_FORMAT_DXT5_RGBA;
00469 
00470 #if 0
00471    case GL_COMPRESSED_RGB_FXT1_3DFX:
00472       return PIPE_FORMAT_RGB_FXT1;
00473    case GL_COMPRESSED_RGBA_FXT1_3DFX:
00474       return PIPE_FORMAT_RGB_FXT1;
00475 #endif
00476 
00477    case GL_DEPTH_COMPONENT16:
00478       if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, target, tex_usage, geom_flags ))
00479          return PIPE_FORMAT_Z16_UNORM;
00480       /* fall-through */
00481    case GL_DEPTH_COMPONENT24:
00482       if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags ))
00483          return PIPE_FORMAT_S8Z24_UNORM;
00484       if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags ))
00485          return PIPE_FORMAT_Z24S8_UNORM;
00486       /* fall-through */
00487    case GL_DEPTH_COMPONENT32:
00488       if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, target, tex_usage, geom_flags ))
00489          return PIPE_FORMAT_Z32_UNORM;
00490       /* fall-through */
00491    case GL_DEPTH_COMPONENT:
00492       return default_depth_format( screen, target, tex_usage, geom_flags );
00493 
00494    case GL_STENCIL_INDEX:
00495    case GL_STENCIL_INDEX1_EXT:
00496    case GL_STENCIL_INDEX4_EXT:
00497    case GL_STENCIL_INDEX8_EXT:
00498    case GL_STENCIL_INDEX16_EXT:
00499       if (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, target, tex_usage, geom_flags ))
00500          return PIPE_FORMAT_S8_UNORM;
00501       if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags ))
00502          return PIPE_FORMAT_S8Z24_UNORM;
00503       if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags ))
00504          return PIPE_FORMAT_Z24S8_UNORM;
00505       return PIPE_FORMAT_NONE;
00506 
00507    case GL_DEPTH_STENCIL_EXT:
00508    case GL_DEPTH24_STENCIL8_EXT:
00509       if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags ))
00510          return PIPE_FORMAT_S8Z24_UNORM;
00511       if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags ))
00512          return PIPE_FORMAT_Z24S8_UNORM;
00513       return PIPE_FORMAT_NONE;
00514 
00515    default:
00516       return PIPE_FORMAT_NONE;
00517    }
00518 }
00519 
00520 
00521 static GLboolean
00522 is_stencil_format(GLenum format)
00523 {
00524    switch (format) {
00525    case GL_STENCIL_INDEX:
00526    case GL_STENCIL_INDEX1_EXT:
00527    case GL_STENCIL_INDEX4_EXT:
00528    case GL_STENCIL_INDEX8_EXT:
00529    case GL_STENCIL_INDEX16_EXT:
00530    case GL_DEPTH_STENCIL_EXT:
00531    case GL_DEPTH24_STENCIL8_EXT:
00532       return GL_TRUE;
00533    default:
00534       return GL_FALSE;
00535    }
00536 }
00537 
00541 enum pipe_format
00542 st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat)
00543 {
00544    uint usage;
00545    if (is_stencil_format(internalFormat))
00546       usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
00547    else
00548       usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
00549    return st_choose_format(pipe, internalFormat, PIPE_TEXTURE_2D, usage);
00550 }
00551 
00552 
00553 static const struct gl_texture_format *
00554 translate_gallium_format_to_mesa_format(enum pipe_format format)
00555 {
00556    switch (format) {
00557    case PIPE_FORMAT_A8R8G8B8_UNORM:
00558       return &_mesa_texformat_argb8888;
00559    case PIPE_FORMAT_A1R5G5B5_UNORM:
00560       return &_mesa_texformat_argb1555;
00561    case PIPE_FORMAT_A4R4G4B4_UNORM:
00562       return &_mesa_texformat_argb4444;
00563    case PIPE_FORMAT_R5G6B5_UNORM:
00564       return &_mesa_texformat_rgb565;
00565    case PIPE_FORMAT_A8L8_UNORM:
00566       return &_mesa_texformat_al88;
00567    case PIPE_FORMAT_A8_UNORM:
00568       return &_mesa_texformat_a8;
00569    case PIPE_FORMAT_L8_UNORM:
00570       return &_mesa_texformat_l8;
00571    case PIPE_FORMAT_I8_UNORM:
00572       return &_mesa_texformat_i8;
00573    case PIPE_FORMAT_Z16_UNORM:
00574       return &_mesa_texformat_z16;
00575    case PIPE_FORMAT_Z32_UNORM:
00576       return &_mesa_texformat_z32;
00577    case PIPE_FORMAT_Z24S8_UNORM:
00578       return &_mesa_texformat_z24_s8;
00579    case PIPE_FORMAT_S8Z24_UNORM:
00580       return &_mesa_texformat_s8_z24;
00581    case PIPE_FORMAT_YCBCR:
00582       return &_mesa_texformat_ycbcr;
00583    case PIPE_FORMAT_YCBCR_REV:
00584       return &_mesa_texformat_ycbcr_rev;
00585 #if FEATURE_texture_s3tc
00586    case PIPE_FORMAT_DXT1_RGB:
00587       return &_mesa_texformat_rgb_dxt1;
00588    case PIPE_FORMAT_DXT1_RGBA:
00589       return &_mesa_texformat_rgba_dxt1;
00590    case PIPE_FORMAT_DXT3_RGBA:
00591       return &_mesa_texformat_rgba_dxt3;
00592    case PIPE_FORMAT_DXT5_RGBA:
00593       return &_mesa_texformat_rgba_dxt5;
00594 #endif
00595    /* XXX add additional cases */
00596    default:
00597       assert(0);
00598       return NULL;
00599    }
00600 }
00601 
00602 
00606 const struct gl_texture_format *
00607 st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat,
00608                        GLenum format, GLenum type)
00609 {
00610    enum pipe_format pFormat;
00611 
00612    (void) format;
00613    (void) type;
00614 
00615    pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE_2D, 
00616                               PIPE_TEXTURE_USAGE_SAMPLER);
00617    if (pFormat == PIPE_FORMAT_NONE)
00618       return NULL;
00619 
00620    return translate_gallium_format_to_mesa_format(pFormat);
00621 }

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4