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 SNORM (signed-normalized) format.
416 _mesa_is_enum_format_snorm(GLenum format
)
419 /* signed, normalized texture formats */
431 case GL_RGBA16_SNORM
:
433 case GL_ALPHA8_SNORM
:
434 case GL_ALPHA16_SNORM
:
435 case GL_LUMINANCE_SNORM
:
436 case GL_LUMINANCE8_SNORM
:
437 case GL_LUMINANCE16_SNORM
:
438 case GL_LUMINANCE_ALPHA_SNORM
:
439 case GL_LUMINANCE8_ALPHA8_SNORM
:
440 case GL_LUMINANCE16_ALPHA16_SNORM
:
441 case GL_INTENSITY_SNORM
:
442 case GL_INTENSITY8_SNORM
:
443 case GL_INTENSITY16_SNORM
:
451 * Test if the given format is an integer (non-normalized) format.
454 _mesa_is_enum_format_unsigned_int(GLenum format
)
457 /* specific integer formats */
458 case GL_RGBA32UI_EXT
:
462 case GL_ALPHA32UI_EXT
:
463 case GL_INTENSITY32UI_EXT
:
464 case GL_LUMINANCE32UI_EXT
:
465 case GL_LUMINANCE_ALPHA32UI_EXT
:
466 case GL_RGBA16UI_EXT
:
470 case GL_ALPHA16UI_EXT
:
471 case GL_INTENSITY16UI_EXT
:
472 case GL_LUMINANCE16UI_EXT
:
473 case GL_LUMINANCE_ALPHA16UI_EXT
:
478 case GL_ALPHA8UI_EXT
:
479 case GL_INTENSITY8UI_EXT
:
480 case GL_LUMINANCE8UI_EXT
:
481 case GL_LUMINANCE_ALPHA8UI_EXT
:
491 * Test if the given format is an integer (non-normalized) format.
494 _mesa_is_enum_format_signed_int(GLenum format
)
497 /* generic integer formats */
498 case GL_RED_INTEGER_EXT
:
499 case GL_GREEN_INTEGER_EXT
:
500 case GL_BLUE_INTEGER_EXT
:
501 case GL_ALPHA_INTEGER_EXT
:
502 case GL_RGB_INTEGER_EXT
:
503 case GL_RGBA_INTEGER_EXT
:
504 case GL_BGR_INTEGER_EXT
:
505 case GL_BGRA_INTEGER_EXT
:
506 case GL_LUMINANCE_INTEGER_EXT
:
507 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
509 /* specific integer formats */
514 case GL_ALPHA32I_EXT
:
515 case GL_INTENSITY32I_EXT
:
516 case GL_LUMINANCE32I_EXT
:
517 case GL_LUMINANCE_ALPHA32I_EXT
:
522 case GL_ALPHA16I_EXT
:
523 case GL_INTENSITY16I_EXT
:
524 case GL_LUMINANCE16I_EXT
:
525 case GL_LUMINANCE_ALPHA16I_EXT
:
531 case GL_INTENSITY8I_EXT
:
532 case GL_LUMINANCE8I_EXT
:
533 case GL_LUMINANCE_ALPHA8I_EXT
:
542 * Test if the given format is an integer (non-normalized) format.
545 _mesa_is_enum_format_integer(GLenum format
)
547 return _mesa_is_enum_format_unsigned_int(format
) ||
548 _mesa_is_enum_format_signed_int(format
);
553 _mesa_is_type_unsigned(GLenum type
)
556 case GL_UNSIGNED_INT
:
557 case GL_UNSIGNED_INT_8_8_8_8
:
558 case GL_UNSIGNED_INT_8_8_8_8_REV
:
559 case GL_UNSIGNED_INT_10_10_10_2
:
560 case GL_UNSIGNED_INT_2_10_10_10_REV
:
562 case GL_UNSIGNED_SHORT
:
563 case GL_UNSIGNED_SHORT_4_4_4_4
:
564 case GL_UNSIGNED_SHORT_5_5_5_1
:
565 case GL_UNSIGNED_SHORT_5_6_5
:
566 case GL_UNSIGNED_SHORT_5_6_5_REV
:
567 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
568 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
569 case GL_UNSIGNED_SHORT_8_8_MESA
:
570 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
572 case GL_UNSIGNED_BYTE
:
573 case GL_UNSIGNED_BYTE_3_3_2
:
574 case GL_UNSIGNED_BYTE_2_3_3_REV
:
584 * Test if the given image format is a color/RGBA format (i.e., not color
585 * index, depth, stencil, etc).
586 * \param format the image format value (may by an internal texture format)
587 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
590 _mesa_is_color_format(GLenum format
)
608 case GL_LUMINANCE_ALPHA
:
609 case GL_LUMINANCE4_ALPHA4
:
610 case GL_LUMINANCE6_ALPHA2
:
611 case GL_LUMINANCE8_ALPHA8
:
612 case GL_LUMINANCE12_ALPHA4
:
613 case GL_LUMINANCE12_ALPHA12
:
614 case GL_LUMINANCE16_ALPHA16
:
647 /* float texture formats */
648 case GL_ALPHA16F_ARB
:
649 case GL_ALPHA32F_ARB
:
650 case GL_LUMINANCE16F_ARB
:
651 case GL_LUMINANCE32F_ARB
:
652 case GL_LUMINANCE_ALPHA16F_ARB
:
653 case GL_LUMINANCE_ALPHA32F_ARB
:
654 case GL_INTENSITY16F_ARB
:
655 case GL_INTENSITY32F_ARB
:
664 /* compressed formats */
665 case GL_COMPRESSED_ALPHA
:
666 case GL_COMPRESSED_LUMINANCE
:
667 case GL_COMPRESSED_LUMINANCE_ALPHA
:
668 case GL_COMPRESSED_INTENSITY
:
669 case GL_COMPRESSED_RED
:
670 case GL_COMPRESSED_RG
:
671 case GL_COMPRESSED_RGB
:
672 case GL_COMPRESSED_RGBA
:
677 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
678 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
679 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
680 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
681 case GL_COMPRESSED_RGB_FXT1_3DFX
:
682 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
685 case GL_SRGB_ALPHA_EXT
:
686 case GL_SRGB8_ALPHA8_EXT
:
687 case GL_SLUMINANCE_ALPHA_EXT
:
688 case GL_SLUMINANCE8_ALPHA8_EXT
:
689 case GL_SLUMINANCE_EXT
:
690 case GL_SLUMINANCE8_EXT
:
691 case GL_COMPRESSED_SRGB_EXT
:
692 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
693 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
694 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
695 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
696 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
697 case GL_COMPRESSED_SLUMINANCE_EXT
:
698 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
699 case GL_COMPRESSED_RED_RGTC1
:
700 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
701 case GL_COMPRESSED_RG_RGTC2
:
702 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
703 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
704 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
705 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
706 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
707 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
708 case GL_ETC1_RGB8_OES
:
709 case GL_COMPRESSED_RGB8_ETC2
:
710 case GL_COMPRESSED_SRGB8_ETC2
:
711 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
712 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
713 case GL_COMPRESSED_R11_EAC
:
714 case GL_COMPRESSED_RG11_EAC
:
715 case GL_COMPRESSED_SIGNED_R11_EAC
:
716 case GL_COMPRESSED_SIGNED_RG11_EAC
:
717 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
718 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
719 /* generic integer formats */
720 case GL_RED_INTEGER_EXT
:
721 case GL_GREEN_INTEGER_EXT
:
722 case GL_BLUE_INTEGER_EXT
:
723 case GL_ALPHA_INTEGER_EXT
:
724 case GL_RGB_INTEGER_EXT
:
725 case GL_RGBA_INTEGER_EXT
:
726 case GL_BGR_INTEGER_EXT
:
727 case GL_BGRA_INTEGER_EXT
:
729 case GL_LUMINANCE_INTEGER_EXT
:
730 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
731 /* sized integer formats */
732 case GL_RGBA32UI_EXT
:
736 case GL_ALPHA32UI_EXT
:
737 case GL_INTENSITY32UI_EXT
:
738 case GL_LUMINANCE32UI_EXT
:
739 case GL_LUMINANCE_ALPHA32UI_EXT
:
740 case GL_RGBA16UI_EXT
:
744 case GL_ALPHA16UI_EXT
:
745 case GL_INTENSITY16UI_EXT
:
746 case GL_LUMINANCE16UI_EXT
:
747 case GL_LUMINANCE_ALPHA16UI_EXT
:
752 case GL_ALPHA8UI_EXT
:
753 case GL_INTENSITY8UI_EXT
:
754 case GL_LUMINANCE8UI_EXT
:
755 case GL_LUMINANCE_ALPHA8UI_EXT
:
760 case GL_ALPHA32I_EXT
:
761 case GL_INTENSITY32I_EXT
:
762 case GL_LUMINANCE32I_EXT
:
763 case GL_LUMINANCE_ALPHA32I_EXT
:
768 case GL_ALPHA16I_EXT
:
769 case GL_INTENSITY16I_EXT
:
770 case GL_LUMINANCE16I_EXT
:
771 case GL_LUMINANCE_ALPHA16I_EXT
:
777 case GL_INTENSITY8I_EXT
:
778 case GL_LUMINANCE8I_EXT
:
779 case GL_LUMINANCE_ALPHA8I_EXT
:
780 /* signed, normalized texture formats */
792 case GL_RGBA16_SNORM
:
794 case GL_ALPHA8_SNORM
:
795 case GL_ALPHA16_SNORM
:
796 case GL_LUMINANCE_SNORM
:
797 case GL_LUMINANCE8_SNORM
:
798 case GL_LUMINANCE16_SNORM
:
799 case GL_LUMINANCE_ALPHA_SNORM
:
800 case GL_LUMINANCE8_ALPHA8_SNORM
:
801 case GL_LUMINANCE16_ALPHA16_SNORM
:
802 case GL_INTENSITY_SNORM
:
803 case GL_INTENSITY8_SNORM
:
804 case GL_INTENSITY16_SNORM
:
806 case GL_R11F_G11F_B10F
:
809 case GL_YCBCR_MESA
: /* not considered to be RGB */
818 * Test if the given image format is a depth component format.
821 _mesa_is_depth_format(GLenum format
)
824 case GL_DEPTH_COMPONENT
:
825 case GL_DEPTH_COMPONENT16
:
826 case GL_DEPTH_COMPONENT24
:
827 case GL_DEPTH_COMPONENT32
:
828 case GL_DEPTH_COMPONENT32F
:
837 * Test if the given image format is a stencil format.
840 _mesa_is_stencil_format(GLenum format
)
843 case GL_STENCIL_INDEX
:
852 * Test if the given image format is a YCbCr format.
855 _mesa_is_ycbcr_format(GLenum format
)
867 * Test if the given image format is a depth+stencil format.
870 _mesa_is_depthstencil_format(GLenum format
)
873 case GL_DEPTH24_STENCIL8_EXT
:
874 case GL_DEPTH_STENCIL_EXT
:
875 case GL_DEPTH32F_STENCIL8
:
884 * Test if the given image format is a depth or stencil format.
887 _mesa_is_depth_or_stencil_format(GLenum format
)
890 case GL_DEPTH_COMPONENT
:
891 case GL_DEPTH_COMPONENT16
:
892 case GL_DEPTH_COMPONENT24
:
893 case GL_DEPTH_COMPONENT32
:
894 case GL_STENCIL_INDEX
:
895 case GL_STENCIL_INDEX1_EXT
:
896 case GL_STENCIL_INDEX4_EXT
:
897 case GL_STENCIL_INDEX8_EXT
:
898 case GL_STENCIL_INDEX16_EXT
:
899 case GL_DEPTH_STENCIL_EXT
:
900 case GL_DEPTH24_STENCIL8_EXT
:
901 case GL_DEPTH_COMPONENT32F
:
902 case GL_DEPTH32F_STENCIL8
:
911 * Test if an image format is a supported compressed format.
912 * \param format the internal format token provided by the user.
913 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
916 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
919 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
920 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
921 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
922 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
923 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
925 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
930 return _mesa_is_desktop_gl(ctx
) &&
931 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
932 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
933 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
934 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
935 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
936 return _mesa_is_desktop_gl(ctx
)
937 && ctx
->Extensions
.EXT_texture_sRGB
938 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
939 case GL_COMPRESSED_RGB_FXT1_3DFX
:
940 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
941 return _mesa_is_desktop_gl(ctx
)
942 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
943 case GL_COMPRESSED_RED_RGTC1
:
944 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
945 case GL_COMPRESSED_RG_RGTC2
:
946 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
947 return _mesa_is_desktop_gl(ctx
)
948 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
949 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
950 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
951 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
952 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
953 return ctx
->API
== API_OPENGL_COMPAT
954 && ctx
->Extensions
.EXT_texture_compression_latc
;
955 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
956 return ctx
->API
== API_OPENGL_COMPAT
957 && ctx
->Extensions
.ATI_texture_compression_3dc
;
958 case GL_ETC1_RGB8_OES
:
959 return _mesa_is_gles(ctx
)
960 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
961 case GL_COMPRESSED_RGB8_ETC2
:
962 case GL_COMPRESSED_SRGB8_ETC2
:
963 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
964 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
965 case GL_COMPRESSED_R11_EAC
:
966 case GL_COMPRESSED_RG11_EAC
:
967 case GL_COMPRESSED_SIGNED_R11_EAC
:
968 case GL_COMPRESSED_SIGNED_RG11_EAC
:
969 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
970 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
971 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
972 case GL_PALETTE4_RGB8_OES
:
973 case GL_PALETTE4_RGBA8_OES
:
974 case GL_PALETTE4_R5_G6_B5_OES
:
975 case GL_PALETTE4_RGBA4_OES
:
976 case GL_PALETTE4_RGB5_A1_OES
:
977 case GL_PALETTE8_RGB8_OES
:
978 case GL_PALETTE8_RGBA8_OES
:
979 case GL_PALETTE8_R5_G6_B5_OES
:
980 case GL_PALETTE8_RGBA4_OES
:
981 case GL_PALETTE8_RGB5_A1_OES
:
982 return ctx
->API
== API_OPENGLES
;
990 * Convert various base formats to the cooresponding integer format.
993 _mesa_base_format_to_integer_format(GLenum format
)
997 return GL_RED_INTEGER
;
999 return GL_GREEN_INTEGER
;
1001 return GL_BLUE_INTEGER
;
1003 return GL_RG_INTEGER
;
1005 return GL_RGB_INTEGER
;
1007 return GL_RGBA_INTEGER
;
1009 return GL_BGR_INTEGER
;
1011 return GL_BGRA_INTEGER
;
1013 return GL_ALPHA_INTEGER
;
1015 return GL_LUMINANCE_INTEGER_EXT
;
1016 case GL_LUMINANCE_ALPHA
:
1017 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1025 * Does the given base texture/renderbuffer format have the channel
1029 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1032 case GL_TEXTURE_RED_SIZE
:
1033 case GL_TEXTURE_RED_TYPE
:
1034 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1035 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1036 if (base_format
== GL_RED
||
1037 base_format
== GL_RG
||
1038 base_format
== GL_RGB
||
1039 base_format
== GL_RGBA
) {
1043 case GL_TEXTURE_GREEN_SIZE
:
1044 case GL_TEXTURE_GREEN_TYPE
:
1045 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1046 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1047 if (base_format
== GL_RG
||
1048 base_format
== GL_RGB
||
1049 base_format
== GL_RGBA
) {
1053 case GL_TEXTURE_BLUE_SIZE
:
1054 case GL_TEXTURE_BLUE_TYPE
:
1055 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1056 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1057 if (base_format
== GL_RGB
||
1058 base_format
== GL_RGBA
) {
1062 case GL_TEXTURE_ALPHA_SIZE
:
1063 case GL_TEXTURE_ALPHA_TYPE
:
1064 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1065 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1066 if (base_format
== GL_RGBA
||
1067 base_format
== GL_ALPHA
||
1068 base_format
== GL_LUMINANCE_ALPHA
) {
1072 case GL_TEXTURE_LUMINANCE_SIZE
:
1073 case GL_TEXTURE_LUMINANCE_TYPE
:
1074 if (base_format
== GL_LUMINANCE
||
1075 base_format
== GL_LUMINANCE_ALPHA
) {
1079 case GL_TEXTURE_INTENSITY_SIZE
:
1080 case GL_TEXTURE_INTENSITY_TYPE
:
1081 if (base_format
== GL_INTENSITY
) {
1085 case GL_TEXTURE_DEPTH_SIZE
:
1086 case GL_TEXTURE_DEPTH_TYPE
:
1087 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1088 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1089 if (base_format
== GL_DEPTH_STENCIL
||
1090 base_format
== GL_DEPTH_COMPONENT
) {
1094 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1095 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1096 if (base_format
== GL_DEPTH_STENCIL
||
1097 base_format
== GL_STENCIL_INDEX
) {
1102 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1103 __FUNCTION__
, pname
);
1112 * Returns the number of channels/components for a base format.
1115 _mesa_base_format_component_count(GLenum base_format
)
1117 switch (base_format
) {
1121 case GL_DEPTH_COMPONENT
:
1124 case GL_LUMINANCE_ALPHA
:
1125 case GL_DEPTH_STENCIL
:
1138 * If format is a generic compressed format, return the corresponding
1139 * non-compressed format. For other formats, return the format as-is.
1142 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1145 case GL_COMPRESSED_RED
:
1147 case GL_COMPRESSED_RG
:
1149 case GL_COMPRESSED_RGB
:
1151 case GL_COMPRESSED_RGBA
:
1153 case GL_COMPRESSED_ALPHA
:
1155 case GL_COMPRESSED_LUMINANCE
:
1156 return GL_LUMINANCE
;
1157 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1158 return GL_LUMINANCE_ALPHA
;
1159 case GL_COMPRESSED_INTENSITY
:
1160 return GL_INTENSITY
;
1162 case GL_COMPRESSED_SRGB
:
1164 case GL_COMPRESSED_SRGB_ALPHA
:
1165 return GL_SRGB_ALPHA
;
1166 case GL_COMPRESSED_SLUMINANCE
:
1167 return GL_SLUMINANCE
;
1168 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1169 return GL_SLUMINANCE_ALPHA
;
1177 * Return the equivalent non-generic internal format.
1178 * This is useful for comparing whether two internal formats are equivalent.
1181 _mesa_get_nongeneric_internalformat(GLenum format
)
1184 /* GL 1.1 formats. */
1192 case GL_LUMINANCE_ALPHA
:
1193 return GL_LUMINANCE8_ALPHA8
;
1196 return GL_LUMINANCE8
;
1200 return GL_INTENSITY8
;
1202 /* GL_ARB_texture_rg */
1208 /* GL_EXT_texture_sRGB */
1212 return GL_SRGB8_ALPHA8
;
1214 return GL_SLUMINANCE8
;
1215 case GL_SLUMINANCE_ALPHA
:
1216 return GL_SLUMINANCE8_ALPHA8
;
1218 /* GL_EXT_texture_snorm */
1220 return GL_RGBA8_SNORM
;
1222 return GL_RGB8_SNORM
;
1224 return GL_RG8_SNORM
;
1227 case GL_LUMINANCE_ALPHA_SNORM
:
1228 return GL_LUMINANCE8_ALPHA8_SNORM
;
1229 case GL_LUMINANCE_SNORM
:
1230 return GL_LUMINANCE8_SNORM
;
1231 case GL_ALPHA_SNORM
:
1232 return GL_ALPHA8_SNORM
;
1233 case GL_INTENSITY_SNORM
:
1234 return GL_INTENSITY8_SNORM
;
1243 * Convert an sRGB internal format to linear.
1246 _mesa_get_linear_internalformat(GLenum format
)
1255 case GL_SRGB8_ALPHA8
:
1257 case GL_SLUMINANCE8
:
1258 return GL_LUMINANCE8
;
1260 return GL_LUMINANCE
;
1261 case GL_SLUMINANCE_ALPHA
:
1262 return GL_LUMINANCE_ALPHA
;
1263 case GL_SLUMINANCE8_ALPHA8
:
1264 return GL_LUMINANCE8_ALPHA8
;
1272 * Do error checking of format/type combinations for glReadPixels,
1273 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1274 * and type values, we may either generate GL_INVALID_OPERATION or
1277 * \param format pixel format.
1278 * \param type pixel type.
1280 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1283 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1284 GLenum format
, GLenum type
)
1286 /* From OpenGL 3.3 spec, page 220:
1287 * "If the format is DEPTH_STENCIL, then values are taken from
1288 * both the depth buffer and the stencil buffer. If there is no
1289 * depth buffer or if there is no stencil buffer, then the error
1290 * INVALID_OPERATION occurs. If the type parameter is not
1291 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1292 * error INVALID_ENUM occurs."
1294 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1295 * cannot be used to read depth or stencil in that API.
1297 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1298 && type
!= GL_UNSIGNED_INT_24_8
1299 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1300 return GL_INVALID_ENUM
;
1302 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1305 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1306 return GL_INVALID_ENUM
;
1310 case GL_UNSIGNED_BYTE_3_3_2
:
1311 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1312 case GL_UNSIGNED_SHORT_5_6_5
:
1313 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1314 if (format
== GL_RGB
) {
1317 if (format
== GL_RGB_INTEGER_EXT
&&
1318 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1321 return GL_INVALID_OPERATION
;
1323 case GL_UNSIGNED_SHORT_4_4_4_4
:
1324 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1325 case GL_UNSIGNED_SHORT_5_5_5_1
:
1326 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1327 case GL_UNSIGNED_INT_8_8_8_8
:
1328 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1329 case GL_UNSIGNED_INT_10_10_10_2
:
1330 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1331 if (format
== GL_RGBA
||
1332 format
== GL_BGRA
||
1333 format
== GL_ABGR_EXT
) {
1336 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1337 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1340 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1341 ctx
->API
== API_OPENGLES2
) {
1342 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1344 return GL_INVALID_OPERATION
;
1346 case GL_UNSIGNED_INT_24_8
:
1347 if (format
!= GL_DEPTH_STENCIL
) {
1348 return GL_INVALID_OPERATION
;
1352 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1353 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1354 return GL_INVALID_ENUM
;
1356 if (format
!= GL_DEPTH_STENCIL
) {
1357 return GL_INVALID_OPERATION
;
1361 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1362 if (!ctx
->Extensions
.EXT_packed_float
) {
1363 return GL_INVALID_ENUM
;
1365 if (format
!= GL_RGB
) {
1366 return GL_INVALID_OPERATION
;
1371 ; /* fall-through */
1374 /* now, for each format, check the type for compatibility */
1376 case GL_COLOR_INDEX
:
1377 case GL_STENCIL_INDEX
:
1381 case GL_UNSIGNED_BYTE
:
1383 case GL_UNSIGNED_SHORT
:
1385 case GL_UNSIGNED_INT
:
1390 return GL_INVALID_ENUM
;
1397 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1401 case GL_LUMINANCE_ALPHA
:
1402 case GL_DEPTH_COMPONENT
:
1405 case GL_UNSIGNED_BYTE
:
1407 case GL_UNSIGNED_SHORT
:
1409 case GL_UNSIGNED_INT
:
1414 return GL_INVALID_ENUM
;
1418 if (!ctx
->Extensions
.ARB_texture_rg
)
1419 return GL_INVALID_ENUM
;
1422 case GL_UNSIGNED_BYTE
:
1424 case GL_UNSIGNED_SHORT
:
1426 case GL_UNSIGNED_INT
:
1431 return GL_INVALID_ENUM
;
1437 case GL_UNSIGNED_BYTE
:
1439 case GL_UNSIGNED_SHORT
:
1441 case GL_UNSIGNED_INT
:
1443 case GL_UNSIGNED_BYTE_3_3_2
:
1444 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1445 case GL_UNSIGNED_SHORT_5_6_5
:
1446 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1449 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1450 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1451 return (ctx
->API
== API_OPENGLES2
)
1452 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1453 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1454 return ctx
->Extensions
.EXT_texture_shared_exponent
1455 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1456 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1457 return ctx
->Extensions
.EXT_packed_float
1458 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1460 return GL_INVALID_ENUM
;
1465 /* NOTE: no packed types are supported with BGR. That's
1466 * intentional, according to the GL spec.
1469 case GL_UNSIGNED_BYTE
:
1471 case GL_UNSIGNED_SHORT
:
1473 case GL_UNSIGNED_INT
:
1478 return GL_INVALID_ENUM
;
1486 case GL_UNSIGNED_BYTE
:
1488 case GL_UNSIGNED_SHORT
:
1490 case GL_UNSIGNED_INT
:
1492 case GL_UNSIGNED_SHORT_4_4_4_4
:
1493 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1494 case GL_UNSIGNED_SHORT_5_5_5_1
:
1495 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1496 case GL_UNSIGNED_INT_8_8_8_8
:
1497 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1498 case GL_UNSIGNED_INT_10_10_10_2
:
1499 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1503 return GL_INVALID_ENUM
;
1507 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1508 return GL_INVALID_ENUM
;
1509 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1510 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1513 return GL_INVALID_OPERATION
;
1515 case GL_DEPTH_STENCIL
:
1516 if (type
== GL_UNSIGNED_INT_24_8
)
1518 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1519 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1522 return GL_INVALID_ENUM
;
1524 /* integer-valued formats */
1525 case GL_RED_INTEGER_EXT
:
1526 case GL_GREEN_INTEGER_EXT
:
1527 case GL_BLUE_INTEGER_EXT
:
1528 case GL_ALPHA_INTEGER_EXT
:
1532 case GL_UNSIGNED_BYTE
:
1534 case GL_UNSIGNED_SHORT
:
1536 case GL_UNSIGNED_INT
:
1537 return (ctx
->Version
>= 30 ||
1538 ctx
->Extensions
.EXT_texture_integer
)
1539 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1541 return GL_INVALID_ENUM
;
1544 case GL_RGB_INTEGER_EXT
:
1547 case GL_UNSIGNED_BYTE
:
1549 case GL_UNSIGNED_SHORT
:
1551 case GL_UNSIGNED_INT
:
1552 return (ctx
->Version
>= 30 ||
1553 ctx
->Extensions
.EXT_texture_integer
)
1554 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1555 case GL_UNSIGNED_BYTE_3_3_2
:
1556 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1557 case GL_UNSIGNED_SHORT_5_6_5
:
1558 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1559 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1560 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1562 return GL_INVALID_ENUM
;
1565 case GL_BGR_INTEGER_EXT
:
1568 case GL_UNSIGNED_BYTE
:
1570 case GL_UNSIGNED_SHORT
:
1572 case GL_UNSIGNED_INT
:
1573 /* NOTE: no packed formats w/ BGR format */
1574 return (ctx
->Version
>= 30 ||
1575 ctx
->Extensions
.EXT_texture_integer
)
1576 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1578 return GL_INVALID_ENUM
;
1581 case GL_RGBA_INTEGER_EXT
:
1582 case GL_BGRA_INTEGER_EXT
:
1585 case GL_UNSIGNED_BYTE
:
1587 case GL_UNSIGNED_SHORT
:
1589 case GL_UNSIGNED_INT
:
1590 return (ctx
->Version
>= 30 ||
1591 ctx
->Extensions
.EXT_texture_integer
)
1592 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1593 case GL_UNSIGNED_SHORT_4_4_4_4
:
1594 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1595 case GL_UNSIGNED_SHORT_5_5_5_1
:
1596 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1597 case GL_UNSIGNED_INT_8_8_8_8
:
1598 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1599 case GL_UNSIGNED_INT_10_10_10_2
:
1600 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1601 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1602 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1604 return GL_INVALID_ENUM
;
1607 case GL_LUMINANCE_INTEGER_EXT
:
1608 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1611 case GL_UNSIGNED_BYTE
:
1613 case GL_UNSIGNED_SHORT
:
1615 case GL_UNSIGNED_INT
:
1616 return ctx
->Extensions
.EXT_texture_integer
1617 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1619 return GL_INVALID_ENUM
;
1623 return GL_INVALID_ENUM
;
1630 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1631 * and glTex[Sub]Image.
1632 * \return error code, or GL_NO_ERROR.
1635 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1636 unsigned dimensions
)
1638 GLboolean type_valid
= GL_TRUE
;
1643 case GL_LUMINANCE_ALPHA
:
1644 type_valid
= (type
== GL_UNSIGNED_BYTE
1646 || type
== GL_HALF_FLOAT_OES
);
1650 type_valid
= (type
== GL_UNSIGNED_BYTE
1651 || type
== GL_UNSIGNED_SHORT_5_6_5
1653 || type
== GL_HALF_FLOAT_OES
);
1657 type_valid
= (type
== GL_UNSIGNED_BYTE
1658 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1659 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1661 || type
== GL_HALF_FLOAT_OES
1662 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1665 case GL_DEPTH_COMPONENT
:
1666 /* This format is filtered against invalid dimensionalities elsewhere.
1668 type_valid
= (type
== GL_UNSIGNED_SHORT
1669 || type
== GL_UNSIGNED_INT
);
1672 case GL_DEPTH_STENCIL
:
1673 /* This format is filtered against invalid dimensionalities elsewhere.
1675 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1679 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1681 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1682 * the format does not appear to be allowed for 3D textures in OpenGL
1685 if (dimensions
!= 2)
1686 return GL_INVALID_VALUE
;
1691 return GL_INVALID_VALUE
;
1694 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1699 * Do error checking of format/type combinations for OpenGL ES 3
1701 * \return error code, or GL_NO_ERROR.
1704 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1705 GLenum internalFormat
)
1710 case GL_UNSIGNED_BYTE
:
1711 switch (internalFormat
) {
1716 case GL_SRGB8_ALPHA8_EXT
:
1719 return GL_INVALID_OPERATION
;
1724 if (internalFormat
!= GL_RGBA8_SNORM
)
1725 return GL_INVALID_OPERATION
;
1728 case GL_UNSIGNED_SHORT_4_4_4_4
:
1729 switch (internalFormat
) {
1734 return GL_INVALID_OPERATION
;
1738 case GL_UNSIGNED_SHORT_5_5_5_1
:
1739 switch (internalFormat
) {
1744 return GL_INVALID_OPERATION
;
1748 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1749 switch (internalFormat
) {
1750 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1755 return GL_INVALID_OPERATION
;
1760 if (internalFormat
!= GL_RGBA16F
)
1761 return GL_INVALID_OPERATION
;
1765 switch (internalFormat
) {
1770 return GL_INVALID_OPERATION
;
1775 return GL_INVALID_OPERATION
;
1779 case GL_RGBA_INTEGER
:
1781 case GL_UNSIGNED_BYTE
:
1782 if (internalFormat
!= GL_RGBA8UI
)
1783 return GL_INVALID_OPERATION
;
1787 if (internalFormat
!= GL_RGBA8I
)
1788 return GL_INVALID_OPERATION
;
1791 case GL_UNSIGNED_SHORT
:
1792 if (internalFormat
!= GL_RGBA16UI
)
1793 return GL_INVALID_OPERATION
;
1797 if (internalFormat
!= GL_RGBA16I
)
1798 return GL_INVALID_OPERATION
;
1801 case GL_UNSIGNED_INT
:
1802 if (internalFormat
!= GL_RGBA32UI
)
1803 return GL_INVALID_OPERATION
;
1807 if (internalFormat
!= GL_RGBA32I
)
1808 return GL_INVALID_OPERATION
;
1811 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1812 if (internalFormat
!= GL_RGB10_A2UI
)
1813 return GL_INVALID_OPERATION
;
1817 return GL_INVALID_OPERATION
;
1823 case GL_UNSIGNED_BYTE
:
1824 switch (internalFormat
) {
1831 return GL_INVALID_OPERATION
;
1836 if (internalFormat
!= GL_RGB8_SNORM
)
1837 return GL_INVALID_OPERATION
;
1840 case GL_UNSIGNED_SHORT_5_6_5
:
1841 switch (internalFormat
) {
1846 return GL_INVALID_OPERATION
;
1850 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1851 if (internalFormat
!= GL_R11F_G11F_B10F
)
1852 return GL_INVALID_OPERATION
;
1855 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1856 if (internalFormat
!= GL_RGB9_E5
)
1857 return GL_INVALID_OPERATION
;
1861 switch (internalFormat
) {
1863 case GL_R11F_G11F_B10F
:
1867 return GL_INVALID_OPERATION
;
1872 switch (internalFormat
) {
1875 case GL_R11F_G11F_B10F
:
1879 return GL_INVALID_OPERATION
;
1883 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1884 switch (internalFormat
) {
1885 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1888 return GL_INVALID_OPERATION
;
1893 return GL_INVALID_OPERATION
;
1897 case GL_RGB_INTEGER
:
1899 case GL_UNSIGNED_BYTE
:
1900 if (internalFormat
!= GL_RGB8UI
)
1901 return GL_INVALID_OPERATION
;
1905 if (internalFormat
!= GL_RGB8I
)
1906 return GL_INVALID_OPERATION
;
1909 case GL_UNSIGNED_SHORT
:
1910 if (internalFormat
!= GL_RGB16UI
)
1911 return GL_INVALID_OPERATION
;
1915 if (internalFormat
!= GL_RGB16I
)
1916 return GL_INVALID_OPERATION
;
1919 case GL_UNSIGNED_INT
:
1920 if (internalFormat
!= GL_RGB32UI
)
1921 return GL_INVALID_OPERATION
;
1925 if (internalFormat
!= GL_RGB32I
)
1926 return GL_INVALID_OPERATION
;
1930 return GL_INVALID_OPERATION
;
1936 case GL_UNSIGNED_BYTE
:
1937 if (internalFormat
!= GL_RG8
)
1938 return GL_INVALID_OPERATION
;
1942 if (internalFormat
!= GL_RG8_SNORM
)
1943 return GL_INVALID_OPERATION
;
1947 if (internalFormat
!= GL_RG16F
)
1948 return GL_INVALID_OPERATION
;
1952 switch (internalFormat
) {
1957 return GL_INVALID_OPERATION
;
1962 return GL_INVALID_OPERATION
;
1968 case GL_UNSIGNED_BYTE
:
1969 if (internalFormat
!= GL_RG8UI
)
1970 return GL_INVALID_OPERATION
;
1974 if (internalFormat
!= GL_RG8I
)
1975 return GL_INVALID_OPERATION
;
1978 case GL_UNSIGNED_SHORT
:
1979 if (internalFormat
!= GL_RG16UI
)
1980 return GL_INVALID_OPERATION
;
1984 if (internalFormat
!= GL_RG16I
)
1985 return GL_INVALID_OPERATION
;
1988 case GL_UNSIGNED_INT
:
1989 if (internalFormat
!= GL_RG32UI
)
1990 return GL_INVALID_OPERATION
;
1994 if (internalFormat
!= GL_RG32I
)
1995 return GL_INVALID_OPERATION
;
1999 return GL_INVALID_OPERATION
;
2005 case GL_UNSIGNED_BYTE
:
2006 if (internalFormat
!= GL_R8
)
2007 return GL_INVALID_OPERATION
;
2011 if (internalFormat
!= GL_R8_SNORM
)
2012 return GL_INVALID_OPERATION
;
2016 if (internalFormat
!= GL_R16F
)
2017 return GL_INVALID_OPERATION
;
2021 switch (internalFormat
) {
2026 return GL_INVALID_OPERATION
;
2031 return GL_INVALID_OPERATION
;
2035 case GL_RED_INTEGER
:
2037 case GL_UNSIGNED_BYTE
:
2038 if (internalFormat
!= GL_R8UI
)
2039 return GL_INVALID_OPERATION
;
2043 if (internalFormat
!= GL_R8I
)
2044 return GL_INVALID_OPERATION
;
2047 case GL_UNSIGNED_SHORT
:
2048 if (internalFormat
!= GL_R16UI
)
2049 return GL_INVALID_OPERATION
;
2053 if (internalFormat
!= GL_R16I
)
2054 return GL_INVALID_OPERATION
;
2057 case GL_UNSIGNED_INT
:
2058 if (internalFormat
!= GL_R32UI
)
2059 return GL_INVALID_OPERATION
;
2063 if (internalFormat
!= GL_R32I
)
2064 return GL_INVALID_OPERATION
;
2068 return GL_INVALID_OPERATION
;
2072 case GL_DEPTH_COMPONENT
:
2074 case GL_UNSIGNED_SHORT
:
2075 if (internalFormat
!= GL_DEPTH_COMPONENT
2076 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2077 return GL_INVALID_OPERATION
;
2080 case GL_UNSIGNED_INT
:
2081 switch (internalFormat
) {
2082 case GL_DEPTH_COMPONENT
:
2083 case GL_DEPTH_COMPONENT16
:
2084 case GL_DEPTH_COMPONENT24
:
2087 return GL_INVALID_OPERATION
;
2092 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2093 return GL_INVALID_OPERATION
;
2097 return GL_INVALID_OPERATION
;
2101 case GL_DEPTH_STENCIL
:
2103 case GL_UNSIGNED_INT_24_8
:
2104 if (internalFormat
!= GL_DEPTH_STENCIL
2105 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2106 return GL_INVALID_OPERATION
;
2109 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2110 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2111 return GL_INVALID_OPERATION
;
2115 return GL_INVALID_OPERATION
;
2121 case GL_LUMINANCE_ALPHA
:
2122 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2123 return GL_INVALID_OPERATION
;