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
;
71 * To describe compressed formats. If not compressed, Width=Height=Depth=1.
73 GLubyte BlockWidth
, BlockHeight
, BlockDepth
;
74 GLubyte BytesPerBlock
;
77 mesa_array_format ArrayFormat
;
80 #include "format_info.h"
82 static const struct gl_format_info
*
83 _mesa_get_format_info(mesa_format format
)
85 const struct gl_format_info
*info
= &format_info
[format
];
86 STATIC_ASSERT(ARRAY_SIZE(format_info
) == MESA_FORMAT_COUNT
);
87 assert(info
->Name
== format
);
92 /** Return string name of format (for debugging) */
94 _mesa_get_format_name(mesa_format format
)
96 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
103 * Return bytes needed to store a block of pixels in the given format.
104 * Normally, a block is 1x1 (a single pixel). But for compressed formats
105 * a block may be 4x4 or 8x4, etc.
107 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
110 _mesa_get_format_bytes(mesa_format format
)
112 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
113 assert(info
->BytesPerBlock
);
114 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
115 _mesa_is_format_compressed(format
));
116 return info
->BytesPerBlock
;
121 * Return bits per component for the given format.
122 * \param format one of MESA_FORMAT_x
123 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
126 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
128 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
132 case GL_TEXTURE_RED_SIZE
:
133 case GL_RENDERBUFFER_RED_SIZE_EXT
:
134 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
135 case GL_INTERNALFORMAT_RED_SIZE
:
136 return info
->RedBits
;
138 case GL_TEXTURE_GREEN_SIZE
:
139 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
140 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
141 case GL_INTERNALFORMAT_GREEN_SIZE
:
142 return info
->GreenBits
;
144 case GL_TEXTURE_BLUE_SIZE
:
145 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
146 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
147 case GL_INTERNALFORMAT_BLUE_SIZE
:
148 return info
->BlueBits
;
150 case GL_TEXTURE_ALPHA_SIZE
:
151 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
152 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
153 case GL_INTERNALFORMAT_ALPHA_SIZE
:
154 return info
->AlphaBits
;
155 case GL_TEXTURE_INTENSITY_SIZE
:
156 return info
->IntensityBits
;
157 case GL_TEXTURE_LUMINANCE_SIZE
:
158 return info
->LuminanceBits
;
162 case GL_TEXTURE_DEPTH_SIZE_ARB
:
163 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
164 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
165 case GL_INTERNALFORMAT_DEPTH_SIZE
:
166 return info
->DepthBits
;
167 case GL_STENCIL_BITS
:
168 case GL_TEXTURE_STENCIL_SIZE_EXT
:
169 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
170 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
171 case GL_INTERNALFORMAT_STENCIL_SIZE
:
172 return info
->StencilBits
;
174 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
181 _mesa_get_format_max_bits(mesa_format format
)
183 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
184 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
185 max
= MAX2(max
, info
->BlueBits
);
186 max
= MAX2(max
, info
->AlphaBits
);
187 max
= MAX2(max
, info
->LuminanceBits
);
188 max
= MAX2(max
, info
->IntensityBits
);
189 max
= MAX2(max
, info
->DepthBits
);
190 max
= MAX2(max
, info
->StencilBits
);
196 * Return the layout type of the given format.
198 extern enum mesa_format_layout
199 _mesa_get_format_layout(mesa_format format
)
201 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
207 * Return the data type (or more specifically, the data representation)
208 * for the given format.
209 * The return value will be one of:
210 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
211 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
212 * GL_UNSIGNED_INT = an ordinary unsigned integer
213 * GL_INT = an ordinary signed integer
214 * GL_FLOAT = an ordinary float
217 _mesa_get_format_datatype(mesa_format format
)
219 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
220 return info
->DataType
;
224 get_base_format_for_array_format(mesa_array_format format
)
229 _mesa_array_format_get_swizzle(format
, swizzle
);
230 num_channels
= _mesa_array_format_get_num_channels(format
);
232 switch (num_channels
) {
234 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
235 * This is not really a problem for now because we only create array
236 * formats from GL format/type combinations, and these cannot specify
243 if (swizzle
[0] == 0 &&
247 return GL_LUMINANCE_ALPHA
;
248 if (swizzle
[0] == 1 &&
252 return GL_LUMINANCE_ALPHA
;
253 if (swizzle
[0] == 0 &&
258 if (swizzle
[0] == 1 &&
265 if (swizzle
[0] == 0 &&
270 if (swizzle
[0] == 0 &&
275 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
277 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
279 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
281 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
286 unreachable("Unsupported format");
290 * Return the basic format for the given type. The result will be one of
291 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
292 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
293 * This functions accepts a mesa_format or a mesa_array_format.
296 _mesa_get_format_base_format(uint32_t format
)
298 if (!_mesa_format_is_mesa_array_format(format
)) {
299 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
300 return info
->BaseFormat
;
302 return get_base_format_for_array_format(format
);
308 * Return the block size (in pixels) for the given format. Normally
309 * the block size is 1x1. But compressed formats will have block sizes
310 * of 4x4 or 8x4 pixels, etc.
311 * \param bw returns block width in pixels
312 * \param bh returns block height in pixels
315 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
317 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
318 /* Use _mesa_get_format_block_size_3d() for 3D blocks. */
319 assert(info
->BlockDepth
== 1);
321 *bw
= info
->BlockWidth
;
322 *bh
= info
->BlockHeight
;
327 * Return the block size (in pixels) for the given format. Normally
328 * the block size is 1x1x1. But compressed formats will have block
329 * sizes of 4x4x4, 3x3x3 pixels, etc.
330 * \param bw returns block width in pixels
331 * \param bh returns block height in pixels
332 * \param bd returns block depth in pixels
335 _mesa_get_format_block_size_3d(mesa_format format
,
340 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
341 *bw
= info
->BlockWidth
;
342 *bh
= info
->BlockHeight
;
343 *bd
= info
->BlockDepth
;
348 * Returns the an array of four numbers representing the transformation
349 * from the RGBA or SZ colorspace to the given format. For array formats,
350 * the i'th RGBA component is given by:
352 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
353 * comp = data[swizzle[i]];
354 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
356 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
358 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
359 * // data does not contain a channel of this format
361 * For packed formats, the swizzle gives the number of components left of
362 * the least significant bit.
364 * Compressed formats have no swizzle.
367 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
369 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
370 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
374 _mesa_array_format_flip_channels(mesa_array_format format
)
379 num_channels
= _mesa_array_format_get_num_channels(format
);
380 _mesa_array_format_get_swizzle(format
, swizzle
);
382 if (num_channels
== 1)
385 if (num_channels
== 2) {
386 /* Assert that the swizzle makes sense for 2 channels */
387 for (unsigned i
= 0; i
< 4; i
++)
388 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
390 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
391 _mesa_array_format_set_swizzle(&format
,
392 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
393 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
397 if (num_channels
== 4) {
398 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
399 _mesa_array_format_set_swizzle(&format
,
400 flip
[swizzle
[0]], flip
[swizzle
[1]],
401 flip
[swizzle
[2]], flip
[swizzle
[3]]);
405 unreachable("Invalid array format");
409 _mesa_format_to_array_format(mesa_format format
)
411 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
412 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
413 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
414 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
416 return info
->ArrayFormat
;
419 static struct hash_table
*format_array_format_table
;
420 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
423 array_formats_equal(const void *a
, const void *b
)
425 return (intptr_t)a
== (intptr_t)b
;
429 format_array_format_table_init(void)
431 const struct gl_format_info
*info
;
432 mesa_array_format array_format
;
435 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
436 array_formats_equal
);
438 if (!format_array_format_table
) {
439 _mesa_error_no_memory(__func__
);
443 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
444 info
= _mesa_get_format_info(f
);
445 if (!info
->ArrayFormat
)
448 if (_mesa_little_endian()) {
449 array_format
= info
->ArrayFormat
;
451 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
454 /* This can happen and does for some of the BGR formats. Let's take
455 * the first one in the list.
457 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
459 (void *)(intptr_t)array_format
))
462 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
464 (void *)(intptr_t)array_format
,
465 (void *)(intptr_t)f
);
470 _mesa_format_from_array_format(uint32_t array_format
)
472 struct hash_entry
*entry
;
474 assert(_mesa_format_is_mesa_array_format(array_format
));
476 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
478 if (!format_array_format_table
) {
479 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
480 format_array_format_table_exists
= once_flag_init
;
481 return MESA_FORMAT_NONE
;
484 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
486 (void *)(intptr_t)array_format
);
488 return (intptr_t)entry
->data
;
490 return MESA_FORMAT_NONE
;
493 /** Is the given format a compressed format? */
495 _mesa_is_format_compressed(mesa_format format
)
497 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
498 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
503 * Determine if the given format represents a packed depth/stencil buffer.
506 _mesa_is_format_packed_depth_stencil(mesa_format format
)
508 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
510 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
515 * Is the given format a signed/unsigned integer color format?
518 _mesa_is_format_integer_color(mesa_format format
)
520 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
521 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
522 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
523 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
524 info
->BaseFormat
!= GL_STENCIL_INDEX
;
529 * Is the given format an unsigned integer format?
532 _mesa_is_format_unsigned(mesa_format format
)
534 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
535 return _mesa_is_type_unsigned(info
->DataType
);
540 * Does the given format store signed values?
543 _mesa_is_format_signed(mesa_format format
)
545 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
546 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
547 /* these packed float formats only store unsigned values */
551 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
552 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
553 info
->DataType
== GL_INT
||
554 info
->DataType
== GL_FLOAT
);
559 * Is the given format an integer format?
562 _mesa_is_format_integer(mesa_format format
)
564 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
565 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
570 * Return true if the given format is a color format.
573 _mesa_is_format_color_format(mesa_format format
)
575 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
576 switch (info
->BaseFormat
) {
577 case GL_DEPTH_COMPONENT
:
578 case GL_STENCIL_INDEX
:
579 case GL_DEPTH_STENCIL
:
588 * Return color encoding for given format.
589 * \return GL_LINEAR or GL_SRGB
592 _mesa_get_format_color_encoding(mesa_format format
)
594 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
595 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
600 * Return TRUE if format is an ETC2 compressed format specified
601 * by GL_ARB_ES3_compatibility.
604 _mesa_is_format_etc2(mesa_format format
)
607 case MESA_FORMAT_ETC2_RGB8
:
608 case MESA_FORMAT_ETC2_SRGB8
:
609 case MESA_FORMAT_ETC2_RGBA8_EAC
:
610 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
611 case MESA_FORMAT_ETC2_R11_EAC
:
612 case MESA_FORMAT_ETC2_RG11_EAC
:
613 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
614 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
615 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
616 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
625 * If the given format is a compressed format, return a corresponding
626 * uncompressed format.
629 _mesa_get_uncompressed_format(mesa_format format
)
632 case MESA_FORMAT_RGB_FXT1
:
633 return MESA_FORMAT_BGR_UNORM8
;
634 case MESA_FORMAT_RGBA_FXT1
:
635 return MESA_FORMAT_A8B8G8R8_UNORM
;
636 case MESA_FORMAT_RGB_DXT1
:
637 case MESA_FORMAT_SRGB_DXT1
:
638 return MESA_FORMAT_BGR_UNORM8
;
639 case MESA_FORMAT_RGBA_DXT1
:
640 case MESA_FORMAT_SRGBA_DXT1
:
641 return MESA_FORMAT_A8B8G8R8_UNORM
;
642 case MESA_FORMAT_RGBA_DXT3
:
643 case MESA_FORMAT_SRGBA_DXT3
:
644 return MESA_FORMAT_A8B8G8R8_UNORM
;
645 case MESA_FORMAT_RGBA_DXT5
:
646 case MESA_FORMAT_SRGBA_DXT5
:
647 return MESA_FORMAT_A8B8G8R8_UNORM
;
648 case MESA_FORMAT_R_RGTC1_UNORM
:
649 return MESA_FORMAT_R_UNORM8
;
650 case MESA_FORMAT_R_RGTC1_SNORM
:
651 return MESA_FORMAT_R_SNORM8
;
652 case MESA_FORMAT_RG_RGTC2_UNORM
:
653 return MESA_FORMAT_R8G8_UNORM
;
654 case MESA_FORMAT_RG_RGTC2_SNORM
:
655 return MESA_FORMAT_R8G8_SNORM
;
656 case MESA_FORMAT_L_LATC1_UNORM
:
657 return MESA_FORMAT_L_UNORM8
;
658 case MESA_FORMAT_L_LATC1_SNORM
:
659 return MESA_FORMAT_L_SNORM8
;
660 case MESA_FORMAT_LA_LATC2_UNORM
:
661 return MESA_FORMAT_L8A8_UNORM
;
662 case MESA_FORMAT_LA_LATC2_SNORM
:
663 return MESA_FORMAT_L8A8_SNORM
;
664 case MESA_FORMAT_ETC1_RGB8
:
665 case MESA_FORMAT_ETC2_RGB8
:
666 case MESA_FORMAT_ETC2_SRGB8
:
667 return MESA_FORMAT_BGR_UNORM8
;
668 case MESA_FORMAT_ETC2_RGBA8_EAC
:
669 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
670 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
671 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
672 return MESA_FORMAT_A8B8G8R8_UNORM
;
673 case MESA_FORMAT_ETC2_R11_EAC
:
674 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
675 return MESA_FORMAT_R_UNORM16
;
676 case MESA_FORMAT_ETC2_RG11_EAC
:
677 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
678 return MESA_FORMAT_R16G16_UNORM
;
679 case MESA_FORMAT_BPTC_RGBA_UNORM
:
680 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
681 return MESA_FORMAT_A8B8G8R8_UNORM
;
682 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
683 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
684 return MESA_FORMAT_RGB_FLOAT32
;
687 assert(!_mesa_is_format_compressed(format
));
695 _mesa_format_num_components(mesa_format format
)
697 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
698 return ((info
->RedBits
> 0) +
699 (info
->GreenBits
> 0) +
700 (info
->BlueBits
> 0) +
701 (info
->AlphaBits
> 0) +
702 (info
->LuminanceBits
> 0) +
703 (info
->IntensityBits
> 0) +
704 (info
->DepthBits
> 0) +
705 (info
->StencilBits
> 0));
710 * Returns true if a color format has data stored in the R/G/B/A channels,
711 * given an index from 0 to 3.
714 _mesa_format_has_color_component(mesa_format format
, int component
)
716 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
718 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
719 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
720 info
->BaseFormat
!= GL_STENCIL_INDEX
);
724 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
726 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
728 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
730 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
732 assert(!"Invalid color component: must be 0..3");
739 * Return number of bytes needed to store an image of the given size
740 * in the given format.
743 _mesa_format_image_size(mesa_format format
, GLsizei width
,
744 GLsizei height
, GLsizei depth
)
746 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
748 /* Strictly speaking, a conditional isn't needed here */
749 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
750 /* compressed format (2D only for now) */
751 const GLuint bw
= info
->BlockWidth
;
752 const GLuint bh
= info
->BlockHeight
;
753 const GLuint bd
= info
->BlockDepth
;
754 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
755 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
756 const GLuint dblocks
= (depth
+ bd
- 1) / bd
;
757 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
760 sz
= width
* height
* depth
* info
->BytesPerBlock
;
767 * Same as _mesa_format_image_size() but returns a 64-bit value to
768 * accommodate very large textures.
771 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
772 GLsizei height
, GLsizei depth
)
774 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
776 /* Strictly speaking, a conditional isn't needed here */
777 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
778 /* compressed format (2D only for now) */
779 const uint64_t bw
= info
->BlockWidth
;
780 const uint64_t bh
= info
->BlockHeight
;
781 const uint64_t bd
= info
->BlockDepth
;
782 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
783 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
784 const uint64_t dblocks
= (depth
+ bd
- 1) / bd
;
785 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
788 sz
= ((uint64_t) width
* (uint64_t) height
*
789 (uint64_t) depth
* info
->BytesPerBlock
);
797 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
799 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
800 /* Strictly speaking, a conditional isn't needed here */
801 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
802 /* compressed format */
803 const GLuint bw
= info
->BlockWidth
;
804 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
805 const GLint stride
= wblocks
* info
->BytesPerBlock
;
809 const GLint stride
= width
* info
->BytesPerBlock
;
817 * Return datatype and number of components per texel for the given
818 * uncompressed mesa_format. Only used for mipmap generation code.
821 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
822 GLenum
*datatype
, GLuint
*comps
)
825 case MESA_FORMAT_A8B8G8R8_UNORM
:
826 case MESA_FORMAT_R8G8B8A8_UNORM
:
827 case MESA_FORMAT_B8G8R8A8_UNORM
:
828 case MESA_FORMAT_A8R8G8B8_UNORM
:
829 case MESA_FORMAT_X8B8G8R8_UNORM
:
830 case MESA_FORMAT_R8G8B8X8_UNORM
:
831 case MESA_FORMAT_B8G8R8X8_UNORM
:
832 case MESA_FORMAT_X8R8G8B8_UNORM
:
833 case MESA_FORMAT_A8B8G8R8_UINT
:
834 case MESA_FORMAT_R8G8B8A8_UINT
:
835 case MESA_FORMAT_B8G8R8A8_UINT
:
836 case MESA_FORMAT_A8R8G8B8_UINT
:
837 *datatype
= GL_UNSIGNED_BYTE
;
840 case MESA_FORMAT_BGR_UNORM8
:
841 case MESA_FORMAT_RGB_UNORM8
:
842 *datatype
= GL_UNSIGNED_BYTE
;
845 case MESA_FORMAT_B5G6R5_UNORM
:
846 case MESA_FORMAT_R5G6B5_UNORM
:
847 case MESA_FORMAT_B5G6R5_UINT
:
848 case MESA_FORMAT_R5G6B5_UINT
:
849 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
853 case MESA_FORMAT_B4G4R4A4_UNORM
:
854 case MESA_FORMAT_A4R4G4B4_UNORM
:
855 case MESA_FORMAT_B4G4R4X4_UNORM
:
856 case MESA_FORMAT_B4G4R4A4_UINT
:
857 case MESA_FORMAT_A4R4G4B4_UINT
:
858 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
862 case MESA_FORMAT_B5G5R5A1_UNORM
:
863 case MESA_FORMAT_A1R5G5B5_UNORM
:
864 case MESA_FORMAT_B5G5R5X1_UNORM
:
865 case MESA_FORMAT_B5G5R5A1_UINT
:
866 case MESA_FORMAT_A1R5G5B5_UINT
:
867 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
871 case MESA_FORMAT_B10G10R10A2_UNORM
:
872 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
876 case MESA_FORMAT_A1B5G5R5_UNORM
:
877 case MESA_FORMAT_A1B5G5R5_UINT
:
878 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
882 case MESA_FORMAT_L4A4_UNORM
:
883 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
887 case MESA_FORMAT_L8A8_UNORM
:
888 case MESA_FORMAT_A8L8_UNORM
:
889 case MESA_FORMAT_R8G8_UNORM
:
890 case MESA_FORMAT_G8R8_UNORM
:
891 *datatype
= GL_UNSIGNED_BYTE
;
895 case MESA_FORMAT_L16A16_UNORM
:
896 case MESA_FORMAT_A16L16_UNORM
:
897 case MESA_FORMAT_R16G16_UNORM
:
898 case MESA_FORMAT_G16R16_UNORM
:
899 *datatype
= GL_UNSIGNED_SHORT
;
903 case MESA_FORMAT_R_UNORM16
:
904 case MESA_FORMAT_A_UNORM16
:
905 case MESA_FORMAT_L_UNORM16
:
906 case MESA_FORMAT_I_UNORM16
:
907 *datatype
= GL_UNSIGNED_SHORT
;
911 case MESA_FORMAT_R3G3B2_UNORM
:
912 case MESA_FORMAT_R3G3B2_UINT
:
913 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
916 case MESA_FORMAT_A4B4G4R4_UNORM
:
917 case MESA_FORMAT_A4B4G4R4_UINT
:
918 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
922 case MESA_FORMAT_R4G4B4A4_UNORM
:
923 case MESA_FORMAT_R4G4B4A4_UINT
:
924 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
927 case MESA_FORMAT_R5G5B5A1_UNORM
:
928 case MESA_FORMAT_R5G5B5A1_UINT
:
929 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
932 case MESA_FORMAT_A2B10G10R10_UNORM
:
933 case MESA_FORMAT_A2B10G10R10_UINT
:
934 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
937 case MESA_FORMAT_A2R10G10B10_UNORM
:
938 case MESA_FORMAT_A2R10G10B10_UINT
:
939 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
943 case MESA_FORMAT_B2G3R3_UNORM
:
944 case MESA_FORMAT_B2G3R3_UINT
:
945 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
949 case MESA_FORMAT_A_UNORM8
:
950 case MESA_FORMAT_L_UNORM8
:
951 case MESA_FORMAT_I_UNORM8
:
952 case MESA_FORMAT_R_UNORM8
:
953 case MESA_FORMAT_S_UINT8
:
954 *datatype
= GL_UNSIGNED_BYTE
;
958 case MESA_FORMAT_YCBCR
:
959 case MESA_FORMAT_YCBCR_REV
:
960 *datatype
= GL_UNSIGNED_SHORT
;
964 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
965 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
969 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
970 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
974 case MESA_FORMAT_Z_UNORM16
:
975 *datatype
= GL_UNSIGNED_SHORT
;
979 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
980 *datatype
= GL_UNSIGNED_INT
;
984 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
985 *datatype
= GL_UNSIGNED_INT
;
989 case MESA_FORMAT_Z_UNORM32
:
990 *datatype
= GL_UNSIGNED_INT
;
994 case MESA_FORMAT_Z_FLOAT32
:
995 *datatype
= GL_FLOAT
;
999 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1000 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1004 case MESA_FORMAT_R_SNORM8
:
1005 case MESA_FORMAT_A_SNORM8
:
1006 case MESA_FORMAT_L_SNORM8
:
1007 case MESA_FORMAT_I_SNORM8
:
1008 *datatype
= GL_BYTE
;
1011 case MESA_FORMAT_R8G8_SNORM
:
1012 case MESA_FORMAT_L8A8_SNORM
:
1013 case MESA_FORMAT_A8L8_SNORM
:
1014 *datatype
= GL_BYTE
;
1017 case MESA_FORMAT_A8B8G8R8_SNORM
:
1018 case MESA_FORMAT_R8G8B8A8_SNORM
:
1019 case MESA_FORMAT_X8B8G8R8_SNORM
:
1020 *datatype
= GL_BYTE
;
1024 case MESA_FORMAT_RGBA_UNORM16
:
1025 *datatype
= GL_UNSIGNED_SHORT
;
1029 case MESA_FORMAT_R_SNORM16
:
1030 case MESA_FORMAT_A_SNORM16
:
1031 case MESA_FORMAT_L_SNORM16
:
1032 case MESA_FORMAT_I_SNORM16
:
1033 *datatype
= GL_SHORT
;
1036 case MESA_FORMAT_R16G16_SNORM
:
1037 case MESA_FORMAT_LA_SNORM16
:
1038 *datatype
= GL_SHORT
;
1041 case MESA_FORMAT_RGB_SNORM16
:
1042 *datatype
= GL_SHORT
;
1045 case MESA_FORMAT_RGBA_SNORM16
:
1046 *datatype
= GL_SHORT
;
1050 case MESA_FORMAT_BGR_SRGB8
:
1051 *datatype
= GL_UNSIGNED_BYTE
;
1054 case MESA_FORMAT_A8B8G8R8_SRGB
:
1055 case MESA_FORMAT_B8G8R8A8_SRGB
:
1056 case MESA_FORMAT_A8R8G8B8_SRGB
:
1057 case MESA_FORMAT_R8G8B8A8_SRGB
:
1058 *datatype
= GL_UNSIGNED_BYTE
;
1061 case MESA_FORMAT_L_SRGB8
:
1062 *datatype
= GL_UNSIGNED_BYTE
;
1065 case MESA_FORMAT_L8A8_SRGB
:
1066 case MESA_FORMAT_A8L8_SRGB
:
1067 *datatype
= GL_UNSIGNED_BYTE
;
1071 case MESA_FORMAT_RGBA_FLOAT32
:
1072 *datatype
= GL_FLOAT
;
1075 case MESA_FORMAT_RGBA_FLOAT16
:
1076 *datatype
= GL_HALF_FLOAT_ARB
;
1079 case MESA_FORMAT_RGB_FLOAT32
:
1080 *datatype
= GL_FLOAT
;
1083 case MESA_FORMAT_RGB_FLOAT16
:
1084 *datatype
= GL_HALF_FLOAT_ARB
;
1087 case MESA_FORMAT_LA_FLOAT32
:
1088 case MESA_FORMAT_RG_FLOAT32
:
1089 *datatype
= GL_FLOAT
;
1092 case MESA_FORMAT_LA_FLOAT16
:
1093 case MESA_FORMAT_RG_FLOAT16
:
1094 *datatype
= GL_HALF_FLOAT_ARB
;
1097 case MESA_FORMAT_A_FLOAT32
:
1098 case MESA_FORMAT_L_FLOAT32
:
1099 case MESA_FORMAT_I_FLOAT32
:
1100 case MESA_FORMAT_R_FLOAT32
:
1101 *datatype
= GL_FLOAT
;
1104 case MESA_FORMAT_A_FLOAT16
:
1105 case MESA_FORMAT_L_FLOAT16
:
1106 case MESA_FORMAT_I_FLOAT16
:
1107 case MESA_FORMAT_R_FLOAT16
:
1108 *datatype
= GL_HALF_FLOAT_ARB
;
1112 case MESA_FORMAT_A_UINT8
:
1113 case MESA_FORMAT_L_UINT8
:
1114 case MESA_FORMAT_I_UINT8
:
1115 *datatype
= GL_UNSIGNED_BYTE
;
1118 case MESA_FORMAT_LA_UINT8
:
1119 *datatype
= GL_UNSIGNED_BYTE
;
1123 case MESA_FORMAT_A_UINT16
:
1124 case MESA_FORMAT_L_UINT16
:
1125 case MESA_FORMAT_I_UINT16
:
1126 *datatype
= GL_UNSIGNED_SHORT
;
1129 case MESA_FORMAT_LA_UINT16
:
1130 *datatype
= GL_UNSIGNED_SHORT
;
1133 case MESA_FORMAT_A_UINT32
:
1134 case MESA_FORMAT_L_UINT32
:
1135 case MESA_FORMAT_I_UINT32
:
1136 *datatype
= GL_UNSIGNED_INT
;
1139 case MESA_FORMAT_LA_UINT32
:
1140 *datatype
= GL_UNSIGNED_INT
;
1143 case MESA_FORMAT_A_SINT8
:
1144 case MESA_FORMAT_L_SINT8
:
1145 case MESA_FORMAT_I_SINT8
:
1146 *datatype
= GL_BYTE
;
1149 case MESA_FORMAT_LA_SINT8
:
1150 *datatype
= GL_BYTE
;
1154 case MESA_FORMAT_A_SINT16
:
1155 case MESA_FORMAT_L_SINT16
:
1156 case MESA_FORMAT_I_SINT16
:
1157 *datatype
= GL_SHORT
;
1160 case MESA_FORMAT_LA_SINT16
:
1161 *datatype
= GL_SHORT
;
1165 case MESA_FORMAT_A_SINT32
:
1166 case MESA_FORMAT_L_SINT32
:
1167 case MESA_FORMAT_I_SINT32
:
1171 case MESA_FORMAT_LA_SINT32
:
1176 case MESA_FORMAT_R_SINT8
:
1177 *datatype
= GL_BYTE
;
1180 case MESA_FORMAT_RG_SINT8
:
1181 *datatype
= GL_BYTE
;
1184 case MESA_FORMAT_RGB_SINT8
:
1185 *datatype
= GL_BYTE
;
1188 case MESA_FORMAT_RGBA_SINT8
:
1189 *datatype
= GL_BYTE
;
1192 case MESA_FORMAT_R_SINT16
:
1193 *datatype
= GL_SHORT
;
1196 case MESA_FORMAT_RG_SINT16
:
1197 *datatype
= GL_SHORT
;
1200 case MESA_FORMAT_RGB_SINT16
:
1201 *datatype
= GL_SHORT
;
1204 case MESA_FORMAT_RGBA_SINT16
:
1205 *datatype
= GL_SHORT
;
1208 case MESA_FORMAT_R_SINT32
:
1212 case MESA_FORMAT_RG_SINT32
:
1216 case MESA_FORMAT_RGB_SINT32
:
1220 case MESA_FORMAT_RGBA_SINT32
:
1226 * \name Non-normalized unsigned integer formats.
1228 case MESA_FORMAT_R_UINT8
:
1229 *datatype
= GL_UNSIGNED_BYTE
;
1232 case MESA_FORMAT_RG_UINT8
:
1233 *datatype
= GL_UNSIGNED_BYTE
;
1236 case MESA_FORMAT_RGB_UINT8
:
1237 *datatype
= GL_UNSIGNED_BYTE
;
1240 case MESA_FORMAT_RGBA_UINT8
:
1241 *datatype
= GL_UNSIGNED_BYTE
;
1244 case MESA_FORMAT_R_UINT16
:
1245 *datatype
= GL_UNSIGNED_SHORT
;
1248 case MESA_FORMAT_RG_UINT16
:
1249 *datatype
= GL_UNSIGNED_SHORT
;
1252 case MESA_FORMAT_RGB_UINT16
:
1253 *datatype
= GL_UNSIGNED_SHORT
;
1256 case MESA_FORMAT_RGBA_UINT16
:
1257 *datatype
= GL_UNSIGNED_SHORT
;
1260 case MESA_FORMAT_R_UINT32
:
1261 *datatype
= GL_UNSIGNED_INT
;
1264 case MESA_FORMAT_RG_UINT32
:
1265 *datatype
= GL_UNSIGNED_INT
;
1268 case MESA_FORMAT_RGB_UINT32
:
1269 *datatype
= GL_UNSIGNED_INT
;
1272 case MESA_FORMAT_RGBA_UINT32
:
1273 *datatype
= GL_UNSIGNED_INT
;
1277 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1278 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1282 case MESA_FORMAT_R11G11B10_FLOAT
:
1283 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1287 case MESA_FORMAT_B10G10R10A2_UINT
:
1288 case MESA_FORMAT_R10G10B10A2_UINT
:
1289 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1293 case MESA_FORMAT_R8G8B8X8_SRGB
:
1294 case MESA_FORMAT_X8B8G8R8_SRGB
:
1295 case MESA_FORMAT_RGBX_UINT8
:
1296 *datatype
= GL_UNSIGNED_BYTE
;
1300 case MESA_FORMAT_R8G8B8X8_SNORM
:
1301 case MESA_FORMAT_RGBX_SINT8
:
1302 *datatype
= GL_BYTE
;
1306 case MESA_FORMAT_B10G10R10X2_UNORM
:
1307 case MESA_FORMAT_R10G10B10X2_UNORM
:
1308 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1312 case MESA_FORMAT_RGBX_UNORM16
:
1313 case MESA_FORMAT_RGBX_UINT16
:
1314 *datatype
= GL_UNSIGNED_SHORT
;
1318 case MESA_FORMAT_RGBX_SNORM16
:
1319 case MESA_FORMAT_RGBX_SINT16
:
1320 *datatype
= GL_SHORT
;
1324 case MESA_FORMAT_RGBX_FLOAT16
:
1325 *datatype
= GL_HALF_FLOAT
;
1329 case MESA_FORMAT_RGBX_FLOAT32
:
1330 *datatype
= GL_FLOAT
;
1334 case MESA_FORMAT_RGBX_UINT32
:
1335 *datatype
= GL_UNSIGNED_INT
;
1339 case MESA_FORMAT_RGBX_SINT32
:
1344 case MESA_FORMAT_R10G10B10A2_UNORM
:
1345 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1349 case MESA_FORMAT_G8R8_SNORM
:
1350 *datatype
= GL_BYTE
;
1354 case MESA_FORMAT_G16R16_SNORM
:
1355 *datatype
= GL_SHORT
;
1359 case MESA_FORMAT_B8G8R8X8_SRGB
:
1360 case MESA_FORMAT_X8R8G8B8_SRGB
:
1361 *datatype
= GL_UNSIGNED_BYTE
;
1365 case MESA_FORMAT_COUNT
:
1369 /* Warn if any formats are not handled */
1370 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1371 _mesa_get_format_name(format
));
1372 assert(format
== MESA_FORMAT_NONE
||
1373 _mesa_is_format_compressed(format
));
1380 * Check if a mesa_format exactly matches a GL format/type combination
1381 * such that we can use memcpy() from one to the other.
1382 * \param mesa_format a MESA_FORMAT_x value
1383 * \param format the user-specified image format
1384 * \param type the user-specified image datatype
1385 * \param swapBytes typically the current pixel pack/unpack byteswap state
1386 * \param[out] error GL_NO_ERROR if format is an expected input.
1387 * GL_INVALID_ENUM if format is an unexpected input.
1388 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1391 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1392 GLenum format
, GLenum type
,
1393 GLboolean swapBytes
, GLenum
*error
)
1395 const GLboolean littleEndian
= _mesa_little_endian();
1397 *error
= GL_NO_ERROR
;
1399 /* Note: When reading a GL format/type combination, the format lists channel
1400 * assignments from most significant channel in the type to least
1401 * significant. A type with _REV indicates that the assignments are
1402 * swapped, so they are listed from least significant to most significant.
1404 * Compressed formats will fall through and return GL_FALSE.
1406 * For sanity, please keep this switch statement ordered the same as the
1407 * enums in formats.h.
1410 switch (mesa_format
) {
1412 case MESA_FORMAT_NONE
:
1413 case MESA_FORMAT_COUNT
:
1416 case MESA_FORMAT_A8B8G8R8_UNORM
:
1417 case MESA_FORMAT_A8B8G8R8_SRGB
:
1418 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1421 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1424 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1427 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1431 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1435 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1440 case MESA_FORMAT_R8G8B8A8_UNORM
:
1441 case MESA_FORMAT_R8G8B8A8_SRGB
:
1442 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1446 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1449 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1452 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1456 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1460 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1465 case MESA_FORMAT_B8G8R8A8_UNORM
:
1466 case MESA_FORMAT_B8G8R8A8_SRGB
:
1467 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1471 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1474 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1479 case MESA_FORMAT_A8R8G8B8_UNORM
:
1480 case MESA_FORMAT_A8R8G8B8_SRGB
:
1481 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1484 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1488 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1493 case MESA_FORMAT_X8B8G8R8_UNORM
:
1494 case MESA_FORMAT_R8G8B8X8_UNORM
:
1497 case MESA_FORMAT_B8G8R8X8_UNORM
:
1498 case MESA_FORMAT_X8R8G8B8_UNORM
:
1501 case MESA_FORMAT_BGR_UNORM8
:
1502 case MESA_FORMAT_BGR_SRGB8
:
1503 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1505 case MESA_FORMAT_RGB_UNORM8
:
1506 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1508 case MESA_FORMAT_B5G6R5_UNORM
:
1509 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1510 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1513 case MESA_FORMAT_R5G6B5_UNORM
:
1514 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1515 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1518 case MESA_FORMAT_B4G4R4A4_UNORM
:
1519 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1522 case MESA_FORMAT_A4R4G4B4_UNORM
:
1525 case MESA_FORMAT_A1B5G5R5_UNORM
:
1526 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1529 case MESA_FORMAT_B5G5R5A1_UNORM
:
1530 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1533 case MESA_FORMAT_A1R5G5B5_UNORM
:
1534 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1537 case MESA_FORMAT_L4A4_UNORM
:
1539 case MESA_FORMAT_L8A8_UNORM
:
1540 case MESA_FORMAT_L8A8_SRGB
:
1541 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1542 case MESA_FORMAT_A8L8_UNORM
:
1543 case MESA_FORMAT_A8L8_SRGB
:
1546 case MESA_FORMAT_L16A16_UNORM
:
1547 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1548 case MESA_FORMAT_A16L16_UNORM
:
1551 case MESA_FORMAT_B2G3R3_UNORM
:
1552 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1554 case MESA_FORMAT_R3G3B2_UNORM
:
1555 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1557 case MESA_FORMAT_A4B4G4R4_UNORM
:
1558 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1561 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1564 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1567 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1572 case MESA_FORMAT_R4G4B4A4_UNORM
:
1573 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1576 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1579 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1582 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1587 case MESA_FORMAT_R5G5B5A1_UNORM
:
1588 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1590 case MESA_FORMAT_A2B10G10R10_UNORM
:
1591 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1593 case MESA_FORMAT_A2B10G10R10_UINT
:
1594 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1596 case MESA_FORMAT_A2R10G10B10_UNORM
:
1597 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1599 case MESA_FORMAT_A2R10G10B10_UINT
:
1600 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1602 case MESA_FORMAT_A_UNORM8
:
1603 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1604 case MESA_FORMAT_A_UNORM16
:
1605 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1606 case MESA_FORMAT_L_UNORM8
:
1607 case MESA_FORMAT_L_SRGB8
:
1608 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1609 case MESA_FORMAT_L_UNORM16
:
1610 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1611 case MESA_FORMAT_I_UNORM8
:
1612 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1613 case MESA_FORMAT_I_UNORM16
:
1614 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1616 case MESA_FORMAT_YCBCR
:
1617 return format
== GL_YCBCR_MESA
&&
1618 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1619 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1620 case MESA_FORMAT_YCBCR_REV
:
1621 return format
== GL_YCBCR_MESA
&&
1622 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1623 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1625 case MESA_FORMAT_R_UNORM8
:
1626 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1627 case MESA_FORMAT_R8G8_UNORM
:
1628 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1629 case MESA_FORMAT_G8R8_UNORM
:
1632 case MESA_FORMAT_R_UNORM16
:
1633 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1635 case MESA_FORMAT_R16G16_UNORM
:
1636 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1638 case MESA_FORMAT_G16R16_UNORM
:
1641 case MESA_FORMAT_B10G10R10A2_UNORM
:
1642 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1645 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1646 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1648 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1649 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1652 case MESA_FORMAT_Z_UNORM16
:
1653 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1656 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1659 case MESA_FORMAT_Z_UNORM32
:
1660 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1663 case MESA_FORMAT_S_UINT8
:
1664 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1666 case MESA_FORMAT_RGBA_FLOAT32
:
1667 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1668 case MESA_FORMAT_RGBA_FLOAT16
:
1669 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1671 case MESA_FORMAT_RGB_FLOAT32
:
1672 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1673 case MESA_FORMAT_RGB_FLOAT16
:
1674 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1676 case MESA_FORMAT_A_FLOAT32
:
1677 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1678 case MESA_FORMAT_A_FLOAT16
:
1679 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1681 case MESA_FORMAT_L_FLOAT32
:
1682 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1683 case MESA_FORMAT_L_FLOAT16
:
1684 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1686 case MESA_FORMAT_LA_FLOAT32
:
1687 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1688 case MESA_FORMAT_LA_FLOAT16
:
1689 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1691 case MESA_FORMAT_I_FLOAT32
:
1692 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1693 case MESA_FORMAT_I_FLOAT16
:
1694 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1696 case MESA_FORMAT_R_FLOAT32
:
1697 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1698 case MESA_FORMAT_R_FLOAT16
:
1699 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1701 case MESA_FORMAT_RG_FLOAT32
:
1702 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1703 case MESA_FORMAT_RG_FLOAT16
:
1704 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1706 case MESA_FORMAT_A_UINT8
:
1707 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1708 case MESA_FORMAT_A_UINT16
:
1709 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1711 case MESA_FORMAT_A_UINT32
:
1712 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1714 case MESA_FORMAT_A_SINT8
:
1715 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1716 case MESA_FORMAT_A_SINT16
:
1717 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1718 case MESA_FORMAT_A_SINT32
:
1719 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1721 case MESA_FORMAT_I_UINT8
:
1722 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1723 case MESA_FORMAT_I_UINT16
:
1724 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1725 case MESA_FORMAT_I_UINT32
:
1726 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1727 case MESA_FORMAT_I_SINT8
:
1728 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1729 case MESA_FORMAT_I_SINT16
:
1730 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1731 case MESA_FORMAT_I_SINT32
:
1732 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1734 case MESA_FORMAT_L_UINT8
:
1735 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1736 case MESA_FORMAT_L_UINT16
:
1737 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1739 case MESA_FORMAT_L_UINT32
:
1740 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1742 case MESA_FORMAT_L_SINT8
:
1743 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1744 case MESA_FORMAT_L_SINT16
:
1745 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1747 case MESA_FORMAT_L_SINT32
:
1748 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1750 case MESA_FORMAT_LA_UINT8
:
1751 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1752 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1753 case MESA_FORMAT_LA_UINT16
:
1754 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1755 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1756 case MESA_FORMAT_LA_UINT32
:
1757 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1758 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1759 case MESA_FORMAT_LA_SINT8
:
1760 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1762 case MESA_FORMAT_LA_SINT16
:
1763 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1765 case MESA_FORMAT_LA_SINT32
:
1766 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1769 case MESA_FORMAT_R_SINT8
:
1770 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1771 case MESA_FORMAT_RG_SINT8
:
1772 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1773 case MESA_FORMAT_RGB_SINT8
:
1774 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1775 case MESA_FORMAT_RGBA_SINT8
:
1776 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1777 case MESA_FORMAT_R_SINT16
:
1778 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1779 case MESA_FORMAT_RG_SINT16
:
1780 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1781 case MESA_FORMAT_RGB_SINT16
:
1782 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1783 case MESA_FORMAT_RGBA_SINT16
:
1784 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1785 case MESA_FORMAT_R_SINT32
:
1786 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1787 case MESA_FORMAT_RG_SINT32
:
1788 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1789 case MESA_FORMAT_RGB_SINT32
:
1790 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1791 case MESA_FORMAT_RGBA_SINT32
:
1792 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1794 case MESA_FORMAT_R_UINT8
:
1795 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1796 case MESA_FORMAT_RG_UINT8
:
1797 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1798 case MESA_FORMAT_RGB_UINT8
:
1799 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1800 case MESA_FORMAT_RGBA_UINT8
:
1801 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1803 case MESA_FORMAT_R_UINT16
:
1804 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1806 case MESA_FORMAT_RG_UINT16
:
1807 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1808 case MESA_FORMAT_RGB_UINT16
:
1809 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1811 case MESA_FORMAT_RGBA_UINT16
:
1812 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1814 case MESA_FORMAT_R_UINT32
:
1815 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1816 case MESA_FORMAT_RG_UINT32
:
1817 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1818 case MESA_FORMAT_RGB_UINT32
:
1819 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1820 case MESA_FORMAT_RGBA_UINT32
:
1821 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1823 case MESA_FORMAT_R_SNORM8
:
1824 return format
== GL_RED
&& type
== GL_BYTE
;
1825 case MESA_FORMAT_R8G8_SNORM
:
1826 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1828 case MESA_FORMAT_X8B8G8R8_SNORM
:
1831 case MESA_FORMAT_A8B8G8R8_SNORM
:
1832 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1835 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1840 case MESA_FORMAT_R8G8B8A8_SNORM
:
1841 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1844 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1849 case MESA_FORMAT_R_SNORM16
:
1850 return format
== GL_RED
&& type
== GL_SHORT
&&
1852 case MESA_FORMAT_R16G16_SNORM
:
1853 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1854 case MESA_FORMAT_RGB_SNORM16
:
1855 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1856 case MESA_FORMAT_RGBA_SNORM16
:
1857 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1858 case MESA_FORMAT_RGBA_UNORM16
:
1859 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1862 case MESA_FORMAT_A_SNORM8
:
1863 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1864 case MESA_FORMAT_L_SNORM8
:
1865 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1866 case MESA_FORMAT_L8A8_SNORM
:
1867 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1868 littleEndian
&& !swapBytes
;
1869 case MESA_FORMAT_A8L8_SNORM
:
1870 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1871 !littleEndian
&& !swapBytes
;
1872 case MESA_FORMAT_I_SNORM8
:
1873 return format
== GL_RED
&& type
== GL_BYTE
;
1874 case MESA_FORMAT_A_SNORM16
:
1875 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1876 case MESA_FORMAT_L_SNORM16
:
1877 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1878 case MESA_FORMAT_LA_SNORM16
:
1879 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1880 littleEndian
&& !swapBytes
;
1881 case MESA_FORMAT_I_SNORM16
:
1882 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1885 case MESA_FORMAT_B10G10R10A2_UINT
:
1886 return (format
== GL_BGRA_INTEGER_EXT
&&
1887 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1890 case MESA_FORMAT_R10G10B10A2_UINT
:
1891 return (format
== GL_RGBA_INTEGER_EXT
&&
1892 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1895 case MESA_FORMAT_B5G6R5_UINT
:
1896 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1898 case MESA_FORMAT_R5G6B5_UINT
:
1899 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1901 case MESA_FORMAT_B2G3R3_UINT
:
1902 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1904 case MESA_FORMAT_R3G3B2_UINT
:
1905 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1907 case MESA_FORMAT_A4B4G4R4_UINT
:
1908 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1911 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1915 case MESA_FORMAT_R4G4B4A4_UINT
:
1916 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1919 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1924 case MESA_FORMAT_B4G4R4A4_UINT
:
1925 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1928 case MESA_FORMAT_A4R4G4B4_UINT
:
1931 case MESA_FORMAT_A1B5G5R5_UINT
:
1932 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1935 case MESA_FORMAT_B5G5R5A1_UINT
:
1936 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1939 case MESA_FORMAT_A1R5G5B5_UINT
:
1940 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1943 case MESA_FORMAT_R5G5B5A1_UINT
:
1944 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1946 case MESA_FORMAT_A8B8G8R8_UINT
:
1947 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1950 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1954 case MESA_FORMAT_A8R8G8B8_UINT
:
1955 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1959 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1965 case MESA_FORMAT_R8G8B8A8_UINT
:
1966 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1970 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1975 case MESA_FORMAT_B8G8R8A8_UINT
:
1976 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1980 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1985 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1986 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
1989 case MESA_FORMAT_R11G11B10_FLOAT
:
1990 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
1993 case MESA_FORMAT_Z_FLOAT32
:
1994 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
1996 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1997 return format
== GL_DEPTH_STENCIL
&&
1998 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2000 case MESA_FORMAT_B4G4R4X4_UNORM
:
2001 case MESA_FORMAT_B5G5R5X1_UNORM
:
2002 case MESA_FORMAT_R8G8B8X8_SNORM
:
2003 case MESA_FORMAT_R8G8B8X8_SRGB
:
2004 case MESA_FORMAT_X8B8G8R8_SRGB
:
2005 case MESA_FORMAT_RGBX_UINT8
:
2006 case MESA_FORMAT_RGBX_SINT8
:
2007 case MESA_FORMAT_B10G10R10X2_UNORM
:
2008 case MESA_FORMAT_R10G10B10X2_UNORM
:
2009 case MESA_FORMAT_RGBX_UNORM16
:
2010 case MESA_FORMAT_RGBX_SNORM16
:
2011 case MESA_FORMAT_RGBX_FLOAT16
:
2012 case MESA_FORMAT_RGBX_UINT16
:
2013 case MESA_FORMAT_RGBX_SINT16
:
2014 case MESA_FORMAT_RGBX_FLOAT32
:
2015 case MESA_FORMAT_RGBX_UINT32
:
2016 case MESA_FORMAT_RGBX_SINT32
:
2019 case MESA_FORMAT_R10G10B10A2_UNORM
:
2020 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2023 case MESA_FORMAT_G8R8_SNORM
:
2024 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2027 case MESA_FORMAT_G16R16_SNORM
:
2028 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2031 case MESA_FORMAT_B8G8R8X8_SRGB
:
2032 case MESA_FORMAT_X8R8G8B8_SRGB
:
2035 assert(_mesa_is_format_compressed(mesa_format
));
2037 *error
= GL_INVALID_ENUM
;