2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "glformats.h"
55 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
56 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
57 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
58 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
74 MAP4(ZERO
, ZERO
, ZERO
, 0),
104 MAP4(0, ZERO
, ZERO
, ONE
),
110 MAP4(ZERO
, 0, ZERO
, ONE
),
116 MAP4(ZERO
, ZERO
, 0, ONE
),
140 MAP4(0, 1, ZERO
, ONE
),
146 * Convert a GL image format enum to an IDX_* value (see above).
149 get_map_idx(GLenum value
)
153 case GL_LUMINANCE_INTEGER_EXT
:
154 return IDX_LUMINANCE
;
156 case GL_ALPHA_INTEGER
:
159 return IDX_INTENSITY
;
160 case GL_LUMINANCE_ALPHA
:
161 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
162 return IDX_LUMINANCE_ALPHA
;
167 case GL_RGBA_INTEGER
:
180 case GL_BGRA_INTEGER
:
188 _mesa_problem(NULL
, "Unexpected inFormat %s",
189 _mesa_lookup_enum_by_nr(value
));
195 * When promoting texture formats (see below) we need to compute the
196 * mapping of dest components back to source components.
197 * This function does that.
198 * \param inFormat the incoming format of the texture
199 * \param outFormat the final texture format
200 * \return map[6] a full 6-component map
203 _mesa_compute_component_mapping(GLenum inFormat
, GLenum outFormat
, GLubyte
*map
)
205 const int inFmt
= get_map_idx(inFormat
);
206 const int outFmt
= get_map_idx(outFormat
);
207 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
208 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
211 for (i
= 0; i
< 4; i
++)
212 map
[i
] = in2rgba
[rgba2out
[i
]];
218 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
219 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
220 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
231 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
234 _mesa_type_is_packed(GLenum type
)
237 case GL_UNSIGNED_BYTE_3_3_2
:
238 case GL_UNSIGNED_BYTE_2_3_3_REV
:
239 case MESA_UNSIGNED_BYTE_4_4
:
240 case GL_UNSIGNED_SHORT_5_6_5
:
241 case GL_UNSIGNED_SHORT_5_6_5_REV
:
242 case GL_UNSIGNED_SHORT_4_4_4_4
:
243 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
244 case GL_UNSIGNED_SHORT_5_5_5_1
:
245 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
246 case GL_UNSIGNED_INT_8_8_8_8
:
247 case GL_UNSIGNED_INT_8_8_8_8_REV
:
248 case GL_UNSIGNED_INT_10_10_10_2
:
249 case GL_UNSIGNED_INT_2_10_10_10_REV
:
250 case GL_UNSIGNED_SHORT_8_8_MESA
:
251 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
252 case GL_UNSIGNED_INT_24_8_EXT
:
253 case GL_UNSIGNED_INT_5_9_9_9_REV
:
254 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
255 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
264 * Get the size of a GL data type.
266 * \param type GL data type.
268 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
269 * if an invalid type enum.
272 _mesa_sizeof_type(GLenum type
)
277 case GL_UNSIGNED_BYTE
:
278 return sizeof(GLubyte
);
280 return sizeof(GLbyte
);
281 case GL_UNSIGNED_SHORT
:
282 return sizeof(GLushort
);
284 return sizeof(GLshort
);
285 case GL_UNSIGNED_INT
:
286 return sizeof(GLuint
);
288 return sizeof(GLint
);
290 return sizeof(GLfloat
);
292 return sizeof(GLdouble
);
293 case GL_HALF_FLOAT_ARB
:
294 return sizeof(GLhalfARB
);
296 return sizeof(GLfixed
);
304 * Same as _mesa_sizeof_type() but also accepting the packed pixel
308 _mesa_sizeof_packed_type(GLenum type
)
313 case GL_UNSIGNED_BYTE
:
314 return sizeof(GLubyte
);
316 return sizeof(GLbyte
);
317 case GL_UNSIGNED_SHORT
:
318 return sizeof(GLushort
);
320 return sizeof(GLshort
);
321 case GL_UNSIGNED_INT
:
322 return sizeof(GLuint
);
324 return sizeof(GLint
);
325 case GL_HALF_FLOAT_ARB
:
326 return sizeof(GLhalfARB
);
328 return sizeof(GLfloat
);
329 case GL_UNSIGNED_BYTE_3_3_2
:
330 case GL_UNSIGNED_BYTE_2_3_3_REV
:
331 case MESA_UNSIGNED_BYTE_4_4
:
332 return sizeof(GLubyte
);
333 case GL_UNSIGNED_SHORT_5_6_5
:
334 case GL_UNSIGNED_SHORT_5_6_5_REV
:
335 case GL_UNSIGNED_SHORT_4_4_4_4
:
336 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
337 case GL_UNSIGNED_SHORT_5_5_5_1
:
338 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
339 case GL_UNSIGNED_SHORT_8_8_MESA
:
340 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
341 return sizeof(GLushort
);
342 case GL_UNSIGNED_INT_8_8_8_8
:
343 case GL_UNSIGNED_INT_8_8_8_8_REV
:
344 case GL_UNSIGNED_INT_10_10_10_2
:
345 case GL_UNSIGNED_INT_2_10_10_10_REV
:
346 case GL_UNSIGNED_INT_24_8_EXT
:
347 case GL_UNSIGNED_INT_5_9_9_9_REV
:
348 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
349 return sizeof(GLuint
);
350 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
359 * Get the number of components in a pixel format.
361 * \param format pixel format.
363 * \return the number of components in the given format, or -1 if a bad format.
366 _mesa_components_in_format(GLenum format
)
370 case GL_STENCIL_INDEX
:
371 case GL_DEPTH_COMPONENT
:
373 case GL_RED_INTEGER_EXT
:
375 case GL_GREEN_INTEGER_EXT
:
377 case GL_BLUE_INTEGER_EXT
:
379 case GL_ALPHA_INTEGER_EXT
:
381 case GL_LUMINANCE_INTEGER_EXT
:
385 case GL_LUMINANCE_ALPHA
:
386 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
389 case GL_DEPTH_STENCIL_EXT
:
395 case GL_RGB_INTEGER_EXT
:
396 case GL_BGR_INTEGER_EXT
:
402 case GL_RGBA_INTEGER_EXT
:
403 case GL_BGRA_INTEGER_EXT
:
413 * Get the bytes per pixel of pixel format type pair.
415 * \param format pixel format.
416 * \param type pixel type.
418 * \return bytes per pixel, or -1 if a bad format or type was given.
421 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
423 GLint comps
= _mesa_components_in_format(format
);
429 return 0; /* special case */
431 case GL_UNSIGNED_BYTE
:
432 return comps
* sizeof(GLubyte
);
434 case GL_UNSIGNED_SHORT
:
435 return comps
* sizeof(GLshort
);
437 case GL_UNSIGNED_INT
:
438 return comps
* sizeof(GLint
);
440 return comps
* sizeof(GLfloat
);
441 case GL_HALF_FLOAT_ARB
:
442 return comps
* sizeof(GLhalfARB
);
443 case GL_UNSIGNED_BYTE_3_3_2
:
444 case GL_UNSIGNED_BYTE_2_3_3_REV
:
445 if (format
== GL_RGB
|| format
== GL_BGR
||
446 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
447 return sizeof(GLubyte
);
449 return -1; /* error */
450 case GL_UNSIGNED_SHORT_5_6_5
:
451 case GL_UNSIGNED_SHORT_5_6_5_REV
:
452 if (format
== GL_RGB
|| format
== GL_BGR
||
453 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
454 return sizeof(GLushort
);
456 return -1; /* error */
457 case GL_UNSIGNED_SHORT_4_4_4_4
:
458 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
459 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
460 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
461 return sizeof(GLushort
);
464 case GL_UNSIGNED_SHORT_5_5_5_1
:
465 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
466 if (format
== GL_RGBA
|| format
== GL_BGRA
||
467 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
468 return sizeof(GLushort
);
471 case GL_UNSIGNED_INT_8_8_8_8
:
472 case GL_UNSIGNED_INT_8_8_8_8_REV
:
473 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
474 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
476 return sizeof(GLuint
);
479 case GL_UNSIGNED_INT_10_10_10_2
:
480 case GL_UNSIGNED_INT_2_10_10_10_REV
:
481 if (format
== GL_RGBA
|| format
== GL_BGRA
||
482 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
484 return sizeof(GLuint
);
487 case GL_UNSIGNED_SHORT_8_8_MESA
:
488 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
489 if (format
== GL_YCBCR_MESA
)
490 return sizeof(GLushort
);
493 case GL_UNSIGNED_INT_24_8_EXT
:
494 if (format
== GL_DEPTH_STENCIL_EXT
)
495 return sizeof(GLuint
);
498 case GL_UNSIGNED_INT_5_9_9_9_REV
:
499 if (format
== GL_RGB
)
500 return sizeof(GLuint
);
503 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
504 if (format
== GL_RGB
)
505 return sizeof(GLuint
);
508 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
509 if (format
== GL_DEPTH_STENCIL
)
520 * Get the number of bytes for a vertex attrib with the given number of
521 * components and type.
523 * \param comps number of components.
524 * \param type data type.
526 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
529 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
533 case GL_UNSIGNED_BYTE
:
534 return comps
* sizeof(GLubyte
);
536 case GL_UNSIGNED_SHORT
:
537 return comps
* sizeof(GLshort
);
539 case GL_UNSIGNED_INT
:
540 return comps
* sizeof(GLint
);
542 return comps
* sizeof(GLfloat
);
543 case GL_HALF_FLOAT_ARB
:
544 return comps
* sizeof(GLhalfARB
);
546 return comps
* sizeof(GLdouble
);
548 return comps
* sizeof(GLfixed
);
549 case GL_INT_2_10_10_10_REV
:
550 case GL_UNSIGNED_INT_2_10_10_10_REV
:
552 return sizeof(GLuint
);
555 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
557 return sizeof(GLuint
);
566 * Test if the given format is unsized.
569 _mesa_is_enum_format_unsized(GLenum format
)
584 case GL_LUMINANCE_ALPHA
:
589 case GL_SLUMINANCE_ALPHA
:
596 case GL_INTENSITY_SNORM
:
597 case GL_LUMINANCE_SNORM
:
598 case GL_LUMINANCE_ALPHA_SNORM
:
601 case GL_GREEN_INTEGER
:
602 case GL_BLUE_INTEGER
:
603 case GL_ALPHA_INTEGER
:
605 case GL_RGBA_INTEGER
:
607 case GL_BGRA_INTEGER
:
609 case GL_LUMINANCE_INTEGER_EXT
:
610 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
612 case GL_DEPTH_COMPONENT
:
613 case GL_DEPTH_STENCIL
:
614 case GL_STENCIL_INDEX
:
622 * Test if the given format is a UNORM (unsigned-normalized) format.
625 _mesa_is_enum_format_unorm(GLenum format
)
644 case GL_LUMINANCE_ALPHA
:
645 case GL_SLUMINANCE_ALPHA
:
646 case GL_LUMINANCE4_ALPHA4
:
647 case GL_LUMINANCE6_ALPHA2
:
648 case GL_LUMINANCE8_ALPHA8
:
649 case GL_LUMINANCE12_ALPHA4
:
650 case GL_LUMINANCE12_ALPHA12
:
651 case GL_LUMINANCE16_ALPHA16
:
693 * Test if the given format is a SNORM (signed-normalized) format.
696 _mesa_is_enum_format_snorm(GLenum format
)
699 /* signed, normalized texture formats */
711 case GL_RGBA16_SNORM
:
713 case GL_ALPHA8_SNORM
:
714 case GL_ALPHA16_SNORM
:
715 case GL_LUMINANCE_SNORM
:
716 case GL_LUMINANCE8_SNORM
:
717 case GL_LUMINANCE16_SNORM
:
718 case GL_LUMINANCE_ALPHA_SNORM
:
719 case GL_LUMINANCE8_ALPHA8_SNORM
:
720 case GL_LUMINANCE16_ALPHA16_SNORM
:
721 case GL_INTENSITY_SNORM
:
722 case GL_INTENSITY8_SNORM
:
723 case GL_INTENSITY16_SNORM
:
731 * Test if the given format is an integer (non-normalized) format.
734 _mesa_is_enum_format_unsigned_int(GLenum format
)
737 /* specific integer formats */
738 case GL_RGBA32UI_EXT
:
742 case GL_ALPHA32UI_EXT
:
743 case GL_INTENSITY32UI_EXT
:
744 case GL_LUMINANCE32UI_EXT
:
745 case GL_LUMINANCE_ALPHA32UI_EXT
:
746 case GL_RGBA16UI_EXT
:
750 case GL_ALPHA16UI_EXT
:
751 case GL_INTENSITY16UI_EXT
:
752 case GL_LUMINANCE16UI_EXT
:
753 case GL_LUMINANCE_ALPHA16UI_EXT
:
758 case GL_ALPHA8UI_EXT
:
759 case GL_INTENSITY8UI_EXT
:
760 case GL_LUMINANCE8UI_EXT
:
761 case GL_LUMINANCE_ALPHA8UI_EXT
:
771 * Test if the given format is an integer (non-normalized) format.
774 _mesa_is_enum_format_signed_int(GLenum format
)
777 /* generic integer formats */
778 case GL_RED_INTEGER_EXT
:
779 case GL_GREEN_INTEGER_EXT
:
780 case GL_BLUE_INTEGER_EXT
:
781 case GL_ALPHA_INTEGER_EXT
:
782 case GL_RGB_INTEGER_EXT
:
783 case GL_RGBA_INTEGER_EXT
:
784 case GL_BGR_INTEGER_EXT
:
785 case GL_BGRA_INTEGER_EXT
:
786 case GL_LUMINANCE_INTEGER_EXT
:
787 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
789 /* specific integer formats */
794 case GL_ALPHA32I_EXT
:
795 case GL_INTENSITY32I_EXT
:
796 case GL_LUMINANCE32I_EXT
:
797 case GL_LUMINANCE_ALPHA32I_EXT
:
802 case GL_ALPHA16I_EXT
:
803 case GL_INTENSITY16I_EXT
:
804 case GL_LUMINANCE16I_EXT
:
805 case GL_LUMINANCE_ALPHA16I_EXT
:
811 case GL_INTENSITY8I_EXT
:
812 case GL_LUMINANCE8I_EXT
:
813 case GL_LUMINANCE_ALPHA8I_EXT
:
822 * Test if the given format is an integer (non-normalized) format.
825 _mesa_is_enum_format_integer(GLenum format
)
827 return _mesa_is_enum_format_unsigned_int(format
) ||
828 _mesa_is_enum_format_signed_int(format
);
833 _mesa_is_type_unsigned(GLenum type
)
836 case GL_UNSIGNED_INT
:
837 case GL_UNSIGNED_INT_8_8_8_8
:
838 case GL_UNSIGNED_INT_8_8_8_8_REV
:
839 case GL_UNSIGNED_INT_10_10_10_2
:
840 case GL_UNSIGNED_INT_2_10_10_10_REV
:
842 case GL_UNSIGNED_SHORT
:
843 case GL_UNSIGNED_SHORT_4_4_4_4
:
844 case GL_UNSIGNED_SHORT_5_5_5_1
:
845 case GL_UNSIGNED_SHORT_5_6_5
:
846 case GL_UNSIGNED_SHORT_5_6_5_REV
:
847 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
848 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
849 case GL_UNSIGNED_SHORT_8_8_MESA
:
850 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
852 case GL_UNSIGNED_BYTE
:
853 case GL_UNSIGNED_BYTE_3_3_2
:
854 case GL_UNSIGNED_BYTE_2_3_3_REV
:
864 * Test if the given image format is a color/RGBA format (i.e., not color
865 * index, depth, stencil, etc).
866 * \param format the image format value (may by an internal texture format)
867 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
870 _mesa_is_color_format(GLenum format
)
888 case GL_LUMINANCE_ALPHA
:
889 case GL_LUMINANCE4_ALPHA4
:
890 case GL_LUMINANCE6_ALPHA2
:
891 case GL_LUMINANCE8_ALPHA8
:
892 case GL_LUMINANCE12_ALPHA4
:
893 case GL_LUMINANCE12_ALPHA12
:
894 case GL_LUMINANCE16_ALPHA16
:
927 /* float texture formats */
928 case GL_ALPHA16F_ARB
:
929 case GL_ALPHA32F_ARB
:
930 case GL_LUMINANCE16F_ARB
:
931 case GL_LUMINANCE32F_ARB
:
932 case GL_LUMINANCE_ALPHA16F_ARB
:
933 case GL_LUMINANCE_ALPHA32F_ARB
:
934 case GL_INTENSITY16F_ARB
:
935 case GL_INTENSITY32F_ARB
:
944 /* compressed formats */
945 case GL_COMPRESSED_ALPHA
:
946 case GL_COMPRESSED_LUMINANCE
:
947 case GL_COMPRESSED_LUMINANCE_ALPHA
:
948 case GL_COMPRESSED_INTENSITY
:
949 case GL_COMPRESSED_RED
:
950 case GL_COMPRESSED_RG
:
951 case GL_COMPRESSED_RGB
:
952 case GL_COMPRESSED_RGBA
:
957 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
958 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
959 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
960 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
961 case GL_COMPRESSED_RGB_FXT1_3DFX
:
962 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
965 case GL_SRGB_ALPHA_EXT
:
966 case GL_SRGB8_ALPHA8_EXT
:
967 case GL_SLUMINANCE_ALPHA_EXT
:
968 case GL_SLUMINANCE8_ALPHA8_EXT
:
969 case GL_SLUMINANCE_EXT
:
970 case GL_SLUMINANCE8_EXT
:
971 case GL_COMPRESSED_SRGB_EXT
:
972 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
973 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
974 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
975 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
976 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
977 case GL_COMPRESSED_SLUMINANCE_EXT
:
978 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
979 case GL_COMPRESSED_RED_RGTC1
:
980 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
981 case GL_COMPRESSED_RG_RGTC2
:
982 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
983 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
984 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
985 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
986 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
987 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
988 case GL_ETC1_RGB8_OES
:
989 case GL_COMPRESSED_RGB8_ETC2
:
990 case GL_COMPRESSED_SRGB8_ETC2
:
991 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
992 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
993 case GL_COMPRESSED_R11_EAC
:
994 case GL_COMPRESSED_RG11_EAC
:
995 case GL_COMPRESSED_SIGNED_R11_EAC
:
996 case GL_COMPRESSED_SIGNED_RG11_EAC
:
997 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
998 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
999 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1000 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1001 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1002 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1003 /* generic integer formats */
1004 case GL_RED_INTEGER_EXT
:
1005 case GL_GREEN_INTEGER_EXT
:
1006 case GL_BLUE_INTEGER_EXT
:
1007 case GL_ALPHA_INTEGER_EXT
:
1008 case GL_RGB_INTEGER_EXT
:
1009 case GL_RGBA_INTEGER_EXT
:
1010 case GL_BGR_INTEGER_EXT
:
1011 case GL_BGRA_INTEGER_EXT
:
1013 case GL_LUMINANCE_INTEGER_EXT
:
1014 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1015 /* sized integer formats */
1016 case GL_RGBA32UI_EXT
:
1017 case GL_RGB32UI_EXT
:
1020 case GL_ALPHA32UI_EXT
:
1021 case GL_INTENSITY32UI_EXT
:
1022 case GL_LUMINANCE32UI_EXT
:
1023 case GL_LUMINANCE_ALPHA32UI_EXT
:
1024 case GL_RGBA16UI_EXT
:
1025 case GL_RGB16UI_EXT
:
1028 case GL_ALPHA16UI_EXT
:
1029 case GL_INTENSITY16UI_EXT
:
1030 case GL_LUMINANCE16UI_EXT
:
1031 case GL_LUMINANCE_ALPHA16UI_EXT
:
1032 case GL_RGBA8UI_EXT
:
1036 case GL_ALPHA8UI_EXT
:
1037 case GL_INTENSITY8UI_EXT
:
1038 case GL_LUMINANCE8UI_EXT
:
1039 case GL_LUMINANCE_ALPHA8UI_EXT
:
1040 case GL_RGBA32I_EXT
:
1044 case GL_ALPHA32I_EXT
:
1045 case GL_INTENSITY32I_EXT
:
1046 case GL_LUMINANCE32I_EXT
:
1047 case GL_LUMINANCE_ALPHA32I_EXT
:
1048 case GL_RGBA16I_EXT
:
1052 case GL_ALPHA16I_EXT
:
1053 case GL_INTENSITY16I_EXT
:
1054 case GL_LUMINANCE16I_EXT
:
1055 case GL_LUMINANCE_ALPHA16I_EXT
:
1060 case GL_ALPHA8I_EXT
:
1061 case GL_INTENSITY8I_EXT
:
1062 case GL_LUMINANCE8I_EXT
:
1063 case GL_LUMINANCE_ALPHA8I_EXT
:
1064 /* signed, normalized texture formats */
1073 case GL_RGB16_SNORM
:
1075 case GL_RGBA8_SNORM
:
1076 case GL_RGBA16_SNORM
:
1077 case GL_ALPHA_SNORM
:
1078 case GL_ALPHA8_SNORM
:
1079 case GL_ALPHA16_SNORM
:
1080 case GL_LUMINANCE_SNORM
:
1081 case GL_LUMINANCE8_SNORM
:
1082 case GL_LUMINANCE16_SNORM
:
1083 case GL_LUMINANCE_ALPHA_SNORM
:
1084 case GL_LUMINANCE8_ALPHA8_SNORM
:
1085 case GL_LUMINANCE16_ALPHA16_SNORM
:
1086 case GL_INTENSITY_SNORM
:
1087 case GL_INTENSITY8_SNORM
:
1088 case GL_INTENSITY16_SNORM
:
1090 case GL_R11F_G11F_B10F
:
1093 case GL_YCBCR_MESA
: /* not considered to be RGB */
1102 * Test if the given image format is a depth component format.
1105 _mesa_is_depth_format(GLenum format
)
1108 case GL_DEPTH_COMPONENT
:
1109 case GL_DEPTH_COMPONENT16
:
1110 case GL_DEPTH_COMPONENT24
:
1111 case GL_DEPTH_COMPONENT32
:
1112 case GL_DEPTH_COMPONENT32F
:
1121 * Test if the given image format is a stencil format.
1124 _mesa_is_stencil_format(GLenum format
)
1127 case GL_STENCIL_INDEX
:
1136 * Test if the given image format is a YCbCr format.
1139 _mesa_is_ycbcr_format(GLenum format
)
1151 * Test if the given image format is a depth+stencil format.
1154 _mesa_is_depthstencil_format(GLenum format
)
1157 case GL_DEPTH24_STENCIL8_EXT
:
1158 case GL_DEPTH_STENCIL_EXT
:
1159 case GL_DEPTH32F_STENCIL8
:
1168 * Test if the given image format is a depth or stencil format.
1171 _mesa_is_depth_or_stencil_format(GLenum format
)
1174 case GL_DEPTH_COMPONENT
:
1175 case GL_DEPTH_COMPONENT16
:
1176 case GL_DEPTH_COMPONENT24
:
1177 case GL_DEPTH_COMPONENT32
:
1178 case GL_STENCIL_INDEX
:
1179 case GL_STENCIL_INDEX1_EXT
:
1180 case GL_STENCIL_INDEX4_EXT
:
1181 case GL_STENCIL_INDEX8_EXT
:
1182 case GL_STENCIL_INDEX16_EXT
:
1183 case GL_DEPTH_STENCIL_EXT
:
1184 case GL_DEPTH24_STENCIL8_EXT
:
1185 case GL_DEPTH_COMPONENT32F
:
1186 case GL_DEPTH32F_STENCIL8
:
1195 * Test if an image format is a supported compressed format.
1196 * \param format the internal format token provided by the user.
1197 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1200 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1203 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1204 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1205 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1206 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1207 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
1209 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1214 return _mesa_is_desktop_gl(ctx
) &&
1215 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1216 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1217 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1218 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1219 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1220 return _mesa_is_desktop_gl(ctx
)
1221 && ctx
->Extensions
.EXT_texture_sRGB
1222 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1223 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1224 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1225 return _mesa_is_desktop_gl(ctx
)
1226 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1227 case GL_COMPRESSED_RED_RGTC1
:
1228 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1229 case GL_COMPRESSED_RG_RGTC2
:
1230 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1231 return _mesa_is_desktop_gl(ctx
)
1232 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1233 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1234 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1235 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1236 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1237 return ctx
->API
== API_OPENGL_COMPAT
1238 && ctx
->Extensions
.EXT_texture_compression_latc
;
1239 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1240 return ctx
->API
== API_OPENGL_COMPAT
1241 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1242 case GL_ETC1_RGB8_OES
:
1243 return _mesa_is_gles(ctx
)
1244 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1245 case GL_COMPRESSED_RGB8_ETC2
:
1246 case GL_COMPRESSED_SRGB8_ETC2
:
1247 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1248 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1249 case GL_COMPRESSED_R11_EAC
:
1250 case GL_COMPRESSED_RG11_EAC
:
1251 case GL_COMPRESSED_SIGNED_R11_EAC
:
1252 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1253 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1254 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1255 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1256 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1257 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1258 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1259 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1260 return _mesa_is_desktop_gl(ctx
) &&
1261 ctx
->Extensions
.ARB_texture_compression_bptc
;
1262 case GL_PALETTE4_RGB8_OES
:
1263 case GL_PALETTE4_RGBA8_OES
:
1264 case GL_PALETTE4_R5_G6_B5_OES
:
1265 case GL_PALETTE4_RGBA4_OES
:
1266 case GL_PALETTE4_RGB5_A1_OES
:
1267 case GL_PALETTE8_RGB8_OES
:
1268 case GL_PALETTE8_RGBA8_OES
:
1269 case GL_PALETTE8_R5_G6_B5_OES
:
1270 case GL_PALETTE8_RGBA4_OES
:
1271 case GL_PALETTE8_RGB5_A1_OES
:
1272 return ctx
->API
== API_OPENGLES
;
1280 * Convert various base formats to the cooresponding integer format.
1283 _mesa_base_format_to_integer_format(GLenum format
)
1287 return GL_RED_INTEGER
;
1289 return GL_GREEN_INTEGER
;
1291 return GL_BLUE_INTEGER
;
1293 return GL_RG_INTEGER
;
1295 return GL_RGB_INTEGER
;
1297 return GL_RGBA_INTEGER
;
1299 return GL_BGR_INTEGER
;
1301 return GL_BGRA_INTEGER
;
1303 return GL_ALPHA_INTEGER
;
1305 return GL_LUMINANCE_INTEGER_EXT
;
1306 case GL_LUMINANCE_ALPHA
:
1307 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1315 * Does the given base texture/renderbuffer format have the channel
1319 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1322 case GL_TEXTURE_RED_SIZE
:
1323 case GL_TEXTURE_RED_TYPE
:
1324 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1325 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1326 if (base_format
== GL_RED
||
1327 base_format
== GL_RG
||
1328 base_format
== GL_RGB
||
1329 base_format
== GL_RGBA
) {
1333 case GL_TEXTURE_GREEN_SIZE
:
1334 case GL_TEXTURE_GREEN_TYPE
:
1335 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1336 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1337 if (base_format
== GL_RG
||
1338 base_format
== GL_RGB
||
1339 base_format
== GL_RGBA
) {
1343 case GL_TEXTURE_BLUE_SIZE
:
1344 case GL_TEXTURE_BLUE_TYPE
:
1345 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1346 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1347 if (base_format
== GL_RGB
||
1348 base_format
== GL_RGBA
) {
1352 case GL_TEXTURE_ALPHA_SIZE
:
1353 case GL_TEXTURE_ALPHA_TYPE
:
1354 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1355 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1356 if (base_format
== GL_RGBA
||
1357 base_format
== GL_ALPHA
||
1358 base_format
== GL_LUMINANCE_ALPHA
) {
1362 case GL_TEXTURE_LUMINANCE_SIZE
:
1363 case GL_TEXTURE_LUMINANCE_TYPE
:
1364 if (base_format
== GL_LUMINANCE
||
1365 base_format
== GL_LUMINANCE_ALPHA
) {
1369 case GL_TEXTURE_INTENSITY_SIZE
:
1370 case GL_TEXTURE_INTENSITY_TYPE
:
1371 if (base_format
== GL_INTENSITY
) {
1375 case GL_TEXTURE_DEPTH_SIZE
:
1376 case GL_TEXTURE_DEPTH_TYPE
:
1377 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1378 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1379 if (base_format
== GL_DEPTH_STENCIL
||
1380 base_format
== GL_DEPTH_COMPONENT
) {
1384 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1385 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1386 if (base_format
== GL_DEPTH_STENCIL
||
1387 base_format
== GL_STENCIL_INDEX
) {
1392 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1393 __FUNCTION__
, pname
);
1402 * Returns the number of channels/components for a base format.
1405 _mesa_base_format_component_count(GLenum base_format
)
1407 switch (base_format
) {
1411 case GL_DEPTH_COMPONENT
:
1414 case GL_LUMINANCE_ALPHA
:
1415 case GL_DEPTH_STENCIL
:
1428 * If format is a generic compressed format, return the corresponding
1429 * non-compressed format. For other formats, return the format as-is.
1432 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1435 case GL_COMPRESSED_RED
:
1437 case GL_COMPRESSED_RG
:
1439 case GL_COMPRESSED_RGB
:
1441 case GL_COMPRESSED_RGBA
:
1443 case GL_COMPRESSED_ALPHA
:
1445 case GL_COMPRESSED_LUMINANCE
:
1446 return GL_LUMINANCE
;
1447 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1448 return GL_LUMINANCE_ALPHA
;
1449 case GL_COMPRESSED_INTENSITY
:
1450 return GL_INTENSITY
;
1452 case GL_COMPRESSED_SRGB
:
1454 case GL_COMPRESSED_SRGB_ALPHA
:
1455 return GL_SRGB_ALPHA
;
1456 case GL_COMPRESSED_SLUMINANCE
:
1457 return GL_SLUMINANCE
;
1458 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1459 return GL_SLUMINANCE_ALPHA
;
1467 * Return the equivalent non-generic internal format.
1468 * This is useful for comparing whether two internal formats are equivalent.
1471 _mesa_get_nongeneric_internalformat(GLenum format
)
1474 /* GL 1.1 formats. */
1482 case GL_LUMINANCE_ALPHA
:
1483 return GL_LUMINANCE8_ALPHA8
;
1486 return GL_LUMINANCE8
;
1490 return GL_INTENSITY8
;
1492 /* GL_ARB_texture_rg */
1498 /* GL_EXT_texture_sRGB */
1502 return GL_SRGB8_ALPHA8
;
1504 return GL_SLUMINANCE8
;
1505 case GL_SLUMINANCE_ALPHA
:
1506 return GL_SLUMINANCE8_ALPHA8
;
1508 /* GL_EXT_texture_snorm */
1510 return GL_RGBA8_SNORM
;
1512 return GL_RGB8_SNORM
;
1514 return GL_RG8_SNORM
;
1517 case GL_LUMINANCE_ALPHA_SNORM
:
1518 return GL_LUMINANCE8_ALPHA8_SNORM
;
1519 case GL_LUMINANCE_SNORM
:
1520 return GL_LUMINANCE8_SNORM
;
1521 case GL_ALPHA_SNORM
:
1522 return GL_ALPHA8_SNORM
;
1523 case GL_INTENSITY_SNORM
:
1524 return GL_INTENSITY8_SNORM
;
1533 * Convert an sRGB internal format to linear.
1536 _mesa_get_linear_internalformat(GLenum format
)
1545 case GL_SRGB8_ALPHA8
:
1547 case GL_SLUMINANCE8
:
1548 return GL_LUMINANCE8
;
1550 return GL_LUMINANCE
;
1551 case GL_SLUMINANCE_ALPHA
:
1552 return GL_LUMINANCE_ALPHA
;
1553 case GL_SLUMINANCE8_ALPHA8
:
1554 return GL_LUMINANCE8_ALPHA8
;
1562 * Do error checking of format/type combinations for glReadPixels,
1563 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1564 * and type values, we may either generate GL_INVALID_OPERATION or
1567 * \param format pixel format.
1568 * \param type pixel type.
1570 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1573 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1574 GLenum format
, GLenum type
)
1576 /* From OpenGL 3.3 spec, page 220:
1577 * "If the format is DEPTH_STENCIL, then values are taken from
1578 * both the depth buffer and the stencil buffer. If there is no
1579 * depth buffer or if there is no stencil buffer, then the error
1580 * INVALID_OPERATION occurs. If the type parameter is not
1581 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1582 * error INVALID_ENUM occurs."
1584 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1585 * cannot be used to read depth or stencil in that API.
1587 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1588 && type
!= GL_UNSIGNED_INT_24_8
1589 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1590 return GL_INVALID_ENUM
;
1592 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1595 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1596 return GL_INVALID_ENUM
;
1600 case GL_UNSIGNED_BYTE_3_3_2
:
1601 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1602 case GL_UNSIGNED_SHORT_5_6_5
:
1603 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1604 if (format
== GL_RGB
) {
1607 if (format
== GL_RGB_INTEGER_EXT
&&
1608 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1611 return GL_INVALID_OPERATION
;
1613 case GL_UNSIGNED_SHORT_4_4_4_4
:
1614 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1615 case GL_UNSIGNED_INT_8_8_8_8
:
1616 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1617 if (format
== GL_RGBA
||
1618 format
== GL_BGRA
||
1619 format
== GL_ABGR_EXT
) {
1622 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1623 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1626 return GL_INVALID_OPERATION
;
1628 case GL_UNSIGNED_SHORT_5_5_5_1
:
1629 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1630 case GL_UNSIGNED_INT_10_10_10_2
:
1631 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1632 if (format
== GL_RGBA
||
1633 format
== GL_BGRA
) {
1636 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1637 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1640 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1641 ctx
->API
== API_OPENGLES2
) {
1642 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1644 return GL_INVALID_OPERATION
;
1646 case GL_UNSIGNED_INT_24_8
:
1647 if (format
!= GL_DEPTH_STENCIL
) {
1648 return GL_INVALID_OPERATION
;
1652 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1653 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1654 return GL_INVALID_ENUM
;
1656 if (format
!= GL_DEPTH_STENCIL
) {
1657 return GL_INVALID_OPERATION
;
1661 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1662 if (!ctx
->Extensions
.EXT_packed_float
) {
1663 return GL_INVALID_ENUM
;
1665 if (format
!= GL_RGB
) {
1666 return GL_INVALID_OPERATION
;
1671 ; /* fall-through */
1674 /* now, for each format, check the type for compatibility */
1676 case GL_COLOR_INDEX
:
1677 case GL_STENCIL_INDEX
:
1681 case GL_UNSIGNED_BYTE
:
1683 case GL_UNSIGNED_SHORT
:
1685 case GL_UNSIGNED_INT
:
1690 return GL_INVALID_ENUM
;
1697 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1701 case GL_LUMINANCE_ALPHA
:
1702 case GL_DEPTH_COMPONENT
:
1705 case GL_UNSIGNED_BYTE
:
1707 case GL_UNSIGNED_SHORT
:
1709 case GL_UNSIGNED_INT
:
1714 return GL_INVALID_ENUM
;
1718 if (!ctx
->Extensions
.ARB_texture_rg
)
1719 return GL_INVALID_ENUM
;
1722 case GL_UNSIGNED_BYTE
:
1724 case GL_UNSIGNED_SHORT
:
1726 case GL_UNSIGNED_INT
:
1731 return GL_INVALID_ENUM
;
1737 case GL_UNSIGNED_BYTE
:
1739 case GL_UNSIGNED_SHORT
:
1741 case GL_UNSIGNED_INT
:
1743 case GL_UNSIGNED_BYTE_3_3_2
:
1744 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1745 case GL_UNSIGNED_SHORT_5_6_5
:
1746 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1749 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1750 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1751 return (ctx
->API
== API_OPENGLES2
)
1752 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1753 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1754 return ctx
->Extensions
.EXT_texture_shared_exponent
1755 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1756 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1757 return ctx
->Extensions
.EXT_packed_float
1758 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1760 return GL_INVALID_ENUM
;
1765 /* NOTE: no packed types are supported with BGR. That's
1766 * intentional, according to the GL spec.
1769 case GL_UNSIGNED_BYTE
:
1771 case GL_UNSIGNED_SHORT
:
1773 case GL_UNSIGNED_INT
:
1778 return GL_INVALID_ENUM
;
1785 case GL_UNSIGNED_BYTE
:
1787 case GL_UNSIGNED_SHORT
:
1789 case GL_UNSIGNED_INT
:
1791 case GL_UNSIGNED_SHORT_4_4_4_4
:
1792 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1793 case GL_UNSIGNED_SHORT_5_5_5_1
:
1794 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1795 case GL_UNSIGNED_INT_8_8_8_8
:
1796 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1797 case GL_UNSIGNED_INT_10_10_10_2
:
1798 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1802 return GL_INVALID_ENUM
;
1808 case GL_UNSIGNED_BYTE
:
1810 case GL_UNSIGNED_SHORT
:
1812 case GL_UNSIGNED_INT
:
1814 case GL_UNSIGNED_SHORT_4_4_4_4
:
1815 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1816 case GL_UNSIGNED_INT_8_8_8_8
:
1817 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1821 return GL_INVALID_ENUM
;
1825 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1826 return GL_INVALID_ENUM
;
1827 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1828 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1831 return GL_INVALID_OPERATION
;
1833 case GL_DEPTH_STENCIL
:
1834 if (type
== GL_UNSIGNED_INT_24_8
)
1836 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1837 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1840 return GL_INVALID_ENUM
;
1842 /* integer-valued formats */
1843 case GL_RED_INTEGER_EXT
:
1844 case GL_GREEN_INTEGER_EXT
:
1845 case GL_BLUE_INTEGER_EXT
:
1846 case GL_ALPHA_INTEGER_EXT
:
1850 case GL_UNSIGNED_BYTE
:
1852 case GL_UNSIGNED_SHORT
:
1854 case GL_UNSIGNED_INT
:
1855 return (ctx
->Version
>= 30 ||
1856 ctx
->Extensions
.EXT_texture_integer
)
1857 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1859 return GL_INVALID_ENUM
;
1862 case GL_RGB_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
;
1873 case GL_UNSIGNED_BYTE_3_3_2
:
1874 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1875 case GL_UNSIGNED_SHORT_5_6_5
:
1876 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1877 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1878 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1880 return GL_INVALID_ENUM
;
1883 case GL_BGR_INTEGER_EXT
:
1886 case GL_UNSIGNED_BYTE
:
1888 case GL_UNSIGNED_SHORT
:
1890 case GL_UNSIGNED_INT
:
1891 /* NOTE: no packed formats w/ BGR format */
1892 return (ctx
->Version
>= 30 ||
1893 ctx
->Extensions
.EXT_texture_integer
)
1894 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1896 return GL_INVALID_ENUM
;
1899 case GL_RGBA_INTEGER_EXT
:
1900 case GL_BGRA_INTEGER_EXT
:
1903 case GL_UNSIGNED_BYTE
:
1905 case GL_UNSIGNED_SHORT
:
1907 case GL_UNSIGNED_INT
:
1908 return (ctx
->Version
>= 30 ||
1909 ctx
->Extensions
.EXT_texture_integer
)
1910 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1911 case GL_UNSIGNED_SHORT_4_4_4_4
:
1912 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1913 case GL_UNSIGNED_SHORT_5_5_5_1
:
1914 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1915 case GL_UNSIGNED_INT_8_8_8_8
:
1916 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1917 case GL_UNSIGNED_INT_10_10_10_2
:
1918 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1919 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1920 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1922 return GL_INVALID_ENUM
;
1925 case GL_LUMINANCE_INTEGER_EXT
:
1926 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1929 case GL_UNSIGNED_BYTE
:
1931 case GL_UNSIGNED_SHORT
:
1933 case GL_UNSIGNED_INT
:
1934 return ctx
->Extensions
.EXT_texture_integer
1935 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1937 return GL_INVALID_ENUM
;
1941 return GL_INVALID_ENUM
;
1948 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1949 * and glTex[Sub]Image.
1950 * \return error code, or GL_NO_ERROR.
1953 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1954 unsigned dimensions
)
1956 GLboolean type_valid
= GL_TRUE
;
1961 case GL_LUMINANCE_ALPHA
:
1962 type_valid
= (type
== GL_UNSIGNED_BYTE
1964 || type
== GL_HALF_FLOAT_OES
);
1968 type_valid
= (type
== GL_UNSIGNED_BYTE
1969 || type
== GL_UNSIGNED_SHORT_5_6_5
1971 || type
== GL_HALF_FLOAT_OES
);
1975 type_valid
= (type
== GL_UNSIGNED_BYTE
1976 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1977 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1979 || type
== GL_HALF_FLOAT_OES
1980 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1983 case GL_DEPTH_COMPONENT
:
1984 /* This format is filtered against invalid dimensionalities elsewhere.
1986 type_valid
= (type
== GL_UNSIGNED_SHORT
1987 || type
== GL_UNSIGNED_INT
);
1990 case GL_DEPTH_STENCIL
:
1991 /* This format is filtered against invalid dimensionalities elsewhere.
1993 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1997 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1999 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2000 * the format does not appear to be allowed for 3D textures in OpenGL
2003 if (dimensions
!= 2)
2004 return GL_INVALID_VALUE
;
2009 return GL_INVALID_VALUE
;
2012 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2017 * Do error checking of format/type combinations for OpenGL ES 3
2019 * \return error code, or GL_NO_ERROR.
2022 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
2023 GLenum internalFormat
)
2028 case GL_UNSIGNED_BYTE
:
2029 switch (internalFormat
) {
2034 case GL_SRGB8_ALPHA8_EXT
:
2037 return GL_INVALID_OPERATION
;
2042 if (internalFormat
!= GL_RGBA8_SNORM
)
2043 return GL_INVALID_OPERATION
;
2046 case GL_UNSIGNED_SHORT_4_4_4_4
:
2047 switch (internalFormat
) {
2052 return GL_INVALID_OPERATION
;
2056 case GL_UNSIGNED_SHORT_5_5_5_1
:
2057 switch (internalFormat
) {
2062 return GL_INVALID_OPERATION
;
2066 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2067 switch (internalFormat
) {
2068 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2073 return GL_INVALID_OPERATION
;
2078 if (internalFormat
!= GL_RGBA16F
)
2079 return GL_INVALID_OPERATION
;
2083 switch (internalFormat
) {
2088 return GL_INVALID_OPERATION
;
2093 return GL_INVALID_OPERATION
;
2097 case GL_RGBA_INTEGER
:
2099 case GL_UNSIGNED_BYTE
:
2100 if (internalFormat
!= GL_RGBA8UI
)
2101 return GL_INVALID_OPERATION
;
2105 if (internalFormat
!= GL_RGBA8I
)
2106 return GL_INVALID_OPERATION
;
2109 case GL_UNSIGNED_SHORT
:
2110 if (internalFormat
!= GL_RGBA16UI
)
2111 return GL_INVALID_OPERATION
;
2115 if (internalFormat
!= GL_RGBA16I
)
2116 return GL_INVALID_OPERATION
;
2119 case GL_UNSIGNED_INT
:
2120 if (internalFormat
!= GL_RGBA32UI
)
2121 return GL_INVALID_OPERATION
;
2125 if (internalFormat
!= GL_RGBA32I
)
2126 return GL_INVALID_OPERATION
;
2129 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2130 if (internalFormat
!= GL_RGB10_A2UI
)
2131 return GL_INVALID_OPERATION
;
2135 return GL_INVALID_OPERATION
;
2141 case GL_UNSIGNED_BYTE
:
2142 switch (internalFormat
) {
2149 return GL_INVALID_OPERATION
;
2154 if (internalFormat
!= GL_RGB8_SNORM
)
2155 return GL_INVALID_OPERATION
;
2158 case GL_UNSIGNED_SHORT_5_6_5
:
2159 switch (internalFormat
) {
2164 return GL_INVALID_OPERATION
;
2168 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2169 if (internalFormat
!= GL_R11F_G11F_B10F
)
2170 return GL_INVALID_OPERATION
;
2173 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2174 if (internalFormat
!= GL_RGB9_E5
)
2175 return GL_INVALID_OPERATION
;
2179 switch (internalFormat
) {
2181 case GL_R11F_G11F_B10F
:
2185 return GL_INVALID_OPERATION
;
2190 switch (internalFormat
) {
2193 case GL_R11F_G11F_B10F
:
2197 return GL_INVALID_OPERATION
;
2201 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2202 switch (internalFormat
) {
2203 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2206 return GL_INVALID_OPERATION
;
2211 return GL_INVALID_OPERATION
;
2215 case GL_RGB_INTEGER
:
2217 case GL_UNSIGNED_BYTE
:
2218 if (internalFormat
!= GL_RGB8UI
)
2219 return GL_INVALID_OPERATION
;
2223 if (internalFormat
!= GL_RGB8I
)
2224 return GL_INVALID_OPERATION
;
2227 case GL_UNSIGNED_SHORT
:
2228 if (internalFormat
!= GL_RGB16UI
)
2229 return GL_INVALID_OPERATION
;
2233 if (internalFormat
!= GL_RGB16I
)
2234 return GL_INVALID_OPERATION
;
2237 case GL_UNSIGNED_INT
:
2238 if (internalFormat
!= GL_RGB32UI
)
2239 return GL_INVALID_OPERATION
;
2243 if (internalFormat
!= GL_RGB32I
)
2244 return GL_INVALID_OPERATION
;
2248 return GL_INVALID_OPERATION
;
2254 case GL_UNSIGNED_BYTE
:
2255 if (internalFormat
!= GL_RG8
)
2256 return GL_INVALID_OPERATION
;
2260 if (internalFormat
!= GL_RG8_SNORM
)
2261 return GL_INVALID_OPERATION
;
2265 if (internalFormat
!= GL_RG16F
)
2266 return GL_INVALID_OPERATION
;
2270 switch (internalFormat
) {
2275 return GL_INVALID_OPERATION
;
2280 return GL_INVALID_OPERATION
;
2286 case GL_UNSIGNED_BYTE
:
2287 if (internalFormat
!= GL_RG8UI
)
2288 return GL_INVALID_OPERATION
;
2292 if (internalFormat
!= GL_RG8I
)
2293 return GL_INVALID_OPERATION
;
2296 case GL_UNSIGNED_SHORT
:
2297 if (internalFormat
!= GL_RG16UI
)
2298 return GL_INVALID_OPERATION
;
2302 if (internalFormat
!= GL_RG16I
)
2303 return GL_INVALID_OPERATION
;
2306 case GL_UNSIGNED_INT
:
2307 if (internalFormat
!= GL_RG32UI
)
2308 return GL_INVALID_OPERATION
;
2312 if (internalFormat
!= GL_RG32I
)
2313 return GL_INVALID_OPERATION
;
2317 return GL_INVALID_OPERATION
;
2323 case GL_UNSIGNED_BYTE
:
2324 if (internalFormat
!= GL_R8
)
2325 return GL_INVALID_OPERATION
;
2329 if (internalFormat
!= GL_R8_SNORM
)
2330 return GL_INVALID_OPERATION
;
2334 if (internalFormat
!= GL_R16F
)
2335 return GL_INVALID_OPERATION
;
2339 switch (internalFormat
) {
2344 return GL_INVALID_OPERATION
;
2349 return GL_INVALID_OPERATION
;
2353 case GL_RED_INTEGER
:
2355 case GL_UNSIGNED_BYTE
:
2356 if (internalFormat
!= GL_R8UI
)
2357 return GL_INVALID_OPERATION
;
2361 if (internalFormat
!= GL_R8I
)
2362 return GL_INVALID_OPERATION
;
2365 case GL_UNSIGNED_SHORT
:
2366 if (internalFormat
!= GL_R16UI
)
2367 return GL_INVALID_OPERATION
;
2371 if (internalFormat
!= GL_R16I
)
2372 return GL_INVALID_OPERATION
;
2375 case GL_UNSIGNED_INT
:
2376 if (internalFormat
!= GL_R32UI
)
2377 return GL_INVALID_OPERATION
;
2381 if (internalFormat
!= GL_R32I
)
2382 return GL_INVALID_OPERATION
;
2386 return GL_INVALID_OPERATION
;
2390 case GL_DEPTH_COMPONENT
:
2392 case GL_UNSIGNED_SHORT
:
2393 if (internalFormat
!= GL_DEPTH_COMPONENT
2394 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2395 return GL_INVALID_OPERATION
;
2398 case GL_UNSIGNED_INT
:
2399 switch (internalFormat
) {
2400 case GL_DEPTH_COMPONENT
:
2401 case GL_DEPTH_COMPONENT16
:
2402 case GL_DEPTH_COMPONENT24
:
2405 return GL_INVALID_OPERATION
;
2410 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2411 return GL_INVALID_OPERATION
;
2415 return GL_INVALID_OPERATION
;
2419 case GL_DEPTH_STENCIL
:
2421 case GL_UNSIGNED_INT_24_8
:
2422 if (internalFormat
!= GL_DEPTH_STENCIL
2423 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2424 return GL_INVALID_OPERATION
;
2427 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2428 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2429 return GL_INVALID_OPERATION
;
2433 return GL_INVALID_OPERATION
;
2439 case GL_LUMINANCE_ALPHA
:
2440 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2441 return GL_INVALID_OPERATION
;
2449 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
2451 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
2452 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
2453 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
2454 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
2458 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
2462 case GL_RGBA_INTEGER_EXT
:
2463 set_swizzle(swizzle
, 0, 1, 2, 3);
2466 case GL_BGRA_INTEGER_EXT
:
2467 set_swizzle(swizzle
, 2, 1, 0, 3);
2470 set_swizzle(swizzle
, 3, 2, 1, 0);
2473 case GL_RGB_INTEGER_EXT
:
2474 set_swizzle(swizzle
, 0, 1, 2, 5);
2477 case GL_BGR_INTEGER_EXT
:
2478 set_swizzle(swizzle
, 2, 1, 0, 5);
2480 case GL_LUMINANCE_ALPHA
:
2481 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2482 set_swizzle(swizzle
, 0, 0, 0, 1);
2486 set_swizzle(swizzle
, 0, 1, 4, 5);
2489 case GL_RED_INTEGER_EXT
:
2490 set_swizzle(swizzle
, 0, 4, 4, 5);
2493 case GL_GREEN_INTEGER_EXT
:
2494 set_swizzle(swizzle
, 4, 0, 4, 5);
2497 case GL_BLUE_INTEGER_EXT
:
2498 set_swizzle(swizzle
, 4, 4, 0, 5);
2501 case GL_ALPHA_INTEGER_EXT
:
2502 set_swizzle(swizzle
, 4, 4, 4, 0);
2505 case GL_LUMINANCE_INTEGER_EXT
:
2506 set_swizzle(swizzle
, 0, 0, 0, 5);
2509 set_swizzle(swizzle
, 0, 0, 0, 0);
2517 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
2518 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
2519 * otherwise (for non-array formats).
2521 * This function will typically be used to compute a mesa format from a GL type
2522 * so we can then call _mesa_format_convert. This function does
2523 * not consider byte swapping, so it returns types assuming that no byte
2524 * swapping is involved. If byte swapping is involved then clients are supposed
2525 * to handle that on their side before calling _mesa_format_convert.
2527 * This function returns an uint32_t that can pack a mesa_format or a
2528 * mesa_array_format. Clients must check the mesa array format bit
2529 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
2530 * format is a mesa_array_format or a mesa_format.
2533 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
2535 mesa_array_format array_format
;
2537 bool is_array_format
= true;
2539 bool normalized
= false, is_float
= false, is_signed
= false;
2540 int num_channels
= 0, type_size
= 0;
2542 /* Extract array format type information from the OpenGL data type */
2544 case GL_UNSIGNED_BYTE
:
2551 case GL_UNSIGNED_SHORT
:
2558 case GL_UNSIGNED_INT
:
2576 is_array_format
= false;
2580 /* Extract array format swizzle information from the OpenGL format */
2581 if (is_array_format
)
2582 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
2584 /* If this is an array format type after checking data type and format,
2585 * create the array format
2587 if (is_array_format
) {
2588 normalized
= !_mesa_is_enum_format_integer(format
);
2589 num_channels
= _mesa_components_in_format(format
);
2592 MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
2593 normalized
, num_channels
,
2594 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
2596 if (!_mesa_little_endian())
2597 array_format
= _mesa_array_format_flip_channels(array_format
);
2599 return array_format
;
2602 /* Otherwise this is not an array format, so return the mesa_format
2603 * matching the OpenGL format and data type
2606 case GL_UNSIGNED_SHORT_5_6_5
:
2607 if (format
== GL_RGB
)
2608 return MESA_FORMAT_B5G6R5_UNORM
;
2609 else if (format
== GL_BGR
)
2610 return MESA_FORMAT_R5G6B5_UNORM
;
2612 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2613 if (format
== GL_RGB
)
2614 return MESA_FORMAT_R5G6B5_UNORM
;
2615 else if (format
== GL_BGR
)
2616 return MESA_FORMAT_B5G6R5_UNORM
;
2618 case GL_UNSIGNED_SHORT_4_4_4_4
:
2619 if (format
== GL_RGBA
)
2620 return MESA_FORMAT_A4B4G4R4_UNORM
;
2621 else if (format
== GL_BGRA
)
2622 return MESA_FORMAT_A4R4G4B4_UNORM
;
2623 else if (format
== GL_ABGR_EXT
)
2624 return MESA_FORMAT_R4G4B4A4_UNORM
;
2626 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2627 if (format
== GL_RGBA
)
2628 return MESA_FORMAT_R4G4B4A4_UNORM
;
2629 else if (format
== GL_BGRA
)
2630 return MESA_FORMAT_B4G4R4A4_UNORM
;
2631 else if (format
== GL_ABGR_EXT
)
2632 return MESA_FORMAT_A4B4G4R4_UNORM
;
2634 case GL_UNSIGNED_SHORT_5_5_5_1
:
2635 if (format
== GL_RGBA
)
2636 return MESA_FORMAT_A1B5G5R5_UNORM
;
2637 else if (format
== GL_BGRA
)
2638 return MESA_FORMAT_A1R5G5B5_UNORM
;
2640 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2641 if (format
== GL_RGBA
)
2642 return MESA_FORMAT_R5G5B5A1_UNORM
;
2643 else if (format
== GL_BGRA
)
2644 return MESA_FORMAT_B5G5R5A1_UNORM
;
2646 case GL_UNSIGNED_BYTE_3_3_2
:
2647 if (format
== GL_RGB
)
2648 return MESA_FORMAT_B2G3R3_UNORM
;
2650 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2651 if (format
== GL_RGB
)
2652 return MESA_FORMAT_R3G3B2_UNORM
;
2654 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2655 if (format
== GL_RGB
)
2656 return MESA_FORMAT_R9G9B9E5_FLOAT
;
2658 case GL_UNSIGNED_INT_10_10_10_2
:
2659 if (format
== GL_RGBA
)
2660 return MESA_FORMAT_A2B10G10R10_UNORM
;
2661 else if (format
== GL_RGBA_INTEGER
)
2662 return MESA_FORMAT_A2B10G10R10_UINT
;
2663 else if (format
== GL_BGRA
)
2664 return MESA_FORMAT_A2R10G10B10_UNORM
;
2665 else if (format
== GL_BGRA_INTEGER
)
2666 return MESA_FORMAT_A2R10G10B10_UINT
;
2668 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2669 if (format
== GL_RGB
)
2670 return MESA_FORMAT_R10G10B10X2_UNORM
;
2671 if (format
== GL_RGBA
)
2672 return MESA_FORMAT_R10G10B10A2_UNORM
;
2673 else if (format
== GL_RGBA_INTEGER
)
2674 return MESA_FORMAT_R10G10B10A2_UINT
;
2675 else if (format
== GL_BGRA
)
2676 return MESA_FORMAT_B10G10R10A2_UNORM
;
2677 else if (format
== GL_BGRA_INTEGER
)
2678 return MESA_FORMAT_B10G10R10A2_UINT
;
2680 case GL_UNSIGNED_INT_8_8_8_8
:
2681 if (format
== GL_RGBA
)
2682 return MESA_FORMAT_A8B8G8R8_UNORM
;
2683 else if (format
== GL_BGRA
)
2684 return MESA_FORMAT_A8R8G8B8_UNORM
;
2685 else if (format
== GL_ABGR_EXT
)
2686 return MESA_FORMAT_R8G8B8A8_UNORM
;
2688 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2689 if (format
== GL_RGBA
)
2690 return MESA_FORMAT_R8G8B8A8_UNORM
;
2691 else if (format
== GL_BGRA
)
2692 return MESA_FORMAT_B8G8R8A8_UNORM
;
2693 else if (format
== GL_ABGR_EXT
)
2694 return MESA_FORMAT_A8B8G8R8_UNORM
;
2696 case GL_UNSIGNED_SHORT_8_8_MESA
:
2697 if (format
== GL_YCBCR_MESA
)
2698 return MESA_FORMAT_YCBCR
;
2700 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
2701 if (format
== GL_YCBCR_MESA
)
2702 return MESA_FORMAT_YCBCR_REV
;
2704 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2705 if (format
== GL_RGB
)
2706 return MESA_FORMAT_R11G11B10_FLOAT
;
2711 /* If we got here it means that we could not find a Mesa format that
2712 * matches the GL format/type provided. We may need to add a new Mesa
2713 * format in that case.
2715 unreachable("Unsupported format");