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.
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_SIGNED_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 */
324 MESA_FORMAT_Z24_S8
, /* Name */
325 "MESA_FORMAT_Z24_S8", /* StrName */
326 GL_DEPTH_STENCIL
, /* BaseFormat */
327 GL_UNSIGNED_INT
, /* DataType */
328 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
329 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
330 1, 1, 4 /* BlockWidth/Height,Bytes */
333 MESA_FORMAT_S8_Z24
, /* Name */
334 "MESA_FORMAT_S8_Z24", /* StrName */
335 GL_DEPTH_STENCIL
, /* BaseFormat */
336 GL_UNSIGNED_INT
, /* DataType */
337 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
338 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
339 1, 1, 4 /* BlockWidth/Height,Bytes */
342 MESA_FORMAT_Z16
, /* Name */
343 "MESA_FORMAT_Z16", /* StrName */
344 GL_DEPTH_COMPONENT
, /* BaseFormat */
345 GL_UNSIGNED_INT
, /* DataType */
346 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
347 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
348 1, 1, 2 /* BlockWidth/Height,Bytes */
351 MESA_FORMAT_X8_Z24
, /* Name */
352 "MESA_FORMAT_X8_Z24", /* StrName */
353 GL_DEPTH_COMPONENT
, /* BaseFormat */
354 GL_UNSIGNED_INT
, /* DataType */
355 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
356 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
357 1, 1, 4 /* BlockWidth/Height,Bytes */
360 MESA_FORMAT_Z24_X8
, /* Name */
361 "MESA_FORMAT_Z24_X8", /* StrName */
362 GL_DEPTH_COMPONENT
, /* BaseFormat */
363 GL_UNSIGNED_INT
, /* DataType */
364 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
365 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
366 1, 1, 4 /* BlockWidth/Height,Bytes */
369 MESA_FORMAT_Z32
, /* Name */
370 "MESA_FORMAT_Z32", /* StrName */
371 GL_DEPTH_COMPONENT
, /* BaseFormat */
372 GL_UNSIGNED_INT
, /* DataType */
373 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
374 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
375 1, 1, 4 /* BlockWidth/Height,Bytes */
378 MESA_FORMAT_S8
, /* Name */
379 "MESA_FORMAT_S8", /* StrName */
380 GL_STENCIL_INDEX
, /* BaseFormat */
381 GL_UNSIGNED_INT
, /* DataType */
382 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
383 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
384 1, 1, 1 /* BlockWidth/Height,Bytes */
390 GL_UNSIGNED_NORMALIZED
,
397 "MESA_FORMAT_SRGBA8",
399 GL_UNSIGNED_NORMALIZED
,
406 "MESA_FORMAT_SARGB8",
408 GL_UNSIGNED_NORMALIZED
,
417 GL_UNSIGNED_NORMALIZED
,
426 GL_UNSIGNED_NORMALIZED
,
432 MESA_FORMAT_SRGB_DXT1
, /* Name */
433 "MESA_FORMAT_SRGB_DXT1", /* StrName */
434 GL_RGB
, /* BaseFormat */
435 GL_UNSIGNED_NORMALIZED
, /* DataType */
436 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
437 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
438 4, 4, 8 /* 8 bytes per 4x4 block */
441 MESA_FORMAT_SRGBA_DXT1
,
442 "MESA_FORMAT_SRGBA_DXT1",
444 GL_UNSIGNED_NORMALIZED
,
447 4, 4, 8 /* 8 bytes per 4x4 block */
450 MESA_FORMAT_SRGBA_DXT3
,
451 "MESA_FORMAT_SRGBA_DXT3",
453 GL_UNSIGNED_NORMALIZED
,
456 4, 4, 16 /* 16 bytes per 4x4 block */
459 MESA_FORMAT_SRGBA_DXT5
,
460 "MESA_FORMAT_SRGBA_DXT5",
462 GL_UNSIGNED_NORMALIZED
,
465 4, 4, 16 /* 16 bytes per 4x4 block */
469 MESA_FORMAT_RGB_FXT1
,
470 "MESA_FORMAT_RGB_FXT1",
472 GL_UNSIGNED_NORMALIZED
,
473 4, 4, 4, 0, /* approx Red/Green/BlueBits */
475 8, 4, 16 /* 16 bytes per 8x4 block */
478 MESA_FORMAT_RGBA_FXT1
,
479 "MESA_FORMAT_RGBA_FXT1",
481 GL_UNSIGNED_NORMALIZED
,
482 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
484 8, 4, 16 /* 16 bytes per 8x4 block */
488 MESA_FORMAT_RGB_DXT1
, /* Name */
489 "MESA_FORMAT_RGB_DXT1", /* StrName */
490 GL_RGB
, /* BaseFormat */
491 GL_UNSIGNED_NORMALIZED
, /* DataType */
492 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
493 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
494 4, 4, 8 /* 8 bytes per 4x4 block */
497 MESA_FORMAT_RGBA_DXT1
,
498 "MESA_FORMAT_RGBA_DXT1",
500 GL_UNSIGNED_NORMALIZED
,
503 4, 4, 8 /* 8 bytes per 4x4 block */
506 MESA_FORMAT_RGBA_DXT3
,
507 "MESA_FORMAT_RGBA_DXT3",
509 GL_UNSIGNED_NORMALIZED
,
512 4, 4, 16 /* 16 bytes per 4x4 block */
515 MESA_FORMAT_RGBA_DXT5
,
516 "MESA_FORMAT_RGBA_DXT5",
518 GL_UNSIGNED_NORMALIZED
,
521 4, 4, 16 /* 16 bytes per 4x4 block */
524 MESA_FORMAT_RGBA_FLOAT32
,
525 "MESA_FORMAT_RGBA_FLOAT32",
533 MESA_FORMAT_RGBA_FLOAT16
,
534 "MESA_FORMAT_RGBA_FLOAT16",
542 MESA_FORMAT_RGB_FLOAT32
,
543 "MESA_FORMAT_RGB_FLOAT32",
551 MESA_FORMAT_RGB_FLOAT16
,
552 "MESA_FORMAT_RGB_FLOAT16",
560 MESA_FORMAT_ALPHA_FLOAT32
,
561 "MESA_FORMAT_ALPHA_FLOAT32",
569 MESA_FORMAT_ALPHA_FLOAT16
,
570 "MESA_FORMAT_ALPHA_FLOAT16",
578 MESA_FORMAT_LUMINANCE_FLOAT32
,
579 "MESA_FORMAT_LUMINANCE_FLOAT32",
587 MESA_FORMAT_LUMINANCE_FLOAT16
,
588 "MESA_FORMAT_LUMINANCE_FLOAT16",
596 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
597 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
605 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
606 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
614 MESA_FORMAT_INTENSITY_FLOAT32
,
615 "MESA_FORMAT_INTENSITY_FLOAT32",
623 MESA_FORMAT_INTENSITY_FLOAT16
,
624 "MESA_FORMAT_INTENSITY_FLOAT16",
635 GL_SIGNED_NORMALIZED
,
641 /* Signed 8 bits / channel */
643 MESA_FORMAT_SIGNED_R8
, /* Name */
644 "MESA_FORMAT_SIGNED_R8", /* StrName */
645 GL_RGBA
, /* BaseFormat */
646 GL_SIGNED_NORMALIZED
, /* DataType */
647 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
648 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
649 1, 1, 1 /* BlockWidth/Height,Bytes */
652 MESA_FORMAT_SIGNED_RG88
,
653 "MESA_FORMAT_SIGNED_RG88",
655 GL_SIGNED_NORMALIZED
,
661 MESA_FORMAT_SIGNED_RGBX8888
,
662 "MESA_FORMAT_SIGNED_RGBX8888",
664 GL_SIGNED_NORMALIZED
,
667 1, 1, 4 /* 4 bpp, but no alpha */
670 MESA_FORMAT_SIGNED_RGBA8888
,
671 "MESA_FORMAT_SIGNED_RGBA8888",
673 GL_SIGNED_NORMALIZED
,
679 MESA_FORMAT_SIGNED_RGBA8888_REV
,
680 "MESA_FORMAT_SIGNED_RGBA8888_REV",
682 GL_SIGNED_NORMALIZED
,
688 /* Signed 16 bits / channel */
690 MESA_FORMAT_SIGNED_R_16
,
691 "MESA_FORMAT_SIGNED_R_16",
693 GL_SIGNED_NORMALIZED
,
699 MESA_FORMAT_SIGNED_RG_16
,
700 "MESA_FORMAT_SIGNED_RG_16",
702 GL_SIGNED_NORMALIZED
,
708 MESA_FORMAT_SIGNED_RGB_16
,
709 "MESA_FORMAT_SIGNED_RGB_16",
711 GL_SIGNED_NORMALIZED
,
717 MESA_FORMAT_SIGNED_RGBA_16
,
718 "MESA_FORMAT_SIGNED_RGBA_16",
720 GL_SIGNED_NORMALIZED
,
729 static const struct gl_format_info
*
730 _mesa_get_format_info(gl_format format
)
732 const struct gl_format_info
*info
= &format_info
[format
];
733 assert(info
->Name
== format
);
738 /** Return string name of format (for debugging) */
740 _mesa_get_format_name(gl_format format
)
742 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
743 ASSERT(info
->BytesPerBlock
);
744 return info
->StrName
;
750 * Return bytes needed to store a block of pixels in the given format.
751 * Normally, a block is 1x1 (a single pixel). But for compressed formats
752 * a block may be 4x4 or 8x4, etc.
755 _mesa_get_format_bytes(gl_format format
)
757 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
758 ASSERT(info
->BytesPerBlock
);
759 return info
->BytesPerBlock
;
764 * Return bits per component for the given format.
765 * \param format one of MESA_FORMAT_x
766 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
769 _mesa_get_format_bits(gl_format format
, GLenum pname
)
771 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
775 case GL_TEXTURE_RED_SIZE
:
776 case GL_RENDERBUFFER_RED_SIZE_EXT
:
777 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
778 return info
->RedBits
;
780 case GL_TEXTURE_GREEN_SIZE
:
781 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
782 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
783 return info
->GreenBits
;
785 case GL_TEXTURE_BLUE_SIZE
:
786 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
787 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
788 return info
->BlueBits
;
790 case GL_TEXTURE_ALPHA_SIZE
:
791 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
792 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
793 return info
->AlphaBits
;
794 case GL_TEXTURE_INTENSITY_SIZE
:
795 return info
->IntensityBits
;
796 case GL_TEXTURE_LUMINANCE_SIZE
:
797 return info
->LuminanceBits
;
799 case GL_TEXTURE_INDEX_SIZE_EXT
:
800 return info
->IndexBits
;
802 case GL_TEXTURE_DEPTH_SIZE_ARB
:
803 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
804 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
805 return info
->DepthBits
;
806 case GL_STENCIL_BITS
:
807 case GL_TEXTURE_STENCIL_SIZE_EXT
:
808 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
809 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
810 return info
->StencilBits
;
812 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
819 * Return the data type (or more specifically, the data representation)
820 * for the given format.
821 * The return value will be one of:
822 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
823 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
824 * GL_UNSIGNED_INT = an ordinary unsigned integer
825 * GL_FLOAT = an ordinary float
828 _mesa_get_format_datatype(gl_format format
)
830 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
831 return info
->DataType
;
836 * Return the basic format for the given type. The result will be
837 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
838 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
839 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
842 _mesa_get_format_base_format(gl_format format
)
844 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
845 return info
->BaseFormat
;
850 * Return the block size (in pixels) for the given format. Normally
851 * the block size is 1x1. But compressed formats will have block sizes
852 * of 4x4 or 8x4 pixels, etc.
853 * \param bw returns block width in pixels
854 * \param bh returns block height in pixels
857 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
859 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
860 *bw
= info
->BlockWidth
;
861 *bh
= info
->BlockHeight
;
865 /** Is the given format a compressed format? */
867 _mesa_is_format_compressed(gl_format format
)
869 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
870 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
875 * Return color encoding for given format.
876 * \return GL_LINEAR or GL_SRGB
879 _mesa_get_format_color_encoding(gl_format format
)
881 /* XXX this info should be encoded in gl_format_info */
883 case MESA_FORMAT_SRGB8
:
884 case MESA_FORMAT_SRGBA8
:
885 case MESA_FORMAT_SARGB8
:
886 case MESA_FORMAT_SL8
:
887 case MESA_FORMAT_SLA8
:
888 case MESA_FORMAT_SRGB_DXT1
:
889 case MESA_FORMAT_SRGBA_DXT1
:
890 case MESA_FORMAT_SRGBA_DXT3
:
891 case MESA_FORMAT_SRGBA_DXT5
:
900 * Return number of bytes needed to store an image of the given size
901 * in the given format.
904 _mesa_format_image_size(gl_format format
, GLsizei width
,
905 GLsizei height
, GLsizei depth
)
907 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
908 /* Strictly speaking, a conditional isn't needed here */
909 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
910 /* compressed format */
911 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
912 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
913 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
914 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
919 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
927 _mesa_format_row_stride(gl_format format
, GLsizei width
)
929 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
930 /* Strictly speaking, a conditional isn't needed here */
931 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
932 /* compressed format */
933 const GLuint bw
= info
->BlockWidth
;
934 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
935 const GLint stride
= wblocks
* info
->BytesPerBlock
;
939 const GLint stride
= width
* info
->BytesPerBlock
;
947 * Do sanity checking of the format info table.
950 _mesa_test_formats(void)
954 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
956 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
957 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
960 assert(info
->Name
== i
);
962 if (info
->Name
== MESA_FORMAT_NONE
)
965 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
966 if (info
->RedBits
> 0) {
967 GLuint t
= info
->RedBits
+ info
->GreenBits
968 + info
->BlueBits
+ info
->AlphaBits
;
969 assert(t
/ 8 == info
->BytesPerBlock
);
974 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
975 info
->DataType
== GL_SIGNED_NORMALIZED
||
976 info
->DataType
== GL_UNSIGNED_INT
||
977 info
->DataType
== GL_FLOAT
);
979 if (info
->BaseFormat
== GL_RGB
) {
980 assert(info
->RedBits
> 0);
981 assert(info
->GreenBits
> 0);
982 assert(info
->BlueBits
> 0);
983 assert(info
->AlphaBits
== 0);
984 assert(info
->LuminanceBits
== 0);
985 assert(info
->IntensityBits
== 0);
987 else if (info
->BaseFormat
== GL_RGBA
) {
988 assert(info
->RedBits
> 0);
989 assert(info
->GreenBits
> 0);
990 assert(info
->BlueBits
> 0);
991 assert(info
->AlphaBits
> 0);
992 assert(info
->LuminanceBits
== 0);
993 assert(info
->IntensityBits
== 0);
995 else if (info
->BaseFormat
== GL_LUMINANCE
) {
996 assert(info
->RedBits
== 0);
997 assert(info
->GreenBits
== 0);
998 assert(info
->BlueBits
== 0);
999 assert(info
->AlphaBits
== 0);
1000 assert(info
->LuminanceBits
> 0);
1001 assert(info
->IntensityBits
== 0);
1003 else if (info
->BaseFormat
== GL_INTENSITY
) {
1004 assert(info
->RedBits
== 0);
1005 assert(info
->GreenBits
== 0);
1006 assert(info
->BlueBits
== 0);
1007 assert(info
->AlphaBits
== 0);
1008 assert(info
->LuminanceBits
== 0);
1009 assert(info
->IntensityBits
> 0);
1018 * Return datatype and number of components per texel for the given gl_format.
1019 * Only used for mipmap generation code.
1022 _mesa_format_to_type_and_comps(gl_format format
,
1023 GLenum
*datatype
, GLuint
*comps
)
1026 case MESA_FORMAT_RGBA8888
:
1027 case MESA_FORMAT_RGBA8888_REV
:
1028 case MESA_FORMAT_ARGB8888
:
1029 case MESA_FORMAT_ARGB8888_REV
:
1030 case MESA_FORMAT_XRGB8888
:
1031 *datatype
= GL_UNSIGNED_BYTE
;
1034 case MESA_FORMAT_RGB888
:
1035 case MESA_FORMAT_BGR888
:
1036 *datatype
= GL_UNSIGNED_BYTE
;
1039 case MESA_FORMAT_RGB565
:
1040 case MESA_FORMAT_RGB565_REV
:
1041 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1045 case MESA_FORMAT_ARGB4444
:
1046 case MESA_FORMAT_ARGB4444_REV
:
1047 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1051 case MESA_FORMAT_ARGB1555
:
1052 case MESA_FORMAT_ARGB1555_REV
:
1053 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1057 case MESA_FORMAT_AL88
:
1058 case MESA_FORMAT_AL88_REV
:
1059 *datatype
= GL_UNSIGNED_BYTE
;
1063 case MESA_FORMAT_AL1616
:
1064 case MESA_FORMAT_AL1616_REV
:
1065 *datatype
= GL_UNSIGNED_SHORT
;
1069 case MESA_FORMAT_RGB332
:
1070 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1074 case MESA_FORMAT_A8
:
1075 case MESA_FORMAT_L8
:
1076 case MESA_FORMAT_I8
:
1077 case MESA_FORMAT_CI8
:
1078 *datatype
= GL_UNSIGNED_BYTE
;
1082 case MESA_FORMAT_YCBCR
:
1083 case MESA_FORMAT_YCBCR_REV
:
1084 *datatype
= GL_UNSIGNED_SHORT
;
1088 case MESA_FORMAT_Z24_S8
:
1089 *datatype
= GL_UNSIGNED_INT
;
1090 *comps
= 1; /* XXX OK? */
1093 case MESA_FORMAT_S8_Z24
:
1094 *datatype
= GL_UNSIGNED_INT
;
1095 *comps
= 1; /* XXX OK? */
1098 case MESA_FORMAT_Z16
:
1099 *datatype
= GL_UNSIGNED_SHORT
;
1103 case MESA_FORMAT_X8_Z24
:
1104 *datatype
= GL_UNSIGNED_INT
;
1108 case MESA_FORMAT_Z24_X8
:
1109 *datatype
= GL_UNSIGNED_INT
;
1113 case MESA_FORMAT_Z32
:
1114 *datatype
= GL_UNSIGNED_INT
;
1118 case MESA_FORMAT_DUDV8
:
1119 *datatype
= GL_BYTE
;
1123 case MESA_FORMAT_SIGNED_RGBA8888
:
1124 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1125 *datatype
= GL_BYTE
;
1129 case MESA_FORMAT_SIGNED_R_16
:
1130 *datatype
= GL_SHORT
;
1133 case MESA_FORMAT_SIGNED_RG_16
:
1134 *datatype
= GL_SHORT
;
1137 case MESA_FORMAT_SIGNED_RGB_16
:
1138 *datatype
= GL_SHORT
;
1141 case MESA_FORMAT_SIGNED_RGBA_16
:
1142 *datatype
= GL_SHORT
;
1146 #if FEATURE_EXT_texture_sRGB
1147 case MESA_FORMAT_SRGB8
:
1148 *datatype
= GL_UNSIGNED_BYTE
;
1151 case MESA_FORMAT_SRGBA8
:
1152 case MESA_FORMAT_SARGB8
:
1153 *datatype
= GL_UNSIGNED_BYTE
;
1156 case MESA_FORMAT_SL8
:
1157 *datatype
= GL_UNSIGNED_BYTE
;
1160 case MESA_FORMAT_SLA8
:
1161 *datatype
= GL_UNSIGNED_BYTE
;
1166 #if FEATURE_texture_fxt1
1167 case MESA_FORMAT_RGB_FXT1
:
1168 case MESA_FORMAT_RGBA_FXT1
:
1170 #if FEATURE_texture_s3tc
1171 case MESA_FORMAT_RGB_DXT1
:
1172 case MESA_FORMAT_RGBA_DXT1
:
1173 case MESA_FORMAT_RGBA_DXT3
:
1174 case MESA_FORMAT_RGBA_DXT5
:
1175 #if FEATURE_EXT_texture_sRGB
1176 case MESA_FORMAT_SRGB_DXT1
:
1177 case MESA_FORMAT_SRGBA_DXT1
:
1178 case MESA_FORMAT_SRGBA_DXT3
:
1179 case MESA_FORMAT_SRGBA_DXT5
:
1181 /* XXX generate error instead? */
1182 *datatype
= GL_UNSIGNED_BYTE
;
1187 case MESA_FORMAT_RGBA_FLOAT32
:
1188 *datatype
= GL_FLOAT
;
1191 case MESA_FORMAT_RGBA_FLOAT16
:
1192 *datatype
= GL_HALF_FLOAT_ARB
;
1195 case MESA_FORMAT_RGB_FLOAT32
:
1196 *datatype
= GL_FLOAT
;
1199 case MESA_FORMAT_RGB_FLOAT16
:
1200 *datatype
= GL_HALF_FLOAT_ARB
;
1203 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1204 *datatype
= GL_FLOAT
;
1207 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1208 *datatype
= GL_HALF_FLOAT_ARB
;
1211 case MESA_FORMAT_ALPHA_FLOAT32
:
1212 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1213 case MESA_FORMAT_INTENSITY_FLOAT32
:
1214 *datatype
= GL_FLOAT
;
1217 case MESA_FORMAT_ALPHA_FLOAT16
:
1218 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1219 case MESA_FORMAT_INTENSITY_FLOAT16
:
1220 *datatype
= GL_HALF_FLOAT_ARB
;
1225 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");