2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "glformats.h"
31 #include "c11/threads.h"
32 #include "util/hash_table.h"
35 * Information about texture formats.
41 /** text name for debugging */
44 enum mesa_format_layout Layout
;
47 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
48 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
49 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
54 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
55 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
63 GLubyte LuminanceBits
;
64 GLubyte IntensityBits
;
71 * To describe compressed formats. If not compressed, Width=Height=1.
73 GLubyte BlockWidth
, BlockHeight
;
74 GLubyte BytesPerBlock
;
77 mesa_array_format ArrayFormat
;
80 #include "format_info.h"
82 static const struct gl_format_info
*
83 _mesa_get_format_info(mesa_format format
)
85 const struct gl_format_info
*info
= &format_info
[format
];
86 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
87 assert(info
->Name
== format
);
92 /** Return string name of format (for debugging) */
94 _mesa_get_format_name(mesa_format format
)
96 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
103 * Return bytes needed to store a block of pixels in the given format.
104 * Normally, a block is 1x1 (a single pixel). But for compressed formats
105 * a block may be 4x4 or 8x4, etc.
107 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
110 _mesa_get_format_bytes(mesa_format format
)
112 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
113 assert(info
->BytesPerBlock
);
114 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
115 _mesa_is_format_compressed(format
));
116 return info
->BytesPerBlock
;
121 * Return bits per component for the given format.
122 * \param format one of MESA_FORMAT_x
123 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
126 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
128 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
132 case GL_TEXTURE_RED_SIZE
:
133 case GL_RENDERBUFFER_RED_SIZE_EXT
:
134 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
135 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 *bw
= info
->BlockWidth
;
319 *bh
= info
->BlockHeight
;
324 * Returns the an array of four numbers representing the transformation
325 * from the RGBA or SZ colorspace to the given format. For array formats,
326 * the i'th RGBA component is given by:
328 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
329 * comp = data[swizzle[i]];
330 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
332 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
334 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
335 * // data does not contain a channel of this format
337 * For packed formats, the swizzle gives the number of components left of
338 * the least significant bit.
340 * Compressed formats have no swizzle.
343 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
345 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
346 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
350 _mesa_array_format_flip_channels(mesa_array_format format
)
355 num_channels
= _mesa_array_format_get_num_channels(format
);
356 _mesa_array_format_get_swizzle(format
, swizzle
);
358 if (num_channels
== 1)
361 if (num_channels
== 2) {
362 /* Assert that the swizzle makes sense for 2 channels */
363 for (unsigned i
= 0; i
< 4; i
++)
364 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
366 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
367 _mesa_array_format_set_swizzle(&format
,
368 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
369 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
373 if (num_channels
== 4) {
374 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
375 _mesa_array_format_set_swizzle(&format
,
376 flip
[swizzle
[0]], flip
[swizzle
[1]],
377 flip
[swizzle
[2]], flip
[swizzle
[3]]);
381 unreachable("Invalid array format");
385 _mesa_format_to_array_format(mesa_format format
)
387 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
388 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
389 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
390 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
392 return info
->ArrayFormat
;
395 static struct hash_table
*format_array_format_table
;
396 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
399 array_formats_equal(const void *a
, const void *b
)
401 return (intptr_t)a
== (intptr_t)b
;
405 format_array_format_table_init(void)
407 const struct gl_format_info
*info
;
408 mesa_array_format array_format
;
411 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
412 array_formats_equal
);
414 if (!format_array_format_table
) {
415 _mesa_error_no_memory(__func__
);
419 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
420 info
= _mesa_get_format_info(f
);
421 if (!info
->ArrayFormat
)
424 if (_mesa_little_endian()) {
425 array_format
= info
->ArrayFormat
;
427 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
430 /* This can happen and does for some of the BGR formats. Let's take
431 * the first one in the list.
433 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
435 (void *)(intptr_t)array_format
))
438 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
440 (void *)(intptr_t)array_format
,
441 (void *)(intptr_t)f
);
446 _mesa_format_from_array_format(uint32_t array_format
)
448 struct hash_entry
*entry
;
450 assert(_mesa_format_is_mesa_array_format(array_format
));
452 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
454 if (!format_array_format_table
) {
455 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
456 format_array_format_table_exists
= once_flag_init
;
457 return MESA_FORMAT_NONE
;
460 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
462 (void *)(intptr_t)array_format
);
464 return (intptr_t)entry
->data
;
466 return MESA_FORMAT_NONE
;
469 /** Is the given format a compressed format? */
471 _mesa_is_format_compressed(mesa_format format
)
473 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
474 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
479 * Determine if the given format represents a packed depth/stencil buffer.
482 _mesa_is_format_packed_depth_stencil(mesa_format format
)
484 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
486 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
491 * Is the given format a signed/unsigned integer color format?
494 _mesa_is_format_integer_color(mesa_format format
)
496 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
497 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
498 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
499 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
500 info
->BaseFormat
!= GL_STENCIL_INDEX
;
505 * Is the given format an unsigned integer format?
508 _mesa_is_format_unsigned(mesa_format format
)
510 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
511 return _mesa_is_type_unsigned(info
->DataType
);
516 * Does the given format store signed values?
519 _mesa_is_format_signed(mesa_format format
)
521 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
522 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
523 /* these packed float formats only store unsigned values */
527 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
528 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
529 info
->DataType
== GL_INT
||
530 info
->DataType
== GL_FLOAT
);
535 * Is the given format an integer format?
538 _mesa_is_format_integer(mesa_format format
)
540 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
541 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
546 * Return true if the given format is a color format.
549 _mesa_is_format_color_format(mesa_format format
)
551 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
552 switch (info
->BaseFormat
) {
553 case GL_DEPTH_COMPONENT
:
554 case GL_STENCIL_INDEX
:
555 case GL_DEPTH_STENCIL
:
564 * Return color encoding for given format.
565 * \return GL_LINEAR or GL_SRGB
568 _mesa_get_format_color_encoding(mesa_format format
)
570 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
571 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
576 * Return TRUE if format is an ETC2 compressed format specified
577 * by GL_ARB_ES3_compatibility.
580 _mesa_is_format_etc2(mesa_format format
)
583 case MESA_FORMAT_ETC2_RGB8
:
584 case MESA_FORMAT_ETC2_SRGB8
:
585 case MESA_FORMAT_ETC2_RGBA8_EAC
:
586 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
587 case MESA_FORMAT_ETC2_R11_EAC
:
588 case MESA_FORMAT_ETC2_RG11_EAC
:
589 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
590 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
591 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
592 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
601 * For an sRGB format, return the corresponding linear color space format.
602 * For non-sRGB formats, return the format as-is.
605 _mesa_get_srgb_format_linear(mesa_format format
)
608 case MESA_FORMAT_BGR_SRGB8
:
609 format
= MESA_FORMAT_BGR_UNORM8
;
611 case MESA_FORMAT_A8B8G8R8_SRGB
:
612 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
614 case MESA_FORMAT_B8G8R8A8_SRGB
:
615 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
617 case MESA_FORMAT_A8R8G8B8_SRGB
:
618 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
620 case MESA_FORMAT_R8G8B8A8_SRGB
:
621 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
623 case MESA_FORMAT_L_SRGB8
:
624 format
= MESA_FORMAT_L_UNORM8
;
626 case MESA_FORMAT_L8A8_SRGB
:
627 format
= MESA_FORMAT_L8A8_UNORM
;
629 case MESA_FORMAT_A8L8_SRGB
:
630 format
= MESA_FORMAT_A8L8_UNORM
;
632 case MESA_FORMAT_SRGB_DXT1
:
633 format
= MESA_FORMAT_RGB_DXT1
;
635 case MESA_FORMAT_SRGBA_DXT1
:
636 format
= MESA_FORMAT_RGBA_DXT1
;
638 case MESA_FORMAT_SRGBA_DXT3
:
639 format
= MESA_FORMAT_RGBA_DXT3
;
641 case MESA_FORMAT_SRGBA_DXT5
:
642 format
= MESA_FORMAT_RGBA_DXT5
;
644 case MESA_FORMAT_R8G8B8X8_SRGB
:
645 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
647 case MESA_FORMAT_X8B8G8R8_SRGB
:
648 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
650 case MESA_FORMAT_ETC2_SRGB8
:
651 format
= MESA_FORMAT_ETC2_RGB8
;
653 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
654 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
656 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
657 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
659 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
660 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
662 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
663 format
= MESA_FORMAT_RGBA_ASTC_4x4
;
665 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
666 format
= MESA_FORMAT_RGBA_ASTC_5x4
;
668 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
669 format
= MESA_FORMAT_RGBA_ASTC_5x5
;
671 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
672 format
= MESA_FORMAT_RGBA_ASTC_6x5
;
674 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
675 format
= MESA_FORMAT_RGBA_ASTC_6x6
;
677 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
678 format
= MESA_FORMAT_RGBA_ASTC_8x5
;
680 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
681 format
= MESA_FORMAT_RGBA_ASTC_8x6
;
683 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
684 format
= MESA_FORMAT_RGBA_ASTC_8x8
;
686 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
687 format
= MESA_FORMAT_RGBA_ASTC_10x5
;
689 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
690 format
= MESA_FORMAT_RGBA_ASTC_10x6
;
692 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
693 format
= MESA_FORMAT_RGBA_ASTC_10x8
;
695 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
696 format
= MESA_FORMAT_RGBA_ASTC_10x10
;
698 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
699 format
= MESA_FORMAT_RGBA_ASTC_12x10
;
701 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
702 format
= MESA_FORMAT_RGBA_ASTC_12x12
;
704 case MESA_FORMAT_B8G8R8X8_SRGB
:
705 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
707 case MESA_FORMAT_X8R8G8B8_SRGB
:
708 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
718 * If the given format is a compressed format, return a corresponding
719 * uncompressed format.
722 _mesa_get_uncompressed_format(mesa_format format
)
725 case MESA_FORMAT_RGB_FXT1
:
726 return MESA_FORMAT_BGR_UNORM8
;
727 case MESA_FORMAT_RGBA_FXT1
:
728 return MESA_FORMAT_A8B8G8R8_UNORM
;
729 case MESA_FORMAT_RGB_DXT1
:
730 case MESA_FORMAT_SRGB_DXT1
:
731 return MESA_FORMAT_BGR_UNORM8
;
732 case MESA_FORMAT_RGBA_DXT1
:
733 case MESA_FORMAT_SRGBA_DXT1
:
734 return MESA_FORMAT_A8B8G8R8_UNORM
;
735 case MESA_FORMAT_RGBA_DXT3
:
736 case MESA_FORMAT_SRGBA_DXT3
:
737 return MESA_FORMAT_A8B8G8R8_UNORM
;
738 case MESA_FORMAT_RGBA_DXT5
:
739 case MESA_FORMAT_SRGBA_DXT5
:
740 return MESA_FORMAT_A8B8G8R8_UNORM
;
741 case MESA_FORMAT_R_RGTC1_UNORM
:
742 return MESA_FORMAT_R_UNORM8
;
743 case MESA_FORMAT_R_RGTC1_SNORM
:
744 return MESA_FORMAT_R_SNORM8
;
745 case MESA_FORMAT_RG_RGTC2_UNORM
:
746 return MESA_FORMAT_R8G8_UNORM
;
747 case MESA_FORMAT_RG_RGTC2_SNORM
:
748 return MESA_FORMAT_R8G8_SNORM
;
749 case MESA_FORMAT_L_LATC1_UNORM
:
750 return MESA_FORMAT_L_UNORM8
;
751 case MESA_FORMAT_L_LATC1_SNORM
:
752 return MESA_FORMAT_L_SNORM8
;
753 case MESA_FORMAT_LA_LATC2_UNORM
:
754 return MESA_FORMAT_L8A8_UNORM
;
755 case MESA_FORMAT_LA_LATC2_SNORM
:
756 return MESA_FORMAT_L8A8_SNORM
;
757 case MESA_FORMAT_ETC1_RGB8
:
758 case MESA_FORMAT_ETC2_RGB8
:
759 case MESA_FORMAT_ETC2_SRGB8
:
760 return MESA_FORMAT_BGR_UNORM8
;
761 case MESA_FORMAT_ETC2_RGBA8_EAC
:
762 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
763 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
764 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
765 return MESA_FORMAT_A8B8G8R8_UNORM
;
766 case MESA_FORMAT_ETC2_R11_EAC
:
767 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
768 return MESA_FORMAT_R_UNORM16
;
769 case MESA_FORMAT_ETC2_RG11_EAC
:
770 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
771 return MESA_FORMAT_R16G16_UNORM
;
772 case MESA_FORMAT_BPTC_RGBA_UNORM
:
773 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
774 return MESA_FORMAT_A8B8G8R8_UNORM
;
775 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
776 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
777 return MESA_FORMAT_RGB_FLOAT32
;
780 assert(!_mesa_is_format_compressed(format
));
788 _mesa_format_num_components(mesa_format format
)
790 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
791 return ((info
->RedBits
> 0) +
792 (info
->GreenBits
> 0) +
793 (info
->BlueBits
> 0) +
794 (info
->AlphaBits
> 0) +
795 (info
->LuminanceBits
> 0) +
796 (info
->IntensityBits
> 0) +
797 (info
->DepthBits
> 0) +
798 (info
->StencilBits
> 0));
803 * Returns true if a color format has data stored in the R/G/B/A channels,
804 * given an index from 0 to 3.
807 _mesa_format_has_color_component(mesa_format format
, int component
)
809 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
811 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
812 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
813 info
->BaseFormat
!= GL_STENCIL_INDEX
);
817 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
819 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
821 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
823 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
825 assert(!"Invalid color component: must be 0..3");
832 * Return number of bytes needed to store an image of the given size
833 * in the given format.
836 _mesa_format_image_size(mesa_format format
, GLsizei width
,
837 GLsizei height
, GLsizei depth
)
839 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
840 /* Strictly speaking, a conditional isn't needed here */
841 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
842 /* compressed format (2D only for now) */
843 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
844 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
845 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
846 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
851 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
858 * Same as _mesa_format_image_size() but returns a 64-bit value to
859 * accommodate very large textures.
862 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
863 GLsizei height
, GLsizei depth
)
865 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
866 /* Strictly speaking, a conditional isn't needed here */
867 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
868 /* compressed format (2D only for now) */
869 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
870 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
871 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
872 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
877 const uint64_t sz
= ((uint64_t) width
*
880 info
->BytesPerBlock
);
888 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
890 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
891 /* Strictly speaking, a conditional isn't needed here */
892 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
893 /* compressed format */
894 const GLuint bw
= info
->BlockWidth
;
895 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
896 const GLint stride
= wblocks
* info
->BytesPerBlock
;
900 const GLint stride
= width
* info
->BytesPerBlock
;
908 * Return datatype and number of components per texel for the given
909 * uncompressed mesa_format. Only used for mipmap generation code.
912 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
913 GLenum
*datatype
, GLuint
*comps
)
916 case MESA_FORMAT_A8B8G8R8_UNORM
:
917 case MESA_FORMAT_R8G8B8A8_UNORM
:
918 case MESA_FORMAT_B8G8R8A8_UNORM
:
919 case MESA_FORMAT_A8R8G8B8_UNORM
:
920 case MESA_FORMAT_X8B8G8R8_UNORM
:
921 case MESA_FORMAT_R8G8B8X8_UNORM
:
922 case MESA_FORMAT_B8G8R8X8_UNORM
:
923 case MESA_FORMAT_X8R8G8B8_UNORM
:
924 case MESA_FORMAT_A8B8G8R8_UINT
:
925 case MESA_FORMAT_R8G8B8A8_UINT
:
926 case MESA_FORMAT_B8G8R8A8_UINT
:
927 case MESA_FORMAT_A8R8G8B8_UINT
:
928 *datatype
= GL_UNSIGNED_BYTE
;
931 case MESA_FORMAT_BGR_UNORM8
:
932 case MESA_FORMAT_RGB_UNORM8
:
933 *datatype
= GL_UNSIGNED_BYTE
;
936 case MESA_FORMAT_B5G6R5_UNORM
:
937 case MESA_FORMAT_R5G6B5_UNORM
:
938 case MESA_FORMAT_B5G6R5_UINT
:
939 case MESA_FORMAT_R5G6B5_UINT
:
940 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
944 case MESA_FORMAT_B4G4R4A4_UNORM
:
945 case MESA_FORMAT_A4R4G4B4_UNORM
:
946 case MESA_FORMAT_B4G4R4X4_UNORM
:
947 case MESA_FORMAT_B4G4R4A4_UINT
:
948 case MESA_FORMAT_A4R4G4B4_UINT
:
949 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
953 case MESA_FORMAT_B5G5R5A1_UNORM
:
954 case MESA_FORMAT_A1R5G5B5_UNORM
:
955 case MESA_FORMAT_B5G5R5X1_UNORM
:
956 case MESA_FORMAT_B5G5R5A1_UINT
:
957 case MESA_FORMAT_A1R5G5B5_UINT
:
958 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
962 case MESA_FORMAT_B10G10R10A2_UNORM
:
963 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
967 case MESA_FORMAT_A1B5G5R5_UNORM
:
968 case MESA_FORMAT_A1B5G5R5_UINT
:
969 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
973 case MESA_FORMAT_L4A4_UNORM
:
974 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
978 case MESA_FORMAT_L8A8_UNORM
:
979 case MESA_FORMAT_A8L8_UNORM
:
980 case MESA_FORMAT_R8G8_UNORM
:
981 case MESA_FORMAT_G8R8_UNORM
:
982 *datatype
= GL_UNSIGNED_BYTE
;
986 case MESA_FORMAT_L16A16_UNORM
:
987 case MESA_FORMAT_A16L16_UNORM
:
988 case MESA_FORMAT_R16G16_UNORM
:
989 case MESA_FORMAT_G16R16_UNORM
:
990 *datatype
= GL_UNSIGNED_SHORT
;
994 case MESA_FORMAT_R_UNORM16
:
995 case MESA_FORMAT_A_UNORM16
:
996 case MESA_FORMAT_L_UNORM16
:
997 case MESA_FORMAT_I_UNORM16
:
998 *datatype
= GL_UNSIGNED_SHORT
;
1002 case MESA_FORMAT_R3G3B2_UNORM
:
1003 case MESA_FORMAT_R3G3B2_UINT
:
1004 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1007 case MESA_FORMAT_A4B4G4R4_UNORM
:
1008 case MESA_FORMAT_A4B4G4R4_UINT
:
1009 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1013 case MESA_FORMAT_R4G4B4A4_UNORM
:
1014 case MESA_FORMAT_R4G4B4A4_UINT
:
1015 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1018 case MESA_FORMAT_R5G5B5A1_UNORM
:
1019 case MESA_FORMAT_R5G5B5A1_UINT
:
1020 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1023 case MESA_FORMAT_A2B10G10R10_UNORM
:
1024 case MESA_FORMAT_A2B10G10R10_UINT
:
1025 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1028 case MESA_FORMAT_A2R10G10B10_UNORM
:
1029 case MESA_FORMAT_A2R10G10B10_UINT
:
1030 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1034 case MESA_FORMAT_B2G3R3_UNORM
:
1035 case MESA_FORMAT_B2G3R3_UINT
:
1036 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1040 case MESA_FORMAT_A_UNORM8
:
1041 case MESA_FORMAT_L_UNORM8
:
1042 case MESA_FORMAT_I_UNORM8
:
1043 case MESA_FORMAT_R_UNORM8
:
1044 case MESA_FORMAT_S_UINT8
:
1045 *datatype
= GL_UNSIGNED_BYTE
;
1049 case MESA_FORMAT_YCBCR
:
1050 case MESA_FORMAT_YCBCR_REV
:
1051 *datatype
= GL_UNSIGNED_SHORT
;
1055 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1056 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1060 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1061 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1065 case MESA_FORMAT_Z_UNORM16
:
1066 *datatype
= GL_UNSIGNED_SHORT
;
1070 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1071 *datatype
= GL_UNSIGNED_INT
;
1075 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1076 *datatype
= GL_UNSIGNED_INT
;
1080 case MESA_FORMAT_Z_UNORM32
:
1081 *datatype
= GL_UNSIGNED_INT
;
1085 case MESA_FORMAT_Z_FLOAT32
:
1086 *datatype
= GL_FLOAT
;
1090 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1091 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1095 case MESA_FORMAT_R_SNORM8
:
1096 case MESA_FORMAT_A_SNORM8
:
1097 case MESA_FORMAT_L_SNORM8
:
1098 case MESA_FORMAT_I_SNORM8
:
1099 *datatype
= GL_BYTE
;
1102 case MESA_FORMAT_R8G8_SNORM
:
1103 case MESA_FORMAT_L8A8_SNORM
:
1104 case MESA_FORMAT_A8L8_SNORM
:
1105 *datatype
= GL_BYTE
;
1108 case MESA_FORMAT_A8B8G8R8_SNORM
:
1109 case MESA_FORMAT_R8G8B8A8_SNORM
:
1110 case MESA_FORMAT_X8B8G8R8_SNORM
:
1111 *datatype
= GL_BYTE
;
1115 case MESA_FORMAT_RGBA_UNORM16
:
1116 *datatype
= GL_UNSIGNED_SHORT
;
1120 case MESA_FORMAT_R_SNORM16
:
1121 case MESA_FORMAT_A_SNORM16
:
1122 case MESA_FORMAT_L_SNORM16
:
1123 case MESA_FORMAT_I_SNORM16
:
1124 *datatype
= GL_SHORT
;
1127 case MESA_FORMAT_R16G16_SNORM
:
1128 case MESA_FORMAT_LA_SNORM16
:
1129 *datatype
= GL_SHORT
;
1132 case MESA_FORMAT_RGB_SNORM16
:
1133 *datatype
= GL_SHORT
;
1136 case MESA_FORMAT_RGBA_SNORM16
:
1137 *datatype
= GL_SHORT
;
1141 case MESA_FORMAT_BGR_SRGB8
:
1142 *datatype
= GL_UNSIGNED_BYTE
;
1145 case MESA_FORMAT_A8B8G8R8_SRGB
:
1146 case MESA_FORMAT_B8G8R8A8_SRGB
:
1147 case MESA_FORMAT_A8R8G8B8_SRGB
:
1148 case MESA_FORMAT_R8G8B8A8_SRGB
:
1149 *datatype
= GL_UNSIGNED_BYTE
;
1152 case MESA_FORMAT_L_SRGB8
:
1153 *datatype
= GL_UNSIGNED_BYTE
;
1156 case MESA_FORMAT_L8A8_SRGB
:
1157 case MESA_FORMAT_A8L8_SRGB
:
1158 *datatype
= GL_UNSIGNED_BYTE
;
1162 case MESA_FORMAT_RGBA_FLOAT32
:
1163 *datatype
= GL_FLOAT
;
1166 case MESA_FORMAT_RGBA_FLOAT16
:
1167 *datatype
= GL_HALF_FLOAT_ARB
;
1170 case MESA_FORMAT_RGB_FLOAT32
:
1171 *datatype
= GL_FLOAT
;
1174 case MESA_FORMAT_RGB_FLOAT16
:
1175 *datatype
= GL_HALF_FLOAT_ARB
;
1178 case MESA_FORMAT_LA_FLOAT32
:
1179 case MESA_FORMAT_RG_FLOAT32
:
1180 *datatype
= GL_FLOAT
;
1183 case MESA_FORMAT_LA_FLOAT16
:
1184 case MESA_FORMAT_RG_FLOAT16
:
1185 *datatype
= GL_HALF_FLOAT_ARB
;
1188 case MESA_FORMAT_A_FLOAT32
:
1189 case MESA_FORMAT_L_FLOAT32
:
1190 case MESA_FORMAT_I_FLOAT32
:
1191 case MESA_FORMAT_R_FLOAT32
:
1192 *datatype
= GL_FLOAT
;
1195 case MESA_FORMAT_A_FLOAT16
:
1196 case MESA_FORMAT_L_FLOAT16
:
1197 case MESA_FORMAT_I_FLOAT16
:
1198 case MESA_FORMAT_R_FLOAT16
:
1199 *datatype
= GL_HALF_FLOAT_ARB
;
1203 case MESA_FORMAT_A_UINT8
:
1204 case MESA_FORMAT_L_UINT8
:
1205 case MESA_FORMAT_I_UINT8
:
1206 *datatype
= GL_UNSIGNED_BYTE
;
1209 case MESA_FORMAT_LA_UINT8
:
1210 *datatype
= GL_UNSIGNED_BYTE
;
1214 case MESA_FORMAT_A_UINT16
:
1215 case MESA_FORMAT_L_UINT16
:
1216 case MESA_FORMAT_I_UINT16
:
1217 *datatype
= GL_UNSIGNED_SHORT
;
1220 case MESA_FORMAT_LA_UINT16
:
1221 *datatype
= GL_UNSIGNED_SHORT
;
1224 case MESA_FORMAT_A_UINT32
:
1225 case MESA_FORMAT_L_UINT32
:
1226 case MESA_FORMAT_I_UINT32
:
1227 *datatype
= GL_UNSIGNED_INT
;
1230 case MESA_FORMAT_LA_UINT32
:
1231 *datatype
= GL_UNSIGNED_INT
;
1234 case MESA_FORMAT_A_SINT8
:
1235 case MESA_FORMAT_L_SINT8
:
1236 case MESA_FORMAT_I_SINT8
:
1237 *datatype
= GL_BYTE
;
1240 case MESA_FORMAT_LA_SINT8
:
1241 *datatype
= GL_BYTE
;
1245 case MESA_FORMAT_A_SINT16
:
1246 case MESA_FORMAT_L_SINT16
:
1247 case MESA_FORMAT_I_SINT16
:
1248 *datatype
= GL_SHORT
;
1251 case MESA_FORMAT_LA_SINT16
:
1252 *datatype
= GL_SHORT
;
1256 case MESA_FORMAT_A_SINT32
:
1257 case MESA_FORMAT_L_SINT32
:
1258 case MESA_FORMAT_I_SINT32
:
1262 case MESA_FORMAT_LA_SINT32
:
1267 case MESA_FORMAT_R_SINT8
:
1268 *datatype
= GL_BYTE
;
1271 case MESA_FORMAT_RG_SINT8
:
1272 *datatype
= GL_BYTE
;
1275 case MESA_FORMAT_RGB_SINT8
:
1276 *datatype
= GL_BYTE
;
1279 case MESA_FORMAT_RGBA_SINT8
:
1280 *datatype
= GL_BYTE
;
1283 case MESA_FORMAT_R_SINT16
:
1284 *datatype
= GL_SHORT
;
1287 case MESA_FORMAT_RG_SINT16
:
1288 *datatype
= GL_SHORT
;
1291 case MESA_FORMAT_RGB_SINT16
:
1292 *datatype
= GL_SHORT
;
1295 case MESA_FORMAT_RGBA_SINT16
:
1296 *datatype
= GL_SHORT
;
1299 case MESA_FORMAT_R_SINT32
:
1303 case MESA_FORMAT_RG_SINT32
:
1307 case MESA_FORMAT_RGB_SINT32
:
1311 case MESA_FORMAT_RGBA_SINT32
:
1317 * \name Non-normalized unsigned integer formats.
1319 case MESA_FORMAT_R_UINT8
:
1320 *datatype
= GL_UNSIGNED_BYTE
;
1323 case MESA_FORMAT_RG_UINT8
:
1324 *datatype
= GL_UNSIGNED_BYTE
;
1327 case MESA_FORMAT_RGB_UINT8
:
1328 *datatype
= GL_UNSIGNED_BYTE
;
1331 case MESA_FORMAT_RGBA_UINT8
:
1332 *datatype
= GL_UNSIGNED_BYTE
;
1335 case MESA_FORMAT_R_UINT16
:
1336 *datatype
= GL_UNSIGNED_SHORT
;
1339 case MESA_FORMAT_RG_UINT16
:
1340 *datatype
= GL_UNSIGNED_SHORT
;
1343 case MESA_FORMAT_RGB_UINT16
:
1344 *datatype
= GL_UNSIGNED_SHORT
;
1347 case MESA_FORMAT_RGBA_UINT16
:
1348 *datatype
= GL_UNSIGNED_SHORT
;
1351 case MESA_FORMAT_R_UINT32
:
1352 *datatype
= GL_UNSIGNED_INT
;
1355 case MESA_FORMAT_RG_UINT32
:
1356 *datatype
= GL_UNSIGNED_INT
;
1359 case MESA_FORMAT_RGB_UINT32
:
1360 *datatype
= GL_UNSIGNED_INT
;
1363 case MESA_FORMAT_RGBA_UINT32
:
1364 *datatype
= GL_UNSIGNED_INT
;
1368 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1369 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1373 case MESA_FORMAT_R11G11B10_FLOAT
:
1374 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1378 case MESA_FORMAT_B10G10R10A2_UINT
:
1379 case MESA_FORMAT_R10G10B10A2_UINT
:
1380 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1384 case MESA_FORMAT_R8G8B8X8_SRGB
:
1385 case MESA_FORMAT_X8B8G8R8_SRGB
:
1386 case MESA_FORMAT_RGBX_UINT8
:
1387 *datatype
= GL_UNSIGNED_BYTE
;
1391 case MESA_FORMAT_R8G8B8X8_SNORM
:
1392 case MESA_FORMAT_RGBX_SINT8
:
1393 *datatype
= GL_BYTE
;
1397 case MESA_FORMAT_B10G10R10X2_UNORM
:
1398 case MESA_FORMAT_R10G10B10X2_UNORM
:
1399 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1403 case MESA_FORMAT_RGBX_UNORM16
:
1404 case MESA_FORMAT_RGBX_UINT16
:
1405 *datatype
= GL_UNSIGNED_SHORT
;
1409 case MESA_FORMAT_RGBX_SNORM16
:
1410 case MESA_FORMAT_RGBX_SINT16
:
1411 *datatype
= GL_SHORT
;
1415 case MESA_FORMAT_RGBX_FLOAT16
:
1416 *datatype
= GL_HALF_FLOAT
;
1420 case MESA_FORMAT_RGBX_FLOAT32
:
1421 *datatype
= GL_FLOAT
;
1425 case MESA_FORMAT_RGBX_UINT32
:
1426 *datatype
= GL_UNSIGNED_INT
;
1430 case MESA_FORMAT_RGBX_SINT32
:
1435 case MESA_FORMAT_R10G10B10A2_UNORM
:
1436 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1440 case MESA_FORMAT_G8R8_SNORM
:
1441 *datatype
= GL_BYTE
;
1445 case MESA_FORMAT_G16R16_SNORM
:
1446 *datatype
= GL_SHORT
;
1450 case MESA_FORMAT_B8G8R8X8_SRGB
:
1451 case MESA_FORMAT_X8R8G8B8_SRGB
:
1452 *datatype
= GL_UNSIGNED_BYTE
;
1456 case MESA_FORMAT_COUNT
:
1460 /* Warn if any formats are not handled */
1461 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1462 _mesa_get_format_name(format
));
1463 assert(format
== MESA_FORMAT_NONE
||
1464 _mesa_is_format_compressed(format
));
1471 * Check if a mesa_format exactly matches a GL format/type combination
1472 * such that we can use memcpy() from one to the other.
1473 * \param mesa_format a MESA_FORMAT_x value
1474 * \param format the user-specified image format
1475 * \param type the user-specified image datatype
1476 * \param swapBytes typically the current pixel pack/unpack byteswap state
1477 * \param[out] error GL_NO_ERROR if format is an expected input.
1478 * GL_INVALID_ENUM if format is an unexpected input.
1479 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1482 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1483 GLenum format
, GLenum type
,
1484 GLboolean swapBytes
, GLenum
*error
)
1486 const GLboolean littleEndian
= _mesa_little_endian();
1488 *error
= GL_NO_ERROR
;
1490 /* Note: When reading a GL format/type combination, the format lists channel
1491 * assignments from most significant channel in the type to least
1492 * significant. A type with _REV indicates that the assignments are
1493 * swapped, so they are listed from least significant to most significant.
1495 * Compressed formats will fall through and return GL_FALSE.
1497 * For sanity, please keep this switch statement ordered the same as the
1498 * enums in formats.h.
1501 switch (mesa_format
) {
1503 case MESA_FORMAT_NONE
:
1504 case MESA_FORMAT_COUNT
:
1507 case MESA_FORMAT_A8B8G8R8_UNORM
:
1508 case MESA_FORMAT_A8B8G8R8_SRGB
:
1509 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1512 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1515 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1518 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1522 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1526 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1531 case MESA_FORMAT_R8G8B8A8_UNORM
:
1532 case MESA_FORMAT_R8G8B8A8_SRGB
:
1533 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1537 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1540 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1543 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1547 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1551 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1556 case MESA_FORMAT_B8G8R8A8_UNORM
:
1557 case MESA_FORMAT_B8G8R8A8_SRGB
:
1558 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1562 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1565 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1570 case MESA_FORMAT_A8R8G8B8_UNORM
:
1571 case MESA_FORMAT_A8R8G8B8_SRGB
:
1572 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1575 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1579 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1584 case MESA_FORMAT_X8B8G8R8_UNORM
:
1585 case MESA_FORMAT_R8G8B8X8_UNORM
:
1588 case MESA_FORMAT_B8G8R8X8_UNORM
:
1589 case MESA_FORMAT_X8R8G8B8_UNORM
:
1592 case MESA_FORMAT_BGR_UNORM8
:
1593 case MESA_FORMAT_BGR_SRGB8
:
1594 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1596 case MESA_FORMAT_RGB_UNORM8
:
1597 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1599 case MESA_FORMAT_B5G6R5_UNORM
:
1600 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1601 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1604 case MESA_FORMAT_R5G6B5_UNORM
:
1605 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1606 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1609 case MESA_FORMAT_B4G4R4A4_UNORM
:
1610 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1613 case MESA_FORMAT_A4R4G4B4_UNORM
:
1616 case MESA_FORMAT_A1B5G5R5_UNORM
:
1617 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1620 case MESA_FORMAT_B5G5R5A1_UNORM
:
1621 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1624 case MESA_FORMAT_A1R5G5B5_UNORM
:
1625 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1628 case MESA_FORMAT_L4A4_UNORM
:
1630 case MESA_FORMAT_L8A8_UNORM
:
1631 case MESA_FORMAT_L8A8_SRGB
:
1632 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1633 case MESA_FORMAT_A8L8_UNORM
:
1634 case MESA_FORMAT_A8L8_SRGB
:
1637 case MESA_FORMAT_L16A16_UNORM
:
1638 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1639 case MESA_FORMAT_A16L16_UNORM
:
1642 case MESA_FORMAT_B2G3R3_UNORM
:
1643 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1645 case MESA_FORMAT_R3G3B2_UNORM
:
1646 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1648 case MESA_FORMAT_A4B4G4R4_UNORM
:
1649 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1652 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1655 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1658 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1663 case MESA_FORMAT_R4G4B4A4_UNORM
:
1664 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1667 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1670 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1673 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1678 case MESA_FORMAT_R5G5B5A1_UNORM
:
1679 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1681 case MESA_FORMAT_A2B10G10R10_UNORM
:
1682 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1684 case MESA_FORMAT_A2B10G10R10_UINT
:
1685 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1687 case MESA_FORMAT_A2R10G10B10_UNORM
:
1688 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1690 case MESA_FORMAT_A2R10G10B10_UINT
:
1691 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1693 case MESA_FORMAT_A_UNORM8
:
1694 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1695 case MESA_FORMAT_A_UNORM16
:
1696 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1697 case MESA_FORMAT_L_UNORM8
:
1698 case MESA_FORMAT_L_SRGB8
:
1699 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1700 case MESA_FORMAT_L_UNORM16
:
1701 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1702 case MESA_FORMAT_I_UNORM8
:
1703 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1704 case MESA_FORMAT_I_UNORM16
:
1705 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1707 case MESA_FORMAT_YCBCR
:
1708 return format
== GL_YCBCR_MESA
&&
1709 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1710 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1711 case MESA_FORMAT_YCBCR_REV
:
1712 return format
== GL_YCBCR_MESA
&&
1713 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1714 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1716 case MESA_FORMAT_R_UNORM8
:
1717 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1718 case MESA_FORMAT_R8G8_UNORM
:
1719 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1720 case MESA_FORMAT_G8R8_UNORM
:
1723 case MESA_FORMAT_R_UNORM16
:
1724 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1726 case MESA_FORMAT_R16G16_UNORM
:
1727 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1729 case MESA_FORMAT_G16R16_UNORM
:
1732 case MESA_FORMAT_B10G10R10A2_UNORM
:
1733 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1736 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1737 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1739 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1740 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1743 case MESA_FORMAT_Z_UNORM16
:
1744 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1747 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1750 case MESA_FORMAT_Z_UNORM32
:
1751 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1754 case MESA_FORMAT_S_UINT8
:
1755 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1757 case MESA_FORMAT_RGBA_FLOAT32
:
1758 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1759 case MESA_FORMAT_RGBA_FLOAT16
:
1760 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1762 case MESA_FORMAT_RGB_FLOAT32
:
1763 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1764 case MESA_FORMAT_RGB_FLOAT16
:
1765 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1767 case MESA_FORMAT_A_FLOAT32
:
1768 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1769 case MESA_FORMAT_A_FLOAT16
:
1770 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1772 case MESA_FORMAT_L_FLOAT32
:
1773 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1774 case MESA_FORMAT_L_FLOAT16
:
1775 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1777 case MESA_FORMAT_LA_FLOAT32
:
1778 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1779 case MESA_FORMAT_LA_FLOAT16
:
1780 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1782 case MESA_FORMAT_I_FLOAT32
:
1783 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1784 case MESA_FORMAT_I_FLOAT16
:
1785 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1787 case MESA_FORMAT_R_FLOAT32
:
1788 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1789 case MESA_FORMAT_R_FLOAT16
:
1790 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1792 case MESA_FORMAT_RG_FLOAT32
:
1793 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1794 case MESA_FORMAT_RG_FLOAT16
:
1795 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1797 case MESA_FORMAT_A_UINT8
:
1798 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1799 case MESA_FORMAT_A_UINT16
:
1800 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1802 case MESA_FORMAT_A_UINT32
:
1803 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1805 case MESA_FORMAT_A_SINT8
:
1806 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1807 case MESA_FORMAT_A_SINT16
:
1808 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1809 case MESA_FORMAT_A_SINT32
:
1810 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1812 case MESA_FORMAT_I_UINT8
:
1813 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1814 case MESA_FORMAT_I_UINT16
:
1815 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1816 case MESA_FORMAT_I_UINT32
:
1817 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1818 case MESA_FORMAT_I_SINT8
:
1819 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1820 case MESA_FORMAT_I_SINT16
:
1821 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1822 case MESA_FORMAT_I_SINT32
:
1823 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1825 case MESA_FORMAT_L_UINT8
:
1826 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1827 case MESA_FORMAT_L_UINT16
:
1828 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1830 case MESA_FORMAT_L_UINT32
:
1831 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1833 case MESA_FORMAT_L_SINT8
:
1834 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1835 case MESA_FORMAT_L_SINT16
:
1836 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1838 case MESA_FORMAT_L_SINT32
:
1839 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1841 case MESA_FORMAT_LA_UINT8
:
1842 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1843 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1844 case MESA_FORMAT_LA_UINT16
:
1845 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1846 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1847 case MESA_FORMAT_LA_UINT32
:
1848 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1849 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1850 case MESA_FORMAT_LA_SINT8
:
1851 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1853 case MESA_FORMAT_LA_SINT16
:
1854 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1856 case MESA_FORMAT_LA_SINT32
:
1857 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1860 case MESA_FORMAT_R_SINT8
:
1861 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1862 case MESA_FORMAT_RG_SINT8
:
1863 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1864 case MESA_FORMAT_RGB_SINT8
:
1865 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1866 case MESA_FORMAT_RGBA_SINT8
:
1867 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1868 case MESA_FORMAT_R_SINT16
:
1869 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1870 case MESA_FORMAT_RG_SINT16
:
1871 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1872 case MESA_FORMAT_RGB_SINT16
:
1873 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1874 case MESA_FORMAT_RGBA_SINT16
:
1875 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1876 case MESA_FORMAT_R_SINT32
:
1877 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1878 case MESA_FORMAT_RG_SINT32
:
1879 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1880 case MESA_FORMAT_RGB_SINT32
:
1881 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1882 case MESA_FORMAT_RGBA_SINT32
:
1883 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1885 case MESA_FORMAT_R_UINT8
:
1886 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1887 case MESA_FORMAT_RG_UINT8
:
1888 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1889 case MESA_FORMAT_RGB_UINT8
:
1890 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1891 case MESA_FORMAT_RGBA_UINT8
:
1892 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1894 case MESA_FORMAT_R_UINT16
:
1895 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1897 case MESA_FORMAT_RG_UINT16
:
1898 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1899 case MESA_FORMAT_RGB_UINT16
:
1900 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1902 case MESA_FORMAT_RGBA_UINT16
:
1903 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1905 case MESA_FORMAT_R_UINT32
:
1906 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1907 case MESA_FORMAT_RG_UINT32
:
1908 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1909 case MESA_FORMAT_RGB_UINT32
:
1910 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1911 case MESA_FORMAT_RGBA_UINT32
:
1912 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1914 case MESA_FORMAT_R_SNORM8
:
1915 return format
== GL_RED
&& type
== GL_BYTE
;
1916 case MESA_FORMAT_R8G8_SNORM
:
1917 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1919 case MESA_FORMAT_X8B8G8R8_SNORM
:
1922 case MESA_FORMAT_A8B8G8R8_SNORM
:
1923 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1926 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1931 case MESA_FORMAT_R8G8B8A8_SNORM
:
1932 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1935 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1940 case MESA_FORMAT_R_SNORM16
:
1941 return format
== GL_RED
&& type
== GL_SHORT
&&
1943 case MESA_FORMAT_R16G16_SNORM
:
1944 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1945 case MESA_FORMAT_RGB_SNORM16
:
1946 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1947 case MESA_FORMAT_RGBA_SNORM16
:
1948 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1949 case MESA_FORMAT_RGBA_UNORM16
:
1950 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1953 case MESA_FORMAT_A_SNORM8
:
1954 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1955 case MESA_FORMAT_L_SNORM8
:
1956 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1957 case MESA_FORMAT_L8A8_SNORM
:
1958 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1959 littleEndian
&& !swapBytes
;
1960 case MESA_FORMAT_A8L8_SNORM
:
1961 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1962 !littleEndian
&& !swapBytes
;
1963 case MESA_FORMAT_I_SNORM8
:
1964 return format
== GL_RED
&& type
== GL_BYTE
;
1965 case MESA_FORMAT_A_SNORM16
:
1966 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1967 case MESA_FORMAT_L_SNORM16
:
1968 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1969 case MESA_FORMAT_LA_SNORM16
:
1970 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1971 littleEndian
&& !swapBytes
;
1972 case MESA_FORMAT_I_SNORM16
:
1973 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1976 case MESA_FORMAT_B10G10R10A2_UINT
:
1977 return (format
== GL_BGRA_INTEGER_EXT
&&
1978 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1981 case MESA_FORMAT_R10G10B10A2_UINT
:
1982 return (format
== GL_RGBA_INTEGER_EXT
&&
1983 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1986 case MESA_FORMAT_B5G6R5_UINT
:
1987 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1989 case MESA_FORMAT_R5G6B5_UINT
:
1990 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1992 case MESA_FORMAT_B2G3R3_UINT
:
1993 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1995 case MESA_FORMAT_R3G3B2_UINT
:
1996 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1998 case MESA_FORMAT_A4B4G4R4_UINT
:
1999 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
2002 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
2006 case MESA_FORMAT_R4G4B4A4_UINT
:
2007 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
2010 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
2015 case MESA_FORMAT_B4G4R4A4_UINT
:
2016 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
2019 case MESA_FORMAT_A4R4G4B4_UINT
:
2022 case MESA_FORMAT_A1B5G5R5_UINT
:
2023 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2026 case MESA_FORMAT_B5G5R5A1_UINT
:
2027 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
2030 case MESA_FORMAT_A1R5G5B5_UINT
:
2031 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
2034 case MESA_FORMAT_R5G5B5A1_UINT
:
2035 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
2037 case MESA_FORMAT_A8B8G8R8_UINT
:
2038 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
2041 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
2045 case MESA_FORMAT_A8R8G8B8_UINT
:
2046 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
2050 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2056 case MESA_FORMAT_R8G8B8A8_UINT
:
2057 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2061 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2066 case MESA_FORMAT_B8G8R8A8_UINT
:
2067 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
2071 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
2076 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2077 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2080 case MESA_FORMAT_R11G11B10_FLOAT
:
2081 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2084 case MESA_FORMAT_Z_FLOAT32
:
2085 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2087 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2088 return format
== GL_DEPTH_STENCIL
&&
2089 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2091 case MESA_FORMAT_B4G4R4X4_UNORM
:
2092 case MESA_FORMAT_B5G5R5X1_UNORM
:
2093 case MESA_FORMAT_R8G8B8X8_SNORM
:
2094 case MESA_FORMAT_R8G8B8X8_SRGB
:
2095 case MESA_FORMAT_X8B8G8R8_SRGB
:
2096 case MESA_FORMAT_RGBX_UINT8
:
2097 case MESA_FORMAT_RGBX_SINT8
:
2098 case MESA_FORMAT_B10G10R10X2_UNORM
:
2099 case MESA_FORMAT_R10G10B10X2_UNORM
:
2100 case MESA_FORMAT_RGBX_UNORM16
:
2101 case MESA_FORMAT_RGBX_SNORM16
:
2102 case MESA_FORMAT_RGBX_FLOAT16
:
2103 case MESA_FORMAT_RGBX_UINT16
:
2104 case MESA_FORMAT_RGBX_SINT16
:
2105 case MESA_FORMAT_RGBX_FLOAT32
:
2106 case MESA_FORMAT_RGBX_UINT32
:
2107 case MESA_FORMAT_RGBX_SINT32
:
2110 case MESA_FORMAT_R10G10B10A2_UNORM
:
2111 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2114 case MESA_FORMAT_G8R8_SNORM
:
2115 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2118 case MESA_FORMAT_G16R16_SNORM
:
2119 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2122 case MESA_FORMAT_B8G8R8X8_SRGB
:
2123 case MESA_FORMAT_X8R8G8B8_SRGB
:
2126 assert(_mesa_is_format_compressed(mesa_format
));
2128 *error
= GL_INVALID_ENUM
;