1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5 * Copyright (c) 2008-2009 VMware, Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * 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#include <stdbool.h> 38#include <stdint.h> 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44 45/** 46 * OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type 47 * for GL_LUMINANCE4_ALPHA4. 48 */ 49#define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1) 50 51 52/** 53 * Max number of bytes for any non-compressed pixel format below, or for 54 * intermediate pixel storage in Mesa. This should never be less than 55 * 16. Maybe 32 someday? 56 */ 57#define MAX_PIXEL_BYTES 16 58 59/** 60 * Specifies the layout of a pixel format. See the MESA_FORMAT 61 * documentation below. 62 */ 63enum mesa_format_layout { 64 MESA_FORMAT_LAYOUT_ARRAY, 65 MESA_FORMAT_LAYOUT_PACKED, 66 MESA_FORMAT_LAYOUT_S3TC, 67 MESA_FORMAT_LAYOUT_RGTC, 68 MESA_FORMAT_LAYOUT_LATC, 69 MESA_FORMAT_LAYOUT_FXT1, 70 MESA_FORMAT_LAYOUT_ETC1, 71 MESA_FORMAT_LAYOUT_ETC2, 72 MESA_FORMAT_LAYOUT_BPTC, 73 MESA_FORMAT_LAYOUT_ASTC, 74 MESA_FORMAT_LAYOUT_ATC, 75 MESA_FORMAT_LAYOUT_OTHER, 76}; 77 78/** 79 * An enum representing different possible swizzling values. This is used 80 * to interpret the output of _mesa_get_format_swizzle 81 */ 82enum { 83 MESA_FORMAT_SWIZZLE_X = 0, 84 MESA_FORMAT_SWIZZLE_Y = 1, 85 MESA_FORMAT_SWIZZLE_Z = 2, 86 MESA_FORMAT_SWIZZLE_W = 3, 87 MESA_FORMAT_SWIZZLE_ZERO = 4, 88 MESA_FORMAT_SWIZZLE_ONE = 5, 89 MESA_FORMAT_SWIZZLE_NONE = 6, 90}; 91 92/** 93 * An uint32_t that encodes the information necessary to represent an 94 * array format 95 */ 96typedef uint32_t mesa_array_format; 97 98/** 99 * Encoding for valid array format data types 100 */ 101enum mesa_array_format_datatype { 102 MESA_ARRAY_FORMAT_TYPE_UBYTE = 0x0, 103 MESA_ARRAY_FORMAT_TYPE_USHORT = 0x1, 104 MESA_ARRAY_FORMAT_TYPE_UINT = 0x2, 105 MESA_ARRAY_FORMAT_TYPE_BYTE = 0x4, 106 MESA_ARRAY_FORMAT_TYPE_SHORT = 0x5, 107 MESA_ARRAY_FORMAT_TYPE_INT = 0x6, 108 MESA_ARRAY_FORMAT_TYPE_HALF = 0xd, 109 MESA_ARRAY_FORMAT_TYPE_FLOAT = 0xe, 110}; 111 112/** 113 * An enum useful to encode/decode information stored in a mesa_array_format 114 */ 115enum { 116 MESA_ARRAY_FORMAT_TYPE_IS_SIGNED = 0x4, 117 MESA_ARRAY_FORMAT_TYPE_IS_FLOAT = 0x8, 118 MESA_ARRAY_FORMAT_TYPE_NORMALIZED = 0x10, 119 MESA_ARRAY_FORMAT_DATATYPE_MASK = 0xf, 120 MESA_ARRAY_FORMAT_TYPE_MASK = 0x1f, 121 MESA_ARRAY_FORMAT_TYPE_SIZE_MASK = 0x3, 122 MESA_ARRAY_FORMAT_NUM_CHANS_MASK = 0xe0, 123 MESA_ARRAY_FORMAT_SWIZZLE_X_MASK = 0x00700, 124 MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK = 0x03800, 125 MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK = 0x1c000, 126 MESA_ARRAY_FORMAT_SWIZZLE_W_MASK = 0xe0000, 127 MESA_ARRAY_FORMAT_BIT = 0x80000000 128}; 129 130#define MESA_ARRAY_FORMAT(SIZE, SIGNED, IS_FLOAT, NORM, NUM_CHANS, \ 131 SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W) ( \ 132 (((SIZE >> 1) ) & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK) | \ 133 (((SIGNED) << 2 ) & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) | \ 134 (((IS_FLOAT) << 3 ) & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) | \ 135 (((NORM) << 4 ) & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) | \ 136 (((NUM_CHANS) << 5 ) & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) | \ 137 (((SWIZZLE_X) << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) | \ 138 (((SWIZZLE_Y) << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) | \ 139 (((SWIZZLE_Z) << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) | \ 140 (((SWIZZLE_W) << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) | \ 141 MESA_ARRAY_FORMAT_BIT) 142 143/** 144 * Various helpers to access the data encoded in a mesa_array_format 145 */ 146static inline bool 147_mesa_array_format_is_signed(mesa_array_format f) 148{ 149 return (f & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED) != 0; 150} 151 152static inline bool 153_mesa_array_format_is_float(mesa_array_format f) 154{ 155 return (f & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT) != 0; 156} 157 158static inline bool 159_mesa_array_format_is_normalized(mesa_array_format f) 160{ 161 return (f & MESA_ARRAY_FORMAT_TYPE_NORMALIZED) !=0; 162} 163 164static inline enum mesa_array_format_datatype 165_mesa_array_format_get_datatype(mesa_array_format f) 166{ 167 return (enum mesa_array_format_datatype) 168 (f & MESA_ARRAY_FORMAT_DATATYPE_MASK); 169} 170 171static inline int 172_mesa_array_format_datatype_get_size(enum mesa_array_format_datatype type) 173{ 174 return 1 << (type & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK); 175} 176 177static inline int 178_mesa_array_format_get_type_size(mesa_array_format f) 179{ 180 return 1 << (f & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK); 181} 182 183static inline int 184_mesa_array_format_get_num_channels(mesa_array_format f) 185{ 186 return (f & MESA_ARRAY_FORMAT_NUM_CHANS_MASK) >> 5; 187} 188 189static inline void 190_mesa_array_format_get_swizzle(mesa_array_format f, uint8_t *swizzle) 191{ 192 swizzle[0] = (f & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) >> 8; 193 swizzle[1] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) >> 11; 194 swizzle[2] = (f & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) >> 14; 195 swizzle[3] = (f & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK) >> 17; 196} 197 198static inline void 199_mesa_array_format_set_swizzle(mesa_array_format *f, 200 int32_t x, int32_t y, int32_t z, int32_t w) 201{ 202 *f &= ~(MESA_ARRAY_FORMAT_SWIZZLE_X_MASK | 203 MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK | 204 MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK | 205 MESA_ARRAY_FORMAT_SWIZZLE_W_MASK); 206 207 *f |= ((x << 8 ) & MESA_ARRAY_FORMAT_SWIZZLE_X_MASK) | 208 ((y << 11) & MESA_ARRAY_FORMAT_SWIZZLE_Y_MASK) | 209 ((z << 14) & MESA_ARRAY_FORMAT_SWIZZLE_Z_MASK) | 210 ((w << 17) & MESA_ARRAY_FORMAT_SWIZZLE_W_MASK); 211} 212 213/** 214 * A helper to know if the format stored in a uint32_t is a mesa_format 215 * or a mesa_array_format 216 */ 217static inline bool 218_mesa_format_is_mesa_array_format(uint32_t f) 219{ 220 return (f & MESA_ARRAY_FORMAT_BIT) != 0; 221} 222 223/** 224 * Mesa texture/renderbuffer image formats. 225 */ 226typedef enum 227{ 228 MESA_FORMAT_NONE = 0, 229 230 /** 231 * \name Basic hardware formats 232 * 233 * The mesa format name specification is as follows: 234 * 235 * There shall be 3 naming format base types: those for component array 236 * formats (type A); those for compressed formats (type C); and those for 237 * packed component formats (type P). With type A formats, color component 238 * order does not change with endianess. Each format name shall begin with 239 * MESA_FORMAT_, followed by a component label (from the Component Label 240 * list below) for each component in the order that the component(s) occur 241 * in the format, except for non-linear color formats where the first 242 * letter shall be 'S'. For type P formats, each component label is 243 * followed by the number of bits that represent it in the fundamental 244 * data type used by the format. 245 * 246 * Following the listing of the component labels shall be an underscore; a 247 * compression type followed by an underscore for Type C formats only; a 248 * storage type from the list below; and a bit with for type A formats, 249 * which is the bit width for each array element. 250 * 251 * 252 * ---------- Format Base Type A: Array ---------- 253 * MESA_FORMAT_[component list]_[storage type][array element bit width] 254 * 255 * examples: 256 * MESA_FORMAT_A_SNORM8 - uchar[i] = A 257 * MESA_FORMAT_RGBA_16 - ushort[i * 4 + 0] = R, ushort[i * 4 + 1] = G, 258 * ushort[i * 4 + 2] = B, ushort[i * 4 + 3] = A 259 * MESA_FORMAT_Z_UNORM32 - float[i] = Z 260 * 261 * 262 * 263 * ---------- Format Base Type C: Compressed ---------- 264 * MESA_FORMAT_[component list*][_*][compression type][storage type*] 265 * * where required 266 * 267 * examples: 268 * MESA_FORMAT_RGB_ETC1 269 * MESA_FORMAT_RGBA_ETC2 270 * MESA_FORMAT_LATC1_UNORM 271 * MESA_FORMAT_RGBA_FXT1 272 * 273 * 274 * 275 * ---------- Format Base Type P: Packed ---------- 276 * MESA_FORMAT_[[component list,bit width][storage type*][_]][_][storage type**] 277 * * when type differs between component 278 * ** when type applies to all components 279 * 280 * examples: msb <------ TEXEL BITS -----------> lsb 281 * MESA_FORMAT_A8B8G8R8_UNORM, RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA 282 * MESA_FORMAT_R5G6B5_UNORM BBBB BGGG GGGR RRRR 283 * MESA_FORMAT_B4G4R4X4_UNORM XXXX RRRR GGGG BBBB 284 * MESA_FORMAT_Z32_FLOAT_S8X24_UINT 285 * MESA_FORMAT_R10G10B10A2_UINT 286 * MESA_FORMAT_R9G9B9E5_FLOAT 287 * 288 * 289 * 290 * ---------- Component Labels: ---------- 291 * A - Alpha 292 * B - Blue 293 * DU - Delta U 294 * DV - Delta V 295 * E - Shared Exponent 296 * G - Green 297 * I - Intensity 298 * L - Luminance 299 * R - Red 300 * S - Stencil (when not followed by RGB or RGBA) 301 * U - Chrominance 302 * V - Chrominance 303 * Y - Luma 304 * X - Packing bits 305 * Z - Depth 306 * 307 * 308 * 309 * ---------- Type C Compression Types: ---------- 310 * DXT1 - Color component labels shall be given 311 * DXT3 - Color component labels shall be given 312 * DXT5 - Color component labels shall be given 313 * ETC1 - No other information required 314 * ETC2 - No other information required 315 * FXT1 - Color component labels shall be given 316 * FXT3 - Color component labels shall be given 317 * LATC1 - Fundamental data type shall be given 318 * LATC2 - Fundamental data type shall be given 319 * RGTC1 - Color component labels and data type shall be given 320 * RGTC2 - Color component labels and data type shall be given 321 * 322 * 323 * 324 * ---------- Storage Types: ---------- 325 * FLOAT 326 * SINT 327 * UINT 328 * SNORM 329 * UNORM 330 * SRGB - RGB components, or L are UNORMs in sRGB color space. 331 * Alpha, if present is linear. 332 * 333 */ 334 335 /* Packed unorm formats */ /* msb <------ TEXEL BITS -----------> lsb */ 336 /* ---- ---- ---- ---- ---- ---- ---- ---- */ 337 MESA_FORMAT_A8B8G8R8_UNORM, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */ 338 MESA_FORMAT_X8B8G8R8_UNORM, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */ 339 MESA_FORMAT_R8G8B8A8_UNORM, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */ 340 MESA_FORMAT_R8G8B8X8_UNORM, /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */ 341 MESA_FORMAT_B8G8R8A8_UNORM, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */ 342 MESA_FORMAT_B8G8R8X8_UNORM, /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */ 343 MESA_FORMAT_A8R8G8B8_UNORM, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */ 344 MESA_FORMAT_X8R8G8B8_UNORM, /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */ 345 MESA_FORMAT_L16A16_UNORM, /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */ 346 MESA_FORMAT_A16L16_UNORM, /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */ 347 MESA_FORMAT_B5G6R5_UNORM, /* RRRR RGGG GGGB BBBB */ 348 MESA_FORMAT_R5G6B5_UNORM, /* BBBB BGGG GGGR RRRR */ 349 MESA_FORMAT_B4G4R4A4_UNORM, /* AAAA RRRR GGGG BBBB */ 350 MESA_FORMAT_B4G4R4X4_UNORM, /* xxxx RRRR GGGG BBBB */ 351 MESA_FORMAT_A4R4G4B4_UNORM, /* BBBB GGGG RRRR AAAA */ 352 MESA_FORMAT_A1B5G5R5_UNORM, /* RRRR RGGG GGBB BBBA */ 353 MESA_FORMAT_X1B5G5R5_UNORM, /* BBBB BGGG GGRR RRRX */ 354 MESA_FORMAT_B5G5R5A1_UNORM, /* ARRR RRGG GGGB BBBB */ 355 MESA_FORMAT_B5G5R5X1_UNORM, /* xRRR RRGG GGGB BBBB */ 356 MESA_FORMAT_A1R5G5B5_UNORM, /* BBBB BGGG GGRR RRRA */ 357 MESA_FORMAT_L8A8_UNORM, /* AAAA AAAA LLLL LLLL */ 358 MESA_FORMAT_A8L8_UNORM, /* LLLL LLLL AAAA AAAA */ 359 MESA_FORMAT_R8G8_UNORM, /* GGGG GGGG RRRR RRRR */ 360 MESA_FORMAT_G8R8_UNORM, /* RRRR RRRR GGGG GGGG */ 361 MESA_FORMAT_L4A4_UNORM, /* AAAA LLLL */ 362 MESA_FORMAT_B2G3R3_UNORM, /* RRRG GGBB */ 363 364 MESA_FORMAT_R16G16_UNORM, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */ 365 MESA_FORMAT_G16R16_UNORM, /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */ 366 MESA_FORMAT_B10G10R10A2_UNORM,/* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */ 367 MESA_FORMAT_B10G10R10X2_UNORM,/* xxRR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */ 368 MESA_FORMAT_R10G10B10A2_UNORM,/* AABB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */ 369 MESA_FORMAT_R10G10B10X2_UNORM,/* xxBB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */ 370 371 MESA_FORMAT_S8_UINT_Z24_UNORM,/* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */ 372 MESA_FORMAT_X8_UINT_Z24_UNORM,/* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */ 373 MESA_FORMAT_Z24_UNORM_S8_UINT,/* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */ 374 MESA_FORMAT_Z24_UNORM_X8_UINT,/* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */ 375 376 /* Other formats */ 377 MESA_FORMAT_R3G3B2_UNORM, /* BBGG GRRR */ 378 MESA_FORMAT_A4B4G4R4_UNORM, /* RRRR GGGG BBBB AAAA */ 379 MESA_FORMAT_R4G4B4A4_UNORM, /* AAAA BBBB GGGG RRRR */ 380 MESA_FORMAT_R5G5B5A1_UNORM, /* ABBB BBGG GGGR RRRR */ 381 MESA_FORMAT_A2B10G10R10_UNORM,/* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */ 382 MESA_FORMAT_A2R10G10B10_UNORM,/* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */ 383 384 MESA_FORMAT_YCBCR, /* YYYY YYYY UorV UorV */ 385 MESA_FORMAT_YCBCR_REV, /* UorV UorV YYYY YYYY */ 386 387 /* Array unorm formats */ 388 MESA_FORMAT_A_UNORM8, /* ubyte[i] = A */ 389 MESA_FORMAT_A_UNORM16, /* ushort[i] = A */ 390 MESA_FORMAT_L_UNORM8, /* ubyte[i] = L */ 391 MESA_FORMAT_L_UNORM16, /* ushort[i] = L */ 392 MESA_FORMAT_I_UNORM8, /* ubyte[i] = I */ 393 MESA_FORMAT_I_UNORM16, /* ushort[i] = I */ 394 MESA_FORMAT_R_UNORM8, /* ubyte[i] = R */ 395 MESA_FORMAT_R_UNORM16, /* ushort[i] = R */ 396 MESA_FORMAT_BGR_UNORM8, /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */ 397 MESA_FORMAT_RGB_UNORM8, /* ubyte[i*3] = R, [i*3+1] = G, [i*3+2] = B */ 398 MESA_FORMAT_RGBA_UNORM16, /* ushort[i] = R, [1] = G, [2] = B, [3] = A */ 399 MESA_FORMAT_RGBX_UNORM16, 400 401 MESA_FORMAT_Z_UNORM16, /* ushort[i] = Z */ 402 MESA_FORMAT_Z_UNORM32, /* uint[i] = Z */ 403 MESA_FORMAT_S_UINT8, /* ubyte[i] = S */ 404 405 /* Packed signed/normalized formats */ 406 /* msb <------ TEXEL BITS -----------> lsb */ 407 /* ---- ---- ---- ---- ---- ---- ---- ---- */ 408 MESA_FORMAT_A8B8G8R8_SNORM, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */ 409 MESA_FORMAT_X8B8G8R8_SNORM, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */ 410 MESA_FORMAT_R8G8B8A8_SNORM, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */ 411 MESA_FORMAT_R8G8B8X8_SNORM, /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */ 412 MESA_FORMAT_R16G16_SNORM, /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */ 413 MESA_FORMAT_G16R16_SNORM, /* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */ 414 MESA_FORMAT_R8G8_SNORM, /* GGGG GGGG RRRR RRRR */ 415 MESA_FORMAT_G8R8_SNORM, /* RRRR RRRR GGGG GGGG */ 416 MESA_FORMAT_L8A8_SNORM, /* AAAA AAAA LLLL LLLL */ 417 MESA_FORMAT_A8L8_SNORM, /* LLLL LLLL AAAA AAAA */ 418 419 /* Array signed/normalized formats */ 420 MESA_FORMAT_A_SNORM8, /* byte[i] = A */ 421 MESA_FORMAT_A_SNORM16, /* short[i] = A */ 422 MESA_FORMAT_L_SNORM8, /* byte[i] = L */ 423 MESA_FORMAT_L_SNORM16, /* short[i] = L */ 424 MESA_FORMAT_I_SNORM8, /* byte[i] = I */ 425 MESA_FORMAT_I_SNORM16, /* short[i] = I */ 426 MESA_FORMAT_R_SNORM8, /* byte[i] = R */ 427 MESA_FORMAT_R_SNORM16, /* short[i] = R */ 428 MESA_FORMAT_LA_SNORM16, /* short[i * 2] = L, [i * 2 + 1] = A */ 429 MESA_FORMAT_RGB_SNORM16, /* short[i*3] = R, [i*3+1] = G, [i*3+2] = B */ 430 MESA_FORMAT_RGBA_SNORM16, /* ... */ 431 MESA_FORMAT_RGBX_SNORM16, /* ... */ 432 433 /* Packed sRGB formats */ 434 MESA_FORMAT_A8B8G8R8_SRGB, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */ 435 MESA_FORMAT_B8G8R8A8_SRGB, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */ 436 MESA_FORMAT_A8R8G8B8_SRGB, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */ 437 MESA_FORMAT_B8G8R8X8_SRGB, /* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */ 438 MESA_FORMAT_X8R8G8B8_SRGB, /* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */ 439 MESA_FORMAT_R8G8B8A8_SRGB, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */ 440 MESA_FORMAT_R8G8B8X8_SRGB, /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */ 441 MESA_FORMAT_X8B8G8R8_SRGB, /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */ 442 MESA_FORMAT_L8A8_SRGB, /* AAAA AAAA LLLL LLLL */ 443 MESA_FORMAT_A8L8_SRGB, /* LLLL LLLL AAAA AAAA */ 444 MESA_FORMAT_R_SRGB8, /* RRRR RRRR */ 445 446 /* Array sRGB formats */ 447 MESA_FORMAT_L_SRGB8, /* ubyte[i] = L */ 448 MESA_FORMAT_BGR_SRGB8, /* ubyte[i*3] = B, [i*3+1] = G, [i*3+2] = R */ 449 450 /* Packed float formats */ 451 MESA_FORMAT_R9G9B9E5_FLOAT, 452 MESA_FORMAT_R11G11B10_FLOAT, /* BBBB BBBB BBGG GGGG GGGG GRRR RRRR RRRR */ 453 MESA_FORMAT_Z32_FLOAT_S8X24_UINT, /* (float, x24s8) */ 454 455 /* Array float formats */ 456 MESA_FORMAT_A_FLOAT16, 457 MESA_FORMAT_A_FLOAT32, 458 MESA_FORMAT_L_FLOAT16, 459 MESA_FORMAT_L_FLOAT32, 460 MESA_FORMAT_LA_FLOAT16, 461 MESA_FORMAT_LA_FLOAT32, 462 MESA_FORMAT_I_FLOAT16, 463 MESA_FORMAT_I_FLOAT32, 464 MESA_FORMAT_R_FLOAT16, 465 MESA_FORMAT_R_FLOAT32, 466 MESA_FORMAT_RG_FLOAT16, 467 MESA_FORMAT_RG_FLOAT32, 468 MESA_FORMAT_RGB_FLOAT16, 469 MESA_FORMAT_RGB_FLOAT32, 470 MESA_FORMAT_RGBA_FLOAT16, 471 MESA_FORMAT_RGBA_FLOAT32, /* float[0] = R, [1] = G, [2] = B, [3] = A */ 472 MESA_FORMAT_RGBX_FLOAT16, 473 MESA_FORMAT_RGBX_FLOAT32, 474 MESA_FORMAT_Z_FLOAT32, 475 476 /* Packed signed/unsigned non-normalized integer formats */ 477 478 MESA_FORMAT_A8B8G8R8_UINT, /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */ 479 MESA_FORMAT_A8R8G8B8_UINT, /* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */ 480 MESA_FORMAT_R8G8B8A8_UINT, /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */ 481 MESA_FORMAT_B8G8R8A8_UINT, /* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */ 482 MESA_FORMAT_B10G10R10A2_UINT, /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */ 483 MESA_FORMAT_R10G10B10A2_UINT, /* AABB BBBB BBBB GGGG GGGG GGRR RRRR RRRR */ 484 MESA_FORMAT_A2B10G10R10_UINT, /* RRRR RRRR RRGG GGGG GGGG BBBB BBBB BBAA */ 485 MESA_FORMAT_A2R10G10B10_UINT, /* BBBB BBBB BBGG GGGG GGGG RRRR RRRR RRAA */ 486 MESA_FORMAT_B5G6R5_UINT, /* RRRR RGGG GGGB BBBB */ 487 MESA_FORMAT_R5G6B5_UINT, /* BBBB BGGG GGGR RRRR */ 488 MESA_FORMAT_B2G3R3_UINT, /* RRRG GGBB */ 489 MESA_FORMAT_R3G3B2_UINT, /* BBGG GRRR */ 490 MESA_FORMAT_A4B4G4R4_UINT, /* RRRR GGGG BBBB AAAA */ 491 MESA_FORMAT_R4G4B4A4_UINT, /* AAAA BBBB GGGG RRRR */ 492 MESA_FORMAT_B4G4R4A4_UINT, /* AAAA RRRR GGGG BBBB */ 493 MESA_FORMAT_A4R4G4B4_UINT, /* BBBB GGGG RRRR AAAA */ 494 MESA_FORMAT_A1B5G5R5_UINT, /* RRRR RGGG GGBB BBBA */ 495 MESA_FORMAT_B5G5R5A1_UINT, /* ARRR RRGG GGGB BBBB */ 496 MESA_FORMAT_A1R5G5B5_UINT, /* BBBB BGGG GGRR RRRA */ 497 MESA_FORMAT_R5G5B5A1_UINT, /* ABBB BBGG GGGR RRRR */ 498 499 /* Array signed/unsigned non-normalized integer formats */ 500 MESA_FORMAT_A_UINT8, 501 MESA_FORMAT_A_UINT16, 502 MESA_FORMAT_A_UINT32, 503 MESA_FORMAT_A_SINT8, 504 MESA_FORMAT_A_SINT16, 505 MESA_FORMAT_A_SINT32, 506 507 MESA_FORMAT_I_UINT8, 508 MESA_FORMAT_I_UINT16, 509 MESA_FORMAT_I_UINT32, 510 MESA_FORMAT_I_SINT8, 511 MESA_FORMAT_I_SINT16, 512 MESA_FORMAT_I_SINT32, 513 514 MESA_FORMAT_L_UINT8, 515 MESA_FORMAT_L_UINT16, 516 MESA_FORMAT_L_UINT32, 517 MESA_FORMAT_L_SINT8, 518 MESA_FORMAT_L_SINT16, 519 MESA_FORMAT_L_SINT32, 520 521 MESA_FORMAT_LA_UINT8, 522 MESA_FORMAT_LA_UINT16, 523 MESA_FORMAT_LA_UINT32, 524 MESA_FORMAT_LA_SINT8, 525 MESA_FORMAT_LA_SINT16, 526 MESA_FORMAT_LA_SINT32, 527 528 MESA_FORMAT_R_UINT8, 529 MESA_FORMAT_R_UINT16, 530 MESA_FORMAT_R_UINT32, 531 MESA_FORMAT_R_SINT8, 532 MESA_FORMAT_R_SINT16, 533 MESA_FORMAT_R_SINT32, 534 535 MESA_FORMAT_RG_UINT8, 536 MESA_FORMAT_RG_UINT16, 537 MESA_FORMAT_RG_UINT32, 538 MESA_FORMAT_RG_SINT8, 539 MESA_FORMAT_RG_SINT16, 540 MESA_FORMAT_RG_SINT32, 541 542 MESA_FORMAT_RGB_UINT8, 543 MESA_FORMAT_RGB_UINT16, 544 MESA_FORMAT_RGB_UINT32, 545 MESA_FORMAT_RGB_SINT8, 546 MESA_FORMAT_RGB_SINT16, 547 MESA_FORMAT_RGB_SINT32, 548 549 MESA_FORMAT_RGBA_UINT8, 550 MESA_FORMAT_RGBA_UINT16, 551 MESA_FORMAT_RGBA_UINT32, 552 MESA_FORMAT_RGBA_SINT8, 553 MESA_FORMAT_RGBA_SINT16, 554 MESA_FORMAT_RGBA_SINT32, 555 556 MESA_FORMAT_RGBX_UINT8, 557 MESA_FORMAT_RGBX_UINT16, 558 MESA_FORMAT_RGBX_UINT32, 559 MESA_FORMAT_RGBX_SINT8, 560 MESA_FORMAT_RGBX_SINT16, 561 MESA_FORMAT_RGBX_SINT32, 562 563 /* DXT compressed formats */ 564 MESA_FORMAT_RGB_DXT1, 565 MESA_FORMAT_RGBA_DXT1, 566 MESA_FORMAT_RGBA_DXT3, 567 MESA_FORMAT_RGBA_DXT5, 568 569 /* DXT sRGB compressed formats */ 570 MESA_FORMAT_SRGB_DXT1, 571 MESA_FORMAT_SRGBA_DXT1, 572 MESA_FORMAT_SRGBA_DXT3, 573 MESA_FORMAT_SRGBA_DXT5, 574 575 /* FXT1 compressed formats */ 576 MESA_FORMAT_RGB_FXT1, 577 MESA_FORMAT_RGBA_FXT1, 578 579 /* RGTC compressed formats */ 580 MESA_FORMAT_R_RGTC1_UNORM, 581 MESA_FORMAT_R_RGTC1_SNORM, 582 MESA_FORMAT_RG_RGTC2_UNORM, 583 MESA_FORMAT_RG_RGTC2_SNORM, 584 585 /* LATC1/2 compressed formats */ 586 MESA_FORMAT_L_LATC1_UNORM, 587 MESA_FORMAT_L_LATC1_SNORM, 588 MESA_FORMAT_LA_LATC2_UNORM, 589 MESA_FORMAT_LA_LATC2_SNORM, 590 591 /* ETC1/2 compressed formats */ 592 MESA_FORMAT_ETC1_RGB8, 593 MESA_FORMAT_ETC2_RGB8, 594 MESA_FORMAT_ETC2_SRGB8, 595 MESA_FORMAT_ETC2_RGBA8_EAC, 596 MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC, 597 MESA_FORMAT_ETC2_R11_EAC, 598 MESA_FORMAT_ETC2_RG11_EAC, 599 MESA_FORMAT_ETC2_SIGNED_R11_EAC, 600 MESA_FORMAT_ETC2_SIGNED_RG11_EAC, 601 MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1, 602 MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1, 603 604 /* BPTC compressed formats */ 605 MESA_FORMAT_BPTC_RGBA_UNORM, 606 MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM, 607 MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT, 608 MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT, 609 610 /* ASTC compressed formats */ 611 MESA_FORMAT_RGBA_ASTC_4x4, 612 MESA_FORMAT_RGBA_ASTC_5x4, 613 MESA_FORMAT_RGBA_ASTC_5x5, 614 MESA_FORMAT_RGBA_ASTC_6x5, 615 MESA_FORMAT_RGBA_ASTC_6x6, 616 MESA_FORMAT_RGBA_ASTC_8x5, 617 MESA_FORMAT_RGBA_ASTC_8x6, 618 MESA_FORMAT_RGBA_ASTC_8x8, 619 MESA_FORMAT_RGBA_ASTC_10x5, 620 MESA_FORMAT_RGBA_ASTC_10x6, 621 MESA_FORMAT_RGBA_ASTC_10x8, 622 MESA_FORMAT_RGBA_ASTC_10x10, 623 MESA_FORMAT_RGBA_ASTC_12x10, 624 MESA_FORMAT_RGBA_ASTC_12x12, 625 626 MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4, 627 MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4, 628 MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5, 629 MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5, 630 MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6, 631 MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5, 632 MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6, 633 MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8, 634 MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5, 635 MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6, 636 MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8, 637 MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10, 638 MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10, 639 MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12, 640 641 MESA_FORMAT_RGBA_ASTC_3x3x3, 642 MESA_FORMAT_RGBA_ASTC_4x3x3, 643 MESA_FORMAT_RGBA_ASTC_4x4x3, 644 MESA_FORMAT_RGBA_ASTC_4x4x4, 645 MESA_FORMAT_RGBA_ASTC_5x4x4, 646 MESA_FORMAT_RGBA_ASTC_5x5x4, 647 MESA_FORMAT_RGBA_ASTC_5x5x5, 648 MESA_FORMAT_RGBA_ASTC_6x5x5, 649 MESA_FORMAT_RGBA_ASTC_6x6x5, 650 MESA_FORMAT_RGBA_ASTC_6x6x6, 651 MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3, 652 MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3, 653 MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3, 654 MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4, 655 MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4, 656 MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4, 657 MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5, 658 MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5, 659 MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5, 660 MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6, 661 662 /* ATC compressed formats */ 663 MESA_FORMAT_ATC_RGB, 664 MESA_FORMAT_ATC_RGBA_EXPLICIT, 665 MESA_FORMAT_ATC_RGBA_INTERPOLATED, 666 667 MESA_FORMAT_COUNT 668} mesa_format; 669 670 671extern const char * 672_mesa_get_format_name(mesa_format format); 673 674extern GLint 675_mesa_get_format_bytes(mesa_format format); 676 677extern GLint 678_mesa_get_format_bits(mesa_format format, GLenum pname); 679 680extern GLuint 681_mesa_get_format_max_bits(mesa_format format); 682 683extern enum mesa_format_layout 684_mesa_get_format_layout(mesa_format format); 685 686extern GLenum 687_mesa_get_format_datatype(mesa_format format); 688 689extern GLenum 690_mesa_get_format_base_format(uint32_t format); 691 692extern void 693_mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh); 694 695extern void 696_mesa_get_format_block_size_3d(mesa_format format, GLuint *bw, 697 GLuint *bh, GLuint *bd); 698 699extern mesa_array_format 700_mesa_array_format_flip_channels(mesa_array_format format); 701 702extern void 703_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]); 704 705extern uint32_t 706_mesa_format_to_array_format(mesa_format format); 707 708extern mesa_format 709_mesa_format_from_array_format(uint32_t array_format); 710 711extern GLboolean 712_mesa_is_format_compressed(mesa_format format); 713 714extern GLboolean 715_mesa_is_format_packed_depth_stencil(mesa_format format); 716 717extern GLboolean 718_mesa_is_format_integer_color(mesa_format format); 719 720extern GLboolean 721_mesa_is_format_unsigned(mesa_format format); 722 723extern GLboolean 724_mesa_is_format_signed(mesa_format format); 725 726extern GLboolean 727_mesa_is_format_integer(mesa_format format); 728 729extern bool 730_mesa_is_format_etc2(mesa_format format); 731 732bool 733_mesa_is_format_astc_2d(mesa_format format); 734 735GLenum 736_mesa_is_format_color_format(mesa_format format); 737 738extern GLenum 739_mesa_get_format_color_encoding(mesa_format format); 740 741extern GLuint 742_mesa_format_image_size(mesa_format format, GLsizei width, 743 GLsizei height, GLsizei depth); 744 745extern uint64_t 746_mesa_format_image_size64(mesa_format format, GLsizei width, 747 GLsizei height, GLsizei depth); 748 749extern GLint 750_mesa_format_row_stride(mesa_format format, GLsizei width); 751 752extern void 753_mesa_uncompressed_format_to_type_and_comps(mesa_format format, 754 GLenum *datatype, GLuint *comps); 755 756extern void 757_mesa_test_formats(void); 758 759extern mesa_format 760_mesa_get_srgb_format_linear(mesa_format format); 761 762extern mesa_format 763_mesa_get_linear_format_srgb(mesa_format format); 764 765extern mesa_format 766_mesa_get_uncompressed_format(mesa_format format); 767 768extern GLuint 769_mesa_format_num_components(mesa_format format); 770 771extern bool 772_mesa_format_has_color_component(mesa_format format, int component); 773 774GLboolean 775_mesa_format_matches_format_and_type(mesa_format mesa_format, 776 GLenum format, GLenum type, 777 GLboolean swapBytes, GLenum *error); 778 779mesa_format 780_mesa_format_fallback_rgbx_to_rgba(mesa_format format); 781 782#ifdef __cplusplus 783} 784#endif 785 786#endif /* FORMATS_H */ 787