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_enum_to_string(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_enum_to_string(inFormat
),
220 outFormat
, _mesa_enum_to_string(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(const 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",
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
:
1683 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1686 return GL_INVALID_OPERATION
;
1690 ; /* fall-through */
1693 /* now, for each format, check the type for compatibility */
1695 case GL_COLOR_INDEX
:
1696 case GL_STENCIL_INDEX
:
1700 case GL_UNSIGNED_BYTE
:
1702 case GL_UNSIGNED_SHORT
:
1704 case GL_UNSIGNED_INT
:
1709 return GL_INVALID_ENUM
;
1716 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1720 case GL_LUMINANCE_ALPHA
:
1721 case GL_DEPTH_COMPONENT
:
1724 case GL_UNSIGNED_BYTE
:
1726 case GL_UNSIGNED_SHORT
:
1728 case GL_UNSIGNED_INT
:
1733 return GL_INVALID_ENUM
;
1737 if (!ctx
->Extensions
.ARB_texture_rg
)
1738 return GL_INVALID_ENUM
;
1741 case GL_UNSIGNED_BYTE
:
1743 case GL_UNSIGNED_SHORT
:
1745 case GL_UNSIGNED_INT
:
1750 return GL_INVALID_ENUM
;
1756 case GL_UNSIGNED_BYTE
:
1758 case GL_UNSIGNED_SHORT
:
1760 case GL_UNSIGNED_INT
:
1762 case GL_UNSIGNED_BYTE_3_3_2
:
1763 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1764 case GL_UNSIGNED_SHORT_5_6_5
:
1765 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1768 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1769 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1770 return (ctx
->API
== API_OPENGLES2
)
1771 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1772 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1773 return ctx
->Extensions
.EXT_texture_shared_exponent
1774 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1775 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1776 return ctx
->Extensions
.EXT_packed_float
1777 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1779 return GL_INVALID_ENUM
;
1784 /* NOTE: no packed types are supported with BGR. That's
1785 * intentional, according to the GL spec.
1788 case GL_UNSIGNED_BYTE
:
1790 case GL_UNSIGNED_SHORT
:
1792 case GL_UNSIGNED_INT
:
1797 return GL_INVALID_ENUM
;
1804 case GL_UNSIGNED_BYTE
:
1806 case GL_UNSIGNED_SHORT
:
1808 case GL_UNSIGNED_INT
:
1810 case GL_UNSIGNED_SHORT_4_4_4_4
:
1811 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1812 case GL_UNSIGNED_SHORT_5_5_5_1
:
1813 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1814 case GL_UNSIGNED_INT_8_8_8_8
:
1815 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1816 case GL_UNSIGNED_INT_10_10_10_2
:
1817 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1821 return GL_INVALID_ENUM
;
1827 case GL_UNSIGNED_BYTE
:
1829 case GL_UNSIGNED_SHORT
:
1831 case GL_UNSIGNED_INT
:
1833 case GL_UNSIGNED_SHORT_4_4_4_4
:
1834 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1835 case GL_UNSIGNED_INT_8_8_8_8
:
1836 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1840 return GL_INVALID_ENUM
;
1844 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1845 return GL_INVALID_ENUM
;
1846 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1847 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1850 return GL_INVALID_OPERATION
;
1852 case GL_DEPTH_STENCIL
:
1853 if (type
== GL_UNSIGNED_INT_24_8
)
1855 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1856 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1859 return GL_INVALID_ENUM
;
1861 /* integer-valued formats */
1862 case GL_RED_INTEGER_EXT
:
1863 case GL_GREEN_INTEGER_EXT
:
1864 case GL_BLUE_INTEGER_EXT
:
1865 case GL_ALPHA_INTEGER_EXT
:
1869 case GL_UNSIGNED_BYTE
:
1871 case GL_UNSIGNED_SHORT
:
1873 case GL_UNSIGNED_INT
:
1874 return (ctx
->Version
>= 30 ||
1875 ctx
->Extensions
.EXT_texture_integer
)
1876 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1878 return GL_INVALID_ENUM
;
1881 case GL_RGB_INTEGER_EXT
:
1884 case GL_UNSIGNED_BYTE
:
1886 case GL_UNSIGNED_SHORT
:
1888 case GL_UNSIGNED_INT
:
1889 return (ctx
->Version
>= 30 ||
1890 ctx
->Extensions
.EXT_texture_integer
)
1891 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1892 case GL_UNSIGNED_BYTE_3_3_2
:
1893 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1894 case GL_UNSIGNED_SHORT_5_6_5
:
1895 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1896 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1897 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1899 return GL_INVALID_ENUM
;
1902 case GL_BGR_INTEGER_EXT
:
1905 case GL_UNSIGNED_BYTE
:
1907 case GL_UNSIGNED_SHORT
:
1909 case GL_UNSIGNED_INT
:
1910 /* NOTE: no packed formats w/ BGR format */
1911 return (ctx
->Version
>= 30 ||
1912 ctx
->Extensions
.EXT_texture_integer
)
1913 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1915 return GL_INVALID_ENUM
;
1918 case GL_RGBA_INTEGER_EXT
:
1919 case GL_BGRA_INTEGER_EXT
:
1922 case GL_UNSIGNED_BYTE
:
1924 case GL_UNSIGNED_SHORT
:
1926 case GL_UNSIGNED_INT
:
1927 return (ctx
->Version
>= 30 ||
1928 ctx
->Extensions
.EXT_texture_integer
)
1929 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1930 case GL_UNSIGNED_SHORT_4_4_4_4
:
1931 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1932 case GL_UNSIGNED_SHORT_5_5_5_1
:
1933 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1934 case GL_UNSIGNED_INT_8_8_8_8
:
1935 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1936 case GL_UNSIGNED_INT_10_10_10_2
:
1937 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1938 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1939 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1941 return GL_INVALID_ENUM
;
1944 case GL_LUMINANCE_INTEGER_EXT
:
1945 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1948 case GL_UNSIGNED_BYTE
:
1950 case GL_UNSIGNED_SHORT
:
1952 case GL_UNSIGNED_INT
:
1953 return ctx
->Extensions
.EXT_texture_integer
1954 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1956 return GL_INVALID_ENUM
;
1960 return GL_INVALID_ENUM
;
1967 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1968 * and glTex[Sub]Image.
1969 * \return error code, or GL_NO_ERROR.
1972 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1973 unsigned dimensions
)
1975 GLboolean type_valid
= GL_TRUE
;
1980 case GL_LUMINANCE_ALPHA
:
1981 type_valid
= (type
== GL_UNSIGNED_BYTE
1983 || type
== GL_HALF_FLOAT_OES
);
1987 type_valid
= (type
== GL_UNSIGNED_BYTE
1988 || type
== GL_UNSIGNED_SHORT_5_6_5
1990 || type
== GL_HALF_FLOAT_OES
);
1994 type_valid
= (type
== GL_UNSIGNED_BYTE
1995 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1996 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1998 || type
== GL_HALF_FLOAT_OES
1999 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2002 case GL_DEPTH_COMPONENT
:
2003 /* This format is filtered against invalid dimensionalities elsewhere.
2005 type_valid
= (type
== GL_UNSIGNED_SHORT
2006 || type
== GL_UNSIGNED_INT
);
2009 case GL_DEPTH_STENCIL
:
2010 /* This format is filtered against invalid dimensionalities elsewhere.
2012 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2016 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2018 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2019 * the format does not appear to be allowed for 3D textures in OpenGL
2022 if (dimensions
!= 2)
2023 return GL_INVALID_VALUE
;
2028 return GL_INVALID_VALUE
;
2031 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2036 * Do error checking of format/type combinations for OpenGL ES 3
2038 * \return error code, or GL_NO_ERROR.
2041 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2042 GLenum format
, GLenum type
,
2043 GLenum internalFormat
)
2048 case GL_UNSIGNED_BYTE
:
2049 switch (internalFormat
) {
2054 case GL_SRGB8_ALPHA8_EXT
:
2057 return GL_INVALID_OPERATION
;
2062 if (internalFormat
!= GL_RGBA8_SNORM
)
2063 return GL_INVALID_OPERATION
;
2066 case GL_UNSIGNED_SHORT_4_4_4_4
:
2067 switch (internalFormat
) {
2072 return GL_INVALID_OPERATION
;
2076 case GL_UNSIGNED_SHORT_5_5_5_1
:
2077 switch (internalFormat
) {
2082 return GL_INVALID_OPERATION
;
2086 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2087 switch (internalFormat
) {
2088 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2093 return GL_INVALID_OPERATION
;
2098 if (internalFormat
!= GL_RGBA16F
)
2099 return GL_INVALID_OPERATION
;
2103 switch (internalFormat
) {
2108 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2111 return GL_INVALID_OPERATION
;
2115 case GL_HALF_FLOAT_OES
:
2116 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2119 return GL_INVALID_OPERATION
;
2123 case GL_RGBA_INTEGER
:
2125 case GL_UNSIGNED_BYTE
:
2126 if (internalFormat
!= GL_RGBA8UI
)
2127 return GL_INVALID_OPERATION
;
2131 if (internalFormat
!= GL_RGBA8I
)
2132 return GL_INVALID_OPERATION
;
2135 case GL_UNSIGNED_SHORT
:
2136 if (internalFormat
!= GL_RGBA16UI
)
2137 return GL_INVALID_OPERATION
;
2141 if (internalFormat
!= GL_RGBA16I
)
2142 return GL_INVALID_OPERATION
;
2145 case GL_UNSIGNED_INT
:
2146 if (internalFormat
!= GL_RGBA32UI
)
2147 return GL_INVALID_OPERATION
;
2151 if (internalFormat
!= GL_RGBA32I
)
2152 return GL_INVALID_OPERATION
;
2155 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2156 if (internalFormat
!= GL_RGB10_A2UI
)
2157 return GL_INVALID_OPERATION
;
2161 return GL_INVALID_OPERATION
;
2167 case GL_UNSIGNED_BYTE
:
2168 switch (internalFormat
) {
2175 return GL_INVALID_OPERATION
;
2180 if (internalFormat
!= GL_RGB8_SNORM
)
2181 return GL_INVALID_OPERATION
;
2184 case GL_UNSIGNED_SHORT_5_6_5
:
2185 switch (internalFormat
) {
2190 return GL_INVALID_OPERATION
;
2194 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2195 if (internalFormat
!= GL_R11F_G11F_B10F
)
2196 return GL_INVALID_OPERATION
;
2199 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2200 if (internalFormat
!= GL_RGB9_E5
)
2201 return GL_INVALID_OPERATION
;
2205 switch (internalFormat
) {
2207 case GL_R11F_G11F_B10F
:
2211 return GL_INVALID_OPERATION
;
2216 switch (internalFormat
) {
2219 case GL_R11F_G11F_B10F
:
2223 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2226 return GL_INVALID_OPERATION
;
2230 case GL_HALF_FLOAT_OES
:
2231 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2232 return GL_INVALID_OPERATION
;
2235 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2236 switch (internalFormat
) {
2237 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2240 return GL_INVALID_OPERATION
;
2245 return GL_INVALID_OPERATION
;
2249 case GL_RGB_INTEGER
:
2251 case GL_UNSIGNED_BYTE
:
2252 if (internalFormat
!= GL_RGB8UI
)
2253 return GL_INVALID_OPERATION
;
2257 if (internalFormat
!= GL_RGB8I
)
2258 return GL_INVALID_OPERATION
;
2261 case GL_UNSIGNED_SHORT
:
2262 if (internalFormat
!= GL_RGB16UI
)
2263 return GL_INVALID_OPERATION
;
2267 if (internalFormat
!= GL_RGB16I
)
2268 return GL_INVALID_OPERATION
;
2271 case GL_UNSIGNED_INT
:
2272 if (internalFormat
!= GL_RGB32UI
)
2273 return GL_INVALID_OPERATION
;
2277 if (internalFormat
!= GL_RGB32I
)
2278 return GL_INVALID_OPERATION
;
2282 return GL_INVALID_OPERATION
;
2288 case GL_UNSIGNED_BYTE
:
2289 if (internalFormat
!= GL_RG8
)
2290 return GL_INVALID_OPERATION
;
2294 if (internalFormat
!= GL_RG8_SNORM
)
2295 return GL_INVALID_OPERATION
;
2299 case GL_HALF_FLOAT_OES
:
2300 switch (internalFormat
) {
2304 if (ctx
->Extensions
.ARB_texture_rg
&&
2305 ctx
->Extensions
.OES_texture_half_float
)
2309 return GL_INVALID_OPERATION
;
2314 switch (internalFormat
) {
2319 if (ctx
->Extensions
.ARB_texture_rg
&&
2320 ctx
->Extensions
.OES_texture_float
)
2324 return GL_INVALID_OPERATION
;
2329 return GL_INVALID_OPERATION
;
2335 case GL_UNSIGNED_BYTE
:
2336 if (internalFormat
!= GL_RG8UI
)
2337 return GL_INVALID_OPERATION
;
2341 if (internalFormat
!= GL_RG8I
)
2342 return GL_INVALID_OPERATION
;
2345 case GL_UNSIGNED_SHORT
:
2346 if (internalFormat
!= GL_RG16UI
)
2347 return GL_INVALID_OPERATION
;
2351 if (internalFormat
!= GL_RG16I
)
2352 return GL_INVALID_OPERATION
;
2355 case GL_UNSIGNED_INT
:
2356 if (internalFormat
!= GL_RG32UI
)
2357 return GL_INVALID_OPERATION
;
2361 if (internalFormat
!= GL_RG32I
)
2362 return GL_INVALID_OPERATION
;
2366 return GL_INVALID_OPERATION
;
2372 case GL_UNSIGNED_BYTE
:
2373 if (internalFormat
!= GL_R8
)
2374 return GL_INVALID_OPERATION
;
2378 if (internalFormat
!= GL_R8_SNORM
)
2379 return GL_INVALID_OPERATION
;
2383 case GL_HALF_FLOAT_OES
:
2384 switch (internalFormat
) {
2389 if (ctx
->Extensions
.ARB_texture_rg
&&
2390 ctx
->Extensions
.OES_texture_half_float
)
2394 return GL_INVALID_OPERATION
;
2399 switch (internalFormat
) {
2404 if (ctx
->Extensions
.ARB_texture_rg
&&
2405 ctx
->Extensions
.OES_texture_float
)
2409 return GL_INVALID_OPERATION
;
2414 return GL_INVALID_OPERATION
;
2418 case GL_RED_INTEGER
:
2420 case GL_UNSIGNED_BYTE
:
2421 if (internalFormat
!= GL_R8UI
)
2422 return GL_INVALID_OPERATION
;
2426 if (internalFormat
!= GL_R8I
)
2427 return GL_INVALID_OPERATION
;
2430 case GL_UNSIGNED_SHORT
:
2431 if (internalFormat
!= GL_R16UI
)
2432 return GL_INVALID_OPERATION
;
2436 if (internalFormat
!= GL_R16I
)
2437 return GL_INVALID_OPERATION
;
2440 case GL_UNSIGNED_INT
:
2441 if (internalFormat
!= GL_R32UI
)
2442 return GL_INVALID_OPERATION
;
2446 if (internalFormat
!= GL_R32I
)
2447 return GL_INVALID_OPERATION
;
2451 return GL_INVALID_OPERATION
;
2455 case GL_DEPTH_COMPONENT
:
2457 case GL_UNSIGNED_SHORT
:
2458 if (internalFormat
!= GL_DEPTH_COMPONENT
2459 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2460 return GL_INVALID_OPERATION
;
2463 case GL_UNSIGNED_INT
:
2464 switch (internalFormat
) {
2465 case GL_DEPTH_COMPONENT
:
2466 case GL_DEPTH_COMPONENT16
:
2467 case GL_DEPTH_COMPONENT24
:
2470 return GL_INVALID_OPERATION
;
2475 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2476 return GL_INVALID_OPERATION
;
2480 return GL_INVALID_OPERATION
;
2484 case GL_DEPTH_STENCIL
:
2486 case GL_UNSIGNED_INT_24_8
:
2487 if (internalFormat
!= GL_DEPTH_STENCIL
2488 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2489 return GL_INVALID_OPERATION
;
2492 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2493 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2494 return GL_INVALID_OPERATION
;
2498 return GL_INVALID_OPERATION
;
2504 case GL_LUMINANCE_ALPHA
:
2507 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2509 case GL_HALF_FLOAT_OES
:
2510 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2513 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2514 return GL_INVALID_OPERATION
;
2522 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
2524 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
2525 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
2526 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
2527 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
2531 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
2535 case GL_RGBA_INTEGER_EXT
:
2536 set_swizzle(swizzle
, 0, 1, 2, 3);
2539 case GL_BGRA_INTEGER_EXT
:
2540 set_swizzle(swizzle
, 2, 1, 0, 3);
2543 set_swizzle(swizzle
, 3, 2, 1, 0);
2546 case GL_RGB_INTEGER_EXT
:
2547 set_swizzle(swizzle
, 0, 1, 2, 5);
2550 case GL_BGR_INTEGER_EXT
:
2551 set_swizzle(swizzle
, 2, 1, 0, 5);
2553 case GL_LUMINANCE_ALPHA
:
2554 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2555 set_swizzle(swizzle
, 0, 0, 0, 1);
2559 set_swizzle(swizzle
, 0, 1, 4, 5);
2562 case GL_RED_INTEGER_EXT
:
2563 set_swizzle(swizzle
, 0, 4, 4, 5);
2566 case GL_GREEN_INTEGER_EXT
:
2567 set_swizzle(swizzle
, 4, 0, 4, 5);
2570 case GL_BLUE_INTEGER_EXT
:
2571 set_swizzle(swizzle
, 4, 4, 0, 5);
2574 case GL_ALPHA_INTEGER_EXT
:
2575 set_swizzle(swizzle
, 4, 4, 4, 0);
2578 case GL_LUMINANCE_INTEGER_EXT
:
2579 set_swizzle(swizzle
, 0, 0, 0, 5);
2582 set_swizzle(swizzle
, 0, 0, 0, 0);
2590 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
2591 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
2592 * otherwise (for non-array formats).
2594 * This function will typically be used to compute a mesa format from a GL type
2595 * so we can then call _mesa_format_convert. This function does
2596 * not consider byte swapping, so it returns types assuming that no byte
2597 * swapping is involved. If byte swapping is involved then clients are supposed
2598 * to handle that on their side before calling _mesa_format_convert.
2600 * This function returns an uint32_t that can pack a mesa_format or a
2601 * mesa_array_format. Clients must check the mesa array format bit
2602 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
2603 * format is a mesa_array_format or a mesa_format.
2606 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
2608 mesa_array_format array_format
;
2610 bool is_array_format
= true;
2612 bool normalized
= false, is_float
= false, is_signed
= false;
2613 int num_channels
= 0, type_size
= 0;
2615 /* Extract array format type information from the OpenGL data type */
2617 case GL_UNSIGNED_BYTE
:
2624 case GL_UNSIGNED_SHORT
:
2631 case GL_UNSIGNED_INT
:
2639 case GL_HALF_FLOAT_OES
:
2650 is_array_format
= false;
2654 /* Extract array format swizzle information from the OpenGL format */
2655 if (is_array_format
)
2656 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
2658 /* If this is an array format type after checking data type and format,
2659 * create the array format
2661 if (is_array_format
) {
2662 normalized
= !_mesa_is_enum_format_integer(format
);
2663 num_channels
= _mesa_components_in_format(format
);
2666 MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
2667 normalized
, num_channels
,
2668 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
2670 if (!_mesa_little_endian())
2671 array_format
= _mesa_array_format_flip_channels(array_format
);
2673 return array_format
;
2676 /* Otherwise this is not an array format, so return the mesa_format
2677 * matching the OpenGL format and data type
2680 case GL_UNSIGNED_SHORT_5_6_5
:
2681 if (format
== GL_RGB
)
2682 return MESA_FORMAT_B5G6R5_UNORM
;
2683 else if (format
== GL_BGR
)
2684 return MESA_FORMAT_R5G6B5_UNORM
;
2686 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2687 if (format
== GL_RGB
)
2688 return MESA_FORMAT_R5G6B5_UNORM
;
2689 else if (format
== GL_BGR
)
2690 return MESA_FORMAT_B5G6R5_UNORM
;
2692 case GL_UNSIGNED_SHORT_4_4_4_4
:
2693 if (format
== GL_RGBA
)
2694 return MESA_FORMAT_A4B4G4R4_UNORM
;
2695 else if (format
== GL_BGRA
)
2696 return MESA_FORMAT_A4R4G4B4_UNORM
;
2697 else if (format
== GL_ABGR_EXT
)
2698 return MESA_FORMAT_R4G4B4A4_UNORM
;
2700 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2701 if (format
== GL_RGBA
)
2702 return MESA_FORMAT_R4G4B4A4_UNORM
;
2703 else if (format
== GL_BGRA
)
2704 return MESA_FORMAT_B4G4R4A4_UNORM
;
2705 else if (format
== GL_ABGR_EXT
)
2706 return MESA_FORMAT_A4B4G4R4_UNORM
;
2708 case GL_UNSIGNED_SHORT_5_5_5_1
:
2709 if (format
== GL_RGBA
)
2710 return MESA_FORMAT_A1B5G5R5_UNORM
;
2711 else if (format
== GL_BGRA
)
2712 return MESA_FORMAT_A1R5G5B5_UNORM
;
2714 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2715 if (format
== GL_RGBA
)
2716 return MESA_FORMAT_R5G5B5A1_UNORM
;
2717 else if (format
== GL_BGRA
)
2718 return MESA_FORMAT_B5G5R5A1_UNORM
;
2720 case GL_UNSIGNED_BYTE_3_3_2
:
2721 if (format
== GL_RGB
)
2722 return MESA_FORMAT_B2G3R3_UNORM
;
2724 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2725 if (format
== GL_RGB
)
2726 return MESA_FORMAT_R3G3B2_UNORM
;
2728 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2729 if (format
== GL_RGB
)
2730 return MESA_FORMAT_R9G9B9E5_FLOAT
;
2732 case GL_UNSIGNED_INT_10_10_10_2
:
2733 if (format
== GL_RGBA
)
2734 return MESA_FORMAT_A2B10G10R10_UNORM
;
2735 else if (format
== GL_RGBA_INTEGER
)
2736 return MESA_FORMAT_A2B10G10R10_UINT
;
2737 else if (format
== GL_BGRA
)
2738 return MESA_FORMAT_A2R10G10B10_UNORM
;
2739 else if (format
== GL_BGRA_INTEGER
)
2740 return MESA_FORMAT_A2R10G10B10_UINT
;
2742 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2743 if (format
== GL_RGB
)
2744 return MESA_FORMAT_R10G10B10X2_UNORM
;
2745 if (format
== GL_RGBA
)
2746 return MESA_FORMAT_R10G10B10A2_UNORM
;
2747 else if (format
== GL_RGBA_INTEGER
)
2748 return MESA_FORMAT_R10G10B10A2_UINT
;
2749 else if (format
== GL_BGRA
)
2750 return MESA_FORMAT_B10G10R10A2_UNORM
;
2751 else if (format
== GL_BGRA_INTEGER
)
2752 return MESA_FORMAT_B10G10R10A2_UINT
;
2754 case GL_UNSIGNED_INT_8_8_8_8
:
2755 if (format
== GL_RGBA
)
2756 return MESA_FORMAT_A8B8G8R8_UNORM
;
2757 else if (format
== GL_BGRA
)
2758 return MESA_FORMAT_A8R8G8B8_UNORM
;
2759 else if (format
== GL_ABGR_EXT
)
2760 return MESA_FORMAT_R8G8B8A8_UNORM
;
2762 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2763 if (format
== GL_RGBA
)
2764 return MESA_FORMAT_R8G8B8A8_UNORM
;
2765 else if (format
== GL_BGRA
)
2766 return MESA_FORMAT_B8G8R8A8_UNORM
;
2767 else if (format
== GL_ABGR_EXT
)
2768 return MESA_FORMAT_A8B8G8R8_UNORM
;
2770 case GL_UNSIGNED_SHORT_8_8_MESA
:
2771 if (format
== GL_YCBCR_MESA
)
2772 return MESA_FORMAT_YCBCR
;
2774 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
2775 if (format
== GL_YCBCR_MESA
)
2776 return MESA_FORMAT_YCBCR_REV
;
2778 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2779 if (format
== GL_RGB
)
2780 return MESA_FORMAT_R11G11B10_FLOAT
;
2785 /* If we got here it means that we could not find a Mesa format that
2786 * matches the GL format/type provided. We may need to add a new Mesa
2787 * format in that case.
2789 unreachable("Unsupported format");