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"
54 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
55 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
56 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
57 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
73 MAP4(ZERO
, ZERO
, ZERO
, 0),
103 MAP4(0, ZERO
, ZERO
, ONE
),
109 MAP4(ZERO
, 0, ZERO
, ONE
),
115 MAP4(ZERO
, ZERO
, 0, ONE
),
139 MAP4(0, 1, ZERO
, ONE
),
145 * Convert a GL image format enum to an IDX_* value (see above).
148 get_map_idx(GLenum value
)
152 case GL_LUMINANCE_INTEGER_EXT
:
153 return IDX_LUMINANCE
;
155 case GL_ALPHA_INTEGER
:
158 return IDX_INTENSITY
;
159 case GL_LUMINANCE_ALPHA
:
160 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
161 return IDX_LUMINANCE_ALPHA
;
166 case GL_RGBA_INTEGER
:
179 case GL_BGRA_INTEGER
:
187 _mesa_problem(NULL
, "Unexpected inFormat %s",
188 _mesa_lookup_enum_by_nr(value
));
194 * When promoting texture formats (see below) we need to compute the
195 * mapping of dest components back to source components.
196 * This function does that.
197 * \param inFormat the incoming format of the texture
198 * \param outFormat the final texture format
199 * \return map[6] a full 6-component map
202 _mesa_compute_component_mapping(GLenum inFormat
, GLenum outFormat
, GLubyte
*map
)
204 const int inFmt
= get_map_idx(inFormat
);
205 const int outFmt
= get_map_idx(outFormat
);
206 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
207 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
210 for (i
= 0; i
< 4; i
++)
211 map
[i
] = in2rgba
[rgba2out
[i
]];
217 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
218 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
219 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
230 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
233 _mesa_type_is_packed(GLenum type
)
236 case GL_UNSIGNED_BYTE_3_3_2
:
237 case GL_UNSIGNED_BYTE_2_3_3_REV
:
238 case MESA_UNSIGNED_BYTE_4_4
:
239 case GL_UNSIGNED_SHORT_5_6_5
:
240 case GL_UNSIGNED_SHORT_5_6_5_REV
:
241 case GL_UNSIGNED_SHORT_4_4_4_4
:
242 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
243 case GL_UNSIGNED_SHORT_5_5_5_1
:
244 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
245 case GL_UNSIGNED_INT_8_8_8_8
:
246 case GL_UNSIGNED_INT_8_8_8_8_REV
:
247 case GL_UNSIGNED_INT_10_10_10_2
:
248 case GL_UNSIGNED_INT_2_10_10_10_REV
:
249 case GL_UNSIGNED_SHORT_8_8_MESA
:
250 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
251 case GL_UNSIGNED_INT_24_8_EXT
:
252 case GL_UNSIGNED_INT_5_9_9_9_REV
:
253 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
254 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
263 * Get the size of a GL data type.
265 * \param type GL data type.
267 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
268 * if an invalid type enum.
271 _mesa_sizeof_type(GLenum type
)
276 case GL_UNSIGNED_BYTE
:
277 return sizeof(GLubyte
);
279 return sizeof(GLbyte
);
280 case GL_UNSIGNED_SHORT
:
281 return sizeof(GLushort
);
283 return sizeof(GLshort
);
284 case GL_UNSIGNED_INT
:
285 return sizeof(GLuint
);
287 return sizeof(GLint
);
289 return sizeof(GLfloat
);
291 return sizeof(GLdouble
);
292 case GL_HALF_FLOAT_ARB
:
293 return sizeof(GLhalfARB
);
295 return sizeof(GLfixed
);
303 * Same as _mesa_sizeof_type() but also accepting the packed pixel
307 _mesa_sizeof_packed_type(GLenum type
)
312 case GL_UNSIGNED_BYTE
:
313 return sizeof(GLubyte
);
315 return sizeof(GLbyte
);
316 case GL_UNSIGNED_SHORT
:
317 return sizeof(GLushort
);
319 return sizeof(GLshort
);
320 case GL_UNSIGNED_INT
:
321 return sizeof(GLuint
);
323 return sizeof(GLint
);
324 case GL_HALF_FLOAT_ARB
:
325 return sizeof(GLhalfARB
);
327 return sizeof(GLfloat
);
328 case GL_UNSIGNED_BYTE_3_3_2
:
329 case GL_UNSIGNED_BYTE_2_3_3_REV
:
330 case MESA_UNSIGNED_BYTE_4_4
:
331 return sizeof(GLubyte
);
332 case GL_UNSIGNED_SHORT_5_6_5
:
333 case GL_UNSIGNED_SHORT_5_6_5_REV
:
334 case GL_UNSIGNED_SHORT_4_4_4_4
:
335 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
336 case GL_UNSIGNED_SHORT_5_5_5_1
:
337 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
338 case GL_UNSIGNED_SHORT_8_8_MESA
:
339 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
340 return sizeof(GLushort
);
341 case GL_UNSIGNED_INT_8_8_8_8
:
342 case GL_UNSIGNED_INT_8_8_8_8_REV
:
343 case GL_UNSIGNED_INT_10_10_10_2
:
344 case GL_UNSIGNED_INT_2_10_10_10_REV
:
345 case GL_UNSIGNED_INT_24_8_EXT
:
346 case GL_UNSIGNED_INT_5_9_9_9_REV
:
347 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
348 return sizeof(GLuint
);
349 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
358 * Get the number of components in a pixel format.
360 * \param format pixel format.
362 * \return the number of components in the given format, or -1 if a bad format.
365 _mesa_components_in_format(GLenum format
)
369 case GL_STENCIL_INDEX
:
370 case GL_DEPTH_COMPONENT
:
372 case GL_RED_INTEGER_EXT
:
374 case GL_GREEN_INTEGER_EXT
:
376 case GL_BLUE_INTEGER_EXT
:
378 case GL_ALPHA_INTEGER_EXT
:
380 case GL_LUMINANCE_INTEGER_EXT
:
384 case GL_LUMINANCE_ALPHA
:
385 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
388 case GL_DEPTH_STENCIL_EXT
:
394 case GL_RGB_INTEGER_EXT
:
395 case GL_BGR_INTEGER_EXT
:
401 case GL_RGBA_INTEGER_EXT
:
402 case GL_BGRA_INTEGER_EXT
:
412 * Get the bytes per pixel of pixel format type pair.
414 * \param format pixel format.
415 * \param type pixel type.
417 * \return bytes per pixel, or -1 if a bad format or type was given.
420 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
422 GLint comps
= _mesa_components_in_format(format
);
428 return 0; /* special case */
430 case GL_UNSIGNED_BYTE
:
431 return comps
* sizeof(GLubyte
);
433 case GL_UNSIGNED_SHORT
:
434 return comps
* sizeof(GLshort
);
436 case GL_UNSIGNED_INT
:
437 return comps
* sizeof(GLint
);
439 return comps
* sizeof(GLfloat
);
440 case GL_HALF_FLOAT_ARB
:
441 return comps
* sizeof(GLhalfARB
);
442 case GL_UNSIGNED_BYTE_3_3_2
:
443 case GL_UNSIGNED_BYTE_2_3_3_REV
:
444 if (format
== GL_RGB
|| format
== GL_BGR
||
445 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
446 return sizeof(GLubyte
);
448 return -1; /* error */
449 case GL_UNSIGNED_SHORT_5_6_5
:
450 case GL_UNSIGNED_SHORT_5_6_5_REV
:
451 if (format
== GL_RGB
|| format
== GL_BGR
||
452 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
453 return sizeof(GLushort
);
455 return -1; /* error */
456 case GL_UNSIGNED_SHORT_4_4_4_4
:
457 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
458 case GL_UNSIGNED_SHORT_5_5_5_1
:
459 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
460 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
461 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
462 return sizeof(GLushort
);
465 case GL_UNSIGNED_INT_8_8_8_8
:
466 case GL_UNSIGNED_INT_8_8_8_8_REV
:
467 case GL_UNSIGNED_INT_10_10_10_2
:
468 case GL_UNSIGNED_INT_2_10_10_10_REV
:
469 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
470 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
472 return sizeof(GLuint
);
475 case GL_UNSIGNED_SHORT_8_8_MESA
:
476 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
477 if (format
== GL_YCBCR_MESA
)
478 return sizeof(GLushort
);
481 case GL_UNSIGNED_INT_24_8_EXT
:
482 if (format
== GL_DEPTH_STENCIL_EXT
)
483 return sizeof(GLuint
);
486 case GL_UNSIGNED_INT_5_9_9_9_REV
:
487 if (format
== GL_RGB
)
488 return sizeof(GLuint
);
491 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
492 if (format
== GL_RGB
)
493 return sizeof(GLuint
);
496 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
497 if (format
== GL_DEPTH_STENCIL
)
508 * Get the number of bytes for a vertex attrib with the given number of
509 * components and type.
511 * \param comps number of components.
512 * \param type data type.
514 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
517 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
521 case GL_UNSIGNED_BYTE
:
522 return comps
* sizeof(GLubyte
);
524 case GL_UNSIGNED_SHORT
:
525 return comps
* sizeof(GLshort
);
527 case GL_UNSIGNED_INT
:
528 return comps
* sizeof(GLint
);
530 return comps
* sizeof(GLfloat
);
531 case GL_HALF_FLOAT_ARB
:
532 return comps
* sizeof(GLhalfARB
);
534 return comps
* sizeof(GLdouble
);
536 return comps
* sizeof(GLfixed
);
537 case GL_INT_2_10_10_10_REV
:
538 case GL_UNSIGNED_INT_2_10_10_10_REV
:
540 return sizeof(GLuint
);
543 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
545 return sizeof(GLuint
);
554 * Test if the given format is unsized.
557 _mesa_is_enum_format_unsized(GLenum format
)
572 case GL_LUMINANCE_ALPHA
:
577 case GL_SLUMINANCE_ALPHA
:
584 case GL_INTENSITY_SNORM
:
585 case GL_LUMINANCE_SNORM
:
586 case GL_LUMINANCE_ALPHA_SNORM
:
589 case GL_GREEN_INTEGER
:
590 case GL_BLUE_INTEGER
:
591 case GL_ALPHA_INTEGER
:
593 case GL_RGBA_INTEGER
:
595 case GL_BGRA_INTEGER
:
597 case GL_LUMINANCE_INTEGER_EXT
:
598 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
600 case GL_DEPTH_COMPONENT
:
601 case GL_DEPTH_STENCIL
:
602 case GL_STENCIL_INDEX
:
610 * Test if the given format is a UNORM (unsigned-normalized) format.
613 _mesa_is_enum_format_unorm(GLenum format
)
632 case GL_LUMINANCE_ALPHA
:
633 case GL_SLUMINANCE_ALPHA
:
634 case GL_LUMINANCE4_ALPHA4
:
635 case GL_LUMINANCE6_ALPHA2
:
636 case GL_LUMINANCE8_ALPHA8
:
637 case GL_LUMINANCE12_ALPHA4
:
638 case GL_LUMINANCE12_ALPHA12
:
639 case GL_LUMINANCE16_ALPHA16
:
681 * Test if the given format is a SNORM (signed-normalized) format.
684 _mesa_is_enum_format_snorm(GLenum format
)
687 /* signed, normalized texture formats */
699 case GL_RGBA16_SNORM
:
701 case GL_ALPHA8_SNORM
:
702 case GL_ALPHA16_SNORM
:
703 case GL_LUMINANCE_SNORM
:
704 case GL_LUMINANCE8_SNORM
:
705 case GL_LUMINANCE16_SNORM
:
706 case GL_LUMINANCE_ALPHA_SNORM
:
707 case GL_LUMINANCE8_ALPHA8_SNORM
:
708 case GL_LUMINANCE16_ALPHA16_SNORM
:
709 case GL_INTENSITY_SNORM
:
710 case GL_INTENSITY8_SNORM
:
711 case GL_INTENSITY16_SNORM
:
719 * Test if the given format is an integer (non-normalized) format.
722 _mesa_is_enum_format_unsigned_int(GLenum format
)
725 /* specific integer formats */
726 case GL_RGBA32UI_EXT
:
730 case GL_ALPHA32UI_EXT
:
731 case GL_INTENSITY32UI_EXT
:
732 case GL_LUMINANCE32UI_EXT
:
733 case GL_LUMINANCE_ALPHA32UI_EXT
:
734 case GL_RGBA16UI_EXT
:
738 case GL_ALPHA16UI_EXT
:
739 case GL_INTENSITY16UI_EXT
:
740 case GL_LUMINANCE16UI_EXT
:
741 case GL_LUMINANCE_ALPHA16UI_EXT
:
746 case GL_ALPHA8UI_EXT
:
747 case GL_INTENSITY8UI_EXT
:
748 case GL_LUMINANCE8UI_EXT
:
749 case GL_LUMINANCE_ALPHA8UI_EXT
:
759 * Test if the given format is an integer (non-normalized) format.
762 _mesa_is_enum_format_signed_int(GLenum format
)
765 /* generic integer formats */
766 case GL_RED_INTEGER_EXT
:
767 case GL_GREEN_INTEGER_EXT
:
768 case GL_BLUE_INTEGER_EXT
:
769 case GL_ALPHA_INTEGER_EXT
:
770 case GL_RGB_INTEGER_EXT
:
771 case GL_RGBA_INTEGER_EXT
:
772 case GL_BGR_INTEGER_EXT
:
773 case GL_BGRA_INTEGER_EXT
:
774 case GL_LUMINANCE_INTEGER_EXT
:
775 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
777 /* specific integer formats */
782 case GL_ALPHA32I_EXT
:
783 case GL_INTENSITY32I_EXT
:
784 case GL_LUMINANCE32I_EXT
:
785 case GL_LUMINANCE_ALPHA32I_EXT
:
790 case GL_ALPHA16I_EXT
:
791 case GL_INTENSITY16I_EXT
:
792 case GL_LUMINANCE16I_EXT
:
793 case GL_LUMINANCE_ALPHA16I_EXT
:
799 case GL_INTENSITY8I_EXT
:
800 case GL_LUMINANCE8I_EXT
:
801 case GL_LUMINANCE_ALPHA8I_EXT
:
810 * Test if the given format is an integer (non-normalized) format.
813 _mesa_is_enum_format_integer(GLenum format
)
815 return _mesa_is_enum_format_unsigned_int(format
) ||
816 _mesa_is_enum_format_signed_int(format
);
821 _mesa_is_type_unsigned(GLenum type
)
824 case GL_UNSIGNED_INT
:
825 case GL_UNSIGNED_INT_8_8_8_8
:
826 case GL_UNSIGNED_INT_8_8_8_8_REV
:
827 case GL_UNSIGNED_INT_10_10_10_2
:
828 case GL_UNSIGNED_INT_2_10_10_10_REV
:
830 case GL_UNSIGNED_SHORT
:
831 case GL_UNSIGNED_SHORT_4_4_4_4
:
832 case GL_UNSIGNED_SHORT_5_5_5_1
:
833 case GL_UNSIGNED_SHORT_5_6_5
:
834 case GL_UNSIGNED_SHORT_5_6_5_REV
:
835 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
836 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
837 case GL_UNSIGNED_SHORT_8_8_MESA
:
838 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
840 case GL_UNSIGNED_BYTE
:
841 case GL_UNSIGNED_BYTE_3_3_2
:
842 case GL_UNSIGNED_BYTE_2_3_3_REV
:
852 * Test if the given image format is a color/RGBA format (i.e., not color
853 * index, depth, stencil, etc).
854 * \param format the image format value (may by an internal texture format)
855 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
858 _mesa_is_color_format(GLenum format
)
876 case GL_LUMINANCE_ALPHA
:
877 case GL_LUMINANCE4_ALPHA4
:
878 case GL_LUMINANCE6_ALPHA2
:
879 case GL_LUMINANCE8_ALPHA8
:
880 case GL_LUMINANCE12_ALPHA4
:
881 case GL_LUMINANCE12_ALPHA12
:
882 case GL_LUMINANCE16_ALPHA16
:
915 /* float texture formats */
916 case GL_ALPHA16F_ARB
:
917 case GL_ALPHA32F_ARB
:
918 case GL_LUMINANCE16F_ARB
:
919 case GL_LUMINANCE32F_ARB
:
920 case GL_LUMINANCE_ALPHA16F_ARB
:
921 case GL_LUMINANCE_ALPHA32F_ARB
:
922 case GL_INTENSITY16F_ARB
:
923 case GL_INTENSITY32F_ARB
:
932 /* compressed formats */
933 case GL_COMPRESSED_ALPHA
:
934 case GL_COMPRESSED_LUMINANCE
:
935 case GL_COMPRESSED_LUMINANCE_ALPHA
:
936 case GL_COMPRESSED_INTENSITY
:
937 case GL_COMPRESSED_RED
:
938 case GL_COMPRESSED_RG
:
939 case GL_COMPRESSED_RGB
:
940 case GL_COMPRESSED_RGBA
:
945 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
946 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
947 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
948 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
949 case GL_COMPRESSED_RGB_FXT1_3DFX
:
950 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
953 case GL_SRGB_ALPHA_EXT
:
954 case GL_SRGB8_ALPHA8_EXT
:
955 case GL_SLUMINANCE_ALPHA_EXT
:
956 case GL_SLUMINANCE8_ALPHA8_EXT
:
957 case GL_SLUMINANCE_EXT
:
958 case GL_SLUMINANCE8_EXT
:
959 case GL_COMPRESSED_SRGB_EXT
:
960 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
961 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
962 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
963 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
964 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
965 case GL_COMPRESSED_SLUMINANCE_EXT
:
966 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
967 case GL_COMPRESSED_RED_RGTC1
:
968 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
969 case GL_COMPRESSED_RG_RGTC2
:
970 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
971 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
972 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
973 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
974 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
975 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
976 case GL_ETC1_RGB8_OES
:
977 case GL_COMPRESSED_RGB8_ETC2
:
978 case GL_COMPRESSED_SRGB8_ETC2
:
979 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
980 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
981 case GL_COMPRESSED_R11_EAC
:
982 case GL_COMPRESSED_RG11_EAC
:
983 case GL_COMPRESSED_SIGNED_R11_EAC
:
984 case GL_COMPRESSED_SIGNED_RG11_EAC
:
985 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
986 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
987 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
988 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
989 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
990 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
991 /* generic integer formats */
992 case GL_RED_INTEGER_EXT
:
993 case GL_GREEN_INTEGER_EXT
:
994 case GL_BLUE_INTEGER_EXT
:
995 case GL_ALPHA_INTEGER_EXT
:
996 case GL_RGB_INTEGER_EXT
:
997 case GL_RGBA_INTEGER_EXT
:
998 case GL_BGR_INTEGER_EXT
:
999 case GL_BGRA_INTEGER_EXT
:
1001 case GL_LUMINANCE_INTEGER_EXT
:
1002 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1003 /* sized integer formats */
1004 case GL_RGBA32UI_EXT
:
1005 case GL_RGB32UI_EXT
:
1008 case GL_ALPHA32UI_EXT
:
1009 case GL_INTENSITY32UI_EXT
:
1010 case GL_LUMINANCE32UI_EXT
:
1011 case GL_LUMINANCE_ALPHA32UI_EXT
:
1012 case GL_RGBA16UI_EXT
:
1013 case GL_RGB16UI_EXT
:
1016 case GL_ALPHA16UI_EXT
:
1017 case GL_INTENSITY16UI_EXT
:
1018 case GL_LUMINANCE16UI_EXT
:
1019 case GL_LUMINANCE_ALPHA16UI_EXT
:
1020 case GL_RGBA8UI_EXT
:
1024 case GL_ALPHA8UI_EXT
:
1025 case GL_INTENSITY8UI_EXT
:
1026 case GL_LUMINANCE8UI_EXT
:
1027 case GL_LUMINANCE_ALPHA8UI_EXT
:
1028 case GL_RGBA32I_EXT
:
1032 case GL_ALPHA32I_EXT
:
1033 case GL_INTENSITY32I_EXT
:
1034 case GL_LUMINANCE32I_EXT
:
1035 case GL_LUMINANCE_ALPHA32I_EXT
:
1036 case GL_RGBA16I_EXT
:
1040 case GL_ALPHA16I_EXT
:
1041 case GL_INTENSITY16I_EXT
:
1042 case GL_LUMINANCE16I_EXT
:
1043 case GL_LUMINANCE_ALPHA16I_EXT
:
1048 case GL_ALPHA8I_EXT
:
1049 case GL_INTENSITY8I_EXT
:
1050 case GL_LUMINANCE8I_EXT
:
1051 case GL_LUMINANCE_ALPHA8I_EXT
:
1052 /* signed, normalized texture formats */
1061 case GL_RGB16_SNORM
:
1063 case GL_RGBA8_SNORM
:
1064 case GL_RGBA16_SNORM
:
1065 case GL_ALPHA_SNORM
:
1066 case GL_ALPHA8_SNORM
:
1067 case GL_ALPHA16_SNORM
:
1068 case GL_LUMINANCE_SNORM
:
1069 case GL_LUMINANCE8_SNORM
:
1070 case GL_LUMINANCE16_SNORM
:
1071 case GL_LUMINANCE_ALPHA_SNORM
:
1072 case GL_LUMINANCE8_ALPHA8_SNORM
:
1073 case GL_LUMINANCE16_ALPHA16_SNORM
:
1074 case GL_INTENSITY_SNORM
:
1075 case GL_INTENSITY8_SNORM
:
1076 case GL_INTENSITY16_SNORM
:
1078 case GL_R11F_G11F_B10F
:
1081 case GL_YCBCR_MESA
: /* not considered to be RGB */
1090 * Test if the given image format is a depth component format.
1093 _mesa_is_depth_format(GLenum format
)
1096 case GL_DEPTH_COMPONENT
:
1097 case GL_DEPTH_COMPONENT16
:
1098 case GL_DEPTH_COMPONENT24
:
1099 case GL_DEPTH_COMPONENT32
:
1100 case GL_DEPTH_COMPONENT32F
:
1109 * Test if the given image format is a stencil format.
1112 _mesa_is_stencil_format(GLenum format
)
1115 case GL_STENCIL_INDEX
:
1124 * Test if the given image format is a YCbCr format.
1127 _mesa_is_ycbcr_format(GLenum format
)
1139 * Test if the given image format is a depth+stencil format.
1142 _mesa_is_depthstencil_format(GLenum format
)
1145 case GL_DEPTH24_STENCIL8_EXT
:
1146 case GL_DEPTH_STENCIL_EXT
:
1147 case GL_DEPTH32F_STENCIL8
:
1156 * Test if the given image format is a depth or stencil format.
1159 _mesa_is_depth_or_stencil_format(GLenum format
)
1162 case GL_DEPTH_COMPONENT
:
1163 case GL_DEPTH_COMPONENT16
:
1164 case GL_DEPTH_COMPONENT24
:
1165 case GL_DEPTH_COMPONENT32
:
1166 case GL_STENCIL_INDEX
:
1167 case GL_STENCIL_INDEX1_EXT
:
1168 case GL_STENCIL_INDEX4_EXT
:
1169 case GL_STENCIL_INDEX8_EXT
:
1170 case GL_STENCIL_INDEX16_EXT
:
1171 case GL_DEPTH_STENCIL_EXT
:
1172 case GL_DEPTH24_STENCIL8_EXT
:
1173 case GL_DEPTH_COMPONENT32F
:
1174 case GL_DEPTH32F_STENCIL8
:
1183 * Test if an image format is a supported compressed format.
1184 * \param format the internal format token provided by the user.
1185 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1188 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1191 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1192 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1193 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1194 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1195 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
1197 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1202 return _mesa_is_desktop_gl(ctx
) &&
1203 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1204 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1205 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1206 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1207 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1208 return _mesa_is_desktop_gl(ctx
)
1209 && ctx
->Extensions
.EXT_texture_sRGB
1210 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1211 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1212 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1213 return _mesa_is_desktop_gl(ctx
)
1214 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1215 case GL_COMPRESSED_RED_RGTC1
:
1216 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1217 case GL_COMPRESSED_RG_RGTC2
:
1218 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1219 return _mesa_is_desktop_gl(ctx
)
1220 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1221 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1222 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1223 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1224 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1225 return ctx
->API
== API_OPENGL_COMPAT
1226 && ctx
->Extensions
.EXT_texture_compression_latc
;
1227 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1228 return ctx
->API
== API_OPENGL_COMPAT
1229 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1230 case GL_ETC1_RGB8_OES
:
1231 return _mesa_is_gles(ctx
)
1232 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1233 case GL_COMPRESSED_RGB8_ETC2
:
1234 case GL_COMPRESSED_SRGB8_ETC2
:
1235 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1236 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1237 case GL_COMPRESSED_R11_EAC
:
1238 case GL_COMPRESSED_RG11_EAC
:
1239 case GL_COMPRESSED_SIGNED_R11_EAC
:
1240 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1241 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1242 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1243 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1244 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1245 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1246 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1247 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1248 return _mesa_is_desktop_gl(ctx
) &&
1249 ctx
->Extensions
.ARB_texture_compression_bptc
;
1250 case GL_PALETTE4_RGB8_OES
:
1251 case GL_PALETTE4_RGBA8_OES
:
1252 case GL_PALETTE4_R5_G6_B5_OES
:
1253 case GL_PALETTE4_RGBA4_OES
:
1254 case GL_PALETTE4_RGB5_A1_OES
:
1255 case GL_PALETTE8_RGB8_OES
:
1256 case GL_PALETTE8_RGBA8_OES
:
1257 case GL_PALETTE8_R5_G6_B5_OES
:
1258 case GL_PALETTE8_RGBA4_OES
:
1259 case GL_PALETTE8_RGB5_A1_OES
:
1260 return ctx
->API
== API_OPENGLES
;
1268 * Convert various base formats to the cooresponding integer format.
1271 _mesa_base_format_to_integer_format(GLenum format
)
1275 return GL_RED_INTEGER
;
1277 return GL_GREEN_INTEGER
;
1279 return GL_BLUE_INTEGER
;
1281 return GL_RG_INTEGER
;
1283 return GL_RGB_INTEGER
;
1285 return GL_RGBA_INTEGER
;
1287 return GL_BGR_INTEGER
;
1289 return GL_BGRA_INTEGER
;
1291 return GL_ALPHA_INTEGER
;
1293 return GL_LUMINANCE_INTEGER_EXT
;
1294 case GL_LUMINANCE_ALPHA
:
1295 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1303 * Does the given base texture/renderbuffer format have the channel
1307 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1310 case GL_TEXTURE_RED_SIZE
:
1311 case GL_TEXTURE_RED_TYPE
:
1312 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1313 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1314 if (base_format
== GL_RED
||
1315 base_format
== GL_RG
||
1316 base_format
== GL_RGB
||
1317 base_format
== GL_RGBA
) {
1321 case GL_TEXTURE_GREEN_SIZE
:
1322 case GL_TEXTURE_GREEN_TYPE
:
1323 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1324 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1325 if (base_format
== GL_RG
||
1326 base_format
== GL_RGB
||
1327 base_format
== GL_RGBA
) {
1331 case GL_TEXTURE_BLUE_SIZE
:
1332 case GL_TEXTURE_BLUE_TYPE
:
1333 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1334 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1335 if (base_format
== GL_RGB
||
1336 base_format
== GL_RGBA
) {
1340 case GL_TEXTURE_ALPHA_SIZE
:
1341 case GL_TEXTURE_ALPHA_TYPE
:
1342 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1343 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1344 if (base_format
== GL_RGBA
||
1345 base_format
== GL_ALPHA
||
1346 base_format
== GL_LUMINANCE_ALPHA
) {
1350 case GL_TEXTURE_LUMINANCE_SIZE
:
1351 case GL_TEXTURE_LUMINANCE_TYPE
:
1352 if (base_format
== GL_LUMINANCE
||
1353 base_format
== GL_LUMINANCE_ALPHA
) {
1357 case GL_TEXTURE_INTENSITY_SIZE
:
1358 case GL_TEXTURE_INTENSITY_TYPE
:
1359 if (base_format
== GL_INTENSITY
) {
1363 case GL_TEXTURE_DEPTH_SIZE
:
1364 case GL_TEXTURE_DEPTH_TYPE
:
1365 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1366 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1367 if (base_format
== GL_DEPTH_STENCIL
||
1368 base_format
== GL_DEPTH_COMPONENT
) {
1372 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1373 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1374 if (base_format
== GL_DEPTH_STENCIL
||
1375 base_format
== GL_STENCIL_INDEX
) {
1380 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1381 __FUNCTION__
, pname
);
1390 * Returns the number of channels/components for a base format.
1393 _mesa_base_format_component_count(GLenum base_format
)
1395 switch (base_format
) {
1399 case GL_DEPTH_COMPONENT
:
1402 case GL_LUMINANCE_ALPHA
:
1403 case GL_DEPTH_STENCIL
:
1416 * If format is a generic compressed format, return the corresponding
1417 * non-compressed format. For other formats, return the format as-is.
1420 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1423 case GL_COMPRESSED_RED
:
1425 case GL_COMPRESSED_RG
:
1427 case GL_COMPRESSED_RGB
:
1429 case GL_COMPRESSED_RGBA
:
1431 case GL_COMPRESSED_ALPHA
:
1433 case GL_COMPRESSED_LUMINANCE
:
1434 return GL_LUMINANCE
;
1435 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1436 return GL_LUMINANCE_ALPHA
;
1437 case GL_COMPRESSED_INTENSITY
:
1438 return GL_INTENSITY
;
1440 case GL_COMPRESSED_SRGB
:
1442 case GL_COMPRESSED_SRGB_ALPHA
:
1443 return GL_SRGB_ALPHA
;
1444 case GL_COMPRESSED_SLUMINANCE
:
1445 return GL_SLUMINANCE
;
1446 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1447 return GL_SLUMINANCE_ALPHA
;
1455 * Return the equivalent non-generic internal format.
1456 * This is useful for comparing whether two internal formats are equivalent.
1459 _mesa_get_nongeneric_internalformat(GLenum format
)
1462 /* GL 1.1 formats. */
1470 case GL_LUMINANCE_ALPHA
:
1471 return GL_LUMINANCE8_ALPHA8
;
1474 return GL_LUMINANCE8
;
1478 return GL_INTENSITY8
;
1480 /* GL_ARB_texture_rg */
1486 /* GL_EXT_texture_sRGB */
1490 return GL_SRGB8_ALPHA8
;
1492 return GL_SLUMINANCE8
;
1493 case GL_SLUMINANCE_ALPHA
:
1494 return GL_SLUMINANCE8_ALPHA8
;
1496 /* GL_EXT_texture_snorm */
1498 return GL_RGBA8_SNORM
;
1500 return GL_RGB8_SNORM
;
1502 return GL_RG8_SNORM
;
1505 case GL_LUMINANCE_ALPHA_SNORM
:
1506 return GL_LUMINANCE8_ALPHA8_SNORM
;
1507 case GL_LUMINANCE_SNORM
:
1508 return GL_LUMINANCE8_SNORM
;
1509 case GL_ALPHA_SNORM
:
1510 return GL_ALPHA8_SNORM
;
1511 case GL_INTENSITY_SNORM
:
1512 return GL_INTENSITY8_SNORM
;
1521 * Convert an sRGB internal format to linear.
1524 _mesa_get_linear_internalformat(GLenum format
)
1533 case GL_SRGB8_ALPHA8
:
1535 case GL_SLUMINANCE8
:
1536 return GL_LUMINANCE8
;
1538 return GL_LUMINANCE
;
1539 case GL_SLUMINANCE_ALPHA
:
1540 return GL_LUMINANCE_ALPHA
;
1541 case GL_SLUMINANCE8_ALPHA8
:
1542 return GL_LUMINANCE8_ALPHA8
;
1550 * Do error checking of format/type combinations for glReadPixels,
1551 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1552 * and type values, we may either generate GL_INVALID_OPERATION or
1555 * \param format pixel format.
1556 * \param type pixel type.
1558 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1561 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1562 GLenum format
, GLenum type
)
1564 /* From OpenGL 3.3 spec, page 220:
1565 * "If the format is DEPTH_STENCIL, then values are taken from
1566 * both the depth buffer and the stencil buffer. If there is no
1567 * depth buffer or if there is no stencil buffer, then the error
1568 * INVALID_OPERATION occurs. If the type parameter is not
1569 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1570 * error INVALID_ENUM occurs."
1572 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1573 * cannot be used to read depth or stencil in that API.
1575 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1576 && type
!= GL_UNSIGNED_INT_24_8
1577 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1578 return GL_INVALID_ENUM
;
1580 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1583 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1584 return GL_INVALID_ENUM
;
1588 case GL_UNSIGNED_BYTE_3_3_2
:
1589 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1590 case GL_UNSIGNED_SHORT_5_6_5
:
1591 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1592 if (format
== GL_RGB
) {
1595 if (format
== GL_RGB_INTEGER_EXT
&&
1596 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1599 return GL_INVALID_OPERATION
;
1601 case GL_UNSIGNED_SHORT_4_4_4_4
:
1602 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1603 case GL_UNSIGNED_SHORT_5_5_5_1
:
1604 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1605 case GL_UNSIGNED_INT_8_8_8_8
:
1606 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1607 case GL_UNSIGNED_INT_10_10_10_2
:
1608 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1609 if (format
== GL_RGBA
||
1610 format
== GL_BGRA
||
1611 format
== GL_ABGR_EXT
) {
1614 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1615 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1618 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1619 ctx
->API
== API_OPENGLES2
) {
1620 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1622 return GL_INVALID_OPERATION
;
1624 case GL_UNSIGNED_INT_24_8
:
1625 if (format
!= GL_DEPTH_STENCIL
) {
1626 return GL_INVALID_OPERATION
;
1630 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1631 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1632 return GL_INVALID_ENUM
;
1634 if (format
!= GL_DEPTH_STENCIL
) {
1635 return GL_INVALID_OPERATION
;
1639 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1640 if (!ctx
->Extensions
.EXT_packed_float
) {
1641 return GL_INVALID_ENUM
;
1643 if (format
!= GL_RGB
) {
1644 return GL_INVALID_OPERATION
;
1649 ; /* fall-through */
1652 /* now, for each format, check the type for compatibility */
1654 case GL_COLOR_INDEX
:
1655 case GL_STENCIL_INDEX
:
1659 case GL_UNSIGNED_BYTE
:
1661 case GL_UNSIGNED_SHORT
:
1663 case GL_UNSIGNED_INT
:
1668 return GL_INVALID_ENUM
;
1675 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1679 case GL_LUMINANCE_ALPHA
:
1680 case GL_DEPTH_COMPONENT
:
1683 case GL_UNSIGNED_BYTE
:
1685 case GL_UNSIGNED_SHORT
:
1687 case GL_UNSIGNED_INT
:
1692 return GL_INVALID_ENUM
;
1696 if (!ctx
->Extensions
.ARB_texture_rg
)
1697 return GL_INVALID_ENUM
;
1700 case GL_UNSIGNED_BYTE
:
1702 case GL_UNSIGNED_SHORT
:
1704 case GL_UNSIGNED_INT
:
1709 return GL_INVALID_ENUM
;
1715 case GL_UNSIGNED_BYTE
:
1717 case GL_UNSIGNED_SHORT
:
1719 case GL_UNSIGNED_INT
:
1721 case GL_UNSIGNED_BYTE_3_3_2
:
1722 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1723 case GL_UNSIGNED_SHORT_5_6_5
:
1724 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1727 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1728 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1729 return (ctx
->API
== API_OPENGLES2
)
1730 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1731 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1732 return ctx
->Extensions
.EXT_texture_shared_exponent
1733 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1734 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1735 return ctx
->Extensions
.EXT_packed_float
1736 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1738 return GL_INVALID_ENUM
;
1743 /* NOTE: no packed types are supported with BGR. That's
1744 * intentional, according to the GL spec.
1747 case GL_UNSIGNED_BYTE
:
1749 case GL_UNSIGNED_SHORT
:
1751 case GL_UNSIGNED_INT
:
1756 return GL_INVALID_ENUM
;
1764 case GL_UNSIGNED_BYTE
:
1766 case GL_UNSIGNED_SHORT
:
1768 case GL_UNSIGNED_INT
:
1770 case GL_UNSIGNED_SHORT_4_4_4_4
:
1771 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1772 case GL_UNSIGNED_SHORT_5_5_5_1
:
1773 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1774 case GL_UNSIGNED_INT_8_8_8_8
:
1775 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1776 case GL_UNSIGNED_INT_10_10_10_2
:
1777 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1781 return GL_INVALID_ENUM
;
1785 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1786 return GL_INVALID_ENUM
;
1787 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1788 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1791 return GL_INVALID_OPERATION
;
1793 case GL_DEPTH_STENCIL
:
1794 if (type
== GL_UNSIGNED_INT_24_8
)
1796 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1797 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1800 return GL_INVALID_ENUM
;
1802 /* integer-valued formats */
1803 case GL_RED_INTEGER_EXT
:
1804 case GL_GREEN_INTEGER_EXT
:
1805 case GL_BLUE_INTEGER_EXT
:
1806 case GL_ALPHA_INTEGER_EXT
:
1810 case GL_UNSIGNED_BYTE
:
1812 case GL_UNSIGNED_SHORT
:
1814 case GL_UNSIGNED_INT
:
1815 return (ctx
->Version
>= 30 ||
1816 ctx
->Extensions
.EXT_texture_integer
)
1817 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1819 return GL_INVALID_ENUM
;
1822 case GL_RGB_INTEGER_EXT
:
1825 case GL_UNSIGNED_BYTE
:
1827 case GL_UNSIGNED_SHORT
:
1829 case GL_UNSIGNED_INT
:
1830 return (ctx
->Version
>= 30 ||
1831 ctx
->Extensions
.EXT_texture_integer
)
1832 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1833 case GL_UNSIGNED_BYTE_3_3_2
:
1834 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1835 case GL_UNSIGNED_SHORT_5_6_5
:
1836 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1837 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1838 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1840 return GL_INVALID_ENUM
;
1843 case GL_BGR_INTEGER_EXT
:
1846 case GL_UNSIGNED_BYTE
:
1848 case GL_UNSIGNED_SHORT
:
1850 case GL_UNSIGNED_INT
:
1851 /* NOTE: no packed formats w/ BGR format */
1852 return (ctx
->Version
>= 30 ||
1853 ctx
->Extensions
.EXT_texture_integer
)
1854 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1856 return GL_INVALID_ENUM
;
1859 case GL_RGBA_INTEGER_EXT
:
1860 case GL_BGRA_INTEGER_EXT
:
1863 case GL_UNSIGNED_BYTE
:
1865 case GL_UNSIGNED_SHORT
:
1867 case GL_UNSIGNED_INT
:
1868 return (ctx
->Version
>= 30 ||
1869 ctx
->Extensions
.EXT_texture_integer
)
1870 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1871 case GL_UNSIGNED_SHORT_4_4_4_4
:
1872 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1873 case GL_UNSIGNED_SHORT_5_5_5_1
:
1874 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1875 case GL_UNSIGNED_INT_8_8_8_8
:
1876 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1877 case GL_UNSIGNED_INT_10_10_10_2
:
1878 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1879 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1880 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1882 return GL_INVALID_ENUM
;
1885 case GL_LUMINANCE_INTEGER_EXT
:
1886 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1889 case GL_UNSIGNED_BYTE
:
1891 case GL_UNSIGNED_SHORT
:
1893 case GL_UNSIGNED_INT
:
1894 return ctx
->Extensions
.EXT_texture_integer
1895 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1897 return GL_INVALID_ENUM
;
1901 return GL_INVALID_ENUM
;
1908 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1909 * and glTex[Sub]Image.
1910 * \return error code, or GL_NO_ERROR.
1913 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1914 unsigned dimensions
)
1916 GLboolean type_valid
= GL_TRUE
;
1921 case GL_LUMINANCE_ALPHA
:
1922 type_valid
= (type
== GL_UNSIGNED_BYTE
1924 || type
== GL_HALF_FLOAT_OES
);
1928 type_valid
= (type
== GL_UNSIGNED_BYTE
1929 || type
== GL_UNSIGNED_SHORT_5_6_5
1931 || type
== GL_HALF_FLOAT_OES
);
1935 type_valid
= (type
== GL_UNSIGNED_BYTE
1936 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1937 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1939 || type
== GL_HALF_FLOAT_OES
1940 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1943 case GL_DEPTH_COMPONENT
:
1944 /* This format is filtered against invalid dimensionalities elsewhere.
1946 type_valid
= (type
== GL_UNSIGNED_SHORT
1947 || type
== GL_UNSIGNED_INT
);
1950 case GL_DEPTH_STENCIL
:
1951 /* This format is filtered against invalid dimensionalities elsewhere.
1953 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1957 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1959 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1960 * the format does not appear to be allowed for 3D textures in OpenGL
1963 if (dimensions
!= 2)
1964 return GL_INVALID_VALUE
;
1969 return GL_INVALID_VALUE
;
1972 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1977 * Do error checking of format/type combinations for OpenGL ES 3
1979 * \return error code, or GL_NO_ERROR.
1982 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1983 GLenum internalFormat
)
1988 case GL_UNSIGNED_BYTE
:
1989 switch (internalFormat
) {
1994 case GL_SRGB8_ALPHA8_EXT
:
1997 return GL_INVALID_OPERATION
;
2002 if (internalFormat
!= GL_RGBA8_SNORM
)
2003 return GL_INVALID_OPERATION
;
2006 case GL_UNSIGNED_SHORT_4_4_4_4
:
2007 switch (internalFormat
) {
2012 return GL_INVALID_OPERATION
;
2016 case GL_UNSIGNED_SHORT_5_5_5_1
:
2017 switch (internalFormat
) {
2022 return GL_INVALID_OPERATION
;
2026 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2027 switch (internalFormat
) {
2028 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2033 return GL_INVALID_OPERATION
;
2038 if (internalFormat
!= GL_RGBA16F
)
2039 return GL_INVALID_OPERATION
;
2043 switch (internalFormat
) {
2048 return GL_INVALID_OPERATION
;
2053 return GL_INVALID_OPERATION
;
2057 case GL_RGBA_INTEGER
:
2059 case GL_UNSIGNED_BYTE
:
2060 if (internalFormat
!= GL_RGBA8UI
)
2061 return GL_INVALID_OPERATION
;
2065 if (internalFormat
!= GL_RGBA8I
)
2066 return GL_INVALID_OPERATION
;
2069 case GL_UNSIGNED_SHORT
:
2070 if (internalFormat
!= GL_RGBA16UI
)
2071 return GL_INVALID_OPERATION
;
2075 if (internalFormat
!= GL_RGBA16I
)
2076 return GL_INVALID_OPERATION
;
2079 case GL_UNSIGNED_INT
:
2080 if (internalFormat
!= GL_RGBA32UI
)
2081 return GL_INVALID_OPERATION
;
2085 if (internalFormat
!= GL_RGBA32I
)
2086 return GL_INVALID_OPERATION
;
2089 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2090 if (internalFormat
!= GL_RGB10_A2UI
)
2091 return GL_INVALID_OPERATION
;
2095 return GL_INVALID_OPERATION
;
2101 case GL_UNSIGNED_BYTE
:
2102 switch (internalFormat
) {
2109 return GL_INVALID_OPERATION
;
2114 if (internalFormat
!= GL_RGB8_SNORM
)
2115 return GL_INVALID_OPERATION
;
2118 case GL_UNSIGNED_SHORT_5_6_5
:
2119 switch (internalFormat
) {
2124 return GL_INVALID_OPERATION
;
2128 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2129 if (internalFormat
!= GL_R11F_G11F_B10F
)
2130 return GL_INVALID_OPERATION
;
2133 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2134 if (internalFormat
!= GL_RGB9_E5
)
2135 return GL_INVALID_OPERATION
;
2139 switch (internalFormat
) {
2141 case GL_R11F_G11F_B10F
:
2145 return GL_INVALID_OPERATION
;
2150 switch (internalFormat
) {
2153 case GL_R11F_G11F_B10F
:
2157 return GL_INVALID_OPERATION
;
2161 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2162 switch (internalFormat
) {
2163 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2166 return GL_INVALID_OPERATION
;
2171 return GL_INVALID_OPERATION
;
2175 case GL_RGB_INTEGER
:
2177 case GL_UNSIGNED_BYTE
:
2178 if (internalFormat
!= GL_RGB8UI
)
2179 return GL_INVALID_OPERATION
;
2183 if (internalFormat
!= GL_RGB8I
)
2184 return GL_INVALID_OPERATION
;
2187 case GL_UNSIGNED_SHORT
:
2188 if (internalFormat
!= GL_RGB16UI
)
2189 return GL_INVALID_OPERATION
;
2193 if (internalFormat
!= GL_RGB16I
)
2194 return GL_INVALID_OPERATION
;
2197 case GL_UNSIGNED_INT
:
2198 if (internalFormat
!= GL_RGB32UI
)
2199 return GL_INVALID_OPERATION
;
2203 if (internalFormat
!= GL_RGB32I
)
2204 return GL_INVALID_OPERATION
;
2208 return GL_INVALID_OPERATION
;
2214 case GL_UNSIGNED_BYTE
:
2215 if (internalFormat
!= GL_RG8
)
2216 return GL_INVALID_OPERATION
;
2220 if (internalFormat
!= GL_RG8_SNORM
)
2221 return GL_INVALID_OPERATION
;
2225 if (internalFormat
!= GL_RG16F
)
2226 return GL_INVALID_OPERATION
;
2230 switch (internalFormat
) {
2235 return GL_INVALID_OPERATION
;
2240 return GL_INVALID_OPERATION
;
2246 case GL_UNSIGNED_BYTE
:
2247 if (internalFormat
!= GL_RG8UI
)
2248 return GL_INVALID_OPERATION
;
2252 if (internalFormat
!= GL_RG8I
)
2253 return GL_INVALID_OPERATION
;
2256 case GL_UNSIGNED_SHORT
:
2257 if (internalFormat
!= GL_RG16UI
)
2258 return GL_INVALID_OPERATION
;
2262 if (internalFormat
!= GL_RG16I
)
2263 return GL_INVALID_OPERATION
;
2266 case GL_UNSIGNED_INT
:
2267 if (internalFormat
!= GL_RG32UI
)
2268 return GL_INVALID_OPERATION
;
2272 if (internalFormat
!= GL_RG32I
)
2273 return GL_INVALID_OPERATION
;
2277 return GL_INVALID_OPERATION
;
2283 case GL_UNSIGNED_BYTE
:
2284 if (internalFormat
!= GL_R8
)
2285 return GL_INVALID_OPERATION
;
2289 if (internalFormat
!= GL_R8_SNORM
)
2290 return GL_INVALID_OPERATION
;
2294 if (internalFormat
!= GL_R16F
)
2295 return GL_INVALID_OPERATION
;
2299 switch (internalFormat
) {
2304 return GL_INVALID_OPERATION
;
2309 return GL_INVALID_OPERATION
;
2313 case GL_RED_INTEGER
:
2315 case GL_UNSIGNED_BYTE
:
2316 if (internalFormat
!= GL_R8UI
)
2317 return GL_INVALID_OPERATION
;
2321 if (internalFormat
!= GL_R8I
)
2322 return GL_INVALID_OPERATION
;
2325 case GL_UNSIGNED_SHORT
:
2326 if (internalFormat
!= GL_R16UI
)
2327 return GL_INVALID_OPERATION
;
2331 if (internalFormat
!= GL_R16I
)
2332 return GL_INVALID_OPERATION
;
2335 case GL_UNSIGNED_INT
:
2336 if (internalFormat
!= GL_R32UI
)
2337 return GL_INVALID_OPERATION
;
2341 if (internalFormat
!= GL_R32I
)
2342 return GL_INVALID_OPERATION
;
2346 return GL_INVALID_OPERATION
;
2350 case GL_DEPTH_COMPONENT
:
2352 case GL_UNSIGNED_SHORT
:
2353 if (internalFormat
!= GL_DEPTH_COMPONENT
2354 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2355 return GL_INVALID_OPERATION
;
2358 case GL_UNSIGNED_INT
:
2359 switch (internalFormat
) {
2360 case GL_DEPTH_COMPONENT
:
2361 case GL_DEPTH_COMPONENT16
:
2362 case GL_DEPTH_COMPONENT24
:
2365 return GL_INVALID_OPERATION
;
2370 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2371 return GL_INVALID_OPERATION
;
2375 return GL_INVALID_OPERATION
;
2379 case GL_DEPTH_STENCIL
:
2381 case GL_UNSIGNED_INT_24_8
:
2382 if (internalFormat
!= GL_DEPTH_STENCIL
2383 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2384 return GL_INVALID_OPERATION
;
2387 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2388 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2389 return GL_INVALID_OPERATION
;
2393 return GL_INVALID_OPERATION
;
2399 case GL_LUMINANCE_ALPHA
:
2400 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2401 return GL_INVALID_OPERATION
;