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
;
71 * To describe compressed formats. If not compressed, Width=Height=1.
73 GLubyte BlockWidth
, BlockHeight
;
74 GLubyte BytesPerBlock
;
77 mesa_array_format ArrayFormat
;
80 #include "format_info.h"
82 static const struct gl_format_info
*
83 _mesa_get_format_info(mesa_format format
)
85 const struct gl_format_info
*info
= &format_info
[format
];
86 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
87 assert(info
->Name
== format
);
92 /** Return string name of format (for debugging) */
94 _mesa_get_format_name(mesa_format format
)
96 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
103 * Return bytes needed to store a block of pixels in the given format.
104 * Normally, a block is 1x1 (a single pixel). But for compressed formats
105 * a block may be 4x4 or 8x4, etc.
107 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
110 _mesa_get_format_bytes(mesa_format format
)
112 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
113 assert(info
->BytesPerBlock
);
114 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
115 _mesa_is_format_compressed(format
));
116 return info
->BytesPerBlock
;
121 * Return bits per component for the given format.
122 * \param format one of MESA_FORMAT_x
123 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
126 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
128 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
132 case GL_TEXTURE_RED_SIZE
:
133 case GL_RENDERBUFFER_RED_SIZE_EXT
:
134 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
135 return info
->RedBits
;
137 case GL_TEXTURE_GREEN_SIZE
:
138 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
139 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
140 return info
->GreenBits
;
142 case GL_TEXTURE_BLUE_SIZE
:
143 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
144 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
145 return info
->BlueBits
;
147 case GL_TEXTURE_ALPHA_SIZE
:
148 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
149 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
150 return info
->AlphaBits
;
151 case GL_TEXTURE_INTENSITY_SIZE
:
152 return info
->IntensityBits
;
153 case GL_TEXTURE_LUMINANCE_SIZE
:
154 return info
->LuminanceBits
;
158 case GL_TEXTURE_DEPTH_SIZE_ARB
:
159 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
160 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
161 return info
->DepthBits
;
162 case GL_STENCIL_BITS
:
163 case GL_TEXTURE_STENCIL_SIZE_EXT
:
164 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
165 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
166 return info
->StencilBits
;
168 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
175 _mesa_get_format_max_bits(mesa_format format
)
177 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
178 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
179 max
= MAX2(max
, info
->BlueBits
);
180 max
= MAX2(max
, info
->AlphaBits
);
181 max
= MAX2(max
, info
->LuminanceBits
);
182 max
= MAX2(max
, info
->IntensityBits
);
183 max
= MAX2(max
, info
->DepthBits
);
184 max
= MAX2(max
, info
->StencilBits
);
190 * Return the layout type of the given format.
192 extern enum mesa_format_layout
193 _mesa_get_format_layout(mesa_format format
)
195 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
201 * Return the data type (or more specifically, the data representation)
202 * for the given format.
203 * The return value will be one of:
204 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
205 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
206 * GL_UNSIGNED_INT = an ordinary unsigned integer
207 * GL_INT = an ordinary signed integer
208 * GL_FLOAT = an ordinary float
211 _mesa_get_format_datatype(mesa_format format
)
213 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
214 return info
->DataType
;
218 get_base_format_for_array_format(mesa_array_format format
)
223 _mesa_array_format_get_swizzle(format
, swizzle
);
224 num_channels
= _mesa_array_format_get_num_channels(format
);
226 switch (num_channels
) {
228 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
229 * This is not really a problem for now because we only create array
230 * formats from GL format/type combinations, and these cannot specify
237 if (swizzle
[0] == 0 &&
241 return GL_LUMINANCE_ALPHA
;
242 if (swizzle
[0] == 1 &&
246 return GL_LUMINANCE_ALPHA
;
247 if (swizzle
[0] == 0 &&
252 if (swizzle
[0] == 1 &&
259 if (swizzle
[0] == 0 &&
264 if (swizzle
[0] == 0 &&
269 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
271 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
273 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
275 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
280 unreachable("Unsupported format");
284 * Return the basic format for the given type. The result will be one of
285 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
286 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
287 * This functions accepts a mesa_format or a mesa_array_format.
290 _mesa_get_format_base_format(uint32_t format
)
292 if (!_mesa_format_is_mesa_array_format(format
)) {
293 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
294 return info
->BaseFormat
;
296 return get_base_format_for_array_format(format
);
302 * Return the block size (in pixels) for the given format. Normally
303 * the block size is 1x1. But compressed formats will have block sizes
304 * of 4x4 or 8x4 pixels, etc.
305 * \param bw returns block width in pixels
306 * \param bh returns block height in pixels
309 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
311 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
312 *bw
= info
->BlockWidth
;
313 *bh
= info
->BlockHeight
;
318 * Returns the an array of four numbers representing the transformation
319 * from the RGBA or SZ colorspace to the given format. For array formats,
320 * the i'th RGBA component is given by:
322 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
323 * comp = data[swizzle[i]];
324 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
326 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
328 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
329 * // data does not contain a channel of this format
331 * For packed formats, the swizzle gives the number of components left of
332 * the least significant bit.
334 * Compressed formats have no swizzle.
337 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
339 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
340 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
344 _mesa_array_format_flip_channels(mesa_array_format format
)
349 num_channels
= _mesa_array_format_get_num_channels(format
);
350 _mesa_array_format_get_swizzle(format
, swizzle
);
352 if (num_channels
== 1)
355 if (num_channels
== 2) {
356 /* Assert that the swizzle makes sense for 2 channels */
357 for (unsigned i
= 0; i
< 4; i
++)
358 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
360 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
361 _mesa_array_format_set_swizzle(&format
,
362 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
363 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
367 if (num_channels
== 4) {
368 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
369 _mesa_array_format_set_swizzle(&format
,
370 flip
[swizzle
[0]], flip
[swizzle
[1]],
371 flip
[swizzle
[2]], flip
[swizzle
[3]]);
375 unreachable("Invalid array format");
379 _mesa_format_to_array_format(mesa_format format
)
381 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
382 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
383 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 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
565 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
570 * Return TRUE if format is an ETC2 compressed format specified
571 * by GL_ARB_ES3_compatibility.
574 _mesa_is_format_etc2(mesa_format format
)
577 case MESA_FORMAT_ETC2_RGB8
:
578 case MESA_FORMAT_ETC2_SRGB8
:
579 case MESA_FORMAT_ETC2_RGBA8_EAC
:
580 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
581 case MESA_FORMAT_ETC2_R11_EAC
:
582 case MESA_FORMAT_ETC2_RG11_EAC
:
583 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
584 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
585 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
586 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
595 * For an sRGB format, return the corresponding linear color space format.
596 * For non-sRGB formats, return the format as-is.
599 _mesa_get_srgb_format_linear(mesa_format format
)
602 case MESA_FORMAT_BGR_SRGB8
:
603 format
= MESA_FORMAT_BGR_UNORM8
;
605 case MESA_FORMAT_A8B8G8R8_SRGB
:
606 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
608 case MESA_FORMAT_B8G8R8A8_SRGB
:
609 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
611 case MESA_FORMAT_A8R8G8B8_SRGB
:
612 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
614 case MESA_FORMAT_R8G8B8A8_SRGB
:
615 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
617 case MESA_FORMAT_L_SRGB8
:
618 format
= MESA_FORMAT_L_UNORM8
;
620 case MESA_FORMAT_L8A8_SRGB
:
621 format
= MESA_FORMAT_L8A8_UNORM
;
623 case MESA_FORMAT_A8L8_SRGB
:
624 format
= MESA_FORMAT_A8L8_UNORM
;
626 case MESA_FORMAT_SRGB_DXT1
:
627 format
= MESA_FORMAT_RGB_DXT1
;
629 case MESA_FORMAT_SRGBA_DXT1
:
630 format
= MESA_FORMAT_RGBA_DXT1
;
632 case MESA_FORMAT_SRGBA_DXT3
:
633 format
= MESA_FORMAT_RGBA_DXT3
;
635 case MESA_FORMAT_SRGBA_DXT5
:
636 format
= MESA_FORMAT_RGBA_DXT5
;
638 case MESA_FORMAT_R8G8B8X8_SRGB
:
639 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
641 case MESA_FORMAT_X8B8G8R8_SRGB
:
642 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
644 case MESA_FORMAT_ETC2_SRGB8
:
645 format
= MESA_FORMAT_ETC2_RGB8
;
647 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
648 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
650 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
651 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
653 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
654 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
656 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
657 format
= MESA_FORMAT_RGBA_ASTC_4x4
;
659 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
660 format
= MESA_FORMAT_RGBA_ASTC_5x4
;
662 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
663 format
= MESA_FORMAT_RGBA_ASTC_5x5
;
665 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
666 format
= MESA_FORMAT_RGBA_ASTC_6x5
;
668 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
669 format
= MESA_FORMAT_RGBA_ASTC_6x6
;
671 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
672 format
= MESA_FORMAT_RGBA_ASTC_8x5
;
674 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
675 format
= MESA_FORMAT_RGBA_ASTC_8x6
;
677 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
678 format
= MESA_FORMAT_RGBA_ASTC_8x8
;
680 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
681 format
= MESA_FORMAT_RGBA_ASTC_10x5
;
683 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
684 format
= MESA_FORMAT_RGBA_ASTC_10x6
;
686 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
687 format
= MESA_FORMAT_RGBA_ASTC_10x8
;
689 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
690 format
= MESA_FORMAT_RGBA_ASTC_10x10
;
692 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
693 format
= MESA_FORMAT_RGBA_ASTC_12x10
;
695 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
696 format
= MESA_FORMAT_RGBA_ASTC_12x12
;
698 case MESA_FORMAT_B8G8R8X8_SRGB
:
699 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
701 case MESA_FORMAT_X8R8G8B8_SRGB
:
702 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
712 * If the given format is a compressed format, return a corresponding
713 * uncompressed format.
716 _mesa_get_uncompressed_format(mesa_format format
)
719 case MESA_FORMAT_RGB_FXT1
:
720 return MESA_FORMAT_BGR_UNORM8
;
721 case MESA_FORMAT_RGBA_FXT1
:
722 return MESA_FORMAT_A8B8G8R8_UNORM
;
723 case MESA_FORMAT_RGB_DXT1
:
724 case MESA_FORMAT_SRGB_DXT1
:
725 return MESA_FORMAT_BGR_UNORM8
;
726 case MESA_FORMAT_RGBA_DXT1
:
727 case MESA_FORMAT_SRGBA_DXT1
:
728 return MESA_FORMAT_A8B8G8R8_UNORM
;
729 case MESA_FORMAT_RGBA_DXT3
:
730 case MESA_FORMAT_SRGBA_DXT3
:
731 return MESA_FORMAT_A8B8G8R8_UNORM
;
732 case MESA_FORMAT_RGBA_DXT5
:
733 case MESA_FORMAT_SRGBA_DXT5
:
734 return MESA_FORMAT_A8B8G8R8_UNORM
;
735 case MESA_FORMAT_R_RGTC1_UNORM
:
736 return MESA_FORMAT_R_UNORM8
;
737 case MESA_FORMAT_R_RGTC1_SNORM
:
738 return MESA_FORMAT_R_SNORM8
;
739 case MESA_FORMAT_RG_RGTC2_UNORM
:
740 return MESA_FORMAT_R8G8_UNORM
;
741 case MESA_FORMAT_RG_RGTC2_SNORM
:
742 return MESA_FORMAT_R8G8_SNORM
;
743 case MESA_FORMAT_L_LATC1_UNORM
:
744 return MESA_FORMAT_L_UNORM8
;
745 case MESA_FORMAT_L_LATC1_SNORM
:
746 return MESA_FORMAT_L_SNORM8
;
747 case MESA_FORMAT_LA_LATC2_UNORM
:
748 return MESA_FORMAT_L8A8_UNORM
;
749 case MESA_FORMAT_LA_LATC2_SNORM
:
750 return MESA_FORMAT_L8A8_SNORM
;
751 case MESA_FORMAT_ETC1_RGB8
:
752 case MESA_FORMAT_ETC2_RGB8
:
753 case MESA_FORMAT_ETC2_SRGB8
:
754 return MESA_FORMAT_BGR_UNORM8
;
755 case MESA_FORMAT_ETC2_RGBA8_EAC
:
756 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
757 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
758 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
759 return MESA_FORMAT_A8B8G8R8_UNORM
;
760 case MESA_FORMAT_ETC2_R11_EAC
:
761 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
762 return MESA_FORMAT_R_UNORM16
;
763 case MESA_FORMAT_ETC2_RG11_EAC
:
764 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
765 return MESA_FORMAT_R16G16_UNORM
;
766 case MESA_FORMAT_BPTC_RGBA_UNORM
:
767 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
768 return MESA_FORMAT_A8B8G8R8_UNORM
;
769 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
770 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
771 return MESA_FORMAT_RGB_FLOAT32
;
774 assert(!_mesa_is_format_compressed(format
));
782 _mesa_format_num_components(mesa_format format
)
784 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
785 return ((info
->RedBits
> 0) +
786 (info
->GreenBits
> 0) +
787 (info
->BlueBits
> 0) +
788 (info
->AlphaBits
> 0) +
789 (info
->LuminanceBits
> 0) +
790 (info
->IntensityBits
> 0) +
791 (info
->DepthBits
> 0) +
792 (info
->StencilBits
> 0));
797 * Returns true if a color format has data stored in the R/G/B/A channels,
798 * given an index from 0 to 3.
801 _mesa_format_has_color_component(mesa_format format
, int component
)
803 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
805 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
806 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
807 info
->BaseFormat
!= GL_STENCIL_INDEX
);
811 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
813 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
815 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
817 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
819 assert(!"Invalid color component: must be 0..3");
826 * Return number of bytes needed to store an image of the given size
827 * in the given format.
830 _mesa_format_image_size(mesa_format format
, GLsizei width
,
831 GLsizei height
, GLsizei depth
)
833 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
834 /* Strictly speaking, a conditional isn't needed here */
835 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
836 /* compressed format (2D only for now) */
837 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
838 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
839 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
840 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
845 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
852 * Same as _mesa_format_image_size() but returns a 64-bit value to
853 * accommodate very large textures.
856 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
857 GLsizei height
, GLsizei depth
)
859 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
860 /* Strictly speaking, a conditional isn't needed here */
861 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
862 /* compressed format (2D only for now) */
863 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
864 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
865 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
866 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
871 const uint64_t sz
= ((uint64_t) width
*
874 info
->BytesPerBlock
);
882 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
884 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
885 /* Strictly speaking, a conditional isn't needed here */
886 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
887 /* compressed format */
888 const GLuint bw
= info
->BlockWidth
;
889 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
890 const GLint stride
= wblocks
* info
->BytesPerBlock
;
894 const GLint stride
= width
* info
->BytesPerBlock
;
902 * Return datatype and number of components per texel for the given
903 * uncompressed mesa_format. Only used for mipmap generation code.
906 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
907 GLenum
*datatype
, GLuint
*comps
)
910 case MESA_FORMAT_A8B8G8R8_UNORM
:
911 case MESA_FORMAT_R8G8B8A8_UNORM
:
912 case MESA_FORMAT_B8G8R8A8_UNORM
:
913 case MESA_FORMAT_A8R8G8B8_UNORM
:
914 case MESA_FORMAT_X8B8G8R8_UNORM
:
915 case MESA_FORMAT_R8G8B8X8_UNORM
:
916 case MESA_FORMAT_B8G8R8X8_UNORM
:
917 case MESA_FORMAT_X8R8G8B8_UNORM
:
918 case MESA_FORMAT_A8B8G8R8_UINT
:
919 case MESA_FORMAT_R8G8B8A8_UINT
:
920 case MESA_FORMAT_B8G8R8A8_UINT
:
921 case MESA_FORMAT_A8R8G8B8_UINT
:
922 *datatype
= GL_UNSIGNED_BYTE
;
925 case MESA_FORMAT_BGR_UNORM8
:
926 case MESA_FORMAT_RGB_UNORM8
:
927 *datatype
= GL_UNSIGNED_BYTE
;
930 case MESA_FORMAT_B5G6R5_UNORM
:
931 case MESA_FORMAT_R5G6B5_UNORM
:
932 case MESA_FORMAT_B5G6R5_UINT
:
933 case MESA_FORMAT_R5G6B5_UINT
:
934 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
938 case MESA_FORMAT_B4G4R4A4_UNORM
:
939 case MESA_FORMAT_A4R4G4B4_UNORM
:
940 case MESA_FORMAT_B4G4R4X4_UNORM
:
941 case MESA_FORMAT_B4G4R4A4_UINT
:
942 case MESA_FORMAT_A4R4G4B4_UINT
:
943 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
947 case MESA_FORMAT_B5G5R5A1_UNORM
:
948 case MESA_FORMAT_A1R5G5B5_UNORM
:
949 case MESA_FORMAT_B5G5R5X1_UNORM
:
950 case MESA_FORMAT_B5G5R5A1_UINT
:
951 case MESA_FORMAT_A1R5G5B5_UINT
:
952 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
956 case MESA_FORMAT_B10G10R10A2_UNORM
:
957 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
961 case MESA_FORMAT_A1B5G5R5_UNORM
:
962 case MESA_FORMAT_A1B5G5R5_UINT
:
963 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
967 case MESA_FORMAT_L4A4_UNORM
:
968 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
972 case MESA_FORMAT_L8A8_UNORM
:
973 case MESA_FORMAT_A8L8_UNORM
:
974 case MESA_FORMAT_R8G8_UNORM
:
975 case MESA_FORMAT_G8R8_UNORM
:
976 *datatype
= GL_UNSIGNED_BYTE
;
980 case MESA_FORMAT_L16A16_UNORM
:
981 case MESA_FORMAT_A16L16_UNORM
:
982 case MESA_FORMAT_R16G16_UNORM
:
983 case MESA_FORMAT_G16R16_UNORM
:
984 *datatype
= GL_UNSIGNED_SHORT
;
988 case MESA_FORMAT_R_UNORM16
:
989 case MESA_FORMAT_A_UNORM16
:
990 case MESA_FORMAT_L_UNORM16
:
991 case MESA_FORMAT_I_UNORM16
:
992 *datatype
= GL_UNSIGNED_SHORT
;
996 case MESA_FORMAT_R3G3B2_UNORM
:
997 case MESA_FORMAT_R3G3B2_UINT
:
998 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1001 case MESA_FORMAT_A4B4G4R4_UNORM
:
1002 case MESA_FORMAT_A4B4G4R4_UINT
:
1003 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1007 case MESA_FORMAT_R4G4B4A4_UNORM
:
1008 case MESA_FORMAT_R4G4B4A4_UINT
:
1009 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1012 case MESA_FORMAT_R5G5B5A1_UNORM
:
1013 case MESA_FORMAT_R5G5B5A1_UINT
:
1014 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1017 case MESA_FORMAT_A2B10G10R10_UNORM
:
1018 case MESA_FORMAT_A2B10G10R10_UINT
:
1019 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1022 case MESA_FORMAT_A2R10G10B10_UNORM
:
1023 case MESA_FORMAT_A2R10G10B10_UINT
:
1024 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1028 case MESA_FORMAT_B2G3R3_UNORM
:
1029 case MESA_FORMAT_B2G3R3_UINT
:
1030 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1034 case MESA_FORMAT_A_UNORM8
:
1035 case MESA_FORMAT_L_UNORM8
:
1036 case MESA_FORMAT_I_UNORM8
:
1037 case MESA_FORMAT_R_UNORM8
:
1038 case MESA_FORMAT_S_UINT8
:
1039 *datatype
= GL_UNSIGNED_BYTE
;
1043 case MESA_FORMAT_YCBCR
:
1044 case MESA_FORMAT_YCBCR_REV
:
1045 *datatype
= GL_UNSIGNED_SHORT
;
1049 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1050 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1054 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1055 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1059 case MESA_FORMAT_Z_UNORM16
:
1060 *datatype
= GL_UNSIGNED_SHORT
;
1064 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1065 *datatype
= GL_UNSIGNED_INT
;
1069 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1070 *datatype
= GL_UNSIGNED_INT
;
1074 case MESA_FORMAT_Z_UNORM32
:
1075 *datatype
= GL_UNSIGNED_INT
;
1079 case MESA_FORMAT_Z_FLOAT32
:
1080 *datatype
= GL_FLOAT
;
1084 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1085 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1089 case MESA_FORMAT_R_SNORM8
:
1090 case MESA_FORMAT_A_SNORM8
:
1091 case MESA_FORMAT_L_SNORM8
:
1092 case MESA_FORMAT_I_SNORM8
:
1093 *datatype
= GL_BYTE
;
1096 case MESA_FORMAT_R8G8_SNORM
:
1097 case MESA_FORMAT_L8A8_SNORM
:
1098 case MESA_FORMAT_A8L8_SNORM
:
1099 *datatype
= GL_BYTE
;
1102 case MESA_FORMAT_A8B8G8R8_SNORM
:
1103 case MESA_FORMAT_R8G8B8A8_SNORM
:
1104 case MESA_FORMAT_X8B8G8R8_SNORM
:
1105 *datatype
= GL_BYTE
;
1109 case MESA_FORMAT_RGBA_UNORM16
:
1110 *datatype
= GL_UNSIGNED_SHORT
;
1114 case MESA_FORMAT_R_SNORM16
:
1115 case MESA_FORMAT_A_SNORM16
:
1116 case MESA_FORMAT_L_SNORM16
:
1117 case MESA_FORMAT_I_SNORM16
:
1118 *datatype
= GL_SHORT
;
1121 case MESA_FORMAT_R16G16_SNORM
:
1122 case MESA_FORMAT_LA_SNORM16
:
1123 *datatype
= GL_SHORT
;
1126 case MESA_FORMAT_RGB_SNORM16
:
1127 *datatype
= GL_SHORT
;
1130 case MESA_FORMAT_RGBA_SNORM16
:
1131 *datatype
= GL_SHORT
;
1135 case MESA_FORMAT_BGR_SRGB8
:
1136 *datatype
= GL_UNSIGNED_BYTE
;
1139 case MESA_FORMAT_A8B8G8R8_SRGB
:
1140 case MESA_FORMAT_B8G8R8A8_SRGB
:
1141 case MESA_FORMAT_A8R8G8B8_SRGB
:
1142 case MESA_FORMAT_R8G8B8A8_SRGB
:
1143 *datatype
= GL_UNSIGNED_BYTE
;
1146 case MESA_FORMAT_L_SRGB8
:
1147 *datatype
= GL_UNSIGNED_BYTE
;
1150 case MESA_FORMAT_L8A8_SRGB
:
1151 case MESA_FORMAT_A8L8_SRGB
:
1152 *datatype
= GL_UNSIGNED_BYTE
;
1156 case MESA_FORMAT_RGBA_FLOAT32
:
1157 *datatype
= GL_FLOAT
;
1160 case MESA_FORMAT_RGBA_FLOAT16
:
1161 *datatype
= GL_HALF_FLOAT_ARB
;
1164 case MESA_FORMAT_RGB_FLOAT32
:
1165 *datatype
= GL_FLOAT
;
1168 case MESA_FORMAT_RGB_FLOAT16
:
1169 *datatype
= GL_HALF_FLOAT_ARB
;
1172 case MESA_FORMAT_LA_FLOAT32
:
1173 case MESA_FORMAT_RG_FLOAT32
:
1174 *datatype
= GL_FLOAT
;
1177 case MESA_FORMAT_LA_FLOAT16
:
1178 case MESA_FORMAT_RG_FLOAT16
:
1179 *datatype
= GL_HALF_FLOAT_ARB
;
1182 case MESA_FORMAT_A_FLOAT32
:
1183 case MESA_FORMAT_L_FLOAT32
:
1184 case MESA_FORMAT_I_FLOAT32
:
1185 case MESA_FORMAT_R_FLOAT32
:
1186 *datatype
= GL_FLOAT
;
1189 case MESA_FORMAT_A_FLOAT16
:
1190 case MESA_FORMAT_L_FLOAT16
:
1191 case MESA_FORMAT_I_FLOAT16
:
1192 case MESA_FORMAT_R_FLOAT16
:
1193 *datatype
= GL_HALF_FLOAT_ARB
;
1197 case MESA_FORMAT_A_UINT8
:
1198 case MESA_FORMAT_L_UINT8
:
1199 case MESA_FORMAT_I_UINT8
:
1200 *datatype
= GL_UNSIGNED_BYTE
;
1203 case MESA_FORMAT_LA_UINT8
:
1204 *datatype
= GL_UNSIGNED_BYTE
;
1208 case MESA_FORMAT_A_UINT16
:
1209 case MESA_FORMAT_L_UINT16
:
1210 case MESA_FORMAT_I_UINT16
:
1211 *datatype
= GL_UNSIGNED_SHORT
;
1214 case MESA_FORMAT_LA_UINT16
:
1215 *datatype
= GL_UNSIGNED_SHORT
;
1218 case MESA_FORMAT_A_UINT32
:
1219 case MESA_FORMAT_L_UINT32
:
1220 case MESA_FORMAT_I_UINT32
:
1221 *datatype
= GL_UNSIGNED_INT
;
1224 case MESA_FORMAT_LA_UINT32
:
1225 *datatype
= GL_UNSIGNED_INT
;
1228 case MESA_FORMAT_A_SINT8
:
1229 case MESA_FORMAT_L_SINT8
:
1230 case MESA_FORMAT_I_SINT8
:
1231 *datatype
= GL_BYTE
;
1234 case MESA_FORMAT_LA_SINT8
:
1235 *datatype
= GL_BYTE
;
1239 case MESA_FORMAT_A_SINT16
:
1240 case MESA_FORMAT_L_SINT16
:
1241 case MESA_FORMAT_I_SINT16
:
1242 *datatype
= GL_SHORT
;
1245 case MESA_FORMAT_LA_SINT16
:
1246 *datatype
= GL_SHORT
;
1250 case MESA_FORMAT_A_SINT32
:
1251 case MESA_FORMAT_L_SINT32
:
1252 case MESA_FORMAT_I_SINT32
:
1256 case MESA_FORMAT_LA_SINT32
:
1261 case MESA_FORMAT_R_SINT8
:
1262 *datatype
= GL_BYTE
;
1265 case MESA_FORMAT_RG_SINT8
:
1266 *datatype
= GL_BYTE
;
1269 case MESA_FORMAT_RGB_SINT8
:
1270 *datatype
= GL_BYTE
;
1273 case MESA_FORMAT_RGBA_SINT8
:
1274 *datatype
= GL_BYTE
;
1277 case MESA_FORMAT_R_SINT16
:
1278 *datatype
= GL_SHORT
;
1281 case MESA_FORMAT_RG_SINT16
:
1282 *datatype
= GL_SHORT
;
1285 case MESA_FORMAT_RGB_SINT16
:
1286 *datatype
= GL_SHORT
;
1289 case MESA_FORMAT_RGBA_SINT16
:
1290 *datatype
= GL_SHORT
;
1293 case MESA_FORMAT_R_SINT32
:
1297 case MESA_FORMAT_RG_SINT32
:
1301 case MESA_FORMAT_RGB_SINT32
:
1305 case MESA_FORMAT_RGBA_SINT32
:
1311 * \name Non-normalized unsigned integer formats.
1313 case MESA_FORMAT_R_UINT8
:
1314 *datatype
= GL_UNSIGNED_BYTE
;
1317 case MESA_FORMAT_RG_UINT8
:
1318 *datatype
= GL_UNSIGNED_BYTE
;
1321 case MESA_FORMAT_RGB_UINT8
:
1322 *datatype
= GL_UNSIGNED_BYTE
;
1325 case MESA_FORMAT_RGBA_UINT8
:
1326 *datatype
= GL_UNSIGNED_BYTE
;
1329 case MESA_FORMAT_R_UINT16
:
1330 *datatype
= GL_UNSIGNED_SHORT
;
1333 case MESA_FORMAT_RG_UINT16
:
1334 *datatype
= GL_UNSIGNED_SHORT
;
1337 case MESA_FORMAT_RGB_UINT16
:
1338 *datatype
= GL_UNSIGNED_SHORT
;
1341 case MESA_FORMAT_RGBA_UINT16
:
1342 *datatype
= GL_UNSIGNED_SHORT
;
1345 case MESA_FORMAT_R_UINT32
:
1346 *datatype
= GL_UNSIGNED_INT
;
1349 case MESA_FORMAT_RG_UINT32
:
1350 *datatype
= GL_UNSIGNED_INT
;
1353 case MESA_FORMAT_RGB_UINT32
:
1354 *datatype
= GL_UNSIGNED_INT
;
1357 case MESA_FORMAT_RGBA_UINT32
:
1358 *datatype
= GL_UNSIGNED_INT
;
1362 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1363 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1367 case MESA_FORMAT_R11G11B10_FLOAT
:
1368 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1372 case MESA_FORMAT_B10G10R10A2_UINT
:
1373 case MESA_FORMAT_R10G10B10A2_UINT
:
1374 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1378 case MESA_FORMAT_R8G8B8X8_SRGB
:
1379 case MESA_FORMAT_X8B8G8R8_SRGB
:
1380 case MESA_FORMAT_RGBX_UINT8
:
1381 *datatype
= GL_UNSIGNED_BYTE
;
1385 case MESA_FORMAT_R8G8B8X8_SNORM
:
1386 case MESA_FORMAT_RGBX_SINT8
:
1387 *datatype
= GL_BYTE
;
1391 case MESA_FORMAT_B10G10R10X2_UNORM
:
1392 case MESA_FORMAT_R10G10B10X2_UNORM
:
1393 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1397 case MESA_FORMAT_RGBX_UNORM16
:
1398 case MESA_FORMAT_RGBX_UINT16
:
1399 *datatype
= GL_UNSIGNED_SHORT
;
1403 case MESA_FORMAT_RGBX_SNORM16
:
1404 case MESA_FORMAT_RGBX_SINT16
:
1405 *datatype
= GL_SHORT
;
1409 case MESA_FORMAT_RGBX_FLOAT16
:
1410 *datatype
= GL_HALF_FLOAT
;
1414 case MESA_FORMAT_RGBX_FLOAT32
:
1415 *datatype
= GL_FLOAT
;
1419 case MESA_FORMAT_RGBX_UINT32
:
1420 *datatype
= GL_UNSIGNED_INT
;
1424 case MESA_FORMAT_RGBX_SINT32
:
1429 case MESA_FORMAT_R10G10B10A2_UNORM
:
1430 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1434 case MESA_FORMAT_G8R8_SNORM
:
1435 *datatype
= GL_BYTE
;
1439 case MESA_FORMAT_G16R16_SNORM
:
1440 *datatype
= GL_SHORT
;
1444 case MESA_FORMAT_B8G8R8X8_SRGB
:
1445 case MESA_FORMAT_X8R8G8B8_SRGB
:
1446 *datatype
= GL_UNSIGNED_BYTE
;
1450 case MESA_FORMAT_COUNT
:
1454 /* Warn if any formats are not handled */
1455 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1456 _mesa_get_format_name(format
));
1457 assert(format
== MESA_FORMAT_NONE
||
1458 _mesa_is_format_compressed(format
));
1465 * Check if a mesa_format exactly matches a GL format/type combination
1466 * such that we can use memcpy() from one to the other.
1467 * \param mesa_format a MESA_FORMAT_x value
1468 * \param format the user-specified image format
1469 * \param type the user-specified image datatype
1470 * \param swapBytes typically the current pixel pack/unpack byteswap state
1471 * \param[out] error GL_NO_ERROR if format is an expected input.
1472 * GL_INVALID_ENUM if format is an unexpected input.
1473 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1476 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1477 GLenum format
, GLenum type
,
1478 GLboolean swapBytes
, GLenum
*error
)
1480 const GLboolean littleEndian
= _mesa_little_endian();
1482 *error
= GL_NO_ERROR
;
1484 /* Note: When reading a GL format/type combination, the format lists channel
1485 * assignments from most significant channel in the type to least
1486 * significant. A type with _REV indicates that the assignments are
1487 * swapped, so they are listed from least significant to most significant.
1489 * Compressed formats will fall through and return GL_FALSE.
1491 * For sanity, please keep this switch statement ordered the same as the
1492 * enums in formats.h.
1495 switch (mesa_format
) {
1497 case MESA_FORMAT_NONE
:
1498 case MESA_FORMAT_COUNT
:
1501 case MESA_FORMAT_A8B8G8R8_UNORM
:
1502 case MESA_FORMAT_A8B8G8R8_SRGB
:
1503 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1506 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1509 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1512 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1516 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1520 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1525 case MESA_FORMAT_R8G8B8A8_UNORM
:
1526 case MESA_FORMAT_R8G8B8A8_SRGB
:
1527 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1531 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1534 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1537 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1541 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1545 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1550 case MESA_FORMAT_B8G8R8A8_UNORM
:
1551 case MESA_FORMAT_B8G8R8A8_SRGB
:
1552 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1556 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1559 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1564 case MESA_FORMAT_A8R8G8B8_UNORM
:
1565 case MESA_FORMAT_A8R8G8B8_SRGB
:
1566 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1569 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1573 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1578 case MESA_FORMAT_X8B8G8R8_UNORM
:
1579 case MESA_FORMAT_R8G8B8X8_UNORM
:
1582 case MESA_FORMAT_B8G8R8X8_UNORM
:
1583 case MESA_FORMAT_X8R8G8B8_UNORM
:
1586 case MESA_FORMAT_BGR_UNORM8
:
1587 case MESA_FORMAT_BGR_SRGB8
:
1588 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1590 case MESA_FORMAT_RGB_UNORM8
:
1591 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1593 case MESA_FORMAT_B5G6R5_UNORM
:
1594 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1595 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1598 case MESA_FORMAT_R5G6B5_UNORM
:
1599 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1600 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1603 case MESA_FORMAT_B4G4R4A4_UNORM
:
1604 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1607 case MESA_FORMAT_A4R4G4B4_UNORM
:
1610 case MESA_FORMAT_A1B5G5R5_UNORM
:
1611 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1614 case MESA_FORMAT_B5G5R5A1_UNORM
:
1615 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1618 case MESA_FORMAT_A1R5G5B5_UNORM
:
1619 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1622 case MESA_FORMAT_L4A4_UNORM
:
1624 case MESA_FORMAT_L8A8_UNORM
:
1625 case MESA_FORMAT_L8A8_SRGB
:
1626 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1627 case MESA_FORMAT_A8L8_UNORM
:
1628 case MESA_FORMAT_A8L8_SRGB
:
1631 case MESA_FORMAT_L16A16_UNORM
:
1632 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1633 case MESA_FORMAT_A16L16_UNORM
:
1636 case MESA_FORMAT_B2G3R3_UNORM
:
1637 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1639 case MESA_FORMAT_R3G3B2_UNORM
:
1640 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1642 case MESA_FORMAT_A4B4G4R4_UNORM
:
1643 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1646 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1649 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1652 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1657 case MESA_FORMAT_R4G4B4A4_UNORM
:
1658 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1661 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1664 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1667 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1672 case MESA_FORMAT_R5G5B5A1_UNORM
:
1673 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1675 case MESA_FORMAT_A2B10G10R10_UNORM
:
1676 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1678 case MESA_FORMAT_A2B10G10R10_UINT
:
1679 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1681 case MESA_FORMAT_A2R10G10B10_UNORM
:
1682 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1684 case MESA_FORMAT_A2R10G10B10_UINT
:
1685 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1687 case MESA_FORMAT_A_UNORM8
:
1688 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1689 case MESA_FORMAT_A_UNORM16
:
1690 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1691 case MESA_FORMAT_L_UNORM8
:
1692 case MESA_FORMAT_L_SRGB8
:
1693 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1694 case MESA_FORMAT_L_UNORM16
:
1695 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1696 case MESA_FORMAT_I_UNORM8
:
1697 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1698 case MESA_FORMAT_I_UNORM16
:
1699 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1701 case MESA_FORMAT_YCBCR
:
1702 return format
== GL_YCBCR_MESA
&&
1703 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1704 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1705 case MESA_FORMAT_YCBCR_REV
:
1706 return format
== GL_YCBCR_MESA
&&
1707 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1708 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1710 case MESA_FORMAT_R_UNORM8
:
1711 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1712 case MESA_FORMAT_R8G8_UNORM
:
1713 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1714 case MESA_FORMAT_G8R8_UNORM
:
1717 case MESA_FORMAT_R_UNORM16
:
1718 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1720 case MESA_FORMAT_R16G16_UNORM
:
1721 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1723 case MESA_FORMAT_G16R16_UNORM
:
1726 case MESA_FORMAT_B10G10R10A2_UNORM
:
1727 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1730 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1731 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1733 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1734 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1737 case MESA_FORMAT_Z_UNORM16
:
1738 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1741 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1744 case MESA_FORMAT_Z_UNORM32
:
1745 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1748 case MESA_FORMAT_S_UINT8
:
1749 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1751 case MESA_FORMAT_RGBA_FLOAT32
:
1752 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1753 case MESA_FORMAT_RGBA_FLOAT16
:
1754 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1756 case MESA_FORMAT_RGB_FLOAT32
:
1757 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1758 case MESA_FORMAT_RGB_FLOAT16
:
1759 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1761 case MESA_FORMAT_A_FLOAT32
:
1762 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1763 case MESA_FORMAT_A_FLOAT16
:
1764 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1766 case MESA_FORMAT_L_FLOAT32
:
1767 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1768 case MESA_FORMAT_L_FLOAT16
:
1769 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1771 case MESA_FORMAT_LA_FLOAT32
:
1772 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1773 case MESA_FORMAT_LA_FLOAT16
:
1774 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1776 case MESA_FORMAT_I_FLOAT32
:
1777 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1778 case MESA_FORMAT_I_FLOAT16
:
1779 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1781 case MESA_FORMAT_R_FLOAT32
:
1782 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1783 case MESA_FORMAT_R_FLOAT16
:
1784 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1786 case MESA_FORMAT_RG_FLOAT32
:
1787 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1788 case MESA_FORMAT_RG_FLOAT16
:
1789 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1791 case MESA_FORMAT_A_UINT8
:
1792 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1793 case MESA_FORMAT_A_UINT16
:
1794 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1796 case MESA_FORMAT_A_UINT32
:
1797 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1799 case MESA_FORMAT_A_SINT8
:
1800 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1801 case MESA_FORMAT_A_SINT16
:
1802 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1803 case MESA_FORMAT_A_SINT32
:
1804 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1806 case MESA_FORMAT_I_UINT8
:
1807 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1808 case MESA_FORMAT_I_UINT16
:
1809 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1810 case MESA_FORMAT_I_UINT32
:
1811 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1812 case MESA_FORMAT_I_SINT8
:
1813 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1814 case MESA_FORMAT_I_SINT16
:
1815 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1816 case MESA_FORMAT_I_SINT32
:
1817 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1819 case MESA_FORMAT_L_UINT8
:
1820 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1821 case MESA_FORMAT_L_UINT16
:
1822 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1824 case MESA_FORMAT_L_UINT32
:
1825 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1827 case MESA_FORMAT_L_SINT8
:
1828 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1829 case MESA_FORMAT_L_SINT16
:
1830 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1832 case MESA_FORMAT_L_SINT32
:
1833 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1835 case MESA_FORMAT_LA_UINT8
:
1836 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1837 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1838 case MESA_FORMAT_LA_UINT16
:
1839 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1840 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1841 case MESA_FORMAT_LA_UINT32
:
1842 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1843 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1844 case MESA_FORMAT_LA_SINT8
:
1845 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1847 case MESA_FORMAT_LA_SINT16
:
1848 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1850 case MESA_FORMAT_LA_SINT32
:
1851 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1854 case MESA_FORMAT_R_SINT8
:
1855 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1856 case MESA_FORMAT_RG_SINT8
:
1857 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1858 case MESA_FORMAT_RGB_SINT8
:
1859 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1860 case MESA_FORMAT_RGBA_SINT8
:
1861 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1862 case MESA_FORMAT_R_SINT16
:
1863 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1864 case MESA_FORMAT_RG_SINT16
:
1865 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1866 case MESA_FORMAT_RGB_SINT16
:
1867 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1868 case MESA_FORMAT_RGBA_SINT16
:
1869 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1870 case MESA_FORMAT_R_SINT32
:
1871 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1872 case MESA_FORMAT_RG_SINT32
:
1873 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1874 case MESA_FORMAT_RGB_SINT32
:
1875 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1876 case MESA_FORMAT_RGBA_SINT32
:
1877 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1879 case MESA_FORMAT_R_UINT8
:
1880 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1881 case MESA_FORMAT_RG_UINT8
:
1882 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1883 case MESA_FORMAT_RGB_UINT8
:
1884 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1885 case MESA_FORMAT_RGBA_UINT8
:
1886 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1888 case MESA_FORMAT_R_UINT16
:
1889 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1891 case MESA_FORMAT_RG_UINT16
:
1892 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1893 case MESA_FORMAT_RGB_UINT16
:
1894 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1896 case MESA_FORMAT_RGBA_UINT16
:
1897 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1899 case MESA_FORMAT_R_UINT32
:
1900 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1901 case MESA_FORMAT_RG_UINT32
:
1902 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1903 case MESA_FORMAT_RGB_UINT32
:
1904 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1905 case MESA_FORMAT_RGBA_UINT32
:
1906 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1908 case MESA_FORMAT_R_SNORM8
:
1909 return format
== GL_RED
&& type
== GL_BYTE
;
1910 case MESA_FORMAT_R8G8_SNORM
:
1911 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1913 case MESA_FORMAT_X8B8G8R8_SNORM
:
1916 case MESA_FORMAT_A8B8G8R8_SNORM
:
1917 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1920 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1925 case MESA_FORMAT_R8G8B8A8_SNORM
:
1926 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1929 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1934 case MESA_FORMAT_R_SNORM16
:
1935 return format
== GL_RED
&& type
== GL_SHORT
&&
1937 case MESA_FORMAT_R16G16_SNORM
:
1938 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1939 case MESA_FORMAT_RGB_SNORM16
:
1940 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1941 case MESA_FORMAT_RGBA_SNORM16
:
1942 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1943 case MESA_FORMAT_RGBA_UNORM16
:
1944 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1947 case MESA_FORMAT_A_SNORM8
:
1948 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1949 case MESA_FORMAT_L_SNORM8
:
1950 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1951 case MESA_FORMAT_L8A8_SNORM
:
1952 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1953 littleEndian
&& !swapBytes
;
1954 case MESA_FORMAT_A8L8_SNORM
:
1955 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1956 !littleEndian
&& !swapBytes
;
1957 case MESA_FORMAT_I_SNORM8
:
1958 return format
== GL_RED
&& type
== GL_BYTE
;
1959 case MESA_FORMAT_A_SNORM16
:
1960 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1961 case MESA_FORMAT_L_SNORM16
:
1962 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1963 case MESA_FORMAT_LA_SNORM16
:
1964 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1965 littleEndian
&& !swapBytes
;
1966 case MESA_FORMAT_I_SNORM16
:
1967 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1970 case MESA_FORMAT_B10G10R10A2_UINT
:
1971 return (format
== GL_BGRA_INTEGER_EXT
&&
1972 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1975 case MESA_FORMAT_R10G10B10A2_UINT
:
1976 return (format
== GL_RGBA_INTEGER_EXT
&&
1977 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1980 case MESA_FORMAT_B5G6R5_UINT
:
1981 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1983 case MESA_FORMAT_R5G6B5_UINT
:
1984 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1986 case MESA_FORMAT_B2G3R3_UINT
:
1987 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1989 case MESA_FORMAT_R3G3B2_UINT
:
1990 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1992 case MESA_FORMAT_A4B4G4R4_UINT
:
1993 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1996 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
2000 case MESA_FORMAT_R4G4B4A4_UINT
:
2001 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
2004 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
2009 case MESA_FORMAT_B4G4R4A4_UINT
:
2010 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
2013 case MESA_FORMAT_A4R4G4B4_UINT
:
2016 case MESA_FORMAT_A1B5G5R5_UINT
:
2017 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2020 case MESA_FORMAT_B5G5R5A1_UINT
:
2021 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
2024 case MESA_FORMAT_A1R5G5B5_UINT
:
2025 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2028 case MESA_FORMAT_R5G5B5A1_UINT
:
2029 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
2031 case MESA_FORMAT_A8B8G8R8_UINT
:
2032 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
2035 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
2039 case MESA_FORMAT_A8R8G8B8_UINT
:
2040 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
2044 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2050 case MESA_FORMAT_R8G8B8A8_UINT
:
2051 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2055 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2060 case MESA_FORMAT_B8G8R8A8_UINT
:
2061 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2065 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2070 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2071 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2074 case MESA_FORMAT_R11G11B10_FLOAT
:
2075 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2078 case MESA_FORMAT_Z_FLOAT32
:
2079 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2081 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2082 return format
== GL_DEPTH_STENCIL
&&
2083 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2085 case MESA_FORMAT_B4G4R4X4_UNORM
:
2086 case MESA_FORMAT_B5G5R5X1_UNORM
:
2087 case MESA_FORMAT_R8G8B8X8_SNORM
:
2088 case MESA_FORMAT_R8G8B8X8_SRGB
:
2089 case MESA_FORMAT_X8B8G8R8_SRGB
:
2090 case MESA_FORMAT_RGBX_UINT8
:
2091 case MESA_FORMAT_RGBX_SINT8
:
2092 case MESA_FORMAT_B10G10R10X2_UNORM
:
2093 case MESA_FORMAT_R10G10B10X2_UNORM
:
2094 case MESA_FORMAT_RGBX_UNORM16
:
2095 case MESA_FORMAT_RGBX_SNORM16
:
2096 case MESA_FORMAT_RGBX_FLOAT16
:
2097 case MESA_FORMAT_RGBX_UINT16
:
2098 case MESA_FORMAT_RGBX_SINT16
:
2099 case MESA_FORMAT_RGBX_FLOAT32
:
2100 case MESA_FORMAT_RGBX_UINT32
:
2101 case MESA_FORMAT_RGBX_SINT32
:
2104 case MESA_FORMAT_R10G10B10A2_UNORM
:
2105 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2108 case MESA_FORMAT_G8R8_SNORM
:
2109 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2112 case MESA_FORMAT_G16R16_SNORM
:
2113 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2116 case MESA_FORMAT_B8G8R8X8_SRGB
:
2117 case MESA_FORMAT_X8R8G8B8_SRGB
:
2120 assert(_mesa_is_format_compressed(mesa_format
));
2122 *error
= GL_INVALID_ENUM
;