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.
191 * The return value will be one of:
192 * MESA_FORMAT_LAYOUT_ARRAY
193 * MESA_FORMAT_LAYOUT_PACKED
194 * MESA_FORMAT_LAYOUT_S3TC
195 * MESA_FORMAT_LAYOUT_RGTC
196 * MESA_FORMAT_LAYOUT_FXT1
197 * MESA_FORMAT_LAYOUT_ETC1
198 * MESA_FORMAT_LAYOUT_ETC2
199 * MESA_FORMAT_LAYOUT_BPTC
200 * MESA_FORMAT_LAYOUT_ASTC
201 * MESA_FORMAT_LAYOUT_OTHER
203 extern enum mesa_format_layout
204 _mesa_get_format_layout(mesa_format format
)
206 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
212 * Return the data type (or more specifically, the data representation)
213 * for the given format.
214 * The return value will be one of:
215 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
216 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
217 * GL_UNSIGNED_INT = an ordinary unsigned integer
218 * GL_INT = an ordinary signed integer
219 * GL_FLOAT = an ordinary float
222 _mesa_get_format_datatype(mesa_format format
)
224 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
225 return info
->DataType
;
229 get_base_format_for_array_format(mesa_array_format format
)
234 _mesa_array_format_get_swizzle(format
, swizzle
);
235 num_channels
= _mesa_array_format_get_num_channels(format
);
237 switch (num_channels
) {
239 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
240 * This is not really a problem for now because we only create array
241 * formats from GL format/type combinations, and these cannot specify
248 if (swizzle
[0] == 0 &&
252 return GL_LUMINANCE_ALPHA
;
253 if (swizzle
[0] == 1 &&
257 return GL_LUMINANCE_ALPHA
;
258 if (swizzle
[0] == 0 &&
263 if (swizzle
[0] == 1 &&
270 if (swizzle
[0] == 0 &&
275 if (swizzle
[0] == 0 &&
280 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
282 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
284 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
286 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
291 unreachable("Unsupported format");
295 * Return the basic format for the given type. The result will be one of
296 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
297 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
298 * This functions accepts a mesa_format or a mesa_array_format.
301 _mesa_get_format_base_format(uint32_t format
)
303 if (!_mesa_format_is_mesa_array_format(format
)) {
304 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
305 return info
->BaseFormat
;
307 return get_base_format_for_array_format(format
);
313 * Return the block size (in pixels) for the given format. Normally
314 * the block size is 1x1. But compressed formats will have block sizes
315 * of 4x4 or 8x4 pixels, etc.
316 * \param bw returns block width in pixels
317 * \param bh returns block height in pixels
320 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
322 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
323 *bw
= info
->BlockWidth
;
324 *bh
= info
->BlockHeight
;
329 * Returns the an array of four numbers representing the transformation
330 * from the RGBA or SZ colorspace to the given format. For array formats,
331 * the i'th RGBA component is given by:
333 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
334 * comp = data[swizzle[i]];
335 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
337 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
339 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
340 * // data does not contain a channel of this format
342 * For packed formats, the swizzle gives the number of components left of
343 * the least significant bit.
345 * Compressed formats have no swizzle.
348 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
350 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
351 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
355 _mesa_array_format_flip_channels(mesa_array_format format
)
360 num_channels
= _mesa_array_format_get_num_channels(format
);
361 _mesa_array_format_get_swizzle(format
, swizzle
);
363 if (num_channels
== 1)
366 if (num_channels
== 2) {
367 /* Assert that the swizzle makes sense for 2 channels */
368 for (unsigned i
= 0; i
< 4; i
++)
369 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
371 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
372 _mesa_array_format_set_swizzle(&format
,
373 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
374 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
378 if (num_channels
== 4) {
379 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
380 _mesa_array_format_set_swizzle(&format
,
381 flip
[swizzle
[0]], flip
[swizzle
[1]],
382 flip
[swizzle
[2]], flip
[swizzle
[3]]);
386 unreachable("Invalid array format");
390 _mesa_format_to_array_format(mesa_format format
)
392 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
393 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
394 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
395 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
397 return info
->ArrayFormat
;
400 static struct hash_table
*format_array_format_table
;
401 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
404 array_formats_equal(const void *a
, const void *b
)
406 return (intptr_t)a
== (intptr_t)b
;
410 format_array_format_table_init(void)
412 const struct gl_format_info
*info
;
413 mesa_array_format array_format
;
416 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
417 array_formats_equal
);
419 if (!format_array_format_table
) {
420 _mesa_error_no_memory(__func__
);
424 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
425 info
= _mesa_get_format_info(f
);
426 if (!info
->ArrayFormat
)
429 if (_mesa_little_endian()) {
430 array_format
= info
->ArrayFormat
;
432 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
435 /* This can happen and does for some of the BGR formats. Let's take
436 * the first one in the list.
438 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
440 (void *)(intptr_t)array_format
))
443 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
445 (void *)(intptr_t)array_format
,
446 (void *)(intptr_t)f
);
451 _mesa_format_from_array_format(uint32_t array_format
)
453 struct hash_entry
*entry
;
455 assert(_mesa_format_is_mesa_array_format(array_format
));
457 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
459 if (!format_array_format_table
) {
460 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
461 format_array_format_table_exists
= once_flag_init
;
462 return MESA_FORMAT_NONE
;
465 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
467 (void *)(intptr_t)array_format
);
469 return (intptr_t)entry
->data
;
471 return MESA_FORMAT_NONE
;
474 /** Is the given format a compressed format? */
476 _mesa_is_format_compressed(mesa_format format
)
478 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
479 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
484 * Determine if the given format represents a packed depth/stencil buffer.
487 _mesa_is_format_packed_depth_stencil(mesa_format format
)
489 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
491 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
496 * Is the given format a signed/unsigned integer color format?
499 _mesa_is_format_integer_color(mesa_format format
)
501 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
502 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
503 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
504 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
505 info
->BaseFormat
!= GL_STENCIL_INDEX
;
510 * Is the given format an unsigned integer format?
513 _mesa_is_format_unsigned(mesa_format format
)
515 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
516 return _mesa_is_type_unsigned(info
->DataType
);
521 * Does the given format store signed values?
524 _mesa_is_format_signed(mesa_format format
)
526 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
527 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
528 /* these packed float formats only store unsigned values */
532 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
533 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
534 info
->DataType
== GL_INT
||
535 info
->DataType
== GL_FLOAT
);
540 * Is the given format an integer format?
543 _mesa_is_format_integer(mesa_format format
)
545 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
546 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
551 * Return true if the given format is a color format.
554 _mesa_is_format_color_format(mesa_format format
)
556 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
557 switch (info
->BaseFormat
) {
558 case GL_DEPTH_COMPONENT
:
559 case GL_STENCIL_INDEX
:
560 case GL_DEPTH_STENCIL
:
569 * Return color encoding for given format.
570 * \return GL_LINEAR or GL_SRGB
573 _mesa_get_format_color_encoding(mesa_format format
)
575 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
576 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
581 * Return TRUE if format is an ETC2 compressed format specified
582 * by GL_ARB_ES3_compatibility.
585 _mesa_is_format_etc2(mesa_format format
)
588 case MESA_FORMAT_ETC2_RGB8
:
589 case MESA_FORMAT_ETC2_SRGB8
:
590 case MESA_FORMAT_ETC2_RGBA8_EAC
:
591 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
592 case MESA_FORMAT_ETC2_R11_EAC
:
593 case MESA_FORMAT_ETC2_RG11_EAC
:
594 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
595 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
596 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
597 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
606 * For an sRGB format, return the corresponding linear color space format.
607 * For non-sRGB formats, return the format as-is.
610 _mesa_get_srgb_format_linear(mesa_format format
)
613 case MESA_FORMAT_BGR_SRGB8
:
614 format
= MESA_FORMAT_BGR_UNORM8
;
616 case MESA_FORMAT_A8B8G8R8_SRGB
:
617 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
619 case MESA_FORMAT_B8G8R8A8_SRGB
:
620 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
622 case MESA_FORMAT_A8R8G8B8_SRGB
:
623 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
625 case MESA_FORMAT_R8G8B8A8_SRGB
:
626 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
628 case MESA_FORMAT_L_SRGB8
:
629 format
= MESA_FORMAT_L_UNORM8
;
631 case MESA_FORMAT_L8A8_SRGB
:
632 format
= MESA_FORMAT_L8A8_UNORM
;
634 case MESA_FORMAT_A8L8_SRGB
:
635 format
= MESA_FORMAT_A8L8_UNORM
;
637 case MESA_FORMAT_SRGB_DXT1
:
638 format
= MESA_FORMAT_RGB_DXT1
;
640 case MESA_FORMAT_SRGBA_DXT1
:
641 format
= MESA_FORMAT_RGBA_DXT1
;
643 case MESA_FORMAT_SRGBA_DXT3
:
644 format
= MESA_FORMAT_RGBA_DXT3
;
646 case MESA_FORMAT_SRGBA_DXT5
:
647 format
= MESA_FORMAT_RGBA_DXT5
;
649 case MESA_FORMAT_R8G8B8X8_SRGB
:
650 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
652 case MESA_FORMAT_X8B8G8R8_SRGB
:
653 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
655 case MESA_FORMAT_ETC2_SRGB8
:
656 format
= MESA_FORMAT_ETC2_RGB8
;
658 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
659 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
661 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
662 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
664 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
665 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
667 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
668 format
= MESA_FORMAT_RGBA_ASTC_4x4
;
670 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
671 format
= MESA_FORMAT_RGBA_ASTC_5x4
;
673 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
674 format
= MESA_FORMAT_RGBA_ASTC_5x5
;
676 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
677 format
= MESA_FORMAT_RGBA_ASTC_6x5
;
679 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
680 format
= MESA_FORMAT_RGBA_ASTC_6x6
;
682 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
683 format
= MESA_FORMAT_RGBA_ASTC_8x5
;
685 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
686 format
= MESA_FORMAT_RGBA_ASTC_8x6
;
688 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
689 format
= MESA_FORMAT_RGBA_ASTC_8x8
;
691 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
692 format
= MESA_FORMAT_RGBA_ASTC_10x5
;
694 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
695 format
= MESA_FORMAT_RGBA_ASTC_10x6
;
697 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
698 format
= MESA_FORMAT_RGBA_ASTC_10x8
;
700 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
701 format
= MESA_FORMAT_RGBA_ASTC_10x10
;
703 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
704 format
= MESA_FORMAT_RGBA_ASTC_12x10
;
706 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
707 format
= MESA_FORMAT_RGBA_ASTC_12x12
;
709 case MESA_FORMAT_B8G8R8X8_SRGB
:
710 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
712 case MESA_FORMAT_X8R8G8B8_SRGB
:
713 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
723 * If the given format is a compressed format, return a corresponding
724 * uncompressed format.
727 _mesa_get_uncompressed_format(mesa_format format
)
730 case MESA_FORMAT_RGB_FXT1
:
731 return MESA_FORMAT_BGR_UNORM8
;
732 case MESA_FORMAT_RGBA_FXT1
:
733 return MESA_FORMAT_A8B8G8R8_UNORM
;
734 case MESA_FORMAT_RGB_DXT1
:
735 case MESA_FORMAT_SRGB_DXT1
:
736 return MESA_FORMAT_BGR_UNORM8
;
737 case MESA_FORMAT_RGBA_DXT1
:
738 case MESA_FORMAT_SRGBA_DXT1
:
739 return MESA_FORMAT_A8B8G8R8_UNORM
;
740 case MESA_FORMAT_RGBA_DXT3
:
741 case MESA_FORMAT_SRGBA_DXT3
:
742 return MESA_FORMAT_A8B8G8R8_UNORM
;
743 case MESA_FORMAT_RGBA_DXT5
:
744 case MESA_FORMAT_SRGBA_DXT5
:
745 return MESA_FORMAT_A8B8G8R8_UNORM
;
746 case MESA_FORMAT_R_RGTC1_UNORM
:
747 return MESA_FORMAT_R_UNORM8
;
748 case MESA_FORMAT_R_RGTC1_SNORM
:
749 return MESA_FORMAT_R_SNORM8
;
750 case MESA_FORMAT_RG_RGTC2_UNORM
:
751 return MESA_FORMAT_R8G8_UNORM
;
752 case MESA_FORMAT_RG_RGTC2_SNORM
:
753 return MESA_FORMAT_R8G8_SNORM
;
754 case MESA_FORMAT_L_LATC1_UNORM
:
755 return MESA_FORMAT_L_UNORM8
;
756 case MESA_FORMAT_L_LATC1_SNORM
:
757 return MESA_FORMAT_L_SNORM8
;
758 case MESA_FORMAT_LA_LATC2_UNORM
:
759 return MESA_FORMAT_L8A8_UNORM
;
760 case MESA_FORMAT_LA_LATC2_SNORM
:
761 return MESA_FORMAT_L8A8_SNORM
;
762 case MESA_FORMAT_ETC1_RGB8
:
763 case MESA_FORMAT_ETC2_RGB8
:
764 case MESA_FORMAT_ETC2_SRGB8
:
765 return MESA_FORMAT_BGR_UNORM8
;
766 case MESA_FORMAT_ETC2_RGBA8_EAC
:
767 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
768 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
769 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
770 return MESA_FORMAT_A8B8G8R8_UNORM
;
771 case MESA_FORMAT_ETC2_R11_EAC
:
772 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
773 return MESA_FORMAT_R_UNORM16
;
774 case MESA_FORMAT_ETC2_RG11_EAC
:
775 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
776 return MESA_FORMAT_R16G16_UNORM
;
777 case MESA_FORMAT_BPTC_RGBA_UNORM
:
778 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
779 return MESA_FORMAT_A8B8G8R8_UNORM
;
780 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
781 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
782 return MESA_FORMAT_RGB_FLOAT32
;
785 assert(!_mesa_is_format_compressed(format
));
793 _mesa_format_num_components(mesa_format format
)
795 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
796 return ((info
->RedBits
> 0) +
797 (info
->GreenBits
> 0) +
798 (info
->BlueBits
> 0) +
799 (info
->AlphaBits
> 0) +
800 (info
->LuminanceBits
> 0) +
801 (info
->IntensityBits
> 0) +
802 (info
->DepthBits
> 0) +
803 (info
->StencilBits
> 0));
808 * Returns true if a color format has data stored in the R/G/B/A channels,
809 * given an index from 0 to 3.
812 _mesa_format_has_color_component(mesa_format format
, int component
)
814 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
816 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
817 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
818 info
->BaseFormat
!= GL_STENCIL_INDEX
);
822 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
824 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
826 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
828 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
830 assert(!"Invalid color component: must be 0..3");
837 * Return number of bytes needed to store an image of the given size
838 * in the given format.
841 _mesa_format_image_size(mesa_format format
, GLsizei width
,
842 GLsizei height
, GLsizei depth
)
844 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
845 /* Strictly speaking, a conditional isn't needed here */
846 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
847 /* compressed format (2D only for now) */
848 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
849 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
850 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
851 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
856 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
863 * Same as _mesa_format_image_size() but returns a 64-bit value to
864 * accommodate very large textures.
867 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
868 GLsizei height
, GLsizei depth
)
870 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
871 /* Strictly speaking, a conditional isn't needed here */
872 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
873 /* compressed format (2D only for now) */
874 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
875 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
876 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
877 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
882 const uint64_t sz
= ((uint64_t) width
*
885 info
->BytesPerBlock
);
893 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
895 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
896 /* Strictly speaking, a conditional isn't needed here */
897 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
898 /* compressed format */
899 const GLuint bw
= info
->BlockWidth
;
900 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
901 const GLint stride
= wblocks
* info
->BytesPerBlock
;
905 const GLint stride
= width
* info
->BytesPerBlock
;
913 * Return datatype and number of components per texel for the given
914 * uncompressed mesa_format. Only used for mipmap generation code.
917 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
918 GLenum
*datatype
, GLuint
*comps
)
921 case MESA_FORMAT_A8B8G8R8_UNORM
:
922 case MESA_FORMAT_R8G8B8A8_UNORM
:
923 case MESA_FORMAT_B8G8R8A8_UNORM
:
924 case MESA_FORMAT_A8R8G8B8_UNORM
:
925 case MESA_FORMAT_X8B8G8R8_UNORM
:
926 case MESA_FORMAT_R8G8B8X8_UNORM
:
927 case MESA_FORMAT_B8G8R8X8_UNORM
:
928 case MESA_FORMAT_X8R8G8B8_UNORM
:
929 *datatype
= GL_UNSIGNED_BYTE
;
932 case MESA_FORMAT_BGR_UNORM8
:
933 case MESA_FORMAT_RGB_UNORM8
:
934 *datatype
= GL_UNSIGNED_BYTE
;
937 case MESA_FORMAT_B5G6R5_UNORM
:
938 case MESA_FORMAT_R5G6B5_UNORM
:
939 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
943 case MESA_FORMAT_B4G4R4A4_UNORM
:
944 case MESA_FORMAT_A4R4G4B4_UNORM
:
945 case MESA_FORMAT_B4G4R4X4_UNORM
:
946 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
950 case MESA_FORMAT_B5G5R5A1_UNORM
:
951 case MESA_FORMAT_A1R5G5B5_UNORM
:
952 case MESA_FORMAT_B5G5R5X1_UNORM
:
953 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
957 case MESA_FORMAT_B10G10R10A2_UNORM
:
958 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
962 case MESA_FORMAT_A1B5G5R5_UNORM
:
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 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1000 case MESA_FORMAT_A4B4G4R4_UNORM
:
1001 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1005 case MESA_FORMAT_R4G4B4A4_UNORM
:
1006 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1009 case MESA_FORMAT_R5G5B5A1_UNORM
:
1010 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1013 case MESA_FORMAT_A2B10G10R10_UNORM
:
1014 case MESA_FORMAT_A2B10G10R10_UINT
:
1015 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1018 case MESA_FORMAT_A2R10G10B10_UNORM
:
1019 case MESA_FORMAT_A2R10G10B10_UINT
:
1020 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1024 case MESA_FORMAT_B2G3R3_UNORM
:
1025 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1029 case MESA_FORMAT_A_UNORM8
:
1030 case MESA_FORMAT_L_UNORM8
:
1031 case MESA_FORMAT_I_UNORM8
:
1032 case MESA_FORMAT_R_UNORM8
:
1033 case MESA_FORMAT_S_UINT8
:
1034 *datatype
= GL_UNSIGNED_BYTE
;
1038 case MESA_FORMAT_YCBCR
:
1039 case MESA_FORMAT_YCBCR_REV
:
1040 *datatype
= GL_UNSIGNED_SHORT
;
1044 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1045 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1049 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1050 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1054 case MESA_FORMAT_Z_UNORM16
:
1055 *datatype
= GL_UNSIGNED_SHORT
;
1059 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1060 *datatype
= GL_UNSIGNED_INT
;
1064 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1065 *datatype
= GL_UNSIGNED_INT
;
1069 case MESA_FORMAT_Z_UNORM32
:
1070 *datatype
= GL_UNSIGNED_INT
;
1074 case MESA_FORMAT_Z_FLOAT32
:
1075 *datatype
= GL_FLOAT
;
1079 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1080 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1084 case MESA_FORMAT_R_SNORM8
:
1085 case MESA_FORMAT_A_SNORM8
:
1086 case MESA_FORMAT_L_SNORM8
:
1087 case MESA_FORMAT_I_SNORM8
:
1088 *datatype
= GL_BYTE
;
1091 case MESA_FORMAT_R8G8_SNORM
:
1092 case MESA_FORMAT_L8A8_SNORM
:
1093 case MESA_FORMAT_A8L8_SNORM
:
1094 *datatype
= GL_BYTE
;
1097 case MESA_FORMAT_A8B8G8R8_SNORM
:
1098 case MESA_FORMAT_R8G8B8A8_SNORM
:
1099 case MESA_FORMAT_X8B8G8R8_SNORM
:
1100 *datatype
= GL_BYTE
;
1104 case MESA_FORMAT_RGBA_UNORM16
:
1105 *datatype
= GL_UNSIGNED_SHORT
;
1109 case MESA_FORMAT_R_SNORM16
:
1110 case MESA_FORMAT_A_SNORM16
:
1111 case MESA_FORMAT_L_SNORM16
:
1112 case MESA_FORMAT_I_SNORM16
:
1113 *datatype
= GL_SHORT
;
1116 case MESA_FORMAT_R16G16_SNORM
:
1117 case MESA_FORMAT_LA_SNORM16
:
1118 *datatype
= GL_SHORT
;
1121 case MESA_FORMAT_RGB_SNORM16
:
1122 *datatype
= GL_SHORT
;
1125 case MESA_FORMAT_RGBA_SNORM16
:
1126 *datatype
= GL_SHORT
;
1130 case MESA_FORMAT_BGR_SRGB8
:
1131 *datatype
= GL_UNSIGNED_BYTE
;
1134 case MESA_FORMAT_A8B8G8R8_SRGB
:
1135 case MESA_FORMAT_B8G8R8A8_SRGB
:
1136 case MESA_FORMAT_A8R8G8B8_SRGB
:
1137 case MESA_FORMAT_R8G8B8A8_SRGB
:
1138 *datatype
= GL_UNSIGNED_BYTE
;
1141 case MESA_FORMAT_L_SRGB8
:
1142 *datatype
= GL_UNSIGNED_BYTE
;
1145 case MESA_FORMAT_L8A8_SRGB
:
1146 case MESA_FORMAT_A8L8_SRGB
:
1147 *datatype
= GL_UNSIGNED_BYTE
;
1151 case MESA_FORMAT_RGBA_FLOAT32
:
1152 *datatype
= GL_FLOAT
;
1155 case MESA_FORMAT_RGBA_FLOAT16
:
1156 *datatype
= GL_HALF_FLOAT_ARB
;
1159 case MESA_FORMAT_RGB_FLOAT32
:
1160 *datatype
= GL_FLOAT
;
1163 case MESA_FORMAT_RGB_FLOAT16
:
1164 *datatype
= GL_HALF_FLOAT_ARB
;
1167 case MESA_FORMAT_LA_FLOAT32
:
1168 case MESA_FORMAT_RG_FLOAT32
:
1169 *datatype
= GL_FLOAT
;
1172 case MESA_FORMAT_LA_FLOAT16
:
1173 case MESA_FORMAT_RG_FLOAT16
:
1174 *datatype
= GL_HALF_FLOAT_ARB
;
1177 case MESA_FORMAT_A_FLOAT32
:
1178 case MESA_FORMAT_L_FLOAT32
:
1179 case MESA_FORMAT_I_FLOAT32
:
1180 case MESA_FORMAT_R_FLOAT32
:
1181 *datatype
= GL_FLOAT
;
1184 case MESA_FORMAT_A_FLOAT16
:
1185 case MESA_FORMAT_L_FLOAT16
:
1186 case MESA_FORMAT_I_FLOAT16
:
1187 case MESA_FORMAT_R_FLOAT16
:
1188 *datatype
= GL_HALF_FLOAT_ARB
;
1192 case MESA_FORMAT_A_UINT8
:
1193 case MESA_FORMAT_L_UINT8
:
1194 case MESA_FORMAT_I_UINT8
:
1195 *datatype
= GL_UNSIGNED_BYTE
;
1198 case MESA_FORMAT_LA_UINT8
:
1199 *datatype
= GL_UNSIGNED_BYTE
;
1203 case MESA_FORMAT_A_UINT16
:
1204 case MESA_FORMAT_L_UINT16
:
1205 case MESA_FORMAT_I_UINT16
:
1206 *datatype
= GL_UNSIGNED_SHORT
;
1209 case MESA_FORMAT_LA_UINT16
:
1210 *datatype
= GL_UNSIGNED_SHORT
;
1213 case MESA_FORMAT_A_UINT32
:
1214 case MESA_FORMAT_L_UINT32
:
1215 case MESA_FORMAT_I_UINT32
:
1216 *datatype
= GL_UNSIGNED_INT
;
1219 case MESA_FORMAT_LA_UINT32
:
1220 *datatype
= GL_UNSIGNED_INT
;
1223 case MESA_FORMAT_A_SINT8
:
1224 case MESA_FORMAT_L_SINT8
:
1225 case MESA_FORMAT_I_SINT8
:
1226 *datatype
= GL_BYTE
;
1229 case MESA_FORMAT_LA_SINT8
:
1230 *datatype
= GL_BYTE
;
1234 case MESA_FORMAT_A_SINT16
:
1235 case MESA_FORMAT_L_SINT16
:
1236 case MESA_FORMAT_I_SINT16
:
1237 *datatype
= GL_SHORT
;
1240 case MESA_FORMAT_LA_SINT16
:
1241 *datatype
= GL_SHORT
;
1245 case MESA_FORMAT_A_SINT32
:
1246 case MESA_FORMAT_L_SINT32
:
1247 case MESA_FORMAT_I_SINT32
:
1251 case MESA_FORMAT_LA_SINT32
:
1256 case MESA_FORMAT_R_SINT8
:
1257 *datatype
= GL_BYTE
;
1260 case MESA_FORMAT_RG_SINT8
:
1261 *datatype
= GL_BYTE
;
1264 case MESA_FORMAT_RGB_SINT8
:
1265 *datatype
= GL_BYTE
;
1268 case MESA_FORMAT_RGBA_SINT8
:
1269 *datatype
= GL_BYTE
;
1272 case MESA_FORMAT_R_SINT16
:
1273 *datatype
= GL_SHORT
;
1276 case MESA_FORMAT_RG_SINT16
:
1277 *datatype
= GL_SHORT
;
1280 case MESA_FORMAT_RGB_SINT16
:
1281 *datatype
= GL_SHORT
;
1284 case MESA_FORMAT_RGBA_SINT16
:
1285 *datatype
= GL_SHORT
;
1288 case MESA_FORMAT_R_SINT32
:
1292 case MESA_FORMAT_RG_SINT32
:
1296 case MESA_FORMAT_RGB_SINT32
:
1300 case MESA_FORMAT_RGBA_SINT32
:
1306 * \name Non-normalized unsigned integer formats.
1308 case MESA_FORMAT_R_UINT8
:
1309 *datatype
= GL_UNSIGNED_BYTE
;
1312 case MESA_FORMAT_RG_UINT8
:
1313 *datatype
= GL_UNSIGNED_BYTE
;
1316 case MESA_FORMAT_RGB_UINT8
:
1317 *datatype
= GL_UNSIGNED_BYTE
;
1320 case MESA_FORMAT_RGBA_UINT8
:
1321 *datatype
= GL_UNSIGNED_BYTE
;
1324 case MESA_FORMAT_R_UINT16
:
1325 *datatype
= GL_UNSIGNED_SHORT
;
1328 case MESA_FORMAT_RG_UINT16
:
1329 *datatype
= GL_UNSIGNED_SHORT
;
1332 case MESA_FORMAT_RGB_UINT16
:
1333 *datatype
= GL_UNSIGNED_SHORT
;
1336 case MESA_FORMAT_RGBA_UINT16
:
1337 *datatype
= GL_UNSIGNED_SHORT
;
1340 case MESA_FORMAT_R_UINT32
:
1341 *datatype
= GL_UNSIGNED_INT
;
1344 case MESA_FORMAT_RG_UINT32
:
1345 *datatype
= GL_UNSIGNED_INT
;
1348 case MESA_FORMAT_RGB_UINT32
:
1349 *datatype
= GL_UNSIGNED_INT
;
1352 case MESA_FORMAT_RGBA_UINT32
:
1353 *datatype
= GL_UNSIGNED_INT
;
1357 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1358 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1362 case MESA_FORMAT_R11G11B10_FLOAT
:
1363 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1367 case MESA_FORMAT_B10G10R10A2_UINT
:
1368 case MESA_FORMAT_R10G10B10A2_UINT
:
1369 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1373 case MESA_FORMAT_R8G8B8X8_SRGB
:
1374 case MESA_FORMAT_X8B8G8R8_SRGB
:
1375 case MESA_FORMAT_RGBX_UINT8
:
1376 *datatype
= GL_UNSIGNED_BYTE
;
1380 case MESA_FORMAT_R8G8B8X8_SNORM
:
1381 case MESA_FORMAT_RGBX_SINT8
:
1382 *datatype
= GL_BYTE
;
1386 case MESA_FORMAT_B10G10R10X2_UNORM
:
1387 case MESA_FORMAT_R10G10B10X2_UNORM
:
1388 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1392 case MESA_FORMAT_RGBX_UNORM16
:
1393 case MESA_FORMAT_RGBX_UINT16
:
1394 *datatype
= GL_UNSIGNED_SHORT
;
1398 case MESA_FORMAT_RGBX_SNORM16
:
1399 case MESA_FORMAT_RGBX_SINT16
:
1400 *datatype
= GL_SHORT
;
1404 case MESA_FORMAT_RGBX_FLOAT16
:
1405 *datatype
= GL_HALF_FLOAT
;
1409 case MESA_FORMAT_RGBX_FLOAT32
:
1410 *datatype
= GL_FLOAT
;
1414 case MESA_FORMAT_RGBX_UINT32
:
1415 *datatype
= GL_UNSIGNED_INT
;
1419 case MESA_FORMAT_RGBX_SINT32
:
1424 case MESA_FORMAT_R10G10B10A2_UNORM
:
1425 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1429 case MESA_FORMAT_G8R8_SNORM
:
1430 *datatype
= GL_BYTE
;
1434 case MESA_FORMAT_G16R16_SNORM
:
1435 *datatype
= GL_SHORT
;
1439 case MESA_FORMAT_B8G8R8X8_SRGB
:
1440 case MESA_FORMAT_X8R8G8B8_SRGB
:
1441 *datatype
= GL_UNSIGNED_BYTE
;
1445 case MESA_FORMAT_COUNT
:
1449 /* Warn if any formats are not handled */
1450 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1451 _mesa_get_format_name(format
));
1452 assert(format
== MESA_FORMAT_NONE
||
1453 _mesa_is_format_compressed(format
));
1460 * Check if a mesa_format exactly matches a GL format/type combination
1461 * such that we can use memcpy() from one to the other.
1462 * \param mesa_format a MESA_FORMAT_x value
1463 * \param format the user-specified image format
1464 * \param type the user-specified image datatype
1465 * \param swapBytes typically the current pixel pack/unpack byteswap state
1466 * \param[out] error GL_NO_ERROR if format is an expected input.
1467 * GL_INVALID_ENUM if format is an unexpected input.
1468 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1471 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1472 GLenum format
, GLenum type
,
1473 GLboolean swapBytes
, GLenum
*error
)
1475 const GLboolean littleEndian
= _mesa_little_endian();
1477 *error
= GL_NO_ERROR
;
1479 /* Note: When reading a GL format/type combination, the format lists channel
1480 * assignments from most significant channel in the type to least
1481 * significant. A type with _REV indicates that the assignments are
1482 * swapped, so they are listed from least significant to most significant.
1484 * Compressed formats will fall through and return GL_FALSE.
1486 * For sanity, please keep this switch statement ordered the same as the
1487 * enums in formats.h.
1490 switch (mesa_format
) {
1492 case MESA_FORMAT_NONE
:
1493 case MESA_FORMAT_COUNT
:
1496 case MESA_FORMAT_A8B8G8R8_UNORM
:
1497 case MESA_FORMAT_A8B8G8R8_SRGB
:
1498 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1501 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1504 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1507 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1511 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1515 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1520 case MESA_FORMAT_R8G8B8A8_UNORM
:
1521 case MESA_FORMAT_R8G8B8A8_SRGB
:
1522 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1526 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1529 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1532 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1536 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1540 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1545 case MESA_FORMAT_B8G8R8A8_UNORM
:
1546 case MESA_FORMAT_B8G8R8A8_SRGB
:
1547 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1551 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1554 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1559 case MESA_FORMAT_A8R8G8B8_UNORM
:
1560 case MESA_FORMAT_A8R8G8B8_SRGB
:
1561 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1564 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1568 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1573 case MESA_FORMAT_X8B8G8R8_UNORM
:
1574 case MESA_FORMAT_R8G8B8X8_UNORM
:
1577 case MESA_FORMAT_B8G8R8X8_UNORM
:
1578 case MESA_FORMAT_X8R8G8B8_UNORM
:
1581 case MESA_FORMAT_BGR_UNORM8
:
1582 case MESA_FORMAT_BGR_SRGB8
:
1583 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1585 case MESA_FORMAT_RGB_UNORM8
:
1586 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1588 case MESA_FORMAT_B5G6R5_UNORM
:
1589 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1590 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1593 case MESA_FORMAT_R5G6B5_UNORM
:
1594 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1595 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1598 case MESA_FORMAT_B4G4R4A4_UNORM
:
1599 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1602 case MESA_FORMAT_A4R4G4B4_UNORM
:
1605 case MESA_FORMAT_A1B5G5R5_UNORM
:
1606 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1609 case MESA_FORMAT_B5G5R5A1_UNORM
:
1610 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1613 case MESA_FORMAT_A1R5G5B5_UNORM
:
1614 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1617 case MESA_FORMAT_L4A4_UNORM
:
1619 case MESA_FORMAT_L8A8_UNORM
:
1620 case MESA_FORMAT_L8A8_SRGB
:
1621 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1622 case MESA_FORMAT_A8L8_UNORM
:
1623 case MESA_FORMAT_A8L8_SRGB
:
1626 case MESA_FORMAT_L16A16_UNORM
:
1627 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1628 case MESA_FORMAT_A16L16_UNORM
:
1631 case MESA_FORMAT_B2G3R3_UNORM
:
1632 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1634 case MESA_FORMAT_R3G3B2_UNORM
:
1635 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1637 case MESA_FORMAT_A4B4G4R4_UNORM
:
1638 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1641 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1644 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1647 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1652 case MESA_FORMAT_R4G4B4A4_UNORM
:
1653 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1656 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1659 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1662 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1667 case MESA_FORMAT_R5G5B5A1_UNORM
:
1668 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1670 case MESA_FORMAT_A2B10G10R10_UNORM
:
1671 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1673 case MESA_FORMAT_A2B10G10R10_UINT
:
1674 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1676 case MESA_FORMAT_A2R10G10B10_UNORM
:
1677 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1679 case MESA_FORMAT_A2R10G10B10_UINT
:
1680 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1682 case MESA_FORMAT_A_UNORM8
:
1683 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1684 case MESA_FORMAT_A_UNORM16
:
1685 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1686 case MESA_FORMAT_L_UNORM8
:
1687 case MESA_FORMAT_L_SRGB8
:
1688 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1689 case MESA_FORMAT_L_UNORM16
:
1690 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1691 case MESA_FORMAT_I_UNORM8
:
1692 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1693 case MESA_FORMAT_I_UNORM16
:
1694 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1696 case MESA_FORMAT_YCBCR
:
1697 return format
== GL_YCBCR_MESA
&&
1698 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1699 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1700 case MESA_FORMAT_YCBCR_REV
:
1701 return format
== GL_YCBCR_MESA
&&
1702 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1703 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1705 case MESA_FORMAT_R_UNORM8
:
1706 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1707 case MESA_FORMAT_R8G8_UNORM
:
1708 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1709 case MESA_FORMAT_G8R8_UNORM
:
1712 case MESA_FORMAT_R_UNORM16
:
1713 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1715 case MESA_FORMAT_R16G16_UNORM
:
1716 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1718 case MESA_FORMAT_G16R16_UNORM
:
1721 case MESA_FORMAT_B10G10R10A2_UNORM
:
1722 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1725 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1726 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1728 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1729 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1732 case MESA_FORMAT_Z_UNORM16
:
1733 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1736 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1739 case MESA_FORMAT_Z_UNORM32
:
1740 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1743 case MESA_FORMAT_S_UINT8
:
1744 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1746 case MESA_FORMAT_RGBA_FLOAT32
:
1747 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1748 case MESA_FORMAT_RGBA_FLOAT16
:
1749 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1751 case MESA_FORMAT_RGB_FLOAT32
:
1752 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1753 case MESA_FORMAT_RGB_FLOAT16
:
1754 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1756 case MESA_FORMAT_A_FLOAT32
:
1757 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1758 case MESA_FORMAT_A_FLOAT16
:
1759 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1761 case MESA_FORMAT_L_FLOAT32
:
1762 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1763 case MESA_FORMAT_L_FLOAT16
:
1764 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1766 case MESA_FORMAT_LA_FLOAT32
:
1767 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1768 case MESA_FORMAT_LA_FLOAT16
:
1769 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1771 case MESA_FORMAT_I_FLOAT32
:
1772 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1773 case MESA_FORMAT_I_FLOAT16
:
1774 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1776 case MESA_FORMAT_R_FLOAT32
:
1777 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1778 case MESA_FORMAT_R_FLOAT16
:
1779 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1781 case MESA_FORMAT_RG_FLOAT32
:
1782 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1783 case MESA_FORMAT_RG_FLOAT16
:
1784 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1786 case MESA_FORMAT_A_UINT8
:
1787 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1788 case MESA_FORMAT_A_UINT16
:
1789 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1791 case MESA_FORMAT_A_UINT32
:
1792 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1794 case MESA_FORMAT_A_SINT8
:
1795 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1796 case MESA_FORMAT_A_SINT16
:
1797 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1798 case MESA_FORMAT_A_SINT32
:
1799 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1801 case MESA_FORMAT_I_UINT8
:
1802 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1803 case MESA_FORMAT_I_UINT16
:
1804 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1805 case MESA_FORMAT_I_UINT32
:
1806 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1807 case MESA_FORMAT_I_SINT8
:
1808 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1809 case MESA_FORMAT_I_SINT16
:
1810 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1811 case MESA_FORMAT_I_SINT32
:
1812 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1814 case MESA_FORMAT_L_UINT8
:
1815 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1816 case MESA_FORMAT_L_UINT16
:
1817 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1819 case MESA_FORMAT_L_UINT32
:
1820 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1822 case MESA_FORMAT_L_SINT8
:
1823 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1824 case MESA_FORMAT_L_SINT16
:
1825 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1827 case MESA_FORMAT_L_SINT32
:
1828 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1830 case MESA_FORMAT_LA_UINT8
:
1831 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1832 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1833 case MESA_FORMAT_LA_UINT16
:
1834 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1835 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1836 case MESA_FORMAT_LA_UINT32
:
1837 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1838 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1839 case MESA_FORMAT_LA_SINT8
:
1840 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1842 case MESA_FORMAT_LA_SINT16
:
1843 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1845 case MESA_FORMAT_LA_SINT32
:
1846 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1849 case MESA_FORMAT_R_SINT8
:
1850 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1851 case MESA_FORMAT_RG_SINT8
:
1852 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1853 case MESA_FORMAT_RGB_SINT8
:
1854 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1855 case MESA_FORMAT_RGBA_SINT8
:
1856 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1857 case MESA_FORMAT_R_SINT16
:
1858 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1859 case MESA_FORMAT_RG_SINT16
:
1860 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1861 case MESA_FORMAT_RGB_SINT16
:
1862 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1863 case MESA_FORMAT_RGBA_SINT16
:
1864 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1865 case MESA_FORMAT_R_SINT32
:
1866 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1867 case MESA_FORMAT_RG_SINT32
:
1868 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1869 case MESA_FORMAT_RGB_SINT32
:
1870 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1871 case MESA_FORMAT_RGBA_SINT32
:
1872 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1874 case MESA_FORMAT_R_UINT8
:
1875 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1876 case MESA_FORMAT_RG_UINT8
:
1877 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1878 case MESA_FORMAT_RGB_UINT8
:
1879 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1880 case MESA_FORMAT_RGBA_UINT8
:
1881 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1883 case MESA_FORMAT_R_UINT16
:
1884 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1886 case MESA_FORMAT_RG_UINT16
:
1887 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1888 case MESA_FORMAT_RGB_UINT16
:
1889 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1891 case MESA_FORMAT_RGBA_UINT16
:
1892 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1894 case MESA_FORMAT_R_UINT32
:
1895 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1896 case MESA_FORMAT_RG_UINT32
:
1897 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1898 case MESA_FORMAT_RGB_UINT32
:
1899 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1900 case MESA_FORMAT_RGBA_UINT32
:
1901 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1903 case MESA_FORMAT_R_SNORM8
:
1904 return format
== GL_RED
&& type
== GL_BYTE
;
1905 case MESA_FORMAT_R8G8_SNORM
:
1906 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1908 case MESA_FORMAT_X8B8G8R8_SNORM
:
1911 case MESA_FORMAT_A8B8G8R8_SNORM
:
1912 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1915 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1920 case MESA_FORMAT_R8G8B8A8_SNORM
:
1921 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1924 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1929 case MESA_FORMAT_R_SNORM16
:
1930 return format
== GL_RED
&& type
== GL_SHORT
&&
1932 case MESA_FORMAT_R16G16_SNORM
:
1933 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1934 case MESA_FORMAT_RGB_SNORM16
:
1935 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1936 case MESA_FORMAT_RGBA_SNORM16
:
1937 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1938 case MESA_FORMAT_RGBA_UNORM16
:
1939 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1942 case MESA_FORMAT_A_SNORM8
:
1943 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1944 case MESA_FORMAT_L_SNORM8
:
1945 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1946 case MESA_FORMAT_L8A8_SNORM
:
1947 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1948 littleEndian
&& !swapBytes
;
1949 case MESA_FORMAT_A8L8_SNORM
:
1950 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1951 !littleEndian
&& !swapBytes
;
1952 case MESA_FORMAT_I_SNORM8
:
1953 return format
== GL_RED
&& type
== GL_BYTE
;
1954 case MESA_FORMAT_A_SNORM16
:
1955 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1956 case MESA_FORMAT_L_SNORM16
:
1957 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1958 case MESA_FORMAT_LA_SNORM16
:
1959 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1960 littleEndian
&& !swapBytes
;
1961 case MESA_FORMAT_I_SNORM16
:
1962 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1965 case MESA_FORMAT_B10G10R10A2_UINT
:
1966 return (format
== GL_BGRA_INTEGER_EXT
&&
1967 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1970 case MESA_FORMAT_R10G10B10A2_UINT
:
1971 return (format
== GL_RGBA_INTEGER_EXT
&&
1972 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1975 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1976 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
1979 case MESA_FORMAT_R11G11B10_FLOAT
:
1980 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
1983 case MESA_FORMAT_Z_FLOAT32
:
1984 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
1986 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1987 return format
== GL_DEPTH_STENCIL
&&
1988 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
1990 case MESA_FORMAT_B4G4R4X4_UNORM
:
1991 case MESA_FORMAT_B5G5R5X1_UNORM
:
1992 case MESA_FORMAT_R8G8B8X8_SNORM
:
1993 case MESA_FORMAT_R8G8B8X8_SRGB
:
1994 case MESA_FORMAT_X8B8G8R8_SRGB
:
1995 case MESA_FORMAT_RGBX_UINT8
:
1996 case MESA_FORMAT_RGBX_SINT8
:
1997 case MESA_FORMAT_B10G10R10X2_UNORM
:
1998 case MESA_FORMAT_R10G10B10X2_UNORM
:
1999 case MESA_FORMAT_RGBX_UNORM16
:
2000 case MESA_FORMAT_RGBX_SNORM16
:
2001 case MESA_FORMAT_RGBX_FLOAT16
:
2002 case MESA_FORMAT_RGBX_UINT16
:
2003 case MESA_FORMAT_RGBX_SINT16
:
2004 case MESA_FORMAT_RGBX_FLOAT32
:
2005 case MESA_FORMAT_RGBX_UINT32
:
2006 case MESA_FORMAT_RGBX_SINT32
:
2009 case MESA_FORMAT_R10G10B10A2_UNORM
:
2010 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2013 case MESA_FORMAT_G8R8_SNORM
:
2014 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2017 case MESA_FORMAT_G16R16_SNORM
:
2018 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2021 case MESA_FORMAT_B8G8R8X8_SRGB
:
2022 case MESA_FORMAT_X8R8G8B8_SRGB
:
2025 assert(_mesa_is_format_compressed(mesa_format
));
2027 *error
= GL_INVALID_ENUM
;