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
;
76 #include "format_info.c"
78 static const struct gl_format_info
*
79 _mesa_get_format_info(mesa_format format
)
81 const struct gl_format_info
*info
= &format_info
[format
];
82 assert(info
->Name
== format
);
87 /** Return string name of format (for debugging) */
89 _mesa_get_format_name(mesa_format format
)
91 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
98 * Return bytes needed to store a block of pixels in the given format.
99 * Normally, a block is 1x1 (a single pixel). But for compressed formats
100 * a block may be 4x4 or 8x4, etc.
102 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
105 _mesa_get_format_bytes(mesa_format format
)
107 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
108 ASSERT(info
->BytesPerBlock
);
109 ASSERT(info
->BytesPerBlock
<= MAX_PIXEL_BYTES
||
110 _mesa_is_format_compressed(format
));
111 return info
->BytesPerBlock
;
116 * Return bits per component for the given format.
117 * \param format one of MESA_FORMAT_x
118 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
121 _mesa_get_format_bits(mesa_format format
, GLenum pname
)
123 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
127 case GL_TEXTURE_RED_SIZE
:
128 case GL_RENDERBUFFER_RED_SIZE_EXT
:
129 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
130 return info
->RedBits
;
132 case GL_TEXTURE_GREEN_SIZE
:
133 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
134 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
135 return info
->GreenBits
;
137 case GL_TEXTURE_BLUE_SIZE
:
138 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
139 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
140 return info
->BlueBits
;
142 case GL_TEXTURE_ALPHA_SIZE
:
143 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
144 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
145 return info
->AlphaBits
;
146 case GL_TEXTURE_INTENSITY_SIZE
:
147 return info
->IntensityBits
;
148 case GL_TEXTURE_LUMINANCE_SIZE
:
149 return info
->LuminanceBits
;
153 case GL_TEXTURE_DEPTH_SIZE_ARB
:
154 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
155 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
156 return info
->DepthBits
;
157 case GL_STENCIL_BITS
:
158 case GL_TEXTURE_STENCIL_SIZE_EXT
:
159 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
160 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
161 return info
->StencilBits
;
163 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
170 _mesa_get_format_max_bits(mesa_format format
)
172 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
173 GLuint max
= MAX2(info
->RedBits
, info
->GreenBits
);
174 max
= MAX2(max
, info
->BlueBits
);
175 max
= MAX2(max
, info
->AlphaBits
);
176 max
= MAX2(max
, info
->LuminanceBits
);
177 max
= MAX2(max
, info
->IntensityBits
);
178 max
= MAX2(max
, info
->DepthBits
);
179 max
= MAX2(max
, info
->StencilBits
);
185 * Return the layout type of the given format.
186 * The return value will be one of:
187 * MESA_FORMAT_LAYOUT_ARRAY
188 * MESA_FORMAT_LAYOUT_PACKED
189 * MESA_FORMAT_LAYOUT_OTHER
191 extern enum mesa_format_layout
192 _mesa_get_format_layout(mesa_format format
)
194 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
200 * Return the data type (or more specifically, the data representation)
201 * for the given format.
202 * The return value will be one of:
203 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
204 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
205 * GL_UNSIGNED_INT = an ordinary unsigned integer
206 * GL_INT = an ordinary signed integer
207 * GL_FLOAT = an ordinary float
210 _mesa_get_format_datatype(mesa_format format
)
212 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
213 return info
->DataType
;
218 * Return the basic format for the given type. The result will be one of
219 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
220 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
223 _mesa_get_format_base_format(mesa_format format
)
225 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
226 return info
->BaseFormat
;
231 * Return the block size (in pixels) for the given format. Normally
232 * the block size is 1x1. But compressed formats will have block sizes
233 * of 4x4 or 8x4 pixels, etc.
234 * \param bw returns block width in pixels
235 * \param bh returns block height in pixels
238 _mesa_get_format_block_size(mesa_format format
, GLuint
*bw
, GLuint
*bh
)
240 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
241 *bw
= info
->BlockWidth
;
242 *bh
= info
->BlockHeight
;
247 * Returns the an array of four numbers representing the transformation
248 * from the RGBA or SZ colorspace to the given format. For array formats,
249 * the i'th RGBA component is given by:
251 * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)
252 * comp = data[swizzle[i]];
253 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)
255 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)
257 * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)
258 * // data does not contain a channel of this format
260 * For packed formats, the swizzle gives the number of components left of
261 * the least significant bit.
263 * Compressed formats have no swizzle.
266 _mesa_get_format_swizzle(mesa_format format
, uint8_t swizzle_out
[4])
268 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
269 memcpy(swizzle_out
, info
->Swizzle
, sizeof(info
->Swizzle
));
273 /** Is the given format a compressed format? */
275 _mesa_is_format_compressed(mesa_format format
)
277 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
278 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
283 * Determine if the given format represents a packed depth/stencil buffer.
286 _mesa_is_format_packed_depth_stencil(mesa_format format
)
288 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
290 return info
->BaseFormat
== GL_DEPTH_STENCIL
;
295 * Is the given format a signed/unsigned integer color format?
298 _mesa_is_format_integer_color(mesa_format format
)
300 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
301 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
) &&
302 info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
303 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
304 info
->BaseFormat
!= GL_STENCIL_INDEX
;
309 * Is the given format an unsigned integer format?
312 _mesa_is_format_unsigned(mesa_format format
)
314 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
315 return _mesa_is_type_unsigned(info
->DataType
);
320 * Does the given format store signed values?
323 _mesa_is_format_signed(mesa_format format
)
325 if (format
== MESA_FORMAT_R11G11B10_FLOAT
||
326 format
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
327 /* these packed float formats only store unsigned values */
331 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
332 return (info
->DataType
== GL_SIGNED_NORMALIZED
||
333 info
->DataType
== GL_INT
||
334 info
->DataType
== GL_FLOAT
);
339 * Is the given format an integer format?
342 _mesa_is_format_integer(mesa_format format
)
344 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
345 return (info
->DataType
== GL_INT
|| info
->DataType
== GL_UNSIGNED_INT
);
349 * Return color encoding for given format.
350 * \return GL_LINEAR or GL_SRGB
353 _mesa_get_format_color_encoding(mesa_format format
)
355 /* XXX this info should be encoded in gl_format_info */
357 case MESA_FORMAT_BGR_SRGB8
:
358 case MESA_FORMAT_A8B8G8R8_SRGB
:
359 case MESA_FORMAT_B8G8R8A8_SRGB
:
360 case MESA_FORMAT_R8G8B8A8_SRGB
:
361 case MESA_FORMAT_L_SRGB8
:
362 case MESA_FORMAT_L8A8_SRGB
:
363 case MESA_FORMAT_SRGB_DXT1
:
364 case MESA_FORMAT_SRGBA_DXT1
:
365 case MESA_FORMAT_SRGBA_DXT3
:
366 case MESA_FORMAT_SRGBA_DXT5
:
367 case MESA_FORMAT_R8G8B8X8_SRGB
:
368 case MESA_FORMAT_ETC2_SRGB8
:
369 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
370 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
371 case MESA_FORMAT_B8G8R8X8_SRGB
:
380 * Return TRUE if format is an ETC2 compressed format specified
381 * by GL_ARB_ES3_compatibility.
384 _mesa_is_format_etc2(mesa_format format
)
387 case MESA_FORMAT_ETC2_RGB8
:
388 case MESA_FORMAT_ETC2_SRGB8
:
389 case MESA_FORMAT_ETC2_RGBA8_EAC
:
390 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
391 case MESA_FORMAT_ETC2_R11_EAC
:
392 case MESA_FORMAT_ETC2_RG11_EAC
:
393 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
394 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
395 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
396 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
405 * For an sRGB format, return the corresponding linear color space format.
406 * For non-sRGB formats, return the format as-is.
409 _mesa_get_srgb_format_linear(mesa_format format
)
412 case MESA_FORMAT_BGR_SRGB8
:
413 format
= MESA_FORMAT_BGR_UNORM8
;
415 case MESA_FORMAT_A8B8G8R8_SRGB
:
416 format
= MESA_FORMAT_A8B8G8R8_UNORM
;
418 case MESA_FORMAT_B8G8R8A8_SRGB
:
419 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
421 case MESA_FORMAT_R8G8B8A8_SRGB
:
422 format
= MESA_FORMAT_R8G8B8A8_UNORM
;
424 case MESA_FORMAT_L_SRGB8
:
425 format
= MESA_FORMAT_L_UNORM8
;
427 case MESA_FORMAT_L8A8_SRGB
:
428 format
= MESA_FORMAT_L8A8_UNORM
;
430 case MESA_FORMAT_SRGB_DXT1
:
431 format
= MESA_FORMAT_RGB_DXT1
;
433 case MESA_FORMAT_SRGBA_DXT1
:
434 format
= MESA_FORMAT_RGBA_DXT1
;
436 case MESA_FORMAT_SRGBA_DXT3
:
437 format
= MESA_FORMAT_RGBA_DXT3
;
439 case MESA_FORMAT_SRGBA_DXT5
:
440 format
= MESA_FORMAT_RGBA_DXT5
;
442 case MESA_FORMAT_R8G8B8X8_SRGB
:
443 format
= MESA_FORMAT_R8G8B8X8_UNORM
;
445 case MESA_FORMAT_ETC2_SRGB8
:
446 format
= MESA_FORMAT_ETC2_RGB8
;
448 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
449 format
= MESA_FORMAT_ETC2_RGBA8_EAC
;
451 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
452 format
= MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
;
454 case MESA_FORMAT_B8G8R8X8_SRGB
:
455 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
465 * If the given format is a compressed format, return a corresponding
466 * uncompressed format.
469 _mesa_get_uncompressed_format(mesa_format format
)
472 case MESA_FORMAT_RGB_FXT1
:
473 return MESA_FORMAT_BGR_UNORM8
;
474 case MESA_FORMAT_RGBA_FXT1
:
475 return MESA_FORMAT_A8B8G8R8_UNORM
;
476 case MESA_FORMAT_RGB_DXT1
:
477 case MESA_FORMAT_SRGB_DXT1
:
478 return MESA_FORMAT_BGR_UNORM8
;
479 case MESA_FORMAT_RGBA_DXT1
:
480 case MESA_FORMAT_SRGBA_DXT1
:
481 return MESA_FORMAT_A8B8G8R8_UNORM
;
482 case MESA_FORMAT_RGBA_DXT3
:
483 case MESA_FORMAT_SRGBA_DXT3
:
484 return MESA_FORMAT_A8B8G8R8_UNORM
;
485 case MESA_FORMAT_RGBA_DXT5
:
486 case MESA_FORMAT_SRGBA_DXT5
:
487 return MESA_FORMAT_A8B8G8R8_UNORM
;
488 case MESA_FORMAT_R_RGTC1_UNORM
:
489 return MESA_FORMAT_R_UNORM8
;
490 case MESA_FORMAT_R_RGTC1_SNORM
:
491 return MESA_FORMAT_R_SNORM8
;
492 case MESA_FORMAT_RG_RGTC2_UNORM
:
493 return MESA_FORMAT_R8G8_UNORM
;
494 case MESA_FORMAT_RG_RGTC2_SNORM
:
495 return MESA_FORMAT_R8G8_SNORM
;
496 case MESA_FORMAT_L_LATC1_UNORM
:
497 return MESA_FORMAT_L_UNORM8
;
498 case MESA_FORMAT_L_LATC1_SNORM
:
499 return MESA_FORMAT_L_SNORM8
;
500 case MESA_FORMAT_LA_LATC2_UNORM
:
501 return MESA_FORMAT_L8A8_UNORM
;
502 case MESA_FORMAT_LA_LATC2_SNORM
:
503 return MESA_FORMAT_L8A8_SNORM
;
504 case MESA_FORMAT_ETC1_RGB8
:
505 case MESA_FORMAT_ETC2_RGB8
:
506 case MESA_FORMAT_ETC2_SRGB8
:
507 return MESA_FORMAT_BGR_UNORM8
;
508 case MESA_FORMAT_ETC2_RGBA8_EAC
:
509 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
510 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
511 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
512 return MESA_FORMAT_A8B8G8R8_UNORM
;
513 case MESA_FORMAT_ETC2_R11_EAC
:
514 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
515 return MESA_FORMAT_R_UNORM16
;
516 case MESA_FORMAT_ETC2_RG11_EAC
:
517 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
518 return MESA_FORMAT_R16G16_UNORM
;
521 assert(!_mesa_is_format_compressed(format
));
529 _mesa_format_num_components(mesa_format format
)
531 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
532 return ((info
->RedBits
> 0) +
533 (info
->GreenBits
> 0) +
534 (info
->BlueBits
> 0) +
535 (info
->AlphaBits
> 0) +
536 (info
->LuminanceBits
> 0) +
537 (info
->IntensityBits
> 0) +
538 (info
->DepthBits
> 0) +
539 (info
->StencilBits
> 0));
544 * Returns true if a color format has data stored in the R/G/B/A channels,
545 * given an index from 0 to 3.
548 _mesa_format_has_color_component(mesa_format format
, int component
)
550 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
552 assert(info
->BaseFormat
!= GL_DEPTH_COMPONENT
&&
553 info
->BaseFormat
!= GL_DEPTH_STENCIL
&&
554 info
->BaseFormat
!= GL_STENCIL_INDEX
);
558 return (info
->RedBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
560 return (info
->GreenBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
562 return (info
->BlueBits
+ info
->IntensityBits
+ info
->LuminanceBits
) > 0;
564 return (info
->AlphaBits
+ info
->IntensityBits
) > 0;
566 assert(!"Invalid color component: must be 0..3");
573 * Return number of bytes needed to store an image of the given size
574 * in the given format.
577 _mesa_format_image_size(mesa_format format
, GLsizei width
,
578 GLsizei height
, GLsizei depth
)
580 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
581 /* Strictly speaking, a conditional isn't needed here */
582 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
583 /* compressed format (2D only for now) */
584 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
585 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
586 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
587 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
592 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
599 * Same as _mesa_format_image_size() but returns a 64-bit value to
600 * accomodate very large textures.
603 _mesa_format_image_size64(mesa_format format
, GLsizei width
,
604 GLsizei height
, GLsizei depth
)
606 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
607 /* Strictly speaking, a conditional isn't needed here */
608 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
609 /* compressed format (2D only for now) */
610 const uint64_t bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
611 const uint64_t wblocks
= (width
+ bw
- 1) / bw
;
612 const uint64_t hblocks
= (height
+ bh
- 1) / bh
;
613 const uint64_t sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
618 const uint64_t sz
= ((uint64_t) width
*
621 info
->BytesPerBlock
);
629 _mesa_format_row_stride(mesa_format format
, GLsizei width
)
631 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
632 /* Strictly speaking, a conditional isn't needed here */
633 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
634 /* compressed format */
635 const GLuint bw
= info
->BlockWidth
;
636 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
637 const GLint stride
= wblocks
* info
->BytesPerBlock
;
641 const GLint stride
= width
* info
->BytesPerBlock
;
648 * Debug/test: check that all formats are handled in the
649 * _mesa_format_to_type_and_comps() function. When new pixel formats
650 * are added to Mesa, that function needs to be updated.
651 * This is a no-op after the first call.
654 check_format_to_type_and_comps(void)
658 for (f
= MESA_FORMAT_NONE
+ 1; f
< MESA_FORMAT_COUNT
; f
++) {
661 /* This function will emit a problem/warning if the format is
664 _mesa_format_to_type_and_comps(f
, &datatype
, &comps
);
669 * Do sanity checking of the format info table.
672 _mesa_test_formats(void)
676 STATIC_ASSERT(Elements(format_info
) == MESA_FORMAT_COUNT
);
678 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
679 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
682 assert(info
->Name
== i
);
684 if (info
->Name
== MESA_FORMAT_NONE
)
687 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
688 if (info
->RedBits
> 0) {
689 GLuint t
= info
->RedBits
+ info
->GreenBits
690 + info
->BlueBits
+ info
->AlphaBits
;
691 assert(t
/ 8 <= info
->BytesPerBlock
);
696 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
697 info
->DataType
== GL_SIGNED_NORMALIZED
||
698 info
->DataType
== GL_UNSIGNED_INT
||
699 info
->DataType
== GL_INT
||
700 info
->DataType
== GL_FLOAT
||
701 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
702 info
->DataType
== GL_NONE
);
704 if (info
->BaseFormat
== GL_RGB
) {
705 assert(info
->RedBits
> 0);
706 assert(info
->GreenBits
> 0);
707 assert(info
->BlueBits
> 0);
708 assert(info
->AlphaBits
== 0);
709 assert(info
->LuminanceBits
== 0);
710 assert(info
->IntensityBits
== 0);
712 else if (info
->BaseFormat
== GL_RGBA
) {
713 assert(info
->RedBits
> 0);
714 assert(info
->GreenBits
> 0);
715 assert(info
->BlueBits
> 0);
716 assert(info
->AlphaBits
> 0);
717 assert(info
->LuminanceBits
== 0);
718 assert(info
->IntensityBits
== 0);
720 else if (info
->BaseFormat
== GL_RG
) {
721 assert(info
->RedBits
> 0);
722 assert(info
->GreenBits
> 0);
723 assert(info
->BlueBits
== 0);
724 assert(info
->AlphaBits
== 0);
725 assert(info
->LuminanceBits
== 0);
726 assert(info
->IntensityBits
== 0);
728 else if (info
->BaseFormat
== GL_RED
) {
729 assert(info
->RedBits
> 0);
730 assert(info
->GreenBits
== 0);
731 assert(info
->BlueBits
== 0);
732 assert(info
->AlphaBits
== 0);
733 assert(info
->LuminanceBits
== 0);
734 assert(info
->IntensityBits
== 0);
736 else if (info
->BaseFormat
== GL_LUMINANCE
) {
737 assert(info
->RedBits
== 0);
738 assert(info
->GreenBits
== 0);
739 assert(info
->BlueBits
== 0);
740 assert(info
->AlphaBits
== 0);
741 assert(info
->LuminanceBits
> 0);
742 assert(info
->IntensityBits
== 0);
744 else if (info
->BaseFormat
== GL_INTENSITY
) {
745 assert(info
->RedBits
== 0);
746 assert(info
->GreenBits
== 0);
747 assert(info
->BlueBits
== 0);
748 assert(info
->AlphaBits
== 0);
749 assert(info
->LuminanceBits
== 0);
750 assert(info
->IntensityBits
> 0);
754 check_format_to_type_and_comps();
760 * Return datatype and number of components per texel for the given mesa_format.
761 * Only used for mipmap generation code.
764 _mesa_format_to_type_and_comps(mesa_format format
,
765 GLenum
*datatype
, GLuint
*comps
)
768 case MESA_FORMAT_A8B8G8R8_UNORM
:
769 case MESA_FORMAT_R8G8B8A8_UNORM
:
770 case MESA_FORMAT_B8G8R8A8_UNORM
:
771 case MESA_FORMAT_A8R8G8B8_UNORM
:
772 case MESA_FORMAT_X8B8G8R8_UNORM
:
773 case MESA_FORMAT_R8G8B8X8_UNORM
:
774 case MESA_FORMAT_B8G8R8X8_UNORM
:
775 case MESA_FORMAT_X8R8G8B8_UNORM
:
776 *datatype
= GL_UNSIGNED_BYTE
;
779 case MESA_FORMAT_BGR_UNORM8
:
780 case MESA_FORMAT_RGB_UNORM8
:
781 *datatype
= GL_UNSIGNED_BYTE
;
784 case MESA_FORMAT_B5G6R5_UNORM
:
785 case MESA_FORMAT_R5G6B5_UNORM
:
786 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
790 case MESA_FORMAT_B4G4R4A4_UNORM
:
791 case MESA_FORMAT_A4R4G4B4_UNORM
:
792 case MESA_FORMAT_B4G4R4X4_UNORM
:
793 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
797 case MESA_FORMAT_B5G5R5A1_UNORM
:
798 case MESA_FORMAT_A1R5G5B5_UNORM
:
799 case MESA_FORMAT_B5G5R5X1_UNORM
:
800 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
804 case MESA_FORMAT_B10G10R10A2_UNORM
:
805 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
809 case MESA_FORMAT_A1B5G5R5_UNORM
:
810 *datatype
= GL_UNSIGNED_SHORT_5_5_5_1
;
814 case MESA_FORMAT_L4A4_UNORM
:
815 *datatype
= MESA_UNSIGNED_BYTE_4_4
;
819 case MESA_FORMAT_L8A8_UNORM
:
820 case MESA_FORMAT_A8L8_UNORM
:
821 case MESA_FORMAT_R8G8_UNORM
:
822 case MESA_FORMAT_G8R8_UNORM
:
823 *datatype
= GL_UNSIGNED_BYTE
;
827 case MESA_FORMAT_L16A16_UNORM
:
828 case MESA_FORMAT_A16L16_UNORM
:
829 case MESA_FORMAT_R16G16_UNORM
:
830 case MESA_FORMAT_G16R16_UNORM
:
831 *datatype
= GL_UNSIGNED_SHORT
;
835 case MESA_FORMAT_R_UNORM16
:
836 case MESA_FORMAT_A_UNORM16
:
837 case MESA_FORMAT_L_UNORM16
:
838 case MESA_FORMAT_I_UNORM16
:
839 *datatype
= GL_UNSIGNED_SHORT
;
843 case MESA_FORMAT_B2G3R3_UNORM
:
844 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
848 case MESA_FORMAT_A_UNORM8
:
849 case MESA_FORMAT_L_UNORM8
:
850 case MESA_FORMAT_I_UNORM8
:
851 case MESA_FORMAT_R_UNORM8
:
852 case MESA_FORMAT_S_UINT8
:
853 *datatype
= GL_UNSIGNED_BYTE
;
857 case MESA_FORMAT_YCBCR
:
858 case MESA_FORMAT_YCBCR_REV
:
859 *datatype
= GL_UNSIGNED_SHORT
;
863 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
864 *datatype
= GL_UNSIGNED_INT_24_8_MESA
;
868 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
869 *datatype
= GL_UNSIGNED_INT_8_24_REV_MESA
;
873 case MESA_FORMAT_Z_UNORM16
:
874 *datatype
= GL_UNSIGNED_SHORT
;
878 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
879 *datatype
= GL_UNSIGNED_INT
;
883 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
884 *datatype
= GL_UNSIGNED_INT
;
888 case MESA_FORMAT_Z_UNORM32
:
889 *datatype
= GL_UNSIGNED_INT
;
893 case MESA_FORMAT_Z_FLOAT32
:
894 *datatype
= GL_FLOAT
;
898 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
899 *datatype
= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
903 case MESA_FORMAT_R_SNORM8
:
904 case MESA_FORMAT_A_SNORM8
:
905 case MESA_FORMAT_L_SNORM8
:
906 case MESA_FORMAT_I_SNORM8
:
910 case MESA_FORMAT_R8G8_SNORM
:
911 case MESA_FORMAT_L8A8_SNORM
:
915 case MESA_FORMAT_A8B8G8R8_SNORM
:
916 case MESA_FORMAT_R8G8B8A8_SNORM
:
917 case MESA_FORMAT_X8B8G8R8_SNORM
:
922 case MESA_FORMAT_RGBA_UNORM16
:
923 *datatype
= GL_UNSIGNED_SHORT
;
927 case MESA_FORMAT_R_SNORM16
:
928 case MESA_FORMAT_A_SNORM16
:
929 case MESA_FORMAT_L_SNORM16
:
930 case MESA_FORMAT_I_SNORM16
:
931 *datatype
= GL_SHORT
;
934 case MESA_FORMAT_R16G16_SNORM
:
935 case MESA_FORMAT_LA_SNORM16
:
936 *datatype
= GL_SHORT
;
939 case MESA_FORMAT_RGB_SNORM16
:
940 *datatype
= GL_SHORT
;
943 case MESA_FORMAT_RGBA_SNORM16
:
944 *datatype
= GL_SHORT
;
948 case MESA_FORMAT_BGR_SRGB8
:
949 *datatype
= GL_UNSIGNED_BYTE
;
952 case MESA_FORMAT_A8B8G8R8_SRGB
:
953 case MESA_FORMAT_B8G8R8A8_SRGB
:
954 case MESA_FORMAT_R8G8B8A8_SRGB
:
955 *datatype
= GL_UNSIGNED_BYTE
;
958 case MESA_FORMAT_L_SRGB8
:
959 *datatype
= GL_UNSIGNED_BYTE
;
962 case MESA_FORMAT_L8A8_SRGB
:
963 *datatype
= GL_UNSIGNED_BYTE
;
967 case MESA_FORMAT_RGB_FXT1
:
968 case MESA_FORMAT_RGBA_FXT1
:
969 case MESA_FORMAT_RGB_DXT1
:
970 case MESA_FORMAT_RGBA_DXT1
:
971 case MESA_FORMAT_RGBA_DXT3
:
972 case MESA_FORMAT_RGBA_DXT5
:
973 case MESA_FORMAT_SRGB_DXT1
:
974 case MESA_FORMAT_SRGBA_DXT1
:
975 case MESA_FORMAT_SRGBA_DXT3
:
976 case MESA_FORMAT_SRGBA_DXT5
:
977 case MESA_FORMAT_R_RGTC1_UNORM
:
978 case MESA_FORMAT_R_RGTC1_SNORM
:
979 case MESA_FORMAT_RG_RGTC2_UNORM
:
980 case MESA_FORMAT_RG_RGTC2_SNORM
:
981 case MESA_FORMAT_L_LATC1_UNORM
:
982 case MESA_FORMAT_L_LATC1_SNORM
:
983 case MESA_FORMAT_LA_LATC2_UNORM
:
984 case MESA_FORMAT_LA_LATC2_SNORM
:
985 case MESA_FORMAT_ETC1_RGB8
:
986 case MESA_FORMAT_ETC2_RGB8
:
987 case MESA_FORMAT_ETC2_SRGB8
:
988 case MESA_FORMAT_ETC2_RGBA8_EAC
:
989 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
990 case MESA_FORMAT_ETC2_R11_EAC
:
991 case MESA_FORMAT_ETC2_RG11_EAC
:
992 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
993 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
994 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
995 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
996 /* XXX generate error instead? */
997 *datatype
= GL_UNSIGNED_BYTE
;
1001 case MESA_FORMAT_RGBA_FLOAT32
:
1002 *datatype
= GL_FLOAT
;
1005 case MESA_FORMAT_RGBA_FLOAT16
:
1006 *datatype
= GL_HALF_FLOAT_ARB
;
1009 case MESA_FORMAT_RGB_FLOAT32
:
1010 *datatype
= GL_FLOAT
;
1013 case MESA_FORMAT_RGB_FLOAT16
:
1014 *datatype
= GL_HALF_FLOAT_ARB
;
1017 case MESA_FORMAT_LA_FLOAT32
:
1018 case MESA_FORMAT_RG_FLOAT32
:
1019 *datatype
= GL_FLOAT
;
1022 case MESA_FORMAT_LA_FLOAT16
:
1023 case MESA_FORMAT_RG_FLOAT16
:
1024 *datatype
= GL_HALF_FLOAT_ARB
;
1027 case MESA_FORMAT_A_FLOAT32
:
1028 case MESA_FORMAT_L_FLOAT32
:
1029 case MESA_FORMAT_I_FLOAT32
:
1030 case MESA_FORMAT_R_FLOAT32
:
1031 *datatype
= GL_FLOAT
;
1034 case MESA_FORMAT_A_FLOAT16
:
1035 case MESA_FORMAT_L_FLOAT16
:
1036 case MESA_FORMAT_I_FLOAT16
:
1037 case MESA_FORMAT_R_FLOAT16
:
1038 *datatype
= GL_HALF_FLOAT_ARB
;
1042 case MESA_FORMAT_A_UINT8
:
1043 case MESA_FORMAT_L_UINT8
:
1044 case MESA_FORMAT_I_UINT8
:
1045 *datatype
= GL_UNSIGNED_BYTE
;
1048 case MESA_FORMAT_LA_UINT8
:
1049 *datatype
= GL_UNSIGNED_BYTE
;
1053 case MESA_FORMAT_A_UINT16
:
1054 case MESA_FORMAT_L_UINT16
:
1055 case MESA_FORMAT_I_UINT16
:
1056 *datatype
= GL_UNSIGNED_SHORT
;
1059 case MESA_FORMAT_LA_UINT16
:
1060 *datatype
= GL_UNSIGNED_SHORT
;
1063 case MESA_FORMAT_A_UINT32
:
1064 case MESA_FORMAT_L_UINT32
:
1065 case MESA_FORMAT_I_UINT32
:
1066 *datatype
= GL_UNSIGNED_INT
;
1069 case MESA_FORMAT_LA_UINT32
:
1070 *datatype
= GL_UNSIGNED_INT
;
1073 case MESA_FORMAT_A_SINT8
:
1074 case MESA_FORMAT_L_SINT8
:
1075 case MESA_FORMAT_I_SINT8
:
1076 *datatype
= GL_BYTE
;
1079 case MESA_FORMAT_LA_SINT8
:
1080 *datatype
= GL_BYTE
;
1084 case MESA_FORMAT_A_SINT16
:
1085 case MESA_FORMAT_L_SINT16
:
1086 case MESA_FORMAT_I_SINT16
:
1087 *datatype
= GL_SHORT
;
1090 case MESA_FORMAT_LA_SINT16
:
1091 *datatype
= GL_SHORT
;
1095 case MESA_FORMAT_A_SINT32
:
1096 case MESA_FORMAT_L_SINT32
:
1097 case MESA_FORMAT_I_SINT32
:
1101 case MESA_FORMAT_LA_SINT32
:
1106 case MESA_FORMAT_R_SINT8
:
1107 *datatype
= GL_BYTE
;
1110 case MESA_FORMAT_RG_SINT8
:
1111 *datatype
= GL_BYTE
;
1114 case MESA_FORMAT_RGB_SINT8
:
1115 *datatype
= GL_BYTE
;
1118 case MESA_FORMAT_RGBA_SINT8
:
1119 *datatype
= GL_BYTE
;
1122 case MESA_FORMAT_R_SINT16
:
1123 *datatype
= GL_SHORT
;
1126 case MESA_FORMAT_RG_SINT16
:
1127 *datatype
= GL_SHORT
;
1130 case MESA_FORMAT_RGB_SINT16
:
1131 *datatype
= GL_SHORT
;
1134 case MESA_FORMAT_RGBA_SINT16
:
1135 *datatype
= GL_SHORT
;
1138 case MESA_FORMAT_R_SINT32
:
1142 case MESA_FORMAT_RG_SINT32
:
1146 case MESA_FORMAT_RGB_SINT32
:
1150 case MESA_FORMAT_RGBA_SINT32
:
1156 * \name Non-normalized unsigned integer formats.
1158 case MESA_FORMAT_R_UINT8
:
1159 *datatype
= GL_UNSIGNED_BYTE
;
1162 case MESA_FORMAT_RG_UINT8
:
1163 *datatype
= GL_UNSIGNED_BYTE
;
1166 case MESA_FORMAT_RGB_UINT8
:
1167 *datatype
= GL_UNSIGNED_BYTE
;
1170 case MESA_FORMAT_RGBA_UINT8
:
1171 *datatype
= GL_UNSIGNED_BYTE
;
1174 case MESA_FORMAT_R_UINT16
:
1175 *datatype
= GL_UNSIGNED_SHORT
;
1178 case MESA_FORMAT_RG_UINT16
:
1179 *datatype
= GL_UNSIGNED_SHORT
;
1182 case MESA_FORMAT_RGB_UINT16
:
1183 *datatype
= GL_UNSIGNED_SHORT
;
1186 case MESA_FORMAT_RGBA_UINT16
:
1187 *datatype
= GL_UNSIGNED_SHORT
;
1190 case MESA_FORMAT_R_UINT32
:
1191 *datatype
= GL_UNSIGNED_INT
;
1194 case MESA_FORMAT_RG_UINT32
:
1195 *datatype
= GL_UNSIGNED_INT
;
1198 case MESA_FORMAT_RGB_UINT32
:
1199 *datatype
= GL_UNSIGNED_INT
;
1202 case MESA_FORMAT_RGBA_UINT32
:
1203 *datatype
= GL_UNSIGNED_INT
;
1207 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1208 *datatype
= GL_UNSIGNED_INT_5_9_9_9_REV
;
1212 case MESA_FORMAT_R11G11B10_FLOAT
:
1213 *datatype
= GL_UNSIGNED_INT_10F_11F_11F_REV
;
1217 case MESA_FORMAT_B10G10R10A2_UINT
:
1218 case MESA_FORMAT_R10G10B10A2_UINT
:
1219 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1223 case MESA_FORMAT_R8G8B8X8_SRGB
:
1224 case MESA_FORMAT_RGBX_UINT8
:
1225 *datatype
= GL_UNSIGNED_BYTE
;
1229 case MESA_FORMAT_R8G8B8X8_SNORM
:
1230 case MESA_FORMAT_RGBX_SINT8
:
1231 *datatype
= GL_BYTE
;
1235 case MESA_FORMAT_B10G10R10X2_UNORM
:
1236 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1240 case MESA_FORMAT_RGBX_UNORM16
:
1241 case MESA_FORMAT_RGBX_UINT16
:
1242 *datatype
= GL_UNSIGNED_SHORT
;
1246 case MESA_FORMAT_RGBX_SNORM16
:
1247 case MESA_FORMAT_RGBX_SINT16
:
1248 *datatype
= GL_SHORT
;
1252 case MESA_FORMAT_RGBX_FLOAT16
:
1253 *datatype
= GL_HALF_FLOAT
;
1257 case MESA_FORMAT_RGBX_FLOAT32
:
1258 *datatype
= GL_FLOAT
;
1262 case MESA_FORMAT_RGBX_UINT32
:
1263 *datatype
= GL_UNSIGNED_INT
;
1267 case MESA_FORMAT_RGBX_SINT32
:
1272 case MESA_FORMAT_R10G10B10A2_UNORM
:
1273 *datatype
= GL_UNSIGNED_INT_2_10_10_10_REV
;
1277 case MESA_FORMAT_G8R8_SNORM
:
1278 *datatype
= GL_BYTE
;
1282 case MESA_FORMAT_G16R16_SNORM
:
1283 *datatype
= GL_SHORT
;
1287 case MESA_FORMAT_B8G8R8X8_SRGB
:
1288 *datatype
= GL_UNSIGNED_BYTE
;
1292 case MESA_FORMAT_COUNT
:
1296 case MESA_FORMAT_NONE
:
1297 /* For debug builds, warn if any formats are not handled */
1301 _mesa_problem(NULL
, "bad format %s in _mesa_format_to_type_and_comps",
1302 _mesa_get_format_name(format
));
1309 * Check if a mesa_format exactly matches a GL format/type combination
1310 * such that we can use memcpy() from one to the other.
1311 * \param mesa_format a MESA_FORMAT_x value
1312 * \param format the user-specified image format
1313 * \param type the user-specified image datatype
1314 * \param swapBytes typically the current pixel pack/unpack byteswap state
1315 * \return GL_TRUE if the formats match, GL_FALSE otherwise.
1318 _mesa_format_matches_format_and_type(mesa_format mesa_format
,
1319 GLenum format
, GLenum type
,
1320 GLboolean swapBytes
)
1322 const GLboolean littleEndian
= _mesa_little_endian();
1324 /* Note: When reading a GL format/type combination, the format lists channel
1325 * assignments from most significant channel in the type to least
1326 * significant. A type with _REV indicates that the assignments are
1327 * swapped, so they are listed from least significant to most significant.
1329 * For sanity, please keep this switch statement ordered the same as the
1330 * enums in formats.h.
1333 switch (mesa_format
) {
1335 case MESA_FORMAT_NONE
:
1336 case MESA_FORMAT_COUNT
:
1339 case MESA_FORMAT_A8B8G8R8_UNORM
:
1340 case MESA_FORMAT_A8B8G8R8_SRGB
:
1341 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1344 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&& swapBytes
)
1347 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1350 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
1354 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
1358 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1363 case MESA_FORMAT_R8G8B8A8_UNORM
:
1364 case MESA_FORMAT_R8G8B8A8_SRGB
:
1365 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1369 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1372 if (format
== GL_RGBA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1375 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8
&&
1379 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1383 if (format
== GL_ABGR_EXT
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1388 case MESA_FORMAT_B8G8R8A8_UNORM
:
1389 case MESA_FORMAT_B8G8R8A8_SRGB
:
1390 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1394 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& swapBytes
)
1397 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
)
1402 case MESA_FORMAT_A8R8G8B8_UNORM
:
1403 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8
&& !swapBytes
)
1406 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_8_8_8_8_REV
&&
1410 if (format
== GL_BGRA
&& type
== GL_UNSIGNED_BYTE
&& !littleEndian
)
1415 case MESA_FORMAT_X8B8G8R8_UNORM
:
1416 case MESA_FORMAT_R8G8B8X8_UNORM
:
1419 case MESA_FORMAT_B8G8R8X8_UNORM
:
1420 case MESA_FORMAT_X8R8G8B8_UNORM
:
1423 case MESA_FORMAT_BGR_UNORM8
:
1424 case MESA_FORMAT_BGR_SRGB8
:
1425 return format
== GL_BGR
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1427 case MESA_FORMAT_RGB_UNORM8
:
1428 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1430 case MESA_FORMAT_B5G6R5_UNORM
:
1431 return format
== GL_RGB
&& type
== GL_UNSIGNED_SHORT_5_6_5
&& !swapBytes
;
1433 case MESA_FORMAT_R5G6B5_UNORM
:
1434 /* Some of the 16-bit MESA_FORMATs that would seem to correspond to
1435 * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,
1436 * according to formats.h, so they can't be matched.
1440 case MESA_FORMAT_B4G4R4A4_UNORM
:
1441 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
&&
1444 case MESA_FORMAT_A4R4G4B4_UNORM
:
1447 case MESA_FORMAT_A1B5G5R5_UNORM
:
1448 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT_5_5_5_1
&&
1451 case MESA_FORMAT_B5G5R5A1_UNORM
:
1452 return format
== GL_BGRA
&& type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
&&
1455 case MESA_FORMAT_A1R5G5B5_UNORM
:
1458 case MESA_FORMAT_L4A4_UNORM
:
1460 case MESA_FORMAT_L8A8_UNORM
:
1461 case MESA_FORMAT_L8A8_SRGB
:
1462 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1463 case MESA_FORMAT_A8L8_UNORM
:
1466 case MESA_FORMAT_L16A16_UNORM
:
1467 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&& !swapBytes
;
1468 case MESA_FORMAT_A16L16_UNORM
:
1471 case MESA_FORMAT_B2G3R3_UNORM
:
1472 return format
== GL_RGB
&& type
== GL_UNSIGNED_BYTE_3_3_2
;
1474 case MESA_FORMAT_A_UNORM8
:
1475 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_BYTE
;
1476 case MESA_FORMAT_A_UNORM16
:
1477 return format
== GL_ALPHA
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1478 case MESA_FORMAT_L_UNORM8
:
1479 case MESA_FORMAT_L_SRGB8
:
1480 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_BYTE
;
1481 case MESA_FORMAT_L_UNORM16
:
1482 return format
== GL_LUMINANCE
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1483 case MESA_FORMAT_I_UNORM8
:
1484 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1485 case MESA_FORMAT_I_UNORM16
:
1486 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1488 case MESA_FORMAT_YCBCR
:
1489 return format
== GL_YCBCR_MESA
&&
1490 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
!= swapBytes
) ||
1491 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
== swapBytes
));
1492 case MESA_FORMAT_YCBCR_REV
:
1493 return format
== GL_YCBCR_MESA
&&
1494 ((type
== GL_UNSIGNED_SHORT_8_8_MESA
&& littleEndian
== swapBytes
) ||
1495 (type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
&& littleEndian
!= swapBytes
));
1497 case MESA_FORMAT_R_UNORM8
:
1498 return format
== GL_RED
&& type
== GL_UNSIGNED_BYTE
;
1499 case MESA_FORMAT_R8G8_UNORM
:
1500 return format
== GL_RG
&& type
== GL_UNSIGNED_BYTE
&& littleEndian
;
1501 case MESA_FORMAT_G8R8_UNORM
:
1504 case MESA_FORMAT_R_UNORM16
:
1505 return format
== GL_RED
&& type
== GL_UNSIGNED_SHORT
&&
1507 case MESA_FORMAT_R16G16_UNORM
:
1508 return format
== GL_RG
&& type
== GL_UNSIGNED_SHORT
&& littleEndian
&&
1510 case MESA_FORMAT_G16R16_UNORM
:
1513 case MESA_FORMAT_B10G10R10A2_UNORM
:
1514 return format
== GL_BGRA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1517 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
1518 return format
== GL_DEPTH_STENCIL
&& type
== GL_UNSIGNED_INT_24_8
&&
1520 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
1521 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
1524 case MESA_FORMAT_Z_UNORM16
:
1525 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_SHORT
&&
1528 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
1531 case MESA_FORMAT_Z_UNORM32
:
1532 return format
== GL_DEPTH_COMPONENT
&& type
== GL_UNSIGNED_INT
&&
1535 case MESA_FORMAT_S_UINT8
:
1536 return format
== GL_STENCIL_INDEX
&& type
== GL_UNSIGNED_BYTE
;
1538 case MESA_FORMAT_SRGB_DXT1
:
1539 case MESA_FORMAT_SRGBA_DXT1
:
1540 case MESA_FORMAT_SRGBA_DXT3
:
1541 case MESA_FORMAT_SRGBA_DXT5
:
1544 case MESA_FORMAT_RGB_FXT1
:
1545 case MESA_FORMAT_RGBA_FXT1
:
1546 case MESA_FORMAT_RGB_DXT1
:
1547 case MESA_FORMAT_RGBA_DXT1
:
1548 case MESA_FORMAT_RGBA_DXT3
:
1549 case MESA_FORMAT_RGBA_DXT5
:
1552 case MESA_FORMAT_RGBA_FLOAT32
:
1553 return format
== GL_RGBA
&& type
== GL_FLOAT
&& !swapBytes
;
1554 case MESA_FORMAT_RGBA_FLOAT16
:
1555 return format
== GL_RGBA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1557 case MESA_FORMAT_RGB_FLOAT32
:
1558 return format
== GL_RGB
&& type
== GL_FLOAT
&& !swapBytes
;
1559 case MESA_FORMAT_RGB_FLOAT16
:
1560 return format
== GL_RGB
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1562 case MESA_FORMAT_A_FLOAT32
:
1563 return format
== GL_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1564 case MESA_FORMAT_A_FLOAT16
:
1565 return format
== GL_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1567 case MESA_FORMAT_L_FLOAT32
:
1568 return format
== GL_LUMINANCE
&& type
== GL_FLOAT
&& !swapBytes
;
1569 case MESA_FORMAT_L_FLOAT16
:
1570 return format
== GL_LUMINANCE
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1572 case MESA_FORMAT_LA_FLOAT32
:
1573 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_FLOAT
&& !swapBytes
;
1574 case MESA_FORMAT_LA_FLOAT16
:
1575 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1577 case MESA_FORMAT_I_FLOAT32
:
1578 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1579 case MESA_FORMAT_I_FLOAT16
:
1580 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1582 case MESA_FORMAT_R_FLOAT32
:
1583 return format
== GL_RED
&& type
== GL_FLOAT
&& !swapBytes
;
1584 case MESA_FORMAT_R_FLOAT16
:
1585 return format
== GL_RED
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1587 case MESA_FORMAT_RG_FLOAT32
:
1588 return format
== GL_RG
&& type
== GL_FLOAT
&& !swapBytes
;
1589 case MESA_FORMAT_RG_FLOAT16
:
1590 return format
== GL_RG
&& type
== GL_HALF_FLOAT
&& !swapBytes
;
1592 case MESA_FORMAT_A_UINT8
:
1593 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1594 case MESA_FORMAT_A_UINT16
:
1595 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1597 case MESA_FORMAT_A_UINT32
:
1598 return format
== GL_ALPHA_INTEGER
&& type
== GL_UNSIGNED_INT
&&
1600 case MESA_FORMAT_A_SINT8
:
1601 return format
== GL_ALPHA_INTEGER
&& type
== GL_BYTE
;
1602 case MESA_FORMAT_A_SINT16
:
1603 return format
== GL_ALPHA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1604 case MESA_FORMAT_A_SINT32
:
1605 return format
== GL_ALPHA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1607 case MESA_FORMAT_I_UINT8
:
1608 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1609 case MESA_FORMAT_I_UINT16
:
1610 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1611 case MESA_FORMAT_I_UINT32
:
1612 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1613 case MESA_FORMAT_I_SINT8
:
1614 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1615 case MESA_FORMAT_I_SINT16
:
1616 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1617 case MESA_FORMAT_I_SINT32
:
1618 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1620 case MESA_FORMAT_L_UINT8
:
1621 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_BYTE
;
1622 case MESA_FORMAT_L_UINT16
:
1623 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_SHORT
&&
1625 case MESA_FORMAT_L_UINT32
:
1626 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_UNSIGNED_INT
&&
1628 case MESA_FORMAT_L_SINT8
:
1629 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_BYTE
;
1630 case MESA_FORMAT_L_SINT16
:
1631 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_SHORT
&&
1633 case MESA_FORMAT_L_SINT32
:
1634 return format
== GL_LUMINANCE_INTEGER_EXT
&& type
== GL_INT
&& !swapBytes
;
1636 case MESA_FORMAT_LA_UINT8
:
1637 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1638 type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1639 case MESA_FORMAT_LA_UINT16
:
1640 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1641 type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1642 case MESA_FORMAT_LA_UINT32
:
1643 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&&
1644 type
== GL_UNSIGNED_INT
&& !swapBytes
;
1645 case MESA_FORMAT_LA_SINT8
:
1646 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_BYTE
&&
1648 case MESA_FORMAT_LA_SINT16
:
1649 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_SHORT
&&
1651 case MESA_FORMAT_LA_SINT32
:
1652 return format
== GL_LUMINANCE_ALPHA_INTEGER_EXT
&& type
== GL_INT
&&
1655 case MESA_FORMAT_R_SINT8
:
1656 return format
== GL_RED_INTEGER
&& type
== GL_BYTE
;
1657 case MESA_FORMAT_RG_SINT8
:
1658 return format
== GL_RG_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1659 case MESA_FORMAT_RGB_SINT8
:
1660 return format
== GL_RGB_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1661 case MESA_FORMAT_RGBA_SINT8
:
1662 return format
== GL_RGBA_INTEGER
&& type
== GL_BYTE
&& !swapBytes
;
1663 case MESA_FORMAT_R_SINT16
:
1664 return format
== GL_RED_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1665 case MESA_FORMAT_RG_SINT16
:
1666 return format
== GL_RG_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1667 case MESA_FORMAT_RGB_SINT16
:
1668 return format
== GL_RGB_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1669 case MESA_FORMAT_RGBA_SINT16
:
1670 return format
== GL_RGBA_INTEGER
&& type
== GL_SHORT
&& !swapBytes
;
1671 case MESA_FORMAT_R_SINT32
:
1672 return format
== GL_RED_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1673 case MESA_FORMAT_RG_SINT32
:
1674 return format
== GL_RG_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1675 case MESA_FORMAT_RGB_SINT32
:
1676 return format
== GL_RGB_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1677 case MESA_FORMAT_RGBA_SINT32
:
1678 return format
== GL_RGBA_INTEGER
&& type
== GL_INT
&& !swapBytes
;
1680 case MESA_FORMAT_R_UINT8
:
1681 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_BYTE
;
1682 case MESA_FORMAT_RG_UINT8
:
1683 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1684 case MESA_FORMAT_RGB_UINT8
:
1685 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_BYTE
&& !swapBytes
;
1686 case MESA_FORMAT_RGBA_UINT8
:
1687 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_BYTE
&&
1689 case MESA_FORMAT_R_UINT16
:
1690 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1692 case MESA_FORMAT_RG_UINT16
:
1693 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_SHORT
&& !swapBytes
;
1694 case MESA_FORMAT_RGB_UINT16
:
1695 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1697 case MESA_FORMAT_RGBA_UINT16
:
1698 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_SHORT
&&
1700 case MESA_FORMAT_R_UINT32
:
1701 return format
== GL_RED_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1702 case MESA_FORMAT_RG_UINT32
:
1703 return format
== GL_RG_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1704 case MESA_FORMAT_RGB_UINT32
:
1705 return format
== GL_RGB_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1706 case MESA_FORMAT_RGBA_UINT32
:
1707 return format
== GL_RGBA_INTEGER
&& type
== GL_UNSIGNED_INT
&& !swapBytes
;
1709 case MESA_FORMAT_R_SNORM8
:
1710 return format
== GL_RED
&& type
== GL_BYTE
;
1711 case MESA_FORMAT_R8G8_SNORM
:
1712 return format
== GL_RG
&& type
== GL_BYTE
&& littleEndian
&&
1714 case MESA_FORMAT_X8B8G8R8_SNORM
:
1717 case MESA_FORMAT_A8B8G8R8_SNORM
:
1718 if (format
== GL_RGBA
&& type
== GL_BYTE
&& !littleEndian
)
1721 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& littleEndian
)
1726 case MESA_FORMAT_R8G8B8A8_SNORM
:
1727 if (format
== GL_RGBA
&& type
== GL_BYTE
&& littleEndian
)
1730 if (format
== GL_ABGR_EXT
&& type
== GL_BYTE
&& !littleEndian
)
1735 case MESA_FORMAT_R_SNORM16
:
1736 return format
== GL_RED
&& type
== GL_SHORT
&&
1738 case MESA_FORMAT_R16G16_SNORM
:
1739 return format
== GL_RG
&& type
== GL_SHORT
&& littleEndian
&& !swapBytes
;
1740 case MESA_FORMAT_RGB_SNORM16
:
1741 return format
== GL_RGB
&& type
== GL_SHORT
&& !swapBytes
;
1742 case MESA_FORMAT_RGBA_SNORM16
:
1743 return format
== GL_RGBA
&& type
== GL_SHORT
&& !swapBytes
;
1744 case MESA_FORMAT_RGBA_UNORM16
:
1745 return format
== GL_RGBA
&& type
== GL_UNSIGNED_SHORT
&&
1748 case MESA_FORMAT_R_RGTC1_UNORM
:
1749 case MESA_FORMAT_R_RGTC1_SNORM
:
1750 case MESA_FORMAT_RG_RGTC2_UNORM
:
1751 case MESA_FORMAT_RG_RGTC2_SNORM
:
1754 case MESA_FORMAT_L_LATC1_UNORM
:
1755 case MESA_FORMAT_L_LATC1_SNORM
:
1756 case MESA_FORMAT_LA_LATC2_UNORM
:
1757 case MESA_FORMAT_LA_LATC2_SNORM
:
1760 case MESA_FORMAT_ETC1_RGB8
:
1761 case MESA_FORMAT_ETC2_RGB8
:
1762 case MESA_FORMAT_ETC2_SRGB8
:
1763 case MESA_FORMAT_ETC2_RGBA8_EAC
:
1764 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
:
1765 case MESA_FORMAT_ETC2_R11_EAC
:
1766 case MESA_FORMAT_ETC2_RG11_EAC
:
1767 case MESA_FORMAT_ETC2_SIGNED_R11_EAC
:
1768 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC
:
1769 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
:
1770 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
:
1773 case MESA_FORMAT_A_SNORM8
:
1774 return format
== GL_ALPHA
&& type
== GL_BYTE
;
1775 case MESA_FORMAT_L_SNORM8
:
1776 return format
== GL_LUMINANCE
&& type
== GL_BYTE
;
1777 case MESA_FORMAT_L8A8_SNORM
:
1778 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_BYTE
&&
1779 littleEndian
&& !swapBytes
;
1780 case MESA_FORMAT_I_SNORM8
:
1781 return format
== GL_RED
&& type
== GL_BYTE
;
1782 case MESA_FORMAT_A_SNORM16
:
1783 return format
== GL_ALPHA
&& type
== GL_SHORT
&& !swapBytes
;
1784 case MESA_FORMAT_L_SNORM16
:
1785 return format
== GL_LUMINANCE
&& type
== GL_SHORT
&& !swapBytes
;
1786 case MESA_FORMAT_LA_SNORM16
:
1787 return format
== GL_LUMINANCE_ALPHA
&& type
== GL_SHORT
&&
1788 littleEndian
&& !swapBytes
;
1789 case MESA_FORMAT_I_SNORM16
:
1790 return format
== GL_RED
&& type
== GL_SHORT
&& littleEndian
&&
1793 case MESA_FORMAT_B10G10R10A2_UINT
:
1794 return (format
== GL_BGRA_INTEGER_EXT
&&
1795 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1798 case MESA_FORMAT_R10G10B10A2_UINT
:
1799 return (format
== GL_RGBA_INTEGER_EXT
&&
1800 type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1803 case MESA_FORMAT_R9G9B9E5_FLOAT
:
1804 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_5_9_9_9_REV
&&
1807 case MESA_FORMAT_R11G11B10_FLOAT
:
1808 return format
== GL_RGB
&& type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&&
1811 case MESA_FORMAT_Z_FLOAT32
:
1812 return format
== GL_DEPTH_COMPONENT
&& type
== GL_FLOAT
&& !swapBytes
;
1814 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
1815 return format
== GL_DEPTH_STENCIL
&&
1816 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
&& !swapBytes
;
1818 case MESA_FORMAT_B4G4R4X4_UNORM
:
1819 case MESA_FORMAT_B5G5R5X1_UNORM
:
1820 case MESA_FORMAT_R8G8B8X8_SNORM
:
1821 case MESA_FORMAT_R8G8B8X8_SRGB
:
1822 case MESA_FORMAT_RGBX_UINT8
:
1823 case MESA_FORMAT_RGBX_SINT8
:
1824 case MESA_FORMAT_B10G10R10X2_UNORM
:
1825 case MESA_FORMAT_RGBX_UNORM16
:
1826 case MESA_FORMAT_RGBX_SNORM16
:
1827 case MESA_FORMAT_RGBX_FLOAT16
:
1828 case MESA_FORMAT_RGBX_UINT16
:
1829 case MESA_FORMAT_RGBX_SINT16
:
1830 case MESA_FORMAT_RGBX_FLOAT32
:
1831 case MESA_FORMAT_RGBX_UINT32
:
1832 case MESA_FORMAT_RGBX_SINT32
:
1835 case MESA_FORMAT_R10G10B10A2_UNORM
:
1836 return format
== GL_RGBA
&& type
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1839 case MESA_FORMAT_G8R8_SNORM
:
1840 return format
== GL_RG
&& type
== GL_BYTE
&& !littleEndian
&&
1843 case MESA_FORMAT_G16R16_SNORM
:
1844 return format
== GL_RG
&& type
== GL_SHORT
&& !littleEndian
&&
1847 case MESA_FORMAT_B8G8R8X8_SRGB
: