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.c"
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()
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 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
401 info
= _mesa_get_format_info(f
);
402 if (!info
->ArrayFormat
)
405 if (_mesa_little_endian()) {
406 array_format
= info
->ArrayFormat
;
408 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
411 /* This can happen and does for some of the BGR formats. Let's take
412 * the first one in the list.
414 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
416 (void *)(intptr_t)array_format
))
419 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
421 (void *)(intptr_t)array_format
,
422 (void *)(intptr_t)f
);
427 _mesa_format_from_array_format(uint32_t array_format
)
429 struct hash_entry
*entry
;
431 assert(_mesa_format_is_mesa_array_format(array_format
));
433 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
435 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
437 (void *)(intptr_t)array_format
);
439 return (intptr_t)entry
->data
;
441 return MESA_FORMAT_NONE
;
444 /** Is the given format a compressed format? */
446 _mesa_is_format_compressed(mesa_format format
)
448 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
449 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
454 * Determine if the given format represents a packed depth/stencil buffer.
457 _mesa_is_format_packed_depth_stencil(mesa_format format
)
459 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
461 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
466 * Is the given format a signed/unsigned integer color format?
469 _mesa_is_format_integer_color(mesa_format format
)
471 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
472 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
473 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
474 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
475 info
->BaseFormat
!= GL_STENCIL_INDEX
;
480 * Is the given format an unsigned integer format?
483 _mesa_is_format_unsigned(mesa_format format
)
485 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
486 return _mesa_is_type_unsigned(info
->DataType
);
491 * Does the given format store signed values?
494 _mesa_is_format_signed(mesa_format format
)
496 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
497 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
498 /* these packed float formats only store unsigned values */
502 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
503 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
504 info
->DataType
== GL_INT
||
505 info
->DataType
== GL_FLOAT
);
510 * Is the given format an integer format?
513 _mesa_is_format_integer(mesa_format format
)
515 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
516 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
521 * Return true if the given format is a color format.
524 _mesa_is_format_color_format(mesa_format format
)
526 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
527 switch (info
->BaseFormat
) {
528 case GL_DEPTH_COMPONENT
:
529 case GL_STENCIL_INDEX
:
530 case GL_DEPTH_STENCIL
:
539 * Return color encoding for given format.
540 * \return GL_LINEAR or GL_SRGB
543 _mesa_get_format_color_encoding(mesa_format format
)
545 /* XXX this info should be encoded in gl_format_info */
547 case MESA_FORMAT_BGR_SRGB8
:
548 case MESA_FORMAT_A8B8G8R8_SRGB
:
549 case MESA_FORMAT_B8G8R8A8_SRGB
:
550 case MESA_FORMAT_A8R8G8B8_SRGB
:
551 case MESA_FORMAT_R8G8B8A8_SRGB
:
552 case MESA_FORMAT_L_SRGB8
:
553 case MESA_FORMAT_L8A8_SRGB
:
554 case MESA_FORMAT_A8L8_SRGB
:
555 case MESA_FORMAT_SRGB_DXT1
:
556 case MESA_FORMAT_SRGBA_DXT1
:
557 case MESA_FORMAT_SRGBA_DXT3
:
558 case MESA_FORMAT_SRGBA_DXT5
:
559 case MESA_FORMAT_R8G8B8X8_SRGB
:
560 case MESA_FORMAT_ETC2_SRGB8
:
561 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
562 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
563 case MESA_FORMAT_B8G8R8X8_SRGB
:
564 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
573 * Return TRUE if format is an ETC2 compressed format specified
574 * by GL_ARB_ES3_compatibility.
577 _mesa_is_format_etc2(mesa_format format
)
580 case MESA_FORMAT_ETC2_RGB8
:
581 case MESA_FORMAT_ETC2_SRGB8
:
582 case MESA_FORMAT_ETC2_RGBA8_EAC
:
583 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
584 case MESA_FORMAT_ETC2_R11_EAC
:
585 case MESA_FORMAT_ETC2_RG11_EAC
:
586 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
587 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
588 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
589 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
598 * For an sRGB format, return the corresponding linear color space format.
599 * For non-sRGB formats, return the format as-is.
602 _mesa_get_srgb_format_linear(mesa_format format
)
605 case MESA_FORMAT_BGR_SRGB8
:
606 format
= MESA_FORMAT_BGR_UNORM8
;
608 case MESA_FORMAT_A8B8G8R8_SRGB
:
609 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
611 case MESA_FORMAT_B8G8R8A8_SRGB
:
612 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
614 case MESA_FORMAT_A8R8G8B8_SRGB
:
615 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
617 case MESA_FORMAT_R8G8B8A8_SRGB
:
618 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
620 case MESA_FORMAT_L_SRGB8
:
621 format
= MESA_FORMAT_L_UNORM8
;
623 case MESA_FORMAT_L8A8_SRGB
:
624 format
= MESA_FORMAT_L8A8_UNORM
;
626 case MESA_FORMAT_A8L8_SRGB
:
627 format
= MESA_FORMAT_A8L8_UNORM
;
629 case MESA_FORMAT_SRGB_DXT1
:
630 format
= MESA_FORMAT_RGB_DXT1
;
632 case MESA_FORMAT_SRGBA_DXT1
:
633 format
= MESA_FORMAT_RGBA_DXT1
;
635 case MESA_FORMAT_SRGBA_DXT3
:
636 format
= MESA_FORMAT_RGBA_DXT3
;
638 case MESA_FORMAT_SRGBA_DXT5
:
639 format
= MESA_FORMAT_RGBA_DXT5
;
641 case MESA_FORMAT_R8G8B8X8_SRGB
:
642 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
644 case MESA_FORMAT_X8B8G8R8_SRGB
:
645 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
647 case MESA_FORMAT_ETC2_SRGB8
:
648 format
= MESA_FORMAT_ETC2_RGB8
;
650 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
651 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
653 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
654 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
656 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
657 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
659 case MESA_FORMAT_B8G8R8X8_SRGB
:
660 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
662 case MESA_FORMAT_X8R8G8B8_SRGB
:
663 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
673 * If the given format is a compressed format, return a corresponding
674 * uncompressed format.
677 _mesa_get_uncompressed_format(mesa_format format
)
680 case MESA_FORMAT_RGB_FXT1
:
681 return MESA_FORMAT_BGR_UNORM8
;
682 case MESA_FORMAT_RGBA_FXT1
:
683 return MESA_FORMAT_A8B8G8R8_UNORM
;
684 case MESA_FORMAT_RGB_DXT1
:
685 case MESA_FORMAT_SRGB_DXT1
:
686 return MESA_FORMAT_BGR_UNORM8
;
687 case MESA_FORMAT_RGBA_DXT1
:
688 case MESA_FORMAT_SRGBA_DXT1
:
689 return MESA_FORMAT_A8B8G8R8_UNORM
;
690 case MESA_FORMAT_RGBA_DXT3
:
691 case MESA_FORMAT_SRGBA_DXT3
:
692 return MESA_FORMAT_A8B8G8R8_UNORM
;
693 case MESA_FORMAT_RGBA_DXT5
:
694 case MESA_FORMAT_SRGBA_DXT5
:
695 return MESA_FORMAT_A8B8G8R8_UNORM
;
696 case MESA_FORMAT_R_RGTC1_UNORM
:
697 return MESA_FORMAT_R_UNORM8
;
698 case MESA_FORMAT_R_RGTC1_SNORM
:
699 return MESA_FORMAT_R_SNORM8
;
700 case MESA_FORMAT_RG_RGTC2_UNORM
:
701 return MESA_FORMAT_R8G8_UNORM
;
702 case MESA_FORMAT_RG_RGTC2_SNORM
:
703 return MESA_FORMAT_R8G8_SNORM
;
704 case MESA_FORMAT_L_LATC1_UNORM
:
705 return MESA_FORMAT_L_UNORM8
;
706 case MESA_FORMAT_L_LATC1_SNORM
:
707 return MESA_FORMAT_L_SNORM8
;
708 case MESA_FORMAT_LA_LATC2_UNORM
:
709 return MESA_FORMAT_L8A8_UNORM
;
710 case MESA_FORMAT_LA_LATC2_SNORM
:
711 return MESA_FORMAT_L8A8_SNORM
;
712 case MESA_FORMAT_ETC1_RGB8
:
713 case MESA_FORMAT_ETC2_RGB8
:
714 case MESA_FORMAT_ETC2_SRGB8
:
715 return MESA_FORMAT_BGR_UNORM8
;
716 case MESA_FORMAT_ETC2_RGBA8_EAC
:
717 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
718 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
719 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
720 return MESA_FORMAT_A8B8G8R8_UNORM
;
721 case MESA_FORMAT_ETC2_R11_EAC
:
722 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
723 return MESA_FORMAT_R_UNORM16
;
724 case MESA_FORMAT_ETC2_RG11_EAC
:
725 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
726 return MESA_FORMAT_R16G16_UNORM
;
727 case MESA_FORMAT_BPTC_RGBA_UNORM
:
728 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
729 return MESA_FORMAT_A8B8G8R8_UNORM
;
730 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
731 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
732 return MESA_FORMAT_RGB_FLOAT32
;
735 assert(!_mesa_is_format_compressed(format
));
743 _mesa_format_num_components(mesa_format format
)
745 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
746 return ((info
->RedBits
> 0) +
747 (info
->GreenBits
> 0) +
748 (info
->BlueBits
> 0) +
749 (info
->AlphaBits
> 0) +
750 (info
->LuminanceBits
> 0) +
751 (info
->IntensityBits
> 0) +
752 (info
->DepthBits
> 0) +
753 (info
->StencilBits
> 0));
758 * Returns true if a color format has data stored in the R/G/B/A channels,
759 * given an index from 0 to 3.
762 _mesa_format_has_color_component(mesa_format format
, int component
)
764 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
766 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
767 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
768 info
->BaseFormat
!= GL_STENCIL_INDEX
);
772 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
774 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
776 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
778 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
780 assert(!"Invalid color component: must be 0..3");
787 * Return number of bytes needed to store an image of the given size
788 * in the given format.
791 _mesa_format_image_size(mesa_format format
, GLsizei width
,
792 GLsizei height
, GLsizei depth
)
794 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
795 /* Strictly speaking, a conditional isn't needed here */
796 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
797 /* compressed format (2D only for now) */
798 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
799 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
800 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
801 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
806 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
813 * Same as _mesa_format_image_size() but returns a 64-bit value to
814 * accomodate very large textures.
817 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
818 GLsizei height
, GLsizei depth
)
820 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
821 /* Strictly speaking, a conditional isn't needed here */
822 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
823 /* compressed format (2D only for now) */
824 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
825 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
826 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
827 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
832 const uint64_t sz
= ((uint64_t) width
*
835 info
->BytesPerBlock
);
843 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
845 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
846 /* Strictly speaking, a conditional isn't needed here */
847 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
848 /* compressed format */
849 const GLuint bw
= info
->BlockWidth
;
850 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
851 const GLint stride
= wblocks
* info
->BytesPerBlock
;
855 const GLint stride
= width
* info
->BytesPerBlock
;
862 * Debug/test: check that all formats are handled in the
863 * _mesa_format_to_type_and_comps() function. When new pixel formats
864 * are added to Mesa, that function needs to be updated.
865 * This is a no-op after the first call.
868 check_format_to_type_and_comps(void)
872 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
875 /* This function will emit a problem/warning if the format is
878 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
883 * Do sanity checking of the format info table.
886 _mesa_test_formats(void)
890 STATIC_ASSERT(Elements(format_info
) == MESA_FORMAT_COUNT
);
892 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
893 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
896 assert(info
->Name
== i
);
898 if (info
->Name
== MESA_FORMAT_NONE
)
901 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
902 if (info
->RedBits
> 0) {
903 GLuint t
= info
->RedBits
+ info
->GreenBits
904 + info
->BlueBits
+ info
->AlphaBits
;
905 assert(t
/ 8 <= info
->BytesPerBlock
);
910 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
911 info
->DataType
== GL_SIGNED_NORMALIZED
||
912 info
->DataType
== GL_UNSIGNED_INT
||
913 info
->DataType
== GL_INT
||
914 info
->DataType
== GL_FLOAT
||
915 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
916 info
->DataType
== GL_NONE
);
918 if (info
->BaseFormat
== GL_RGB
) {
919 assert(info
->RedBits
> 0);
920 assert(info
->GreenBits
> 0);
921 assert(info
->BlueBits
> 0);
922 assert(info
->AlphaBits
== 0);
923 assert(info
->LuminanceBits
== 0);
924 assert(info
->IntensityBits
== 0);
926 else if (info
->BaseFormat
== GL_RGBA
) {
927 assert(info
->RedBits
> 0);
928 assert(info
->GreenBits
> 0);
929 assert(info
->BlueBits
> 0);
930 assert(info
->AlphaBits
> 0);
931 assert(info
->LuminanceBits
== 0);
932 assert(info
->IntensityBits
== 0);
934 else if (info
->BaseFormat
== GL_RG
) {
935 assert(info
->RedBits
> 0);
936 assert(info
->GreenBits
> 0);
937 assert(info
->BlueBits
== 0);
938 assert(info
->AlphaBits
== 0);
939 assert(info
->LuminanceBits
== 0);
940 assert(info
->IntensityBits
== 0);
942 else if (info
->BaseFormat
== GL_RED
) {
943 assert(info
->RedBits
> 0);
944 assert(info
->GreenBits
== 0);
945 assert(info
->BlueBits
== 0);
946 assert(info
->AlphaBits
== 0);
947 assert(info
->LuminanceBits
== 0);
948 assert(info
->IntensityBits
== 0);
950 else if (info
->BaseFormat
== GL_LUMINANCE
) {
951 assert(info
->RedBits
== 0);
952 assert(info
->GreenBits
== 0);
953 assert(info
->BlueBits
== 0);
954 assert(info
->AlphaBits
== 0);
955 assert(info
->LuminanceBits
> 0);
956 assert(info
->IntensityBits
== 0);
958 else if (info
->BaseFormat
== GL_INTENSITY
) {
959 assert(info
->RedBits
== 0);
960 assert(info
->GreenBits
== 0);
961 assert(info
->BlueBits
== 0);
962 assert(info
->AlphaBits
== 0);
963 assert(info
->LuminanceBits
== 0);
964 assert(info
->IntensityBits
> 0);
968 check_format_to_type_and_comps();
974 * Return datatype and number of components per texel for the given mesa_format.
975 * Only used for mipmap generation code.
978 _mesa_format_to_type_and_comps(mesa_format format
,
979 GLenum
*datatype
, GLuint
*comps
)
982 case MESA_FORMAT_A8B8G8R8_UNORM
:
983 case MESA_FORMAT_R8G8B8A8_UNORM
:
984 case MESA_FORMAT_B8G8R8A8_UNORM
:
985 case MESA_FORMAT_A8R8G8B8_UNORM
:
986 case MESA_FORMAT_X8B8G8R8_UNORM
:
987 case MESA_FORMAT_R8G8B8X8_UNORM
:
988 case MESA_FORMAT_B8G8R8X8_UNORM
:
989 case MESA_FORMAT_X8R8G8B8_UNORM
:
990 *datatype
= GL_UNSIGNED_BYTE
;
993 case MESA_FORMAT_BGR_UNORM8
:
994 case MESA_FORMAT_RGB_UNORM8
:
995 *datatype
= GL_UNSIGNED_BYTE
;
998 case MESA_FORMAT_B5G6R5_UNORM
:
999 case MESA_FORMAT_R5G6B5_UNORM
:
1000 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
1004 case MESA_FORMAT_B4G4R4A4_UNORM
:
1005 case MESA_FORMAT_A4R4G4B4_UNORM
:
1006 case MESA_FORMAT_B4G4R4X4_UNORM
:
1007 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1011 case MESA_FORMAT_B5G5R5A1_UNORM
:
1012 case MESA_FORMAT_A1R5G5B5_UNORM
:
1013 case MESA_FORMAT_B5G5R5X1_UNORM
:
1014 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1018 case MESA_FORMAT_B10G10R10A2_UNORM
:
1019 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1023 case MESA_FORMAT_A1B5G5R5_UNORM
:
1024 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1028 case MESA_FORMAT_L4A4_UNORM
:
1029 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
1033 case MESA_FORMAT_L8A8_UNORM
:
1034 case MESA_FORMAT_A8L8_UNORM
:
1035 case MESA_FORMAT_R8G8_UNORM
:
1036 case MESA_FORMAT_G8R8_UNORM
:
1037 *datatype
= GL_UNSIGNED_BYTE
;
1041 case MESA_FORMAT_L16A16_UNORM
:
1042 case MESA_FORMAT_A16L16_UNORM
:
1043 case MESA_FORMAT_R16G16_UNORM
:
1044 case MESA_FORMAT_G16R16_UNORM
:
1045 *datatype
= GL_UNSIGNED_SHORT
;
1049 case MESA_FORMAT_R_UNORM16
:
1050 case MESA_FORMAT_A_UNORM16
:
1051 case MESA_FORMAT_L_UNORM16
:
1052 case MESA_FORMAT_I_UNORM16
:
1053 *datatype
= GL_UNSIGNED_SHORT
;
1057 case MESA_FORMAT_R3G3B2_UNORM
:
1058 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1061 case MESA_FORMAT_A4B4G4R4_UNORM
:
1062 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1066 case MESA_FORMAT_R4G4B4A4_UNORM
:
1067 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1070 case MESA_FORMAT_R5G5B5A1_UNORM
:
1071 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1074 case MESA_FORMAT_A2B10G10R10_UNORM
:
1075 case MESA_FORMAT_A2B10G10R10_UINT
:
1076 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1079 case MESA_FORMAT_A2R10G10B10_UNORM
:
1080 case MESA_FORMAT_A2R10G10B10_UINT
:
1081 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1085 case MESA_FORMAT_B2G3R3_UNORM
:
1086 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1090 case MESA_FORMAT_A_UNORM8
:
1091 case MESA_FORMAT_L_UNORM8
:
1092 case MESA_FORMAT_I_UNORM8
:
1093 case MESA_FORMAT_R_UNORM8
:
1094 case MESA_FORMAT_S_UINT8
:
1095 *datatype
= GL_UNSIGNED_BYTE
;
1099 case MESA_FORMAT_YCBCR
:
1100 case MESA_FORMAT_YCBCR_REV
:
1101 *datatype
= GL_UNSIGNED_SHORT
;
1105 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1106 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1110 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1111 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1115 case MESA_FORMAT_Z_UNORM16
:
1116 *datatype
= GL_UNSIGNED_SHORT
;
1120 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1121 *datatype
= GL_UNSIGNED_INT
;
1125 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1126 *datatype
= GL_UNSIGNED_INT
;
1130 case MESA_FORMAT_Z_UNORM32
:
1131 *datatype
= GL_UNSIGNED_INT
;
1135 case MESA_FORMAT_Z_FLOAT32
:
1136 *datatype
= GL_FLOAT
;
1140 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1141 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1145 case MESA_FORMAT_R_SNORM8
:
1146 case MESA_FORMAT_A_SNORM8
:
1147 case MESA_FORMAT_L_SNORM8
:
1148 case MESA_FORMAT_I_SNORM8
:
1149 *datatype
= GL_BYTE
;
1152 case MESA_FORMAT_R8G8_SNORM
:
1153 case MESA_FORMAT_L8A8_SNORM
:
1154 case MESA_FORMAT_A8L8_SNORM
:
1155 *datatype
= GL_BYTE
;
1158 case MESA_FORMAT_A8B8G8R8_SNORM
:
1159 case MESA_FORMAT_R8G8B8A8_SNORM
:
1160 case MESA_FORMAT_X8B8G8R8_SNORM
:
1161 *datatype
= GL_BYTE
;
1165 case MESA_FORMAT_RGBA_UNORM16
:
1166 *datatype
= GL_UNSIGNED_SHORT
;
1170 case MESA_FORMAT_R_SNORM16
:
1171 case MESA_FORMAT_A_SNORM16
:
1172 case MESA_FORMAT_L_SNORM16
:
1173 case MESA_FORMAT_I_SNORM16
:
1174 *datatype
= GL_SHORT
;
1177 case MESA_FORMAT_R16G16_SNORM
:
1178 case MESA_FORMAT_LA_SNORM16
:
1179 *datatype
= GL_SHORT
;
1182 case MESA_FORMAT_RGB_SNORM16
:
1183 *datatype
= GL_SHORT
;
1186 case MESA_FORMAT_RGBA_SNORM16
:
1187 *datatype
= GL_SHORT
;
1191 case MESA_FORMAT_BGR_SRGB8
:
1192 *datatype
= GL_UNSIGNED_BYTE
;
1195 case MESA_FORMAT_A8B8G8R8_SRGB
:
1196 case MESA_FORMAT_B8G8R8A8_SRGB
:
1197 case MESA_FORMAT_A8R8G8B8_SRGB
:
1198 case MESA_FORMAT_R8G8B8A8_SRGB
:
1199 *datatype
= GL_UNSIGNED_BYTE
;
1202 case MESA_FORMAT_L_SRGB8
:
1203 *datatype
= GL_UNSIGNED_BYTE
;
1206 case MESA_FORMAT_L8A8_SRGB
:
1207 case MESA_FORMAT_A8L8_SRGB
:
1208 *datatype
= GL_UNSIGNED_BYTE
;
1212 case MESA_FORMAT_RGB_FXT1
:
1213 case MESA_FORMAT_RGBA_FXT1
:
1214 case MESA_FORMAT_RGB_DXT1
:
1215 case MESA_FORMAT_RGBA_DXT1
:
1216 case MESA_FORMAT_RGBA_DXT3
:
1217 case MESA_FORMAT_RGBA_DXT5
:
1218 case MESA_FORMAT_SRGB_DXT1
:
1219 case MESA_FORMAT_SRGBA_DXT1
:
1220 case MESA_FORMAT_SRGBA_DXT3
:
1221 case MESA_FORMAT_SRGBA_DXT5
:
1222 case MESA_FORMAT_R_RGTC1_UNORM
:
1223 case MESA_FORMAT_R_RGTC1_SNORM
:
1224 case MESA_FORMAT_RG_RGTC2_UNORM
:
1225 case MESA_FORMAT_RG_RGTC2_SNORM
:
1226 case MESA_FORMAT_L_LATC1_UNORM
:
1227 case MESA_FORMAT_L_LATC1_SNORM
:
1228 case MESA_FORMAT_LA_LATC2_UNORM
:
1229 case MESA_FORMAT_LA_LATC2_SNORM
:
1230 case MESA_FORMAT_ETC1_RGB8
:
1231 case MESA_FORMAT_ETC2_RGB8
:
1232 case MESA_FORMAT_ETC2_SRGB8
:
1233 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1234 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1235 case MESA_FORMAT_ETC2_R11_EAC
:
1236 case MESA_FORMAT_ETC2_RG11_EAC
:
1237 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1238 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1239 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1240 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1241 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1242 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1243 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1244 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1245 /* XXX generate error instead? */
1246 *datatype
= GL_UNSIGNED_BYTE
;
1250 case MESA_FORMAT_RGBA_FLOAT32
:
1251 *datatype
= GL_FLOAT
;
1254 case MESA_FORMAT_RGBA_FLOAT16
:
1255 *datatype
= GL_HALF_FLOAT_ARB
;
1258 case MESA_FORMAT_RGB_FLOAT32
:
1259 *datatype
= GL_FLOAT
;
1262 case MESA_FORMAT_RGB_FLOAT16
:
1263 *datatype
= GL_HALF_FLOAT_ARB
;
1266 case MESA_FORMAT_LA_FLOAT32
:
1267 case MESA_FORMAT_RG_FLOAT32
:
1268 *datatype
= GL_FLOAT
;
1271 case MESA_FORMAT_LA_FLOAT16
:
1272 case MESA_FORMAT_RG_FLOAT16
:
1273 *datatype
= GL_HALF_FLOAT_ARB
;
1276 case MESA_FORMAT_A_FLOAT32
:
1277 case MESA_FORMAT_L_FLOAT32
:
1278 case MESA_FORMAT_I_FLOAT32
:
1279 case MESA_FORMAT_R_FLOAT32
:
1280 *datatype
= GL_FLOAT
;
1283 case MESA_FORMAT_A_FLOAT16
:
1284 case MESA_FORMAT_L_FLOAT16
:
1285 case MESA_FORMAT_I_FLOAT16
:
1286 case MESA_FORMAT_R_FLOAT16
:
1287 *datatype
= GL_HALF_FLOAT_ARB
;
1291 case MESA_FORMAT_A_UINT8
:
1292 case MESA_FORMAT_L_UINT8
:
1293 case MESA_FORMAT_I_UINT8
:
1294 *datatype
= GL_UNSIGNED_BYTE
;
1297 case MESA_FORMAT_LA_UINT8
:
1298 *datatype
= GL_UNSIGNED_BYTE
;
1302 case MESA_FORMAT_A_UINT16
:
1303 case MESA_FORMAT_L_UINT16
:
1304 case MESA_FORMAT_I_UINT16
:
1305 *datatype
= GL_UNSIGNED_SHORT
;
1308 case MESA_FORMAT_LA_UINT16
:
1309 *datatype
= GL_UNSIGNED_SHORT
;
1312 case MESA_FORMAT_A_UINT32
:
1313 case MESA_FORMAT_L_UINT32
:
1314 case MESA_FORMAT_I_UINT32
:
1315 *datatype
= GL_UNSIGNED_INT
;
1318 case MESA_FORMAT_LA_UINT32
:
1319 *datatype
= GL_UNSIGNED_INT
;
1322 case MESA_FORMAT_A_SINT8
:
1323 case MESA_FORMAT_L_SINT8
:
1324 case MESA_FORMAT_I_SINT8
:
1325 *datatype
= GL_BYTE
;
1328 case MESA_FORMAT_LA_SINT8
:
1329 *datatype
= GL_BYTE
;
1333 case MESA_FORMAT_A_SINT16
:
1334 case MESA_FORMAT_L_SINT16
:
1335 case MESA_FORMAT_I_SINT16
:
1336 *datatype
= GL_SHORT
;
1339 case MESA_FORMAT_LA_SINT16
:
1340 *datatype
= GL_SHORT
;
1344 case MESA_FORMAT_A_SINT32
:
1345 case MESA_FORMAT_L_SINT32
:
1346 case MESA_FORMAT_I_SINT32
:
1350 case MESA_FORMAT_LA_SINT32
:
1355 case MESA_FORMAT_R_SINT8
:
1356 *datatype
= GL_BYTE
;
1359 case MESA_FORMAT_RG_SINT8
:
1360 *datatype
= GL_BYTE
;
1363 case MESA_FORMAT_RGB_SINT8
:
1364 *datatype
= GL_BYTE
;
1367 case MESA_FORMAT_RGBA_SINT8
:
1368 *datatype
= GL_BYTE
;
1371 case MESA_FORMAT_R_SINT16
:
1372 *datatype
= GL_SHORT
;
1375 case MESA_FORMAT_RG_SINT16
:
1376 *datatype
= GL_SHORT
;
1379 case MESA_FORMAT_RGB_SINT16
:
1380 *datatype
= GL_SHORT
;
1383 case MESA_FORMAT_RGBA_SINT16
:
1384 *datatype
= GL_SHORT
;
1387 case MESA_FORMAT_R_SINT32
:
1391 case MESA_FORMAT_RG_SINT32
:
1395 case MESA_FORMAT_RGB_SINT32
:
1399 case MESA_FORMAT_RGBA_SINT32
:
1405 * \name Non-normalized unsigned integer formats.
1407 case MESA_FORMAT_R_UINT8
:
1408 *datatype
= GL_UNSIGNED_BYTE
;
1411 case MESA_FORMAT_RG_UINT8
:
1412 *datatype
= GL_UNSIGNED_BYTE
;
1415 case MESA_FORMAT_RGB_UINT8
:
1416 *datatype
= GL_UNSIGNED_BYTE
;
1419 case MESA_FORMAT_RGBA_UINT8
:
1420 *datatype
= GL_UNSIGNED_BYTE
;
1423 case MESA_FORMAT_R_UINT16
:
1424 *datatype
= GL_UNSIGNED_SHORT
;
1427 case MESA_FORMAT_RG_UINT16
:
1428 *datatype
= GL_UNSIGNED_SHORT
;
1431 case MESA_FORMAT_RGB_UINT16
:
1432 *datatype
= GL_UNSIGNED_SHORT
;
1435 case MESA_FORMAT_RGBA_UINT16
:
1436 *datatype
= GL_UNSIGNED_SHORT
;
1439 case MESA_FORMAT_R_UINT32
:
1440 *datatype
= GL_UNSIGNED_INT
;
1443 case MESA_FORMAT_RG_UINT32
:
1444 *datatype
= GL_UNSIGNED_INT
;
1447 case MESA_FORMAT_RGB_UINT32
:
1448 *datatype
= GL_UNSIGNED_INT
;
1451 case MESA_FORMAT_RGBA_UINT32
:
1452 *datatype
= GL_UNSIGNED_INT
;
1456 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1457 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1461 case MESA_FORMAT_R11G11B10_FLOAT
:
1462 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1466 case MESA_FORMAT_B10G10R10A2_UINT
:
1467 case MESA_FORMAT_R10G10B10A2_UINT
:
1468 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1472 case MESA_FORMAT_R8G8B8X8_SRGB
:
1473 case MESA_FORMAT_X8B8G8R8_SRGB
:
1474 case MESA_FORMAT_RGBX_UINT8
:
1475 *datatype
= GL_UNSIGNED_BYTE
;
1479 case MESA_FORMAT_R8G8B8X8_SNORM
:
1480 case MESA_FORMAT_RGBX_SINT8
:
1481 *datatype
= GL_BYTE
;
1485 case MESA_FORMAT_B10G10R10X2_UNORM
:
1486 case MESA_FORMAT_R10G10B10X2_UNORM
:
1487 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1491 case MESA_FORMAT_RGBX_UNORM16
:
1492 case MESA_FORMAT_RGBX_UINT16
:
1493 *datatype
= GL_UNSIGNED_SHORT
;
1497 case MESA_FORMAT_RGBX_SNORM16
:
1498 case MESA_FORMAT_RGBX_SINT16
:
1499 *datatype
= GL_SHORT
;
1503 case MESA_FORMAT_RGBX_FLOAT16
:
1504 *datatype
= GL_HALF_FLOAT
;
1508 case MESA_FORMAT_RGBX_FLOAT32
:
1509 *datatype
= GL_FLOAT
;
1513 case MESA_FORMAT_RGBX_UINT32
:
1514 *datatype
= GL_UNSIGNED_INT
;
1518 case MESA_FORMAT_RGBX_SINT32
:
1523 case MESA_FORMAT_R10G10B10A2_UNORM
:
1524 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1528 case MESA_FORMAT_G8R8_SNORM
:
1529 *datatype
= GL_BYTE
;
1533 case MESA_FORMAT_G16R16_SNORM
:
1534 *datatype
= GL_SHORT
;
1538 case MESA_FORMAT_B8G8R8X8_SRGB
:
1539 case MESA_FORMAT_X8R8G8B8_SRGB
:
1540 *datatype
= GL_UNSIGNED_BYTE
;
1544 case MESA_FORMAT_COUNT
:
1548 case MESA_FORMAT_NONE
:
1549 /* For debug builds, warn if any formats are not handled */
1553 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1554 _mesa_get_format_name(format
));
1561 * Check if a mesa_format exactly matches a GL format/type combination
1562 * such that we can use memcpy() from one to the other.
1563 * \param mesa_format a MESA_FORMAT_x value
1564 * \param format the user-specified image format
1565 * \param type the user-specified image datatype
1566 * \param swapBytes typically the current pixel pack/unpack byteswap state
1567 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1570 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1571 GLenum format
, GLenum type
,
1572 GLboolean swapBytes
)
1574 const GLboolean littleEndian
= _mesa_little_endian();
1576 /* Note: When reading a GL format/type combination, the format lists channel
1577 * assignments from most significant channel in the type to least
1578 * significant. A type with _REV indicates that the assignments are
1579 * swapped, so they are listed from least significant to most significant.
1581 * For sanity, please keep this switch statement ordered the same as the
1582 * enums in formats.h.
1585 switch (mesa_format
) {
1587 case MESA_FORMAT_NONE
:
1588 case MESA_FORMAT_COUNT
:
1591 case MESA_FORMAT_A8B8G8R8_UNORM
:
1592 case MESA_FORMAT_A8B8G8R8_SRGB
:
1593 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1596 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1599 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1602 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1606 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1610 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1615 case MESA_FORMAT_R8G8B8A8_UNORM
:
1616 case MESA_FORMAT_R8G8B8A8_SRGB
:
1617 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1621 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1624 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1627 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1631 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1635 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1640 case MESA_FORMAT_B8G8R8A8_UNORM
:
1641 case MESA_FORMAT_B8G8R8A8_SRGB
:
1642 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1646 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1649 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1654 case MESA_FORMAT_A8R8G8B8_UNORM
:
1655 case MESA_FORMAT_A8R8G8B8_SRGB
:
1656 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1659 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1663 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1668 case MESA_FORMAT_X8B8G8R8_UNORM
:
1669 case MESA_FORMAT_R8G8B8X8_UNORM
:
1672 case MESA_FORMAT_B8G8R8X8_UNORM
:
1673 case MESA_FORMAT_X8R8G8B8_UNORM
:
1676 case MESA_FORMAT_BGR_UNORM8
:
1677 case MESA_FORMAT_BGR_SRGB8
:
1678 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1680 case MESA_FORMAT_RGB_UNORM8
:
1681 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1683 case MESA_FORMAT_B5G6R5_UNORM
:
1684 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1685 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1688 case MESA_FORMAT_R5G6B5_UNORM
:
1689 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1690 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1693 case MESA_FORMAT_B4G4R4A4_UNORM
:
1694 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1697 case MESA_FORMAT_A4R4G4B4_UNORM
:
1700 case MESA_FORMAT_A1B5G5R5_UNORM
:
1701 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1704 case MESA_FORMAT_B5G5R5A1_UNORM
:
1705 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1708 case MESA_FORMAT_A1R5G5B5_UNORM
:
1709 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1712 case MESA_FORMAT_L4A4_UNORM
:
1714 case MESA_FORMAT_L8A8_UNORM
:
1715 case MESA_FORMAT_L8A8_SRGB
:
1716 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1717 case MESA_FORMAT_A8L8_UNORM
:
1718 case MESA_FORMAT_A8L8_SRGB
:
1721 case MESA_FORMAT_L16A16_UNORM
:
1722 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1723 case MESA_FORMAT_A16L16_UNORM
:
1726 case MESA_FORMAT_B2G3R3_UNORM
:
1727 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1729 case MESA_FORMAT_R3G3B2_UNORM
:
1730 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1732 case MESA_FORMAT_A4B4G4R4_UNORM
:
1733 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1736 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1739 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1742 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1747 case MESA_FORMAT_R4G4B4A4_UNORM
:
1748 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1751 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1754 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1757 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1762 case MESA_FORMAT_R5G5B5A1_UNORM
:
1763 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1765 case MESA_FORMAT_A2B10G10R10_UNORM
:
1766 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1768 case MESA_FORMAT_A2B10G10R10_UINT
:
1769 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1771 case MESA_FORMAT_A2R10G10B10_UNORM
:
1772 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1774 case MESA_FORMAT_A2R10G10B10_UINT
:
1775 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1777 case MESA_FORMAT_A_UNORM8
:
1778 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1779 case MESA_FORMAT_A_UNORM16
:
1780 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1781 case MESA_FORMAT_L_UNORM8
:
1782 case MESA_FORMAT_L_SRGB8
:
1783 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1784 case MESA_FORMAT_L_UNORM16
:
1785 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1786 case MESA_FORMAT_I_UNORM8
:
1787 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1788 case MESA_FORMAT_I_UNORM16
:
1789 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1791 case MESA_FORMAT_YCBCR
:
1792 return format
== GL_YCBCR_MESA
&&
1793 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1794 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1795 case MESA_FORMAT_YCBCR_REV
:
1796 return format
== GL_YCBCR_MESA
&&
1797 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1798 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1800 case MESA_FORMAT_R_UNORM8
:
1801 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1802 case MESA_FORMAT_R8G8_UNORM
:
1803 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1804 case MESA_FORMAT_G8R8_UNORM
:
1807 case MESA_FORMAT_R_UNORM16
:
1808 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1810 case MESA_FORMAT_R16G16_UNORM
:
1811 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1813 case MESA_FORMAT_G16R16_UNORM
:
1816 case MESA_FORMAT_B10G10R10A2_UNORM
:
1817 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1820 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1821 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1823 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1824 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1827 case MESA_FORMAT_Z_UNORM16
:
1828 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1831 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1834 case MESA_FORMAT_Z_UNORM32
:
1835 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1838 case MESA_FORMAT_S_UINT8
:
1839 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1841 case MESA_FORMAT_SRGB_DXT1
:
1842 case MESA_FORMAT_SRGBA_DXT1
:
1843 case MESA_FORMAT_SRGBA_DXT3
:
1844 case MESA_FORMAT_SRGBA_DXT5
:
1847 case MESA_FORMAT_RGB_FXT1
:
1848 case MESA_FORMAT_RGBA_FXT1
:
1849 case MESA_FORMAT_RGB_DXT1
:
1850 case MESA_FORMAT_RGBA_DXT1
:
1851 case MESA_FORMAT_RGBA_DXT3
:
1852 case MESA_FORMAT_RGBA_DXT5
:
1855 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1856 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1857 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1858 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1861 case MESA_FORMAT_RGBA_FLOAT32
:
1862 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1863 case MESA_FORMAT_RGBA_FLOAT16
:
1864 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1866 case MESA_FORMAT_RGB_FLOAT32
:
1867 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1868 case MESA_FORMAT_RGB_FLOAT16
:
1869 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1871 case MESA_FORMAT_A_FLOAT32
:
1872 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1873 case MESA_FORMAT_A_FLOAT16
:
1874 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1876 case MESA_FORMAT_L_FLOAT32
:
1877 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1878 case MESA_FORMAT_L_FLOAT16
:
1879 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1881 case MESA_FORMAT_LA_FLOAT32
:
1882 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1883 case MESA_FORMAT_LA_FLOAT16
:
1884 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1886 case MESA_FORMAT_I_FLOAT32
:
1887 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1888 case MESA_FORMAT_I_FLOAT16
:
1889 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1891 case MESA_FORMAT_R_FLOAT32
:
1892 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1893 case MESA_FORMAT_R_FLOAT16
:
1894 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1896 case MESA_FORMAT_RG_FLOAT32
:
1897 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1898 case MESA_FORMAT_RG_FLOAT16
:
1899 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1901 case MESA_FORMAT_A_UINT8
:
1902 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1903 case MESA_FORMAT_A_UINT16
:
1904 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1906 case MESA_FORMAT_A_UINT32
:
1907 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1909 case MESA_FORMAT_A_SINT8
:
1910 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1911 case MESA_FORMAT_A_SINT16
:
1912 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1913 case MESA_FORMAT_A_SINT32
:
1914 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1916 case MESA_FORMAT_I_UINT8
:
1917 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1918 case MESA_FORMAT_I_UINT16
:
1919 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1920 case MESA_FORMAT_I_UINT32
:
1921 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1922 case MESA_FORMAT_I_SINT8
:
1923 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1924 case MESA_FORMAT_I_SINT16
:
1925 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1926 case MESA_FORMAT_I_SINT32
:
1927 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1929 case MESA_FORMAT_L_UINT8
:
1930 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1931 case MESA_FORMAT_L_UINT16
:
1932 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1934 case MESA_FORMAT_L_UINT32
:
1935 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1937 case MESA_FORMAT_L_SINT8
:
1938 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1939 case MESA_FORMAT_L_SINT16
:
1940 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1942 case MESA_FORMAT_L_SINT32
:
1943 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1945 case MESA_FORMAT_LA_UINT8
:
1946 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1947 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1948 case MESA_FORMAT_LA_UINT16
:
1949 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1950 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1951 case MESA_FORMAT_LA_UINT32
:
1952 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1953 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1954 case MESA_FORMAT_LA_SINT8
:
1955 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1957 case MESA_FORMAT_LA_SINT16
:
1958 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1960 case MESA_FORMAT_LA_SINT32
:
1961 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1964 case MESA_FORMAT_R_SINT8
:
1965 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1966 case MESA_FORMAT_RG_SINT8
:
1967 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1968 case MESA_FORMAT_RGB_SINT8
:
1969 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1970 case MESA_FORMAT_RGBA_SINT8
:
1971 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1972 case MESA_FORMAT_R_SINT16
:
1973 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1974 case MESA_FORMAT_RG_SINT16
:
1975 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1976 case MESA_FORMAT_RGB_SINT16
:
1977 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1978 case MESA_FORMAT_RGBA_SINT16
:
1979 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1980 case MESA_FORMAT_R_SINT32
:
1981 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1982 case MESA_FORMAT_RG_SINT32
:
1983 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1984 case MESA_FORMAT_RGB_SINT32
:
1985 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1986 case MESA_FORMAT_RGBA_SINT32
:
1987 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1989 case MESA_FORMAT_R_UINT8
:
1990 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1991 case MESA_FORMAT_RG_UINT8
:
1992 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1993 case MESA_FORMAT_RGB_UINT8
:
1994 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1995 case MESA_FORMAT_RGBA_UINT8
:
1996 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1998 case MESA_FORMAT_R_UINT16
:
1999 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2001 case MESA_FORMAT_RG_UINT16
:
2002 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
2003 case MESA_FORMAT_RGB_UINT16
:
2004 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2006 case MESA_FORMAT_RGBA_UINT16
:
2007 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
2009 case MESA_FORMAT_R_UINT32
:
2010 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2011 case MESA_FORMAT_RG_UINT32
:
2012 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2013 case MESA_FORMAT_RGB_UINT32
:
2014 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2015 case MESA_FORMAT_RGBA_UINT32
:
2016 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2018 case MESA_FORMAT_R_SNORM8
:
2019 return format
== GL_RED
&& type
== GL_BYTE
;
2020 case MESA_FORMAT_R8G8_SNORM
:
2021 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2023 case MESA_FORMAT_X8B8G8R8_SNORM
:
2026 case MESA_FORMAT_A8B8G8R8_SNORM
:
2027 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2030 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2035 case MESA_FORMAT_R8G8B8A8_SNORM
:
2036 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2039 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2044 case MESA_FORMAT_R_SNORM16
:
2045 return format
== GL_RED
&& type
== GL_SHORT
&&
2047 case MESA_FORMAT_R16G16_SNORM
:
2048 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2049 case MESA_FORMAT_RGB_SNORM16
:
2050 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2051 case MESA_FORMAT_RGBA_SNORM16
:
2052 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2053 case MESA_FORMAT_RGBA_UNORM16
:
2054 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2057 case MESA_FORMAT_R_RGTC1_UNORM
:
2058 case MESA_FORMAT_R_RGTC1_SNORM
:
2059 case MESA_FORMAT_RG_RGTC2_UNORM
:
2060 case MESA_FORMAT_RG_RGTC2_SNORM
:
2063 case MESA_FORMAT_L_LATC1_UNORM
:
2064 case MESA_FORMAT_L_LATC1_SNORM
:
2065 case MESA_FORMAT_LA_LATC2_UNORM
:
2066 case MESA_FORMAT_LA_LATC2_SNORM
:
2069 case MESA_FORMAT_ETC1_RGB8
:
2070 case MESA_FORMAT_ETC2_RGB8
:
2071 case MESA_FORMAT_ETC2_SRGB8
:
2072 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2073 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2074 case MESA_FORMAT_ETC2_R11_EAC
:
2075 case MESA_FORMAT_ETC2_RG11_EAC
:
2076 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2077 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2078 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2079 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2082 case MESA_FORMAT_A_SNORM8
:
2083 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2084 case MESA_FORMAT_L_SNORM8
:
2085 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2086 case MESA_FORMAT_L8A8_SNORM
:
2087 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2088 littleEndian
&& !swapBytes
;
2089 case MESA_FORMAT_A8L8_SNORM
:
2090 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2091 !littleEndian
&& !swapBytes
;
2092 case MESA_FORMAT_I_SNORM8
:
2093 return format
== GL_RED
&& type
== GL_BYTE
;
2094 case MESA_FORMAT_A_SNORM16
:
2095 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2096 case MESA_FORMAT_L_SNORM16
:
2097 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2098 case MESA_FORMAT_LA_SNORM16
:
2099 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2100 littleEndian
&& !swapBytes
;
2101 case MESA_FORMAT_I_SNORM16
:
2102 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2105 case MESA_FORMAT_B10G10R10A2_UINT
:
2106 return (format
== GL_BGRA_INTEGER_EXT
&&
2107 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2110 case MESA_FORMAT_R10G10B10A2_UINT
:
2111 return (format
== GL_RGBA_INTEGER_EXT
&&
2112 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2115 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2116 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2119 case MESA_FORMAT_R11G11B10_FLOAT
:
2120 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2123 case MESA_FORMAT_Z_FLOAT32
:
2124 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2126 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2127 return format
== GL_DEPTH_STENCIL
&&
2128 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2130 case MESA_FORMAT_B4G4R4X4_UNORM
:
2131 case MESA_FORMAT_B5G5R5X1_UNORM
:
2132 case MESA_FORMAT_R8G8B8X8_SNORM
:
2133 case MESA_FORMAT_R8G8B8X8_SRGB
:
2134 case MESA_FORMAT_X8B8G8R8_SRGB
:
2135 case MESA_FORMAT_RGBX_UINT8
:
2136 case MESA_FORMAT_RGBX_SINT8
:
2137 case MESA_FORMAT_B10G10R10X2_UNORM
:
2138 case MESA_FORMAT_R10G10B10X2_UNORM
:
2139 case MESA_FORMAT_RGBX_UNORM16
:
2140 case MESA_FORMAT_RGBX_SNORM16
:
2141 case MESA_FORMAT_RGBX_FLOAT16
:
2142 case MESA_FORMAT_RGBX_UINT16
:
2143 case MESA_FORMAT_RGBX_SINT16
:
2144 case MESA_FORMAT_RGBX_FLOAT32
:
2145 case MESA_FORMAT_RGBX_UINT32
:
2146 case MESA_FORMAT_RGBX_SINT32
:
2149 case MESA_FORMAT_R10G10B10A2_UNORM
:
2150 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2153 case MESA_FORMAT_G8R8_SNORM
:
2154 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2157 case MESA_FORMAT_G16R16_SNORM
:
2158 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2161 case MESA_FORMAT_B8G8R8X8_SRGB
:
2162 case MESA_FORMAT_X8R8G8B8_SRGB
: