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 case GL_HALF_FLOAT_OES
:
295 return sizeof(GLhalfARB
);
297 return sizeof(GLfixed
);
305 * Same as _mesa_sizeof_type() but also accepting the packed pixel
309 _mesa_sizeof_packed_type(GLenum type
)
314 case GL_UNSIGNED_BYTE
:
315 return sizeof(GLubyte
);
317 return sizeof(GLbyte
);
318 case GL_UNSIGNED_SHORT
:
319 return sizeof(GLushort
);
321 return sizeof(GLshort
);
322 case GL_UNSIGNED_INT
:
323 return sizeof(GLuint
);
325 return sizeof(GLint
);
326 case GL_HALF_FLOAT_ARB
:
327 case GL_HALF_FLOAT_OES
:
328 return sizeof(GLhalfARB
);
330 return sizeof(GLfloat
);
331 case GL_UNSIGNED_BYTE_3_3_2
:
332 case GL_UNSIGNED_BYTE_2_3_3_REV
:
333 case MESA_UNSIGNED_BYTE_4_4
:
334 return sizeof(GLubyte
);
335 case GL_UNSIGNED_SHORT_5_6_5
:
336 case GL_UNSIGNED_SHORT_5_6_5_REV
:
337 case GL_UNSIGNED_SHORT_4_4_4_4
:
338 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
339 case GL_UNSIGNED_SHORT_5_5_5_1
:
340 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
341 case GL_UNSIGNED_SHORT_8_8_MESA
:
342 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
343 return sizeof(GLushort
);
344 case GL_UNSIGNED_INT_8_8_8_8
:
345 case GL_UNSIGNED_INT_8_8_8_8_REV
:
346 case GL_UNSIGNED_INT_10_10_10_2
:
347 case GL_UNSIGNED_INT_2_10_10_10_REV
:
348 case GL_UNSIGNED_INT_24_8_EXT
:
349 case GL_UNSIGNED_INT_5_9_9_9_REV
:
350 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
351 return sizeof(GLuint
);
352 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
361 * Get the number of components in a pixel format.
363 * \param format pixel format.
365 * \return the number of components in the given format, or -1 if a bad format.
368 _mesa_components_in_format(GLenum format
)
372 case GL_STENCIL_INDEX
:
373 case GL_DEPTH_COMPONENT
:
375 case GL_RED_INTEGER_EXT
:
377 case GL_GREEN_INTEGER_EXT
:
379 case GL_BLUE_INTEGER_EXT
:
381 case GL_ALPHA_INTEGER_EXT
:
383 case GL_LUMINANCE_INTEGER_EXT
:
387 case GL_LUMINANCE_ALPHA
:
388 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
391 case GL_DEPTH_STENCIL_EXT
:
397 case GL_RGB_INTEGER_EXT
:
398 case GL_BGR_INTEGER_EXT
:
404 case GL_RGBA_INTEGER_EXT
:
405 case GL_BGRA_INTEGER_EXT
:
415 * Get the bytes per pixel of pixel format type pair.
417 * \param format pixel format.
418 * \param type pixel type.
420 * \return bytes per pixel, or -1 if a bad format or type was given.
423 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
425 GLint comps
= _mesa_components_in_format(format
);
431 return 0; /* special case */
433 case GL_UNSIGNED_BYTE
:
434 return comps
* sizeof(GLubyte
);
436 case GL_UNSIGNED_SHORT
:
437 return comps
* sizeof(GLshort
);
439 case GL_UNSIGNED_INT
:
440 return comps
* sizeof(GLint
);
442 return comps
* sizeof(GLfloat
);
443 case GL_HALF_FLOAT_ARB
:
444 case GL_HALF_FLOAT_OES
:
445 return comps
* sizeof(GLhalfARB
);
446 case GL_UNSIGNED_BYTE_3_3_2
:
447 case GL_UNSIGNED_BYTE_2_3_3_REV
:
448 if (format
== GL_RGB
|| format
== GL_BGR
||
449 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
450 return sizeof(GLubyte
);
452 return -1; /* error */
453 case GL_UNSIGNED_SHORT_5_6_5
:
454 case GL_UNSIGNED_SHORT_5_6_5_REV
:
455 if (format
== GL_RGB
|| format
== GL_BGR
||
456 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
457 return sizeof(GLushort
);
459 return -1; /* error */
460 case GL_UNSIGNED_SHORT_4_4_4_4
:
461 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
462 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
463 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
464 return sizeof(GLushort
);
467 case GL_UNSIGNED_SHORT_5_5_5_1
:
468 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
469 if (format
== GL_RGBA
|| format
== GL_BGRA
||
470 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
471 return sizeof(GLushort
);
474 case GL_UNSIGNED_INT_8_8_8_8
:
475 case GL_UNSIGNED_INT_8_8_8_8_REV
:
476 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
477 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
479 return sizeof(GLuint
);
482 case GL_UNSIGNED_INT_10_10_10_2
:
483 case GL_UNSIGNED_INT_2_10_10_10_REV
:
484 if (format
== GL_RGBA
|| format
== GL_BGRA
||
485 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
487 return sizeof(GLuint
);
490 case GL_UNSIGNED_SHORT_8_8_MESA
:
491 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
492 if (format
== GL_YCBCR_MESA
)
493 return sizeof(GLushort
);
496 case GL_UNSIGNED_INT_24_8_EXT
:
497 if (format
== GL_DEPTH_STENCIL_EXT
)
498 return sizeof(GLuint
);
501 case GL_UNSIGNED_INT_5_9_9_9_REV
:
502 if (format
== GL_RGB
)
503 return sizeof(GLuint
);
506 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
507 if (format
== GL_RGB
)
508 return sizeof(GLuint
);
511 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
512 if (format
== GL_DEPTH_STENCIL
)
523 * Get the number of bytes for a vertex attrib with the given number of
524 * components and type.
526 * \param comps number of components.
527 * \param type data type.
529 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
532 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
536 case GL_UNSIGNED_BYTE
:
537 return comps
* sizeof(GLubyte
);
539 case GL_UNSIGNED_SHORT
:
540 return comps
* sizeof(GLshort
);
542 case GL_UNSIGNED_INT
:
543 return comps
* sizeof(GLint
);
545 return comps
* sizeof(GLfloat
);
546 case GL_HALF_FLOAT_ARB
:
547 return comps
* sizeof(GLhalfARB
);
549 return comps
* sizeof(GLdouble
);
551 return comps
* sizeof(GLfixed
);
552 case GL_INT_2_10_10_10_REV
:
553 case GL_UNSIGNED_INT_2_10_10_10_REV
:
555 return sizeof(GLuint
);
558 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
560 return sizeof(GLuint
);
569 * Test if the given format is unsized.
572 _mesa_is_enum_format_unsized(GLenum format
)
587 case GL_LUMINANCE_ALPHA
:
592 case GL_SLUMINANCE_ALPHA
:
599 case GL_INTENSITY_SNORM
:
600 case GL_LUMINANCE_SNORM
:
601 case GL_LUMINANCE_ALPHA_SNORM
:
604 case GL_GREEN_INTEGER
:
605 case GL_BLUE_INTEGER
:
606 case GL_ALPHA_INTEGER
:
608 case GL_RGBA_INTEGER
:
610 case GL_BGRA_INTEGER
:
612 case GL_LUMINANCE_INTEGER_EXT
:
613 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
615 case GL_DEPTH_COMPONENT
:
616 case GL_DEPTH_STENCIL
:
617 case GL_STENCIL_INDEX
:
625 * Test if the given format is a UNORM (unsigned-normalized) format.
628 _mesa_is_enum_format_unorm(GLenum format
)
647 case GL_LUMINANCE_ALPHA
:
648 case GL_SLUMINANCE_ALPHA
:
649 case GL_LUMINANCE4_ALPHA4
:
650 case GL_LUMINANCE6_ALPHA2
:
651 case GL_LUMINANCE8_ALPHA8
:
652 case GL_LUMINANCE12_ALPHA4
:
653 case GL_LUMINANCE12_ALPHA12
:
654 case GL_LUMINANCE16_ALPHA16
:
696 * Test if the given format is a SNORM (signed-normalized) format.
699 _mesa_is_enum_format_snorm(GLenum format
)
702 /* signed, normalized texture formats */
714 case GL_RGBA16_SNORM
:
716 case GL_ALPHA8_SNORM
:
717 case GL_ALPHA16_SNORM
:
718 case GL_LUMINANCE_SNORM
:
719 case GL_LUMINANCE8_SNORM
:
720 case GL_LUMINANCE16_SNORM
:
721 case GL_LUMINANCE_ALPHA_SNORM
:
722 case GL_LUMINANCE8_ALPHA8_SNORM
:
723 case GL_LUMINANCE16_ALPHA16_SNORM
:
724 case GL_INTENSITY_SNORM
:
725 case GL_INTENSITY8_SNORM
:
726 case GL_INTENSITY16_SNORM
:
734 * Test if the given format is an integer (non-normalized) format.
737 _mesa_is_enum_format_unsigned_int(GLenum format
)
740 /* specific integer formats */
741 case GL_RGBA32UI_EXT
:
745 case GL_ALPHA32UI_EXT
:
746 case GL_INTENSITY32UI_EXT
:
747 case GL_LUMINANCE32UI_EXT
:
748 case GL_LUMINANCE_ALPHA32UI_EXT
:
749 case GL_RGBA16UI_EXT
:
753 case GL_ALPHA16UI_EXT
:
754 case GL_INTENSITY16UI_EXT
:
755 case GL_LUMINANCE16UI_EXT
:
756 case GL_LUMINANCE_ALPHA16UI_EXT
:
761 case GL_ALPHA8UI_EXT
:
762 case GL_INTENSITY8UI_EXT
:
763 case GL_LUMINANCE8UI_EXT
:
764 case GL_LUMINANCE_ALPHA8UI_EXT
:
774 * Test if the given format is an integer (non-normalized) format.
777 _mesa_is_enum_format_signed_int(GLenum format
)
780 /* generic integer formats */
781 case GL_RED_INTEGER_EXT
:
782 case GL_GREEN_INTEGER_EXT
:
783 case GL_BLUE_INTEGER_EXT
:
784 case GL_ALPHA_INTEGER_EXT
:
785 case GL_RGB_INTEGER_EXT
:
786 case GL_RGBA_INTEGER_EXT
:
787 case GL_BGR_INTEGER_EXT
:
788 case GL_BGRA_INTEGER_EXT
:
789 case GL_LUMINANCE_INTEGER_EXT
:
790 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
792 /* specific integer formats */
797 case GL_ALPHA32I_EXT
:
798 case GL_INTENSITY32I_EXT
:
799 case GL_LUMINANCE32I_EXT
:
800 case GL_LUMINANCE_ALPHA32I_EXT
:
805 case GL_ALPHA16I_EXT
:
806 case GL_INTENSITY16I_EXT
:
807 case GL_LUMINANCE16I_EXT
:
808 case GL_LUMINANCE_ALPHA16I_EXT
:
814 case GL_INTENSITY8I_EXT
:
815 case GL_LUMINANCE8I_EXT
:
816 case GL_LUMINANCE_ALPHA8I_EXT
:
825 * Test if the given format is an integer (non-normalized) format.
828 _mesa_is_enum_format_integer(GLenum format
)
830 return _mesa_is_enum_format_unsigned_int(format
) ||
831 _mesa_is_enum_format_signed_int(format
);
836 _mesa_is_type_unsigned(GLenum type
)
839 case GL_UNSIGNED_INT
:
840 case GL_UNSIGNED_INT_8_8_8_8
:
841 case GL_UNSIGNED_INT_8_8_8_8_REV
:
842 case GL_UNSIGNED_INT_10_10_10_2
:
843 case GL_UNSIGNED_INT_2_10_10_10_REV
:
845 case GL_UNSIGNED_SHORT
:
846 case GL_UNSIGNED_SHORT_4_4_4_4
:
847 case GL_UNSIGNED_SHORT_5_5_5_1
:
848 case GL_UNSIGNED_SHORT_5_6_5
:
849 case GL_UNSIGNED_SHORT_5_6_5_REV
:
850 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
851 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
852 case GL_UNSIGNED_SHORT_8_8_MESA
:
853 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
855 case GL_UNSIGNED_BYTE
:
856 case GL_UNSIGNED_BYTE_3_3_2
:
857 case GL_UNSIGNED_BYTE_2_3_3_REV
:
867 * Test if the given image format is a color/RGBA format (i.e., not color
868 * index, depth, stencil, etc).
869 * \param format the image format value (may by an internal texture format)
870 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
873 _mesa_is_color_format(GLenum format
)
891 case GL_LUMINANCE_ALPHA
:
892 case GL_LUMINANCE4_ALPHA4
:
893 case GL_LUMINANCE6_ALPHA2
:
894 case GL_LUMINANCE8_ALPHA8
:
895 case GL_LUMINANCE12_ALPHA4
:
896 case GL_LUMINANCE12_ALPHA12
:
897 case GL_LUMINANCE16_ALPHA16
:
930 /* float texture formats */
931 case GL_ALPHA16F_ARB
:
932 case GL_ALPHA32F_ARB
:
933 case GL_LUMINANCE16F_ARB
:
934 case GL_LUMINANCE32F_ARB
:
935 case GL_LUMINANCE_ALPHA16F_ARB
:
936 case GL_LUMINANCE_ALPHA32F_ARB
:
937 case GL_INTENSITY16F_ARB
:
938 case GL_INTENSITY32F_ARB
:
947 /* compressed formats */
948 case GL_COMPRESSED_ALPHA
:
949 case GL_COMPRESSED_LUMINANCE
:
950 case GL_COMPRESSED_LUMINANCE_ALPHA
:
951 case GL_COMPRESSED_INTENSITY
:
952 case GL_COMPRESSED_RED
:
953 case GL_COMPRESSED_RG
:
954 case GL_COMPRESSED_RGB
:
955 case GL_COMPRESSED_RGBA
:
960 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
961 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
962 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
963 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
964 case GL_COMPRESSED_RGB_FXT1_3DFX
:
965 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
968 case GL_SRGB_ALPHA_EXT
:
969 case GL_SRGB8_ALPHA8_EXT
:
970 case GL_SLUMINANCE_ALPHA_EXT
:
971 case GL_SLUMINANCE8_ALPHA8_EXT
:
972 case GL_SLUMINANCE_EXT
:
973 case GL_SLUMINANCE8_EXT
:
974 case GL_COMPRESSED_SRGB_EXT
:
975 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
976 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
977 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
978 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
979 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
980 case GL_COMPRESSED_SLUMINANCE_EXT
:
981 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
982 case GL_COMPRESSED_RED_RGTC1
:
983 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
984 case GL_COMPRESSED_RG_RGTC2
:
985 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
986 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
987 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
988 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
989 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
990 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
991 case GL_ETC1_RGB8_OES
:
992 case GL_COMPRESSED_RGB8_ETC2
:
993 case GL_COMPRESSED_SRGB8_ETC2
:
994 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
995 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
996 case GL_COMPRESSED_R11_EAC
:
997 case GL_COMPRESSED_RG11_EAC
:
998 case GL_COMPRESSED_SIGNED_R11_EAC
:
999 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1000 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1001 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1002 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1003 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1004 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1005 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1006 /* generic integer formats */
1007 case GL_RED_INTEGER_EXT
:
1008 case GL_GREEN_INTEGER_EXT
:
1009 case GL_BLUE_INTEGER_EXT
:
1010 case GL_ALPHA_INTEGER_EXT
:
1011 case GL_RGB_INTEGER_EXT
:
1012 case GL_RGBA_INTEGER_EXT
:
1013 case GL_BGR_INTEGER_EXT
:
1014 case GL_BGRA_INTEGER_EXT
:
1016 case GL_LUMINANCE_INTEGER_EXT
:
1017 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1018 /* sized integer formats */
1019 case GL_RGBA32UI_EXT
:
1020 case GL_RGB32UI_EXT
:
1023 case GL_ALPHA32UI_EXT
:
1024 case GL_INTENSITY32UI_EXT
:
1025 case GL_LUMINANCE32UI_EXT
:
1026 case GL_LUMINANCE_ALPHA32UI_EXT
:
1027 case GL_RGBA16UI_EXT
:
1028 case GL_RGB16UI_EXT
:
1031 case GL_ALPHA16UI_EXT
:
1032 case GL_INTENSITY16UI_EXT
:
1033 case GL_LUMINANCE16UI_EXT
:
1034 case GL_LUMINANCE_ALPHA16UI_EXT
:
1035 case GL_RGBA8UI_EXT
:
1039 case GL_ALPHA8UI_EXT
:
1040 case GL_INTENSITY8UI_EXT
:
1041 case GL_LUMINANCE8UI_EXT
:
1042 case GL_LUMINANCE_ALPHA8UI_EXT
:
1043 case GL_RGBA32I_EXT
:
1047 case GL_ALPHA32I_EXT
:
1048 case GL_INTENSITY32I_EXT
:
1049 case GL_LUMINANCE32I_EXT
:
1050 case GL_LUMINANCE_ALPHA32I_EXT
:
1051 case GL_RGBA16I_EXT
:
1055 case GL_ALPHA16I_EXT
:
1056 case GL_INTENSITY16I_EXT
:
1057 case GL_LUMINANCE16I_EXT
:
1058 case GL_LUMINANCE_ALPHA16I_EXT
:
1063 case GL_ALPHA8I_EXT
:
1064 case GL_INTENSITY8I_EXT
:
1065 case GL_LUMINANCE8I_EXT
:
1066 case GL_LUMINANCE_ALPHA8I_EXT
:
1067 /* signed, normalized texture formats */
1076 case GL_RGB16_SNORM
:
1078 case GL_RGBA8_SNORM
:
1079 case GL_RGBA16_SNORM
:
1080 case GL_ALPHA_SNORM
:
1081 case GL_ALPHA8_SNORM
:
1082 case GL_ALPHA16_SNORM
:
1083 case GL_LUMINANCE_SNORM
:
1084 case GL_LUMINANCE8_SNORM
:
1085 case GL_LUMINANCE16_SNORM
:
1086 case GL_LUMINANCE_ALPHA_SNORM
:
1087 case GL_LUMINANCE8_ALPHA8_SNORM
:
1088 case GL_LUMINANCE16_ALPHA16_SNORM
:
1089 case GL_INTENSITY_SNORM
:
1090 case GL_INTENSITY8_SNORM
:
1091 case GL_INTENSITY16_SNORM
:
1093 case GL_R11F_G11F_B10F
:
1096 case GL_YCBCR_MESA
: /* not considered to be RGB */
1105 * Test if the given image format is a depth component format.
1108 _mesa_is_depth_format(GLenum format
)
1111 case GL_DEPTH_COMPONENT
:
1112 case GL_DEPTH_COMPONENT16
:
1113 case GL_DEPTH_COMPONENT24
:
1114 case GL_DEPTH_COMPONENT32
:
1115 case GL_DEPTH_COMPONENT32F
:
1124 * Test if the given image format is a stencil format.
1127 _mesa_is_stencil_format(GLenum format
)
1130 case GL_STENCIL_INDEX
:
1139 * Test if the given image format is a YCbCr format.
1142 _mesa_is_ycbcr_format(GLenum format
)
1154 * Test if the given image format is a depth+stencil format.
1157 _mesa_is_depthstencil_format(GLenum format
)
1160 case GL_DEPTH24_STENCIL8_EXT
:
1161 case GL_DEPTH_STENCIL_EXT
:
1162 case GL_DEPTH32F_STENCIL8
:
1171 * Test if the given image format is a depth or stencil format.
1174 _mesa_is_depth_or_stencil_format(GLenum format
)
1177 case GL_DEPTH_COMPONENT
:
1178 case GL_DEPTH_COMPONENT16
:
1179 case GL_DEPTH_COMPONENT24
:
1180 case GL_DEPTH_COMPONENT32
:
1181 case GL_STENCIL_INDEX
:
1182 case GL_STENCIL_INDEX1_EXT
:
1183 case GL_STENCIL_INDEX4_EXT
:
1184 case GL_STENCIL_INDEX8_EXT
:
1185 case GL_STENCIL_INDEX16_EXT
:
1186 case GL_DEPTH_STENCIL_EXT
:
1187 case GL_DEPTH24_STENCIL8_EXT
:
1188 case GL_DEPTH_COMPONENT32F
:
1189 case GL_DEPTH32F_STENCIL8
:
1198 * Test if an image format is a supported compressed format.
1199 * \param format the internal format token provided by the user.
1200 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1203 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1206 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1207 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1208 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1209 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1210 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
1212 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1217 return _mesa_is_desktop_gl(ctx
) &&
1218 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1219 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1220 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1221 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1222 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1223 return _mesa_is_desktop_gl(ctx
)
1224 && ctx
->Extensions
.EXT_texture_sRGB
1225 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1226 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1227 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1228 return _mesa_is_desktop_gl(ctx
)
1229 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1230 case GL_COMPRESSED_RED_RGTC1
:
1231 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1232 case GL_COMPRESSED_RG_RGTC2
:
1233 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1234 return _mesa_is_desktop_gl(ctx
)
1235 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1236 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1237 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1238 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1239 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1240 return ctx
->API
== API_OPENGL_COMPAT
1241 && ctx
->Extensions
.EXT_texture_compression_latc
;
1242 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1243 return ctx
->API
== API_OPENGL_COMPAT
1244 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1245 case GL_ETC1_RGB8_OES
:
1246 return _mesa_is_gles(ctx
)
1247 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1248 case GL_COMPRESSED_RGB8_ETC2
:
1249 case GL_COMPRESSED_SRGB8_ETC2
:
1250 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1251 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1252 case GL_COMPRESSED_R11_EAC
:
1253 case GL_COMPRESSED_RG11_EAC
:
1254 case GL_COMPRESSED_SIGNED_R11_EAC
:
1255 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1256 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1257 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1258 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1259 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1260 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1261 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1262 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1263 return _mesa_is_desktop_gl(ctx
) &&
1264 ctx
->Extensions
.ARB_texture_compression_bptc
;
1265 case GL_PALETTE4_RGB8_OES
:
1266 case GL_PALETTE4_RGBA8_OES
:
1267 case GL_PALETTE4_R5_G6_B5_OES
:
1268 case GL_PALETTE4_RGBA4_OES
:
1269 case GL_PALETTE4_RGB5_A1_OES
:
1270 case GL_PALETTE8_RGB8_OES
:
1271 case GL_PALETTE8_RGBA8_OES
:
1272 case GL_PALETTE8_R5_G6_B5_OES
:
1273 case GL_PALETTE8_RGBA4_OES
:
1274 case GL_PALETTE8_RGB5_A1_OES
:
1275 return ctx
->API
== API_OPENGLES
;
1283 * Convert various base formats to the cooresponding integer format.
1286 _mesa_base_format_to_integer_format(GLenum format
)
1290 return GL_RED_INTEGER
;
1292 return GL_GREEN_INTEGER
;
1294 return GL_BLUE_INTEGER
;
1296 return GL_RG_INTEGER
;
1298 return GL_RGB_INTEGER
;
1300 return GL_RGBA_INTEGER
;
1302 return GL_BGR_INTEGER
;
1304 return GL_BGRA_INTEGER
;
1306 return GL_ALPHA_INTEGER
;
1308 return GL_LUMINANCE_INTEGER_EXT
;
1309 case GL_LUMINANCE_ALPHA
:
1310 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1318 * Does the given base texture/renderbuffer format have the channel
1322 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1325 case GL_TEXTURE_RED_SIZE
:
1326 case GL_TEXTURE_RED_TYPE
:
1327 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1328 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1329 if (base_format
== GL_RED
||
1330 base_format
== GL_RG
||
1331 base_format
== GL_RGB
||
1332 base_format
== GL_RGBA
) {
1336 case GL_TEXTURE_GREEN_SIZE
:
1337 case GL_TEXTURE_GREEN_TYPE
:
1338 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1339 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1340 if (base_format
== GL_RG
||
1341 base_format
== GL_RGB
||
1342 base_format
== GL_RGBA
) {
1346 case GL_TEXTURE_BLUE_SIZE
:
1347 case GL_TEXTURE_BLUE_TYPE
:
1348 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1349 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1350 if (base_format
== GL_RGB
||
1351 base_format
== GL_RGBA
) {
1355 case GL_TEXTURE_ALPHA_SIZE
:
1356 case GL_TEXTURE_ALPHA_TYPE
:
1357 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1358 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1359 if (base_format
== GL_RGBA
||
1360 base_format
== GL_ALPHA
||
1361 base_format
== GL_LUMINANCE_ALPHA
) {
1365 case GL_TEXTURE_LUMINANCE_SIZE
:
1366 case GL_TEXTURE_LUMINANCE_TYPE
:
1367 if (base_format
== GL_LUMINANCE
||
1368 base_format
== GL_LUMINANCE_ALPHA
) {
1372 case GL_TEXTURE_INTENSITY_SIZE
:
1373 case GL_TEXTURE_INTENSITY_TYPE
:
1374 if (base_format
== GL_INTENSITY
) {
1378 case GL_TEXTURE_DEPTH_SIZE
:
1379 case GL_TEXTURE_DEPTH_TYPE
:
1380 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1381 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1382 if (base_format
== GL_DEPTH_STENCIL
||
1383 base_format
== GL_DEPTH_COMPONENT
) {
1387 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1388 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1389 if (base_format
== GL_DEPTH_STENCIL
||
1390 base_format
== GL_STENCIL_INDEX
) {
1395 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1396 __FUNCTION__
, pname
);
1405 * Returns the number of channels/components for a base format.
1408 _mesa_base_format_component_count(GLenum base_format
)
1410 switch (base_format
) {
1414 case GL_DEPTH_COMPONENT
:
1417 case GL_LUMINANCE_ALPHA
:
1418 case GL_DEPTH_STENCIL
:
1431 * If format is a generic compressed format, return the corresponding
1432 * non-compressed format. For other formats, return the format as-is.
1435 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1438 case GL_COMPRESSED_RED
:
1440 case GL_COMPRESSED_RG
:
1442 case GL_COMPRESSED_RGB
:
1444 case GL_COMPRESSED_RGBA
:
1446 case GL_COMPRESSED_ALPHA
:
1448 case GL_COMPRESSED_LUMINANCE
:
1449 return GL_LUMINANCE
;
1450 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1451 return GL_LUMINANCE_ALPHA
;
1452 case GL_COMPRESSED_INTENSITY
:
1453 return GL_INTENSITY
;
1455 case GL_COMPRESSED_SRGB
:
1457 case GL_COMPRESSED_SRGB_ALPHA
:
1458 return GL_SRGB_ALPHA
;
1459 case GL_COMPRESSED_SLUMINANCE
:
1460 return GL_SLUMINANCE
;
1461 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1462 return GL_SLUMINANCE_ALPHA
;
1470 * Return the equivalent non-generic internal format.
1471 * This is useful for comparing whether two internal formats are equivalent.
1474 _mesa_get_nongeneric_internalformat(GLenum format
)
1477 /* GL 1.1 formats. */
1485 case GL_LUMINANCE_ALPHA
:
1486 return GL_LUMINANCE8_ALPHA8
;
1489 return GL_LUMINANCE8
;
1493 return GL_INTENSITY8
;
1495 /* GL_ARB_texture_rg */
1501 /* GL_EXT_texture_sRGB */
1505 return GL_SRGB8_ALPHA8
;
1507 return GL_SLUMINANCE8
;
1508 case GL_SLUMINANCE_ALPHA
:
1509 return GL_SLUMINANCE8_ALPHA8
;
1511 /* GL_EXT_texture_snorm */
1513 return GL_RGBA8_SNORM
;
1515 return GL_RGB8_SNORM
;
1517 return GL_RG8_SNORM
;
1520 case GL_LUMINANCE_ALPHA_SNORM
:
1521 return GL_LUMINANCE8_ALPHA8_SNORM
;
1522 case GL_LUMINANCE_SNORM
:
1523 return GL_LUMINANCE8_SNORM
;
1524 case GL_ALPHA_SNORM
:
1525 return GL_ALPHA8_SNORM
;
1526 case GL_INTENSITY_SNORM
:
1527 return GL_INTENSITY8_SNORM
;
1536 * Convert an sRGB internal format to linear.
1539 _mesa_get_linear_internalformat(GLenum format
)
1548 case GL_SRGB8_ALPHA8
:
1550 case GL_SLUMINANCE8
:
1551 return GL_LUMINANCE8
;
1553 return GL_LUMINANCE
;
1554 case GL_SLUMINANCE_ALPHA
:
1555 return GL_LUMINANCE_ALPHA
;
1556 case GL_SLUMINANCE8_ALPHA8
:
1557 return GL_LUMINANCE8_ALPHA8
;
1565 * Do error checking of format/type combinations for glReadPixels,
1566 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1567 * and type values, we may either generate GL_INVALID_OPERATION or
1570 * \param format pixel format.
1571 * \param type pixel type.
1573 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1576 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1577 GLenum format
, GLenum type
)
1579 /* From OpenGL 3.3 spec, page 220:
1580 * "If the format is DEPTH_STENCIL, then values are taken from
1581 * both the depth buffer and the stencil buffer. If there is no
1582 * depth buffer or if there is no stencil buffer, then the error
1583 * INVALID_OPERATION occurs. If the type parameter is not
1584 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1585 * error INVALID_ENUM occurs."
1587 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1588 * cannot be used to read depth or stencil in that API.
1590 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1591 && type
!= GL_UNSIGNED_INT_24_8
1592 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1593 return GL_INVALID_ENUM
;
1595 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1598 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1599 return GL_INVALID_ENUM
;
1603 case GL_UNSIGNED_BYTE_3_3_2
:
1604 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1605 case GL_UNSIGNED_SHORT_5_6_5
:
1606 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1607 if (format
== GL_RGB
) {
1610 if (format
== GL_RGB_INTEGER_EXT
&&
1611 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1614 return GL_INVALID_OPERATION
;
1616 case GL_UNSIGNED_SHORT_4_4_4_4
:
1617 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1618 case GL_UNSIGNED_INT_8_8_8_8
:
1619 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1620 if (format
== GL_RGBA
||
1621 format
== GL_BGRA
||
1622 format
== GL_ABGR_EXT
) {
1625 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1626 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1629 return GL_INVALID_OPERATION
;
1631 case GL_UNSIGNED_SHORT_5_5_5_1
:
1632 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1633 case GL_UNSIGNED_INT_10_10_10_2
:
1634 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1635 if (format
== GL_RGBA
||
1636 format
== GL_BGRA
) {
1639 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1640 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1643 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1644 ctx
->API
== API_OPENGLES2
) {
1645 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1647 return GL_INVALID_OPERATION
;
1649 case GL_UNSIGNED_INT_24_8
:
1650 if (format
!= GL_DEPTH_STENCIL
) {
1651 return GL_INVALID_OPERATION
;
1655 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1656 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1657 return GL_INVALID_ENUM
;
1659 if (format
!= GL_DEPTH_STENCIL
) {
1660 return GL_INVALID_OPERATION
;
1664 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1665 if (!ctx
->Extensions
.EXT_packed_float
) {
1666 return GL_INVALID_ENUM
;
1668 if (format
!= GL_RGB
) {
1669 return GL_INVALID_OPERATION
;
1673 case GL_HALF_FLOAT_OES
:
1677 case GL_LUMINANCE_ALPHA
:
1682 return GL_INVALID_OPERATION
;
1686 ; /* fall-through */
1689 /* now, for each format, check the type for compatibility */
1691 case GL_COLOR_INDEX
:
1692 case GL_STENCIL_INDEX
:
1696 case GL_UNSIGNED_BYTE
:
1698 case GL_UNSIGNED_SHORT
:
1700 case GL_UNSIGNED_INT
:
1705 return GL_INVALID_ENUM
;
1712 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1716 case GL_LUMINANCE_ALPHA
:
1717 case GL_DEPTH_COMPONENT
:
1720 case GL_UNSIGNED_BYTE
:
1722 case GL_UNSIGNED_SHORT
:
1724 case GL_UNSIGNED_INT
:
1729 return GL_INVALID_ENUM
;
1733 if (!ctx
->Extensions
.ARB_texture_rg
)
1734 return GL_INVALID_ENUM
;
1737 case GL_UNSIGNED_BYTE
:
1739 case GL_UNSIGNED_SHORT
:
1741 case GL_UNSIGNED_INT
:
1746 return GL_INVALID_ENUM
;
1752 case GL_UNSIGNED_BYTE
:
1754 case GL_UNSIGNED_SHORT
:
1756 case GL_UNSIGNED_INT
:
1758 case GL_UNSIGNED_BYTE_3_3_2
:
1759 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1760 case GL_UNSIGNED_SHORT_5_6_5
:
1761 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1764 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1765 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1766 return (ctx
->API
== API_OPENGLES2
)
1767 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1768 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1769 return ctx
->Extensions
.EXT_texture_shared_exponent
1770 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1771 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1772 return ctx
->Extensions
.EXT_packed_float
1773 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1775 return GL_INVALID_ENUM
;
1780 /* NOTE: no packed types are supported with BGR. That's
1781 * intentional, according to the GL spec.
1784 case GL_UNSIGNED_BYTE
:
1786 case GL_UNSIGNED_SHORT
:
1788 case GL_UNSIGNED_INT
:
1793 return GL_INVALID_ENUM
;
1800 case GL_UNSIGNED_BYTE
:
1802 case GL_UNSIGNED_SHORT
:
1804 case GL_UNSIGNED_INT
:
1806 case GL_UNSIGNED_SHORT_4_4_4_4
:
1807 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1808 case GL_UNSIGNED_SHORT_5_5_5_1
:
1809 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1810 case GL_UNSIGNED_INT_8_8_8_8
:
1811 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1812 case GL_UNSIGNED_INT_10_10_10_2
:
1813 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1817 return GL_INVALID_ENUM
;
1823 case GL_UNSIGNED_BYTE
:
1825 case GL_UNSIGNED_SHORT
:
1827 case GL_UNSIGNED_INT
:
1829 case GL_UNSIGNED_SHORT_4_4_4_4
:
1830 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1831 case GL_UNSIGNED_INT_8_8_8_8
:
1832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1836 return GL_INVALID_ENUM
;
1840 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1841 return GL_INVALID_ENUM
;
1842 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1843 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1846 return GL_INVALID_OPERATION
;
1848 case GL_DEPTH_STENCIL
:
1849 if (type
== GL_UNSIGNED_INT_24_8
)
1851 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1852 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1855 return GL_INVALID_ENUM
;
1857 /* integer-valued formats */
1858 case GL_RED_INTEGER_EXT
:
1859 case GL_GREEN_INTEGER_EXT
:
1860 case GL_BLUE_INTEGER_EXT
:
1861 case GL_ALPHA_INTEGER_EXT
:
1865 case GL_UNSIGNED_BYTE
:
1867 case GL_UNSIGNED_SHORT
:
1869 case GL_UNSIGNED_INT
:
1870 return (ctx
->Version
>= 30 ||
1871 ctx
->Extensions
.EXT_texture_integer
)
1872 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1874 return GL_INVALID_ENUM
;
1877 case GL_RGB_INTEGER_EXT
:
1880 case GL_UNSIGNED_BYTE
:
1882 case GL_UNSIGNED_SHORT
:
1884 case GL_UNSIGNED_INT
:
1885 return (ctx
->Version
>= 30 ||
1886 ctx
->Extensions
.EXT_texture_integer
)
1887 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1888 case GL_UNSIGNED_BYTE_3_3_2
:
1889 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1890 case GL_UNSIGNED_SHORT_5_6_5
:
1891 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1892 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1893 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1895 return GL_INVALID_ENUM
;
1898 case GL_BGR_INTEGER_EXT
:
1901 case GL_UNSIGNED_BYTE
:
1903 case GL_UNSIGNED_SHORT
:
1905 case GL_UNSIGNED_INT
:
1906 /* NOTE: no packed formats w/ BGR format */
1907 return (ctx
->Version
>= 30 ||
1908 ctx
->Extensions
.EXT_texture_integer
)
1909 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1911 return GL_INVALID_ENUM
;
1914 case GL_RGBA_INTEGER_EXT
:
1915 case GL_BGRA_INTEGER_EXT
:
1918 case GL_UNSIGNED_BYTE
:
1920 case GL_UNSIGNED_SHORT
:
1922 case GL_UNSIGNED_INT
:
1923 return (ctx
->Version
>= 30 ||
1924 ctx
->Extensions
.EXT_texture_integer
)
1925 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1926 case GL_UNSIGNED_SHORT_4_4_4_4
:
1927 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1928 case GL_UNSIGNED_SHORT_5_5_5_1
:
1929 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1930 case GL_UNSIGNED_INT_8_8_8_8
:
1931 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1932 case GL_UNSIGNED_INT_10_10_10_2
:
1933 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1934 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1935 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1937 return GL_INVALID_ENUM
;
1940 case GL_LUMINANCE_INTEGER_EXT
:
1941 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1944 case GL_UNSIGNED_BYTE
:
1946 case GL_UNSIGNED_SHORT
:
1948 case GL_UNSIGNED_INT
:
1949 return ctx
->Extensions
.EXT_texture_integer
1950 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1952 return GL_INVALID_ENUM
;
1956 return GL_INVALID_ENUM
;
1963 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1964 * and glTex[Sub]Image.
1965 * \return error code, or GL_NO_ERROR.
1968 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1969 unsigned dimensions
)
1971 GLboolean type_valid
= GL_TRUE
;
1976 case GL_LUMINANCE_ALPHA
:
1977 type_valid
= (type
== GL_UNSIGNED_BYTE
1979 || type
== GL_HALF_FLOAT_OES
);
1983 type_valid
= (type
== GL_UNSIGNED_BYTE
1984 || type
== GL_UNSIGNED_SHORT_5_6_5
1986 || type
== GL_HALF_FLOAT_OES
);
1990 type_valid
= (type
== GL_UNSIGNED_BYTE
1991 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1992 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1994 || type
== GL_HALF_FLOAT_OES
1995 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1998 case GL_DEPTH_COMPONENT
:
1999 /* This format is filtered against invalid dimensionalities elsewhere.
2001 type_valid
= (type
== GL_UNSIGNED_SHORT
2002 || type
== GL_UNSIGNED_INT
);
2005 case GL_DEPTH_STENCIL
:
2006 /* This format is filtered against invalid dimensionalities elsewhere.
2008 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2012 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2014 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2015 * the format does not appear to be allowed for 3D textures in OpenGL
2018 if (dimensions
!= 2)
2019 return GL_INVALID_VALUE
;
2024 return GL_INVALID_VALUE
;
2027 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2032 * Do error checking of format/type combinations for OpenGL ES 3
2034 * \return error code, or GL_NO_ERROR.
2037 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2038 GLenum format
, GLenum type
,
2039 GLenum internalFormat
)
2044 case GL_UNSIGNED_BYTE
:
2045 switch (internalFormat
) {
2050 case GL_SRGB8_ALPHA8_EXT
:
2053 return GL_INVALID_OPERATION
;
2058 if (internalFormat
!= GL_RGBA8_SNORM
)
2059 return GL_INVALID_OPERATION
;
2062 case GL_UNSIGNED_SHORT_4_4_4_4
:
2063 switch (internalFormat
) {
2068 return GL_INVALID_OPERATION
;
2072 case GL_UNSIGNED_SHORT_5_5_5_1
:
2073 switch (internalFormat
) {
2078 return GL_INVALID_OPERATION
;
2082 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2083 switch (internalFormat
) {
2084 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2089 return GL_INVALID_OPERATION
;
2094 if (internalFormat
!= GL_RGBA16F
)
2095 return GL_INVALID_OPERATION
;
2099 switch (internalFormat
) {
2104 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2107 return GL_INVALID_OPERATION
;
2111 case GL_HALF_FLOAT_OES
:
2112 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2115 return GL_INVALID_OPERATION
;
2119 case GL_RGBA_INTEGER
:
2121 case GL_UNSIGNED_BYTE
:
2122 if (internalFormat
!= GL_RGBA8UI
)
2123 return GL_INVALID_OPERATION
;
2127 if (internalFormat
!= GL_RGBA8I
)
2128 return GL_INVALID_OPERATION
;
2131 case GL_UNSIGNED_SHORT
:
2132 if (internalFormat
!= GL_RGBA16UI
)
2133 return GL_INVALID_OPERATION
;
2137 if (internalFormat
!= GL_RGBA16I
)
2138 return GL_INVALID_OPERATION
;
2141 case GL_UNSIGNED_INT
:
2142 if (internalFormat
!= GL_RGBA32UI
)
2143 return GL_INVALID_OPERATION
;
2147 if (internalFormat
!= GL_RGBA32I
)
2148 return GL_INVALID_OPERATION
;
2151 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2152 if (internalFormat
!= GL_RGB10_A2UI
)
2153 return GL_INVALID_OPERATION
;
2157 return GL_INVALID_OPERATION
;
2163 case GL_UNSIGNED_BYTE
:
2164 switch (internalFormat
) {
2171 return GL_INVALID_OPERATION
;
2176 if (internalFormat
!= GL_RGB8_SNORM
)
2177 return GL_INVALID_OPERATION
;
2180 case GL_UNSIGNED_SHORT_5_6_5
:
2181 switch (internalFormat
) {
2186 return GL_INVALID_OPERATION
;
2190 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2191 if (internalFormat
!= GL_R11F_G11F_B10F
)
2192 return GL_INVALID_OPERATION
;
2195 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2196 if (internalFormat
!= GL_RGB9_E5
)
2197 return GL_INVALID_OPERATION
;
2201 switch (internalFormat
) {
2203 case GL_R11F_G11F_B10F
:
2207 return GL_INVALID_OPERATION
;
2212 switch (internalFormat
) {
2215 case GL_R11F_G11F_B10F
:
2219 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2222 return GL_INVALID_OPERATION
;
2226 case GL_HALF_FLOAT_OES
:
2227 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2228 return GL_INVALID_OPERATION
;
2231 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2232 switch (internalFormat
) {
2233 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2236 return GL_INVALID_OPERATION
;
2241 return GL_INVALID_OPERATION
;
2245 case GL_RGB_INTEGER
:
2247 case GL_UNSIGNED_BYTE
:
2248 if (internalFormat
!= GL_RGB8UI
)
2249 return GL_INVALID_OPERATION
;
2253 if (internalFormat
!= GL_RGB8I
)
2254 return GL_INVALID_OPERATION
;
2257 case GL_UNSIGNED_SHORT
:
2258 if (internalFormat
!= GL_RGB16UI
)
2259 return GL_INVALID_OPERATION
;
2263 if (internalFormat
!= GL_RGB16I
)
2264 return GL_INVALID_OPERATION
;
2267 case GL_UNSIGNED_INT
:
2268 if (internalFormat
!= GL_RGB32UI
)
2269 return GL_INVALID_OPERATION
;
2273 if (internalFormat
!= GL_RGB32I
)
2274 return GL_INVALID_OPERATION
;
2278 return GL_INVALID_OPERATION
;
2284 case GL_UNSIGNED_BYTE
:
2285 if (internalFormat
!= GL_RG8
)
2286 return GL_INVALID_OPERATION
;
2290 if (internalFormat
!= GL_RG8_SNORM
)
2291 return GL_INVALID_OPERATION
;
2295 if (internalFormat
!= GL_RG16F
)
2296 return GL_INVALID_OPERATION
;
2300 switch (internalFormat
) {
2305 return GL_INVALID_OPERATION
;
2310 return GL_INVALID_OPERATION
;
2316 case GL_UNSIGNED_BYTE
:
2317 if (internalFormat
!= GL_RG8UI
)
2318 return GL_INVALID_OPERATION
;
2322 if (internalFormat
!= GL_RG8I
)
2323 return GL_INVALID_OPERATION
;
2326 case GL_UNSIGNED_SHORT
:
2327 if (internalFormat
!= GL_RG16UI
)
2328 return GL_INVALID_OPERATION
;
2332 if (internalFormat
!= GL_RG16I
)
2333 return GL_INVALID_OPERATION
;
2336 case GL_UNSIGNED_INT
:
2337 if (internalFormat
!= GL_RG32UI
)
2338 return GL_INVALID_OPERATION
;
2342 if (internalFormat
!= GL_RG32I
)
2343 return GL_INVALID_OPERATION
;
2347 return GL_INVALID_OPERATION
;
2353 case GL_UNSIGNED_BYTE
:
2354 if (internalFormat
!= GL_R8
)
2355 return GL_INVALID_OPERATION
;
2359 if (internalFormat
!= GL_R8_SNORM
)
2360 return GL_INVALID_OPERATION
;
2364 if (internalFormat
!= GL_R16F
)
2365 return GL_INVALID_OPERATION
;
2369 switch (internalFormat
) {
2374 return GL_INVALID_OPERATION
;
2379 return GL_INVALID_OPERATION
;
2383 case GL_RED_INTEGER
:
2385 case GL_UNSIGNED_BYTE
:
2386 if (internalFormat
!= GL_R8UI
)
2387 return GL_INVALID_OPERATION
;
2391 if (internalFormat
!= GL_R8I
)
2392 return GL_INVALID_OPERATION
;
2395 case GL_UNSIGNED_SHORT
:
2396 if (internalFormat
!= GL_R16UI
)
2397 return GL_INVALID_OPERATION
;
2401 if (internalFormat
!= GL_R16I
)
2402 return GL_INVALID_OPERATION
;
2405 case GL_UNSIGNED_INT
:
2406 if (internalFormat
!= GL_R32UI
)
2407 return GL_INVALID_OPERATION
;
2411 if (internalFormat
!= GL_R32I
)
2412 return GL_INVALID_OPERATION
;
2416 return GL_INVALID_OPERATION
;
2420 case GL_DEPTH_COMPONENT
:
2422 case GL_UNSIGNED_SHORT
:
2423 if (internalFormat
!= GL_DEPTH_COMPONENT
2424 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2425 return GL_INVALID_OPERATION
;
2428 case GL_UNSIGNED_INT
:
2429 switch (internalFormat
) {
2430 case GL_DEPTH_COMPONENT
:
2431 case GL_DEPTH_COMPONENT16
:
2432 case GL_DEPTH_COMPONENT24
:
2435 return GL_INVALID_OPERATION
;
2440 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2441 return GL_INVALID_OPERATION
;
2445 return GL_INVALID_OPERATION
;
2449 case GL_DEPTH_STENCIL
:
2451 case GL_UNSIGNED_INT_24_8
:
2452 if (internalFormat
!= GL_DEPTH_STENCIL
2453 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2454 return GL_INVALID_OPERATION
;
2457 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2458 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2459 return GL_INVALID_OPERATION
;
2463 return GL_INVALID_OPERATION
;
2469 case GL_LUMINANCE_ALPHA
:
2472 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2474 case GL_HALF_FLOAT_OES
:
2475 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2478 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2479 return GL_INVALID_OPERATION
;
2487 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
2489 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
2490 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
2491 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
2492 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
2496 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
2500 case GL_RGBA_INTEGER_EXT
:
2501 set_swizzle(swizzle
, 0, 1, 2, 3);
2504 case GL_BGRA_INTEGER_EXT
:
2505 set_swizzle(swizzle
, 2, 1, 0, 3);
2508 set_swizzle(swizzle
, 3, 2, 1, 0);
2511 case GL_RGB_INTEGER_EXT
:
2512 set_swizzle(swizzle
, 0, 1, 2, 5);
2515 case GL_BGR_INTEGER_EXT
:
2516 set_swizzle(swizzle
, 2, 1, 0, 5);
2518 case GL_LUMINANCE_ALPHA
:
2519 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2520 set_swizzle(swizzle
, 0, 0, 0, 1);
2524 set_swizzle(swizzle
, 0, 1, 4, 5);
2527 case GL_RED_INTEGER_EXT
:
2528 set_swizzle(swizzle
, 0, 4, 4, 5);
2531 case GL_GREEN_INTEGER_EXT
:
2532 set_swizzle(swizzle
, 4, 0, 4, 5);
2535 case GL_BLUE_INTEGER_EXT
:
2536 set_swizzle(swizzle
, 4, 4, 0, 5);
2539 case GL_ALPHA_INTEGER_EXT
:
2540 set_swizzle(swizzle
, 4, 4, 4, 0);
2543 case GL_LUMINANCE_INTEGER_EXT
:
2544 set_swizzle(swizzle
, 0, 0, 0, 5);
2547 set_swizzle(swizzle
, 0, 0, 0, 0);
2555 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
2556 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
2557 * otherwise (for non-array formats).
2559 * This function will typically be used to compute a mesa format from a GL type
2560 * so we can then call _mesa_format_convert. This function does
2561 * not consider byte swapping, so it returns types assuming that no byte
2562 * swapping is involved. If byte swapping is involved then clients are supposed
2563 * to handle that on their side before calling _mesa_format_convert.
2565 * This function returns an uint32_t that can pack a mesa_format or a
2566 * mesa_array_format. Clients must check the mesa array format bit
2567 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
2568 * format is a mesa_array_format or a mesa_format.
2571 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
2573 mesa_array_format array_format
;
2575 bool is_array_format
= true;
2577 bool normalized
= false, is_float
= false, is_signed
= false;
2578 int num_channels
= 0, type_size
= 0;
2580 /* Extract array format type information from the OpenGL data type */
2582 case GL_UNSIGNED_BYTE
:
2589 case GL_UNSIGNED_SHORT
:
2596 case GL_UNSIGNED_INT
:
2604 case GL_HALF_FLOAT_OES
:
2615 is_array_format
= false;
2619 /* Extract array format swizzle information from the OpenGL format */
2620 if (is_array_format
)
2621 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
2623 /* If this is an array format type after checking data type and format,
2624 * create the array format
2626 if (is_array_format
) {
2627 normalized
= !_mesa_is_enum_format_integer(format
);
2628 num_channels
= _mesa_components_in_format(format
);
2631 MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
2632 normalized
, num_channels
,
2633 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
2635 if (!_mesa_little_endian())
2636 array_format
= _mesa_array_format_flip_channels(array_format
);
2638 return array_format
;
2641 /* Otherwise this is not an array format, so return the mesa_format
2642 * matching the OpenGL format and data type
2645 case GL_UNSIGNED_SHORT_5_6_5
:
2646 if (format
== GL_RGB
)
2647 return MESA_FORMAT_B5G6R5_UNORM
;
2648 else if (format
== GL_BGR
)
2649 return MESA_FORMAT_R5G6B5_UNORM
;
2651 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2652 if (format
== GL_RGB
)
2653 return MESA_FORMAT_R5G6B5_UNORM
;
2654 else if (format
== GL_BGR
)
2655 return MESA_FORMAT_B5G6R5_UNORM
;
2657 case GL_UNSIGNED_SHORT_4_4_4_4
:
2658 if (format
== GL_RGBA
)
2659 return MESA_FORMAT_A4B4G4R4_UNORM
;
2660 else if (format
== GL_BGRA
)
2661 return MESA_FORMAT_A4R4G4B4_UNORM
;
2662 else if (format
== GL_ABGR_EXT
)
2663 return MESA_FORMAT_R4G4B4A4_UNORM
;
2665 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2666 if (format
== GL_RGBA
)
2667 return MESA_FORMAT_R4G4B4A4_UNORM
;
2668 else if (format
== GL_BGRA
)
2669 return MESA_FORMAT_B4G4R4A4_UNORM
;
2670 else if (format
== GL_ABGR_EXT
)
2671 return MESA_FORMAT_A4B4G4R4_UNORM
;
2673 case GL_UNSIGNED_SHORT_5_5_5_1
:
2674 if (format
== GL_RGBA
)
2675 return MESA_FORMAT_A1B5G5R5_UNORM
;
2676 else if (format
== GL_BGRA
)
2677 return MESA_FORMAT_A1R5G5B5_UNORM
;
2679 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2680 if (format
== GL_RGBA
)
2681 return MESA_FORMAT_R5G5B5A1_UNORM
;
2682 else if (format
== GL_BGRA
)
2683 return MESA_FORMAT_B5G5R5A1_UNORM
;
2685 case GL_UNSIGNED_BYTE_3_3_2
:
2686 if (format
== GL_RGB
)
2687 return MESA_FORMAT_B2G3R3_UNORM
;
2689 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2690 if (format
== GL_RGB
)
2691 return MESA_FORMAT_R3G3B2_UNORM
;
2693 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2694 if (format
== GL_RGB
)
2695 return MESA_FORMAT_R9G9B9E5_FLOAT
;
2697 case GL_UNSIGNED_INT_10_10_10_2
:
2698 if (format
== GL_RGBA
)
2699 return MESA_FORMAT_A2B10G10R10_UNORM
;
2700 else if (format
== GL_RGBA_INTEGER
)
2701 return MESA_FORMAT_A2B10G10R10_UINT
;
2702 else if (format
== GL_BGRA
)
2703 return MESA_FORMAT_A2R10G10B10_UNORM
;
2704 else if (format
== GL_BGRA_INTEGER
)
2705 return MESA_FORMAT_A2R10G10B10_UINT
;
2707 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2708 if (format
== GL_RGB
)
2709 return MESA_FORMAT_R10G10B10X2_UNORM
;
2710 if (format
== GL_RGBA
)
2711 return MESA_FORMAT_R10G10B10A2_UNORM
;
2712 else if (format
== GL_RGBA_INTEGER
)
2713 return MESA_FORMAT_R10G10B10A2_UINT
;
2714 else if (format
== GL_BGRA
)
2715 return MESA_FORMAT_B10G10R10A2_UNORM
;
2716 else if (format
== GL_BGRA_INTEGER
)
2717 return MESA_FORMAT_B10G10R10A2_UINT
;
2719 case GL_UNSIGNED_INT_8_8_8_8
:
2720 if (format
== GL_RGBA
)
2721 return MESA_FORMAT_A8B8G8R8_UNORM
;
2722 else if (format
== GL_BGRA
)
2723 return MESA_FORMAT_A8R8G8B8_UNORM
;
2724 else if (format
== GL_ABGR_EXT
)
2725 return MESA_FORMAT_R8G8B8A8_UNORM
;
2727 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2728 if (format
== GL_RGBA
)
2729 return MESA_FORMAT_R8G8B8A8_UNORM
;
2730 else if (format
== GL_BGRA
)
2731 return MESA_FORMAT_B8G8R8A8_UNORM
;
2732 else if (format
== GL_ABGR_EXT
)
2733 return MESA_FORMAT_A8B8G8R8_UNORM
;
2735 case GL_UNSIGNED_SHORT_8_8_MESA
:
2736 if (format
== GL_YCBCR_MESA
)
2737 return MESA_FORMAT_YCBCR
;
2739 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
2740 if (format
== GL_YCBCR_MESA
)
2741 return MESA_FORMAT_YCBCR_REV
;
2743 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2744 if (format
== GL_RGB
)
2745 return MESA_FORMAT_R11G11B10_FLOAT
;
2750 /* If we got here it means that we could not find a Mesa format that
2751 * matches the GL format/type provided. We may need to add a new Mesa
2752 * format in that case.
2754 unreachable("Unsupported format");