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.
31 #include "glformats.h"
32 #include "c11/threads.h"
33 #include "util/hash_table.h"
36 * Information about texture formats.
42 /** text name for debugging */
45 enum mesa_format_layout Layout
;
48 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
49 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
50 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
55 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
56 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
64 GLubyte LuminanceBits
;
65 GLubyte IntensityBits
;
72 * To describe compressed formats. If not compressed, Width=Height=Depth=1.
74 GLubyte BlockWidth
, BlockHeight
, BlockDepth
;
75 GLubyte BytesPerBlock
;
78 mesa_array_format ArrayFormat
;
81 #include "format_info.h"
83 static const struct gl_format_info
*
84 _mesa_get_format_info(mesa_format format
)
86 const struct gl_format_info
*info
= &format_info
[format
];
87 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
88 assert(info
->Name
== format
);
93 /** Return string name of format (for debugging) */
95 _mesa_get_format_name(mesa_format format
)
97 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
104 * Return bytes needed to store a block of pixels in the given format.
105 * Normally, a block is 1x1 (a single pixel). But for compressed formats
106 * a block may be 4x4 or 8x4, etc.
108 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
111 _mesa_get_format_bytes(mesa_format format
)
113 if (_mesa_format_is_mesa_array_format(format
)) {
114 return _mesa_array_format_get_type_size(format
) *
115 _mesa_array_format_get_num_channels(format
);
118 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
119 assert(info
->BytesPerBlock
);
120 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
121 _mesa_is_format_compressed(format
));
122 return info
->BytesPerBlock
;
127 * Return bits per component for the given format.
128 * \param format one of MESA_FORMAT_x
129 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
132 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
134 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
138 case GL_TEXTURE_RED_SIZE
:
139 case GL_RENDERBUFFER_RED_SIZE_EXT
:
140 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
141 case GL_INTERNALFORMAT_RED_SIZE
:
142 return info
->RedBits
;
144 case GL_TEXTURE_GREEN_SIZE
:
145 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
146 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
147 case GL_INTERNALFORMAT_GREEN_SIZE
:
148 return info
->GreenBits
;
150 case GL_TEXTURE_BLUE_SIZE
:
151 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
152 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
153 case GL_INTERNALFORMAT_BLUE_SIZE
:
154 return info
->BlueBits
;
156 case GL_TEXTURE_ALPHA_SIZE
:
157 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
158 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
159 case GL_INTERNALFORMAT_ALPHA_SIZE
:
160 return info
->AlphaBits
;
161 case GL_TEXTURE_INTENSITY_SIZE
:
162 return info
->IntensityBits
;
163 case GL_TEXTURE_LUMINANCE_SIZE
:
164 return info
->LuminanceBits
;
168 case GL_TEXTURE_DEPTH_SIZE_ARB
:
169 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
170 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
171 case GL_INTERNALFORMAT_DEPTH_SIZE
:
172 return info
->DepthBits
;
173 case GL_STENCIL_BITS
:
174 case GL_TEXTURE_STENCIL_SIZE_EXT
:
175 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
176 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
177 case GL_INTERNALFORMAT_STENCIL_SIZE
:
178 return info
->StencilBits
;
180 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
187 _mesa_get_format_max_bits(mesa_format format
)
189 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
190 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
191 max
= MAX2(max
, info
->BlueBits
);
192 max
= MAX2(max
, info
->AlphaBits
);
193 max
= MAX2(max
, info
->LuminanceBits
);
194 max
= MAX2(max
, info
->IntensityBits
);
195 max
= MAX2(max
, info
->DepthBits
);
196 max
= MAX2(max
, info
->StencilBits
);
202 * Return the layout type of the given format.
204 extern enum mesa_format_layout
205 _mesa_get_format_layout(mesa_format format
)
207 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
213 * Return the data type (or more specifically, the data representation)
214 * for the given format.
215 * The return value will be one of:
216 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
217 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
218 * GL_UNSIGNED_INT = an ordinary unsigned integer
219 * GL_INT = an ordinary signed integer
220 * GL_FLOAT = an ordinary float
223 _mesa_get_format_datatype(mesa_format format
)
225 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
226 return info
->DataType
;
230 get_base_format_for_array_format(mesa_array_format format
)
235 _mesa_array_format_get_swizzle(format
, swizzle
);
236 num_channels
= _mesa_array_format_get_num_channels(format
);
238 switch (num_channels
) {
240 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
241 * This is not really a problem for now because we only create array
242 * formats from GL format/type combinations, and these cannot specify
249 if (swizzle
[0] == 0 &&
253 return GL_LUMINANCE_ALPHA
;
254 if (swizzle
[0] == 1 &&
258 return GL_LUMINANCE_ALPHA
;
259 if (swizzle
[0] == 0 &&
264 if (swizzle
[0] == 1 &&
271 if (swizzle
[0] == 0 &&
276 if (swizzle
[0] == 0 &&
281 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
283 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
285 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
287 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
292 unreachable("Unsupported format");
296 * Return the basic format for the given type. The result will be one of
297 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
298 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
299 * This functions accepts a mesa_format or a mesa_array_format.
302 _mesa_get_format_base_format(uint32_t format
)
304 if (!_mesa_format_is_mesa_array_format(format
)) {
305 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
306 return info
->BaseFormat
;
308 return get_base_format_for_array_format(format
);
314 * Return the block size (in pixels) for the given format. Normally
315 * the block size is 1x1. But compressed formats will have block sizes
316 * of 4x4 or 8x4 pixels, etc.
317 * \param bw returns block width in pixels
318 * \param bh returns block height in pixels
321 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
323 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
324 /* Use _mesa_get_format_block_size_3d() for 3D blocks. */
325 assert(info
->BlockDepth
== 1);
327 *bw
= info
->BlockWidth
;
328 *bh
= info
->BlockHeight
;
333 * Return the block size (in pixels) for the given format. Normally
334 * the block size is 1x1x1. But compressed formats will have block
335 * sizes of 4x4x4, 3x3x3 pixels, etc.
336 * \param bw returns block width in pixels
337 * \param bh returns block height in pixels
338 * \param bd returns block depth in pixels
341 _mesa_get_format_block_size_3d(mesa_format format
,
346 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
347 *bw
= info
->BlockWidth
;
348 *bh
= info
->BlockHeight
;
349 *bd
= info
->BlockDepth
;
354 * Returns the an array of four numbers representing the transformation
355 * from the RGBA or SZ colorspace to the given format. For array formats,
356 * the i'th RGBA component is given by:
358 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
359 * comp = data[swizzle[i]];
360 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
362 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
364 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
365 * // data does not contain a channel of this format
367 * For packed formats, the swizzle gives the number of components left of
368 * the least significant bit.
370 * Compressed formats have no swizzle.
373 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
375 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
376 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
380 _mesa_array_format_flip_channels(mesa_array_format format
)
385 num_channels
= _mesa_array_format_get_num_channels(format
);
386 _mesa_array_format_get_swizzle(format
, swizzle
);
388 if (num_channels
== 1)
391 if (num_channels
== 2) {
392 /* Assert that the swizzle makes sense for 2 channels */
393 for (unsigned i
= 0; i
< 4; i
++)
394 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
396 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
397 _mesa_array_format_set_swizzle(&format
,
398 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
399 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
403 if (num_channels
== 4) {
404 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
405 _mesa_array_format_set_swizzle(&format
,
406 flip
[swizzle
[0]], flip
[swizzle
[1]],
407 flip
[swizzle
[2]], flip
[swizzle
[3]]);
411 unreachable("Invalid array format");
415 _mesa_format_to_array_format(mesa_format format
)
417 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
418 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
419 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
420 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
422 return info
->ArrayFormat
;
425 static struct hash_table
*format_array_format_table
;
426 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
429 array_formats_equal(const void *a
, const void *b
)
431 return (intptr_t)a
== (intptr_t)b
;
435 format_array_format_table_init(void)
437 const struct gl_format_info
*info
;
438 mesa_array_format array_format
;
441 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
442 array_formats_equal
);
444 if (!format_array_format_table
) {
445 _mesa_error_no_memory(__func__
);
449 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
450 info
= _mesa_get_format_info(f
);
451 if (!info
->ArrayFormat
)
454 if (_mesa_little_endian()) {
455 array_format
= info
->ArrayFormat
;
457 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
460 /* This can happen and does for some of the BGR formats. Let's take
461 * the first one in the list.
463 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
465 (void *)(intptr_t)array_format
))
468 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
470 (void *)(intptr_t)array_format
,
471 (void *)(intptr_t)f
);
476 _mesa_format_from_array_format(uint32_t array_format
)
478 struct hash_entry
*entry
;
480 assert(_mesa_format_is_mesa_array_format(array_format
));
482 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
484 if (!format_array_format_table
) {
485 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
486 format_array_format_table_exists
= once_flag_init
;
487 return MESA_FORMAT_NONE
;
490 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
492 (void *)(intptr_t)array_format
);
494 return (intptr_t)entry
->data
;
496 return MESA_FORMAT_NONE
;
499 /** Is the given format a compressed format? */
501 _mesa_is_format_compressed(mesa_format format
)
503 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
504 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
509 * Determine if the given format represents a packed depth/stencil buffer.
512 _mesa_is_format_packed_depth_stencil(mesa_format format
)
514 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
516 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
521 * Is the given format a signed/unsigned integer color format?
524 _mesa_is_format_integer_color(mesa_format format
)
526 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
527 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
528 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
529 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
530 info
->BaseFormat
!= GL_STENCIL_INDEX
;
535 * Is the given format an unsigned integer format?
538 _mesa_is_format_unsigned(mesa_format format
)
540 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
541 return _mesa_is_type_unsigned(info
->DataType
);
546 * Does the given format store signed values?
549 _mesa_is_format_signed(mesa_format format
)
551 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
552 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
553 /* these packed float formats only store unsigned values */
557 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
558 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
559 info
->DataType
== GL_INT
||
560 info
->DataType
== GL_FLOAT
);
565 * Is the given format an integer format?
568 _mesa_is_format_integer(mesa_format format
)
570 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
571 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
576 * Return true if the given format is a color format.
579 _mesa_is_format_color_format(mesa_format format
)
581 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
582 switch (info
->BaseFormat
) {
583 case GL_DEPTH_COMPONENT
:
584 case GL_STENCIL_INDEX
:
585 case GL_DEPTH_STENCIL
:
594 * Return color encoding for given format.
595 * \return GL_LINEAR or GL_SRGB
598 _mesa_get_format_color_encoding(mesa_format format
)
600 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
601 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
606 * Return TRUE if format is an ETC2 compressed format specified
607 * by GL_ARB_ES3_compatibility.
610 _mesa_is_format_etc2(mesa_format format
)
613 case MESA_FORMAT_ETC2_RGB8
:
614 case MESA_FORMAT_ETC2_SRGB8
:
615 case MESA_FORMAT_ETC2_RGBA8_EAC
:
616 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
617 case MESA_FORMAT_ETC2_R11_EAC
:
618 case MESA_FORMAT_ETC2_RG11_EAC
:
619 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
620 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
621 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
622 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
631 * Return TRUE if format is an ASTC 2D compressed format.
634 _mesa_is_format_astc_2d(mesa_format format
)
637 case MESA_FORMAT_RGBA_ASTC_4x4
:
638 case MESA_FORMAT_RGBA_ASTC_5x4
:
639 case MESA_FORMAT_RGBA_ASTC_5x5
:
640 case MESA_FORMAT_RGBA_ASTC_6x5
:
641 case MESA_FORMAT_RGBA_ASTC_6x6
:
642 case MESA_FORMAT_RGBA_ASTC_8x5
:
643 case MESA_FORMAT_RGBA_ASTC_8x6
:
644 case MESA_FORMAT_RGBA_ASTC_8x8
:
645 case MESA_FORMAT_RGBA_ASTC_10x5
:
646 case MESA_FORMAT_RGBA_ASTC_10x6
:
647 case MESA_FORMAT_RGBA_ASTC_10x8
:
648 case MESA_FORMAT_RGBA_ASTC_10x10
:
649 case MESA_FORMAT_RGBA_ASTC_12x10
:
650 case MESA_FORMAT_RGBA_ASTC_12x12
:
651 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
652 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
653 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
654 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
655 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
656 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
657 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
658 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
659 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
660 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
661 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
662 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
663 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
664 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
673 * If the given format is a compressed format, return a corresponding
674 * uncompressed format.
677 _mesa_get_uncompressed_format(mesa_format format
)
680 case MESA_FORMAT_RGB_FXT1
:
681 return MESA_FORMAT_BGR_UNORM8
;
682 case MESA_FORMAT_RGBA_FXT1
:
683 return MESA_FORMAT_A8B8G8R8_UNORM
;
684 case MESA_FORMAT_RGB_DXT1
:
685 case MESA_FORMAT_SRGB_DXT1
:
686 return MESA_FORMAT_BGR_UNORM8
;
687 case MESA_FORMAT_RGBA_DXT1
:
688 case MESA_FORMAT_SRGBA_DXT1
:
689 return MESA_FORMAT_A8B8G8R8_UNORM
;
690 case MESA_FORMAT_RGBA_DXT3
:
691 case MESA_FORMAT_SRGBA_DXT3
:
692 return MESA_FORMAT_A8B8G8R8_UNORM
;
693 case MESA_FORMAT_RGBA_DXT5
:
694 case MESA_FORMAT_SRGBA_DXT5
:
695 return MESA_FORMAT_A8B8G8R8_UNORM
;
696 case MESA_FORMAT_R_RGTC1_UNORM
:
697 return MESA_FORMAT_R_UNORM8
;
698 case MESA_FORMAT_R_RGTC1_SNORM
:
699 return MESA_FORMAT_R_SNORM8
;
700 case MESA_FORMAT_RG_RGTC2_UNORM
:
701 return MESA_FORMAT_R8G8_UNORM
;
702 case MESA_FORMAT_RG_RGTC2_SNORM
:
703 return MESA_FORMAT_R8G8_SNORM
;
704 case MESA_FORMAT_L_LATC1_UNORM
:
705 return MESA_FORMAT_L_UNORM8
;
706 case MESA_FORMAT_L_LATC1_SNORM
:
707 return MESA_FORMAT_L_SNORM8
;
708 case MESA_FORMAT_LA_LATC2_UNORM
:
709 return MESA_FORMAT_L8A8_UNORM
;
710 case MESA_FORMAT_LA_LATC2_SNORM
:
711 return MESA_FORMAT_L8A8_SNORM
;
712 case MESA_FORMAT_ETC1_RGB8
:
713 case MESA_FORMAT_ETC2_RGB8
:
714 case MESA_FORMAT_ETC2_SRGB8
:
715 case MESA_FORMAT_ATC_RGB
:
716 return MESA_FORMAT_BGR_UNORM8
;
717 case MESA_FORMAT_ETC2_RGBA8_EAC
:
718 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
719 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
720 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
721 case MESA_FORMAT_ATC_RGBA_EXPLICIT
:
722 case MESA_FORMAT_ATC_RGBA_INTERPOLATED
:
723 return MESA_FORMAT_A8B8G8R8_UNORM
;
724 case MESA_FORMAT_ETC2_R11_EAC
:
725 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
726 return MESA_FORMAT_R_UNORM16
;
727 case MESA_FORMAT_ETC2_RG11_EAC
:
728 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
729 return MESA_FORMAT_R16G16_UNORM
;
730 case MESA_FORMAT_BPTC_RGBA_UNORM
:
731 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
732 return MESA_FORMAT_A8B8G8R8_UNORM
;
733 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
734 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
735 return MESA_FORMAT_RGB_FLOAT32
;
737 assert(!_mesa_is_format_compressed(format
));
744 _mesa_format_num_components(mesa_format format
)
746 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
747 return ((info
->RedBits
> 0) +
748 (info
->GreenBits
> 0) +
749 (info
->BlueBits
> 0) +
750 (info
->AlphaBits
> 0) +
751 (info
->LuminanceBits
> 0) +
752 (info
->IntensityBits
> 0) +
753 (info
->DepthBits
> 0) +
754 (info
->StencilBits
> 0));
759 * Returns true if a color format has data stored in the R/G/B/A channels,
760 * given an index from 0 to 3.
763 _mesa_format_has_color_component(mesa_format format
, int component
)
765 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
767 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
768 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
769 info
->BaseFormat
!= GL_STENCIL_INDEX
);
773 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
775 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
777 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
779 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
781 assert(!"Invalid color component: must be 0..3");
788 * Return number of bytes needed to store an image of the given size
789 * in the given format.
792 _mesa_format_image_size(mesa_format format
, GLsizei width
,
793 GLsizei height
, GLsizei depth
)
795 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
797 /* Strictly speaking, a conditional isn't needed here */
798 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
799 /* compressed format (2D only for now) */
800 const GLuint bw
= info
->BlockWidth
;
801 const GLuint bh
= info
->BlockHeight
;
802 const GLuint bd
= info
->BlockDepth
;
803 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
804 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
805 const GLuint dblocks
= (depth
+ bd
- 1) / bd
;
806 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
809 sz
= width
* height
* depth
* info
->BytesPerBlock
;
816 * Same as _mesa_format_image_size() but returns a 64-bit value to
817 * accommodate very large textures.
820 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
821 GLsizei height
, GLsizei depth
)
823 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
825 /* Strictly speaking, a conditional isn't needed here */
826 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
827 /* compressed format (2D only for now) */
828 const uint64_t bw
= info
->BlockWidth
;
829 const uint64_t bh
= info
->BlockHeight
;
830 const uint64_t bd
= info
->BlockDepth
;
831 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
832 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
833 const uint64_t dblocks
= (depth
+ bd
- 1) / bd
;
834 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
837 sz
= ((uint64_t) width
* (uint64_t) height
*
838 (uint64_t) depth
* info
->BytesPerBlock
);
846 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
848 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
849 /* Strictly speaking, a conditional isn't needed here */
850 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
851 /* compressed format */
852 const GLuint bw
= info
->BlockWidth
;
853 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
854 const GLint stride
= wblocks
* info
->BytesPerBlock
;
858 const GLint stride
= width
* info
->BytesPerBlock
;
866 * Return datatype and number of components per texel for the given
867 * uncompressed mesa_format. Only used for mipmap generation code.
870 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
871 GLenum
*datatype
, GLuint
*comps
)
874 case MESA_FORMAT_A8B8G8R8_UNORM
:
875 case MESA_FORMAT_R8G8B8A8_UNORM
:
876 case MESA_FORMAT_B8G8R8A8_UNORM
:
877 case MESA_FORMAT_A8R8G8B8_UNORM
:
878 case MESA_FORMAT_X8B8G8R8_UNORM
:
879 case MESA_FORMAT_R8G8B8X8_UNORM
:
880 case MESA_FORMAT_B8G8R8X8_UNORM
:
881 case MESA_FORMAT_X8R8G8B8_UNORM
:
882 case MESA_FORMAT_A8B8G8R8_UINT
:
883 case MESA_FORMAT_R8G8B8A8_UINT
:
884 case MESA_FORMAT_B8G8R8A8_UINT
:
885 case MESA_FORMAT_A8R8G8B8_UINT
:
886 *datatype
= GL_UNSIGNED_BYTE
;
889 case MESA_FORMAT_BGR_UNORM8
:
890 case MESA_FORMAT_RGB_UNORM8
:
891 *datatype
= GL_UNSIGNED_BYTE
;
894 case MESA_FORMAT_B5G6R5_UNORM
:
895 case MESA_FORMAT_R5G6B5_UNORM
:
896 case MESA_FORMAT_B5G6R5_UINT
:
897 case MESA_FORMAT_R5G6B5_UINT
:
898 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
902 case MESA_FORMAT_B4G4R4A4_UNORM
:
903 case MESA_FORMAT_A4R4G4B4_UNORM
:
904 case MESA_FORMAT_B4G4R4X4_UNORM
:
905 case MESA_FORMAT_B4G4R4A4_UINT
:
906 case MESA_FORMAT_A4R4G4B4_UINT
:
907 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
911 case MESA_FORMAT_B5G5R5A1_UNORM
:
912 case MESA_FORMAT_A1R5G5B5_UNORM
:
913 case MESA_FORMAT_B5G5R5X1_UNORM
:
914 case MESA_FORMAT_B5G5R5A1_UINT
:
915 case MESA_FORMAT_A1R5G5B5_UINT
:
916 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
920 case MESA_FORMAT_B10G10R10A2_UNORM
:
921 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
925 case MESA_FORMAT_A1B5G5R5_UNORM
:
926 case MESA_FORMAT_A1B5G5R5_UINT
:
927 case MESA_FORMAT_X1B5G5R5_UNORM
:
928 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
932 case MESA_FORMAT_L4A4_UNORM
:
933 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
937 case MESA_FORMAT_L8A8_UNORM
:
938 case MESA_FORMAT_A8L8_UNORM
:
939 case MESA_FORMAT_R8G8_UNORM
:
940 case MESA_FORMAT_G8R8_UNORM
:
941 *datatype
= GL_UNSIGNED_BYTE
;
945 case MESA_FORMAT_L16A16_UNORM
:
946 case MESA_FORMAT_A16L16_UNORM
:
947 case MESA_FORMAT_R16G16_UNORM
:
948 case MESA_FORMAT_G16R16_UNORM
:
949 *datatype
= GL_UNSIGNED_SHORT
;
953 case MESA_FORMAT_R_UNORM16
:
954 case MESA_FORMAT_A_UNORM16
:
955 case MESA_FORMAT_L_UNORM16
:
956 case MESA_FORMAT_I_UNORM16
:
957 *datatype
= GL_UNSIGNED_SHORT
;
961 case MESA_FORMAT_R3G3B2_UNORM
:
962 case MESA_FORMAT_R3G3B2_UINT
:
963 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
966 case MESA_FORMAT_A4B4G4R4_UNORM
:
967 case MESA_FORMAT_A4B4G4R4_UINT
:
968 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
972 case MESA_FORMAT_R4G4B4A4_UNORM
:
973 case MESA_FORMAT_R4G4B4A4_UINT
:
974 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
977 case MESA_FORMAT_R5G5B5A1_UNORM
:
978 case MESA_FORMAT_R5G5B5A1_UINT
:
979 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
982 case MESA_FORMAT_A2B10G10R10_UNORM
:
983 case MESA_FORMAT_A2B10G10R10_UINT
:
984 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
987 case MESA_FORMAT_A2R10G10B10_UNORM
:
988 case MESA_FORMAT_A2R10G10B10_UINT
:
989 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
993 case MESA_FORMAT_B2G3R3_UNORM
:
994 case MESA_FORMAT_B2G3R3_UINT
:
995 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
999 case MESA_FORMAT_A_UNORM8
:
1000 case MESA_FORMAT_L_UNORM8
:
1001 case MESA_FORMAT_I_UNORM8
:
1002 case MESA_FORMAT_R_UNORM8
:
1003 case MESA_FORMAT_S_UINT8
:
1004 *datatype
= GL_UNSIGNED_BYTE
;
1008 case MESA_FORMAT_YCBCR
:
1009 case MESA_FORMAT_YCBCR_REV
:
1010 *datatype
= GL_UNSIGNED_SHORT
;
1014 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1015 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1019 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1020 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1024 case MESA_FORMAT_Z_UNORM16
:
1025 *datatype
= GL_UNSIGNED_SHORT
;
1029 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1030 *datatype
= GL_UNSIGNED_INT
;
1034 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1035 *datatype
= GL_UNSIGNED_INT
;
1039 case MESA_FORMAT_Z_UNORM32
:
1040 *datatype
= GL_UNSIGNED_INT
;
1044 case MESA_FORMAT_Z_FLOAT32
:
1045 *datatype
= GL_FLOAT
;
1049 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1050 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1054 case MESA_FORMAT_R_SNORM8
:
1055 case MESA_FORMAT_A_SNORM8
:
1056 case MESA_FORMAT_L_SNORM8
:
1057 case MESA_FORMAT_I_SNORM8
:
1058 *datatype
= GL_BYTE
;
1061 case MESA_FORMAT_R8G8_SNORM
:
1062 case MESA_FORMAT_L8A8_SNORM
:
1063 case MESA_FORMAT_A8L8_SNORM
:
1064 *datatype
= GL_BYTE
;
1067 case MESA_FORMAT_A8B8G8R8_SNORM
:
1068 case MESA_FORMAT_R8G8B8A8_SNORM
:
1069 case MESA_FORMAT_X8B8G8R8_SNORM
:
1070 *datatype
= GL_BYTE
;
1074 case MESA_FORMAT_RGBA_UNORM16
:
1075 *datatype
= GL_UNSIGNED_SHORT
;
1079 case MESA_FORMAT_R_SNORM16
:
1080 case MESA_FORMAT_A_SNORM16
:
1081 case MESA_FORMAT_L_SNORM16
:
1082 case MESA_FORMAT_I_SNORM16
:
1083 *datatype
= GL_SHORT
;
1086 case MESA_FORMAT_R16G16_SNORM
:
1087 case MESA_FORMAT_LA_SNORM16
:
1088 *datatype
= GL_SHORT
;
1091 case MESA_FORMAT_RGB_SNORM16
:
1092 *datatype
= GL_SHORT
;
1095 case MESA_FORMAT_RGBA_SNORM16
:
1096 *datatype
= GL_SHORT
;
1100 case MESA_FORMAT_BGR_SRGB8
:
1101 *datatype
= GL_UNSIGNED_BYTE
;
1104 case MESA_FORMAT_A8B8G8R8_SRGB
:
1105 case MESA_FORMAT_B8G8R8A8_SRGB
:
1106 case MESA_FORMAT_A8R8G8B8_SRGB
:
1107 case MESA_FORMAT_R8G8B8A8_SRGB
:
1108 *datatype
= GL_UNSIGNED_BYTE
;
1111 case MESA_FORMAT_L_SRGB8
:
1112 case MESA_FORMAT_R_SRGB8
:
1113 *datatype
= GL_UNSIGNED_BYTE
;
1116 case MESA_FORMAT_L8A8_SRGB
:
1117 case MESA_FORMAT_A8L8_SRGB
:
1118 *datatype
= GL_UNSIGNED_BYTE
;
1122 case MESA_FORMAT_RGBA_FLOAT32
:
1123 *datatype
= GL_FLOAT
;
1126 case MESA_FORMAT_RGBA_FLOAT16
:
1127 *datatype
= GL_HALF_FLOAT_ARB
;
1130 case MESA_FORMAT_RGB_FLOAT32
:
1131 *datatype
= GL_FLOAT
;
1134 case MESA_FORMAT_RGB_FLOAT16
:
1135 *datatype
= GL_HALF_FLOAT_ARB
;
1138 case MESA_FORMAT_LA_FLOAT32
:
1139 case MESA_FORMAT_RG_FLOAT32
:
1140 *datatype
= GL_FLOAT
;
1143 case MESA_FORMAT_LA_FLOAT16
:
1144 case MESA_FORMAT_RG_FLOAT16
:
1145 *datatype
= GL_HALF_FLOAT_ARB
;
1148 case MESA_FORMAT_A_FLOAT32
:
1149 case MESA_FORMAT_L_FLOAT32
:
1150 case MESA_FORMAT_I_FLOAT32
:
1151 case MESA_FORMAT_R_FLOAT32
:
1152 *datatype
= GL_FLOAT
;
1155 case MESA_FORMAT_A_FLOAT16
:
1156 case MESA_FORMAT_L_FLOAT16
:
1157 case MESA_FORMAT_I_FLOAT16
:
1158 case MESA_FORMAT_R_FLOAT16
:
1159 *datatype
= GL_HALF_FLOAT_ARB
;
1163 case MESA_FORMAT_A_UINT8
:
1164 case MESA_FORMAT_L_UINT8
:
1165 case MESA_FORMAT_I_UINT8
:
1166 *datatype
= GL_UNSIGNED_BYTE
;
1169 case MESA_FORMAT_LA_UINT8
:
1170 *datatype
= GL_UNSIGNED_BYTE
;
1174 case MESA_FORMAT_A_UINT16
:
1175 case MESA_FORMAT_L_UINT16
:
1176 case MESA_FORMAT_I_UINT16
:
1177 *datatype
= GL_UNSIGNED_SHORT
;
1180 case MESA_FORMAT_LA_UINT16
:
1181 *datatype
= GL_UNSIGNED_SHORT
;
1184 case MESA_FORMAT_A_UINT32
:
1185 case MESA_FORMAT_L_UINT32
:
1186 case MESA_FORMAT_I_UINT32
:
1187 *datatype
= GL_UNSIGNED_INT
;
1190 case MESA_FORMAT_LA_UINT32
:
1191 *datatype
= GL_UNSIGNED_INT
;
1194 case MESA_FORMAT_A_SINT8
:
1195 case MESA_FORMAT_L_SINT8
:
1196 case MESA_FORMAT_I_SINT8
:
1197 *datatype
= GL_BYTE
;
1200 case MESA_FORMAT_LA_SINT8
:
1201 *datatype
= GL_BYTE
;
1205 case MESA_FORMAT_A_SINT16
:
1206 case MESA_FORMAT_L_SINT16
:
1207 case MESA_FORMAT_I_SINT16
:
1208 *datatype
= GL_SHORT
;
1211 case MESA_FORMAT_LA_SINT16
:
1212 *datatype
= GL_SHORT
;
1216 case MESA_FORMAT_A_SINT32
:
1217 case MESA_FORMAT_L_SINT32
:
1218 case MESA_FORMAT_I_SINT32
:
1222 case MESA_FORMAT_LA_SINT32
:
1227 case MESA_FORMAT_R_SINT8
:
1228 *datatype
= GL_BYTE
;
1231 case MESA_FORMAT_RG_SINT8
:
1232 *datatype
= GL_BYTE
;
1235 case MESA_FORMAT_RGB_SINT8
:
1236 *datatype
= GL_BYTE
;
1239 case MESA_FORMAT_RGBA_SINT8
:
1240 *datatype
= GL_BYTE
;
1243 case MESA_FORMAT_R_SINT16
:
1244 *datatype
= GL_SHORT
;
1247 case MESA_FORMAT_RG_SINT16
:
1248 *datatype
= GL_SHORT
;
1251 case MESA_FORMAT_RGB_SINT16
:
1252 *datatype
= GL_SHORT
;
1255 case MESA_FORMAT_RGBA_SINT16
:
1256 *datatype
= GL_SHORT
;
1259 case MESA_FORMAT_R_SINT32
:
1263 case MESA_FORMAT_RG_SINT32
:
1267 case MESA_FORMAT_RGB_SINT32
:
1271 case MESA_FORMAT_RGBA_SINT32
:
1277 * \name Non-normalized unsigned integer formats.
1279 case MESA_FORMAT_R_UINT8
:
1280 *datatype
= GL_UNSIGNED_BYTE
;
1283 case MESA_FORMAT_RG_UINT8
:
1284 *datatype
= GL_UNSIGNED_BYTE
;
1287 case MESA_FORMAT_RGB_UINT8
:
1288 *datatype
= GL_UNSIGNED_BYTE
;
1291 case MESA_FORMAT_RGBA_UINT8
:
1292 *datatype
= GL_UNSIGNED_BYTE
;
1295 case MESA_FORMAT_R_UINT16
:
1296 *datatype
= GL_UNSIGNED_SHORT
;
1299 case MESA_FORMAT_RG_UINT16
:
1300 *datatype
= GL_UNSIGNED_SHORT
;
1303 case MESA_FORMAT_RGB_UINT16
:
1304 *datatype
= GL_UNSIGNED_SHORT
;
1307 case MESA_FORMAT_RGBA_UINT16
:
1308 *datatype
= GL_UNSIGNED_SHORT
;
1311 case MESA_FORMAT_R_UINT32
:
1312 *datatype
= GL_UNSIGNED_INT
;
1315 case MESA_FORMAT_RG_UINT32
:
1316 *datatype
= GL_UNSIGNED_INT
;
1319 case MESA_FORMAT_RGB_UINT32
:
1320 *datatype
= GL_UNSIGNED_INT
;
1323 case MESA_FORMAT_RGBA_UINT32
:
1324 *datatype
= GL_UNSIGNED_INT
;
1328 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1329 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1333 case MESA_FORMAT_R11G11B10_FLOAT
:
1334 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1338 case MESA_FORMAT_B10G10R10A2_UINT
:
1339 case MESA_FORMAT_R10G10B10A2_UINT
:
1340 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1344 case MESA_FORMAT_R8G8B8X8_SRGB
:
1345 case MESA_FORMAT_X8B8G8R8_SRGB
:
1346 case MESA_FORMAT_RGBX_UINT8
:
1347 *datatype
= GL_UNSIGNED_BYTE
;
1351 case MESA_FORMAT_R8G8B8X8_SNORM
:
1352 case MESA_FORMAT_RGBX_SINT8
:
1353 *datatype
= GL_BYTE
;
1357 case MESA_FORMAT_B10G10R10X2_UNORM
:
1358 case MESA_FORMAT_R10G10B10X2_UNORM
:
1359 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1363 case MESA_FORMAT_RGBX_UNORM16
:
1364 case MESA_FORMAT_RGBX_UINT16
:
1365 *datatype
= GL_UNSIGNED_SHORT
;
1369 case MESA_FORMAT_RGBX_SNORM16
:
1370 case MESA_FORMAT_RGBX_SINT16
:
1371 *datatype
= GL_SHORT
;
1375 case MESA_FORMAT_RGBX_FLOAT16
:
1376 *datatype
= GL_HALF_FLOAT
;
1380 case MESA_FORMAT_RGBX_FLOAT32
:
1381 *datatype
= GL_FLOAT
;
1385 case MESA_FORMAT_RGBX_UINT32
:
1386 *datatype
= GL_UNSIGNED_INT
;
1390 case MESA_FORMAT_RGBX_SINT32
:
1395 case MESA_FORMAT_R10G10B10A2_UNORM
:
1396 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1400 case MESA_FORMAT_G8R8_SNORM
:
1401 *datatype
= GL_BYTE
;
1405 case MESA_FORMAT_G16R16_SNORM
:
1406 *datatype
= GL_SHORT
;
1410 case MESA_FORMAT_B8G8R8X8_SRGB
:
1411 case MESA_FORMAT_X8R8G8B8_SRGB
:
1412 *datatype
= GL_UNSIGNED_BYTE
;
1416 case MESA_FORMAT_COUNT
:
1420 /* Warn if any formats are not handled */
1421 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1422 _mesa_get_format_name(format
));
1423 assert(format
== MESA_FORMAT_NONE
||
1424 _mesa_is_format_compressed(format
));
1431 * Check if a mesa_format exactly matches a GL format/type combination
1432 * such that we can use memcpy() from one to the other.
1433 * \param mesa_format a MESA_FORMAT_x value
1434 * \param format the user-specified image format
1435 * \param type the user-specified image datatype
1436 * \param swapBytes typically the current pixel pack/unpack byteswap state
1437 * \param[out] error GL_NO_ERROR if format is an expected input.
1438 * GL_INVALID_ENUM if format is an unexpected input.
1439 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1442 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1443 GLenum format
, GLenum type
,
1444 GLboolean swapBytes
, GLenum
*error
)
1446 const GLboolean littleEndian
= _mesa_little_endian();
1448 *error
= GL_NO_ERROR
;
1450 /* Note: When reading a GL format/type combination, the format lists channel
1451 * assignments from most significant channel in the type to least
1452 * significant. A type with _REV indicates that the assignments are
1453 * swapped, so they are listed from least significant to most significant.
1455 * Compressed formats will fall through and return GL_FALSE.
1457 * For sanity, please keep this switch statement ordered the same as the
1458 * enums in formats.h.
1461 switch (mesa_format
) {
1463 case MESA_FORMAT_NONE
:
1464 case MESA_FORMAT_COUNT
:
1467 case MESA_FORMAT_A8B8G8R8_UNORM
:
1468 case MESA_FORMAT_A8B8G8R8_SRGB
:
1469 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1472 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1475 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1478 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1482 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1486 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1491 case MESA_FORMAT_R8G8B8A8_UNORM
:
1492 case MESA_FORMAT_R8G8B8A8_SRGB
:
1493 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1497 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1500 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1503 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1507 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1511 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1516 case MESA_FORMAT_B8G8R8A8_UNORM
:
1517 case MESA_FORMAT_B8G8R8A8_SRGB
:
1518 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1522 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1525 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1530 case MESA_FORMAT_A8R8G8B8_UNORM
:
1531 case MESA_FORMAT_A8R8G8B8_SRGB
:
1532 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1535 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1539 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1544 case MESA_FORMAT_X8B8G8R8_UNORM
:
1545 case MESA_FORMAT_R8G8B8X8_UNORM
:
1548 case MESA_FORMAT_B8G8R8X8_UNORM
:
1549 case MESA_FORMAT_X8R8G8B8_UNORM
:
1552 case MESA_FORMAT_BGR_UNORM8
:
1553 case MESA_FORMAT_BGR_SRGB8
:
1554 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1556 case MESA_FORMAT_RGB_UNORM8
:
1557 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1559 case MESA_FORMAT_B5G6R5_UNORM
:
1560 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1561 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1564 case MESA_FORMAT_R5G6B5_UNORM
:
1565 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1566 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1569 case MESA_FORMAT_B4G4R4A4_UNORM
:
1570 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1573 case MESA_FORMAT_A4R4G4B4_UNORM
:
1576 case MESA_FORMAT_A1B5G5R5_UNORM
:
1577 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1580 case MESA_FORMAT_X1B5G5R5_UNORM
:
1581 return format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1584 case MESA_FORMAT_B5G5R5A1_UNORM
:
1585 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1588 case MESA_FORMAT_A1R5G5B5_UNORM
:
1589 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1592 case MESA_FORMAT_L4A4_UNORM
:
1594 case MESA_FORMAT_L8A8_UNORM
:
1595 case MESA_FORMAT_L8A8_SRGB
:
1596 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1597 case MESA_FORMAT_A8L8_UNORM
:
1598 case MESA_FORMAT_A8L8_SRGB
:
1601 case MESA_FORMAT_L16A16_UNORM
:
1602 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1603 case MESA_FORMAT_A16L16_UNORM
:
1606 case MESA_FORMAT_B2G3R3_UNORM
:
1607 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1609 case MESA_FORMAT_R3G3B2_UNORM
:
1610 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1612 case MESA_FORMAT_A4B4G4R4_UNORM
:
1613 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1616 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1621 case MESA_FORMAT_R4G4B4A4_UNORM
:
1622 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1625 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1628 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1631 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1636 case MESA_FORMAT_R5G5B5A1_UNORM
:
1637 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1639 case MESA_FORMAT_A2B10G10R10_UNORM
:
1640 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1642 case MESA_FORMAT_A2B10G10R10_UINT
:
1643 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1645 case MESA_FORMAT_A2R10G10B10_UNORM
:
1646 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1648 case MESA_FORMAT_A2R10G10B10_UINT
:
1649 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1651 case MESA_FORMAT_A_UNORM8
:
1652 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1653 case MESA_FORMAT_A_UNORM16
:
1654 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1655 case MESA_FORMAT_L_UNORM8
:
1656 case MESA_FORMAT_L_SRGB8
:
1657 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1658 case MESA_FORMAT_L_UNORM16
:
1659 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1660 case MESA_FORMAT_I_UNORM8
:
1661 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1662 case MESA_FORMAT_I_UNORM16
:
1663 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1665 case MESA_FORMAT_YCBCR
:
1666 return format
== GL_YCBCR_MESA
&&
1667 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1668 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1669 case MESA_FORMAT_YCBCR_REV
:
1670 return format
== GL_YCBCR_MESA
&&
1671 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1672 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1674 case MESA_FORMAT_R_UNORM8
:
1675 case MESA_FORMAT_R_SRGB8
:
1676 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1677 case MESA_FORMAT_R8G8_UNORM
:
1678 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1679 case MESA_FORMAT_G8R8_UNORM
:
1682 case MESA_FORMAT_R_UNORM16
:
1683 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1685 case MESA_FORMAT_R16G16_UNORM
:
1686 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1688 case MESA_FORMAT_G16R16_UNORM
:
1691 case MESA_FORMAT_B10G10R10A2_UNORM
:
1692 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1695 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1696 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1698 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1699 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1702 case MESA_FORMAT_Z_UNORM16
:
1703 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1706 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1709 case MESA_FORMAT_Z_UNORM32
:
1710 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1713 case MESA_FORMAT_S_UINT8
:
1714 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1716 case MESA_FORMAT_RGBA_FLOAT32
:
1717 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1718 case MESA_FORMAT_RGBA_FLOAT16
:
1719 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1721 case MESA_FORMAT_RGB_FLOAT32
:
1722 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1723 case MESA_FORMAT_RGB_FLOAT16
:
1724 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1726 case MESA_FORMAT_A_FLOAT32
:
1727 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1728 case MESA_FORMAT_A_FLOAT16
:
1729 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1731 case MESA_FORMAT_L_FLOAT32
:
1732 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1733 case MESA_FORMAT_L_FLOAT16
:
1734 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1736 case MESA_FORMAT_LA_FLOAT32
:
1737 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1738 case MESA_FORMAT_LA_FLOAT16
:
1739 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1741 case MESA_FORMAT_I_FLOAT32
:
1742 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1743 case MESA_FORMAT_I_FLOAT16
:
1744 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1746 case MESA_FORMAT_R_FLOAT32
:
1747 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1748 case MESA_FORMAT_R_FLOAT16
:
1749 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1751 case MESA_FORMAT_RG_FLOAT32
:
1752 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1753 case MESA_FORMAT_RG_FLOAT16
:
1754 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1756 case MESA_FORMAT_A_UINT8
:
1757 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1758 case MESA_FORMAT_A_UINT16
:
1759 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1761 case MESA_FORMAT_A_UINT32
:
1762 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1764 case MESA_FORMAT_A_SINT8
:
1765 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1766 case MESA_FORMAT_A_SINT16
:
1767 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1768 case MESA_FORMAT_A_SINT32
:
1769 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1771 case MESA_FORMAT_I_UINT8
:
1772 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1773 case MESA_FORMAT_I_UINT16
:
1774 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1775 case MESA_FORMAT_I_UINT32
:
1776 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1777 case MESA_FORMAT_I_SINT8
:
1778 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1779 case MESA_FORMAT_I_SINT16
:
1780 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1781 case MESA_FORMAT_I_SINT32
:
1782 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1784 case MESA_FORMAT_L_UINT8
:
1785 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1786 case MESA_FORMAT_L_UINT16
:
1787 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1789 case MESA_FORMAT_L_UINT32
:
1790 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1792 case MESA_FORMAT_L_SINT8
:
1793 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1794 case MESA_FORMAT_L_SINT16
:
1795 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1797 case MESA_FORMAT_L_SINT32
:
1798 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1800 case MESA_FORMAT_LA_UINT8
:
1801 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1802 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1803 case MESA_FORMAT_LA_UINT16
:
1804 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1805 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1806 case MESA_FORMAT_LA_UINT32
:
1807 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1808 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1809 case MESA_FORMAT_LA_SINT8
:
1810 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1812 case MESA_FORMAT_LA_SINT16
:
1813 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1815 case MESA_FORMAT_LA_SINT32
:
1816 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1819 case MESA_FORMAT_R_SINT8
:
1820 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1821 case MESA_FORMAT_RG_SINT8
:
1822 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1823 case MESA_FORMAT_RGB_SINT8
:
1824 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1825 case MESA_FORMAT_RGBA_SINT8
:
1826 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1827 case MESA_FORMAT_R_SINT16
:
1828 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1829 case MESA_FORMAT_RG_SINT16
:
1830 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1831 case MESA_FORMAT_RGB_SINT16
:
1832 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1833 case MESA_FORMAT_RGBA_SINT16
:
1834 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1835 case MESA_FORMAT_R_SINT32
:
1836 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1837 case MESA_FORMAT_RG_SINT32
:
1838 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1839 case MESA_FORMAT_RGB_SINT32
:
1840 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1841 case MESA_FORMAT_RGBA_SINT32
:
1842 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1844 case MESA_FORMAT_R_UINT8
:
1845 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1846 case MESA_FORMAT_RG_UINT8
:
1847 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1848 case MESA_FORMAT_RGB_UINT8
:
1849 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1850 case MESA_FORMAT_RGBA_UINT8
:
1851 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1853 case MESA_FORMAT_R_UINT16
:
1854 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1856 case MESA_FORMAT_RG_UINT16
:
1857 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1858 case MESA_FORMAT_RGB_UINT16
:
1859 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1861 case MESA_FORMAT_RGBA_UINT16
:
1862 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1864 case MESA_FORMAT_R_UINT32
:
1865 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1866 case MESA_FORMAT_RG_UINT32
:
1867 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1868 case MESA_FORMAT_RGB_UINT32
:
1869 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1870 case MESA_FORMAT_RGBA_UINT32
:
1871 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1873 case MESA_FORMAT_R_SNORM8
:
1874 return format
== GL_RED
&& type
== GL_BYTE
;
1875 case MESA_FORMAT_R8G8_SNORM
:
1876 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1878 case MESA_FORMAT_X8B8G8R8_SNORM
:
1881 case MESA_FORMAT_A8B8G8R8_SNORM
:
1882 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1885 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1890 case MESA_FORMAT_R8G8B8A8_SNORM
:
1891 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1894 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1899 case MESA_FORMAT_R_SNORM16
:
1900 return format
== GL_RED
&& type
== GL_SHORT
&&
1902 case MESA_FORMAT_R16G16_SNORM
:
1903 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1904 case MESA_FORMAT_RGB_SNORM16
:
1905 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1906 case MESA_FORMAT_RGBA_SNORM16
:
1907 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1908 case MESA_FORMAT_RGBA_UNORM16
:
1909 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1912 case MESA_FORMAT_A_SNORM8
:
1913 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1914 case MESA_FORMAT_L_SNORM8
:
1915 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1916 case MESA_FORMAT_L8A8_SNORM
:
1917 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1918 littleEndian
&& !swapBytes
;
1919 case MESA_FORMAT_A8L8_SNORM
:
1920 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1921 !littleEndian
&& !swapBytes
;
1922 case MESA_FORMAT_I_SNORM8
:
1923 return format
== GL_RED
&& type
== GL_BYTE
;
1924 case MESA_FORMAT_A_SNORM16
:
1925 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1926 case MESA_FORMAT_L_SNORM16
:
1927 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1928 case MESA_FORMAT_LA_SNORM16
:
1929 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1930 littleEndian
&& !swapBytes
;
1931 case MESA_FORMAT_I_SNORM16
:
1932 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1935 case MESA_FORMAT_B10G10R10A2_UINT
:
1936 return (format
== GL_BGRA_INTEGER_EXT
&&
1937 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1940 case MESA_FORMAT_R10G10B10A2_UINT
:
1941 return (format
== GL_RGBA_INTEGER_EXT
&&
1942 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1945 case MESA_FORMAT_B5G6R5_UINT
:
1946 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1948 case MESA_FORMAT_R5G6B5_UINT
:
1949 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1951 case MESA_FORMAT_B2G3R3_UINT
:
1952 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1954 case MESA_FORMAT_R3G3B2_UINT
:
1955 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1957 case MESA_FORMAT_A4B4G4R4_UINT
:
1958 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1961 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1965 case MESA_FORMAT_R4G4B4A4_UINT
:
1966 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1969 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1974 case MESA_FORMAT_B4G4R4A4_UINT
:
1975 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1978 case MESA_FORMAT_A4R4G4B4_UINT
:
1981 case MESA_FORMAT_A1B5G5R5_UINT
:
1982 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1985 case MESA_FORMAT_B5G5R5A1_UINT
:
1986 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1989 case MESA_FORMAT_A1R5G5B5_UINT
:
1990 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1993 case MESA_FORMAT_R5G5B5A1_UINT
:
1994 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1996 case MESA_FORMAT_A8B8G8R8_UINT
:
1997 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
2000 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
2004 case MESA_FORMAT_A8R8G8B8_UINT
:
2005 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
2009 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2015 case MESA_FORMAT_R8G8B8A8_UINT
:
2016 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2020 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2025 case MESA_FORMAT_B8G8R8A8_UINT
:
2026 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2030 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2035 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2036 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2039 case MESA_FORMAT_R11G11B10_FLOAT
:
2040 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2043 case MESA_FORMAT_Z_FLOAT32
:
2044 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2046 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2047 return format
== GL_DEPTH_STENCIL
&&
2048 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2050 case MESA_FORMAT_B4G4R4X4_UNORM
:
2051 case MESA_FORMAT_B5G5R5X1_UNORM
:
2052 case MESA_FORMAT_R8G8B8X8_SNORM
:
2053 case MESA_FORMAT_R8G8B8X8_SRGB
:
2054 case MESA_FORMAT_X8B8G8R8_SRGB
:
2055 case MESA_FORMAT_RGBX_UINT8
:
2056 case MESA_FORMAT_RGBX_SINT8
:
2057 case MESA_FORMAT_B10G10R10X2_UNORM
:
2058 case MESA_FORMAT_RGBX_UNORM16
:
2059 case MESA_FORMAT_RGBX_SNORM16
:
2060 case MESA_FORMAT_RGBX_FLOAT16
:
2061 case MESA_FORMAT_RGBX_UINT16
:
2062 case MESA_FORMAT_RGBX_SINT16
:
2063 case MESA_FORMAT_RGBX_FLOAT32
:
2064 case MESA_FORMAT_RGBX_UINT32
:
2065 case MESA_FORMAT_RGBX_SINT32
:
2068 case MESA_FORMAT_R10G10B10X2_UNORM
:
2069 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2071 case MESA_FORMAT_R10G10B10A2_UNORM
:
2072 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2075 case MESA_FORMAT_G8R8_SNORM
:
2076 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2079 case MESA_FORMAT_G16R16_SNORM
:
2080 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2083 case MESA_FORMAT_B8G8R8X8_SRGB
:
2084 case MESA_FORMAT_X8R8G8B8_SRGB
:
2087 assert(_mesa_is_format_compressed(mesa_format
));
2089 *error
= GL_INVALID_ENUM
;