2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "glformats.h"
55 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
56 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
57 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
58 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
74 MAP4(ZERO
, ZERO
, ZERO
, 0),
104 MAP4(0, ZERO
, ZERO
, ONE
),
110 MAP4(ZERO
, 0, ZERO
, ONE
),
116 MAP4(ZERO
, ZERO
, 0, ONE
),
140 MAP4(0, 1, ZERO
, ONE
),
146 * Convert a GL image format enum to an IDX_* value (see above).
149 get_map_idx(GLenum value
)
153 case GL_LUMINANCE_INTEGER_EXT
:
154 return IDX_LUMINANCE
;
156 case GL_ALPHA_INTEGER
:
159 return IDX_INTENSITY
;
160 case GL_LUMINANCE_ALPHA
:
161 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
162 return IDX_LUMINANCE_ALPHA
;
167 case GL_RGBA_INTEGER
:
180 case GL_BGRA_INTEGER
:
188 _mesa_problem(NULL
, "Unexpected inFormat %s",
189 _mesa_lookup_enum_by_nr(value
));
195 * When promoting texture formats (see below) we need to compute the
196 * mapping of dest components back to source components.
197 * This function does that.
198 * \param inFormat the incoming format of the texture
199 * \param outFormat the final texture format
200 * \return map[6] a full 6-component map
203 _mesa_compute_component_mapping(GLenum inFormat
, GLenum outFormat
, GLubyte
*map
)
205 const int inFmt
= get_map_idx(inFormat
);
206 const int outFmt
= get_map_idx(outFormat
);
207 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
208 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
211 for (i
= 0; i
< 4; i
++)
212 map
[i
] = in2rgba
[rgba2out
[i
]];
218 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
219 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
220 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
231 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
234 _mesa_type_is_packed(GLenum type
)
237 case GL_UNSIGNED_BYTE_3_3_2
:
238 case GL_UNSIGNED_BYTE_2_3_3_REV
:
239 case MESA_UNSIGNED_BYTE_4_4
:
240 case GL_UNSIGNED_SHORT_5_6_5
:
241 case GL_UNSIGNED_SHORT_5_6_5_REV
:
242 case GL_UNSIGNED_SHORT_4_4_4_4
:
243 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
244 case GL_UNSIGNED_SHORT_5_5_5_1
:
245 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
246 case GL_UNSIGNED_INT_8_8_8_8
:
247 case GL_UNSIGNED_INT_8_8_8_8_REV
:
248 case GL_UNSIGNED_INT_10_10_10_2
:
249 case GL_UNSIGNED_INT_2_10_10_10_REV
:
250 case GL_UNSIGNED_SHORT_8_8_MESA
:
251 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
252 case GL_UNSIGNED_INT_24_8_EXT
:
253 case GL_UNSIGNED_INT_5_9_9_9_REV
:
254 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
255 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
264 * Get the size of a GL data type.
266 * \param type GL data type.
268 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
269 * if an invalid type enum.
272 _mesa_sizeof_type(GLenum type
)
277 case GL_UNSIGNED_BYTE
:
278 return sizeof(GLubyte
);
280 return sizeof(GLbyte
);
281 case GL_UNSIGNED_SHORT
:
282 return sizeof(GLushort
);
284 return sizeof(GLshort
);
285 case GL_UNSIGNED_INT
:
286 return sizeof(GLuint
);
288 return sizeof(GLint
);
290 return sizeof(GLfloat
);
292 return sizeof(GLdouble
);
293 case GL_HALF_FLOAT_ARB
:
294 return sizeof(GLhalfARB
);
296 return sizeof(GLfixed
);
304 * Same as _mesa_sizeof_type() but also accepting the packed pixel
308 _mesa_sizeof_packed_type(GLenum type
)
313 case GL_UNSIGNED_BYTE
:
314 return sizeof(GLubyte
);
316 return sizeof(GLbyte
);
317 case GL_UNSIGNED_SHORT
:
318 return sizeof(GLushort
);
320 return sizeof(GLshort
);
321 case GL_UNSIGNED_INT
:
322 return sizeof(GLuint
);
324 return sizeof(GLint
);
325 case GL_HALF_FLOAT_ARB
:
326 return sizeof(GLhalfARB
);
328 return sizeof(GLfloat
);
329 case GL_UNSIGNED_BYTE_3_3_2
:
330 case GL_UNSIGNED_BYTE_2_3_3_REV
:
331 case MESA_UNSIGNED_BYTE_4_4
:
332 return sizeof(GLubyte
);
333 case GL_UNSIGNED_SHORT_5_6_5
:
334 case GL_UNSIGNED_SHORT_5_6_5_REV
:
335 case GL_UNSIGNED_SHORT_4_4_4_4
:
336 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
337 case GL_UNSIGNED_SHORT_5_5_5_1
:
338 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
339 case GL_UNSIGNED_SHORT_8_8_MESA
:
340 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
341 return sizeof(GLushort
);
342 case GL_UNSIGNED_INT_8_8_8_8
:
343 case GL_UNSIGNED_INT_8_8_8_8_REV
:
344 case GL_UNSIGNED_INT_10_10_10_2
:
345 case GL_UNSIGNED_INT_2_10_10_10_REV
:
346 case GL_UNSIGNED_INT_24_8_EXT
:
347 case GL_UNSIGNED_INT_5_9_9_9_REV
:
348 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
349 return sizeof(GLuint
);
350 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
359 * Get the number of components in a pixel format.
361 * \param format pixel format.
363 * \return the number of components in the given format, or -1 if a bad format.
366 _mesa_components_in_format(GLenum format
)
370 case GL_STENCIL_INDEX
:
371 case GL_DEPTH_COMPONENT
:
373 case GL_RED_INTEGER_EXT
:
375 case GL_GREEN_INTEGER_EXT
:
377 case GL_BLUE_INTEGER_EXT
:
379 case GL_ALPHA_INTEGER_EXT
:
381 case GL_LUMINANCE_INTEGER_EXT
:
385 case GL_LUMINANCE_ALPHA
:
386 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
389 case GL_DEPTH_STENCIL_EXT
:
395 case GL_RGB_INTEGER_EXT
:
396 case GL_BGR_INTEGER_EXT
:
402 case GL_RGBA_INTEGER_EXT
:
403 case GL_BGRA_INTEGER_EXT
:
413 * Get the bytes per pixel of pixel format type pair.
415 * \param format pixel format.
416 * \param type pixel type.
418 * \return bytes per pixel, or -1 if a bad format or type was given.
421 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
423 GLint comps
= _mesa_components_in_format(format
);
429 return 0; /* special case */
431 case GL_UNSIGNED_BYTE
:
432 return comps
* sizeof(GLubyte
);
434 case GL_UNSIGNED_SHORT
:
435 return comps
* sizeof(GLshort
);
437 case GL_UNSIGNED_INT
:
438 return comps
* sizeof(GLint
);
440 return comps
* sizeof(GLfloat
);
441 case GL_HALF_FLOAT_ARB
:
442 return comps
* sizeof(GLhalfARB
);
443 case GL_UNSIGNED_BYTE_3_3_2
:
444 case GL_UNSIGNED_BYTE_2_3_3_REV
:
445 if (format
== GL_RGB
|| format
== GL_BGR
||
446 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
447 return sizeof(GLubyte
);
449 return -1; /* error */
450 case GL_UNSIGNED_SHORT_5_6_5
:
451 case GL_UNSIGNED_SHORT_5_6_5_REV
:
452 if (format
== GL_RGB
|| format
== GL_BGR
||
453 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
454 return sizeof(GLushort
);
456 return -1; /* error */
457 case GL_UNSIGNED_SHORT_4_4_4_4
:
458 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
459 case GL_UNSIGNED_SHORT_5_5_5_1
:
460 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
461 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
462 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
463 return sizeof(GLushort
);
466 case GL_UNSIGNED_INT_8_8_8_8
:
467 case GL_UNSIGNED_INT_8_8_8_8_REV
:
468 case GL_UNSIGNED_INT_10_10_10_2
:
469 case GL_UNSIGNED_INT_2_10_10_10_REV
:
470 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
471 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
473 return sizeof(GLuint
);
476 case GL_UNSIGNED_SHORT_8_8_MESA
:
477 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
478 if (format
== GL_YCBCR_MESA
)
479 return sizeof(GLushort
);
482 case GL_UNSIGNED_INT_24_8_EXT
:
483 if (format
== GL_DEPTH_STENCIL_EXT
)
484 return sizeof(GLuint
);
487 case GL_UNSIGNED_INT_5_9_9_9_REV
:
488 if (format
== GL_RGB
)
489 return sizeof(GLuint
);
492 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
493 if (format
== GL_RGB
)
494 return sizeof(GLuint
);
497 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
498 if (format
== GL_DEPTH_STENCIL
)
509 * Get the number of bytes for a vertex attrib with the given number of
510 * components and type.
512 * \param comps number of components.
513 * \param type data type.
515 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
518 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
522 case GL_UNSIGNED_BYTE
:
523 return comps
* sizeof(GLubyte
);
525 case GL_UNSIGNED_SHORT
:
526 return comps
* sizeof(GLshort
);
528 case GL_UNSIGNED_INT
:
529 return comps
* sizeof(GLint
);
531 return comps
* sizeof(GLfloat
);
532 case GL_HALF_FLOAT_ARB
:
533 return comps
* sizeof(GLhalfARB
);
535 return comps
* sizeof(GLdouble
);
537 return comps
* sizeof(GLfixed
);
538 case GL_INT_2_10_10_10_REV
:
539 case GL_UNSIGNED_INT_2_10_10_10_REV
:
541 return sizeof(GLuint
);
544 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
546 return sizeof(GLuint
);
555 * Test if the given format is unsized.
558 _mesa_is_enum_format_unsized(GLenum format
)
573 case GL_LUMINANCE_ALPHA
:
578 case GL_SLUMINANCE_ALPHA
:
585 case GL_INTENSITY_SNORM
:
586 case GL_LUMINANCE_SNORM
:
587 case GL_LUMINANCE_ALPHA_SNORM
:
590 case GL_GREEN_INTEGER
:
591 case GL_BLUE_INTEGER
:
592 case GL_ALPHA_INTEGER
:
594 case GL_RGBA_INTEGER
:
596 case GL_BGRA_INTEGER
:
598 case GL_LUMINANCE_INTEGER_EXT
:
599 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
601 case GL_DEPTH_COMPONENT
:
602 case GL_DEPTH_STENCIL
:
603 case GL_STENCIL_INDEX
:
611 * Test if the given format is a UNORM (unsigned-normalized) format.
614 _mesa_is_enum_format_unorm(GLenum format
)
633 case GL_LUMINANCE_ALPHA
:
634 case GL_SLUMINANCE_ALPHA
:
635 case GL_LUMINANCE4_ALPHA4
:
636 case GL_LUMINANCE6_ALPHA2
:
637 case GL_LUMINANCE8_ALPHA8
:
638 case GL_LUMINANCE12_ALPHA4
:
639 case GL_LUMINANCE12_ALPHA12
:
640 case GL_LUMINANCE16_ALPHA16
:
682 * Test if the given format is a SNORM (signed-normalized) format.
685 _mesa_is_enum_format_snorm(GLenum format
)
688 /* signed, normalized texture formats */
700 case GL_RGBA16_SNORM
:
702 case GL_ALPHA8_SNORM
:
703 case GL_ALPHA16_SNORM
:
704 case GL_LUMINANCE_SNORM
:
705 case GL_LUMINANCE8_SNORM
:
706 case GL_LUMINANCE16_SNORM
:
707 case GL_LUMINANCE_ALPHA_SNORM
:
708 case GL_LUMINANCE8_ALPHA8_SNORM
:
709 case GL_LUMINANCE16_ALPHA16_SNORM
:
710 case GL_INTENSITY_SNORM
:
711 case GL_INTENSITY8_SNORM
:
712 case GL_INTENSITY16_SNORM
:
720 * Test if the given format is an integer (non-normalized) format.
723 _mesa_is_enum_format_unsigned_int(GLenum format
)
726 /* specific integer formats */
727 case GL_RGBA32UI_EXT
:
731 case GL_ALPHA32UI_EXT
:
732 case GL_INTENSITY32UI_EXT
:
733 case GL_LUMINANCE32UI_EXT
:
734 case GL_LUMINANCE_ALPHA32UI_EXT
:
735 case GL_RGBA16UI_EXT
:
739 case GL_ALPHA16UI_EXT
:
740 case GL_INTENSITY16UI_EXT
:
741 case GL_LUMINANCE16UI_EXT
:
742 case GL_LUMINANCE_ALPHA16UI_EXT
:
747 case GL_ALPHA8UI_EXT
:
748 case GL_INTENSITY8UI_EXT
:
749 case GL_LUMINANCE8UI_EXT
:
750 case GL_LUMINANCE_ALPHA8UI_EXT
:
760 * Test if the given format is an integer (non-normalized) format.
763 _mesa_is_enum_format_signed_int(GLenum format
)
766 /* generic integer formats */
767 case GL_RED_INTEGER_EXT
:
768 case GL_GREEN_INTEGER_EXT
:
769 case GL_BLUE_INTEGER_EXT
:
770 case GL_ALPHA_INTEGER_EXT
:
771 case GL_RGB_INTEGER_EXT
:
772 case GL_RGBA_INTEGER_EXT
:
773 case GL_BGR_INTEGER_EXT
:
774 case GL_BGRA_INTEGER_EXT
:
775 case GL_LUMINANCE_INTEGER_EXT
:
776 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
778 /* specific integer formats */
783 case GL_ALPHA32I_EXT
:
784 case GL_INTENSITY32I_EXT
:
785 case GL_LUMINANCE32I_EXT
:
786 case GL_LUMINANCE_ALPHA32I_EXT
:
791 case GL_ALPHA16I_EXT
:
792 case GL_INTENSITY16I_EXT
:
793 case GL_LUMINANCE16I_EXT
:
794 case GL_LUMINANCE_ALPHA16I_EXT
:
800 case GL_INTENSITY8I_EXT
:
801 case GL_LUMINANCE8I_EXT
:
802 case GL_LUMINANCE_ALPHA8I_EXT
:
811 * Test if the given format is an integer (non-normalized) format.
814 _mesa_is_enum_format_integer(GLenum format
)
816 return _mesa_is_enum_format_unsigned_int(format
) ||
817 _mesa_is_enum_format_signed_int(format
);
822 _mesa_is_type_unsigned(GLenum type
)
825 case GL_UNSIGNED_INT
:
826 case GL_UNSIGNED_INT_8_8_8_8
:
827 case GL_UNSIGNED_INT_8_8_8_8_REV
:
828 case GL_UNSIGNED_INT_10_10_10_2
:
829 case GL_UNSIGNED_INT_2_10_10_10_REV
:
831 case GL_UNSIGNED_SHORT
:
832 case GL_UNSIGNED_SHORT_4_4_4_4
:
833 case GL_UNSIGNED_SHORT_5_5_5_1
:
834 case GL_UNSIGNED_SHORT_5_6_5
:
835 case GL_UNSIGNED_SHORT_5_6_5_REV
:
836 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
837 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
838 case GL_UNSIGNED_SHORT_8_8_MESA
:
839 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
841 case GL_UNSIGNED_BYTE
:
842 case GL_UNSIGNED_BYTE_3_3_2
:
843 case GL_UNSIGNED_BYTE_2_3_3_REV
:
853 * Test if the given image format is a color/RGBA format (i.e., not color
854 * index, depth, stencil, etc).
855 * \param format the image format value (may by an internal texture format)
856 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
859 _mesa_is_color_format(GLenum format
)
877 case GL_LUMINANCE_ALPHA
:
878 case GL_LUMINANCE4_ALPHA4
:
879 case GL_LUMINANCE6_ALPHA2
:
880 case GL_LUMINANCE8_ALPHA8
:
881 case GL_LUMINANCE12_ALPHA4
:
882 case GL_LUMINANCE12_ALPHA12
:
883 case GL_LUMINANCE16_ALPHA16
:
916 /* float texture formats */
917 case GL_ALPHA16F_ARB
:
918 case GL_ALPHA32F_ARB
:
919 case GL_LUMINANCE16F_ARB
:
920 case GL_LUMINANCE32F_ARB
:
921 case GL_LUMINANCE_ALPHA16F_ARB
:
922 case GL_LUMINANCE_ALPHA32F_ARB
:
923 case GL_INTENSITY16F_ARB
:
924 case GL_INTENSITY32F_ARB
:
933 /* compressed formats */
934 case GL_COMPRESSED_ALPHA
:
935 case GL_COMPRESSED_LUMINANCE
:
936 case GL_COMPRESSED_LUMINANCE_ALPHA
:
937 case GL_COMPRESSED_INTENSITY
:
938 case GL_COMPRESSED_RED
:
939 case GL_COMPRESSED_RG
:
940 case GL_COMPRESSED_RGB
:
941 case GL_COMPRESSED_RGBA
:
946 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
947 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
948 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
949 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
950 case GL_COMPRESSED_RGB_FXT1_3DFX
:
951 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
954 case GL_SRGB_ALPHA_EXT
:
955 case GL_SRGB8_ALPHA8_EXT
:
956 case GL_SLUMINANCE_ALPHA_EXT
:
957 case GL_SLUMINANCE8_ALPHA8_EXT
:
958 case GL_SLUMINANCE_EXT
:
959 case GL_SLUMINANCE8_EXT
:
960 case GL_COMPRESSED_SRGB_EXT
:
961 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
962 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
963 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
964 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
965 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
966 case GL_COMPRESSED_SLUMINANCE_EXT
:
967 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
968 case GL_COMPRESSED_RED_RGTC1
:
969 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
970 case GL_COMPRESSED_RG_RGTC2
:
971 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
972 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
973 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
974 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
975 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
976 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
977 case GL_ETC1_RGB8_OES
:
978 case GL_COMPRESSED_RGB8_ETC2
:
979 case GL_COMPRESSED_SRGB8_ETC2
:
980 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
981 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
982 case GL_COMPRESSED_R11_EAC
:
983 case GL_COMPRESSED_RG11_EAC
:
984 case GL_COMPRESSED_SIGNED_R11_EAC
:
985 case GL_COMPRESSED_SIGNED_RG11_EAC
:
986 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
987 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
988 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
989 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
990 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
991 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
992 /* generic integer formats */
993 case GL_RED_INTEGER_EXT
:
994 case GL_GREEN_INTEGER_EXT
:
995 case GL_BLUE_INTEGER_EXT
:
996 case GL_ALPHA_INTEGER_EXT
:
997 case GL_RGB_INTEGER_EXT
:
998 case GL_RGBA_INTEGER_EXT
:
999 case GL_BGR_INTEGER_EXT
:
1000 case GL_BGRA_INTEGER_EXT
:
1002 case GL_LUMINANCE_INTEGER_EXT
:
1003 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1004 /* sized integer formats */
1005 case GL_RGBA32UI_EXT
:
1006 case GL_RGB32UI_EXT
:
1009 case GL_ALPHA32UI_EXT
:
1010 case GL_INTENSITY32UI_EXT
:
1011 case GL_LUMINANCE32UI_EXT
:
1012 case GL_LUMINANCE_ALPHA32UI_EXT
:
1013 case GL_RGBA16UI_EXT
:
1014 case GL_RGB16UI_EXT
:
1017 case GL_ALPHA16UI_EXT
:
1018 case GL_INTENSITY16UI_EXT
:
1019 case GL_LUMINANCE16UI_EXT
:
1020 case GL_LUMINANCE_ALPHA16UI_EXT
:
1021 case GL_RGBA8UI_EXT
:
1025 case GL_ALPHA8UI_EXT
:
1026 case GL_INTENSITY8UI_EXT
:
1027 case GL_LUMINANCE8UI_EXT
:
1028 case GL_LUMINANCE_ALPHA8UI_EXT
:
1029 case GL_RGBA32I_EXT
:
1033 case GL_ALPHA32I_EXT
:
1034 case GL_INTENSITY32I_EXT
:
1035 case GL_LUMINANCE32I_EXT
:
1036 case GL_LUMINANCE_ALPHA32I_EXT
:
1037 case GL_RGBA16I_EXT
:
1041 case GL_ALPHA16I_EXT
:
1042 case GL_INTENSITY16I_EXT
:
1043 case GL_LUMINANCE16I_EXT
:
1044 case GL_LUMINANCE_ALPHA16I_EXT
:
1049 case GL_ALPHA8I_EXT
:
1050 case GL_INTENSITY8I_EXT
:
1051 case GL_LUMINANCE8I_EXT
:
1052 case GL_LUMINANCE_ALPHA8I_EXT
:
1053 /* signed, normalized texture formats */
1062 case GL_RGB16_SNORM
:
1064 case GL_RGBA8_SNORM
:
1065 case GL_RGBA16_SNORM
:
1066 case GL_ALPHA_SNORM
:
1067 case GL_ALPHA8_SNORM
:
1068 case GL_ALPHA16_SNORM
:
1069 case GL_LUMINANCE_SNORM
:
1070 case GL_LUMINANCE8_SNORM
:
1071 case GL_LUMINANCE16_SNORM
:
1072 case GL_LUMINANCE_ALPHA_SNORM
:
1073 case GL_LUMINANCE8_ALPHA8_SNORM
:
1074 case GL_LUMINANCE16_ALPHA16_SNORM
:
1075 case GL_INTENSITY_SNORM
:
1076 case GL_INTENSITY8_SNORM
:
1077 case GL_INTENSITY16_SNORM
:
1079 case GL_R11F_G11F_B10F
:
1082 case GL_YCBCR_MESA
: /* not considered to be RGB */
1091 * Test if the given image format is a depth component format.
1094 _mesa_is_depth_format(GLenum format
)
1097 case GL_DEPTH_COMPONENT
:
1098 case GL_DEPTH_COMPONENT16
:
1099 case GL_DEPTH_COMPONENT24
:
1100 case GL_DEPTH_COMPONENT32
:
1101 case GL_DEPTH_COMPONENT32F
:
1110 * Test if the given image format is a stencil format.
1113 _mesa_is_stencil_format(GLenum format
)
1116 case GL_STENCIL_INDEX
:
1125 * Test if the given image format is a YCbCr format.
1128 _mesa_is_ycbcr_format(GLenum format
)
1140 * Test if the given image format is a depth+stencil format.
1143 _mesa_is_depthstencil_format(GLenum format
)
1146 case GL_DEPTH24_STENCIL8_EXT
:
1147 case GL_DEPTH_STENCIL_EXT
:
1148 case GL_DEPTH32F_STENCIL8
:
1157 * Test if the given image format is a depth or stencil format.
1160 _mesa_is_depth_or_stencil_format(GLenum format
)
1163 case GL_DEPTH_COMPONENT
:
1164 case GL_DEPTH_COMPONENT16
:
1165 case GL_DEPTH_COMPONENT24
:
1166 case GL_DEPTH_COMPONENT32
:
1167 case GL_STENCIL_INDEX
:
1168 case GL_STENCIL_INDEX1_EXT
:
1169 case GL_STENCIL_INDEX4_EXT
:
1170 case GL_STENCIL_INDEX8_EXT
:
1171 case GL_STENCIL_INDEX16_EXT
:
1172 case GL_DEPTH_STENCIL_EXT
:
1173 case GL_DEPTH24_STENCIL8_EXT
:
1174 case GL_DEPTH_COMPONENT32F
:
1175 case GL_DEPTH32F_STENCIL8
:
1184 * Test if an image format is a supported compressed format.
1185 * \param format the internal format token provided by the user.
1186 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1189 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1192 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1193 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1194 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1195 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1196 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
1198 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1203 return _mesa_is_desktop_gl(ctx
) &&
1204 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1205 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1206 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1207 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1208 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1209 return _mesa_is_desktop_gl(ctx
)
1210 && ctx
->Extensions
.EXT_texture_sRGB
1211 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1212 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1213 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1214 return _mesa_is_desktop_gl(ctx
)
1215 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1216 case GL_COMPRESSED_RED_RGTC1
:
1217 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1218 case GL_COMPRESSED_RG_RGTC2
:
1219 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1220 return _mesa_is_desktop_gl(ctx
)
1221 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1222 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1223 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1224 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1225 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1226 return ctx
->API
== API_OPENGL_COMPAT
1227 && ctx
->Extensions
.EXT_texture_compression_latc
;
1228 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1229 return ctx
->API
== API_OPENGL_COMPAT
1230 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1231 case GL_ETC1_RGB8_OES
:
1232 return _mesa_is_gles(ctx
)
1233 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1234 case GL_COMPRESSED_RGB8_ETC2
:
1235 case GL_COMPRESSED_SRGB8_ETC2
:
1236 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1237 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1238 case GL_COMPRESSED_R11_EAC
:
1239 case GL_COMPRESSED_RG11_EAC
:
1240 case GL_COMPRESSED_SIGNED_R11_EAC
:
1241 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1242 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1243 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1244 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1245 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1246 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1247 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1248 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1249 return _mesa_is_desktop_gl(ctx
) &&
1250 ctx
->Extensions
.ARB_texture_compression_bptc
;
1251 case GL_PALETTE4_RGB8_OES
:
1252 case GL_PALETTE4_RGBA8_OES
:
1253 case GL_PALETTE4_R5_G6_B5_OES
:
1254 case GL_PALETTE4_RGBA4_OES
:
1255 case GL_PALETTE4_RGB5_A1_OES
:
1256 case GL_PALETTE8_RGB8_OES
:
1257 case GL_PALETTE8_RGBA8_OES
:
1258 case GL_PALETTE8_R5_G6_B5_OES
:
1259 case GL_PALETTE8_RGBA4_OES
:
1260 case GL_PALETTE8_RGB5_A1_OES
:
1261 return ctx
->API
== API_OPENGLES
;
1269 * Convert various base formats to the cooresponding integer format.
1272 _mesa_base_format_to_integer_format(GLenum format
)
1276 return GL_RED_INTEGER
;
1278 return GL_GREEN_INTEGER
;
1280 return GL_BLUE_INTEGER
;
1282 return GL_RG_INTEGER
;
1284 return GL_RGB_INTEGER
;
1286 return GL_RGBA_INTEGER
;
1288 return GL_BGR_INTEGER
;
1290 return GL_BGRA_INTEGER
;
1292 return GL_ALPHA_INTEGER
;
1294 return GL_LUMINANCE_INTEGER_EXT
;
1295 case GL_LUMINANCE_ALPHA
:
1296 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1304 * Does the given base texture/renderbuffer format have the channel
1308 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1311 case GL_TEXTURE_RED_SIZE
:
1312 case GL_TEXTURE_RED_TYPE
:
1313 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1314 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1315 if (base_format
== GL_RED
||
1316 base_format
== GL_RG
||
1317 base_format
== GL_RGB
||
1318 base_format
== GL_RGBA
) {
1322 case GL_TEXTURE_GREEN_SIZE
:
1323 case GL_TEXTURE_GREEN_TYPE
:
1324 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1325 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1326 if (base_format
== GL_RG
||
1327 base_format
== GL_RGB
||
1328 base_format
== GL_RGBA
) {
1332 case GL_TEXTURE_BLUE_SIZE
:
1333 case GL_TEXTURE_BLUE_TYPE
:
1334 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1335 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1336 if (base_format
== GL_RGB
||
1337 base_format
== GL_RGBA
) {
1341 case GL_TEXTURE_ALPHA_SIZE
:
1342 case GL_TEXTURE_ALPHA_TYPE
:
1343 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1344 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1345 if (base_format
== GL_RGBA
||
1346 base_format
== GL_ALPHA
||
1347 base_format
== GL_LUMINANCE_ALPHA
) {
1351 case GL_TEXTURE_LUMINANCE_SIZE
:
1352 case GL_TEXTURE_LUMINANCE_TYPE
:
1353 if (base_format
== GL_LUMINANCE
||
1354 base_format
== GL_LUMINANCE_ALPHA
) {
1358 case GL_TEXTURE_INTENSITY_SIZE
:
1359 case GL_TEXTURE_INTENSITY_TYPE
:
1360 if (base_format
== GL_INTENSITY
) {
1364 case GL_TEXTURE_DEPTH_SIZE
:
1365 case GL_TEXTURE_DEPTH_TYPE
:
1366 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1367 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1368 if (base_format
== GL_DEPTH_STENCIL
||
1369 base_format
== GL_DEPTH_COMPONENT
) {
1373 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1374 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1375 if (base_format
== GL_DEPTH_STENCIL
||
1376 base_format
== GL_STENCIL_INDEX
) {
1381 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1382 __FUNCTION__
, pname
);
1391 * Returns the number of channels/components for a base format.
1394 _mesa_base_format_component_count(GLenum base_format
)
1396 switch (base_format
) {
1400 case GL_DEPTH_COMPONENT
:
1403 case GL_LUMINANCE_ALPHA
:
1404 case GL_DEPTH_STENCIL
:
1417 * If format is a generic compressed format, return the corresponding
1418 * non-compressed format. For other formats, return the format as-is.
1421 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1424 case GL_COMPRESSED_RED
:
1426 case GL_COMPRESSED_RG
:
1428 case GL_COMPRESSED_RGB
:
1430 case GL_COMPRESSED_RGBA
:
1432 case GL_COMPRESSED_ALPHA
:
1434 case GL_COMPRESSED_LUMINANCE
:
1435 return GL_LUMINANCE
;
1436 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1437 return GL_LUMINANCE_ALPHA
;
1438 case GL_COMPRESSED_INTENSITY
:
1439 return GL_INTENSITY
;
1441 case GL_COMPRESSED_SRGB
:
1443 case GL_COMPRESSED_SRGB_ALPHA
:
1444 return GL_SRGB_ALPHA
;
1445 case GL_COMPRESSED_SLUMINANCE
:
1446 return GL_SLUMINANCE
;
1447 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1448 return GL_SLUMINANCE_ALPHA
;
1456 * Return the equivalent non-generic internal format.
1457 * This is useful for comparing whether two internal formats are equivalent.
1460 _mesa_get_nongeneric_internalformat(GLenum format
)
1463 /* GL 1.1 formats. */
1471 case GL_LUMINANCE_ALPHA
:
1472 return GL_LUMINANCE8_ALPHA8
;
1475 return GL_LUMINANCE8
;
1479 return GL_INTENSITY8
;
1481 /* GL_ARB_texture_rg */
1487 /* GL_EXT_texture_sRGB */
1491 return GL_SRGB8_ALPHA8
;
1493 return GL_SLUMINANCE8
;
1494 case GL_SLUMINANCE_ALPHA
:
1495 return GL_SLUMINANCE8_ALPHA8
;
1497 /* GL_EXT_texture_snorm */
1499 return GL_RGBA8_SNORM
;
1501 return GL_RGB8_SNORM
;
1503 return GL_RG8_SNORM
;
1506 case GL_LUMINANCE_ALPHA_SNORM
:
1507 return GL_LUMINANCE8_ALPHA8_SNORM
;
1508 case GL_LUMINANCE_SNORM
:
1509 return GL_LUMINANCE8_SNORM
;
1510 case GL_ALPHA_SNORM
:
1511 return GL_ALPHA8_SNORM
;
1512 case GL_INTENSITY_SNORM
:
1513 return GL_INTENSITY8_SNORM
;
1522 * Convert an sRGB internal format to linear.
1525 _mesa_get_linear_internalformat(GLenum format
)
1534 case GL_SRGB8_ALPHA8
:
1536 case GL_SLUMINANCE8
:
1537 return GL_LUMINANCE8
;
1539 return GL_LUMINANCE
;
1540 case GL_SLUMINANCE_ALPHA
:
1541 return GL_LUMINANCE_ALPHA
;
1542 case GL_SLUMINANCE8_ALPHA8
:
1543 return GL_LUMINANCE8_ALPHA8
;
1551 * Do error checking of format/type combinations for glReadPixels,
1552 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1553 * and type values, we may either generate GL_INVALID_OPERATION or
1556 * \param format pixel format.
1557 * \param type pixel type.
1559 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1562 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1563 GLenum format
, GLenum type
)
1565 /* From OpenGL 3.3 spec, page 220:
1566 * "If the format is DEPTH_STENCIL, then values are taken from
1567 * both the depth buffer and the stencil buffer. If there is no
1568 * depth buffer or if there is no stencil buffer, then the error
1569 * INVALID_OPERATION occurs. If the type parameter is not
1570 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1571 * error INVALID_ENUM occurs."
1573 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1574 * cannot be used to read depth or stencil in that API.
1576 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1577 && type
!= GL_UNSIGNED_INT_24_8
1578 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1579 return GL_INVALID_ENUM
;
1581 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1584 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1585 return GL_INVALID_ENUM
;
1589 case GL_UNSIGNED_BYTE_3_3_2
:
1590 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1591 case GL_UNSIGNED_SHORT_5_6_5
:
1592 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1593 if (format
== GL_RGB
) {
1596 if (format
== GL_RGB_INTEGER_EXT
&&
1597 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1600 return GL_INVALID_OPERATION
;
1602 case GL_UNSIGNED_SHORT_4_4_4_4
:
1603 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1604 case GL_UNSIGNED_SHORT_5_5_5_1
:
1605 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1606 case GL_UNSIGNED_INT_8_8_8_8
:
1607 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1608 case GL_UNSIGNED_INT_10_10_10_2
:
1609 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1610 if (format
== GL_RGBA
||
1611 format
== GL_BGRA
||
1612 format
== GL_ABGR_EXT
) {
1615 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1616 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1619 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1620 ctx
->API
== API_OPENGLES2
) {
1621 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1623 return GL_INVALID_OPERATION
;
1625 case GL_UNSIGNED_INT_24_8
:
1626 if (format
!= GL_DEPTH_STENCIL
) {
1627 return GL_INVALID_OPERATION
;
1631 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1632 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1633 return GL_INVALID_ENUM
;
1635 if (format
!= GL_DEPTH_STENCIL
) {
1636 return GL_INVALID_OPERATION
;
1640 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1641 if (!ctx
->Extensions
.EXT_packed_float
) {
1642 return GL_INVALID_ENUM
;
1644 if (format
!= GL_RGB
) {
1645 return GL_INVALID_OPERATION
;
1650 ; /* fall-through */
1653 /* now, for each format, check the type for compatibility */
1655 case GL_COLOR_INDEX
:
1656 case GL_STENCIL_INDEX
:
1660 case GL_UNSIGNED_BYTE
:
1662 case GL_UNSIGNED_SHORT
:
1664 case GL_UNSIGNED_INT
:
1669 return GL_INVALID_ENUM
;
1676 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1680 case GL_LUMINANCE_ALPHA
:
1681 case GL_DEPTH_COMPONENT
:
1684 case GL_UNSIGNED_BYTE
:
1686 case GL_UNSIGNED_SHORT
:
1688 case GL_UNSIGNED_INT
:
1693 return GL_INVALID_ENUM
;
1697 if (!ctx
->Extensions
.ARB_texture_rg
)
1698 return GL_INVALID_ENUM
;
1701 case GL_UNSIGNED_BYTE
:
1703 case GL_UNSIGNED_SHORT
:
1705 case GL_UNSIGNED_INT
:
1710 return GL_INVALID_ENUM
;
1716 case GL_UNSIGNED_BYTE
:
1718 case GL_UNSIGNED_SHORT
:
1720 case GL_UNSIGNED_INT
:
1722 case GL_UNSIGNED_BYTE_3_3_2
:
1723 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1724 case GL_UNSIGNED_SHORT_5_6_5
:
1725 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1728 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1729 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1730 return (ctx
->API
== API_OPENGLES2
)
1731 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1732 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1733 return ctx
->Extensions
.EXT_texture_shared_exponent
1734 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1735 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1736 return ctx
->Extensions
.EXT_packed_float
1737 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1739 return GL_INVALID_ENUM
;
1744 /* NOTE: no packed types are supported with BGR. That's
1745 * intentional, according to the GL spec.
1748 case GL_UNSIGNED_BYTE
:
1750 case GL_UNSIGNED_SHORT
:
1752 case GL_UNSIGNED_INT
:
1757 return GL_INVALID_ENUM
;
1765 case GL_UNSIGNED_BYTE
:
1767 case GL_UNSIGNED_SHORT
:
1769 case GL_UNSIGNED_INT
:
1771 case GL_UNSIGNED_SHORT_4_4_4_4
:
1772 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1773 case GL_UNSIGNED_SHORT_5_5_5_1
:
1774 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1775 case GL_UNSIGNED_INT_8_8_8_8
:
1776 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1777 case GL_UNSIGNED_INT_10_10_10_2
:
1778 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1782 return GL_INVALID_ENUM
;
1786 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1787 return GL_INVALID_ENUM
;
1788 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1789 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1792 return GL_INVALID_OPERATION
;
1794 case GL_DEPTH_STENCIL
:
1795 if (type
== GL_UNSIGNED_INT_24_8
)
1797 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1798 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1801 return GL_INVALID_ENUM
;
1803 /* integer-valued formats */
1804 case GL_RED_INTEGER_EXT
:
1805 case GL_GREEN_INTEGER_EXT
:
1806 case GL_BLUE_INTEGER_EXT
:
1807 case GL_ALPHA_INTEGER_EXT
:
1811 case GL_UNSIGNED_BYTE
:
1813 case GL_UNSIGNED_SHORT
:
1815 case GL_UNSIGNED_INT
:
1816 return (ctx
->Version
>= 30 ||
1817 ctx
->Extensions
.EXT_texture_integer
)
1818 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1820 return GL_INVALID_ENUM
;
1823 case GL_RGB_INTEGER_EXT
:
1826 case GL_UNSIGNED_BYTE
:
1828 case GL_UNSIGNED_SHORT
:
1830 case GL_UNSIGNED_INT
:
1831 return (ctx
->Version
>= 30 ||
1832 ctx
->Extensions
.EXT_texture_integer
)
1833 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1834 case GL_UNSIGNED_BYTE_3_3_2
:
1835 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1836 case GL_UNSIGNED_SHORT_5_6_5
:
1837 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1838 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1839 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1841 return GL_INVALID_ENUM
;
1844 case GL_BGR_INTEGER_EXT
:
1847 case GL_UNSIGNED_BYTE
:
1849 case GL_UNSIGNED_SHORT
:
1851 case GL_UNSIGNED_INT
:
1852 /* NOTE: no packed formats w/ BGR format */
1853 return (ctx
->Version
>= 30 ||
1854 ctx
->Extensions
.EXT_texture_integer
)
1855 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1857 return GL_INVALID_ENUM
;
1860 case GL_RGBA_INTEGER_EXT
:
1861 case GL_BGRA_INTEGER_EXT
:
1864 case GL_UNSIGNED_BYTE
:
1866 case GL_UNSIGNED_SHORT
:
1868 case GL_UNSIGNED_INT
:
1869 return (ctx
->Version
>= 30 ||
1870 ctx
->Extensions
.EXT_texture_integer
)
1871 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1872 case GL_UNSIGNED_SHORT_4_4_4_4
:
1873 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1874 case GL_UNSIGNED_SHORT_5_5_5_1
:
1875 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1876 case GL_UNSIGNED_INT_8_8_8_8
:
1877 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1878 case GL_UNSIGNED_INT_10_10_10_2
:
1879 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1880 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1881 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1883 return GL_INVALID_ENUM
;
1886 case GL_LUMINANCE_INTEGER_EXT
:
1887 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1890 case GL_UNSIGNED_BYTE
:
1892 case GL_UNSIGNED_SHORT
:
1894 case GL_UNSIGNED_INT
:
1895 return ctx
->Extensions
.EXT_texture_integer
1896 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1898 return GL_INVALID_ENUM
;
1902 return GL_INVALID_ENUM
;
1909 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1910 * and glTex[Sub]Image.
1911 * \return error code, or GL_NO_ERROR.
1914 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1915 unsigned dimensions
)
1917 GLboolean type_valid
= GL_TRUE
;
1922 case GL_LUMINANCE_ALPHA
:
1923 type_valid
= (type
== GL_UNSIGNED_BYTE
1925 || type
== GL_HALF_FLOAT_OES
);
1929 type_valid
= (type
== GL_UNSIGNED_BYTE
1930 || type
== GL_UNSIGNED_SHORT_5_6_5
1932 || type
== GL_HALF_FLOAT_OES
);
1936 type_valid
= (type
== GL_UNSIGNED_BYTE
1937 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1938 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1940 || type
== GL_HALF_FLOAT_OES
1941 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1944 case GL_DEPTH_COMPONENT
:
1945 /* This format is filtered against invalid dimensionalities elsewhere.
1947 type_valid
= (type
== GL_UNSIGNED_SHORT
1948 || type
== GL_UNSIGNED_INT
);
1951 case GL_DEPTH_STENCIL
:
1952 /* This format is filtered against invalid dimensionalities elsewhere.
1954 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1958 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1960 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1961 * the format does not appear to be allowed for 3D textures in OpenGL
1964 if (dimensions
!= 2)
1965 return GL_INVALID_VALUE
;
1970 return GL_INVALID_VALUE
;
1973 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1978 * Do error checking of format/type combinations for OpenGL ES 3
1980 * \return error code, or GL_NO_ERROR.
1983 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1984 GLenum internalFormat
)
1989 case GL_UNSIGNED_BYTE
:
1990 switch (internalFormat
) {
1995 case GL_SRGB8_ALPHA8_EXT
:
1998 return GL_INVALID_OPERATION
;
2003 if (internalFormat
!= GL_RGBA8_SNORM
)
2004 return GL_INVALID_OPERATION
;
2007 case GL_UNSIGNED_SHORT_4_4_4_4
:
2008 switch (internalFormat
) {
2013 return GL_INVALID_OPERATION
;
2017 case GL_UNSIGNED_SHORT_5_5_5_1
:
2018 switch (internalFormat
) {
2023 return GL_INVALID_OPERATION
;
2027 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2028 switch (internalFormat
) {
2029 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2034 return GL_INVALID_OPERATION
;
2039 if (internalFormat
!= GL_RGBA16F
)
2040 return GL_INVALID_OPERATION
;
2044 switch (internalFormat
) {
2049 return GL_INVALID_OPERATION
;
2054 return GL_INVALID_OPERATION
;
2058 case GL_RGBA_INTEGER
:
2060 case GL_UNSIGNED_BYTE
:
2061 if (internalFormat
!= GL_RGBA8UI
)
2062 return GL_INVALID_OPERATION
;
2066 if (internalFormat
!= GL_RGBA8I
)
2067 return GL_INVALID_OPERATION
;
2070 case GL_UNSIGNED_SHORT
:
2071 if (internalFormat
!= GL_RGBA16UI
)
2072 return GL_INVALID_OPERATION
;
2076 if (internalFormat
!= GL_RGBA16I
)
2077 return GL_INVALID_OPERATION
;
2080 case GL_UNSIGNED_INT
:
2081 if (internalFormat
!= GL_RGBA32UI
)
2082 return GL_INVALID_OPERATION
;
2086 if (internalFormat
!= GL_RGBA32I
)
2087 return GL_INVALID_OPERATION
;
2090 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2091 if (internalFormat
!= GL_RGB10_A2UI
)
2092 return GL_INVALID_OPERATION
;
2096 return GL_INVALID_OPERATION
;
2102 case GL_UNSIGNED_BYTE
:
2103 switch (internalFormat
) {
2110 return GL_INVALID_OPERATION
;
2115 if (internalFormat
!= GL_RGB8_SNORM
)
2116 return GL_INVALID_OPERATION
;
2119 case GL_UNSIGNED_SHORT_5_6_5
:
2120 switch (internalFormat
) {
2125 return GL_INVALID_OPERATION
;
2129 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2130 if (internalFormat
!= GL_R11F_G11F_B10F
)
2131 return GL_INVALID_OPERATION
;
2134 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2135 if (internalFormat
!= GL_RGB9_E5
)
2136 return GL_INVALID_OPERATION
;
2140 switch (internalFormat
) {
2142 case GL_R11F_G11F_B10F
:
2146 return GL_INVALID_OPERATION
;
2151 switch (internalFormat
) {
2154 case GL_R11F_G11F_B10F
:
2158 return GL_INVALID_OPERATION
;
2162 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2163 switch (internalFormat
) {
2164 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2167 return GL_INVALID_OPERATION
;
2172 return GL_INVALID_OPERATION
;
2176 case GL_RGB_INTEGER
:
2178 case GL_UNSIGNED_BYTE
:
2179 if (internalFormat
!= GL_RGB8UI
)
2180 return GL_INVALID_OPERATION
;
2184 if (internalFormat
!= GL_RGB8I
)
2185 return GL_INVALID_OPERATION
;
2188 case GL_UNSIGNED_SHORT
:
2189 if (internalFormat
!= GL_RGB16UI
)
2190 return GL_INVALID_OPERATION
;
2194 if (internalFormat
!= GL_RGB16I
)
2195 return GL_INVALID_OPERATION
;
2198 case GL_UNSIGNED_INT
:
2199 if (internalFormat
!= GL_RGB32UI
)
2200 return GL_INVALID_OPERATION
;
2204 if (internalFormat
!= GL_RGB32I
)
2205 return GL_INVALID_OPERATION
;
2209 return GL_INVALID_OPERATION
;
2215 case GL_UNSIGNED_BYTE
:
2216 if (internalFormat
!= GL_RG8
)
2217 return GL_INVALID_OPERATION
;
2221 if (internalFormat
!= GL_RG8_SNORM
)
2222 return GL_INVALID_OPERATION
;
2226 if (internalFormat
!= GL_RG16F
)
2227 return GL_INVALID_OPERATION
;
2231 switch (internalFormat
) {
2236 return GL_INVALID_OPERATION
;
2241 return GL_INVALID_OPERATION
;
2247 case GL_UNSIGNED_BYTE
:
2248 if (internalFormat
!= GL_RG8UI
)
2249 return GL_INVALID_OPERATION
;
2253 if (internalFormat
!= GL_RG8I
)
2254 return GL_INVALID_OPERATION
;
2257 case GL_UNSIGNED_SHORT
:
2258 if (internalFormat
!= GL_RG16UI
)
2259 return GL_INVALID_OPERATION
;
2263 if (internalFormat
!= GL_RG16I
)
2264 return GL_INVALID_OPERATION
;
2267 case GL_UNSIGNED_INT
:
2268 if (internalFormat
!= GL_RG32UI
)
2269 return GL_INVALID_OPERATION
;
2273 if (internalFormat
!= GL_RG32I
)
2274 return GL_INVALID_OPERATION
;
2278 return GL_INVALID_OPERATION
;
2284 case GL_UNSIGNED_BYTE
:
2285 if (internalFormat
!= GL_R8
)
2286 return GL_INVALID_OPERATION
;
2290 if (internalFormat
!= GL_R8_SNORM
)
2291 return GL_INVALID_OPERATION
;
2295 if (internalFormat
!= GL_R16F
)
2296 return GL_INVALID_OPERATION
;
2300 switch (internalFormat
) {
2305 return GL_INVALID_OPERATION
;
2310 return GL_INVALID_OPERATION
;
2314 case GL_RED_INTEGER
:
2316 case GL_UNSIGNED_BYTE
:
2317 if (internalFormat
!= GL_R8UI
)
2318 return GL_INVALID_OPERATION
;
2322 if (internalFormat
!= GL_R8I
)
2323 return GL_INVALID_OPERATION
;
2326 case GL_UNSIGNED_SHORT
:
2327 if (internalFormat
!= GL_R16UI
)
2328 return GL_INVALID_OPERATION
;
2332 if (internalFormat
!= GL_R16I
)
2333 return GL_INVALID_OPERATION
;
2336 case GL_UNSIGNED_INT
:
2337 if (internalFormat
!= GL_R32UI
)
2338 return GL_INVALID_OPERATION
;
2342 if (internalFormat
!= GL_R32I
)
2343 return GL_INVALID_OPERATION
;
2347 return GL_INVALID_OPERATION
;
2351 case GL_DEPTH_COMPONENT
:
2353 case GL_UNSIGNED_SHORT
:
2354 if (internalFormat
!= GL_DEPTH_COMPONENT
2355 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2356 return GL_INVALID_OPERATION
;
2359 case GL_UNSIGNED_INT
:
2360 switch (internalFormat
) {
2361 case GL_DEPTH_COMPONENT
:
2362 case GL_DEPTH_COMPONENT16
:
2363 case GL_DEPTH_COMPONENT24
:
2366 return GL_INVALID_OPERATION
;
2371 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2372 return GL_INVALID_OPERATION
;
2376 return GL_INVALID_OPERATION
;
2380 case GL_DEPTH_STENCIL
:
2382 case GL_UNSIGNED_INT_24_8
:
2383 if (internalFormat
!= GL_DEPTH_STENCIL
2384 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2385 return GL_INVALID_OPERATION
;
2388 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2389 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2390 return GL_INVALID_OPERATION
;
2394 return GL_INVALID_OPERATION
;
2400 case GL_LUMINANCE_ALPHA
:
2401 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2402 return GL_INVALID_OPERATION
;
2410 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
2412 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
2413 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
2414 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
2415 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
2419 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
2423 case GL_RGBA_INTEGER_EXT
:
2424 set_swizzle(swizzle
, 0, 1, 2, 3);
2427 case GL_BGRA_INTEGER_EXT
:
2428 set_swizzle(swizzle
, 2, 1, 0, 3);
2431 set_swizzle(swizzle
, 3, 2, 1, 0);
2434 case GL_RGB_INTEGER_EXT
:
2435 set_swizzle(swizzle
, 0, 1, 2, 5);
2438 case GL_BGR_INTEGER_EXT
:
2439 set_swizzle(swizzle
, 2, 1, 0, 5);
2441 case GL_LUMINANCE_ALPHA
:
2442 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2443 set_swizzle(swizzle
, 0, 0, 0, 1);
2447 set_swizzle(swizzle
, 0, 1, 4, 5);
2450 case GL_RED_INTEGER_EXT
:
2451 set_swizzle(swizzle
, 0, 4, 4, 5);
2454 case GL_GREEN_INTEGER_EXT
:
2455 set_swizzle(swizzle
, 4, 0, 4, 5);
2458 case GL_BLUE_INTEGER_EXT
:
2459 set_swizzle(swizzle
, 4, 4, 0, 5);
2462 case GL_ALPHA_INTEGER_EXT
:
2463 set_swizzle(swizzle
, 4, 4, 4, 0);
2466 case GL_LUMINANCE_INTEGER_EXT
:
2467 set_swizzle(swizzle
, 0, 0, 0, 5);
2470 set_swizzle(swizzle
, 0, 0, 0, 0);
2478 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
2479 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
2480 * otherwise (for non-array formats).
2482 * This function will typically be used to compute a mesa format from a GL type
2483 * so we can then call _mesa_format_convert. This function does
2484 * not consider byte swapping, so it returns types assuming that no byte
2485 * swapping is involved. If byte swapping is involved then clients are supposed
2486 * to handle that on their side before calling _mesa_format_convert.
2488 * This function returns an uint32_t that can pack a mesa_format or a
2489 * mesa_array_format. Clients must check the mesa array format bit
2490 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
2491 * format is a mesa_array_format or a mesa_format.
2494 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
2496 mesa_array_format array_format
;
2498 bool is_array_format
= true;
2500 bool normalized
= false, is_float
= false, is_signed
= false;
2501 int num_channels
= 0, type_size
= 0;
2503 /* Extract array format type information from the OpenGL data type */
2505 case GL_UNSIGNED_BYTE
:
2512 case GL_UNSIGNED_SHORT
:
2519 case GL_UNSIGNED_INT
:
2537 is_array_format
= false;
2541 /* Extract array format swizzle information from the OpenGL format */
2542 if (is_array_format
)
2543 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
2545 /* If this is an array format type after checking data type and format,
2546 * create the array format
2548 if (is_array_format
) {
2549 normalized
= !_mesa_is_enum_format_integer(format
);
2550 num_channels
= _mesa_components_in_format(format
);
2553 MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
2554 normalized
, num_channels
,
2555 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
2557 if (!_mesa_little_endian())
2558 array_format
= _mesa_array_format_flip_channels(array_format
);
2560 return array_format
;
2563 /* Otherwise this is not an array format, so return the mesa_format
2564 * matching the OpenGL format and data type
2567 case GL_UNSIGNED_SHORT_5_6_5
:
2568 if (format
== GL_RGB
)
2569 return MESA_FORMAT_B5G6R5_UNORM
;
2570 else if (format
== GL_BGR
)
2571 return MESA_FORMAT_R5G6B5_UNORM
;
2573 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2574 if (format
== GL_RGB
)
2575 return MESA_FORMAT_R5G6B5_UNORM
;
2576 else if (format
== GL_BGR
)
2577 return MESA_FORMAT_B5G6R5_UNORM
;
2579 case GL_UNSIGNED_SHORT_4_4_4_4
:
2580 if (format
== GL_RGBA
)
2581 return MESA_FORMAT_A4B4G4R4_UNORM
;
2582 else if (format
== GL_BGRA
)
2583 return MESA_FORMAT_A4R4G4B4_UNORM
;
2584 else if (format
== GL_ABGR_EXT
)
2585 return MESA_FORMAT_R4G4B4A4_UNORM
;
2587 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2588 if (format
== GL_RGBA
)
2589 return MESA_FORMAT_R4G4B4A4_UNORM
;
2590 else if (format
== GL_BGRA
)
2591 return MESA_FORMAT_B4G4R4A4_UNORM
;
2592 else if (format
== GL_ABGR_EXT
)
2593 return MESA_FORMAT_A4B4G4R4_UNORM
;
2595 case GL_UNSIGNED_SHORT_5_5_5_1
:
2596 if (format
== GL_RGBA
)
2597 return MESA_FORMAT_A1B5G5R5_UNORM
;
2598 else if (format
== GL_BGRA
)
2599 return MESA_FORMAT_A1R5G5B5_UNORM
;
2600 else if (format
== GL_ABGR_EXT
)
2601 return MESA_FORMAT_R1G5B5A5_UNORM
;
2603 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2604 if (format
== GL_RGBA
)
2605 return MESA_FORMAT_R5G5B5A1_UNORM
;
2606 else if (format
== GL_BGRA
)
2607 return MESA_FORMAT_B5G5R5A1_UNORM
;
2608 else if (format
== GL_ABGR_EXT
)
2609 return MESA_FORMAT_A5B5G5R1_UNORM
;
2611 case GL_UNSIGNED_BYTE_3_3_2
:
2612 if (format
== GL_RGB
)
2613 return MESA_FORMAT_B2G3R3_UNORM
;
2615 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2616 if (format
== GL_RGB
)
2617 return MESA_FORMAT_R3G3B2_UNORM
;
2619 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2620 if (format
== GL_RGB
)
2621 return MESA_FORMAT_R9G9B9E5_FLOAT
;
2623 case GL_UNSIGNED_INT_10_10_10_2
:
2624 if (format
== GL_RGBA
)
2625 return MESA_FORMAT_A2B10G10R10_UNORM
;
2626 else if (format
== GL_RGBA_INTEGER
)
2627 return MESA_FORMAT_A2B10G10R10_UINT
;
2628 else if (format
== GL_BGRA
)
2629 return MESA_FORMAT_A2R10G10B10_UNORM
;
2630 else if (format
== GL_BGRA_INTEGER
)
2631 return MESA_FORMAT_A2R10G10B10_UINT
;
2632 else if (format
== GL_ABGR_EXT
)
2633 return MESA_FORMAT_R2G10B10A10_UNORM
;
2635 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2636 if (format
== GL_RGBA
)
2637 return MESA_FORMAT_R10G10B10A2_UNORM
;
2638 else if (format
== GL_RGBA_INTEGER
)
2639 return MESA_FORMAT_R10G10B10A2_UINT
;
2640 else if (format
== GL_BGRA
)
2641 return MESA_FORMAT_B10G10R10A2_UNORM
;
2642 else if (format
== GL_BGRA_INTEGER
)
2643 return MESA_FORMAT_B10G10R10A2_UINT
;
2644 else if (format
== GL_ABGR_EXT
)
2645 return MESA_FORMAT_A10B10G10R2_UNORM
;
2647 case GL_UNSIGNED_INT_8_8_8_8
:
2648 if (format
== GL_RGBA
)
2649 return MESA_FORMAT_A8B8G8R8_UNORM
;
2650 else if (format
== GL_BGRA
)
2651 return MESA_FORMAT_A8R8G8B8_UNORM
;
2652 else if (format
== GL_ABGR_EXT
)
2653 return MESA_FORMAT_R8G8B8A8_UNORM
;
2655 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2656 if (format
== GL_RGBA
)
2657 return MESA_FORMAT_R8G8B8A8_UNORM
;
2658 else if (format
== GL_BGRA
)
2659 return MESA_FORMAT_B8G8R8A8_UNORM
;
2660 else if (format
== GL_ABGR_EXT
)
2661 return MESA_FORMAT_A8B8G8R8_UNORM
;
2663 case GL_UNSIGNED_SHORT_8_8_MESA
:
2664 if (format
== GL_YCBCR_MESA
)
2665 return MESA_FORMAT_YCBCR
;
2667 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
2668 if (format
== GL_YCBCR_MESA
)
2669 return MESA_FORMAT_YCBCR_REV
;
2671 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2672 if (format
== GL_RGB
)
2673 return MESA_FORMAT_R11G11B10_FLOAT
;
2678 /* If we got here it means that we could not find a Mesa format that
2679 * matches the GL format/type provided. We may need to add a new Mesa
2680 * format in that case.
2682 assert(!"Unsupported format");