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"
33 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
36 _mesa_type_is_packed(GLenum type
)
39 case GL_UNSIGNED_BYTE_3_3_2
:
40 case GL_UNSIGNED_BYTE_2_3_3_REV
:
41 case MESA_UNSIGNED_BYTE_4_4
:
42 case GL_UNSIGNED_SHORT_5_6_5
:
43 case GL_UNSIGNED_SHORT_5_6_5_REV
:
44 case GL_UNSIGNED_SHORT_4_4_4_4
:
45 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
46 case GL_UNSIGNED_SHORT_5_5_5_1
:
47 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
48 case GL_UNSIGNED_INT_8_8_8_8
:
49 case GL_UNSIGNED_INT_8_8_8_8_REV
:
50 case GL_UNSIGNED_INT_10_10_10_2
:
51 case GL_UNSIGNED_INT_2_10_10_10_REV
:
52 case GL_UNSIGNED_SHORT_8_8_MESA
:
53 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
54 case GL_UNSIGNED_INT_24_8_EXT
:
55 case GL_UNSIGNED_INT_5_9_9_9_REV
:
56 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
57 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
66 * Get the size of a GL data type.
68 * \param type GL data type.
70 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
71 * if an invalid type enum.
74 _mesa_sizeof_type(GLenum type
)
79 case GL_UNSIGNED_BYTE
:
80 return sizeof(GLubyte
);
82 return sizeof(GLbyte
);
83 case GL_UNSIGNED_SHORT
:
84 return sizeof(GLushort
);
86 return sizeof(GLshort
);
88 return sizeof(GLuint
);
92 return sizeof(GLfloat
);
94 return sizeof(GLdouble
);
95 case GL_HALF_FLOAT_ARB
:
96 return sizeof(GLhalfARB
);
98 return sizeof(GLfixed
);
106 * Same as _mesa_sizeof_type() but also accepting the packed pixel
110 _mesa_sizeof_packed_type(GLenum type
)
115 case GL_UNSIGNED_BYTE
:
116 return sizeof(GLubyte
);
118 return sizeof(GLbyte
);
119 case GL_UNSIGNED_SHORT
:
120 return sizeof(GLushort
);
122 return sizeof(GLshort
);
123 case GL_UNSIGNED_INT
:
124 return sizeof(GLuint
);
126 return sizeof(GLint
);
127 case GL_HALF_FLOAT_ARB
:
128 return sizeof(GLhalfARB
);
130 return sizeof(GLfloat
);
131 case GL_UNSIGNED_BYTE_3_3_2
:
132 case GL_UNSIGNED_BYTE_2_3_3_REV
:
133 case MESA_UNSIGNED_BYTE_4_4
:
134 return sizeof(GLubyte
);
135 case GL_UNSIGNED_SHORT_5_6_5
:
136 case GL_UNSIGNED_SHORT_5_6_5_REV
:
137 case GL_UNSIGNED_SHORT_4_4_4_4
:
138 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
139 case GL_UNSIGNED_SHORT_5_5_5_1
:
140 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
141 case GL_UNSIGNED_SHORT_8_8_MESA
:
142 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
143 return sizeof(GLushort
);
144 case GL_UNSIGNED_INT_8_8_8_8
:
145 case GL_UNSIGNED_INT_8_8_8_8_REV
:
146 case GL_UNSIGNED_INT_10_10_10_2
:
147 case GL_UNSIGNED_INT_2_10_10_10_REV
:
148 case GL_UNSIGNED_INT_24_8_EXT
:
149 case GL_UNSIGNED_INT_5_9_9_9_REV
:
150 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
151 return sizeof(GLuint
);
152 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
161 * Get the number of components in a pixel format.
163 * \param format pixel format.
165 * \return the number of components in the given format, or -1 if a bad format.
168 _mesa_components_in_format(GLenum format
)
172 case GL_STENCIL_INDEX
:
173 case GL_DEPTH_COMPONENT
:
175 case GL_RED_INTEGER_EXT
:
177 case GL_GREEN_INTEGER_EXT
:
179 case GL_BLUE_INTEGER_EXT
:
181 case GL_ALPHA_INTEGER_EXT
:
183 case GL_LUMINANCE_INTEGER_EXT
:
187 case GL_LUMINANCE_ALPHA
:
188 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
191 case GL_DEPTH_STENCIL_EXT
:
197 case GL_RGB_INTEGER_EXT
:
198 case GL_BGR_INTEGER_EXT
:
204 case GL_RGBA_INTEGER_EXT
:
205 case GL_BGRA_INTEGER_EXT
:
215 * Get the bytes per pixel of pixel format type pair.
217 * \param format pixel format.
218 * \param type pixel type.
220 * \return bytes per pixel, or -1 if a bad format or type was given.
223 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
225 GLint comps
= _mesa_components_in_format(format
);
231 return 0; /* special case */
233 case GL_UNSIGNED_BYTE
:
234 return comps
* sizeof(GLubyte
);
236 case GL_UNSIGNED_SHORT
:
237 return comps
* sizeof(GLshort
);
239 case GL_UNSIGNED_INT
:
240 return comps
* sizeof(GLint
);
242 return comps
* sizeof(GLfloat
);
243 case GL_HALF_FLOAT_ARB
:
244 return comps
* sizeof(GLhalfARB
);
245 case GL_UNSIGNED_BYTE_3_3_2
:
246 case GL_UNSIGNED_BYTE_2_3_3_REV
:
247 if (format
== GL_RGB
|| format
== GL_BGR
||
248 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
249 return sizeof(GLubyte
);
251 return -1; /* error */
252 case GL_UNSIGNED_SHORT_5_6_5
:
253 case GL_UNSIGNED_SHORT_5_6_5_REV
:
254 if (format
== GL_RGB
|| format
== GL_BGR
||
255 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
256 return sizeof(GLushort
);
258 return -1; /* error */
259 case GL_UNSIGNED_SHORT_4_4_4_4
:
260 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
261 case GL_UNSIGNED_SHORT_5_5_5_1
:
262 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
263 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
264 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
265 return sizeof(GLushort
);
268 case GL_UNSIGNED_INT_8_8_8_8
:
269 case GL_UNSIGNED_INT_8_8_8_8_REV
:
270 case GL_UNSIGNED_INT_10_10_10_2
:
271 case GL_UNSIGNED_INT_2_10_10_10_REV
:
272 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
273 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
275 return sizeof(GLuint
);
278 case GL_UNSIGNED_SHORT_8_8_MESA
:
279 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
280 if (format
== GL_YCBCR_MESA
)
281 return sizeof(GLushort
);
284 case GL_UNSIGNED_INT_24_8_EXT
:
285 if (format
== GL_DEPTH_STENCIL_EXT
)
286 return sizeof(GLuint
);
289 case GL_UNSIGNED_INT_5_9_9_9_REV
:
290 if (format
== GL_RGB
)
291 return sizeof(GLuint
);
294 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
295 if (format
== GL_RGB
)
296 return sizeof(GLuint
);
299 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
300 if (format
== GL_DEPTH_STENCIL
)
311 * Get the number of bytes for a vertex attrib with the given number of
312 * components and type.
314 * \param comps number of components.
315 * \param type data type.
317 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
320 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
324 case GL_UNSIGNED_BYTE
:
325 return comps
* sizeof(GLubyte
);
327 case GL_UNSIGNED_SHORT
:
328 return comps
* sizeof(GLshort
);
330 case GL_UNSIGNED_INT
:
331 return comps
* sizeof(GLint
);
333 return comps
* sizeof(GLfloat
);
334 case GL_HALF_FLOAT_ARB
:
335 return comps
* sizeof(GLhalfARB
);
337 return comps
* sizeof(GLdouble
);
339 return comps
* sizeof(GLfixed
);
340 case GL_INT_2_10_10_10_REV
:
341 case GL_UNSIGNED_INT_2_10_10_10_REV
:
343 return sizeof(GLuint
);
346 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
348 return sizeof(GLuint
);
357 * Test if the given format is unsized.
360 _mesa_is_enum_format_unsized(GLenum format
)
375 case GL_LUMINANCE_ALPHA
:
380 case GL_SLUMINANCE_ALPHA
:
387 case GL_INTENSITY_SNORM
:
388 case GL_LUMINANCE_SNORM
:
389 case GL_LUMINANCE_ALPHA_SNORM
:
392 case GL_GREEN_INTEGER
:
393 case GL_BLUE_INTEGER
:
394 case GL_ALPHA_INTEGER
:
396 case GL_RGBA_INTEGER
:
398 case GL_BGRA_INTEGER
:
400 case GL_LUMINANCE_INTEGER_EXT
:
401 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
403 case GL_DEPTH_COMPONENT
:
404 case GL_DEPTH_STENCIL
:
405 case GL_STENCIL_INDEX
:
413 * Test if the given format is a UNORM (unsigned-normalized) format.
416 _mesa_is_enum_format_unorm(GLenum format
)
435 case GL_LUMINANCE_ALPHA
:
436 case GL_SLUMINANCE_ALPHA
:
437 case GL_LUMINANCE4_ALPHA4
:
438 case GL_LUMINANCE6_ALPHA2
:
439 case GL_LUMINANCE8_ALPHA8
:
440 case GL_LUMINANCE12_ALPHA4
:
441 case GL_LUMINANCE12_ALPHA12
:
442 case GL_LUMINANCE16_ALPHA16
:
484 * Test if the given format is a SNORM (signed-normalized) format.
487 _mesa_is_enum_format_snorm(GLenum format
)
490 /* signed, normalized texture formats */
502 case GL_RGBA16_SNORM
:
504 case GL_ALPHA8_SNORM
:
505 case GL_ALPHA16_SNORM
:
506 case GL_LUMINANCE_SNORM
:
507 case GL_LUMINANCE8_SNORM
:
508 case GL_LUMINANCE16_SNORM
:
509 case GL_LUMINANCE_ALPHA_SNORM
:
510 case GL_LUMINANCE8_ALPHA8_SNORM
:
511 case GL_LUMINANCE16_ALPHA16_SNORM
:
512 case GL_INTENSITY_SNORM
:
513 case GL_INTENSITY8_SNORM
:
514 case GL_INTENSITY16_SNORM
:
522 * Test if the given format is an integer (non-normalized) format.
525 _mesa_is_enum_format_unsigned_int(GLenum format
)
528 /* specific integer formats */
529 case GL_RGBA32UI_EXT
:
533 case GL_ALPHA32UI_EXT
:
534 case GL_INTENSITY32UI_EXT
:
535 case GL_LUMINANCE32UI_EXT
:
536 case GL_LUMINANCE_ALPHA32UI_EXT
:
537 case GL_RGBA16UI_EXT
:
541 case GL_ALPHA16UI_EXT
:
542 case GL_INTENSITY16UI_EXT
:
543 case GL_LUMINANCE16UI_EXT
:
544 case GL_LUMINANCE_ALPHA16UI_EXT
:
549 case GL_ALPHA8UI_EXT
:
550 case GL_INTENSITY8UI_EXT
:
551 case GL_LUMINANCE8UI_EXT
:
552 case GL_LUMINANCE_ALPHA8UI_EXT
:
562 * Test if the given format is an integer (non-normalized) format.
565 _mesa_is_enum_format_signed_int(GLenum format
)
568 /* generic integer formats */
569 case GL_RED_INTEGER_EXT
:
570 case GL_GREEN_INTEGER_EXT
:
571 case GL_BLUE_INTEGER_EXT
:
572 case GL_ALPHA_INTEGER_EXT
:
573 case GL_RGB_INTEGER_EXT
:
574 case GL_RGBA_INTEGER_EXT
:
575 case GL_BGR_INTEGER_EXT
:
576 case GL_BGRA_INTEGER_EXT
:
577 case GL_LUMINANCE_INTEGER_EXT
:
578 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
580 /* specific integer formats */
585 case GL_ALPHA32I_EXT
:
586 case GL_INTENSITY32I_EXT
:
587 case GL_LUMINANCE32I_EXT
:
588 case GL_LUMINANCE_ALPHA32I_EXT
:
593 case GL_ALPHA16I_EXT
:
594 case GL_INTENSITY16I_EXT
:
595 case GL_LUMINANCE16I_EXT
:
596 case GL_LUMINANCE_ALPHA16I_EXT
:
602 case GL_INTENSITY8I_EXT
:
603 case GL_LUMINANCE8I_EXT
:
604 case GL_LUMINANCE_ALPHA8I_EXT
:
613 * Test if the given format is an integer (non-normalized) format.
616 _mesa_is_enum_format_integer(GLenum format
)
618 return _mesa_is_enum_format_unsigned_int(format
) ||
619 _mesa_is_enum_format_signed_int(format
);
624 _mesa_is_type_unsigned(GLenum type
)
627 case GL_UNSIGNED_INT
:
628 case GL_UNSIGNED_INT_8_8_8_8
:
629 case GL_UNSIGNED_INT_8_8_8_8_REV
:
630 case GL_UNSIGNED_INT_10_10_10_2
:
631 case GL_UNSIGNED_INT_2_10_10_10_REV
:
633 case GL_UNSIGNED_SHORT
:
634 case GL_UNSIGNED_SHORT_4_4_4_4
:
635 case GL_UNSIGNED_SHORT_5_5_5_1
:
636 case GL_UNSIGNED_SHORT_5_6_5
:
637 case GL_UNSIGNED_SHORT_5_6_5_REV
:
638 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
639 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
640 case GL_UNSIGNED_SHORT_8_8_MESA
:
641 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
643 case GL_UNSIGNED_BYTE
:
644 case GL_UNSIGNED_BYTE_3_3_2
:
645 case GL_UNSIGNED_BYTE_2_3_3_REV
:
655 * Test if the given image format is a color/RGBA format (i.e., not color
656 * index, depth, stencil, etc).
657 * \param format the image format value (may by an internal texture format)
658 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
661 _mesa_is_color_format(GLenum format
)
679 case GL_LUMINANCE_ALPHA
:
680 case GL_LUMINANCE4_ALPHA4
:
681 case GL_LUMINANCE6_ALPHA2
:
682 case GL_LUMINANCE8_ALPHA8
:
683 case GL_LUMINANCE12_ALPHA4
:
684 case GL_LUMINANCE12_ALPHA12
:
685 case GL_LUMINANCE16_ALPHA16
:
718 /* float texture formats */
719 case GL_ALPHA16F_ARB
:
720 case GL_ALPHA32F_ARB
:
721 case GL_LUMINANCE16F_ARB
:
722 case GL_LUMINANCE32F_ARB
:
723 case GL_LUMINANCE_ALPHA16F_ARB
:
724 case GL_LUMINANCE_ALPHA32F_ARB
:
725 case GL_INTENSITY16F_ARB
:
726 case GL_INTENSITY32F_ARB
:
735 /* compressed formats */
736 case GL_COMPRESSED_ALPHA
:
737 case GL_COMPRESSED_LUMINANCE
:
738 case GL_COMPRESSED_LUMINANCE_ALPHA
:
739 case GL_COMPRESSED_INTENSITY
:
740 case GL_COMPRESSED_RED
:
741 case GL_COMPRESSED_RG
:
742 case GL_COMPRESSED_RGB
:
743 case GL_COMPRESSED_RGBA
:
748 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
749 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
750 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
751 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
752 case GL_COMPRESSED_RGB_FXT1_3DFX
:
753 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
756 case GL_SRGB_ALPHA_EXT
:
757 case GL_SRGB8_ALPHA8_EXT
:
758 case GL_SLUMINANCE_ALPHA_EXT
:
759 case GL_SLUMINANCE8_ALPHA8_EXT
:
760 case GL_SLUMINANCE_EXT
:
761 case GL_SLUMINANCE8_EXT
:
762 case GL_COMPRESSED_SRGB_EXT
:
763 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
764 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
765 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
766 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
767 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
768 case GL_COMPRESSED_SLUMINANCE_EXT
:
769 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
770 case GL_COMPRESSED_RED_RGTC1
:
771 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
772 case GL_COMPRESSED_RG_RGTC2
:
773 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
774 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
775 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
776 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
777 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
778 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
779 case GL_ETC1_RGB8_OES
:
780 case GL_COMPRESSED_RGB8_ETC2
:
781 case GL_COMPRESSED_SRGB8_ETC2
:
782 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
783 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
784 case GL_COMPRESSED_R11_EAC
:
785 case GL_COMPRESSED_RG11_EAC
:
786 case GL_COMPRESSED_SIGNED_R11_EAC
:
787 case GL_COMPRESSED_SIGNED_RG11_EAC
:
788 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
789 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
790 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
791 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
792 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
793 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
794 /* generic integer formats */
795 case GL_RED_INTEGER_EXT
:
796 case GL_GREEN_INTEGER_EXT
:
797 case GL_BLUE_INTEGER_EXT
:
798 case GL_ALPHA_INTEGER_EXT
:
799 case GL_RGB_INTEGER_EXT
:
800 case GL_RGBA_INTEGER_EXT
:
801 case GL_BGR_INTEGER_EXT
:
802 case GL_BGRA_INTEGER_EXT
:
804 case GL_LUMINANCE_INTEGER_EXT
:
805 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
806 /* sized integer formats */
807 case GL_RGBA32UI_EXT
:
811 case GL_ALPHA32UI_EXT
:
812 case GL_INTENSITY32UI_EXT
:
813 case GL_LUMINANCE32UI_EXT
:
814 case GL_LUMINANCE_ALPHA32UI_EXT
:
815 case GL_RGBA16UI_EXT
:
819 case GL_ALPHA16UI_EXT
:
820 case GL_INTENSITY16UI_EXT
:
821 case GL_LUMINANCE16UI_EXT
:
822 case GL_LUMINANCE_ALPHA16UI_EXT
:
827 case GL_ALPHA8UI_EXT
:
828 case GL_INTENSITY8UI_EXT
:
829 case GL_LUMINANCE8UI_EXT
:
830 case GL_LUMINANCE_ALPHA8UI_EXT
:
835 case GL_ALPHA32I_EXT
:
836 case GL_INTENSITY32I_EXT
:
837 case GL_LUMINANCE32I_EXT
:
838 case GL_LUMINANCE_ALPHA32I_EXT
:
843 case GL_ALPHA16I_EXT
:
844 case GL_INTENSITY16I_EXT
:
845 case GL_LUMINANCE16I_EXT
:
846 case GL_LUMINANCE_ALPHA16I_EXT
:
852 case GL_INTENSITY8I_EXT
:
853 case GL_LUMINANCE8I_EXT
:
854 case GL_LUMINANCE_ALPHA8I_EXT
:
855 /* signed, normalized texture formats */
867 case GL_RGBA16_SNORM
:
869 case GL_ALPHA8_SNORM
:
870 case GL_ALPHA16_SNORM
:
871 case GL_LUMINANCE_SNORM
:
872 case GL_LUMINANCE8_SNORM
:
873 case GL_LUMINANCE16_SNORM
:
874 case GL_LUMINANCE_ALPHA_SNORM
:
875 case GL_LUMINANCE8_ALPHA8_SNORM
:
876 case GL_LUMINANCE16_ALPHA16_SNORM
:
877 case GL_INTENSITY_SNORM
:
878 case GL_INTENSITY8_SNORM
:
879 case GL_INTENSITY16_SNORM
:
881 case GL_R11F_G11F_B10F
:
884 case GL_YCBCR_MESA
: /* not considered to be RGB */
893 * Test if the given image format is a depth component format.
896 _mesa_is_depth_format(GLenum format
)
899 case GL_DEPTH_COMPONENT
:
900 case GL_DEPTH_COMPONENT16
:
901 case GL_DEPTH_COMPONENT24
:
902 case GL_DEPTH_COMPONENT32
:
903 case GL_DEPTH_COMPONENT32F
:
912 * Test if the given image format is a stencil format.
915 _mesa_is_stencil_format(GLenum format
)
918 case GL_STENCIL_INDEX
:
927 * Test if the given image format is a YCbCr format.
930 _mesa_is_ycbcr_format(GLenum format
)
942 * Test if the given image format is a depth+stencil format.
945 _mesa_is_depthstencil_format(GLenum format
)
948 case GL_DEPTH24_STENCIL8_EXT
:
949 case GL_DEPTH_STENCIL_EXT
:
950 case GL_DEPTH32F_STENCIL8
:
959 * Test if the given image format is a depth or stencil format.
962 _mesa_is_depth_or_stencil_format(GLenum format
)
965 case GL_DEPTH_COMPONENT
:
966 case GL_DEPTH_COMPONENT16
:
967 case GL_DEPTH_COMPONENT24
:
968 case GL_DEPTH_COMPONENT32
:
969 case GL_STENCIL_INDEX
:
970 case GL_STENCIL_INDEX1_EXT
:
971 case GL_STENCIL_INDEX4_EXT
:
972 case GL_STENCIL_INDEX8_EXT
:
973 case GL_STENCIL_INDEX16_EXT
:
974 case GL_DEPTH_STENCIL_EXT
:
975 case GL_DEPTH24_STENCIL8_EXT
:
976 case GL_DEPTH_COMPONENT32F
:
977 case GL_DEPTH32F_STENCIL8
:
986 * Test if an image format is a supported compressed format.
987 * \param format the internal format token provided by the user.
988 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
991 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
994 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
995 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
996 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
997 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
998 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
1000 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1005 return _mesa_is_desktop_gl(ctx
) &&
1006 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1007 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1008 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1009 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1010 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1011 return _mesa_is_desktop_gl(ctx
)
1012 && ctx
->Extensions
.EXT_texture_sRGB
1013 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1014 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1015 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1016 return _mesa_is_desktop_gl(ctx
)
1017 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1018 case GL_COMPRESSED_RED_RGTC1
:
1019 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1020 case GL_COMPRESSED_RG_RGTC2
:
1021 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1022 return _mesa_is_desktop_gl(ctx
)
1023 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1024 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1025 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1026 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1027 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1028 return ctx
->API
== API_OPENGL_COMPAT
1029 && ctx
->Extensions
.EXT_texture_compression_latc
;
1030 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1031 return ctx
->API
== API_OPENGL_COMPAT
1032 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1033 case GL_ETC1_RGB8_OES
:
1034 return _mesa_is_gles(ctx
)
1035 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1036 case GL_COMPRESSED_RGB8_ETC2
:
1037 case GL_COMPRESSED_SRGB8_ETC2
:
1038 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1039 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1040 case GL_COMPRESSED_R11_EAC
:
1041 case GL_COMPRESSED_RG11_EAC
:
1042 case GL_COMPRESSED_SIGNED_R11_EAC
:
1043 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1044 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1045 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1046 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1047 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1048 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1049 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1050 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1051 return _mesa_is_desktop_gl(ctx
) &&
1052 ctx
->Extensions
.ARB_texture_compression_bptc
;
1053 case GL_PALETTE4_RGB8_OES
:
1054 case GL_PALETTE4_RGBA8_OES
:
1055 case GL_PALETTE4_R5_G6_B5_OES
:
1056 case GL_PALETTE4_RGBA4_OES
:
1057 case GL_PALETTE4_RGB5_A1_OES
:
1058 case GL_PALETTE8_RGB8_OES
:
1059 case GL_PALETTE8_RGBA8_OES
:
1060 case GL_PALETTE8_R5_G6_B5_OES
:
1061 case GL_PALETTE8_RGBA4_OES
:
1062 case GL_PALETTE8_RGB5_A1_OES
:
1063 return ctx
->API
== API_OPENGLES
;
1071 * Convert various base formats to the cooresponding integer format.
1074 _mesa_base_format_to_integer_format(GLenum format
)
1078 return GL_RED_INTEGER
;
1080 return GL_GREEN_INTEGER
;
1082 return GL_BLUE_INTEGER
;
1084 return GL_RG_INTEGER
;
1086 return GL_RGB_INTEGER
;
1088 return GL_RGBA_INTEGER
;
1090 return GL_BGR_INTEGER
;
1092 return GL_BGRA_INTEGER
;
1094 return GL_ALPHA_INTEGER
;
1096 return GL_LUMINANCE_INTEGER_EXT
;
1097 case GL_LUMINANCE_ALPHA
:
1098 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1106 * Does the given base texture/renderbuffer format have the channel
1110 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1113 case GL_TEXTURE_RED_SIZE
:
1114 case GL_TEXTURE_RED_TYPE
:
1115 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1116 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1117 if (base_format
== GL_RED
||
1118 base_format
== GL_RG
||
1119 base_format
== GL_RGB
||
1120 base_format
== GL_RGBA
) {
1124 case GL_TEXTURE_GREEN_SIZE
:
1125 case GL_TEXTURE_GREEN_TYPE
:
1126 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1127 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1128 if (base_format
== GL_RG
||
1129 base_format
== GL_RGB
||
1130 base_format
== GL_RGBA
) {
1134 case GL_TEXTURE_BLUE_SIZE
:
1135 case GL_TEXTURE_BLUE_TYPE
:
1136 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1137 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1138 if (base_format
== GL_RGB
||
1139 base_format
== GL_RGBA
) {
1143 case GL_TEXTURE_ALPHA_SIZE
:
1144 case GL_TEXTURE_ALPHA_TYPE
:
1145 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1146 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1147 if (base_format
== GL_RGBA
||
1148 base_format
== GL_ALPHA
||
1149 base_format
== GL_LUMINANCE_ALPHA
) {
1153 case GL_TEXTURE_LUMINANCE_SIZE
:
1154 case GL_TEXTURE_LUMINANCE_TYPE
:
1155 if (base_format
== GL_LUMINANCE
||
1156 base_format
== GL_LUMINANCE_ALPHA
) {
1160 case GL_TEXTURE_INTENSITY_SIZE
:
1161 case GL_TEXTURE_INTENSITY_TYPE
:
1162 if (base_format
== GL_INTENSITY
) {
1166 case GL_TEXTURE_DEPTH_SIZE
:
1167 case GL_TEXTURE_DEPTH_TYPE
:
1168 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1169 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1170 if (base_format
== GL_DEPTH_STENCIL
||
1171 base_format
== GL_DEPTH_COMPONENT
) {
1175 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1176 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1177 if (base_format
== GL_DEPTH_STENCIL
||
1178 base_format
== GL_STENCIL_INDEX
) {
1183 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1184 __FUNCTION__
, pname
);
1193 * Returns the number of channels/components for a base format.
1196 _mesa_base_format_component_count(GLenum base_format
)
1198 switch (base_format
) {
1202 case GL_DEPTH_COMPONENT
:
1205 case GL_LUMINANCE_ALPHA
:
1206 case GL_DEPTH_STENCIL
:
1219 * If format is a generic compressed format, return the corresponding
1220 * non-compressed format. For other formats, return the format as-is.
1223 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1226 case GL_COMPRESSED_RED
:
1228 case GL_COMPRESSED_RG
:
1230 case GL_COMPRESSED_RGB
:
1232 case GL_COMPRESSED_RGBA
:
1234 case GL_COMPRESSED_ALPHA
:
1236 case GL_COMPRESSED_LUMINANCE
:
1237 return GL_LUMINANCE
;
1238 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1239 return GL_LUMINANCE_ALPHA
;
1240 case GL_COMPRESSED_INTENSITY
:
1241 return GL_INTENSITY
;
1243 case GL_COMPRESSED_SRGB
:
1245 case GL_COMPRESSED_SRGB_ALPHA
:
1246 return GL_SRGB_ALPHA
;
1247 case GL_COMPRESSED_SLUMINANCE
:
1248 return GL_SLUMINANCE
;
1249 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1250 return GL_SLUMINANCE_ALPHA
;
1258 * Return the equivalent non-generic internal format.
1259 * This is useful for comparing whether two internal formats are equivalent.
1262 _mesa_get_nongeneric_internalformat(GLenum format
)
1265 /* GL 1.1 formats. */
1273 case GL_LUMINANCE_ALPHA
:
1274 return GL_LUMINANCE8_ALPHA8
;
1277 return GL_LUMINANCE8
;
1281 return GL_INTENSITY8
;
1283 /* GL_ARB_texture_rg */
1289 /* GL_EXT_texture_sRGB */
1293 return GL_SRGB8_ALPHA8
;
1295 return GL_SLUMINANCE8
;
1296 case GL_SLUMINANCE_ALPHA
:
1297 return GL_SLUMINANCE8_ALPHA8
;
1299 /* GL_EXT_texture_snorm */
1301 return GL_RGBA8_SNORM
;
1303 return GL_RGB8_SNORM
;
1305 return GL_RG8_SNORM
;
1308 case GL_LUMINANCE_ALPHA_SNORM
:
1309 return GL_LUMINANCE8_ALPHA8_SNORM
;
1310 case GL_LUMINANCE_SNORM
:
1311 return GL_LUMINANCE8_SNORM
;
1312 case GL_ALPHA_SNORM
:
1313 return GL_ALPHA8_SNORM
;
1314 case GL_INTENSITY_SNORM
:
1315 return GL_INTENSITY8_SNORM
;
1324 * Convert an sRGB internal format to linear.
1327 _mesa_get_linear_internalformat(GLenum format
)
1336 case GL_SRGB8_ALPHA8
:
1338 case GL_SLUMINANCE8
:
1339 return GL_LUMINANCE8
;
1341 return GL_LUMINANCE
;
1342 case GL_SLUMINANCE_ALPHA
:
1343 return GL_LUMINANCE_ALPHA
;
1344 case GL_SLUMINANCE8_ALPHA8
:
1345 return GL_LUMINANCE8_ALPHA8
;
1353 * Do error checking of format/type combinations for glReadPixels,
1354 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1355 * and type values, we may either generate GL_INVALID_OPERATION or
1358 * \param format pixel format.
1359 * \param type pixel type.
1361 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1364 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1365 GLenum format
, GLenum type
)
1367 /* From OpenGL 3.3 spec, page 220:
1368 * "If the format is DEPTH_STENCIL, then values are taken from
1369 * both the depth buffer and the stencil buffer. If there is no
1370 * depth buffer or if there is no stencil buffer, then the error
1371 * INVALID_OPERATION occurs. If the type parameter is not
1372 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1373 * error INVALID_ENUM occurs."
1375 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1376 * cannot be used to read depth or stencil in that API.
1378 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1379 && type
!= GL_UNSIGNED_INT_24_8
1380 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1381 return GL_INVALID_ENUM
;
1383 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1386 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1387 return GL_INVALID_ENUM
;
1391 case GL_UNSIGNED_BYTE_3_3_2
:
1392 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1393 case GL_UNSIGNED_SHORT_5_6_5
:
1394 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1395 if (format
== GL_RGB
) {
1398 if (format
== GL_RGB_INTEGER_EXT
&&
1399 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1402 return GL_INVALID_OPERATION
;
1404 case GL_UNSIGNED_SHORT_4_4_4_4
:
1405 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1406 case GL_UNSIGNED_SHORT_5_5_5_1
:
1407 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1408 case GL_UNSIGNED_INT_8_8_8_8
:
1409 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1410 case GL_UNSIGNED_INT_10_10_10_2
:
1411 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1412 if (format
== GL_RGBA
||
1413 format
== GL_BGRA
||
1414 format
== GL_ABGR_EXT
) {
1417 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1418 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1421 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1422 ctx
->API
== API_OPENGLES2
) {
1423 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1425 return GL_INVALID_OPERATION
;
1427 case GL_UNSIGNED_INT_24_8
:
1428 if (format
!= GL_DEPTH_STENCIL
) {
1429 return GL_INVALID_OPERATION
;
1433 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1434 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1435 return GL_INVALID_ENUM
;
1437 if (format
!= GL_DEPTH_STENCIL
) {
1438 return GL_INVALID_OPERATION
;
1442 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1443 if (!ctx
->Extensions
.EXT_packed_float
) {
1444 return GL_INVALID_ENUM
;
1446 if (format
!= GL_RGB
) {
1447 return GL_INVALID_OPERATION
;
1452 ; /* fall-through */
1455 /* now, for each format, check the type for compatibility */
1457 case GL_COLOR_INDEX
:
1458 case GL_STENCIL_INDEX
:
1462 case GL_UNSIGNED_BYTE
:
1464 case GL_UNSIGNED_SHORT
:
1466 case GL_UNSIGNED_INT
:
1471 return GL_INVALID_ENUM
;
1478 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1482 case GL_LUMINANCE_ALPHA
:
1483 case GL_DEPTH_COMPONENT
:
1486 case GL_UNSIGNED_BYTE
:
1488 case GL_UNSIGNED_SHORT
:
1490 case GL_UNSIGNED_INT
:
1495 return GL_INVALID_ENUM
;
1499 if (!ctx
->Extensions
.ARB_texture_rg
)
1500 return GL_INVALID_ENUM
;
1503 case GL_UNSIGNED_BYTE
:
1505 case GL_UNSIGNED_SHORT
:
1507 case GL_UNSIGNED_INT
:
1512 return GL_INVALID_ENUM
;
1518 case GL_UNSIGNED_BYTE
:
1520 case GL_UNSIGNED_SHORT
:
1522 case GL_UNSIGNED_INT
:
1524 case GL_UNSIGNED_BYTE_3_3_2
:
1525 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1526 case GL_UNSIGNED_SHORT_5_6_5
:
1527 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1530 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1531 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1532 return (ctx
->API
== API_OPENGLES2
)
1533 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1534 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1535 return ctx
->Extensions
.EXT_texture_shared_exponent
1536 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1537 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1538 return ctx
->Extensions
.EXT_packed_float
1539 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1541 return GL_INVALID_ENUM
;
1546 /* NOTE: no packed types are supported with BGR. That's
1547 * intentional, according to the GL spec.
1550 case GL_UNSIGNED_BYTE
:
1552 case GL_UNSIGNED_SHORT
:
1554 case GL_UNSIGNED_INT
:
1559 return GL_INVALID_ENUM
;
1567 case GL_UNSIGNED_BYTE
:
1569 case GL_UNSIGNED_SHORT
:
1571 case GL_UNSIGNED_INT
:
1573 case GL_UNSIGNED_SHORT_4_4_4_4
:
1574 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1575 case GL_UNSIGNED_SHORT_5_5_5_1
:
1576 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1577 case GL_UNSIGNED_INT_8_8_8_8
:
1578 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1579 case GL_UNSIGNED_INT_10_10_10_2
:
1580 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1584 return GL_INVALID_ENUM
;
1588 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1589 return GL_INVALID_ENUM
;
1590 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1591 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1594 return GL_INVALID_OPERATION
;
1596 case GL_DEPTH_STENCIL
:
1597 if (type
== GL_UNSIGNED_INT_24_8
)
1599 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1600 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1603 return GL_INVALID_ENUM
;
1605 /* integer-valued formats */
1606 case GL_RED_INTEGER_EXT
:
1607 case GL_GREEN_INTEGER_EXT
:
1608 case GL_BLUE_INTEGER_EXT
:
1609 case GL_ALPHA_INTEGER_EXT
:
1613 case GL_UNSIGNED_BYTE
:
1615 case GL_UNSIGNED_SHORT
:
1617 case GL_UNSIGNED_INT
:
1618 return (ctx
->Version
>= 30 ||
1619 ctx
->Extensions
.EXT_texture_integer
)
1620 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1622 return GL_INVALID_ENUM
;
1625 case GL_RGB_INTEGER_EXT
:
1628 case GL_UNSIGNED_BYTE
:
1630 case GL_UNSIGNED_SHORT
:
1632 case GL_UNSIGNED_INT
:
1633 return (ctx
->Version
>= 30 ||
1634 ctx
->Extensions
.EXT_texture_integer
)
1635 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1636 case GL_UNSIGNED_BYTE_3_3_2
:
1637 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1638 case GL_UNSIGNED_SHORT_5_6_5
:
1639 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1640 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1641 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1643 return GL_INVALID_ENUM
;
1646 case GL_BGR_INTEGER_EXT
:
1649 case GL_UNSIGNED_BYTE
:
1651 case GL_UNSIGNED_SHORT
:
1653 case GL_UNSIGNED_INT
:
1654 /* NOTE: no packed formats w/ BGR format */
1655 return (ctx
->Version
>= 30 ||
1656 ctx
->Extensions
.EXT_texture_integer
)
1657 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1659 return GL_INVALID_ENUM
;
1662 case GL_RGBA_INTEGER_EXT
:
1663 case GL_BGRA_INTEGER_EXT
:
1666 case GL_UNSIGNED_BYTE
:
1668 case GL_UNSIGNED_SHORT
:
1670 case GL_UNSIGNED_INT
:
1671 return (ctx
->Version
>= 30 ||
1672 ctx
->Extensions
.EXT_texture_integer
)
1673 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1674 case GL_UNSIGNED_SHORT_4_4_4_4
:
1675 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1676 case GL_UNSIGNED_SHORT_5_5_5_1
:
1677 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1678 case GL_UNSIGNED_INT_8_8_8_8
:
1679 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1680 case GL_UNSIGNED_INT_10_10_10_2
:
1681 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1682 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1683 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1685 return GL_INVALID_ENUM
;
1688 case GL_LUMINANCE_INTEGER_EXT
:
1689 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1692 case GL_UNSIGNED_BYTE
:
1694 case GL_UNSIGNED_SHORT
:
1696 case GL_UNSIGNED_INT
:
1697 return ctx
->Extensions
.EXT_texture_integer
1698 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1700 return GL_INVALID_ENUM
;
1704 return GL_INVALID_ENUM
;
1711 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1712 * and glTex[Sub]Image.
1713 * \return error code, or GL_NO_ERROR.
1716 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1717 unsigned dimensions
)
1719 GLboolean type_valid
= GL_TRUE
;
1724 case GL_LUMINANCE_ALPHA
:
1725 type_valid
= (type
== GL_UNSIGNED_BYTE
1727 || type
== GL_HALF_FLOAT_OES
);
1731 type_valid
= (type
== GL_UNSIGNED_BYTE
1732 || type
== GL_UNSIGNED_SHORT_5_6_5
1734 || type
== GL_HALF_FLOAT_OES
);
1738 type_valid
= (type
== GL_UNSIGNED_BYTE
1739 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1740 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1742 || type
== GL_HALF_FLOAT_OES
1743 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1746 case GL_DEPTH_COMPONENT
:
1747 /* This format is filtered against invalid dimensionalities elsewhere.
1749 type_valid
= (type
== GL_UNSIGNED_SHORT
1750 || type
== GL_UNSIGNED_INT
);
1753 case GL_DEPTH_STENCIL
:
1754 /* This format is filtered against invalid dimensionalities elsewhere.
1756 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1760 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1762 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1763 * the format does not appear to be allowed for 3D textures in OpenGL
1766 if (dimensions
!= 2)
1767 return GL_INVALID_VALUE
;
1772 return GL_INVALID_VALUE
;
1775 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1780 * Do error checking of format/type combinations for OpenGL ES 3
1782 * \return error code, or GL_NO_ERROR.
1785 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1786 GLenum internalFormat
)
1791 case GL_UNSIGNED_BYTE
:
1792 switch (internalFormat
) {
1797 case GL_SRGB8_ALPHA8_EXT
:
1800 return GL_INVALID_OPERATION
;
1805 if (internalFormat
!= GL_RGBA8_SNORM
)
1806 return GL_INVALID_OPERATION
;
1809 case GL_UNSIGNED_SHORT_4_4_4_4
:
1810 switch (internalFormat
) {
1815 return GL_INVALID_OPERATION
;
1819 case GL_UNSIGNED_SHORT_5_5_5_1
:
1820 switch (internalFormat
) {
1825 return GL_INVALID_OPERATION
;
1829 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1830 switch (internalFormat
) {
1831 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1836 return GL_INVALID_OPERATION
;
1841 if (internalFormat
!= GL_RGBA16F
)
1842 return GL_INVALID_OPERATION
;
1846 switch (internalFormat
) {
1851 return GL_INVALID_OPERATION
;
1856 return GL_INVALID_OPERATION
;
1860 case GL_RGBA_INTEGER
:
1862 case GL_UNSIGNED_BYTE
:
1863 if (internalFormat
!= GL_RGBA8UI
)
1864 return GL_INVALID_OPERATION
;
1868 if (internalFormat
!= GL_RGBA8I
)
1869 return GL_INVALID_OPERATION
;
1872 case GL_UNSIGNED_SHORT
:
1873 if (internalFormat
!= GL_RGBA16UI
)
1874 return GL_INVALID_OPERATION
;
1878 if (internalFormat
!= GL_RGBA16I
)
1879 return GL_INVALID_OPERATION
;
1882 case GL_UNSIGNED_INT
:
1883 if (internalFormat
!= GL_RGBA32UI
)
1884 return GL_INVALID_OPERATION
;
1888 if (internalFormat
!= GL_RGBA32I
)
1889 return GL_INVALID_OPERATION
;
1892 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1893 if (internalFormat
!= GL_RGB10_A2UI
)
1894 return GL_INVALID_OPERATION
;
1898 return GL_INVALID_OPERATION
;
1904 case GL_UNSIGNED_BYTE
:
1905 switch (internalFormat
) {
1912 return GL_INVALID_OPERATION
;
1917 if (internalFormat
!= GL_RGB8_SNORM
)
1918 return GL_INVALID_OPERATION
;
1921 case GL_UNSIGNED_SHORT_5_6_5
:
1922 switch (internalFormat
) {
1927 return GL_INVALID_OPERATION
;
1931 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1932 if (internalFormat
!= GL_R11F_G11F_B10F
)
1933 return GL_INVALID_OPERATION
;
1936 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1937 if (internalFormat
!= GL_RGB9_E5
)
1938 return GL_INVALID_OPERATION
;
1942 switch (internalFormat
) {
1944 case GL_R11F_G11F_B10F
:
1948 return GL_INVALID_OPERATION
;
1953 switch (internalFormat
) {
1956 case GL_R11F_G11F_B10F
:
1960 return GL_INVALID_OPERATION
;
1964 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1965 switch (internalFormat
) {
1966 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1969 return GL_INVALID_OPERATION
;
1974 return GL_INVALID_OPERATION
;
1978 case GL_RGB_INTEGER
:
1980 case GL_UNSIGNED_BYTE
:
1981 if (internalFormat
!= GL_RGB8UI
)
1982 return GL_INVALID_OPERATION
;
1986 if (internalFormat
!= GL_RGB8I
)
1987 return GL_INVALID_OPERATION
;
1990 case GL_UNSIGNED_SHORT
:
1991 if (internalFormat
!= GL_RGB16UI
)
1992 return GL_INVALID_OPERATION
;
1996 if (internalFormat
!= GL_RGB16I
)
1997 return GL_INVALID_OPERATION
;
2000 case GL_UNSIGNED_INT
:
2001 if (internalFormat
!= GL_RGB32UI
)
2002 return GL_INVALID_OPERATION
;
2006 if (internalFormat
!= GL_RGB32I
)
2007 return GL_INVALID_OPERATION
;
2011 return GL_INVALID_OPERATION
;
2017 case GL_UNSIGNED_BYTE
:
2018 if (internalFormat
!= GL_RG8
)
2019 return GL_INVALID_OPERATION
;
2023 if (internalFormat
!= GL_RG8_SNORM
)
2024 return GL_INVALID_OPERATION
;
2028 if (internalFormat
!= GL_RG16F
)
2029 return GL_INVALID_OPERATION
;
2033 switch (internalFormat
) {
2038 return GL_INVALID_OPERATION
;
2043 return GL_INVALID_OPERATION
;
2049 case GL_UNSIGNED_BYTE
:
2050 if (internalFormat
!= GL_RG8UI
)
2051 return GL_INVALID_OPERATION
;
2055 if (internalFormat
!= GL_RG8I
)
2056 return GL_INVALID_OPERATION
;
2059 case GL_UNSIGNED_SHORT
:
2060 if (internalFormat
!= GL_RG16UI
)
2061 return GL_INVALID_OPERATION
;
2065 if (internalFormat
!= GL_RG16I
)
2066 return GL_INVALID_OPERATION
;
2069 case GL_UNSIGNED_INT
:
2070 if (internalFormat
!= GL_RG32UI
)
2071 return GL_INVALID_OPERATION
;
2075 if (internalFormat
!= GL_RG32I
)
2076 return GL_INVALID_OPERATION
;
2080 return GL_INVALID_OPERATION
;
2086 case GL_UNSIGNED_BYTE
:
2087 if (internalFormat
!= GL_R8
)
2088 return GL_INVALID_OPERATION
;
2092 if (internalFormat
!= GL_R8_SNORM
)
2093 return GL_INVALID_OPERATION
;
2097 if (internalFormat
!= GL_R16F
)
2098 return GL_INVALID_OPERATION
;
2102 switch (internalFormat
) {
2107 return GL_INVALID_OPERATION
;
2112 return GL_INVALID_OPERATION
;
2116 case GL_RED_INTEGER
:
2118 case GL_UNSIGNED_BYTE
:
2119 if (internalFormat
!= GL_R8UI
)
2120 return GL_INVALID_OPERATION
;
2124 if (internalFormat
!= GL_R8I
)
2125 return GL_INVALID_OPERATION
;
2128 case GL_UNSIGNED_SHORT
:
2129 if (internalFormat
!= GL_R16UI
)
2130 return GL_INVALID_OPERATION
;
2134 if (internalFormat
!= GL_R16I
)
2135 return GL_INVALID_OPERATION
;
2138 case GL_UNSIGNED_INT
:
2139 if (internalFormat
!= GL_R32UI
)
2140 return GL_INVALID_OPERATION
;
2144 if (internalFormat
!= GL_R32I
)
2145 return GL_INVALID_OPERATION
;
2149 return GL_INVALID_OPERATION
;
2153 case GL_DEPTH_COMPONENT
:
2155 case GL_UNSIGNED_SHORT
:
2156 if (internalFormat
!= GL_DEPTH_COMPONENT
2157 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2158 return GL_INVALID_OPERATION
;
2161 case GL_UNSIGNED_INT
:
2162 switch (internalFormat
) {
2163 case GL_DEPTH_COMPONENT
:
2164 case GL_DEPTH_COMPONENT16
:
2165 case GL_DEPTH_COMPONENT24
:
2168 return GL_INVALID_OPERATION
;
2173 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2174 return GL_INVALID_OPERATION
;
2178 return GL_INVALID_OPERATION
;
2182 case GL_DEPTH_STENCIL
:
2184 case GL_UNSIGNED_INT_24_8
:
2185 if (internalFormat
!= GL_DEPTH_STENCIL
2186 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2187 return GL_INVALID_OPERATION
;
2190 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2191 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2192 return GL_INVALID_OPERATION
;
2196 return GL_INVALID_OPERATION
;
2202 case GL_LUMINANCE_ALPHA
:
2203 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2204 return GL_INVALID_OPERATION
;