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  * Authors:
     28  *   Brian Paul
     29  */
     30 
     31 
     32 #ifndef FORMATS_H
     33 #define FORMATS_H
     34 
     35 
     36 #include <GL/gl.h>
     37 
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 
     44 /* OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
     45  * for GL_LUMINANCE4_ALPHA4. */
     46 #define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
     47 
     48 
     49 /**
     50  * Max number of bytes for any non-compressed pixel format below, or for
     51  * intermediate pixel storage in Mesa.  This should never be less than
     52  * 16.  Maybe 32 someday?
     53  */
     54 #define MAX_PIXEL_BYTES 16
     55 
     56 
     57 /**
     58  * Mesa texture/renderbuffer image formats.
     59  */
     60 typedef enum
     61 {
     62    MESA_FORMAT_NONE = 0,
     63 
     64    /**
     65     * \name Basic hardware formats
     66     */
     67    /*@{*/
     68 				/* msb <------ TEXEL BITS -----------> lsb */
     69 				/* ---- ---- ---- ---- ---- ---- ---- ---- */
     70    MESA_FORMAT_RGBA8888,	/* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
     71    MESA_FORMAT_RGBA8888_REV,	/* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
     72    MESA_FORMAT_ARGB8888,	/* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
     73    MESA_FORMAT_ARGB8888_REV,	/* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
     74    MESA_FORMAT_RGBX8888,	/* RRRR RRRR GGGG GGGG BBBB BBBB XXXX XXXX */
     75    MESA_FORMAT_RGBX8888_REV,	/* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
     76    MESA_FORMAT_XRGB8888,	/* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
     77    MESA_FORMAT_XRGB8888_REV,	/* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
     78    MESA_FORMAT_RGB888,		/*           RRRR RRRR GGGG GGGG BBBB BBBB */
     79    MESA_FORMAT_BGR888,		/*           BBBB BBBB GGGG GGGG RRRR RRRR */
     80    MESA_FORMAT_RGB565,		/*                     RRRR RGGG GGGB BBBB */
     81    MESA_FORMAT_RGB565_REV,	/*                     GGGB BBBB RRRR RGGG */
     82    MESA_FORMAT_ARGB4444,	/*                     AAAA RRRR GGGG BBBB */
     83    MESA_FORMAT_ARGB4444_REV,	/*                     GGGG BBBB AAAA RRRR */
     84    MESA_FORMAT_RGBA5551,        /*                     RRRR RGGG GGBB BBBA */
     85    MESA_FORMAT_ARGB1555,	/*                     ARRR RRGG GGGB BBBB */
     86    MESA_FORMAT_ARGB1555_REV,	/*                     GGGB BBBB ARRR RRGG */
     87    MESA_FORMAT_AL44,		/*                               AAAA LLLL */
     88    MESA_FORMAT_AL88,		/*                     AAAA AAAA LLLL LLLL */
     89    MESA_FORMAT_AL88_REV,	/*                     LLLL LLLL AAAA AAAA */
     90    MESA_FORMAT_AL1616,          /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
     91    MESA_FORMAT_AL1616_REV,      /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
     92    MESA_FORMAT_RGB332,		/*                               RRRG GGBB */
     93    MESA_FORMAT_A8,		/*                               AAAA AAAA */
     94    MESA_FORMAT_A16,             /*                     AAAA AAAA AAAA AAAA */
     95    MESA_FORMAT_L8,		/*                               LLLL LLLL */
     96    MESA_FORMAT_L16,             /*                     LLLL LLLL LLLL LLLL */
     97    MESA_FORMAT_I8,		/*                               IIII IIII */
     98    MESA_FORMAT_I16,             /*                     IIII IIII IIII IIII */
     99    MESA_FORMAT_YCBCR,		/*                     YYYY YYYY UorV UorV */
    100    MESA_FORMAT_YCBCR_REV,	/*                     UorV UorV YYYY YYYY */
    101    MESA_FORMAT_R8,		/*                               RRRR RRRR */
    102    MESA_FORMAT_GR88,		/*                     GGGG GGGG RRRR RRRR */
    103    MESA_FORMAT_RG88,    	/*                     RRRR RRRR GGGG GGGG */
    104    MESA_FORMAT_R16,		/*                     RRRR RRRR RRRR RRRR */
    105    MESA_FORMAT_RG1616,		/* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
    106    MESA_FORMAT_RG1616_REV,	/* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
    107    MESA_FORMAT_ARGB2101010,     /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
    108    MESA_FORMAT_Z24_S8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
    109    MESA_FORMAT_S8_Z24,          /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    110    MESA_FORMAT_Z16,             /*                     ZZZZ ZZZZ ZZZZ ZZZZ */
    111    MESA_FORMAT_X8_Z24,          /* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    112    MESA_FORMAT_Z24_X8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */
    113    MESA_FORMAT_Z32,             /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    114    MESA_FORMAT_S8,              /*                               SSSS SSSS */
    115    /*@}*/
    116 
    117    /**
    118     * \name 8-bit/channel sRGB formats
    119     */
    120    /*@{*/
    121    MESA_FORMAT_SRGB8,           /*           RRRR RRRR GGGG GGGG BBBB BBBB */
    122    MESA_FORMAT_SRGBA8,          /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    123    MESA_FORMAT_SARGB8,          /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
    124    MESA_FORMAT_SL8,             /*                               LLLL LLLL */
    125    MESA_FORMAT_SLA8,            /*                     AAAA AAAA LLLL LLLL */
    126    MESA_FORMAT_SRGB_DXT1,
    127    MESA_FORMAT_SRGBA_DXT1,
    128    MESA_FORMAT_SRGBA_DXT3,
    129    MESA_FORMAT_SRGBA_DXT5,
    130    /*@}*/
    131 
    132    /**
    133     * \name Compressed texture formats.
    134     */
    135    /*@{*/
    136    MESA_FORMAT_RGB_FXT1,
    137    MESA_FORMAT_RGBA_FXT1,
    138    MESA_FORMAT_RGB_DXT1,
    139    MESA_FORMAT_RGBA_DXT1,
    140    MESA_FORMAT_RGBA_DXT3,
    141    MESA_FORMAT_RGBA_DXT5,
    142    /*@}*/
    143 
    144    /**
    145     * \name Floating point texture formats.
    146     */
    147    /*@{*/
    148    MESA_FORMAT_RGBA_FLOAT32,
    149    MESA_FORMAT_RGBA_FLOAT16,
    150    MESA_FORMAT_RGB_FLOAT32,
    151    MESA_FORMAT_RGB_FLOAT16,
    152    MESA_FORMAT_ALPHA_FLOAT32,
    153    MESA_FORMAT_ALPHA_FLOAT16,
    154    MESA_FORMAT_LUMINANCE_FLOAT32,
    155    MESA_FORMAT_LUMINANCE_FLOAT16,
    156    MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
    157    MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
    158    MESA_FORMAT_INTENSITY_FLOAT32,
    159    MESA_FORMAT_INTENSITY_FLOAT16,
    160    MESA_FORMAT_R_FLOAT32,
    161    MESA_FORMAT_R_FLOAT16,
    162    MESA_FORMAT_RG_FLOAT32,
    163    MESA_FORMAT_RG_FLOAT16,
    164    /*@}*/
    165 
    166    /**
    167     * \name Non-normalized signed integer formats.
    168     * XXX Note: these are just stand-ins for some better hardware
    169     * formats TBD such as BGRA or ARGB.
    170     */
    171    MESA_FORMAT_ALPHA_UINT8,
    172    MESA_FORMAT_ALPHA_UINT16,
    173    MESA_FORMAT_ALPHA_UINT32,
    174    MESA_FORMAT_ALPHA_INT8,
    175    MESA_FORMAT_ALPHA_INT16,
    176    MESA_FORMAT_ALPHA_INT32,
    177 
    178    MESA_FORMAT_INTENSITY_UINT8,
    179    MESA_FORMAT_INTENSITY_UINT16,
    180    MESA_FORMAT_INTENSITY_UINT32,
    181    MESA_FORMAT_INTENSITY_INT8,
    182    MESA_FORMAT_INTENSITY_INT16,
    183    MESA_FORMAT_INTENSITY_INT32,
    184 
    185    MESA_FORMAT_LUMINANCE_UINT8,
    186    MESA_FORMAT_LUMINANCE_UINT16,
    187    MESA_FORMAT_LUMINANCE_UINT32,
    188    MESA_FORMAT_LUMINANCE_INT8,
    189    MESA_FORMAT_LUMINANCE_INT16,
    190    MESA_FORMAT_LUMINANCE_INT32,
    191 
    192    MESA_FORMAT_LUMINANCE_ALPHA_UINT8,
    193    MESA_FORMAT_LUMINANCE_ALPHA_UINT16,
    194    MESA_FORMAT_LUMINANCE_ALPHA_UINT32,
    195    MESA_FORMAT_LUMINANCE_ALPHA_INT8,
    196    MESA_FORMAT_LUMINANCE_ALPHA_INT16,
    197    MESA_FORMAT_LUMINANCE_ALPHA_INT32,
    198 
    199    MESA_FORMAT_R_INT8,
    200    MESA_FORMAT_RG_INT8,
    201    MESA_FORMAT_RGB_INT8,
    202    MESA_FORMAT_RGBA_INT8,
    203    MESA_FORMAT_R_INT16,
    204    MESA_FORMAT_RG_INT16,
    205    MESA_FORMAT_RGB_INT16,
    206    MESA_FORMAT_RGBA_INT16,
    207    MESA_FORMAT_R_INT32,
    208    MESA_FORMAT_RG_INT32,
    209    MESA_FORMAT_RGB_INT32,
    210    MESA_FORMAT_RGBA_INT32,
    211 
    212    /**
    213     * \name Non-normalized unsigned integer formats.
    214     */
    215    MESA_FORMAT_R_UINT8,
    216    MESA_FORMAT_RG_UINT8,
    217    MESA_FORMAT_RGB_UINT8,
    218    MESA_FORMAT_RGBA_UINT8,
    219    MESA_FORMAT_R_UINT16,
    220    MESA_FORMAT_RG_UINT16,
    221    MESA_FORMAT_RGB_UINT16,
    222    MESA_FORMAT_RGBA_UINT16,
    223    MESA_FORMAT_R_UINT32,
    224    MESA_FORMAT_RG_UINT32,
    225    MESA_FORMAT_RGB_UINT32,
    226    MESA_FORMAT_RGBA_UINT32,
    227 
    228                                   /* msb <------ TEXEL BITS -----------> lsb */
    229                                   /* ---- ---- ---- ---- ---- ---- ---- ---- */
    230    /**
    231     * \name Signed fixed point texture formats.
    232     */
    233    /*@{*/
    234    MESA_FORMAT_DUDV8,             /*                     DUDU DUDU DVDV DVDV */
    235    MESA_FORMAT_SIGNED_R8,         /*                               RRRR RRRR */
    236    MESA_FORMAT_SIGNED_RG88_REV,   /*                     GGGG GGGG RRRR RRRR */
    237    MESA_FORMAT_SIGNED_RGBX8888,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
    238    MESA_FORMAT_SIGNED_RGBA8888,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
    239    MESA_FORMAT_SIGNED_RGBA8888_REV,/*AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    240    MESA_FORMAT_SIGNED_R16,        /*                     RRRR RRRR RRRR RRRR */
    241    MESA_FORMAT_SIGNED_GR1616,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
    242    MESA_FORMAT_SIGNED_RGB_16,     /* ushort[0]=R, ushort[1]=G, ushort[2]=B */
    243    MESA_FORMAT_SIGNED_RGBA_16,    /* ... */
    244    MESA_FORMAT_RGBA_16,           /* ... */
    245    /*@}*/
    246 
    247    /*@{*/
    248    MESA_FORMAT_RED_RGTC1,
    249    MESA_FORMAT_SIGNED_RED_RGTC1,
    250    MESA_FORMAT_RG_RGTC2,
    251    MESA_FORMAT_SIGNED_RG_RGTC2,
    252    /*@}*/
    253 
    254    /*@{*/
    255    MESA_FORMAT_L_LATC1,
    256    MESA_FORMAT_SIGNED_L_LATC1,
    257    MESA_FORMAT_LA_LATC2,
    258    MESA_FORMAT_SIGNED_LA_LATC2,
    259    /*@}*/
    260 
    261    MESA_FORMAT_ETC1_RGB8,
    262 
    263    MESA_FORMAT_SIGNED_A8,         /*                               AAAA AAAA */
    264    MESA_FORMAT_SIGNED_L8,         /*                               LLLL LLLL */
    265    MESA_FORMAT_SIGNED_AL88,       /*                     AAAA AAAA LLLL LLLL */
    266    MESA_FORMAT_SIGNED_I8,         /*                               IIII IIII */
    267    MESA_FORMAT_SIGNED_A16,        /*                     AAAA AAAA AAAA AAAA */
    268    MESA_FORMAT_SIGNED_L16,        /*                     LLLL LLLL LLLL LLLL */
    269    MESA_FORMAT_SIGNED_AL1616,     /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
    270    MESA_FORMAT_SIGNED_I16,        /*                     IIII IIII IIII IIII */
    271 
    272    MESA_FORMAT_RGB9_E5_FLOAT,
    273    MESA_FORMAT_R11_G11_B10_FLOAT,
    274 
    275    MESA_FORMAT_Z32_FLOAT,
    276    MESA_FORMAT_Z32_FLOAT_X24S8,
    277 
    278    MESA_FORMAT_ARGB2101010_UINT,
    279    MESA_FORMAT_ABGR2101010_UINT,
    280 
    281    MESA_FORMAT_COUNT
    282 } gl_format;
    283 
    284 
    285 extern const char *
    286 _mesa_get_format_name(gl_format format);
    287 
    288 extern GLint
    289 _mesa_get_format_bytes(gl_format format);
    290 
    291 extern GLint
    292 _mesa_get_format_bits(gl_format format, GLenum pname);
    293 
    294 extern GLuint
    295 _mesa_get_format_max_bits(gl_format format);
    296 
    297 extern GLenum
    298 _mesa_get_format_datatype(gl_format format);
    299 
    300 extern GLenum
    301 _mesa_get_format_base_format(gl_format format);
    302 
    303 extern void
    304 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh);
    305 
    306 extern GLboolean
    307 _mesa_is_format_compressed(gl_format format);
    308 
    309 extern GLboolean
    310 _mesa_is_format_packed_depth_stencil(gl_format format);
    311 
    312 extern GLboolean
    313 _mesa_is_format_integer_color(gl_format format);
    314 
    315 extern GLboolean
    316 _mesa_is_format_unsigned(gl_format format);
    317 
    318 extern GLenum
    319 _mesa_get_format_color_encoding(gl_format format);
    320 
    321 extern GLuint
    322 _mesa_format_image_size(gl_format format, GLsizei width,
    323                         GLsizei height, GLsizei depth);
    324 
    325 extern uint64_t
    326 _mesa_format_image_size64(gl_format format, GLsizei width,
    327                           GLsizei height, GLsizei depth);
    328 
    329 extern GLint
    330 _mesa_format_row_stride(gl_format format, GLsizei width);
    331 
    332 extern void
    333 _mesa_format_to_type_and_comps(gl_format format,
    334                                GLenum *datatype, GLuint *comps);
    335 
    336 extern void
    337 _mesa_test_formats(void);
    338 
    339 extern gl_format
    340 _mesa_get_srgb_format_linear(gl_format format);
    341 
    342 extern gl_format
    343 _mesa_get_uncompressed_format(gl_format format);
    344 
    345 extern GLuint
    346 _mesa_format_num_components(gl_format format);
    347 
    348 GLboolean
    349 _mesa_format_matches_format_and_type(gl_format gl_format,
    350 				     GLenum format, GLenum type,
    351                                      GLboolean swapBytes);
    352 
    353 #ifdef __cplusplus
    354 }
    355 #endif
    356 
    357 #endif /* FORMATS_H */
    358