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 case MESA_FORMAT_X1B5G5R5_UNORM
:
879 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
883 case MESA_FORMAT_L4A4_UNORM
:
884 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
888 case MESA_FORMAT_L8A8_UNORM
:
889 case MESA_FORMAT_A8L8_UNORM
:
890 case MESA_FORMAT_R8G8_UNORM
:
891 case MESA_FORMAT_G8R8_UNORM
:
892 *datatype
= GL_UNSIGNED_BYTE
;
896 case MESA_FORMAT_L16A16_UNORM
:
897 case MESA_FORMAT_A16L16_UNORM
:
898 case MESA_FORMAT_R16G16_UNORM
:
899 case MESA_FORMAT_G16R16_UNORM
:
900 *datatype
= GL_UNSIGNED_SHORT
;
904 case MESA_FORMAT_R_UNORM16
:
905 case MESA_FORMAT_A_UNORM16
:
906 case MESA_FORMAT_L_UNORM16
:
907 case MESA_FORMAT_I_UNORM16
:
908 *datatype
= GL_UNSIGNED_SHORT
;
912 case MESA_FORMAT_R3G3B2_UNORM
:
913 case MESA_FORMAT_R3G3B2_UINT
:
914 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
917 case MESA_FORMAT_A4B4G4R4_UNORM
:
918 case MESA_FORMAT_A4B4G4R4_UINT
:
919 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
923 case MESA_FORMAT_R4G4B4A4_UNORM
:
924 case MESA_FORMAT_R4G4B4A4_UINT
:
925 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
928 case MESA_FORMAT_R5G5B5A1_UNORM
:
929 case MESA_FORMAT_R5G5B5A1_UINT
:
930 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
933 case MESA_FORMAT_A2B10G10R10_UNORM
:
934 case MESA_FORMAT_A2B10G10R10_UINT
:
935 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
938 case MESA_FORMAT_A2R10G10B10_UNORM
:
939 case MESA_FORMAT_A2R10G10B10_UINT
:
940 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
944 case MESA_FORMAT_B2G3R3_UNORM
:
945 case MESA_FORMAT_B2G3R3_UINT
:
946 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
950 case MESA_FORMAT_A_UNORM8
:
951 case MESA_FORMAT_L_UNORM8
:
952 case MESA_FORMAT_I_UNORM8
:
953 case MESA_FORMAT_R_UNORM8
:
954 case MESA_FORMAT_S_UINT8
:
955 *datatype
= GL_UNSIGNED_BYTE
;
959 case MESA_FORMAT_YCBCR
:
960 case MESA_FORMAT_YCBCR_REV
:
961 *datatype
= GL_UNSIGNED_SHORT
;
965 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
966 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
970 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
971 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
975 case MESA_FORMAT_Z_UNORM16
:
976 *datatype
= GL_UNSIGNED_SHORT
;
980 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
981 *datatype
= GL_UNSIGNED_INT
;
985 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
986 *datatype
= GL_UNSIGNED_INT
;
990 case MESA_FORMAT_Z_UNORM32
:
991 *datatype
= GL_UNSIGNED_INT
;
995 case MESA_FORMAT_Z_FLOAT32
:
996 *datatype
= GL_FLOAT
;
1000 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1001 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1005 case MESA_FORMAT_R_SNORM8
:
1006 case MESA_FORMAT_A_SNORM8
:
1007 case MESA_FORMAT_L_SNORM8
:
1008 case MESA_FORMAT_I_SNORM8
:
1009 *datatype
= GL_BYTE
;
1012 case MESA_FORMAT_R8G8_SNORM
:
1013 case MESA_FORMAT_L8A8_SNORM
:
1014 case MESA_FORMAT_A8L8_SNORM
:
1015 *datatype
= GL_BYTE
;
1018 case MESA_FORMAT_A8B8G8R8_SNORM
:
1019 case MESA_FORMAT_R8G8B8A8_SNORM
:
1020 case MESA_FORMAT_X8B8G8R8_SNORM
:
1021 *datatype
= GL_BYTE
;
1025 case MESA_FORMAT_RGBA_UNORM16
:
1026 *datatype
= GL_UNSIGNED_SHORT
;
1030 case MESA_FORMAT_R_SNORM16
:
1031 case MESA_FORMAT_A_SNORM16
:
1032 case MESA_FORMAT_L_SNORM16
:
1033 case MESA_FORMAT_I_SNORM16
:
1034 *datatype
= GL_SHORT
;
1037 case MESA_FORMAT_R16G16_SNORM
:
1038 case MESA_FORMAT_LA_SNORM16
:
1039 *datatype
= GL_SHORT
;
1042 case MESA_FORMAT_RGB_SNORM16
:
1043 *datatype
= GL_SHORT
;
1046 case MESA_FORMAT_RGBA_SNORM16
:
1047 *datatype
= GL_SHORT
;
1051 case MESA_FORMAT_BGR_SRGB8
:
1052 *datatype
= GL_UNSIGNED_BYTE
;
1055 case MESA_FORMAT_A8B8G8R8_SRGB
:
1056 case MESA_FORMAT_B8G8R8A8_SRGB
:
1057 case MESA_FORMAT_A8R8G8B8_SRGB
:
1058 case MESA_FORMAT_R8G8B8A8_SRGB
:
1059 *datatype
= GL_UNSIGNED_BYTE
;
1062 case MESA_FORMAT_L_SRGB8
:
1063 *datatype
= GL_UNSIGNED_BYTE
;
1066 case MESA_FORMAT_L8A8_SRGB
:
1067 case MESA_FORMAT_A8L8_SRGB
:
1068 *datatype
= GL_UNSIGNED_BYTE
;
1072 case MESA_FORMAT_RGBA_FLOAT32
:
1073 *datatype
= GL_FLOAT
;
1076 case MESA_FORMAT_RGBA_FLOAT16
:
1077 *datatype
= GL_HALF_FLOAT_ARB
;
1080 case MESA_FORMAT_RGB_FLOAT32
:
1081 *datatype
= GL_FLOAT
;
1084 case MESA_FORMAT_RGB_FLOAT16
:
1085 *datatype
= GL_HALF_FLOAT_ARB
;
1088 case MESA_FORMAT_LA_FLOAT32
:
1089 case MESA_FORMAT_RG_FLOAT32
:
1090 *datatype
= GL_FLOAT
;
1093 case MESA_FORMAT_LA_FLOAT16
:
1094 case MESA_FORMAT_RG_FLOAT16
:
1095 *datatype
= GL_HALF_FLOAT_ARB
;
1098 case MESA_FORMAT_A_FLOAT32
:
1099 case MESA_FORMAT_L_FLOAT32
:
1100 case MESA_FORMAT_I_FLOAT32
:
1101 case MESA_FORMAT_R_FLOAT32
:
1102 *datatype
= GL_FLOAT
;
1105 case MESA_FORMAT_A_FLOAT16
:
1106 case MESA_FORMAT_L_FLOAT16
:
1107 case MESA_FORMAT_I_FLOAT16
:
1108 case MESA_FORMAT_R_FLOAT16
:
1109 *datatype
= GL_HALF_FLOAT_ARB
;
1113 case MESA_FORMAT_A_UINT8
:
1114 case MESA_FORMAT_L_UINT8
:
1115 case MESA_FORMAT_I_UINT8
:
1116 *datatype
= GL_UNSIGNED_BYTE
;
1119 case MESA_FORMAT_LA_UINT8
:
1120 *datatype
= GL_UNSIGNED_BYTE
;
1124 case MESA_FORMAT_A_UINT16
:
1125 case MESA_FORMAT_L_UINT16
:
1126 case MESA_FORMAT_I_UINT16
:
1127 *datatype
= GL_UNSIGNED_SHORT
;
1130 case MESA_FORMAT_LA_UINT16
:
1131 *datatype
= GL_UNSIGNED_SHORT
;
1134 case MESA_FORMAT_A_UINT32
:
1135 case MESA_FORMAT_L_UINT32
:
1136 case MESA_FORMAT_I_UINT32
:
1137 *datatype
= GL_UNSIGNED_INT
;
1140 case MESA_FORMAT_LA_UINT32
:
1141 *datatype
= GL_UNSIGNED_INT
;
1144 case MESA_FORMAT_A_SINT8
:
1145 case MESA_FORMAT_L_SINT8
:
1146 case MESA_FORMAT_I_SINT8
:
1147 *datatype
= GL_BYTE
;
1150 case MESA_FORMAT_LA_SINT8
:
1151 *datatype
= GL_BYTE
;
1155 case MESA_FORMAT_A_SINT16
:
1156 case MESA_FORMAT_L_SINT16
:
1157 case MESA_FORMAT_I_SINT16
:
1158 *datatype
= GL_SHORT
;
1161 case MESA_FORMAT_LA_SINT16
:
1162 *datatype
= GL_SHORT
;
1166 case MESA_FORMAT_A_SINT32
:
1167 case MESA_FORMAT_L_SINT32
:
1168 case MESA_FORMAT_I_SINT32
:
1172 case MESA_FORMAT_LA_SINT32
:
1177 case MESA_FORMAT_R_SINT8
:
1178 *datatype
= GL_BYTE
;
1181 case MESA_FORMAT_RG_SINT8
:
1182 *datatype
= GL_BYTE
;
1185 case MESA_FORMAT_RGB_SINT8
:
1186 *datatype
= GL_BYTE
;
1189 case MESA_FORMAT_RGBA_SINT8
:
1190 *datatype
= GL_BYTE
;
1193 case MESA_FORMAT_R_SINT16
:
1194 *datatype
= GL_SHORT
;
1197 case MESA_FORMAT_RG_SINT16
:
1198 *datatype
= GL_SHORT
;
1201 case MESA_FORMAT_RGB_SINT16
:
1202 *datatype
= GL_SHORT
;
1205 case MESA_FORMAT_RGBA_SINT16
:
1206 *datatype
= GL_SHORT
;
1209 case MESA_FORMAT_R_SINT32
:
1213 case MESA_FORMAT_RG_SINT32
:
1217 case MESA_FORMAT_RGB_SINT32
:
1221 case MESA_FORMAT_RGBA_SINT32
:
1227 * \name Non-normalized unsigned integer formats.
1229 case MESA_FORMAT_R_UINT8
:
1230 *datatype
= GL_UNSIGNED_BYTE
;
1233 case MESA_FORMAT_RG_UINT8
:
1234 *datatype
= GL_UNSIGNED_BYTE
;
1237 case MESA_FORMAT_RGB_UINT8
:
1238 *datatype
= GL_UNSIGNED_BYTE
;
1241 case MESA_FORMAT_RGBA_UINT8
:
1242 *datatype
= GL_UNSIGNED_BYTE
;
1245 case MESA_FORMAT_R_UINT16
:
1246 *datatype
= GL_UNSIGNED_SHORT
;
1249 case MESA_FORMAT_RG_UINT16
:
1250 *datatype
= GL_UNSIGNED_SHORT
;
1253 case MESA_FORMAT_RGB_UINT16
:
1254 *datatype
= GL_UNSIGNED_SHORT
;
1257 case MESA_FORMAT_RGBA_UINT16
:
1258 *datatype
= GL_UNSIGNED_SHORT
;
1261 case MESA_FORMAT_R_UINT32
:
1262 *datatype
= GL_UNSIGNED_INT
;
1265 case MESA_FORMAT_RG_UINT32
:
1266 *datatype
= GL_UNSIGNED_INT
;
1269 case MESA_FORMAT_RGB_UINT32
:
1270 *datatype
= GL_UNSIGNED_INT
;
1273 case MESA_FORMAT_RGBA_UINT32
:
1274 *datatype
= GL_UNSIGNED_INT
;
1278 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1279 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1283 case MESA_FORMAT_R11G11B10_FLOAT
:
1284 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1288 case MESA_FORMAT_B10G10R10A2_UINT
:
1289 case MESA_FORMAT_R10G10B10A2_UINT
:
1290 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1294 case MESA_FORMAT_R8G8B8X8_SRGB
:
1295 case MESA_FORMAT_X8B8G8R8_SRGB
:
1296 case MESA_FORMAT_RGBX_UINT8
:
1297 *datatype
= GL_UNSIGNED_BYTE
;
1301 case MESA_FORMAT_R8G8B8X8_SNORM
:
1302 case MESA_FORMAT_RGBX_SINT8
:
1303 *datatype
= GL_BYTE
;
1307 case MESA_FORMAT_B10G10R10X2_UNORM
:
1308 case MESA_FORMAT_R10G10B10X2_UNORM
:
1309 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1313 case MESA_FORMAT_RGBX_UNORM16
:
1314 case MESA_FORMAT_RGBX_UINT16
:
1315 *datatype
= GL_UNSIGNED_SHORT
;
1319 case MESA_FORMAT_RGBX_SNORM16
:
1320 case MESA_FORMAT_RGBX_SINT16
:
1321 *datatype
= GL_SHORT
;
1325 case MESA_FORMAT_RGBX_FLOAT16
:
1326 *datatype
= GL_HALF_FLOAT
;
1330 case MESA_FORMAT_RGBX_FLOAT32
:
1331 *datatype
= GL_FLOAT
;
1335 case MESA_FORMAT_RGBX_UINT32
:
1336 *datatype
= GL_UNSIGNED_INT
;
1340 case MESA_FORMAT_RGBX_SINT32
:
1345 case MESA_FORMAT_R10G10B10A2_UNORM
:
1346 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1350 case MESA_FORMAT_G8R8_SNORM
:
1351 *datatype
= GL_BYTE
;
1355 case MESA_FORMAT_G16R16_SNORM
:
1356 *datatype
= GL_SHORT
;
1360 case MESA_FORMAT_B8G8R8X8_SRGB
:
1361 case MESA_FORMAT_X8R8G8B8_SRGB
:
1362 *datatype
= GL_UNSIGNED_BYTE
;
1366 case MESA_FORMAT_COUNT
:
1370 /* Warn if any formats are not handled */
1371 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1372 _mesa_get_format_name(format
));
1373 assert(format
== MESA_FORMAT_NONE
||
1374 _mesa_is_format_compressed(format
));
1381 * Check if a mesa_format exactly matches a GL format/type combination
1382 * such that we can use memcpy() from one to the other.
1383 * \param mesa_format a MESA_FORMAT_x value
1384 * \param format the user-specified image format
1385 * \param type the user-specified image datatype
1386 * \param swapBytes typically the current pixel pack/unpack byteswap state
1387 * \param[out] error GL_NO_ERROR if format is an expected input.
1388 * GL_INVALID_ENUM if format is an unexpected input.
1389 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1392 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1393 GLenum format
, GLenum type
,
1394 GLboolean swapBytes
, GLenum
*error
)
1396 const GLboolean littleEndian
= _mesa_little_endian();
1398 *error
= GL_NO_ERROR
;
1400 /* Note: When reading a GL format/type combination, the format lists channel
1401 * assignments from most significant channel in the type to least
1402 * significant. A type with _REV indicates that the assignments are
1403 * swapped, so they are listed from least significant to most significant.
1405 * Compressed formats will fall through and return GL_FALSE.
1407 * For sanity, please keep this switch statement ordered the same as the
1408 * enums in formats.h.
1411 switch (mesa_format
) {
1413 case MESA_FORMAT_NONE
:
1414 case MESA_FORMAT_COUNT
:
1417 case MESA_FORMAT_A8B8G8R8_UNORM
:
1418 case MESA_FORMAT_A8B8G8R8_SRGB
:
1419 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1422 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1425 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1428 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1432 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1436 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1441 case MESA_FORMAT_R8G8B8A8_UNORM
:
1442 case MESA_FORMAT_R8G8B8A8_SRGB
:
1443 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1447 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1450 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1453 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1457 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1461 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1466 case MESA_FORMAT_B8G8R8A8_UNORM
:
1467 case MESA_FORMAT_B8G8R8A8_SRGB
:
1468 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1472 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1475 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1480 case MESA_FORMAT_A8R8G8B8_UNORM
:
1481 case MESA_FORMAT_A8R8G8B8_SRGB
:
1482 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1485 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1489 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1494 case MESA_FORMAT_X8B8G8R8_UNORM
:
1495 case MESA_FORMAT_R8G8B8X8_UNORM
:
1498 case MESA_FORMAT_B8G8R8X8_UNORM
:
1499 case MESA_FORMAT_X8R8G8B8_UNORM
:
1502 case MESA_FORMAT_BGR_UNORM8
:
1503 case MESA_FORMAT_BGR_SRGB8
:
1504 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1506 case MESA_FORMAT_RGB_UNORM8
:
1507 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1509 case MESA_FORMAT_B5G6R5_UNORM
:
1510 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1511 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1514 case MESA_FORMAT_R5G6B5_UNORM
:
1515 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1516 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1519 case MESA_FORMAT_B4G4R4A4_UNORM
:
1520 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1523 case MESA_FORMAT_A4R4G4B4_UNORM
:
1526 case MESA_FORMAT_A1B5G5R5_UNORM
:
1527 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1530 case MESA_FORMAT_X1B5G5R5_UNORM
:
1531 return format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1534 case MESA_FORMAT_B5G5R5A1_UNORM
:
1535 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1538 case MESA_FORMAT_A1R5G5B5_UNORM
:
1539 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1542 case MESA_FORMAT_L4A4_UNORM
:
1544 case MESA_FORMAT_L8A8_UNORM
:
1545 case MESA_FORMAT_L8A8_SRGB
:
1546 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1547 case MESA_FORMAT_A8L8_UNORM
:
1548 case MESA_FORMAT_A8L8_SRGB
:
1551 case MESA_FORMAT_L16A16_UNORM
:
1552 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1553 case MESA_FORMAT_A16L16_UNORM
:
1556 case MESA_FORMAT_B2G3R3_UNORM
:
1557 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1559 case MESA_FORMAT_R3G3B2_UNORM
:
1560 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1562 case MESA_FORMAT_A4B4G4R4_UNORM
:
1563 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1566 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1569 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1572 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1577 case MESA_FORMAT_R4G4B4A4_UNORM
:
1578 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1581 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1584 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1587 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1592 case MESA_FORMAT_R5G5B5A1_UNORM
:
1593 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1595 case MESA_FORMAT_A2B10G10R10_UNORM
:
1596 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1598 case MESA_FORMAT_A2B10G10R10_UINT
:
1599 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1601 case MESA_FORMAT_A2R10G10B10_UNORM
:
1602 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1604 case MESA_FORMAT_A2R10G10B10_UINT
:
1605 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1607 case MESA_FORMAT_A_UNORM8
:
1608 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1609 case MESA_FORMAT_A_UNORM16
:
1610 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1611 case MESA_FORMAT_L_UNORM8
:
1612 case MESA_FORMAT_L_SRGB8
:
1613 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1614 case MESA_FORMAT_L_UNORM16
:
1615 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1616 case MESA_FORMAT_I_UNORM8
:
1617 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1618 case MESA_FORMAT_I_UNORM16
:
1619 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1621 case MESA_FORMAT_YCBCR
:
1622 return format
== GL_YCBCR_MESA
&&
1623 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1624 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1625 case MESA_FORMAT_YCBCR_REV
:
1626 return format
== GL_YCBCR_MESA
&&
1627 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1628 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1630 case MESA_FORMAT_R_UNORM8
:
1631 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1632 case MESA_FORMAT_R8G8_UNORM
:
1633 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1634 case MESA_FORMAT_G8R8_UNORM
:
1637 case MESA_FORMAT_R_UNORM16
:
1638 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1640 case MESA_FORMAT_R16G16_UNORM
:
1641 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1643 case MESA_FORMAT_G16R16_UNORM
:
1646 case MESA_FORMAT_B10G10R10A2_UNORM
:
1647 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1650 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1651 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1653 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1654 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1657 case MESA_FORMAT_Z_UNORM16
:
1658 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1661 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1664 case MESA_FORMAT_Z_UNORM32
:
1665 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1668 case MESA_FORMAT_S_UINT8
:
1669 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1671 case MESA_FORMAT_RGBA_FLOAT32
:
1672 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1673 case MESA_FORMAT_RGBA_FLOAT16
:
1674 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1676 case MESA_FORMAT_RGB_FLOAT32
:
1677 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1678 case MESA_FORMAT_RGB_FLOAT16
:
1679 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1681 case MESA_FORMAT_A_FLOAT32
:
1682 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1683 case MESA_FORMAT_A_FLOAT16
:
1684 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1686 case MESA_FORMAT_L_FLOAT32
:
1687 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1688 case MESA_FORMAT_L_FLOAT16
:
1689 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1691 case MESA_FORMAT_LA_FLOAT32
:
1692 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1693 case MESA_FORMAT_LA_FLOAT16
:
1694 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1696 case MESA_FORMAT_I_FLOAT32
:
1697 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1698 case MESA_FORMAT_I_FLOAT16
:
1699 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1701 case MESA_FORMAT_R_FLOAT32
:
1702 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1703 case MESA_FORMAT_R_FLOAT16
:
1704 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1706 case MESA_FORMAT_RG_FLOAT32
:
1707 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1708 case MESA_FORMAT_RG_FLOAT16
:
1709 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1711 case MESA_FORMAT_A_UINT8
:
1712 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1713 case MESA_FORMAT_A_UINT16
:
1714 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1716 case MESA_FORMAT_A_UINT32
:
1717 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1719 case MESA_FORMAT_A_SINT8
:
1720 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1721 case MESA_FORMAT_A_SINT16
:
1722 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1723 case MESA_FORMAT_A_SINT32
:
1724 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1726 case MESA_FORMAT_I_UINT8
:
1727 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1728 case MESA_FORMAT_I_UINT16
:
1729 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1730 case MESA_FORMAT_I_UINT32
:
1731 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1732 case MESA_FORMAT_I_SINT8
:
1733 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1734 case MESA_FORMAT_I_SINT16
:
1735 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1736 case MESA_FORMAT_I_SINT32
:
1737 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1739 case MESA_FORMAT_L_UINT8
:
1740 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1741 case MESA_FORMAT_L_UINT16
:
1742 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1744 case MESA_FORMAT_L_UINT32
:
1745 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1747 case MESA_FORMAT_L_SINT8
:
1748 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1749 case MESA_FORMAT_L_SINT16
:
1750 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1752 case MESA_FORMAT_L_SINT32
:
1753 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1755 case MESA_FORMAT_LA_UINT8
:
1756 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1757 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1758 case MESA_FORMAT_LA_UINT16
:
1759 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1760 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1761 case MESA_FORMAT_LA_UINT32
:
1762 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1763 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1764 case MESA_FORMAT_LA_SINT8
:
1765 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1767 case MESA_FORMAT_LA_SINT16
:
1768 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1770 case MESA_FORMAT_LA_SINT32
:
1771 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1774 case MESA_FORMAT_R_SINT8
:
1775 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1776 case MESA_FORMAT_RG_SINT8
:
1777 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1778 case MESA_FORMAT_RGB_SINT8
:
1779 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1780 case MESA_FORMAT_RGBA_SINT8
:
1781 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1782 case MESA_FORMAT_R_SINT16
:
1783 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1784 case MESA_FORMAT_RG_SINT16
:
1785 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1786 case MESA_FORMAT_RGB_SINT16
:
1787 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1788 case MESA_FORMAT_RGBA_SINT16
:
1789 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1790 case MESA_FORMAT_R_SINT32
:
1791 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1792 case MESA_FORMAT_RG_SINT32
:
1793 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1794 case MESA_FORMAT_RGB_SINT32
:
1795 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1796 case MESA_FORMAT_RGBA_SINT32
:
1797 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1799 case MESA_FORMAT_R_UINT8
:
1800 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1801 case MESA_FORMAT_RG_UINT8
:
1802 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1803 case MESA_FORMAT_RGB_UINT8
:
1804 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1805 case MESA_FORMAT_RGBA_UINT8
:
1806 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1808 case MESA_FORMAT_R_UINT16
:
1809 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1811 case MESA_FORMAT_RG_UINT16
:
1812 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1813 case MESA_FORMAT_RGB_UINT16
:
1814 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1816 case MESA_FORMAT_RGBA_UINT16
:
1817 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1819 case MESA_FORMAT_R_UINT32
:
1820 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1821 case MESA_FORMAT_RG_UINT32
:
1822 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1823 case MESA_FORMAT_RGB_UINT32
:
1824 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1825 case MESA_FORMAT_RGBA_UINT32
:
1826 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1828 case MESA_FORMAT_R_SNORM8
:
1829 return format
== GL_RED
&& type
== GL_BYTE
;
1830 case MESA_FORMAT_R8G8_SNORM
:
1831 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1833 case MESA_FORMAT_X8B8G8R8_SNORM
:
1836 case MESA_FORMAT_A8B8G8R8_SNORM
:
1837 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1840 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1845 case MESA_FORMAT_R8G8B8A8_SNORM
:
1846 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1849 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1854 case MESA_FORMAT_R_SNORM16
:
1855 return format
== GL_RED
&& type
== GL_SHORT
&&
1857 case MESA_FORMAT_R16G16_SNORM
:
1858 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1859 case MESA_FORMAT_RGB_SNORM16
:
1860 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1861 case MESA_FORMAT_RGBA_SNORM16
:
1862 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1863 case MESA_FORMAT_RGBA_UNORM16
:
1864 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1867 case MESA_FORMAT_A_SNORM8
:
1868 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1869 case MESA_FORMAT_L_SNORM8
:
1870 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1871 case MESA_FORMAT_L8A8_SNORM
:
1872 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1873 littleEndian
&& !swapBytes
;
1874 case MESA_FORMAT_A8L8_SNORM
:
1875 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1876 !littleEndian
&& !swapBytes
;
1877 case MESA_FORMAT_I_SNORM8
:
1878 return format
== GL_RED
&& type
== GL_BYTE
;
1879 case MESA_FORMAT_A_SNORM16
:
1880 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1881 case MESA_FORMAT_L_SNORM16
:
1882 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1883 case MESA_FORMAT_LA_SNORM16
:
1884 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1885 littleEndian
&& !swapBytes
;
1886 case MESA_FORMAT_I_SNORM16
:
1887 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1890 case MESA_FORMAT_B10G10R10A2_UINT
:
1891 return (format
== GL_BGRA_INTEGER_EXT
&&
1892 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1895 case MESA_FORMAT_R10G10B10A2_UINT
:
1896 return (format
== GL_RGBA_INTEGER_EXT
&&
1897 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1900 case MESA_FORMAT_B5G6R5_UINT
:
1901 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1903 case MESA_FORMAT_R5G6B5_UINT
:
1904 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1906 case MESA_FORMAT_B2G3R3_UINT
:
1907 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1909 case MESA_FORMAT_R3G3B2_UINT
:
1910 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1912 case MESA_FORMAT_A4B4G4R4_UINT
:
1913 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1916 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1920 case MESA_FORMAT_R4G4B4A4_UINT
:
1921 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1924 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1929 case MESA_FORMAT_B4G4R4A4_UINT
:
1930 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1933 case MESA_FORMAT_A4R4G4B4_UINT
:
1936 case MESA_FORMAT_A1B5G5R5_UINT
:
1937 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1940 case MESA_FORMAT_B5G5R5A1_UINT
:
1941 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1944 case MESA_FORMAT_A1R5G5B5_UINT
:
1945 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1948 case MESA_FORMAT_R5G5B5A1_UINT
:
1949 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1951 case MESA_FORMAT_A8B8G8R8_UINT
:
1952 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1955 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1959 case MESA_FORMAT_A8R8G8B8_UINT
:
1960 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1964 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1970 case MESA_FORMAT_R8G8B8A8_UINT
:
1971 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1975 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1980 case MESA_FORMAT_B8G8R8A8_UINT
:
1981 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1985 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1990 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1991 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
1994 case MESA_FORMAT_R11G11B10_FLOAT
:
1995 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
1998 case MESA_FORMAT_Z_FLOAT32
:
1999 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2001 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2002 return format
== GL_DEPTH_STENCIL
&&
2003 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2005 case MESA_FORMAT_B4G4R4X4_UNORM
:
2006 case MESA_FORMAT_B5G5R5X1_UNORM
:
2007 case MESA_FORMAT_R8G8B8X8_SNORM
:
2008 case MESA_FORMAT_R8G8B8X8_SRGB
:
2009 case MESA_FORMAT_X8B8G8R8_SRGB
:
2010 case MESA_FORMAT_RGBX_UINT8
:
2011 case MESA_FORMAT_RGBX_SINT8
:
2012 case MESA_FORMAT_B10G10R10X2_UNORM
:
2013 case MESA_FORMAT_RGBX_UNORM16
:
2014 case MESA_FORMAT_RGBX_SNORM16
:
2015 case MESA_FORMAT_RGBX_FLOAT16
:
2016 case MESA_FORMAT_RGBX_UINT16
:
2017 case MESA_FORMAT_RGBX_SINT16
:
2018 case MESA_FORMAT_RGBX_FLOAT32
:
2019 case MESA_FORMAT_RGBX_UINT32
:
2020 case MESA_FORMAT_RGBX_SINT32
:
2023 case MESA_FORMAT_R10G10B10X2_UNORM
:
2024 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2026 case MESA_FORMAT_R10G10B10A2_UNORM
:
2027 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2030 case MESA_FORMAT_G8R8_SNORM
:
2031 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2034 case MESA_FORMAT_G16R16_SNORM
:
2035 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2038 case MESA_FORMAT_B8G8R8X8_SRGB
:
2039 case MESA_FORMAT_X8R8G8B8_SRGB
:
2042 assert(_mesa_is_format_compressed(mesa_format
));
2044 *error
= GL_INVALID_ENUM
;