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.
31 #include "glformats.h"
32 #include "c11/threads.h"
33 #include "util/hash_table.h"
36 * Information about texture formats.
38 struct mesa_format_info
42 /** text name for debugging */
45 enum mesa_format_layout Layout
;
48 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
49 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
50 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
55 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
56 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
64 uint8_t LuminanceBits
;
65 uint8_t IntensityBits
;
72 * To describe compressed formats. If not compressed, Width=Height=Depth=1.
74 uint8_t BlockWidth
, BlockHeight
, BlockDepth
;
75 uint8_t BytesPerBlock
;
78 mesa_array_format ArrayFormat
;
81 #include "format_info.h"
83 static const struct mesa_format_info
*
84 _mesa_get_format_info(mesa_format format
)
86 const struct mesa_format_info
*info
= &format_info
[format
];
87 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
89 /* The MESA_FORMAT_* enums are sparse, don't return a format info
92 if (info
->Name
== MESA_FORMAT_NONE
&& format
!= MESA_FORMAT_NONE
)
95 assert(info
->Name
== format
);
100 /** Return string name of format (for debugging) */
102 _mesa_get_format_name(mesa_format format
)
104 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
107 return info
->StrName
;
113 * Return bytes needed to store a block of pixels in the given format.
114 * Normally, a block is 1x1 (a single pixel). But for compressed formats
115 * a block may be 4x4 or 8x4, etc.
117 * Note: return is signed, so as not to coerce math to unsigned. cf. fdo #37351
120 _mesa_get_format_bytes(mesa_format format
)
122 if (_mesa_format_is_mesa_array_format(format
)) {
123 return _mesa_array_format_get_type_size(format
) *
124 _mesa_array_format_get_num_channels(format
);
127 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
128 assert(info
->BytesPerBlock
);
129 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
130 _mesa_is_format_compressed(format
));
131 return info
->BytesPerBlock
;
136 * Return bits per component for the given format.
137 * \param format one of MESA_FORMAT_x
138 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
141 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
143 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
147 case GL_TEXTURE_RED_SIZE
:
148 case GL_RENDERBUFFER_RED_SIZE_EXT
:
149 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
150 case GL_INTERNALFORMAT_RED_SIZE
:
151 return info
->RedBits
;
153 case GL_TEXTURE_GREEN_SIZE
:
154 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
155 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
156 case GL_INTERNALFORMAT_GREEN_SIZE
:
157 return info
->GreenBits
;
159 case GL_TEXTURE_BLUE_SIZE
:
160 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
161 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
162 case GL_INTERNALFORMAT_BLUE_SIZE
:
163 return info
->BlueBits
;
165 case GL_TEXTURE_ALPHA_SIZE
:
166 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
167 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
168 case GL_INTERNALFORMAT_ALPHA_SIZE
:
169 return info
->AlphaBits
;
170 case GL_TEXTURE_INTENSITY_SIZE
:
171 return info
->IntensityBits
;
172 case GL_TEXTURE_LUMINANCE_SIZE
:
173 return info
->LuminanceBits
;
177 case GL_TEXTURE_DEPTH_SIZE_ARB
:
178 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
179 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
180 case GL_INTERNALFORMAT_DEPTH_SIZE
:
181 return info
->DepthBits
;
182 case GL_STENCIL_BITS
:
183 case GL_TEXTURE_STENCIL_SIZE_EXT
:
184 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
185 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
186 case GL_INTERNALFORMAT_STENCIL_SIZE
:
187 return info
->StencilBits
;
189 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
196 _mesa_get_format_max_bits(mesa_format format
)
198 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
199 unsigned int max
= MAX2(info
->RedBits
, info
->GreenBits
);
200 max
= MAX2(max
, info
->BlueBits
);
201 max
= MAX2(max
, info
->AlphaBits
);
202 max
= MAX2(max
, info
->LuminanceBits
);
203 max
= MAX2(max
, info
->IntensityBits
);
204 max
= MAX2(max
, info
->DepthBits
);
205 max
= MAX2(max
, info
->StencilBits
);
211 * Return the layout type of the given format.
213 extern enum mesa_format_layout
214 _mesa_get_format_layout(mesa_format format
)
216 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
222 * Return the data type (or more specifically, the data representation)
223 * for the given format.
224 * The return value will be one of:
225 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
226 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
227 * GL_UNSIGNED_INT = an ordinary unsigned integer
228 * GL_INT = an ordinary signed integer
229 * GL_FLOAT = an ordinary float
232 _mesa_get_format_datatype(mesa_format format
)
234 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
235 return info
->DataType
;
239 get_base_format_for_array_format(mesa_array_format format
)
244 switch (_mesa_array_format_get_base_format(format
)) {
245 case MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH
:
246 return GL_DEPTH_COMPONENT
;
247 case MESA_ARRAY_FORMAT_BASE_FORMAT_STENCIL
:
248 return GL_STENCIL_INDEX
;
249 case MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS
:
253 _mesa_array_format_get_swizzle(format
, swizzle
);
254 num_channels
= _mesa_array_format_get_num_channels(format
);
256 switch (num_channels
) {
258 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
259 * This is not really a problem for now because we only create array
260 * formats from GL format/type combinations, and these cannot specify
267 if (swizzle
[0] == 0 &&
271 return GL_LUMINANCE_ALPHA
;
272 if (swizzle
[0] == 1 &&
276 return GL_LUMINANCE_ALPHA
;
277 if (swizzle
[0] == 0 &&
282 if (swizzle
[0] == 1 &&
289 if (swizzle
[0] == 0 &&
294 if (swizzle
[0] == 0 &&
299 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
301 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
303 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
305 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
310 unreachable("Unsupported format");
314 * Return the basic format for the given type. The result will be one of
315 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
316 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
317 * This functions accepts a mesa_format or a mesa_array_format.
320 _mesa_get_format_base_format(uint32_t format
)
322 if (!_mesa_format_is_mesa_array_format(format
)) {
323 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
324 return info
->BaseFormat
;
326 return get_base_format_for_array_format(format
);
332 * Return the block size (in pixels) for the given format. Normally
333 * the block size is 1x1. But compressed formats will have block sizes
334 * of 4x4 or 8x4 pixels, etc.
335 * \param bw returns block width in pixels
336 * \param bh returns block height in pixels
339 _mesa_get_format_block_size(mesa_format format
,
340 unsigned int *bw
, unsigned int *bh
)
342 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
343 /* Use _mesa_get_format_block_size_3d() for 3D blocks. */
344 assert(info
->BlockDepth
== 1);
346 *bw
= info
->BlockWidth
;
347 *bh
= info
->BlockHeight
;
352 * Return the block size (in pixels) for the given format. Normally
353 * the block size is 1x1x1. But compressed formats will have block
354 * sizes of 4x4x4, 3x3x3 pixels, etc.
355 * \param bw returns block width in pixels
356 * \param bh returns block height in pixels
357 * \param bd returns block depth in pixels
360 _mesa_get_format_block_size_3d(mesa_format format
,
365 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
366 *bw
= info
->BlockWidth
;
367 *bh
= info
->BlockHeight
;
368 *bd
= info
->BlockDepth
;
373 * Returns the an array of four numbers representing the transformation
374 * from the RGBA or SZ colorspace to the given format. For array formats,
375 * the i'th RGBA component is given by:
377 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
378 * comp = data[swizzle[i]];
379 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
381 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
383 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
384 * // data does not contain a channel of this format
386 * For packed formats, the swizzle gives the number of components left of
387 * the least significant bit.
389 * Compressed formats have no swizzle.
392 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
394 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
395 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
399 _mesa_array_format_flip_channels(mesa_array_format format
)
404 num_channels
= _mesa_array_format_get_num_channels(format
);
405 _mesa_array_format_get_swizzle(format
, swizzle
);
407 if (num_channels
== 1)
410 if (num_channels
== 2) {
411 /* Assert that the swizzle makes sense for 2 channels */
412 for (unsigned i
= 0; i
< 4; i
++)
413 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
415 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
416 _mesa_array_format_set_swizzle(&format
,
417 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
418 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
422 if (num_channels
== 4) {
423 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
424 _mesa_array_format_set_swizzle(&format
,
425 flip
[swizzle
[0]], flip
[swizzle
[1]],
426 flip
[swizzle
[2]], flip
[swizzle
[3]]);
430 unreachable("Invalid array format");
434 _mesa_format_to_array_format(mesa_format format
)
436 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
437 #if UTIL_ARCH_BIG_ENDIAN
438 if (info
->ArrayFormat
&& info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
439 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
442 return info
->ArrayFormat
;
445 static struct hash_table
*format_array_format_table
;
446 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
449 format_array_format_table_destroy(void)
451 _mesa_hash_table_destroy(format_array_format_table
, NULL
);
455 array_formats_equal(const void *a
, const void *b
)
457 return (intptr_t)a
== (intptr_t)b
;
461 format_array_format_table_init(void)
463 const struct mesa_format_info
*info
;
464 mesa_array_format array_format
;
467 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
468 array_formats_equal
);
470 if (!format_array_format_table
) {
471 _mesa_error_no_memory(__func__
);
475 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
476 info
= _mesa_get_format_info(f
);
477 if (!info
|| !info
->ArrayFormat
)
480 #if UTIL_ARCH_LITTLE_ENDIAN
481 array_format
= info
->ArrayFormat
;
483 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
486 /* This can happen and does for some of the BGR formats. Let's take
487 * the first one in the list.
489 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
491 (void *)(intptr_t)array_format
))
494 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
496 (void *)(intptr_t)array_format
,
497 (void *)(intptr_t)f
);
500 atexit(format_array_format_table_destroy
);
504 _mesa_format_from_array_format(uint32_t array_format
)
506 struct hash_entry
*entry
;
508 assert(_mesa_format_is_mesa_array_format(array_format
));
510 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
512 if (!format_array_format_table
) {
513 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
514 format_array_format_table_exists
= once_flag_init
;
515 return MESA_FORMAT_NONE
;
518 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
520 (void *)(intptr_t)array_format
);
522 return (intptr_t)entry
->data
;
524 return MESA_FORMAT_NONE
;
527 /** Is the given format a compressed format? */
529 _mesa_is_format_compressed(mesa_format format
)
531 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
532 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
537 * Determine if the given format represents a packed depth/stencil buffer.
540 _mesa_is_format_packed_depth_stencil(mesa_format format
)
542 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
544 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
549 * Is the given format a signed/unsigned integer color format?
552 _mesa_is_format_integer_color(mesa_format format
)
554 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
555 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
556 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
557 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
558 info
->BaseFormat
!= GL_STENCIL_INDEX
;
563 * Is the given format an unsigned integer format?
566 _mesa_is_format_unsigned(mesa_format format
)
568 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
569 return _mesa_is_type_unsigned(info
->DataType
);
574 * Does the given format store signed values?
577 _mesa_is_format_signed(mesa_format format
)
579 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
580 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
581 /* these packed float formats only store unsigned values */
585 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
586 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
587 info
->DataType
== GL_INT
||
588 info
->DataType
== GL_FLOAT
);
593 * Is the given format an integer format?
596 _mesa_is_format_integer(mesa_format format
)
598 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
599 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
604 * Return true if the given format is a color format.
607 _mesa_is_format_color_format(mesa_format format
)
609 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
610 switch (info
->BaseFormat
) {
611 case GL_DEPTH_COMPONENT
:
612 case GL_STENCIL_INDEX
:
613 case GL_DEPTH_STENCIL
:
621 _mesa_is_format_srgb(mesa_format format
)
623 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
624 return info
->IsSRGBFormat
;
628 * Return TRUE if format is an ETC2 compressed format specified
629 * by GL_ARB_ES3_compatibility.
632 _mesa_is_format_etc2(mesa_format format
)
635 case MESA_FORMAT_ETC2_RGB8
:
636 case MESA_FORMAT_ETC2_SRGB8
:
637 case MESA_FORMAT_ETC2_RGBA8_EAC
:
638 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
639 case MESA_FORMAT_ETC2_R11_EAC
:
640 case MESA_FORMAT_ETC2_RG11_EAC
:
641 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
642 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
643 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
644 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
653 * Return TRUE if format is an ASTC 2D compressed format.
656 _mesa_is_format_astc_2d(mesa_format format
)
659 case MESA_FORMAT_RGBA_ASTC_4x4
:
660 case MESA_FORMAT_RGBA_ASTC_5x4
:
661 case MESA_FORMAT_RGBA_ASTC_5x5
:
662 case MESA_FORMAT_RGBA_ASTC_6x5
:
663 case MESA_FORMAT_RGBA_ASTC_6x6
:
664 case MESA_FORMAT_RGBA_ASTC_8x5
:
665 case MESA_FORMAT_RGBA_ASTC_8x6
:
666 case MESA_FORMAT_RGBA_ASTC_8x8
:
667 case MESA_FORMAT_RGBA_ASTC_10x5
:
668 case MESA_FORMAT_RGBA_ASTC_10x6
:
669 case MESA_FORMAT_RGBA_ASTC_10x8
:
670 case MESA_FORMAT_RGBA_ASTC_10x10
:
671 case MESA_FORMAT_RGBA_ASTC_12x10
:
672 case MESA_FORMAT_RGBA_ASTC_12x12
:
673 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4
:
674 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4
:
675 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
:
676 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5
:
677 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6
:
678 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5
:
679 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6
:
680 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8
:
681 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5
:
682 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6
:
683 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8
:
684 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10
:
685 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10
:
686 case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12
:
695 * If the given format is a compressed format, return a corresponding
696 * uncompressed format.
699 _mesa_get_uncompressed_format(mesa_format format
)
702 case MESA_FORMAT_RGB_FXT1
:
703 return MESA_FORMAT_BGR_UNORM8
;
704 case MESA_FORMAT_RGBA_FXT1
:
705 return MESA_FORMAT_A8B8G8R8_UNORM
;
706 case MESA_FORMAT_RGB_DXT1
:
707 case MESA_FORMAT_SRGB_DXT1
:
708 return MESA_FORMAT_BGR_UNORM8
;
709 case MESA_FORMAT_RGBA_DXT1
:
710 case MESA_FORMAT_SRGBA_DXT1
:
711 return MESA_FORMAT_A8B8G8R8_UNORM
;
712 case MESA_FORMAT_RGBA_DXT3
:
713 case MESA_FORMAT_SRGBA_DXT3
:
714 return MESA_FORMAT_A8B8G8R8_UNORM
;
715 case MESA_FORMAT_RGBA_DXT5
:
716 case MESA_FORMAT_SRGBA_DXT5
:
717 return MESA_FORMAT_A8B8G8R8_UNORM
;
718 case MESA_FORMAT_R_RGTC1_UNORM
:
719 return MESA_FORMAT_R_UNORM8
;
720 case MESA_FORMAT_R_RGTC1_SNORM
:
721 return MESA_FORMAT_R_SNORM8
;
722 case MESA_FORMAT_RG_RGTC2_UNORM
:
723 return MESA_FORMAT_RG_UNORM8
;
724 case MESA_FORMAT_RG_RGTC2_SNORM
:
725 return MESA_FORMAT_RG_SNORM8
;
726 case MESA_FORMAT_L_LATC1_UNORM
:
727 return MESA_FORMAT_L_UNORM8
;
728 case MESA_FORMAT_L_LATC1_SNORM
:
729 return MESA_FORMAT_L_SNORM8
;
730 case MESA_FORMAT_LA_LATC2_UNORM
:
731 return MESA_FORMAT_LA_UNORM8
;
732 case MESA_FORMAT_LA_LATC2_SNORM
:
733 return MESA_FORMAT_LA_SNORM8
;
734 case MESA_FORMAT_ETC1_RGB8
:
735 case MESA_FORMAT_ETC2_RGB8
:
736 case MESA_FORMAT_ETC2_SRGB8
:
737 case MESA_FORMAT_ATC_RGB
:
738 return MESA_FORMAT_BGR_UNORM8
;
739 case MESA_FORMAT_ETC2_RGBA8_EAC
:
740 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
741 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
742 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
743 case MESA_FORMAT_ATC_RGBA_EXPLICIT
:
744 case MESA_FORMAT_ATC_RGBA_INTERPOLATED
:
745 return MESA_FORMAT_A8B8G8R8_UNORM
;
746 case MESA_FORMAT_ETC2_R11_EAC
:
747 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
748 return MESA_FORMAT_R_UNORM16
;
749 case MESA_FORMAT_ETC2_RG11_EAC
:
750 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
751 return MESA_FORMAT_RG_UNORM16
;
752 case MESA_FORMAT_BPTC_RGBA_UNORM
:
753 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
754 return MESA_FORMAT_A8B8G8R8_UNORM
;
755 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
756 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
757 return MESA_FORMAT_RGB_FLOAT32
;
759 assert(!_mesa_is_format_compressed(format
));
766 _mesa_format_num_components(mesa_format format
)
768 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
769 return ((info
->RedBits
> 0) +
770 (info
->GreenBits
> 0) +
771 (info
->BlueBits
> 0) +
772 (info
->AlphaBits
> 0) +
773 (info
->LuminanceBits
> 0) +
774 (info
->IntensityBits
> 0) +
775 (info
->DepthBits
> 0) +
776 (info
->StencilBits
> 0));
781 * Returns true if a color format has data stored in the R/G/B/A channels,
782 * given an index from 0 to 3.
785 _mesa_format_has_color_component(mesa_format format
, int component
)
787 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
789 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
790 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
791 info
->BaseFormat
!= GL_STENCIL_INDEX
);
795 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
797 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
799 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
801 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
803 assert(!"Invalid color component: must be 0..3");
810 * Return number of bytes needed to store an image of the given size
811 * in the given format.
814 _mesa_format_image_size(mesa_format format
, int width
,
815 int height
, int depth
)
817 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
819 /* Strictly speaking, a conditional isn't needed here */
820 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
821 /* compressed format (2D only for now) */
822 const uint32_t bw
= info
->BlockWidth
;
823 const uint32_t bh
= info
->BlockHeight
;
824 const uint32_t bd
= info
->BlockDepth
;
825 const uint32_t wblocks
= (width
+ bw
- 1) / bw
;
826 const uint32_t hblocks
= (height
+ bh
- 1) / bh
;
827 const uint32_t dblocks
= (depth
+ bd
- 1) / bd
;
828 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
831 sz
= width
* height
* depth
* info
->BytesPerBlock
;
838 * Same as _mesa_format_image_size() but returns a 64-bit value to
839 * accommodate very large textures.
842 _mesa_format_image_size64(mesa_format format
, int width
,
843 int height
, int depth
)
845 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
847 /* Strictly speaking, a conditional isn't needed here */
848 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
849 /* compressed format (2D only for now) */
850 const uint64_t bw
= info
->BlockWidth
;
851 const uint64_t bh
= info
->BlockHeight
;
852 const uint64_t bd
= info
->BlockDepth
;
853 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
854 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
855 const uint64_t dblocks
= (depth
+ bd
- 1) / bd
;
856 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
859 sz
= ((uint64_t) width
* (uint64_t) height
*
860 (uint64_t) depth
* info
->BytesPerBlock
);
868 _mesa_format_row_stride(mesa_format format
, int width
)
870 const struct mesa_format_info
*info
= _mesa_get_format_info(format
);
871 /* Strictly speaking, a conditional isn't needed here */
872 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
873 /* compressed format */
874 const uint32_t bw
= info
->BlockWidth
;
875 const uint32_t wblocks
= (width
+ bw
- 1) / bw
;
876 const int32_t stride
= wblocks
* info
->BytesPerBlock
;
880 const int32_t stride
= width
* info
->BytesPerBlock
;
888 * Return datatype and number of components per texel for the given
889 * uncompressed mesa_format. Only used for mipmap generation code.
892 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
893 GLenum
*datatype
, GLuint
*comps
)
896 case MESA_FORMAT_A8B8G8R8_UNORM
:
897 case MESA_FORMAT_R8G8B8A8_UNORM
:
898 case MESA_FORMAT_B8G8R8A8_UNORM
:
899 case MESA_FORMAT_A8R8G8B8_UNORM
:
900 case MESA_FORMAT_X8B8G8R8_UNORM
:
901 case MESA_FORMAT_R8G8B8X8_UNORM
:
902 case MESA_FORMAT_B8G8R8X8_UNORM
:
903 case MESA_FORMAT_X8R8G8B8_UNORM
:
904 case MESA_FORMAT_A8B8G8R8_UINT
:
905 case MESA_FORMAT_R8G8B8A8_UINT
:
906 case MESA_FORMAT_B8G8R8A8_UINT
:
907 case MESA_FORMAT_A8R8G8B8_UINT
:
908 *datatype
= GL_UNSIGNED_BYTE
;
911 case MESA_FORMAT_BGR_UNORM8
:
912 case MESA_FORMAT_RGB_UNORM8
:
913 *datatype
= GL_UNSIGNED_BYTE
;
916 case MESA_FORMAT_B5G6R5_UNORM
:
917 case MESA_FORMAT_R5G6B5_UNORM
:
918 case MESA_FORMAT_B5G6R5_UINT
:
919 case MESA_FORMAT_R5G6B5_UINT
:
920 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
924 case MESA_FORMAT_B4G4R4A4_UNORM
:
925 case MESA_FORMAT_A4R4G4B4_UNORM
:
926 case MESA_FORMAT_B4G4R4X4_UNORM
:
927 case MESA_FORMAT_B4G4R4A4_UINT
:
928 case MESA_FORMAT_A4R4G4B4_UINT
:
929 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
933 case MESA_FORMAT_B5G5R5A1_UNORM
:
934 case MESA_FORMAT_A1R5G5B5_UNORM
:
935 case MESA_FORMAT_B5G5R5X1_UNORM
:
936 case MESA_FORMAT_B5G5R5A1_UINT
:
937 case MESA_FORMAT_A1R5G5B5_UINT
:
938 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
942 case MESA_FORMAT_B10G10R10A2_UNORM
:
943 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
947 case MESA_FORMAT_A1B5G5R5_UNORM
:
948 case MESA_FORMAT_A1B5G5R5_UINT
:
949 case MESA_FORMAT_X1B5G5R5_UNORM
:
950 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
954 case MESA_FORMAT_L4A4_UNORM
:
955 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
959 case MESA_FORMAT_LA_UNORM8
:
960 case MESA_FORMAT_RG_UNORM8
:
961 *datatype
= GL_UNSIGNED_BYTE
;
965 case MESA_FORMAT_LA_UNORM16
:
966 case MESA_FORMAT_RG_UNORM16
:
967 *datatype
= GL_UNSIGNED_SHORT
;
971 case MESA_FORMAT_R_UNORM16
:
972 case MESA_FORMAT_A_UNORM16
:
973 case MESA_FORMAT_L_UNORM16
:
974 case MESA_FORMAT_I_UNORM16
:
975 *datatype
= GL_UNSIGNED_SHORT
;
979 case MESA_FORMAT_R3G3B2_UNORM
:
980 case MESA_FORMAT_R3G3B2_UINT
:
981 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
984 case MESA_FORMAT_A4B4G4R4_UNORM
:
985 case MESA_FORMAT_A4B4G4R4_UINT
:
986 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
990 case MESA_FORMAT_R4G4B4A4_UNORM
:
991 case MESA_FORMAT_R4G4B4A4_UINT
:
992 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
995 case MESA_FORMAT_R5G5B5A1_UNORM
:
996 case MESA_FORMAT_R5G5B5A1_UINT
:
997 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1000 case MESA_FORMAT_A2B10G10R10_UNORM
:
1001 case MESA_FORMAT_A2B10G10R10_UINT
:
1002 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1005 case MESA_FORMAT_A2R10G10B10_UNORM
:
1006 case MESA_FORMAT_A2R10G10B10_UINT
:
1007 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1011 case MESA_FORMAT_B2G3R3_UNORM
:
1012 case MESA_FORMAT_B2G3R3_UINT
:
1013 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1017 case MESA_FORMAT_A_UNORM8
:
1018 case MESA_FORMAT_L_UNORM8
:
1019 case MESA_FORMAT_I_UNORM8
:
1020 case MESA_FORMAT_R_UNORM8
:
1021 case MESA_FORMAT_S_UINT8
:
1022 *datatype
= GL_UNSIGNED_BYTE
;
1026 case MESA_FORMAT_YCBCR
:
1027 case MESA_FORMAT_YCBCR_REV
:
1028 *datatype
= GL_UNSIGNED_SHORT
;
1032 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1033 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1037 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1038 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1042 case MESA_FORMAT_Z_UNORM16
:
1043 *datatype
= GL_UNSIGNED_SHORT
;
1047 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1048 *datatype
= GL_UNSIGNED_INT
;
1052 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1053 *datatype
= GL_UNSIGNED_INT
;
1057 case MESA_FORMAT_Z_UNORM32
:
1058 *datatype
= GL_UNSIGNED_INT
;
1062 case MESA_FORMAT_Z_FLOAT32
:
1063 *datatype
= GL_FLOAT
;
1067 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1068 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1072 case MESA_FORMAT_R_SNORM8
:
1073 case MESA_FORMAT_A_SNORM8
:
1074 case MESA_FORMAT_L_SNORM8
:
1075 case MESA_FORMAT_I_SNORM8
:
1076 *datatype
= GL_BYTE
;
1079 case MESA_FORMAT_RG_SNORM8
:
1080 case MESA_FORMAT_LA_SNORM8
:
1081 *datatype
= GL_BYTE
;
1084 case MESA_FORMAT_A8B8G8R8_SNORM
:
1085 case MESA_FORMAT_R8G8B8A8_SNORM
:
1086 case MESA_FORMAT_X8B8G8R8_SNORM
:
1087 *datatype
= GL_BYTE
;
1091 case MESA_FORMAT_RGBA_UNORM16
:
1092 *datatype
= GL_UNSIGNED_SHORT
;
1096 case MESA_FORMAT_R_SNORM16
:
1097 case MESA_FORMAT_A_SNORM16
:
1098 case MESA_FORMAT_L_SNORM16
:
1099 case MESA_FORMAT_I_SNORM16
:
1100 *datatype
= GL_SHORT
;
1103 case MESA_FORMAT_RG_SNORM16
:
1104 case MESA_FORMAT_LA_SNORM16
:
1105 *datatype
= GL_SHORT
;
1108 case MESA_FORMAT_RGB_SNORM16
:
1109 *datatype
= GL_SHORT
;
1112 case MESA_FORMAT_RGBA_SNORM16
:
1113 *datatype
= GL_SHORT
;
1117 case MESA_FORMAT_BGR_SRGB8
:
1118 *datatype
= GL_UNSIGNED_BYTE
;
1121 case MESA_FORMAT_A8B8G8R8_SRGB
:
1122 case MESA_FORMAT_B8G8R8A8_SRGB
:
1123 case MESA_FORMAT_A8R8G8B8_SRGB
:
1124 case MESA_FORMAT_R8G8B8A8_SRGB
:
1125 *datatype
= GL_UNSIGNED_BYTE
;
1128 case MESA_FORMAT_L_SRGB8
:
1129 case MESA_FORMAT_R_SRGB8
:
1130 *datatype
= GL_UNSIGNED_BYTE
;
1133 case MESA_FORMAT_LA_SRGB8
:
1134 *datatype
= GL_UNSIGNED_BYTE
;
1138 case MESA_FORMAT_RGBA_FLOAT32
:
1139 *datatype
= GL_FLOAT
;
1142 case MESA_FORMAT_RGBA_FLOAT16
:
1143 *datatype
= GL_HALF_FLOAT_ARB
;
1146 case MESA_FORMAT_RGB_FLOAT32
:
1147 *datatype
= GL_FLOAT
;
1150 case MESA_FORMAT_RGB_FLOAT16
:
1151 *datatype
= GL_HALF_FLOAT_ARB
;
1154 case MESA_FORMAT_LA_FLOAT32
:
1155 case MESA_FORMAT_RG_FLOAT32
:
1156 *datatype
= GL_FLOAT
;
1159 case MESA_FORMAT_LA_FLOAT16
:
1160 case MESA_FORMAT_RG_FLOAT16
:
1161 *datatype
= GL_HALF_FLOAT_ARB
;
1164 case MESA_FORMAT_A_FLOAT32
:
1165 case MESA_FORMAT_L_FLOAT32
:
1166 case MESA_FORMAT_I_FLOAT32
:
1167 case MESA_FORMAT_R_FLOAT32
:
1168 *datatype
= GL_FLOAT
;
1171 case MESA_FORMAT_A_FLOAT16
:
1172 case MESA_FORMAT_L_FLOAT16
:
1173 case MESA_FORMAT_I_FLOAT16
:
1174 case MESA_FORMAT_R_FLOAT16
:
1175 *datatype
= GL_HALF_FLOAT_ARB
;
1179 case MESA_FORMAT_A_UINT8
:
1180 case MESA_FORMAT_L_UINT8
:
1181 case MESA_FORMAT_I_UINT8
:
1182 *datatype
= GL_UNSIGNED_BYTE
;
1185 case MESA_FORMAT_LA_UINT8
:
1186 *datatype
= GL_UNSIGNED_BYTE
;
1190 case MESA_FORMAT_A_UINT16
:
1191 case MESA_FORMAT_L_UINT16
:
1192 case MESA_FORMAT_I_UINT16
:
1193 *datatype
= GL_UNSIGNED_SHORT
;
1196 case MESA_FORMAT_LA_UINT16
:
1197 *datatype
= GL_UNSIGNED_SHORT
;
1200 case MESA_FORMAT_A_UINT32
:
1201 case MESA_FORMAT_L_UINT32
:
1202 case MESA_FORMAT_I_UINT32
:
1203 *datatype
= GL_UNSIGNED_INT
;
1206 case MESA_FORMAT_LA_UINT32
:
1207 *datatype
= GL_UNSIGNED_INT
;
1210 case MESA_FORMAT_A_SINT8
:
1211 case MESA_FORMAT_L_SINT8
:
1212 case MESA_FORMAT_I_SINT8
:
1213 *datatype
= GL_BYTE
;
1216 case MESA_FORMAT_LA_SINT8
:
1217 *datatype
= GL_BYTE
;
1221 case MESA_FORMAT_A_SINT16
:
1222 case MESA_FORMAT_L_SINT16
:
1223 case MESA_FORMAT_I_SINT16
:
1224 *datatype
= GL_SHORT
;
1227 case MESA_FORMAT_LA_SINT16
:
1228 *datatype
= GL_SHORT
;
1232 case MESA_FORMAT_A_SINT32
:
1233 case MESA_FORMAT_L_SINT32
:
1234 case MESA_FORMAT_I_SINT32
:
1238 case MESA_FORMAT_LA_SINT32
:
1243 case MESA_FORMAT_R_SINT8
:
1244 *datatype
= GL_BYTE
;
1247 case MESA_FORMAT_RG_SINT8
:
1248 *datatype
= GL_BYTE
;
1251 case MESA_FORMAT_RGB_SINT8
:
1252 *datatype
= GL_BYTE
;
1255 case MESA_FORMAT_RGBA_SINT8
:
1256 *datatype
= GL_BYTE
;
1259 case MESA_FORMAT_R_SINT16
:
1260 *datatype
= GL_SHORT
;
1263 case MESA_FORMAT_RG_SINT16
:
1264 *datatype
= GL_SHORT
;
1267 case MESA_FORMAT_RGB_SINT16
:
1268 *datatype
= GL_SHORT
;
1271 case MESA_FORMAT_RGBA_SINT16
:
1272 *datatype
= GL_SHORT
;
1275 case MESA_FORMAT_R_SINT32
:
1279 case MESA_FORMAT_RG_SINT32
:
1283 case MESA_FORMAT_RGB_SINT32
:
1287 case MESA_FORMAT_RGBA_SINT32
:
1293 * \name Non-normalized unsigned integer formats.
1295 case MESA_FORMAT_R_UINT8
:
1296 *datatype
= GL_UNSIGNED_BYTE
;
1299 case MESA_FORMAT_RG_UINT8
:
1300 *datatype
= GL_UNSIGNED_BYTE
;
1303 case MESA_FORMAT_RGB_UINT8
:
1304 *datatype
= GL_UNSIGNED_BYTE
;
1307 case MESA_FORMAT_R_UINT16
:
1308 *datatype
= GL_UNSIGNED_SHORT
;
1311 case MESA_FORMAT_RG_UINT16
:
1312 *datatype
= GL_UNSIGNED_SHORT
;
1315 case MESA_FORMAT_RGB_UINT16
:
1316 *datatype
= GL_UNSIGNED_SHORT
;
1319 case MESA_FORMAT_RGBA_UINT16
:
1320 *datatype
= GL_UNSIGNED_SHORT
;
1323 case MESA_FORMAT_R_UINT32
:
1324 *datatype
= GL_UNSIGNED_INT
;
1327 case MESA_FORMAT_RG_UINT32
:
1328 *datatype
= GL_UNSIGNED_INT
;
1331 case MESA_FORMAT_RGB_UINT32
:
1332 *datatype
= GL_UNSIGNED_INT
;
1335 case MESA_FORMAT_RGBA_UINT32
:
1336 *datatype
= GL_UNSIGNED_INT
;
1340 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1341 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1345 case MESA_FORMAT_R11G11B10_FLOAT
:
1346 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1350 case MESA_FORMAT_B10G10R10A2_UINT
:
1351 case MESA_FORMAT_R10G10B10A2_UINT
:
1352 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1356 case MESA_FORMAT_R8G8B8X8_SRGB
:
1357 case MESA_FORMAT_X8B8G8R8_SRGB
:
1358 case MESA_FORMAT_RGBX_UINT8
:
1359 *datatype
= GL_UNSIGNED_BYTE
;
1363 case MESA_FORMAT_R8G8B8X8_SNORM
:
1364 case MESA_FORMAT_RGBX_SINT8
:
1365 *datatype
= GL_BYTE
;
1369 case MESA_FORMAT_B10G10R10X2_UNORM
:
1370 case MESA_FORMAT_R10G10B10X2_UNORM
:
1371 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1375 case MESA_FORMAT_RGBX_UNORM16
:
1376 case MESA_FORMAT_RGBX_UINT16
:
1377 *datatype
= GL_UNSIGNED_SHORT
;
1381 case MESA_FORMAT_RGBX_SNORM16
:
1382 case MESA_FORMAT_RGBX_SINT16
:
1383 *datatype
= GL_SHORT
;
1387 case MESA_FORMAT_RGBX_FLOAT16
:
1388 *datatype
= GL_HALF_FLOAT
;
1392 case MESA_FORMAT_RGBX_FLOAT32
:
1393 *datatype
= GL_FLOAT
;
1397 case MESA_FORMAT_RGBX_UINT32
:
1398 *datatype
= GL_UNSIGNED_INT
;
1402 case MESA_FORMAT_RGBX_SINT32
:
1407 case MESA_FORMAT_R10G10B10A2_UNORM
:
1408 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1412 case MESA_FORMAT_B8G8R8X8_SRGB
:
1413 case MESA_FORMAT_X8R8G8B8_SRGB
:
1414 *datatype
= GL_UNSIGNED_BYTE
;
1418 case MESA_FORMAT_COUNT
:
1422 const char *name
= _mesa_get_format_name(format
);
1423 /* Warn if any formats are not handled */
1424 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1425 name
? name
: "???");
1426 assert(format
== MESA_FORMAT_NONE
||
1427 _mesa_is_format_compressed(format
));
1435 * Check if a mesa_format exactly matches a GL format/type combination
1436 * such that we can use memcpy() from one to the other.
1437 * \param mesa_format a MESA_FORMAT_x value
1438 * \param format the user-specified image format
1439 * \param type the user-specified image datatype
1440 * \param swapBytes typically the current pixel pack/unpack byteswap state
1441 * \param[out] error GL_NO_ERROR if format is an expected input.
1442 * GL_INVALID_ENUM if format is an unexpected input.
1443 * \return true if the formats match, false otherwise.
1446 _mesa_format_matches_format_and_type(mesa_format mformat
,
1447 GLenum format
, GLenum type
,
1448 bool swapBytes
, GLenum
*error
)
1451 *error
= GL_NO_ERROR
;
1453 if (_mesa_is_format_compressed(mformat
)) {
1455 *error
= GL_INVALID_ENUM
;
1459 if (swapBytes
&& !_mesa_swap_bytes_in_type_enum(&type
))
1462 /* format/type don't include srgb and should match regardless of it. */
1463 mformat
= _mesa_get_srgb_format_linear(mformat
);
1465 /* intensity formats are uploaded with GL_RED, and we want to find
1466 * memcpy matches for them.
1468 mformat
= _mesa_get_intensity_format_red(mformat
);
1470 if (format
== GL_COLOR_INDEX
)
1473 mesa_format other_format
= _mesa_format_from_format_and_type(format
, type
);
1474 if (_mesa_format_is_mesa_array_format(other_format
))
1475 other_format
= _mesa_format_from_array_format(other_format
);
1477 return other_format
== mformat
;