2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
32 * Information about texture formats.
38 /** text name for debugging */
42 * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
43 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
44 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
49 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
50 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
58 GLubyte LuminanceBits
;
59 GLubyte IntensityBits
;
65 * To describe compressed formats. If not compressed, Width=Height=1.
67 GLubyte BlockWidth
, BlockHeight
;
68 GLubyte BytesPerBlock
;
73 * Info about each format.
74 * These must be in the same order as the MESA_FORMAT_* enums so that
75 * we can do lookups without searching.
77 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
80 MESA_FORMAT_NONE
, /* Name */
81 "MESA_FORMAT_NONE", /* StrName */
82 GL_NONE
, /* BaseFormat */
83 GL_NONE
, /* DataType */
84 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
85 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
86 0, 0, 0 /* BlockWidth/Height,Bytes */
89 MESA_FORMAT_RGBA8888
, /* Name */
90 "MESA_FORMAT_RGBA8888", /* StrName */
91 GL_RGBA
, /* BaseFormat */
92 GL_UNSIGNED_NORMALIZED
, /* DataType */
93 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
94 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
95 1, 1, 4 /* BlockWidth/Height,Bytes */
98 MESA_FORMAT_RGBA8888_REV
, /* Name */
99 "MESA_FORMAT_RGBA8888_REV", /* StrName */
100 GL_RGBA
, /* BaseFormat */
101 GL_UNSIGNED_NORMALIZED
, /* DataType */
102 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
103 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
104 1, 1, 4 /* BlockWidth/Height,Bytes */
107 MESA_FORMAT_ARGB8888
, /* Name */
108 "MESA_FORMAT_ARGB8888", /* StrName */
109 GL_RGBA
, /* BaseFormat */
110 GL_UNSIGNED_NORMALIZED
, /* DataType */
111 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
112 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
113 1, 1, 4 /* BlockWidth/Height,Bytes */
116 MESA_FORMAT_ARGB8888_REV
, /* Name */
117 "MESA_FORMAT_ARGB8888_REV", /* StrName */
118 GL_RGBA
, /* BaseFormat */
119 GL_UNSIGNED_NORMALIZED
, /* DataType */
120 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
121 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
122 1, 1, 4 /* BlockWidth/Height,Bytes */
125 MESA_FORMAT_XRGB8888
, /* Name */
126 "MESA_FORMAT_XRGB8888", /* StrName */
127 GL_RGB
, /* BaseFormat */
128 GL_UNSIGNED_NORMALIZED
, /* DataType */
129 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
130 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
131 1, 1, 4 /* BlockWidth/Height,Bytes */
134 MESA_FORMAT_XRGB8888_REV
, /* Name */
135 "MESA_FORMAT_XRGB8888_REV", /* StrName */
136 GL_RGB
, /* BaseFormat */
137 GL_UNSIGNED_NORMALIZED
, /* DataType */
138 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
139 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
140 1, 1, 4 /* BlockWidth/Height,Bytes */
143 MESA_FORMAT_RGB888
, /* Name */
144 "MESA_FORMAT_RGB888", /* StrName */
145 GL_RGB
, /* BaseFormat */
146 GL_UNSIGNED_NORMALIZED
, /* DataType */
147 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
148 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
149 1, 1, 3 /* BlockWidth/Height,Bytes */
152 MESA_FORMAT_BGR888
, /* Name */
153 "MESA_FORMAT_BGR888", /* StrName */
154 GL_RGB
, /* BaseFormat */
155 GL_UNSIGNED_NORMALIZED
, /* DataType */
156 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
157 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
158 1, 1, 3 /* BlockWidth/Height,Bytes */
161 MESA_FORMAT_RGB565
, /* Name */
162 "MESA_FORMAT_RGB565", /* StrName */
163 GL_RGB
, /* BaseFormat */
164 GL_UNSIGNED_NORMALIZED
, /* DataType */
165 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
166 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
167 1, 1, 2 /* BlockWidth/Height,Bytes */
170 MESA_FORMAT_RGB565_REV
, /* Name */
171 "MESA_FORMAT_RGB565_REV", /* StrName */
172 GL_RGB
, /* BaseFormat */
173 GL_UNSIGNED_NORMALIZED
, /* DataType */
174 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
175 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
176 1, 1, 2 /* BlockWidth/Height,Bytes */
179 MESA_FORMAT_ARGB4444
, /* Name */
180 "MESA_FORMAT_ARGB4444", /* StrName */
181 GL_RGBA
, /* BaseFormat */
182 GL_UNSIGNED_NORMALIZED
, /* DataType */
183 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
184 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
185 1, 1, 2 /* BlockWidth/Height,Bytes */
188 MESA_FORMAT_ARGB4444_REV
, /* Name */
189 "MESA_FORMAT_ARGB4444_REV", /* StrName */
190 GL_RGBA
, /* BaseFormat */
191 GL_UNSIGNED_NORMALIZED
, /* DataType */
192 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
193 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
194 1, 1, 2 /* BlockWidth/Height,Bytes */
197 MESA_FORMAT_RGBA5551
, /* Name */
198 "MESA_FORMAT_RGBA5551", /* StrName */
199 GL_RGBA
, /* BaseFormat */
200 GL_UNSIGNED_NORMALIZED
, /* DataType */
201 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
202 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
203 1, 1, 2 /* BlockWidth/Height,Bytes */
206 MESA_FORMAT_ARGB1555
, /* Name */
207 "MESA_FORMAT_ARGB1555", /* StrName */
208 GL_RGBA
, /* BaseFormat */
209 GL_UNSIGNED_NORMALIZED
, /* DataType */
210 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
211 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
212 1, 1, 2 /* BlockWidth/Height,Bytes */
215 MESA_FORMAT_ARGB1555_REV
, /* Name */
216 "MESA_FORMAT_ARGB1555_REV", /* StrName */
217 GL_RGBA
, /* BaseFormat */
218 GL_UNSIGNED_NORMALIZED
, /* DataType */
219 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
220 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
221 1, 1, 2 /* BlockWidth/Height,Bytes */
224 MESA_FORMAT_AL88
, /* Name */
225 "MESA_FORMAT_AL88", /* StrName */
226 GL_LUMINANCE_ALPHA
, /* BaseFormat */
227 GL_UNSIGNED_NORMALIZED
, /* DataType */
228 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
229 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
230 1, 1, 2 /* BlockWidth/Height,Bytes */
233 MESA_FORMAT_AL88_REV
, /* Name */
234 "MESA_FORMAT_AL88_REV", /* StrName */
235 GL_LUMINANCE_ALPHA
, /* BaseFormat */
236 GL_UNSIGNED_NORMALIZED
, /* DataType */
237 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
238 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
239 1, 1, 2 /* BlockWidth/Height,Bytes */
242 MESA_FORMAT_AL1616
, /* Name */
243 "MESA_FORMAT_AL1616", /* StrName */
244 GL_LUMINANCE_ALPHA
, /* BaseFormat */
245 GL_UNSIGNED_NORMALIZED
, /* DataType */
246 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
247 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
248 1, 1, 4 /* BlockWidth/Height,Bytes */
251 MESA_FORMAT_AL1616_REV
, /* Name */
252 "MESA_FORMAT_AL1616_REV", /* StrName */
253 GL_LUMINANCE_ALPHA
, /* BaseFormat */
254 GL_UNSIGNED_NORMALIZED
, /* DataType */
255 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
256 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
257 1, 1, 4 /* BlockWidth/Height,Bytes */
260 MESA_FORMAT_RGB332
, /* Name */
261 "MESA_FORMAT_RGB332", /* StrName */
262 GL_RGB
, /* BaseFormat */
263 GL_UNSIGNED_NORMALIZED
, /* DataType */
264 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
265 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
266 1, 1, 1 /* BlockWidth/Height,Bytes */
269 MESA_FORMAT_A8
, /* Name */
270 "MESA_FORMAT_A8", /* StrName */
271 GL_ALPHA
, /* BaseFormat */
272 GL_UNSIGNED_NORMALIZED
, /* DataType */
273 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
274 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
275 1, 1, 1 /* BlockWidth/Height,Bytes */
278 MESA_FORMAT_L8
, /* Name */
279 "MESA_FORMAT_L8", /* StrName */
280 GL_LUMINANCE
, /* BaseFormat */
281 GL_UNSIGNED_NORMALIZED
, /* DataType */
282 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
283 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
284 1, 1, 1 /* BlockWidth/Height,Bytes */
287 MESA_FORMAT_I8
, /* Name */
288 "MESA_FORMAT_I8", /* StrName */
289 GL_INTENSITY
, /* BaseFormat */
290 GL_UNSIGNED_NORMALIZED
, /* DataType */
291 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
292 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
293 1, 1, 1 /* BlockWidth/Height,Bytes */
296 MESA_FORMAT_CI8
, /* Name */
297 "MESA_FORMAT_CI8", /* StrName */
298 GL_COLOR_INDEX
, /* BaseFormat */
299 GL_UNSIGNED_INT
, /* DataType */
300 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
301 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
302 1, 1, 1 /* BlockWidth/Height,Bytes */
305 MESA_FORMAT_YCBCR
, /* Name */
306 "MESA_FORMAT_YCBCR", /* StrName */
307 GL_YCBCR_MESA
, /* BaseFormat */
308 GL_UNSIGNED_NORMALIZED
, /* DataType */
309 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
310 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
311 1, 1, 2 /* BlockWidth/Height,Bytes */
314 MESA_FORMAT_YCBCR_REV
, /* Name */
315 "MESA_FORMAT_YCBCR_REV", /* StrName */
316 GL_YCBCR_MESA
, /* BaseFormat */
317 GL_UNSIGNED_NORMALIZED
, /* DataType */
318 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
319 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
320 1, 1, 2 /* BlockWidth/Height,Bytes */
323 MESA_FORMAT_Z24_S8
, /* Name */
324 "MESA_FORMAT_Z24_S8", /* StrName */
325 GL_DEPTH_STENCIL
, /* BaseFormat */
326 GL_UNSIGNED_INT
, /* DataType */
327 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
328 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
329 1, 1, 4 /* BlockWidth/Height,Bytes */
332 MESA_FORMAT_S8_Z24
, /* Name */
333 "MESA_FORMAT_S8_Z24", /* StrName */
334 GL_DEPTH_STENCIL
, /* BaseFormat */
335 GL_UNSIGNED_INT
, /* DataType */
336 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
337 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
338 1, 1, 4 /* BlockWidth/Height,Bytes */
341 MESA_FORMAT_Z16
, /* Name */
342 "MESA_FORMAT_Z16", /* StrName */
343 GL_DEPTH_COMPONENT
, /* BaseFormat */
344 GL_UNSIGNED_INT
, /* DataType */
345 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
346 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
347 1, 1, 2 /* BlockWidth/Height,Bytes */
350 MESA_FORMAT_X8_Z24
, /* Name */
351 "MESA_FORMAT_X8_Z24", /* StrName */
352 GL_DEPTH_COMPONENT
, /* BaseFormat */
353 GL_UNSIGNED_INT
, /* DataType */
354 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
355 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
356 1, 1, 4 /* BlockWidth/Height,Bytes */
359 MESA_FORMAT_Z24_X8
, /* Name */
360 "MESA_FORMAT_Z24_X8", /* StrName */
361 GL_DEPTH_COMPONENT
, /* BaseFormat */
362 GL_UNSIGNED_INT
, /* DataType */
363 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
364 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
365 1, 1, 4 /* BlockWidth/Height,Bytes */
368 MESA_FORMAT_Z32
, /* Name */
369 "MESA_FORMAT_Z32", /* StrName */
370 GL_DEPTH_COMPONENT
, /* BaseFormat */
371 GL_UNSIGNED_INT
, /* DataType */
372 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
373 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
374 1, 1, 4 /* BlockWidth/Height,Bytes */
377 MESA_FORMAT_S8
, /* Name */
378 "MESA_FORMAT_S8", /* StrName */
379 GL_STENCIL_INDEX
, /* BaseFormat */
380 GL_UNSIGNED_INT
, /* DataType */
381 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
382 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
383 1, 1, 1 /* BlockWidth/Height,Bytes */
389 GL_UNSIGNED_NORMALIZED
,
396 "MESA_FORMAT_SRGBA8",
398 GL_UNSIGNED_NORMALIZED
,
405 "MESA_FORMAT_SARGB8",
407 GL_UNSIGNED_NORMALIZED
,
416 GL_UNSIGNED_NORMALIZED
,
425 GL_UNSIGNED_NORMALIZED
,
431 MESA_FORMAT_SRGB_DXT1
, /* Name */
432 "MESA_FORMAT_SRGB_DXT1", /* StrName */
433 GL_RGB
, /* BaseFormat */
434 GL_UNSIGNED_NORMALIZED
, /* DataType */
435 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
436 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
437 4, 4, 8 /* 8 bytes per 4x4 block */
440 MESA_FORMAT_SRGBA_DXT1
,
441 "MESA_FORMAT_SRGBA_DXT1",
443 GL_UNSIGNED_NORMALIZED
,
446 4, 4, 8 /* 8 bytes per 4x4 block */
449 MESA_FORMAT_SRGBA_DXT3
,
450 "MESA_FORMAT_SRGBA_DXT3",
452 GL_UNSIGNED_NORMALIZED
,
455 4, 4, 16 /* 16 bytes per 4x4 block */
458 MESA_FORMAT_SRGBA_DXT5
,
459 "MESA_FORMAT_SRGBA_DXT5",
461 GL_UNSIGNED_NORMALIZED
,
464 4, 4, 16 /* 16 bytes per 4x4 block */
468 MESA_FORMAT_RGB_FXT1
,
469 "MESA_FORMAT_RGB_FXT1",
471 GL_UNSIGNED_NORMALIZED
,
472 4, 4, 4, 0, /* approx Red/Green/BlueBits */
474 8, 4, 16 /* 16 bytes per 8x4 block */
477 MESA_FORMAT_RGBA_FXT1
,
478 "MESA_FORMAT_RGBA_FXT1",
480 GL_UNSIGNED_NORMALIZED
,
481 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
483 8, 4, 16 /* 16 bytes per 8x4 block */
487 MESA_FORMAT_RGB_DXT1
, /* Name */
488 "MESA_FORMAT_RGB_DXT1", /* StrName */
489 GL_RGB
, /* BaseFormat */
490 GL_UNSIGNED_NORMALIZED
, /* DataType */
491 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
492 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
493 4, 4, 8 /* 8 bytes per 4x4 block */
496 MESA_FORMAT_RGBA_DXT1
,
497 "MESA_FORMAT_RGBA_DXT1",
499 GL_UNSIGNED_NORMALIZED
,
502 4, 4, 8 /* 8 bytes per 4x4 block */
505 MESA_FORMAT_RGBA_DXT3
,
506 "MESA_FORMAT_RGBA_DXT3",
508 GL_UNSIGNED_NORMALIZED
,
511 4, 4, 16 /* 16 bytes per 4x4 block */
514 MESA_FORMAT_RGBA_DXT5
,
515 "MESA_FORMAT_RGBA_DXT5",
517 GL_UNSIGNED_NORMALIZED
,
520 4, 4, 16 /* 16 bytes per 4x4 block */
523 MESA_FORMAT_RGBA_FLOAT32
,
524 "MESA_FORMAT_RGBA_FLOAT32",
532 MESA_FORMAT_RGBA_FLOAT16
,
533 "MESA_FORMAT_RGBA_FLOAT16",
541 MESA_FORMAT_RGB_FLOAT32
,
542 "MESA_FORMAT_RGB_FLOAT32",
550 MESA_FORMAT_RGB_FLOAT16
,
551 "MESA_FORMAT_RGB_FLOAT16",
559 MESA_FORMAT_ALPHA_FLOAT32
,
560 "MESA_FORMAT_ALPHA_FLOAT32",
568 MESA_FORMAT_ALPHA_FLOAT16
,
569 "MESA_FORMAT_ALPHA_FLOAT16",
577 MESA_FORMAT_LUMINANCE_FLOAT32
,
578 "MESA_FORMAT_LUMINANCE_FLOAT32",
586 MESA_FORMAT_LUMINANCE_FLOAT16
,
587 "MESA_FORMAT_LUMINANCE_FLOAT16",
595 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
596 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
604 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
605 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
613 MESA_FORMAT_INTENSITY_FLOAT32
,
614 "MESA_FORMAT_INTENSITY_FLOAT32",
622 MESA_FORMAT_INTENSITY_FLOAT16
,
623 "MESA_FORMAT_INTENSITY_FLOAT16",
631 /* unnormalized signed int formats */
633 MESA_FORMAT_RGBA_INT8
,
634 "MESA_FORMAT_RGBA_INT8",
642 MESA_FORMAT_RGBA_INT16
,
643 "MESA_FORMAT_RGBA_INT16",
651 MESA_FORMAT_RGBA_INT32
,
652 "MESA_FORMAT_RGBA_INT32",
660 /* unnormalized unsigned int formats */
662 MESA_FORMAT_RGBA_UINT8
,
663 "MESA_FORMAT_RGBA_UINT8",
671 MESA_FORMAT_RGBA_UINT16
,
672 "MESA_FORMAT_RGBA_UINT16",
680 MESA_FORMAT_RGBA_UINT32
,
681 "MESA_FORMAT_RGBA_UINT32",
694 GL_SIGNED_NORMALIZED
,
700 /* Signed 8 bits / channel */
702 MESA_FORMAT_SIGNED_R8
, /* Name */
703 "MESA_FORMAT_SIGNED_R8", /* StrName */
704 GL_RGBA
, /* BaseFormat */
705 GL_SIGNED_NORMALIZED
, /* DataType */
706 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
707 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
708 1, 1, 1 /* BlockWidth/Height,Bytes */
711 MESA_FORMAT_SIGNED_RG88
,
712 "MESA_FORMAT_SIGNED_RG88",
714 GL_SIGNED_NORMALIZED
,
720 MESA_FORMAT_SIGNED_RGBX8888
,
721 "MESA_FORMAT_SIGNED_RGBX8888",
723 GL_SIGNED_NORMALIZED
,
726 1, 1, 4 /* 4 bpp, but no alpha */
729 MESA_FORMAT_SIGNED_RGBA8888
,
730 "MESA_FORMAT_SIGNED_RGBA8888",
732 GL_SIGNED_NORMALIZED
,
738 MESA_FORMAT_SIGNED_RGBA8888_REV
,
739 "MESA_FORMAT_SIGNED_RGBA8888_REV",
741 GL_SIGNED_NORMALIZED
,
747 /* Signed 16 bits / channel */
749 MESA_FORMAT_SIGNED_R_16
,
750 "MESA_FORMAT_SIGNED_R_16",
752 GL_SIGNED_NORMALIZED
,
758 MESA_FORMAT_SIGNED_RG_16
,
759 "MESA_FORMAT_SIGNED_RG_16",
761 GL_SIGNED_NORMALIZED
,
767 MESA_FORMAT_SIGNED_RGB_16
,
768 "MESA_FORMAT_SIGNED_RGB_16",
770 GL_SIGNED_NORMALIZED
,
776 MESA_FORMAT_SIGNED_RGBA_16
,
777 "MESA_FORMAT_SIGNED_RGBA_16",
779 GL_SIGNED_NORMALIZED
,
786 "MESA_FORMAT_RGBA_16",
788 GL_UNSIGNED_NORMALIZED
,
797 static const struct gl_format_info
*
798 _mesa_get_format_info(gl_format format
)
800 const struct gl_format_info
*info
= &format_info
[format
];
801 assert(info
->Name
== format
);
806 /** Return string name of format (for debugging) */
808 _mesa_get_format_name(gl_format format
)
810 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
811 ASSERT(info
->BytesPerBlock
);
812 return info
->StrName
;
818 * Return bytes needed to store a block of pixels in the given format.
819 * Normally, a block is 1x1 (a single pixel). But for compressed formats
820 * a block may be 4x4 or 8x4, etc.
823 _mesa_get_format_bytes(gl_format format
)
825 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
826 ASSERT(info
->BytesPerBlock
);
827 return info
->BytesPerBlock
;
832 * Return bits per component for the given format.
833 * \param format one of MESA_FORMAT_x
834 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
837 _mesa_get_format_bits(gl_format format
, GLenum pname
)
839 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
843 case GL_TEXTURE_RED_SIZE
:
844 case GL_RENDERBUFFER_RED_SIZE_EXT
:
845 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
846 return info
->RedBits
;
848 case GL_TEXTURE_GREEN_SIZE
:
849 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
850 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
851 return info
->GreenBits
;
853 case GL_TEXTURE_BLUE_SIZE
:
854 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
855 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
856 return info
->BlueBits
;
858 case GL_TEXTURE_ALPHA_SIZE
:
859 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
860 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
861 return info
->AlphaBits
;
862 case GL_TEXTURE_INTENSITY_SIZE
:
863 return info
->IntensityBits
;
864 case GL_TEXTURE_LUMINANCE_SIZE
:
865 return info
->LuminanceBits
;
867 case GL_TEXTURE_INDEX_SIZE_EXT
:
868 return info
->IndexBits
;
870 case GL_TEXTURE_DEPTH_SIZE_ARB
:
871 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
872 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
873 return info
->DepthBits
;
874 case GL_STENCIL_BITS
:
875 case GL_TEXTURE_STENCIL_SIZE_EXT
:
876 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
877 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
878 return info
->StencilBits
;
880 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
887 * Return the data type (or more specifically, the data representation)
888 * for the given format.
889 * The return value will be one of:
890 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
891 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
892 * GL_UNSIGNED_INT = an ordinary unsigned integer
893 * GL_FLOAT = an ordinary float
896 _mesa_get_format_datatype(gl_format format
)
898 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
899 return info
->DataType
;
904 * Return the basic format for the given type. The result will be
905 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
906 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
907 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
910 _mesa_get_format_base_format(gl_format format
)
912 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
913 return info
->BaseFormat
;
918 * Return the block size (in pixels) for the given format. Normally
919 * the block size is 1x1. But compressed formats will have block sizes
920 * of 4x4 or 8x4 pixels, etc.
921 * \param bw returns block width in pixels
922 * \param bh returns block height in pixels
925 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
927 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
928 *bw
= info
->BlockWidth
;
929 *bh
= info
->BlockHeight
;
933 /** Is the given format a compressed format? */
935 _mesa_is_format_compressed(gl_format format
)
937 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
938 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
943 * Determine if the given format represents a packed depth/stencil buffer.
946 _mesa_is_format_packed_depth_stencil(gl_format format
)
948 if (format
== MESA_FORMAT_Z24_S8
949 || format
== MESA_FORMAT_Z24_X8
950 || format
== MESA_FORMAT_S8_Z24
951 || format
== MESA_FORMAT_X8_Z24
)
959 * Return color encoding for given format.
960 * \return GL_LINEAR or GL_SRGB
963 _mesa_get_format_color_encoding(gl_format format
)
965 /* XXX this info should be encoded in gl_format_info */
967 case MESA_FORMAT_SRGB8
:
968 case MESA_FORMAT_SRGBA8
:
969 case MESA_FORMAT_SARGB8
:
970 case MESA_FORMAT_SL8
:
971 case MESA_FORMAT_SLA8
:
972 case MESA_FORMAT_SRGB_DXT1
:
973 case MESA_FORMAT_SRGBA_DXT1
:
974 case MESA_FORMAT_SRGBA_DXT3
:
975 case MESA_FORMAT_SRGBA_DXT5
:
984 * Return number of bytes needed to store an image of the given size
985 * in the given format.
988 _mesa_format_image_size(gl_format format
, GLsizei width
,
989 GLsizei height
, GLsizei depth
)
991 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
992 /* Strictly speaking, a conditional isn't needed here */
993 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
994 /* compressed format */
995 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
996 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
997 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
998 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1002 /* non-compressed */
1003 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
1011 _mesa_format_row_stride(gl_format format
, GLsizei width
)
1013 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1014 /* Strictly speaking, a conditional isn't needed here */
1015 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1016 /* compressed format */
1017 const GLuint bw
= info
->BlockWidth
;
1018 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1019 const GLint stride
= wblocks
* info
->BytesPerBlock
;
1023 const GLint stride
= width
* info
->BytesPerBlock
;
1031 * Do sanity checking of the format info table.
1034 _mesa_test_formats(void)
1038 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
1040 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
1041 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
1044 assert(info
->Name
== i
);
1046 if (info
->Name
== MESA_FORMAT_NONE
)
1049 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
1050 if (info
->RedBits
> 0) {
1051 GLuint t
= info
->RedBits
+ info
->GreenBits
1052 + info
->BlueBits
+ info
->AlphaBits
;
1053 assert(t
/ 8 == info
->BytesPerBlock
);
1058 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
1059 info
->DataType
== GL_SIGNED_NORMALIZED
||
1060 info
->DataType
== GL_UNSIGNED_INT
||
1061 info
->DataType
== GL_FLOAT
);
1063 if (info
->BaseFormat
== GL_RGB
) {
1064 assert(info
->RedBits
> 0);
1065 assert(info
->GreenBits
> 0);
1066 assert(info
->BlueBits
> 0);
1067 assert(info
->AlphaBits
== 0);
1068 assert(info
->LuminanceBits
== 0);
1069 assert(info
->IntensityBits
== 0);
1071 else if (info
->BaseFormat
== GL_RGBA
) {
1072 assert(info
->RedBits
> 0);
1073 assert(info
->GreenBits
> 0);
1074 assert(info
->BlueBits
> 0);
1075 assert(info
->AlphaBits
> 0);
1076 assert(info
->LuminanceBits
== 0);
1077 assert(info
->IntensityBits
== 0);
1079 else if (info
->BaseFormat
== GL_LUMINANCE
) {
1080 assert(info
->RedBits
== 0);
1081 assert(info
->GreenBits
== 0);
1082 assert(info
->BlueBits
== 0);
1083 assert(info
->AlphaBits
== 0);
1084 assert(info
->LuminanceBits
> 0);
1085 assert(info
->IntensityBits
== 0);
1087 else if (info
->BaseFormat
== GL_INTENSITY
) {
1088 assert(info
->RedBits
== 0);
1089 assert(info
->GreenBits
== 0);
1090 assert(info
->BlueBits
== 0);
1091 assert(info
->AlphaBits
== 0);
1092 assert(info
->LuminanceBits
== 0);
1093 assert(info
->IntensityBits
> 0);
1102 * Return datatype and number of components per texel for the given gl_format.
1103 * Only used for mipmap generation code.
1106 _mesa_format_to_type_and_comps(gl_format format
,
1107 GLenum
*datatype
, GLuint
*comps
)
1110 case MESA_FORMAT_RGBA8888
:
1111 case MESA_FORMAT_RGBA8888_REV
:
1112 case MESA_FORMAT_ARGB8888
:
1113 case MESA_FORMAT_ARGB8888_REV
:
1114 case MESA_FORMAT_XRGB8888
:
1115 *datatype
= GL_UNSIGNED_BYTE
;
1118 case MESA_FORMAT_RGB888
:
1119 case MESA_FORMAT_BGR888
:
1120 *datatype
= GL_UNSIGNED_BYTE
;
1123 case MESA_FORMAT_RGB565
:
1124 case MESA_FORMAT_RGB565_REV
:
1125 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1129 case MESA_FORMAT_ARGB4444
:
1130 case MESA_FORMAT_ARGB4444_REV
:
1131 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1135 case MESA_FORMAT_ARGB1555
:
1136 case MESA_FORMAT_ARGB1555_REV
:
1137 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1141 case MESA_FORMAT_AL88
:
1142 case MESA_FORMAT_AL88_REV
:
1143 *datatype
= GL_UNSIGNED_BYTE
;
1147 case MESA_FORMAT_AL1616
:
1148 case MESA_FORMAT_AL1616_REV
:
1149 *datatype
= GL_UNSIGNED_SHORT
;
1153 case MESA_FORMAT_RGB332
:
1154 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1158 case MESA_FORMAT_A8
:
1159 case MESA_FORMAT_L8
:
1160 case MESA_FORMAT_I8
:
1161 case MESA_FORMAT_CI8
:
1162 *datatype
= GL_UNSIGNED_BYTE
;
1166 case MESA_FORMAT_YCBCR
:
1167 case MESA_FORMAT_YCBCR_REV
:
1168 *datatype
= GL_UNSIGNED_SHORT
;
1172 case MESA_FORMAT_Z24_S8
:
1173 *datatype
= GL_UNSIGNED_INT
;
1174 *comps
= 1; /* XXX OK? */
1177 case MESA_FORMAT_S8_Z24
:
1178 *datatype
= GL_UNSIGNED_INT
;
1179 *comps
= 1; /* XXX OK? */
1182 case MESA_FORMAT_Z16
:
1183 *datatype
= GL_UNSIGNED_SHORT
;
1187 case MESA_FORMAT_X8_Z24
:
1188 *datatype
= GL_UNSIGNED_INT
;
1192 case MESA_FORMAT_Z24_X8
:
1193 *datatype
= GL_UNSIGNED_INT
;
1197 case MESA_FORMAT_Z32
:
1198 *datatype
= GL_UNSIGNED_INT
;
1202 case MESA_FORMAT_DUDV8
:
1203 *datatype
= GL_BYTE
;
1207 case MESA_FORMAT_SIGNED_RGBA8888
:
1208 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1209 *datatype
= GL_BYTE
;
1213 case MESA_FORMAT_SIGNED_R_16
:
1214 *datatype
= GL_SHORT
;
1217 case MESA_FORMAT_SIGNED_RG_16
:
1218 *datatype
= GL_SHORT
;
1221 case MESA_FORMAT_SIGNED_RGB_16
:
1222 *datatype
= GL_SHORT
;
1225 case MESA_FORMAT_SIGNED_RGBA_16
:
1226 *datatype
= GL_SHORT
;
1230 #if FEATURE_EXT_texture_sRGB
1231 case MESA_FORMAT_SRGB8
:
1232 *datatype
= GL_UNSIGNED_BYTE
;
1235 case MESA_FORMAT_SRGBA8
:
1236 case MESA_FORMAT_SARGB8
:
1237 *datatype
= GL_UNSIGNED_BYTE
;
1240 case MESA_FORMAT_SL8
:
1241 *datatype
= GL_UNSIGNED_BYTE
;
1244 case MESA_FORMAT_SLA8
:
1245 *datatype
= GL_UNSIGNED_BYTE
;
1250 #if FEATURE_texture_fxt1
1251 case MESA_FORMAT_RGB_FXT1
:
1252 case MESA_FORMAT_RGBA_FXT1
:
1254 #if FEATURE_texture_s3tc
1255 case MESA_FORMAT_RGB_DXT1
:
1256 case MESA_FORMAT_RGBA_DXT1
:
1257 case MESA_FORMAT_RGBA_DXT3
:
1258 case MESA_FORMAT_RGBA_DXT5
:
1259 #if FEATURE_EXT_texture_sRGB
1260 case MESA_FORMAT_SRGB_DXT1
:
1261 case MESA_FORMAT_SRGBA_DXT1
:
1262 case MESA_FORMAT_SRGBA_DXT3
:
1263 case MESA_FORMAT_SRGBA_DXT5
:
1265 /* XXX generate error instead? */
1266 *datatype
= GL_UNSIGNED_BYTE
;
1271 case MESA_FORMAT_RGBA_FLOAT32
:
1272 *datatype
= GL_FLOAT
;
1275 case MESA_FORMAT_RGBA_FLOAT16
:
1276 *datatype
= GL_HALF_FLOAT_ARB
;
1279 case MESA_FORMAT_RGB_FLOAT32
:
1280 *datatype
= GL_FLOAT
;
1283 case MESA_FORMAT_RGB_FLOAT16
:
1284 *datatype
= GL_HALF_FLOAT_ARB
;
1287 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1288 *datatype
= GL_FLOAT
;
1291 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1292 *datatype
= GL_HALF_FLOAT_ARB
;
1295 case MESA_FORMAT_ALPHA_FLOAT32
:
1296 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1297 case MESA_FORMAT_INTENSITY_FLOAT32
:
1298 *datatype
= GL_FLOAT
;
1301 case MESA_FORMAT_ALPHA_FLOAT16
:
1302 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1303 case MESA_FORMAT_INTENSITY_FLOAT16
:
1304 *datatype
= GL_HALF_FLOAT_ARB
;
1308 case MESA_FORMAT_RGBA_INT8
:
1309 *datatype
= GL_BYTE
;
1312 case MESA_FORMAT_RGBA_INT16
:
1313 *datatype
= GL_SHORT
;
1316 case MESA_FORMAT_RGBA_INT32
:
1322 * \name Non-normalized unsigned integer formats.
1324 case MESA_FORMAT_RGBA_UINT8
:
1325 *datatype
= GL_UNSIGNED_BYTE
;
1328 case MESA_FORMAT_RGBA_UINT16
:
1329 *datatype
= GL_UNSIGNED_SHORT
;
1332 case MESA_FORMAT_RGBA_UINT32
:
1333 *datatype
= GL_UNSIGNED_INT
;
1339 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");