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 case MESA_FORMAT_B5G6R5_UINT
:
940 case MESA_FORMAT_R5G6B5_UINT
:
941 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
945 case MESA_FORMAT_B4G4R4A4_UNORM
:
946 case MESA_FORMAT_A4R4G4B4_UNORM
:
947 case MESA_FORMAT_B4G4R4X4_UNORM
:
948 case MESA_FORMAT_B4G4R4A4_UINT
:
949 case MESA_FORMAT_A4R4G4B4_UINT
:
950 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
954 case MESA_FORMAT_B5G5R5A1_UNORM
:
955 case MESA_FORMAT_A1R5G5B5_UNORM
:
956 case MESA_FORMAT_B5G5R5X1_UNORM
:
957 case MESA_FORMAT_B5G5R5A1_UINT
:
958 case MESA_FORMAT_A1R5G5B5_UINT
:
959 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
963 case MESA_FORMAT_B10G10R10A2_UNORM
:
964 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
968 case MESA_FORMAT_A1B5G5R5_UNORM
:
969 case MESA_FORMAT_A1B5G5R5_UINT
:
970 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
974 case MESA_FORMAT_L4A4_UNORM
:
975 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
979 case MESA_FORMAT_L8A8_UNORM
:
980 case MESA_FORMAT_A8L8_UNORM
:
981 case MESA_FORMAT_R8G8_UNORM
:
982 case MESA_FORMAT_G8R8_UNORM
:
983 *datatype
= GL_UNSIGNED_BYTE
;
987 case MESA_FORMAT_L16A16_UNORM
:
988 case MESA_FORMAT_A16L16_UNORM
:
989 case MESA_FORMAT_R16G16_UNORM
:
990 case MESA_FORMAT_G16R16_UNORM
:
991 *datatype
= GL_UNSIGNED_SHORT
;
995 case MESA_FORMAT_R_UNORM16
:
996 case MESA_FORMAT_A_UNORM16
:
997 case MESA_FORMAT_L_UNORM16
:
998 case MESA_FORMAT_I_UNORM16
:
999 *datatype
= GL_UNSIGNED_SHORT
;
1003 case MESA_FORMAT_R3G3B2_UNORM
:
1004 case MESA_FORMAT_R3G3B2_UINT
:
1005 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1008 case MESA_FORMAT_A4B4G4R4_UNORM
:
1009 case MESA_FORMAT_A4B4G4R4_UINT
:
1010 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1014 case MESA_FORMAT_R4G4B4A4_UNORM
:
1015 case MESA_FORMAT_R4G4B4A4_UINT
:
1016 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1019 case MESA_FORMAT_R5G5B5A1_UNORM
:
1020 case MESA_FORMAT_R5G5B5A1_UINT
:
1021 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1024 case MESA_FORMAT_A2B10G10R10_UNORM
:
1025 case MESA_FORMAT_A2B10G10R10_UINT
:
1026 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1029 case MESA_FORMAT_A2R10G10B10_UNORM
:
1030 case MESA_FORMAT_A2R10G10B10_UINT
:
1031 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1035 case MESA_FORMAT_B2G3R3_UNORM
:
1036 case MESA_FORMAT_B2G3R3_UINT
:
1037 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1041 case MESA_FORMAT_A_UNORM8
:
1042 case MESA_FORMAT_L_UNORM8
:
1043 case MESA_FORMAT_I_UNORM8
:
1044 case MESA_FORMAT_R_UNORM8
:
1045 case MESA_FORMAT_S_UINT8
:
1046 *datatype
= GL_UNSIGNED_BYTE
;
1050 case MESA_FORMAT_YCBCR
:
1051 case MESA_FORMAT_YCBCR_REV
:
1052 *datatype
= GL_UNSIGNED_SHORT
;
1056 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1057 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1061 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1062 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1066 case MESA_FORMAT_Z_UNORM16
:
1067 *datatype
= GL_UNSIGNED_SHORT
;
1071 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1072 *datatype
= GL_UNSIGNED_INT
;
1076 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1077 *datatype
= GL_UNSIGNED_INT
;
1081 case MESA_FORMAT_Z_UNORM32
:
1082 *datatype
= GL_UNSIGNED_INT
;
1086 case MESA_FORMAT_Z_FLOAT32
:
1087 *datatype
= GL_FLOAT
;
1091 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1092 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1096 case MESA_FORMAT_R_SNORM8
:
1097 case MESA_FORMAT_A_SNORM8
:
1098 case MESA_FORMAT_L_SNORM8
:
1099 case MESA_FORMAT_I_SNORM8
:
1100 *datatype
= GL_BYTE
;
1103 case MESA_FORMAT_R8G8_SNORM
:
1104 case MESA_FORMAT_L8A8_SNORM
:
1105 case MESA_FORMAT_A8L8_SNORM
:
1106 *datatype
= GL_BYTE
;
1109 case MESA_FORMAT_A8B8G8R8_SNORM
:
1110 case MESA_FORMAT_R8G8B8A8_SNORM
:
1111 case MESA_FORMAT_X8B8G8R8_SNORM
:
1112 *datatype
= GL_BYTE
;
1116 case MESA_FORMAT_RGBA_UNORM16
:
1117 *datatype
= GL_UNSIGNED_SHORT
;
1121 case MESA_FORMAT_R_SNORM16
:
1122 case MESA_FORMAT_A_SNORM16
:
1123 case MESA_FORMAT_L_SNORM16
:
1124 case MESA_FORMAT_I_SNORM16
:
1125 *datatype
= GL_SHORT
;
1128 case MESA_FORMAT_R16G16_SNORM
:
1129 case MESA_FORMAT_LA_SNORM16
:
1130 *datatype
= GL_SHORT
;
1133 case MESA_FORMAT_RGB_SNORM16
:
1134 *datatype
= GL_SHORT
;
1137 case MESA_FORMAT_RGBA_SNORM16
:
1138 *datatype
= GL_SHORT
;
1142 case MESA_FORMAT_BGR_SRGB8
:
1143 *datatype
= GL_UNSIGNED_BYTE
;
1146 case MESA_FORMAT_A8B8G8R8_SRGB
:
1147 case MESA_FORMAT_B8G8R8A8_SRGB
:
1148 case MESA_FORMAT_A8R8G8B8_SRGB
:
1149 case MESA_FORMAT_R8G8B8A8_SRGB
:
1150 *datatype
= GL_UNSIGNED_BYTE
;
1153 case MESA_FORMAT_L_SRGB8
:
1154 *datatype
= GL_UNSIGNED_BYTE
;
1157 case MESA_FORMAT_L8A8_SRGB
:
1158 case MESA_FORMAT_A8L8_SRGB
:
1159 *datatype
= GL_UNSIGNED_BYTE
;
1163 case MESA_FORMAT_RGBA_FLOAT32
:
1164 *datatype
= GL_FLOAT
;
1167 case MESA_FORMAT_RGBA_FLOAT16
:
1168 *datatype
= GL_HALF_FLOAT_ARB
;
1171 case MESA_FORMAT_RGB_FLOAT32
:
1172 *datatype
= GL_FLOAT
;
1175 case MESA_FORMAT_RGB_FLOAT16
:
1176 *datatype
= GL_HALF_FLOAT_ARB
;
1179 case MESA_FORMAT_LA_FLOAT32
:
1180 case MESA_FORMAT_RG_FLOAT32
:
1181 *datatype
= GL_FLOAT
;
1184 case MESA_FORMAT_LA_FLOAT16
:
1185 case MESA_FORMAT_RG_FLOAT16
:
1186 *datatype
= GL_HALF_FLOAT_ARB
;
1189 case MESA_FORMAT_A_FLOAT32
:
1190 case MESA_FORMAT_L_FLOAT32
:
1191 case MESA_FORMAT_I_FLOAT32
:
1192 case MESA_FORMAT_R_FLOAT32
:
1193 *datatype
= GL_FLOAT
;
1196 case MESA_FORMAT_A_FLOAT16
:
1197 case MESA_FORMAT_L_FLOAT16
:
1198 case MESA_FORMAT_I_FLOAT16
:
1199 case MESA_FORMAT_R_FLOAT16
:
1200 *datatype
= GL_HALF_FLOAT_ARB
;
1204 case MESA_FORMAT_A_UINT8
:
1205 case MESA_FORMAT_L_UINT8
:
1206 case MESA_FORMAT_I_UINT8
:
1207 *datatype
= GL_UNSIGNED_BYTE
;
1210 case MESA_FORMAT_LA_UINT8
:
1211 *datatype
= GL_UNSIGNED_BYTE
;
1215 case MESA_FORMAT_A_UINT16
:
1216 case MESA_FORMAT_L_UINT16
:
1217 case MESA_FORMAT_I_UINT16
:
1218 *datatype
= GL_UNSIGNED_SHORT
;
1221 case MESA_FORMAT_LA_UINT16
:
1222 *datatype
= GL_UNSIGNED_SHORT
;
1225 case MESA_FORMAT_A_UINT32
:
1226 case MESA_FORMAT_L_UINT32
:
1227 case MESA_FORMAT_I_UINT32
:
1228 *datatype
= GL_UNSIGNED_INT
;
1231 case MESA_FORMAT_LA_UINT32
:
1232 *datatype
= GL_UNSIGNED_INT
;
1235 case MESA_FORMAT_A_SINT8
:
1236 case MESA_FORMAT_L_SINT8
:
1237 case MESA_FORMAT_I_SINT8
:
1238 *datatype
= GL_BYTE
;
1241 case MESA_FORMAT_LA_SINT8
:
1242 *datatype
= GL_BYTE
;
1246 case MESA_FORMAT_A_SINT16
:
1247 case MESA_FORMAT_L_SINT16
:
1248 case MESA_FORMAT_I_SINT16
:
1249 *datatype
= GL_SHORT
;
1252 case MESA_FORMAT_LA_SINT16
:
1253 *datatype
= GL_SHORT
;
1257 case MESA_FORMAT_A_SINT32
:
1258 case MESA_FORMAT_L_SINT32
:
1259 case MESA_FORMAT_I_SINT32
:
1263 case MESA_FORMAT_LA_SINT32
:
1268 case MESA_FORMAT_R_SINT8
:
1269 *datatype
= GL_BYTE
;
1272 case MESA_FORMAT_RG_SINT8
:
1273 *datatype
= GL_BYTE
;
1276 case MESA_FORMAT_RGB_SINT8
:
1277 *datatype
= GL_BYTE
;
1280 case MESA_FORMAT_RGBA_SINT8
:
1281 *datatype
= GL_BYTE
;
1284 case MESA_FORMAT_R_SINT16
:
1285 *datatype
= GL_SHORT
;
1288 case MESA_FORMAT_RG_SINT16
:
1289 *datatype
= GL_SHORT
;
1292 case MESA_FORMAT_RGB_SINT16
:
1293 *datatype
= GL_SHORT
;
1296 case MESA_FORMAT_RGBA_SINT16
:
1297 *datatype
= GL_SHORT
;
1300 case MESA_FORMAT_R_SINT32
:
1304 case MESA_FORMAT_RG_SINT32
:
1308 case MESA_FORMAT_RGB_SINT32
:
1312 case MESA_FORMAT_RGBA_SINT32
:
1318 * \name Non-normalized unsigned integer formats.
1320 case MESA_FORMAT_R_UINT8
:
1321 *datatype
= GL_UNSIGNED_BYTE
;
1324 case MESA_FORMAT_RG_UINT8
:
1325 *datatype
= GL_UNSIGNED_BYTE
;
1328 case MESA_FORMAT_RGB_UINT8
:
1329 *datatype
= GL_UNSIGNED_BYTE
;
1332 case MESA_FORMAT_RGBA_UINT8
:
1333 *datatype
= GL_UNSIGNED_BYTE
;
1336 case MESA_FORMAT_R_UINT16
:
1337 *datatype
= GL_UNSIGNED_SHORT
;
1340 case MESA_FORMAT_RG_UINT16
:
1341 *datatype
= GL_UNSIGNED_SHORT
;
1344 case MESA_FORMAT_RGB_UINT16
:
1345 *datatype
= GL_UNSIGNED_SHORT
;
1348 case MESA_FORMAT_RGBA_UINT16
:
1349 *datatype
= GL_UNSIGNED_SHORT
;
1352 case MESA_FORMAT_R_UINT32
:
1353 *datatype
= GL_UNSIGNED_INT
;
1356 case MESA_FORMAT_RG_UINT32
:
1357 *datatype
= GL_UNSIGNED_INT
;
1360 case MESA_FORMAT_RGB_UINT32
:
1361 *datatype
= GL_UNSIGNED_INT
;
1364 case MESA_FORMAT_RGBA_UINT32
:
1365 *datatype
= GL_UNSIGNED_INT
;
1369 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1370 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1374 case MESA_FORMAT_R11G11B10_FLOAT
:
1375 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1379 case MESA_FORMAT_B10G10R10A2_UINT
:
1380 case MESA_FORMAT_R10G10B10A2_UINT
:
1381 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1385 case MESA_FORMAT_R8G8B8X8_SRGB
:
1386 case MESA_FORMAT_X8B8G8R8_SRGB
:
1387 case MESA_FORMAT_RGBX_UINT8
:
1388 *datatype
= GL_UNSIGNED_BYTE
;
1392 case MESA_FORMAT_R8G8B8X8_SNORM
:
1393 case MESA_FORMAT_RGBX_SINT8
:
1394 *datatype
= GL_BYTE
;
1398 case MESA_FORMAT_B10G10R10X2_UNORM
:
1399 case MESA_FORMAT_R10G10B10X2_UNORM
:
1400 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1404 case MESA_FORMAT_RGBX_UNORM16
:
1405 case MESA_FORMAT_RGBX_UINT16
:
1406 *datatype
= GL_UNSIGNED_SHORT
;
1410 case MESA_FORMAT_RGBX_SNORM16
:
1411 case MESA_FORMAT_RGBX_SINT16
:
1412 *datatype
= GL_SHORT
;
1416 case MESA_FORMAT_RGBX_FLOAT16
:
1417 *datatype
= GL_HALF_FLOAT
;
1421 case MESA_FORMAT_RGBX_FLOAT32
:
1422 *datatype
= GL_FLOAT
;
1426 case MESA_FORMAT_RGBX_UINT32
:
1427 *datatype
= GL_UNSIGNED_INT
;
1431 case MESA_FORMAT_RGBX_SINT32
:
1436 case MESA_FORMAT_R10G10B10A2_UNORM
:
1437 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1441 case MESA_FORMAT_G8R8_SNORM
:
1442 *datatype
= GL_BYTE
;
1446 case MESA_FORMAT_G16R16_SNORM
:
1447 *datatype
= GL_SHORT
;
1451 case MESA_FORMAT_B8G8R8X8_SRGB
:
1452 case MESA_FORMAT_X8R8G8B8_SRGB
:
1453 *datatype
= GL_UNSIGNED_BYTE
;
1457 case MESA_FORMAT_COUNT
:
1461 /* Warn if any formats are not handled */
1462 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1463 _mesa_get_format_name(format
));
1464 assert(format
== MESA_FORMAT_NONE
||
1465 _mesa_is_format_compressed(format
));
1472 * Check if a mesa_format exactly matches a GL format/type combination
1473 * such that we can use memcpy() from one to the other.
1474 * \param mesa_format a MESA_FORMAT_x value
1475 * \param format the user-specified image format
1476 * \param type the user-specified image datatype
1477 * \param swapBytes typically the current pixel pack/unpack byteswap state
1478 * \param[out] error GL_NO_ERROR if format is an expected input.
1479 * GL_INVALID_ENUM if format is an unexpected input.
1480 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1483 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1484 GLenum format
, GLenum type
,
1485 GLboolean swapBytes
, GLenum
*error
)
1487 const GLboolean littleEndian
= _mesa_little_endian();
1489 *error
= GL_NO_ERROR
;
1491 /* Note: When reading a GL format/type combination, the format lists channel
1492 * assignments from most significant channel in the type to least
1493 * significant. A type with _REV indicates that the assignments are
1494 * swapped, so they are listed from least significant to most significant.
1496 * Compressed formats will fall through and return GL_FALSE.
1498 * For sanity, please keep this switch statement ordered the same as the
1499 * enums in formats.h.
1502 switch (mesa_format
) {
1504 case MESA_FORMAT_NONE
:
1505 case MESA_FORMAT_COUNT
:
1508 case MESA_FORMAT_A8B8G8R8_UNORM
:
1509 case MESA_FORMAT_A8B8G8R8_SRGB
:
1510 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1513 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1516 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1519 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1523 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1527 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1532 case MESA_FORMAT_R8G8B8A8_UNORM
:
1533 case MESA_FORMAT_R8G8B8A8_SRGB
:
1534 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1538 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1541 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1544 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1548 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1552 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1557 case MESA_FORMAT_B8G8R8A8_UNORM
:
1558 case MESA_FORMAT_B8G8R8A8_SRGB
:
1559 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1563 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1566 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1571 case MESA_FORMAT_A8R8G8B8_UNORM
:
1572 case MESA_FORMAT_A8R8G8B8_SRGB
:
1573 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1576 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1580 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1585 case MESA_FORMAT_X8B8G8R8_UNORM
:
1586 case MESA_FORMAT_R8G8B8X8_UNORM
:
1589 case MESA_FORMAT_B8G8R8X8_UNORM
:
1590 case MESA_FORMAT_X8R8G8B8_UNORM
:
1593 case MESA_FORMAT_BGR_UNORM8
:
1594 case MESA_FORMAT_BGR_SRGB8
:
1595 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1597 case MESA_FORMAT_RGB_UNORM8
:
1598 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1600 case MESA_FORMAT_B5G6R5_UNORM
:
1601 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1602 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1605 case MESA_FORMAT_R5G6B5_UNORM
:
1606 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1607 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1610 case MESA_FORMAT_B4G4R4A4_UNORM
:
1611 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1614 case MESA_FORMAT_A4R4G4B4_UNORM
:
1617 case MESA_FORMAT_A1B5G5R5_UNORM
:
1618 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1621 case MESA_FORMAT_B5G5R5A1_UNORM
:
1622 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1625 case MESA_FORMAT_A1R5G5B5_UNORM
:
1626 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1629 case MESA_FORMAT_L4A4_UNORM
:
1631 case MESA_FORMAT_L8A8_UNORM
:
1632 case MESA_FORMAT_L8A8_SRGB
:
1633 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1634 case MESA_FORMAT_A8L8_UNORM
:
1635 case MESA_FORMAT_A8L8_SRGB
:
1638 case MESA_FORMAT_L16A16_UNORM
:
1639 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1640 case MESA_FORMAT_A16L16_UNORM
:
1643 case MESA_FORMAT_B2G3R3_UNORM
:
1644 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1646 case MESA_FORMAT_R3G3B2_UNORM
:
1647 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1649 case MESA_FORMAT_A4B4G4R4_UNORM
:
1650 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1653 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1656 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1659 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1664 case MESA_FORMAT_R4G4B4A4_UNORM
:
1665 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1668 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1671 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1674 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1679 case MESA_FORMAT_R5G5B5A1_UNORM
:
1680 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1682 case MESA_FORMAT_A2B10G10R10_UNORM
:
1683 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1685 case MESA_FORMAT_A2B10G10R10_UINT
:
1686 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1688 case MESA_FORMAT_A2R10G10B10_UNORM
:
1689 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1691 case MESA_FORMAT_A2R10G10B10_UINT
:
1692 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1694 case MESA_FORMAT_A_UNORM8
:
1695 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1696 case MESA_FORMAT_A_UNORM16
:
1697 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1698 case MESA_FORMAT_L_UNORM8
:
1699 case MESA_FORMAT_L_SRGB8
:
1700 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1701 case MESA_FORMAT_L_UNORM16
:
1702 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1703 case MESA_FORMAT_I_UNORM8
:
1704 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1705 case MESA_FORMAT_I_UNORM16
:
1706 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1708 case MESA_FORMAT_YCBCR
:
1709 return format
== GL_YCBCR_MESA
&&
1710 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1711 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1712 case MESA_FORMAT_YCBCR_REV
:
1713 return format
== GL_YCBCR_MESA
&&
1714 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1715 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1717 case MESA_FORMAT_R_UNORM8
:
1718 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1719 case MESA_FORMAT_R8G8_UNORM
:
1720 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1721 case MESA_FORMAT_G8R8_UNORM
:
1724 case MESA_FORMAT_R_UNORM16
:
1725 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1727 case MESA_FORMAT_R16G16_UNORM
:
1728 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1730 case MESA_FORMAT_G16R16_UNORM
:
1733 case MESA_FORMAT_B10G10R10A2_UNORM
:
1734 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1737 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1738 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1740 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1741 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1744 case MESA_FORMAT_Z_UNORM16
:
1745 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1748 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1751 case MESA_FORMAT_Z_UNORM32
:
1752 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1755 case MESA_FORMAT_S_UINT8
:
1756 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1758 case MESA_FORMAT_RGBA_FLOAT32
:
1759 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1760 case MESA_FORMAT_RGBA_FLOAT16
:
1761 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1763 case MESA_FORMAT_RGB_FLOAT32
:
1764 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1765 case MESA_FORMAT_RGB_FLOAT16
:
1766 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1768 case MESA_FORMAT_A_FLOAT32
:
1769 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1770 case MESA_FORMAT_A_FLOAT16
:
1771 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1773 case MESA_FORMAT_L_FLOAT32
:
1774 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1775 case MESA_FORMAT_L_FLOAT16
:
1776 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1778 case MESA_FORMAT_LA_FLOAT32
:
1779 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1780 case MESA_FORMAT_LA_FLOAT16
:
1781 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1783 case MESA_FORMAT_I_FLOAT32
:
1784 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1785 case MESA_FORMAT_I_FLOAT16
:
1786 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1788 case MESA_FORMAT_R_FLOAT32
:
1789 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1790 case MESA_FORMAT_R_FLOAT16
:
1791 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1793 case MESA_FORMAT_RG_FLOAT32
:
1794 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1795 case MESA_FORMAT_RG_FLOAT16
:
1796 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1798 case MESA_FORMAT_A_UINT8
:
1799 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1800 case MESA_FORMAT_A_UINT16
:
1801 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1803 case MESA_FORMAT_A_UINT32
:
1804 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1806 case MESA_FORMAT_A_SINT8
:
1807 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1808 case MESA_FORMAT_A_SINT16
:
1809 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1810 case MESA_FORMAT_A_SINT32
:
1811 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1813 case MESA_FORMAT_I_UINT8
:
1814 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1815 case MESA_FORMAT_I_UINT16
:
1816 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1817 case MESA_FORMAT_I_UINT32
:
1818 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1819 case MESA_FORMAT_I_SINT8
:
1820 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1821 case MESA_FORMAT_I_SINT16
:
1822 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1823 case MESA_FORMAT_I_SINT32
:
1824 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1826 case MESA_FORMAT_L_UINT8
:
1827 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1828 case MESA_FORMAT_L_UINT16
:
1829 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1831 case MESA_FORMAT_L_UINT32
:
1832 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1834 case MESA_FORMAT_L_SINT8
:
1835 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1836 case MESA_FORMAT_L_SINT16
:
1837 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1839 case MESA_FORMAT_L_SINT32
:
1840 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1842 case MESA_FORMAT_LA_UINT8
:
1843 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1844 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1845 case MESA_FORMAT_LA_UINT16
:
1846 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1847 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1848 case MESA_FORMAT_LA_UINT32
:
1849 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1850 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1851 case MESA_FORMAT_LA_SINT8
:
1852 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1854 case MESA_FORMAT_LA_SINT16
:
1855 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1857 case MESA_FORMAT_LA_SINT32
:
1858 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1861 case MESA_FORMAT_R_SINT8
:
1862 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1863 case MESA_FORMAT_RG_SINT8
:
1864 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1865 case MESA_FORMAT_RGB_SINT8
:
1866 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1867 case MESA_FORMAT_RGBA_SINT8
:
1868 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1869 case MESA_FORMAT_R_SINT16
:
1870 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1871 case MESA_FORMAT_RG_SINT16
:
1872 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1873 case MESA_FORMAT_RGB_SINT16
:
1874 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1875 case MESA_FORMAT_RGBA_SINT16
:
1876 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1877 case MESA_FORMAT_R_SINT32
:
1878 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1879 case MESA_FORMAT_RG_SINT32
:
1880 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1881 case MESA_FORMAT_RGB_SINT32
:
1882 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1883 case MESA_FORMAT_RGBA_SINT32
:
1884 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1886 case MESA_FORMAT_R_UINT8
:
1887 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1888 case MESA_FORMAT_RG_UINT8
:
1889 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1890 case MESA_FORMAT_RGB_UINT8
:
1891 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1892 case MESA_FORMAT_RGBA_UINT8
:
1893 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1895 case MESA_FORMAT_R_UINT16
:
1896 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1898 case MESA_FORMAT_RG_UINT16
:
1899 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1900 case MESA_FORMAT_RGB_UINT16
:
1901 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1903 case MESA_FORMAT_RGBA_UINT16
:
1904 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1906 case MESA_FORMAT_R_UINT32
:
1907 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1908 case MESA_FORMAT_RG_UINT32
:
1909 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1910 case MESA_FORMAT_RGB_UINT32
:
1911 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1912 case MESA_FORMAT_RGBA_UINT32
:
1913 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1915 case MESA_FORMAT_R_SNORM8
:
1916 return format
== GL_RED
&& type
== GL_BYTE
;
1917 case MESA_FORMAT_R8G8_SNORM
:
1918 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1920 case MESA_FORMAT_X8B8G8R8_SNORM
:
1923 case MESA_FORMAT_A8B8G8R8_SNORM
:
1924 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1927 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1932 case MESA_FORMAT_R8G8B8A8_SNORM
:
1933 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1936 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1941 case MESA_FORMAT_R_SNORM16
:
1942 return format
== GL_RED
&& type
== GL_SHORT
&&
1944 case MESA_FORMAT_R16G16_SNORM
:
1945 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1946 case MESA_FORMAT_RGB_SNORM16
:
1947 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1948 case MESA_FORMAT_RGBA_SNORM16
:
1949 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1950 case MESA_FORMAT_RGBA_UNORM16
:
1951 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1954 case MESA_FORMAT_A_SNORM8
:
1955 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1956 case MESA_FORMAT_L_SNORM8
:
1957 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1958 case MESA_FORMAT_L8A8_SNORM
:
1959 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1960 littleEndian
&& !swapBytes
;
1961 case MESA_FORMAT_A8L8_SNORM
:
1962 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1963 !littleEndian
&& !swapBytes
;
1964 case MESA_FORMAT_I_SNORM8
:
1965 return format
== GL_RED
&& type
== GL_BYTE
;
1966 case MESA_FORMAT_A_SNORM16
:
1967 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1968 case MESA_FORMAT_L_SNORM16
:
1969 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1970 case MESA_FORMAT_LA_SNORM16
:
1971 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1972 littleEndian
&& !swapBytes
;
1973 case MESA_FORMAT_I_SNORM16
:
1974 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1977 case MESA_FORMAT_B10G10R10A2_UINT
:
1978 return (format
== GL_BGRA_INTEGER_EXT
&&
1979 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1982 case MESA_FORMAT_R10G10B10A2_UINT
:
1983 return (format
== GL_RGBA_INTEGER_EXT
&&
1984 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1987 case MESA_FORMAT_B5G6R5_UINT
:
1988 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1990 case MESA_FORMAT_R5G6B5_UINT
:
1991 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1993 case MESA_FORMAT_B2G3R3_UINT
:
1994 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1996 case MESA_FORMAT_R3G3B2_UINT
:
1997 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1999 case MESA_FORMAT_A4B4G4R4_UINT
:
2000 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
2003 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
2007 case MESA_FORMAT_R4G4B4A4_UINT
:
2008 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
2011 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
2016 case MESA_FORMAT_B4G4R4A4_UINT
:
2017 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
2020 case MESA_FORMAT_A4R4G4B4_UINT
:
2023 case MESA_FORMAT_A1B5G5R5_UINT
:
2024 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2027 case MESA_FORMAT_B5G5R5A1_UINT
:
2028 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
2031 case MESA_FORMAT_A1R5G5B5_UINT
:
2032 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2035 case MESA_FORMAT_R5G5B5A1_UINT
:
2036 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
2038 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2039 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2042 case MESA_FORMAT_R11G11B10_FLOAT
:
2043 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2046 case MESA_FORMAT_Z_FLOAT32
:
2047 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2049 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2050 return format
== GL_DEPTH_STENCIL
&&
2051 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2053 case MESA_FORMAT_B4G4R4X4_UNORM
:
2054 case MESA_FORMAT_B5G5R5X1_UNORM
:
2055 case MESA_FORMAT_R8G8B8X8_SNORM
:
2056 case MESA_FORMAT_R8G8B8X8_SRGB
:
2057 case MESA_FORMAT_X8B8G8R8_SRGB
:
2058 case MESA_FORMAT_RGBX_UINT8
:
2059 case MESA_FORMAT_RGBX_SINT8
:
2060 case MESA_FORMAT_B10G10R10X2_UNORM
:
2061 case MESA_FORMAT_R10G10B10X2_UNORM
:
2062 case MESA_FORMAT_RGBX_UNORM16
:
2063 case MESA_FORMAT_RGBX_SNORM16
:
2064 case MESA_FORMAT_RGBX_FLOAT16
:
2065 case MESA_FORMAT_RGBX_UINT16
:
2066 case MESA_FORMAT_RGBX_SINT16
:
2067 case MESA_FORMAT_RGBX_FLOAT32
:
2068 case MESA_FORMAT_RGBX_UINT32
:
2069 case MESA_FORMAT_RGBX_SINT32
:
2072 case MESA_FORMAT_R10G10B10A2_UNORM
:
2073 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2076 case MESA_FORMAT_G8R8_SNORM
:
2077 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2080 case MESA_FORMAT_G16R16_SNORM
:
2081 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2084 case MESA_FORMAT_B8G8R8X8_SRGB
:
2085 case MESA_FORMAT_X8R8G8B8_SRGB
:
2088 assert(_mesa_is_format_compressed(mesa_format
));
2090 *error
= GL_INVALID_ENUM
;