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 format_array_format_table_exists
= ONCE_FLAG_INIT
;
442 return MESA_FORMAT_NONE
;
445 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
447 (void *)(intptr_t)array_format
);
449 return (intptr_t)entry
->data
;
451 return MESA_FORMAT_NONE
;
454 /** Is the given format a compressed format? */
456 _mesa_is_format_compressed(mesa_format format
)
458 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
459 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
464 * Determine if the given format represents a packed depth/stencil buffer.
467 _mesa_is_format_packed_depth_stencil(mesa_format format
)
469 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
471 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
476 * Is the given format a signed/unsigned integer color format?
479 _mesa_is_format_integer_color(mesa_format format
)
481 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
482 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
483 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
484 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
485 info
->BaseFormat
!= GL_STENCIL_INDEX
;
490 * Is the given format an unsigned integer format?
493 _mesa_is_format_unsigned(mesa_format format
)
495 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
496 return _mesa_is_type_unsigned(info
->DataType
);
501 * Does the given format store signed values?
504 _mesa_is_format_signed(mesa_format format
)
506 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
507 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
508 /* these packed float formats only store unsigned values */
512 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
513 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
514 info
->DataType
== GL_INT
||
515 info
->DataType
== GL_FLOAT
);
520 * Is the given format an integer format?
523 _mesa_is_format_integer(mesa_format format
)
525 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
526 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
531 * Return true if the given format is a color format.
534 _mesa_is_format_color_format(mesa_format format
)
536 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
537 switch (info
->BaseFormat
) {
538 case GL_DEPTH_COMPONENT
:
539 case GL_STENCIL_INDEX
:
540 case GL_DEPTH_STENCIL
:
549 * Return color encoding for given format.
550 * \return GL_LINEAR or GL_SRGB
553 _mesa_get_format_color_encoding(mesa_format format
)
555 /* XXX this info should be encoded in gl_format_info */
557 case MESA_FORMAT_BGR_SRGB8
:
558 case MESA_FORMAT_A8B8G8R8_SRGB
:
559 case MESA_FORMAT_B8G8R8A8_SRGB
:
560 case MESA_FORMAT_A8R8G8B8_SRGB
:
561 case MESA_FORMAT_R8G8B8A8_SRGB
:
562 case MESA_FORMAT_L_SRGB8
:
563 case MESA_FORMAT_L8A8_SRGB
:
564 case MESA_FORMAT_A8L8_SRGB
:
565 case MESA_FORMAT_SRGB_DXT1
:
566 case MESA_FORMAT_SRGBA_DXT1
:
567 case MESA_FORMAT_SRGBA_DXT3
:
568 case MESA_FORMAT_SRGBA_DXT5
:
569 case MESA_FORMAT_R8G8B8X8_SRGB
:
570 case MESA_FORMAT_ETC2_SRGB8
:
571 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
572 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
573 case MESA_FORMAT_B8G8R8X8_SRGB
:
574 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
583 * Return TRUE if format is an ETC2 compressed format specified
584 * by GL_ARB_ES3_compatibility.
587 _mesa_is_format_etc2(mesa_format format
)
590 case MESA_FORMAT_ETC2_RGB8
:
591 case MESA_FORMAT_ETC2_SRGB8
:
592 case MESA_FORMAT_ETC2_RGBA8_EAC
:
593 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
594 case MESA_FORMAT_ETC2_R11_EAC
:
595 case MESA_FORMAT_ETC2_RG11_EAC
:
596 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
597 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
598 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
599 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
608 * For an sRGB format, return the corresponding linear color space format.
609 * For non-sRGB formats, return the format as-is.
612 _mesa_get_srgb_format_linear(mesa_format format
)
615 case MESA_FORMAT_BGR_SRGB8
:
616 format
= MESA_FORMAT_BGR_UNORM8
;
618 case MESA_FORMAT_A8B8G8R8_SRGB
:
619 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
621 case MESA_FORMAT_B8G8R8A8_SRGB
:
622 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
624 case MESA_FORMAT_A8R8G8B8_SRGB
:
625 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
627 case MESA_FORMAT_R8G8B8A8_SRGB
:
628 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
630 case MESA_FORMAT_L_SRGB8
:
631 format
= MESA_FORMAT_L_UNORM8
;
633 case MESA_FORMAT_L8A8_SRGB
:
634 format
= MESA_FORMAT_L8A8_UNORM
;
636 case MESA_FORMAT_A8L8_SRGB
:
637 format
= MESA_FORMAT_A8L8_UNORM
;
639 case MESA_FORMAT_SRGB_DXT1
:
640 format
= MESA_FORMAT_RGB_DXT1
;
642 case MESA_FORMAT_SRGBA_DXT1
:
643 format
= MESA_FORMAT_RGBA_DXT1
;
645 case MESA_FORMAT_SRGBA_DXT3
:
646 format
= MESA_FORMAT_RGBA_DXT3
;
648 case MESA_FORMAT_SRGBA_DXT5
:
649 format
= MESA_FORMAT_RGBA_DXT5
;
651 case MESA_FORMAT_R8G8B8X8_SRGB
:
652 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
654 case MESA_FORMAT_X8B8G8R8_SRGB
:
655 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
657 case MESA_FORMAT_ETC2_SRGB8
:
658 format
= MESA_FORMAT_ETC2_RGB8
;
660 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
661 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
663 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
664 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
666 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
667 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
669 case MESA_FORMAT_B8G8R8X8_SRGB
:
670 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
672 case MESA_FORMAT_X8R8G8B8_SRGB
:
673 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
683 * If the given format is a compressed format, return a corresponding
684 * uncompressed format.
687 _mesa_get_uncompressed_format(mesa_format format
)
690 case MESA_FORMAT_RGB_FXT1
:
691 return MESA_FORMAT_BGR_UNORM8
;
692 case MESA_FORMAT_RGBA_FXT1
:
693 return MESA_FORMAT_A8B8G8R8_UNORM
;
694 case MESA_FORMAT_RGB_DXT1
:
695 case MESA_FORMAT_SRGB_DXT1
:
696 return MESA_FORMAT_BGR_UNORM8
;
697 case MESA_FORMAT_RGBA_DXT1
:
698 case MESA_FORMAT_SRGBA_DXT1
:
699 return MESA_FORMAT_A8B8G8R8_UNORM
;
700 case MESA_FORMAT_RGBA_DXT3
:
701 case MESA_FORMAT_SRGBA_DXT3
:
702 return MESA_FORMAT_A8B8G8R8_UNORM
;
703 case MESA_FORMAT_RGBA_DXT5
:
704 case MESA_FORMAT_SRGBA_DXT5
:
705 return MESA_FORMAT_A8B8G8R8_UNORM
;
706 case MESA_FORMAT_R_RGTC1_UNORM
:
707 return MESA_FORMAT_R_UNORM8
;
708 case MESA_FORMAT_R_RGTC1_SNORM
:
709 return MESA_FORMAT_R_SNORM8
;
710 case MESA_FORMAT_RG_RGTC2_UNORM
:
711 return MESA_FORMAT_R8G8_UNORM
;
712 case MESA_FORMAT_RG_RGTC2_SNORM
:
713 return MESA_FORMAT_R8G8_SNORM
;
714 case MESA_FORMAT_L_LATC1_UNORM
:
715 return MESA_FORMAT_L_UNORM8
;
716 case MESA_FORMAT_L_LATC1_SNORM
:
717 return MESA_FORMAT_L_SNORM8
;
718 case MESA_FORMAT_LA_LATC2_UNORM
:
719 return MESA_FORMAT_L8A8_UNORM
;
720 case MESA_FORMAT_LA_LATC2_SNORM
:
721 return MESA_FORMAT_L8A8_SNORM
;
722 case MESA_FORMAT_ETC1_RGB8
:
723 case MESA_FORMAT_ETC2_RGB8
:
724 case MESA_FORMAT_ETC2_SRGB8
:
725 return MESA_FORMAT_BGR_UNORM8
;
726 case MESA_FORMAT_ETC2_RGBA8_EAC
:
727 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
728 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
729 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
730 return MESA_FORMAT_A8B8G8R8_UNORM
;
731 case MESA_FORMAT_ETC2_R11_EAC
:
732 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
733 return MESA_FORMAT_R_UNORM16
;
734 case MESA_FORMAT_ETC2_RG11_EAC
:
735 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
736 return MESA_FORMAT_R16G16_UNORM
;
737 case MESA_FORMAT_BPTC_RGBA_UNORM
:
738 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
739 return MESA_FORMAT_A8B8G8R8_UNORM
;
740 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
741 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
742 return MESA_FORMAT_RGB_FLOAT32
;
745 assert(!_mesa_is_format_compressed(format
));
753 _mesa_format_num_components(mesa_format format
)
755 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
756 return ((info
->RedBits
> 0) +
757 (info
->GreenBits
> 0) +
758 (info
->BlueBits
> 0) +
759 (info
->AlphaBits
> 0) +
760 (info
->LuminanceBits
> 0) +
761 (info
->IntensityBits
> 0) +
762 (info
->DepthBits
> 0) +
763 (info
->StencilBits
> 0));
768 * Returns true if a color format has data stored in the R/G/B/A channels,
769 * given an index from 0 to 3.
772 _mesa_format_has_color_component(mesa_format format
, int component
)
774 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
776 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
777 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
778 info
->BaseFormat
!= GL_STENCIL_INDEX
);
782 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
784 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
786 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
788 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
790 assert(!"Invalid color component: must be 0..3");
797 * Return number of bytes needed to store an image of the given size
798 * in the given format.
801 _mesa_format_image_size(mesa_format format
, GLsizei width
,
802 GLsizei height
, GLsizei depth
)
804 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
805 /* Strictly speaking, a conditional isn't needed here */
806 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
807 /* compressed format (2D only for now) */
808 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
809 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
810 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
811 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
816 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
823 * Same as _mesa_format_image_size() but returns a 64-bit value to
824 * accommodate very large textures.
827 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
828 GLsizei height
, GLsizei depth
)
830 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
831 /* Strictly speaking, a conditional isn't needed here */
832 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
833 /* compressed format (2D only for now) */
834 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
835 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
836 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
837 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
842 const uint64_t sz
= ((uint64_t) width
*
845 info
->BytesPerBlock
);
853 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
855 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
856 /* Strictly speaking, a conditional isn't needed here */
857 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
858 /* compressed format */
859 const GLuint bw
= info
->BlockWidth
;
860 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
861 const GLint stride
= wblocks
* info
->BytesPerBlock
;
865 const GLint stride
= width
* info
->BytesPerBlock
;
872 * Debug/test: check that all formats are handled in the
873 * _mesa_format_to_type_and_comps() function. When new pixel formats
874 * are added to Mesa, that function needs to be updated.
875 * This is a no-op after the first call.
878 check_format_to_type_and_comps(void)
882 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
885 /* This function will emit a problem/warning if the format is
888 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
893 * Do sanity checking of the format info table.
896 _mesa_test_formats(void)
900 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
902 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
903 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
906 assert(info
->Name
== i
);
908 if (info
->Name
== MESA_FORMAT_NONE
)
911 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
912 if (info
->RedBits
> 0) {
913 GLuint t
= info
->RedBits
+ info
->GreenBits
914 + info
->BlueBits
+ info
->AlphaBits
;
915 assert(t
/ 8 <= info
->BytesPerBlock
);
920 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
921 info
->DataType
== GL_SIGNED_NORMALIZED
||
922 info
->DataType
== GL_UNSIGNED_INT
||
923 info
->DataType
== GL_INT
||
924 info
->DataType
== GL_FLOAT
||
925 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
926 info
->DataType
== GL_NONE
);
928 if (info
->BaseFormat
== GL_RGB
) {
929 assert(info
->RedBits
> 0);
930 assert(info
->GreenBits
> 0);
931 assert(info
->BlueBits
> 0);
932 assert(info
->AlphaBits
== 0);
933 assert(info
->LuminanceBits
== 0);
934 assert(info
->IntensityBits
== 0);
936 else if (info
->BaseFormat
== GL_RGBA
) {
937 assert(info
->RedBits
> 0);
938 assert(info
->GreenBits
> 0);
939 assert(info
->BlueBits
> 0);
940 assert(info
->AlphaBits
> 0);
941 assert(info
->LuminanceBits
== 0);
942 assert(info
->IntensityBits
== 0);
944 else if (info
->BaseFormat
== GL_RG
) {
945 assert(info
->RedBits
> 0);
946 assert(info
->GreenBits
> 0);
947 assert(info
->BlueBits
== 0);
948 assert(info
->AlphaBits
== 0);
949 assert(info
->LuminanceBits
== 0);
950 assert(info
->IntensityBits
== 0);
952 else if (info
->BaseFormat
== GL_RED
) {
953 assert(info
->RedBits
> 0);
954 assert(info
->GreenBits
== 0);
955 assert(info
->BlueBits
== 0);
956 assert(info
->AlphaBits
== 0);
957 assert(info
->LuminanceBits
== 0);
958 assert(info
->IntensityBits
== 0);
960 else if (info
->BaseFormat
== GL_LUMINANCE
) {
961 assert(info
->RedBits
== 0);
962 assert(info
->GreenBits
== 0);
963 assert(info
->BlueBits
== 0);
964 assert(info
->AlphaBits
== 0);
965 assert(info
->LuminanceBits
> 0);
966 assert(info
->IntensityBits
== 0);
968 else if (info
->BaseFormat
== GL_INTENSITY
) {
969 assert(info
->RedBits
== 0);
970 assert(info
->GreenBits
== 0);
971 assert(info
->BlueBits
== 0);
972 assert(info
->AlphaBits
== 0);
973 assert(info
->LuminanceBits
== 0);
974 assert(info
->IntensityBits
> 0);
978 check_format_to_type_and_comps();
984 * Return datatype and number of components per texel for the given mesa_format.
985 * Only used for mipmap generation code.
988 _mesa_format_to_type_and_comps(mesa_format format
,
989 GLenum
*datatype
, GLuint
*comps
)
992 case MESA_FORMAT_A8B8G8R8_UNORM
:
993 case MESA_FORMAT_R8G8B8A8_UNORM
:
994 case MESA_FORMAT_B8G8R8A8_UNORM
:
995 case MESA_FORMAT_A8R8G8B8_UNORM
:
996 case MESA_FORMAT_X8B8G8R8_UNORM
:
997 case MESA_FORMAT_R8G8B8X8_UNORM
:
998 case MESA_FORMAT_B8G8R8X8_UNORM
:
999 case MESA_FORMAT_X8R8G8B8_UNORM
:
1000 *datatype
= GL_UNSIGNED_BYTE
;
1003 case MESA_FORMAT_BGR_UNORM8
:
1004 case MESA_FORMAT_RGB_UNORM8
:
1005 *datatype
= GL_UNSIGNED_BYTE
;
1008 case MESA_FORMAT_B5G6R5_UNORM
:
1009 case MESA_FORMAT_R5G6B5_UNORM
:
1010 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1014 case MESA_FORMAT_B4G4R4A4_UNORM
:
1015 case MESA_FORMAT_A4R4G4B4_UNORM
:
1016 case MESA_FORMAT_B4G4R4X4_UNORM
:
1017 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1021 case MESA_FORMAT_B5G5R5A1_UNORM
:
1022 case MESA_FORMAT_A1R5G5B5_UNORM
:
1023 case MESA_FORMAT_B5G5R5X1_UNORM
:
1024 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1028 case MESA_FORMAT_B10G10R10A2_UNORM
:
1029 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1033 case MESA_FORMAT_A1B5G5R5_UNORM
:
1034 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1038 case MESA_FORMAT_L4A4_UNORM
:
1039 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1043 case MESA_FORMAT_L8A8_UNORM
:
1044 case MESA_FORMAT_A8L8_UNORM
:
1045 case MESA_FORMAT_R8G8_UNORM
:
1046 case MESA_FORMAT_G8R8_UNORM
:
1047 *datatype
= GL_UNSIGNED_BYTE
;
1051 case MESA_FORMAT_L16A16_UNORM
:
1052 case MESA_FORMAT_A16L16_UNORM
:
1053 case MESA_FORMAT_R16G16_UNORM
:
1054 case MESA_FORMAT_G16R16_UNORM
:
1055 *datatype
= GL_UNSIGNED_SHORT
;
1059 case MESA_FORMAT_R_UNORM16
:
1060 case MESA_FORMAT_A_UNORM16
:
1061 case MESA_FORMAT_L_UNORM16
:
1062 case MESA_FORMAT_I_UNORM16
:
1063 *datatype
= GL_UNSIGNED_SHORT
;
1067 case MESA_FORMAT_R3G3B2_UNORM
:
1068 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1071 case MESA_FORMAT_A4B4G4R4_UNORM
:
1072 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1076 case MESA_FORMAT_R4G4B4A4_UNORM
:
1077 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1080 case MESA_FORMAT_R5G5B5A1_UNORM
:
1081 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1084 case MESA_FORMAT_A2B10G10R10_UNORM
:
1085 case MESA_FORMAT_A2B10G10R10_UINT
:
1086 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1089 case MESA_FORMAT_A2R10G10B10_UNORM
:
1090 case MESA_FORMAT_A2R10G10B10_UINT
:
1091 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1095 case MESA_FORMAT_B2G3R3_UNORM
:
1096 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1100 case MESA_FORMAT_A_UNORM8
:
1101 case MESA_FORMAT_L_UNORM8
:
1102 case MESA_FORMAT_I_UNORM8
:
1103 case MESA_FORMAT_R_UNORM8
:
1104 case MESA_FORMAT_S_UINT8
:
1105 *datatype
= GL_UNSIGNED_BYTE
;
1109 case MESA_FORMAT_YCBCR
:
1110 case MESA_FORMAT_YCBCR_REV
:
1111 *datatype
= GL_UNSIGNED_SHORT
;
1115 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1116 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1120 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1121 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1125 case MESA_FORMAT_Z_UNORM16
:
1126 *datatype
= GL_UNSIGNED_SHORT
;
1130 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1131 *datatype
= GL_UNSIGNED_INT
;
1135 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1136 *datatype
= GL_UNSIGNED_INT
;
1140 case MESA_FORMAT_Z_UNORM32
:
1141 *datatype
= GL_UNSIGNED_INT
;
1145 case MESA_FORMAT_Z_FLOAT32
:
1146 *datatype
= GL_FLOAT
;
1150 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1151 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1155 case MESA_FORMAT_R_SNORM8
:
1156 case MESA_FORMAT_A_SNORM8
:
1157 case MESA_FORMAT_L_SNORM8
:
1158 case MESA_FORMAT_I_SNORM8
:
1159 *datatype
= GL_BYTE
;
1162 case MESA_FORMAT_R8G8_SNORM
:
1163 case MESA_FORMAT_L8A8_SNORM
:
1164 case MESA_FORMAT_A8L8_SNORM
:
1165 *datatype
= GL_BYTE
;
1168 case MESA_FORMAT_A8B8G8R8_SNORM
:
1169 case MESA_FORMAT_R8G8B8A8_SNORM
:
1170 case MESA_FORMAT_X8B8G8R8_SNORM
:
1171 *datatype
= GL_BYTE
;
1175 case MESA_FORMAT_RGBA_UNORM16
:
1176 *datatype
= GL_UNSIGNED_SHORT
;
1180 case MESA_FORMAT_R_SNORM16
:
1181 case MESA_FORMAT_A_SNORM16
:
1182 case MESA_FORMAT_L_SNORM16
:
1183 case MESA_FORMAT_I_SNORM16
:
1184 *datatype
= GL_SHORT
;
1187 case MESA_FORMAT_R16G16_SNORM
:
1188 case MESA_FORMAT_LA_SNORM16
:
1189 *datatype
= GL_SHORT
;
1192 case MESA_FORMAT_RGB_SNORM16
:
1193 *datatype
= GL_SHORT
;
1196 case MESA_FORMAT_RGBA_SNORM16
:
1197 *datatype
= GL_SHORT
;
1201 case MESA_FORMAT_BGR_SRGB8
:
1202 *datatype
= GL_UNSIGNED_BYTE
;
1205 case MESA_FORMAT_A8B8G8R8_SRGB
:
1206 case MESA_FORMAT_B8G8R8A8_SRGB
:
1207 case MESA_FORMAT_A8R8G8B8_SRGB
:
1208 case MESA_FORMAT_R8G8B8A8_SRGB
:
1209 *datatype
= GL_UNSIGNED_BYTE
;
1212 case MESA_FORMAT_L_SRGB8
:
1213 *datatype
= GL_UNSIGNED_BYTE
;
1216 case MESA_FORMAT_L8A8_SRGB
:
1217 case MESA_FORMAT_A8L8_SRGB
:
1218 *datatype
= GL_UNSIGNED_BYTE
;
1222 case MESA_FORMAT_RGB_FXT1
:
1223 case MESA_FORMAT_RGBA_FXT1
:
1224 case MESA_FORMAT_RGB_DXT1
:
1225 case MESA_FORMAT_RGBA_DXT1
:
1226 case MESA_FORMAT_RGBA_DXT3
:
1227 case MESA_FORMAT_RGBA_DXT5
:
1228 case MESA_FORMAT_SRGB_DXT1
:
1229 case MESA_FORMAT_SRGBA_DXT1
:
1230 case MESA_FORMAT_SRGBA_DXT3
:
1231 case MESA_FORMAT_SRGBA_DXT5
:
1232 case MESA_FORMAT_R_RGTC1_UNORM
:
1233 case MESA_FORMAT_R_RGTC1_SNORM
:
1234 case MESA_FORMAT_RG_RGTC2_UNORM
:
1235 case MESA_FORMAT_RG_RGTC2_SNORM
:
1236 case MESA_FORMAT_L_LATC1_UNORM
:
1237 case MESA_FORMAT_L_LATC1_SNORM
:
1238 case MESA_FORMAT_LA_LATC2_UNORM
:
1239 case MESA_FORMAT_LA_LATC2_SNORM
:
1240 case MESA_FORMAT_ETC1_RGB8
:
1241 case MESA_FORMAT_ETC2_RGB8
:
1242 case MESA_FORMAT_ETC2_SRGB8
:
1243 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1244 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1245 case MESA_FORMAT_ETC2_R11_EAC
:
1246 case MESA_FORMAT_ETC2_RG11_EAC
:
1247 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1248 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1249 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1250 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1251 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1252 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1253 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1254 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1255 /* XXX generate error instead? */
1256 *datatype
= GL_UNSIGNED_BYTE
;
1260 case MESA_FORMAT_RGBA_FLOAT32
:
1261 *datatype
= GL_FLOAT
;
1264 case MESA_FORMAT_RGBA_FLOAT16
:
1265 *datatype
= GL_HALF_FLOAT_ARB
;
1268 case MESA_FORMAT_RGB_FLOAT32
:
1269 *datatype
= GL_FLOAT
;
1272 case MESA_FORMAT_RGB_FLOAT16
:
1273 *datatype
= GL_HALF_FLOAT_ARB
;
1276 case MESA_FORMAT_LA_FLOAT32
:
1277 case MESA_FORMAT_RG_FLOAT32
:
1278 *datatype
= GL_FLOAT
;
1281 case MESA_FORMAT_LA_FLOAT16
:
1282 case MESA_FORMAT_RG_FLOAT16
:
1283 *datatype
= GL_HALF_FLOAT_ARB
;
1286 case MESA_FORMAT_A_FLOAT32
:
1287 case MESA_FORMAT_L_FLOAT32
:
1288 case MESA_FORMAT_I_FLOAT32
:
1289 case MESA_FORMAT_R_FLOAT32
:
1290 *datatype
= GL_FLOAT
;
1293 case MESA_FORMAT_A_FLOAT16
:
1294 case MESA_FORMAT_L_FLOAT16
:
1295 case MESA_FORMAT_I_FLOAT16
:
1296 case MESA_FORMAT_R_FLOAT16
:
1297 *datatype
= GL_HALF_FLOAT_ARB
;
1301 case MESA_FORMAT_A_UINT8
:
1302 case MESA_FORMAT_L_UINT8
:
1303 case MESA_FORMAT_I_UINT8
:
1304 *datatype
= GL_UNSIGNED_BYTE
;
1307 case MESA_FORMAT_LA_UINT8
:
1308 *datatype
= GL_UNSIGNED_BYTE
;
1312 case MESA_FORMAT_A_UINT16
:
1313 case MESA_FORMAT_L_UINT16
:
1314 case MESA_FORMAT_I_UINT16
:
1315 *datatype
= GL_UNSIGNED_SHORT
;
1318 case MESA_FORMAT_LA_UINT16
:
1319 *datatype
= GL_UNSIGNED_SHORT
;
1322 case MESA_FORMAT_A_UINT32
:
1323 case MESA_FORMAT_L_UINT32
:
1324 case MESA_FORMAT_I_UINT32
:
1325 *datatype
= GL_UNSIGNED_INT
;
1328 case MESA_FORMAT_LA_UINT32
:
1329 *datatype
= GL_UNSIGNED_INT
;
1332 case MESA_FORMAT_A_SINT8
:
1333 case MESA_FORMAT_L_SINT8
:
1334 case MESA_FORMAT_I_SINT8
:
1335 *datatype
= GL_BYTE
;
1338 case MESA_FORMAT_LA_SINT8
:
1339 *datatype
= GL_BYTE
;
1343 case MESA_FORMAT_A_SINT16
:
1344 case MESA_FORMAT_L_SINT16
:
1345 case MESA_FORMAT_I_SINT16
:
1346 *datatype
= GL_SHORT
;
1349 case MESA_FORMAT_LA_SINT16
:
1350 *datatype
= GL_SHORT
;
1354 case MESA_FORMAT_A_SINT32
:
1355 case MESA_FORMAT_L_SINT32
:
1356 case MESA_FORMAT_I_SINT32
:
1360 case MESA_FORMAT_LA_SINT32
:
1365 case MESA_FORMAT_R_SINT8
:
1366 *datatype
= GL_BYTE
;
1369 case MESA_FORMAT_RG_SINT8
:
1370 *datatype
= GL_BYTE
;
1373 case MESA_FORMAT_RGB_SINT8
:
1374 *datatype
= GL_BYTE
;
1377 case MESA_FORMAT_RGBA_SINT8
:
1378 *datatype
= GL_BYTE
;
1381 case MESA_FORMAT_R_SINT16
:
1382 *datatype
= GL_SHORT
;
1385 case MESA_FORMAT_RG_SINT16
:
1386 *datatype
= GL_SHORT
;
1389 case MESA_FORMAT_RGB_SINT16
:
1390 *datatype
= GL_SHORT
;
1393 case MESA_FORMAT_RGBA_SINT16
:
1394 *datatype
= GL_SHORT
;
1397 case MESA_FORMAT_R_SINT32
:
1401 case MESA_FORMAT_RG_SINT32
:
1405 case MESA_FORMAT_RGB_SINT32
:
1409 case MESA_FORMAT_RGBA_SINT32
:
1415 * \name Non-normalized unsigned integer formats.
1417 case MESA_FORMAT_R_UINT8
:
1418 *datatype
= GL_UNSIGNED_BYTE
;
1421 case MESA_FORMAT_RG_UINT8
:
1422 *datatype
= GL_UNSIGNED_BYTE
;
1425 case MESA_FORMAT_RGB_UINT8
:
1426 *datatype
= GL_UNSIGNED_BYTE
;
1429 case MESA_FORMAT_RGBA_UINT8
:
1430 *datatype
= GL_UNSIGNED_BYTE
;
1433 case MESA_FORMAT_R_UINT16
:
1434 *datatype
= GL_UNSIGNED_SHORT
;
1437 case MESA_FORMAT_RG_UINT16
:
1438 *datatype
= GL_UNSIGNED_SHORT
;
1441 case MESA_FORMAT_RGB_UINT16
:
1442 *datatype
= GL_UNSIGNED_SHORT
;
1445 case MESA_FORMAT_RGBA_UINT16
:
1446 *datatype
= GL_UNSIGNED_SHORT
;
1449 case MESA_FORMAT_R_UINT32
:
1450 *datatype
= GL_UNSIGNED_INT
;
1453 case MESA_FORMAT_RG_UINT32
:
1454 *datatype
= GL_UNSIGNED_INT
;
1457 case MESA_FORMAT_RGB_UINT32
:
1458 *datatype
= GL_UNSIGNED_INT
;
1461 case MESA_FORMAT_RGBA_UINT32
:
1462 *datatype
= GL_UNSIGNED_INT
;
1466 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1467 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1471 case MESA_FORMAT_R11G11B10_FLOAT
:
1472 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1476 case MESA_FORMAT_B10G10R10A2_UINT
:
1477 case MESA_FORMAT_R10G10B10A2_UINT
:
1478 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1482 case MESA_FORMAT_R8G8B8X8_SRGB
:
1483 case MESA_FORMAT_X8B8G8R8_SRGB
:
1484 case MESA_FORMAT_RGBX_UINT8
:
1485 *datatype
= GL_UNSIGNED_BYTE
;
1489 case MESA_FORMAT_R8G8B8X8_SNORM
:
1490 case MESA_FORMAT_RGBX_SINT8
:
1491 *datatype
= GL_BYTE
;
1495 case MESA_FORMAT_B10G10R10X2_UNORM
:
1496 case MESA_FORMAT_R10G10B10X2_UNORM
:
1497 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1501 case MESA_FORMAT_RGBX_UNORM16
:
1502 case MESA_FORMAT_RGBX_UINT16
:
1503 *datatype
= GL_UNSIGNED_SHORT
;
1507 case MESA_FORMAT_RGBX_SNORM16
:
1508 case MESA_FORMAT_RGBX_SINT16
:
1509 *datatype
= GL_SHORT
;
1513 case MESA_FORMAT_RGBX_FLOAT16
:
1514 *datatype
= GL_HALF_FLOAT
;
1518 case MESA_FORMAT_RGBX_FLOAT32
:
1519 *datatype
= GL_FLOAT
;
1523 case MESA_FORMAT_RGBX_UINT32
:
1524 *datatype
= GL_UNSIGNED_INT
;
1528 case MESA_FORMAT_RGBX_SINT32
:
1533 case MESA_FORMAT_R10G10B10A2_UNORM
:
1534 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1538 case MESA_FORMAT_G8R8_SNORM
:
1539 *datatype
= GL_BYTE
;
1543 case MESA_FORMAT_G16R16_SNORM
:
1544 *datatype
= GL_SHORT
;
1548 case MESA_FORMAT_B8G8R8X8_SRGB
:
1549 case MESA_FORMAT_X8R8G8B8_SRGB
:
1550 *datatype
= GL_UNSIGNED_BYTE
;
1554 case MESA_FORMAT_COUNT
:
1558 case MESA_FORMAT_NONE
:
1559 /* For debug builds, warn if any formats are not handled */
1563 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1564 _mesa_get_format_name(format
));
1571 * Check if a mesa_format exactly matches a GL format/type combination
1572 * such that we can use memcpy() from one to the other.
1573 * \param mesa_format a MESA_FORMAT_x value
1574 * \param format the user-specified image format
1575 * \param type the user-specified image datatype
1576 * \param swapBytes typically the current pixel pack/unpack byteswap state
1577 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1580 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1581 GLenum format
, GLenum type
,
1582 GLboolean swapBytes
)
1584 const GLboolean littleEndian
= _mesa_little_endian();
1586 /* Note: When reading a GL format/type combination, the format lists channel
1587 * assignments from most significant channel in the type to least
1588 * significant. A type with _REV indicates that the assignments are
1589 * swapped, so they are listed from least significant to most significant.
1591 * For sanity, please keep this switch statement ordered the same as the
1592 * enums in formats.h.
1595 switch (mesa_format
) {
1597 case MESA_FORMAT_NONE
:
1598 case MESA_FORMAT_COUNT
:
1601 case MESA_FORMAT_A8B8G8R8_UNORM
:
1602 case MESA_FORMAT_A8B8G8R8_SRGB
:
1603 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1606 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1609 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1612 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1616 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1620 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1625 case MESA_FORMAT_R8G8B8A8_UNORM
:
1626 case MESA_FORMAT_R8G8B8A8_SRGB
:
1627 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1631 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1634 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1637 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1641 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1645 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1650 case MESA_FORMAT_B8G8R8A8_UNORM
:
1651 case MESA_FORMAT_B8G8R8A8_SRGB
:
1652 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1656 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1659 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1664 case MESA_FORMAT_A8R8G8B8_UNORM
:
1665 case MESA_FORMAT_A8R8G8B8_SRGB
:
1666 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1669 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1673 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1678 case MESA_FORMAT_X8B8G8R8_UNORM
:
1679 case MESA_FORMAT_R8G8B8X8_UNORM
:
1682 case MESA_FORMAT_B8G8R8X8_UNORM
:
1683 case MESA_FORMAT_X8R8G8B8_UNORM
:
1686 case MESA_FORMAT_BGR_UNORM8
:
1687 case MESA_FORMAT_BGR_SRGB8
:
1688 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1690 case MESA_FORMAT_RGB_UNORM8
:
1691 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1693 case MESA_FORMAT_B5G6R5_UNORM
:
1694 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1695 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1698 case MESA_FORMAT_R5G6B5_UNORM
:
1699 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1700 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1703 case MESA_FORMAT_B4G4R4A4_UNORM
:
1704 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1707 case MESA_FORMAT_A4R4G4B4_UNORM
:
1710 case MESA_FORMAT_A1B5G5R5_UNORM
:
1711 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1714 case MESA_FORMAT_B5G5R5A1_UNORM
:
1715 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1718 case MESA_FORMAT_A1R5G5B5_UNORM
:
1719 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1722 case MESA_FORMAT_L4A4_UNORM
:
1724 case MESA_FORMAT_L8A8_UNORM
:
1725 case MESA_FORMAT_L8A8_SRGB
:
1726 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1727 case MESA_FORMAT_A8L8_UNORM
:
1728 case MESA_FORMAT_A8L8_SRGB
:
1731 case MESA_FORMAT_L16A16_UNORM
:
1732 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1733 case MESA_FORMAT_A16L16_UNORM
:
1736 case MESA_FORMAT_B2G3R3_UNORM
:
1737 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1739 case MESA_FORMAT_R3G3B2_UNORM
:
1740 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1742 case MESA_FORMAT_A4B4G4R4_UNORM
:
1743 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1746 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1749 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1752 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1757 case MESA_FORMAT_R4G4B4A4_UNORM
:
1758 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1761 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1764 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1767 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1772 case MESA_FORMAT_R5G5B5A1_UNORM
:
1773 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1775 case MESA_FORMAT_A2B10G10R10_UNORM
:
1776 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1778 case MESA_FORMAT_A2B10G10R10_UINT
:
1779 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1781 case MESA_FORMAT_A2R10G10B10_UNORM
:
1782 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1784 case MESA_FORMAT_A2R10G10B10_UINT
:
1785 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1787 case MESA_FORMAT_A_UNORM8
:
1788 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1789 case MESA_FORMAT_A_UNORM16
:
1790 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1791 case MESA_FORMAT_L_UNORM8
:
1792 case MESA_FORMAT_L_SRGB8
:
1793 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1794 case MESA_FORMAT_L_UNORM16
:
1795 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1796 case MESA_FORMAT_I_UNORM8
:
1797 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1798 case MESA_FORMAT_I_UNORM16
:
1799 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1801 case MESA_FORMAT_YCBCR
:
1802 return format
== GL_YCBCR_MESA
&&
1803 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1804 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1805 case MESA_FORMAT_YCBCR_REV
:
1806 return format
== GL_YCBCR_MESA
&&
1807 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1808 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1810 case MESA_FORMAT_R_UNORM8
:
1811 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1812 case MESA_FORMAT_R8G8_UNORM
:
1813 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1814 case MESA_FORMAT_G8R8_UNORM
:
1817 case MESA_FORMAT_R_UNORM16
:
1818 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1820 case MESA_FORMAT_R16G16_UNORM
:
1821 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1823 case MESA_FORMAT_G16R16_UNORM
:
1826 case MESA_FORMAT_B10G10R10A2_UNORM
:
1827 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1830 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1831 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1833 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1834 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1837 case MESA_FORMAT_Z_UNORM16
:
1838 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1841 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1844 case MESA_FORMAT_Z_UNORM32
:
1845 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1848 case MESA_FORMAT_S_UINT8
:
1849 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1851 case MESA_FORMAT_SRGB_DXT1
:
1852 case MESA_FORMAT_SRGBA_DXT1
:
1853 case MESA_FORMAT_SRGBA_DXT3
:
1854 case MESA_FORMAT_SRGBA_DXT5
:
1857 case MESA_FORMAT_RGB_FXT1
:
1858 case MESA_FORMAT_RGBA_FXT1
:
1859 case MESA_FORMAT_RGB_DXT1
:
1860 case MESA_FORMAT_RGBA_DXT1
:
1861 case MESA_FORMAT_RGBA_DXT3
:
1862 case MESA_FORMAT_RGBA_DXT5
:
1865 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1866 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1867 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1868 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1871 case MESA_FORMAT_RGBA_FLOAT32
:
1872 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1873 case MESA_FORMAT_RGBA_FLOAT16
:
1874 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1876 case MESA_FORMAT_RGB_FLOAT32
:
1877 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1878 case MESA_FORMAT_RGB_FLOAT16
:
1879 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1881 case MESA_FORMAT_A_FLOAT32
:
1882 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1883 case MESA_FORMAT_A_FLOAT16
:
1884 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1886 case MESA_FORMAT_L_FLOAT32
:
1887 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1888 case MESA_FORMAT_L_FLOAT16
:
1889 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1891 case MESA_FORMAT_LA_FLOAT32
:
1892 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1893 case MESA_FORMAT_LA_FLOAT16
:
1894 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1896 case MESA_FORMAT_I_FLOAT32
:
1897 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1898 case MESA_FORMAT_I_FLOAT16
:
1899 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1901 case MESA_FORMAT_R_FLOAT32
:
1902 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1903 case MESA_FORMAT_R_FLOAT16
:
1904 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1906 case MESA_FORMAT_RG_FLOAT32
:
1907 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1908 case MESA_FORMAT_RG_FLOAT16
:
1909 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1911 case MESA_FORMAT_A_UINT8
:
1912 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1913 case MESA_FORMAT_A_UINT16
:
1914 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1916 case MESA_FORMAT_A_UINT32
:
1917 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1919 case MESA_FORMAT_A_SINT8
:
1920 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1921 case MESA_FORMAT_A_SINT16
:
1922 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1923 case MESA_FORMAT_A_SINT32
:
1924 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1926 case MESA_FORMAT_I_UINT8
:
1927 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1928 case MESA_FORMAT_I_UINT16
:
1929 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1930 case MESA_FORMAT_I_UINT32
:
1931 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1932 case MESA_FORMAT_I_SINT8
:
1933 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1934 case MESA_FORMAT_I_SINT16
:
1935 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1936 case MESA_FORMAT_I_SINT32
:
1937 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1939 case MESA_FORMAT_L_UINT8
:
1940 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1941 case MESA_FORMAT_L_UINT16
:
1942 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1944 case MESA_FORMAT_L_UINT32
:
1945 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1947 case MESA_FORMAT_L_SINT8
:
1948 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1949 case MESA_FORMAT_L_SINT16
:
1950 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1952 case MESA_FORMAT_L_SINT32
:
1953 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1955 case MESA_FORMAT_LA_UINT8
:
1956 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1957 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1958 case MESA_FORMAT_LA_UINT16
:
1959 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1960 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1961 case MESA_FORMAT_LA_UINT32
:
1962 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1963 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1964 case MESA_FORMAT_LA_SINT8
:
1965 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1967 case MESA_FORMAT_LA_SINT16
:
1968 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1970 case MESA_FORMAT_LA_SINT32
:
1971 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1974 case MESA_FORMAT_R_SINT8
:
1975 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1976 case MESA_FORMAT_RG_SINT8
:
1977 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1978 case MESA_FORMAT_RGB_SINT8
:
1979 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1980 case MESA_FORMAT_RGBA_SINT8
:
1981 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1982 case MESA_FORMAT_R_SINT16
:
1983 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1984 case MESA_FORMAT_RG_SINT16
:
1985 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1986 case MESA_FORMAT_RGB_SINT16
:
1987 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1988 case MESA_FORMAT_RGBA_SINT16
:
1989 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1990 case MESA_FORMAT_R_SINT32
:
1991 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1992 case MESA_FORMAT_RG_SINT32
:
1993 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1994 case MESA_FORMAT_RGB_SINT32
:
1995 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1996 case MESA_FORMAT_RGBA_SINT32
:
1997 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1999 case MESA_FORMAT_R_UINT8
:
2000 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
2001 case MESA_FORMAT_RG_UINT8
:
2002 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2003 case MESA_FORMAT_RGB_UINT8
:
2004 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
2005 case MESA_FORMAT_RGBA_UINT8
:
2006 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
2008 case MESA_FORMAT_R_UINT16
:
2009 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2011 case MESA_FORMAT_RG_UINT16
:
2012 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2013 case MESA_FORMAT_RGB_UINT16
:
2014 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2016 case MESA_FORMAT_RGBA_UINT16
:
2017 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2019 case MESA_FORMAT_R_UINT32
:
2020 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2021 case MESA_FORMAT_RG_UINT32
:
2022 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2023 case MESA_FORMAT_RGB_UINT32
:
2024 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2025 case MESA_FORMAT_RGBA_UINT32
:
2026 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2028 case MESA_FORMAT_R_SNORM8
:
2029 return format
== GL_RED
&& type
== GL_BYTE
;
2030 case MESA_FORMAT_R8G8_SNORM
:
2031 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2033 case MESA_FORMAT_X8B8G8R8_SNORM
:
2036 case MESA_FORMAT_A8B8G8R8_SNORM
:
2037 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2040 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2045 case MESA_FORMAT_R8G8B8A8_SNORM
:
2046 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2049 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2054 case MESA_FORMAT_R_SNORM16
:
2055 return format
== GL_RED
&& type
== GL_SHORT
&&
2057 case MESA_FORMAT_R16G16_SNORM
:
2058 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2059 case MESA_FORMAT_RGB_SNORM16
:
2060 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2061 case MESA_FORMAT_RGBA_SNORM16
:
2062 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2063 case MESA_FORMAT_RGBA_UNORM16
:
2064 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2067 case MESA_FORMAT_R_RGTC1_UNORM
:
2068 case MESA_FORMAT_R_RGTC1_SNORM
:
2069 case MESA_FORMAT_RG_RGTC2_UNORM
:
2070 case MESA_FORMAT_RG_RGTC2_SNORM
:
2073 case MESA_FORMAT_L_LATC1_UNORM
:
2074 case MESA_FORMAT_L_LATC1_SNORM
:
2075 case MESA_FORMAT_LA_LATC2_UNORM
:
2076 case MESA_FORMAT_LA_LATC2_SNORM
:
2079 case MESA_FORMAT_ETC1_RGB8
:
2080 case MESA_FORMAT_ETC2_RGB8
:
2081 case MESA_FORMAT_ETC2_SRGB8
:
2082 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2083 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2084 case MESA_FORMAT_ETC2_R11_EAC
:
2085 case MESA_FORMAT_ETC2_RG11_EAC
:
2086 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2087 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2088 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2089 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2092 case MESA_FORMAT_A_SNORM8
:
2093 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2094 case MESA_FORMAT_L_SNORM8
:
2095 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2096 case MESA_FORMAT_L8A8_SNORM
:
2097 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2098 littleEndian
&& !swapBytes
;
2099 case MESA_FORMAT_A8L8_SNORM
:
2100 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2101 !littleEndian
&& !swapBytes
;
2102 case MESA_FORMAT_I_SNORM8
:
2103 return format
== GL_RED
&& type
== GL_BYTE
;
2104 case MESA_FORMAT_A_SNORM16
:
2105 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2106 case MESA_FORMAT_L_SNORM16
:
2107 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2108 case MESA_FORMAT_LA_SNORM16
:
2109 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2110 littleEndian
&& !swapBytes
;
2111 case MESA_FORMAT_I_SNORM16
:
2112 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2115 case MESA_FORMAT_B10G10R10A2_UINT
:
2116 return (format
== GL_BGRA_INTEGER_EXT
&&
2117 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2120 case MESA_FORMAT_R10G10B10A2_UINT
:
2121 return (format
== GL_RGBA_INTEGER_EXT
&&
2122 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2125 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2126 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2129 case MESA_FORMAT_R11G11B10_FLOAT
:
2130 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2133 case MESA_FORMAT_Z_FLOAT32
:
2134 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2136 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2137 return format
== GL_DEPTH_STENCIL
&&
2138 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2140 case MESA_FORMAT_B4G4R4X4_UNORM
:
2141 case MESA_FORMAT_B5G5R5X1_UNORM
:
2142 case MESA_FORMAT_R8G8B8X8_SNORM
:
2143 case MESA_FORMAT_R8G8B8X8_SRGB
:
2144 case MESA_FORMAT_X8B8G8R8_SRGB
:
2145 case MESA_FORMAT_RGBX_UINT8
:
2146 case MESA_FORMAT_RGBX_SINT8
:
2147 case MESA_FORMAT_B10G10R10X2_UNORM
:
2148 case MESA_FORMAT_R10G10B10X2_UNORM
:
2149 case MESA_FORMAT_RGBX_UNORM16
:
2150 case MESA_FORMAT_RGBX_SNORM16
:
2151 case MESA_FORMAT_RGBX_FLOAT16
:
2152 case MESA_FORMAT_RGBX_UINT16
:
2153 case MESA_FORMAT_RGBX_SINT16
:
2154 case MESA_FORMAT_RGBX_FLOAT32
:
2155 case MESA_FORMAT_RGBX_UINT32
:
2156 case MESA_FORMAT_RGBX_SINT32
:
2159 case MESA_FORMAT_R10G10B10A2_UNORM
:
2160 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2163 case MESA_FORMAT_G8R8_SNORM
:
2164 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2167 case MESA_FORMAT_G16R16_SNORM
:
2168 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2171 case MESA_FORMAT_B8G8R8X8_SRGB
:
2172 case MESA_FORMAT_X8R8G8B8_SRGB
: