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=Depth=1.
73 GLubyte BlockWidth
, BlockHeight
, BlockDepth
;
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 case GL_INTERNALFORMAT_RED_SIZE
:
136 return info
->RedBits
;
138 case GL_TEXTURE_GREEN_SIZE
:
139 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
140 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
141 case GL_INTERNALFORMAT_GREEN_SIZE
:
142 return info
->GreenBits
;
144 case GL_TEXTURE_BLUE_SIZE
:
145 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
146 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
147 case GL_INTERNALFORMAT_BLUE_SIZE
:
148 return info
->BlueBits
;
150 case GL_TEXTURE_ALPHA_SIZE
:
151 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
152 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
153 case GL_INTERNALFORMAT_ALPHA_SIZE
:
154 return info
->AlphaBits
;
155 case GL_TEXTURE_INTENSITY_SIZE
:
156 return info
->IntensityBits
;
157 case GL_TEXTURE_LUMINANCE_SIZE
:
158 return info
->LuminanceBits
;
162 case GL_TEXTURE_DEPTH_SIZE_ARB
:
163 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
164 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
165 case GL_INTERNALFORMAT_DEPTH_SIZE
:
166 return info
->DepthBits
;
167 case GL_STENCIL_BITS
:
168 case GL_TEXTURE_STENCIL_SIZE_EXT
:
169 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
170 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
171 case GL_INTERNALFORMAT_STENCIL_SIZE
:
172 return info
->StencilBits
;
174 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
181 _mesa_get_format_max_bits(mesa_format format
)
183 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
184 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
185 max
= MAX2(max
, info
->BlueBits
);
186 max
= MAX2(max
, info
->AlphaBits
);
187 max
= MAX2(max
, info
->LuminanceBits
);
188 max
= MAX2(max
, info
->IntensityBits
);
189 max
= MAX2(max
, info
->DepthBits
);
190 max
= MAX2(max
, info
->StencilBits
);
196 * Return the layout type of the given format.
198 extern enum mesa_format_layout
199 _mesa_get_format_layout(mesa_format format
)
201 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
207 * Return the data type (or more specifically, the data representation)
208 * for the given format.
209 * The return value will be one of:
210 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
211 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
212 * GL_UNSIGNED_INT = an ordinary unsigned integer
213 * GL_INT = an ordinary signed integer
214 * GL_FLOAT = an ordinary float
217 _mesa_get_format_datatype(mesa_format format
)
219 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
220 return info
->DataType
;
224 get_base_format_for_array_format(mesa_array_format format
)
229 _mesa_array_format_get_swizzle(format
, swizzle
);
230 num_channels
= _mesa_array_format_get_num_channels(format
);
232 switch (num_channels
) {
234 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
235 * This is not really a problem for now because we only create array
236 * formats from GL format/type combinations, and these cannot specify
243 if (swizzle
[0] == 0 &&
247 return GL_LUMINANCE_ALPHA
;
248 if (swizzle
[0] == 1 &&
252 return GL_LUMINANCE_ALPHA
;
253 if (swizzle
[0] == 0 &&
258 if (swizzle
[0] == 1 &&
265 if (swizzle
[0] == 0 &&
270 if (swizzle
[0] == 0 &&
275 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
277 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
279 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
281 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
286 unreachable("Unsupported format");
290 * Return the basic format for the given type. The result will be one of
291 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
292 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
293 * This functions accepts a mesa_format or a mesa_array_format.
296 _mesa_get_format_base_format(uint32_t format
)
298 if (!_mesa_format_is_mesa_array_format(format
)) {
299 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
300 return info
->BaseFormat
;
302 return get_base_format_for_array_format(format
);
308 * Return the block size (in pixels) for the given format. Normally
309 * the block size is 1x1. But compressed formats will have block sizes
310 * of 4x4 or 8x4 pixels, etc.
311 * \param bw returns block width in pixels
312 * \param bh returns block height in pixels
315 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
317 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
318 /* Use _mesa_get_format_block_size_3d() for 3D blocks. */
319 assert(info
->BlockDepth
== 1);
321 *bw
= info
->BlockWidth
;
322 *bh
= info
->BlockHeight
;
327 * Return the block size (in pixels) for the given format. Normally
328 * the block size is 1x1x1. But compressed formats will have block
329 * sizes of 4x4x4, 3x3x3 pixels, etc.
330 * \param bw returns block width in pixels
331 * \param bh returns block height in pixels
332 * \param bd returns block depth in pixels
335 _mesa_get_format_block_size_3d(mesa_format format
,
340 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
341 *bw
= info
->BlockWidth
;
342 *bh
= info
->BlockHeight
;
343 *bd
= info
->BlockDepth
;
348 * Returns the an array of four numbers representing the transformation
349 * from the RGBA or SZ colorspace to the given format. For array formats,
350 * the i'th RGBA component is given by:
352 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
353 * comp = data[swizzle[i]];
354 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
356 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
358 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
359 * // data does not contain a channel of this format
361 * For packed formats, the swizzle gives the number of components left of
362 * the least significant bit.
364 * Compressed formats have no swizzle.
367 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
369 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
370 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
374 _mesa_array_format_flip_channels(mesa_array_format format
)
379 num_channels
= _mesa_array_format_get_num_channels(format
);
380 _mesa_array_format_get_swizzle(format
, swizzle
);
382 if (num_channels
== 1)
385 if (num_channels
== 2) {
386 /* Assert that the swizzle makes sense for 2 channels */
387 for (unsigned i
= 0; i
< 4; i
++)
388 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
390 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
391 _mesa_array_format_set_swizzle(&format
,
392 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
393 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
397 if (num_channels
== 4) {
398 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
399 _mesa_array_format_set_swizzle(&format
,
400 flip
[swizzle
[0]], flip
[swizzle
[1]],
401 flip
[swizzle
[2]], flip
[swizzle
[3]]);
405 unreachable("Invalid array format");
409 _mesa_format_to_array_format(mesa_format format
)
411 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
412 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
413 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
414 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
416 return info
->ArrayFormat
;
419 static struct hash_table
*format_array_format_table
;
420 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
423 array_formats_equal(const void *a
, const void *b
)
425 return (intptr_t)a
== (intptr_t)b
;
429 format_array_format_table_init(void)
431 const struct gl_format_info
*info
;
432 mesa_array_format array_format
;
435 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
436 array_formats_equal
);
438 if (!format_array_format_table
) {
439 _mesa_error_no_memory(__func__
);
443 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
444 info
= _mesa_get_format_info(f
);
445 if (!info
->ArrayFormat
)
448 if (_mesa_little_endian()) {
449 array_format
= info
->ArrayFormat
;
451 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
454 /* This can happen and does for some of the BGR formats. Let's take
455 * the first one in the list.
457 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
459 (void *)(intptr_t)array_format
))
462 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
464 (void *)(intptr_t)array_format
,
465 (void *)(intptr_t)f
);
470 _mesa_format_from_array_format(uint32_t array_format
)
472 struct hash_entry
*entry
;
474 assert(_mesa_format_is_mesa_array_format(array_format
));
476 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
478 if (!format_array_format_table
) {
479 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
480 format_array_format_table_exists
= once_flag_init
;
481 return MESA_FORMAT_NONE
;
484 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
486 (void *)(intptr_t)array_format
);
488 return (intptr_t)entry
->data
;
490 return MESA_FORMAT_NONE
;
493 /** Is the given format a compressed format? */
495 _mesa_is_format_compressed(mesa_format format
)
497 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
498 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
503 * Determine if the given format represents a packed depth/stencil buffer.
506 _mesa_is_format_packed_depth_stencil(mesa_format format
)
508 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
510 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
515 * Is the given format a signed/unsigned integer color format?
518 _mesa_is_format_integer_color(mesa_format format
)
520 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
521 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
522 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
523 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
524 info
->BaseFormat
!= GL_STENCIL_INDEX
;
529 * Is the given format an unsigned integer format?
532 _mesa_is_format_unsigned(mesa_format format
)
534 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
535 return _mesa_is_type_unsigned(info
->DataType
);
540 * Does the given format store signed values?
543 _mesa_is_format_signed(mesa_format format
)
545 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
546 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
547 /* these packed float formats only store unsigned values */
551 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
552 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
553 info
->DataType
== GL_INT
||
554 info
->DataType
== GL_FLOAT
);
559 * Is the given format an integer format?
562 _mesa_is_format_integer(mesa_format format
)
564 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
565 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
570 * Return true if the given format is a color format.
573 _mesa_is_format_color_format(mesa_format format
)
575 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
576 switch (info
->BaseFormat
) {
577 case GL_DEPTH_COMPONENT
:
578 case GL_STENCIL_INDEX
:
579 case GL_DEPTH_STENCIL
:
588 * Return color encoding for given format.
589 * \return GL_LINEAR or GL_SRGB
592 _mesa_get_format_color_encoding(mesa_format format
)
594 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
595 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
600 * Return TRUE if format is an ETC2 compressed format specified
601 * by GL_ARB_ES3_compatibility.
604 _mesa_is_format_etc2(mesa_format format
)
607 case MESA_FORMAT_ETC2_RGB8
:
608 case MESA_FORMAT_ETC2_SRGB8
:
609 case MESA_FORMAT_ETC2_RGBA8_EAC
:
610 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
611 case MESA_FORMAT_ETC2_R11_EAC
:
612 case MESA_FORMAT_ETC2_RG11_EAC
:
613 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
614 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
615 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
616 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
625 * For an sRGB format, return the corresponding linear color space format.
626 * For non-sRGB formats, return the format as-is.
629 _mesa_get_srgb_format_linear(mesa_format format
)
632 case MESA_FORMAT_BGR_SRGB8
:
633 format
= MESA_FORMAT_BGR_UNORM8
;
635 case MESA_FORMAT_A8B8G8R8_SRGB
:
636 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
638 case MESA_FORMAT_B8G8R8A8_SRGB
:
639 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
641 case MESA_FORMAT_A8R8G8B8_SRGB
:
642 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
644 case MESA_FORMAT_R8G8B8A8_SRGB
:
645 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
647 case MESA_FORMAT_L_SRGB8
:
648 format
= MESA_FORMAT_L_UNORM8
;
650 case MESA_FORMAT_L8A8_SRGB
:
651 format
= MESA_FORMAT_L8A8_UNORM
;
653 case MESA_FORMAT_A8L8_SRGB
:
654 format
= MESA_FORMAT_A8L8_UNORM
;
656 case MESA_FORMAT_SRGB_DXT1
:
657 format
= MESA_FORMAT_RGB_DXT1
;
659 case MESA_FORMAT_SRGBA_DXT1
:
660 format
= MESA_FORMAT_RGBA_DXT1
;
662 case MESA_FORMAT_SRGBA_DXT3
:
663 format
= MESA_FORMAT_RGBA_DXT3
;
665 case MESA_FORMAT_SRGBA_DXT5
:
666 format
= MESA_FORMAT_RGBA_DXT5
;
668 case MESA_FORMAT_R8G8B8X8_SRGB
:
669 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
671 case MESA_FORMAT_X8B8G8R8_SRGB
:
672 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
674 case MESA_FORMAT_ETC2_SRGB8
:
675 format
= MESA_FORMAT_ETC2_RGB8
;
677 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
678 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
680 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
681 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
683 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
684 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
686 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
687 format
= MESA_FORMAT_RGBA_ASTC_4x4
;
689 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
690 format
= MESA_FORMAT_RGBA_ASTC_5x4
;
692 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
693 format
= MESA_FORMAT_RGBA_ASTC_5x5
;
695 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
696 format
= MESA_FORMAT_RGBA_ASTC_6x5
;
698 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
699 format
= MESA_FORMAT_RGBA_ASTC_6x6
;
701 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
702 format
= MESA_FORMAT_RGBA_ASTC_8x5
;
704 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
705 format
= MESA_FORMAT_RGBA_ASTC_8x6
;
707 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
708 format
= MESA_FORMAT_RGBA_ASTC_8x8
;
710 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
711 format
= MESA_FORMAT_RGBA_ASTC_10x5
;
713 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
714 format
= MESA_FORMAT_RGBA_ASTC_10x6
;
716 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
717 format
= MESA_FORMAT_RGBA_ASTC_10x8
;
719 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
720 format
= MESA_FORMAT_RGBA_ASTC_10x10
;
722 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
723 format
= MESA_FORMAT_RGBA_ASTC_12x10
;
725 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
726 format
= MESA_FORMAT_RGBA_ASTC_12x12
;
728 case MESA_FORMAT_B8G8R8X8_SRGB
:
729 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
731 case MESA_FORMAT_X8R8G8B8_SRGB
:
732 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
742 * If the given format is a compressed format, return a corresponding
743 * uncompressed format.
746 _mesa_get_uncompressed_format(mesa_format format
)
749 case MESA_FORMAT_RGB_FXT1
:
750 return MESA_FORMAT_BGR_UNORM8
;
751 case MESA_FORMAT_RGBA_FXT1
:
752 return MESA_FORMAT_A8B8G8R8_UNORM
;
753 case MESA_FORMAT_RGB_DXT1
:
754 case MESA_FORMAT_SRGB_DXT1
:
755 return MESA_FORMAT_BGR_UNORM8
;
756 case MESA_FORMAT_RGBA_DXT1
:
757 case MESA_FORMAT_SRGBA_DXT1
:
758 return MESA_FORMAT_A8B8G8R8_UNORM
;
759 case MESA_FORMAT_RGBA_DXT3
:
760 case MESA_FORMAT_SRGBA_DXT3
:
761 return MESA_FORMAT_A8B8G8R8_UNORM
;
762 case MESA_FORMAT_RGBA_DXT5
:
763 case MESA_FORMAT_SRGBA_DXT5
:
764 return MESA_FORMAT_A8B8G8R8_UNORM
;
765 case MESA_FORMAT_R_RGTC1_UNORM
:
766 return MESA_FORMAT_R_UNORM8
;
767 case MESA_FORMAT_R_RGTC1_SNORM
:
768 return MESA_FORMAT_R_SNORM8
;
769 case MESA_FORMAT_RG_RGTC2_UNORM
:
770 return MESA_FORMAT_R8G8_UNORM
;
771 case MESA_FORMAT_RG_RGTC2_SNORM
:
772 return MESA_FORMAT_R8G8_SNORM
;
773 case MESA_FORMAT_L_LATC1_UNORM
:
774 return MESA_FORMAT_L_UNORM8
;
775 case MESA_FORMAT_L_LATC1_SNORM
:
776 return MESA_FORMAT_L_SNORM8
;
777 case MESA_FORMAT_LA_LATC2_UNORM
:
778 return MESA_FORMAT_L8A8_UNORM
;
779 case MESA_FORMAT_LA_LATC2_SNORM
:
780 return MESA_FORMAT_L8A8_SNORM
;
781 case MESA_FORMAT_ETC1_RGB8
:
782 case MESA_FORMAT_ETC2_RGB8
:
783 case MESA_FORMAT_ETC2_SRGB8
:
784 return MESA_FORMAT_BGR_UNORM8
;
785 case MESA_FORMAT_ETC2_RGBA8_EAC
:
786 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
787 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
788 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
789 return MESA_FORMAT_A8B8G8R8_UNORM
;
790 case MESA_FORMAT_ETC2_R11_EAC
:
791 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
792 return MESA_FORMAT_R_UNORM16
;
793 case MESA_FORMAT_ETC2_RG11_EAC
:
794 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
795 return MESA_FORMAT_R16G16_UNORM
;
796 case MESA_FORMAT_BPTC_RGBA_UNORM
:
797 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
798 return MESA_FORMAT_A8B8G8R8_UNORM
;
799 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
800 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
801 return MESA_FORMAT_RGB_FLOAT32
;
804 assert(!_mesa_is_format_compressed(format
));
812 _mesa_format_num_components(mesa_format format
)
814 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
815 return ((info
->RedBits
> 0) +
816 (info
->GreenBits
> 0) +
817 (info
->BlueBits
> 0) +
818 (info
->AlphaBits
> 0) +
819 (info
->LuminanceBits
> 0) +
820 (info
->IntensityBits
> 0) +
821 (info
->DepthBits
> 0) +
822 (info
->StencilBits
> 0));
827 * Returns true if a color format has data stored in the R/G/B/A channels,
828 * given an index from 0 to 3.
831 _mesa_format_has_color_component(mesa_format format
, int component
)
833 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
835 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
836 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
837 info
->BaseFormat
!= GL_STENCIL_INDEX
);
841 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
843 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
845 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
847 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
849 assert(!"Invalid color component: must be 0..3");
856 * Return number of bytes needed to store an image of the given size
857 * in the given format.
860 _mesa_format_image_size(mesa_format format
, GLsizei width
,
861 GLsizei height
, GLsizei depth
)
863 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
865 /* Strictly speaking, a conditional isn't needed here */
866 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
867 /* compressed format (2D only for now) */
868 const GLuint bw
= info
->BlockWidth
;
869 const GLuint bh
= info
->BlockHeight
;
870 const GLuint bd
= info
->BlockDepth
;
871 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
872 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
873 const GLuint dblocks
= (depth
+ bd
- 1) / bd
;
874 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
877 sz
= width
* height
* depth
* info
->BytesPerBlock
;
884 * Same as _mesa_format_image_size() but returns a 64-bit value to
885 * accommodate very large textures.
888 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
889 GLsizei height
, GLsizei depth
)
891 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
893 /* Strictly speaking, a conditional isn't needed here */
894 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
895 /* compressed format (2D only for now) */
896 const uint64_t bw
= info
->BlockWidth
;
897 const uint64_t bh
= info
->BlockHeight
;
898 const uint64_t bd
= info
->BlockDepth
;
899 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
900 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
901 const uint64_t dblocks
= (depth
+ bd
- 1) / bd
;
902 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
905 sz
= ((uint64_t) width
* (uint64_t) height
*
906 (uint64_t) depth
* info
->BytesPerBlock
);
914 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
916 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
917 /* Strictly speaking, a conditional isn't needed here */
918 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
919 /* compressed format */
920 const GLuint bw
= info
->BlockWidth
;
921 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
922 const GLint stride
= wblocks
* info
->BytesPerBlock
;
926 const GLint stride
= width
* info
->BytesPerBlock
;
934 * Return datatype and number of components per texel for the given
935 * uncompressed mesa_format. Only used for mipmap generation code.
938 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
939 GLenum
*datatype
, GLuint
*comps
)
942 case MESA_FORMAT_A8B8G8R8_UNORM
:
943 case MESA_FORMAT_R8G8B8A8_UNORM
:
944 case MESA_FORMAT_B8G8R8A8_UNORM
:
945 case MESA_FORMAT_A8R8G8B8_UNORM
:
946 case MESA_FORMAT_X8B8G8R8_UNORM
:
947 case MESA_FORMAT_R8G8B8X8_UNORM
:
948 case MESA_FORMAT_B8G8R8X8_UNORM
:
949 case MESA_FORMAT_X8R8G8B8_UNORM
:
950 case MESA_FORMAT_A8B8G8R8_UINT
:
951 case MESA_FORMAT_R8G8B8A8_UINT
:
952 case MESA_FORMAT_B8G8R8A8_UINT
:
953 case MESA_FORMAT_A8R8G8B8_UINT
:
954 *datatype
= GL_UNSIGNED_BYTE
;
957 case MESA_FORMAT_BGR_UNORM8
:
958 case MESA_FORMAT_RGB_UNORM8
:
959 *datatype
= GL_UNSIGNED_BYTE
;
962 case MESA_FORMAT_B5G6R5_UNORM
:
963 case MESA_FORMAT_R5G6B5_UNORM
:
964 case MESA_FORMAT_B5G6R5_UINT
:
965 case MESA_FORMAT_R5G6B5_UINT
:
966 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
970 case MESA_FORMAT_B4G4R4A4_UNORM
:
971 case MESA_FORMAT_A4R4G4B4_UNORM
:
972 case MESA_FORMAT_B4G4R4X4_UNORM
:
973 case MESA_FORMAT_B4G4R4A4_UINT
:
974 case MESA_FORMAT_A4R4G4B4_UINT
:
975 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
979 case MESA_FORMAT_B5G5R5A1_UNORM
:
980 case MESA_FORMAT_A1R5G5B5_UNORM
:
981 case MESA_FORMAT_B5G5R5X1_UNORM
:
982 case MESA_FORMAT_B5G5R5A1_UINT
:
983 case MESA_FORMAT_A1R5G5B5_UINT
:
984 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
988 case MESA_FORMAT_B10G10R10A2_UNORM
:
989 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
993 case MESA_FORMAT_A1B5G5R5_UNORM
:
994 case MESA_FORMAT_A1B5G5R5_UINT
:
995 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
999 case MESA_FORMAT_L4A4_UNORM
:
1000 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1004 case MESA_FORMAT_L8A8_UNORM
:
1005 case MESA_FORMAT_A8L8_UNORM
:
1006 case MESA_FORMAT_R8G8_UNORM
:
1007 case MESA_FORMAT_G8R8_UNORM
:
1008 *datatype
= GL_UNSIGNED_BYTE
;
1012 case MESA_FORMAT_L16A16_UNORM
:
1013 case MESA_FORMAT_A16L16_UNORM
:
1014 case MESA_FORMAT_R16G16_UNORM
:
1015 case MESA_FORMAT_G16R16_UNORM
:
1016 *datatype
= GL_UNSIGNED_SHORT
;
1020 case MESA_FORMAT_R_UNORM16
:
1021 case MESA_FORMAT_A_UNORM16
:
1022 case MESA_FORMAT_L_UNORM16
:
1023 case MESA_FORMAT_I_UNORM16
:
1024 *datatype
= GL_UNSIGNED_SHORT
;
1028 case MESA_FORMAT_R3G3B2_UNORM
:
1029 case MESA_FORMAT_R3G3B2_UINT
:
1030 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1033 case MESA_FORMAT_A4B4G4R4_UNORM
:
1034 case MESA_FORMAT_A4B4G4R4_UINT
:
1035 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1039 case MESA_FORMAT_R4G4B4A4_UNORM
:
1040 case MESA_FORMAT_R4G4B4A4_UINT
:
1041 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1044 case MESA_FORMAT_R5G5B5A1_UNORM
:
1045 case MESA_FORMAT_R5G5B5A1_UINT
:
1046 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1049 case MESA_FORMAT_A2B10G10R10_UNORM
:
1050 case MESA_FORMAT_A2B10G10R10_UINT
:
1051 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1054 case MESA_FORMAT_A2R10G10B10_UNORM
:
1055 case MESA_FORMAT_A2R10G10B10_UINT
:
1056 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1060 case MESA_FORMAT_B2G3R3_UNORM
:
1061 case MESA_FORMAT_B2G3R3_UINT
:
1062 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1066 case MESA_FORMAT_A_UNORM8
:
1067 case MESA_FORMAT_L_UNORM8
:
1068 case MESA_FORMAT_I_UNORM8
:
1069 case MESA_FORMAT_R_UNORM8
:
1070 case MESA_FORMAT_S_UINT8
:
1071 *datatype
= GL_UNSIGNED_BYTE
;
1075 case MESA_FORMAT_YCBCR
:
1076 case MESA_FORMAT_YCBCR_REV
:
1077 *datatype
= GL_UNSIGNED_SHORT
;
1081 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1082 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1086 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1087 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1091 case MESA_FORMAT_Z_UNORM16
:
1092 *datatype
= GL_UNSIGNED_SHORT
;
1096 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1097 *datatype
= GL_UNSIGNED_INT
;
1101 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1102 *datatype
= GL_UNSIGNED_INT
;
1106 case MESA_FORMAT_Z_UNORM32
:
1107 *datatype
= GL_UNSIGNED_INT
;
1111 case MESA_FORMAT_Z_FLOAT32
:
1112 *datatype
= GL_FLOAT
;
1116 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1117 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1121 case MESA_FORMAT_R_SNORM8
:
1122 case MESA_FORMAT_A_SNORM8
:
1123 case MESA_FORMAT_L_SNORM8
:
1124 case MESA_FORMAT_I_SNORM8
:
1125 *datatype
= GL_BYTE
;
1128 case MESA_FORMAT_R8G8_SNORM
:
1129 case MESA_FORMAT_L8A8_SNORM
:
1130 case MESA_FORMAT_A8L8_SNORM
:
1131 *datatype
= GL_BYTE
;
1134 case MESA_FORMAT_A8B8G8R8_SNORM
:
1135 case MESA_FORMAT_R8G8B8A8_SNORM
:
1136 case MESA_FORMAT_X8B8G8R8_SNORM
:
1137 *datatype
= GL_BYTE
;
1141 case MESA_FORMAT_RGBA_UNORM16
:
1142 *datatype
= GL_UNSIGNED_SHORT
;
1146 case MESA_FORMAT_R_SNORM16
:
1147 case MESA_FORMAT_A_SNORM16
:
1148 case MESA_FORMAT_L_SNORM16
:
1149 case MESA_FORMAT_I_SNORM16
:
1150 *datatype
= GL_SHORT
;
1153 case MESA_FORMAT_R16G16_SNORM
:
1154 case MESA_FORMAT_LA_SNORM16
:
1155 *datatype
= GL_SHORT
;
1158 case MESA_FORMAT_RGB_SNORM16
:
1159 *datatype
= GL_SHORT
;
1162 case MESA_FORMAT_RGBA_SNORM16
:
1163 *datatype
= GL_SHORT
;
1167 case MESA_FORMAT_BGR_SRGB8
:
1168 *datatype
= GL_UNSIGNED_BYTE
;
1171 case MESA_FORMAT_A8B8G8R8_SRGB
:
1172 case MESA_FORMAT_B8G8R8A8_SRGB
:
1173 case MESA_FORMAT_A8R8G8B8_SRGB
:
1174 case MESA_FORMAT_R8G8B8A8_SRGB
:
1175 *datatype
= GL_UNSIGNED_BYTE
;
1178 case MESA_FORMAT_L_SRGB8
:
1179 *datatype
= GL_UNSIGNED_BYTE
;
1182 case MESA_FORMAT_L8A8_SRGB
:
1183 case MESA_FORMAT_A8L8_SRGB
:
1184 *datatype
= GL_UNSIGNED_BYTE
;
1188 case MESA_FORMAT_RGBA_FLOAT32
:
1189 *datatype
= GL_FLOAT
;
1192 case MESA_FORMAT_RGBA_FLOAT16
:
1193 *datatype
= GL_HALF_FLOAT_ARB
;
1196 case MESA_FORMAT_RGB_FLOAT32
:
1197 *datatype
= GL_FLOAT
;
1200 case MESA_FORMAT_RGB_FLOAT16
:
1201 *datatype
= GL_HALF_FLOAT_ARB
;
1204 case MESA_FORMAT_LA_FLOAT32
:
1205 case MESA_FORMAT_RG_FLOAT32
:
1206 *datatype
= GL_FLOAT
;
1209 case MESA_FORMAT_LA_FLOAT16
:
1210 case MESA_FORMAT_RG_FLOAT16
:
1211 *datatype
= GL_HALF_FLOAT_ARB
;
1214 case MESA_FORMAT_A_FLOAT32
:
1215 case MESA_FORMAT_L_FLOAT32
:
1216 case MESA_FORMAT_I_FLOAT32
:
1217 case MESA_FORMAT_R_FLOAT32
:
1218 *datatype
= GL_FLOAT
;
1221 case MESA_FORMAT_A_FLOAT16
:
1222 case MESA_FORMAT_L_FLOAT16
:
1223 case MESA_FORMAT_I_FLOAT16
:
1224 case MESA_FORMAT_R_FLOAT16
:
1225 *datatype
= GL_HALF_FLOAT_ARB
;
1229 case MESA_FORMAT_A_UINT8
:
1230 case MESA_FORMAT_L_UINT8
:
1231 case MESA_FORMAT_I_UINT8
:
1232 *datatype
= GL_UNSIGNED_BYTE
;
1235 case MESA_FORMAT_LA_UINT8
:
1236 *datatype
= GL_UNSIGNED_BYTE
;
1240 case MESA_FORMAT_A_UINT16
:
1241 case MESA_FORMAT_L_UINT16
:
1242 case MESA_FORMAT_I_UINT16
:
1243 *datatype
= GL_UNSIGNED_SHORT
;
1246 case MESA_FORMAT_LA_UINT16
:
1247 *datatype
= GL_UNSIGNED_SHORT
;
1250 case MESA_FORMAT_A_UINT32
:
1251 case MESA_FORMAT_L_UINT32
:
1252 case MESA_FORMAT_I_UINT32
:
1253 *datatype
= GL_UNSIGNED_INT
;
1256 case MESA_FORMAT_LA_UINT32
:
1257 *datatype
= GL_UNSIGNED_INT
;
1260 case MESA_FORMAT_A_SINT8
:
1261 case MESA_FORMAT_L_SINT8
:
1262 case MESA_FORMAT_I_SINT8
:
1263 *datatype
= GL_BYTE
;
1266 case MESA_FORMAT_LA_SINT8
:
1267 *datatype
= GL_BYTE
;
1271 case MESA_FORMAT_A_SINT16
:
1272 case MESA_FORMAT_L_SINT16
:
1273 case MESA_FORMAT_I_SINT16
:
1274 *datatype
= GL_SHORT
;
1277 case MESA_FORMAT_LA_SINT16
:
1278 *datatype
= GL_SHORT
;
1282 case MESA_FORMAT_A_SINT32
:
1283 case MESA_FORMAT_L_SINT32
:
1284 case MESA_FORMAT_I_SINT32
:
1288 case MESA_FORMAT_LA_SINT32
:
1293 case MESA_FORMAT_R_SINT8
:
1294 *datatype
= GL_BYTE
;
1297 case MESA_FORMAT_RG_SINT8
:
1298 *datatype
= GL_BYTE
;
1301 case MESA_FORMAT_RGB_SINT8
:
1302 *datatype
= GL_BYTE
;
1305 case MESA_FORMAT_RGBA_SINT8
:
1306 *datatype
= GL_BYTE
;
1309 case MESA_FORMAT_R_SINT16
:
1310 *datatype
= GL_SHORT
;
1313 case MESA_FORMAT_RG_SINT16
:
1314 *datatype
= GL_SHORT
;
1317 case MESA_FORMAT_RGB_SINT16
:
1318 *datatype
= GL_SHORT
;
1321 case MESA_FORMAT_RGBA_SINT16
:
1322 *datatype
= GL_SHORT
;
1325 case MESA_FORMAT_R_SINT32
:
1329 case MESA_FORMAT_RG_SINT32
:
1333 case MESA_FORMAT_RGB_SINT32
:
1337 case MESA_FORMAT_RGBA_SINT32
:
1343 * \name Non-normalized unsigned integer formats.
1345 case MESA_FORMAT_R_UINT8
:
1346 *datatype
= GL_UNSIGNED_BYTE
;
1349 case MESA_FORMAT_RG_UINT8
:
1350 *datatype
= GL_UNSIGNED_BYTE
;
1353 case MESA_FORMAT_RGB_UINT8
:
1354 *datatype
= GL_UNSIGNED_BYTE
;
1357 case MESA_FORMAT_RGBA_UINT8
:
1358 *datatype
= GL_UNSIGNED_BYTE
;
1361 case MESA_FORMAT_R_UINT16
:
1362 *datatype
= GL_UNSIGNED_SHORT
;
1365 case MESA_FORMAT_RG_UINT16
:
1366 *datatype
= GL_UNSIGNED_SHORT
;
1369 case MESA_FORMAT_RGB_UINT16
:
1370 *datatype
= GL_UNSIGNED_SHORT
;
1373 case MESA_FORMAT_RGBA_UINT16
:
1374 *datatype
= GL_UNSIGNED_SHORT
;
1377 case MESA_FORMAT_R_UINT32
:
1378 *datatype
= GL_UNSIGNED_INT
;
1381 case MESA_FORMAT_RG_UINT32
:
1382 *datatype
= GL_UNSIGNED_INT
;
1385 case MESA_FORMAT_RGB_UINT32
:
1386 *datatype
= GL_UNSIGNED_INT
;
1389 case MESA_FORMAT_RGBA_UINT32
:
1390 *datatype
= GL_UNSIGNED_INT
;
1394 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1395 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1399 case MESA_FORMAT_R11G11B10_FLOAT
:
1400 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1404 case MESA_FORMAT_B10G10R10A2_UINT
:
1405 case MESA_FORMAT_R10G10B10A2_UINT
:
1406 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1410 case MESA_FORMAT_R8G8B8X8_SRGB
:
1411 case MESA_FORMAT_X8B8G8R8_SRGB
:
1412 case MESA_FORMAT_RGBX_UINT8
:
1413 *datatype
= GL_UNSIGNED_BYTE
;
1417 case MESA_FORMAT_R8G8B8X8_SNORM
:
1418 case MESA_FORMAT_RGBX_SINT8
:
1419 *datatype
= GL_BYTE
;
1423 case MESA_FORMAT_B10G10R10X2_UNORM
:
1424 case MESA_FORMAT_R10G10B10X2_UNORM
:
1425 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1429 case MESA_FORMAT_RGBX_UNORM16
:
1430 case MESA_FORMAT_RGBX_UINT16
:
1431 *datatype
= GL_UNSIGNED_SHORT
;
1435 case MESA_FORMAT_RGBX_SNORM16
:
1436 case MESA_FORMAT_RGBX_SINT16
:
1437 *datatype
= GL_SHORT
;
1441 case MESA_FORMAT_RGBX_FLOAT16
:
1442 *datatype
= GL_HALF_FLOAT
;
1446 case MESA_FORMAT_RGBX_FLOAT32
:
1447 *datatype
= GL_FLOAT
;
1451 case MESA_FORMAT_RGBX_UINT32
:
1452 *datatype
= GL_UNSIGNED_INT
;
1456 case MESA_FORMAT_RGBX_SINT32
:
1461 case MESA_FORMAT_R10G10B10A2_UNORM
:
1462 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1466 case MESA_FORMAT_G8R8_SNORM
:
1467 *datatype
= GL_BYTE
;
1471 case MESA_FORMAT_G16R16_SNORM
:
1472 *datatype
= GL_SHORT
;
1476 case MESA_FORMAT_B8G8R8X8_SRGB
:
1477 case MESA_FORMAT_X8R8G8B8_SRGB
:
1478 *datatype
= GL_UNSIGNED_BYTE
;
1482 case MESA_FORMAT_COUNT
:
1486 /* Warn if any formats are not handled */
1487 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1488 _mesa_get_format_name(format
));
1489 assert(format
== MESA_FORMAT_NONE
||
1490 _mesa_is_format_compressed(format
));
1497 * Check if a mesa_format exactly matches a GL format/type combination
1498 * such that we can use memcpy() from one to the other.
1499 * \param mesa_format a MESA_FORMAT_x value
1500 * \param format the user-specified image format
1501 * \param type the user-specified image datatype
1502 * \param swapBytes typically the current pixel pack/unpack byteswap state
1503 * \param[out] error GL_NO_ERROR if format is an expected input.
1504 * GL_INVALID_ENUM if format is an unexpected input.
1505 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1508 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1509 GLenum format
, GLenum type
,
1510 GLboolean swapBytes
, GLenum
*error
)
1512 const GLboolean littleEndian
= _mesa_little_endian();
1514 *error
= GL_NO_ERROR
;
1516 /* Note: When reading a GL format/type combination, the format lists channel
1517 * assignments from most significant channel in the type to least
1518 * significant. A type with _REV indicates that the assignments are
1519 * swapped, so they are listed from least significant to most significant.
1521 * Compressed formats will fall through and return GL_FALSE.
1523 * For sanity, please keep this switch statement ordered the same as the
1524 * enums in formats.h.
1527 switch (mesa_format
) {
1529 case MESA_FORMAT_NONE
:
1530 case MESA_FORMAT_COUNT
:
1533 case MESA_FORMAT_A8B8G8R8_UNORM
:
1534 case MESA_FORMAT_A8B8G8R8_SRGB
:
1535 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1538 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& 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_REV
1548 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1552 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1557 case MESA_FORMAT_R8G8B8A8_UNORM
:
1558 case MESA_FORMAT_R8G8B8A8_SRGB
:
1559 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1563 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1566 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1569 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1573 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1577 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1582 case MESA_FORMAT_B8G8R8A8_UNORM
:
1583 case MESA_FORMAT_B8G8R8A8_SRGB
:
1584 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1588 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1591 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1596 case MESA_FORMAT_A8R8G8B8_UNORM
:
1597 case MESA_FORMAT_A8R8G8B8_SRGB
:
1598 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1601 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1605 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1610 case MESA_FORMAT_X8B8G8R8_UNORM
:
1611 case MESA_FORMAT_R8G8B8X8_UNORM
:
1614 case MESA_FORMAT_B8G8R8X8_UNORM
:
1615 case MESA_FORMAT_X8R8G8B8_UNORM
:
1618 case MESA_FORMAT_BGR_UNORM8
:
1619 case MESA_FORMAT_BGR_SRGB8
:
1620 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1622 case MESA_FORMAT_RGB_UNORM8
:
1623 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1625 case MESA_FORMAT_B5G6R5_UNORM
:
1626 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1627 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1630 case MESA_FORMAT_R5G6B5_UNORM
:
1631 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1632 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1635 case MESA_FORMAT_B4G4R4A4_UNORM
:
1636 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1639 case MESA_FORMAT_A4R4G4B4_UNORM
:
1642 case MESA_FORMAT_A1B5G5R5_UNORM
:
1643 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1646 case MESA_FORMAT_B5G5R5A1_UNORM
:
1647 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1650 case MESA_FORMAT_A1R5G5B5_UNORM
:
1651 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1654 case MESA_FORMAT_L4A4_UNORM
:
1656 case MESA_FORMAT_L8A8_UNORM
:
1657 case MESA_FORMAT_L8A8_SRGB
:
1658 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1659 case MESA_FORMAT_A8L8_UNORM
:
1660 case MESA_FORMAT_A8L8_SRGB
:
1663 case MESA_FORMAT_L16A16_UNORM
:
1664 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1665 case MESA_FORMAT_A16L16_UNORM
:
1668 case MESA_FORMAT_B2G3R3_UNORM
:
1669 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1671 case MESA_FORMAT_R3G3B2_UNORM
:
1672 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1674 case MESA_FORMAT_A4B4G4R4_UNORM
:
1675 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1678 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1681 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1684 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1689 case MESA_FORMAT_R4G4B4A4_UNORM
:
1690 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1693 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1696 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1699 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1704 case MESA_FORMAT_R5G5B5A1_UNORM
:
1705 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1707 case MESA_FORMAT_A2B10G10R10_UNORM
:
1708 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1710 case MESA_FORMAT_A2B10G10R10_UINT
:
1711 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1713 case MESA_FORMAT_A2R10G10B10_UNORM
:
1714 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1716 case MESA_FORMAT_A2R10G10B10_UINT
:
1717 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1719 case MESA_FORMAT_A_UNORM8
:
1720 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1721 case MESA_FORMAT_A_UNORM16
:
1722 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1723 case MESA_FORMAT_L_UNORM8
:
1724 case MESA_FORMAT_L_SRGB8
:
1725 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1726 case MESA_FORMAT_L_UNORM16
:
1727 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1728 case MESA_FORMAT_I_UNORM8
:
1729 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1730 case MESA_FORMAT_I_UNORM16
:
1731 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1733 case MESA_FORMAT_YCBCR
:
1734 return format
== GL_YCBCR_MESA
&&
1735 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1736 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1737 case MESA_FORMAT_YCBCR_REV
:
1738 return format
== GL_YCBCR_MESA
&&
1739 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1740 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1742 case MESA_FORMAT_R_UNORM8
:
1743 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1744 case MESA_FORMAT_R8G8_UNORM
:
1745 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1746 case MESA_FORMAT_G8R8_UNORM
:
1749 case MESA_FORMAT_R_UNORM16
:
1750 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1752 case MESA_FORMAT_R16G16_UNORM
:
1753 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1755 case MESA_FORMAT_G16R16_UNORM
:
1758 case MESA_FORMAT_B10G10R10A2_UNORM
:
1759 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1762 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1763 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1765 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1766 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1769 case MESA_FORMAT_Z_UNORM16
:
1770 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1773 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1776 case MESA_FORMAT_Z_UNORM32
:
1777 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1780 case MESA_FORMAT_S_UINT8
:
1781 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1783 case MESA_FORMAT_RGBA_FLOAT32
:
1784 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1785 case MESA_FORMAT_RGBA_FLOAT16
:
1786 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1788 case MESA_FORMAT_RGB_FLOAT32
:
1789 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1790 case MESA_FORMAT_RGB_FLOAT16
:
1791 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1793 case MESA_FORMAT_A_FLOAT32
:
1794 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1795 case MESA_FORMAT_A_FLOAT16
:
1796 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1798 case MESA_FORMAT_L_FLOAT32
:
1799 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1800 case MESA_FORMAT_L_FLOAT16
:
1801 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1803 case MESA_FORMAT_LA_FLOAT32
:
1804 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1805 case MESA_FORMAT_LA_FLOAT16
:
1806 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1808 case MESA_FORMAT_I_FLOAT32
:
1809 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1810 case MESA_FORMAT_I_FLOAT16
:
1811 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1813 case MESA_FORMAT_R_FLOAT32
:
1814 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1815 case MESA_FORMAT_R_FLOAT16
:
1816 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1818 case MESA_FORMAT_RG_FLOAT32
:
1819 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1820 case MESA_FORMAT_RG_FLOAT16
:
1821 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1823 case MESA_FORMAT_A_UINT8
:
1824 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1825 case MESA_FORMAT_A_UINT16
:
1826 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1828 case MESA_FORMAT_A_UINT32
:
1829 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1831 case MESA_FORMAT_A_SINT8
:
1832 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1833 case MESA_FORMAT_A_SINT16
:
1834 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1835 case MESA_FORMAT_A_SINT32
:
1836 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1838 case MESA_FORMAT_I_UINT8
:
1839 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1840 case MESA_FORMAT_I_UINT16
:
1841 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1842 case MESA_FORMAT_I_UINT32
:
1843 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1844 case MESA_FORMAT_I_SINT8
:
1845 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1846 case MESA_FORMAT_I_SINT16
:
1847 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1848 case MESA_FORMAT_I_SINT32
:
1849 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1851 case MESA_FORMAT_L_UINT8
:
1852 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1853 case MESA_FORMAT_L_UINT16
:
1854 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1856 case MESA_FORMAT_L_UINT32
:
1857 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1859 case MESA_FORMAT_L_SINT8
:
1860 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1861 case MESA_FORMAT_L_SINT16
:
1862 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1864 case MESA_FORMAT_L_SINT32
:
1865 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1867 case MESA_FORMAT_LA_UINT8
:
1868 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1869 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1870 case MESA_FORMAT_LA_UINT16
:
1871 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1872 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1873 case MESA_FORMAT_LA_UINT32
:
1874 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1875 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1876 case MESA_FORMAT_LA_SINT8
:
1877 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1879 case MESA_FORMAT_LA_SINT16
:
1880 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1882 case MESA_FORMAT_LA_SINT32
:
1883 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1886 case MESA_FORMAT_R_SINT8
:
1887 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1888 case MESA_FORMAT_RG_SINT8
:
1889 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1890 case MESA_FORMAT_RGB_SINT8
:
1891 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1892 case MESA_FORMAT_RGBA_SINT8
:
1893 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1894 case MESA_FORMAT_R_SINT16
:
1895 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1896 case MESA_FORMAT_RG_SINT16
:
1897 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1898 case MESA_FORMAT_RGB_SINT16
:
1899 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1900 case MESA_FORMAT_RGBA_SINT16
:
1901 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1902 case MESA_FORMAT_R_SINT32
:
1903 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1904 case MESA_FORMAT_RG_SINT32
:
1905 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1906 case MESA_FORMAT_RGB_SINT32
:
1907 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1908 case MESA_FORMAT_RGBA_SINT32
:
1909 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1911 case MESA_FORMAT_R_UINT8
:
1912 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1913 case MESA_FORMAT_RG_UINT8
:
1914 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1915 case MESA_FORMAT_RGB_UINT8
:
1916 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1917 case MESA_FORMAT_RGBA_UINT8
:
1918 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1920 case MESA_FORMAT_R_UINT16
:
1921 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1923 case MESA_FORMAT_RG_UINT16
:
1924 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1925 case MESA_FORMAT_RGB_UINT16
:
1926 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1928 case MESA_FORMAT_RGBA_UINT16
:
1929 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1931 case MESA_FORMAT_R_UINT32
:
1932 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1933 case MESA_FORMAT_RG_UINT32
:
1934 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1935 case MESA_FORMAT_RGB_UINT32
:
1936 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1937 case MESA_FORMAT_RGBA_UINT32
:
1938 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1940 case MESA_FORMAT_R_SNORM8
:
1941 return format
== GL_RED
&& type
== GL_BYTE
;
1942 case MESA_FORMAT_R8G8_SNORM
:
1943 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1945 case MESA_FORMAT_X8B8G8R8_SNORM
:
1948 case MESA_FORMAT_A8B8G8R8_SNORM
:
1949 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1952 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1957 case MESA_FORMAT_R8G8B8A8_SNORM
:
1958 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1961 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1966 case MESA_FORMAT_R_SNORM16
:
1967 return format
== GL_RED
&& type
== GL_SHORT
&&
1969 case MESA_FORMAT_R16G16_SNORM
:
1970 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1971 case MESA_FORMAT_RGB_SNORM16
:
1972 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1973 case MESA_FORMAT_RGBA_SNORM16
:
1974 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1975 case MESA_FORMAT_RGBA_UNORM16
:
1976 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1979 case MESA_FORMAT_A_SNORM8
:
1980 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1981 case MESA_FORMAT_L_SNORM8
:
1982 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1983 case MESA_FORMAT_L8A8_SNORM
:
1984 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1985 littleEndian
&& !swapBytes
;
1986 case MESA_FORMAT_A8L8_SNORM
:
1987 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1988 !littleEndian
&& !swapBytes
;
1989 case MESA_FORMAT_I_SNORM8
:
1990 return format
== GL_RED
&& type
== GL_BYTE
;
1991 case MESA_FORMAT_A_SNORM16
:
1992 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1993 case MESA_FORMAT_L_SNORM16
:
1994 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1995 case MESA_FORMAT_LA_SNORM16
:
1996 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1997 littleEndian
&& !swapBytes
;
1998 case MESA_FORMAT_I_SNORM16
:
1999 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2002 case MESA_FORMAT_B10G10R10A2_UINT
:
2003 return (format
== GL_BGRA_INTEGER_EXT
&&
2004 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2007 case MESA_FORMAT_R10G10B10A2_UINT
:
2008 return (format
== GL_RGBA_INTEGER_EXT
&&
2009 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2012 case MESA_FORMAT_B5G6R5_UINT
:
2013 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
2015 case MESA_FORMAT_R5G6B5_UINT
:
2016 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
2018 case MESA_FORMAT_B2G3R3_UINT
:
2019 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
2021 case MESA_FORMAT_R3G3B2_UINT
:
2022 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
2024 case MESA_FORMAT_A4B4G4R4_UINT
:
2025 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
2028 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
2032 case MESA_FORMAT_R4G4B4A4_UINT
:
2033 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
2036 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
2041 case MESA_FORMAT_B4G4R4A4_UINT
:
2042 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
2045 case MESA_FORMAT_A4R4G4B4_UINT
:
2048 case MESA_FORMAT_A1B5G5R5_UINT
:
2049 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2052 case MESA_FORMAT_B5G5R5A1_UINT
:
2053 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
2056 case MESA_FORMAT_A1R5G5B5_UINT
:
2057 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2060 case MESA_FORMAT_R5G5B5A1_UINT
:
2061 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
2063 case MESA_FORMAT_A8B8G8R8_UINT
:
2064 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
2067 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
2071 case MESA_FORMAT_A8R8G8B8_UINT
:
2072 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
2076 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2082 case MESA_FORMAT_R8G8B8A8_UINT
:
2083 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2087 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2092 case MESA_FORMAT_B8G8R8A8_UINT
:
2093 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2097 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2102 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2103 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2106 case MESA_FORMAT_R11G11B10_FLOAT
:
2107 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2110 case MESA_FORMAT_Z_FLOAT32
:
2111 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2113 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2114 return format
== GL_DEPTH_STENCIL
&&
2115 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2117 case MESA_FORMAT_B4G4R4X4_UNORM
:
2118 case MESA_FORMAT_B5G5R5X1_UNORM
:
2119 case MESA_FORMAT_R8G8B8X8_SNORM
:
2120 case MESA_FORMAT_R8G8B8X8_SRGB
:
2121 case MESA_FORMAT_X8B8G8R8_SRGB
:
2122 case MESA_FORMAT_RGBX_UINT8
:
2123 case MESA_FORMAT_RGBX_SINT8
:
2124 case MESA_FORMAT_B10G10R10X2_UNORM
:
2125 case MESA_FORMAT_R10G10B10X2_UNORM
:
2126 case MESA_FORMAT_RGBX_UNORM16
:
2127 case MESA_FORMAT_RGBX_SNORM16
:
2128 case MESA_FORMAT_RGBX_FLOAT16
:
2129 case MESA_FORMAT_RGBX_UINT16
:
2130 case MESA_FORMAT_RGBX_SINT16
:
2131 case MESA_FORMAT_RGBX_FLOAT32
:
2132 case MESA_FORMAT_RGBX_UINT32
:
2133 case MESA_FORMAT_RGBX_SINT32
:
2136 case MESA_FORMAT_R10G10B10A2_UNORM
:
2137 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2140 case MESA_FORMAT_G8R8_SNORM
:
2141 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2144 case MESA_FORMAT_G16R16_SNORM
:
2145 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2148 case MESA_FORMAT_B8G8R8X8_SRGB
:
2149 case MESA_FORMAT_X8R8G8B8_SRGB
:
2152 assert(_mesa_is_format_compressed(mesa_format
));
2154 *error
= GL_INVALID_ENUM
;