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
);
864 /* Strictly speaking, a conditional isn't needed here */
865 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
866 /* compressed format (2D only for now) */
867 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
868 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
869 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
870 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
875 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
882 * Same as _mesa_format_image_size() but returns a 64-bit value to
883 * accommodate very large textures.
886 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
887 GLsizei height
, GLsizei depth
)
889 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
890 /* Strictly speaking, a conditional isn't needed here */
891 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
892 /* compressed format (2D only for now) */
893 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
894 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
895 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
896 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
901 const uint64_t sz
= ((uint64_t) width
*
904 info
->BytesPerBlock
);
912 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
914 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
915 /* Strictly speaking, a conditional isn't needed here */
916 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
917 /* compressed format */
918 const GLuint bw
= info
->BlockWidth
;
919 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
920 const GLint stride
= wblocks
* info
->BytesPerBlock
;
924 const GLint stride
= width
* info
->BytesPerBlock
;
932 * Return datatype and number of components per texel for the given
933 * uncompressed mesa_format. Only used for mipmap generation code.
936 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
937 GLenum
*datatype
, GLuint
*comps
)
940 case MESA_FORMAT_A8B8G8R8_UNORM
:
941 case MESA_FORMAT_R8G8B8A8_UNORM
:
942 case MESA_FORMAT_B8G8R8A8_UNORM
:
943 case MESA_FORMAT_A8R8G8B8_UNORM
:
944 case MESA_FORMAT_X8B8G8R8_UNORM
:
945 case MESA_FORMAT_R8G8B8X8_UNORM
:
946 case MESA_FORMAT_B8G8R8X8_UNORM
:
947 case MESA_FORMAT_X8R8G8B8_UNORM
:
948 case MESA_FORMAT_A8B8G8R8_UINT
:
949 case MESA_FORMAT_R8G8B8A8_UINT
:
950 case MESA_FORMAT_B8G8R8A8_UINT
:
951 case MESA_FORMAT_A8R8G8B8_UINT
:
952 *datatype
= GL_UNSIGNED_BYTE
;
955 case MESA_FORMAT_BGR_UNORM8
:
956 case MESA_FORMAT_RGB_UNORM8
:
957 *datatype
= GL_UNSIGNED_BYTE
;
960 case MESA_FORMAT_B5G6R5_UNORM
:
961 case MESA_FORMAT_R5G6B5_UNORM
:
962 case MESA_FORMAT_B5G6R5_UINT
:
963 case MESA_FORMAT_R5G6B5_UINT
:
964 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
968 case MESA_FORMAT_B4G4R4A4_UNORM
:
969 case MESA_FORMAT_A4R4G4B4_UNORM
:
970 case MESA_FORMAT_B4G4R4X4_UNORM
:
971 case MESA_FORMAT_B4G4R4A4_UINT
:
972 case MESA_FORMAT_A4R4G4B4_UINT
:
973 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
977 case MESA_FORMAT_B5G5R5A1_UNORM
:
978 case MESA_FORMAT_A1R5G5B5_UNORM
:
979 case MESA_FORMAT_B5G5R5X1_UNORM
:
980 case MESA_FORMAT_B5G5R5A1_UINT
:
981 case MESA_FORMAT_A1R5G5B5_UINT
:
982 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
986 case MESA_FORMAT_B10G10R10A2_UNORM
:
987 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
991 case MESA_FORMAT_A1B5G5R5_UNORM
:
992 case MESA_FORMAT_A1B5G5R5_UINT
:
993 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
997 case MESA_FORMAT_L4A4_UNORM
:
998 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1002 case MESA_FORMAT_L8A8_UNORM
:
1003 case MESA_FORMAT_A8L8_UNORM
:
1004 case MESA_FORMAT_R8G8_UNORM
:
1005 case MESA_FORMAT_G8R8_UNORM
:
1006 *datatype
= GL_UNSIGNED_BYTE
;
1010 case MESA_FORMAT_L16A16_UNORM
:
1011 case MESA_FORMAT_A16L16_UNORM
:
1012 case MESA_FORMAT_R16G16_UNORM
:
1013 case MESA_FORMAT_G16R16_UNORM
:
1014 *datatype
= GL_UNSIGNED_SHORT
;
1018 case MESA_FORMAT_R_UNORM16
:
1019 case MESA_FORMAT_A_UNORM16
:
1020 case MESA_FORMAT_L_UNORM16
:
1021 case MESA_FORMAT_I_UNORM16
:
1022 *datatype
= GL_UNSIGNED_SHORT
;
1026 case MESA_FORMAT_R3G3B2_UNORM
:
1027 case MESA_FORMAT_R3G3B2_UINT
:
1028 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1031 case MESA_FORMAT_A4B4G4R4_UNORM
:
1032 case MESA_FORMAT_A4B4G4R4_UINT
:
1033 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1037 case MESA_FORMAT_R4G4B4A4_UNORM
:
1038 case MESA_FORMAT_R4G4B4A4_UINT
:
1039 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1042 case MESA_FORMAT_R5G5B5A1_UNORM
:
1043 case MESA_FORMAT_R5G5B5A1_UINT
:
1044 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1047 case MESA_FORMAT_A2B10G10R10_UNORM
:
1048 case MESA_FORMAT_A2B10G10R10_UINT
:
1049 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1052 case MESA_FORMAT_A2R10G10B10_UNORM
:
1053 case MESA_FORMAT_A2R10G10B10_UINT
:
1054 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1058 case MESA_FORMAT_B2G3R3_UNORM
:
1059 case MESA_FORMAT_B2G3R3_UINT
:
1060 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1064 case MESA_FORMAT_A_UNORM8
:
1065 case MESA_FORMAT_L_UNORM8
:
1066 case MESA_FORMAT_I_UNORM8
:
1067 case MESA_FORMAT_R_UNORM8
:
1068 case MESA_FORMAT_S_UINT8
:
1069 *datatype
= GL_UNSIGNED_BYTE
;
1073 case MESA_FORMAT_YCBCR
:
1074 case MESA_FORMAT_YCBCR_REV
:
1075 *datatype
= GL_UNSIGNED_SHORT
;
1079 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1080 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1084 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1085 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1089 case MESA_FORMAT_Z_UNORM16
:
1090 *datatype
= GL_UNSIGNED_SHORT
;
1094 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1095 *datatype
= GL_UNSIGNED_INT
;
1099 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1100 *datatype
= GL_UNSIGNED_INT
;
1104 case MESA_FORMAT_Z_UNORM32
:
1105 *datatype
= GL_UNSIGNED_INT
;
1109 case MESA_FORMAT_Z_FLOAT32
:
1110 *datatype
= GL_FLOAT
;
1114 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1115 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1119 case MESA_FORMAT_R_SNORM8
:
1120 case MESA_FORMAT_A_SNORM8
:
1121 case MESA_FORMAT_L_SNORM8
:
1122 case MESA_FORMAT_I_SNORM8
:
1123 *datatype
= GL_BYTE
;
1126 case MESA_FORMAT_R8G8_SNORM
:
1127 case MESA_FORMAT_L8A8_SNORM
:
1128 case MESA_FORMAT_A8L8_SNORM
:
1129 *datatype
= GL_BYTE
;
1132 case MESA_FORMAT_A8B8G8R8_SNORM
:
1133 case MESA_FORMAT_R8G8B8A8_SNORM
:
1134 case MESA_FORMAT_X8B8G8R8_SNORM
:
1135 *datatype
= GL_BYTE
;
1139 case MESA_FORMAT_RGBA_UNORM16
:
1140 *datatype
= GL_UNSIGNED_SHORT
;
1144 case MESA_FORMAT_R_SNORM16
:
1145 case MESA_FORMAT_A_SNORM16
:
1146 case MESA_FORMAT_L_SNORM16
:
1147 case MESA_FORMAT_I_SNORM16
:
1148 *datatype
= GL_SHORT
;
1151 case MESA_FORMAT_R16G16_SNORM
:
1152 case MESA_FORMAT_LA_SNORM16
:
1153 *datatype
= GL_SHORT
;
1156 case MESA_FORMAT_RGB_SNORM16
:
1157 *datatype
= GL_SHORT
;
1160 case MESA_FORMAT_RGBA_SNORM16
:
1161 *datatype
= GL_SHORT
;
1165 case MESA_FORMAT_BGR_SRGB8
:
1166 *datatype
= GL_UNSIGNED_BYTE
;
1169 case MESA_FORMAT_A8B8G8R8_SRGB
:
1170 case MESA_FORMAT_B8G8R8A8_SRGB
:
1171 case MESA_FORMAT_A8R8G8B8_SRGB
:
1172 case MESA_FORMAT_R8G8B8A8_SRGB
:
1173 *datatype
= GL_UNSIGNED_BYTE
;
1176 case MESA_FORMAT_L_SRGB8
:
1177 *datatype
= GL_UNSIGNED_BYTE
;
1180 case MESA_FORMAT_L8A8_SRGB
:
1181 case MESA_FORMAT_A8L8_SRGB
:
1182 *datatype
= GL_UNSIGNED_BYTE
;
1186 case MESA_FORMAT_RGBA_FLOAT32
:
1187 *datatype
= GL_FLOAT
;
1190 case MESA_FORMAT_RGBA_FLOAT16
:
1191 *datatype
= GL_HALF_FLOAT_ARB
;
1194 case MESA_FORMAT_RGB_FLOAT32
:
1195 *datatype
= GL_FLOAT
;
1198 case MESA_FORMAT_RGB_FLOAT16
:
1199 *datatype
= GL_HALF_FLOAT_ARB
;
1202 case MESA_FORMAT_LA_FLOAT32
:
1203 case MESA_FORMAT_RG_FLOAT32
:
1204 *datatype
= GL_FLOAT
;
1207 case MESA_FORMAT_LA_FLOAT16
:
1208 case MESA_FORMAT_RG_FLOAT16
:
1209 *datatype
= GL_HALF_FLOAT_ARB
;
1212 case MESA_FORMAT_A_FLOAT32
:
1213 case MESA_FORMAT_L_FLOAT32
:
1214 case MESA_FORMAT_I_FLOAT32
:
1215 case MESA_FORMAT_R_FLOAT32
:
1216 *datatype
= GL_FLOAT
;
1219 case MESA_FORMAT_A_FLOAT16
:
1220 case MESA_FORMAT_L_FLOAT16
:
1221 case MESA_FORMAT_I_FLOAT16
:
1222 case MESA_FORMAT_R_FLOAT16
:
1223 *datatype
= GL_HALF_FLOAT_ARB
;
1227 case MESA_FORMAT_A_UINT8
:
1228 case MESA_FORMAT_L_UINT8
:
1229 case MESA_FORMAT_I_UINT8
:
1230 *datatype
= GL_UNSIGNED_BYTE
;
1233 case MESA_FORMAT_LA_UINT8
:
1234 *datatype
= GL_UNSIGNED_BYTE
;
1238 case MESA_FORMAT_A_UINT16
:
1239 case MESA_FORMAT_L_UINT16
:
1240 case MESA_FORMAT_I_UINT16
:
1241 *datatype
= GL_UNSIGNED_SHORT
;
1244 case MESA_FORMAT_LA_UINT16
:
1245 *datatype
= GL_UNSIGNED_SHORT
;
1248 case MESA_FORMAT_A_UINT32
:
1249 case MESA_FORMAT_L_UINT32
:
1250 case MESA_FORMAT_I_UINT32
:
1251 *datatype
= GL_UNSIGNED_INT
;
1254 case MESA_FORMAT_LA_UINT32
:
1255 *datatype
= GL_UNSIGNED_INT
;
1258 case MESA_FORMAT_A_SINT8
:
1259 case MESA_FORMAT_L_SINT8
:
1260 case MESA_FORMAT_I_SINT8
:
1261 *datatype
= GL_BYTE
;
1264 case MESA_FORMAT_LA_SINT8
:
1265 *datatype
= GL_BYTE
;
1269 case MESA_FORMAT_A_SINT16
:
1270 case MESA_FORMAT_L_SINT16
:
1271 case MESA_FORMAT_I_SINT16
:
1272 *datatype
= GL_SHORT
;
1275 case MESA_FORMAT_LA_SINT16
:
1276 *datatype
= GL_SHORT
;
1280 case MESA_FORMAT_A_SINT32
:
1281 case MESA_FORMAT_L_SINT32
:
1282 case MESA_FORMAT_I_SINT32
:
1286 case MESA_FORMAT_LA_SINT32
:
1291 case MESA_FORMAT_R_SINT8
:
1292 *datatype
= GL_BYTE
;
1295 case MESA_FORMAT_RG_SINT8
:
1296 *datatype
= GL_BYTE
;
1299 case MESA_FORMAT_RGB_SINT8
:
1300 *datatype
= GL_BYTE
;
1303 case MESA_FORMAT_RGBA_SINT8
:
1304 *datatype
= GL_BYTE
;
1307 case MESA_FORMAT_R_SINT16
:
1308 *datatype
= GL_SHORT
;
1311 case MESA_FORMAT_RG_SINT16
:
1312 *datatype
= GL_SHORT
;
1315 case MESA_FORMAT_RGB_SINT16
:
1316 *datatype
= GL_SHORT
;
1319 case MESA_FORMAT_RGBA_SINT16
:
1320 *datatype
= GL_SHORT
;
1323 case MESA_FORMAT_R_SINT32
:
1327 case MESA_FORMAT_RG_SINT32
:
1331 case MESA_FORMAT_RGB_SINT32
:
1335 case MESA_FORMAT_RGBA_SINT32
:
1341 * \name Non-normalized unsigned integer formats.
1343 case MESA_FORMAT_R_UINT8
:
1344 *datatype
= GL_UNSIGNED_BYTE
;
1347 case MESA_FORMAT_RG_UINT8
:
1348 *datatype
= GL_UNSIGNED_BYTE
;
1351 case MESA_FORMAT_RGB_UINT8
:
1352 *datatype
= GL_UNSIGNED_BYTE
;
1355 case MESA_FORMAT_RGBA_UINT8
:
1356 *datatype
= GL_UNSIGNED_BYTE
;
1359 case MESA_FORMAT_R_UINT16
:
1360 *datatype
= GL_UNSIGNED_SHORT
;
1363 case MESA_FORMAT_RG_UINT16
:
1364 *datatype
= GL_UNSIGNED_SHORT
;
1367 case MESA_FORMAT_RGB_UINT16
:
1368 *datatype
= GL_UNSIGNED_SHORT
;
1371 case MESA_FORMAT_RGBA_UINT16
:
1372 *datatype
= GL_UNSIGNED_SHORT
;
1375 case MESA_FORMAT_R_UINT32
:
1376 *datatype
= GL_UNSIGNED_INT
;
1379 case MESA_FORMAT_RG_UINT32
:
1380 *datatype
= GL_UNSIGNED_INT
;
1383 case MESA_FORMAT_RGB_UINT32
:
1384 *datatype
= GL_UNSIGNED_INT
;
1387 case MESA_FORMAT_RGBA_UINT32
:
1388 *datatype
= GL_UNSIGNED_INT
;
1392 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1393 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1397 case MESA_FORMAT_R11G11B10_FLOAT
:
1398 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1402 case MESA_FORMAT_B10G10R10A2_UINT
:
1403 case MESA_FORMAT_R10G10B10A2_UINT
:
1404 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1408 case MESA_FORMAT_R8G8B8X8_SRGB
:
1409 case MESA_FORMAT_X8B8G8R8_SRGB
:
1410 case MESA_FORMAT_RGBX_UINT8
:
1411 *datatype
= GL_UNSIGNED_BYTE
;
1415 case MESA_FORMAT_R8G8B8X8_SNORM
:
1416 case MESA_FORMAT_RGBX_SINT8
:
1417 *datatype
= GL_BYTE
;
1421 case MESA_FORMAT_B10G10R10X2_UNORM
:
1422 case MESA_FORMAT_R10G10B10X2_UNORM
:
1423 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1427 case MESA_FORMAT_RGBX_UNORM16
:
1428 case MESA_FORMAT_RGBX_UINT16
:
1429 *datatype
= GL_UNSIGNED_SHORT
;
1433 case MESA_FORMAT_RGBX_SNORM16
:
1434 case MESA_FORMAT_RGBX_SINT16
:
1435 *datatype
= GL_SHORT
;
1439 case MESA_FORMAT_RGBX_FLOAT16
:
1440 *datatype
= GL_HALF_FLOAT
;
1444 case MESA_FORMAT_RGBX_FLOAT32
:
1445 *datatype
= GL_FLOAT
;
1449 case MESA_FORMAT_RGBX_UINT32
:
1450 *datatype
= GL_UNSIGNED_INT
;
1454 case MESA_FORMAT_RGBX_SINT32
:
1459 case MESA_FORMAT_R10G10B10A2_UNORM
:
1460 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1464 case MESA_FORMAT_G8R8_SNORM
:
1465 *datatype
= GL_BYTE
;
1469 case MESA_FORMAT_G16R16_SNORM
:
1470 *datatype
= GL_SHORT
;
1474 case MESA_FORMAT_B8G8R8X8_SRGB
:
1475 case MESA_FORMAT_X8R8G8B8_SRGB
:
1476 *datatype
= GL_UNSIGNED_BYTE
;
1480 case MESA_FORMAT_COUNT
:
1484 /* Warn if any formats are not handled */
1485 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1486 _mesa_get_format_name(format
));
1487 assert(format
== MESA_FORMAT_NONE
||
1488 _mesa_is_format_compressed(format
));
1495 * Check if a mesa_format exactly matches a GL format/type combination
1496 * such that we can use memcpy() from one to the other.
1497 * \param mesa_format a MESA_FORMAT_x value
1498 * \param format the user-specified image format
1499 * \param type the user-specified image datatype
1500 * \param swapBytes typically the current pixel pack/unpack byteswap state
1501 * \param[out] error GL_NO_ERROR if format is an expected input.
1502 * GL_INVALID_ENUM if format is an unexpected input.
1503 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1506 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1507 GLenum format
, GLenum type
,
1508 GLboolean swapBytes
, GLenum
*error
)
1510 const GLboolean littleEndian
= _mesa_little_endian();
1512 *error
= GL_NO_ERROR
;
1514 /* Note: When reading a GL format/type combination, the format lists channel
1515 * assignments from most significant channel in the type to least
1516 * significant. A type with _REV indicates that the assignments are
1517 * swapped, so they are listed from least significant to most significant.
1519 * Compressed formats will fall through and return GL_FALSE.
1521 * For sanity, please keep this switch statement ordered the same as the
1522 * enums in formats.h.
1525 switch (mesa_format
) {
1527 case MESA_FORMAT_NONE
:
1528 case MESA_FORMAT_COUNT
:
1531 case MESA_FORMAT_A8B8G8R8_UNORM
:
1532 case MESA_FORMAT_A8B8G8R8_SRGB
:
1533 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1536 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1539 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1542 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1546 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1550 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1555 case MESA_FORMAT_R8G8B8A8_UNORM
:
1556 case MESA_FORMAT_R8G8B8A8_SRGB
:
1557 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1561 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1564 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1567 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1571 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1575 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1580 case MESA_FORMAT_B8G8R8A8_UNORM
:
1581 case MESA_FORMAT_B8G8R8A8_SRGB
:
1582 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1586 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1589 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1594 case MESA_FORMAT_A8R8G8B8_UNORM
:
1595 case MESA_FORMAT_A8R8G8B8_SRGB
:
1596 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1599 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1603 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1608 case MESA_FORMAT_X8B8G8R8_UNORM
:
1609 case MESA_FORMAT_R8G8B8X8_UNORM
:
1612 case MESA_FORMAT_B8G8R8X8_UNORM
:
1613 case MESA_FORMAT_X8R8G8B8_UNORM
:
1616 case MESA_FORMAT_BGR_UNORM8
:
1617 case MESA_FORMAT_BGR_SRGB8
:
1618 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1620 case MESA_FORMAT_RGB_UNORM8
:
1621 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1623 case MESA_FORMAT_B5G6R5_UNORM
:
1624 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1625 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1628 case MESA_FORMAT_R5G6B5_UNORM
:
1629 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1630 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1633 case MESA_FORMAT_B4G4R4A4_UNORM
:
1634 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1637 case MESA_FORMAT_A4R4G4B4_UNORM
:
1640 case MESA_FORMAT_A1B5G5R5_UNORM
:
1641 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1644 case MESA_FORMAT_B5G5R5A1_UNORM
:
1645 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1648 case MESA_FORMAT_A1R5G5B5_UNORM
:
1649 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1652 case MESA_FORMAT_L4A4_UNORM
:
1654 case MESA_FORMAT_L8A8_UNORM
:
1655 case MESA_FORMAT_L8A8_SRGB
:
1656 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1657 case MESA_FORMAT_A8L8_UNORM
:
1658 case MESA_FORMAT_A8L8_SRGB
:
1661 case MESA_FORMAT_L16A16_UNORM
:
1662 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1663 case MESA_FORMAT_A16L16_UNORM
:
1666 case MESA_FORMAT_B2G3R3_UNORM
:
1667 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1669 case MESA_FORMAT_R3G3B2_UNORM
:
1670 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1672 case MESA_FORMAT_A4B4G4R4_UNORM
:
1673 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1676 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1679 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1682 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1687 case MESA_FORMAT_R4G4B4A4_UNORM
:
1688 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1691 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1694 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1697 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1702 case MESA_FORMAT_R5G5B5A1_UNORM
:
1703 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1705 case MESA_FORMAT_A2B10G10R10_UNORM
:
1706 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1708 case MESA_FORMAT_A2B10G10R10_UINT
:
1709 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1711 case MESA_FORMAT_A2R10G10B10_UNORM
:
1712 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1714 case MESA_FORMAT_A2R10G10B10_UINT
:
1715 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1717 case MESA_FORMAT_A_UNORM8
:
1718 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1719 case MESA_FORMAT_A_UNORM16
:
1720 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1721 case MESA_FORMAT_L_UNORM8
:
1722 case MESA_FORMAT_L_SRGB8
:
1723 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1724 case MESA_FORMAT_L_UNORM16
:
1725 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1726 case MESA_FORMAT_I_UNORM8
:
1727 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1728 case MESA_FORMAT_I_UNORM16
:
1729 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1731 case MESA_FORMAT_YCBCR
:
1732 return format
== GL_YCBCR_MESA
&&
1733 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1734 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1735 case MESA_FORMAT_YCBCR_REV
:
1736 return format
== GL_YCBCR_MESA
&&
1737 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1738 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1740 case MESA_FORMAT_R_UNORM8
:
1741 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1742 case MESA_FORMAT_R8G8_UNORM
:
1743 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1744 case MESA_FORMAT_G8R8_UNORM
:
1747 case MESA_FORMAT_R_UNORM16
:
1748 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1750 case MESA_FORMAT_R16G16_UNORM
:
1751 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1753 case MESA_FORMAT_G16R16_UNORM
:
1756 case MESA_FORMAT_B10G10R10A2_UNORM
:
1757 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1760 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1761 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1763 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1764 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1767 case MESA_FORMAT_Z_UNORM16
:
1768 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1771 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1774 case MESA_FORMAT_Z_UNORM32
:
1775 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1778 case MESA_FORMAT_S_UINT8
:
1779 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1781 case MESA_FORMAT_RGBA_FLOAT32
:
1782 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1783 case MESA_FORMAT_RGBA_FLOAT16
:
1784 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1786 case MESA_FORMAT_RGB_FLOAT32
:
1787 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1788 case MESA_FORMAT_RGB_FLOAT16
:
1789 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1791 case MESA_FORMAT_A_FLOAT32
:
1792 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1793 case MESA_FORMAT_A_FLOAT16
:
1794 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1796 case MESA_FORMAT_L_FLOAT32
:
1797 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1798 case MESA_FORMAT_L_FLOAT16
:
1799 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1801 case MESA_FORMAT_LA_FLOAT32
:
1802 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1803 case MESA_FORMAT_LA_FLOAT16
:
1804 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1806 case MESA_FORMAT_I_FLOAT32
:
1807 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1808 case MESA_FORMAT_I_FLOAT16
:
1809 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1811 case MESA_FORMAT_R_FLOAT32
:
1812 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1813 case MESA_FORMAT_R_FLOAT16
:
1814 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1816 case MESA_FORMAT_RG_FLOAT32
:
1817 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1818 case MESA_FORMAT_RG_FLOAT16
:
1819 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1821 case MESA_FORMAT_A_UINT8
:
1822 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1823 case MESA_FORMAT_A_UINT16
:
1824 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1826 case MESA_FORMAT_A_UINT32
:
1827 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1829 case MESA_FORMAT_A_SINT8
:
1830 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1831 case MESA_FORMAT_A_SINT16
:
1832 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1833 case MESA_FORMAT_A_SINT32
:
1834 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1836 case MESA_FORMAT_I_UINT8
:
1837 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1838 case MESA_FORMAT_I_UINT16
:
1839 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1840 case MESA_FORMAT_I_UINT32
:
1841 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1842 case MESA_FORMAT_I_SINT8
:
1843 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1844 case MESA_FORMAT_I_SINT16
:
1845 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1846 case MESA_FORMAT_I_SINT32
:
1847 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1849 case MESA_FORMAT_L_UINT8
:
1850 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1851 case MESA_FORMAT_L_UINT16
:
1852 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1854 case MESA_FORMAT_L_UINT32
:
1855 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1857 case MESA_FORMAT_L_SINT8
:
1858 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1859 case MESA_FORMAT_L_SINT16
:
1860 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1862 case MESA_FORMAT_L_SINT32
:
1863 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1865 case MESA_FORMAT_LA_UINT8
:
1866 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1867 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1868 case MESA_FORMAT_LA_UINT16
:
1869 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1870 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1871 case MESA_FORMAT_LA_UINT32
:
1872 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1873 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1874 case MESA_FORMAT_LA_SINT8
:
1875 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1877 case MESA_FORMAT_LA_SINT16
:
1878 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1880 case MESA_FORMAT_LA_SINT32
:
1881 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1884 case MESA_FORMAT_R_SINT8
:
1885 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1886 case MESA_FORMAT_RG_SINT8
:
1887 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1888 case MESA_FORMAT_RGB_SINT8
:
1889 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1890 case MESA_FORMAT_RGBA_SINT8
:
1891 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1892 case MESA_FORMAT_R_SINT16
:
1893 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1894 case MESA_FORMAT_RG_SINT16
:
1895 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1896 case MESA_FORMAT_RGB_SINT16
:
1897 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1898 case MESA_FORMAT_RGBA_SINT16
:
1899 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1900 case MESA_FORMAT_R_SINT32
:
1901 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1902 case MESA_FORMAT_RG_SINT32
:
1903 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1904 case MESA_FORMAT_RGB_SINT32
:
1905 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1906 case MESA_FORMAT_RGBA_SINT32
:
1907 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1909 case MESA_FORMAT_R_UINT8
:
1910 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1911 case MESA_FORMAT_RG_UINT8
:
1912 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1913 case MESA_FORMAT_RGB_UINT8
:
1914 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1915 case MESA_FORMAT_RGBA_UINT8
:
1916 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1918 case MESA_FORMAT_R_UINT16
:
1919 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1921 case MESA_FORMAT_RG_UINT16
:
1922 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1923 case MESA_FORMAT_RGB_UINT16
:
1924 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1926 case MESA_FORMAT_RGBA_UINT16
:
1927 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1929 case MESA_FORMAT_R_UINT32
:
1930 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1931 case MESA_FORMAT_RG_UINT32
:
1932 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1933 case MESA_FORMAT_RGB_UINT32
:
1934 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1935 case MESA_FORMAT_RGBA_UINT32
:
1936 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1938 case MESA_FORMAT_R_SNORM8
:
1939 return format
== GL_RED
&& type
== GL_BYTE
;
1940 case MESA_FORMAT_R8G8_SNORM
:
1941 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1943 case MESA_FORMAT_X8B8G8R8_SNORM
:
1946 case MESA_FORMAT_A8B8G8R8_SNORM
:
1947 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1950 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1955 case MESA_FORMAT_R8G8B8A8_SNORM
:
1956 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1959 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1964 case MESA_FORMAT_R_SNORM16
:
1965 return format
== GL_RED
&& type
== GL_SHORT
&&
1967 case MESA_FORMAT_R16G16_SNORM
:
1968 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1969 case MESA_FORMAT_RGB_SNORM16
:
1970 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1971 case MESA_FORMAT_RGBA_SNORM16
:
1972 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1973 case MESA_FORMAT_RGBA_UNORM16
:
1974 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1977 case MESA_FORMAT_A_SNORM8
:
1978 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1979 case MESA_FORMAT_L_SNORM8
:
1980 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1981 case MESA_FORMAT_L8A8_SNORM
:
1982 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1983 littleEndian
&& !swapBytes
;
1984 case MESA_FORMAT_A8L8_SNORM
:
1985 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1986 !littleEndian
&& !swapBytes
;
1987 case MESA_FORMAT_I_SNORM8
:
1988 return format
== GL_RED
&& type
== GL_BYTE
;
1989 case MESA_FORMAT_A_SNORM16
:
1990 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1991 case MESA_FORMAT_L_SNORM16
:
1992 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1993 case MESA_FORMAT_LA_SNORM16
:
1994 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1995 littleEndian
&& !swapBytes
;
1996 case MESA_FORMAT_I_SNORM16
:
1997 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2000 case MESA_FORMAT_B10G10R10A2_UINT
:
2001 return (format
== GL_BGRA_INTEGER_EXT
&&
2002 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2005 case MESA_FORMAT_R10G10B10A2_UINT
:
2006 return (format
== GL_RGBA_INTEGER_EXT
&&
2007 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2010 case MESA_FORMAT_B5G6R5_UINT
:
2011 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
2013 case MESA_FORMAT_R5G6B5_UINT
:
2014 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
2016 case MESA_FORMAT_B2G3R3_UINT
:
2017 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
2019 case MESA_FORMAT_R3G3B2_UINT
:
2020 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
2022 case MESA_FORMAT_A4B4G4R4_UINT
:
2023 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
2026 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
2030 case MESA_FORMAT_R4G4B4A4_UINT
:
2031 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
2034 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
2039 case MESA_FORMAT_B4G4R4A4_UINT
:
2040 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
2043 case MESA_FORMAT_A4R4G4B4_UINT
:
2046 case MESA_FORMAT_A1B5G5R5_UINT
:
2047 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2050 case MESA_FORMAT_B5G5R5A1_UINT
:
2051 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
2054 case MESA_FORMAT_A1R5G5B5_UINT
:
2055 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2058 case MESA_FORMAT_R5G5B5A1_UINT
:
2059 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
2061 case MESA_FORMAT_A8B8G8R8_UINT
:
2062 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
2065 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
2069 case MESA_FORMAT_A8R8G8B8_UINT
:
2070 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
2074 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2080 case MESA_FORMAT_R8G8B8A8_UINT
:
2081 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2085 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2090 case MESA_FORMAT_B8G8R8A8_UINT
:
2091 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2095 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2100 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2101 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2104 case MESA_FORMAT_R11G11B10_FLOAT
:
2105 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2108 case MESA_FORMAT_Z_FLOAT32
:
2109 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2111 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2112 return format
== GL_DEPTH_STENCIL
&&
2113 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2115 case MESA_FORMAT_B4G4R4X4_UNORM
:
2116 case MESA_FORMAT_B5G5R5X1_UNORM
:
2117 case MESA_FORMAT_R8G8B8X8_SNORM
:
2118 case MESA_FORMAT_R8G8B8X8_SRGB
:
2119 case MESA_FORMAT_X8B8G8R8_SRGB
:
2120 case MESA_FORMAT_RGBX_UINT8
:
2121 case MESA_FORMAT_RGBX_SINT8
:
2122 case MESA_FORMAT_B10G10R10X2_UNORM
:
2123 case MESA_FORMAT_R10G10B10X2_UNORM
:
2124 case MESA_FORMAT_RGBX_UNORM16
:
2125 case MESA_FORMAT_RGBX_SNORM16
:
2126 case MESA_FORMAT_RGBX_FLOAT16
:
2127 case MESA_FORMAT_RGBX_UINT16
:
2128 case MESA_FORMAT_RGBX_SINT16
:
2129 case MESA_FORMAT_RGBX_FLOAT32
:
2130 case MESA_FORMAT_RGBX_UINT32
:
2131 case MESA_FORMAT_RGBX_SINT32
:
2134 case MESA_FORMAT_R10G10B10A2_UNORM
:
2135 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2138 case MESA_FORMAT_G8R8_SNORM
:
2139 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2142 case MESA_FORMAT_G16R16_SNORM
:
2143 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2146 case MESA_FORMAT_B8G8R8X8_SRGB
:
2147 case MESA_FORMAT_X8R8G8B8_SRGB
:
2150 assert(_mesa_is_format_compressed(mesa_format
));
2152 *error
= GL_INVALID_ENUM
;