st_format.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pipe_format_info

Functions

GLboolean st_get_format_info (enum pipe_format format, struct pipe_format_info *pinfo)
GLuint st_sizeof_format (enum pipe_format format)
 Return bytes per pixel for the given format.
GLenum st_format_datatype (enum pipe_format format)
 Return bytes per pixel for the given format.
enum pipe_format st_mesa_format_to_pipe_format (GLuint mesaFormat)
enum pipe_format st_choose_format (struct pipe_context *pipe, GLint internalFormat, enum pipe_texture_target target, unsigned tex_usage)
 Given an OpenGL internalFormat value for a texture or surface, return the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
enum pipe_format st_choose_renderbuffer_format (struct pipe_context *pipe, GLint internalFormat)
 Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
struct gl_texture_format * st_ChooseTextureFormat (GLcontext *ctx, GLint internalFormat, GLenum format, GLenum type)
 Called via ctx->Driver.chooseTextureFormat().


Function Documentation

enum pipe_format st_choose_format ( struct pipe_context pipe,
GLint  internalFormat,
enum pipe_texture_target  target,
unsigned  tex_usage 
)

Given an OpenGL internalFormat value for a texture or surface, return the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.

Parameters:
target one of PIPE_TEXTURE_x
tex_usage either PIPE_TEXTURE_USAGE_RENDER_TARGET or PIPE_TEXTURE_USAGE_SAMPLER

Definition at line 350 of file st_format.c.

References default_deep_rgba_format(), default_depth_format(), default_rgba_format(), pipe_screen::is_format_supported, PIPE_FORMAT_A1R5G5B5_UNORM, PIPE_FORMAT_A4R4G4B4_UNORM, PIPE_FORMAT_A8_UNORM, PIPE_FORMAT_A8L8_UNORM, PIPE_FORMAT_DXT1_RGB, PIPE_FORMAT_DXT1_RGBA, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT5_RGBA, PIPE_FORMAT_I8_UNORM, PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_NONE, PIPE_FORMAT_R5G6B5_UNORM, PIPE_FORMAT_S8_UNORM, PIPE_FORMAT_S8Z24_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV, PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_Z24S8_UNORM, PIPE_FORMAT_Z32_UNORM, PIPE_TEXTURE_USAGE_RENDER_TARGET, and pipe_context::screen.

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 }

enum pipe_format st_choose_renderbuffer_format ( struct pipe_context pipe,
GLint  internalFormat 
)

Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.

Definition at line 542 of file st_format.c.

References is_stencil_format(), PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, PIPE_TEXTURE_USAGE_RENDER_TARGET, and st_choose_format().

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 }

struct gl_texture_format* st_ChooseTextureFormat ( GLcontext *  ctx,
GLint  internalFormat,
GLenum  format,
GLenum  type 
) [read]

Called via ctx->Driver.chooseTextureFormat().

Definition at line 607 of file st_format.c.

References PIPE_FORMAT_NONE, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER, st_choose_format(), and translate_gallium_format_to_mesa_format().

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 }

GLenum st_format_datatype ( enum pipe_format  format  ) 

Return bytes per pixel for the given format.

Definition at line 214 of file st_format.c.

References assert, pipe_format_info::datatype, and st_get_format_info().

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 }

GLboolean st_get_format_info ( enum pipe_format  format,
struct pipe_format_info pinfo 
)

Definition at line 86 of file st_format.c.

References pipe_format_info::alpha_bits, assert, pipe_format_info::base_format, pipe_format_info::blue_bits, pipe_format_info::datatype, pipe_format_info::depth_bits, pipe_format_info::format, format_bits(), format_max_bits(), format_size(), pipe_format_info::green_bits, pipe_format_info::intensity_bits, pipe_format_info::luminance_bits, pf_layout(), pf_name(), pf_swizzle_w, pf_swizzle_x, pf_swizzle_y, pf_swizzle_z, pf_type, PIPE_FORMAT_A1R5G5B5_UNORM, PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_LAYOUT_RGBAZS, PIPE_FORMAT_LAYOUT_YCBCR, PIPE_FORMAT_R5G6B5_UNORM, PIPE_FORMAT_TYPE_UNORM, pipe_format_info::red_bits, pipe_format_info::size, and pipe_format_info::stencil_bits.

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 }

enum pipe_format st_mesa_format_to_pipe_format ( GLuint  mesaFormat  ) 

Definition at line 226 of file st_format.c.

References assert, PIPE_FORMAT_A1R5G5B5_UNORM, PIPE_FORMAT_A4R4G4B4_UNORM, PIPE_FORMAT_A8_UNORM, PIPE_FORMAT_A8L8_UNORM, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_DXT1_RGB, PIPE_FORMAT_DXT1_RGBA, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT5_RGBA, PIPE_FORMAT_I8_UNORM, PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_R5G6B5_UNORM, PIPE_FORMAT_S8Z24_UNORM, PIPE_FORMAT_YCBCR, PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_Z24S8_UNORM, and PIPE_FORMAT_Z32_UNORM.

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 }

GLuint st_sizeof_format ( enum pipe_format  format  ) 

Return bytes per pixel for the given format.

Definition at line 199 of file st_format.c.

References assert, pipe_format_info::size, and st_get_format_info().

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 }


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