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"
34 * Information about texture formats.
40 /** text name for debugging */
44 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
45 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
46 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
51 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
52 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
60 GLubyte LuminanceBits
;
61 GLubyte IntensityBits
;
67 * To describe compressed formats. If not compressed, Width=Height=1.
69 GLubyte BlockWidth
, BlockHeight
;
70 GLubyte BytesPerBlock
;
75 * Info about each format.
76 * These must be in the same order as the MESA_FORMAT_* enums so that
77 * we can do lookups without searching.
79 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
82 MESA_FORMAT_NONE
, /* Name */
83 "MESA_FORMAT_NONE", /* StrName */
84 GL_NONE
, /* BaseFormat */
85 GL_NONE
, /* DataType */
86 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
87 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
88 0, 0, 0 /* BlockWidth/Height,Bytes */
91 MESA_FORMAT_RGBA8888
, /* Name */
92 "MESA_FORMAT_RGBA8888", /* StrName */
93 GL_RGBA
, /* BaseFormat */
94 GL_UNSIGNED_NORMALIZED
, /* DataType */
95 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
96 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
97 1, 1, 4 /* BlockWidth/Height,Bytes */
100 MESA_FORMAT_RGBA8888_REV
, /* Name */
101 "MESA_FORMAT_RGBA8888_REV", /* StrName */
102 GL_RGBA
, /* BaseFormat */
103 GL_UNSIGNED_NORMALIZED
, /* DataType */
104 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
105 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
106 1, 1, 4 /* BlockWidth/Height,Bytes */
109 MESA_FORMAT_ARGB8888
, /* Name */
110 "MESA_FORMAT_ARGB8888", /* StrName */
111 GL_RGBA
, /* BaseFormat */
112 GL_UNSIGNED_NORMALIZED
, /* DataType */
113 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
114 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
115 1, 1, 4 /* BlockWidth/Height,Bytes */
118 MESA_FORMAT_ARGB8888_REV
, /* Name */
119 "MESA_FORMAT_ARGB8888_REV", /* StrName */
120 GL_RGBA
, /* BaseFormat */
121 GL_UNSIGNED_NORMALIZED
, /* DataType */
122 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
123 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
124 1, 1, 4 /* BlockWidth/Height,Bytes */
127 MESA_FORMAT_RGBX8888
, /* Name */
128 "MESA_FORMAT_RGBX8888", /* StrName */
129 GL_RGB
, /* BaseFormat */
130 GL_UNSIGNED_NORMALIZED
, /* DataType */
131 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
132 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
133 1, 1, 4 /* BlockWidth/Height,Bytes */
136 MESA_FORMAT_RGBX8888_REV
, /* Name */
137 "MESA_FORMAT_RGBX8888_REV", /* StrName */
138 GL_RGB
, /* BaseFormat */
139 GL_UNSIGNED_NORMALIZED
, /* DataType */
140 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
141 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
142 1, 1, 4 /* BlockWidth/Height,Bytes */
145 MESA_FORMAT_XRGB8888
, /* Name */
146 "MESA_FORMAT_XRGB8888", /* StrName */
147 GL_RGB
, /* BaseFormat */
148 GL_UNSIGNED_NORMALIZED
, /* DataType */
149 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
150 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
151 1, 1, 4 /* BlockWidth/Height,Bytes */
154 MESA_FORMAT_XRGB8888_REV
, /* Name */
155 "MESA_FORMAT_XRGB8888_REV", /* StrName */
156 GL_RGB
, /* BaseFormat */
157 GL_UNSIGNED_NORMALIZED
, /* DataType */
158 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
159 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
160 1, 1, 4 /* BlockWidth/Height,Bytes */
163 MESA_FORMAT_RGB888
, /* Name */
164 "MESA_FORMAT_RGB888", /* StrName */
165 GL_RGB
, /* BaseFormat */
166 GL_UNSIGNED_NORMALIZED
, /* DataType */
167 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
168 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
169 1, 1, 3 /* BlockWidth/Height,Bytes */
172 MESA_FORMAT_BGR888
, /* Name */
173 "MESA_FORMAT_BGR888", /* StrName */
174 GL_RGB
, /* BaseFormat */
175 GL_UNSIGNED_NORMALIZED
, /* DataType */
176 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
177 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
178 1, 1, 3 /* BlockWidth/Height,Bytes */
181 MESA_FORMAT_RGB565
, /* Name */
182 "MESA_FORMAT_RGB565", /* StrName */
183 GL_RGB
, /* BaseFormat */
184 GL_UNSIGNED_NORMALIZED
, /* DataType */
185 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
186 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
187 1, 1, 2 /* BlockWidth/Height,Bytes */
190 MESA_FORMAT_RGB565_REV
, /* Name */
191 "MESA_FORMAT_RGB565_REV", /* StrName */
192 GL_RGB
, /* BaseFormat */
193 GL_UNSIGNED_NORMALIZED
, /* DataType */
194 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
195 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
196 1, 1, 2 /* BlockWidth/Height,Bytes */
199 MESA_FORMAT_ARGB4444
, /* Name */
200 "MESA_FORMAT_ARGB4444", /* StrName */
201 GL_RGBA
, /* BaseFormat */
202 GL_UNSIGNED_NORMALIZED
, /* DataType */
203 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
204 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
205 1, 1, 2 /* BlockWidth/Height,Bytes */
208 MESA_FORMAT_ARGB4444_REV
, /* Name */
209 "MESA_FORMAT_ARGB4444_REV", /* StrName */
210 GL_RGBA
, /* BaseFormat */
211 GL_UNSIGNED_NORMALIZED
, /* DataType */
212 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
213 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
214 1, 1, 2 /* BlockWidth/Height,Bytes */
217 MESA_FORMAT_RGBA5551
, /* Name */
218 "MESA_FORMAT_RGBA5551", /* StrName */
219 GL_RGBA
, /* BaseFormat */
220 GL_UNSIGNED_NORMALIZED
, /* DataType */
221 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
222 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
223 1, 1, 2 /* BlockWidth/Height,Bytes */
226 MESA_FORMAT_ARGB1555
, /* Name */
227 "MESA_FORMAT_ARGB1555", /* StrName */
228 GL_RGBA
, /* BaseFormat */
229 GL_UNSIGNED_NORMALIZED
, /* DataType */
230 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
231 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
232 1, 1, 2 /* BlockWidth/Height,Bytes */
235 MESA_FORMAT_ARGB1555_REV
, /* Name */
236 "MESA_FORMAT_ARGB1555_REV", /* StrName */
237 GL_RGBA
, /* BaseFormat */
238 GL_UNSIGNED_NORMALIZED
, /* DataType */
239 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
240 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
241 1, 1, 2 /* BlockWidth/Height,Bytes */
244 MESA_FORMAT_AL44
, /* Name */
245 "MESA_FORMAT_AL44", /* StrName */
246 GL_LUMINANCE_ALPHA
, /* BaseFormat */
247 GL_UNSIGNED_NORMALIZED
, /* DataType */
248 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
249 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
250 1, 1, 1 /* BlockWidth/Height,Bytes */
253 MESA_FORMAT_AL88
, /* Name */
254 "MESA_FORMAT_AL88", /* StrName */
255 GL_LUMINANCE_ALPHA
, /* BaseFormat */
256 GL_UNSIGNED_NORMALIZED
, /* DataType */
257 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
258 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
259 1, 1, 2 /* BlockWidth/Height,Bytes */
262 MESA_FORMAT_AL88_REV
, /* Name */
263 "MESA_FORMAT_AL88_REV", /* StrName */
264 GL_LUMINANCE_ALPHA
, /* BaseFormat */
265 GL_UNSIGNED_NORMALIZED
, /* DataType */
266 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
267 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
268 1, 1, 2 /* BlockWidth/Height,Bytes */
271 MESA_FORMAT_AL1616
, /* Name */
272 "MESA_FORMAT_AL1616", /* StrName */
273 GL_LUMINANCE_ALPHA
, /* BaseFormat */
274 GL_UNSIGNED_NORMALIZED
, /* DataType */
275 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
276 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
277 1, 1, 4 /* BlockWidth/Height,Bytes */
280 MESA_FORMAT_AL1616_REV
, /* Name */
281 "MESA_FORMAT_AL1616_REV", /* StrName */
282 GL_LUMINANCE_ALPHA
, /* BaseFormat */
283 GL_UNSIGNED_NORMALIZED
, /* DataType */
284 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
285 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
286 1, 1, 4 /* BlockWidth/Height,Bytes */
289 MESA_FORMAT_RGB332
, /* Name */
290 "MESA_FORMAT_RGB332", /* StrName */
291 GL_RGB
, /* BaseFormat */
292 GL_UNSIGNED_NORMALIZED
, /* DataType */
293 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
294 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
295 1, 1, 1 /* BlockWidth/Height,Bytes */
298 MESA_FORMAT_A8
, /* Name */
299 "MESA_FORMAT_A8", /* StrName */
300 GL_ALPHA
, /* BaseFormat */
301 GL_UNSIGNED_NORMALIZED
, /* DataType */
302 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
303 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
304 1, 1, 1 /* BlockWidth/Height,Bytes */
307 MESA_FORMAT_A16
, /* Name */
308 "MESA_FORMAT_A16", /* StrName */
309 GL_ALPHA
, /* BaseFormat */
310 GL_UNSIGNED_NORMALIZED
, /* DataType */
311 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
312 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
313 1, 1, 2 /* BlockWidth/Height,Bytes */
316 MESA_FORMAT_L8
, /* Name */
317 "MESA_FORMAT_L8", /* StrName */
318 GL_LUMINANCE
, /* BaseFormat */
319 GL_UNSIGNED_NORMALIZED
, /* DataType */
320 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
321 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
322 1, 1, 1 /* BlockWidth/Height,Bytes */
325 MESA_FORMAT_L16
, /* Name */
326 "MESA_FORMAT_L16", /* StrName */
327 GL_LUMINANCE
, /* BaseFormat */
328 GL_UNSIGNED_NORMALIZED
, /* DataType */
329 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
330 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
331 1, 1, 2 /* BlockWidth/Height,Bytes */
334 MESA_FORMAT_I8
, /* Name */
335 "MESA_FORMAT_I8", /* StrName */
336 GL_INTENSITY
, /* BaseFormat */
337 GL_UNSIGNED_NORMALIZED
, /* DataType */
338 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
339 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
340 1, 1, 1 /* BlockWidth/Height,Bytes */
343 MESA_FORMAT_I16
, /* Name */
344 "MESA_FORMAT_I16", /* StrName */
345 GL_INTENSITY
, /* BaseFormat */
346 GL_UNSIGNED_NORMALIZED
, /* DataType */
347 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
348 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
349 1, 1, 2 /* BlockWidth/Height,Bytes */
352 MESA_FORMAT_YCBCR
, /* Name */
353 "MESA_FORMAT_YCBCR", /* StrName */
354 GL_YCBCR_MESA
, /* BaseFormat */
355 GL_UNSIGNED_NORMALIZED
, /* DataType */
356 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
357 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
358 1, 1, 2 /* BlockWidth/Height,Bytes */
361 MESA_FORMAT_YCBCR_REV
, /* Name */
362 "MESA_FORMAT_YCBCR_REV", /* StrName */
363 GL_YCBCR_MESA
, /* BaseFormat */
364 GL_UNSIGNED_NORMALIZED
, /* DataType */
365 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
366 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
367 1, 1, 2 /* BlockWidth/Height,Bytes */
370 MESA_FORMAT_Z16
, /* Name */
371 "MESA_FORMAT_Z16", /* StrName */
372 GL_DEPTH_COMPONENT
, /* BaseFormat */
373 GL_UNSIGNED_NORMALIZED
, /* DataType */
374 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
375 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
376 1, 1, 2 /* BlockWidth/Height,Bytes */
379 MESA_FORMAT_X8_Z24
, /* Name */
380 "MESA_FORMAT_X8_Z24", /* StrName */
381 GL_DEPTH_COMPONENT
, /* BaseFormat */
382 GL_UNSIGNED_NORMALIZED
, /* DataType */
383 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
384 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
385 1, 1, 4 /* BlockWidth/Height,Bytes */
388 MESA_FORMAT_Z24_X8
, /* Name */
389 "MESA_FORMAT_Z24_X8", /* StrName */
390 GL_DEPTH_COMPONENT
, /* BaseFormat */
391 GL_UNSIGNED_NORMALIZED
, /* DataType */
392 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
393 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
394 1, 1, 4 /* BlockWidth/Height,Bytes */
397 MESA_FORMAT_Z32
, /* Name */
398 "MESA_FORMAT_Z32", /* StrName */
399 GL_DEPTH_COMPONENT
, /* BaseFormat */
400 GL_UNSIGNED_NORMALIZED
, /* DataType */
401 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
402 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
403 1, 1, 4 /* BlockWidth/Height,Bytes */
406 MESA_FORMAT_S8
, /* Name */
407 "MESA_FORMAT_S8", /* StrName */
408 GL_STENCIL_INDEX
, /* BaseFormat */
409 GL_UNSIGNED_INT
, /* DataType */
410 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
411 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
412 1, 1, 1 /* BlockWidth/Height,Bytes */
415 MESA_FORMAT_RGBA_FLOAT32
,
416 "MESA_FORMAT_RGBA_FLOAT32",
424 MESA_FORMAT_RGBA_FLOAT16
,
425 "MESA_FORMAT_RGBA_FLOAT16",
433 MESA_FORMAT_RGB_FLOAT32
,
434 "MESA_FORMAT_RGB_FLOAT32",
442 MESA_FORMAT_RGB_FLOAT16
,
443 "MESA_FORMAT_RGB_FLOAT16",
451 MESA_FORMAT_ALPHA_FLOAT32
,
452 "MESA_FORMAT_ALPHA_FLOAT32",
460 MESA_FORMAT_ALPHA_FLOAT16
,
461 "MESA_FORMAT_ALPHA_FLOAT16",
469 MESA_FORMAT_LUMINANCE_FLOAT32
,
470 "MESA_FORMAT_LUMINANCE_FLOAT32",
478 MESA_FORMAT_LUMINANCE_FLOAT16
,
479 "MESA_FORMAT_LUMINANCE_FLOAT16",
487 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
488 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
496 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
497 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
505 MESA_FORMAT_INTENSITY_FLOAT32
,
506 "MESA_FORMAT_INTENSITY_FLOAT32",
514 MESA_FORMAT_INTENSITY_FLOAT16
,
515 "MESA_FORMAT_INTENSITY_FLOAT16",
523 /* unnormalized signed int formats */
524 /* unnormalized unsigned int formats */
526 MESA_FORMAT_ALPHA_UINT8
,
527 "MESA_FORMAT_ALPHA_UINT8",
535 MESA_FORMAT_ALPHA_UINT16
,
536 "MESA_FORMAT_ALPHA_UINT16",
544 MESA_FORMAT_ALPHA_UINT32
,
545 "MESA_FORMAT_ALPHA_UINT32",
553 MESA_FORMAT_ALPHA_INT8
,
554 "MESA_FORMAT_ALPHA_INT8",
562 MESA_FORMAT_ALPHA_INT16
,
563 "MESA_FORMAT_ALPHA_INT16",
571 MESA_FORMAT_ALPHA_INT32
,
572 "MESA_FORMAT_ALPHA_INT32",
580 MESA_FORMAT_INTENSITY_UINT8
,
581 "MESA_FORMAT_INTENSITY_UINT8",
589 MESA_FORMAT_INTENSITY_UINT16
,
590 "MESA_FORMAT_INTENSITY_UINT16",
598 MESA_FORMAT_INTENSITY_UINT32
,
599 "MESA_FORMAT_INTENSITY_UINT32",
607 MESA_FORMAT_INTENSITY_INT8
,
608 "MESA_FORMAT_INTENSITY_INT8",
616 MESA_FORMAT_INTENSITY_INT16
,
617 "MESA_FORMAT_INTENSITY_INT16",
625 MESA_FORMAT_INTENSITY_INT32
,
626 "MESA_FORMAT_INTENSITY_INT32",
634 MESA_FORMAT_LUMINANCE_UINT8
,
635 "MESA_FORMAT_LUMINANCE_UINT8",
643 MESA_FORMAT_LUMINANCE_UINT16
,
644 "MESA_FORMAT_LUMINANCE_UINT16",
652 MESA_FORMAT_LUMINANCE_UINT32
,
653 "MESA_FORMAT_LUMINANCE_UINT32",
661 MESA_FORMAT_LUMINANCE_INT8
,
662 "MESA_FORMAT_LUMINANCE_INT8",
670 MESA_FORMAT_LUMINANCE_INT16
,
671 "MESA_FORMAT_LUMINANCE_INT16",
679 MESA_FORMAT_LUMINANCE_INT32
,
680 "MESA_FORMAT_LUMINANCE_INT32",
688 MESA_FORMAT_LUMINANCE_ALPHA_UINT8
,
689 "MESA_FORMAT_LUMINANCE_ALPHA_UINT8",
697 MESA_FORMAT_LUMINANCE_ALPHA_UINT16
,
698 "MESA_FORMAT_LUMINANCE_ALPHA_UINT16",
706 MESA_FORMAT_LUMINANCE_ALPHA_UINT32
,
707 "MESA_FORMAT_LUMINANCE_ALPHA_UINT32",
715 MESA_FORMAT_LUMINANCE_ALPHA_INT8
,
716 "MESA_FORMAT_LUMINANCE_ALPHA_INT8",
724 MESA_FORMAT_LUMINANCE_ALPHA_INT16
,
725 "MESA_FORMAT_LUMINANCE_ALPHA_INT16",
733 MESA_FORMAT_LUMINANCE_ALPHA_INT32
,
734 "MESA_FORMAT_LUMINANCE_ALPHA_INT32",
742 MESA_FORMAT_RGB_INT8
,
743 "MESA_FORMAT_RGB_INT8",
751 MESA_FORMAT_RGBA_INT8
,
752 "MESA_FORMAT_RGBA_INT8",
760 MESA_FORMAT_RGB_INT16
,
761 "MESA_FORMAT_RGB_INT16",
769 MESA_FORMAT_RGBA_INT16
,
770 "MESA_FORMAT_RGBA_INT16",
778 MESA_FORMAT_RGB_INT32
,
779 "MESA_FORMAT_RGB_INT32",
787 MESA_FORMAT_RGBA_INT32
,
788 "MESA_FORMAT_RGBA_INT32",
796 MESA_FORMAT_RGB_UINT8
,
797 "MESA_FORMAT_RGB_UINT8",
805 MESA_FORMAT_RGBA_UINT8
,
806 "MESA_FORMAT_RGBA_UINT8",
814 MESA_FORMAT_RGB_UINT16
,
815 "MESA_FORMAT_RGB_UINT16",
823 MESA_FORMAT_RGBA_UINT16
,
824 "MESA_FORMAT_RGBA_UINT16",
832 MESA_FORMAT_RGB_UINT32
,
833 "MESA_FORMAT_RGB_UINT32",
841 MESA_FORMAT_RGBA_UINT32
,
842 "MESA_FORMAT_RGBA_UINT32",
852 MESA_FORMAT_SIGNED_RGBA_16
,
853 "MESA_FORMAT_SIGNED_RGBA_16",
855 GL_SIGNED_NORMALIZED
,
862 "MESA_FORMAT_RGBA_16",
864 GL_UNSIGNED_NORMALIZED
,
873 static const struct gl_format_info
*
874 _mesa_get_format_info(gl_format format
)
876 const struct gl_format_info
*info
= &format_info
[format
];
877 assert(info
->Name
== format
);
882 /** Return string name of format (for debugging) */
884 _mesa_get_format_name(gl_format format
)
886 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
887 return info
->StrName
;
893 * Return bytes needed to store a block of pixels in the given format.
894 * Normally, a block is 1x1 (a single pixel). But for compressed formats
895 * a block may be 4x4 or 8x4, etc.
897 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
900 _mesa_get_format_bytes(gl_format format
)
902 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
903 ASSERT(info
->BytesPerBlock
);
904 ASSERT(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
);
905 return info
->BytesPerBlock
;
910 * Return bits per component for the given format.
911 * \param format one of MESA_FORMAT_x
912 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
915 _mesa_get_format_bits(gl_format format
, GLenum pname
)
917 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
921 case GL_TEXTURE_RED_SIZE
:
922 case GL_RENDERBUFFER_RED_SIZE_EXT
:
923 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
924 return info
->RedBits
;
926 case GL_TEXTURE_GREEN_SIZE
:
927 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
928 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
929 return info
->GreenBits
;
931 case GL_TEXTURE_BLUE_SIZE
:
932 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
933 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
934 return info
->BlueBits
;
936 case GL_TEXTURE_ALPHA_SIZE
:
937 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
938 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
939 return info
->AlphaBits
;
940 case GL_TEXTURE_INTENSITY_SIZE
:
941 return info
->IntensityBits
;
942 case GL_TEXTURE_LUMINANCE_SIZE
:
943 return info
->LuminanceBits
;
945 return info
->IndexBits
;
947 case GL_TEXTURE_DEPTH_SIZE_ARB
:
948 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
949 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
950 return info
->DepthBits
;
951 case GL_STENCIL_BITS
:
952 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
953 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
954 return info
->StencilBits
;
956 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
963 _mesa_get_format_max_bits(gl_format format
)
965 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
966 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
967 max
= MAX2(max
, info
->BlueBits
);
968 max
= MAX2(max
, info
->AlphaBits
);
969 max
= MAX2(max
, info
->LuminanceBits
);
970 max
= MAX2(max
, info
->IntensityBits
);
971 max
= MAX2(max
, info
->DepthBits
);
972 max
= MAX2(max
, info
->StencilBits
);
978 * Return the data type (or more specifically, the data representation)
979 * for the given format.
980 * The return value will be one of:
981 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
982 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
983 * GL_UNSIGNED_INT = an ordinary unsigned integer
984 * GL_INT = an ordinary signed integer
985 * GL_FLOAT = an ordinary float
988 _mesa_get_format_datatype(gl_format format
)
990 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
991 return info
->DataType
;
996 * Return the basic format for the given type. The result will be one of
997 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
998 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
1001 _mesa_get_format_base_format(gl_format format
)
1003 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1004 return info
->BaseFormat
;
1009 * Return the block size (in pixels) for the given format. Normally
1010 * the block size is 1x1. But compressed formats will have block sizes
1011 * of 4x4 or 8x4 pixels, etc.
1012 * \param bw returns block width in pixels
1013 * \param bh returns block height in pixels
1016 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
1018 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1019 *bw
= info
->BlockWidth
;
1020 *bh
= info
->BlockHeight
;
1025 * Is the given format a signed/unsigned integer color format?
1028 _mesa_is_format_integer_color(gl_format format
)
1030 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1031 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
1032 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
1033 info
->BaseFormat
!= GL_STENCIL_INDEX
;
1038 _mesa_format_num_components(gl_format format
)
1040 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1041 return ((info
->RedBits
> 0) +
1042 (info
->GreenBits
> 0) +
1043 (info
->BlueBits
> 0) +
1044 (info
->AlphaBits
> 0) +
1045 (info
->LuminanceBits
> 0) +
1046 (info
->IntensityBits
> 0) +
1047 (info
->DepthBits
> 0) +
1048 (info
->StencilBits
> 0));
1053 * Return number of bytes needed to store an image of the given size
1054 * in the given format.
1057 _mesa_format_image_size(gl_format format
, GLsizei width
,
1058 GLsizei height
, GLsizei depth
)
1060 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1061 /* Strictly speaking, a conditional isn't needed here */
1062 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1063 /* compressed format (2D only for now) */
1064 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
1065 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1066 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
1067 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1072 /* non-compressed */
1073 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
1080 * Same as _mesa_format_image_size() but returns a 64-bit value to
1081 * accomodate very large textures.
1084 _mesa_format_image_size64(gl_format format
, GLsizei width
,
1085 GLsizei height
, GLsizei depth
)
1087 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1088 /* Strictly speaking, a conditional isn't needed here */
1089 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1090 /* compressed format (2D only for now) */
1091 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
1092 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
1093 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
1094 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1099 /* non-compressed */
1100 const uint64_t sz
= ((uint64_t) width
*
1103 info
->BytesPerBlock
);
1111 _mesa_format_row_stride(gl_format format
, GLsizei width
)
1113 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1114 /* Strictly speaking, a conditional isn't needed here */
1115 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1116 /* compressed format */
1117 const GLuint bw
= info
->BlockWidth
;
1118 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1119 const GLint stride
= wblocks
* info
->BytesPerBlock
;
1123 const GLint stride
= width
* info
->BytesPerBlock
;
1130 * Debug/test: check that all formats are handled in the
1131 * _mesa_format_to_type_and_comps() function. When new pixel formats
1132 * are added to Mesa, that function needs to be updated.
1133 * This is a no-op after the first call.
1136 check_format_to_type_and_comps(void)
1140 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
1141 GLenum datatype
= 0;
1143 /* This function will emit a problem/warning if the format is
1146 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
1152 * Do sanity checking of the format info table.
1155 _mesa_test_formats(void)
1159 STATIC_ASSERT(Elements(format_info
) == MESA_FORMAT_COUNT
);
1161 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
1162 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
1165 assert(info
->Name
== i
);
1167 if (info
->Name
== MESA_FORMAT_NONE
)
1170 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
1171 if (info
->RedBits
> 0) {
1172 GLuint t
= info
->RedBits
+ info
->GreenBits
1173 + info
->BlueBits
+ info
->AlphaBits
;
1174 assert(t
/ 8 <= info
->BytesPerBlock
);
1179 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
1180 info
->DataType
== GL_SIGNED_NORMALIZED
||
1181 info
->DataType
== GL_UNSIGNED_INT
||
1182 info
->DataType
== GL_INT
||
1183 info
->DataType
== GL_FLOAT
||
1184 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
1185 info
->DataType
== GL_NONE
);
1187 if (info
->BaseFormat
== GL_RGB
) {
1188 assert(info
->RedBits
> 0);
1189 assert(info
->GreenBits
> 0);
1190 assert(info
->BlueBits
> 0);
1191 assert(info
->AlphaBits
== 0);
1192 assert(info
->LuminanceBits
== 0);
1193 assert(info
->IntensityBits
== 0);
1195 else if (info
->BaseFormat
== GL_RGBA
) {
1196 assert(info
->RedBits
> 0);
1197 assert(info
->GreenBits
> 0);
1198 assert(info
->BlueBits
> 0);
1199 assert(info
->AlphaBits
> 0);
1200 assert(info
->LuminanceBits
== 0);
1201 assert(info
->IntensityBits
== 0);
1203 else if (info
->BaseFormat
== GL_RG
) {
1204 assert(info
->RedBits
> 0);
1205 assert(info
->GreenBits
> 0);
1206 assert(info
->BlueBits
== 0);
1207 assert(info
->AlphaBits
== 0);
1208 assert(info
->LuminanceBits
== 0);
1209 assert(info
->IntensityBits
== 0);
1211 else if (info
->BaseFormat
== GL_RED
) {
1212 assert(info
->RedBits
> 0);
1213 assert(info
->GreenBits
== 0);
1214 assert(info
->BlueBits
== 0);
1215 assert(info
->AlphaBits
== 0);
1216 assert(info
->LuminanceBits
== 0);
1217 assert(info
->IntensityBits
== 0);
1219 else if (info
->BaseFormat
== GL_LUMINANCE
) {
1220 assert(info
->RedBits
== 0);
1221 assert(info
->GreenBits
== 0);
1222 assert(info
->BlueBits
== 0);
1223 assert(info
->AlphaBits
== 0);
1224 assert(info
->LuminanceBits
> 0);
1225 assert(info
->IntensityBits
== 0);
1227 else if (info
->BaseFormat
== GL_INTENSITY
) {
1228 assert(info
->RedBits
== 0);
1229 assert(info
->GreenBits
== 0);
1230 assert(info
->BlueBits
== 0);
1231 assert(info
->AlphaBits
== 0);
1232 assert(info
->LuminanceBits
== 0);
1233 assert(info
->IntensityBits
> 0);
1237 check_format_to_type_and_comps();
1243 * Return datatype and number of components per texel for the given gl_format.
1244 * Only used for mipmap generation code.
1247 _mesa_format_to_type_and_comps(gl_format format
,
1248 GLenum
*datatype
, GLuint
*comps
)
1251 case MESA_FORMAT_RGBA8888
:
1252 case MESA_FORMAT_RGBA8888_REV
:
1253 case MESA_FORMAT_ARGB8888
:
1254 case MESA_FORMAT_ARGB8888_REV
:
1255 case MESA_FORMAT_RGBX8888
:
1256 case MESA_FORMAT_RGBX8888_REV
:
1257 case MESA_FORMAT_XRGB8888
:
1258 case MESA_FORMAT_XRGB8888_REV
:
1259 *datatype
= GL_UNSIGNED_BYTE
;
1262 case MESA_FORMAT_RGB888
:
1263 case MESA_FORMAT_BGR888
:
1264 *datatype
= GL_UNSIGNED_BYTE
;
1267 case MESA_FORMAT_RGB565
:
1268 case MESA_FORMAT_RGB565_REV
:
1269 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1273 case MESA_FORMAT_ARGB4444
:
1274 case MESA_FORMAT_ARGB4444_REV
:
1275 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1279 case MESA_FORMAT_ARGB1555
:
1280 case MESA_FORMAT_ARGB1555_REV
:
1281 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1285 case MESA_FORMAT_RGBA5551
:
1286 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1290 case MESA_FORMAT_AL44
:
1291 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1295 case MESA_FORMAT_AL88
:
1296 case MESA_FORMAT_AL88_REV
:
1297 *datatype
= GL_UNSIGNED_BYTE
;
1301 case MESA_FORMAT_AL1616
:
1302 case MESA_FORMAT_AL1616_REV
:
1303 *datatype
= GL_UNSIGNED_SHORT
;
1307 case MESA_FORMAT_A16
:
1308 case MESA_FORMAT_L16
:
1309 case MESA_FORMAT_I16
:
1310 *datatype
= GL_UNSIGNED_SHORT
;
1314 case MESA_FORMAT_RGB332
:
1315 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1319 case MESA_FORMAT_A8
:
1320 case MESA_FORMAT_L8
:
1321 case MESA_FORMAT_I8
:
1322 case MESA_FORMAT_S8
:
1323 *datatype
= GL_UNSIGNED_BYTE
;
1327 case MESA_FORMAT_YCBCR
:
1328 case MESA_FORMAT_YCBCR_REV
:
1329 *datatype
= GL_UNSIGNED_SHORT
;
1333 case MESA_FORMAT_Z16
:
1334 *datatype
= GL_UNSIGNED_SHORT
;
1338 case MESA_FORMAT_X8_Z24
:
1339 *datatype
= GL_UNSIGNED_INT
;
1343 case MESA_FORMAT_Z24_X8
:
1344 *datatype
= GL_UNSIGNED_INT
;
1348 case MESA_FORMAT_Z32
:
1349 *datatype
= GL_UNSIGNED_INT
;
1353 case MESA_FORMAT_RGBA_16
:
1354 *datatype
= GL_UNSIGNED_SHORT
;
1358 case MESA_FORMAT_SIGNED_RGBA_16
:
1359 *datatype
= GL_SHORT
;
1363 case MESA_FORMAT_RGBA_FLOAT32
:
1364 *datatype
= GL_FLOAT
;
1367 case MESA_FORMAT_RGBA_FLOAT16
:
1368 *datatype
= GL_HALF_FLOAT_ARB
;
1371 case MESA_FORMAT_RGB_FLOAT32
:
1372 *datatype
= GL_FLOAT
;
1375 case MESA_FORMAT_RGB_FLOAT16
:
1376 *datatype
= GL_HALF_FLOAT_ARB
;
1379 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1380 *datatype
= GL_FLOAT
;
1383 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1384 *datatype
= GL_HALF_FLOAT_ARB
;
1387 case MESA_FORMAT_ALPHA_FLOAT32
:
1388 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1389 case MESA_FORMAT_INTENSITY_FLOAT32
:
1390 *datatype
= GL_FLOAT
;
1393 case MESA_FORMAT_ALPHA_FLOAT16
:
1394 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1395 case MESA_FORMAT_INTENSITY_FLOAT16
:
1396 *datatype
= GL_HALF_FLOAT_ARB
;
1400 case MESA_FORMAT_ALPHA_UINT8
:
1401 case MESA_FORMAT_LUMINANCE_UINT8
:
1402 case MESA_FORMAT_INTENSITY_UINT8
:
1403 *datatype
= GL_UNSIGNED_BYTE
;
1406 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
1407 *datatype
= GL_UNSIGNED_BYTE
;
1411 case MESA_FORMAT_ALPHA_UINT16
:
1412 case MESA_FORMAT_LUMINANCE_UINT16
:
1413 case MESA_FORMAT_INTENSITY_UINT16
:
1414 *datatype
= GL_UNSIGNED_SHORT
;
1417 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
1418 *datatype
= GL_UNSIGNED_SHORT
;
1421 case MESA_FORMAT_ALPHA_UINT32
:
1422 case MESA_FORMAT_LUMINANCE_UINT32
:
1423 case MESA_FORMAT_INTENSITY_UINT32
:
1424 *datatype
= GL_UNSIGNED_INT
;
1427 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
1428 *datatype
= GL_UNSIGNED_INT
;
1431 case MESA_FORMAT_ALPHA_INT8
:
1432 case MESA_FORMAT_LUMINANCE_INT8
:
1433 case MESA_FORMAT_INTENSITY_INT8
:
1434 *datatype
= GL_BYTE
;
1437 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
1438 *datatype
= GL_BYTE
;
1442 case MESA_FORMAT_ALPHA_INT16
:
1443 case MESA_FORMAT_LUMINANCE_INT16
:
1444 case MESA_FORMAT_INTENSITY_INT16
:
1445 *datatype
= GL_SHORT
;
1448 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
1449 *datatype
= GL_SHORT
;
1453 case MESA_FORMAT_ALPHA_INT32
:
1454 case MESA_FORMAT_LUMINANCE_INT32
:
1455 case MESA_FORMAT_INTENSITY_INT32
:
1459 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
1464 case MESA_FORMAT_RGB_INT8
:
1465 *datatype
= GL_BYTE
;
1468 case MESA_FORMAT_RGBA_INT8
:
1469 *datatype
= GL_BYTE
;
1472 case MESA_FORMAT_RGB_INT16
:
1473 *datatype
= GL_SHORT
;
1476 case MESA_FORMAT_RGBA_INT16
:
1477 *datatype
= GL_SHORT
;
1480 case MESA_FORMAT_RGB_INT32
:
1484 case MESA_FORMAT_RGBA_INT32
:
1490 * \name Non-normalized unsigned integer formats.
1492 case MESA_FORMAT_RGB_UINT8
:
1493 *datatype
= GL_UNSIGNED_BYTE
;
1496 case MESA_FORMAT_RGBA_UINT8
:
1497 *datatype
= GL_UNSIGNED_BYTE
;
1500 case MESA_FORMAT_RGB_UINT16
:
1501 *datatype
= GL_UNSIGNED_SHORT
;
1504 case MESA_FORMAT_RGBA_UINT16
:
1505 *datatype
= GL_UNSIGNED_SHORT
;
1508 case MESA_FORMAT_RGB_UINT32
:
1509 *datatype
= GL_UNSIGNED_INT
;
1512 case MESA_FORMAT_RGBA_UINT32
:
1513 *datatype
= GL_UNSIGNED_INT
;
1517 case MESA_FORMAT_COUNT
:
1521 case MESA_FORMAT_NONE
:
1522 /* For debug builds, warn if any formats are not handled */
1526 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1527 _mesa_get_format_name(format
));
1534 * Check if a gl_format exactly matches a GL formaat/type combination
1535 * such that we can use memcpy() from one to the other.
1537 * Note: this matching assumes that GL_PACK/UNPACK_SWAP_BYTES is unset.
1539 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1542 _mesa_format_matches_format_and_type(gl_format gl_format
,
1543 GLenum format
, GLenum type
)
1545 const GLboolean littleEndian
= _mesa_little_endian();
1547 /* Note: When reading a GL format/type combination, the format lists channel
1548 * assignments from most significant channel in the type to least
1549 * significant. A type with _REV indicates that the assignments are
1550 * swapped, so they are listed from least significant to most significant.
1552 * For sanity, please keep this switch statement ordered the same as the
1553 * enums in formats.h.
1556 switch (gl_format
) {
1558 case MESA_FORMAT_NONE
:
1559 case MESA_FORMAT_COUNT
:
1562 case MESA_FORMAT_RGBA8888
:
1563 return ((format
== GL_RGBA
&& (type
== GL_UNSIGNED_INT_8_8_8_8
||
1564 (type
== GL_UNSIGNED_BYTE
&& !littleEndian
))) ||
1565 (format
== GL_ABGR_EXT
&& (type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1566 (type
== GL_UNSIGNED_BYTE
&& littleEndian
))));
1568 case MESA_FORMAT_RGBA8888_REV
:
1569 return ((format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
));
1571 case MESA_FORMAT_ARGB8888
:
1572 return ((format
== GL_BGRA
&& (type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
1573 (type
== GL_UNSIGNED_BYTE
&& littleEndian
))));
1575 case MESA_FORMAT_ARGB8888_REV
:
1576 return ((format
== GL_BGRA
&& (type
== GL_UNSIGNED_INT_8_8_8_8
||
1577 (type
== GL_UNSIGNED_BYTE
&& !littleEndian
))));
1579 case MESA_FORMAT_RGBX8888
:
1580 case MESA_FORMAT_RGBX8888_REV
:
1583 case MESA_FORMAT_XRGB8888
:
1584 case MESA_FORMAT_XRGB8888_REV
:
1587 case MESA_FORMAT_RGB888
:
1588 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1590 case MESA_FORMAT_BGR888
:
1591 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1593 case MESA_FORMAT_RGB565
:
1594 return format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1595 case MESA_FORMAT_RGB565_REV
:
1596 /* Some of the 16-bit MESA_FORMATs that would seem to correspond to
1597 * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,
1598 * according to formats.h, so they can't be matched.
1602 case MESA_FORMAT_ARGB4444
:
1603 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
;
1604 case MESA_FORMAT_ARGB4444_REV
:
1607 case MESA_FORMAT_RGBA5551
:
1608 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
;
1610 case MESA_FORMAT_ARGB1555
:
1611 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1612 case MESA_FORMAT_ARGB1555_REV
:
1615 case MESA_FORMAT_AL44
:
1617 case MESA_FORMAT_AL88
:
1618 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1619 case MESA_FORMAT_AL88_REV
:
1622 case MESA_FORMAT_AL1616
:
1623 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
;
1624 case MESA_FORMAT_AL1616_REV
:
1627 case MESA_FORMAT_RGB332
:
1628 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1630 case MESA_FORMAT_A8
:
1631 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1632 case MESA_FORMAT_A16
:
1633 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
;
1634 case MESA_FORMAT_L8
:
1635 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1636 case MESA_FORMAT_L16
:
1637 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
;
1638 case MESA_FORMAT_I8
:
1639 return format
== GL_INTENSITY
&& type
== GL_UNSIGNED_BYTE
;
1640 case MESA_FORMAT_I16
:
1641 return format
== GL_INTENSITY
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
;
1643 case MESA_FORMAT_YCBCR
:
1644 case MESA_FORMAT_YCBCR_REV
:
1647 case MESA_FORMAT_Z24_X8
:
1650 case MESA_FORMAT_Z16
:
1651 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
;
1653 case MESA_FORMAT_X8_Z24
:
1656 case MESA_FORMAT_Z32
:
1657 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
;
1659 case MESA_FORMAT_S8
:
1662 case MESA_FORMAT_RGBA_FLOAT32
:
1663 return format
== GL_RGBA
&& type
== GL_FLOAT
;
1664 case MESA_FORMAT_RGBA_FLOAT16
:
1665 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
;
1667 case MESA_FORMAT_RGB_FLOAT32
:
1668 return format
== GL_RGB
&& type
== GL_FLOAT
;
1669 case MESA_FORMAT_RGB_FLOAT16
:
1670 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
;
1672 case MESA_FORMAT_ALPHA_FLOAT32
:
1673 return format
== GL_ALPHA
&& type
== GL_FLOAT
;
1674 case MESA_FORMAT_ALPHA_FLOAT16
:
1675 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
;
1677 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1678 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
;
1679 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1680 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
;
1682 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1683 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
;
1684 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1685 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
;
1687 case MESA_FORMAT_INTENSITY_FLOAT32
:
1688 return format
== GL_INTENSITY
&& type
== GL_FLOAT
;
1689 case MESA_FORMAT_INTENSITY_FLOAT16
:
1690 return format
== GL_INTENSITY
&& type
== GL_HALF_FLOAT
;
1692 /* FINISHME: What do we want to do for GL_EXT_texture_integer? */
1693 case MESA_FORMAT_ALPHA_UINT8
:
1694 case MESA_FORMAT_ALPHA_UINT16
:
1695 case MESA_FORMAT_ALPHA_UINT32
:
1696 case MESA_FORMAT_ALPHA_INT8
:
1697 case MESA_FORMAT_ALPHA_INT16
:
1698 case MESA_FORMAT_ALPHA_INT32
:
1701 case MESA_FORMAT_INTENSITY_UINT8
:
1702 case MESA_FORMAT_INTENSITY_UINT16
:
1703 case MESA_FORMAT_INTENSITY_UINT32
:
1704 case MESA_FORMAT_INTENSITY_INT8
:
1705 case MESA_FORMAT_INTENSITY_INT16
:
1706 case MESA_FORMAT_INTENSITY_INT32
:
1709 case MESA_FORMAT_LUMINANCE_UINT8
:
1710 case MESA_FORMAT_LUMINANCE_UINT16
:
1711 case MESA_FORMAT_LUMINANCE_UINT32
:
1712 case MESA_FORMAT_LUMINANCE_INT8
:
1713 case MESA_FORMAT_LUMINANCE_INT16
:
1714 case MESA_FORMAT_LUMINANCE_INT32
:
1717 case MESA_FORMAT_LUMINANCE_ALPHA_UINT8
:
1718 case MESA_FORMAT_LUMINANCE_ALPHA_UINT16
:
1719 case MESA_FORMAT_LUMINANCE_ALPHA_UINT32
:
1720 case MESA_FORMAT_LUMINANCE_ALPHA_INT8
:
1721 case MESA_FORMAT_LUMINANCE_ALPHA_INT16
:
1722 case MESA_FORMAT_LUMINANCE_ALPHA_INT32
:
1725 case MESA_FORMAT_RGB_INT8
:
1726 case MESA_FORMAT_RGBA_INT8
:
1727 case MESA_FORMAT_RGB_INT16
:
1728 case MESA_FORMAT_RGBA_INT16
:
1729 case MESA_FORMAT_RGB_INT32
:
1730 case MESA_FORMAT_RGBA_INT32
:
1733 case MESA_FORMAT_RGB_UINT8
:
1734 case MESA_FORMAT_RGBA_UINT8
:
1735 case MESA_FORMAT_RGB_UINT16
:
1736 case MESA_FORMAT_RGBA_UINT16
:
1737 case MESA_FORMAT_RGB_UINT32
:
1738 case MESA_FORMAT_RGBA_UINT32
:
1741 case MESA_FORMAT_SIGNED_RGBA_16
:
1742 case MESA_FORMAT_RGBA_16
:
1743 /* FINISHME: SNORM */