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 formats are handled in the
889 * _mesa_format_to_type_and_comps() function. When new pixel formats
890 * 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 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
909 * Do sanity checking of the format info table.
912 _mesa_test_formats(void)
916 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
918 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
919 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
922 assert(info
->Name
== i
);
924 if (info
->Name
== MESA_FORMAT_NONE
)
927 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
928 if (info
->RedBits
> 0) {
929 GLuint t
= info
->RedBits
+ info
->GreenBits
930 + info
->BlueBits
+ info
->AlphaBits
;
931 assert(t
/ 8 <= info
->BytesPerBlock
);
936 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
937 info
->DataType
== GL_SIGNED_NORMALIZED
||
938 info
->DataType
== GL_UNSIGNED_INT
||
939 info
->DataType
== GL_INT
||
940 info
->DataType
== GL_FLOAT
||
941 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
942 info
->DataType
== GL_NONE
);
944 if (info
->BaseFormat
== GL_RGB
) {
945 assert(info
->RedBits
> 0);
946 assert(info
->GreenBits
> 0);
947 assert(info
->BlueBits
> 0);
948 assert(info
->AlphaBits
== 0);
949 assert(info
->LuminanceBits
== 0);
950 assert(info
->IntensityBits
== 0);
952 else if (info
->BaseFormat
== GL_RGBA
) {
953 assert(info
->RedBits
> 0);
954 assert(info
->GreenBits
> 0);
955 assert(info
->BlueBits
> 0);
956 assert(info
->AlphaBits
> 0);
957 assert(info
->LuminanceBits
== 0);
958 assert(info
->IntensityBits
== 0);
960 else if (info
->BaseFormat
== GL_RG
) {
961 assert(info
->RedBits
> 0);
962 assert(info
->GreenBits
> 0);
963 assert(info
->BlueBits
== 0);
964 assert(info
->AlphaBits
== 0);
965 assert(info
->LuminanceBits
== 0);
966 assert(info
->IntensityBits
== 0);
968 else if (info
->BaseFormat
== GL_RED
) {
969 assert(info
->RedBits
> 0);
970 assert(info
->GreenBits
== 0);
971 assert(info
->BlueBits
== 0);
972 assert(info
->AlphaBits
== 0);
973 assert(info
->LuminanceBits
== 0);
974 assert(info
->IntensityBits
== 0);
976 else if (info
->BaseFormat
== GL_LUMINANCE
) {
977 assert(info
->RedBits
== 0);
978 assert(info
->GreenBits
== 0);
979 assert(info
->BlueBits
== 0);
980 assert(info
->AlphaBits
== 0);
981 assert(info
->LuminanceBits
> 0);
982 assert(info
->IntensityBits
== 0);
984 else if (info
->BaseFormat
== GL_INTENSITY
) {
985 assert(info
->RedBits
== 0);
986 assert(info
->GreenBits
== 0);
987 assert(info
->BlueBits
== 0);
988 assert(info
->AlphaBits
== 0);
989 assert(info
->LuminanceBits
== 0);
990 assert(info
->IntensityBits
> 0);
994 check_format_to_type_and_comps();
1000 * Return datatype and number of components per texel for the given mesa_format.
1001 * Only used for mipmap generation code.
1004 _mesa_format_to_type_and_comps(mesa_format format
,
1005 GLenum
*datatype
, GLuint
*comps
)
1008 case MESA_FORMAT_A8B8G8R8_UNORM
:
1009 case MESA_FORMAT_R8G8B8A8_UNORM
:
1010 case MESA_FORMAT_B8G8R8A8_UNORM
:
1011 case MESA_FORMAT_A8R8G8B8_UNORM
:
1012 case MESA_FORMAT_X8B8G8R8_UNORM
:
1013 case MESA_FORMAT_R8G8B8X8_UNORM
:
1014 case MESA_FORMAT_B8G8R8X8_UNORM
:
1015 case MESA_FORMAT_X8R8G8B8_UNORM
:
1016 *datatype
= GL_UNSIGNED_BYTE
;
1019 case MESA_FORMAT_BGR_UNORM8
:
1020 case MESA_FORMAT_RGB_UNORM8
:
1021 *datatype
= GL_UNSIGNED_BYTE
;
1024 case MESA_FORMAT_B5G6R5_UNORM
:
1025 case MESA_FORMAT_R5G6B5_UNORM
:
1026 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1030 case MESA_FORMAT_B4G4R4A4_UNORM
:
1031 case MESA_FORMAT_A4R4G4B4_UNORM
:
1032 case MESA_FORMAT_B4G4R4X4_UNORM
:
1033 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1037 case MESA_FORMAT_B5G5R5A1_UNORM
:
1038 case MESA_FORMAT_A1R5G5B5_UNORM
:
1039 case MESA_FORMAT_B5G5R5X1_UNORM
:
1040 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1044 case MESA_FORMAT_B10G10R10A2_UNORM
:
1045 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1049 case MESA_FORMAT_A1B5G5R5_UNORM
:
1050 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1054 case MESA_FORMAT_L4A4_UNORM
:
1055 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1059 case MESA_FORMAT_L8A8_UNORM
:
1060 case MESA_FORMAT_A8L8_UNORM
:
1061 case MESA_FORMAT_R8G8_UNORM
:
1062 case MESA_FORMAT_G8R8_UNORM
:
1063 *datatype
= GL_UNSIGNED_BYTE
;
1067 case MESA_FORMAT_L16A16_UNORM
:
1068 case MESA_FORMAT_A16L16_UNORM
:
1069 case MESA_FORMAT_R16G16_UNORM
:
1070 case MESA_FORMAT_G16R16_UNORM
:
1071 *datatype
= GL_UNSIGNED_SHORT
;
1075 case MESA_FORMAT_R_UNORM16
:
1076 case MESA_FORMAT_A_UNORM16
:
1077 case MESA_FORMAT_L_UNORM16
:
1078 case MESA_FORMAT_I_UNORM16
:
1079 *datatype
= GL_UNSIGNED_SHORT
;
1083 case MESA_FORMAT_R3G3B2_UNORM
:
1084 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1087 case MESA_FORMAT_A4B4G4R4_UNORM
:
1088 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1092 case MESA_FORMAT_R4G4B4A4_UNORM
:
1093 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1096 case MESA_FORMAT_R5G5B5A1_UNORM
:
1097 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1100 case MESA_FORMAT_A2B10G10R10_UNORM
:
1101 case MESA_FORMAT_A2B10G10R10_UINT
:
1102 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1105 case MESA_FORMAT_A2R10G10B10_UNORM
:
1106 case MESA_FORMAT_A2R10G10B10_UINT
:
1107 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1111 case MESA_FORMAT_B2G3R3_UNORM
:
1112 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1116 case MESA_FORMAT_A_UNORM8
:
1117 case MESA_FORMAT_L_UNORM8
:
1118 case MESA_FORMAT_I_UNORM8
:
1119 case MESA_FORMAT_R_UNORM8
:
1120 case MESA_FORMAT_S_UINT8
:
1121 *datatype
= GL_UNSIGNED_BYTE
;
1125 case MESA_FORMAT_YCBCR
:
1126 case MESA_FORMAT_YCBCR_REV
:
1127 *datatype
= GL_UNSIGNED_SHORT
;
1131 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1132 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1136 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1137 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1141 case MESA_FORMAT_Z_UNORM16
:
1142 *datatype
= GL_UNSIGNED_SHORT
;
1146 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1147 *datatype
= GL_UNSIGNED_INT
;
1151 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1152 *datatype
= GL_UNSIGNED_INT
;
1156 case MESA_FORMAT_Z_UNORM32
:
1157 *datatype
= GL_UNSIGNED_INT
;
1161 case MESA_FORMAT_Z_FLOAT32
:
1162 *datatype
= GL_FLOAT
;
1166 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1167 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1171 case MESA_FORMAT_R_SNORM8
:
1172 case MESA_FORMAT_A_SNORM8
:
1173 case MESA_FORMAT_L_SNORM8
:
1174 case MESA_FORMAT_I_SNORM8
:
1175 *datatype
= GL_BYTE
;
1178 case MESA_FORMAT_R8G8_SNORM
:
1179 case MESA_FORMAT_L8A8_SNORM
:
1180 case MESA_FORMAT_A8L8_SNORM
:
1181 *datatype
= GL_BYTE
;
1184 case MESA_FORMAT_A8B8G8R8_SNORM
:
1185 case MESA_FORMAT_R8G8B8A8_SNORM
:
1186 case MESA_FORMAT_X8B8G8R8_SNORM
:
1187 *datatype
= GL_BYTE
;
1191 case MESA_FORMAT_RGBA_UNORM16
:
1192 *datatype
= GL_UNSIGNED_SHORT
;
1196 case MESA_FORMAT_R_SNORM16
:
1197 case MESA_FORMAT_A_SNORM16
:
1198 case MESA_FORMAT_L_SNORM16
:
1199 case MESA_FORMAT_I_SNORM16
:
1200 *datatype
= GL_SHORT
;
1203 case MESA_FORMAT_R16G16_SNORM
:
1204 case MESA_FORMAT_LA_SNORM16
:
1205 *datatype
= GL_SHORT
;
1208 case MESA_FORMAT_RGB_SNORM16
:
1209 *datatype
= GL_SHORT
;
1212 case MESA_FORMAT_RGBA_SNORM16
:
1213 *datatype
= GL_SHORT
;
1217 case MESA_FORMAT_BGR_SRGB8
:
1218 *datatype
= GL_UNSIGNED_BYTE
;
1221 case MESA_FORMAT_A8B8G8R8_SRGB
:
1222 case MESA_FORMAT_B8G8R8A8_SRGB
:
1223 case MESA_FORMAT_A8R8G8B8_SRGB
:
1224 case MESA_FORMAT_R8G8B8A8_SRGB
:
1225 *datatype
= GL_UNSIGNED_BYTE
;
1228 case MESA_FORMAT_L_SRGB8
:
1229 *datatype
= GL_UNSIGNED_BYTE
;
1232 case MESA_FORMAT_L8A8_SRGB
:
1233 case MESA_FORMAT_A8L8_SRGB
:
1234 *datatype
= GL_UNSIGNED_BYTE
;
1238 case MESA_FORMAT_RGB_FXT1
:
1239 case MESA_FORMAT_RGBA_FXT1
:
1240 case MESA_FORMAT_RGB_DXT1
:
1241 case MESA_FORMAT_RGBA_DXT1
:
1242 case MESA_FORMAT_RGBA_DXT3
:
1243 case MESA_FORMAT_RGBA_DXT5
:
1244 case MESA_FORMAT_SRGB_DXT1
:
1245 case MESA_FORMAT_SRGBA_DXT1
:
1246 case MESA_FORMAT_SRGBA_DXT3
:
1247 case MESA_FORMAT_SRGBA_DXT5
:
1248 case MESA_FORMAT_R_RGTC1_UNORM
:
1249 case MESA_FORMAT_R_RGTC1_SNORM
:
1250 case MESA_FORMAT_RG_RGTC2_UNORM
:
1251 case MESA_FORMAT_RG_RGTC2_SNORM
:
1252 case MESA_FORMAT_L_LATC1_UNORM
:
1253 case MESA_FORMAT_L_LATC1_SNORM
:
1254 case MESA_FORMAT_LA_LATC2_UNORM
:
1255 case MESA_FORMAT_LA_LATC2_SNORM
:
1256 case MESA_FORMAT_ETC1_RGB8
:
1257 case MESA_FORMAT_ETC2_RGB8
:
1258 case MESA_FORMAT_ETC2_SRGB8
:
1259 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1260 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1261 case MESA_FORMAT_ETC2_R11_EAC
:
1262 case MESA_FORMAT_ETC2_RG11_EAC
:
1263 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1264 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1265 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1266 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1267 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1268 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1269 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1270 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1271 /* XXX generate error instead? */
1272 *datatype
= GL_UNSIGNED_BYTE
;
1276 case MESA_FORMAT_RGBA_FLOAT32
:
1277 *datatype
= GL_FLOAT
;
1280 case MESA_FORMAT_RGBA_FLOAT16
:
1281 *datatype
= GL_HALF_FLOAT_ARB
;
1284 case MESA_FORMAT_RGB_FLOAT32
:
1285 *datatype
= GL_FLOAT
;
1288 case MESA_FORMAT_RGB_FLOAT16
:
1289 *datatype
= GL_HALF_FLOAT_ARB
;
1292 case MESA_FORMAT_LA_FLOAT32
:
1293 case MESA_FORMAT_RG_FLOAT32
:
1294 *datatype
= GL_FLOAT
;
1297 case MESA_FORMAT_LA_FLOAT16
:
1298 case MESA_FORMAT_RG_FLOAT16
:
1299 *datatype
= GL_HALF_FLOAT_ARB
;
1302 case MESA_FORMAT_A_FLOAT32
:
1303 case MESA_FORMAT_L_FLOAT32
:
1304 case MESA_FORMAT_I_FLOAT32
:
1305 case MESA_FORMAT_R_FLOAT32
:
1306 *datatype
= GL_FLOAT
;
1309 case MESA_FORMAT_A_FLOAT16
:
1310 case MESA_FORMAT_L_FLOAT16
:
1311 case MESA_FORMAT_I_FLOAT16
:
1312 case MESA_FORMAT_R_FLOAT16
:
1313 *datatype
= GL_HALF_FLOAT_ARB
;
1317 case MESA_FORMAT_A_UINT8
:
1318 case MESA_FORMAT_L_UINT8
:
1319 case MESA_FORMAT_I_UINT8
:
1320 *datatype
= GL_UNSIGNED_BYTE
;
1323 case MESA_FORMAT_LA_UINT8
:
1324 *datatype
= GL_UNSIGNED_BYTE
;
1328 case MESA_FORMAT_A_UINT16
:
1329 case MESA_FORMAT_L_UINT16
:
1330 case MESA_FORMAT_I_UINT16
:
1331 *datatype
= GL_UNSIGNED_SHORT
;
1334 case MESA_FORMAT_LA_UINT16
:
1335 *datatype
= GL_UNSIGNED_SHORT
;
1338 case MESA_FORMAT_A_UINT32
:
1339 case MESA_FORMAT_L_UINT32
:
1340 case MESA_FORMAT_I_UINT32
:
1341 *datatype
= GL_UNSIGNED_INT
;
1344 case MESA_FORMAT_LA_UINT32
:
1345 *datatype
= GL_UNSIGNED_INT
;
1348 case MESA_FORMAT_A_SINT8
:
1349 case MESA_FORMAT_L_SINT8
:
1350 case MESA_FORMAT_I_SINT8
:
1351 *datatype
= GL_BYTE
;
1354 case MESA_FORMAT_LA_SINT8
:
1355 *datatype
= GL_BYTE
;
1359 case MESA_FORMAT_A_SINT16
:
1360 case MESA_FORMAT_L_SINT16
:
1361 case MESA_FORMAT_I_SINT16
:
1362 *datatype
= GL_SHORT
;
1365 case MESA_FORMAT_LA_SINT16
:
1366 *datatype
= GL_SHORT
;
1370 case MESA_FORMAT_A_SINT32
:
1371 case MESA_FORMAT_L_SINT32
:
1372 case MESA_FORMAT_I_SINT32
:
1376 case MESA_FORMAT_LA_SINT32
:
1381 case MESA_FORMAT_R_SINT8
:
1382 *datatype
= GL_BYTE
;
1385 case MESA_FORMAT_RG_SINT8
:
1386 *datatype
= GL_BYTE
;
1389 case MESA_FORMAT_RGB_SINT8
:
1390 *datatype
= GL_BYTE
;
1393 case MESA_FORMAT_RGBA_SINT8
:
1394 *datatype
= GL_BYTE
;
1397 case MESA_FORMAT_R_SINT16
:
1398 *datatype
= GL_SHORT
;
1401 case MESA_FORMAT_RG_SINT16
:
1402 *datatype
= GL_SHORT
;
1405 case MESA_FORMAT_RGB_SINT16
:
1406 *datatype
= GL_SHORT
;
1409 case MESA_FORMAT_RGBA_SINT16
:
1410 *datatype
= GL_SHORT
;
1413 case MESA_FORMAT_R_SINT32
:
1417 case MESA_FORMAT_RG_SINT32
:
1421 case MESA_FORMAT_RGB_SINT32
:
1425 case MESA_FORMAT_RGBA_SINT32
:
1431 * \name Non-normalized unsigned integer formats.
1433 case MESA_FORMAT_R_UINT8
:
1434 *datatype
= GL_UNSIGNED_BYTE
;
1437 case MESA_FORMAT_RG_UINT8
:
1438 *datatype
= GL_UNSIGNED_BYTE
;
1441 case MESA_FORMAT_RGB_UINT8
:
1442 *datatype
= GL_UNSIGNED_BYTE
;
1445 case MESA_FORMAT_RGBA_UINT8
:
1446 *datatype
= GL_UNSIGNED_BYTE
;
1449 case MESA_FORMAT_R_UINT16
:
1450 *datatype
= GL_UNSIGNED_SHORT
;
1453 case MESA_FORMAT_RG_UINT16
:
1454 *datatype
= GL_UNSIGNED_SHORT
;
1457 case MESA_FORMAT_RGB_UINT16
:
1458 *datatype
= GL_UNSIGNED_SHORT
;
1461 case MESA_FORMAT_RGBA_UINT16
:
1462 *datatype
= GL_UNSIGNED_SHORT
;
1465 case MESA_FORMAT_R_UINT32
:
1466 *datatype
= GL_UNSIGNED_INT
;
1469 case MESA_FORMAT_RG_UINT32
:
1470 *datatype
= GL_UNSIGNED_INT
;
1473 case MESA_FORMAT_RGB_UINT32
:
1474 *datatype
= GL_UNSIGNED_INT
;
1477 case MESA_FORMAT_RGBA_UINT32
:
1478 *datatype
= GL_UNSIGNED_INT
;
1482 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1483 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1487 case MESA_FORMAT_R11G11B10_FLOAT
:
1488 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1492 case MESA_FORMAT_B10G10R10A2_UINT
:
1493 case MESA_FORMAT_R10G10B10A2_UINT
:
1494 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1498 case MESA_FORMAT_R8G8B8X8_SRGB
:
1499 case MESA_FORMAT_X8B8G8R8_SRGB
:
1500 case MESA_FORMAT_RGBX_UINT8
:
1501 *datatype
= GL_UNSIGNED_BYTE
;
1505 case MESA_FORMAT_R8G8B8X8_SNORM
:
1506 case MESA_FORMAT_RGBX_SINT8
:
1507 *datatype
= GL_BYTE
;
1511 case MESA_FORMAT_B10G10R10X2_UNORM
:
1512 case MESA_FORMAT_R10G10B10X2_UNORM
:
1513 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1517 case MESA_FORMAT_RGBX_UNORM16
:
1518 case MESA_FORMAT_RGBX_UINT16
:
1519 *datatype
= GL_UNSIGNED_SHORT
;
1523 case MESA_FORMAT_RGBX_SNORM16
:
1524 case MESA_FORMAT_RGBX_SINT16
:
1525 *datatype
= GL_SHORT
;
1529 case MESA_FORMAT_RGBX_FLOAT16
:
1530 *datatype
= GL_HALF_FLOAT
;
1534 case MESA_FORMAT_RGBX_FLOAT32
:
1535 *datatype
= GL_FLOAT
;
1539 case MESA_FORMAT_RGBX_UINT32
:
1540 *datatype
= GL_UNSIGNED_INT
;
1544 case MESA_FORMAT_RGBX_SINT32
:
1549 case MESA_FORMAT_R10G10B10A2_UNORM
:
1550 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1554 case MESA_FORMAT_G8R8_SNORM
:
1555 *datatype
= GL_BYTE
;
1559 case MESA_FORMAT_G16R16_SNORM
:
1560 *datatype
= GL_SHORT
;
1564 case MESA_FORMAT_B8G8R8X8_SRGB
:
1565 case MESA_FORMAT_X8R8G8B8_SRGB
:
1566 *datatype
= GL_UNSIGNED_BYTE
;
1570 case MESA_FORMAT_COUNT
:
1574 case MESA_FORMAT_NONE
:
1575 /* For debug builds, warn if any formats are not handled */
1579 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1580 _mesa_get_format_name(format
));
1587 * Check if a mesa_format exactly matches a GL format/type combination
1588 * such that we can use memcpy() from one to the other.
1589 * \param mesa_format a MESA_FORMAT_x value
1590 * \param format the user-specified image format
1591 * \param type the user-specified image datatype
1592 * \param swapBytes typically the current pixel pack/unpack byteswap state
1593 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1596 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1597 GLenum format
, GLenum type
,
1598 GLboolean swapBytes
)
1600 const GLboolean littleEndian
= _mesa_little_endian();
1602 /* Note: When reading a GL format/type combination, the format lists channel
1603 * assignments from most significant channel in the type to least
1604 * significant. A type with _REV indicates that the assignments are
1605 * swapped, so they are listed from least significant to most significant.
1607 * For sanity, please keep this switch statement ordered the same as the
1608 * enums in formats.h.
1611 switch (mesa_format
) {
1613 case MESA_FORMAT_NONE
:
1614 case MESA_FORMAT_COUNT
:
1617 case MESA_FORMAT_A8B8G8R8_UNORM
:
1618 case MESA_FORMAT_A8B8G8R8_SRGB
:
1619 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1622 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1625 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1628 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1632 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1636 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1641 case MESA_FORMAT_R8G8B8A8_UNORM
:
1642 case MESA_FORMAT_R8G8B8A8_SRGB
:
1643 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1647 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1650 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1653 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1657 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1661 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1666 case MESA_FORMAT_B8G8R8A8_UNORM
:
1667 case MESA_FORMAT_B8G8R8A8_SRGB
:
1668 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1672 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1675 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1680 case MESA_FORMAT_A8R8G8B8_UNORM
:
1681 case MESA_FORMAT_A8R8G8B8_SRGB
:
1682 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1685 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1689 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1694 case MESA_FORMAT_X8B8G8R8_UNORM
:
1695 case MESA_FORMAT_R8G8B8X8_UNORM
:
1698 case MESA_FORMAT_B8G8R8X8_UNORM
:
1699 case MESA_FORMAT_X8R8G8B8_UNORM
:
1702 case MESA_FORMAT_BGR_UNORM8
:
1703 case MESA_FORMAT_BGR_SRGB8
:
1704 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1706 case MESA_FORMAT_RGB_UNORM8
:
1707 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1709 case MESA_FORMAT_B5G6R5_UNORM
:
1710 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1711 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1714 case MESA_FORMAT_R5G6B5_UNORM
:
1715 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1716 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1719 case MESA_FORMAT_B4G4R4A4_UNORM
:
1720 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1723 case MESA_FORMAT_A4R4G4B4_UNORM
:
1726 case MESA_FORMAT_A1B5G5R5_UNORM
:
1727 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1730 case MESA_FORMAT_B5G5R5A1_UNORM
:
1731 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1734 case MESA_FORMAT_A1R5G5B5_UNORM
:
1735 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1738 case MESA_FORMAT_L4A4_UNORM
:
1740 case MESA_FORMAT_L8A8_UNORM
:
1741 case MESA_FORMAT_L8A8_SRGB
:
1742 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1743 case MESA_FORMAT_A8L8_UNORM
:
1744 case MESA_FORMAT_A8L8_SRGB
:
1747 case MESA_FORMAT_L16A16_UNORM
:
1748 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1749 case MESA_FORMAT_A16L16_UNORM
:
1752 case MESA_FORMAT_B2G3R3_UNORM
:
1753 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1755 case MESA_FORMAT_R3G3B2_UNORM
:
1756 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1758 case MESA_FORMAT_A4B4G4R4_UNORM
:
1759 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1762 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1765 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1768 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1773 case MESA_FORMAT_R4G4B4A4_UNORM
:
1774 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1777 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1780 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1783 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1788 case MESA_FORMAT_R5G5B5A1_UNORM
:
1789 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1791 case MESA_FORMAT_A2B10G10R10_UNORM
:
1792 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1794 case MESA_FORMAT_A2B10G10R10_UINT
:
1795 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1797 case MESA_FORMAT_A2R10G10B10_UNORM
:
1798 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1800 case MESA_FORMAT_A2R10G10B10_UINT
:
1801 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1803 case MESA_FORMAT_A_UNORM8
:
1804 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1805 case MESA_FORMAT_A_UNORM16
:
1806 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1807 case MESA_FORMAT_L_UNORM8
:
1808 case MESA_FORMAT_L_SRGB8
:
1809 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1810 case MESA_FORMAT_L_UNORM16
:
1811 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1812 case MESA_FORMAT_I_UNORM8
:
1813 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1814 case MESA_FORMAT_I_UNORM16
:
1815 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1817 case MESA_FORMAT_YCBCR
:
1818 return format
== GL_YCBCR_MESA
&&
1819 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1820 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1821 case MESA_FORMAT_YCBCR_REV
:
1822 return format
== GL_YCBCR_MESA
&&
1823 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1824 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1826 case MESA_FORMAT_R_UNORM8
:
1827 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1828 case MESA_FORMAT_R8G8_UNORM
:
1829 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1830 case MESA_FORMAT_G8R8_UNORM
:
1833 case MESA_FORMAT_R_UNORM16
:
1834 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1836 case MESA_FORMAT_R16G16_UNORM
:
1837 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1839 case MESA_FORMAT_G16R16_UNORM
:
1842 case MESA_FORMAT_B10G10R10A2_UNORM
:
1843 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1846 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1847 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1849 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1850 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1853 case MESA_FORMAT_Z_UNORM16
:
1854 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1857 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1860 case MESA_FORMAT_Z_UNORM32
:
1861 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1864 case MESA_FORMAT_S_UINT8
:
1865 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1867 case MESA_FORMAT_SRGB_DXT1
:
1868 case MESA_FORMAT_SRGBA_DXT1
:
1869 case MESA_FORMAT_SRGBA_DXT3
:
1870 case MESA_FORMAT_SRGBA_DXT5
:
1873 case MESA_FORMAT_RGB_FXT1
:
1874 case MESA_FORMAT_RGBA_FXT1
:
1875 case MESA_FORMAT_RGB_DXT1
:
1876 case MESA_FORMAT_RGBA_DXT1
:
1877 case MESA_FORMAT_RGBA_DXT3
:
1878 case MESA_FORMAT_RGBA_DXT5
:
1881 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1882 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1883 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1884 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1887 case MESA_FORMAT_RGBA_FLOAT32
:
1888 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1889 case MESA_FORMAT_RGBA_FLOAT16
:
1890 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1892 case MESA_FORMAT_RGB_FLOAT32
:
1893 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1894 case MESA_FORMAT_RGB_FLOAT16
:
1895 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1897 case MESA_FORMAT_A_FLOAT32
:
1898 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1899 case MESA_FORMAT_A_FLOAT16
:
1900 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1902 case MESA_FORMAT_L_FLOAT32
:
1903 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1904 case MESA_FORMAT_L_FLOAT16
:
1905 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1907 case MESA_FORMAT_LA_FLOAT32
:
1908 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1909 case MESA_FORMAT_LA_FLOAT16
:
1910 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1912 case MESA_FORMAT_I_FLOAT32
:
1913 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1914 case MESA_FORMAT_I_FLOAT16
:
1915 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1917 case MESA_FORMAT_R_FLOAT32
:
1918 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1919 case MESA_FORMAT_R_FLOAT16
:
1920 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1922 case MESA_FORMAT_RG_FLOAT32
:
1923 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1924 case MESA_FORMAT_RG_FLOAT16
:
1925 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1927 case MESA_FORMAT_A_UINT8
:
1928 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1929 case MESA_FORMAT_A_UINT16
:
1930 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1932 case MESA_FORMAT_A_UINT32
:
1933 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1935 case MESA_FORMAT_A_SINT8
:
1936 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1937 case MESA_FORMAT_A_SINT16
:
1938 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1939 case MESA_FORMAT_A_SINT32
:
1940 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1942 case MESA_FORMAT_I_UINT8
:
1943 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1944 case MESA_FORMAT_I_UINT16
:
1945 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1946 case MESA_FORMAT_I_UINT32
:
1947 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1948 case MESA_FORMAT_I_SINT8
:
1949 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1950 case MESA_FORMAT_I_SINT16
:
1951 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1952 case MESA_FORMAT_I_SINT32
:
1953 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1955 case MESA_FORMAT_L_UINT8
:
1956 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1957 case MESA_FORMAT_L_UINT16
:
1958 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1960 case MESA_FORMAT_L_UINT32
:
1961 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1963 case MESA_FORMAT_L_SINT8
:
1964 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1965 case MESA_FORMAT_L_SINT16
:
1966 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1968 case MESA_FORMAT_L_SINT32
:
1969 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1971 case MESA_FORMAT_LA_UINT8
:
1972 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1973 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1974 case MESA_FORMAT_LA_UINT16
:
1975 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1976 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1977 case MESA_FORMAT_LA_UINT32
:
1978 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1979 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1980 case MESA_FORMAT_LA_SINT8
:
1981 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1983 case MESA_FORMAT_LA_SINT16
:
1984 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1986 case MESA_FORMAT_LA_SINT32
:
1987 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1990 case MESA_FORMAT_R_SINT8
:
1991 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1992 case MESA_FORMAT_RG_SINT8
:
1993 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1994 case MESA_FORMAT_RGB_SINT8
:
1995 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1996 case MESA_FORMAT_RGBA_SINT8
:
1997 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1998 case MESA_FORMAT_R_SINT16
:
1999 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2000 case MESA_FORMAT_RG_SINT16
:
2001 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2002 case MESA_FORMAT_RGB_SINT16
:
2003 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2004 case MESA_FORMAT_RGBA_SINT16
:
2005 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2006 case MESA_FORMAT_R_SINT32
:
2007 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2008 case MESA_FORMAT_RG_SINT32
:
2009 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2010 case MESA_FORMAT_RGB_SINT32
:
2011 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2012 case MESA_FORMAT_RGBA_SINT32
:
2013 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2015 case MESA_FORMAT_R_UINT8
:
2016 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2017 case MESA_FORMAT_RG_UINT8
:
2018 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2019 case MESA_FORMAT_RGB_UINT8
:
2020 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2021 case MESA_FORMAT_RGBA_UINT8
:
2022 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2024 case MESA_FORMAT_R_UINT16
:
2025 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2027 case MESA_FORMAT_RG_UINT16
:
2028 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2029 case MESA_FORMAT_RGB_UINT16
:
2030 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2032 case MESA_FORMAT_RGBA_UINT16
:
2033 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2035 case MESA_FORMAT_R_UINT32
:
2036 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2037 case MESA_FORMAT_RG_UINT32
:
2038 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2039 case MESA_FORMAT_RGB_UINT32
:
2040 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2041 case MESA_FORMAT_RGBA_UINT32
:
2042 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2044 case MESA_FORMAT_R_SNORM8
:
2045 return format
== GL_RED
&& type
== GL_BYTE
;
2046 case MESA_FORMAT_R8G8_SNORM
:
2047 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2049 case MESA_FORMAT_X8B8G8R8_SNORM
:
2052 case MESA_FORMAT_A8B8G8R8_SNORM
:
2053 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2056 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2061 case MESA_FORMAT_R8G8B8A8_SNORM
:
2062 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2065 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2070 case MESA_FORMAT_R_SNORM16
:
2071 return format
== GL_RED
&& type
== GL_SHORT
&&
2073 case MESA_FORMAT_R16G16_SNORM
:
2074 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2075 case MESA_FORMAT_RGB_SNORM16
:
2076 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2077 case MESA_FORMAT_RGBA_SNORM16
:
2078 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2079 case MESA_FORMAT_RGBA_UNORM16
:
2080 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2083 case MESA_FORMAT_R_RGTC1_UNORM
:
2084 case MESA_FORMAT_R_RGTC1_SNORM
:
2085 case MESA_FORMAT_RG_RGTC2_UNORM
:
2086 case MESA_FORMAT_RG_RGTC2_SNORM
:
2089 case MESA_FORMAT_L_LATC1_UNORM
:
2090 case MESA_FORMAT_L_LATC1_SNORM
:
2091 case MESA_FORMAT_LA_LATC2_UNORM
:
2092 case MESA_FORMAT_LA_LATC2_SNORM
:
2095 case MESA_FORMAT_ETC1_RGB8
:
2096 case MESA_FORMAT_ETC2_RGB8
:
2097 case MESA_FORMAT_ETC2_SRGB8
:
2098 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2099 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2100 case MESA_FORMAT_ETC2_R11_EAC
:
2101 case MESA_FORMAT_ETC2_RG11_EAC
:
2102 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2103 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2104 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2105 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2108 case MESA_FORMAT_A_SNORM8
:
2109 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2110 case MESA_FORMAT_L_SNORM8
:
2111 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2112 case MESA_FORMAT_L8A8_SNORM
:
2113 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2114 littleEndian
&& !swapBytes
;
2115 case MESA_FORMAT_A8L8_SNORM
:
2116 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2117 !littleEndian
&& !swapBytes
;
2118 case MESA_FORMAT_I_SNORM8
:
2119 return format
== GL_RED
&& type
== GL_BYTE
;
2120 case MESA_FORMAT_A_SNORM16
:
2121 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2122 case MESA_FORMAT_L_SNORM16
:
2123 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2124 case MESA_FORMAT_LA_SNORM16
:
2125 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2126 littleEndian
&& !swapBytes
;
2127 case MESA_FORMAT_I_SNORM16
:
2128 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2131 case MESA_FORMAT_B10G10R10A2_UINT
:
2132 return (format
== GL_BGRA_INTEGER_EXT
&&
2133 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2136 case MESA_FORMAT_R10G10B10A2_UINT
:
2137 return (format
== GL_RGBA_INTEGER_EXT
&&
2138 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2141 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2142 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2145 case MESA_FORMAT_R11G11B10_FLOAT
:
2146 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2149 case MESA_FORMAT_Z_FLOAT32
:
2150 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2152 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2153 return format
== GL_DEPTH_STENCIL
&&
2154 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2156 case MESA_FORMAT_B4G4R4X4_UNORM
:
2157 case MESA_FORMAT_B5G5R5X1_UNORM
:
2158 case MESA_FORMAT_R8G8B8X8_SNORM
:
2159 case MESA_FORMAT_R8G8B8X8_SRGB
:
2160 case MESA_FORMAT_X8B8G8R8_SRGB
:
2161 case MESA_FORMAT_RGBX_UINT8
:
2162 case MESA_FORMAT_RGBX_SINT8
:
2163 case MESA_FORMAT_B10G10R10X2_UNORM
:
2164 case MESA_FORMAT_R10G10B10X2_UNORM
:
2165 case MESA_FORMAT_RGBX_UNORM16
:
2166 case MESA_FORMAT_RGBX_SNORM16
:
2167 case MESA_FORMAT_RGBX_FLOAT16
:
2168 case MESA_FORMAT_RGBX_UINT16
:
2169 case MESA_FORMAT_RGBX_SINT16
:
2170 case MESA_FORMAT_RGBX_FLOAT32
:
2171 case MESA_FORMAT_RGBX_UINT32
:
2172 case MESA_FORMAT_RGBX_SINT32
:
2175 case MESA_FORMAT_R10G10B10A2_UNORM
:
2176 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2179 case MESA_FORMAT_G8R8_SNORM
:
2180 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2183 case MESA_FORMAT_G16R16_SNORM
:
2184 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2187 case MESA_FORMAT_B8G8R8X8_SRGB
:
2188 case MESA_FORMAT_X8R8G8B8_SRGB
: