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"
34 * Information about texture formats.
40 /** text name for debugging */
43 enum mesa_format_layout Layout
;
46 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
47 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
48 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
53 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
54 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
62 GLubyte LuminanceBits
;
63 GLubyte IntensityBits
;
68 * To describe compressed formats. If not compressed, Width=Height=1.
70 GLubyte BlockWidth
, BlockHeight
;
71 GLubyte BytesPerBlock
;
74 mesa_array_format ArrayFormat
;
77 #include "format_info.c"
79 static const struct gl_format_info
*
80 _mesa_get_format_info(mesa_format format
)
82 const struct gl_format_info
*info
= &format_info
[format
];
83 assert(info
->Name
== format
);
88 /** Return string name of format (for debugging) */
90 _mesa_get_format_name(mesa_format format
)
92 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
99 * Return bytes needed to store a block of pixels in the given format.
100 * Normally, a block is 1x1 (a single pixel). But for compressed formats
101 * a block may be 4x4 or 8x4, etc.
103 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
106 _mesa_get_format_bytes(mesa_format format
)
108 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
109 ASSERT(info
->BytesPerBlock
);
110 ASSERT(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
111 _mesa_is_format_compressed(format
));
112 return info
->BytesPerBlock
;
117 * Return bits per component for the given format.
118 * \param format one of MESA_FORMAT_x
119 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
122 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
124 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
128 case GL_TEXTURE_RED_SIZE
:
129 case GL_RENDERBUFFER_RED_SIZE_EXT
:
130 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
131 return info
->RedBits
;
133 case GL_TEXTURE_GREEN_SIZE
:
134 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
135 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
136 return info
->GreenBits
;
138 case GL_TEXTURE_BLUE_SIZE
:
139 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
140 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
141 return info
->BlueBits
;
143 case GL_TEXTURE_ALPHA_SIZE
:
144 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
145 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
146 return info
->AlphaBits
;
147 case GL_TEXTURE_INTENSITY_SIZE
:
148 return info
->IntensityBits
;
149 case GL_TEXTURE_LUMINANCE_SIZE
:
150 return info
->LuminanceBits
;
154 case GL_TEXTURE_DEPTH_SIZE_ARB
:
155 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
156 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
157 return info
->DepthBits
;
158 case GL_STENCIL_BITS
:
159 case GL_TEXTURE_STENCIL_SIZE_EXT
:
160 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
161 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
162 return info
->StencilBits
;
164 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
171 _mesa_get_format_max_bits(mesa_format format
)
173 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
174 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
175 max
= MAX2(max
, info
->BlueBits
);
176 max
= MAX2(max
, info
->AlphaBits
);
177 max
= MAX2(max
, info
->LuminanceBits
);
178 max
= MAX2(max
, info
->IntensityBits
);
179 max
= MAX2(max
, info
->DepthBits
);
180 max
= MAX2(max
, info
->StencilBits
);
186 * Return the layout type of the given format.
187 * The return value will be one of:
188 * MESA_FORMAT_LAYOUT_ARRAY
189 * MESA_FORMAT_LAYOUT_PACKED
190 * MESA_FORMAT_LAYOUT_OTHER
192 extern enum mesa_format_layout
193 _mesa_get_format_layout(mesa_format format
)
195 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
201 * Return the data type (or more specifically, the data representation)
202 * for the given format.
203 * The return value will be one of:
204 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
205 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
206 * GL_UNSIGNED_INT = an ordinary unsigned integer
207 * GL_INT = an ordinary signed integer
208 * GL_FLOAT = an ordinary float
211 _mesa_get_format_datatype(mesa_format format
)
213 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
214 return info
->DataType
;
218 get_base_format_for_array_format(mesa_array_format format
)
223 _mesa_array_format_get_swizzle(format
, swizzle
);
224 num_channels
= _mesa_array_format_get_num_channels(format
);
226 switch (num_channels
) {
228 /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB.
229 * This is not really a problem for now because we only create array
230 * formats from GL format/type combinations, and these cannot specify
237 if (swizzle
[0] == 0 &&
241 return GL_LUMINANCE_ALPHA
;
242 if (swizzle
[0] == 1 &&
246 return GL_LUMINANCE_ALPHA
;
247 if (swizzle
[0] == 0 &&
252 if (swizzle
[0] == 1 &&
259 if (swizzle
[0] == 0 &&
264 if (swizzle
[0] == 0 &&
269 if (swizzle
[0] <= MESA_FORMAT_SWIZZLE_W
)
271 if (swizzle
[1] <= MESA_FORMAT_SWIZZLE_W
)
273 if (swizzle
[2] <= MESA_FORMAT_SWIZZLE_W
)
275 if (swizzle
[3] <= MESA_FORMAT_SWIZZLE_W
)
280 unreachable("Unsupported format");
284 * Return the basic format for the given type. The result will be one of
285 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
286 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
287 * This functions accepts a mesa_format or a mesa_array_format.
290 _mesa_get_format_base_format(uint32_t format
)
292 if (!_mesa_format_is_mesa_array_format(format
)) {
293 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
294 return info
->BaseFormat
;
296 return get_base_format_for_array_format(format
);
302 * Return the block size (in pixels) for the given format. Normally
303 * the block size is 1x1. But compressed formats will have block sizes
304 * of 4x4 or 8x4 pixels, etc.
305 * \param bw returns block width in pixels
306 * \param bh returns block height in pixels
309 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
311 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
312 *bw
= info
->BlockWidth
;
313 *bh
= info
->BlockHeight
;
318 * Returns the an array of four numbers representing the transformation
319 * from the RGBA or SZ colorspace to the given format. For array formats,
320 * the i'th RGBA component is given by:
322 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
323 * comp = data[swizzle[i]];
324 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
326 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
328 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
329 * // data does not contain a channel of this format
331 * For packed formats, the swizzle gives the number of components left of
332 * the least significant bit.
334 * Compressed formats have no swizzle.
337 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
339 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
340 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
344 _mesa_array_format_flip_channels(mesa_array_format format
)
349 num_channels
= _mesa_array_format_get_num_channels(format
);
350 _mesa_array_format_get_swizzle(format
, swizzle
);
352 if (num_channels
== 1)
355 if (num_channels
== 2) {
356 _mesa_array_format_set_swizzle(&format
, swizzle
[1], swizzle
[0],
357 swizzle
[2], swizzle
[3]);
361 if (num_channels
== 4) {
362 _mesa_array_format_set_swizzle(&format
, swizzle
[3], swizzle
[2],
363 swizzle
[1], swizzle
[0]);
367 unreachable("Invalid array format");
371 _mesa_format_to_array_format(mesa_format format
)
373 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
374 if (_mesa_little_endian())
375 return info
->ArrayFormat
;
377 return _mesa_array_format_flip_channels(info
->ArrayFormat
);
381 _mesa_format_from_array_format(uint32_t array_format
)
383 mesa_array_format af
;
386 assert(_mesa_format_is_mesa_array_format(array_format
));
388 if (_mesa_little_endian())
391 af
= _mesa_array_format_flip_channels(array_format
);
393 for (f
= 1; f
< MESA_FORMAT_COUNT
; ++f
)
394 if (_mesa_get_format_info(f
)->ArrayFormat
== af
)
397 return MESA_FORMAT_NONE
;
400 /** Is the given format a compressed format? */
402 _mesa_is_format_compressed(mesa_format format
)
404 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
405 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
410 * Determine if the given format represents a packed depth/stencil buffer.
413 _mesa_is_format_packed_depth_stencil(mesa_format format
)
415 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
417 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
422 * Is the given format a signed/unsigned integer color format?
425 _mesa_is_format_integer_color(mesa_format format
)
427 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
428 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
429 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
430 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
431 info
->BaseFormat
!= GL_STENCIL_INDEX
;
436 * Is the given format an unsigned integer format?
439 _mesa_is_format_unsigned(mesa_format format
)
441 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
442 return _mesa_is_type_unsigned(info
->DataType
);
447 * Does the given format store signed values?
450 _mesa_is_format_signed(mesa_format format
)
452 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
453 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
454 /* these packed float formats only store unsigned values */
458 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
459 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
460 info
->DataType
== GL_INT
||
461 info
->DataType
== GL_FLOAT
);
466 * Is the given format an integer format?
469 _mesa_is_format_integer(mesa_format format
)
471 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
472 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
477 * Return true if the given format is a color format.
480 _mesa_is_format_color_format(mesa_format format
)
482 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
483 switch (info
->BaseFormat
) {
484 case GL_DEPTH_COMPONENT
:
485 case GL_STENCIL_INDEX
:
486 case GL_DEPTH_STENCIL
:
495 * Return color encoding for given format.
496 * \return GL_LINEAR or GL_SRGB
499 _mesa_get_format_color_encoding(mesa_format format
)
501 /* XXX this info should be encoded in gl_format_info */
503 case MESA_FORMAT_BGR_SRGB8
:
504 case MESA_FORMAT_A8B8G8R8_SRGB
:
505 case MESA_FORMAT_B8G8R8A8_SRGB
:
506 case MESA_FORMAT_A8R8G8B8_SRGB
:
507 case MESA_FORMAT_R8G8B8A8_SRGB
:
508 case MESA_FORMAT_L_SRGB8
:
509 case MESA_FORMAT_L8A8_SRGB
:
510 case MESA_FORMAT_A8L8_SRGB
:
511 case MESA_FORMAT_SRGB_DXT1
:
512 case MESA_FORMAT_SRGBA_DXT1
:
513 case MESA_FORMAT_SRGBA_DXT3
:
514 case MESA_FORMAT_SRGBA_DXT5
:
515 case MESA_FORMAT_R8G8B8X8_SRGB
:
516 case MESA_FORMAT_ETC2_SRGB8
:
517 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
518 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
519 case MESA_FORMAT_B8G8R8X8_SRGB
:
520 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
529 * Return TRUE if format is an ETC2 compressed format specified
530 * by GL_ARB_ES3_compatibility.
533 _mesa_is_format_etc2(mesa_format format
)
536 case MESA_FORMAT_ETC2_RGB8
:
537 case MESA_FORMAT_ETC2_SRGB8
:
538 case MESA_FORMAT_ETC2_RGBA8_EAC
:
539 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
540 case MESA_FORMAT_ETC2_R11_EAC
:
541 case MESA_FORMAT_ETC2_RG11_EAC
:
542 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
543 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
544 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
545 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
554 * For an sRGB format, return the corresponding linear color space format.
555 * For non-sRGB formats, return the format as-is.
558 _mesa_get_srgb_format_linear(mesa_format format
)
561 case MESA_FORMAT_BGR_SRGB8
:
562 format
= MESA_FORMAT_BGR_UNORM8
;
564 case MESA_FORMAT_A8B8G8R8_SRGB
:
565 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
567 case MESA_FORMAT_B8G8R8A8_SRGB
:
568 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
570 case MESA_FORMAT_A8R8G8B8_SRGB
:
571 format
= MESA_FORMAT_A8R8G8B8_UNORM
;
573 case MESA_FORMAT_R8G8B8A8_SRGB
:
574 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
576 case MESA_FORMAT_L_SRGB8
:
577 format
= MESA_FORMAT_L_UNORM8
;
579 case MESA_FORMAT_L8A8_SRGB
:
580 format
= MESA_FORMAT_L8A8_UNORM
;
582 case MESA_FORMAT_A8L8_SRGB
:
583 format
= MESA_FORMAT_A8L8_UNORM
;
585 case MESA_FORMAT_SRGB_DXT1
:
586 format
= MESA_FORMAT_RGB_DXT1
;
588 case MESA_FORMAT_SRGBA_DXT1
:
589 format
= MESA_FORMAT_RGBA_DXT1
;
591 case MESA_FORMAT_SRGBA_DXT3
:
592 format
= MESA_FORMAT_RGBA_DXT3
;
594 case MESA_FORMAT_SRGBA_DXT5
:
595 format
= MESA_FORMAT_RGBA_DXT5
;
597 case MESA_FORMAT_R8G8B8X8_SRGB
:
598 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
600 case MESA_FORMAT_X8B8G8R8_SRGB
:
601 format
= MESA_FORMAT_X8B8G8R8_UNORM
;
603 case MESA_FORMAT_ETC2_SRGB8
:
604 format
= MESA_FORMAT_ETC2_RGB8
;
606 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
607 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
609 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
610 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
612 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
613 format
= MESA_FORMAT_BPTC_RGBA_UNORM
;
615 case MESA_FORMAT_B8G8R8X8_SRGB
:
616 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
618 case MESA_FORMAT_X8R8G8B8_SRGB
:
619 format
= MESA_FORMAT_X8R8G8B8_UNORM
;
629 * If the given format is a compressed format, return a corresponding
630 * uncompressed format.
633 _mesa_get_uncompressed_format(mesa_format format
)
636 case MESA_FORMAT_RGB_FXT1
:
637 return MESA_FORMAT_BGR_UNORM8
;
638 case MESA_FORMAT_RGBA_FXT1
:
639 return MESA_FORMAT_A8B8G8R8_UNORM
;
640 case MESA_FORMAT_RGB_DXT1
:
641 case MESA_FORMAT_SRGB_DXT1
:
642 return MESA_FORMAT_BGR_UNORM8
;
643 case MESA_FORMAT_RGBA_DXT1
:
644 case MESA_FORMAT_SRGBA_DXT1
:
645 return MESA_FORMAT_A8B8G8R8_UNORM
;
646 case MESA_FORMAT_RGBA_DXT3
:
647 case MESA_FORMAT_SRGBA_DXT3
:
648 return MESA_FORMAT_A8B8G8R8_UNORM
;
649 case MESA_FORMAT_RGBA_DXT5
:
650 case MESA_FORMAT_SRGBA_DXT5
:
651 return MESA_FORMAT_A8B8G8R8_UNORM
;
652 case MESA_FORMAT_R_RGTC1_UNORM
:
653 return MESA_FORMAT_R_UNORM8
;
654 case MESA_FORMAT_R_RGTC1_SNORM
:
655 return MESA_FORMAT_R_SNORM8
;
656 case MESA_FORMAT_RG_RGTC2_UNORM
:
657 return MESA_FORMAT_R8G8_UNORM
;
658 case MESA_FORMAT_RG_RGTC2_SNORM
:
659 return MESA_FORMAT_R8G8_SNORM
;
660 case MESA_FORMAT_L_LATC1_UNORM
:
661 return MESA_FORMAT_L_UNORM8
;
662 case MESA_FORMAT_L_LATC1_SNORM
:
663 return MESA_FORMAT_L_SNORM8
;
664 case MESA_FORMAT_LA_LATC2_UNORM
:
665 return MESA_FORMAT_L8A8_UNORM
;
666 case MESA_FORMAT_LA_LATC2_SNORM
:
667 return MESA_FORMAT_L8A8_SNORM
;
668 case MESA_FORMAT_ETC1_RGB8
:
669 case MESA_FORMAT_ETC2_RGB8
:
670 case MESA_FORMAT_ETC2_SRGB8
:
671 return MESA_FORMAT_BGR_UNORM8
;
672 case MESA_FORMAT_ETC2_RGBA8_EAC
:
673 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
674 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
675 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
676 return MESA_FORMAT_A8B8G8R8_UNORM
;
677 case MESA_FORMAT_ETC2_R11_EAC
:
678 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
679 return MESA_FORMAT_R_UNORM16
;
680 case MESA_FORMAT_ETC2_RG11_EAC
:
681 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
682 return MESA_FORMAT_R16G16_UNORM
;
683 case MESA_FORMAT_BPTC_RGBA_UNORM
:
684 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
685 return MESA_FORMAT_A8B8G8R8_UNORM
;
686 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
687 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
688 return MESA_FORMAT_RGB_FLOAT32
;
691 assert(!_mesa_is_format_compressed(format
));
699 _mesa_format_num_components(mesa_format format
)
701 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
702 return ((info
->RedBits
> 0) +
703 (info
->GreenBits
> 0) +
704 (info
->BlueBits
> 0) +
705 (info
->AlphaBits
> 0) +
706 (info
->LuminanceBits
> 0) +
707 (info
->IntensityBits
> 0) +
708 (info
->DepthBits
> 0) +
709 (info
->StencilBits
> 0));
714 * Returns true if a color format has data stored in the R/G/B/A channels,
715 * given an index from 0 to 3.
718 _mesa_format_has_color_component(mesa_format format
, int component
)
720 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
722 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
723 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
724 info
->BaseFormat
!= GL_STENCIL_INDEX
);
728 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
730 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
732 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
734 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
736 assert(!"Invalid color component: must be 0..3");
743 * Return number of bytes needed to store an image of the given size
744 * in the given format.
747 _mesa_format_image_size(mesa_format format
, GLsizei width
,
748 GLsizei height
, GLsizei depth
)
750 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
751 /* Strictly speaking, a conditional isn't needed here */
752 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
753 /* compressed format (2D only for now) */
754 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
755 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
756 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
757 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
762 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
769 * Same as _mesa_format_image_size() but returns a 64-bit value to
770 * accomodate very large textures.
773 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
774 GLsizei height
, GLsizei depth
)
776 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
777 /* Strictly speaking, a conditional isn't needed here */
778 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
779 /* compressed format (2D only for now) */
780 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
781 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
782 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
783 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
788 const uint64_t sz
= ((uint64_t) width
*
791 info
->BytesPerBlock
);
799 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
801 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
802 /* Strictly speaking, a conditional isn't needed here */
803 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
804 /* compressed format */
805 const GLuint bw
= info
->BlockWidth
;
806 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
807 const GLint stride
= wblocks
* info
->BytesPerBlock
;
811 const GLint stride
= width
* info
->BytesPerBlock
;
818 * Debug/test: check that all formats are handled in the
819 * _mesa_format_to_type_and_comps() function. When new pixel formats
820 * are added to Mesa, that function needs to be updated.
821 * This is a no-op after the first call.
824 check_format_to_type_and_comps(void)
828 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
831 /* This function will emit a problem/warning if the format is
834 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
839 * Do sanity checking of the format info table.
842 _mesa_test_formats(void)
846 STATIC_ASSERT(Elements(format_info
) == MESA_FORMAT_COUNT
);
848 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
849 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
852 assert(info
->Name
== i
);
854 if (info
->Name
== MESA_FORMAT_NONE
)
857 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
858 if (info
->RedBits
> 0) {
859 GLuint t
= info
->RedBits
+ info
->GreenBits
860 + info
->BlueBits
+ info
->AlphaBits
;
861 assert(t
/ 8 <= info
->BytesPerBlock
);
866 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
867 info
->DataType
== GL_SIGNED_NORMALIZED
||
868 info
->DataType
== GL_UNSIGNED_INT
||
869 info
->DataType
== GL_INT
||
870 info
->DataType
== GL_FLOAT
||
871 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
872 info
->DataType
== GL_NONE
);
874 if (info
->BaseFormat
== GL_RGB
) {
875 assert(info
->RedBits
> 0);
876 assert(info
->GreenBits
> 0);
877 assert(info
->BlueBits
> 0);
878 assert(info
->AlphaBits
== 0);
879 assert(info
->LuminanceBits
== 0);
880 assert(info
->IntensityBits
== 0);
882 else if (info
->BaseFormat
== GL_RGBA
) {
883 assert(info
->RedBits
> 0);
884 assert(info
->GreenBits
> 0);
885 assert(info
->BlueBits
> 0);
886 assert(info
->AlphaBits
> 0);
887 assert(info
->LuminanceBits
== 0);
888 assert(info
->IntensityBits
== 0);
890 else if (info
->BaseFormat
== GL_RG
) {
891 assert(info
->RedBits
> 0);
892 assert(info
->GreenBits
> 0);
893 assert(info
->BlueBits
== 0);
894 assert(info
->AlphaBits
== 0);
895 assert(info
->LuminanceBits
== 0);
896 assert(info
->IntensityBits
== 0);
898 else if (info
->BaseFormat
== GL_RED
) {
899 assert(info
->RedBits
> 0);
900 assert(info
->GreenBits
== 0);
901 assert(info
->BlueBits
== 0);
902 assert(info
->AlphaBits
== 0);
903 assert(info
->LuminanceBits
== 0);
904 assert(info
->IntensityBits
== 0);
906 else if (info
->BaseFormat
== GL_LUMINANCE
) {
907 assert(info
->RedBits
== 0);
908 assert(info
->GreenBits
== 0);
909 assert(info
->BlueBits
== 0);
910 assert(info
->AlphaBits
== 0);
911 assert(info
->LuminanceBits
> 0);
912 assert(info
->IntensityBits
== 0);
914 else if (info
->BaseFormat
== GL_INTENSITY
) {
915 assert(info
->RedBits
== 0);
916 assert(info
->GreenBits
== 0);
917 assert(info
->BlueBits
== 0);
918 assert(info
->AlphaBits
== 0);
919 assert(info
->LuminanceBits
== 0);
920 assert(info
->IntensityBits
> 0);
924 check_format_to_type_and_comps();
930 * Return datatype and number of components per texel for the given mesa_format.
931 * Only used for mipmap generation code.
934 _mesa_format_to_type_and_comps(mesa_format format
,
935 GLenum
*datatype
, GLuint
*comps
)
938 case MESA_FORMAT_A8B8G8R8_UNORM
:
939 case MESA_FORMAT_R8G8B8A8_UNORM
:
940 case MESA_FORMAT_B8G8R8A8_UNORM
:
941 case MESA_FORMAT_A8R8G8B8_UNORM
:
942 case MESA_FORMAT_X8B8G8R8_UNORM
:
943 case MESA_FORMAT_R8G8B8X8_UNORM
:
944 case MESA_FORMAT_B8G8R8X8_UNORM
:
945 case MESA_FORMAT_X8R8G8B8_UNORM
:
946 *datatype
= GL_UNSIGNED_BYTE
;
949 case MESA_FORMAT_BGR_UNORM8
:
950 case MESA_FORMAT_RGB_UNORM8
:
951 *datatype
= GL_UNSIGNED_BYTE
;
954 case MESA_FORMAT_B5G6R5_UNORM
:
955 case MESA_FORMAT_R5G6B5_UNORM
:
956 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
960 case MESA_FORMAT_B4G4R4A4_UNORM
:
961 case MESA_FORMAT_A4R4G4B4_UNORM
:
962 case MESA_FORMAT_B4G4R4X4_UNORM
:
963 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
967 case MESA_FORMAT_B5G5R5A1_UNORM
:
968 case MESA_FORMAT_A1R5G5B5_UNORM
:
969 case MESA_FORMAT_B5G5R5X1_UNORM
:
970 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
974 case MESA_FORMAT_B10G10R10A2_UNORM
:
975 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
979 case MESA_FORMAT_A1B5G5R5_UNORM
:
980 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
984 case MESA_FORMAT_L4A4_UNORM
:
985 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
989 case MESA_FORMAT_L8A8_UNORM
:
990 case MESA_FORMAT_A8L8_UNORM
:
991 case MESA_FORMAT_R8G8_UNORM
:
992 case MESA_FORMAT_G8R8_UNORM
:
993 *datatype
= GL_UNSIGNED_BYTE
;
997 case MESA_FORMAT_L16A16_UNORM
:
998 case MESA_FORMAT_A16L16_UNORM
:
999 case MESA_FORMAT_R16G16_UNORM
:
1000 case MESA_FORMAT_G16R16_UNORM
:
1001 *datatype
= GL_UNSIGNED_SHORT
;
1005 case MESA_FORMAT_R_UNORM16
:
1006 case MESA_FORMAT_A_UNORM16
:
1007 case MESA_FORMAT_L_UNORM16
:
1008 case MESA_FORMAT_I_UNORM16
:
1009 *datatype
= GL_UNSIGNED_SHORT
;
1013 case MESA_FORMAT_R3G3B2_UNORM
:
1014 *datatype
= GL_UNSIGNED_BYTE_2_3_3_REV
;
1017 case MESA_FORMAT_A4B4G4R4_UNORM
:
1018 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1022 case MESA_FORMAT_R4G4B4A4_UNORM
:
1023 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
1026 case MESA_FORMAT_R1G5B5A5_UNORM
:
1027 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
1030 case MESA_FORMAT_R5G5B5A1_UNORM
:
1031 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1034 case MESA_FORMAT_A5B5G5R1_UNORM
:
1035 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1038 case MESA_FORMAT_A2B10G10R10_UNORM
:
1039 case MESA_FORMAT_A2B10G10R10_UINT
:
1040 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1043 case MESA_FORMAT_A2R10G10B10_UNORM
:
1044 case MESA_FORMAT_A2R10G10B10_UINT
:
1045 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1048 case MESA_FORMAT_R2G10B10A10_UNORM
:
1049 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1052 case MESA_FORMAT_A10B10G10R2_UNORM
:
1053 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1057 case MESA_FORMAT_B2G3R3_UNORM
:
1058 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1062 case MESA_FORMAT_A_UNORM8
:
1063 case MESA_FORMAT_L_UNORM8
:
1064 case MESA_FORMAT_I_UNORM8
:
1065 case MESA_FORMAT_R_UNORM8
:
1066 case MESA_FORMAT_S_UINT8
:
1067 *datatype
= GL_UNSIGNED_BYTE
;
1071 case MESA_FORMAT_YCBCR
:
1072 case MESA_FORMAT_YCBCR_REV
:
1073 *datatype
= GL_UNSIGNED_SHORT
;
1077 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1078 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1082 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1083 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1087 case MESA_FORMAT_Z_UNORM16
:
1088 *datatype
= GL_UNSIGNED_SHORT
;
1092 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1093 *datatype
= GL_UNSIGNED_INT
;
1097 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1098 *datatype
= GL_UNSIGNED_INT
;
1102 case MESA_FORMAT_Z_UNORM32
:
1103 *datatype
= GL_UNSIGNED_INT
;
1107 case MESA_FORMAT_Z_FLOAT32
:
1108 *datatype
= GL_FLOAT
;
1112 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1113 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1117 case MESA_FORMAT_R_SNORM8
:
1118 case MESA_FORMAT_A_SNORM8
:
1119 case MESA_FORMAT_L_SNORM8
:
1120 case MESA_FORMAT_I_SNORM8
:
1121 *datatype
= GL_BYTE
;
1124 case MESA_FORMAT_R8G8_SNORM
:
1125 case MESA_FORMAT_L8A8_SNORM
:
1126 case MESA_FORMAT_A8L8_SNORM
:
1127 *datatype
= GL_BYTE
;
1130 case MESA_FORMAT_A8B8G8R8_SNORM
:
1131 case MESA_FORMAT_R8G8B8A8_SNORM
:
1132 case MESA_FORMAT_X8B8G8R8_SNORM
:
1133 *datatype
= GL_BYTE
;
1137 case MESA_FORMAT_RGBA_UNORM16
:
1138 *datatype
= GL_UNSIGNED_SHORT
;
1142 case MESA_FORMAT_R_SNORM16
:
1143 case MESA_FORMAT_A_SNORM16
:
1144 case MESA_FORMAT_L_SNORM16
:
1145 case MESA_FORMAT_I_SNORM16
:
1146 *datatype
= GL_SHORT
;
1149 case MESA_FORMAT_R16G16_SNORM
:
1150 case MESA_FORMAT_LA_SNORM16
:
1151 *datatype
= GL_SHORT
;
1154 case MESA_FORMAT_RGB_SNORM16
:
1155 *datatype
= GL_SHORT
;
1158 case MESA_FORMAT_RGBA_SNORM16
:
1159 *datatype
= GL_SHORT
;
1163 case MESA_FORMAT_BGR_SRGB8
:
1164 *datatype
= GL_UNSIGNED_BYTE
;
1167 case MESA_FORMAT_A8B8G8R8_SRGB
:
1168 case MESA_FORMAT_B8G8R8A8_SRGB
:
1169 case MESA_FORMAT_A8R8G8B8_SRGB
:
1170 case MESA_FORMAT_R8G8B8A8_SRGB
:
1171 *datatype
= GL_UNSIGNED_BYTE
;
1174 case MESA_FORMAT_L_SRGB8
:
1175 *datatype
= GL_UNSIGNED_BYTE
;
1178 case MESA_FORMAT_L8A8_SRGB
:
1179 case MESA_FORMAT_A8L8_SRGB
:
1180 *datatype
= GL_UNSIGNED_BYTE
;
1184 case MESA_FORMAT_RGB_FXT1
:
1185 case MESA_FORMAT_RGBA_FXT1
:
1186 case MESA_FORMAT_RGB_DXT1
:
1187 case MESA_FORMAT_RGBA_DXT1
:
1188 case MESA_FORMAT_RGBA_DXT3
:
1189 case MESA_FORMAT_RGBA_DXT5
:
1190 case MESA_FORMAT_SRGB_DXT1
:
1191 case MESA_FORMAT_SRGBA_DXT1
:
1192 case MESA_FORMAT_SRGBA_DXT3
:
1193 case MESA_FORMAT_SRGBA_DXT5
:
1194 case MESA_FORMAT_R_RGTC1_UNORM
:
1195 case MESA_FORMAT_R_RGTC1_SNORM
:
1196 case MESA_FORMAT_RG_RGTC2_UNORM
:
1197 case MESA_FORMAT_RG_RGTC2_SNORM
:
1198 case MESA_FORMAT_L_LATC1_UNORM
:
1199 case MESA_FORMAT_L_LATC1_SNORM
:
1200 case MESA_FORMAT_LA_LATC2_UNORM
:
1201 case MESA_FORMAT_LA_LATC2_SNORM
:
1202 case MESA_FORMAT_ETC1_RGB8
:
1203 case MESA_FORMAT_ETC2_RGB8
:
1204 case MESA_FORMAT_ETC2_SRGB8
:
1205 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1206 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1207 case MESA_FORMAT_ETC2_R11_EAC
:
1208 case MESA_FORMAT_ETC2_RG11_EAC
:
1209 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1210 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1211 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1212 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1213 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1214 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1215 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1216 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1217 /* XXX generate error instead? */
1218 *datatype
= GL_UNSIGNED_BYTE
;
1222 case MESA_FORMAT_RGBA_FLOAT32
:
1223 *datatype
= GL_FLOAT
;
1226 case MESA_FORMAT_RGBA_FLOAT16
:
1227 *datatype
= GL_HALF_FLOAT_ARB
;
1230 case MESA_FORMAT_RGB_FLOAT32
:
1231 *datatype
= GL_FLOAT
;
1234 case MESA_FORMAT_RGB_FLOAT16
:
1235 *datatype
= GL_HALF_FLOAT_ARB
;
1238 case MESA_FORMAT_LA_FLOAT32
:
1239 case MESA_FORMAT_RG_FLOAT32
:
1240 *datatype
= GL_FLOAT
;
1243 case MESA_FORMAT_LA_FLOAT16
:
1244 case MESA_FORMAT_RG_FLOAT16
:
1245 *datatype
= GL_HALF_FLOAT_ARB
;
1248 case MESA_FORMAT_A_FLOAT32
:
1249 case MESA_FORMAT_L_FLOAT32
:
1250 case MESA_FORMAT_I_FLOAT32
:
1251 case MESA_FORMAT_R_FLOAT32
:
1252 *datatype
= GL_FLOAT
;
1255 case MESA_FORMAT_A_FLOAT16
:
1256 case MESA_FORMAT_L_FLOAT16
:
1257 case MESA_FORMAT_I_FLOAT16
:
1258 case MESA_FORMAT_R_FLOAT16
:
1259 *datatype
= GL_HALF_FLOAT_ARB
;
1263 case MESA_FORMAT_A_UINT8
:
1264 case MESA_FORMAT_L_UINT8
:
1265 case MESA_FORMAT_I_UINT8
:
1266 *datatype
= GL_UNSIGNED_BYTE
;
1269 case MESA_FORMAT_LA_UINT8
:
1270 *datatype
= GL_UNSIGNED_BYTE
;
1274 case MESA_FORMAT_A_UINT16
:
1275 case MESA_FORMAT_L_UINT16
:
1276 case MESA_FORMAT_I_UINT16
:
1277 *datatype
= GL_UNSIGNED_SHORT
;
1280 case MESA_FORMAT_LA_UINT16
:
1281 *datatype
= GL_UNSIGNED_SHORT
;
1284 case MESA_FORMAT_A_UINT32
:
1285 case MESA_FORMAT_L_UINT32
:
1286 case MESA_FORMAT_I_UINT32
:
1287 *datatype
= GL_UNSIGNED_INT
;
1290 case MESA_FORMAT_LA_UINT32
:
1291 *datatype
= GL_UNSIGNED_INT
;
1294 case MESA_FORMAT_A_SINT8
:
1295 case MESA_FORMAT_L_SINT8
:
1296 case MESA_FORMAT_I_SINT8
:
1297 *datatype
= GL_BYTE
;
1300 case MESA_FORMAT_LA_SINT8
:
1301 *datatype
= GL_BYTE
;
1305 case MESA_FORMAT_A_SINT16
:
1306 case MESA_FORMAT_L_SINT16
:
1307 case MESA_FORMAT_I_SINT16
:
1308 *datatype
= GL_SHORT
;
1311 case MESA_FORMAT_LA_SINT16
:
1312 *datatype
= GL_SHORT
;
1316 case MESA_FORMAT_A_SINT32
:
1317 case MESA_FORMAT_L_SINT32
:
1318 case MESA_FORMAT_I_SINT32
:
1322 case MESA_FORMAT_LA_SINT32
:
1327 case MESA_FORMAT_R_SINT8
:
1328 *datatype
= GL_BYTE
;
1331 case MESA_FORMAT_RG_SINT8
:
1332 *datatype
= GL_BYTE
;
1335 case MESA_FORMAT_RGB_SINT8
:
1336 *datatype
= GL_BYTE
;
1339 case MESA_FORMAT_RGBA_SINT8
:
1340 *datatype
= GL_BYTE
;
1343 case MESA_FORMAT_R_SINT16
:
1344 *datatype
= GL_SHORT
;
1347 case MESA_FORMAT_RG_SINT16
:
1348 *datatype
= GL_SHORT
;
1351 case MESA_FORMAT_RGB_SINT16
:
1352 *datatype
= GL_SHORT
;
1355 case MESA_FORMAT_RGBA_SINT16
:
1356 *datatype
= GL_SHORT
;
1359 case MESA_FORMAT_R_SINT32
:
1363 case MESA_FORMAT_RG_SINT32
:
1367 case MESA_FORMAT_RGB_SINT32
:
1371 case MESA_FORMAT_RGBA_SINT32
:
1377 * \name Non-normalized unsigned integer formats.
1379 case MESA_FORMAT_R_UINT8
:
1380 *datatype
= GL_UNSIGNED_BYTE
;
1383 case MESA_FORMAT_RG_UINT8
:
1384 *datatype
= GL_UNSIGNED_BYTE
;
1387 case MESA_FORMAT_RGB_UINT8
:
1388 *datatype
= GL_UNSIGNED_BYTE
;
1391 case MESA_FORMAT_RGBA_UINT8
:
1392 *datatype
= GL_UNSIGNED_BYTE
;
1395 case MESA_FORMAT_R_UINT16
:
1396 *datatype
= GL_UNSIGNED_SHORT
;
1399 case MESA_FORMAT_RG_UINT16
:
1400 *datatype
= GL_UNSIGNED_SHORT
;
1403 case MESA_FORMAT_RGB_UINT16
:
1404 *datatype
= GL_UNSIGNED_SHORT
;
1407 case MESA_FORMAT_RGBA_UINT16
:
1408 *datatype
= GL_UNSIGNED_SHORT
;
1411 case MESA_FORMAT_R_UINT32
:
1412 *datatype
= GL_UNSIGNED_INT
;
1415 case MESA_FORMAT_RG_UINT32
:
1416 *datatype
= GL_UNSIGNED_INT
;
1419 case MESA_FORMAT_RGB_UINT32
:
1420 *datatype
= GL_UNSIGNED_INT
;
1423 case MESA_FORMAT_RGBA_UINT32
:
1424 *datatype
= GL_UNSIGNED_INT
;
1428 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1429 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1433 case MESA_FORMAT_R11G11B10_FLOAT
:
1434 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1438 case MESA_FORMAT_B10G10R10A2_UINT
:
1439 case MESA_FORMAT_R10G10B10A2_UINT
:
1440 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1444 case MESA_FORMAT_R8G8B8X8_SRGB
:
1445 case MESA_FORMAT_X8B8G8R8_SRGB
:
1446 case MESA_FORMAT_RGBX_UINT8
:
1447 *datatype
= GL_UNSIGNED_BYTE
;
1451 case MESA_FORMAT_R8G8B8X8_SNORM
:
1452 case MESA_FORMAT_RGBX_SINT8
:
1453 *datatype
= GL_BYTE
;
1457 case MESA_FORMAT_B10G10R10X2_UNORM
:
1458 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1462 case MESA_FORMAT_RGBX_UNORM16
:
1463 case MESA_FORMAT_RGBX_UINT16
:
1464 *datatype
= GL_UNSIGNED_SHORT
;
1468 case MESA_FORMAT_RGBX_SNORM16
:
1469 case MESA_FORMAT_RGBX_SINT16
:
1470 *datatype
= GL_SHORT
;
1474 case MESA_FORMAT_RGBX_FLOAT16
:
1475 *datatype
= GL_HALF_FLOAT
;
1479 case MESA_FORMAT_RGBX_FLOAT32
:
1480 *datatype
= GL_FLOAT
;
1484 case MESA_FORMAT_RGBX_UINT32
:
1485 *datatype
= GL_UNSIGNED_INT
;
1489 case MESA_FORMAT_RGBX_SINT32
:
1494 case MESA_FORMAT_R10G10B10A2_UNORM
:
1495 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1499 case MESA_FORMAT_G8R8_SNORM
:
1500 *datatype
= GL_BYTE
;
1504 case MESA_FORMAT_G16R16_SNORM
:
1505 *datatype
= GL_SHORT
;
1509 case MESA_FORMAT_B8G8R8X8_SRGB
:
1510 case MESA_FORMAT_X8R8G8B8_SRGB
:
1511 *datatype
= GL_UNSIGNED_BYTE
;
1515 case MESA_FORMAT_COUNT
:
1519 case MESA_FORMAT_NONE
:
1520 /* For debug builds, warn if any formats are not handled */
1524 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1525 _mesa_get_format_name(format
));
1532 * Check if a mesa_format exactly matches a GL format/type combination
1533 * such that we can use memcpy() from one to the other.
1534 * \param mesa_format a MESA_FORMAT_x value
1535 * \param format the user-specified image format
1536 * \param type the user-specified image datatype
1537 * \param swapBytes typically the current pixel pack/unpack byteswap state
1538 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1541 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1542 GLenum format
, GLenum type
,
1543 GLboolean swapBytes
)
1545 const GLboolean littleEndian
= _mesa_little_endian();
1547 /* Note: When reading a GL format/type combination, the format lists channel
1548 * assignments from most significant channel in the type to least
1549 * significant. A type with _REV indicates that the assignments are
1550 * swapped, so they are listed from least significant to most significant.
1552 * For sanity, please keep this switch statement ordered the same as the
1553 * enums in formats.h.
1556 switch (mesa_format
) {
1558 case MESA_FORMAT_NONE
:
1559 case MESA_FORMAT_COUNT
:
1562 case MESA_FORMAT_A8B8G8R8_UNORM
:
1563 case MESA_FORMAT_A8B8G8R8_SRGB
:
1564 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1567 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1570 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1573 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1577 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1581 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1586 case MESA_FORMAT_R8G8B8A8_UNORM
:
1587 case MESA_FORMAT_R8G8B8A8_SRGB
:
1588 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1592 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1595 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1598 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1602 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1606 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1611 case MESA_FORMAT_B8G8R8A8_UNORM
:
1612 case MESA_FORMAT_B8G8R8A8_SRGB
:
1613 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1617 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1620 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1625 case MESA_FORMAT_A8R8G8B8_UNORM
:
1626 case MESA_FORMAT_A8R8G8B8_SRGB
:
1627 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1630 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1634 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1639 case MESA_FORMAT_X8B8G8R8_UNORM
:
1640 case MESA_FORMAT_R8G8B8X8_UNORM
:
1643 case MESA_FORMAT_B8G8R8X8_UNORM
:
1644 case MESA_FORMAT_X8R8G8B8_UNORM
:
1647 case MESA_FORMAT_BGR_UNORM8
:
1648 case MESA_FORMAT_BGR_SRGB8
:
1649 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1651 case MESA_FORMAT_RGB_UNORM8
:
1652 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1654 case MESA_FORMAT_B5G6R5_UNORM
:
1655 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1656 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1659 case MESA_FORMAT_R5G6B5_UNORM
:
1660 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1661 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1664 case MESA_FORMAT_B4G4R4A4_UNORM
:
1665 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1668 case MESA_FORMAT_A4R4G4B4_UNORM
:
1671 case MESA_FORMAT_A1B5G5R5_UNORM
:
1672 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1675 case MESA_FORMAT_B5G5R5A1_UNORM
:
1676 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1679 case MESA_FORMAT_A1R5G5B5_UNORM
:
1680 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1683 case MESA_FORMAT_L4A4_UNORM
:
1685 case MESA_FORMAT_L8A8_UNORM
:
1686 case MESA_FORMAT_L8A8_SRGB
:
1687 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1688 case MESA_FORMAT_A8L8_UNORM
:
1689 case MESA_FORMAT_A8L8_SRGB
:
1692 case MESA_FORMAT_L16A16_UNORM
:
1693 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1694 case MESA_FORMAT_A16L16_UNORM
:
1697 case MESA_FORMAT_B2G3R3_UNORM
:
1698 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1700 case MESA_FORMAT_R3G3B2_UNORM
:
1701 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1703 case MESA_FORMAT_A4B4G4R4_UNORM
:
1704 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1707 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1710 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1713 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1718 case MESA_FORMAT_R4G4B4A4_UNORM
:
1719 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1722 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1725 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1728 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1733 case MESA_FORMAT_R1G5B5A5_UNORM
:
1734 return format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
;
1736 case MESA_FORMAT_R5G5B5A1_UNORM
:
1737 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1739 case MESA_FORMAT_A5B5G5R1_UNORM
:
1740 return format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1742 case MESA_FORMAT_A2B10G10R10_UNORM
:
1743 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1745 case MESA_FORMAT_A2B10G10R10_UINT
:
1746 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1748 case MESA_FORMAT_A2R10G10B10_UNORM
:
1749 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1751 case MESA_FORMAT_A2R10G10B10_UINT
:
1752 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1754 case MESA_FORMAT_R2G10B10A10_UNORM
:
1755 return format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1757 case MESA_FORMAT_A10B10G10R2_UNORM
:
1758 return format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
;
1760 case MESA_FORMAT_A_UNORM8
:
1761 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1762 case MESA_FORMAT_A_UNORM16
:
1763 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1764 case MESA_FORMAT_L_UNORM8
:
1765 case MESA_FORMAT_L_SRGB8
:
1766 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1767 case MESA_FORMAT_L_UNORM16
:
1768 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1769 case MESA_FORMAT_I_UNORM8
:
1770 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1771 case MESA_FORMAT_I_UNORM16
:
1772 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1774 case MESA_FORMAT_YCBCR
:
1775 return format
== GL_YCBCR_MESA
&&
1776 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1777 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1778 case MESA_FORMAT_YCBCR_REV
:
1779 return format
== GL_YCBCR_MESA
&&
1780 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1781 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1783 case MESA_FORMAT_R_UNORM8
:
1784 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1785 case MESA_FORMAT_R8G8_UNORM
:
1786 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1787 case MESA_FORMAT_G8R8_UNORM
:
1790 case MESA_FORMAT_R_UNORM16
:
1791 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1793 case MESA_FORMAT_R16G16_UNORM
:
1794 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1796 case MESA_FORMAT_G16R16_UNORM
:
1799 case MESA_FORMAT_B10G10R10A2_UNORM
:
1800 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1803 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1804 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1806 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1807 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1810 case MESA_FORMAT_Z_UNORM16
:
1811 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1814 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1817 case MESA_FORMAT_Z_UNORM32
:
1818 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1821 case MESA_FORMAT_S_UINT8
:
1822 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1824 case MESA_FORMAT_SRGB_DXT1
:
1825 case MESA_FORMAT_SRGBA_DXT1
:
1826 case MESA_FORMAT_SRGBA_DXT3
:
1827 case MESA_FORMAT_SRGBA_DXT5
:
1830 case MESA_FORMAT_RGB_FXT1
:
1831 case MESA_FORMAT_RGBA_FXT1
:
1832 case MESA_FORMAT_RGB_DXT1
:
1833 case MESA_FORMAT_RGBA_DXT1
:
1834 case MESA_FORMAT_RGBA_DXT3
:
1835 case MESA_FORMAT_RGBA_DXT5
:
1838 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1839 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1840 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1841 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1844 case MESA_FORMAT_RGBA_FLOAT32
:
1845 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1846 case MESA_FORMAT_RGBA_FLOAT16
:
1847 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1849 case MESA_FORMAT_RGB_FLOAT32
:
1850 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1851 case MESA_FORMAT_RGB_FLOAT16
:
1852 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1854 case MESA_FORMAT_A_FLOAT32
:
1855 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1856 case MESA_FORMAT_A_FLOAT16
:
1857 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1859 case MESA_FORMAT_L_FLOAT32
:
1860 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1861 case MESA_FORMAT_L_FLOAT16
:
1862 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1864 case MESA_FORMAT_LA_FLOAT32
:
1865 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1866 case MESA_FORMAT_LA_FLOAT16
:
1867 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1869 case MESA_FORMAT_I_FLOAT32
:
1870 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1871 case MESA_FORMAT_I_FLOAT16
:
1872 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1874 case MESA_FORMAT_R_FLOAT32
:
1875 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1876 case MESA_FORMAT_R_FLOAT16
:
1877 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1879 case MESA_FORMAT_RG_FLOAT32
:
1880 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1881 case MESA_FORMAT_RG_FLOAT16
:
1882 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1884 case MESA_FORMAT_A_UINT8
:
1885 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1886 case MESA_FORMAT_A_UINT16
:
1887 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1889 case MESA_FORMAT_A_UINT32
:
1890 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1892 case MESA_FORMAT_A_SINT8
:
1893 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1894 case MESA_FORMAT_A_SINT16
:
1895 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1896 case MESA_FORMAT_A_SINT32
:
1897 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1899 case MESA_FORMAT_I_UINT8
:
1900 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1901 case MESA_FORMAT_I_UINT16
:
1902 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1903 case MESA_FORMAT_I_UINT32
:
1904 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1905 case MESA_FORMAT_I_SINT8
:
1906 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1907 case MESA_FORMAT_I_SINT16
:
1908 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1909 case MESA_FORMAT_I_SINT32
:
1910 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1912 case MESA_FORMAT_L_UINT8
:
1913 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1914 case MESA_FORMAT_L_UINT16
:
1915 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1917 case MESA_FORMAT_L_UINT32
:
1918 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1920 case MESA_FORMAT_L_SINT8
:
1921 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1922 case MESA_FORMAT_L_SINT16
:
1923 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1925 case MESA_FORMAT_L_SINT32
:
1926 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1928 case MESA_FORMAT_LA_UINT8
:
1929 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1930 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1931 case MESA_FORMAT_LA_UINT16
:
1932 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1933 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1934 case MESA_FORMAT_LA_UINT32
:
1935 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1936 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1937 case MESA_FORMAT_LA_SINT8
:
1938 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1940 case MESA_FORMAT_LA_SINT16
:
1941 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1943 case MESA_FORMAT_LA_SINT32
:
1944 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1947 case MESA_FORMAT_R_SINT8
:
1948 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1949 case MESA_FORMAT_RG_SINT8
:
1950 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1951 case MESA_FORMAT_RGB_SINT8
:
1952 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1953 case MESA_FORMAT_RGBA_SINT8
:
1954 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1955 case MESA_FORMAT_R_SINT16
:
1956 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1957 case MESA_FORMAT_RG_SINT16
:
1958 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1959 case MESA_FORMAT_RGB_SINT16
:
1960 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1961 case MESA_FORMAT_RGBA_SINT16
:
1962 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1963 case MESA_FORMAT_R_SINT32
:
1964 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1965 case MESA_FORMAT_RG_SINT32
:
1966 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1967 case MESA_FORMAT_RGB_SINT32
:
1968 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1969 case MESA_FORMAT_RGBA_SINT32
:
1970 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1972 case MESA_FORMAT_R_UINT8
:
1973 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1974 case MESA_FORMAT_RG_UINT8
:
1975 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1976 case MESA_FORMAT_RGB_UINT8
:
1977 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1978 case MESA_FORMAT_RGBA_UINT8
:
1979 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1981 case MESA_FORMAT_R_UINT16
:
1982 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1984 case MESA_FORMAT_RG_UINT16
:
1985 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1986 case MESA_FORMAT_RGB_UINT16
:
1987 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1989 case MESA_FORMAT_RGBA_UINT16
:
1990 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1992 case MESA_FORMAT_R_UINT32
:
1993 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1994 case MESA_FORMAT_RG_UINT32
:
1995 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1996 case MESA_FORMAT_RGB_UINT32
:
1997 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1998 case MESA_FORMAT_RGBA_UINT32
:
1999 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
2001 case MESA_FORMAT_R_SNORM8
:
2002 return format
== GL_RED
&& type
== GL_BYTE
;
2003 case MESA_FORMAT_R8G8_SNORM
:
2004 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
2006 case MESA_FORMAT_X8B8G8R8_SNORM
:
2009 case MESA_FORMAT_A8B8G8R8_SNORM
:
2010 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
2013 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
2018 case MESA_FORMAT_R8G8B8A8_SNORM
:
2019 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
2022 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
2027 case MESA_FORMAT_R_SNORM16
:
2028 return format
== GL_RED
&& type
== GL_SHORT
&&
2030 case MESA_FORMAT_R16G16_SNORM
:
2031 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2032 case MESA_FORMAT_RGB_SNORM16
:
2033 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2034 case MESA_FORMAT_RGBA_SNORM16
:
2035 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2036 case MESA_FORMAT_RGBA_UNORM16
:
2037 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2040 case MESA_FORMAT_R_RGTC1_UNORM
:
2041 case MESA_FORMAT_R_RGTC1_SNORM
:
2042 case MESA_FORMAT_RG_RGTC2_UNORM
:
2043 case MESA_FORMAT_RG_RGTC2_SNORM
:
2046 case MESA_FORMAT_L_LATC1_UNORM
:
2047 case MESA_FORMAT_L_LATC1_SNORM
:
2048 case MESA_FORMAT_LA_LATC2_UNORM
:
2049 case MESA_FORMAT_LA_LATC2_SNORM
:
2052 case MESA_FORMAT_ETC1_RGB8
:
2053 case MESA_FORMAT_ETC2_RGB8
:
2054 case MESA_FORMAT_ETC2_SRGB8
:
2055 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2056 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2057 case MESA_FORMAT_ETC2_R11_EAC
:
2058 case MESA_FORMAT_ETC2_RG11_EAC
:
2059 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2060 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2061 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2062 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2065 case MESA_FORMAT_A_SNORM8
:
2066 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2067 case MESA_FORMAT_L_SNORM8
:
2068 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2069 case MESA_FORMAT_L8A8_SNORM
:
2070 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2071 littleEndian
&& !swapBytes
;
2072 case MESA_FORMAT_A8L8_SNORM
:
2073 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2074 !littleEndian
&& !swapBytes
;
2075 case MESA_FORMAT_I_SNORM8
:
2076 return format
== GL_RED
&& type
== GL_BYTE
;
2077 case MESA_FORMAT_A_SNORM16
:
2078 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2079 case MESA_FORMAT_L_SNORM16
:
2080 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2081 case MESA_FORMAT_LA_SNORM16
:
2082 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2083 littleEndian
&& !swapBytes
;
2084 case MESA_FORMAT_I_SNORM16
:
2085 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2088 case MESA_FORMAT_B10G10R10A2_UINT
:
2089 return (format
== GL_BGRA_INTEGER_EXT
&&
2090 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2093 case MESA_FORMAT_R10G10B10A2_UINT
:
2094 return (format
== GL_RGBA_INTEGER_EXT
&&
2095 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2098 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2099 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2102 case MESA_FORMAT_R11G11B10_FLOAT
:
2103 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2106 case MESA_FORMAT_Z_FLOAT32
:
2107 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2109 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2110 return format
== GL_DEPTH_STENCIL
&&
2111 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2113 case MESA_FORMAT_B4G4R4X4_UNORM
:
2114 case MESA_FORMAT_B5G5R5X1_UNORM
:
2115 case MESA_FORMAT_R8G8B8X8_SNORM
:
2116 case MESA_FORMAT_R8G8B8X8_SRGB
:
2117 case MESA_FORMAT_X8B8G8R8_SRGB
:
2118 case MESA_FORMAT_RGBX_UINT8
:
2119 case MESA_FORMAT_RGBX_SINT8
:
2120 case MESA_FORMAT_B10G10R10X2_UNORM
:
2121 case MESA_FORMAT_RGBX_UNORM16
:
2122 case MESA_FORMAT_RGBX_SNORM16
:
2123 case MESA_FORMAT_RGBX_FLOAT16
:
2124 case MESA_FORMAT_RGBX_UINT16
:
2125 case MESA_FORMAT_RGBX_SINT16
:
2126 case MESA_FORMAT_RGBX_FLOAT32
:
2127 case MESA_FORMAT_RGBX_UINT32
:
2128 case MESA_FORMAT_RGBX_SINT32
:
2131 case MESA_FORMAT_R10G10B10A2_UNORM
:
2132 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2135 case MESA_FORMAT_G8R8_SNORM
:
2136 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2139 case MESA_FORMAT_G16R16_SNORM
:
2140 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2143 case MESA_FORMAT_B8G8R8X8_SRGB
:
2144 case MESA_FORMAT_X8R8G8B8_SRGB
: