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_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
44 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
45 * GL_COLOR_INDEX, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX,
46 * GL_DEPTH_STENCIL, GL_DUDV_ATI.
51 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
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_XRGB8888
, /* Name */
128 "MESA_FORMAT_XRGB8888", /* 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_XRGB8888_REV
, /* Name */
137 "MESA_FORMAT_XRGB8888_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_RGB888
, /* Name */
146 "MESA_FORMAT_RGB888", /* 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, 3 /* BlockWidth/Height,Bytes */
154 MESA_FORMAT_BGR888
, /* Name */
155 "MESA_FORMAT_BGR888", /* 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, 3 /* BlockWidth/Height,Bytes */
163 MESA_FORMAT_RGB565
, /* Name */
164 "MESA_FORMAT_RGB565", /* StrName */
165 GL_RGB
, /* BaseFormat */
166 GL_UNSIGNED_NORMALIZED
, /* DataType */
167 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
168 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
169 1, 1, 2 /* BlockWidth/Height,Bytes */
172 MESA_FORMAT_RGB565_REV
, /* Name */
173 "MESA_FORMAT_RGB565_REV", /* StrName */
174 GL_RGB
, /* BaseFormat */
175 GL_UNSIGNED_NORMALIZED
, /* DataType */
176 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
177 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
178 1, 1, 2 /* BlockWidth/Height,Bytes */
181 MESA_FORMAT_ARGB4444
, /* Name */
182 "MESA_FORMAT_ARGB4444", /* StrName */
183 GL_RGBA
, /* BaseFormat */
184 GL_UNSIGNED_NORMALIZED
, /* DataType */
185 4, 4, 4, 4, /* 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_ARGB4444_REV
, /* Name */
191 "MESA_FORMAT_ARGB4444_REV", /* StrName */
192 GL_RGBA
, /* BaseFormat */
193 GL_UNSIGNED_NORMALIZED
, /* DataType */
194 4, 4, 4, 4, /* 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_RGBA5551
, /* Name */
200 "MESA_FORMAT_RGBA5551", /* StrName */
201 GL_RGBA
, /* BaseFormat */
202 GL_UNSIGNED_NORMALIZED
, /* DataType */
203 5, 5, 5, 1, /* 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_ARGB1555
, /* Name */
209 "MESA_FORMAT_ARGB1555", /* StrName */
210 GL_RGBA
, /* BaseFormat */
211 GL_UNSIGNED_NORMALIZED
, /* DataType */
212 5, 5, 5, 1, /* 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_ARGB1555_REV
, /* Name */
218 "MESA_FORMAT_ARGB1555_REV", /* 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_AL44
, /* Name */
227 "MESA_FORMAT_AL44", /* StrName */
228 GL_LUMINANCE_ALPHA
, /* BaseFormat */
229 GL_UNSIGNED_NORMALIZED
, /* DataType */
230 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
231 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
232 1, 1, 1 /* BlockWidth/Height,Bytes */
235 MESA_FORMAT_AL88
, /* Name */
236 "MESA_FORMAT_AL88", /* StrName */
237 GL_LUMINANCE_ALPHA
, /* BaseFormat */
238 GL_UNSIGNED_NORMALIZED
, /* DataType */
239 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
240 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
241 1, 1, 2 /* BlockWidth/Height,Bytes */
244 MESA_FORMAT_AL88_REV
, /* Name */
245 "MESA_FORMAT_AL88_REV", /* StrName */
246 GL_LUMINANCE_ALPHA
, /* BaseFormat */
247 GL_UNSIGNED_NORMALIZED
, /* DataType */
248 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
249 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
250 1, 1, 2 /* BlockWidth/Height,Bytes */
253 MESA_FORMAT_AL1616
, /* Name */
254 "MESA_FORMAT_AL1616", /* StrName */
255 GL_LUMINANCE_ALPHA
, /* BaseFormat */
256 GL_UNSIGNED_NORMALIZED
, /* DataType */
257 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
258 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
259 1, 1, 4 /* BlockWidth/Height,Bytes */
262 MESA_FORMAT_AL1616_REV
, /* Name */
263 "MESA_FORMAT_AL1616_REV", /* StrName */
264 GL_LUMINANCE_ALPHA
, /* BaseFormat */
265 GL_UNSIGNED_NORMALIZED
, /* DataType */
266 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
267 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
268 1, 1, 4 /* BlockWidth/Height,Bytes */
271 MESA_FORMAT_RGB332
, /* Name */
272 "MESA_FORMAT_RGB332", /* StrName */
273 GL_RGB
, /* BaseFormat */
274 GL_UNSIGNED_NORMALIZED
, /* DataType */
275 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
276 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
277 1, 1, 1 /* BlockWidth/Height,Bytes */
280 MESA_FORMAT_A8
, /* Name */
281 "MESA_FORMAT_A8", /* StrName */
282 GL_ALPHA
, /* BaseFormat */
283 GL_UNSIGNED_NORMALIZED
, /* DataType */
284 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
285 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
286 1, 1, 1 /* BlockWidth/Height,Bytes */
289 MESA_FORMAT_A16
, /* Name */
290 "MESA_FORMAT_A16", /* StrName */
291 GL_ALPHA
, /* BaseFormat */
292 GL_UNSIGNED_NORMALIZED
, /* DataType */
293 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
294 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
295 1, 1, 2 /* BlockWidth/Height,Bytes */
298 MESA_FORMAT_L8
, /* Name */
299 "MESA_FORMAT_L8", /* StrName */
300 GL_LUMINANCE
, /* BaseFormat */
301 GL_UNSIGNED_NORMALIZED
, /* DataType */
302 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
303 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
304 1, 1, 1 /* BlockWidth/Height,Bytes */
307 MESA_FORMAT_L16
, /* Name */
308 "MESA_FORMAT_L16", /* StrName */
309 GL_LUMINANCE
, /* BaseFormat */
310 GL_UNSIGNED_NORMALIZED
, /* DataType */
311 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
312 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
313 1, 1, 2 /* BlockWidth/Height,Bytes */
316 MESA_FORMAT_I8
, /* Name */
317 "MESA_FORMAT_I8", /* StrName */
318 GL_INTENSITY
, /* BaseFormat */
319 GL_UNSIGNED_NORMALIZED
, /* DataType */
320 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
321 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
322 1, 1, 1 /* BlockWidth/Height,Bytes */
325 MESA_FORMAT_I16
, /* Name */
326 "MESA_FORMAT_I16", /* StrName */
327 GL_INTENSITY
, /* BaseFormat */
328 GL_UNSIGNED_NORMALIZED
, /* DataType */
329 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
330 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
331 1, 1, 2 /* BlockWidth/Height,Bytes */
334 MESA_FORMAT_CI8
, /* Name */
335 "MESA_FORMAT_CI8", /* StrName */
336 GL_COLOR_INDEX
, /* BaseFormat */
337 GL_UNSIGNED_INT
, /* DataType */
338 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
339 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
340 1, 1, 1 /* BlockWidth/Height,Bytes */
343 MESA_FORMAT_YCBCR
, /* Name */
344 "MESA_FORMAT_YCBCR", /* StrName */
345 GL_YCBCR_MESA
, /* BaseFormat */
346 GL_UNSIGNED_NORMALIZED
, /* DataType */
347 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
348 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
349 1, 1, 2 /* BlockWidth/Height,Bytes */
352 MESA_FORMAT_YCBCR_REV
, /* Name */
353 "MESA_FORMAT_YCBCR_REV", /* 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 */
364 GL_UNSIGNED_NORMALIZED
,
373 GL_UNSIGNED_NORMALIZED
,
379 MESA_FORMAT_RG88_REV
,
380 "MESA_FORMAT_RG88_REV",
382 GL_UNSIGNED_NORMALIZED
,
391 GL_UNSIGNED_NORMALIZED
,
398 "MESA_FORMAT_RG1616",
400 GL_UNSIGNED_NORMALIZED
,
406 MESA_FORMAT_RG1616_REV
,
407 "MESA_FORMAT_RG1616_REV",
409 GL_UNSIGNED_NORMALIZED
,
415 MESA_FORMAT_ARGB2101010
,
416 "MESA_FORMAT_ARGB2101010",
418 GL_UNSIGNED_NORMALIZED
,
424 MESA_FORMAT_Z24_S8
, /* Name */
425 "MESA_FORMAT_Z24_S8", /* StrName */
426 GL_DEPTH_STENCIL
, /* BaseFormat */
427 GL_UNSIGNED_INT
, /* DataType */
428 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
429 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
430 1, 1, 4 /* BlockWidth/Height,Bytes */
433 MESA_FORMAT_S8_Z24
, /* Name */
434 "MESA_FORMAT_S8_Z24", /* StrName */
435 GL_DEPTH_STENCIL
, /* BaseFormat */
436 GL_UNSIGNED_INT
, /* DataType */
437 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
438 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
439 1, 1, 4 /* BlockWidth/Height,Bytes */
442 MESA_FORMAT_Z16
, /* Name */
443 "MESA_FORMAT_Z16", /* StrName */
444 GL_DEPTH_COMPONENT
, /* BaseFormat */
445 GL_UNSIGNED_INT
, /* DataType */
446 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
447 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
448 1, 1, 2 /* BlockWidth/Height,Bytes */
451 MESA_FORMAT_X8_Z24
, /* Name */
452 "MESA_FORMAT_X8_Z24", /* StrName */
453 GL_DEPTH_COMPONENT
, /* BaseFormat */
454 GL_UNSIGNED_INT
, /* DataType */
455 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
456 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
457 1, 1, 4 /* BlockWidth/Height,Bytes */
460 MESA_FORMAT_Z24_X8
, /* Name */
461 "MESA_FORMAT_Z24_X8", /* StrName */
462 GL_DEPTH_COMPONENT
, /* BaseFormat */
463 GL_UNSIGNED_INT
, /* DataType */
464 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
465 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
466 1, 1, 4 /* BlockWidth/Height,Bytes */
469 MESA_FORMAT_Z32
, /* Name */
470 "MESA_FORMAT_Z32", /* StrName */
471 GL_DEPTH_COMPONENT
, /* BaseFormat */
472 GL_UNSIGNED_INT
, /* DataType */
473 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
474 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
475 1, 1, 4 /* BlockWidth/Height,Bytes */
478 MESA_FORMAT_S8
, /* Name */
479 "MESA_FORMAT_S8", /* StrName */
480 GL_STENCIL_INDEX
, /* BaseFormat */
481 GL_UNSIGNED_INT
, /* DataType */
482 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
483 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
484 1, 1, 1 /* BlockWidth/Height,Bytes */
490 GL_UNSIGNED_NORMALIZED
,
497 "MESA_FORMAT_SRGBA8",
499 GL_UNSIGNED_NORMALIZED
,
506 "MESA_FORMAT_SARGB8",
508 GL_UNSIGNED_NORMALIZED
,
517 GL_UNSIGNED_NORMALIZED
,
526 GL_UNSIGNED_NORMALIZED
,
532 MESA_FORMAT_SRGB_DXT1
, /* Name */
533 "MESA_FORMAT_SRGB_DXT1", /* StrName */
534 GL_RGB
, /* BaseFormat */
535 GL_UNSIGNED_NORMALIZED
, /* DataType */
536 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
537 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
538 4, 4, 8 /* 8 bytes per 4x4 block */
541 MESA_FORMAT_SRGBA_DXT1
,
542 "MESA_FORMAT_SRGBA_DXT1",
544 GL_UNSIGNED_NORMALIZED
,
547 4, 4, 8 /* 8 bytes per 4x4 block */
550 MESA_FORMAT_SRGBA_DXT3
,
551 "MESA_FORMAT_SRGBA_DXT3",
553 GL_UNSIGNED_NORMALIZED
,
556 4, 4, 16 /* 16 bytes per 4x4 block */
559 MESA_FORMAT_SRGBA_DXT5
,
560 "MESA_FORMAT_SRGBA_DXT5",
562 GL_UNSIGNED_NORMALIZED
,
565 4, 4, 16 /* 16 bytes per 4x4 block */
569 MESA_FORMAT_RGB_FXT1
,
570 "MESA_FORMAT_RGB_FXT1",
572 GL_UNSIGNED_NORMALIZED
,
573 4, 4, 4, 0, /* approx Red/Green/BlueBits */
575 8, 4, 16 /* 16 bytes per 8x4 block */
578 MESA_FORMAT_RGBA_FXT1
,
579 "MESA_FORMAT_RGBA_FXT1",
581 GL_UNSIGNED_NORMALIZED
,
582 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
584 8, 4, 16 /* 16 bytes per 8x4 block */
588 MESA_FORMAT_RGB_DXT1
, /* Name */
589 "MESA_FORMAT_RGB_DXT1", /* StrName */
590 GL_RGB
, /* BaseFormat */
591 GL_UNSIGNED_NORMALIZED
, /* DataType */
592 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
593 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
594 4, 4, 8 /* 8 bytes per 4x4 block */
597 MESA_FORMAT_RGBA_DXT1
,
598 "MESA_FORMAT_RGBA_DXT1",
600 GL_UNSIGNED_NORMALIZED
,
603 4, 4, 8 /* 8 bytes per 4x4 block */
606 MESA_FORMAT_RGBA_DXT3
,
607 "MESA_FORMAT_RGBA_DXT3",
609 GL_UNSIGNED_NORMALIZED
,
612 4, 4, 16 /* 16 bytes per 4x4 block */
615 MESA_FORMAT_RGBA_DXT5
,
616 "MESA_FORMAT_RGBA_DXT5",
618 GL_UNSIGNED_NORMALIZED
,
621 4, 4, 16 /* 16 bytes per 4x4 block */
624 MESA_FORMAT_RGBA_FLOAT32
,
625 "MESA_FORMAT_RGBA_FLOAT32",
633 MESA_FORMAT_RGBA_FLOAT16
,
634 "MESA_FORMAT_RGBA_FLOAT16",
642 MESA_FORMAT_RGB_FLOAT32
,
643 "MESA_FORMAT_RGB_FLOAT32",
651 MESA_FORMAT_RGB_FLOAT16
,
652 "MESA_FORMAT_RGB_FLOAT16",
660 MESA_FORMAT_ALPHA_FLOAT32
,
661 "MESA_FORMAT_ALPHA_FLOAT32",
669 MESA_FORMAT_ALPHA_FLOAT16
,
670 "MESA_FORMAT_ALPHA_FLOAT16",
678 MESA_FORMAT_LUMINANCE_FLOAT32
,
679 "MESA_FORMAT_LUMINANCE_FLOAT32",
687 MESA_FORMAT_LUMINANCE_FLOAT16
,
688 "MESA_FORMAT_LUMINANCE_FLOAT16",
696 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
697 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
705 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
706 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
714 MESA_FORMAT_INTENSITY_FLOAT32
,
715 "MESA_FORMAT_INTENSITY_FLOAT32",
723 MESA_FORMAT_INTENSITY_FLOAT16
,
724 "MESA_FORMAT_INTENSITY_FLOAT16",
732 MESA_FORMAT_R_FLOAT32
,
733 "MESA_FORMAT_R_FLOAT32",
741 MESA_FORMAT_R_FLOAT16
,
742 "MESA_FORMAT_R_FLOAT16",
750 MESA_FORMAT_RG_FLOAT32
,
751 "MESA_FORMAT_RG_FLOAT32",
759 MESA_FORMAT_RG_FLOAT16
,
760 "MESA_FORMAT_RG_FLOAT16",
768 /* unnormalized signed int formats */
770 MESA_FORMAT_RGBA_INT8
,
771 "MESA_FORMAT_RGBA_INT8",
779 MESA_FORMAT_RGBA_INT16
,
780 "MESA_FORMAT_RGBA_INT16",
788 MESA_FORMAT_RGBA_INT32
,
789 "MESA_FORMAT_RGBA_INT32",
797 /* unnormalized unsigned int formats */
799 MESA_FORMAT_RGBA_UINT8
,
800 "MESA_FORMAT_RGBA_UINT8",
808 MESA_FORMAT_RGBA_UINT16
,
809 "MESA_FORMAT_RGBA_UINT16",
817 MESA_FORMAT_RGBA_UINT32
,
818 "MESA_FORMAT_RGBA_UINT32",
831 GL_SIGNED_NORMALIZED
,
837 /* Signed 8 bits / channel */
839 MESA_FORMAT_SIGNED_R8
, /* Name */
840 "MESA_FORMAT_SIGNED_R8", /* StrName */
841 GL_RED
, /* BaseFormat */
842 GL_SIGNED_NORMALIZED
, /* DataType */
843 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
844 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
845 1, 1, 1 /* BlockWidth/Height,Bytes */
848 MESA_FORMAT_SIGNED_RG88_REV
,
849 "MESA_FORMAT_SIGNED_RG88_REV",
851 GL_SIGNED_NORMALIZED
,
857 MESA_FORMAT_SIGNED_RGBX8888
,
858 "MESA_FORMAT_SIGNED_RGBX8888",
860 GL_SIGNED_NORMALIZED
,
863 1, 1, 4 /* 4 bpp, but no alpha */
866 MESA_FORMAT_SIGNED_RGBA8888
,
867 "MESA_FORMAT_SIGNED_RGBA8888",
869 GL_SIGNED_NORMALIZED
,
875 MESA_FORMAT_SIGNED_RGBA8888_REV
,
876 "MESA_FORMAT_SIGNED_RGBA8888_REV",
878 GL_SIGNED_NORMALIZED
,
884 /* Signed 16 bits / channel */
886 MESA_FORMAT_SIGNED_R16
,
887 "MESA_FORMAT_SIGNED_R16",
889 GL_SIGNED_NORMALIZED
,
895 MESA_FORMAT_SIGNED_GR1616
,
896 "MESA_FORMAT_SIGNED_GR1616",
898 GL_SIGNED_NORMALIZED
,
904 MESA_FORMAT_SIGNED_RGB_16
,
905 "MESA_FORMAT_SIGNED_RGB_16",
907 GL_SIGNED_NORMALIZED
,
913 MESA_FORMAT_SIGNED_RGBA_16
,
914 "MESA_FORMAT_SIGNED_RGBA_16",
916 GL_SIGNED_NORMALIZED
,
923 "MESA_FORMAT_RGBA_16",
925 GL_UNSIGNED_NORMALIZED
,
931 MESA_FORMAT_RED_RGTC1
,
932 "MESA_FORMAT_RED_RGTC1",
934 GL_UNSIGNED_NORMALIZED
,
937 4, 4, 8 /* 8 bytes per 4x4 block */
940 MESA_FORMAT_SIGNED_RED_RGTC1
,
941 "MESA_FORMAT_SIGNED_RED_RGTC1",
943 GL_SIGNED_NORMALIZED
,
946 4, 4, 8 /* 8 bytes per 4x4 block */
949 MESA_FORMAT_RG_RGTC2
,
950 "MESA_FORMAT_RG_RGTC2",
952 GL_UNSIGNED_NORMALIZED
,
955 4, 4, 16 /* 16 bytes per 4x4 block */
958 MESA_FORMAT_SIGNED_RG_RGTC2
,
959 "MESA_FORMAT_SIGNED_RG_RGTC2",
961 GL_SIGNED_NORMALIZED
,
964 4, 4, 16 /* 16 bytes per 4x4 block */
968 "MESA_FORMAT_L_LATC1",
970 GL_UNSIGNED_NORMALIZED
,
973 4, 4, 8 /* 8 bytes per 4x4 block */
976 MESA_FORMAT_SIGNED_L_LATC1
,
977 "MESA_FORMAT_SIGNED_L_LATC1",
979 GL_SIGNED_NORMALIZED
,
982 4, 4, 8 /* 8 bytes per 4x4 block */
985 MESA_FORMAT_LA_LATC2
,
986 "MESA_FORMAT_LA_LATC2",
988 GL_UNSIGNED_NORMALIZED
,
991 4, 4, 16 /* 16 bytes per 4x4 block */
994 MESA_FORMAT_SIGNED_LA_LATC2
,
995 "MESA_FORMAT_SIGNED_LA_LATC2",
997 GL_SIGNED_NORMALIZED
,
1000 4, 4, 16 /* 16 bytes per 4x4 block */
1003 /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
1005 MESA_FORMAT_SIGNED_A8
,
1006 "MESA_FORMAT_SIGNED_A8",
1008 GL_SIGNED_NORMALIZED
,
1014 MESA_FORMAT_SIGNED_L8
,
1015 "MESA_FORMAT_SIGNED_L8",
1017 GL_SIGNED_NORMALIZED
,
1023 MESA_FORMAT_SIGNED_AL88
,
1024 "MESA_FORMAT_SIGNED_AL88",
1026 GL_SIGNED_NORMALIZED
,
1032 MESA_FORMAT_SIGNED_I8
,
1033 "MESA_FORMAT_SIGNED_I8",
1035 GL_SIGNED_NORMALIZED
,
1041 MESA_FORMAT_SIGNED_A16
,
1042 "MESA_FORMAT_SIGNED_A16",
1044 GL_SIGNED_NORMALIZED
,
1050 MESA_FORMAT_SIGNED_L16
,
1051 "MESA_FORMAT_SIGNED_L16",
1053 GL_SIGNED_NORMALIZED
,
1059 MESA_FORMAT_SIGNED_AL1616
,
1060 "MESA_FORMAT_SIGNED_AL1616",
1062 GL_SIGNED_NORMALIZED
,
1068 MESA_FORMAT_SIGNED_I16
,
1069 "MESA_FORMAT_SIGNED_I16",
1071 GL_SIGNED_NORMALIZED
,
1077 MESA_FORMAT_RGB9_E5_FLOAT
,
1078 "MESA_FORMAT_RGB9_E5",
1086 MESA_FORMAT_R11_G11_B10_FLOAT
,
1087 "MESA_FORMAT_R11_G11_B10_FLOAT",
1094 /* ARB_depth_buffer_float */
1096 MESA_FORMAT_Z32_FLOAT
, /* Name */
1097 "MESA_FORMAT_Z32_FLOAT", /* StrName */
1098 GL_DEPTH_COMPONENT
, /* BaseFormat */
1099 GL_FLOAT
, /* DataType */
1100 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1101 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
1102 1, 1, 4 /* BlockWidth/Height,Bytes */
1105 MESA_FORMAT_Z32_FLOAT_X24S8
, /* Name */
1106 "MESA_FORMAT_Z32_FLOAT_X24S8", /* StrName */
1107 GL_DEPTH_STENCIL
, /* BaseFormat */
1108 GL_NONE
/* XXX */, /* DataType */
1109 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1110 0, 0, 0, 32, 8, /* Lum/Int/Index/Depth/StencilBits */
1111 1, 1, 8 /* BlockWidth/Height,Bytes */
1117 static const struct gl_format_info
*
1118 _mesa_get_format_info(gl_format format
)
1120 const struct gl_format_info
*info
= &format_info
[format
];
1121 assert(info
->Name
== format
);
1126 /** Return string name of format (for debugging) */
1128 _mesa_get_format_name(gl_format format
)
1130 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1131 return info
->StrName
;
1137 * Return bytes needed to store a block of pixels in the given format.
1138 * Normally, a block is 1x1 (a single pixel). But for compressed formats
1139 * a block may be 4x4 or 8x4, etc.
1141 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
1144 _mesa_get_format_bytes(gl_format format
)
1146 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1147 ASSERT(info
->BytesPerBlock
);
1148 return info
->BytesPerBlock
;
1153 * Return bits per component for the given format.
1154 * \param format one of MESA_FORMAT_x
1155 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
1158 _mesa_get_format_bits(gl_format format
, GLenum pname
)
1160 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1164 case GL_TEXTURE_RED_SIZE
:
1165 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1166 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1167 return info
->RedBits
;
1169 case GL_TEXTURE_GREEN_SIZE
:
1170 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1171 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1172 return info
->GreenBits
;
1174 case GL_TEXTURE_BLUE_SIZE
:
1175 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1176 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1177 return info
->BlueBits
;
1179 case GL_TEXTURE_ALPHA_SIZE
:
1180 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1181 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1182 return info
->AlphaBits
;
1183 case GL_TEXTURE_INTENSITY_SIZE
:
1184 return info
->IntensityBits
;
1185 case GL_TEXTURE_LUMINANCE_SIZE
:
1186 return info
->LuminanceBits
;
1188 case GL_TEXTURE_INDEX_SIZE_EXT
:
1189 return info
->IndexBits
;
1191 case GL_TEXTURE_DEPTH_SIZE_ARB
:
1192 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1193 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1194 return info
->DepthBits
;
1195 case GL_STENCIL_BITS
:
1196 case GL_TEXTURE_STENCIL_SIZE_EXT
:
1197 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1198 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1199 return info
->StencilBits
;
1201 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
1208 * Return the data type (or more specifically, the data representation)
1209 * for the given format.
1210 * The return value will be one of:
1211 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
1212 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
1213 * GL_UNSIGNED_INT = an ordinary unsigned integer
1214 * GL_INT = an ordinary signed integer
1215 * GL_FLOAT = an ordinary float
1218 _mesa_get_format_datatype(gl_format format
)
1220 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1221 return info
->DataType
;
1226 * Return the basic format for the given type. The result will be
1227 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
1228 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
1229 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
1232 _mesa_get_format_base_format(gl_format format
)
1234 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1235 return info
->BaseFormat
;
1240 * Return the block size (in pixels) for the given format. Normally
1241 * the block size is 1x1. But compressed formats will have block sizes
1242 * of 4x4 or 8x4 pixels, etc.
1243 * \param bw returns block width in pixels
1244 * \param bh returns block height in pixels
1247 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
1249 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1250 *bw
= info
->BlockWidth
;
1251 *bh
= info
->BlockHeight
;
1255 /** Is the given format a compressed format? */
1257 _mesa_is_format_compressed(gl_format format
)
1259 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1260 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
1265 * Determine if the given format represents a packed depth/stencil buffer.
1268 _mesa_is_format_packed_depth_stencil(gl_format format
)
1270 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1272 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
1277 * Is the given format a signed/unsigned integer color format?
1280 _mesa_is_format_integer_color(gl_format format
)
1282 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1283 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
1284 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
1285 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
1286 info
->BaseFormat
!= GL_STENCIL_INDEX
;
1291 * Return color encoding for given format.
1292 * \return GL_LINEAR or GL_SRGB
1295 _mesa_get_format_color_encoding(gl_format format
)
1297 /* XXX this info should be encoded in gl_format_info */
1299 case MESA_FORMAT_SRGB8
:
1300 case MESA_FORMAT_SRGBA8
:
1301 case MESA_FORMAT_SARGB8
:
1302 case MESA_FORMAT_SL8
:
1303 case MESA_FORMAT_SLA8
:
1304 case MESA_FORMAT_SRGB_DXT1
:
1305 case MESA_FORMAT_SRGBA_DXT1
:
1306 case MESA_FORMAT_SRGBA_DXT3
:
1307 case MESA_FORMAT_SRGBA_DXT5
:
1316 * For an sRGB format, return the corresponding linear color space format.
1317 * For non-sRGB formats, return the format as-is.
1320 _mesa_get_srgb_format_linear(gl_format format
)
1323 case MESA_FORMAT_SRGB8
:
1324 format
= MESA_FORMAT_RGB888
;
1326 case MESA_FORMAT_SRGBA8
:
1327 format
= MESA_FORMAT_RGBA8888
;
1329 case MESA_FORMAT_SARGB8
:
1330 format
= MESA_FORMAT_ARGB8888
;
1332 case MESA_FORMAT_SL8
:
1333 format
= MESA_FORMAT_L8
;
1335 case MESA_FORMAT_SLA8
:
1336 format
= MESA_FORMAT_AL88
;
1338 case MESA_FORMAT_SRGB_DXT1
:
1339 format
= MESA_FORMAT_RGB_DXT1
;
1341 case MESA_FORMAT_SRGBA_DXT1
:
1342 format
= MESA_FORMAT_RGBA_DXT1
;
1344 case MESA_FORMAT_SRGBA_DXT3
:
1345 format
= MESA_FORMAT_RGBA_DXT3
;
1347 case MESA_FORMAT_SRGBA_DXT5
:
1348 format
= MESA_FORMAT_RGBA_DXT5
;
1358 * Return number of bytes needed to store an image of the given size
1359 * in the given format.
1362 _mesa_format_image_size(gl_format format
, GLsizei width
,
1363 GLsizei height
, GLsizei depth
)
1365 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1366 /* Strictly speaking, a conditional isn't needed here */
1367 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1368 /* compressed format (2D only for now) */
1369 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
1370 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1371 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
1372 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1377 /* non-compressed */
1378 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
1385 * Same as _mesa_format_image_size() but returns a 64-bit value to
1386 * accomodate very large textures.
1389 _mesa_format_image_size64(gl_format format
, GLsizei width
,
1390 GLsizei height
, GLsizei depth
)
1392 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1393 /* Strictly speaking, a conditional isn't needed here */
1394 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1395 /* compressed format (2D only for now) */
1396 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
1397 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
1398 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
1399 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
1404 /* non-compressed */
1405 const uint64_t sz
= ((uint64_t) width
*
1408 info
->BytesPerBlock
);
1416 _mesa_format_row_stride(gl_format format
, GLsizei width
)
1418 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
1419 /* Strictly speaking, a conditional isn't needed here */
1420 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
1421 /* compressed format */
1422 const GLuint bw
= info
->BlockWidth
;
1423 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
1424 const GLint stride
= wblocks
* info
->BytesPerBlock
;
1428 const GLint stride
= width
* info
->BytesPerBlock
;
1435 * Debug/test: check that all formats are handled in the
1436 * _mesa_format_to_type_and_comps() function. When new pixel formats
1437 * are added to Mesa, that function needs to be updated.
1438 * This is a no-op after the first call.
1441 check_format_to_type_and_comps(void)
1445 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
1446 GLenum datatype
= 0;
1448 /* This function will emit a problem/warning if the format is
1451 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
1457 * Do sanity checking of the format info table.
1460 _mesa_test_formats(void)
1464 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
1466 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
1467 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
1470 assert(info
->Name
== i
);
1472 if (info
->Name
== MESA_FORMAT_NONE
)
1475 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
1476 if (info
->RedBits
> 0) {
1477 GLuint t
= info
->RedBits
+ info
->GreenBits
1478 + info
->BlueBits
+ info
->AlphaBits
;
1479 assert(t
/ 8 <= info
->BytesPerBlock
);
1484 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
1485 info
->DataType
== GL_SIGNED_NORMALIZED
||
1486 info
->DataType
== GL_UNSIGNED_INT
||
1487 info
->DataType
== GL_INT
||
1488 info
->DataType
== GL_FLOAT
);
1490 if (info
->BaseFormat
== GL_RGB
) {
1491 assert(info
->RedBits
> 0);
1492 assert(info
->GreenBits
> 0);
1493 assert(info
->BlueBits
> 0);
1494 assert(info
->AlphaBits
== 0);
1495 assert(info
->LuminanceBits
== 0);
1496 assert(info
->IntensityBits
== 0);
1498 else if (info
->BaseFormat
== GL_RGBA
) {
1499 assert(info
->RedBits
> 0);
1500 assert(info
->GreenBits
> 0);
1501 assert(info
->BlueBits
> 0);
1502 assert(info
->AlphaBits
> 0);
1503 assert(info
->LuminanceBits
== 0);
1504 assert(info
->IntensityBits
== 0);
1506 else if (info
->BaseFormat
== GL_RG
) {
1507 assert(info
->RedBits
> 0);
1508 assert(info
->GreenBits
> 0);
1509 assert(info
->BlueBits
== 0);
1510 assert(info
->AlphaBits
== 0);
1511 assert(info
->LuminanceBits
== 0);
1512 assert(info
->IntensityBits
== 0);
1514 else if (info
->BaseFormat
== GL_RED
) {
1515 assert(info
->RedBits
> 0);
1516 assert(info
->GreenBits
== 0);
1517 assert(info
->BlueBits
== 0);
1518 assert(info
->AlphaBits
== 0);
1519 assert(info
->LuminanceBits
== 0);
1520 assert(info
->IntensityBits
== 0);
1522 else if (info
->BaseFormat
== GL_LUMINANCE
) {
1523 assert(info
->RedBits
== 0);
1524 assert(info
->GreenBits
== 0);
1525 assert(info
->BlueBits
== 0);
1526 assert(info
->AlphaBits
== 0);
1527 assert(info
->LuminanceBits
> 0);
1528 assert(info
->IntensityBits
== 0);
1530 else if (info
->BaseFormat
== GL_INTENSITY
) {
1531 assert(info
->RedBits
== 0);
1532 assert(info
->GreenBits
== 0);
1533 assert(info
->BlueBits
== 0);
1534 assert(info
->AlphaBits
== 0);
1535 assert(info
->LuminanceBits
== 0);
1536 assert(info
->IntensityBits
> 0);
1540 check_format_to_type_and_comps();
1546 * Return datatype and number of components per texel for the given gl_format.
1547 * Only used for mipmap generation code.
1550 _mesa_format_to_type_and_comps(gl_format format
,
1551 GLenum
*datatype
, GLuint
*comps
)
1554 case MESA_FORMAT_RGBA8888
:
1555 case MESA_FORMAT_RGBA8888_REV
:
1556 case MESA_FORMAT_ARGB8888
:
1557 case MESA_FORMAT_ARGB8888_REV
:
1558 case MESA_FORMAT_XRGB8888
:
1559 case MESA_FORMAT_XRGB8888_REV
:
1560 *datatype
= GL_UNSIGNED_BYTE
;
1563 case MESA_FORMAT_RGB888
:
1564 case MESA_FORMAT_BGR888
:
1565 *datatype
= GL_UNSIGNED_BYTE
;
1568 case MESA_FORMAT_RGB565
:
1569 case MESA_FORMAT_RGB565_REV
:
1570 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1574 case MESA_FORMAT_ARGB4444
:
1575 case MESA_FORMAT_ARGB4444_REV
:
1576 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1580 case MESA_FORMAT_ARGB1555
:
1581 case MESA_FORMAT_ARGB1555_REV
:
1582 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1586 case MESA_FORMAT_ARGB2101010
:
1587 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1591 case MESA_FORMAT_RGBA5551
:
1592 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1596 case MESA_FORMAT_AL44
:
1597 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1601 case MESA_FORMAT_AL88
:
1602 case MESA_FORMAT_AL88_REV
:
1603 case MESA_FORMAT_RG88
:
1604 case MESA_FORMAT_RG88_REV
:
1605 *datatype
= GL_UNSIGNED_BYTE
;
1609 case MESA_FORMAT_AL1616
:
1610 case MESA_FORMAT_AL1616_REV
:
1611 case MESA_FORMAT_RG1616
:
1612 case MESA_FORMAT_RG1616_REV
:
1613 *datatype
= GL_UNSIGNED_SHORT
;
1617 case MESA_FORMAT_R16
:
1618 case MESA_FORMAT_A16
:
1619 case MESA_FORMAT_L16
:
1620 case MESA_FORMAT_I16
:
1621 *datatype
= GL_UNSIGNED_SHORT
;
1625 case MESA_FORMAT_RGB332
:
1626 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1630 case MESA_FORMAT_A8
:
1631 case MESA_FORMAT_L8
:
1632 case MESA_FORMAT_I8
:
1633 case MESA_FORMAT_CI8
:
1634 case MESA_FORMAT_R8
:
1635 case MESA_FORMAT_S8
:
1636 *datatype
= GL_UNSIGNED_BYTE
;
1640 case MESA_FORMAT_YCBCR
:
1641 case MESA_FORMAT_YCBCR_REV
:
1642 *datatype
= GL_UNSIGNED_SHORT
;
1646 case MESA_FORMAT_Z24_S8
:
1647 *datatype
= GL_UNSIGNED_INT
;
1648 *comps
= 1; /* XXX OK? */
1651 case MESA_FORMAT_S8_Z24
:
1652 *datatype
= GL_UNSIGNED_INT
;
1653 *comps
= 1; /* XXX OK? */
1656 case MESA_FORMAT_Z16
:
1657 *datatype
= GL_UNSIGNED_SHORT
;
1661 case MESA_FORMAT_X8_Z24
:
1662 *datatype
= GL_UNSIGNED_INT
;
1666 case MESA_FORMAT_Z24_X8
:
1667 *datatype
= GL_UNSIGNED_INT
;
1671 case MESA_FORMAT_Z32
:
1672 *datatype
= GL_UNSIGNED_INT
;
1676 case MESA_FORMAT_Z32_FLOAT
:
1677 *datatype
= GL_FLOAT
;
1681 case MESA_FORMAT_Z32_FLOAT_X24S8
:
1682 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1686 case MESA_FORMAT_DUDV8
:
1687 *datatype
= GL_BYTE
;
1691 case MESA_FORMAT_SIGNED_R8
:
1692 case MESA_FORMAT_SIGNED_A8
:
1693 case MESA_FORMAT_SIGNED_L8
:
1694 case MESA_FORMAT_SIGNED_I8
:
1695 *datatype
= GL_BYTE
;
1698 case MESA_FORMAT_SIGNED_RG88_REV
:
1699 case MESA_FORMAT_SIGNED_AL88
:
1700 *datatype
= GL_BYTE
;
1703 case MESA_FORMAT_SIGNED_RGBA8888
:
1704 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1705 case MESA_FORMAT_SIGNED_RGBX8888
:
1706 *datatype
= GL_BYTE
;
1710 case MESA_FORMAT_RGBA_16
:
1711 *datatype
= GL_UNSIGNED_SHORT
;
1715 case MESA_FORMAT_SIGNED_R16
:
1716 case MESA_FORMAT_SIGNED_A16
:
1717 case MESA_FORMAT_SIGNED_L16
:
1718 case MESA_FORMAT_SIGNED_I16
:
1719 *datatype
= GL_SHORT
;
1722 case MESA_FORMAT_SIGNED_GR1616
:
1723 case MESA_FORMAT_SIGNED_AL1616
:
1724 *datatype
= GL_SHORT
;
1727 case MESA_FORMAT_SIGNED_RGB_16
:
1728 *datatype
= GL_SHORT
;
1731 case MESA_FORMAT_SIGNED_RGBA_16
:
1732 *datatype
= GL_SHORT
;
1736 #if FEATURE_EXT_texture_sRGB
1737 case MESA_FORMAT_SRGB8
:
1738 *datatype
= GL_UNSIGNED_BYTE
;
1741 case MESA_FORMAT_SRGBA8
:
1742 case MESA_FORMAT_SARGB8
:
1743 *datatype
= GL_UNSIGNED_BYTE
;
1746 case MESA_FORMAT_SL8
:
1747 *datatype
= GL_UNSIGNED_BYTE
;
1750 case MESA_FORMAT_SLA8
:
1751 *datatype
= GL_UNSIGNED_BYTE
;
1756 #if FEATURE_texture_fxt1
1757 case MESA_FORMAT_RGB_FXT1
:
1758 case MESA_FORMAT_RGBA_FXT1
:
1760 #if FEATURE_texture_s3tc
1761 case MESA_FORMAT_RGB_DXT1
:
1762 case MESA_FORMAT_RGBA_DXT1
:
1763 case MESA_FORMAT_RGBA_DXT3
:
1764 case MESA_FORMAT_RGBA_DXT5
:
1765 #if FEATURE_EXT_texture_sRGB
1766 case MESA_FORMAT_SRGB_DXT1
:
1767 case MESA_FORMAT_SRGBA_DXT1
:
1768 case MESA_FORMAT_SRGBA_DXT3
:
1769 case MESA_FORMAT_SRGBA_DXT5
:
1772 case MESA_FORMAT_RED_RGTC1
:
1773 case MESA_FORMAT_SIGNED_RED_RGTC1
:
1774 case MESA_FORMAT_RG_RGTC2
:
1775 case MESA_FORMAT_SIGNED_RG_RGTC2
:
1776 case MESA_FORMAT_L_LATC1
:
1777 case MESA_FORMAT_SIGNED_L_LATC1
:
1778 case MESA_FORMAT_LA_LATC2
:
1779 case MESA_FORMAT_SIGNED_LA_LATC2
:
1780 /* XXX generate error instead? */
1781 *datatype
= GL_UNSIGNED_BYTE
;
1785 case MESA_FORMAT_RGBA_FLOAT32
:
1786 *datatype
= GL_FLOAT
;
1789 case MESA_FORMAT_RGBA_FLOAT16
:
1790 *datatype
= GL_HALF_FLOAT_ARB
;
1793 case MESA_FORMAT_RGB_FLOAT32
:
1794 *datatype
= GL_FLOAT
;
1797 case MESA_FORMAT_RGB_FLOAT16
:
1798 *datatype
= GL_HALF_FLOAT_ARB
;
1801 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1802 case MESA_FORMAT_RG_FLOAT32
:
1803 *datatype
= GL_FLOAT
;
1806 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1807 case MESA_FORMAT_RG_FLOAT16
:
1808 *datatype
= GL_HALF_FLOAT_ARB
;
1811 case MESA_FORMAT_ALPHA_FLOAT32
:
1812 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1813 case MESA_FORMAT_INTENSITY_FLOAT32
:
1814 case MESA_FORMAT_R_FLOAT32
:
1815 *datatype
= GL_FLOAT
;
1818 case MESA_FORMAT_ALPHA_FLOAT16
:
1819 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1820 case MESA_FORMAT_INTENSITY_FLOAT16
:
1821 case MESA_FORMAT_R_FLOAT16
:
1822 *datatype
= GL_HALF_FLOAT_ARB
;
1826 case MESA_FORMAT_RGBA_INT8
:
1827 *datatype
= GL_BYTE
;
1830 case MESA_FORMAT_RGBA_INT16
:
1831 *datatype
= GL_SHORT
;
1834 case MESA_FORMAT_RGBA_INT32
:
1840 * \name Non-normalized unsigned integer formats.
1842 case MESA_FORMAT_RGBA_UINT8
:
1843 *datatype
= GL_UNSIGNED_BYTE
;
1846 case MESA_FORMAT_RGBA_UINT16
:
1847 *datatype
= GL_UNSIGNED_SHORT
;
1850 case MESA_FORMAT_RGBA_UINT32
:
1851 *datatype
= GL_UNSIGNED_INT
;
1855 case MESA_FORMAT_RGB9_E5_FLOAT
:
1856 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1860 case MESA_FORMAT_R11_G11_B10_FLOAT
:
1861 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1865 case MESA_FORMAT_COUNT
:
1869 case MESA_FORMAT_NONE
:
1870 /* For debug builds, warn if any formats are not handled */
1874 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1875 _mesa_get_format_name(format
));