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"
31 #include "texcompress.h"
56 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
57 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
58 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
59 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
75 MAP4(ZERO, ZERO, ZERO, 0),
105 MAP4(0, ZERO, ZERO, ONE),
111 MAP4(ZERO, 0, ZERO, ONE),
117 MAP4(ZERO, ZERO, 0, ONE),
141 MAP4(0, 1, ZERO, ONE),
147 * Convert a GL image format enum to an IDX_* value (see above).
150 get_map_idx(GLenum value)
154 case GL_LUMINANCE_INTEGER_EXT:
155 return IDX_LUMINANCE;
157 case GL_ALPHA_INTEGER:
160 return IDX_INTENSITY;
161 case GL_LUMINANCE_ALPHA:
162 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
163 return IDX_LUMINANCE_ALPHA;
168 case GL_RGBA_INTEGER:
181 case GL_BGRA_INTEGER:
189 _mesa_problem(NULL, "Unexpected inFormat %s",
190 _mesa_enum_to_string(value));
196 * When promoting texture formats (see below) we need to compute the
197 * mapping of dest components back to source components.
198 * This function does that.
199 * \param inFormat the incoming format of the texture
200 * \param outFormat the final texture format
201 * \return map[6] a full 6-component map
204 _mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map)
206 const int inFmt = get_map_idx(inFormat);
207 const int outFmt = get_map_idx(outFormat);
208 const GLubyte *in2rgba = mappings[inFmt].to_rgba;
209 const GLubyte *rgba2out = mappings[outFmt].from_rgba;
212 for (i = 0; i < 4; i++)
213 map[i] = in2rgba[rgba2out[i]];
219 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
220 inFormat, _mesa_enum_to_string(inFormat),
221 outFormat, _mesa_enum_to_string(outFormat),
232 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
235 _mesa_type_is_packed(GLenum type)
238 case GL_UNSIGNED_BYTE_3_3_2:
239 case GL_UNSIGNED_BYTE_2_3_3_REV:
240 case MESA_UNSIGNED_BYTE_4_4:
241 case GL_UNSIGNED_SHORT_5_6_5:
242 case GL_UNSIGNED_SHORT_5_6_5_REV:
243 case GL_UNSIGNED_SHORT_4_4_4_4:
244 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
245 case GL_UNSIGNED_SHORT_5_5_5_1:
246 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
247 case GL_UNSIGNED_INT_8_8_8_8:
248 case GL_UNSIGNED_INT_8_8_8_8_REV:
249 case GL_UNSIGNED_INT_10_10_10_2:
250 case GL_UNSIGNED_INT_2_10_10_10_REV:
251 case GL_UNSIGNED_SHORT_8_8_MESA:
252 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
253 case GL_UNSIGNED_INT_24_8_EXT:
254 case GL_UNSIGNED_INT_5_9_9_9_REV:
255 case GL_UNSIGNED_INT_10F_11F_11F_REV:
256 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
265 * Get the size of a GL data type.
267 * \param type GL data type.
269 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
270 * if an invalid type enum.
273 _mesa_sizeof_type(GLenum type)
278 case GL_UNSIGNED_BYTE:
279 return sizeof(GLubyte);
281 return sizeof(GLbyte);
282 case GL_UNSIGNED_SHORT:
283 return sizeof(GLushort);
285 return sizeof(GLshort);
286 case GL_UNSIGNED_INT:
287 return sizeof(GLuint);
289 return sizeof(GLint);
291 return sizeof(GLfloat);
293 return sizeof(GLdouble);
294 case GL_HALF_FLOAT_ARB:
295 case GL_HALF_FLOAT_OES:
296 return sizeof(GLhalfARB);
298 return sizeof(GLfixed);
306 * Same as _mesa_sizeof_type() but also accepting the packed pixel
310 _mesa_sizeof_packed_type(GLenum type)
315 case GL_UNSIGNED_BYTE:
316 return sizeof(GLubyte);
318 return sizeof(GLbyte);
319 case GL_UNSIGNED_SHORT:
320 return sizeof(GLushort);
322 return sizeof(GLshort);
323 case GL_UNSIGNED_INT:
324 return sizeof(GLuint);
326 return sizeof(GLint);
327 case GL_HALF_FLOAT_ARB:
328 case GL_HALF_FLOAT_OES:
329 return sizeof(GLhalfARB);
331 return sizeof(GLfloat);
332 case GL_UNSIGNED_BYTE_3_3_2:
333 case GL_UNSIGNED_BYTE_2_3_3_REV:
334 case MESA_UNSIGNED_BYTE_4_4:
335 return sizeof(GLubyte);
336 case GL_UNSIGNED_SHORT_5_6_5:
337 case GL_UNSIGNED_SHORT_5_6_5_REV:
338 case GL_UNSIGNED_SHORT_4_4_4_4:
339 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
340 case GL_UNSIGNED_SHORT_5_5_5_1:
341 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
342 case GL_UNSIGNED_SHORT_8_8_MESA:
343 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
344 return sizeof(GLushort);
345 case GL_UNSIGNED_INT_8_8_8_8:
346 case GL_UNSIGNED_INT_8_8_8_8_REV:
347 case GL_UNSIGNED_INT_10_10_10_2:
348 case GL_UNSIGNED_INT_2_10_10_10_REV:
349 case GL_UNSIGNED_INT_24_8_EXT:
350 case GL_UNSIGNED_INT_5_9_9_9_REV:
351 case GL_UNSIGNED_INT_10F_11F_11F_REV:
352 return sizeof(GLuint);
353 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
362 * Get the number of components in a pixel format.
364 * \param format pixel format.
366 * \return the number of components in the given format, or -1 if a bad format.
369 _mesa_components_in_format(GLenum format)
373 case GL_STENCIL_INDEX:
374 case GL_DEPTH_COMPONENT:
376 case GL_RED_INTEGER_EXT:
378 case GL_GREEN_INTEGER_EXT:
380 case GL_BLUE_INTEGER_EXT:
382 case GL_ALPHA_INTEGER_EXT:
384 case GL_LUMINANCE_INTEGER_EXT:
388 case GL_LUMINANCE_ALPHA:
389 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
392 case GL_DEPTH_STENCIL_EXT:
398 case GL_RGB_INTEGER_EXT:
399 case GL_BGR_INTEGER_EXT:
405 case GL_RGBA_INTEGER_EXT:
406 case GL_BGRA_INTEGER_EXT:
416 * Get the bytes per pixel of pixel format type pair.
418 * \param format pixel format.
419 * \param type pixel type.
421 * \return bytes per pixel, or -1 if a bad format or type was given.
424 _mesa_bytes_per_pixel(GLenum format, GLenum type)
426 GLint comps = _mesa_components_in_format(format);
432 return 0; /* special case */
434 case GL_UNSIGNED_BYTE:
435 return comps * sizeof(GLubyte);
437 case GL_UNSIGNED_SHORT:
438 return comps * sizeof(GLshort);
440 case GL_UNSIGNED_INT:
441 return comps * sizeof(GLint);
443 return comps * sizeof(GLfloat);
444 case GL_HALF_FLOAT_ARB:
445 case GL_HALF_FLOAT_OES:
446 return comps * sizeof(GLhalfARB);
447 case GL_UNSIGNED_BYTE_3_3_2:
448 case GL_UNSIGNED_BYTE_2_3_3_REV:
449 if (format == GL_RGB || format == GL_BGR ||
450 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
451 return sizeof(GLubyte);
453 return -1; /* error */
454 case GL_UNSIGNED_SHORT_5_6_5:
455 case GL_UNSIGNED_SHORT_5_6_5_REV:
456 if (format == GL_RGB || format == GL_BGR ||
457 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
458 return sizeof(GLushort);
460 return -1; /* error */
461 case GL_UNSIGNED_SHORT_4_4_4_4:
462 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
463 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
464 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
465 return sizeof(GLushort);
468 case GL_UNSIGNED_SHORT_5_5_5_1:
469 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
470 if (format == GL_RGBA || format == GL_BGRA ||
471 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
472 return sizeof(GLushort);
475 case GL_UNSIGNED_INT_8_8_8_8:
476 case GL_UNSIGNED_INT_8_8_8_8_REV:
477 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
478 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT ||
480 return sizeof(GLuint);
483 case GL_UNSIGNED_INT_10_10_10_2:
484 case GL_UNSIGNED_INT_2_10_10_10_REV:
485 if (format == GL_RGBA || format == GL_BGRA ||
486 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT ||
488 return sizeof(GLuint);
491 case GL_UNSIGNED_SHORT_8_8_MESA:
492 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
493 if (format == GL_YCBCR_MESA)
494 return sizeof(GLushort);
497 case GL_UNSIGNED_INT_24_8_EXT:
498 if (format == GL_DEPTH_COMPONENT ||
499 format == GL_DEPTH_STENCIL_EXT)
500 return sizeof(GLuint);
503 case GL_UNSIGNED_INT_5_9_9_9_REV:
504 if (format == GL_RGB)
505 return sizeof(GLuint);
508 case GL_UNSIGNED_INT_10F_11F_11F_REV:
509 if (format == GL_RGB)
510 return sizeof(GLuint);
513 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
514 if (format == GL_DEPTH_STENCIL)
525 * Get the number of bytes for a vertex attrib with the given number of
526 * components and type.
528 * \param comps number of components.
529 * \param type data type.
531 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
534 _mesa_bytes_per_vertex_attrib(GLint comps, GLenum type)
538 case GL_UNSIGNED_BYTE:
539 return comps * sizeof(GLubyte);
541 case GL_UNSIGNED_SHORT:
542 return comps * sizeof(GLshort);
544 case GL_UNSIGNED_INT:
545 return comps * sizeof(GLint);
547 return comps * sizeof(GLfloat);
548 case GL_HALF_FLOAT_ARB:
549 return comps * sizeof(GLhalfARB);
551 return comps * sizeof(GLdouble);
553 return comps * sizeof(GLfixed);
554 case GL_INT_2_10_10_10_REV:
555 case GL_UNSIGNED_INT_2_10_10_10_REV:
557 return sizeof(GLuint);
560 case GL_UNSIGNED_INT_10F_11F_11F_REV:
562 return sizeof(GLuint);
571 * Test if the given format is unsized.
574 _mesa_is_enum_format_unsized(GLenum format)
589 case GL_LUMINANCE_ALPHA:
594 case GL_SLUMINANCE_ALPHA:
601 case GL_INTENSITY_SNORM:
602 case GL_LUMINANCE_SNORM:
603 case GL_LUMINANCE_ALPHA_SNORM:
606 case GL_GREEN_INTEGER:
607 case GL_BLUE_INTEGER:
608 case GL_ALPHA_INTEGER:
610 case GL_RGBA_INTEGER:
612 case GL_BGRA_INTEGER:
614 case GL_LUMINANCE_INTEGER_EXT:
615 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
617 case GL_DEPTH_COMPONENT:
618 case GL_DEPTH_STENCIL:
619 case GL_STENCIL_INDEX:
627 * Test if the given format is a UNORM (unsigned-normalized) format.
630 _mesa_is_enum_format_unorm(GLenum format)
649 case GL_LUMINANCE_ALPHA:
650 case GL_SLUMINANCE_ALPHA:
651 case GL_LUMINANCE4_ALPHA4:
652 case GL_LUMINANCE6_ALPHA2:
653 case GL_LUMINANCE8_ALPHA8:
654 case GL_LUMINANCE12_ALPHA4:
655 case GL_LUMINANCE12_ALPHA12:
656 case GL_LUMINANCE16_ALPHA16:
698 * Test if the given format is a SNORM (signed-normalized) format.
701 _mesa_is_enum_format_snorm(GLenum format)
704 /* signed, normalized texture formats */
716 case GL_RGBA16_SNORM:
718 case GL_ALPHA8_SNORM:
719 case GL_ALPHA16_SNORM:
720 case GL_LUMINANCE_SNORM:
721 case GL_LUMINANCE8_SNORM:
722 case GL_LUMINANCE16_SNORM:
723 case GL_LUMINANCE_ALPHA_SNORM:
724 case GL_LUMINANCE8_ALPHA8_SNORM:
725 case GL_LUMINANCE16_ALPHA16_SNORM:
726 case GL_INTENSITY_SNORM:
727 case GL_INTENSITY8_SNORM:
728 case GL_INTENSITY16_SNORM:
736 * Test if the given format is an integer (non-normalized) format.
739 _mesa_is_enum_format_unsigned_int(GLenum format)
742 /* specific integer formats */
743 case GL_RGBA32UI_EXT:
747 case GL_ALPHA32UI_EXT:
748 case GL_INTENSITY32UI_EXT:
749 case GL_LUMINANCE32UI_EXT:
750 case GL_LUMINANCE_ALPHA32UI_EXT:
751 case GL_RGBA16UI_EXT:
755 case GL_ALPHA16UI_EXT:
756 case GL_INTENSITY16UI_EXT:
757 case GL_LUMINANCE16UI_EXT:
758 case GL_LUMINANCE_ALPHA16UI_EXT:
763 case GL_ALPHA8UI_EXT:
764 case GL_INTENSITY8UI_EXT:
765 case GL_LUMINANCE8UI_EXT:
766 case GL_LUMINANCE_ALPHA8UI_EXT:
776 * Test if the given format is an integer (non-normalized) format.
779 _mesa_is_enum_format_signed_int(GLenum format)
782 /* generic integer formats */
783 case GL_RED_INTEGER_EXT:
784 case GL_GREEN_INTEGER_EXT:
785 case GL_BLUE_INTEGER_EXT:
786 case GL_ALPHA_INTEGER_EXT:
787 case GL_RGB_INTEGER_EXT:
788 case GL_RGBA_INTEGER_EXT:
789 case GL_BGR_INTEGER_EXT:
790 case GL_BGRA_INTEGER_EXT:
791 case GL_LUMINANCE_INTEGER_EXT:
792 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
794 /* specific integer formats */
799 case GL_ALPHA32I_EXT:
800 case GL_INTENSITY32I_EXT:
801 case GL_LUMINANCE32I_EXT:
802 case GL_LUMINANCE_ALPHA32I_EXT:
807 case GL_ALPHA16I_EXT:
808 case GL_INTENSITY16I_EXT:
809 case GL_LUMINANCE16I_EXT:
810 case GL_LUMINANCE_ALPHA16I_EXT:
816 case GL_INTENSITY8I_EXT:
817 case GL_LUMINANCE8I_EXT:
818 case GL_LUMINANCE_ALPHA8I_EXT:
826 * Test if the given format is an ASTC 2D format.
829 is_astc_2d_format(GLenum internalFormat)
831 switch (internalFormat) {
832 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
833 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
834 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
835 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
836 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
837 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
838 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
839 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
840 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
841 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
842 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
843 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
844 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
845 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
846 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
847 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
848 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
849 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
850 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
851 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
852 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
853 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
854 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
855 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
856 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
857 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
858 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
859 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
867 * Test if the given format is an ASTC 3D format.
870 is_astc_3d_format(GLenum internalFormat)
872 switch (internalFormat) {
873 case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES:
874 case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES:
875 case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES:
876 case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES:
877 case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES:
878 case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES:
879 case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES:
880 case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES:
881 case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES:
882 case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES:
883 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES:
884 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES:
885 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES:
886 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES:
887 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES:
888 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES:
889 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES:
890 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES:
891 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES:
892 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES:
900 * Test if the given format is an ASTC format.
903 _mesa_is_astc_format(GLenum internalFormat)
905 return is_astc_2d_format(internalFormat) ||
906 is_astc_3d_format(internalFormat);
910 * Test if the given format is an integer (non-normalized) format.
913 _mesa_is_enum_format_integer(GLenum format)
915 return _mesa_is_enum_format_unsigned_int(format) ||
916 _mesa_is_enum_format_signed_int(format);
921 _mesa_is_type_unsigned(GLenum type)
924 case GL_UNSIGNED_INT:
925 case GL_UNSIGNED_INT_8_8_8_8:
926 case GL_UNSIGNED_INT_8_8_8_8_REV:
927 case GL_UNSIGNED_INT_10_10_10_2:
928 case GL_UNSIGNED_INT_2_10_10_10_REV:
930 case GL_UNSIGNED_SHORT:
931 case GL_UNSIGNED_SHORT_4_4_4_4:
932 case GL_UNSIGNED_SHORT_5_5_5_1:
933 case GL_UNSIGNED_SHORT_5_6_5:
934 case GL_UNSIGNED_SHORT_5_6_5_REV:
935 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
936 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
937 case GL_UNSIGNED_SHORT_8_8_MESA:
938 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
940 case GL_UNSIGNED_BYTE:
941 case GL_UNSIGNED_BYTE_3_3_2:
942 case GL_UNSIGNED_BYTE_2_3_3_REV:
952 * Test if the given image format is a color/RGBA format (i.e., not color
953 * index, depth, stencil, etc).
954 * \param format the image format value (may by an internal texture format)
955 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
958 _mesa_is_color_format(GLenum format)
976 case GL_LUMINANCE_ALPHA:
977 case GL_LUMINANCE4_ALPHA4:
978 case GL_LUMINANCE6_ALPHA2:
979 case GL_LUMINANCE8_ALPHA8:
980 case GL_LUMINANCE12_ALPHA4:
981 case GL_LUMINANCE12_ALPHA12:
982 case GL_LUMINANCE16_ALPHA16:
1015 /* float texture formats */
1016 case GL_ALPHA16F_ARB:
1017 case GL_ALPHA32F_ARB:
1018 case GL_LUMINANCE16F_ARB:
1019 case GL_LUMINANCE32F_ARB:
1020 case GL_LUMINANCE_ALPHA16F_ARB:
1021 case GL_LUMINANCE_ALPHA32F_ARB:
1022 case GL_INTENSITY16F_ARB:
1023 case GL_INTENSITY32F_ARB:
1030 case GL_RGBA16F_ARB:
1031 case GL_RGBA32F_ARB:
1032 /* compressed formats */
1033 case GL_COMPRESSED_ALPHA:
1034 case GL_COMPRESSED_LUMINANCE:
1035 case GL_COMPRESSED_LUMINANCE_ALPHA:
1036 case GL_COMPRESSED_INTENSITY:
1037 case GL_COMPRESSED_RED:
1038 case GL_COMPRESSED_RG:
1039 case GL_COMPRESSED_RGB:
1040 case GL_COMPRESSED_RGBA:
1045 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1046 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1047 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1048 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1049 case GL_COMPRESSED_RGB_FXT1_3DFX:
1050 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1053 case GL_SRGB_ALPHA_EXT:
1054 case GL_SRGB8_ALPHA8_EXT:
1055 case GL_SLUMINANCE_ALPHA_EXT:
1056 case GL_SLUMINANCE8_ALPHA8_EXT:
1057 case GL_SLUMINANCE_EXT:
1058 case GL_SLUMINANCE8_EXT:
1059 case GL_COMPRESSED_SRGB_EXT:
1060 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1061 case GL_COMPRESSED_SRGB_ALPHA_EXT:
1062 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1063 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1064 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1065 case GL_COMPRESSED_SLUMINANCE_EXT:
1066 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
1067 case GL_COMPRESSED_RED_RGTC1:
1068 case GL_COMPRESSED_SIGNED_RED_RGTC1:
1069 case GL_COMPRESSED_RG_RGTC2:
1070 case GL_COMPRESSED_SIGNED_RG_RGTC2:
1071 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
1072 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
1073 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
1074 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
1075 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1076 case GL_ETC1_RGB8_OES:
1077 case GL_COMPRESSED_RGB8_ETC2:
1078 case GL_COMPRESSED_SRGB8_ETC2:
1079 case GL_COMPRESSED_RGBA8_ETC2_EAC:
1080 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1081 case GL_COMPRESSED_R11_EAC:
1082 case GL_COMPRESSED_RG11_EAC:
1083 case GL_COMPRESSED_SIGNED_R11_EAC:
1084 case GL_COMPRESSED_SIGNED_RG11_EAC:
1085 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1086 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1087 case GL_COMPRESSED_RGBA_BPTC_UNORM:
1088 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
1089 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
1090 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
1091 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1092 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1093 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1094 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1095 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1096 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1097 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1098 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1099 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1100 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1101 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1102 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1103 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1104 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1105 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1106 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1107 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1108 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1109 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1110 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1111 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1112 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1113 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1114 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1115 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1116 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1117 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1118 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1119 /* generic integer formats */
1120 case GL_RED_INTEGER_EXT:
1121 case GL_GREEN_INTEGER_EXT:
1122 case GL_BLUE_INTEGER_EXT:
1123 case GL_ALPHA_INTEGER_EXT:
1124 case GL_RGB_INTEGER_EXT:
1125 case GL_RGBA_INTEGER_EXT:
1126 case GL_BGR_INTEGER_EXT:
1127 case GL_BGRA_INTEGER_EXT:
1129 case GL_LUMINANCE_INTEGER_EXT:
1130 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
1131 /* sized integer formats */
1132 case GL_RGBA32UI_EXT:
1133 case GL_RGB32UI_EXT:
1136 case GL_ALPHA32UI_EXT:
1137 case GL_INTENSITY32UI_EXT:
1138 case GL_LUMINANCE32UI_EXT:
1139 case GL_LUMINANCE_ALPHA32UI_EXT:
1140 case GL_RGBA16UI_EXT:
1141 case GL_RGB16UI_EXT:
1144 case GL_ALPHA16UI_EXT:
1145 case GL_INTENSITY16UI_EXT:
1146 case GL_LUMINANCE16UI_EXT:
1147 case GL_LUMINANCE_ALPHA16UI_EXT:
1148 case GL_RGBA8UI_EXT:
1152 case GL_ALPHA8UI_EXT:
1153 case GL_INTENSITY8UI_EXT:
1154 case GL_LUMINANCE8UI_EXT:
1155 case GL_LUMINANCE_ALPHA8UI_EXT:
1156 case GL_RGBA32I_EXT:
1160 case GL_ALPHA32I_EXT:
1161 case GL_INTENSITY32I_EXT:
1162 case GL_LUMINANCE32I_EXT:
1163 case GL_LUMINANCE_ALPHA32I_EXT:
1164 case GL_RGBA16I_EXT:
1168 case GL_ALPHA16I_EXT:
1169 case GL_INTENSITY16I_EXT:
1170 case GL_LUMINANCE16I_EXT:
1171 case GL_LUMINANCE_ALPHA16I_EXT:
1176 case GL_ALPHA8I_EXT:
1177 case GL_INTENSITY8I_EXT:
1178 case GL_LUMINANCE8I_EXT:
1179 case GL_LUMINANCE_ALPHA8I_EXT:
1180 /* signed, normalized texture formats */
1189 case GL_RGB16_SNORM:
1191 case GL_RGBA8_SNORM:
1192 case GL_RGBA16_SNORM:
1193 case GL_ALPHA_SNORM:
1194 case GL_ALPHA8_SNORM:
1195 case GL_ALPHA16_SNORM:
1196 case GL_LUMINANCE_SNORM:
1197 case GL_LUMINANCE8_SNORM:
1198 case GL_LUMINANCE16_SNORM:
1199 case GL_LUMINANCE_ALPHA_SNORM:
1200 case GL_LUMINANCE8_ALPHA8_SNORM:
1201 case GL_LUMINANCE16_ALPHA16_SNORM:
1202 case GL_INTENSITY_SNORM:
1203 case GL_INTENSITY8_SNORM:
1204 case GL_INTENSITY16_SNORM:
1206 case GL_R11F_G11F_B10F:
1209 case GL_YCBCR_MESA: /* not considered to be RGB */
1218 * Test if the given image format is a depth component format.
1221 _mesa_is_depth_format(GLenum format)
1224 case GL_DEPTH_COMPONENT:
1225 case GL_DEPTH_COMPONENT16:
1226 case GL_DEPTH_COMPONENT24:
1227 case GL_DEPTH_COMPONENT32:
1228 case GL_DEPTH_COMPONENT32F:
1237 * Test if the given image format is a stencil format.
1240 _mesa_is_stencil_format(GLenum format)
1243 case GL_STENCIL_INDEX:
1252 * Test if the given image format is a YCbCr format.
1255 _mesa_is_ycbcr_format(GLenum format)
1267 * Test if the given image format is a depth+stencil format.
1270 _mesa_is_depthstencil_format(GLenum format)
1273 case GL_DEPTH24_STENCIL8_EXT:
1274 case GL_DEPTH_STENCIL_EXT:
1275 case GL_DEPTH32F_STENCIL8:
1284 * Test if the given image format is a depth or stencil format.
1287 _mesa_is_depth_or_stencil_format(GLenum format)
1290 case GL_DEPTH_COMPONENT:
1291 case GL_DEPTH_COMPONENT16:
1292 case GL_DEPTH_COMPONENT24:
1293 case GL_DEPTH_COMPONENT32:
1294 case GL_STENCIL_INDEX:
1295 case GL_STENCIL_INDEX1_EXT:
1296 case GL_STENCIL_INDEX4_EXT:
1297 case GL_STENCIL_INDEX8_EXT:
1298 case GL_STENCIL_INDEX16_EXT:
1299 case GL_DEPTH_STENCIL_EXT:
1300 case GL_DEPTH24_STENCIL8_EXT:
1301 case GL_DEPTH_COMPONENT32F:
1302 case GL_DEPTH32F_STENCIL8:
1311 * Test if an image format is a supported compressed format.
1312 * \param format the internal format token provided by the user.
1313 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1316 _mesa_is_compressed_format(const struct gl_context *ctx, GLenum format)
1318 mesa_format m_format = _mesa_glenum_to_compressed_format(format);
1320 /* Some formats in this switch have an equivalent mesa_format_layout
1321 * to the compressed formats in the layout switch below and thus
1322 * must be handled first.
1329 return _mesa_is_desktop_gl(ctx) &&
1330 ctx->Extensions.ANGLE_texture_compression_dxt;
1331 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1332 return ctx->API == API_OPENGL_COMPAT
1333 && ctx->Extensions.ATI_texture_compression_3dc;
1334 case GL_PALETTE4_RGB8_OES:
1335 case GL_PALETTE4_RGBA8_OES:
1336 case GL_PALETTE4_R5_G6_B5_OES:
1337 case GL_PALETTE4_RGBA4_OES:
1338 case GL_PALETTE4_RGB5_A1_OES:
1339 case GL_PALETTE8_RGB8_OES:
1340 case GL_PALETTE8_RGBA8_OES:
1341 case GL_PALETTE8_R5_G6_B5_OES:
1342 case GL_PALETTE8_RGBA4_OES:
1343 case GL_PALETTE8_RGB5_A1_OES:
1344 return ctx->API == API_OPENGLES;
1347 switch (_mesa_get_format_layout(m_format)) {
1348 case MESA_FORMAT_LAYOUT_S3TC:
1349 if (_mesa_get_format_color_encoding(m_format) == GL_LINEAR) {
1350 /* Assume that the ANGLE flag will always be set if the
1353 return ctx->Extensions.ANGLE_texture_compression_dxt;
1355 return _mesa_is_desktop_gl(ctx)
1356 && ctx->Extensions.EXT_texture_sRGB
1357 && ctx->Extensions.EXT_texture_compression_s3tc;
1359 case MESA_FORMAT_LAYOUT_FXT1:
1360 return _mesa_is_desktop_gl(ctx)
1361 && ctx->Extensions.TDFX_texture_compression_FXT1;
1362 case MESA_FORMAT_LAYOUT_RGTC:
1363 return _mesa_is_desktop_gl(ctx)
1364 && ctx->Extensions.ARB_texture_compression_rgtc;
1365 case MESA_FORMAT_LAYOUT_LATC:
1366 return ctx->API == API_OPENGL_COMPAT
1367 && ctx->Extensions.EXT_texture_compression_latc;
1368 case MESA_FORMAT_LAYOUT_ETC1:
1369 return _mesa_is_gles(ctx)
1370 && ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
1371 case MESA_FORMAT_LAYOUT_ETC2:
1372 return _mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility;
1373 case MESA_FORMAT_LAYOUT_BPTC:
1374 return _mesa_is_desktop_gl(ctx) &&
1375 ctx->Extensions.ARB_texture_compression_bptc;
1376 case MESA_FORMAT_LAYOUT_ASTC:
1377 return ctx->Extensions.KHR_texture_compression_astc_ldr;
1384 * Test if the given format represents an sRGB format.
1385 * \param format the GL format (can be an internal format)
1386 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1389 _mesa_is_srgb_format(GLenum format)
1395 case GL_SRGB8_ALPHA8:
1396 case GL_COMPRESSED_SRGB:
1397 case GL_COMPRESSED_SRGB_ALPHA:
1398 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1399 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1400 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1401 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1402 case GL_COMPRESSED_SRGB8_ETC2:
1403 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1404 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1405 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
1406 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1407 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1408 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1409 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1410 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1411 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1412 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1413 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1414 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1415 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1416 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1417 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1418 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1419 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1429 * Convert various unpack formats to the corresponding base format.
1432 _mesa_unpack_format_to_base_format(GLenum format)
1435 case GL_RED_INTEGER:
1437 case GL_GREEN_INTEGER:
1439 case GL_BLUE_INTEGER:
1441 case GL_ALPHA_INTEGER:
1445 case GL_RGB_INTEGER:
1447 case GL_RGBA_INTEGER:
1449 case GL_BGR_INTEGER:
1451 case GL_BGRA_INTEGER:
1453 case GL_LUMINANCE_INTEGER_EXT:
1454 return GL_LUMINANCE;
1455 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
1456 return GL_LUMINANCE_ALPHA;
1467 case GL_LUMINANCE_ALPHA:
1474 * Convert various base formats to the corresponding integer format.
1477 _mesa_base_format_to_integer_format(GLenum format)
1481 return GL_RED_INTEGER;
1483 return GL_GREEN_INTEGER;
1485 return GL_BLUE_INTEGER;
1487 return GL_RG_INTEGER;
1489 return GL_RGB_INTEGER;
1491 return GL_RGBA_INTEGER;
1493 return GL_BGR_INTEGER;
1495 return GL_BGRA_INTEGER;
1497 return GL_ALPHA_INTEGER;
1499 return GL_LUMINANCE_INTEGER_EXT;
1500 case GL_LUMINANCE_ALPHA:
1501 return GL_LUMINANCE_ALPHA_INTEGER_EXT;
1509 * Does the given base texture/renderbuffer format have the channel
1513 _mesa_base_format_has_channel(GLenum base_format, GLenum pname)
1516 case GL_TEXTURE_RED_SIZE:
1517 case GL_TEXTURE_RED_TYPE:
1518 case GL_RENDERBUFFER_RED_SIZE_EXT:
1519 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1520 case GL_INTERNALFORMAT_RED_SIZE:
1521 case GL_INTERNALFORMAT_RED_TYPE:
1522 if (base_format == GL_RED ||
1523 base_format == GL_RG ||
1524 base_format == GL_RGB ||
1525 base_format == GL_RGBA) {
1529 case GL_TEXTURE_GREEN_SIZE:
1530 case GL_TEXTURE_GREEN_TYPE:
1531 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1532 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1533 case GL_INTERNALFORMAT_GREEN_SIZE:
1534 case GL_INTERNALFORMAT_GREEN_TYPE:
1535 if (base_format == GL_RG ||
1536 base_format == GL_RGB ||
1537 base_format == GL_RGBA) {
1541 case GL_TEXTURE_BLUE_SIZE:
1542 case GL_TEXTURE_BLUE_TYPE:
1543 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1544 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1545 case GL_INTERNALFORMAT_BLUE_SIZE:
1546 case GL_INTERNALFORMAT_BLUE_TYPE:
1547 if (base_format == GL_RGB ||
1548 base_format == GL_RGBA) {
1552 case GL_TEXTURE_ALPHA_SIZE:
1553 case GL_TEXTURE_ALPHA_TYPE:
1554 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1555 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1556 case GL_INTERNALFORMAT_ALPHA_SIZE:
1557 case GL_INTERNALFORMAT_ALPHA_TYPE:
1558 if (base_format == GL_RGBA ||
1559 base_format == GL_ALPHA ||
1560 base_format == GL_LUMINANCE_ALPHA) {
1564 case GL_TEXTURE_LUMINANCE_SIZE:
1565 case GL_TEXTURE_LUMINANCE_TYPE:
1566 if (base_format == GL_LUMINANCE ||
1567 base_format == GL_LUMINANCE_ALPHA) {
1571 case GL_TEXTURE_INTENSITY_SIZE:
1572 case GL_TEXTURE_INTENSITY_TYPE:
1573 if (base_format == GL_INTENSITY) {
1577 case GL_TEXTURE_DEPTH_SIZE:
1578 case GL_TEXTURE_DEPTH_TYPE:
1579 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1580 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1581 case GL_INTERNALFORMAT_DEPTH_SIZE:
1582 case GL_INTERNALFORMAT_DEPTH_TYPE:
1583 if (base_format == GL_DEPTH_STENCIL ||
1584 base_format == GL_DEPTH_COMPONENT) {
1588 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1589 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1590 case GL_INTERNALFORMAT_STENCIL_SIZE:
1591 case GL_INTERNALFORMAT_STENCIL_TYPE:
1592 if (base_format == GL_DEPTH_STENCIL ||
1593 base_format == GL_STENCIL_INDEX) {
1598 _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n",
1608 * Returns the number of channels/components for a base format.
1611 _mesa_base_format_component_count(GLenum base_format)
1613 switch (base_format) {
1618 case GL_DEPTH_COMPONENT:
1621 case GL_LUMINANCE_ALPHA:
1622 case GL_DEPTH_STENCIL:
1635 * If format is a generic compressed format, return the corresponding
1636 * non-compressed format. For other formats, return the format as-is.
1639 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format)
1642 case GL_COMPRESSED_RED:
1644 case GL_COMPRESSED_RG:
1646 case GL_COMPRESSED_RGB:
1648 case GL_COMPRESSED_RGBA:
1650 case GL_COMPRESSED_ALPHA:
1652 case GL_COMPRESSED_LUMINANCE:
1653 return GL_LUMINANCE;
1654 case GL_COMPRESSED_LUMINANCE_ALPHA:
1655 return GL_LUMINANCE_ALPHA;
1656 case GL_COMPRESSED_INTENSITY:
1657 return GL_INTENSITY;
1659 case GL_COMPRESSED_SRGB:
1661 case GL_COMPRESSED_SRGB_ALPHA:
1662 return GL_SRGB_ALPHA;
1663 case GL_COMPRESSED_SLUMINANCE:
1664 return GL_SLUMINANCE;
1665 case GL_COMPRESSED_SLUMINANCE_ALPHA:
1666 return GL_SLUMINANCE_ALPHA;
1674 * Return the equivalent non-generic internal format.
1675 * This is useful for comparing whether two internal formats are equivalent.
1678 _mesa_get_nongeneric_internalformat(GLenum format)
1681 /* GL 1.1 formats. */
1689 case GL_LUMINANCE_ALPHA:
1690 return GL_LUMINANCE8_ALPHA8;
1693 return GL_LUMINANCE8;
1697 return GL_INTENSITY8;
1699 /* GL_ARB_texture_rg */
1705 /* GL_EXT_texture_sRGB */
1709 return GL_SRGB8_ALPHA8;
1711 return GL_SLUMINANCE8;
1712 case GL_SLUMINANCE_ALPHA:
1713 return GL_SLUMINANCE8_ALPHA8;
1715 /* GL_EXT_texture_snorm */
1717 return GL_RGBA8_SNORM;
1719 return GL_RGB8_SNORM;
1721 return GL_RG8_SNORM;
1724 case GL_LUMINANCE_ALPHA_SNORM:
1725 return GL_LUMINANCE8_ALPHA8_SNORM;
1726 case GL_LUMINANCE_SNORM:
1727 return GL_LUMINANCE8_SNORM;
1728 case GL_ALPHA_SNORM:
1729 return GL_ALPHA8_SNORM;
1730 case GL_INTENSITY_SNORM:
1731 return GL_INTENSITY8_SNORM;
1740 * Convert an sRGB internal format to linear.
1743 _mesa_get_linear_internalformat(GLenum format)
1752 case GL_SRGB8_ALPHA8:
1754 case GL_SLUMINANCE8:
1755 return GL_LUMINANCE8;
1757 return GL_LUMINANCE;
1758 case GL_SLUMINANCE_ALPHA:
1759 return GL_LUMINANCE_ALPHA;
1760 case GL_SLUMINANCE8_ALPHA8:
1761 return GL_LUMINANCE8_ALPHA8;
1769 * Do error checking of format/type combinations for glReadPixels,
1770 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1771 * and type values, we may either generate GL_INVALID_OPERATION or
1774 * \param format pixel format.
1775 * \param type pixel type.
1777 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1780 _mesa_error_check_format_and_type(const struct gl_context *ctx,
1781 GLenum format, GLenum type)
1783 /* From OpenGL 3.3 spec, page 220:
1784 * "If the format is DEPTH_STENCIL, then values are taken from
1785 * both the depth buffer and the stencil buffer. If there is no
1786 * depth buffer or if there is no stencil buffer, then the error
1787 * INVALID_OPERATION occurs. If the type parameter is not
1788 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1789 * error INVALID_ENUM occurs."
1791 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1792 * cannot be used to read depth or stencil in that API.
1794 if (_mesa_is_desktop_gl(ctx) && format == GL_DEPTH_STENCIL
1795 && type != GL_UNSIGNED_INT_24_8
1796 && type != GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
1797 return GL_INVALID_ENUM;
1799 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1802 if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) {
1803 return GL_INVALID_ENUM;
1807 case GL_UNSIGNED_BYTE_3_3_2:
1808 case GL_UNSIGNED_BYTE_2_3_3_REV:
1809 case GL_UNSIGNED_SHORT_5_6_5:
1810 case GL_UNSIGNED_SHORT_5_6_5_REV:
1811 if (format == GL_RGB) {
1814 if (format == GL_RGB_INTEGER_EXT &&
1815 ctx->Extensions.ARB_texture_rgb10_a2ui) {
1818 return GL_INVALID_OPERATION;
1820 case GL_UNSIGNED_SHORT_4_4_4_4:
1821 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1822 case GL_UNSIGNED_INT_8_8_8_8:
1823 case GL_UNSIGNED_INT_8_8_8_8_REV:
1824 if (format == GL_RGBA ||
1825 format == GL_BGRA ||
1826 format == GL_ABGR_EXT) {
1829 if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
1830 ctx->Extensions.ARB_texture_rgb10_a2ui) {
1833 return GL_INVALID_OPERATION;
1835 case GL_UNSIGNED_SHORT_5_5_5_1:
1836 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1837 case GL_UNSIGNED_INT_10_10_10_2:
1838 case GL_UNSIGNED_INT_2_10_10_10_REV:
1839 if (format == GL_RGBA ||
1840 format == GL_BGRA) {
1843 if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
1844 ctx->Extensions.ARB_texture_rgb10_a2ui) {
1847 if (type == GL_UNSIGNED_INT_2_10_10_10_REV && format == GL_RGB &&
1848 ctx->API == API_OPENGLES2) {
1849 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1851 return GL_INVALID_OPERATION;
1853 case GL_UNSIGNED_INT_24_8:
1854 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1855 if (ctx->API == API_OPENGLES2 && format == GL_DEPTH_COMPONENT)
1858 if (format != GL_DEPTH_STENCIL) {
1859 return GL_INVALID_OPERATION;
1863 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1864 if (!ctx->Extensions.ARB_depth_buffer_float) {
1865 return GL_INVALID_ENUM;
1867 if (format != GL_DEPTH_STENCIL) {
1868 return GL_INVALID_OPERATION;
1872 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1873 if (!ctx->Extensions.EXT_packed_float) {
1874 return GL_INVALID_ENUM;
1876 if (format != GL_RGB) {
1877 return GL_INVALID_OPERATION;
1881 case GL_HALF_FLOAT_OES:
1885 case GL_LUMINANCE_ALPHA:
1891 if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_texture_rg)
1894 return GL_INVALID_OPERATION;
1898 ; /* fall-through */
1901 /* now, for each format, check the type for compatibility */
1903 case GL_COLOR_INDEX:
1904 case GL_STENCIL_INDEX:
1908 case GL_UNSIGNED_BYTE:
1910 case GL_UNSIGNED_SHORT:
1912 case GL_UNSIGNED_INT:
1917 return GL_INVALID_ENUM;
1924 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1928 case GL_LUMINANCE_ALPHA:
1929 case GL_DEPTH_COMPONENT:
1932 case GL_UNSIGNED_BYTE:
1934 case GL_UNSIGNED_SHORT:
1936 case GL_UNSIGNED_INT:
1941 return GL_INVALID_ENUM;
1945 if (!ctx->Extensions.ARB_texture_rg)
1946 return GL_INVALID_ENUM;
1949 case GL_UNSIGNED_BYTE:
1951 case GL_UNSIGNED_SHORT:
1953 case GL_UNSIGNED_INT:
1958 return GL_INVALID_ENUM;
1964 case GL_UNSIGNED_BYTE:
1966 case GL_UNSIGNED_SHORT:
1968 case GL_UNSIGNED_INT:
1970 case GL_UNSIGNED_BYTE_3_3_2:
1971 case GL_UNSIGNED_BYTE_2_3_3_REV:
1972 case GL_UNSIGNED_SHORT_5_6_5:
1973 case GL_UNSIGNED_SHORT_5_6_5_REV:
1976 case GL_UNSIGNED_INT_2_10_10_10_REV:
1977 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1978 return (ctx->API == API_OPENGLES2)
1979 ? GL_NO_ERROR : GL_INVALID_ENUM;
1980 case GL_UNSIGNED_INT_5_9_9_9_REV:
1981 return ctx->Extensions.EXT_texture_shared_exponent
1982 ? GL_NO_ERROR : GL_INVALID_ENUM;
1983 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1984 return ctx->Extensions.EXT_packed_float
1985 ? GL_NO_ERROR : GL_INVALID_ENUM;
1987 return GL_INVALID_ENUM;
1992 /* NOTE: no packed types are supported with BGR. That's
1993 * intentional, according to the GL spec.
1996 case GL_UNSIGNED_BYTE:
1998 case GL_UNSIGNED_SHORT:
2000 case GL_UNSIGNED_INT:
2005 return GL_INVALID_ENUM;
2012 case GL_UNSIGNED_BYTE:
2014 case GL_UNSIGNED_SHORT:
2016 case GL_UNSIGNED_INT:
2018 case GL_UNSIGNED_SHORT_4_4_4_4:
2019 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2020 case GL_UNSIGNED_SHORT_5_5_5_1:
2021 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2022 case GL_UNSIGNED_INT_8_8_8_8:
2023 case GL_UNSIGNED_INT_8_8_8_8_REV:
2024 case GL_UNSIGNED_INT_10_10_10_2:
2025 case GL_UNSIGNED_INT_2_10_10_10_REV:
2029 return GL_INVALID_ENUM;
2035 case GL_UNSIGNED_BYTE:
2037 case GL_UNSIGNED_SHORT:
2039 case GL_UNSIGNED_INT:
2041 case GL_UNSIGNED_SHORT_4_4_4_4:
2042 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2043 case GL_UNSIGNED_INT_8_8_8_8:
2044 case GL_UNSIGNED_INT_8_8_8_8_REV:
2048 return GL_INVALID_ENUM;
2052 if (!ctx->Extensions.MESA_ycbcr_texture)
2053 return GL_INVALID_ENUM;
2054 if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
2055 type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
2058 return GL_INVALID_OPERATION;
2060 case GL_DEPTH_STENCIL:
2061 if (type == GL_UNSIGNED_INT_24_8)
2063 else if (ctx->Extensions.ARB_depth_buffer_float &&
2064 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
2067 return GL_INVALID_ENUM;
2069 /* integer-valued formats */
2070 case GL_RED_INTEGER_EXT:
2071 case GL_GREEN_INTEGER_EXT:
2072 case GL_BLUE_INTEGER_EXT:
2073 case GL_ALPHA_INTEGER_EXT:
2077 case GL_UNSIGNED_BYTE:
2079 case GL_UNSIGNED_SHORT:
2081 case GL_UNSIGNED_INT:
2082 return (ctx->Version >= 30 ||
2083 ctx->Extensions.EXT_texture_integer)
2084 ? GL_NO_ERROR : GL_INVALID_ENUM;
2086 return GL_INVALID_ENUM;
2089 case GL_RGB_INTEGER_EXT:
2092 case GL_UNSIGNED_BYTE:
2094 case GL_UNSIGNED_SHORT:
2096 case GL_UNSIGNED_INT:
2097 return (ctx->Version >= 30 ||
2098 ctx->Extensions.EXT_texture_integer)
2099 ? GL_NO_ERROR : GL_INVALID_ENUM;
2100 case GL_UNSIGNED_BYTE_3_3_2:
2101 case GL_UNSIGNED_BYTE_2_3_3_REV:
2102 case GL_UNSIGNED_SHORT_5_6_5:
2103 case GL_UNSIGNED_SHORT_5_6_5_REV:
2104 return ctx->Extensions.ARB_texture_rgb10_a2ui
2105 ? GL_NO_ERROR : GL_INVALID_ENUM;
2107 return GL_INVALID_ENUM;
2110 case GL_BGR_INTEGER_EXT:
2113 case GL_UNSIGNED_BYTE:
2115 case GL_UNSIGNED_SHORT:
2117 case GL_UNSIGNED_INT:
2118 /* NOTE: no packed formats w/ BGR format */
2119 return (ctx->Version >= 30 ||
2120 ctx->Extensions.EXT_texture_integer)
2121 ? GL_NO_ERROR : GL_INVALID_ENUM;
2123 return GL_INVALID_ENUM;
2126 case GL_RGBA_INTEGER_EXT:
2127 case GL_BGRA_INTEGER_EXT:
2130 case GL_UNSIGNED_BYTE:
2132 case GL_UNSIGNED_SHORT:
2134 case GL_UNSIGNED_INT:
2135 return (ctx->Version >= 30 ||
2136 ctx->Extensions.EXT_texture_integer)
2137 ? GL_NO_ERROR : GL_INVALID_ENUM;
2138 case GL_UNSIGNED_SHORT_4_4_4_4:
2139 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2140 case GL_UNSIGNED_SHORT_5_5_5_1:
2141 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2142 case GL_UNSIGNED_INT_8_8_8_8:
2143 case GL_UNSIGNED_INT_8_8_8_8_REV:
2144 case GL_UNSIGNED_INT_10_10_10_2:
2145 case GL_UNSIGNED_INT_2_10_10_10_REV:
2146 return ctx->Extensions.ARB_texture_rgb10_a2ui
2147 ? GL_NO_ERROR : GL_INVALID_ENUM;
2149 return GL_INVALID_ENUM;
2152 case GL_LUMINANCE_INTEGER_EXT:
2153 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
2156 case GL_UNSIGNED_BYTE:
2158 case GL_UNSIGNED_SHORT:
2160 case GL_UNSIGNED_INT:
2161 return ctx->Extensions.EXT_texture_integer
2162 ? GL_NO_ERROR : GL_INVALID_ENUM;
2164 return GL_INVALID_ENUM;
2168 return GL_INVALID_ENUM;
2175 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2176 * and glTex[Sub]Image.
2177 * \return error code, or GL_NO_ERROR.
2180 _mesa_es_error_check_format_and_type(const struct gl_context *ctx,
2181 GLenum format, GLenum type,
2182 unsigned dimensions)
2184 GLboolean type_valid = GL_TRUE;
2189 if (ctx->API == API_OPENGLES || !ctx->Extensions.ARB_texture_rg)
2190 return GL_INVALID_VALUE;
2194 case GL_LUMINANCE_ALPHA:
2195 type_valid = (type == GL_UNSIGNED_BYTE
2197 || type == GL_HALF_FLOAT_OES);
2201 type_valid = (type == GL_UNSIGNED_BYTE
2202 || type == GL_UNSIGNED_SHORT_5_6_5
2204 || type == GL_HALF_FLOAT_OES);
2208 type_valid = (type == GL_UNSIGNED_BYTE
2209 || type == GL_UNSIGNED_SHORT_4_4_4_4
2210 || type == GL_UNSIGNED_SHORT_5_5_5_1
2212 || type == GL_HALF_FLOAT_OES
2213 || type == GL_UNSIGNED_INT_2_10_10_10_REV);
2216 case GL_DEPTH_COMPONENT:
2217 /* This format is filtered against invalid dimensionalities elsewhere.
2219 type_valid = (type == GL_UNSIGNED_SHORT
2220 || type == GL_UNSIGNED_INT);
2223 case GL_DEPTH_STENCIL:
2224 /* This format is filtered against invalid dimensionalities elsewhere.
2226 type_valid = (type == GL_UNSIGNED_INT_24_8);
2230 type_valid = (type == GL_UNSIGNED_BYTE);
2232 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2233 * the format does not appear to be allowed for 3D textures in OpenGL
2236 if (dimensions != 2)
2237 return GL_INVALID_VALUE;
2242 return GL_INVALID_VALUE;
2245 return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
2249 * Return the simple base format for a given internal texture format.
2250 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2252 * \param ctx GL context.
2253 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2255 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2256 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2258 * This is the format which is used during texture application (i.e. the
2259 * texture format and env mode determine the arithmetic used.
2262 _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
2264 switch (internalFormat) {
2270 return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2275 case GL_LUMINANCE12:
2276 case GL_LUMINANCE16:
2277 return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2279 case GL_LUMINANCE_ALPHA:
2280 case GL_LUMINANCE4_ALPHA4:
2281 case GL_LUMINANCE6_ALPHA2:
2282 case GL_LUMINANCE8_ALPHA8:
2283 case GL_LUMINANCE12_ALPHA4:
2284 case GL_LUMINANCE12_ALPHA12:
2285 case GL_LUMINANCE16_ALPHA16:
2286 return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2290 case GL_INTENSITY12:
2291 case GL_INTENSITY16:
2292 return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2294 return (ctx->API != API_OPENGL_CORE) ? GL_RGB : -1;
2305 return (ctx->API != API_OPENGL_CORE) ? GL_RGBA : -1;
2319 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2321 if (_mesa_is_gles(ctx)) {
2322 switch (internalFormat) {
2330 if (ctx->Extensions.ARB_ES2_compatibility) {
2331 switch (internalFormat) {
2339 if (ctx->Extensions.ARB_depth_texture) {
2340 switch (internalFormat) {
2341 case GL_DEPTH_COMPONENT:
2342 case GL_DEPTH_COMPONENT16:
2343 case GL_DEPTH_COMPONENT24:
2344 case GL_DEPTH_COMPONENT32:
2345 return GL_DEPTH_COMPONENT;
2346 case GL_DEPTH_STENCIL:
2347 case GL_DEPTH24_STENCIL8:
2348 return GL_DEPTH_STENCIL;
2354 if (ctx->Extensions.ARB_texture_stencil8) {
2355 switch (internalFormat) {
2356 case GL_STENCIL_INDEX:
2357 case GL_STENCIL_INDEX1:
2358 case GL_STENCIL_INDEX4:
2359 case GL_STENCIL_INDEX8:
2360 case GL_STENCIL_INDEX16:
2361 return GL_STENCIL_INDEX;
2367 switch (internalFormat) {
2368 case GL_COMPRESSED_ALPHA:
2370 case GL_COMPRESSED_LUMINANCE:
2371 return GL_LUMINANCE;
2372 case GL_COMPRESSED_LUMINANCE_ALPHA:
2373 return GL_LUMINANCE_ALPHA;
2374 case GL_COMPRESSED_INTENSITY:
2375 return GL_INTENSITY;
2376 case GL_COMPRESSED_RGB:
2378 case GL_COMPRESSED_RGBA:
2384 if (_mesa_is_compressed_format(ctx, internalFormat)) {
2385 GLenum base_compressed =
2386 _mesa_gl_compressed_format_base_format(internalFormat);
2387 if (base_compressed)
2388 return base_compressed;
2391 if ((ctx->Extensions.KHR_texture_compression_astc_ldr &&
2392 is_astc_2d_format(internalFormat)) ||
2393 (ctx->Extensions.OES_texture_compression_astc &&
2394 is_astc_3d_format(internalFormat)))
2397 if (ctx->Extensions.MESA_ycbcr_texture) {
2398 if (internalFormat == GL_YCBCR_MESA)
2399 return GL_YCBCR_MESA;
2402 if (ctx->Extensions.ARB_texture_float) {
2403 switch (internalFormat) {
2404 case GL_ALPHA16F_ARB:
2405 case GL_ALPHA32F_ARB:
2407 case GL_RGBA16F_ARB:
2408 case GL_RGBA32F_ARB:
2413 case GL_INTENSITY16F_ARB:
2414 case GL_INTENSITY32F_ARB:
2415 return GL_INTENSITY;
2416 case GL_LUMINANCE16F_ARB:
2417 case GL_LUMINANCE32F_ARB:
2418 return GL_LUMINANCE;
2419 case GL_LUMINANCE_ALPHA16F_ARB:
2420 case GL_LUMINANCE_ALPHA32F_ARB:
2421 return GL_LUMINANCE_ALPHA;
2427 if (ctx->Extensions.EXT_texture_snorm) {
2428 switch (internalFormat) {
2439 case GL_RGB16_SNORM:
2442 case GL_RGBA8_SNORM:
2443 case GL_RGBA16_SNORM:
2445 case GL_ALPHA_SNORM:
2446 case GL_ALPHA8_SNORM:
2447 case GL_ALPHA16_SNORM:
2449 case GL_LUMINANCE_SNORM:
2450 case GL_LUMINANCE8_SNORM:
2451 case GL_LUMINANCE16_SNORM:
2452 return GL_LUMINANCE;
2453 case GL_LUMINANCE_ALPHA_SNORM:
2454 case GL_LUMINANCE8_ALPHA8_SNORM:
2455 case GL_LUMINANCE16_ALPHA16_SNORM:
2456 return GL_LUMINANCE_ALPHA;
2457 case GL_INTENSITY_SNORM:
2458 case GL_INTENSITY8_SNORM:
2459 case GL_INTENSITY16_SNORM:
2460 return GL_INTENSITY;
2466 if (ctx->Extensions.EXT_texture_sRGB) {
2467 switch (internalFormat) {
2470 case GL_COMPRESSED_SRGB_EXT:
2472 case GL_SRGB_ALPHA_EXT:
2473 case GL_SRGB8_ALPHA8_EXT:
2474 case GL_COMPRESSED_SRGB_ALPHA_EXT:
2476 case GL_SLUMINANCE_ALPHA_EXT:
2477 case GL_SLUMINANCE8_ALPHA8_EXT:
2478 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
2479 return GL_LUMINANCE_ALPHA;
2480 case GL_SLUMINANCE_EXT:
2481 case GL_SLUMINANCE8_EXT:
2482 case GL_COMPRESSED_SLUMINANCE_EXT:
2483 return GL_LUMINANCE;
2489 if (ctx->Version >= 30 ||
2490 ctx->Extensions.EXT_texture_integer) {
2491 switch (internalFormat) {
2492 case GL_RGBA8UI_EXT:
2493 case GL_RGBA16UI_EXT:
2494 case GL_RGBA32UI_EXT:
2496 case GL_RGBA16I_EXT:
2497 case GL_RGBA32I_EXT:
2501 case GL_RGB16UI_EXT:
2502 case GL_RGB32UI_EXT:
2510 if (ctx->Extensions.EXT_texture_integer) {
2511 switch (internalFormat) {
2512 case GL_ALPHA8UI_EXT:
2513 case GL_ALPHA16UI_EXT:
2514 case GL_ALPHA32UI_EXT:
2515 case GL_ALPHA8I_EXT:
2516 case GL_ALPHA16I_EXT:
2517 case GL_ALPHA32I_EXT:
2519 case GL_INTENSITY8UI_EXT:
2520 case GL_INTENSITY16UI_EXT:
2521 case GL_INTENSITY32UI_EXT:
2522 case GL_INTENSITY8I_EXT:
2523 case GL_INTENSITY16I_EXT:
2524 case GL_INTENSITY32I_EXT:
2525 return GL_INTENSITY;
2526 case GL_LUMINANCE8UI_EXT:
2527 case GL_LUMINANCE16UI_EXT:
2528 case GL_LUMINANCE32UI_EXT:
2529 case GL_LUMINANCE8I_EXT:
2530 case GL_LUMINANCE16I_EXT:
2531 case GL_LUMINANCE32I_EXT:
2532 return GL_LUMINANCE;
2533 case GL_LUMINANCE_ALPHA8UI_EXT:
2534 case GL_LUMINANCE_ALPHA16UI_EXT:
2535 case GL_LUMINANCE_ALPHA32UI_EXT:
2536 case GL_LUMINANCE_ALPHA8I_EXT:
2537 case GL_LUMINANCE_ALPHA16I_EXT:
2538 case GL_LUMINANCE_ALPHA32I_EXT:
2539 return GL_LUMINANCE_ALPHA;
2545 if (ctx->Extensions.ARB_texture_rg) {
2546 switch (internalFormat) {
2549 if (!ctx->Extensions.ARB_texture_float)
2558 if (ctx->Version < 30 && !ctx->Extensions.EXT_texture_integer)
2564 case GL_COMPRESSED_RED:
2569 if (!ctx->Extensions.ARB_texture_float)
2578 if (ctx->Version < 30 && !ctx->Extensions.EXT_texture_integer)
2584 case GL_COMPRESSED_RG:
2591 if (ctx->Extensions.EXT_texture_shared_exponent) {
2592 switch (internalFormat) {
2593 case GL_RGB9_E5_EXT:
2600 if (ctx->Extensions.EXT_packed_float) {
2601 switch (internalFormat) {
2602 case GL_R11F_G11F_B10F_EXT:
2609 if (ctx->Extensions.ARB_depth_buffer_float) {
2610 switch (internalFormat) {
2611 case GL_DEPTH_COMPONENT32F:
2612 return GL_DEPTH_COMPONENT;
2613 case GL_DEPTH32F_STENCIL8:
2614 return GL_DEPTH_STENCIL;
2620 return -1; /* error */
2624 * Returns the effective internal format from a texture format and type.
2625 * This is used by texture image operations internally for validation, when
2626 * the specified internal format is a base (unsized) format.
2628 * This method will only return a valid effective internal format if the
2629 * combination of format, type and internal format in base form, is acceptable.
2631 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2632 * in extensions, to unambiguously correspond to the given base format, then
2633 * that internal format is returned as the effective. Otherwise, if the
2634 * combination is accepted but a single effective format is not defined, the
2635 * passed base format will be returned instead.
2637 * \param format the texture format
2638 * \param type the texture type
2641 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format,
2645 case GL_UNSIGNED_BYTE:
2655 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2656 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2657 * internal formats, they do not correspond to GL constants, so the base
2658 * format is returned instead.
2661 case GL_LUMINANCE_ALPHA:
2668 case GL_UNSIGNED_SHORT_4_4_4_4:
2669 if (format == GL_RGBA)
2673 case GL_UNSIGNED_SHORT_5_5_5_1:
2674 if (format == GL_RGBA)
2678 case GL_UNSIGNED_SHORT_5_6_5:
2679 if (format == GL_RGB)
2683 /* OES_packed_depth_stencil */
2684 case GL_UNSIGNED_INT_24_8:
2685 if (format == GL_DEPTH_STENCIL)
2686 return GL_DEPTH24_STENCIL8;
2689 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
2690 if (format == GL_DEPTH_STENCIL)
2691 return GL_DEPTH32F_STENCIL8;
2694 case GL_UNSIGNED_SHORT:
2695 if (format == GL_DEPTH_COMPONENT)
2696 return GL_DEPTH_COMPONENT16;
2699 case GL_UNSIGNED_INT:
2700 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2703 if (format == GL_DEPTH_COMPONENT)
2707 /* OES_texture_float and OES_texture_half_float */
2709 if (format == GL_DEPTH_COMPONENT)
2710 return GL_DEPTH_COMPONENT32F;
2712 case GL_HALF_FLOAT_OES:
2716 case GL_LUMINANCE_ALPHA:
2732 /* GL_EXT_texture_type_2_10_10_10_REV */
2733 case GL_UNSIGNED_INT_2_10_10_10_REV:
2742 /* fall through and return NONE */
2750 * Do error checking of format/type combinations for OpenGL ES 3
2752 * \return error code, or GL_NO_ERROR.
2755 _mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
2756 GLenum format, GLenum type,
2757 GLenum internalFormat)
2759 /* If internalFormat is an unsized format, then the effective internal
2760 * format derived from format and type should be used instead. Page 127,
2761 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2763 * "if internalformat is a base internal format, the effective
2764 * internal format is a sized internal format that is derived
2765 * from the format and type for internal use by the GL.
2766 * Table 3.12 specifies the mapping of format and type to effective
2767 * internal formats. The effective internal format is used by the GL
2768 * for purposes such as texture completeness or type checks for
2769 * CopyTex* commands. In these cases, the GL is required to operate
2770 * as if the effective internal format was used as the internalformat
2771 * when specifying the texture data."
2773 if (_mesa_is_enum_format_unsized(internalFormat)) {
2774 GLenum effectiveInternalFormat =
2775 _mesa_es3_effective_internal_format_for_format_and_type(format, type);
2777 if (effectiveInternalFormat == GL_NONE)
2778 return GL_INVALID_OPERATION;
2780 GLenum baseInternalFormat;
2781 if (internalFormat == GL_BGRA_EXT) {
2782 /* Unfortunately, _mesa_base_tex_format returns a base format of
2783 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2784 * asking the question, "what channels does this format have?"
2785 * However, if we're trying to determine if two internal formats
2786 * match in the ES3 sense, we actually want GL_BGRA.
2788 baseInternalFormat = GL_BGRA_EXT;
2790 baseInternalFormat =
2791 _mesa_base_tex_format(ctx, effectiveInternalFormat);
2794 if (internalFormat != baseInternalFormat)
2795 return GL_INVALID_OPERATION;
2797 internalFormat = effectiveInternalFormat;
2802 if (type != GL_UNSIGNED_BYTE || internalFormat != GL_BGRA)
2803 return GL_INVALID_OPERATION;
2808 case GL_UNSIGNED_BYTE:
2809 switch (internalFormat) {
2814 case GL_SRGB8_ALPHA8_EXT:
2817 return GL_INVALID_OPERATION;
2822 if (internalFormat != GL_RGBA8_SNORM)
2823 return GL_INVALID_OPERATION;
2826 case GL_UNSIGNED_SHORT_4_4_4_4:
2827 switch (internalFormat) {
2832 return GL_INVALID_OPERATION;
2836 case GL_UNSIGNED_SHORT_5_5_5_1:
2837 switch (internalFormat) {
2842 return GL_INVALID_OPERATION;
2846 case GL_UNSIGNED_INT_2_10_10_10_REV:
2847 switch (internalFormat) {
2848 case GL_RGBA: /* GL_EXT_texture_type_2_10_10_10_REV */
2853 return GL_INVALID_OPERATION;
2858 if (internalFormat != GL_RGBA16F)
2859 return GL_INVALID_OPERATION;
2863 switch (internalFormat) {
2868 if (ctx->Extensions.OES_texture_float && internalFormat == format)
2871 return GL_INVALID_OPERATION;
2875 case GL_HALF_FLOAT_OES:
2876 if (ctx->Extensions.OES_texture_half_float && internalFormat == format)
2879 return GL_INVALID_OPERATION;
2883 case GL_RGBA_INTEGER:
2885 case GL_UNSIGNED_BYTE:
2886 if (internalFormat != GL_RGBA8UI)
2887 return GL_INVALID_OPERATION;
2891 if (internalFormat != GL_RGBA8I)
2892 return GL_INVALID_OPERATION;
2895 case GL_UNSIGNED_SHORT:
2896 if (internalFormat != GL_RGBA16UI)
2897 return GL_INVALID_OPERATION;
2901 if (internalFormat != GL_RGBA16I)
2902 return GL_INVALID_OPERATION;
2905 case GL_UNSIGNED_INT:
2906 if (internalFormat != GL_RGBA32UI)
2907 return GL_INVALID_OPERATION;
2911 if (internalFormat != GL_RGBA32I)
2912 return GL_INVALID_OPERATION;
2915 case GL_UNSIGNED_INT_2_10_10_10_REV:
2916 if (internalFormat != GL_RGB10_A2UI)
2917 return GL_INVALID_OPERATION;
2921 return GL_INVALID_OPERATION;
2927 case GL_UNSIGNED_BYTE:
2928 switch (internalFormat) {
2935 return GL_INVALID_OPERATION;
2940 if (internalFormat != GL_RGB8_SNORM)
2941 return GL_INVALID_OPERATION;
2944 case GL_UNSIGNED_SHORT_5_6_5:
2945 switch (internalFormat) {
2950 return GL_INVALID_OPERATION;
2954 case GL_UNSIGNED_INT_10F_11F_11F_REV:
2955 if (internalFormat != GL_R11F_G11F_B10F)
2956 return GL_INVALID_OPERATION;
2959 case GL_UNSIGNED_INT_5_9_9_9_REV:
2960 if (internalFormat != GL_RGB9_E5)
2961 return GL_INVALID_OPERATION;
2965 switch (internalFormat) {
2967 case GL_R11F_G11F_B10F:
2971 return GL_INVALID_OPERATION;
2976 switch (internalFormat) {
2979 case GL_R11F_G11F_B10F:
2983 if (ctx->Extensions.OES_texture_float && internalFormat == format)
2986 return GL_INVALID_OPERATION;
2990 case GL_HALF_FLOAT_OES:
2991 if (!ctx->Extensions.OES_texture_half_float || internalFormat != format)
2992 return GL_INVALID_OPERATION;
2995 case GL_UNSIGNED_INT_2_10_10_10_REV:
2996 switch (internalFormat) {
2997 case GL_RGB: /* GL_EXT_texture_type_2_10_10_10_REV */
3000 return GL_INVALID_OPERATION;
3005 return GL_INVALID_OPERATION;
3009 case GL_RGB_INTEGER:
3011 case GL_UNSIGNED_BYTE:
3012 if (internalFormat != GL_RGB8UI)
3013 return GL_INVALID_OPERATION;
3017 if (internalFormat != GL_RGB8I)
3018 return GL_INVALID_OPERATION;
3021 case GL_UNSIGNED_SHORT:
3022 if (internalFormat != GL_RGB16UI)
3023 return GL_INVALID_OPERATION;
3027 if (internalFormat != GL_RGB16I)
3028 return GL_INVALID_OPERATION;
3031 case GL_UNSIGNED_INT:
3032 if (internalFormat != GL_RGB32UI)
3033 return GL_INVALID_OPERATION;
3037 if (internalFormat != GL_RGB32I)
3038 return GL_INVALID_OPERATION;
3042 return GL_INVALID_OPERATION;
3048 case GL_UNSIGNED_BYTE:
3049 if (internalFormat != GL_RG8)
3050 return GL_INVALID_OPERATION;
3054 if (internalFormat != GL_RG8_SNORM)
3055 return GL_INVALID_OPERATION;
3059 case GL_HALF_FLOAT_OES:
3060 switch (internalFormat) {
3064 if (ctx->Extensions.ARB_texture_rg &&
3065 ctx->Extensions.OES_texture_half_float)
3069 return GL_INVALID_OPERATION;
3074 switch (internalFormat) {
3079 if (ctx->Extensions.ARB_texture_rg &&
3080 ctx->Extensions.OES_texture_float)
3084 return GL_INVALID_OPERATION;
3089 return GL_INVALID_OPERATION;
3095 case GL_UNSIGNED_BYTE:
3096 if (internalFormat != GL_RG8UI)
3097 return GL_INVALID_OPERATION;
3101 if (internalFormat != GL_RG8I)
3102 return GL_INVALID_OPERATION;
3105 case GL_UNSIGNED_SHORT:
3106 if (internalFormat != GL_RG16UI)
3107 return GL_INVALID_OPERATION;
3111 if (internalFormat != GL_RG16I)
3112 return GL_INVALID_OPERATION;
3115 case GL_UNSIGNED_INT:
3116 if (internalFormat != GL_RG32UI)
3117 return GL_INVALID_OPERATION;
3121 if (internalFormat != GL_RG32I)
3122 return GL_INVALID_OPERATION;
3126 return GL_INVALID_OPERATION;
3132 case GL_UNSIGNED_BYTE:
3133 if (internalFormat != GL_R8)
3134 return GL_INVALID_OPERATION;
3138 if (internalFormat != GL_R8_SNORM)
3139 return GL_INVALID_OPERATION;
3143 case GL_HALF_FLOAT_OES:
3144 switch (internalFormat) {
3149 if (ctx->Extensions.ARB_texture_rg &&
3150 ctx->Extensions.OES_texture_half_float)
3154 return GL_INVALID_OPERATION;
3159 switch (internalFormat) {
3164 if (ctx->Extensions.ARB_texture_rg &&
3165 ctx->Extensions.OES_texture_float)
3169 return GL_INVALID_OPERATION;
3174 return GL_INVALID_OPERATION;
3178 case GL_RED_INTEGER:
3180 case GL_UNSIGNED_BYTE:
3181 if (internalFormat != GL_R8UI)
3182 return GL_INVALID_OPERATION;
3186 if (internalFormat != GL_R8I)
3187 return GL_INVALID_OPERATION;
3190 case GL_UNSIGNED_SHORT:
3191 if (internalFormat != GL_R16UI)
3192 return GL_INVALID_OPERATION;
3196 if (internalFormat != GL_R16I)
3197 return GL_INVALID_OPERATION;
3200 case GL_UNSIGNED_INT:
3201 if (internalFormat != GL_R32UI)
3202 return GL_INVALID_OPERATION;
3206 if (internalFormat != GL_R32I)
3207 return GL_INVALID_OPERATION;
3211 return GL_INVALID_OPERATION;
3215 case GL_DEPTH_COMPONENT:
3217 case GL_UNSIGNED_SHORT:
3218 if (internalFormat != GL_DEPTH_COMPONENT
3219 && internalFormat != GL_DEPTH_COMPONENT16)
3220 return GL_INVALID_OPERATION;
3223 case GL_UNSIGNED_INT:
3224 switch (internalFormat) {
3225 case GL_DEPTH_COMPONENT:
3226 case GL_DEPTH_COMPONENT16:
3227 case GL_DEPTH_COMPONENT24:
3230 return GL_INVALID_OPERATION;
3235 if (internalFormat != GL_DEPTH_COMPONENT32F)
3236 return GL_INVALID_OPERATION;
3240 return GL_INVALID_OPERATION;
3244 case GL_DEPTH_STENCIL:
3246 case GL_UNSIGNED_INT_24_8:
3247 if (internalFormat != GL_DEPTH_STENCIL
3248 && internalFormat != GL_DEPTH24_STENCIL8)
3249 return GL_INVALID_OPERATION;
3252 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
3253 if (internalFormat != GL_DEPTH32F_STENCIL8)
3254 return GL_INVALID_OPERATION;
3258 return GL_INVALID_OPERATION;
3262 case GL_STENCIL_INDEX:
3263 if (!_mesa_has_OES_texture_stencil8(ctx) ||
3264 type != GL_UNSIGNED_BYTE ||
3265 internalFormat != GL_STENCIL_INDEX8) {
3266 return GL_INVALID_OPERATION;
3272 case GL_LUMINANCE_ALPHA:
3275 if (ctx->Extensions.OES_texture_float && internalFormat == format)
3277 case GL_HALF_FLOAT_OES:
3278 if (ctx->Extensions.OES_texture_half_float && internalFormat == format)
3281 if (type != GL_UNSIGNED_BYTE || format != internalFormat)
3282 return GL_INVALID_OPERATION;
3290 set_swizzle(uint8_t *swizzle, int x, int y, int z, int w)
3292 swizzle[MESA_FORMAT_SWIZZLE_X] = x;
3293 swizzle[MESA_FORMAT_SWIZZLE_Y] = y;
3294 swizzle[MESA_FORMAT_SWIZZLE_Z] = z;
3295 swizzle[MESA_FORMAT_SWIZZLE_W] = w;
3299 get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
3303 case GL_RGBA_INTEGER_EXT:
3304 set_swizzle(swizzle, 0, 1, 2, 3);
3307 case GL_BGRA_INTEGER_EXT:
3308 set_swizzle(swizzle, 2, 1, 0, 3);
3311 set_swizzle(swizzle, 3, 2, 1, 0);
3314 case GL_RGB_INTEGER_EXT:
3315 set_swizzle(swizzle, 0, 1, 2, 5);
3318 case GL_BGR_INTEGER_EXT:
3319 set_swizzle(swizzle, 2, 1, 0, 5);
3321 case GL_LUMINANCE_ALPHA:
3322 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
3323 set_swizzle(swizzle, 0, 0, 0, 1);
3327 set_swizzle(swizzle, 0, 1, 4, 5);
3330 case GL_RED_INTEGER_EXT:
3331 set_swizzle(swizzle, 0, 4, 4, 5);
3334 case GL_GREEN_INTEGER_EXT:
3335 set_swizzle(swizzle, 4, 0, 4, 5);
3338 case GL_BLUE_INTEGER_EXT:
3339 set_swizzle(swizzle, 4, 4, 0, 5);
3342 case GL_ALPHA_INTEGER_EXT:
3343 set_swizzle(swizzle, 4, 4, 4, 0);
3346 case GL_LUMINANCE_INTEGER_EXT:
3347 set_swizzle(swizzle, 0, 0, 0, 5);
3350 set_swizzle(swizzle, 0, 0, 0, 0);
3358 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3359 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3360 * otherwise (for non-array formats).
3362 * This function will typically be used to compute a mesa format from a GL type
3363 * so we can then call _mesa_format_convert. This function does
3364 * not consider byte swapping, so it returns types assuming that no byte
3365 * swapping is involved. If byte swapping is involved then clients are supposed
3366 * to handle that on their side before calling _mesa_format_convert.
3368 * This function returns an uint32_t that can pack a mesa_format or a
3369 * mesa_array_format. Clients must check the mesa array format bit
3370 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3371 * format is a mesa_array_format or a mesa_format.
3374 _mesa_format_from_format_and_type(GLenum format, GLenum type)
3376 bool is_array_format = true;
3378 bool normalized = false, is_float = false, is_signed = false;
3379 int num_channels = 0, type_size = 0;
3381 /* Extract array format type information from the OpenGL data type */
3383 case GL_UNSIGNED_BYTE:
3390 case GL_UNSIGNED_SHORT:
3397 case GL_UNSIGNED_INT:
3405 case GL_HALF_FLOAT_OES:
3416 is_array_format = false;
3420 /* Extract array format swizzle information from the OpenGL format */
3421 if (is_array_format)
3422 is_array_format = get_swizzle_from_gl_format(format, swizzle);
3424 /* If this is an array format type after checking data type and format,
3425 * create the array format
3427 if (is_array_format) {
3428 normalized = !_mesa_is_enum_format_integer(format);
3429 num_channels = _mesa_components_in_format(format);
3431 return MESA_ARRAY_FORMAT(type_size, is_signed, is_float,
3432 normalized, num_channels,
3433 swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
3436 /* Otherwise this is not an array format, so return the mesa_format
3437 * matching the OpenGL format and data type
3440 case GL_UNSIGNED_SHORT_5_6_5:
3441 if (format == GL_RGB)
3442 return MESA_FORMAT_B5G6R5_UNORM;
3443 else if (format == GL_BGR)
3444 return MESA_FORMAT_R5G6B5_UNORM;
3445 else if (format == GL_RGB_INTEGER)
3446 return MESA_FORMAT_B5G6R5_UINT;
3448 case GL_UNSIGNED_SHORT_5_6_5_REV:
3449 if (format == GL_RGB)
3450 return MESA_FORMAT_R5G6B5_UNORM;
3451 else if (format == GL_BGR)
3452 return MESA_FORMAT_B5G6R5_UNORM;
3453 else if (format == GL_RGB_INTEGER)
3454 return MESA_FORMAT_R5G6B5_UINT;
3456 case GL_UNSIGNED_SHORT_4_4_4_4:
3457 if (format == GL_RGBA)
3458 return MESA_FORMAT_A4B4G4R4_UNORM;
3459 else if (format == GL_BGRA)
3460 return MESA_FORMAT_A4R4G4B4_UNORM;
3461 else if (format == GL_ABGR_EXT)
3462 return MESA_FORMAT_R4G4B4A4_UNORM;
3463 else if (format == GL_RGBA_INTEGER)
3464 return MESA_FORMAT_A4B4G4R4_UINT;
3465 else if (format == GL_BGRA_INTEGER)
3466 return MESA_FORMAT_A4R4G4B4_UINT;
3468 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
3469 if (format == GL_RGBA)
3470 return MESA_FORMAT_R4G4B4A4_UNORM;
3471 else if (format == GL_BGRA)
3472 return MESA_FORMAT_B4G4R4A4_UNORM;
3473 else if (format == GL_ABGR_EXT)
3474 return MESA_FORMAT_A4B4G4R4_UNORM;
3475 else if (format == GL_RGBA_INTEGER)
3476 return MESA_FORMAT_R4G4B4A4_UINT;
3477 else if (format == GL_BGRA_INTEGER)
3478 return MESA_FORMAT_B4G4R4A4_UINT;
3480 case GL_UNSIGNED_SHORT_5_5_5_1:
3481 if (format == GL_RGBA)
3482 return MESA_FORMAT_A1B5G5R5_UNORM;
3483 else if (format == GL_BGRA)
3484 return MESA_FORMAT_A1R5G5B5_UNORM;
3485 else if (format == GL_RGBA_INTEGER)
3486 return MESA_FORMAT_A1B5G5R5_UINT;
3487 else if (format == GL_BGRA_INTEGER)
3488 return MESA_FORMAT_A1R5G5B5_UINT;
3490 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
3491 if (format == GL_RGBA)
3492 return MESA_FORMAT_R5G5B5A1_UNORM;
3493 else if (format == GL_BGRA)
3494 return MESA_FORMAT_B5G5R5A1_UNORM;
3495 else if (format == GL_RGBA_INTEGER)
3496 return MESA_FORMAT_R5G5B5A1_UINT;
3497 else if (format == GL_BGRA_INTEGER)
3498 return MESA_FORMAT_B5G5R5A1_UINT;
3500 case GL_UNSIGNED_BYTE_3_3_2:
3501 if (format == GL_RGB)
3502 return MESA_FORMAT_B2G3R3_UNORM;
3503 else if (format == GL_RGB_INTEGER)
3504 return MESA_FORMAT_B2G3R3_UINT;
3506 case GL_UNSIGNED_BYTE_2_3_3_REV:
3507 if (format == GL_RGB)
3508 return MESA_FORMAT_R3G3B2_UNORM;
3509 else if (format == GL_RGB_INTEGER)
3510 return MESA_FORMAT_R3G3B2_UINT;
3512 case GL_UNSIGNED_INT_5_9_9_9_REV:
3513 if (format == GL_RGB)
3514 return MESA_FORMAT_R9G9B9E5_FLOAT;
3516 case GL_UNSIGNED_INT_10_10_10_2:
3517 if (format == GL_RGBA)
3518 return MESA_FORMAT_A2B10G10R10_UNORM;
3519 else if (format == GL_RGBA_INTEGER)
3520 return MESA_FORMAT_A2B10G10R10_UINT;
3521 else if (format == GL_BGRA)
3522 return MESA_FORMAT_A2R10G10B10_UNORM;
3523 else if (format == GL_BGRA_INTEGER)
3524 return MESA_FORMAT_A2R10G10B10_UINT;
3526 case GL_UNSIGNED_INT_2_10_10_10_REV:
3527 if (format == GL_RGB)
3528 return MESA_FORMAT_R10G10B10X2_UNORM;
3529 if (format == GL_RGBA)
3530 return MESA_FORMAT_R10G10B10A2_UNORM;
3531 else if (format == GL_RGBA_INTEGER)
3532 return MESA_FORMAT_R10G10B10A2_UINT;
3533 else if (format == GL_BGRA)
3534 return MESA_FORMAT_B10G10R10A2_UNORM;
3535 else if (format == GL_BGRA_INTEGER)
3536 return MESA_FORMAT_B10G10R10A2_UINT;
3538 case GL_UNSIGNED_INT_8_8_8_8:
3539 if (format == GL_RGBA)
3540 return MESA_FORMAT_A8B8G8R8_UNORM;
3541 else if (format == GL_BGRA)
3542 return MESA_FORMAT_A8R8G8B8_UNORM;
3543 else if (format == GL_ABGR_EXT)
3544 return MESA_FORMAT_R8G8B8A8_UNORM;
3545 else if (format == GL_RGBA_INTEGER)
3546 return MESA_FORMAT_A8B8G8R8_UINT;
3547 else if (format == GL_BGRA_INTEGER)
3548 return MESA_FORMAT_A8R8G8B8_UINT;
3550 case GL_UNSIGNED_INT_8_8_8_8_REV:
3551 if (format == GL_RGBA)
3552 return MESA_FORMAT_R8G8B8A8_UNORM;
3553 else if (format == GL_BGRA)
3554 return MESA_FORMAT_B8G8R8A8_UNORM;
3555 else if (format == GL_ABGR_EXT)
3556 return MESA_FORMAT_A8B8G8R8_UNORM;
3557 else if (format == GL_RGBA_INTEGER)
3558 return MESA_FORMAT_R8G8B8A8_UINT;
3559 else if (format == GL_BGRA_INTEGER)
3560 return MESA_FORMAT_B8G8R8A8_UINT;
3562 case GL_UNSIGNED_SHORT_8_8_MESA:
3563 if (format == GL_YCBCR_MESA)
3564 return MESA_FORMAT_YCBCR;
3566 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
3567 if (format == GL_YCBCR_MESA)
3568 return MESA_FORMAT_YCBCR_REV;
3570 case GL_UNSIGNED_INT_10F_11F_11F_REV:
3571 if (format == GL_RGB)
3572 return MESA_FORMAT_R11G11B10_FLOAT;
3575 if (format == GL_DEPTH_COMPONENT)
3576 return MESA_FORMAT_Z_FLOAT32;
3578 case GL_UNSIGNED_INT:
3579 if (format == GL_DEPTH_COMPONENT)
3580 return MESA_FORMAT_Z_UNORM32;
3582 case GL_UNSIGNED_SHORT:
3583 if (format == GL_DEPTH_COMPONENT)
3584 return MESA_FORMAT_Z_UNORM16;
3586 case GL_UNSIGNED_INT_24_8:
3587 if (format == GL_DEPTH_STENCIL)
3588 return MESA_FORMAT_Z24_UNORM_S8_UINT;
3590 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
3591 if (format == GL_DEPTH_STENCIL)
3592 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT;
3598 /* If we got here it means that we could not find a Mesa format that
3599 * matches the GL format/type provided. We may need to add a new Mesa
3600 * format in that case.
3602 unreachable("Unsupported format");
3606 * Returns true if \p internal_format is a sized internal format that
3607 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3610 _mesa_is_es3_color_renderable(GLenum internal_format)
3612 switch (internal_format) {
3622 case GL_SRGB8_ALPHA8:
3629 case GL_R11F_G11F_B10F:
3655 * Returns true if \p internal_format is a sized internal format that
3656 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3659 _mesa_is_es3_texture_filterable(GLenum internal_format)
3661 switch (internal_format) {
3672 case GL_RGBA8_SNORM:
3675 case GL_SRGB8_ALPHA8:
3680 case GL_R11F_G11F_B10F: