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 if (_mesa_format_is_mesa_array_format(format
)) {
113 return _mesa_array_format_get_type_size(format
) *
114 _mesa_array_format_get_num_channels(format
);
117 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
118 assert(info
->BytesPerBlock
);
119 assert(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
120 _mesa_is_format_compressed(format
));
121 return info
->BytesPerBlock
;
126 * Return bits per component for the given format.
127 * \param format one of MESA_FORMAT_x
128 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
131 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
133 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
137 case GL_TEXTURE_RED_SIZE
:
138 case GL_RENDERBUFFER_RED_SIZE_EXT
:
139 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
140 case GL_INTERNALFORMAT_RED_SIZE
:
141 return info
->RedBits
;
143 case GL_TEXTURE_GREEN_SIZE
:
144 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
145 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
146 case GL_INTERNALFORMAT_GREEN_SIZE
:
147 return info
->GreenBits
;
149 case GL_TEXTURE_BLUE_SIZE
:
150 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
151 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
152 case GL_INTERNALFORMAT_BLUE_SIZE
:
153 return info
->BlueBits
;
155 case GL_TEXTURE_ALPHA_SIZE
:
156 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
157 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
158 case GL_INTERNALFORMAT_ALPHA_SIZE
:
159 return info
->AlphaBits
;
160 case GL_TEXTURE_INTENSITY_SIZE
:
161 return info
->IntensityBits
;
162 case GL_TEXTURE_LUMINANCE_SIZE
:
163 return info
->LuminanceBits
;
167 case GL_TEXTURE_DEPTH_SIZE_ARB
:
168 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
169 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
170 case GL_INTERNALFORMAT_DEPTH_SIZE
:
171 return info
->DepthBits
;
172 case GL_STENCIL_BITS
:
173 case GL_TEXTURE_STENCIL_SIZE_EXT
:
174 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
175 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
176 case GL_INTERNALFORMAT_STENCIL_SIZE
:
177 return info
->StencilBits
;
179 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
186 _mesa_get_format_max_bits(mesa_format format
)
188 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
189 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
190 max
= MAX2(max
, info
->BlueBits
);
191 max
= MAX2(max
, info
->AlphaBits
);
192 max
= MAX2(max
, info
->LuminanceBits
);
193 max
= MAX2(max
, info
->IntensityBits
);
194 max
= MAX2(max
, info
->DepthBits
);
195 max
= MAX2(max
, info
->StencilBits
);
201 * Return the layout type of the given format.
203 extern enum mesa_format_layout
204 _mesa_get_format_layout(mesa_format format
)
206 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
212 * Return the data type (or more specifically, the data representation)
213 * for the given format.
214 * The return value will be one of:
215 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
216 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
217 * GL_UNSIGNED_INT = an ordinary unsigned integer
218 * GL_INT = an ordinary signed integer
219 * GL_FLOAT = an ordinary float
222 _mesa_get_format_datatype(mesa_format format
)
224 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
225 return info
->DataType
;
229 get_base_format_for_array_format(mesa_array_format format
)
234 _mesa_array_format_get_swizzle(format
, swizzle
);
235 num_channels
= _mesa_array_format_get_num_channels(format
);
237 switch (num_channels
) {
239 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
240 * This is not really a problem for now because we only create array
241 * formats from GL format/type combinations, and these cannot specify
248 if (swizzle
[0] == 0 &&
252 return GL_LUMINANCE_ALPHA
;
253 if (swizzle
[0] == 1 &&
257 return GL_LUMINANCE_ALPHA
;
258 if (swizzle
[0] == 0 &&
263 if (swizzle
[0] == 1 &&
270 if (swizzle
[0] == 0 &&
275 if (swizzle
[0] == 0 &&
280 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
282 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
284 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
286 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
291 unreachable("Unsupported format");
295 * Return the basic format for the given type. The result will be one of
296 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
297 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
298 * This functions accepts a mesa_format or a mesa_array_format.
301 _mesa_get_format_base_format(uint32_t format
)
303 if (!_mesa_format_is_mesa_array_format(format
)) {
304 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
305 return info
->BaseFormat
;
307 return get_base_format_for_array_format(format
);
313 * Return the block size (in pixels) for the given format. Normally
314 * the block size is 1x1. But compressed formats will have block sizes
315 * of 4x4 or 8x4 pixels, etc.
316 * \param bw returns block width in pixels
317 * \param bh returns block height in pixels
320 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
322 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
323 /* Use _mesa_get_format_block_size_3d() for 3D blocks. */
324 assert(info
->BlockDepth
== 1);
326 *bw
= info
->BlockWidth
;
327 *bh
= info
->BlockHeight
;
332 * Return the block size (in pixels) for the given format. Normally
333 * the block size is 1x1x1. But compressed formats will have block
334 * sizes of 4x4x4, 3x3x3 pixels, etc.
335 * \param bw returns block width in pixels
336 * \param bh returns block height in pixels
337 * \param bd returns block depth in pixels
340 _mesa_get_format_block_size_3d(mesa_format format
,
345 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
346 *bw
= info
->BlockWidth
;
347 *bh
= info
->BlockHeight
;
348 *bd
= info
->BlockDepth
;
353 * Returns the an array of four numbers representing the transformation
354 * from the RGBA or SZ colorspace to the given format. For array formats,
355 * the i'th RGBA component is given by:
357 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
358 * comp = data[swizzle[i]];
359 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
361 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
363 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
364 * // data does not contain a channel of this format
366 * For packed formats, the swizzle gives the number of components left of
367 * the least significant bit.
369 * Compressed formats have no swizzle.
372 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
374 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
375 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
379 _mesa_array_format_flip_channels(mesa_array_format format
)
384 num_channels
= _mesa_array_format_get_num_channels(format
);
385 _mesa_array_format_get_swizzle(format
, swizzle
);
387 if (num_channels
== 1)
390 if (num_channels
== 2) {
391 /* Assert that the swizzle makes sense for 2 channels */
392 for (unsigned i
= 0; i
< 4; i
++)
393 assert(swizzle
[i
] != 2 && swizzle
[i
] != 3);
395 static const uint8_t flip_xy
[6] = { 1, 0, 2, 3, 4, 5 };
396 _mesa_array_format_set_swizzle(&format
,
397 flip_xy
[swizzle
[0]], flip_xy
[swizzle
[1]],
398 flip_xy
[swizzle
[2]], flip_xy
[swizzle
[3]]);
402 if (num_channels
== 4) {
403 static const uint8_t flip
[6] = { 3, 2, 1, 0, 4, 5 };
404 _mesa_array_format_set_swizzle(&format
,
405 flip
[swizzle
[0]], flip
[swizzle
[1]],
406 flip
[swizzle
[2]], flip
[swizzle
[3]]);
410 unreachable("Invalid array format");
414 _mesa_format_to_array_format(mesa_format format
)
416 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
417 if (info
->ArrayFormat
&& !_mesa_little_endian() &&
418 info
->Layout
== MESA_FORMAT_LAYOUT_PACKED
)
419 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
421 return info
->ArrayFormat
;
424 static struct hash_table
*format_array_format_table
;
425 static once_flag format_array_format_table_exists
= ONCE_FLAG_INIT
;
428 array_formats_equal(const void *a
, const void *b
)
430 return (intptr_t)a
== (intptr_t)b
;
434 format_array_format_table_init(void)
436 const struct gl_format_info
*info
;
437 mesa_array_format array_format
;
440 format_array_format_table
= _mesa_hash_table_create(NULL
, NULL
,
441 array_formats_equal
);
443 if (!format_array_format_table
) {
444 _mesa_error_no_memory(__func__
);
448 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
) {
449 info
= _mesa_get_format_info(f
);
450 if (!info
->ArrayFormat
)
453 if (_mesa_little_endian()) {
454 array_format
= info
->ArrayFormat
;
456 array_format
= _mesa_array_format_flip_channels(info
->ArrayFormat
);
459 /* This can happen and does for some of the BGR formats. Let's take
460 * the first one in the list.
462 if (_mesa_hash_table_search_pre_hashed(format_array_format_table
,
464 (void *)(intptr_t)array_format
))
467 _mesa_hash_table_insert_pre_hashed(format_array_format_table
,
469 (void *)(intptr_t)array_format
,
470 (void *)(intptr_t)f
);
475 _mesa_format_from_array_format(uint32_t array_format
)
477 struct hash_entry
*entry
;
479 assert(_mesa_format_is_mesa_array_format(array_format
));
481 call_once(&format_array_format_table_exists
, format_array_format_table_init
);
483 if (!format_array_format_table
) {
484 static const once_flag once_flag_init
= ONCE_FLAG_INIT
;
485 format_array_format_table_exists
= once_flag_init
;
486 return MESA_FORMAT_NONE
;
489 entry
= _mesa_hash_table_search_pre_hashed(format_array_format_table
,
491 (void *)(intptr_t)array_format
);
493 return (intptr_t)entry
->data
;
495 return MESA_FORMAT_NONE
;
498 /** Is the given format a compressed format? */
500 _mesa_is_format_compressed(mesa_format format
)
502 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
503 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
508 * Determine if the given format represents a packed depth/stencil buffer.
511 _mesa_is_format_packed_depth_stencil(mesa_format format
)
513 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
515 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
520 * Is the given format a signed/unsigned integer color format?
523 _mesa_is_format_integer_color(mesa_format format
)
525 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
526 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
527 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
528 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
529 info
->BaseFormat
!= GL_STENCIL_INDEX
;
534 * Is the given format an unsigned integer format?
537 _mesa_is_format_unsigned(mesa_format format
)
539 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
540 return _mesa_is_type_unsigned(info
->DataType
);
545 * Does the given format store signed values?
548 _mesa_is_format_signed(mesa_format format
)
550 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
551 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
552 /* these packed float formats only store unsigned values */
556 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
557 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
558 info
->DataType
== GL_INT
||
559 info
->DataType
== GL_FLOAT
);
564 * Is the given format an integer format?
567 _mesa_is_format_integer(mesa_format format
)
569 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
570 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
575 * Return true if the given format is a color format.
578 _mesa_is_format_color_format(mesa_format format
)
580 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
581 switch (info
->BaseFormat
) {
582 case GL_DEPTH_COMPONENT
:
583 case GL_STENCIL_INDEX
:
584 case GL_DEPTH_STENCIL
:
593 * Return color encoding for given format.
594 * \return GL_LINEAR or GL_SRGB
597 _mesa_get_format_color_encoding(mesa_format format
)
599 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
600 return info
->IsSRGBFormat
? GL_SRGB
: GL_LINEAR
;
605 * Return TRUE if format is an ETC2 compressed format specified
606 * by GL_ARB_ES3_compatibility.
609 _mesa_is_format_etc2(mesa_format format
)
612 case MESA_FORMAT_ETC2_RGB8
:
613 case MESA_FORMAT_ETC2_SRGB8
:
614 case MESA_FORMAT_ETC2_RGBA8_EAC
:
615 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
616 case MESA_FORMAT_ETC2_R11_EAC
:
617 case MESA_FORMAT_ETC2_RG11_EAC
:
618 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
619 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
620 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
621 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
630 * If the given format is a compressed format, return a corresponding
631 * uncompressed format.
634 _mesa_get_uncompressed_format(mesa_format format
)
637 case MESA_FORMAT_RGB_FXT1
:
638 return MESA_FORMAT_BGR_UNORM8
;
639 case MESA_FORMAT_RGBA_FXT1
:
640 return MESA_FORMAT_A8B8G8R8_UNORM
;
641 case MESA_FORMAT_RGB_DXT1
:
642 case MESA_FORMAT_SRGB_DXT1
:
643 return MESA_FORMAT_BGR_UNORM8
;
644 case MESA_FORMAT_RGBA_DXT1
:
645 case MESA_FORMAT_SRGBA_DXT1
:
646 return MESA_FORMAT_A8B8G8R8_UNORM
;
647 case MESA_FORMAT_RGBA_DXT3
:
648 case MESA_FORMAT_SRGBA_DXT3
:
649 return MESA_FORMAT_A8B8G8R8_UNORM
;
650 case MESA_FORMAT_RGBA_DXT5
:
651 case MESA_FORMAT_SRGBA_DXT5
:
652 return MESA_FORMAT_A8B8G8R8_UNORM
;
653 case MESA_FORMAT_R_RGTC1_UNORM
:
654 return MESA_FORMAT_R_UNORM8
;
655 case MESA_FORMAT_R_RGTC1_SNORM
:
656 return MESA_FORMAT_R_SNORM8
;
657 case MESA_FORMAT_RG_RGTC2_UNORM
:
658 return MESA_FORMAT_R8G8_UNORM
;
659 case MESA_FORMAT_RG_RGTC2_SNORM
:
660 return MESA_FORMAT_R8G8_SNORM
;
661 case MESA_FORMAT_L_LATC1_UNORM
:
662 return MESA_FORMAT_L_UNORM8
;
663 case MESA_FORMAT_L_LATC1_SNORM
:
664 return MESA_FORMAT_L_SNORM8
;
665 case MESA_FORMAT_LA_LATC2_UNORM
:
666 return MESA_FORMAT_L8A8_UNORM
;
667 case MESA_FORMAT_LA_LATC2_SNORM
:
668 return MESA_FORMAT_L8A8_SNORM
;
669 case MESA_FORMAT_ETC1_RGB8
:
670 case MESA_FORMAT_ETC2_RGB8
:
671 case MESA_FORMAT_ETC2_SRGB8
:
672 return MESA_FORMAT_BGR_UNORM8
;
673 case MESA_FORMAT_ETC2_RGBA8_EAC
:
674 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
675 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
676 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
677 return MESA_FORMAT_A8B8G8R8_UNORM
;
678 case MESA_FORMAT_ETC2_R11_EAC
:
679 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
680 return MESA_FORMAT_R_UNORM16
;
681 case MESA_FORMAT_ETC2_RG11_EAC
:
682 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
683 return MESA_FORMAT_R16G16_UNORM
;
684 case MESA_FORMAT_BPTC_RGBA_UNORM
:
685 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
686 return MESA_FORMAT_A8B8G8R8_UNORM
;
687 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
688 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
689 return MESA_FORMAT_RGB_FLOAT32
;
692 assert(!_mesa_is_format_compressed(format
));
700 _mesa_format_num_components(mesa_format format
)
702 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
703 return ((info
->RedBits
> 0) +
704 (info
->GreenBits
> 0) +
705 (info
->BlueBits
> 0) +
706 (info
->AlphaBits
> 0) +
707 (info
->LuminanceBits
> 0) +
708 (info
->IntensityBits
> 0) +
709 (info
->DepthBits
> 0) +
710 (info
->StencilBits
> 0));
715 * Returns true if a color format has data stored in the R/G/B/A channels,
716 * given an index from 0 to 3.
719 _mesa_format_has_color_component(mesa_format format
, int component
)
721 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
723 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
724 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
725 info
->BaseFormat
!= GL_STENCIL_INDEX
);
729 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
731 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
733 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
735 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
737 assert(!"Invalid color component: must be 0..3");
744 * Return number of bytes needed to store an image of the given size
745 * in the given format.
748 _mesa_format_image_size(mesa_format format
, GLsizei width
,
749 GLsizei height
, GLsizei depth
)
751 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
753 /* Strictly speaking, a conditional isn't needed here */
754 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
755 /* compressed format (2D only for now) */
756 const GLuint bw
= info
->BlockWidth
;
757 const GLuint bh
= info
->BlockHeight
;
758 const GLuint bd
= info
->BlockDepth
;
759 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
760 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
761 const GLuint dblocks
= (depth
+ bd
- 1) / bd
;
762 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
765 sz
= width
* height
* depth
* info
->BytesPerBlock
;
772 * Same as _mesa_format_image_size() but returns a 64-bit value to
773 * accommodate very large textures.
776 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
777 GLsizei height
, GLsizei depth
)
779 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
781 /* Strictly speaking, a conditional isn't needed here */
782 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1 || info
->BlockDepth
> 1) {
783 /* compressed format (2D only for now) */
784 const uint64_t bw
= info
->BlockWidth
;
785 const uint64_t bh
= info
->BlockHeight
;
786 const uint64_t bd
= info
->BlockDepth
;
787 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
788 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
789 const uint64_t dblocks
= (depth
+ bd
- 1) / bd
;
790 sz
= wblocks
* hblocks
* dblocks
* info
->BytesPerBlock
;
793 sz
= ((uint64_t) width
* (uint64_t) height
*
794 (uint64_t) depth
* info
->BytesPerBlock
);
802 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
804 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
805 /* Strictly speaking, a conditional isn't needed here */
806 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
807 /* compressed format */
808 const GLuint bw
= info
->BlockWidth
;
809 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
810 const GLint stride
= wblocks
* info
->BytesPerBlock
;
814 const GLint stride
= width
* info
->BytesPerBlock
;
822 * Return datatype and number of components per texel for the given
823 * uncompressed mesa_format. Only used for mipmap generation code.
826 _mesa_uncompressed_format_to_type_and_comps(mesa_format format
,
827 GLenum
*datatype
, GLuint
*comps
)
830 case MESA_FORMAT_A8B8G8R8_UNORM
:
831 case MESA_FORMAT_R8G8B8A8_UNORM
:
832 case MESA_FORMAT_B8G8R8A8_UNORM
:
833 case MESA_FORMAT_A8R8G8B8_UNORM
:
834 case MESA_FORMAT_X8B8G8R8_UNORM
:
835 case MESA_FORMAT_R8G8B8X8_UNORM
:
836 case MESA_FORMAT_B8G8R8X8_UNORM
:
837 case MESA_FORMAT_X8R8G8B8_UNORM
:
838 case MESA_FORMAT_A8B8G8R8_UINT
:
839 case MESA_FORMAT_R8G8B8A8_UINT
:
840 case MESA_FORMAT_B8G8R8A8_UINT
:
841 case MESA_FORMAT_A8R8G8B8_UINT
:
842 *datatype
= GL_UNSIGNED_BYTE
;
845 case MESA_FORMAT_BGR_UNORM8
:
846 case MESA_FORMAT_RGB_UNORM8
:
847 *datatype
= GL_UNSIGNED_BYTE
;
850 case MESA_FORMAT_B5G6R5_UNORM
:
851 case MESA_FORMAT_R5G6B5_UNORM
:
852 case MESA_FORMAT_B5G6R5_UINT
:
853 case MESA_FORMAT_R5G6B5_UINT
:
854 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
858 case MESA_FORMAT_B4G4R4A4_UNORM
:
859 case MESA_FORMAT_A4R4G4B4_UNORM
:
860 case MESA_FORMAT_B4G4R4X4_UNORM
:
861 case MESA_FORMAT_B4G4R4A4_UINT
:
862 case MESA_FORMAT_A4R4G4B4_UINT
:
863 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
867 case MESA_FORMAT_B5G5R5A1_UNORM
:
868 case MESA_FORMAT_A1R5G5B5_UNORM
:
869 case MESA_FORMAT_B5G5R5X1_UNORM
:
870 case MESA_FORMAT_B5G5R5A1_UINT
:
871 case MESA_FORMAT_A1R5G5B5_UINT
:
872 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
876 case MESA_FORMAT_B10G10R10A2_UNORM
:
877 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
881 case MESA_FORMAT_A1B5G5R5_UNORM
:
882 case MESA_FORMAT_A1B5G5R5_UINT
:
883 case MESA_FORMAT_X1B5G5R5_UNORM
:
884 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
888 case MESA_FORMAT_L4A4_UNORM
:
889 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
893 case MESA_FORMAT_L8A8_UNORM
:
894 case MESA_FORMAT_A8L8_UNORM
:
895 case MESA_FORMAT_R8G8_UNORM
:
896 case MESA_FORMAT_G8R8_UNORM
:
897 *datatype
= GL_UNSIGNED_BYTE
;
901 case MESA_FORMAT_L16A16_UNORM
:
902 case MESA_FORMAT_A16L16_UNORM
:
903 case MESA_FORMAT_R16G16_UNORM
:
904 case MESA_FORMAT_G16R16_UNORM
:
905 *datatype
= GL_UNSIGNED_SHORT
;
909 case MESA_FORMAT_R_UNORM16
:
910 case MESA_FORMAT_A_UNORM16
:
911 case MESA_FORMAT_L_UNORM16
:
912 case MESA_FORMAT_I_UNORM16
:
913 *datatype
= GL_UNSIGNED_SHORT
;
917 case MESA_FORMAT_R3G3B2_UNORM
:
918 case MESA_FORMAT_R3G3B2_UINT
:
919 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
922 case MESA_FORMAT_A4B4G4R4_UNORM
:
923 case MESA_FORMAT_A4B4G4R4_UINT
:
924 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
928 case MESA_FORMAT_R4G4B4A4_UNORM
:
929 case MESA_FORMAT_R4G4B4A4_UINT
:
930 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
933 case MESA_FORMAT_R5G5B5A1_UNORM
:
934 case MESA_FORMAT_R5G5B5A1_UINT
:
935 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
938 case MESA_FORMAT_A2B10G10R10_UNORM
:
939 case MESA_FORMAT_A2B10G10R10_UINT
:
940 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
943 case MESA_FORMAT_A2R10G10B10_UNORM
:
944 case MESA_FORMAT_A2R10G10B10_UINT
:
945 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
949 case MESA_FORMAT_B2G3R3_UNORM
:
950 case MESA_FORMAT_B2G3R3_UINT
:
951 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
955 case MESA_FORMAT_A_UNORM8
:
956 case MESA_FORMAT_L_UNORM8
:
957 case MESA_FORMAT_I_UNORM8
:
958 case MESA_FORMAT_R_UNORM8
:
959 case MESA_FORMAT_S_UINT8
:
960 *datatype
= GL_UNSIGNED_BYTE
;
964 case MESA_FORMAT_YCBCR
:
965 case MESA_FORMAT_YCBCR_REV
:
966 *datatype
= GL_UNSIGNED_SHORT
;
970 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
971 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
975 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
976 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
980 case MESA_FORMAT_Z_UNORM16
:
981 *datatype
= GL_UNSIGNED_SHORT
;
985 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
986 *datatype
= GL_UNSIGNED_INT
;
990 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
991 *datatype
= GL_UNSIGNED_INT
;
995 case MESA_FORMAT_Z_UNORM32
:
996 *datatype
= GL_UNSIGNED_INT
;
1000 case MESA_FORMAT_Z_FLOAT32
:
1001 *datatype
= GL_FLOAT
;
1005 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1006 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1010 case MESA_FORMAT_R_SNORM8
:
1011 case MESA_FORMAT_A_SNORM8
:
1012 case MESA_FORMAT_L_SNORM8
:
1013 case MESA_FORMAT_I_SNORM8
:
1014 *datatype
= GL_BYTE
;
1017 case MESA_FORMAT_R8G8_SNORM
:
1018 case MESA_FORMAT_L8A8_SNORM
:
1019 case MESA_FORMAT_A8L8_SNORM
:
1020 *datatype
= GL_BYTE
;
1023 case MESA_FORMAT_A8B8G8R8_SNORM
:
1024 case MESA_FORMAT_R8G8B8A8_SNORM
:
1025 case MESA_FORMAT_X8B8G8R8_SNORM
:
1026 *datatype
= GL_BYTE
;
1030 case MESA_FORMAT_RGBA_UNORM16
:
1031 *datatype
= GL_UNSIGNED_SHORT
;
1035 case MESA_FORMAT_R_SNORM16
:
1036 case MESA_FORMAT_A_SNORM16
:
1037 case MESA_FORMAT_L_SNORM16
:
1038 case MESA_FORMAT_I_SNORM16
:
1039 *datatype
= GL_SHORT
;
1042 case MESA_FORMAT_R16G16_SNORM
:
1043 case MESA_FORMAT_LA_SNORM16
:
1044 *datatype
= GL_SHORT
;
1047 case MESA_FORMAT_RGB_SNORM16
:
1048 *datatype
= GL_SHORT
;
1051 case MESA_FORMAT_RGBA_SNORM16
:
1052 *datatype
= GL_SHORT
;
1056 case MESA_FORMAT_BGR_SRGB8
:
1057 *datatype
= GL_UNSIGNED_BYTE
;
1060 case MESA_FORMAT_A8B8G8R8_SRGB
:
1061 case MESA_FORMAT_B8G8R8A8_SRGB
:
1062 case MESA_FORMAT_A8R8G8B8_SRGB
:
1063 case MESA_FORMAT_R8G8B8A8_SRGB
:
1064 *datatype
= GL_UNSIGNED_BYTE
;
1067 case MESA_FORMAT_L_SRGB8
:
1068 *datatype
= GL_UNSIGNED_BYTE
;
1071 case MESA_FORMAT_L8A8_SRGB
:
1072 case MESA_FORMAT_A8L8_SRGB
:
1073 *datatype
= GL_UNSIGNED_BYTE
;
1077 case MESA_FORMAT_RGBA_FLOAT32
:
1078 *datatype
= GL_FLOAT
;
1081 case MESA_FORMAT_RGBA_FLOAT16
:
1082 *datatype
= GL_HALF_FLOAT_ARB
;
1085 case MESA_FORMAT_RGB_FLOAT32
:
1086 *datatype
= GL_FLOAT
;
1089 case MESA_FORMAT_RGB_FLOAT16
:
1090 *datatype
= GL_HALF_FLOAT_ARB
;
1093 case MESA_FORMAT_LA_FLOAT32
:
1094 case MESA_FORMAT_RG_FLOAT32
:
1095 *datatype
= GL_FLOAT
;
1098 case MESA_FORMAT_LA_FLOAT16
:
1099 case MESA_FORMAT_RG_FLOAT16
:
1100 *datatype
= GL_HALF_FLOAT_ARB
;
1103 case MESA_FORMAT_A_FLOAT32
:
1104 case MESA_FORMAT_L_FLOAT32
:
1105 case MESA_FORMAT_I_FLOAT32
:
1106 case MESA_FORMAT_R_FLOAT32
:
1107 *datatype
= GL_FLOAT
;
1110 case MESA_FORMAT_A_FLOAT16
:
1111 case MESA_FORMAT_L_FLOAT16
:
1112 case MESA_FORMAT_I_FLOAT16
:
1113 case MESA_FORMAT_R_FLOAT16
:
1114 *datatype
= GL_HALF_FLOAT_ARB
;
1118 case MESA_FORMAT_A_UINT8
:
1119 case MESA_FORMAT_L_UINT8
:
1120 case MESA_FORMAT_I_UINT8
:
1121 *datatype
= GL_UNSIGNED_BYTE
;
1124 case MESA_FORMAT_LA_UINT8
:
1125 *datatype
= GL_UNSIGNED_BYTE
;
1129 case MESA_FORMAT_A_UINT16
:
1130 case MESA_FORMAT_L_UINT16
:
1131 case MESA_FORMAT_I_UINT16
:
1132 *datatype
= GL_UNSIGNED_SHORT
;
1135 case MESA_FORMAT_LA_UINT16
:
1136 *datatype
= GL_UNSIGNED_SHORT
;
1139 case MESA_FORMAT_A_UINT32
:
1140 case MESA_FORMAT_L_UINT32
:
1141 case MESA_FORMAT_I_UINT32
:
1142 *datatype
= GL_UNSIGNED_INT
;
1145 case MESA_FORMAT_LA_UINT32
:
1146 *datatype
= GL_UNSIGNED_INT
;
1149 case MESA_FORMAT_A_SINT8
:
1150 case MESA_FORMAT_L_SINT8
:
1151 case MESA_FORMAT_I_SINT8
:
1152 *datatype
= GL_BYTE
;
1155 case MESA_FORMAT_LA_SINT8
:
1156 *datatype
= GL_BYTE
;
1160 case MESA_FORMAT_A_SINT16
:
1161 case MESA_FORMAT_L_SINT16
:
1162 case MESA_FORMAT_I_SINT16
:
1163 *datatype
= GL_SHORT
;
1166 case MESA_FORMAT_LA_SINT16
:
1167 *datatype
= GL_SHORT
;
1171 case MESA_FORMAT_A_SINT32
:
1172 case MESA_FORMAT_L_SINT32
:
1173 case MESA_FORMAT_I_SINT32
:
1177 case MESA_FORMAT_LA_SINT32
:
1182 case MESA_FORMAT_R_SINT8
:
1183 *datatype
= GL_BYTE
;
1186 case MESA_FORMAT_RG_SINT8
:
1187 *datatype
= GL_BYTE
;
1190 case MESA_FORMAT_RGB_SINT8
:
1191 *datatype
= GL_BYTE
;
1194 case MESA_FORMAT_RGBA_SINT8
:
1195 *datatype
= GL_BYTE
;
1198 case MESA_FORMAT_R_SINT16
:
1199 *datatype
= GL_SHORT
;
1202 case MESA_FORMAT_RG_SINT16
:
1203 *datatype
= GL_SHORT
;
1206 case MESA_FORMAT_RGB_SINT16
:
1207 *datatype
= GL_SHORT
;
1210 case MESA_FORMAT_RGBA_SINT16
:
1211 *datatype
= GL_SHORT
;
1214 case MESA_FORMAT_R_SINT32
:
1218 case MESA_FORMAT_RG_SINT32
:
1222 case MESA_FORMAT_RGB_SINT32
:
1226 case MESA_FORMAT_RGBA_SINT32
:
1232 * \name Non-normalized unsigned integer formats.
1234 case MESA_FORMAT_R_UINT8
:
1235 *datatype
= GL_UNSIGNED_BYTE
;
1238 case MESA_FORMAT_RG_UINT8
:
1239 *datatype
= GL_UNSIGNED_BYTE
;
1242 case MESA_FORMAT_RGB_UINT8
:
1243 *datatype
= GL_UNSIGNED_BYTE
;
1246 case MESA_FORMAT_RGBA_UINT8
:
1247 *datatype
= GL_UNSIGNED_BYTE
;
1250 case MESA_FORMAT_R_UINT16
:
1251 *datatype
= GL_UNSIGNED_SHORT
;
1254 case MESA_FORMAT_RG_UINT16
:
1255 *datatype
= GL_UNSIGNED_SHORT
;
1258 case MESA_FORMAT_RGB_UINT16
:
1259 *datatype
= GL_UNSIGNED_SHORT
;
1262 case MESA_FORMAT_RGBA_UINT16
:
1263 *datatype
= GL_UNSIGNED_SHORT
;
1266 case MESA_FORMAT_R_UINT32
:
1267 *datatype
= GL_UNSIGNED_INT
;
1270 case MESA_FORMAT_RG_UINT32
:
1271 *datatype
= GL_UNSIGNED_INT
;
1274 case MESA_FORMAT_RGB_UINT32
:
1275 *datatype
= GL_UNSIGNED_INT
;
1278 case MESA_FORMAT_RGBA_UINT32
:
1279 *datatype
= GL_UNSIGNED_INT
;
1283 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1284 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1288 case MESA_FORMAT_R11G11B10_FLOAT
:
1289 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1293 case MESA_FORMAT_B10G10R10A2_UINT
:
1294 case MESA_FORMAT_R10G10B10A2_UINT
:
1295 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1299 case MESA_FORMAT_R8G8B8X8_SRGB
:
1300 case MESA_FORMAT_X8B8G8R8_SRGB
:
1301 case MESA_FORMAT_RGBX_UINT8
:
1302 *datatype
= GL_UNSIGNED_BYTE
;
1306 case MESA_FORMAT_R8G8B8X8_SNORM
:
1307 case MESA_FORMAT_RGBX_SINT8
:
1308 *datatype
= GL_BYTE
;
1312 case MESA_FORMAT_B10G10R10X2_UNORM
:
1313 case MESA_FORMAT_R10G10B10X2_UNORM
:
1314 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1318 case MESA_FORMAT_RGBX_UNORM16
:
1319 case MESA_FORMAT_RGBX_UINT16
:
1320 *datatype
= GL_UNSIGNED_SHORT
;
1324 case MESA_FORMAT_RGBX_SNORM16
:
1325 case MESA_FORMAT_RGBX_SINT16
:
1326 *datatype
= GL_SHORT
;
1330 case MESA_FORMAT_RGBX_FLOAT16
:
1331 *datatype
= GL_HALF_FLOAT
;
1335 case MESA_FORMAT_RGBX_FLOAT32
:
1336 *datatype
= GL_FLOAT
;
1340 case MESA_FORMAT_RGBX_UINT32
:
1341 *datatype
= GL_UNSIGNED_INT
;
1345 case MESA_FORMAT_RGBX_SINT32
:
1350 case MESA_FORMAT_R10G10B10A2_UNORM
:
1351 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1355 case MESA_FORMAT_G8R8_SNORM
:
1356 *datatype
= GL_BYTE
;
1360 case MESA_FORMAT_G16R16_SNORM
:
1361 *datatype
= GL_SHORT
;
1365 case MESA_FORMAT_B8G8R8X8_SRGB
:
1366 case MESA_FORMAT_X8R8G8B8_SRGB
:
1367 *datatype
= GL_UNSIGNED_BYTE
;
1371 case MESA_FORMAT_COUNT
:
1375 /* Warn if any formats are not handled */
1376 _mesa_problem(NULL
, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
1377 _mesa_get_format_name(format
));
1378 assert(format
== MESA_FORMAT_NONE
||
1379 _mesa_is_format_compressed(format
));
1386 * Check if a mesa_format exactly matches a GL format/type combination
1387 * such that we can use memcpy() from one to the other.
1388 * \param mesa_format a MESA_FORMAT_x value
1389 * \param format the user-specified image format
1390 * \param type the user-specified image datatype
1391 * \param swapBytes typically the current pixel pack/unpack byteswap state
1392 * \param[out] error GL_NO_ERROR if format is an expected input.
1393 * GL_INVALID_ENUM if format is an unexpected input.
1394 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1397 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1398 GLenum format
, GLenum type
,
1399 GLboolean swapBytes
, GLenum
*error
)
1401 const GLboolean littleEndian
= _mesa_little_endian();
1403 *error
= GL_NO_ERROR
;
1405 /* Note: When reading a GL format/type combination, the format lists channel
1406 * assignments from most significant channel in the type to least
1407 * significant. A type with _REV indicates that the assignments are
1408 * swapped, so they are listed from least significant to most significant.
1410 * Compressed formats will fall through and return GL_FALSE.
1412 * For sanity, please keep this switch statement ordered the same as the
1413 * enums in formats.h.
1416 switch (mesa_format
) {
1418 case MESA_FORMAT_NONE
:
1419 case MESA_FORMAT_COUNT
:
1422 case MESA_FORMAT_A8B8G8R8_UNORM
:
1423 case MESA_FORMAT_A8B8G8R8_SRGB
:
1424 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1427 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1430 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1433 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1437 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1441 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1446 case MESA_FORMAT_R8G8B8A8_UNORM
:
1447 case MESA_FORMAT_R8G8B8A8_SRGB
:
1448 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1452 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1455 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1458 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1462 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1466 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1471 case MESA_FORMAT_B8G8R8A8_UNORM
:
1472 case MESA_FORMAT_B8G8R8A8_SRGB
:
1473 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1477 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1480 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1485 case MESA_FORMAT_A8R8G8B8_UNORM
:
1486 case MESA_FORMAT_A8R8G8B8_SRGB
:
1487 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1490 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1494 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1499 case MESA_FORMAT_X8B8G8R8_UNORM
:
1500 case MESA_FORMAT_R8G8B8X8_UNORM
:
1503 case MESA_FORMAT_B8G8R8X8_UNORM
:
1504 case MESA_FORMAT_X8R8G8B8_UNORM
:
1507 case MESA_FORMAT_BGR_UNORM8
:
1508 case MESA_FORMAT_BGR_SRGB8
:
1509 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1511 case MESA_FORMAT_RGB_UNORM8
:
1512 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1514 case MESA_FORMAT_B5G6R5_UNORM
:
1515 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1516 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1519 case MESA_FORMAT_R5G6B5_UNORM
:
1520 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1521 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1524 case MESA_FORMAT_B4G4R4A4_UNORM
:
1525 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1528 case MESA_FORMAT_A4R4G4B4_UNORM
:
1531 case MESA_FORMAT_A1B5G5R5_UNORM
:
1532 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1535 case MESA_FORMAT_X1B5G5R5_UNORM
:
1536 return format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1539 case MESA_FORMAT_B5G5R5A1_UNORM
:
1540 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1543 case MESA_FORMAT_A1R5G5B5_UNORM
:
1544 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1547 case MESA_FORMAT_L4A4_UNORM
:
1549 case MESA_FORMAT_L8A8_UNORM
:
1550 case MESA_FORMAT_L8A8_SRGB
:
1551 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1552 case MESA_FORMAT_A8L8_UNORM
:
1553 case MESA_FORMAT_A8L8_SRGB
:
1556 case MESA_FORMAT_L16A16_UNORM
:
1557 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1558 case MESA_FORMAT_A16L16_UNORM
:
1561 case MESA_FORMAT_B2G3R3_UNORM
:
1562 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1564 case MESA_FORMAT_R3G3B2_UNORM
:
1565 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1567 case MESA_FORMAT_A4B4G4R4_UNORM
:
1568 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1571 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1576 case MESA_FORMAT_R4G4B4A4_UNORM
:
1577 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1580 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1583 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1586 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1591 case MESA_FORMAT_R5G5B5A1_UNORM
:
1592 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1594 case MESA_FORMAT_A2B10G10R10_UNORM
:
1595 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1597 case MESA_FORMAT_A2B10G10R10_UINT
:
1598 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1600 case MESA_FORMAT_A2R10G10B10_UNORM
:
1601 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1603 case MESA_FORMAT_A2R10G10B10_UINT
:
1604 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1606 case MESA_FORMAT_A_UNORM8
:
1607 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1608 case MESA_FORMAT_A_UNORM16
:
1609 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1610 case MESA_FORMAT_L_UNORM8
:
1611 case MESA_FORMAT_L_SRGB8
:
1612 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1613 case MESA_FORMAT_L_UNORM16
:
1614 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1615 case MESA_FORMAT_I_UNORM8
:
1616 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1617 case MESA_FORMAT_I_UNORM16
:
1618 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1620 case MESA_FORMAT_YCBCR
:
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
));
1624 case MESA_FORMAT_YCBCR_REV
:
1625 return format
== GL_YCBCR_MESA
&&
1626 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1627 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1629 case MESA_FORMAT_R_UNORM8
:
1630 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1631 case MESA_FORMAT_R8G8_UNORM
:
1632 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1633 case MESA_FORMAT_G8R8_UNORM
:
1636 case MESA_FORMAT_R_UNORM16
:
1637 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1639 case MESA_FORMAT_R16G16_UNORM
:
1640 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1642 case MESA_FORMAT_G16R16_UNORM
:
1645 case MESA_FORMAT_B10G10R10A2_UNORM
:
1646 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1649 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1650 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1652 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1653 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1656 case MESA_FORMAT_Z_UNORM16
:
1657 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1660 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1663 case MESA_FORMAT_Z_UNORM32
:
1664 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1667 case MESA_FORMAT_S_UINT8
:
1668 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1670 case MESA_FORMAT_RGBA_FLOAT32
:
1671 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1672 case MESA_FORMAT_RGBA_FLOAT16
:
1673 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1675 case MESA_FORMAT_RGB_FLOAT32
:
1676 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1677 case MESA_FORMAT_RGB_FLOAT16
:
1678 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1680 case MESA_FORMAT_A_FLOAT32
:
1681 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1682 case MESA_FORMAT_A_FLOAT16
:
1683 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1685 case MESA_FORMAT_L_FLOAT32
:
1686 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1687 case MESA_FORMAT_L_FLOAT16
:
1688 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1690 case MESA_FORMAT_LA_FLOAT32
:
1691 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1692 case MESA_FORMAT_LA_FLOAT16
:
1693 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1695 case MESA_FORMAT_I_FLOAT32
:
1696 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1697 case MESA_FORMAT_I_FLOAT16
:
1698 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1700 case MESA_FORMAT_R_FLOAT32
:
1701 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1702 case MESA_FORMAT_R_FLOAT16
:
1703 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1705 case MESA_FORMAT_RG_FLOAT32
:
1706 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1707 case MESA_FORMAT_RG_FLOAT16
:
1708 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1710 case MESA_FORMAT_A_UINT8
:
1711 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1712 case MESA_FORMAT_A_UINT16
:
1713 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1715 case MESA_FORMAT_A_UINT32
:
1716 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1718 case MESA_FORMAT_A_SINT8
:
1719 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1720 case MESA_FORMAT_A_SINT16
:
1721 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1722 case MESA_FORMAT_A_SINT32
:
1723 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1725 case MESA_FORMAT_I_UINT8
:
1726 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1727 case MESA_FORMAT_I_UINT16
:
1728 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1729 case MESA_FORMAT_I_UINT32
:
1730 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1731 case MESA_FORMAT_I_SINT8
:
1732 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1733 case MESA_FORMAT_I_SINT16
:
1734 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1735 case MESA_FORMAT_I_SINT32
:
1736 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1738 case MESA_FORMAT_L_UINT8
:
1739 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1740 case MESA_FORMAT_L_UINT16
:
1741 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1743 case MESA_FORMAT_L_UINT32
:
1744 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1746 case MESA_FORMAT_L_SINT8
:
1747 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1748 case MESA_FORMAT_L_SINT16
:
1749 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1751 case MESA_FORMAT_L_SINT32
:
1752 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1754 case MESA_FORMAT_LA_UINT8
:
1755 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1756 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1757 case MESA_FORMAT_LA_UINT16
:
1758 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1759 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1760 case MESA_FORMAT_LA_UINT32
:
1761 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1762 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1763 case MESA_FORMAT_LA_SINT8
:
1764 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1766 case MESA_FORMAT_LA_SINT16
:
1767 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1769 case MESA_FORMAT_LA_SINT32
:
1770 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1773 case MESA_FORMAT_R_SINT8
:
1774 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1775 case MESA_FORMAT_RG_SINT8
:
1776 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1777 case MESA_FORMAT_RGB_SINT8
:
1778 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1779 case MESA_FORMAT_RGBA_SINT8
:
1780 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1781 case MESA_FORMAT_R_SINT16
:
1782 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1783 case MESA_FORMAT_RG_SINT16
:
1784 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1785 case MESA_FORMAT_RGB_SINT16
:
1786 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1787 case MESA_FORMAT_RGBA_SINT16
:
1788 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1789 case MESA_FORMAT_R_SINT32
:
1790 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1791 case MESA_FORMAT_RG_SINT32
:
1792 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1793 case MESA_FORMAT_RGB_SINT32
:
1794 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1795 case MESA_FORMAT_RGBA_SINT32
:
1796 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1798 case MESA_FORMAT_R_UINT8
:
1799 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1800 case MESA_FORMAT_RG_UINT8
:
1801 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1802 case MESA_FORMAT_RGB_UINT8
:
1803 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1804 case MESA_FORMAT_RGBA_UINT8
:
1805 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1807 case MESA_FORMAT_R_UINT16
:
1808 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1810 case MESA_FORMAT_RG_UINT16
:
1811 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1812 case MESA_FORMAT_RGB_UINT16
:
1813 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1815 case MESA_FORMAT_RGBA_UINT16
:
1816 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1818 case MESA_FORMAT_R_UINT32
:
1819 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1820 case MESA_FORMAT_RG_UINT32
:
1821 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1822 case MESA_FORMAT_RGB_UINT32
:
1823 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1824 case MESA_FORMAT_RGBA_UINT32
:
1825 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1827 case MESA_FORMAT_R_SNORM8
:
1828 return format
== GL_RED
&& type
== GL_BYTE
;
1829 case MESA_FORMAT_R8G8_SNORM
:
1830 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1832 case MESA_FORMAT_X8B8G8R8_SNORM
:
1835 case MESA_FORMAT_A8B8G8R8_SNORM
:
1836 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1839 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1844 case MESA_FORMAT_R8G8B8A8_SNORM
:
1845 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1848 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1853 case MESA_FORMAT_R_SNORM16
:
1854 return format
== GL_RED
&& type
== GL_SHORT
&&
1856 case MESA_FORMAT_R16G16_SNORM
:
1857 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1858 case MESA_FORMAT_RGB_SNORM16
:
1859 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1860 case MESA_FORMAT_RGBA_SNORM16
:
1861 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1862 case MESA_FORMAT_RGBA_UNORM16
:
1863 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1866 case MESA_FORMAT_A_SNORM8
:
1867 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1868 case MESA_FORMAT_L_SNORM8
:
1869 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1870 case MESA_FORMAT_L8A8_SNORM
:
1871 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1872 littleEndian
&& !swapBytes
;
1873 case MESA_FORMAT_A8L8_SNORM
:
1874 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1875 !littleEndian
&& !swapBytes
;
1876 case MESA_FORMAT_I_SNORM8
:
1877 return format
== GL_RED
&& type
== GL_BYTE
;
1878 case MESA_FORMAT_A_SNORM16
:
1879 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1880 case MESA_FORMAT_L_SNORM16
:
1881 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1882 case MESA_FORMAT_LA_SNORM16
:
1883 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1884 littleEndian
&& !swapBytes
;
1885 case MESA_FORMAT_I_SNORM16
:
1886 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1889 case MESA_FORMAT_B10G10R10A2_UINT
:
1890 return (format
== GL_BGRA_INTEGER_EXT
&&
1891 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1894 case MESA_FORMAT_R10G10B10A2_UINT
:
1895 return (format
== GL_RGBA_INTEGER_EXT
&&
1896 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1899 case MESA_FORMAT_B5G6R5_UINT
:
1900 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5
;
1902 case MESA_FORMAT_R5G6B5_UINT
:
1903 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
;
1905 case MESA_FORMAT_B2G3R3_UINT
:
1906 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1908 case MESA_FORMAT_R3G3B2_UINT
:
1909 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1911 case MESA_FORMAT_A4B4G4R4_UINT
:
1912 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1915 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1919 case MESA_FORMAT_R4G4B4A4_UINT
:
1920 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1923 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1928 case MESA_FORMAT_B4G4R4A4_UINT
:
1929 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1932 case MESA_FORMAT_A4R4G4B4_UINT
:
1935 case MESA_FORMAT_A1B5G5R5_UINT
:
1936 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1939 case MESA_FORMAT_B5G5R5A1_UINT
:
1940 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1943 case MESA_FORMAT_A1R5G5B5_UINT
:
1944 return format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1947 case MESA_FORMAT_R5G5B5A1_UINT
:
1948 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1950 case MESA_FORMAT_A8B8G8R8_UINT
:
1951 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1954 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1958 case MESA_FORMAT_A8R8G8B8_UINT
:
1959 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1963 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1969 case MESA_FORMAT_R8G8B8A8_UINT
:
1970 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1974 if (format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1979 case MESA_FORMAT_B8G8R8A8_UINT
:
1980 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1984 if (format
== GL_BGRA_INTEGER
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1989 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1990 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
1993 case MESA_FORMAT_R11G11B10_FLOAT
:
1994 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
1997 case MESA_FORMAT_Z_FLOAT32
:
1998 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2000 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2001 return format
== GL_DEPTH_STENCIL
&&
2002 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2004 case MESA_FORMAT_B4G4R4X4_UNORM
:
2005 case MESA_FORMAT_B5G5R5X1_UNORM
:
2006 case MESA_FORMAT_R8G8B8X8_SNORM
:
2007 case MESA_FORMAT_R8G8B8X8_SRGB
:
2008 case MESA_FORMAT_X8B8G8R8_SRGB
:
2009 case MESA_FORMAT_RGBX_UINT8
:
2010 case MESA_FORMAT_RGBX_SINT8
:
2011 case MESA_FORMAT_B10G10R10X2_UNORM
:
2012 case MESA_FORMAT_RGBX_UNORM16
:
2013 case MESA_FORMAT_RGBX_SNORM16
:
2014 case MESA_FORMAT_RGBX_FLOAT16
:
2015 case MESA_FORMAT_RGBX_UINT16
:
2016 case MESA_FORMAT_RGBX_SINT16
:
2017 case MESA_FORMAT_RGBX_FLOAT32
:
2018 case MESA_FORMAT_RGBX_UINT32
:
2019 case MESA_FORMAT_RGBX_SINT32
:
2022 case MESA_FORMAT_R10G10B10X2_UNORM
:
2023 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2025 case MESA_FORMAT_R10G10B10A2_UNORM
:
2026 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2029 case MESA_FORMAT_G8R8_SNORM
:
2030 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2033 case MESA_FORMAT_G16R16_SNORM
:
2034 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2037 case MESA_FORMAT_B8G8R8X8_SRGB
:
2038 case MESA_FORMAT_X8R8G8B8_SRGB
:
2041 assert(_mesa_is_format_compressed(mesa_format
));
2043 *error
= GL_INVALID_ENUM
;