2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "glformats.h"
31 #include "c11/threads.h"
32 #include "util/hash_table.h"
35 * Information about texture formats.
41 /** text name for debugging */
44 enum mesa_format_layout Layout
;
47 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
48 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
49 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
54 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
55 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
63 GLubyte LuminanceBits
;
64 GLubyte IntensityBits
;
69 * To describe compressed formats. If not compressed, Width=Height=1.
71 GLubyte BlockWidth
, BlockHeight
;
72 GLubyte BytesPerBlock
;
75 mesa_array_format ArrayFormat
;
78 #include "format_info.h"
80 static const struct gl_format_info
*
81 _mesa_get_format_info(mesa_format format
)
83 const struct gl_format_info
*info
= &format_info
[format
];
84 assert(info
->Name
== format
);
89 /** Return string name of format (for debugging) */
91 _mesa_get_format_name(mesa_format format
)
93 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
100 * Return bytes needed to store a block of pixels in the given format.
101 * Normally, a block is 1x1 (a single pixel). But for compressed formats
102 * a block may be 4x4 or 8x4, etc.
104 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
107 _mesa_get_format_bytes(mesa_format format
)
109 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
110 assert(info
->BytesPerBlock
);
111 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
112 _mesa_is_format_compressed(format
));
113 return info
->BytesPerBlock
;
118 * Return bits per component for the given format.
119 * \param format one of MESA_FORMAT_x
120 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
123 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
125 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
129 case GL_TEXTURE_RED_SIZE
:
130 case GL_RENDERBUFFER_RED_SIZE_EXT
:
131 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
132 return info
->RedBits
;
134 case GL_TEXTURE_GREEN_SIZE
:
135 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
136 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
137 return info
->GreenBits
;
139 case GL_TEXTURE_BLUE_SIZE
:
140 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
141 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
142 return info
->BlueBits
;
144 case GL_TEXTURE_ALPHA_SIZE
:
145 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
146 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
147 return info
->AlphaBits
;
148 case GL_TEXTURE_INTENSITY_SIZE
:
149 return info
->IntensityBits
;
150 case GL_TEXTURE_LUMINANCE_SIZE
:
151 return info
->LuminanceBits
;
155 case GL_TEXTURE_DEPTH_SIZE_ARB
:
156 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
157 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
158 return info
->DepthBits
;
159 case GL_STENCIL_BITS
:
160 case GL_TEXTURE_STENCIL_SIZE_EXT
:
161 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
162 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
163 return info
->StencilBits
;
165 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
172 _mesa_get_format_max_bits(mesa_format format
)
174 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
175 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
176 max
= MAX2(max
, info
->BlueBits
);
177 max
= MAX2(max
, info
->AlphaBits
);
178 max
= MAX2(max
, info
->LuminanceBits
);
179 max
= MAX2(max
, info
->IntensityBits
);
180 max
= MAX2(max
, info
->DepthBits
);
181 max
= MAX2(max
, info
->StencilBits
);
187 * Return the layout type of the given format.
188 * The return value will be one of:
189 * MESA_FORMAT_LAYOUT_ARRAY
190 * MESA_FORMAT_LAYOUT_PACKED
191 * MESA_FORMAT_LAYOUT_OTHER
193 extern enum mesa_format_layout
194 _mesa_get_format_layout(mesa_format format
)
196 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
202 * Return the data type (or more specifically, the data representation)
203 * for the given format.
204 * The return value will be one of:
205 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
206 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
207 * GL_UNSIGNED_INT = an ordinary unsigned integer
208 * GL_INT = an ordinary signed integer
209 * GL_FLOAT = an ordinary float
212 _mesa_get_format_datatype(mesa_format format
)
214 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
215 return info
->DataType
;
219 get_base_format_for_array_format(mesa_array_format format
)
224 _mesa_array_format_get_swizzle(format
, swizzle
);
225 num_channels
= _mesa_array_format_get_num_channels(format
);
227 switch (num_channels
) {
229 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
230 * This is not really a problem for now because we only create array
231 * formats from GL format/type combinations, and these cannot specify
238 if (swizzle
[0] == 0 &&
242 return GL_LUMINANCE_ALPHA
;
243 if (swizzle
[0] == 1 &&
247 return GL_LUMINANCE_ALPHA
;
248 if (swizzle
[0] == 0 &&
253 if (swizzle
[0] == 1 &&
260 if (swizzle
[0] == 0 &&
265 if (swizzle
[0] == 0 &&
270 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
272 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
274 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
276 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
281 unreachable("Unsupported format");
285 * Return the basic format for the given type. The result will be one of
286 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
287 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
288 * This functions accepts a mesa_format or a mesa_array_format.
291 _mesa_get_format_base_format(uint32_t format
)
293 if (!_mesa_format_is_mesa_array_format(format
)) {
294 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
295 return info
->BaseFormat
;
297 return get_base_format_for_array_format(format
);
303 * Return the block size (in pixels) for the given format. Normally
304 * the block size is 1x1. But compressed formats will have block sizes
305 * of 4x4 or 8x4 pixels, etc.
306 * \param bw returns block width in pixels
307 * \param bh returns block height in pixels
310 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
312 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
313 *bw
= info
->BlockWidth
;
314 *bh
= info
->BlockHeight
;
319 * Returns the an array of four numbers representing the transformation
320 * from the RGBA or SZ colorspace to the given format. For array formats,
321 * the i'th RGBA component is given by:
323 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
324 * comp = data[swizzle[i]];
325 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
327 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
329 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
330 * // data does not contain a channel of this format
332 * For packed formats, the swizzle gives the number of components left of
333 * the least significant bit.
335 * Compressed formats have no swizzle.
338 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
340 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
341 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
345 _mesa_array_format_flip_channels(mesa_array_format format
)
350 num_channels
= _mesa_array_format_get_num_channels(format
);
351 _mesa_array_format_get_swizzle(format
, swizzle
);
353 if (num_channels
== 1)
356 if (num_channels
== 2) {
357 /* Assert that the swizzle makes sense for 2 channels */
358 for (unsigned i
= 0; i
< 4; i
++)
359 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
361 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
362 _mesa_array_format_set_swizzle(&format
,
363 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
364 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
368 if (num_channels
== 4) {
369 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
370 _mesa_array_format_set_swizzle(&format
,
371 flip
[swizzle
[0]], flip
[swizzle
[1]],
372 flip
[swizzle
[2]], flip
[swizzle
[3]]);
376 unreachable("Invalid array format");
380 _mesa_format_to_array_format(mesa_format format
)
382 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
383 if (!_mesa_little_endian() && info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
384 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
386 return info
->ArrayFormat
;
389 static struct hash_table
*format_array_format_table
;
390 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
393 array_formats_equal(const void *a
, const void *b
)
395 return (intptr_t)a
== (intptr_t)b
;
399 format_array_format_table_init(void)
401 const struct gl_format_info
*info
;
402 mesa_array_format array_format
;
405 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
406 array_formats_equal
);
408 if (!format_array_format_table
) {
409 _mesa_error_no_memory(__func__
);
413 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
414 info
= _mesa_get_format_info(f
);
415 if (!info
->ArrayFormat
)
418 if (_mesa_little_endian()) {
419 array_format
= info
->ArrayFormat
;
421 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
424 /* This can happen and does for some of the BGR formats. Let's take
425 * the first one in the list.
427 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
429 (void *)(intptr_t)array_format
))
432 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
434 (void *)(intptr_t)array_format
,
435 (void *)(intptr_t)f
);
440 _mesa_format_from_array_format(uint32_t array_format
)
442 struct hash_entry
*entry
;
444 assert(_mesa_format_is_mesa_array_format(array_format
));
446 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
448 if (!format_array_format_table
) {
449 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
450 format_array_format_table_exists
= once_flag_init
;
451 return MESA_FORMAT_NONE
;
454 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
456 (void *)(intptr_t)array_format
);
458 return (intptr_t)entry
->data
;
460 return MESA_FORMAT_NONE
;
463 /** Is the given format a compressed format? */
465 _mesa_is_format_compressed(mesa_format format
)
467 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
468 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
473 * Determine if the given format represents a packed depth/stencil buffer.
476 _mesa_is_format_packed_depth_stencil(mesa_format format
)
478 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
480 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
485 * Is the given format a signed/unsigned integer color format?
488 _mesa_is_format_integer_color(mesa_format format
)
490 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
491 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
492 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
493 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
494 info
->BaseFormat
!= GL_STENCIL_INDEX
;
499 * Is the given format an unsigned integer format?
502 _mesa_is_format_unsigned(mesa_format format
)
504 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
505 return _mesa_is_type_unsigned(info
->DataType
);
510 * Does the given format store signed values?
513 _mesa_is_format_signed(mesa_format format
)
515 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
516 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
517 /* these packed float formats only store unsigned values */
521 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
522 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
523 info
->DataType
== GL_INT
||
524 info
->DataType
== GL_FLOAT
);
529 * Is the given format an integer format?
532 _mesa_is_format_integer(mesa_format format
)
534 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
535 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
540 * Return true if the given format is a color format.
543 _mesa_is_format_color_format(mesa_format format
)
545 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
546 switch (info
->BaseFormat
) {
547 case GL_DEPTH_COMPONENT
:
548 case GL_STENCIL_INDEX
:
549 case GL_DEPTH_STENCIL
:
558 * Return color encoding for given format.
559 * \return GL_LINEAR or GL_SRGB
562 _mesa_get_format_color_encoding(mesa_format format
)
564 /* XXX this info should be encoded in gl_format_info */
566 case MESA_FORMAT_BGR_SRGB8
:
567 case MESA_FORMAT_A8B8G8R8_SRGB
:
568 case MESA_FORMAT_B8G8R8A8_SRGB
:
569 case MESA_FORMAT_A8R8G8B8_SRGB
:
570 case MESA_FORMAT_R8G8B8A8_SRGB
:
571 case MESA_FORMAT_L_SRGB8
:
572 case MESA_FORMAT_L8A8_SRGB
:
573 case MESA_FORMAT_A8L8_SRGB
:
574 case MESA_FORMAT_SRGB_DXT1
:
575 case MESA_FORMAT_SRGBA_DXT1
:
576 case MESA_FORMAT_SRGBA_DXT3
:
577 case MESA_FORMAT_SRGBA_DXT5
:
578 case MESA_FORMAT_R8G8B8X8_SRGB
:
579 case MESA_FORMAT_ETC2_SRGB8
:
580 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
581 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
582 case MESA_FORMAT_B8G8R8X8_SRGB
:
583 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
592 * Return TRUE if format is an ETC2 compressed format specified
593 * by GL_ARB_ES3_compatibility.
596 _mesa_is_format_etc2(mesa_format format
)
599 case MESA_FORMAT_ETC2_RGB8
:
600 case MESA_FORMAT_ETC2_SRGB8
:
601 case MESA_FORMAT_ETC2_RGBA8_EAC
:
602 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
603 case MESA_FORMAT_ETC2_R11_EAC
:
604 case MESA_FORMAT_ETC2_RG11_EAC
:
605 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
606 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
607 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
608 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
617 * For an sRGB format, return the corresponding linear color space format.
618 * For non-sRGB formats, return the format as-is.
621 _mesa_get_srgb_format_linear(mesa_format format
)
624 case MESA_FORMAT_BGR_SRGB8
:
625 format
= MESA_FORMAT_BGR_UNORM8
;
627 case MESA_FORMAT_A8B8G8R8_SRGB
:
628 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
630 case MESA_FORMAT_B8G8R8A8_SRGB
:
631 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
633 case MESA_FORMAT_A8R8G8B8_SRGB
:
634 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
636 case MESA_FORMAT_R8G8B8A8_SRGB
:
637 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
639 case MESA_FORMAT_L_SRGB8
:
640 format
= MESA_FORMAT_L_UNORM8
;
642 case MESA_FORMAT_L8A8_SRGB
:
643 format
= MESA_FORMAT_L8A8_UNORM
;
645 case MESA_FORMAT_A8L8_SRGB
:
646 format
= MESA_FORMAT_A8L8_UNORM
;
648 case MESA_FORMAT_SRGB_DXT1
:
649 format
= MESA_FORMAT_RGB_DXT1
;
651 case MESA_FORMAT_SRGBA_DXT1
:
652 format
= MESA_FORMAT_RGBA_DXT1
;
654 case MESA_FORMAT_SRGBA_DXT3
:
655 format
= MESA_FORMAT_RGBA_DXT3
;
657 case MESA_FORMAT_SRGBA_DXT5
:
658 format
= MESA_FORMAT_RGBA_DXT5
;
660 case MESA_FORMAT_R8G8B8X8_SRGB
:
661 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
663 case MESA_FORMAT_X8B8G8R8_SRGB
:
664 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
666 case MESA_FORMAT_ETC2_SRGB8
:
667 format
= MESA_FORMAT_ETC2_RGB8
;
669 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
670 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
672 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
673 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
675 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
676 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
678 case MESA_FORMAT_B8G8R8X8_SRGB
:
679 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
681 case MESA_FORMAT_X8R8G8B8_SRGB
:
682 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
692 * If the given format is a compressed format, return a corresponding
693 * uncompressed format.
696 _mesa_get_uncompressed_format(mesa_format format
)
699 case MESA_FORMAT_RGB_FXT1
:
700 return MESA_FORMAT_BGR_UNORM8
;
701 case MESA_FORMAT_RGBA_FXT1
:
702 return MESA_FORMAT_A8B8G8R8_UNORM
;
703 case MESA_FORMAT_RGB_DXT1
:
704 case MESA_FORMAT_SRGB_DXT1
:
705 return MESA_FORMAT_BGR_UNORM8
;
706 case MESA_FORMAT_RGBA_DXT1
:
707 case MESA_FORMAT_SRGBA_DXT1
:
708 return MESA_FORMAT_A8B8G8R8_UNORM
;
709 case MESA_FORMAT_RGBA_DXT3
:
710 case MESA_FORMAT_SRGBA_DXT3
:
711 return MESA_FORMAT_A8B8G8R8_UNORM
;
712 case MESA_FORMAT_RGBA_DXT5
:
713 case MESA_FORMAT_SRGBA_DXT5
:
714 return MESA_FORMAT_A8B8G8R8_UNORM
;
715 case MESA_FORMAT_R_RGTC1_UNORM
:
716 return MESA_FORMAT_R_UNORM8
;
717 case MESA_FORMAT_R_RGTC1_SNORM
:
718 return MESA_FORMAT_R_SNORM8
;
719 case MESA_FORMAT_RG_RGTC2_UNORM
:
720 return MESA_FORMAT_R8G8_UNORM
;
721 case MESA_FORMAT_RG_RGTC2_SNORM
:
722 return MESA_FORMAT_R8G8_SNORM
;
723 case MESA_FORMAT_L_LATC1_UNORM
:
724 return MESA_FORMAT_L_UNORM8
;
725 case MESA_FORMAT_L_LATC1_SNORM
:
726 return MESA_FORMAT_L_SNORM8
;
727 case MESA_FORMAT_LA_LATC2_UNORM
:
728 return MESA_FORMAT_L8A8_UNORM
;
729 case MESA_FORMAT_LA_LATC2_SNORM
:
730 return MESA_FORMAT_L8A8_SNORM
;
731 case MESA_FORMAT_ETC1_RGB8
:
732 case MESA_FORMAT_ETC2_RGB8
:
733 case MESA_FORMAT_ETC2_SRGB8
:
734 return MESA_FORMAT_BGR_UNORM8
;
735 case MESA_FORMAT_ETC2_RGBA8_EAC
:
736 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
737 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
738 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
739 return MESA_FORMAT_A8B8G8R8_UNORM
;
740 case MESA_FORMAT_ETC2_R11_EAC
:
741 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
742 return MESA_FORMAT_R_UNORM16
;
743 case MESA_FORMAT_ETC2_RG11_EAC
:
744 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
745 return MESA_FORMAT_R16G16_UNORM
;
746 case MESA_FORMAT_BPTC_RGBA_UNORM
:
747 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
748 return MESA_FORMAT_A8B8G8R8_UNORM
;
749 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
750 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
751 return MESA_FORMAT_RGB_FLOAT32
;
754 assert(!_mesa_is_format_compressed(format
));
762 _mesa_format_num_components(mesa_format format
)
764 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
765 return ((info
->RedBits
> 0) +
766 (info
->GreenBits
> 0) +
767 (info
->BlueBits
> 0) +
768 (info
->AlphaBits
> 0) +
769 (info
->LuminanceBits
> 0) +
770 (info
->IntensityBits
> 0) +
771 (info
->DepthBits
> 0) +
772 (info
->StencilBits
> 0));
777 * Returns true if a color format has data stored in the R/G/B/A channels,
778 * given an index from 0 to 3.
781 _mesa_format_has_color_component(mesa_format format
, int component
)
783 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
785 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
786 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
787 info
->BaseFormat
!= GL_STENCIL_INDEX
);
791 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
793 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
795 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
797 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
799 assert(!"Invalid color component: must be 0..3");
806 * Return number of bytes needed to store an image of the given size
807 * in the given format.
810 _mesa_format_image_size(mesa_format format
, GLsizei width
,
811 GLsizei height
, GLsizei depth
)
813 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
814 /* Strictly speaking, a conditional isn't needed here */
815 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
816 /* compressed format (2D only for now) */
817 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
818 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
819 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
820 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
825 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
832 * Same as _mesa_format_image_size() but returns a 64-bit value to
833 * accommodate very large textures.
836 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
837 GLsizei height
, GLsizei depth
)
839 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
840 /* Strictly speaking, a conditional isn't needed here */
841 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
842 /* compressed format (2D only for now) */
843 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
844 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
845 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
846 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
851 const uint64_t sz
= ((uint64_t) width
*
854 info
->BytesPerBlock
);
862 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
864 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
865 /* Strictly speaking, a conditional isn't needed here */
866 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
867 /* compressed format */
868 const GLuint bw
= info
->BlockWidth
;
869 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
870 const GLint stride
= wblocks
* info
->BytesPerBlock
;
874 const GLint stride
= width
* info
->BytesPerBlock
;
881 * Debug/test: check that all formats are handled in the
882 * _mesa_format_to_type_and_comps() function. When new pixel formats
883 * are added to Mesa, that function needs to be updated.
884 * This is a no-op after the first call.
887 check_format_to_type_and_comps(void)
891 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
894 /* This function will emit a problem/warning if the format is
897 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
902 * Do sanity checking of the format info table.
905 _mesa_test_formats(void)
909 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
911 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
912 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
915 assert(info
->Name
== i
);
917 if (info
->Name
== MESA_FORMAT_NONE
)
920 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
921 if (info
->RedBits
> 0) {
922 GLuint t
= info
->RedBits
+ info
->GreenBits
923 + info
->BlueBits
+ info
->AlphaBits
;
924 assert(t
/ 8 <= info
->BytesPerBlock
);
929 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
930 info
->DataType
== GL_SIGNED_NORMALIZED
||
931 info
->DataType
== GL_UNSIGNED_INT
||
932 info
->DataType
== GL_INT
||
933 info
->DataType
== GL_FLOAT
||
934 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
935 info
->DataType
== GL_NONE
);
937 if (info
->BaseFormat
== GL_RGB
) {
938 assert(info
->RedBits
> 0);
939 assert(info
->GreenBits
> 0);
940 assert(info
->BlueBits
> 0);
941 assert(info
->AlphaBits
== 0);
942 assert(info
->LuminanceBits
== 0);
943 assert(info
->IntensityBits
== 0);
945 else if (info
->BaseFormat
== GL_RGBA
) {
946 assert(info
->RedBits
> 0);
947 assert(info
->GreenBits
> 0);
948 assert(info
->BlueBits
> 0);
949 assert(info
->AlphaBits
> 0);
950 assert(info
->LuminanceBits
== 0);
951 assert(info
->IntensityBits
== 0);
953 else if (info
->BaseFormat
== GL_RG
) {
954 assert(info
->RedBits
> 0);
955 assert(info
->GreenBits
> 0);
956 assert(info
->BlueBits
== 0);
957 assert(info
->AlphaBits
== 0);
958 assert(info
->LuminanceBits
== 0);
959 assert(info
->IntensityBits
== 0);
961 else if (info
->BaseFormat
== GL_RED
) {
962 assert(info
->RedBits
> 0);
963 assert(info
->GreenBits
== 0);
964 assert(info
->BlueBits
== 0);
965 assert(info
->AlphaBits
== 0);
966 assert(info
->LuminanceBits
== 0);
967 assert(info
->IntensityBits
== 0);
969 else if (info
->BaseFormat
== GL_LUMINANCE
) {
970 assert(info
->RedBits
== 0);
971 assert(info
->GreenBits
== 0);
972 assert(info
->BlueBits
== 0);
973 assert(info
->AlphaBits
== 0);
974 assert(info
->LuminanceBits
> 0);
975 assert(info
->IntensityBits
== 0);
977 else if (info
->BaseFormat
== GL_INTENSITY
) {
978 assert(info
->RedBits
== 0);
979 assert(info
->GreenBits
== 0);
980 assert(info
->BlueBits
== 0);
981 assert(info
->AlphaBits
== 0);
982 assert(info
->LuminanceBits
== 0);
983 assert(info
->IntensityBits
> 0);
987 check_format_to_type_and_comps();
993 * Return datatype and number of components per texel for the given mesa_format.
994 * Only used for mipmap generation code.
997 _mesa_format_to_type_and_comps(mesa_format format
,
998 GLenum
*datatype
, GLuint
*comps
)
1001 case MESA_FORMAT_A8B8G8R8_UNORM
:
1002 case MESA_FORMAT_R8G8B8A8_UNORM
:
1003 case MESA_FORMAT_B8G8R8A8_UNORM
:
1004 case MESA_FORMAT_A8R8G8B8_UNORM
:
1005 case MESA_FORMAT_X8B8G8R8_UNORM
:
1006 case MESA_FORMAT_R8G8B8X8_UNORM
:
1007 case MESA_FORMAT_B8G8R8X8_UNORM
:
1008 case MESA_FORMAT_X8R8G8B8_UNORM
:
1009 *datatype
= GL_UNSIGNED_BYTE
;
1012 case MESA_FORMAT_BGR_UNORM8
:
1013 case MESA_FORMAT_RGB_UNORM8
:
1014 *datatype
= GL_UNSIGNED_BYTE
;
1017 case MESA_FORMAT_B5G6R5_UNORM
:
1018 case MESA_FORMAT_R5G6B5_UNORM
:
1019 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1023 case MESA_FORMAT_B4G4R4A4_UNORM
:
1024 case MESA_FORMAT_A4R4G4B4_UNORM
:
1025 case MESA_FORMAT_B4G4R4X4_UNORM
:
1026 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1030 case MESA_FORMAT_B5G5R5A1_UNORM
:
1031 case MESA_FORMAT_A1R5G5B5_UNORM
:
1032 case MESA_FORMAT_B5G5R5X1_UNORM
:
1033 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1037 case MESA_FORMAT_B10G10R10A2_UNORM
:
1038 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1042 case MESA_FORMAT_A1B5G5R5_UNORM
:
1043 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1047 case MESA_FORMAT_L4A4_UNORM
:
1048 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1052 case MESA_FORMAT_L8A8_UNORM
:
1053 case MESA_FORMAT_A8L8_UNORM
:
1054 case MESA_FORMAT_R8G8_UNORM
:
1055 case MESA_FORMAT_G8R8_UNORM
:
1056 *datatype
= GL_UNSIGNED_BYTE
;
1060 case MESA_FORMAT_L16A16_UNORM
:
1061 case MESA_FORMAT_A16L16_UNORM
:
1062 case MESA_FORMAT_R16G16_UNORM
:
1063 case MESA_FORMAT_G16R16_UNORM
:
1064 *datatype
= GL_UNSIGNED_SHORT
;
1068 case MESA_FORMAT_R_UNORM16
:
1069 case MESA_FORMAT_A_UNORM16
:
1070 case MESA_FORMAT_L_UNORM16
:
1071 case MESA_FORMAT_I_UNORM16
:
1072 *datatype
= GL_UNSIGNED_SHORT
;
1076 case MESA_FORMAT_R3G3B2_UNORM
:
1077 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1080 case MESA_FORMAT_A4B4G4R4_UNORM
:
1081 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1085 case MESA_FORMAT_R4G4B4A4_UNORM
:
1086 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1089 case MESA_FORMAT_R5G5B5A1_UNORM
:
1090 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1093 case MESA_FORMAT_A2B10G10R10_UNORM
:
1094 case MESA_FORMAT_A2B10G10R10_UINT
:
1095 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1098 case MESA_FORMAT_A2R10G10B10_UNORM
:
1099 case MESA_FORMAT_A2R10G10B10_UINT
:
1100 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1104 case MESA_FORMAT_B2G3R3_UNORM
:
1105 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1109 case MESA_FORMAT_A_UNORM8
:
1110 case MESA_FORMAT_L_UNORM8
:
1111 case MESA_FORMAT_I_UNORM8
:
1112 case MESA_FORMAT_R_UNORM8
:
1113 case MESA_FORMAT_S_UINT8
:
1114 *datatype
= GL_UNSIGNED_BYTE
;
1118 case MESA_FORMAT_YCBCR
:
1119 case MESA_FORMAT_YCBCR_REV
:
1120 *datatype
= GL_UNSIGNED_SHORT
;
1124 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1125 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1129 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1130 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1134 case MESA_FORMAT_Z_UNORM16
:
1135 *datatype
= GL_UNSIGNED_SHORT
;
1139 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1140 *datatype
= GL_UNSIGNED_INT
;
1144 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1145 *datatype
= GL_UNSIGNED_INT
;
1149 case MESA_FORMAT_Z_UNORM32
:
1150 *datatype
= GL_UNSIGNED_INT
;
1154 case MESA_FORMAT_Z_FLOAT32
:
1155 *datatype
= GL_FLOAT
;
1159 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1160 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1164 case MESA_FORMAT_R_SNORM8
:
1165 case MESA_FORMAT_A_SNORM8
:
1166 case MESA_FORMAT_L_SNORM8
:
1167 case MESA_FORMAT_I_SNORM8
:
1168 *datatype
= GL_BYTE
;
1171 case MESA_FORMAT_R8G8_SNORM
:
1172 case MESA_FORMAT_L8A8_SNORM
:
1173 case MESA_FORMAT_A8L8_SNORM
:
1174 *datatype
= GL_BYTE
;
1177 case MESA_FORMAT_A8B8G8R8_SNORM
:
1178 case MESA_FORMAT_R8G8B8A8_SNORM
:
1179 case MESA_FORMAT_X8B8G8R8_SNORM
:
1180 *datatype
= GL_BYTE
;
1184 case MESA_FORMAT_RGBA_UNORM16
:
1185 *datatype
= GL_UNSIGNED_SHORT
;
1189 case MESA_FORMAT_R_SNORM16
:
1190 case MESA_FORMAT_A_SNORM16
:
1191 case MESA_FORMAT_L_SNORM16
:
1192 case MESA_FORMAT_I_SNORM16
:
1193 *datatype
= GL_SHORT
;
1196 case MESA_FORMAT_R16G16_SNORM
:
1197 case MESA_FORMAT_LA_SNORM16
:
1198 *datatype
= GL_SHORT
;
1201 case MESA_FORMAT_RGB_SNORM16
:
1202 *datatype
= GL_SHORT
;
1205 case MESA_FORMAT_RGBA_SNORM16
:
1206 *datatype
= GL_SHORT
;
1210 case MESA_FORMAT_BGR_SRGB8
:
1211 *datatype
= GL_UNSIGNED_BYTE
;
1214 case MESA_FORMAT_A8B8G8R8_SRGB
:
1215 case MESA_FORMAT_B8G8R8A8_SRGB
:
1216 case MESA_FORMAT_A8R8G8B8_SRGB
:
1217 case MESA_FORMAT_R8G8B8A8_SRGB
:
1218 *datatype
= GL_UNSIGNED_BYTE
;
1221 case MESA_FORMAT_L_SRGB8
:
1222 *datatype
= GL_UNSIGNED_BYTE
;
1225 case MESA_FORMAT_L8A8_SRGB
:
1226 case MESA_FORMAT_A8L8_SRGB
:
1227 *datatype
= GL_UNSIGNED_BYTE
;
1231 case MESA_FORMAT_RGB_FXT1
:
1232 case MESA_FORMAT_RGBA_FXT1
:
1233 case MESA_FORMAT_RGB_DXT1
:
1234 case MESA_FORMAT_RGBA_DXT1
:
1235 case MESA_FORMAT_RGBA_DXT3
:
1236 case MESA_FORMAT_RGBA_DXT5
:
1237 case MESA_FORMAT_SRGB_DXT1
:
1238 case MESA_FORMAT_SRGBA_DXT1
:
1239 case MESA_FORMAT_SRGBA_DXT3
:
1240 case MESA_FORMAT_SRGBA_DXT5
:
1241 case MESA_FORMAT_R_RGTC1_UNORM
:
1242 case MESA_FORMAT_R_RGTC1_SNORM
:
1243 case MESA_FORMAT_RG_RGTC2_UNORM
:
1244 case MESA_FORMAT_RG_RGTC2_SNORM
:
1245 case MESA_FORMAT_L_LATC1_UNORM
:
1246 case MESA_FORMAT_L_LATC1_SNORM
:
1247 case MESA_FORMAT_LA_LATC2_UNORM
:
1248 case MESA_FORMAT_LA_LATC2_SNORM
:
1249 case MESA_FORMAT_ETC1_RGB8
:
1250 case MESA_FORMAT_ETC2_RGB8
:
1251 case MESA_FORMAT_ETC2_SRGB8
:
1252 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1253 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1254 case MESA_FORMAT_ETC2_R11_EAC
:
1255 case MESA_FORMAT_ETC2_RG11_EAC
:
1256 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1257 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1258 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1259 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1260 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1261 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1262 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1263 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1264 /* XXX generate error instead? */
1265 *datatype
= GL_UNSIGNED_BYTE
;
1269 case MESA_FORMAT_RGBA_FLOAT32
:
1270 *datatype
= GL_FLOAT
;
1273 case MESA_FORMAT_RGBA_FLOAT16
:
1274 *datatype
= GL_HALF_FLOAT_ARB
;
1277 case MESA_FORMAT_RGB_FLOAT32
:
1278 *datatype
= GL_FLOAT
;
1281 case MESA_FORMAT_RGB_FLOAT16
:
1282 *datatype
= GL_HALF_FLOAT_ARB
;
1285 case MESA_FORMAT_LA_FLOAT32
:
1286 case MESA_FORMAT_RG_FLOAT32
:
1287 *datatype
= GL_FLOAT
;
1290 case MESA_FORMAT_LA_FLOAT16
:
1291 case MESA_FORMAT_RG_FLOAT16
:
1292 *datatype
= GL_HALF_FLOAT_ARB
;
1295 case MESA_FORMAT_A_FLOAT32
:
1296 case MESA_FORMAT_L_FLOAT32
:
1297 case MESA_FORMAT_I_FLOAT32
:
1298 case MESA_FORMAT_R_FLOAT32
:
1299 *datatype
= GL_FLOAT
;
1302 case MESA_FORMAT_A_FLOAT16
:
1303 case MESA_FORMAT_L_FLOAT16
:
1304 case MESA_FORMAT_I_FLOAT16
:
1305 case MESA_FORMAT_R_FLOAT16
:
1306 *datatype
= GL_HALF_FLOAT_ARB
;
1310 case MESA_FORMAT_A_UINT8
:
1311 case MESA_FORMAT_L_UINT8
:
1312 case MESA_FORMAT_I_UINT8
:
1313 *datatype
= GL_UNSIGNED_BYTE
;
1316 case MESA_FORMAT_LA_UINT8
:
1317 *datatype
= GL_UNSIGNED_BYTE
;
1321 case MESA_FORMAT_A_UINT16
:
1322 case MESA_FORMAT_L_UINT16
:
1323 case MESA_FORMAT_I_UINT16
:
1324 *datatype
= GL_UNSIGNED_SHORT
;
1327 case MESA_FORMAT_LA_UINT16
:
1328 *datatype
= GL_UNSIGNED_SHORT
;
1331 case MESA_FORMAT_A_UINT32
:
1332 case MESA_FORMAT_L_UINT32
:
1333 case MESA_FORMAT_I_UINT32
:
1334 *datatype
= GL_UNSIGNED_INT
;
1337 case MESA_FORMAT_LA_UINT32
:
1338 *datatype
= GL_UNSIGNED_INT
;
1341 case MESA_FORMAT_A_SINT8
:
1342 case MESA_FORMAT_L_SINT8
:
1343 case MESA_FORMAT_I_SINT8
:
1344 *datatype
= GL_BYTE
;
1347 case MESA_FORMAT_LA_SINT8
:
1348 *datatype
= GL_BYTE
;
1352 case MESA_FORMAT_A_SINT16
:
1353 case MESA_FORMAT_L_SINT16
:
1354 case MESA_FORMAT_I_SINT16
:
1355 *datatype
= GL_SHORT
;
1358 case MESA_FORMAT_LA_SINT16
:
1359 *datatype
= GL_SHORT
;
1363 case MESA_FORMAT_A_SINT32
:
1364 case MESA_FORMAT_L_SINT32
:
1365 case MESA_FORMAT_I_SINT32
:
1369 case MESA_FORMAT_LA_SINT32
:
1374 case MESA_FORMAT_R_SINT8
:
1375 *datatype
= GL_BYTE
;
1378 case MESA_FORMAT_RG_SINT8
:
1379 *datatype
= GL_BYTE
;
1382 case MESA_FORMAT_RGB_SINT8
:
1383 *datatype
= GL_BYTE
;
1386 case MESA_FORMAT_RGBA_SINT8
:
1387 *datatype
= GL_BYTE
;
1390 case MESA_FORMAT_R_SINT16
:
1391 *datatype
= GL_SHORT
;
1394 case MESA_FORMAT_RG_SINT16
:
1395 *datatype
= GL_SHORT
;
1398 case MESA_FORMAT_RGB_SINT16
:
1399 *datatype
= GL_SHORT
;
1402 case MESA_FORMAT_RGBA_SINT16
:
1403 *datatype
= GL_SHORT
;
1406 case MESA_FORMAT_R_SINT32
:
1410 case MESA_FORMAT_RG_SINT32
:
1414 case MESA_FORMAT_RGB_SINT32
:
1418 case MESA_FORMAT_RGBA_SINT32
:
1424 * \name Non-normalized unsigned integer formats.
1426 case MESA_FORMAT_R_UINT8
:
1427 *datatype
= GL_UNSIGNED_BYTE
;
1430 case MESA_FORMAT_RG_UINT8
:
1431 *datatype
= GL_UNSIGNED_BYTE
;
1434 case MESA_FORMAT_RGB_UINT8
:
1435 *datatype
= GL_UNSIGNED_BYTE
;
1438 case MESA_FORMAT_RGBA_UINT8
:
1439 *datatype
= GL_UNSIGNED_BYTE
;
1442 case MESA_FORMAT_R_UINT16
:
1443 *datatype
= GL_UNSIGNED_SHORT
;
1446 case MESA_FORMAT_RG_UINT16
:
1447 *datatype
= GL_UNSIGNED_SHORT
;
1450 case MESA_FORMAT_RGB_UINT16
:
1451 *datatype
= GL_UNSIGNED_SHORT
;
1454 case MESA_FORMAT_RGBA_UINT16
:
1455 *datatype
= GL_UNSIGNED_SHORT
;
1458 case MESA_FORMAT_R_UINT32
:
1459 *datatype
= GL_UNSIGNED_INT
;
1462 case MESA_FORMAT_RG_UINT32
:
1463 *datatype
= GL_UNSIGNED_INT
;
1466 case MESA_FORMAT_RGB_UINT32
:
1467 *datatype
= GL_UNSIGNED_INT
;
1470 case MESA_FORMAT_RGBA_UINT32
:
1471 *datatype
= GL_UNSIGNED_INT
;
1475 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1476 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1480 case MESA_FORMAT_R11G11B10_FLOAT
:
1481 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1485 case MESA_FORMAT_B10G10R10A2_UINT
:
1486 case MESA_FORMAT_R10G10B10A2_UINT
:
1487 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1491 case MESA_FORMAT_R8G8B8X8_SRGB
:
1492 case MESA_FORMAT_X8B8G8R8_SRGB
:
1493 case MESA_FORMAT_RGBX_UINT8
:
1494 *datatype
= GL_UNSIGNED_BYTE
;
1498 case MESA_FORMAT_R8G8B8X8_SNORM
:
1499 case MESA_FORMAT_RGBX_SINT8
:
1500 *datatype
= GL_BYTE
;
1504 case MESA_FORMAT_B10G10R10X2_UNORM
:
1505 case MESA_FORMAT_R10G10B10X2_UNORM
:
1506 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1510 case MESA_FORMAT_RGBX_UNORM16
:
1511 case MESA_FORMAT_RGBX_UINT16
:
1512 *datatype
= GL_UNSIGNED_SHORT
;
1516 case MESA_FORMAT_RGBX_SNORM16
:
1517 case MESA_FORMAT_RGBX_SINT16
:
1518 *datatype
= GL_SHORT
;
1522 case MESA_FORMAT_RGBX_FLOAT16
:
1523 *datatype
= GL_HALF_FLOAT
;
1527 case MESA_FORMAT_RGBX_FLOAT32
:
1528 *datatype
= GL_FLOAT
;
1532 case MESA_FORMAT_RGBX_UINT32
:
1533 *datatype
= GL_UNSIGNED_INT
;
1537 case MESA_FORMAT_RGBX_SINT32
:
1542 case MESA_FORMAT_R10G10B10A2_UNORM
:
1543 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1547 case MESA_FORMAT_G8R8_SNORM
:
1548 *datatype
= GL_BYTE
;
1552 case MESA_FORMAT_G16R16_SNORM
:
1553 *datatype
= GL_SHORT
;
1557 case MESA_FORMAT_B8G8R8X8_SRGB
:
1558 case MESA_FORMAT_X8R8G8B8_SRGB
:
1559 *datatype
= GL_UNSIGNED_BYTE
;
1563 case MESA_FORMAT_COUNT
:
1567 case MESA_FORMAT_NONE
:
1568 /* For debug builds, warn if any formats are not handled */
1572 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1573 _mesa_get_format_name(format
));
1580 * Check if a mesa_format exactly matches a GL format/type combination
1581 * such that we can use memcpy() from one to the other.
1582 * \param mesa_format a MESA_FORMAT_x value
1583 * \param format the user-specified image format
1584 * \param type the user-specified image datatype
1585 * \param swapBytes typically the current pixel pack/unpack byteswap state
1586 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1589 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1590 GLenum format
, GLenum type
,
1591 GLboolean swapBytes
)
1593 const GLboolean littleEndian
= _mesa_little_endian();
1595 /* Note: When reading a GL format/type combination, the format lists channel
1596 * assignments from most significant channel in the type to least
1597 * significant. A type with _REV indicates that the assignments are
1598 * swapped, so they are listed from least significant to most significant.
1600 * For sanity, please keep this switch statement ordered the same as the
1601 * enums in formats.h.
1604 switch (mesa_format
) {
1606 case MESA_FORMAT_NONE
:
1607 case MESA_FORMAT_COUNT
:
1610 case MESA_FORMAT_A8B8G8R8_UNORM
:
1611 case MESA_FORMAT_A8B8G8R8_SRGB
:
1612 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1615 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1618 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1621 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1625 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1629 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1634 case MESA_FORMAT_R8G8B8A8_UNORM
:
1635 case MESA_FORMAT_R8G8B8A8_SRGB
:
1636 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1640 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1643 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1646 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1650 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1654 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1659 case MESA_FORMAT_B8G8R8A8_UNORM
:
1660 case MESA_FORMAT_B8G8R8A8_SRGB
:
1661 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1665 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1668 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1673 case MESA_FORMAT_A8R8G8B8_UNORM
:
1674 case MESA_FORMAT_A8R8G8B8_SRGB
:
1675 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1678 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1682 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1687 case MESA_FORMAT_X8B8G8R8_UNORM
:
1688 case MESA_FORMAT_R8G8B8X8_UNORM
:
1691 case MESA_FORMAT_B8G8R8X8_UNORM
:
1692 case MESA_FORMAT_X8R8G8B8_UNORM
:
1695 case MESA_FORMAT_BGR_UNORM8
:
1696 case MESA_FORMAT_BGR_SRGB8
:
1697 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1699 case MESA_FORMAT_RGB_UNORM8
:
1700 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1702 case MESA_FORMAT_B5G6R5_UNORM
:
1703 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1704 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1707 case MESA_FORMAT_R5G6B5_UNORM
:
1708 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1709 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1712 case MESA_FORMAT_B4G4R4A4_UNORM
:
1713 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1716 case MESA_FORMAT_A4R4G4B4_UNORM
:
1719 case MESA_FORMAT_A1B5G5R5_UNORM
:
1720 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1723 case MESA_FORMAT_B5G5R5A1_UNORM
:
1724 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1727 case MESA_FORMAT_A1R5G5B5_UNORM
:
1728 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1731 case MESA_FORMAT_L4A4_UNORM
:
1733 case MESA_FORMAT_L8A8_UNORM
:
1734 case MESA_FORMAT_L8A8_SRGB
:
1735 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1736 case MESA_FORMAT_A8L8_UNORM
:
1737 case MESA_FORMAT_A8L8_SRGB
:
1740 case MESA_FORMAT_L16A16_UNORM
:
1741 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1742 case MESA_FORMAT_A16L16_UNORM
:
1745 case MESA_FORMAT_B2G3R3_UNORM
:
1746 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1748 case MESA_FORMAT_R3G3B2_UNORM
:
1749 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1751 case MESA_FORMAT_A4B4G4R4_UNORM
:
1752 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1755 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1758 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1761 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1766 case MESA_FORMAT_R4G4B4A4_UNORM
:
1767 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1770 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1773 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1776 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1781 case MESA_FORMAT_R5G5B5A1_UNORM
:
1782 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1784 case MESA_FORMAT_A2B10G10R10_UNORM
:
1785 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1787 case MESA_FORMAT_A2B10G10R10_UINT
:
1788 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1790 case MESA_FORMAT_A2R10G10B10_UNORM
:
1791 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1793 case MESA_FORMAT_A2R10G10B10_UINT
:
1794 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1796 case MESA_FORMAT_A_UNORM8
:
1797 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1798 case MESA_FORMAT_A_UNORM16
:
1799 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1800 case MESA_FORMAT_L_UNORM8
:
1801 case MESA_FORMAT_L_SRGB8
:
1802 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1803 case MESA_FORMAT_L_UNORM16
:
1804 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1805 case MESA_FORMAT_I_UNORM8
:
1806 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1807 case MESA_FORMAT_I_UNORM16
:
1808 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1810 case MESA_FORMAT_YCBCR
:
1811 return format
== GL_YCBCR_MESA
&&
1812 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1813 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1814 case MESA_FORMAT_YCBCR_REV
:
1815 return format
== GL_YCBCR_MESA
&&
1816 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1817 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1819 case MESA_FORMAT_R_UNORM8
:
1820 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1821 case MESA_FORMAT_R8G8_UNORM
:
1822 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1823 case MESA_FORMAT_G8R8_UNORM
:
1826 case MESA_FORMAT_R_UNORM16
:
1827 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1829 case MESA_FORMAT_R16G16_UNORM
:
1830 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1832 case MESA_FORMAT_G16R16_UNORM
:
1835 case MESA_FORMAT_B10G10R10A2_UNORM
:
1836 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1839 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1840 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1842 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1843 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1846 case MESA_FORMAT_Z_UNORM16
:
1847 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1850 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1853 case MESA_FORMAT_Z_UNORM32
:
1854 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1857 case MESA_FORMAT_S_UINT8
:
1858 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1860 case MESA_FORMAT_SRGB_DXT1
:
1861 case MESA_FORMAT_SRGBA_DXT1
:
1862 case MESA_FORMAT_SRGBA_DXT3
:
1863 case MESA_FORMAT_SRGBA_DXT5
:
1866 case MESA_FORMAT_RGB_FXT1
:
1867 case MESA_FORMAT_RGBA_FXT1
:
1868 case MESA_FORMAT_RGB_DXT1
:
1869 case MESA_FORMAT_RGBA_DXT1
:
1870 case MESA_FORMAT_RGBA_DXT3
:
1871 case MESA_FORMAT_RGBA_DXT5
:
1874 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1875 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1876 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1877 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1880 case MESA_FORMAT_RGBA_FLOAT32
:
1881 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1882 case MESA_FORMAT_RGBA_FLOAT16
:
1883 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1885 case MESA_FORMAT_RGB_FLOAT32
:
1886 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1887 case MESA_FORMAT_RGB_FLOAT16
:
1888 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1890 case MESA_FORMAT_A_FLOAT32
:
1891 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1892 case MESA_FORMAT_A_FLOAT16
:
1893 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1895 case MESA_FORMAT_L_FLOAT32
:
1896 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1897 case MESA_FORMAT_L_FLOAT16
:
1898 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1900 case MESA_FORMAT_LA_FLOAT32
:
1901 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1902 case MESA_FORMAT_LA_FLOAT16
:
1903 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1905 case MESA_FORMAT_I_FLOAT32
:
1906 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1907 case MESA_FORMAT_I_FLOAT16
:
1908 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1910 case MESA_FORMAT_R_FLOAT32
:
1911 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1912 case MESA_FORMAT_R_FLOAT16
:
1913 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1915 case MESA_FORMAT_RG_FLOAT32
:
1916 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1917 case MESA_FORMAT_RG_FLOAT16
:
1918 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1920 case MESA_FORMAT_A_UINT8
:
1921 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1922 case MESA_FORMAT_A_UINT16
:
1923 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1925 case MESA_FORMAT_A_UINT32
:
1926 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1928 case MESA_FORMAT_A_SINT8
:
1929 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1930 case MESA_FORMAT_A_SINT16
:
1931 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1932 case MESA_FORMAT_A_SINT32
:
1933 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1935 case MESA_FORMAT_I_UINT8
:
1936 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1937 case MESA_FORMAT_I_UINT16
:
1938 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1939 case MESA_FORMAT_I_UINT32
:
1940 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1941 case MESA_FORMAT_I_SINT8
:
1942 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1943 case MESA_FORMAT_I_SINT16
:
1944 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1945 case MESA_FORMAT_I_SINT32
:
1946 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1948 case MESA_FORMAT_L_UINT8
:
1949 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1950 case MESA_FORMAT_L_UINT16
:
1951 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1953 case MESA_FORMAT_L_UINT32
:
1954 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1956 case MESA_FORMAT_L_SINT8
:
1957 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1958 case MESA_FORMAT_L_SINT16
:
1959 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1961 case MESA_FORMAT_L_SINT32
:
1962 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1964 case MESA_FORMAT_LA_UINT8
:
1965 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1966 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1967 case MESA_FORMAT_LA_UINT16
:
1968 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1969 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1970 case MESA_FORMAT_LA_UINT32
:
1971 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1972 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1973 case MESA_FORMAT_LA_SINT8
:
1974 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1976 case MESA_FORMAT_LA_SINT16
:
1977 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1979 case MESA_FORMAT_LA_SINT32
:
1980 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1983 case MESA_FORMAT_R_SINT8
:
1984 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1985 case MESA_FORMAT_RG_SINT8
:
1986 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1987 case MESA_FORMAT_RGB_SINT8
:
1988 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1989 case MESA_FORMAT_RGBA_SINT8
:
1990 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1991 case MESA_FORMAT_R_SINT16
:
1992 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1993 case MESA_FORMAT_RG_SINT16
:
1994 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1995 case MESA_FORMAT_RGB_SINT16
:
1996 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1997 case MESA_FORMAT_RGBA_SINT16
:
1998 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1999 case MESA_FORMAT_R_SINT32
:
2000 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2001 case MESA_FORMAT_RG_SINT32
:
2002 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2003 case MESA_FORMAT_RGB_SINT32
:
2004 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2005 case MESA_FORMAT_RGBA_SINT32
:
2006 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2008 case MESA_FORMAT_R_UINT8
:
2009 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2010 case MESA_FORMAT_RG_UINT8
:
2011 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2012 case MESA_FORMAT_RGB_UINT8
:
2013 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2014 case MESA_FORMAT_RGBA_UINT8
:
2015 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2017 case MESA_FORMAT_R_UINT16
:
2018 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2020 case MESA_FORMAT_RG_UINT16
:
2021 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2022 case MESA_FORMAT_RGB_UINT16
:
2023 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2025 case MESA_FORMAT_RGBA_UINT16
:
2026 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2028 case MESA_FORMAT_R_UINT32
:
2029 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2030 case MESA_FORMAT_RG_UINT32
:
2031 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2032 case MESA_FORMAT_RGB_UINT32
:
2033 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2034 case MESA_FORMAT_RGBA_UINT32
:
2035 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2037 case MESA_FORMAT_R_SNORM8
:
2038 return format
== GL_RED
&& type
== GL_BYTE
;
2039 case MESA_FORMAT_R8G8_SNORM
:
2040 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2042 case MESA_FORMAT_X8B8G8R8_SNORM
:
2045 case MESA_FORMAT_A8B8G8R8_SNORM
:
2046 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2049 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2054 case MESA_FORMAT_R8G8B8A8_SNORM
:
2055 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2058 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2063 case MESA_FORMAT_R_SNORM16
:
2064 return format
== GL_RED
&& type
== GL_SHORT
&&
2066 case MESA_FORMAT_R16G16_SNORM
:
2067 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2068 case MESA_FORMAT_RGB_SNORM16
:
2069 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2070 case MESA_FORMAT_RGBA_SNORM16
:
2071 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2072 case MESA_FORMAT_RGBA_UNORM16
:
2073 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2076 case MESA_FORMAT_R_RGTC1_UNORM
:
2077 case MESA_FORMAT_R_RGTC1_SNORM
:
2078 case MESA_FORMAT_RG_RGTC2_UNORM
:
2079 case MESA_FORMAT_RG_RGTC2_SNORM
:
2082 case MESA_FORMAT_L_LATC1_UNORM
:
2083 case MESA_FORMAT_L_LATC1_SNORM
:
2084 case MESA_FORMAT_LA_LATC2_UNORM
:
2085 case MESA_FORMAT_LA_LATC2_SNORM
:
2088 case MESA_FORMAT_ETC1_RGB8
:
2089 case MESA_FORMAT_ETC2_RGB8
:
2090 case MESA_FORMAT_ETC2_SRGB8
:
2091 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2092 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2093 case MESA_FORMAT_ETC2_R11_EAC
:
2094 case MESA_FORMAT_ETC2_RG11_EAC
:
2095 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2096 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2097 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2098 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2101 case MESA_FORMAT_A_SNORM8
:
2102 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2103 case MESA_FORMAT_L_SNORM8
:
2104 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2105 case MESA_FORMAT_L8A8_SNORM
:
2106 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2107 littleEndian
&& !swapBytes
;
2108 case MESA_FORMAT_A8L8_SNORM
:
2109 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2110 !littleEndian
&& !swapBytes
;
2111 case MESA_FORMAT_I_SNORM8
:
2112 return format
== GL_RED
&& type
== GL_BYTE
;
2113 case MESA_FORMAT_A_SNORM16
:
2114 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2115 case MESA_FORMAT_L_SNORM16
:
2116 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2117 case MESA_FORMAT_LA_SNORM16
:
2118 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2119 littleEndian
&& !swapBytes
;
2120 case MESA_FORMAT_I_SNORM16
:
2121 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2124 case MESA_FORMAT_B10G10R10A2_UINT
:
2125 return (format
== GL_BGRA_INTEGER_EXT
&&
2126 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2129 case MESA_FORMAT_R10G10B10A2_UINT
:
2130 return (format
== GL_RGBA_INTEGER_EXT
&&
2131 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2134 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2135 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2138 case MESA_FORMAT_R11G11B10_FLOAT
:
2139 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2142 case MESA_FORMAT_Z_FLOAT32
:
2143 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2145 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2146 return format
== GL_DEPTH_STENCIL
&&
2147 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2149 case MESA_FORMAT_B4G4R4X4_UNORM
:
2150 case MESA_FORMAT_B5G5R5X1_UNORM
:
2151 case MESA_FORMAT_R8G8B8X8_SNORM
:
2152 case MESA_FORMAT_R8G8B8X8_SRGB
:
2153 case MESA_FORMAT_X8B8G8R8_SRGB
:
2154 case MESA_FORMAT_RGBX_UINT8
:
2155 case MESA_FORMAT_RGBX_SINT8
:
2156 case MESA_FORMAT_B10G10R10X2_UNORM
:
2157 case MESA_FORMAT_R10G10B10X2_UNORM
:
2158 case MESA_FORMAT_RGBX_UNORM16
:
2159 case MESA_FORMAT_RGBX_SNORM16
:
2160 case MESA_FORMAT_RGBX_FLOAT16
:
2161 case MESA_FORMAT_RGBX_UINT16
:
2162 case MESA_FORMAT_RGBX_SINT16
:
2163 case MESA_FORMAT_RGBX_FLOAT32
:
2164 case MESA_FORMAT_RGBX_UINT32
:
2165 case MESA_FORMAT_RGBX_SINT32
:
2168 case MESA_FORMAT_R10G10B10A2_UNORM
:
2169 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2172 case MESA_FORMAT_G8R8_SNORM
:
2173 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2176 case MESA_FORMAT_G16R16_SNORM
:
2177 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2180 case MESA_FORMAT_B8G8R8X8_SRGB
:
2181 case MESA_FORMAT_X8R8G8B8_SRGB
: