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
;
69 * To describe compressed formats. If not compressed, Width=Height=1.
71 GLubyte BlockWidth
, BlockHeight
;
72 GLubyte BytesPerBlock
;
75 mesa_array_format ArrayFormat
;
78 #include "format_info.h"
80 static const struct gl_format_info
*
81 _mesa_get_format_info(mesa_format format
)
83 const struct gl_format_info
*info
= &format_info
[format
];
84 assert(info
->Name
== format
);
89 /** Return string name of format (for debugging) */
91 _mesa_get_format_name(mesa_format format
)
93 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
100 * Return bytes needed to store a block of pixels in the given format.
101 * Normally, a block is 1x1 (a single pixel). But for compressed formats
102 * a block may be 4x4 or 8x4, etc.
104 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
107 _mesa_get_format_bytes(mesa_format format
)
109 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
110 assert(info
->BytesPerBlock
);
111 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
112 _mesa_is_format_compressed(format
));
113 return info
->BytesPerBlock
;
118 * Return bits per component for the given format.
119 * \param format one of MESA_FORMAT_x
120 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
123 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
125 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
129 case GL_TEXTURE_RED_SIZE
:
130 case GL_RENDERBUFFER_RED_SIZE_EXT
:
131 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
132 return info
->RedBits
;
134 case GL_TEXTURE_GREEN_SIZE
:
135 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
136 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
137 return info
->GreenBits
;
139 case GL_TEXTURE_BLUE_SIZE
:
140 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
141 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
142 return info
->BlueBits
;
144 case GL_TEXTURE_ALPHA_SIZE
:
145 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
146 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
147 return info
->AlphaBits
;
148 case GL_TEXTURE_INTENSITY_SIZE
:
149 return info
->IntensityBits
;
150 case GL_TEXTURE_LUMINANCE_SIZE
:
151 return info
->LuminanceBits
;
155 case GL_TEXTURE_DEPTH_SIZE_ARB
:
156 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
157 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
158 return info
->DepthBits
;
159 case GL_STENCIL_BITS
:
160 case GL_TEXTURE_STENCIL_SIZE_EXT
:
161 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
162 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
163 return info
->StencilBits
;
165 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
172 _mesa_get_format_max_bits(mesa_format format
)
174 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
175 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
176 max
= MAX2(max
, info
->BlueBits
);
177 max
= MAX2(max
, info
->AlphaBits
);
178 max
= MAX2(max
, info
->LuminanceBits
);
179 max
= MAX2(max
, info
->IntensityBits
);
180 max
= MAX2(max
, info
->DepthBits
);
181 max
= MAX2(max
, info
->StencilBits
);
187 * Return the layout type of the given format.
188 * The return value will be one of:
189 * MESA_FORMAT_LAYOUT_ARRAY
190 * MESA_FORMAT_LAYOUT_PACKED
191 * MESA_FORMAT_LAYOUT_S3TC
192 * MESA_FORMAT_LAYOUT_RGTC
193 * MESA_FORMAT_LAYOUT_FXT1
194 * MESA_FORMAT_LAYOUT_ETC1
195 * MESA_FORMAT_LAYOUT_ETC2
196 * MESA_FORMAT_LAYOUT_BPTC
197 * MESA_FORMAT_LAYOUT_OTHER
199 extern enum mesa_format_layout
200 _mesa_get_format_layout(mesa_format format
)
202 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
208 * Return the data type (or more specifically, the data representation)
209 * for the given format.
210 * The return value will be one of:
211 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
212 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
213 * GL_UNSIGNED_INT = an ordinary unsigned integer
214 * GL_INT = an ordinary signed integer
215 * GL_FLOAT = an ordinary float
218 _mesa_get_format_datatype(mesa_format format
)
220 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
221 return info
->DataType
;
225 get_base_format_for_array_format(mesa_array_format format
)
230 _mesa_array_format_get_swizzle(format
, swizzle
);
231 num_channels
= _mesa_array_format_get_num_channels(format
);
233 switch (num_channels
) {
235 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
236 * This is not really a problem for now because we only create array
237 * formats from GL format/type combinations, and these cannot specify
244 if (swizzle
[0] == 0 &&
248 return GL_LUMINANCE_ALPHA
;
249 if (swizzle
[0] == 1 &&
253 return GL_LUMINANCE_ALPHA
;
254 if (swizzle
[0] == 0 &&
259 if (swizzle
[0] == 1 &&
266 if (swizzle
[0] == 0 &&
271 if (swizzle
[0] == 0 &&
276 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
278 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
280 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
282 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
287 unreachable("Unsupported format");
291 * Return the basic format for the given type. The result will be one of
292 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
293 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
294 * This functions accepts a mesa_format or a mesa_array_format.
297 _mesa_get_format_base_format(uint32_t format
)
299 if (!_mesa_format_is_mesa_array_format(format
)) {
300 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
301 return info
->BaseFormat
;
303 return get_base_format_for_array_format(format
);
309 * Return the block size (in pixels) for the given format. Normally
310 * the block size is 1x1. But compressed formats will have block sizes
311 * of 4x4 or 8x4 pixels, etc.
312 * \param bw returns block width in pixels
313 * \param bh returns block height in pixels
316 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
318 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
319 *bw
= info
->BlockWidth
;
320 *bh
= info
->BlockHeight
;
325 * Returns the an array of four numbers representing the transformation
326 * from the RGBA or SZ colorspace to the given format. For array formats,
327 * the i'th RGBA component is given by:
329 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
330 * comp = data[swizzle[i]];
331 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
333 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
335 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
336 * // data does not contain a channel of this format
338 * For packed formats, the swizzle gives the number of components left of
339 * the least significant bit.
341 * Compressed formats have no swizzle.
344 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
346 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
347 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
351 _mesa_array_format_flip_channels(mesa_array_format format
)
356 num_channels
= _mesa_array_format_get_num_channels(format
);
357 _mesa_array_format_get_swizzle(format
, swizzle
);
359 if (num_channels
== 1)
362 if (num_channels
== 2) {
363 /* Assert that the swizzle makes sense for 2 channels */
364 for (unsigned i
= 0; i
< 4; i
++)
365 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
367 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
368 _mesa_array_format_set_swizzle(&format
,
369 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
370 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
374 if (num_channels
== 4) {
375 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
376 _mesa_array_format_set_swizzle(&format
,
377 flip
[swizzle
[0]], flip
[swizzle
[1]],
378 flip
[swizzle
[2]], flip
[swizzle
[3]]);
382 unreachable("Invalid array format");
386 _mesa_format_to_array_format(mesa_format format
)
388 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
389 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
390 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
391 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
393 return info
->ArrayFormat
;
396 static struct hash_table
*format_array_format_table
;
397 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
400 array_formats_equal(const void *a
, const void *b
)
402 return (intptr_t)a
== (intptr_t)b
;
406 format_array_format_table_init(void)
408 const struct gl_format_info
*info
;
409 mesa_array_format array_format
;
412 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
413 array_formats_equal
);
415 if (!format_array_format_table
) {
416 _mesa_error_no_memory(__func__
);
420 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
421 info
= _mesa_get_format_info(f
);
422 if (!info
->ArrayFormat
)
425 if (_mesa_little_endian()) {
426 array_format
= info
->ArrayFormat
;
428 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
431 /* This can happen and does for some of the BGR formats. Let's take
432 * the first one in the list.
434 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
436 (void *)(intptr_t)array_format
))
439 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
441 (void *)(intptr_t)array_format
,
442 (void *)(intptr_t)f
);
447 _mesa_format_from_array_format(uint32_t array_format
)
449 struct hash_entry
*entry
;
451 assert(_mesa_format_is_mesa_array_format(array_format
));
453 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
455 if (!format_array_format_table
) {
456 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
457 format_array_format_table_exists
= once_flag_init
;
458 return MESA_FORMAT_NONE
;
461 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
463 (void *)(intptr_t)array_format
);
465 return (intptr_t)entry
->data
;
467 return MESA_FORMAT_NONE
;
470 /** Is the given format a compressed format? */
472 _mesa_is_format_compressed(mesa_format format
)
474 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
475 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
480 * Determine if the given format represents a packed depth/stencil buffer.
483 _mesa_is_format_packed_depth_stencil(mesa_format format
)
485 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
487 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
492 * Is the given format a signed/unsigned integer color format?
495 _mesa_is_format_integer_color(mesa_format format
)
497 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
498 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
499 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
500 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
501 info
->BaseFormat
!= GL_STENCIL_INDEX
;
506 * Is the given format an unsigned integer format?
509 _mesa_is_format_unsigned(mesa_format format
)
511 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
512 return _mesa_is_type_unsigned(info
->DataType
);
517 * Does the given format store signed values?
520 _mesa_is_format_signed(mesa_format format
)
522 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
523 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
524 /* these packed float formats only store unsigned values */
528 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
529 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
530 info
->DataType
== GL_INT
||
531 info
->DataType
== GL_FLOAT
);
536 * Is the given format an integer format?
539 _mesa_is_format_integer(mesa_format format
)
541 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
542 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
547 * Return true if the given format is a color format.
550 _mesa_is_format_color_format(mesa_format format
)
552 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
553 switch (info
->BaseFormat
) {
554 case GL_DEPTH_COMPONENT
:
555 case GL_STENCIL_INDEX
:
556 case GL_DEPTH_STENCIL
:
565 * Return color encoding for given format.
566 * \return GL_LINEAR or GL_SRGB
569 _mesa_get_format_color_encoding(mesa_format format
)
571 /* XXX this info should be encoded in gl_format_info */
573 case MESA_FORMAT_BGR_SRGB8
:
574 case MESA_FORMAT_A8B8G8R8_SRGB
:
575 case MESA_FORMAT_B8G8R8A8_SRGB
:
576 case MESA_FORMAT_A8R8G8B8_SRGB
:
577 case MESA_FORMAT_R8G8B8A8_SRGB
:
578 case MESA_FORMAT_L_SRGB8
:
579 case MESA_FORMAT_L8A8_SRGB
:
580 case MESA_FORMAT_A8L8_SRGB
:
581 case MESA_FORMAT_SRGB_DXT1
:
582 case MESA_FORMAT_SRGBA_DXT1
:
583 case MESA_FORMAT_SRGBA_DXT3
:
584 case MESA_FORMAT_SRGBA_DXT5
:
585 case MESA_FORMAT_R8G8B8X8_SRGB
:
586 case MESA_FORMAT_ETC2_SRGB8
:
587 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
588 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
589 case MESA_FORMAT_B8G8R8X8_SRGB
:
590 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
599 * Return TRUE if format is an ETC2 compressed format specified
600 * by GL_ARB_ES3_compatibility.
603 _mesa_is_format_etc2(mesa_format format
)
606 case MESA_FORMAT_ETC2_RGB8
:
607 case MESA_FORMAT_ETC2_SRGB8
:
608 case MESA_FORMAT_ETC2_RGBA8_EAC
:
609 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
610 case MESA_FORMAT_ETC2_R11_EAC
:
611 case MESA_FORMAT_ETC2_RG11_EAC
:
612 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
613 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
614 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
615 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
624 * For an sRGB format, return the corresponding linear color space format.
625 * For non-sRGB formats, return the format as-is.
628 _mesa_get_srgb_format_linear(mesa_format format
)
631 case MESA_FORMAT_BGR_SRGB8
:
632 format
= MESA_FORMAT_BGR_UNORM8
;
634 case MESA_FORMAT_A8B8G8R8_SRGB
:
635 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
637 case MESA_FORMAT_B8G8R8A8_SRGB
:
638 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
640 case MESA_FORMAT_A8R8G8B8_SRGB
:
641 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
643 case MESA_FORMAT_R8G8B8A8_SRGB
:
644 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
646 case MESA_FORMAT_L_SRGB8
:
647 format
= MESA_FORMAT_L_UNORM8
;
649 case MESA_FORMAT_L8A8_SRGB
:
650 format
= MESA_FORMAT_L8A8_UNORM
;
652 case MESA_FORMAT_A8L8_SRGB
:
653 format
= MESA_FORMAT_A8L8_UNORM
;
655 case MESA_FORMAT_SRGB_DXT1
:
656 format
= MESA_FORMAT_RGB_DXT1
;
658 case MESA_FORMAT_SRGBA_DXT1
:
659 format
= MESA_FORMAT_RGBA_DXT1
;
661 case MESA_FORMAT_SRGBA_DXT3
:
662 format
= MESA_FORMAT_RGBA_DXT3
;
664 case MESA_FORMAT_SRGBA_DXT5
:
665 format
= MESA_FORMAT_RGBA_DXT5
;
667 case MESA_FORMAT_R8G8B8X8_SRGB
:
668 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
670 case MESA_FORMAT_X8B8G8R8_SRGB
:
671 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
673 case MESA_FORMAT_ETC2_SRGB8
:
674 format
= MESA_FORMAT_ETC2_RGB8
;
676 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
677 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
679 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
680 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
682 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
683 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
685 case MESA_FORMAT_B8G8R8X8_SRGB
:
686 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
688 case MESA_FORMAT_X8R8G8B8_SRGB
:
689 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
699 * If the given format is a compressed format, return a corresponding
700 * uncompressed format.
703 _mesa_get_uncompressed_format(mesa_format format
)
706 case MESA_FORMAT_RGB_FXT1
:
707 return MESA_FORMAT_BGR_UNORM8
;
708 case MESA_FORMAT_RGBA_FXT1
:
709 return MESA_FORMAT_A8B8G8R8_UNORM
;
710 case MESA_FORMAT_RGB_DXT1
:
711 case MESA_FORMAT_SRGB_DXT1
:
712 return MESA_FORMAT_BGR_UNORM8
;
713 case MESA_FORMAT_RGBA_DXT1
:
714 case MESA_FORMAT_SRGBA_DXT1
:
715 return MESA_FORMAT_A8B8G8R8_UNORM
;
716 case MESA_FORMAT_RGBA_DXT3
:
717 case MESA_FORMAT_SRGBA_DXT3
:
718 return MESA_FORMAT_A8B8G8R8_UNORM
;
719 case MESA_FORMAT_RGBA_DXT5
:
720 case MESA_FORMAT_SRGBA_DXT5
:
721 return MESA_FORMAT_A8B8G8R8_UNORM
;
722 case MESA_FORMAT_R_RGTC1_UNORM
:
723 return MESA_FORMAT_R_UNORM8
;
724 case MESA_FORMAT_R_RGTC1_SNORM
:
725 return MESA_FORMAT_R_SNORM8
;
726 case MESA_FORMAT_RG_RGTC2_UNORM
:
727 return MESA_FORMAT_R8G8_UNORM
;
728 case MESA_FORMAT_RG_RGTC2_SNORM
:
729 return MESA_FORMAT_R8G8_SNORM
;
730 case MESA_FORMAT_L_LATC1_UNORM
:
731 return MESA_FORMAT_L_UNORM8
;
732 case MESA_FORMAT_L_LATC1_SNORM
:
733 return MESA_FORMAT_L_SNORM8
;
734 case MESA_FORMAT_LA_LATC2_UNORM
:
735 return MESA_FORMAT_L8A8_UNORM
;
736 case MESA_FORMAT_LA_LATC2_SNORM
:
737 return MESA_FORMAT_L8A8_SNORM
;
738 case MESA_FORMAT_ETC1_RGB8
:
739 case MESA_FORMAT_ETC2_RGB8
:
740 case MESA_FORMAT_ETC2_SRGB8
:
741 return MESA_FORMAT_BGR_UNORM8
;
742 case MESA_FORMAT_ETC2_RGBA8_EAC
:
743 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
744 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
745 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
746 return MESA_FORMAT_A8B8G8R8_UNORM
;
747 case MESA_FORMAT_ETC2_R11_EAC
:
748 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
749 return MESA_FORMAT_R_UNORM16
;
750 case MESA_FORMAT_ETC2_RG11_EAC
:
751 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
752 return MESA_FORMAT_R16G16_UNORM
;
753 case MESA_FORMAT_BPTC_RGBA_UNORM
:
754 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
755 return MESA_FORMAT_A8B8G8R8_UNORM
;
756 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
757 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
758 return MESA_FORMAT_RGB_FLOAT32
;
761 assert(!_mesa_is_format_compressed(format
));
769 _mesa_format_num_components(mesa_format format
)
771 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
772 return ((info
->RedBits
> 0) +
773 (info
->GreenBits
> 0) +
774 (info
->BlueBits
> 0) +
775 (info
->AlphaBits
> 0) +
776 (info
->LuminanceBits
> 0) +
777 (info
->IntensityBits
> 0) +
778 (info
->DepthBits
> 0) +
779 (info
->StencilBits
> 0));
784 * Returns true if a color format has data stored in the R/G/B/A channels,
785 * given an index from 0 to 3.
788 _mesa_format_has_color_component(mesa_format format
, int component
)
790 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
792 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
793 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
794 info
->BaseFormat
!= GL_STENCIL_INDEX
);
798 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
800 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
802 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
804 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
806 assert(!"Invalid color component: must be 0..3");
813 * Return number of bytes needed to store an image of the given size
814 * in the given format.
817 _mesa_format_image_size(mesa_format format
, GLsizei width
,
818 GLsizei height
, GLsizei depth
)
820 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
821 /* Strictly speaking, a conditional isn't needed here */
822 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
823 /* compressed format (2D only for now) */
824 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
825 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
826 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
827 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
832 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
839 * Same as _mesa_format_image_size() but returns a 64-bit value to
840 * accommodate very large textures.
843 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
844 GLsizei height
, GLsizei depth
)
846 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
847 /* Strictly speaking, a conditional isn't needed here */
848 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
849 /* compressed format (2D only for now) */
850 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
851 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
852 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
853 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
858 const uint64_t sz
= ((uint64_t) width
*
861 info
->BytesPerBlock
);
869 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
871 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
872 /* Strictly speaking, a conditional isn't needed here */
873 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
874 /* compressed format */
875 const GLuint bw
= info
->BlockWidth
;
876 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
877 const GLint stride
= wblocks
* info
->BytesPerBlock
;
881 const GLint stride
= width
* info
->BytesPerBlock
;
888 * Debug/test: check that all uncompressed formats are handled in the
889 * _mesa_uncompressed_format_to_type_and_comps() function. When new pixel
890 * formats are added to Mesa, that function needs to be updated.
891 * This is a no-op after the first call.
894 check_format_to_type_and_comps(void)
898 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
901 /* This function will emit a problem/warning if the format is
904 if (!_mesa_is_format_compressed(f
))
905 _mesa_uncompressed_format_to_type_and_comps(f
, &datatype
, &comps
);
910 * Do sanity checking of the format info table.
913 _mesa_test_formats(void)
917 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
919 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
920 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
923 assert(info
->Name
== i
);
925 if (info
->Name
== MESA_FORMAT_NONE
)
928 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
929 if (info
->RedBits
> 0) {
930 GLuint t
= info
->RedBits
+ info
->GreenBits
931 + info
->BlueBits
+ info
->AlphaBits
;
932 assert(t
/ 8 <= info
->BytesPerBlock
);
937 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
938 info
->DataType
== GL_SIGNED_NORMALIZED
||
939 info
->DataType
== GL_UNSIGNED_INT
||
940 info
->DataType
== GL_INT
||
941 info
->DataType
== GL_FLOAT
||
942 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
943 info
->DataType
== GL_NONE
);
945 if (info
->BaseFormat
== GL_RGB
) {
946 assert(info
->RedBits
> 0);
947 assert(info
->GreenBits
> 0);
948 assert(info
->BlueBits
> 0);
949 assert(info
->AlphaBits
== 0);
950 assert(info
->LuminanceBits
== 0);
951 assert(info
->IntensityBits
== 0);
953 else if (info
->BaseFormat
== GL_RGBA
) {
954 assert(info
->RedBits
> 0);
955 assert(info
->GreenBits
> 0);
956 assert(info
->BlueBits
> 0);
957 assert(info
->AlphaBits
> 0);
958 assert(info
->LuminanceBits
== 0);
959 assert(info
->IntensityBits
== 0);
961 else if (info
->BaseFormat
== GL_RG
) {
962 assert(info
->RedBits
> 0);
963 assert(info
->GreenBits
> 0);
964 assert(info
->BlueBits
== 0);
965 assert(info
->AlphaBits
== 0);
966 assert(info
->LuminanceBits
== 0);
967 assert(info
->IntensityBits
== 0);
969 else if (info
->BaseFormat
== GL_RED
) {
970 assert(info
->RedBits
> 0);
971 assert(info
->GreenBits
== 0);
972 assert(info
->BlueBits
== 0);
973 assert(info
->AlphaBits
== 0);
974 assert(info
->LuminanceBits
== 0);
975 assert(info
->IntensityBits
== 0);
977 else if (info
->BaseFormat
== GL_LUMINANCE
) {
978 assert(info
->RedBits
== 0);
979 assert(info
->GreenBits
== 0);
980 assert(info
->BlueBits
== 0);
981 assert(info
->AlphaBits
== 0);
982 assert(info
->LuminanceBits
> 0);
983 assert(info
->IntensityBits
== 0);
985 else if (info
->BaseFormat
== GL_INTENSITY
) {
986 assert(info
->RedBits
== 0);
987 assert(info
->GreenBits
== 0);
988 assert(info
->BlueBits
== 0);
989 assert(info
->AlphaBits
== 0);
990 assert(info
->LuminanceBits
== 0);
991 assert(info
->IntensityBits
> 0);
995 check_format_to_type_and_comps();
1001 * Return datatype and number of components per texel for the given
1002 * uncompressed mesa_format. Only used for mipmap generation code.
1005 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
1006 GLenum
*datatype
, GLuint
*comps
)
1009 case MESA_FORMAT_A8B8G8R8_UNORM
:
1010 case MESA_FORMAT_R8G8B8A8_UNORM
:
1011 case MESA_FORMAT_B8G8R8A8_UNORM
:
1012 case MESA_FORMAT_A8R8G8B8_UNORM
:
1013 case MESA_FORMAT_X8B8G8R8_UNORM
:
1014 case MESA_FORMAT_R8G8B8X8_UNORM
:
1015 case MESA_FORMAT_B8G8R8X8_UNORM
:
1016 case MESA_FORMAT_X8R8G8B8_UNORM
:
1017 *datatype
= GL_UNSIGNED_BYTE
;
1020 case MESA_FORMAT_BGR_UNORM8
:
1021 case MESA_FORMAT_RGB_UNORM8
:
1022 *datatype
= GL_UNSIGNED_BYTE
;
1025 case MESA_FORMAT_B5G6R5_UNORM
:
1026 case MESA_FORMAT_R5G6B5_UNORM
:
1027 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1031 case MESA_FORMAT_B4G4R4A4_UNORM
:
1032 case MESA_FORMAT_A4R4G4B4_UNORM
:
1033 case MESA_FORMAT_B4G4R4X4_UNORM
:
1034 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1038 case MESA_FORMAT_B5G5R5A1_UNORM
:
1039 case MESA_FORMAT_A1R5G5B5_UNORM
:
1040 case MESA_FORMAT_B5G5R5X1_UNORM
:
1041 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1045 case MESA_FORMAT_B10G10R10A2_UNORM
:
1046 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1050 case MESA_FORMAT_A1B5G5R5_UNORM
:
1051 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1055 case MESA_FORMAT_L4A4_UNORM
:
1056 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1060 case MESA_FORMAT_L8A8_UNORM
:
1061 case MESA_FORMAT_A8L8_UNORM
:
1062 case MESA_FORMAT_R8G8_UNORM
:
1063 case MESA_FORMAT_G8R8_UNORM
:
1064 *datatype
= GL_UNSIGNED_BYTE
;
1068 case MESA_FORMAT_L16A16_UNORM
:
1069 case MESA_FORMAT_A16L16_UNORM
:
1070 case MESA_FORMAT_R16G16_UNORM
:
1071 case MESA_FORMAT_G16R16_UNORM
:
1072 *datatype
= GL_UNSIGNED_SHORT
;
1076 case MESA_FORMAT_R_UNORM16
:
1077 case MESA_FORMAT_A_UNORM16
:
1078 case MESA_FORMAT_L_UNORM16
:
1079 case MESA_FORMAT_I_UNORM16
:
1080 *datatype
= GL_UNSIGNED_SHORT
;
1084 case MESA_FORMAT_R3G3B2_UNORM
:
1085 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1088 case MESA_FORMAT_A4B4G4R4_UNORM
:
1089 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1093 case MESA_FORMAT_R4G4B4A4_UNORM
:
1094 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1097 case MESA_FORMAT_R5G5B5A1_UNORM
:
1098 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1101 case MESA_FORMAT_A2B10G10R10_UNORM
:
1102 case MESA_FORMAT_A2B10G10R10_UINT
:
1103 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1106 case MESA_FORMAT_A2R10G10B10_UNORM
:
1107 case MESA_FORMAT_A2R10G10B10_UINT
:
1108 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1112 case MESA_FORMAT_B2G3R3_UNORM
:
1113 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1117 case MESA_FORMAT_A_UNORM8
:
1118 case MESA_FORMAT_L_UNORM8
:
1119 case MESA_FORMAT_I_UNORM8
:
1120 case MESA_FORMAT_R_UNORM8
:
1121 case MESA_FORMAT_S_UINT8
:
1122 *datatype
= GL_UNSIGNED_BYTE
;
1126 case MESA_FORMAT_YCBCR
:
1127 case MESA_FORMAT_YCBCR_REV
:
1128 *datatype
= GL_UNSIGNED_SHORT
;
1132 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1133 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1137 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1138 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1142 case MESA_FORMAT_Z_UNORM16
:
1143 *datatype
= GL_UNSIGNED_SHORT
;
1147 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1148 *datatype
= GL_UNSIGNED_INT
;
1152 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1153 *datatype
= GL_UNSIGNED_INT
;
1157 case MESA_FORMAT_Z_UNORM32
:
1158 *datatype
= GL_UNSIGNED_INT
;
1162 case MESA_FORMAT_Z_FLOAT32
:
1163 *datatype
= GL_FLOAT
;
1167 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1168 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1172 case MESA_FORMAT_R_SNORM8
:
1173 case MESA_FORMAT_A_SNORM8
:
1174 case MESA_FORMAT_L_SNORM8
:
1175 case MESA_FORMAT_I_SNORM8
:
1176 *datatype
= GL_BYTE
;
1179 case MESA_FORMAT_R8G8_SNORM
:
1180 case MESA_FORMAT_L8A8_SNORM
:
1181 case MESA_FORMAT_A8L8_SNORM
:
1182 *datatype
= GL_BYTE
;
1185 case MESA_FORMAT_A8B8G8R8_SNORM
:
1186 case MESA_FORMAT_R8G8B8A8_SNORM
:
1187 case MESA_FORMAT_X8B8G8R8_SNORM
:
1188 *datatype
= GL_BYTE
;
1192 case MESA_FORMAT_RGBA_UNORM16
:
1193 *datatype
= GL_UNSIGNED_SHORT
;
1197 case MESA_FORMAT_R_SNORM16
:
1198 case MESA_FORMAT_A_SNORM16
:
1199 case MESA_FORMAT_L_SNORM16
:
1200 case MESA_FORMAT_I_SNORM16
:
1201 *datatype
= GL_SHORT
;
1204 case MESA_FORMAT_R16G16_SNORM
:
1205 case MESA_FORMAT_LA_SNORM16
:
1206 *datatype
= GL_SHORT
;
1209 case MESA_FORMAT_RGB_SNORM16
:
1210 *datatype
= GL_SHORT
;
1213 case MESA_FORMAT_RGBA_SNORM16
:
1214 *datatype
= GL_SHORT
;
1218 case MESA_FORMAT_BGR_SRGB8
:
1219 *datatype
= GL_UNSIGNED_BYTE
;
1222 case MESA_FORMAT_A8B8G8R8_SRGB
:
1223 case MESA_FORMAT_B8G8R8A8_SRGB
:
1224 case MESA_FORMAT_A8R8G8B8_SRGB
:
1225 case MESA_FORMAT_R8G8B8A8_SRGB
:
1226 *datatype
= GL_UNSIGNED_BYTE
;
1229 case MESA_FORMAT_L_SRGB8
:
1230 *datatype
= GL_UNSIGNED_BYTE
;
1233 case MESA_FORMAT_L8A8_SRGB
:
1234 case MESA_FORMAT_A8L8_SRGB
:
1235 *datatype
= GL_UNSIGNED_BYTE
;
1239 case MESA_FORMAT_RGBA_FLOAT32
:
1240 *datatype
= GL_FLOAT
;
1243 case MESA_FORMAT_RGBA_FLOAT16
:
1244 *datatype
= GL_HALF_FLOAT_ARB
;
1247 case MESA_FORMAT_RGB_FLOAT32
:
1248 *datatype
= GL_FLOAT
;
1251 case MESA_FORMAT_RGB_FLOAT16
:
1252 *datatype
= GL_HALF_FLOAT_ARB
;
1255 case MESA_FORMAT_LA_FLOAT32
:
1256 case MESA_FORMAT_RG_FLOAT32
:
1257 *datatype
= GL_FLOAT
;
1260 case MESA_FORMAT_LA_FLOAT16
:
1261 case MESA_FORMAT_RG_FLOAT16
:
1262 *datatype
= GL_HALF_FLOAT_ARB
;
1265 case MESA_FORMAT_A_FLOAT32
:
1266 case MESA_FORMAT_L_FLOAT32
:
1267 case MESA_FORMAT_I_FLOAT32
:
1268 case MESA_FORMAT_R_FLOAT32
:
1269 *datatype
= GL_FLOAT
;
1272 case MESA_FORMAT_A_FLOAT16
:
1273 case MESA_FORMAT_L_FLOAT16
:
1274 case MESA_FORMAT_I_FLOAT16
:
1275 case MESA_FORMAT_R_FLOAT16
:
1276 *datatype
= GL_HALF_FLOAT_ARB
;
1280 case MESA_FORMAT_A_UINT8
:
1281 case MESA_FORMAT_L_UINT8
:
1282 case MESA_FORMAT_I_UINT8
:
1283 *datatype
= GL_UNSIGNED_BYTE
;
1286 case MESA_FORMAT_LA_UINT8
:
1287 *datatype
= GL_UNSIGNED_BYTE
;
1291 case MESA_FORMAT_A_UINT16
:
1292 case MESA_FORMAT_L_UINT16
:
1293 case MESA_FORMAT_I_UINT16
:
1294 *datatype
= GL_UNSIGNED_SHORT
;
1297 case MESA_FORMAT_LA_UINT16
:
1298 *datatype
= GL_UNSIGNED_SHORT
;
1301 case MESA_FORMAT_A_UINT32
:
1302 case MESA_FORMAT_L_UINT32
:
1303 case MESA_FORMAT_I_UINT32
:
1304 *datatype
= GL_UNSIGNED_INT
;
1307 case MESA_FORMAT_LA_UINT32
:
1308 *datatype
= GL_UNSIGNED_INT
;
1311 case MESA_FORMAT_A_SINT8
:
1312 case MESA_FORMAT_L_SINT8
:
1313 case MESA_FORMAT_I_SINT8
:
1314 *datatype
= GL_BYTE
;
1317 case MESA_FORMAT_LA_SINT8
:
1318 *datatype
= GL_BYTE
;
1322 case MESA_FORMAT_A_SINT16
:
1323 case MESA_FORMAT_L_SINT16
:
1324 case MESA_FORMAT_I_SINT16
:
1325 *datatype
= GL_SHORT
;
1328 case MESA_FORMAT_LA_SINT16
:
1329 *datatype
= GL_SHORT
;
1333 case MESA_FORMAT_A_SINT32
:
1334 case MESA_FORMAT_L_SINT32
:
1335 case MESA_FORMAT_I_SINT32
:
1339 case MESA_FORMAT_LA_SINT32
:
1344 case MESA_FORMAT_R_SINT8
:
1345 *datatype
= GL_BYTE
;
1348 case MESA_FORMAT_RG_SINT8
:
1349 *datatype
= GL_BYTE
;
1352 case MESA_FORMAT_RGB_SINT8
:
1353 *datatype
= GL_BYTE
;
1356 case MESA_FORMAT_RGBA_SINT8
:
1357 *datatype
= GL_BYTE
;
1360 case MESA_FORMAT_R_SINT16
:
1361 *datatype
= GL_SHORT
;
1364 case MESA_FORMAT_RG_SINT16
:
1365 *datatype
= GL_SHORT
;
1368 case MESA_FORMAT_RGB_SINT16
:
1369 *datatype
= GL_SHORT
;
1372 case MESA_FORMAT_RGBA_SINT16
:
1373 *datatype
= GL_SHORT
;
1376 case MESA_FORMAT_R_SINT32
:
1380 case MESA_FORMAT_RG_SINT32
:
1384 case MESA_FORMAT_RGB_SINT32
:
1388 case MESA_FORMAT_RGBA_SINT32
:
1394 * \name Non-normalized unsigned integer formats.
1396 case MESA_FORMAT_R_UINT8
:
1397 *datatype
= GL_UNSIGNED_BYTE
;
1400 case MESA_FORMAT_RG_UINT8
:
1401 *datatype
= GL_UNSIGNED_BYTE
;
1404 case MESA_FORMAT_RGB_UINT8
:
1405 *datatype
= GL_UNSIGNED_BYTE
;
1408 case MESA_FORMAT_RGBA_UINT8
:
1409 *datatype
= GL_UNSIGNED_BYTE
;
1412 case MESA_FORMAT_R_UINT16
:
1413 *datatype
= GL_UNSIGNED_SHORT
;
1416 case MESA_FORMAT_RG_UINT16
:
1417 *datatype
= GL_UNSIGNED_SHORT
;
1420 case MESA_FORMAT_RGB_UINT16
:
1421 *datatype
= GL_UNSIGNED_SHORT
;
1424 case MESA_FORMAT_RGBA_UINT16
:
1425 *datatype
= GL_UNSIGNED_SHORT
;
1428 case MESA_FORMAT_R_UINT32
:
1429 *datatype
= GL_UNSIGNED_INT
;
1432 case MESA_FORMAT_RG_UINT32
:
1433 *datatype
= GL_UNSIGNED_INT
;
1436 case MESA_FORMAT_RGB_UINT32
:
1437 *datatype
= GL_UNSIGNED_INT
;
1440 case MESA_FORMAT_RGBA_UINT32
:
1441 *datatype
= GL_UNSIGNED_INT
;
1445 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1446 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1450 case MESA_FORMAT_R11G11B10_FLOAT
:
1451 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1455 case MESA_FORMAT_B10G10R10A2_UINT
:
1456 case MESA_FORMAT_R10G10B10A2_UINT
:
1457 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1461 case MESA_FORMAT_R8G8B8X8_SRGB
:
1462 case MESA_FORMAT_X8B8G8R8_SRGB
:
1463 case MESA_FORMAT_RGBX_UINT8
:
1464 *datatype
= GL_UNSIGNED_BYTE
;
1468 case MESA_FORMAT_R8G8B8X8_SNORM
:
1469 case MESA_FORMAT_RGBX_SINT8
:
1470 *datatype
= GL_BYTE
;
1474 case MESA_FORMAT_B10G10R10X2_UNORM
:
1475 case MESA_FORMAT_R10G10B10X2_UNORM
:
1476 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1480 case MESA_FORMAT_RGBX_UNORM16
:
1481 case MESA_FORMAT_RGBX_UINT16
:
1482 *datatype
= GL_UNSIGNED_SHORT
;
1486 case MESA_FORMAT_RGBX_SNORM16
:
1487 case MESA_FORMAT_RGBX_SINT16
:
1488 *datatype
= GL_SHORT
;
1492 case MESA_FORMAT_RGBX_FLOAT16
:
1493 *datatype
= GL_HALF_FLOAT
;
1497 case MESA_FORMAT_RGBX_FLOAT32
:
1498 *datatype
= GL_FLOAT
;
1502 case MESA_FORMAT_RGBX_UINT32
:
1503 *datatype
= GL_UNSIGNED_INT
;
1507 case MESA_FORMAT_RGBX_SINT32
:
1512 case MESA_FORMAT_R10G10B10A2_UNORM
:
1513 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1517 case MESA_FORMAT_G8R8_SNORM
:
1518 *datatype
= GL_BYTE
;
1522 case MESA_FORMAT_G16R16_SNORM
:
1523 *datatype
= GL_SHORT
;
1527 case MESA_FORMAT_B8G8R8X8_SRGB
:
1528 case MESA_FORMAT_X8R8G8B8_SRGB
:
1529 *datatype
= GL_UNSIGNED_BYTE
;
1533 case MESA_FORMAT_COUNT
:
1537 case MESA_FORMAT_RGB_FXT1
:
1538 case MESA_FORMAT_RGBA_FXT1
:
1539 case MESA_FORMAT_RGB_DXT1
:
1540 case MESA_FORMAT_RGBA_DXT1
:
1541 case MESA_FORMAT_RGBA_DXT3
:
1542 case MESA_FORMAT_RGBA_DXT5
:
1543 case MESA_FORMAT_SRGB_DXT1
:
1544 case MESA_FORMAT_SRGBA_DXT1
:
1545 case MESA_FORMAT_SRGBA_DXT3
:
1546 case MESA_FORMAT_SRGBA_DXT5
:
1547 case MESA_FORMAT_R_RGTC1_UNORM
:
1548 case MESA_FORMAT_R_RGTC1_SNORM
:
1549 case MESA_FORMAT_RG_RGTC2_UNORM
:
1550 case MESA_FORMAT_RG_RGTC2_SNORM
:
1551 case MESA_FORMAT_L_LATC1_UNORM
:
1552 case MESA_FORMAT_L_LATC1_SNORM
:
1553 case MESA_FORMAT_LA_LATC2_UNORM
:
1554 case MESA_FORMAT_LA_LATC2_SNORM
:
1555 case MESA_FORMAT_ETC1_RGB8
:
1556 case MESA_FORMAT_ETC2_RGB8
:
1557 case MESA_FORMAT_ETC2_SRGB8
:
1558 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1559 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1560 case MESA_FORMAT_ETC2_R11_EAC
:
1561 case MESA_FORMAT_ETC2_RG11_EAC
:
1562 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1563 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1564 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1565 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1566 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1567 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1568 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1569 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1570 assert(_mesa_is_format_compressed(format
));
1571 case MESA_FORMAT_NONE
:
1572 /* For debug builds, warn if any formats are not handled */
1576 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1577 _mesa_get_format_name(format
));
1584 * Check if a mesa_format exactly matches a GL format/type combination
1585 * such that we can use memcpy() from one to the other.
1586 * \param mesa_format a MESA_FORMAT_x value
1587 * \param format the user-specified image format
1588 * \param type the user-specified image datatype
1589 * \param swapBytes typically the current pixel pack/unpack byteswap state
1590 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1593 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1594 GLenum format
, GLenum type
,
1595 GLboolean swapBytes
)
1597 const GLboolean littleEndian
= _mesa_little_endian();
1599 /* Note: When reading a GL format/type combination, the format lists channel
1600 * assignments from most significant channel in the type to least
1601 * significant. A type with _REV indicates that the assignments are
1602 * swapped, so they are listed from least significant to most significant.
1604 * For sanity, please keep this switch statement ordered the same as the
1605 * enums in formats.h.
1608 switch (mesa_format
) {
1610 case MESA_FORMAT_NONE
:
1611 case MESA_FORMAT_COUNT
:
1614 case MESA_FORMAT_A8B8G8R8_UNORM
:
1615 case MESA_FORMAT_A8B8G8R8_SRGB
:
1616 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1619 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1622 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1625 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1629 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1633 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1638 case MESA_FORMAT_R8G8B8A8_UNORM
:
1639 case MESA_FORMAT_R8G8B8A8_SRGB
:
1640 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1644 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1647 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1650 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1654 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1658 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1663 case MESA_FORMAT_B8G8R8A8_UNORM
:
1664 case MESA_FORMAT_B8G8R8A8_SRGB
:
1665 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1669 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1672 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1677 case MESA_FORMAT_A8R8G8B8_UNORM
:
1678 case MESA_FORMAT_A8R8G8B8_SRGB
:
1679 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1682 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1686 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1691 case MESA_FORMAT_X8B8G8R8_UNORM
:
1692 case MESA_FORMAT_R8G8B8X8_UNORM
:
1695 case MESA_FORMAT_B8G8R8X8_UNORM
:
1696 case MESA_FORMAT_X8R8G8B8_UNORM
:
1699 case MESA_FORMAT_BGR_UNORM8
:
1700 case MESA_FORMAT_BGR_SRGB8
:
1701 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1703 case MESA_FORMAT_RGB_UNORM8
:
1704 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1706 case MESA_FORMAT_B5G6R5_UNORM
:
1707 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1708 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1711 case MESA_FORMAT_R5G6B5_UNORM
:
1712 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1713 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1716 case MESA_FORMAT_B4G4R4A4_UNORM
:
1717 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1720 case MESA_FORMAT_A4R4G4B4_UNORM
:
1723 case MESA_FORMAT_A1B5G5R5_UNORM
:
1724 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1727 case MESA_FORMAT_B5G5R5A1_UNORM
:
1728 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1731 case MESA_FORMAT_A1R5G5B5_UNORM
:
1732 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1735 case MESA_FORMAT_L4A4_UNORM
:
1737 case MESA_FORMAT_L8A8_UNORM
:
1738 case MESA_FORMAT_L8A8_SRGB
:
1739 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1740 case MESA_FORMAT_A8L8_UNORM
:
1741 case MESA_FORMAT_A8L8_SRGB
:
1744 case MESA_FORMAT_L16A16_UNORM
:
1745 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1746 case MESA_FORMAT_A16L16_UNORM
:
1749 case MESA_FORMAT_B2G3R3_UNORM
:
1750 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1752 case MESA_FORMAT_R3G3B2_UNORM
:
1753 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1755 case MESA_FORMAT_A4B4G4R4_UNORM
:
1756 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1759 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1762 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1765 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1770 case MESA_FORMAT_R4G4B4A4_UNORM
:
1771 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1774 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1777 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1780 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1785 case MESA_FORMAT_R5G5B5A1_UNORM
:
1786 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1788 case MESA_FORMAT_A2B10G10R10_UNORM
:
1789 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1791 case MESA_FORMAT_A2B10G10R10_UINT
:
1792 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1794 case MESA_FORMAT_A2R10G10B10_UNORM
:
1795 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1797 case MESA_FORMAT_A2R10G10B10_UINT
:
1798 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1800 case MESA_FORMAT_A_UNORM8
:
1801 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1802 case MESA_FORMAT_A_UNORM16
:
1803 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1804 case MESA_FORMAT_L_UNORM8
:
1805 case MESA_FORMAT_L_SRGB8
:
1806 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1807 case MESA_FORMAT_L_UNORM16
:
1808 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1809 case MESA_FORMAT_I_UNORM8
:
1810 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1811 case MESA_FORMAT_I_UNORM16
:
1812 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1814 case MESA_FORMAT_YCBCR
:
1815 return format
== GL_YCBCR_MESA
&&
1816 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1817 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1818 case MESA_FORMAT_YCBCR_REV
:
1819 return format
== GL_YCBCR_MESA
&&
1820 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1821 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1823 case MESA_FORMAT_R_UNORM8
:
1824 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1825 case MESA_FORMAT_R8G8_UNORM
:
1826 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1827 case MESA_FORMAT_G8R8_UNORM
:
1830 case MESA_FORMAT_R_UNORM16
:
1831 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1833 case MESA_FORMAT_R16G16_UNORM
:
1834 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1836 case MESA_FORMAT_G16R16_UNORM
:
1839 case MESA_FORMAT_B10G10R10A2_UNORM
:
1840 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1843 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1844 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1846 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1847 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1850 case MESA_FORMAT_Z_UNORM16
:
1851 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1854 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1857 case MESA_FORMAT_Z_UNORM32
:
1858 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1861 case MESA_FORMAT_S_UINT8
:
1862 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1864 case MESA_FORMAT_SRGB_DXT1
:
1865 case MESA_FORMAT_SRGBA_DXT1
:
1866 case MESA_FORMAT_SRGBA_DXT3
:
1867 case MESA_FORMAT_SRGBA_DXT5
:
1870 case MESA_FORMAT_RGB_FXT1
:
1871 case MESA_FORMAT_RGBA_FXT1
:
1872 case MESA_FORMAT_RGB_DXT1
:
1873 case MESA_FORMAT_RGBA_DXT1
:
1874 case MESA_FORMAT_RGBA_DXT3
:
1875 case MESA_FORMAT_RGBA_DXT5
:
1878 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1879 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1880 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1881 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1884 case MESA_FORMAT_RGBA_FLOAT32
:
1885 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1886 case MESA_FORMAT_RGBA_FLOAT16
:
1887 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1889 case MESA_FORMAT_RGB_FLOAT32
:
1890 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1891 case MESA_FORMAT_RGB_FLOAT16
:
1892 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1894 case MESA_FORMAT_A_FLOAT32
:
1895 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1896 case MESA_FORMAT_A_FLOAT16
:
1897 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1899 case MESA_FORMAT_L_FLOAT32
:
1900 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1901 case MESA_FORMAT_L_FLOAT16
:
1902 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1904 case MESA_FORMAT_LA_FLOAT32
:
1905 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1906 case MESA_FORMAT_LA_FLOAT16
:
1907 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1909 case MESA_FORMAT_I_FLOAT32
:
1910 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1911 case MESA_FORMAT_I_FLOAT16
:
1912 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1914 case MESA_FORMAT_R_FLOAT32
:
1915 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1916 case MESA_FORMAT_R_FLOAT16
:
1917 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1919 case MESA_FORMAT_RG_FLOAT32
:
1920 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1921 case MESA_FORMAT_RG_FLOAT16
:
1922 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1924 case MESA_FORMAT_A_UINT8
:
1925 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1926 case MESA_FORMAT_A_UINT16
:
1927 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1929 case MESA_FORMAT_A_UINT32
:
1930 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1932 case MESA_FORMAT_A_SINT8
:
1933 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1934 case MESA_FORMAT_A_SINT16
:
1935 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1936 case MESA_FORMAT_A_SINT32
:
1937 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1939 case MESA_FORMAT_I_UINT8
:
1940 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1941 case MESA_FORMAT_I_UINT16
:
1942 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1943 case MESA_FORMAT_I_UINT32
:
1944 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1945 case MESA_FORMAT_I_SINT8
:
1946 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1947 case MESA_FORMAT_I_SINT16
:
1948 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1949 case MESA_FORMAT_I_SINT32
:
1950 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1952 case MESA_FORMAT_L_UINT8
:
1953 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1954 case MESA_FORMAT_L_UINT16
:
1955 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1957 case MESA_FORMAT_L_UINT32
:
1958 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1960 case MESA_FORMAT_L_SINT8
:
1961 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1962 case MESA_FORMAT_L_SINT16
:
1963 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1965 case MESA_FORMAT_L_SINT32
:
1966 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1968 case MESA_FORMAT_LA_UINT8
:
1969 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1970 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1971 case MESA_FORMAT_LA_UINT16
:
1972 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1973 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1974 case MESA_FORMAT_LA_UINT32
:
1975 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1976 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1977 case MESA_FORMAT_LA_SINT8
:
1978 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1980 case MESA_FORMAT_LA_SINT16
:
1981 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1983 case MESA_FORMAT_LA_SINT32
:
1984 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1987 case MESA_FORMAT_R_SINT8
:
1988 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1989 case MESA_FORMAT_RG_SINT8
:
1990 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1991 case MESA_FORMAT_RGB_SINT8
:
1992 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1993 case MESA_FORMAT_RGBA_SINT8
:
1994 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1995 case MESA_FORMAT_R_SINT16
:
1996 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1997 case MESA_FORMAT_RG_SINT16
:
1998 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1999 case MESA_FORMAT_RGB_SINT16
:
2000 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2001 case MESA_FORMAT_RGBA_SINT16
:
2002 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2003 case MESA_FORMAT_R_SINT32
:
2004 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2005 case MESA_FORMAT_RG_SINT32
:
2006 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2007 case MESA_FORMAT_RGB_SINT32
:
2008 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2009 case MESA_FORMAT_RGBA_SINT32
:
2010 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2012 case MESA_FORMAT_R_UINT8
:
2013 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2014 case MESA_FORMAT_RG_UINT8
:
2015 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2016 case MESA_FORMAT_RGB_UINT8
:
2017 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2018 case MESA_FORMAT_RGBA_UINT8
:
2019 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2021 case MESA_FORMAT_R_UINT16
:
2022 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2024 case MESA_FORMAT_RG_UINT16
:
2025 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2026 case MESA_FORMAT_RGB_UINT16
:
2027 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2029 case MESA_FORMAT_RGBA_UINT16
:
2030 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2032 case MESA_FORMAT_R_UINT32
:
2033 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2034 case MESA_FORMAT_RG_UINT32
:
2035 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2036 case MESA_FORMAT_RGB_UINT32
:
2037 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2038 case MESA_FORMAT_RGBA_UINT32
:
2039 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2041 case MESA_FORMAT_R_SNORM8
:
2042 return format
== GL_RED
&& type
== GL_BYTE
;
2043 case MESA_FORMAT_R8G8_SNORM
:
2044 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2046 case MESA_FORMAT_X8B8G8R8_SNORM
:
2049 case MESA_FORMAT_A8B8G8R8_SNORM
:
2050 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2053 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2058 case MESA_FORMAT_R8G8B8A8_SNORM
:
2059 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2062 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2067 case MESA_FORMAT_R_SNORM16
:
2068 return format
== GL_RED
&& type
== GL_SHORT
&&
2070 case MESA_FORMAT_R16G16_SNORM
:
2071 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2072 case MESA_FORMAT_RGB_SNORM16
:
2073 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2074 case MESA_FORMAT_RGBA_SNORM16
:
2075 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2076 case MESA_FORMAT_RGBA_UNORM16
:
2077 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2080 case MESA_FORMAT_R_RGTC1_UNORM
:
2081 case MESA_FORMAT_R_RGTC1_SNORM
:
2082 case MESA_FORMAT_RG_RGTC2_UNORM
:
2083 case MESA_FORMAT_RG_RGTC2_SNORM
:
2086 case MESA_FORMAT_L_LATC1_UNORM
:
2087 case MESA_FORMAT_L_LATC1_SNORM
:
2088 case MESA_FORMAT_LA_LATC2_UNORM
:
2089 case MESA_FORMAT_LA_LATC2_SNORM
:
2092 case MESA_FORMAT_ETC1_RGB8
:
2093 case MESA_FORMAT_ETC2_RGB8
:
2094 case MESA_FORMAT_ETC2_SRGB8
:
2095 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2096 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2097 case MESA_FORMAT_ETC2_R11_EAC
:
2098 case MESA_FORMAT_ETC2_RG11_EAC
:
2099 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2100 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2101 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2102 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2105 case MESA_FORMAT_A_SNORM8
:
2106 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2107 case MESA_FORMAT_L_SNORM8
:
2108 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2109 case MESA_FORMAT_L8A8_SNORM
:
2110 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2111 littleEndian
&& !swapBytes
;
2112 case MESA_FORMAT_A8L8_SNORM
:
2113 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2114 !littleEndian
&& !swapBytes
;
2115 case MESA_FORMAT_I_SNORM8
:
2116 return format
== GL_RED
&& type
== GL_BYTE
;
2117 case MESA_FORMAT_A_SNORM16
:
2118 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2119 case MESA_FORMAT_L_SNORM16
:
2120 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2121 case MESA_FORMAT_LA_SNORM16
:
2122 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2123 littleEndian
&& !swapBytes
;
2124 case MESA_FORMAT_I_SNORM16
:
2125 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2128 case MESA_FORMAT_B10G10R10A2_UINT
:
2129 return (format
== GL_BGRA_INTEGER_EXT
&&
2130 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2133 case MESA_FORMAT_R10G10B10A2_UINT
:
2134 return (format
== GL_RGBA_INTEGER_EXT
&&
2135 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2138 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2139 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2142 case MESA_FORMAT_R11G11B10_FLOAT
:
2143 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2146 case MESA_FORMAT_Z_FLOAT32
:
2147 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2149 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2150 return format
== GL_DEPTH_STENCIL
&&
2151 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2153 case MESA_FORMAT_B4G4R4X4_UNORM
:
2154 case MESA_FORMAT_B5G5R5X1_UNORM
:
2155 case MESA_FORMAT_R8G8B8X8_SNORM
:
2156 case MESA_FORMAT_R8G8B8X8_SRGB
:
2157 case MESA_FORMAT_X8B8G8R8_SRGB
:
2158 case MESA_FORMAT_RGBX_UINT8
:
2159 case MESA_FORMAT_RGBX_SINT8
:
2160 case MESA_FORMAT_B10G10R10X2_UNORM
:
2161 case MESA_FORMAT_R10G10B10X2_UNORM
:
2162 case MESA_FORMAT_RGBX_UNORM16
:
2163 case MESA_FORMAT_RGBX_SNORM16
:
2164 case MESA_FORMAT_RGBX_FLOAT16
:
2165 case MESA_FORMAT_RGBX_UINT16
:
2166 case MESA_FORMAT_RGBX_SINT16
:
2167 case MESA_FORMAT_RGBX_FLOAT32
:
2168 case MESA_FORMAT_RGBX_UINT32
:
2169 case MESA_FORMAT_RGBX_SINT32
:
2172 case MESA_FORMAT_R10G10B10A2_UNORM
:
2173 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2176 case MESA_FORMAT_G8R8_SNORM
:
2177 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2180 case MESA_FORMAT_G16R16_SNORM
:
2181 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2184 case MESA_FORMAT_B8G8R8X8_SRGB
:
2185 case MESA_FORMAT_X8R8G8B8_SRGB
: