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_R5G5B5A1_UNORM
:
1027 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1030 case MESA_FORMAT_A2B10G10R10_UNORM
:
1031 case MESA_FORMAT_A2B10G10R10_UINT
:
1032 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1035 case MESA_FORMAT_A2R10G10B10_UNORM
:
1036 case MESA_FORMAT_A2R10G10B10_UINT
:
1037 *datatype
= GL_UNSIGNED_INT_10_10_10_2
;
1041 case MESA_FORMAT_B2G3R3_UNORM
:
1042 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
1046 case MESA_FORMAT_A_UNORM8
:
1047 case MESA_FORMAT_L_UNORM8
:
1048 case MESA_FORMAT_I_UNORM8
:
1049 case MESA_FORMAT_R_UNORM8
:
1050 case MESA_FORMAT_S_UINT8
:
1051 *datatype
= GL_UNSIGNED_BYTE
;
1055 case MESA_FORMAT_YCBCR
:
1056 case MESA_FORMAT_YCBCR_REV
:
1057 *datatype
= GL_UNSIGNED_SHORT
;
1061 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1062 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
1066 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1067 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
1071 case MESA_FORMAT_Z_UNORM16
:
1072 *datatype
= GL_UNSIGNED_SHORT
;
1076 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1077 *datatype
= GL_UNSIGNED_INT
;
1081 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1082 *datatype
= GL_UNSIGNED_INT
;
1086 case MESA_FORMAT_Z_UNORM32
:
1087 *datatype
= GL_UNSIGNED_INT
;
1091 case MESA_FORMAT_Z_FLOAT32
:
1092 *datatype
= GL_FLOAT
;
1096 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1097 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
1101 case MESA_FORMAT_R_SNORM8
:
1102 case MESA_FORMAT_A_SNORM8
:
1103 case MESA_FORMAT_L_SNORM8
:
1104 case MESA_FORMAT_I_SNORM8
:
1105 *datatype
= GL_BYTE
;
1108 case MESA_FORMAT_R8G8_SNORM
:
1109 case MESA_FORMAT_L8A8_SNORM
:
1110 case MESA_FORMAT_A8L8_SNORM
:
1111 *datatype
= GL_BYTE
;
1114 case MESA_FORMAT_A8B8G8R8_SNORM
:
1115 case MESA_FORMAT_R8G8B8A8_SNORM
:
1116 case MESA_FORMAT_X8B8G8R8_SNORM
:
1117 *datatype
= GL_BYTE
;
1121 case MESA_FORMAT_RGBA_UNORM16
:
1122 *datatype
= GL_UNSIGNED_SHORT
;
1126 case MESA_FORMAT_R_SNORM16
:
1127 case MESA_FORMAT_A_SNORM16
:
1128 case MESA_FORMAT_L_SNORM16
:
1129 case MESA_FORMAT_I_SNORM16
:
1130 *datatype
= GL_SHORT
;
1133 case MESA_FORMAT_R16G16_SNORM
:
1134 case MESA_FORMAT_LA_SNORM16
:
1135 *datatype
= GL_SHORT
;
1138 case MESA_FORMAT_RGB_SNORM16
:
1139 *datatype
= GL_SHORT
;
1142 case MESA_FORMAT_RGBA_SNORM16
:
1143 *datatype
= GL_SHORT
;
1147 case MESA_FORMAT_BGR_SRGB8
:
1148 *datatype
= GL_UNSIGNED_BYTE
;
1151 case MESA_FORMAT_A8B8G8R8_SRGB
:
1152 case MESA_FORMAT_B8G8R8A8_SRGB
:
1153 case MESA_FORMAT_A8R8G8B8_SRGB
:
1154 case MESA_FORMAT_R8G8B8A8_SRGB
:
1155 *datatype
= GL_UNSIGNED_BYTE
;
1158 case MESA_FORMAT_L_SRGB8
:
1159 *datatype
= GL_UNSIGNED_BYTE
;
1162 case MESA_FORMAT_L8A8_SRGB
:
1163 case MESA_FORMAT_A8L8_SRGB
:
1164 *datatype
= GL_UNSIGNED_BYTE
;
1168 case MESA_FORMAT_RGB_FXT1
:
1169 case MESA_FORMAT_RGBA_FXT1
:
1170 case MESA_FORMAT_RGB_DXT1
:
1171 case MESA_FORMAT_RGBA_DXT1
:
1172 case MESA_FORMAT_RGBA_DXT3
:
1173 case MESA_FORMAT_RGBA_DXT5
:
1174 case MESA_FORMAT_SRGB_DXT1
:
1175 case MESA_FORMAT_SRGBA_DXT1
:
1176 case MESA_FORMAT_SRGBA_DXT3
:
1177 case MESA_FORMAT_SRGBA_DXT5
:
1178 case MESA_FORMAT_R_RGTC1_UNORM
:
1179 case MESA_FORMAT_R_RGTC1_SNORM
:
1180 case MESA_FORMAT_RG_RGTC2_UNORM
:
1181 case MESA_FORMAT_RG_RGTC2_SNORM
:
1182 case MESA_FORMAT_L_LATC1_UNORM
:
1183 case MESA_FORMAT_L_LATC1_SNORM
:
1184 case MESA_FORMAT_LA_LATC2_UNORM
:
1185 case MESA_FORMAT_LA_LATC2_SNORM
:
1186 case MESA_FORMAT_ETC1_RGB8
:
1187 case MESA_FORMAT_ETC2_RGB8
:
1188 case MESA_FORMAT_ETC2_SRGB8
:
1189 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1190 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1191 case MESA_FORMAT_ETC2_R11_EAC
:
1192 case MESA_FORMAT_ETC2_RG11_EAC
:
1193 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1194 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1195 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1196 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1197 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1198 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1199 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1200 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1201 /* XXX generate error instead? */
1202 *datatype
= GL_UNSIGNED_BYTE
;
1206 case MESA_FORMAT_RGBA_FLOAT32
:
1207 *datatype
= GL_FLOAT
;
1210 case MESA_FORMAT_RGBA_FLOAT16
:
1211 *datatype
= GL_HALF_FLOAT_ARB
;
1214 case MESA_FORMAT_RGB_FLOAT32
:
1215 *datatype
= GL_FLOAT
;
1218 case MESA_FORMAT_RGB_FLOAT16
:
1219 *datatype
= GL_HALF_FLOAT_ARB
;
1222 case MESA_FORMAT_LA_FLOAT32
:
1223 case MESA_FORMAT_RG_FLOAT32
:
1224 *datatype
= GL_FLOAT
;
1227 case MESA_FORMAT_LA_FLOAT16
:
1228 case MESA_FORMAT_RG_FLOAT16
:
1229 *datatype
= GL_HALF_FLOAT_ARB
;
1232 case MESA_FORMAT_A_FLOAT32
:
1233 case MESA_FORMAT_L_FLOAT32
:
1234 case MESA_FORMAT_I_FLOAT32
:
1235 case MESA_FORMAT_R_FLOAT32
:
1236 *datatype
= GL_FLOAT
;
1239 case MESA_FORMAT_A_FLOAT16
:
1240 case MESA_FORMAT_L_FLOAT16
:
1241 case MESA_FORMAT_I_FLOAT16
:
1242 case MESA_FORMAT_R_FLOAT16
:
1243 *datatype
= GL_HALF_FLOAT_ARB
;
1247 case MESA_FORMAT_A_UINT8
:
1248 case MESA_FORMAT_L_UINT8
:
1249 case MESA_FORMAT_I_UINT8
:
1250 *datatype
= GL_UNSIGNED_BYTE
;
1253 case MESA_FORMAT_LA_UINT8
:
1254 *datatype
= GL_UNSIGNED_BYTE
;
1258 case MESA_FORMAT_A_UINT16
:
1259 case MESA_FORMAT_L_UINT16
:
1260 case MESA_FORMAT_I_UINT16
:
1261 *datatype
= GL_UNSIGNED_SHORT
;
1264 case MESA_FORMAT_LA_UINT16
:
1265 *datatype
= GL_UNSIGNED_SHORT
;
1268 case MESA_FORMAT_A_UINT32
:
1269 case MESA_FORMAT_L_UINT32
:
1270 case MESA_FORMAT_I_UINT32
:
1271 *datatype
= GL_UNSIGNED_INT
;
1274 case MESA_FORMAT_LA_UINT32
:
1275 *datatype
= GL_UNSIGNED_INT
;
1278 case MESA_FORMAT_A_SINT8
:
1279 case MESA_FORMAT_L_SINT8
:
1280 case MESA_FORMAT_I_SINT8
:
1281 *datatype
= GL_BYTE
;
1284 case MESA_FORMAT_LA_SINT8
:
1285 *datatype
= GL_BYTE
;
1289 case MESA_FORMAT_A_SINT16
:
1290 case MESA_FORMAT_L_SINT16
:
1291 case MESA_FORMAT_I_SINT16
:
1292 *datatype
= GL_SHORT
;
1295 case MESA_FORMAT_LA_SINT16
:
1296 *datatype
= GL_SHORT
;
1300 case MESA_FORMAT_A_SINT32
:
1301 case MESA_FORMAT_L_SINT32
:
1302 case MESA_FORMAT_I_SINT32
:
1306 case MESA_FORMAT_LA_SINT32
:
1311 case MESA_FORMAT_R_SINT8
:
1312 *datatype
= GL_BYTE
;
1315 case MESA_FORMAT_RG_SINT8
:
1316 *datatype
= GL_BYTE
;
1319 case MESA_FORMAT_RGB_SINT8
:
1320 *datatype
= GL_BYTE
;
1323 case MESA_FORMAT_RGBA_SINT8
:
1324 *datatype
= GL_BYTE
;
1327 case MESA_FORMAT_R_SINT16
:
1328 *datatype
= GL_SHORT
;
1331 case MESA_FORMAT_RG_SINT16
:
1332 *datatype
= GL_SHORT
;
1335 case MESA_FORMAT_RGB_SINT16
:
1336 *datatype
= GL_SHORT
;
1339 case MESA_FORMAT_RGBA_SINT16
:
1340 *datatype
= GL_SHORT
;
1343 case MESA_FORMAT_R_SINT32
:
1347 case MESA_FORMAT_RG_SINT32
:
1351 case MESA_FORMAT_RGB_SINT32
:
1355 case MESA_FORMAT_RGBA_SINT32
:
1361 * \name Non-normalized unsigned integer formats.
1363 case MESA_FORMAT_R_UINT8
:
1364 *datatype
= GL_UNSIGNED_BYTE
;
1367 case MESA_FORMAT_RG_UINT8
:
1368 *datatype
= GL_UNSIGNED_BYTE
;
1371 case MESA_FORMAT_RGB_UINT8
:
1372 *datatype
= GL_UNSIGNED_BYTE
;
1375 case MESA_FORMAT_RGBA_UINT8
:
1376 *datatype
= GL_UNSIGNED_BYTE
;
1379 case MESA_FORMAT_R_UINT16
:
1380 *datatype
= GL_UNSIGNED_SHORT
;
1383 case MESA_FORMAT_RG_UINT16
:
1384 *datatype
= GL_UNSIGNED_SHORT
;
1387 case MESA_FORMAT_RGB_UINT16
:
1388 *datatype
= GL_UNSIGNED_SHORT
;
1391 case MESA_FORMAT_RGBA_UINT16
:
1392 *datatype
= GL_UNSIGNED_SHORT
;
1395 case MESA_FORMAT_R_UINT32
:
1396 *datatype
= GL_UNSIGNED_INT
;
1399 case MESA_FORMAT_RG_UINT32
:
1400 *datatype
= GL_UNSIGNED_INT
;
1403 case MESA_FORMAT_RGB_UINT32
:
1404 *datatype
= GL_UNSIGNED_INT
;
1407 case MESA_FORMAT_RGBA_UINT32
:
1408 *datatype
= GL_UNSIGNED_INT
;
1412 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1413 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1417 case MESA_FORMAT_R11G11B10_FLOAT
:
1418 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1422 case MESA_FORMAT_B10G10R10A2_UINT
:
1423 case MESA_FORMAT_R10G10B10A2_UINT
:
1424 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1428 case MESA_FORMAT_R8G8B8X8_SRGB
:
1429 case MESA_FORMAT_X8B8G8R8_SRGB
:
1430 case MESA_FORMAT_RGBX_UINT8
:
1431 *datatype
= GL_UNSIGNED_BYTE
;
1435 case MESA_FORMAT_R8G8B8X8_SNORM
:
1436 case MESA_FORMAT_RGBX_SINT8
:
1437 *datatype
= GL_BYTE
;
1441 case MESA_FORMAT_B10G10R10X2_UNORM
:
1442 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1446 case MESA_FORMAT_RGBX_UNORM16
:
1447 case MESA_FORMAT_RGBX_UINT16
:
1448 *datatype
= GL_UNSIGNED_SHORT
;
1452 case MESA_FORMAT_RGBX_SNORM16
:
1453 case MESA_FORMAT_RGBX_SINT16
:
1454 *datatype
= GL_SHORT
;
1458 case MESA_FORMAT_RGBX_FLOAT16
:
1459 *datatype
= GL_HALF_FLOAT
;
1463 case MESA_FORMAT_RGBX_FLOAT32
:
1464 *datatype
= GL_FLOAT
;
1468 case MESA_FORMAT_RGBX_UINT32
:
1469 *datatype
= GL_UNSIGNED_INT
;
1473 case MESA_FORMAT_RGBX_SINT32
:
1478 case MESA_FORMAT_R10G10B10A2_UNORM
:
1479 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1483 case MESA_FORMAT_G8R8_SNORM
:
1484 *datatype
= GL_BYTE
;
1488 case MESA_FORMAT_G16R16_SNORM
:
1489 *datatype
= GL_SHORT
;
1493 case MESA_FORMAT_B8G8R8X8_SRGB
:
1494 case MESA_FORMAT_X8R8G8B8_SRGB
:
1495 *datatype
= GL_UNSIGNED_BYTE
;
1499 case MESA_FORMAT_COUNT
:
1503 case MESA_FORMAT_NONE
:
1504 /* For debug builds, warn if any formats are not handled */
1508 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1509 _mesa_get_format_name(format
));
1516 * Check if a mesa_format exactly matches a GL format/type combination
1517 * such that we can use memcpy() from one to the other.
1518 * \param mesa_format a MESA_FORMAT_x value
1519 * \param format the user-specified image format
1520 * \param type the user-specified image datatype
1521 * \param swapBytes typically the current pixel pack/unpack byteswap state
1522 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1525 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1526 GLenum format
, GLenum type
,
1527 GLboolean swapBytes
)
1529 const GLboolean littleEndian
= _mesa_little_endian();
1531 /* Note: When reading a GL format/type combination, the format lists channel
1532 * assignments from most significant channel in the type to least
1533 * significant. A type with _REV indicates that the assignments are
1534 * swapped, so they are listed from least significant to most significant.
1536 * For sanity, please keep this switch statement ordered the same as the
1537 * enums in formats.h.
1540 switch (mesa_format
) {
1542 case MESA_FORMAT_NONE
:
1543 case MESA_FORMAT_COUNT
:
1546 case MESA_FORMAT_A8B8G8R8_UNORM
:
1547 case MESA_FORMAT_A8B8G8R8_SRGB
:
1548 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1551 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1554 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1557 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1561 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1565 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1570 case MESA_FORMAT_R8G8B8A8_UNORM
:
1571 case MESA_FORMAT_R8G8B8A8_SRGB
:
1572 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1576 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1579 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1582 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1586 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1590 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1595 case MESA_FORMAT_B8G8R8A8_UNORM
:
1596 case MESA_FORMAT_B8G8R8A8_SRGB
:
1597 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1601 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1604 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1609 case MESA_FORMAT_A8R8G8B8_UNORM
:
1610 case MESA_FORMAT_A8R8G8B8_SRGB
:
1611 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1614 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1618 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1623 case MESA_FORMAT_X8B8G8R8_UNORM
:
1624 case MESA_FORMAT_R8G8B8X8_UNORM
:
1627 case MESA_FORMAT_B8G8R8X8_UNORM
:
1628 case MESA_FORMAT_X8R8G8B8_UNORM
:
1631 case MESA_FORMAT_BGR_UNORM8
:
1632 case MESA_FORMAT_BGR_SRGB8
:
1633 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1635 case MESA_FORMAT_RGB_UNORM8
:
1636 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1638 case MESA_FORMAT_B5G6R5_UNORM
:
1639 return ((format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1640 (format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1643 case MESA_FORMAT_R5G6B5_UNORM
:
1644 return ((format
== GL_BGR
&& type
== GL_UNSIGNED_SHORT_5_6_5
) ||
1645 (format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5_REV
)) &&
1648 case MESA_FORMAT_B4G4R4A4_UNORM
:
1649 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1652 case MESA_FORMAT_A4R4G4B4_UNORM
:
1655 case MESA_FORMAT_A1B5G5R5_UNORM
:
1656 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1659 case MESA_FORMAT_B5G5R5A1_UNORM
:
1660 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1663 case MESA_FORMAT_A1R5G5B5_UNORM
:
1664 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1667 case MESA_FORMAT_L4A4_UNORM
:
1669 case MESA_FORMAT_L8A8_UNORM
:
1670 case MESA_FORMAT_L8A8_SRGB
:
1671 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1672 case MESA_FORMAT_A8L8_UNORM
:
1673 case MESA_FORMAT_A8L8_SRGB
:
1676 case MESA_FORMAT_L16A16_UNORM
:
1677 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1678 case MESA_FORMAT_A16L16_UNORM
:
1681 case MESA_FORMAT_B2G3R3_UNORM
:
1682 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1684 case MESA_FORMAT_R3G3B2_UNORM
:
1685 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_2_3_3_REV
;
1687 case MESA_FORMAT_A4B4G4R4_UNORM
:
1688 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1691 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1694 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1697 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1702 case MESA_FORMAT_R4G4B4A4_UNORM
:
1703 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& !swapBytes
)
1706 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& swapBytes
)
1709 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&& !swapBytes
)
1712 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4
&& swapBytes
)
1717 case MESA_FORMAT_R5G5B5A1_UNORM
:
1718 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
;
1720 case MESA_FORMAT_A2B10G10R10_UNORM
:
1721 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1723 case MESA_FORMAT_A2B10G10R10_UINT
:
1724 return format
== GL_RGBA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1726 case MESA_FORMAT_A2R10G10B10_UNORM
:
1727 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1729 case MESA_FORMAT_A2R10G10B10_UINT
:
1730 return format
== GL_BGRA_INTEGER_EXT
&& type
== GL_UNSIGNED_INT_10_10_10_2
;
1732 case MESA_FORMAT_A_UNORM8
:
1733 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1734 case MESA_FORMAT_A_UNORM16
:
1735 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1736 case MESA_FORMAT_L_UNORM8
:
1737 case MESA_FORMAT_L_SRGB8
:
1738 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1739 case MESA_FORMAT_L_UNORM16
:
1740 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1741 case MESA_FORMAT_I_UNORM8
:
1742 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1743 case MESA_FORMAT_I_UNORM16
:
1744 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1746 case MESA_FORMAT_YCBCR
:
1747 return format
== GL_YCBCR_MESA
&&
1748 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1749 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1750 case MESA_FORMAT_YCBCR_REV
:
1751 return format
== GL_YCBCR_MESA
&&
1752 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1753 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1755 case MESA_FORMAT_R_UNORM8
:
1756 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1757 case MESA_FORMAT_R8G8_UNORM
:
1758 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1759 case MESA_FORMAT_G8R8_UNORM
:
1762 case MESA_FORMAT_R_UNORM16
:
1763 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1765 case MESA_FORMAT_R16G16_UNORM
:
1766 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1768 case MESA_FORMAT_G16R16_UNORM
:
1771 case MESA_FORMAT_B10G10R10A2_UNORM
:
1772 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1775 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1776 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1778 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1779 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1782 case MESA_FORMAT_Z_UNORM16
:
1783 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1786 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1789 case MESA_FORMAT_Z_UNORM32
:
1790 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1793 case MESA_FORMAT_S_UINT8
:
1794 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1796 case MESA_FORMAT_SRGB_DXT1
:
1797 case MESA_FORMAT_SRGBA_DXT1
:
1798 case MESA_FORMAT_SRGBA_DXT3
:
1799 case MESA_FORMAT_SRGBA_DXT5
:
1802 case MESA_FORMAT_RGB_FXT1
:
1803 case MESA_FORMAT_RGBA_FXT1
:
1804 case MESA_FORMAT_RGB_DXT1
:
1805 case MESA_FORMAT_RGBA_DXT1
:
1806 case MESA_FORMAT_RGBA_DXT3
:
1807 case MESA_FORMAT_RGBA_DXT5
:
1810 case MESA_FORMAT_BPTC_RGBA_UNORM
:
1811 case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM
:
1812 case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT
:
1813 case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT
:
1816 case MESA_FORMAT_RGBA_FLOAT32
:
1817 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1818 case MESA_FORMAT_RGBA_FLOAT16
:
1819 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1821 case MESA_FORMAT_RGB_FLOAT32
:
1822 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1823 case MESA_FORMAT_RGB_FLOAT16
:
1824 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1826 case MESA_FORMAT_A_FLOAT32
:
1827 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1828 case MESA_FORMAT_A_FLOAT16
:
1829 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1831 case MESA_FORMAT_L_FLOAT32
:
1832 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1833 case MESA_FORMAT_L_FLOAT16
:
1834 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1836 case MESA_FORMAT_LA_FLOAT32
:
1837 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1838 case MESA_FORMAT_LA_FLOAT16
:
1839 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1841 case MESA_FORMAT_I_FLOAT32
:
1842 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1843 case MESA_FORMAT_I_FLOAT16
:
1844 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1846 case MESA_FORMAT_R_FLOAT32
:
1847 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1848 case MESA_FORMAT_R_FLOAT16
:
1849 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1851 case MESA_FORMAT_RG_FLOAT32
:
1852 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1853 case MESA_FORMAT_RG_FLOAT16
:
1854 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1856 case MESA_FORMAT_A_UINT8
:
1857 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1858 case MESA_FORMAT_A_UINT16
:
1859 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1861 case MESA_FORMAT_A_UINT32
:
1862 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1864 case MESA_FORMAT_A_SINT8
:
1865 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1866 case MESA_FORMAT_A_SINT16
:
1867 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1868 case MESA_FORMAT_A_SINT32
:
1869 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1871 case MESA_FORMAT_I_UINT8
:
1872 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1873 case MESA_FORMAT_I_UINT16
:
1874 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1875 case MESA_FORMAT_I_UINT32
:
1876 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1877 case MESA_FORMAT_I_SINT8
:
1878 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1879 case MESA_FORMAT_I_SINT16
:
1880 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1881 case MESA_FORMAT_I_SINT32
:
1882 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1884 case MESA_FORMAT_L_UINT8
:
1885 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1886 case MESA_FORMAT_L_UINT16
:
1887 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1889 case MESA_FORMAT_L_UINT32
:
1890 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1892 case MESA_FORMAT_L_SINT8
:
1893 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1894 case MESA_FORMAT_L_SINT16
:
1895 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1897 case MESA_FORMAT_L_SINT32
:
1898 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1900 case MESA_FORMAT_LA_UINT8
:
1901 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1902 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1903 case MESA_FORMAT_LA_UINT16
:
1904 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1905 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1906 case MESA_FORMAT_LA_UINT32
:
1907 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1908 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1909 case MESA_FORMAT_LA_SINT8
:
1910 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1912 case MESA_FORMAT_LA_SINT16
:
1913 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1915 case MESA_FORMAT_LA_SINT32
:
1916 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1919 case MESA_FORMAT_R_SINT8
:
1920 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1921 case MESA_FORMAT_RG_SINT8
:
1922 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1923 case MESA_FORMAT_RGB_SINT8
:
1924 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1925 case MESA_FORMAT_RGBA_SINT8
:
1926 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1927 case MESA_FORMAT_R_SINT16
:
1928 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1929 case MESA_FORMAT_RG_SINT16
:
1930 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1931 case MESA_FORMAT_RGB_SINT16
:
1932 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1933 case MESA_FORMAT_RGBA_SINT16
:
1934 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1935 case MESA_FORMAT_R_SINT32
:
1936 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1937 case MESA_FORMAT_RG_SINT32
:
1938 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1939 case MESA_FORMAT_RGB_SINT32
:
1940 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1941 case MESA_FORMAT_RGBA_SINT32
:
1942 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1944 case MESA_FORMAT_R_UINT8
:
1945 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1946 case MESA_FORMAT_RG_UINT8
:
1947 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1948 case MESA_FORMAT_RGB_UINT8
:
1949 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1950 case MESA_FORMAT_RGBA_UINT8
:
1951 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1953 case MESA_FORMAT_R_UINT16
:
1954 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1956 case MESA_FORMAT_RG_UINT16
:
1957 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1958 case MESA_FORMAT_RGB_UINT16
:
1959 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1961 case MESA_FORMAT_RGBA_UINT16
:
1962 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1964 case MESA_FORMAT_R_UINT32
:
1965 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1966 case MESA_FORMAT_RG_UINT32
:
1967 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1968 case MESA_FORMAT_RGB_UINT32
:
1969 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1970 case MESA_FORMAT_RGBA_UINT32
:
1971 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1973 case MESA_FORMAT_R_SNORM8
:
1974 return format
== GL_RED
&& type
== GL_BYTE
;
1975 case MESA_FORMAT_R8G8_SNORM
:
1976 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1978 case MESA_FORMAT_X8B8G8R8_SNORM
:
1981 case MESA_FORMAT_A8B8G8R8_SNORM
:
1982 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1985 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1990 case MESA_FORMAT_R8G8B8A8_SNORM
:
1991 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1994 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1999 case MESA_FORMAT_R_SNORM16
:
2000 return format
== GL_RED
&& type
== GL_SHORT
&&
2002 case MESA_FORMAT_R16G16_SNORM
:
2003 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
2004 case MESA_FORMAT_RGB_SNORM16
:
2005 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
2006 case MESA_FORMAT_RGBA_SNORM16
:
2007 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
2008 case MESA_FORMAT_RGBA_UNORM16
:
2009 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
2012 case MESA_FORMAT_R_RGTC1_UNORM
:
2013 case MESA_FORMAT_R_RGTC1_SNORM
:
2014 case MESA_FORMAT_RG_RGTC2_UNORM
:
2015 case MESA_FORMAT_RG_RGTC2_SNORM
:
2018 case MESA_FORMAT_L_LATC1_UNORM
:
2019 case MESA_FORMAT_L_LATC1_SNORM
:
2020 case MESA_FORMAT_LA_LATC2_UNORM
:
2021 case MESA_FORMAT_LA_LATC2_SNORM
:
2024 case MESA_FORMAT_ETC1_RGB8
:
2025 case MESA_FORMAT_ETC2_RGB8
:
2026 case MESA_FORMAT_ETC2_SRGB8
:
2027 case MESA_FORMAT_ETC2_RGBA8_EAC
:
2028 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
2029 case MESA_FORMAT_ETC2_R11_EAC
:
2030 case MESA_FORMAT_ETC2_RG11_EAC
:
2031 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
2032 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
2033 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
2034 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
2037 case MESA_FORMAT_A_SNORM8
:
2038 return format
== GL_ALPHA
&& type
== GL_BYTE
;
2039 case MESA_FORMAT_L_SNORM8
:
2040 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
2041 case MESA_FORMAT_L8A8_SNORM
:
2042 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2043 littleEndian
&& !swapBytes
;
2044 case MESA_FORMAT_A8L8_SNORM
:
2045 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
2046 !littleEndian
&& !swapBytes
;
2047 case MESA_FORMAT_I_SNORM8
:
2048 return format
== GL_RED
&& type
== GL_BYTE
;
2049 case MESA_FORMAT_A_SNORM16
:
2050 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
2051 case MESA_FORMAT_L_SNORM16
:
2052 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
2053 case MESA_FORMAT_LA_SNORM16
:
2054 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
2055 littleEndian
&& !swapBytes
;
2056 case MESA_FORMAT_I_SNORM16
:
2057 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
2060 case MESA_FORMAT_B10G10R10A2_UINT
:
2061 return (format
== GL_BGRA_INTEGER_EXT
&&
2062 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2065 case MESA_FORMAT_R10G10B10A2_UINT
:
2066 return (format
== GL_RGBA_INTEGER_EXT
&&
2067 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2070 case MESA_FORMAT_R9G9B9E5_FLOAT
:
2071 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
2074 case MESA_FORMAT_R11G11B10_FLOAT
:
2075 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
2078 case MESA_FORMAT_Z_FLOAT32
:
2079 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
2081 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2082 return format
== GL_DEPTH_STENCIL
&&
2083 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
2085 case MESA_FORMAT_B4G4R4X4_UNORM
:
2086 case MESA_FORMAT_B5G5R5X1_UNORM
:
2087 case MESA_FORMAT_R8G8B8X8_SNORM
:
2088 case MESA_FORMAT_R8G8B8X8_SRGB
:
2089 case MESA_FORMAT_X8B8G8R8_SRGB
:
2090 case MESA_FORMAT_RGBX_UINT8
:
2091 case MESA_FORMAT_RGBX_SINT8
:
2092 case MESA_FORMAT_B10G10R10X2_UNORM
:
2093 case MESA_FORMAT_RGBX_UNORM16
:
2094 case MESA_FORMAT_RGBX_SNORM16
:
2095 case MESA_FORMAT_RGBX_FLOAT16
:
2096 case MESA_FORMAT_RGBX_UINT16
:
2097 case MESA_FORMAT_RGBX_SINT16
:
2098 case MESA_FORMAT_RGBX_FLOAT32
:
2099 case MESA_FORMAT_RGBX_UINT32
:
2100 case MESA_FORMAT_RGBX_SINT32
:
2103 case MESA_FORMAT_R10G10B10A2_UNORM
:
2104 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2107 case MESA_FORMAT_G8R8_SNORM
:
2108 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
2111 case MESA_FORMAT_G16R16_SNORM
:
2112 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
2115 case MESA_FORMAT_B8G8R8X8_SRGB
:
2116 case MESA_FORMAT_X8R8G8B8_SRGB
: