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 _mesa_array_format_set_swizzle(&format
, swizzle
[1], swizzle
[0],
358 swizzle
[2], swizzle
[3]);
362 if (num_channels
== 4) {
363 _mesa_array_format_set_swizzle(&format
, swizzle
[3], swizzle
[2],
364 swizzle
[1], swizzle
[0]);
368 unreachable("Invalid array format");
372 _mesa_format_to_array_format(mesa_format format
)
374 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
375 if (_mesa_little_endian())
376 return info
->ArrayFormat
;
378 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
381 static struct hash_table
*format_array_format_table
;
382 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
385 array_formats_equal(const void *a
, const void *b
)
387 return (intptr_t)a
== (intptr_t)b
;
391 format_array_format_table_init(void)
393 const struct gl_format_info
*info
;
394 mesa_array_format array_format
;
397 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
398 array_formats_equal
);
400 if (!format_array_format_table
) {
401 _mesa_error_no_memory(__func__
);
405 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
406 info
= _mesa_get_format_info(f
);
407 if (!info
->ArrayFormat
)
410 if (_mesa_little_endian()) {
411 array_format
= info
->ArrayFormat
;
413 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
416 /* This can happen and does for some of the BGR formats. Let's take
417 * the first one in the list.
419 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
421 (void *)(intptr_t)array_format
))
424 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
426 (void *)(intptr_t)array_format
,
427 (void *)(intptr_t)f
);
432 _mesa_format_from_array_format(uint32_t array_format
)
434 struct hash_entry
*entry
;
436 assert(_mesa_format_is_mesa_array_format(array_format
));
438 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
440 if (!format_array_format_table
) {
441 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
442 format_array_format_table_exists
= once_flag_init
;
443 return MESA_FORMAT_NONE
;
446 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
448 (void *)(intptr_t)array_format
);
450 return (intptr_t)entry
->data
;
452 return MESA_FORMAT_NONE
;
455 /** Is the given format a compressed format? */
457 _mesa_is_format_compressed(mesa_format format
)
459 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
460 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
465 * Determine if the given format represents a packed depth/stencil buffer.
468 _mesa_is_format_packed_depth_stencil(mesa_format format
)
470 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
472 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
477 * Is the given format a signed/unsigned integer color format?
480 _mesa_is_format_integer_color(mesa_format format
)
482 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
483 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
484 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
485 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
486 info
->BaseFormat
!= GL_STENCIL_INDEX
;
491 * Is the given format an unsigned integer format?
494 _mesa_is_format_unsigned(mesa_format format
)
496 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
497 return _mesa_is_type_unsigned(info
->DataType
);
502 * Does the given format store signed values?
505 _mesa_is_format_signed(mesa_format format
)
507 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
508 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
509 /* these packed float formats only store unsigned values */
513 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
514 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
515 info
->DataType
== GL_INT
||
516 info
->DataType
== GL_FLOAT
);
521 * Is the given format an integer format?
524 _mesa_is_format_integer(mesa_format format
)
526 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
527 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
532 * Return true if the given format is a color format.
535 _mesa_is_format_color_format(mesa_format format
)
537 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
538 switch (info
->BaseFormat
) {
539 case GL_DEPTH_COMPONENT
:
540 case GL_STENCIL_INDEX
:
541 case GL_DEPTH_STENCIL
:
550 * Return color encoding for given format.
551 * \return GL_LINEAR or GL_SRGB
554 _mesa_get_format_color_encoding(mesa_format format
)
556 /* XXX this info should be encoded in gl_format_info */
558 case MESA_FORMAT_BGR_SRGB8
:
559 case MESA_FORMAT_A8B8G8R8_SRGB
:
560 case MESA_FORMAT_B8G8R8A8_SRGB
:
561 case MESA_FORMAT_A8R8G8B8_SRGB
:
562 case MESA_FORMAT_R8G8B8A8_SRGB
:
563 case MESA_FORMAT_L_SRGB8
:
564 case MESA_FORMAT_L8A8_SRGB
:
565 case MESA_FORMAT_A8L8_SRGB
:
566 case MESA_FORMAT_SRGB_DXT1
:
567 case MESA_FORMAT_SRGBA_DXT1
:
568 case MESA_FORMAT_SRGBA_DXT3
:
569 case MESA_FORMAT_SRGBA_DXT5
:
570 case MESA_FORMAT_R8G8B8X8_SRGB
:
571 case MESA_FORMAT_ETC2_SRGB8
:
572 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
573 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
574 case MESA_FORMAT_B8G8R8X8_SRGB
:
575 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
584 * Return TRUE if format is an ETC2 compressed format specified
585 * by GL_ARB_ES3_compatibility.
588 _mesa_is_format_etc2(mesa_format format
)
591 case MESA_FORMAT_ETC2_RGB8
:
592 case MESA_FORMAT_ETC2_SRGB8
:
593 case MESA_FORMAT_ETC2_RGBA8_EAC
:
594 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
595 case MESA_FORMAT_ETC2_R11_EAC
:
596 case MESA_FORMAT_ETC2_RG11_EAC
:
597 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
598 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
599 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
600 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
609 * For an sRGB format, return the corresponding linear color space format.
610 * For non-sRGB formats, return the format as-is.
613 _mesa_get_srgb_format_linear(mesa_format format
)
616 case MESA_FORMAT_BGR_SRGB8
:
617 format
= MESA_FORMAT_BGR_UNORM8
;
619 case MESA_FORMAT_A8B8G8R8_SRGB
:
620 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
622 case MESA_FORMAT_B8G8R8A8_SRGB
:
623 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
625 case MESA_FORMAT_A8R8G8B8_SRGB
:
626 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
628 case MESA_FORMAT_R8G8B8A8_SRGB
:
629 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
631 case MESA_FORMAT_L_SRGB8
:
632 format
= MESA_FORMAT_L_UNORM8
;
634 case MESA_FORMAT_L8A8_SRGB
:
635 format
= MESA_FORMAT_L8A8_UNORM
;
637 case MESA_FORMAT_A8L8_SRGB
:
638 format
= MESA_FORMAT_A8L8_UNORM
;
640 case MESA_FORMAT_SRGB_DXT1
:
641 format
= MESA_FORMAT_RGB_DXT1
;
643 case MESA_FORMAT_SRGBA_DXT1
:
644 format
= MESA_FORMAT_RGBA_DXT1
;
646 case MESA_FORMAT_SRGBA_DXT3
:
647 format
= MESA_FORMAT_RGBA_DXT3
;
649 case MESA_FORMAT_SRGBA_DXT5
:
650 format
= MESA_FORMAT_RGBA_DXT5
;
652 case MESA_FORMAT_R8G8B8X8_SRGB
:
653 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
655 case MESA_FORMAT_X8B8G8R8_SRGB
:
656 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
658 case MESA_FORMAT_ETC2_SRGB8
:
659 format
= MESA_FORMAT_ETC2_RGB8
;
661 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
662 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
664 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
665 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
667 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
668 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
670 case MESA_FORMAT_B8G8R8X8_SRGB
:
671 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
673 case MESA_FORMAT_X8R8G8B8_SRGB
:
674 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
684 * If the given format is a compressed format, return a corresponding
685 * uncompressed format.
688 _mesa_get_uncompressed_format(mesa_format format
)
691 case MESA_FORMAT_RGB_FXT1
:
692 return MESA_FORMAT_BGR_UNORM8
;
693 case MESA_FORMAT_RGBA_FXT1
:
694 return MESA_FORMAT_A8B8G8R8_UNORM
;
695 case MESA_FORMAT_RGB_DXT1
:
696 case MESA_FORMAT_SRGB_DXT1
:
697 return MESA_FORMAT_BGR_UNORM8
;
698 case MESA_FORMAT_RGBA_DXT1
:
699 case MESA_FORMAT_SRGBA_DXT1
:
700 return MESA_FORMAT_A8B8G8R8_UNORM
;
701 case MESA_FORMAT_RGBA_DXT3
:
702 case MESA_FORMAT_SRGBA_DXT3
:
703 return MESA_FORMAT_A8B8G8R8_UNORM
;
704 case MESA_FORMAT_RGBA_DXT5
:
705 case MESA_FORMAT_SRGBA_DXT5
:
706 return MESA_FORMAT_A8B8G8R8_UNORM
;
707 case MESA_FORMAT_R_RGTC1_UNORM
:
708 return MESA_FORMAT_R_UNORM8
;
709 case MESA_FORMAT_R_RGTC1_SNORM
:
710 return MESA_FORMAT_R_SNORM8
;
711 case MESA_FORMAT_RG_RGTC2_UNORM
:
712 return MESA_FORMAT_R8G8_UNORM
;
713 case MESA_FORMAT_RG_RGTC2_SNORM
:
714 return MESA_FORMAT_R8G8_SNORM
;
715 case MESA_FORMAT_L_LATC1_UNORM
:
716 return MESA_FORMAT_L_UNORM8
;
717 case MESA_FORMAT_L_LATC1_SNORM
:
718 return MESA_FORMAT_L_SNORM8
;
719 case MESA_FORMAT_LA_LATC2_UNORM
:
720 return MESA_FORMAT_L8A8_UNORM
;
721 case MESA_FORMAT_LA_LATC2_SNORM
:
722 return MESA_FORMAT_L8A8_SNORM
;
723 case MESA_FORMAT_ETC1_RGB8
:
724 case MESA_FORMAT_ETC2_RGB8
:
725 case MESA_FORMAT_ETC2_SRGB8
:
726 return MESA_FORMAT_BGR_UNORM8
;
727 case MESA_FORMAT_ETC2_RGBA8_EAC
:
728 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
729 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
730 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
731 return MESA_FORMAT_A8B8G8R8_UNORM
;
732 case MESA_FORMAT_ETC2_R11_EAC
:
733 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
734 return MESA_FORMAT_R_UNORM16
;
735 case MESA_FORMAT_ETC2_RG11_EAC
:
736 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
737 return MESA_FORMAT_R16G16_UNORM
;
738 case MESA_FORMAT_BPTC_RGBA_UNORM
:
739 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
740 return MESA_FORMAT_A8B8G8R8_UNORM
;
741 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
742 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
743 return MESA_FORMAT_RGB_FLOAT32
;
746 assert(!_mesa_is_format_compressed(format
));
754 _mesa_format_num_components(mesa_format format
)
756 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
757 return ((info
->RedBits
> 0) +
758 (info
->GreenBits
> 0) +
759 (info
->BlueBits
> 0) +
760 (info
->AlphaBits
> 0) +
761 (info
->LuminanceBits
> 0) +
762 (info
->IntensityBits
> 0) +
763 (info
->DepthBits
> 0) +
764 (info
->StencilBits
> 0));
769 * Returns true if a color format has data stored in the R/G/B/A channels,
770 * given an index from 0 to 3.
773 _mesa_format_has_color_component(mesa_format format
, int component
)
775 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
777 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
778 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
779 info
->BaseFormat
!= GL_STENCIL_INDEX
);
783 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
785 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
787 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
789 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
791 assert(!"Invalid color component: must be 0..3");
798 * Return number of bytes needed to store an image of the given size
799 * in the given format.
802 _mesa_format_image_size(mesa_format format
, GLsizei width
,
803 GLsizei height
, GLsizei depth
)
805 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
806 /* Strictly speaking, a conditional isn't needed here */
807 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
808 /* compressed format (2D only for now) */
809 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
810 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
811 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
812 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
817 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
824 * Same as _mesa_format_image_size() but returns a 64-bit value to
825 * accommodate very large textures.
828 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
829 GLsizei height
, GLsizei depth
)
831 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
832 /* Strictly speaking, a conditional isn't needed here */
833 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
834 /* compressed format (2D only for now) */
835 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
836 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
837 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
838 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
843 const uint64_t sz
= ((uint64_t) width
*
846 info
->BytesPerBlock
);
854 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
856 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
857 /* Strictly speaking, a conditional isn't needed here */
858 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
859 /* compressed format */
860 const GLuint bw
= info
->BlockWidth
;
861 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
862 const GLint stride
= wblocks
* info
->BytesPerBlock
;
866 const GLint stride
= width
* info
->BytesPerBlock
;
873 * Debug/test: check that all formats are handled in the
874 * _mesa_format_to_type_and_comps() function. When new pixel formats
875 * are added to Mesa, that function needs to be updated.
876 * This is a no-op after the first call.
879 check_format_to_type_and_comps(void)
883 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
886 /* This function will emit a problem/warning if the format is
889 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
894 * Do sanity checking of the format info table.
897 _mesa_test_formats(void)
901 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
903 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
904 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
907 assert(info
->Name
== i
);
909 if (info
->Name
== MESA_FORMAT_NONE
)
912 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
913 if (info
->RedBits
> 0) {
914 GLuint t
= info
->RedBits
+ info
->GreenBits
915 + info
->BlueBits
+ info
->AlphaBits
;
916 assert(t
/ 8 <= info
->BytesPerBlock
);
921 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
922 info
->DataType
== GL_SIGNED_NORMALIZED
||
923 info
->DataType
== GL_UNSIGNED_INT
||
924 info
->DataType
== GL_INT
||
925 info
->DataType
== GL_FLOAT
||
926 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
927 info
->DataType
== GL_NONE
);
929 if (info
->BaseFormat
== GL_RGB
) {
930 assert(info
->RedBits
> 0);
931 assert(info
->GreenBits
> 0);
932 assert(info
->BlueBits
> 0);
933 assert(info
->AlphaBits
== 0);
934 assert(info
->LuminanceBits
== 0);
935 assert(info
->IntensityBits
== 0);
937 else if (info
->BaseFormat
== GL_RGBA
) {
938 assert(info
->RedBits
> 0);
939 assert(info
->GreenBits
> 0);
940 assert(info
->BlueBits
> 0);
941 assert(info
->AlphaBits
> 0);
942 assert(info
->LuminanceBits
== 0);
943 assert(info
->IntensityBits
== 0);
945 else if (info
->BaseFormat
== GL_RG
) {
946 assert(info
->RedBits
> 0);
947 assert(info
->GreenBits
> 0);
948 assert(info
->BlueBits
== 0);
949 assert(info
->AlphaBits
== 0);
950 assert(info
->LuminanceBits
== 0);
951 assert(info
->IntensityBits
== 0);
953 else if (info
->BaseFormat
== GL_RED
) {
954 assert(info
->RedBits
> 0);
955 assert(info
->GreenBits
== 0);
956 assert(info
->BlueBits
== 0);
957 assert(info
->AlphaBits
== 0);
958 assert(info
->LuminanceBits
== 0);
959 assert(info
->IntensityBits
== 0);
961 else if (info
->BaseFormat
== GL_LUMINANCE
) {
962 assert(info
->RedBits
== 0);
963 assert(info
->GreenBits
== 0);
964 assert(info
->BlueBits
== 0);
965 assert(info
->AlphaBits
== 0);
966 assert(info
->LuminanceBits
> 0);
967 assert(info
->IntensityBits
== 0);
969 else if (info
->BaseFormat
== GL_INTENSITY
) {
970 assert(info
->RedBits
== 0);
971 assert(info
->GreenBits
== 0);
972 assert(info
->BlueBits
== 0);
973 assert(info
->AlphaBits
== 0);
974 assert(info
->LuminanceBits
== 0);
975 assert(info
->IntensityBits
> 0);
979 check_format_to_type_and_comps();
985 * Return datatype and number of components per texel for the given mesa_format.
986 * Only used for mipmap generation code.
989 _mesa_format_to_type_and_comps(mesa_format format
,
990 GLenum
*datatype
, GLuint
*comps
)
993 case MESA_FORMAT_A8B8G8R8_UNORM
:
994 case MESA_FORMAT_R8G8B8A8_UNORM
:
995 case MESA_FORMAT_B8G8R8A8_UNORM
:
996 case MESA_FORMAT_A8R8G8B8_UNORM
:
997 case MESA_FORMAT_X8B8G8R8_UNORM
:
998 case MESA_FORMAT_R8G8B8X8_UNORM
:
999 case MESA_FORMAT_B8G8R8X8_UNORM
:
1000 case MESA_FORMAT_X8R8G8B8_UNORM
:
1001 *datatype
= GL_UNSIGNED_BYTE
;
1004 case MESA_FORMAT_BGR_UNORM8
:
1005 case MESA_FORMAT_RGB_UNORM8
:
1006 *datatype
= GL_UNSIGNED_BYTE
;
1009 case MESA_FORMAT_B5G6R5_UNORM
:
1010 case MESA_FORMAT_R5G6B5_UNORM
:
1011 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1015 case MESA_FORMAT_B4G4R4A4_UNORM
:
1016 case MESA_FORMAT_A4R4G4B4_UNORM
:
1017 case MESA_FORMAT_B4G4R4X4_UNORM
:
1018 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1022 case MESA_FORMAT_B5G5R5A1_UNORM
:
1023 case MESA_FORMAT_A1R5G5B5_UNORM
:
1024 case MESA_FORMAT_B5G5R5X1_UNORM
:
1025 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1029 case MESA_FORMAT_B10G10R10A2_UNORM
:
1030 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1034 case MESA_FORMAT_A1B5G5R5_UNORM
:
1035 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1039 case MESA_FORMAT_L4A4_UNORM
:
1040 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1044 case MESA_FORMAT_L8A8_UNORM
:
1045 case MESA_FORMAT_A8L8_UNORM
:
1046 case MESA_FORMAT_R8G8_UNORM
:
1047 case MESA_FORMAT_G8R8_UNORM
:
1048 *datatype
= GL_UNSIGNED_BYTE
;
1052 case MESA_FORMAT_L16A16_UNORM
:
1053 case MESA_FORMAT_A16L16_UNORM
:
1054 case MESA_FORMAT_R16G16_UNORM
:
1055 case MESA_FORMAT_G16R16_UNORM
:
1056 *datatype
= GL_UNSIGNED_SHORT
;
1060 case MESA_FORMAT_R_UNORM16
:
1061 case MESA_FORMAT_A_UNORM16
:
1062 case MESA_FORMAT_L_UNORM16
:
1063 case MESA_FORMAT_I_UNORM16
:
1064 *datatype
= GL_UNSIGNED_SHORT
;
1068 case MESA_FORMAT_R3G3B2_UNORM
:
1069 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1072 case MESA_FORMAT_A4B4G4R4_UNORM
:
1073 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1077 case MESA_FORMAT_R4G4B4A4_UNORM
:
1078 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1081 case MESA_FORMAT_R5G5B5A1_UNORM
:
1082 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1085 case MESA_FORMAT_A2B10G10R10_UNORM
:
1086 case MESA_FORMAT_A2B10G10R10_UINT
:
1087 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1090 case MESA_FORMAT_A2R10G10B10_UNORM
:
1091 case MESA_FORMAT_A2R10G10B10_UINT
:
1092 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1096 case MESA_FORMAT_B2G3R3_UNORM
:
1097 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1101 case MESA_FORMAT_A_UNORM8
:
1102 case MESA_FORMAT_L_UNORM8
:
1103 case MESA_FORMAT_I_UNORM8
:
1104 case MESA_FORMAT_R_UNORM8
:
1105 case MESA_FORMAT_S_UINT8
:
1106 *datatype
= GL_UNSIGNED_BYTE
;
1110 case MESA_FORMAT_YCBCR
:
1111 case MESA_FORMAT_YCBCR_REV
:
1112 *datatype
= GL_UNSIGNED_SHORT
;
1116 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1117 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1121 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1122 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1126 case MESA_FORMAT_Z_UNORM16
:
1127 *datatype
= GL_UNSIGNED_SHORT
;
1131 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1132 *datatype
= GL_UNSIGNED_INT
;
1136 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1137 *datatype
= GL_UNSIGNED_INT
;
1141 case MESA_FORMAT_Z_UNORM32
:
1142 *datatype
= GL_UNSIGNED_INT
;
1146 case MESA_FORMAT_Z_FLOAT32
:
1147 *datatype
= GL_FLOAT
;
1151 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1152 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1156 case MESA_FORMAT_R_SNORM8
:
1157 case MESA_FORMAT_A_SNORM8
:
1158 case MESA_FORMAT_L_SNORM8
:
1159 case MESA_FORMAT_I_SNORM8
:
1160 *datatype
= GL_BYTE
;
1163 case MESA_FORMAT_R8G8_SNORM
:
1164 case MESA_FORMAT_L8A8_SNORM
:
1165 case MESA_FORMAT_A8L8_SNORM
:
1166 *datatype
= GL_BYTE
;
1169 case MESA_FORMAT_A8B8G8R8_SNORM
:
1170 case MESA_FORMAT_R8G8B8A8_SNORM
:
1171 case MESA_FORMAT_X8B8G8R8_SNORM
:
1172 *datatype
= GL_BYTE
;
1176 case MESA_FORMAT_RGBA_UNORM16
:
1177 *datatype
= GL_UNSIGNED_SHORT
;
1181 case MESA_FORMAT_R_SNORM16
:
1182 case MESA_FORMAT_A_SNORM16
:
1183 case MESA_FORMAT_L_SNORM16
:
1184 case MESA_FORMAT_I_SNORM16
:
1185 *datatype
= GL_SHORT
;
1188 case MESA_FORMAT_R16G16_SNORM
:
1189 case MESA_FORMAT_LA_SNORM16
:
1190 *datatype
= GL_SHORT
;
1193 case MESA_FORMAT_RGB_SNORM16
:
1194 *datatype
= GL_SHORT
;
1197 case MESA_FORMAT_RGBA_SNORM16
:
1198 *datatype
= GL_SHORT
;
1202 case MESA_FORMAT_BGR_SRGB8
:
1203 *datatype
= GL_UNSIGNED_BYTE
;
1206 case MESA_FORMAT_A8B8G8R8_SRGB
:
1207 case MESA_FORMAT_B8G8R8A8_SRGB
:
1208 case MESA_FORMAT_A8R8G8B8_SRGB
:
1209 case MESA_FORMAT_R8G8B8A8_SRGB
:
1210 *datatype
= GL_UNSIGNED_BYTE
;
1213 case MESA_FORMAT_L_SRGB8
:
1214 *datatype
= GL_UNSIGNED_BYTE
;
1217 case MESA_FORMAT_L8A8_SRGB
:
1218 case MESA_FORMAT_A8L8_SRGB
:
1219 *datatype
= GL_UNSIGNED_BYTE
;
1223 case MESA_FORMAT_RGB_FXT1
:
1224 case MESA_FORMAT_RGBA_FXT1
:
1225 case MESA_FORMAT_RGB_DXT1
:
1226 case MESA_FORMAT_RGBA_DXT1
:
1227 case MESA_FORMAT_RGBA_DXT3
:
1228 case MESA_FORMAT_RGBA_DXT5
:
1229 case MESA_FORMAT_SRGB_DXT1
:
1230 case MESA_FORMAT_SRGBA_DXT1
:
1231 case MESA_FORMAT_SRGBA_DXT3
:
1232 case MESA_FORMAT_SRGBA_DXT5
:
1233 case MESA_FORMAT_R_RGTC1_UNORM
:
1234 case MESA_FORMAT_R_RGTC1_SNORM
:
1235 case MESA_FORMAT_RG_RGTC2_UNORM
:
1236 case MESA_FORMAT_RG_RGTC2_SNORM
:
1237 case MESA_FORMAT_L_LATC1_UNORM
:
1238 case MESA_FORMAT_L_LATC1_SNORM
:
1239 case MESA_FORMAT_LA_LATC2_UNORM
:
1240 case MESA_FORMAT_LA_LATC2_SNORM
:
1241 case MESA_FORMAT_ETC1_RGB8
:
1242 case MESA_FORMAT_ETC2_RGB8
:
1243 case MESA_FORMAT_ETC2_SRGB8
:
1244 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1245 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1246 case MESA_FORMAT_ETC2_R11_EAC
:
1247 case MESA_FORMAT_ETC2_RG11_EAC
:
1248 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1249 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1250 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1251 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1252 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1253 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1254 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1255 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1256 /* XXX generate error instead? */
1257 *datatype
= GL_UNSIGNED_BYTE
;
1261 case MESA_FORMAT_RGBA_FLOAT32
:
1262 *datatype
= GL_FLOAT
;
1265 case MESA_FORMAT_RGBA_FLOAT16
:
1266 *datatype
= GL_HALF_FLOAT_ARB
;
1269 case MESA_FORMAT_RGB_FLOAT32
:
1270 *datatype
= GL_FLOAT
;
1273 case MESA_FORMAT_RGB_FLOAT16
:
1274 *datatype
= GL_HALF_FLOAT_ARB
;
1277 case MESA_FORMAT_LA_FLOAT32
:
1278 case MESA_FORMAT_RG_FLOAT32
:
1279 *datatype
= GL_FLOAT
;
1282 case MESA_FORMAT_LA_FLOAT16
:
1283 case MESA_FORMAT_RG_FLOAT16
:
1284 *datatype
= GL_HALF_FLOAT_ARB
;
1287 case MESA_FORMAT_A_FLOAT32
:
1288 case MESA_FORMAT_L_FLOAT32
:
1289 case MESA_FORMAT_I_FLOAT32
:
1290 case MESA_FORMAT_R_FLOAT32
:
1291 *datatype
= GL_FLOAT
;
1294 case MESA_FORMAT_A_FLOAT16
:
1295 case MESA_FORMAT_L_FLOAT16
:
1296 case MESA_FORMAT_I_FLOAT16
:
1297 case MESA_FORMAT_R_FLOAT16
:
1298 *datatype
= GL_HALF_FLOAT_ARB
;
1302 case MESA_FORMAT_A_UINT8
:
1303 case MESA_FORMAT_L_UINT8
:
1304 case MESA_FORMAT_I_UINT8
:
1305 *datatype
= GL_UNSIGNED_BYTE
;
1308 case MESA_FORMAT_LA_UINT8
:
1309 *datatype
= GL_UNSIGNED_BYTE
;
1313 case MESA_FORMAT_A_UINT16
:
1314 case MESA_FORMAT_L_UINT16
:
1315 case MESA_FORMAT_I_UINT16
:
1316 *datatype
= GL_UNSIGNED_SHORT
;
1319 case MESA_FORMAT_LA_UINT16
:
1320 *datatype
= GL_UNSIGNED_SHORT
;
1323 case MESA_FORMAT_A_UINT32
:
1324 case MESA_FORMAT_L_UINT32
:
1325 case MESA_FORMAT_I_UINT32
:
1326 *datatype
= GL_UNSIGNED_INT
;
1329 case MESA_FORMAT_LA_UINT32
:
1330 *datatype
= GL_UNSIGNED_INT
;
1333 case MESA_FORMAT_A_SINT8
:
1334 case MESA_FORMAT_L_SINT8
:
1335 case MESA_FORMAT_I_SINT8
:
1336 *datatype
= GL_BYTE
;
1339 case MESA_FORMAT_LA_SINT8
:
1340 *datatype
= GL_BYTE
;
1344 case MESA_FORMAT_A_SINT16
:
1345 case MESA_FORMAT_L_SINT16
:
1346 case MESA_FORMAT_I_SINT16
:
1347 *datatype
= GL_SHORT
;
1350 case MESA_FORMAT_LA_SINT16
:
1351 *datatype
= GL_SHORT
;
1355 case MESA_FORMAT_A_SINT32
:
1356 case MESA_FORMAT_L_SINT32
:
1357 case MESA_FORMAT_I_SINT32
:
1361 case MESA_FORMAT_LA_SINT32
:
1366 case MESA_FORMAT_R_SINT8
:
1367 *datatype
= GL_BYTE
;
1370 case MESA_FORMAT_RG_SINT8
:
1371 *datatype
= GL_BYTE
;
1374 case MESA_FORMAT_RGB_SINT8
:
1375 *datatype
= GL_BYTE
;
1378 case MESA_FORMAT_RGBA_SINT8
:
1379 *datatype
= GL_BYTE
;
1382 case MESA_FORMAT_R_SINT16
:
1383 *datatype
= GL_SHORT
;
1386 case MESA_FORMAT_RG_SINT16
:
1387 *datatype
= GL_SHORT
;
1390 case MESA_FORMAT_RGB_SINT16
:
1391 *datatype
= GL_SHORT
;
1394 case MESA_FORMAT_RGBA_SINT16
:
1395 *datatype
= GL_SHORT
;
1398 case MESA_FORMAT_R_SINT32
:
1402 case MESA_FORMAT_RG_SINT32
:
1406 case MESA_FORMAT_RGB_SINT32
:
1410 case MESA_FORMAT_RGBA_SINT32
:
1416 * \name Non-normalized unsigned integer formats.
1418 case MESA_FORMAT_R_UINT8
:
1419 *datatype
= GL_UNSIGNED_BYTE
;
1422 case MESA_FORMAT_RG_UINT8
:
1423 *datatype
= GL_UNSIGNED_BYTE
;
1426 case MESA_FORMAT_RGB_UINT8
:
1427 *datatype
= GL_UNSIGNED_BYTE
;
1430 case MESA_FORMAT_RGBA_UINT8
:
1431 *datatype
= GL_UNSIGNED_BYTE
;
1434 case MESA_FORMAT_R_UINT16
:
1435 *datatype
= GL_UNSIGNED_SHORT
;
1438 case MESA_FORMAT_RG_UINT16
:
1439 *datatype
= GL_UNSIGNED_SHORT
;
1442 case MESA_FORMAT_RGB_UINT16
:
1443 *datatype
= GL_UNSIGNED_SHORT
;
1446 case MESA_FORMAT_RGBA_UINT16
:
1447 *datatype
= GL_UNSIGNED_SHORT
;
1450 case MESA_FORMAT_R_UINT32
:
1451 *datatype
= GL_UNSIGNED_INT
;
1454 case MESA_FORMAT_RG_UINT32
:
1455 *datatype
= GL_UNSIGNED_INT
;
1458 case MESA_FORMAT_RGB_UINT32
:
1459 *datatype
= GL_UNSIGNED_INT
;
1462 case MESA_FORMAT_RGBA_UINT32
:
1463 *datatype
= GL_UNSIGNED_INT
;
1467 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1468 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1472 case MESA_FORMAT_R11G11B10_FLOAT
:
1473 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1477 case MESA_FORMAT_B10G10R10A2_UINT
:
1478 case MESA_FORMAT_R10G10B10A2_UINT
:
1479 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1483 case MESA_FORMAT_R8G8B8X8_SRGB
:
1484 case MESA_FORMAT_X8B8G8R8_SRGB
:
1485 case MESA_FORMAT_RGBX_UINT8
:
1486 *datatype
= GL_UNSIGNED_BYTE
;
1490 case MESA_FORMAT_R8G8B8X8_SNORM
:
1491 case MESA_FORMAT_RGBX_SINT8
:
1492 *datatype
= GL_BYTE
;
1496 case MESA_FORMAT_B10G10R10X2_UNORM
:
1497 case MESA_FORMAT_R10G10B10X2_UNORM
:
1498 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1502 case MESA_FORMAT_RGBX_UNORM16
:
1503 case MESA_FORMAT_RGBX_UINT16
:
1504 *datatype
= GL_UNSIGNED_SHORT
;
1508 case MESA_FORMAT_RGBX_SNORM16
:
1509 case MESA_FORMAT_RGBX_SINT16
:
1510 *datatype
= GL_SHORT
;
1514 case MESA_FORMAT_RGBX_FLOAT16
:
1515 *datatype
= GL_HALF_FLOAT
;
1519 case MESA_FORMAT_RGBX_FLOAT32
:
1520 *datatype
= GL_FLOAT
;
1524 case MESA_FORMAT_RGBX_UINT32
:
1525 *datatype
= GL_UNSIGNED_INT
;
1529 case MESA_FORMAT_RGBX_SINT32
:
1534 case MESA_FORMAT_R10G10B10A2_UNORM
:
1535 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1539 case MESA_FORMAT_G8R8_SNORM
:
1540 *datatype
= GL_BYTE
;
1544 case MESA_FORMAT_G16R16_SNORM
:
1545 *datatype
= GL_SHORT
;
1549 case MESA_FORMAT_B8G8R8X8_SRGB
:
1550 case MESA_FORMAT_X8R8G8B8_SRGB
:
1551 *datatype
= GL_UNSIGNED_BYTE
;
1555 case MESA_FORMAT_COUNT
:
1559 case MESA_FORMAT_NONE
:
1560 /* For debug builds, warn if any formats are not handled */
1564 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1565 _mesa_get_format_name(format
));
1572 * Check if a mesa_format exactly matches a GL format/type combination
1573 * such that we can use memcpy() from one to the other.
1574 * \param mesa_format a MESA_FORMAT_x value
1575 * \param format the user-specified image format
1576 * \param type the user-specified image datatype
1577 * \param swapBytes typically the current pixel pack/unpack byteswap state
1578 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1581 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1582 GLenum format
, GLenum type
,
1583 GLboolean swapBytes
)
1585 const GLboolean littleEndian
= _mesa_little_endian();
1587 /* Note: When reading a GL format/type combination, the format lists channel
1588 * assignments from most significant channel in the type to least
1589 * significant. A type with _REV indicates that the assignments are
1590 * swapped, so they are listed from least significant to most significant.
1592 * For sanity, please keep this switch statement ordered the same as the
1593 * enums in formats.h.
1596 switch (mesa_format
) {
1598 case MESA_FORMAT_NONE
:
1599 case MESA_FORMAT_COUNT
:
1602 case MESA_FORMAT_A8B8G8R8_UNORM
:
1603 case MESA_FORMAT_A8B8G8R8_SRGB
:
1604 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1607 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1610 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1613 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1617 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1621 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1626 case MESA_FORMAT_R8G8B8A8_UNORM
:
1627 case MESA_FORMAT_R8G8B8A8_SRGB
:
1628 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1632 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1635 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1638 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1642 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1646 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1651 case MESA_FORMAT_B8G8R8A8_UNORM
:
1652 case MESA_FORMAT_B8G8R8A8_SRGB
:
1653 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1657 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1660 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1665 case MESA_FORMAT_A8R8G8B8_UNORM
:
1666 case MESA_FORMAT_A8R8G8B8_SRGB
:
1667 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1670 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1674 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1679 case MESA_FORMAT_X8B8G8R8_UNORM
:
1680 case MESA_FORMAT_R8G8B8X8_UNORM
:
1683 case MESA_FORMAT_B8G8R8X8_UNORM
:
1684 case MESA_FORMAT_X8R8G8B8_UNORM
:
1687 case MESA_FORMAT_BGR_UNORM8
:
1688 case MESA_FORMAT_BGR_SRGB8
:
1689 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1691 case MESA_FORMAT_RGB_UNORM8
:
1692 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1694 case MESA_FORMAT_B5G6R5_UNORM
:
1695 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1696 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1699 case MESA_FORMAT_R5G6B5_UNORM
:
1700 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1701 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1704 case MESA_FORMAT_B4G4R4A4_UNORM
:
1705 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1708 case MESA_FORMAT_A4R4G4B4_UNORM
:
1711 case MESA_FORMAT_A1B5G5R5_UNORM
:
1712 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1715 case MESA_FORMAT_B5G5R5A1_UNORM
:
1716 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1719 case MESA_FORMAT_A1R5G5B5_UNORM
:
1720 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1723 case MESA_FORMAT_L4A4_UNORM
:
1725 case MESA_FORMAT_L8A8_UNORM
:
1726 case MESA_FORMAT_L8A8_SRGB
:
1727 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1728 case MESA_FORMAT_A8L8_UNORM
:
1729 case MESA_FORMAT_A8L8_SRGB
:
1732 case MESA_FORMAT_L16A16_UNORM
:
1733 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1734 case MESA_FORMAT_A16L16_UNORM
:
1737 case MESA_FORMAT_B2G3R3_UNORM
:
1738 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1740 case MESA_FORMAT_R3G3B2_UNORM
:
1741 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1743 case MESA_FORMAT_A4B4G4R4_UNORM
:
1744 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1747 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1750 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1753 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1758 case MESA_FORMAT_R4G4B4A4_UNORM
:
1759 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1762 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1765 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1768 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1773 case MESA_FORMAT_R5G5B5A1_UNORM
:
1774 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1776 case MESA_FORMAT_A2B10G10R10_UNORM
:
1777 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1779 case MESA_FORMAT_A2B10G10R10_UINT
:
1780 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1782 case MESA_FORMAT_A2R10G10B10_UNORM
:
1783 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1785 case MESA_FORMAT_A2R10G10B10_UINT
:
1786 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1788 case MESA_FORMAT_A_UNORM8
:
1789 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1790 case MESA_FORMAT_A_UNORM16
:
1791 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1792 case MESA_FORMAT_L_UNORM8
:
1793 case MESA_FORMAT_L_SRGB8
:
1794 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1795 case MESA_FORMAT_L_UNORM16
:
1796 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1797 case MESA_FORMAT_I_UNORM8
:
1798 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1799 case MESA_FORMAT_I_UNORM16
:
1800 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1802 case MESA_FORMAT_YCBCR
:
1803 return format
== GL_YCBCR_MESA
&&
1804 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1805 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1806 case MESA_FORMAT_YCBCR_REV
:
1807 return format
== GL_YCBCR_MESA
&&
1808 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1809 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1811 case MESA_FORMAT_R_UNORM8
:
1812 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1813 case MESA_FORMAT_R8G8_UNORM
:
1814 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1815 case MESA_FORMAT_G8R8_UNORM
:
1818 case MESA_FORMAT_R_UNORM16
:
1819 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1821 case MESA_FORMAT_R16G16_UNORM
:
1822 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1824 case MESA_FORMAT_G16R16_UNORM
:
1827 case MESA_FORMAT_B10G10R10A2_UNORM
:
1828 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1831 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1832 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1834 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1835 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1838 case MESA_FORMAT_Z_UNORM16
:
1839 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1842 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1845 case MESA_FORMAT_Z_UNORM32
:
1846 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1849 case MESA_FORMAT_S_UINT8
:
1850 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1852 case MESA_FORMAT_SRGB_DXT1
:
1853 case MESA_FORMAT_SRGBA_DXT1
:
1854 case MESA_FORMAT_SRGBA_DXT3
:
1855 case MESA_FORMAT_SRGBA_DXT5
:
1858 case MESA_FORMAT_RGB_FXT1
:
1859 case MESA_FORMAT_RGBA_FXT1
:
1860 case MESA_FORMAT_RGB_DXT1
:
1861 case MESA_FORMAT_RGBA_DXT1
:
1862 case MESA_FORMAT_RGBA_DXT3
:
1863 case MESA_FORMAT_RGBA_DXT5
:
1866 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1867 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1868 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1869 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1872 case MESA_FORMAT_RGBA_FLOAT32
:
1873 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1874 case MESA_FORMAT_RGBA_FLOAT16
:
1875 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1877 case MESA_FORMAT_RGB_FLOAT32
:
1878 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1879 case MESA_FORMAT_RGB_FLOAT16
:
1880 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1882 case MESA_FORMAT_A_FLOAT32
:
1883 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1884 case MESA_FORMAT_A_FLOAT16
:
1885 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1887 case MESA_FORMAT_L_FLOAT32
:
1888 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1889 case MESA_FORMAT_L_FLOAT16
:
1890 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1892 case MESA_FORMAT_LA_FLOAT32
:
1893 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1894 case MESA_FORMAT_LA_FLOAT16
:
1895 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1897 case MESA_FORMAT_I_FLOAT32
:
1898 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1899 case MESA_FORMAT_I_FLOAT16
:
1900 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1902 case MESA_FORMAT_R_FLOAT32
:
1903 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1904 case MESA_FORMAT_R_FLOAT16
:
1905 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1907 case MESA_FORMAT_RG_FLOAT32
:
1908 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1909 case MESA_FORMAT_RG_FLOAT16
:
1910 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1912 case MESA_FORMAT_A_UINT8
:
1913 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1914 case MESA_FORMAT_A_UINT16
:
1915 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1917 case MESA_FORMAT_A_UINT32
:
1918 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1920 case MESA_FORMAT_A_SINT8
:
1921 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1922 case MESA_FORMAT_A_SINT16
:
1923 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1924 case MESA_FORMAT_A_SINT32
:
1925 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1927 case MESA_FORMAT_I_UINT8
:
1928 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1929 case MESA_FORMAT_I_UINT16
:
1930 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1931 case MESA_FORMAT_I_UINT32
:
1932 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1933 case MESA_FORMAT_I_SINT8
:
1934 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1935 case MESA_FORMAT_I_SINT16
:
1936 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1937 case MESA_FORMAT_I_SINT32
:
1938 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1940 case MESA_FORMAT_L_UINT8
:
1941 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1942 case MESA_FORMAT_L_UINT16
:
1943 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1945 case MESA_FORMAT_L_UINT32
:
1946 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1948 case MESA_FORMAT_L_SINT8
:
1949 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1950 case MESA_FORMAT_L_SINT16
:
1951 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1953 case MESA_FORMAT_L_SINT32
:
1954 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1956 case MESA_FORMAT_LA_UINT8
:
1957 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1958 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1959 case MESA_FORMAT_LA_UINT16
:
1960 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1961 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1962 case MESA_FORMAT_LA_UINT32
:
1963 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1964 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1965 case MESA_FORMAT_LA_SINT8
:
1966 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1968 case MESA_FORMAT_LA_SINT16
:
1969 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1971 case MESA_FORMAT_LA_SINT32
:
1972 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1975 case MESA_FORMAT_R_SINT8
:
1976 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1977 case MESA_FORMAT_RG_SINT8
:
1978 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1979 case MESA_FORMAT_RGB_SINT8
:
1980 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1981 case MESA_FORMAT_RGBA_SINT8
:
1982 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1983 case MESA_FORMAT_R_SINT16
:
1984 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1985 case MESA_FORMAT_RG_SINT16
:
1986 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1987 case MESA_FORMAT_RGB_SINT16
:
1988 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1989 case MESA_FORMAT_RGBA_SINT16
:
1990 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1991 case MESA_FORMAT_R_SINT32
:
1992 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1993 case MESA_FORMAT_RG_SINT32
:
1994 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1995 case MESA_FORMAT_RGB_SINT32
:
1996 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1997 case MESA_FORMAT_RGBA_SINT32
:
1998 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
2000 case MESA_FORMAT_R_UINT8
:
2001 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2002 case MESA_FORMAT_RG_UINT8
:
2003 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2004 case MESA_FORMAT_RGB_UINT8
:
2005 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2006 case MESA_FORMAT_RGBA_UINT8
:
2007 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2009 case MESA_FORMAT_R_UINT16
:
2010 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2012 case MESA_FORMAT_RG_UINT16
:
2013 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2014 case MESA_FORMAT_RGB_UINT16
:
2015 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2017 case MESA_FORMAT_RGBA_UINT16
:
2018 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2020 case MESA_FORMAT_R_UINT32
:
2021 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2022 case MESA_FORMAT_RG_UINT32
:
2023 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2024 case MESA_FORMAT_RGB_UINT32
:
2025 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2026 case MESA_FORMAT_RGBA_UINT32
:
2027 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2029 case MESA_FORMAT_R_SNORM8
:
2030 return format
== GL_RED
&& type
== GL_BYTE
;
2031 case MESA_FORMAT_R8G8_SNORM
:
2032 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2034 case MESA_FORMAT_X8B8G8R8_SNORM
:
2037 case MESA_FORMAT_A8B8G8R8_SNORM
:
2038 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2041 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2046 case MESA_FORMAT_R8G8B8A8_SNORM
:
2047 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2050 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2055 case MESA_FORMAT_R_SNORM16
:
2056 return format
== GL_RED
&& type
== GL_SHORT
&&
2058 case MESA_FORMAT_R16G16_SNORM
:
2059 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2060 case MESA_FORMAT_RGB_SNORM16
:
2061 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2062 case MESA_FORMAT_RGBA_SNORM16
:
2063 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2064 case MESA_FORMAT_RGBA_UNORM16
:
2065 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2068 case MESA_FORMAT_R_RGTC1_UNORM
:
2069 case MESA_FORMAT_R_RGTC1_SNORM
:
2070 case MESA_FORMAT_RG_RGTC2_UNORM
:
2071 case MESA_FORMAT_RG_RGTC2_SNORM
:
2074 case MESA_FORMAT_L_LATC1_UNORM
:
2075 case MESA_FORMAT_L_LATC1_SNORM
:
2076 case MESA_FORMAT_LA_LATC2_UNORM
:
2077 case MESA_FORMAT_LA_LATC2_SNORM
:
2080 case MESA_FORMAT_ETC1_RGB8
:
2081 case MESA_FORMAT_ETC2_RGB8
:
2082 case MESA_FORMAT_ETC2_SRGB8
:
2083 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2084 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2085 case MESA_FORMAT_ETC2_R11_EAC
:
2086 case MESA_FORMAT_ETC2_RG11_EAC
:
2087 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2088 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2089 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2090 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2093 case MESA_FORMAT_A_SNORM8
:
2094 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2095 case MESA_FORMAT_L_SNORM8
:
2096 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2097 case MESA_FORMAT_L8A8_SNORM
:
2098 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2099 littleEndian
&& !swapBytes
;
2100 case MESA_FORMAT_A8L8_SNORM
:
2101 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2102 !littleEndian
&& !swapBytes
;
2103 case MESA_FORMAT_I_SNORM8
:
2104 return format
== GL_RED
&& type
== GL_BYTE
;
2105 case MESA_FORMAT_A_SNORM16
:
2106 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2107 case MESA_FORMAT_L_SNORM16
:
2108 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2109 case MESA_FORMAT_LA_SNORM16
:
2110 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2111 littleEndian
&& !swapBytes
;
2112 case MESA_FORMAT_I_SNORM16
:
2113 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2116 case MESA_FORMAT_B10G10R10A2_UINT
:
2117 return (format
== GL_BGRA_INTEGER_EXT
&&
2118 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2121 case MESA_FORMAT_R10G10B10A2_UINT
:
2122 return (format
== GL_RGBA_INTEGER_EXT
&&
2123 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2126 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2127 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2130 case MESA_FORMAT_R11G11B10_FLOAT
:
2131 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2134 case MESA_FORMAT_Z_FLOAT32
:
2135 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2137 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2138 return format
== GL_DEPTH_STENCIL
&&
2139 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2141 case MESA_FORMAT_B4G4R4X4_UNORM
:
2142 case MESA_FORMAT_B5G5R5X1_UNORM
:
2143 case MESA_FORMAT_R8G8B8X8_SNORM
:
2144 case MESA_FORMAT_R8G8B8X8_SRGB
:
2145 case MESA_FORMAT_X8B8G8R8_SRGB
:
2146 case MESA_FORMAT_RGBX_UINT8
:
2147 case MESA_FORMAT_RGBX_SINT8
:
2148 case MESA_FORMAT_B10G10R10X2_UNORM
:
2149 case MESA_FORMAT_R10G10B10X2_UNORM
:
2150 case MESA_FORMAT_RGBX_UNORM16
:
2151 case MESA_FORMAT_RGBX_SNORM16
:
2152 case MESA_FORMAT_RGBX_FLOAT16
:
2153 case MESA_FORMAT_RGBX_UINT16
:
2154 case MESA_FORMAT_RGBX_SINT16
:
2155 case MESA_FORMAT_RGBX_FLOAT32
:
2156 case MESA_FORMAT_RGBX_UINT32
:
2157 case MESA_FORMAT_RGBX_SINT32
:
2160 case MESA_FORMAT_R10G10B10A2_UNORM
:
2161 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2164 case MESA_FORMAT_G8R8_SNORM
:
2165 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2168 case MESA_FORMAT_G16R16_SNORM
:
2169 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2172 case MESA_FORMAT_B8G8R8X8_SRGB
:
2173 case MESA_FORMAT_X8R8G8B8_SRGB
: