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