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.
29 #include "mfeatures.h"
33 * Information about texture formats.
39 /** text name for debugging */
43 * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
44 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
45 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
50 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
51 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
59 GLubyte LuminanceBits
;
60 GLubyte IntensityBits
;
66 * To describe compressed formats. If not compressed, Width=Height=1.
68 GLubyte BlockWidth
, BlockHeight
;
69 GLubyte BytesPerBlock
;
74 * Info about each format.
75 * These must be in the same order as the MESA_FORMAT_* enums so that
76 * we can do lookups without searching.
78 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
81 MESA_FORMAT_NONE
, /* Name */
82 "MESA_FORMAT_NONE", /* StrName */
83 GL_NONE
, /* BaseFormat */
84 GL_NONE
, /* DataType */
85 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
86 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
87 0, 0, 0 /* BlockWidth/Height,Bytes */
90 MESA_FORMAT_RGBA8888
, /* Name */
91 "MESA_FORMAT_RGBA8888", /* StrName */
92 GL_RGBA
, /* BaseFormat */
93 GL_UNSIGNED_NORMALIZED
, /* DataType */
94 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
95 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
96 1, 1, 4 /* BlockWidth/Height,Bytes */
99 MESA_FORMAT_RGBA8888_REV
, /* Name */
100 "MESA_FORMAT_RGBA8888_REV", /* StrName */
101 GL_RGBA
, /* BaseFormat */
102 GL_UNSIGNED_NORMALIZED
, /* DataType */
103 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
104 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
105 1, 1, 4 /* BlockWidth/Height,Bytes */
108 MESA_FORMAT_ARGB8888
, /* Name */
109 "MESA_FORMAT_ARGB8888", /* StrName */
110 GL_RGBA
, /* BaseFormat */
111 GL_UNSIGNED_NORMALIZED
, /* DataType */
112 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
113 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
114 1, 1, 4 /* BlockWidth/Height,Bytes */
117 MESA_FORMAT_ARGB8888_REV
, /* Name */
118 "MESA_FORMAT_ARGB8888_REV", /* StrName */
119 GL_RGBA
, /* BaseFormat */
120 GL_UNSIGNED_NORMALIZED
, /* DataType */
121 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
122 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
123 1, 1, 4 /* BlockWidth/Height,Bytes */
126 MESA_FORMAT_XRGB8888
, /* Name */
127 "MESA_FORMAT_XRGB8888", /* StrName */
128 GL_RGB
, /* BaseFormat */
129 GL_UNSIGNED_NORMALIZED
, /* DataType */
130 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
131 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
132 1, 1, 4 /* BlockWidth/Height,Bytes */
135 MESA_FORMAT_XRGB8888_REV
, /* Name */
136 "MESA_FORMAT_XRGB8888_REV", /* StrName */
137 GL_RGB
, /* BaseFormat */
138 GL_UNSIGNED_NORMALIZED
, /* DataType */
139 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
140 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
141 1, 1, 4 /* BlockWidth/Height,Bytes */
144 MESA_FORMAT_RGB888
, /* Name */
145 "MESA_FORMAT_RGB888", /* StrName */
146 GL_RGB
, /* BaseFormat */
147 GL_UNSIGNED_NORMALIZED
, /* DataType */
148 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
149 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
150 1, 1, 3 /* BlockWidth/Height,Bytes */
153 MESA_FORMAT_BGR888
, /* Name */
154 "MESA_FORMAT_BGR888", /* StrName */
155 GL_RGB
, /* BaseFormat */
156 GL_UNSIGNED_NORMALIZED
, /* DataType */
157 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
158 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
159 1, 1, 3 /* BlockWidth/Height,Bytes */
162 MESA_FORMAT_RGB565
, /* Name */
163 "MESA_FORMAT_RGB565", /* StrName */
164 GL_RGB
, /* BaseFormat */
165 GL_UNSIGNED_NORMALIZED
, /* DataType */
166 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
167 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
168 1, 1, 2 /* BlockWidth/Height,Bytes */
171 MESA_FORMAT_RGB565_REV
, /* Name */
172 "MESA_FORMAT_RGB565_REV", /* StrName */
173 GL_RGB
, /* BaseFormat */
174 GL_UNSIGNED_NORMALIZED
, /* DataType */
175 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
176 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
177 1, 1, 2 /* BlockWidth/Height,Bytes */
180 MESA_FORMAT_ARGB4444
, /* Name */
181 "MESA_FORMAT_ARGB4444", /* StrName */
182 GL_RGBA
, /* BaseFormat */
183 GL_UNSIGNED_NORMALIZED
, /* DataType */
184 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
185 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
186 1, 1, 2 /* BlockWidth/Height,Bytes */
189 MESA_FORMAT_ARGB4444_REV
, /* Name */
190 "MESA_FORMAT_ARGB4444_REV", /* StrName */
191 GL_RGBA
, /* BaseFormat */
192 GL_UNSIGNED_NORMALIZED
, /* DataType */
193 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
194 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
195 1, 1, 2 /* BlockWidth/Height,Bytes */
198 MESA_FORMAT_RGBA5551
, /* Name */
199 "MESA_FORMAT_RGBA5551", /* StrName */
200 GL_RGBA
, /* BaseFormat */
201 GL_UNSIGNED_NORMALIZED
, /* DataType */
202 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
203 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
204 1, 1, 2 /* BlockWidth/Height,Bytes */
207 MESA_FORMAT_ARGB1555
, /* Name */
208 "MESA_FORMAT_ARGB1555", /* StrName */
209 GL_RGBA
, /* BaseFormat */
210 GL_UNSIGNED_NORMALIZED
, /* DataType */
211 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
212 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
213 1, 1, 2 /* BlockWidth/Height,Bytes */
216 MESA_FORMAT_ARGB1555_REV
, /* Name */
217 "MESA_FORMAT_ARGB1555_REV", /* StrName */
218 GL_RGBA
, /* BaseFormat */
219 GL_UNSIGNED_NORMALIZED
, /* DataType */
220 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
221 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
222 1, 1, 2 /* BlockWidth/Height,Bytes */
225 MESA_FORMAT_AL88
, /* Name */
226 "MESA_FORMAT_AL88", /* StrName */
227 GL_LUMINANCE_ALPHA
, /* BaseFormat */
228 GL_UNSIGNED_NORMALIZED
, /* DataType */
229 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
230 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
231 1, 1, 2 /* BlockWidth/Height,Bytes */
234 MESA_FORMAT_AL88_REV
, /* Name */
235 "MESA_FORMAT_AL88_REV", /* StrName */
236 GL_LUMINANCE_ALPHA
, /* BaseFormat */
237 GL_UNSIGNED_NORMALIZED
, /* DataType */
238 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
239 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
240 1, 1, 2 /* BlockWidth/Height,Bytes */
243 MESA_FORMAT_AL1616
, /* Name */
244 "MESA_FORMAT_AL1616", /* StrName */
245 GL_LUMINANCE_ALPHA
, /* BaseFormat */
246 GL_UNSIGNED_NORMALIZED
, /* DataType */
247 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
248 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
249 1, 1, 4 /* BlockWidth/Height,Bytes */
252 MESA_FORMAT_AL1616_REV
, /* Name */
253 "MESA_FORMAT_AL1616_REV", /* StrName */
254 GL_LUMINANCE_ALPHA
, /* BaseFormat */
255 GL_UNSIGNED_NORMALIZED
, /* DataType */
256 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
257 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
258 1, 1, 4 /* BlockWidth/Height,Bytes */
261 MESA_FORMAT_RGB332
, /* Name */
262 "MESA_FORMAT_RGB332", /* StrName */
263 GL_RGB
, /* BaseFormat */
264 GL_UNSIGNED_NORMALIZED
, /* DataType */
265 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
266 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
267 1, 1, 1 /* BlockWidth/Height,Bytes */
270 MESA_FORMAT_A8
, /* Name */
271 "MESA_FORMAT_A8", /* StrName */
272 GL_ALPHA
, /* BaseFormat */
273 GL_UNSIGNED_NORMALIZED
, /* DataType */
274 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
275 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
276 1, 1, 1 /* BlockWidth/Height,Bytes */
279 MESA_FORMAT_L8
, /* Name */
280 "MESA_FORMAT_L8", /* StrName */
281 GL_LUMINANCE
, /* BaseFormat */
282 GL_UNSIGNED_NORMALIZED
, /* DataType */
283 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
284 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
285 1, 1, 1 /* BlockWidth/Height,Bytes */
288 MESA_FORMAT_I8
, /* Name */
289 "MESA_FORMAT_I8", /* StrName */
290 GL_INTENSITY
, /* BaseFormat */
291 GL_UNSIGNED_NORMALIZED
, /* DataType */
292 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
293 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
294 1, 1, 1 /* BlockWidth/Height,Bytes */
297 MESA_FORMAT_CI8
, /* Name */
298 "MESA_FORMAT_CI8", /* StrName */
299 GL_COLOR_INDEX
, /* BaseFormat */
300 GL_UNSIGNED_INT
, /* DataType */
301 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
302 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
303 1, 1, 1 /* BlockWidth/Height,Bytes */
306 MESA_FORMAT_YCBCR
, /* Name */
307 "MESA_FORMAT_YCBCR", /* StrName */
308 GL_YCBCR_MESA
, /* BaseFormat */
309 GL_UNSIGNED_NORMALIZED
, /* DataType */
310 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
311 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
312 1, 1, 2 /* BlockWidth/Height,Bytes */
315 MESA_FORMAT_YCBCR_REV
, /* Name */
316 "MESA_FORMAT_YCBCR_REV", /* StrName */
317 GL_YCBCR_MESA
, /* BaseFormat */
318 GL_UNSIGNED_NORMALIZED
, /* DataType */
319 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
320 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
321 1, 1, 2 /* BlockWidth/Height,Bytes */
327 GL_UNSIGNED_NORMALIZED
,
336 GL_UNSIGNED_NORMALIZED
,
342 MESA_FORMAT_RG88_REV
,
343 "MESA_FORMAT_RG88_REV",
345 GL_UNSIGNED_NORMALIZED
,
354 GL_UNSIGNED_NORMALIZED
,
361 "MESA_FORMAT_RG1616",
363 GL_UNSIGNED_NORMALIZED
,
369 MESA_FORMAT_RG1616_REV
,
370 "MESA_FORMAT_RG1616_REV",
372 GL_UNSIGNED_NORMALIZED
,
378 MESA_FORMAT_Z24_S8
, /* Name */
379 "MESA_FORMAT_Z24_S8", /* StrName */
380 GL_DEPTH_STENCIL
, /* BaseFormat */
381 GL_UNSIGNED_INT
, /* DataType */
382 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
383 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
384 1, 1, 4 /* BlockWidth/Height,Bytes */
387 MESA_FORMAT_S8_Z24
, /* Name */
388 "MESA_FORMAT_S8_Z24", /* StrName */
389 GL_DEPTH_STENCIL
, /* BaseFormat */
390 GL_UNSIGNED_INT
, /* DataType */
391 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
392 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
393 1, 1, 4 /* BlockWidth/Height,Bytes */
396 MESA_FORMAT_Z16
, /* Name */
397 "MESA_FORMAT_Z16", /* StrName */
398 GL_DEPTH_COMPONENT
, /* BaseFormat */
399 GL_UNSIGNED_INT
, /* DataType */
400 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
401 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
402 1, 1, 2 /* BlockWidth/Height,Bytes */
405 MESA_FORMAT_X8_Z24
, /* Name */
406 "MESA_FORMAT_X8_Z24", /* StrName */
407 GL_DEPTH_COMPONENT
, /* BaseFormat */
408 GL_UNSIGNED_INT
, /* DataType */
409 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
410 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
411 1, 1, 4 /* BlockWidth/Height,Bytes */
414 MESA_FORMAT_Z24_X8
, /* Name */
415 "MESA_FORMAT_Z24_X8", /* StrName */
416 GL_DEPTH_COMPONENT
, /* BaseFormat */
417 GL_UNSIGNED_INT
, /* DataType */
418 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
419 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
420 1, 1, 4 /* BlockWidth/Height,Bytes */
423 MESA_FORMAT_Z32
, /* Name */
424 "MESA_FORMAT_Z32", /* StrName */
425 GL_DEPTH_COMPONENT
, /* BaseFormat */
426 GL_UNSIGNED_INT
, /* DataType */
427 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
428 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
429 1, 1, 4 /* BlockWidth/Height,Bytes */
432 MESA_FORMAT_S8
, /* Name */
433 "MESA_FORMAT_S8", /* StrName */
434 GL_STENCIL_INDEX
, /* BaseFormat */
435 GL_UNSIGNED_INT
, /* DataType */
436 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
437 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
438 1, 1, 1 /* BlockWidth/Height,Bytes */
444 GL_UNSIGNED_NORMALIZED
,
451 "MESA_FORMAT_SRGBA8",
453 GL_UNSIGNED_NORMALIZED
,
460 "MESA_FORMAT_SARGB8",
462 GL_UNSIGNED_NORMALIZED
,
471 GL_UNSIGNED_NORMALIZED
,
480 GL_UNSIGNED_NORMALIZED
,
486 MESA_FORMAT_SRGB_DXT1
, /* Name */
487 "MESA_FORMAT_SRGB_DXT1", /* StrName */
488 GL_RGB
, /* BaseFormat */
489 GL_UNSIGNED_NORMALIZED
, /* DataType */
490 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
491 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
492 4, 4, 8 /* 8 bytes per 4x4 block */
495 MESA_FORMAT_SRGBA_DXT1
,
496 "MESA_FORMAT_SRGBA_DXT1",
498 GL_UNSIGNED_NORMALIZED
,
501 4, 4, 8 /* 8 bytes per 4x4 block */
504 MESA_FORMAT_SRGBA_DXT3
,
505 "MESA_FORMAT_SRGBA_DXT3",
507 GL_UNSIGNED_NORMALIZED
,
510 4, 4, 16 /* 16 bytes per 4x4 block */
513 MESA_FORMAT_SRGBA_DXT5
,
514 "MESA_FORMAT_SRGBA_DXT5",
516 GL_UNSIGNED_NORMALIZED
,
519 4, 4, 16 /* 16 bytes per 4x4 block */
523 MESA_FORMAT_RGB_FXT1
,
524 "MESA_FORMAT_RGB_FXT1",
526 GL_UNSIGNED_NORMALIZED
,
527 4, 4, 4, 0, /* approx Red/Green/BlueBits */
529 8, 4, 16 /* 16 bytes per 8x4 block */
532 MESA_FORMAT_RGBA_FXT1
,
533 "MESA_FORMAT_RGBA_FXT1",
535 GL_UNSIGNED_NORMALIZED
,
536 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
538 8, 4, 16 /* 16 bytes per 8x4 block */
542 MESA_FORMAT_RGB_DXT1
, /* Name */
543 "MESA_FORMAT_RGB_DXT1", /* StrName */
544 GL_RGB
, /* BaseFormat */
545 GL_UNSIGNED_NORMALIZED
, /* DataType */
546 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
547 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
548 4, 4, 8 /* 8 bytes per 4x4 block */
551 MESA_FORMAT_RGBA_DXT1
,
552 "MESA_FORMAT_RGBA_DXT1",
554 GL_UNSIGNED_NORMALIZED
,
557 4, 4, 8 /* 8 bytes per 4x4 block */
560 MESA_FORMAT_RGBA_DXT3
,
561 "MESA_FORMAT_RGBA_DXT3",
563 GL_UNSIGNED_NORMALIZED
,
566 4, 4, 16 /* 16 bytes per 4x4 block */
569 MESA_FORMAT_RGBA_DXT5
,
570 "MESA_FORMAT_RGBA_DXT5",
572 GL_UNSIGNED_NORMALIZED
,
575 4, 4, 16 /* 16 bytes per 4x4 block */
578 MESA_FORMAT_RGBA_FLOAT32
,
579 "MESA_FORMAT_RGBA_FLOAT32",
587 MESA_FORMAT_RGBA_FLOAT16
,
588 "MESA_FORMAT_RGBA_FLOAT16",
596 MESA_FORMAT_RGB_FLOAT32
,
597 "MESA_FORMAT_RGB_FLOAT32",
605 MESA_FORMAT_RGB_FLOAT16
,
606 "MESA_FORMAT_RGB_FLOAT16",
614 MESA_FORMAT_ALPHA_FLOAT32
,
615 "MESA_FORMAT_ALPHA_FLOAT32",
623 MESA_FORMAT_ALPHA_FLOAT16
,
624 "MESA_FORMAT_ALPHA_FLOAT16",
632 MESA_FORMAT_LUMINANCE_FLOAT32
,
633 "MESA_FORMAT_LUMINANCE_FLOAT32",
641 MESA_FORMAT_LUMINANCE_FLOAT16
,
642 "MESA_FORMAT_LUMINANCE_FLOAT16",
650 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
651 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
659 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
660 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
668 MESA_FORMAT_INTENSITY_FLOAT32
,
669 "MESA_FORMAT_INTENSITY_FLOAT32",
677 MESA_FORMAT_INTENSITY_FLOAT16
,
678 "MESA_FORMAT_INTENSITY_FLOAT16",
686 /* unnormalized signed int formats */
688 MESA_FORMAT_RGBA_INT8
,
689 "MESA_FORMAT_RGBA_INT8",
697 MESA_FORMAT_RGBA_INT16
,
698 "MESA_FORMAT_RGBA_INT16",
706 MESA_FORMAT_RGBA_INT32
,
707 "MESA_FORMAT_RGBA_INT32",
715 /* unnormalized unsigned int formats */
717 MESA_FORMAT_RGBA_UINT8
,
718 "MESA_FORMAT_RGBA_UINT8",
726 MESA_FORMAT_RGBA_UINT16
,
727 "MESA_FORMAT_RGBA_UINT16",
735 MESA_FORMAT_RGBA_UINT32
,
736 "MESA_FORMAT_RGBA_UINT32",
749 GL_SIGNED_NORMALIZED
,
755 /* Signed 8 bits / channel */
757 MESA_FORMAT_SIGNED_R8
, /* Name */
758 "MESA_FORMAT_SIGNED_R8", /* StrName */
759 GL_RGBA
, /* BaseFormat */
760 GL_SIGNED_NORMALIZED
, /* DataType */
761 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
762 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
763 1, 1, 1 /* BlockWidth/Height,Bytes */
766 MESA_FORMAT_SIGNED_RG88
,
767 "MESA_FORMAT_SIGNED_RG88",
769 GL_SIGNED_NORMALIZED
,
775 MESA_FORMAT_SIGNED_RGBX8888
,
776 "MESA_FORMAT_SIGNED_RGBX8888",
778 GL_SIGNED_NORMALIZED
,
781 1, 1, 4 /* 4 bpp, but no alpha */
784 MESA_FORMAT_SIGNED_RGBA8888
,
785 "MESA_FORMAT_SIGNED_RGBA8888",
787 GL_SIGNED_NORMALIZED
,
793 MESA_FORMAT_SIGNED_RGBA8888_REV
,
794 "MESA_FORMAT_SIGNED_RGBA8888_REV",
796 GL_SIGNED_NORMALIZED
,
802 /* Signed 16 bits / channel */
804 MESA_FORMAT_SIGNED_R_16
,
805 "MESA_FORMAT_SIGNED_R_16",
807 GL_SIGNED_NORMALIZED
,
813 MESA_FORMAT_SIGNED_RG_16
,
814 "MESA_FORMAT_SIGNED_RG_16",
816 GL_SIGNED_NORMALIZED
,
822 MESA_FORMAT_SIGNED_RGB_16
,
823 "MESA_FORMAT_SIGNED_RGB_16",
825 GL_SIGNED_NORMALIZED
,
831 MESA_FORMAT_SIGNED_RGBA_16
,
832 "MESA_FORMAT_SIGNED_RGBA_16",
834 GL_SIGNED_NORMALIZED
,
841 "MESA_FORMAT_RGBA_16",
843 GL_UNSIGNED_NORMALIZED
,
852 static const struct gl_format_info
*
853 _mesa_get_format_info(gl_format format
)
855 const struct gl_format_info
*info
= &format_info
[format
];
856 assert(info
->Name
== format
);
861 /** Return string name of format (for debugging) */
863 _mesa_get_format_name(gl_format format
)
865 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
866 ASSERT(info
->BytesPerBlock
);
867 return info
->StrName
;
873 * Return bytes needed to store a block of pixels in the given format.
874 * Normally, a block is 1x1 (a single pixel). But for compressed formats
875 * a block may be 4x4 or 8x4, etc.
878 _mesa_get_format_bytes(gl_format format
)
880 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
881 ASSERT(info
->BytesPerBlock
);
882 return info
->BytesPerBlock
;
887 * Return bits per component for the given format.
888 * \param format one of MESA_FORMAT_x
889 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
892 _mesa_get_format_bits(gl_format format
, GLenum pname
)
894 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
898 case GL_TEXTURE_RED_SIZE
:
899 case GL_RENDERBUFFER_RED_SIZE_EXT
:
900 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
901 return info
->RedBits
;
903 case GL_TEXTURE_GREEN_SIZE
:
904 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
905 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
906 return info
->GreenBits
;
908 case GL_TEXTURE_BLUE_SIZE
:
909 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
910 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
911 return info
->BlueBits
;
913 case GL_TEXTURE_ALPHA_SIZE
:
914 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
915 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
916 return info
->AlphaBits
;
917 case GL_TEXTURE_INTENSITY_SIZE
:
918 return info
->IntensityBits
;
919 case GL_TEXTURE_LUMINANCE_SIZE
:
920 return info
->LuminanceBits
;
922 case GL_TEXTURE_INDEX_SIZE_EXT
:
923 return info
->IndexBits
;
925 case GL_TEXTURE_DEPTH_SIZE_ARB
:
926 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
927 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
928 return info
->DepthBits
;
929 case GL_STENCIL_BITS
:
930 case GL_TEXTURE_STENCIL_SIZE_EXT
:
931 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
932 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
933 return info
->StencilBits
;
935 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
942 * Return the data type (or more specifically, the data representation)
943 * for the given format.
944 * The return value will be one of:
945 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
946 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
947 * GL_UNSIGNED_INT = an ordinary unsigned integer
948 * GL_INT = an ordinary signed integer
949 * GL_FLOAT = an ordinary float
952 _mesa_get_format_datatype(gl_format format
)
954 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
955 return info
->DataType
;
960 * Return the basic format for the given type. The result will be
961 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
962 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
963 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
966 _mesa_get_format_base_format(gl_format format
)
968 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
969 return info
->BaseFormat
;
974 * Return the block size (in pixels) for the given format. Normally
975 * the block size is 1x1. But compressed formats will have block sizes
976 * of 4x4 or 8x4 pixels, etc.
977 * \param bw returns block width in pixels
978 * \param bh returns block height in pixels
981 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
983 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
984 *bw
= info
->BlockWidth
;
985 *bh
= info
->BlockHeight
;
989 /** Is the given format a compressed format? */
991 _mesa_is_format_compressed(gl_format format
)
993 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
994 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
999 * Determine if the given format represents a packed depth/stencil buffer.
1002 _mesa_is_format_packed_depth_stencil(gl_format format
)
1004 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1006 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
1011 * Is the given format a signed/unsigned integer format?
1014 _mesa_is_format_integer(gl_format format
)
1016 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1017 return info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
;
1022 * Return color encoding for given format.
1023 * \return GL_LINEAR or GL_SRGB
1026 _mesa_get_format_color_encoding(gl_format format
)
1028 /* XXX this info should be encoded in gl_format_info */
1030 case MESA_FORMAT_SRGB8
:
1031 case MESA_FORMAT_SRGBA8
:
1032 case MESA_FORMAT_SARGB8
:
1033 case MESA_FORMAT_SL8
:
1034 case MESA_FORMAT_SLA8
:
1035 case MESA_FORMAT_SRGB_DXT1
:
1036 case MESA_FORMAT_SRGBA_DXT1
:
1037 case MESA_FORMAT_SRGBA_DXT3
:
1038 case MESA_FORMAT_SRGBA_DXT5
:
1047 * Return number of bytes needed to store an image of the given size
1048 * in the given format.
1051 _mesa_format_image_size(gl_format format
, GLsizei width
,
1052 GLsizei height
, GLsizei depth
)
1054 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1055 /* Strictly speaking, a conditional isn't needed here */
1056 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1057 /* compressed format */
1058 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
1059 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1060 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
1061 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1065 /* non-compressed */
1066 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
1074 _mesa_format_row_stride(gl_format format
, GLsizei width
)
1076 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1077 /* Strictly speaking, a conditional isn't needed here */
1078 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1079 /* compressed format */
1080 const GLuint bw
= info
->BlockWidth
;
1081 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1082 const GLint stride
= wblocks
* info
->BytesPerBlock
;
1086 const GLint stride
= width
* info
->BytesPerBlock
;
1094 * Do sanity checking of the format info table.
1097 _mesa_test_formats(void)
1101 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
1103 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
1104 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
1107 assert(info
->Name
== i
);
1109 if (info
->Name
== MESA_FORMAT_NONE
)
1112 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
1113 if (info
->RedBits
> 0) {
1114 GLuint t
= info
->RedBits
+ info
->GreenBits
1115 + info
->BlueBits
+ info
->AlphaBits
;
1116 assert(t
/ 8 == info
->BytesPerBlock
);
1121 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
1122 info
->DataType
== GL_SIGNED_NORMALIZED
||
1123 info
->DataType
== GL_UNSIGNED_INT
||
1124 info
->DataType
== GL_FLOAT
);
1126 if (info
->BaseFormat
== GL_RGB
) {
1127 assert(info
->RedBits
> 0);
1128 assert(info
->GreenBits
> 0);
1129 assert(info
->BlueBits
> 0);
1130 assert(info
->AlphaBits
== 0);
1131 assert(info
->LuminanceBits
== 0);
1132 assert(info
->IntensityBits
== 0);
1134 else if (info
->BaseFormat
== GL_RGBA
) {
1135 assert(info
->RedBits
> 0);
1136 assert(info
->GreenBits
> 0);
1137 assert(info
->BlueBits
> 0);
1138 assert(info
->AlphaBits
> 0);
1139 assert(info
->LuminanceBits
== 0);
1140 assert(info
->IntensityBits
== 0);
1142 else if (info
->BaseFormat
== GL_RG
) {
1143 assert(info
->RedBits
> 0);
1144 assert(info
->GreenBits
> 0);
1145 assert(info
->BlueBits
== 0);
1146 assert(info
->AlphaBits
== 0);
1147 assert(info
->LuminanceBits
== 0);
1148 assert(info
->IntensityBits
== 0);
1150 else if (info
->BaseFormat
== GL_RED
) {
1151 assert(info
->RedBits
> 0);
1152 assert(info
->GreenBits
== 0);
1153 assert(info
->BlueBits
== 0);
1154 assert(info
->AlphaBits
== 0);
1155 assert(info
->LuminanceBits
== 0);
1156 assert(info
->IntensityBits
== 0);
1158 else if (info
->BaseFormat
== GL_LUMINANCE
) {
1159 assert(info
->RedBits
== 0);
1160 assert(info
->GreenBits
== 0);
1161 assert(info
->BlueBits
== 0);
1162 assert(info
->AlphaBits
== 0);
1163 assert(info
->LuminanceBits
> 0);
1164 assert(info
->IntensityBits
== 0);
1166 else if (info
->BaseFormat
== GL_INTENSITY
) {
1167 assert(info
->RedBits
== 0);
1168 assert(info
->GreenBits
== 0);
1169 assert(info
->BlueBits
== 0);
1170 assert(info
->AlphaBits
== 0);
1171 assert(info
->LuminanceBits
== 0);
1172 assert(info
->IntensityBits
> 0);
1181 * Return datatype and number of components per texel for the given gl_format.
1182 * Only used for mipmap generation code.
1185 _mesa_format_to_type_and_comps(gl_format format
,
1186 GLenum
*datatype
, GLuint
*comps
)
1189 case MESA_FORMAT_RGBA8888
:
1190 case MESA_FORMAT_RGBA8888_REV
:
1191 case MESA_FORMAT_ARGB8888
:
1192 case MESA_FORMAT_ARGB8888_REV
:
1193 case MESA_FORMAT_XRGB8888
:
1194 *datatype
= GL_UNSIGNED_BYTE
;
1197 case MESA_FORMAT_RGB888
:
1198 case MESA_FORMAT_BGR888
:
1199 *datatype
= GL_UNSIGNED_BYTE
;
1202 case MESA_FORMAT_RGB565
:
1203 case MESA_FORMAT_RGB565_REV
:
1204 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1208 case MESA_FORMAT_ARGB4444
:
1209 case MESA_FORMAT_ARGB4444_REV
:
1210 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1214 case MESA_FORMAT_ARGB1555
:
1215 case MESA_FORMAT_ARGB1555_REV
:
1216 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1220 case MESA_FORMAT_AL88
:
1221 case MESA_FORMAT_AL88_REV
:
1222 case MESA_FORMAT_RG88
:
1223 case MESA_FORMAT_RG88_REV
:
1224 *datatype
= GL_UNSIGNED_BYTE
;
1228 case MESA_FORMAT_AL1616
:
1229 case MESA_FORMAT_AL1616_REV
:
1230 case MESA_FORMAT_RG1616
:
1231 case MESA_FORMAT_RG1616_REV
:
1232 *datatype
= GL_UNSIGNED_SHORT
;
1236 case MESA_FORMAT_R16
:
1237 *datatype
= GL_UNSIGNED_SHORT
;
1241 case MESA_FORMAT_RGB332
:
1242 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1246 case MESA_FORMAT_A8
:
1247 case MESA_FORMAT_L8
:
1248 case MESA_FORMAT_I8
:
1249 case MESA_FORMAT_CI8
:
1250 case MESA_FORMAT_R8
:
1251 *datatype
= GL_UNSIGNED_BYTE
;
1255 case MESA_FORMAT_YCBCR
:
1256 case MESA_FORMAT_YCBCR_REV
:
1257 *datatype
= GL_UNSIGNED_SHORT
;
1261 case MESA_FORMAT_Z24_S8
:
1262 *datatype
= GL_UNSIGNED_INT
;
1263 *comps
= 1; /* XXX OK? */
1266 case MESA_FORMAT_S8_Z24
:
1267 *datatype
= GL_UNSIGNED_INT
;
1268 *comps
= 1; /* XXX OK? */
1271 case MESA_FORMAT_Z16
:
1272 *datatype
= GL_UNSIGNED_SHORT
;
1276 case MESA_FORMAT_X8_Z24
:
1277 *datatype
= GL_UNSIGNED_INT
;
1281 case MESA_FORMAT_Z24_X8
:
1282 *datatype
= GL_UNSIGNED_INT
;
1286 case MESA_FORMAT_Z32
:
1287 *datatype
= GL_UNSIGNED_INT
;
1291 case MESA_FORMAT_DUDV8
:
1292 *datatype
= GL_BYTE
;
1296 case MESA_FORMAT_SIGNED_RGBA8888
:
1297 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1298 *datatype
= GL_BYTE
;
1302 case MESA_FORMAT_SIGNED_R_16
:
1303 *datatype
= GL_SHORT
;
1306 case MESA_FORMAT_SIGNED_RG_16
:
1307 *datatype
= GL_SHORT
;
1310 case MESA_FORMAT_SIGNED_RGB_16
:
1311 *datatype
= GL_SHORT
;
1314 case MESA_FORMAT_SIGNED_RGBA_16
:
1315 *datatype
= GL_SHORT
;
1319 #if FEATURE_EXT_texture_sRGB
1320 case MESA_FORMAT_SRGB8
:
1321 *datatype
= GL_UNSIGNED_BYTE
;
1324 case MESA_FORMAT_SRGBA8
:
1325 case MESA_FORMAT_SARGB8
:
1326 *datatype
= GL_UNSIGNED_BYTE
;
1329 case MESA_FORMAT_SL8
:
1330 *datatype
= GL_UNSIGNED_BYTE
;
1333 case MESA_FORMAT_SLA8
:
1334 *datatype
= GL_UNSIGNED_BYTE
;
1339 #if FEATURE_texture_fxt1
1340 case MESA_FORMAT_RGB_FXT1
:
1341 case MESA_FORMAT_RGBA_FXT1
:
1343 #if FEATURE_texture_s3tc
1344 case MESA_FORMAT_RGB_DXT1
:
1345 case MESA_FORMAT_RGBA_DXT1
:
1346 case MESA_FORMAT_RGBA_DXT3
:
1347 case MESA_FORMAT_RGBA_DXT5
:
1348 #if FEATURE_EXT_texture_sRGB
1349 case MESA_FORMAT_SRGB_DXT1
:
1350 case MESA_FORMAT_SRGBA_DXT1
:
1351 case MESA_FORMAT_SRGBA_DXT3
:
1352 case MESA_FORMAT_SRGBA_DXT5
:
1355 /* XXX generate error instead? */
1356 *datatype
= GL_UNSIGNED_BYTE
;
1360 case MESA_FORMAT_RGBA_FLOAT32
:
1361 *datatype
= GL_FLOAT
;
1364 case MESA_FORMAT_RGBA_FLOAT16
:
1365 *datatype
= GL_HALF_FLOAT_ARB
;
1368 case MESA_FORMAT_RGB_FLOAT32
:
1369 *datatype
= GL_FLOAT
;
1372 case MESA_FORMAT_RGB_FLOAT16
:
1373 *datatype
= GL_HALF_FLOAT_ARB
;
1376 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1377 *datatype
= GL_FLOAT
;
1380 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1381 *datatype
= GL_HALF_FLOAT_ARB
;
1384 case MESA_FORMAT_ALPHA_FLOAT32
:
1385 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1386 case MESA_FORMAT_INTENSITY_FLOAT32
:
1387 *datatype
= GL_FLOAT
;
1390 case MESA_FORMAT_ALPHA_FLOAT16
:
1391 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1392 case MESA_FORMAT_INTENSITY_FLOAT16
:
1393 *datatype
= GL_HALF_FLOAT_ARB
;
1397 case MESA_FORMAT_RGBA_INT8
:
1398 *datatype
= GL_BYTE
;
1401 case MESA_FORMAT_RGBA_INT16
:
1402 *datatype
= GL_SHORT
;
1405 case MESA_FORMAT_RGBA_INT32
:
1411 * \name Non-normalized unsigned integer formats.
1413 case MESA_FORMAT_RGBA_UINT8
:
1414 *datatype
= GL_UNSIGNED_BYTE
;
1417 case MESA_FORMAT_RGBA_UINT16
:
1418 *datatype
= GL_UNSIGNED_SHORT
;
1421 case MESA_FORMAT_RGBA_UINT32
:
1422 *datatype
= GL_UNSIGNED_INT
;
1428 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");