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_OTHER
193 extern enum mesa_format_layout
194 _mesa_get_format_layout(mesa_format format
)
196 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
202 * Return the data type (or more specifically, the data representation)
203 * for the given format.
204 * The return value will be one of:
205 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
206 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
207 * GL_UNSIGNED_INT = an ordinary unsigned integer
208 * GL_INT = an ordinary signed integer
209 * GL_FLOAT = an ordinary float
212 _mesa_get_format_datatype(mesa_format format
)
214 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
215 return info
->DataType
;
219 get_base_format_for_array_format(mesa_array_format format
)
224 _mesa_array_format_get_swizzle(format
, swizzle
);
225 num_channels
= _mesa_array_format_get_num_channels(format
);
227 switch (num_channels
) {
229 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
230 * This is not really a problem for now because we only create array
231 * formats from GL format/type combinations, and these cannot specify
238 if (swizzle
[0] == 0 &&
242 return GL_LUMINANCE_ALPHA
;
243 if (swizzle
[0] == 1 &&
247 return GL_LUMINANCE_ALPHA
;
248 if (swizzle
[0] == 0 &&
253 if (swizzle
[0] == 1 &&
260 if (swizzle
[0] == 0 &&
265 if (swizzle
[0] == 0 &&
270 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
272 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
274 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
276 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
281 unreachable("Unsupported format");
285 * Return the basic format for the given type. The result will be one of
286 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
287 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
288 * This functions accepts a mesa_format or a mesa_array_format.
291 _mesa_get_format_base_format(uint32_t format
)
293 if (!_mesa_format_is_mesa_array_format(format
)) {
294 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
295 return info
->BaseFormat
;
297 return get_base_format_for_array_format(format
);
303 * Return the block size (in pixels) for the given format. Normally
304 * the block size is 1x1. But compressed formats will have block sizes
305 * of 4x4 or 8x4 pixels, etc.
306 * \param bw returns block width in pixels
307 * \param bh returns block height in pixels
310 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
312 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
313 *bw
= info
->BlockWidth
;
314 *bh
= info
->BlockHeight
;
319 * Returns the an array of four numbers representing the transformation
320 * from the RGBA or SZ colorspace to the given format. For array formats,
321 * the i'th RGBA component is given by:
323 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
324 * comp = data[swizzle[i]];
325 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
327 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
329 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
330 * // data does not contain a channel of this format
332 * For packed formats, the swizzle gives the number of components left of
333 * the least significant bit.
335 * Compressed formats have no swizzle.
338 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
340 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
341 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
345 _mesa_array_format_flip_channels(mesa_array_format format
)
350 num_channels
= _mesa_array_format_get_num_channels(format
);
351 _mesa_array_format_get_swizzle(format
, swizzle
);
353 if (num_channels
== 1)
356 if (num_channels
== 2) {
357 /* Assert that the swizzle makes sense for 2 channels */
358 for (unsigned i
= 0; i
< 4; i
++)
359 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
361 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
362 _mesa_array_format_set_swizzle(&format
,
363 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
364 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
368 if (num_channels
== 4) {
369 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
370 _mesa_array_format_set_swizzle(&format
,
371 flip
[swizzle
[0]], flip
[swizzle
[1]],
372 flip
[swizzle
[2]], flip
[swizzle
[3]]);
376 unreachable("Invalid array format");
380 _mesa_format_to_array_format(mesa_format format
)
382 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
383 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
384 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
385 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
387 return info
->ArrayFormat
;
390 static struct hash_table
*format_array_format_table
;
391 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
394 array_formats_equal(const void *a
, const void *b
)
396 return (intptr_t)a
== (intptr_t)b
;
400 format_array_format_table_init(void)
402 const struct gl_format_info
*info
;
403 mesa_array_format array_format
;
406 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
407 array_formats_equal
);
409 if (!format_array_format_table
) {
410 _mesa_error_no_memory(__func__
);
414 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
415 info
= _mesa_get_format_info(f
);
416 if (!info
->ArrayFormat
)
419 if (_mesa_little_endian()) {
420 array_format
= info
->ArrayFormat
;
422 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
425 /* This can happen and does for some of the BGR formats. Let's take
426 * the first one in the list.
428 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
430 (void *)(intptr_t)array_format
))
433 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
435 (void *)(intptr_t)array_format
,
436 (void *)(intptr_t)f
);
441 _mesa_format_from_array_format(uint32_t array_format
)
443 struct hash_entry
*entry
;
445 assert(_mesa_format_is_mesa_array_format(array_format
));
447 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
449 if (!format_array_format_table
) {
450 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
451 format_array_format_table_exists
= once_flag_init
;
452 return MESA_FORMAT_NONE
;
455 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
457 (void *)(intptr_t)array_format
);
459 return (intptr_t)entry
->data
;
461 return MESA_FORMAT_NONE
;
464 /** Is the given format a compressed format? */
466 _mesa_is_format_compressed(mesa_format format
)
468 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
469 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
474 * Determine if the given format represents a packed depth/stencil buffer.
477 _mesa_is_format_packed_depth_stencil(mesa_format format
)
479 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
481 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
486 * Is the given format a signed/unsigned integer color format?
489 _mesa_is_format_integer_color(mesa_format format
)
491 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
492 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
493 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
494 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
495 info
->BaseFormat
!= GL_STENCIL_INDEX
;
500 * Is the given format an unsigned integer format?
503 _mesa_is_format_unsigned(mesa_format format
)
505 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
506 return _mesa_is_type_unsigned(info
->DataType
);
511 * Does the given format store signed values?
514 _mesa_is_format_signed(mesa_format format
)
516 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
517 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
518 /* these packed float formats only store unsigned values */
522 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
523 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
524 info
->DataType
== GL_INT
||
525 info
->DataType
== GL_FLOAT
);
530 * Is the given format an integer format?
533 _mesa_is_format_integer(mesa_format format
)
535 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
536 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
541 * Return true if the given format is a color format.
544 _mesa_is_format_color_format(mesa_format format
)
546 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
547 switch (info
->BaseFormat
) {
548 case GL_DEPTH_COMPONENT
:
549 case GL_STENCIL_INDEX
:
550 case GL_DEPTH_STENCIL
:
559 * Return color encoding for given format.
560 * \return GL_LINEAR or GL_SRGB
563 _mesa_get_format_color_encoding(mesa_format format
)
565 /* XXX this info should be encoded in gl_format_info */
567 case MESA_FORMAT_BGR_SRGB8
:
568 case MESA_FORMAT_A8B8G8R8_SRGB
:
569 case MESA_FORMAT_B8G8R8A8_SRGB
:
570 case MESA_FORMAT_A8R8G8B8_SRGB
:
571 case MESA_FORMAT_R8G8B8A8_SRGB
:
572 case MESA_FORMAT_L_SRGB8
:
573 case MESA_FORMAT_L8A8_SRGB
:
574 case MESA_FORMAT_A8L8_SRGB
:
575 case MESA_FORMAT_SRGB_DXT1
:
576 case MESA_FORMAT_SRGBA_DXT1
:
577 case MESA_FORMAT_SRGBA_DXT3
:
578 case MESA_FORMAT_SRGBA_DXT5
:
579 case MESA_FORMAT_R8G8B8X8_SRGB
:
580 case MESA_FORMAT_ETC2_SRGB8
:
581 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
582 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
583 case MESA_FORMAT_B8G8R8X8_SRGB
:
584 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
593 * Return TRUE if format is an ETC2 compressed format specified
594 * by GL_ARB_ES3_compatibility.
597 _mesa_is_format_etc2(mesa_format format
)
600 case MESA_FORMAT_ETC2_RGB8
:
601 case MESA_FORMAT_ETC2_SRGB8
:
602 case MESA_FORMAT_ETC2_RGBA8_EAC
:
603 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
604 case MESA_FORMAT_ETC2_R11_EAC
:
605 case MESA_FORMAT_ETC2_RG11_EAC
:
606 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
607 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
608 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
609 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
618 * For an sRGB format, return the corresponding linear color space format.
619 * For non-sRGB formats, return the format as-is.
622 _mesa_get_srgb_format_linear(mesa_format format
)
625 case MESA_FORMAT_BGR_SRGB8
:
626 format
= MESA_FORMAT_BGR_UNORM8
;
628 case MESA_FORMAT_A8B8G8R8_SRGB
:
629 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
631 case MESA_FORMAT_B8G8R8A8_SRGB
:
632 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
634 case MESA_FORMAT_A8R8G8B8_SRGB
:
635 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
637 case MESA_FORMAT_R8G8B8A8_SRGB
:
638 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
640 case MESA_FORMAT_L_SRGB8
:
641 format
= MESA_FORMAT_L_UNORM8
;
643 case MESA_FORMAT_L8A8_SRGB
:
644 format
= MESA_FORMAT_L8A8_UNORM
;
646 case MESA_FORMAT_A8L8_SRGB
:
647 format
= MESA_FORMAT_A8L8_UNORM
;
649 case MESA_FORMAT_SRGB_DXT1
:
650 format
= MESA_FORMAT_RGB_DXT1
;
652 case MESA_FORMAT_SRGBA_DXT1
:
653 format
= MESA_FORMAT_RGBA_DXT1
;
655 case MESA_FORMAT_SRGBA_DXT3
:
656 format
= MESA_FORMAT_RGBA_DXT3
;
658 case MESA_FORMAT_SRGBA_DXT5
:
659 format
= MESA_FORMAT_RGBA_DXT5
;
661 case MESA_FORMAT_R8G8B8X8_SRGB
:
662 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
664 case MESA_FORMAT_X8B8G8R8_SRGB
:
665 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
667 case MESA_FORMAT_ETC2_SRGB8
:
668 format
= MESA_FORMAT_ETC2_RGB8
;
670 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
671 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
673 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
674 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
676 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
677 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
679 case MESA_FORMAT_B8G8R8X8_SRGB
:
680 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
682 case MESA_FORMAT_X8R8G8B8_SRGB
:
683 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
693 * If the given format is a compressed format, return a corresponding
694 * uncompressed format.
697 _mesa_get_uncompressed_format(mesa_format format
)
700 case MESA_FORMAT_RGB_FXT1
:
701 return MESA_FORMAT_BGR_UNORM8
;
702 case MESA_FORMAT_RGBA_FXT1
:
703 return MESA_FORMAT_A8B8G8R8_UNORM
;
704 case MESA_FORMAT_RGB_DXT1
:
705 case MESA_FORMAT_SRGB_DXT1
:
706 return MESA_FORMAT_BGR_UNORM8
;
707 case MESA_FORMAT_RGBA_DXT1
:
708 case MESA_FORMAT_SRGBA_DXT1
:
709 return MESA_FORMAT_A8B8G8R8_UNORM
;
710 case MESA_FORMAT_RGBA_DXT3
:
711 case MESA_FORMAT_SRGBA_DXT3
:
712 return MESA_FORMAT_A8B8G8R8_UNORM
;
713 case MESA_FORMAT_RGBA_DXT5
:
714 case MESA_FORMAT_SRGBA_DXT5
:
715 return MESA_FORMAT_A8B8G8R8_UNORM
;
716 case MESA_FORMAT_R_RGTC1_UNORM
:
717 return MESA_FORMAT_R_UNORM8
;
718 case MESA_FORMAT_R_RGTC1_SNORM
:
719 return MESA_FORMAT_R_SNORM8
;
720 case MESA_FORMAT_RG_RGTC2_UNORM
:
721 return MESA_FORMAT_R8G8_UNORM
;
722 case MESA_FORMAT_RG_RGTC2_SNORM
:
723 return MESA_FORMAT_R8G8_SNORM
;
724 case MESA_FORMAT_L_LATC1_UNORM
:
725 return MESA_FORMAT_L_UNORM8
;
726 case MESA_FORMAT_L_LATC1_SNORM
:
727 return MESA_FORMAT_L_SNORM8
;
728 case MESA_FORMAT_LA_LATC2_UNORM
:
729 return MESA_FORMAT_L8A8_UNORM
;
730 case MESA_FORMAT_LA_LATC2_SNORM
:
731 return MESA_FORMAT_L8A8_SNORM
;
732 case MESA_FORMAT_ETC1_RGB8
:
733 case MESA_FORMAT_ETC2_RGB8
:
734 case MESA_FORMAT_ETC2_SRGB8
:
735 return MESA_FORMAT_BGR_UNORM8
;
736 case MESA_FORMAT_ETC2_RGBA8_EAC
:
737 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
738 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
739 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
740 return MESA_FORMAT_A8B8G8R8_UNORM
;
741 case MESA_FORMAT_ETC2_R11_EAC
:
742 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
743 return MESA_FORMAT_R_UNORM16
;
744 case MESA_FORMAT_ETC2_RG11_EAC
:
745 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
746 return MESA_FORMAT_R16G16_UNORM
;
747 case MESA_FORMAT_BPTC_RGBA_UNORM
:
748 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
749 return MESA_FORMAT_A8B8G8R8_UNORM
;
750 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
751 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
752 return MESA_FORMAT_RGB_FLOAT32
;
755 assert(!_mesa_is_format_compressed(format
));
763 _mesa_format_num_components(mesa_format format
)
765 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
766 return ((info
->RedBits
> 0) +
767 (info
->GreenBits
> 0) +
768 (info
->BlueBits
> 0) +
769 (info
->AlphaBits
> 0) +
770 (info
->LuminanceBits
> 0) +
771 (info
->IntensityBits
> 0) +
772 (info
->DepthBits
> 0) +
773 (info
->StencilBits
> 0));
778 * Returns true if a color format has data stored in the R/G/B/A channels,
779 * given an index from 0 to 3.
782 _mesa_format_has_color_component(mesa_format format
, int component
)
784 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
786 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
787 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
788 info
->BaseFormat
!= GL_STENCIL_INDEX
);
792 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
794 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
796 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
798 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
800 assert(!"Invalid color component: must be 0..3");
807 * Return number of bytes needed to store an image of the given size
808 * in the given format.
811 _mesa_format_image_size(mesa_format format
, GLsizei width
,
812 GLsizei height
, GLsizei depth
)
814 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
815 /* Strictly speaking, a conditional isn't needed here */
816 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
817 /* compressed format (2D only for now) */
818 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
819 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
820 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
821 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
826 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
833 * Same as _mesa_format_image_size() but returns a 64-bit value to
834 * accommodate very large textures.
837 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
838 GLsizei height
, GLsizei depth
)
840 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
841 /* Strictly speaking, a conditional isn't needed here */
842 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
843 /* compressed format (2D only for now) */
844 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
845 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
846 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
847 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
852 const uint64_t sz
= ((uint64_t) width
*
855 info
->BytesPerBlock
);
863 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
865 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
866 /* Strictly speaking, a conditional isn't needed here */
867 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
868 /* compressed format */
869 const GLuint bw
= info
->BlockWidth
;
870 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
871 const GLint stride
= wblocks
* info
->BytesPerBlock
;
875 const GLint stride
= width
* info
->BytesPerBlock
;
882 * Debug/test: check that all formats are handled in the
883 * _mesa_format_to_type_and_comps() function. When new pixel formats
884 * are added to Mesa, that function needs to be updated.
885 * This is a no-op after the first call.
888 check_format_to_type_and_comps(void)
892 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
895 /* This function will emit a problem/warning if the format is
898 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
903 * Do sanity checking of the format info table.
906 _mesa_test_formats(void)
910 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
912 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
913 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
916 assert(info
->Name
== i
);
918 if (info
->Name
== MESA_FORMAT_NONE
)
921 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
922 if (info
->RedBits
> 0) {
923 GLuint t
= info
->RedBits
+ info
->GreenBits
924 + info
->BlueBits
+ info
->AlphaBits
;
925 assert(t
/ 8 <= info
->BytesPerBlock
);
930 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
931 info
->DataType
== GL_SIGNED_NORMALIZED
||
932 info
->DataType
== GL_UNSIGNED_INT
||
933 info
->DataType
== GL_INT
||
934 info
->DataType
== GL_FLOAT
||
935 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
936 info
->DataType
== GL_NONE
);
938 if (info
->BaseFormat
== GL_RGB
) {
939 assert(info
->RedBits
> 0);
940 assert(info
->GreenBits
> 0);
941 assert(info
->BlueBits
> 0);
942 assert(info
->AlphaBits
== 0);
943 assert(info
->LuminanceBits
== 0);
944 assert(info
->IntensityBits
== 0);
946 else if (info
->BaseFormat
== GL_RGBA
) {
947 assert(info
->RedBits
> 0);
948 assert(info
->GreenBits
> 0);
949 assert(info
->BlueBits
> 0);
950 assert(info
->AlphaBits
> 0);
951 assert(info
->LuminanceBits
== 0);
952 assert(info
->IntensityBits
== 0);
954 else if (info
->BaseFormat
== GL_RG
) {
955 assert(info
->RedBits
> 0);
956 assert(info
->GreenBits
> 0);
957 assert(info
->BlueBits
== 0);
958 assert(info
->AlphaBits
== 0);
959 assert(info
->LuminanceBits
== 0);
960 assert(info
->IntensityBits
== 0);
962 else if (info
->BaseFormat
== GL_RED
) {
963 assert(info
->RedBits
> 0);
964 assert(info
->GreenBits
== 0);
965 assert(info
->BlueBits
== 0);
966 assert(info
->AlphaBits
== 0);
967 assert(info
->LuminanceBits
== 0);
968 assert(info
->IntensityBits
== 0);
970 else if (info
->BaseFormat
== GL_LUMINANCE
) {
971 assert(info
->RedBits
== 0);
972 assert(info
->GreenBits
== 0);
973 assert(info
->BlueBits
== 0);
974 assert(info
->AlphaBits
== 0);
975 assert(info
->LuminanceBits
> 0);
976 assert(info
->IntensityBits
== 0);
978 else if (info
->BaseFormat
== GL_INTENSITY
) {
979 assert(info
->RedBits
== 0);
980 assert(info
->GreenBits
== 0);
981 assert(info
->BlueBits
== 0);
982 assert(info
->AlphaBits
== 0);
983 assert(info
->LuminanceBits
== 0);
984 assert(info
->IntensityBits
> 0);
988 check_format_to_type_and_comps();
994 * Return datatype and number of components per texel for the given mesa_format.
995 * Only used for mipmap generation code.
998 _mesa_format_to_type_and_comps(mesa_format format
,
999 GLenum
*datatype
, GLuint
*comps
)
1002 case MESA_FORMAT_A8B8G8R8_UNORM
:
1003 case MESA_FORMAT_R8G8B8A8_UNORM
:
1004 case MESA_FORMAT_B8G8R8A8_UNORM
:
1005 case MESA_FORMAT_A8R8G8B8_UNORM
:
1006 case MESA_FORMAT_X8B8G8R8_UNORM
:
1007 case MESA_FORMAT_R8G8B8X8_UNORM
:
1008 case MESA_FORMAT_B8G8R8X8_UNORM
:
1009 case MESA_FORMAT_X8R8G8B8_UNORM
:
1010 *datatype
= GL_UNSIGNED_BYTE
;
1013 case MESA_FORMAT_BGR_UNORM8
:
1014 case MESA_FORMAT_RGB_UNORM8
:
1015 *datatype
= GL_UNSIGNED_BYTE
;
1018 case MESA_FORMAT_B5G6R5_UNORM
:
1019 case MESA_FORMAT_R5G6B5_UNORM
:
1020 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1024 case MESA_FORMAT_B4G4R4A4_UNORM
:
1025 case MESA_FORMAT_A4R4G4B4_UNORM
:
1026 case MESA_FORMAT_B4G4R4X4_UNORM
:
1027 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1031 case MESA_FORMAT_B5G5R5A1_UNORM
:
1032 case MESA_FORMAT_A1R5G5B5_UNORM
:
1033 case MESA_FORMAT_B5G5R5X1_UNORM
:
1034 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1038 case MESA_FORMAT_B10G10R10A2_UNORM
:
1039 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1043 case MESA_FORMAT_A1B5G5R5_UNORM
:
1044 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1048 case MESA_FORMAT_L4A4_UNORM
:
1049 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1053 case MESA_FORMAT_L8A8_UNORM
:
1054 case MESA_FORMAT_A8L8_UNORM
:
1055 case MESA_FORMAT_R8G8_UNORM
:
1056 case MESA_FORMAT_G8R8_UNORM
:
1057 *datatype
= GL_UNSIGNED_BYTE
;
1061 case MESA_FORMAT_L16A16_UNORM
:
1062 case MESA_FORMAT_A16L16_UNORM
:
1063 case MESA_FORMAT_R16G16_UNORM
:
1064 case MESA_FORMAT_G16R16_UNORM
:
1065 *datatype
= GL_UNSIGNED_SHORT
;
1069 case MESA_FORMAT_R_UNORM16
:
1070 case MESA_FORMAT_A_UNORM16
:
1071 case MESA_FORMAT_L_UNORM16
:
1072 case MESA_FORMAT_I_UNORM16
:
1073 *datatype
= GL_UNSIGNED_SHORT
;
1077 case MESA_FORMAT_R3G3B2_UNORM
:
1078 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1081 case MESA_FORMAT_A4B4G4R4_UNORM
:
1082 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1086 case MESA_FORMAT_R4G4B4A4_UNORM
:
1087 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1090 case MESA_FORMAT_R5G5B5A1_UNORM
:
1091 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1094 case MESA_FORMAT_A2B10G10R10_UNORM
:
1095 case MESA_FORMAT_A2B10G10R10_UINT
:
1096 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1099 case MESA_FORMAT_A2R10G10B10_UNORM
:
1100 case MESA_FORMAT_A2R10G10B10_UINT
:
1101 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1105 case MESA_FORMAT_B2G3R3_UNORM
:
1106 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1110 case MESA_FORMAT_A_UNORM8
:
1111 case MESA_FORMAT_L_UNORM8
:
1112 case MESA_FORMAT_I_UNORM8
:
1113 case MESA_FORMAT_R_UNORM8
:
1114 case MESA_FORMAT_S_UINT8
:
1115 *datatype
= GL_UNSIGNED_BYTE
;
1119 case MESA_FORMAT_YCBCR
:
1120 case MESA_FORMAT_YCBCR_REV
:
1121 *datatype
= GL_UNSIGNED_SHORT
;
1125 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1126 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1130 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1131 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1135 case MESA_FORMAT_Z_UNORM16
:
1136 *datatype
= GL_UNSIGNED_SHORT
;
1140 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1141 *datatype
= GL_UNSIGNED_INT
;
1145 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1146 *datatype
= GL_UNSIGNED_INT
;
1150 case MESA_FORMAT_Z_UNORM32
:
1151 *datatype
= GL_UNSIGNED_INT
;
1155 case MESA_FORMAT_Z_FLOAT32
:
1156 *datatype
= GL_FLOAT
;
1160 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1161 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1165 case MESA_FORMAT_R_SNORM8
:
1166 case MESA_FORMAT_A_SNORM8
:
1167 case MESA_FORMAT_L_SNORM8
:
1168 case MESA_FORMAT_I_SNORM8
:
1169 *datatype
= GL_BYTE
;
1172 case MESA_FORMAT_R8G8_SNORM
:
1173 case MESA_FORMAT_L8A8_SNORM
:
1174 case MESA_FORMAT_A8L8_SNORM
:
1175 *datatype
= GL_BYTE
;
1178 case MESA_FORMAT_A8B8G8R8_SNORM
:
1179 case MESA_FORMAT_R8G8B8A8_SNORM
:
1180 case MESA_FORMAT_X8B8G8R8_SNORM
:
1181 *datatype
= GL_BYTE
;
1185 case MESA_FORMAT_RGBA_UNORM16
:
1186 *datatype
= GL_UNSIGNED_SHORT
;
1190 case MESA_FORMAT_R_SNORM16
:
1191 case MESA_FORMAT_A_SNORM16
:
1192 case MESA_FORMAT_L_SNORM16
:
1193 case MESA_FORMAT_I_SNORM16
:
1194 *datatype
= GL_SHORT
;
1197 case MESA_FORMAT_R16G16_SNORM
:
1198 case MESA_FORMAT_LA_SNORM16
:
1199 *datatype
= GL_SHORT
;
1202 case MESA_FORMAT_RGB_SNORM16
:
1203 *datatype
= GL_SHORT
;
1206 case MESA_FORMAT_RGBA_SNORM16
:
1207 *datatype
= GL_SHORT
;
1211 case MESA_FORMAT_BGR_SRGB8
:
1212 *datatype
= GL_UNSIGNED_BYTE
;
1215 case MESA_FORMAT_A8B8G8R8_SRGB
:
1216 case MESA_FORMAT_B8G8R8A8_SRGB
:
1217 case MESA_FORMAT_A8R8G8B8_SRGB
:
1218 case MESA_FORMAT_R8G8B8A8_SRGB
:
1219 *datatype
= GL_UNSIGNED_BYTE
;
1222 case MESA_FORMAT_L_SRGB8
:
1223 *datatype
= GL_UNSIGNED_BYTE
;
1226 case MESA_FORMAT_L8A8_SRGB
:
1227 case MESA_FORMAT_A8L8_SRGB
:
1228 *datatype
= GL_UNSIGNED_BYTE
;
1232 case MESA_FORMAT_RGB_FXT1
:
1233 case MESA_FORMAT_RGBA_FXT1
:
1234 case MESA_FORMAT_RGB_DXT1
:
1235 case MESA_FORMAT_RGBA_DXT1
:
1236 case MESA_FORMAT_RGBA_DXT3
:
1237 case MESA_FORMAT_RGBA_DXT5
:
1238 case MESA_FORMAT_SRGB_DXT1
:
1239 case MESA_FORMAT_SRGBA_DXT1
:
1240 case MESA_FORMAT_SRGBA_DXT3
:
1241 case MESA_FORMAT_SRGBA_DXT5
:
1242 case MESA_FORMAT_R_RGTC1_UNORM
:
1243 case MESA_FORMAT_R_RGTC1_SNORM
:
1244 case MESA_FORMAT_RG_RGTC2_UNORM
:
1245 case MESA_FORMAT_RG_RGTC2_SNORM
:
1246 case MESA_FORMAT_L_LATC1_UNORM
:
1247 case MESA_FORMAT_L_LATC1_SNORM
:
1248 case MESA_FORMAT_LA_LATC2_UNORM
:
1249 case MESA_FORMAT_LA_LATC2_SNORM
:
1250 case MESA_FORMAT_ETC1_RGB8
:
1251 case MESA_FORMAT_ETC2_RGB8
:
1252 case MESA_FORMAT_ETC2_SRGB8
:
1253 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1254 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1255 case MESA_FORMAT_ETC2_R11_EAC
:
1256 case MESA_FORMAT_ETC2_RG11_EAC
:
1257 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1258 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1259 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1260 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1261 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1262 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1263 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1264 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1265 /* XXX generate error instead? */
1266 *datatype
= GL_UNSIGNED_BYTE
;
1270 case MESA_FORMAT_RGBA_FLOAT32
:
1271 *datatype
= GL_FLOAT
;
1274 case MESA_FORMAT_RGBA_FLOAT16
:
1275 *datatype
= GL_HALF_FLOAT_ARB
;
1278 case MESA_FORMAT_RGB_FLOAT32
:
1279 *datatype
= GL_FLOAT
;
1282 case MESA_FORMAT_RGB_FLOAT16
:
1283 *datatype
= GL_HALF_FLOAT_ARB
;
1286 case MESA_FORMAT_LA_FLOAT32
:
1287 case MESA_FORMAT_RG_FLOAT32
:
1288 *datatype
= GL_FLOAT
;
1291 case MESA_FORMAT_LA_FLOAT16
:
1292 case MESA_FORMAT_RG_FLOAT16
:
1293 *datatype
= GL_HALF_FLOAT_ARB
;
1296 case MESA_FORMAT_A_FLOAT32
:
1297 case MESA_FORMAT_L_FLOAT32
:
1298 case MESA_FORMAT_I_FLOAT32
:
1299 case MESA_FORMAT_R_FLOAT32
:
1300 *datatype
= GL_FLOAT
;
1303 case MESA_FORMAT_A_FLOAT16
:
1304 case MESA_FORMAT_L_FLOAT16
:
1305 case MESA_FORMAT_I_FLOAT16
:
1306 case MESA_FORMAT_R_FLOAT16
:
1307 *datatype
= GL_HALF_FLOAT_ARB
;
1311 case MESA_FORMAT_A_UINT8
:
1312 case MESA_FORMAT_L_UINT8
:
1313 case MESA_FORMAT_I_UINT8
:
1314 *datatype
= GL_UNSIGNED_BYTE
;
1317 case MESA_FORMAT_LA_UINT8
:
1318 *datatype
= GL_UNSIGNED_BYTE
;
1322 case MESA_FORMAT_A_UINT16
:
1323 case MESA_FORMAT_L_UINT16
:
1324 case MESA_FORMAT_I_UINT16
:
1325 *datatype
= GL_UNSIGNED_SHORT
;
1328 case MESA_FORMAT_LA_UINT16
:
1329 *datatype
= GL_UNSIGNED_SHORT
;
1332 case MESA_FORMAT_A_UINT32
:
1333 case MESA_FORMAT_L_UINT32
:
1334 case MESA_FORMAT_I_UINT32
:
1335 *datatype
= GL_UNSIGNED_INT
;
1338 case MESA_FORMAT_LA_UINT32
:
1339 *datatype
= GL_UNSIGNED_INT
;
1342 case MESA_FORMAT_A_SINT8
:
1343 case MESA_FORMAT_L_SINT8
:
1344 case MESA_FORMAT_I_SINT8
:
1345 *datatype
= GL_BYTE
;
1348 case MESA_FORMAT_LA_SINT8
:
1349 *datatype
= GL_BYTE
;
1353 case MESA_FORMAT_A_SINT16
:
1354 case MESA_FORMAT_L_SINT16
:
1355 case MESA_FORMAT_I_SINT16
:
1356 *datatype
= GL_SHORT
;
1359 case MESA_FORMAT_LA_SINT16
:
1360 *datatype
= GL_SHORT
;
1364 case MESA_FORMAT_A_SINT32
:
1365 case MESA_FORMAT_L_SINT32
:
1366 case MESA_FORMAT_I_SINT32
:
1370 case MESA_FORMAT_LA_SINT32
:
1375 case MESA_FORMAT_R_SINT8
:
1376 *datatype
= GL_BYTE
;
1379 case MESA_FORMAT_RG_SINT8
:
1380 *datatype
= GL_BYTE
;
1383 case MESA_FORMAT_RGB_SINT8
:
1384 *datatype
= GL_BYTE
;
1387 case MESA_FORMAT_RGBA_SINT8
:
1388 *datatype
= GL_BYTE
;
1391 case MESA_FORMAT_R_SINT16
:
1392 *datatype
= GL_SHORT
;
1395 case MESA_FORMAT_RG_SINT16
:
1396 *datatype
= GL_SHORT
;
1399 case MESA_FORMAT_RGB_SINT16
:
1400 *datatype
= GL_SHORT
;
1403 case MESA_FORMAT_RGBA_SINT16
:
1404 *datatype
= GL_SHORT
;
1407 case MESA_FORMAT_R_SINT32
:
1411 case MESA_FORMAT_RG_SINT32
:
1415 case MESA_FORMAT_RGB_SINT32
:
1419 case MESA_FORMAT_RGBA_SINT32
:
1425 * \name Non-normalized unsigned integer formats.
1427 case MESA_FORMAT_R_UINT8
:
1428 *datatype
= GL_UNSIGNED_BYTE
;
1431 case MESA_FORMAT_RG_UINT8
:
1432 *datatype
= GL_UNSIGNED_BYTE
;
1435 case MESA_FORMAT_RGB_UINT8
:
1436 *datatype
= GL_UNSIGNED_BYTE
;
1439 case MESA_FORMAT_RGBA_UINT8
:
1440 *datatype
= GL_UNSIGNED_BYTE
;
1443 case MESA_FORMAT_R_UINT16
:
1444 *datatype
= GL_UNSIGNED_SHORT
;
1447 case MESA_FORMAT_RG_UINT16
:
1448 *datatype
= GL_UNSIGNED_SHORT
;
1451 case MESA_FORMAT_RGB_UINT16
:
1452 *datatype
= GL_UNSIGNED_SHORT
;
1455 case MESA_FORMAT_RGBA_UINT16
:
1456 *datatype
= GL_UNSIGNED_SHORT
;
1459 case MESA_FORMAT_R_UINT32
:
1460 *datatype
= GL_UNSIGNED_INT
;
1463 case MESA_FORMAT_RG_UINT32
:
1464 *datatype
= GL_UNSIGNED_INT
;
1467 case MESA_FORMAT_RGB_UINT32
:
1468 *datatype
= GL_UNSIGNED_INT
;
1471 case MESA_FORMAT_RGBA_UINT32
:
1472 *datatype
= GL_UNSIGNED_INT
;
1476 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1477 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1481 case MESA_FORMAT_R11G11B10_FLOAT
:
1482 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1486 case MESA_FORMAT_B10G10R10A2_UINT
:
1487 case MESA_FORMAT_R10G10B10A2_UINT
:
1488 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1492 case MESA_FORMAT_R8G8B8X8_SRGB
:
1493 case MESA_FORMAT_X8B8G8R8_SRGB
:
1494 case MESA_FORMAT_RGBX_UINT8
:
1495 *datatype
= GL_UNSIGNED_BYTE
;
1499 case MESA_FORMAT_R8G8B8X8_SNORM
:
1500 case MESA_FORMAT_RGBX_SINT8
:
1501 *datatype
= GL_BYTE
;
1505 case MESA_FORMAT_B10G10R10X2_UNORM
:
1506 case MESA_FORMAT_R10G10B10X2_UNORM
:
1507 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1511 case MESA_FORMAT_RGBX_UNORM16
:
1512 case MESA_FORMAT_RGBX_UINT16
:
1513 *datatype
= GL_UNSIGNED_SHORT
;
1517 case MESA_FORMAT_RGBX_SNORM16
:
1518 case MESA_FORMAT_RGBX_SINT16
:
1519 *datatype
= GL_SHORT
;
1523 case MESA_FORMAT_RGBX_FLOAT16
:
1524 *datatype
= GL_HALF_FLOAT
;
1528 case MESA_FORMAT_RGBX_FLOAT32
:
1529 *datatype
= GL_FLOAT
;
1533 case MESA_FORMAT_RGBX_UINT32
:
1534 *datatype
= GL_UNSIGNED_INT
;
1538 case MESA_FORMAT_RGBX_SINT32
:
1543 case MESA_FORMAT_R10G10B10A2_UNORM
:
1544 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1548 case MESA_FORMAT_G8R8_SNORM
:
1549 *datatype
= GL_BYTE
;
1553 case MESA_FORMAT_G16R16_SNORM
:
1554 *datatype
= GL_SHORT
;
1558 case MESA_FORMAT_B8G8R8X8_SRGB
:
1559 case MESA_FORMAT_X8R8G8B8_SRGB
:
1560 *datatype
= GL_UNSIGNED_BYTE
;
1564 case MESA_FORMAT_COUNT
:
1568 case MESA_FORMAT_NONE
:
1569 /* For debug builds, warn if any formats are not handled */
1573 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1574 _mesa_get_format_name(format
));
1581 * Check if a mesa_format exactly matches a GL format/type combination
1582 * such that we can use memcpy() from one to the other.
1583 * \param mesa_format a MESA_FORMAT_x value
1584 * \param format the user-specified image format
1585 * \param type the user-specified image datatype
1586 * \param swapBytes typically the current pixel pack/unpack byteswap state
1587 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1590 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1591 GLenum format
, GLenum type
,
1592 GLboolean swapBytes
)
1594 const GLboolean littleEndian
= _mesa_little_endian();
1596 /* Note: When reading a GL format/type combination, the format lists channel
1597 * assignments from most significant channel in the type to least
1598 * significant. A type with _REV indicates that the assignments are
1599 * swapped, so they are listed from least significant to most significant.
1601 * For sanity, please keep this switch statement ordered the same as the
1602 * enums in formats.h.
1605 switch (mesa_format
) {
1607 case MESA_FORMAT_NONE
:
1608 case MESA_FORMAT_COUNT
:
1611 case MESA_FORMAT_A8B8G8R8_UNORM
:
1612 case MESA_FORMAT_A8B8G8R8_SRGB
:
1613 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1616 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1619 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1622 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1626 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1630 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1635 case MESA_FORMAT_R8G8B8A8_UNORM
:
1636 case MESA_FORMAT_R8G8B8A8_SRGB
:
1637 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1641 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1644 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1647 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1651 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1655 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1660 case MESA_FORMAT_B8G8R8A8_UNORM
:
1661 case MESA_FORMAT_B8G8R8A8_SRGB
:
1662 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1666 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1669 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1674 case MESA_FORMAT_A8R8G8B8_UNORM
:
1675 case MESA_FORMAT_A8R8G8B8_SRGB
:
1676 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1679 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1683 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1688 case MESA_FORMAT_X8B8G8R8_UNORM
:
1689 case MESA_FORMAT_R8G8B8X8_UNORM
:
1692 case MESA_FORMAT_B8G8R8X8_UNORM
:
1693 case MESA_FORMAT_X8R8G8B8_UNORM
:
1696 case MESA_FORMAT_BGR_UNORM8
:
1697 case MESA_FORMAT_BGR_SRGB8
:
1698 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1700 case MESA_FORMAT_RGB_UNORM8
:
1701 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1703 case MESA_FORMAT_B5G6R5_UNORM
:
1704 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1705 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1708 case MESA_FORMAT_R5G6B5_UNORM
:
1709 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1710 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1713 case MESA_FORMAT_B4G4R4A4_UNORM
:
1714 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1717 case MESA_FORMAT_A4R4G4B4_UNORM
:
1720 case MESA_FORMAT_A1B5G5R5_UNORM
:
1721 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1724 case MESA_FORMAT_B5G5R5A1_UNORM
:
1725 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1728 case MESA_FORMAT_A1R5G5B5_UNORM
:
1729 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1732 case MESA_FORMAT_L4A4_UNORM
:
1734 case MESA_FORMAT_L8A8_UNORM
:
1735 case MESA_FORMAT_L8A8_SRGB
:
1736 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1737 case MESA_FORMAT_A8L8_UNORM
:
1738 case MESA_FORMAT_A8L8_SRGB
:
1741 case MESA_FORMAT_L16A16_UNORM
:
1742 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1743 case MESA_FORMAT_A16L16_UNORM
:
1746 case MESA_FORMAT_B2G3R3_UNORM
:
1747 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1749 case MESA_FORMAT_R3G3B2_UNORM
:
1750 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1752 case MESA_FORMAT_A4B4G4R4_UNORM
:
1753 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1756 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1759 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1762 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1767 case MESA_FORMAT_R4G4B4A4_UNORM
:
1768 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1771 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1774 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1777 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1782 case MESA_FORMAT_R5G5B5A1_UNORM
:
1783 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1785 case MESA_FORMAT_A2B10G10R10_UNORM
:
1786 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1788 case MESA_FORMAT_A2B10G10R10_UINT
:
1789 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1791 case MESA_FORMAT_A2R10G10B10_UNORM
:
1792 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1794 case MESA_FORMAT_A2R10G10B10_UINT
:
1795 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1797 case MESA_FORMAT_A_UNORM8
:
1798 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1799 case MESA_FORMAT_A_UNORM16
:
1800 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1801 case MESA_FORMAT_L_UNORM8
:
1802 case MESA_FORMAT_L_SRGB8
:
1803 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1804 case MESA_FORMAT_L_UNORM16
:
1805 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1806 case MESA_FORMAT_I_UNORM8
:
1807 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1808 case MESA_FORMAT_I_UNORM16
:
1809 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1811 case MESA_FORMAT_YCBCR
:
1812 return format
== GL_YCBCR_MESA
&&
1813 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1814 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1815 case MESA_FORMAT_YCBCR_REV
:
1816 return format
== GL_YCBCR_MESA
&&
1817 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1818 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1820 case MESA_FORMAT_R_UNORM8
:
1821 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1822 case MESA_FORMAT_R8G8_UNORM
:
1823 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1824 case MESA_FORMAT_G8R8_UNORM
:
1827 case MESA_FORMAT_R_UNORM16
:
1828 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1830 case MESA_FORMAT_R16G16_UNORM
:
1831 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1833 case MESA_FORMAT_G16R16_UNORM
:
1836 case MESA_FORMAT_B10G10R10A2_UNORM
:
1837 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1840 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1841 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1843 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1844 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1847 case MESA_FORMAT_Z_UNORM16
:
1848 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1851 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1854 case MESA_FORMAT_Z_UNORM32
:
1855 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1858 case MESA_FORMAT_S_UINT8
:
1859 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1861 case MESA_FORMAT_SRGB_DXT1
:
1862 case MESA_FORMAT_SRGBA_DXT1
:
1863 case MESA_FORMAT_SRGBA_DXT3
:
1864 case MESA_FORMAT_SRGBA_DXT5
:
1867 case MESA_FORMAT_RGB_FXT1
:
1868 case MESA_FORMAT_RGBA_FXT1
:
1869 case MESA_FORMAT_RGB_DXT1
:
1870 case MESA_FORMAT_RGBA_DXT1
:
1871 case MESA_FORMAT_RGBA_DXT3
:
1872 case MESA_FORMAT_RGBA_DXT5
:
1875 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1876 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1877 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1878 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1881 case MESA_FORMAT_RGBA_FLOAT32
:
1882 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1883 case MESA_FORMAT_RGBA_FLOAT16
:
1884 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1886 case MESA_FORMAT_RGB_FLOAT32
:
1887 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1888 case MESA_FORMAT_RGB_FLOAT16
:
1889 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1891 case MESA_FORMAT_A_FLOAT32
:
1892 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1893 case MESA_FORMAT_A_FLOAT16
:
1894 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1896 case MESA_FORMAT_L_FLOAT32
:
1897 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1898 case MESA_FORMAT_L_FLOAT16
:
1899 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1901 case MESA_FORMAT_LA_FLOAT32
:
1902 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1903 case MESA_FORMAT_LA_FLOAT16
:
1904 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1906 case MESA_FORMAT_I_FLOAT32
:
1907 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1908 case MESA_FORMAT_I_FLOAT16
:
1909 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1911 case MESA_FORMAT_R_FLOAT32
:
1912 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1913 case MESA_FORMAT_R_FLOAT16
:
1914 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1916 case MESA_FORMAT_RG_FLOAT32
:
1917 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1918 case MESA_FORMAT_RG_FLOAT16
:
1919 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1921 case MESA_FORMAT_A_UINT8
:
1922 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1923 case MESA_FORMAT_A_UINT16
:
1924 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1926 case MESA_FORMAT_A_UINT32
:
1927 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1929 case MESA_FORMAT_A_SINT8
:
1930 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1931 case MESA_FORMAT_A_SINT16
:
1932 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1933 case MESA_FORMAT_A_SINT32
:
1934 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1936 case MESA_FORMAT_I_UINT8
:
1937 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1938 case MESA_FORMAT_I_UINT16
:
1939 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1940 case MESA_FORMAT_I_UINT32
:
1941 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1942 case MESA_FORMAT_I_SINT8
:
1943 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1944 case MESA_FORMAT_I_SINT16
:
1945 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1946 case MESA_FORMAT_I_SINT32
:
1947 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1949 case MESA_FORMAT_L_UINT8
:
1950 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1951 case MESA_FORMAT_L_UINT16
:
1952 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1954 case MESA_FORMAT_L_UINT32
:
1955 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1957 case MESA_FORMAT_L_SINT8
:
1958 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1959 case MESA_FORMAT_L_SINT16
:
1960 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1962 case MESA_FORMAT_L_SINT32
:
1963 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1965 case MESA_FORMAT_LA_UINT8
:
1966 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1967 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1968 case MESA_FORMAT_LA_UINT16
:
1969 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1970 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1971 case MESA_FORMAT_LA_UINT32
:
1972 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1973 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1974 case MESA_FORMAT_LA_SINT8
:
1975 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1977 case MESA_FORMAT_LA_SINT16
:
1978 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1980 case MESA_FORMAT_LA_SINT32
:
1981 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1984 case MESA_FORMAT_R_SINT8
:
1985 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1986 case MESA_FORMAT_RG_SINT8
:
1987 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1988 case MESA_FORMAT_RGB_SINT8
:
1989 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1990 case MESA_FORMAT_RGBA_SINT8
:
1991 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1992 case MESA_FORMAT_R_SINT16
:
1993 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1994 case MESA_FORMAT_RG_SINT16
:
1995 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1996 case MESA_FORMAT_RGB_SINT16
:
1997 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1998 case MESA_FORMAT_RGBA_SINT16
:
1999 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
2000 case MESA_FORMAT_R_SINT32
:
2001 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2002 case MESA_FORMAT_RG_SINT32
:
2003 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2004 case MESA_FORMAT_RGB_SINT32
:
2005 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2006 case MESA_FORMAT_RGBA_SINT32
:
2007 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2009 case MESA_FORMAT_R_UINT8
:
2010 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2011 case MESA_FORMAT_RG_UINT8
:
2012 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2013 case MESA_FORMAT_RGB_UINT8
:
2014 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2015 case MESA_FORMAT_RGBA_UINT8
:
2016 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2018 case MESA_FORMAT_R_UINT16
:
2019 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2021 case MESA_FORMAT_RG_UINT16
:
2022 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2023 case MESA_FORMAT_RGB_UINT16
:
2024 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2026 case MESA_FORMAT_RGBA_UINT16
:
2027 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2029 case MESA_FORMAT_R_UINT32
:
2030 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2031 case MESA_FORMAT_RG_UINT32
:
2032 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2033 case MESA_FORMAT_RGB_UINT32
:
2034 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2035 case MESA_FORMAT_RGBA_UINT32
:
2036 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2038 case MESA_FORMAT_R_SNORM8
:
2039 return format
== GL_RED
&& type
== GL_BYTE
;
2040 case MESA_FORMAT_R8G8_SNORM
:
2041 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2043 case MESA_FORMAT_X8B8G8R8_SNORM
:
2046 case MESA_FORMAT_A8B8G8R8_SNORM
:
2047 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2050 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2055 case MESA_FORMAT_R8G8B8A8_SNORM
:
2056 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2059 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2064 case MESA_FORMAT_R_SNORM16
:
2065 return format
== GL_RED
&& type
== GL_SHORT
&&
2067 case MESA_FORMAT_R16G16_SNORM
:
2068 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2069 case MESA_FORMAT_RGB_SNORM16
:
2070 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2071 case MESA_FORMAT_RGBA_SNORM16
:
2072 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2073 case MESA_FORMAT_RGBA_UNORM16
:
2074 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2077 case MESA_FORMAT_R_RGTC1_UNORM
:
2078 case MESA_FORMAT_R_RGTC1_SNORM
:
2079 case MESA_FORMAT_RG_RGTC2_UNORM
:
2080 case MESA_FORMAT_RG_RGTC2_SNORM
:
2083 case MESA_FORMAT_L_LATC1_UNORM
:
2084 case MESA_FORMAT_L_LATC1_SNORM
:
2085 case MESA_FORMAT_LA_LATC2_UNORM
:
2086 case MESA_FORMAT_LA_LATC2_SNORM
:
2089 case MESA_FORMAT_ETC1_RGB8
:
2090 case MESA_FORMAT_ETC2_RGB8
:
2091 case MESA_FORMAT_ETC2_SRGB8
:
2092 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2093 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2094 case MESA_FORMAT_ETC2_R11_EAC
:
2095 case MESA_FORMAT_ETC2_RG11_EAC
:
2096 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2097 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2098 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2099 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2102 case MESA_FORMAT_A_SNORM8
:
2103 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2104 case MESA_FORMAT_L_SNORM8
:
2105 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2106 case MESA_FORMAT_L8A8_SNORM
:
2107 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2108 littleEndian
&& !swapBytes
;
2109 case MESA_FORMAT_A8L8_SNORM
:
2110 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2111 !littleEndian
&& !swapBytes
;
2112 case MESA_FORMAT_I_SNORM8
:
2113 return format
== GL_RED
&& type
== GL_BYTE
;
2114 case MESA_FORMAT_A_SNORM16
:
2115 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2116 case MESA_FORMAT_L_SNORM16
:
2117 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2118 case MESA_FORMAT_LA_SNORM16
:
2119 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2120 littleEndian
&& !swapBytes
;
2121 case MESA_FORMAT_I_SNORM16
:
2122 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2125 case MESA_FORMAT_B10G10R10A2_UINT
:
2126 return (format
== GL_BGRA_INTEGER_EXT
&&
2127 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2130 case MESA_FORMAT_R10G10B10A2_UINT
:
2131 return (format
== GL_RGBA_INTEGER_EXT
&&
2132 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2135 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2136 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2139 case MESA_FORMAT_R11G11B10_FLOAT
:
2140 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2143 case MESA_FORMAT_Z_FLOAT32
:
2144 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2146 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2147 return format
== GL_DEPTH_STENCIL
&&
2148 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2150 case MESA_FORMAT_B4G4R4X4_UNORM
:
2151 case MESA_FORMAT_B5G5R5X1_UNORM
:
2152 case MESA_FORMAT_R8G8B8X8_SNORM
:
2153 case MESA_FORMAT_R8G8B8X8_SRGB
:
2154 case MESA_FORMAT_X8B8G8R8_SRGB
:
2155 case MESA_FORMAT_RGBX_UINT8
:
2156 case MESA_FORMAT_RGBX_SINT8
:
2157 case MESA_FORMAT_B10G10R10X2_UNORM
:
2158 case MESA_FORMAT_R10G10B10X2_UNORM
:
2159 case MESA_FORMAT_RGBX_UNORM16
:
2160 case MESA_FORMAT_RGBX_SNORM16
:
2161 case MESA_FORMAT_RGBX_FLOAT16
:
2162 case MESA_FORMAT_RGBX_UINT16
:
2163 case MESA_FORMAT_RGBX_SINT16
:
2164 case MESA_FORMAT_RGBX_FLOAT32
:
2165 case MESA_FORMAT_RGBX_UINT32
:
2166 case MESA_FORMAT_RGBX_SINT32
:
2169 case MESA_FORMAT_R10G10B10A2_UNORM
:
2170 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2173 case MESA_FORMAT_G8R8_SNORM
:
2174 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2177 case MESA_FORMAT_G16R16_SNORM
:
2178 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2181 case MESA_FORMAT_B8G8R8X8_SRGB
:
2182 case MESA_FORMAT_X8R8G8B8_SRGB
: