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
:
199 case GL_RGB_INTEGER_EXT
:
200 case GL_BGR_INTEGER_EXT
:
206 case GL_RGBA_INTEGER_EXT
:
207 case GL_BGRA_INTEGER_EXT
:
217 * Get the bytes per pixel of pixel format type pair.
219 * \param format pixel format.
220 * \param type pixel type.
222 * \return bytes per pixel, or -1 if a bad format or type was given.
225 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
227 GLint comps
= _mesa_components_in_format(format
);
233 return 0; /* special case */
235 case GL_UNSIGNED_BYTE
:
236 return comps
* sizeof(GLubyte
);
238 case GL_UNSIGNED_SHORT
:
239 return comps
* sizeof(GLshort
);
241 case GL_UNSIGNED_INT
:
242 return comps
* sizeof(GLint
);
244 return comps
* sizeof(GLfloat
);
245 case GL_HALF_FLOAT_ARB
:
246 return comps
* sizeof(GLhalfARB
);
247 case GL_UNSIGNED_BYTE_3_3_2
:
248 case GL_UNSIGNED_BYTE_2_3_3_REV
:
249 if (format
== GL_RGB
|| format
== GL_BGR
||
250 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
251 return sizeof(GLubyte
);
253 return -1; /* error */
254 case GL_UNSIGNED_SHORT_5_6_5
:
255 case GL_UNSIGNED_SHORT_5_6_5_REV
:
256 if (format
== GL_RGB
|| format
== GL_BGR
||
257 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
258 return sizeof(GLushort
);
260 return -1; /* error */
261 case GL_UNSIGNED_SHORT_4_4_4_4
:
262 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
263 case GL_UNSIGNED_SHORT_5_5_5_1
:
264 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
265 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
266 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
267 return sizeof(GLushort
);
270 case GL_UNSIGNED_INT_8_8_8_8
:
271 case GL_UNSIGNED_INT_8_8_8_8_REV
:
272 case GL_UNSIGNED_INT_10_10_10_2
:
273 case GL_UNSIGNED_INT_2_10_10_10_REV
:
274 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
275 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
277 return sizeof(GLuint
);
280 case GL_UNSIGNED_SHORT_8_8_MESA
:
281 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
282 if (format
== GL_YCBCR_MESA
)
283 return sizeof(GLushort
);
286 case GL_UNSIGNED_INT_24_8_EXT
:
287 if (format
== GL_DEPTH_STENCIL_EXT
)
288 return sizeof(GLuint
);
291 case GL_UNSIGNED_INT_5_9_9_9_REV
:
292 if (format
== GL_RGB
)
293 return sizeof(GLuint
);
296 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
297 if (format
== GL_RGB
)
298 return sizeof(GLuint
);
301 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
302 if (format
== GL_DEPTH_STENCIL
)
313 * Get the number of bytes for a vertex attrib with the given number of
314 * components and type.
316 * \param comps number of components.
317 * \param type data type.
319 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
322 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
326 case GL_UNSIGNED_BYTE
:
327 return comps
* sizeof(GLubyte
);
329 case GL_UNSIGNED_SHORT
:
330 return comps
* sizeof(GLshort
);
332 case GL_UNSIGNED_INT
:
333 return comps
* sizeof(GLint
);
335 return comps
* sizeof(GLfloat
);
336 case GL_HALF_FLOAT_ARB
:
337 return comps
* sizeof(GLhalfARB
);
339 return comps
* sizeof(GLdouble
);
341 return comps
* sizeof(GLfixed
);
342 case GL_INT_2_10_10_10_REV
:
343 case GL_UNSIGNED_INT_2_10_10_10_REV
:
345 return sizeof(GLuint
);
348 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
350 return sizeof(GLuint
);
360 * Test if the given format is an integer (non-normalized) format.
363 _mesa_is_enum_format_unsigned_int(GLenum format
)
366 /* specific integer formats */
367 case GL_RGBA32UI_EXT
:
371 case GL_ALPHA32UI_EXT
:
372 case GL_INTENSITY32UI_EXT
:
373 case GL_LUMINANCE32UI_EXT
:
374 case GL_LUMINANCE_ALPHA32UI_EXT
:
375 case GL_RGBA16UI_EXT
:
379 case GL_ALPHA16UI_EXT
:
380 case GL_INTENSITY16UI_EXT
:
381 case GL_LUMINANCE16UI_EXT
:
382 case GL_LUMINANCE_ALPHA16UI_EXT
:
387 case GL_ALPHA8UI_EXT
:
388 case GL_INTENSITY8UI_EXT
:
389 case GL_LUMINANCE8UI_EXT
:
390 case GL_LUMINANCE_ALPHA8UI_EXT
:
400 * Test if the given format is an integer (non-normalized) format.
403 _mesa_is_enum_format_signed_int(GLenum format
)
406 /* generic integer formats */
407 case GL_RED_INTEGER_EXT
:
408 case GL_GREEN_INTEGER_EXT
:
409 case GL_BLUE_INTEGER_EXT
:
410 case GL_ALPHA_INTEGER_EXT
:
411 case GL_RGB_INTEGER_EXT
:
412 case GL_RGBA_INTEGER_EXT
:
413 case GL_BGR_INTEGER_EXT
:
414 case GL_BGRA_INTEGER_EXT
:
415 case GL_LUMINANCE_INTEGER_EXT
:
416 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
418 /* specific integer formats */
423 case GL_ALPHA32I_EXT
:
424 case GL_INTENSITY32I_EXT
:
425 case GL_LUMINANCE32I_EXT
:
426 case GL_LUMINANCE_ALPHA32I_EXT
:
431 case GL_ALPHA16I_EXT
:
432 case GL_INTENSITY16I_EXT
:
433 case GL_LUMINANCE16I_EXT
:
434 case GL_LUMINANCE_ALPHA16I_EXT
:
440 case GL_INTENSITY8I_EXT
:
441 case GL_LUMINANCE8I_EXT
:
442 case GL_LUMINANCE_ALPHA8I_EXT
:
451 * Test if the given format is an integer (non-normalized) format.
454 _mesa_is_enum_format_integer(GLenum format
)
456 return _mesa_is_enum_format_unsigned_int(format
) ||
457 _mesa_is_enum_format_signed_int(format
);
462 * Test if the given type is an integer (non-normalized) format.
465 _mesa_is_type_integer(GLenum type
)
469 case GL_UNSIGNED_INT
:
471 case GL_UNSIGNED_SHORT
:
473 case GL_UNSIGNED_BYTE
:
482 * Test if the given format or type is an integer (non-normalized) format.
485 _mesa_is_enum_format_or_type_integer(GLenum format
, GLenum type
)
487 return _mesa_is_enum_format_integer(format
) || _mesa_is_type_integer(type
);
492 _mesa_is_type_unsigned(GLenum type
)
495 case GL_UNSIGNED_INT
:
496 case GL_UNSIGNED_INT_8_8_8_8
:
497 case GL_UNSIGNED_INT_8_8_8_8_REV
:
498 case GL_UNSIGNED_INT_10_10_10_2
:
499 case GL_UNSIGNED_INT_2_10_10_10_REV
:
501 case GL_UNSIGNED_SHORT
:
502 case GL_UNSIGNED_SHORT_4_4_4_4
:
503 case GL_UNSIGNED_SHORT_5_5_5_1
:
504 case GL_UNSIGNED_SHORT_5_6_5
:
505 case GL_UNSIGNED_SHORT_5_6_5_REV
:
506 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
507 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
508 case GL_UNSIGNED_SHORT_8_8_MESA
:
509 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
511 case GL_UNSIGNED_BYTE
:
512 case GL_UNSIGNED_BYTE_3_3_2
:
513 case GL_UNSIGNED_BYTE_2_3_3_REV
:
523 * Test if the given image format is a color/RGBA format (i.e., not color
524 * index, depth, stencil, etc).
525 * \param format the image format value (may by an internal texture format)
526 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
529 _mesa_is_color_format(GLenum format
)
547 case GL_LUMINANCE_ALPHA
:
548 case GL_LUMINANCE4_ALPHA4
:
549 case GL_LUMINANCE6_ALPHA2
:
550 case GL_LUMINANCE8_ALPHA8
:
551 case GL_LUMINANCE12_ALPHA4
:
552 case GL_LUMINANCE12_ALPHA12
:
553 case GL_LUMINANCE16_ALPHA16
:
586 /* float texture formats */
587 case GL_ALPHA16F_ARB
:
588 case GL_ALPHA32F_ARB
:
589 case GL_LUMINANCE16F_ARB
:
590 case GL_LUMINANCE32F_ARB
:
591 case GL_LUMINANCE_ALPHA16F_ARB
:
592 case GL_LUMINANCE_ALPHA32F_ARB
:
593 case GL_INTENSITY16F_ARB
:
594 case GL_INTENSITY32F_ARB
:
603 /* compressed formats */
604 case GL_COMPRESSED_ALPHA
:
605 case GL_COMPRESSED_LUMINANCE
:
606 case GL_COMPRESSED_LUMINANCE_ALPHA
:
607 case GL_COMPRESSED_INTENSITY
:
608 case GL_COMPRESSED_RED
:
609 case GL_COMPRESSED_RG
:
610 case GL_COMPRESSED_RGB
:
611 case GL_COMPRESSED_RGBA
:
616 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
617 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
618 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
619 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
620 case GL_COMPRESSED_RGB_FXT1_3DFX
:
621 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
624 case GL_SRGB_ALPHA_EXT
:
625 case GL_SRGB8_ALPHA8_EXT
:
626 case GL_SLUMINANCE_ALPHA_EXT
:
627 case GL_SLUMINANCE8_ALPHA8_EXT
:
628 case GL_SLUMINANCE_EXT
:
629 case GL_SLUMINANCE8_EXT
:
630 case GL_COMPRESSED_SRGB_EXT
:
631 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
632 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
633 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
634 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
635 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
636 case GL_COMPRESSED_SLUMINANCE_EXT
:
637 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
638 case GL_COMPRESSED_RED_RGTC1
:
639 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
640 case GL_COMPRESSED_RG_RGTC2
:
641 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
642 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
643 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
644 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
645 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
646 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
647 case GL_ETC1_RGB8_OES
:
648 case GL_COMPRESSED_RGB8_ETC2
:
649 case GL_COMPRESSED_SRGB8_ETC2
:
650 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
651 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
652 case GL_COMPRESSED_R11_EAC
:
653 case GL_COMPRESSED_RG11_EAC
:
654 case GL_COMPRESSED_SIGNED_R11_EAC
:
655 case GL_COMPRESSED_SIGNED_RG11_EAC
:
656 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
657 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
658 /* generic integer formats */
659 case GL_RED_INTEGER_EXT
:
660 case GL_GREEN_INTEGER_EXT
:
661 case GL_BLUE_INTEGER_EXT
:
662 case GL_ALPHA_INTEGER_EXT
:
663 case GL_RGB_INTEGER_EXT
:
664 case GL_RGBA_INTEGER_EXT
:
665 case GL_BGR_INTEGER_EXT
:
666 case GL_BGRA_INTEGER_EXT
:
668 case GL_LUMINANCE_INTEGER_EXT
:
669 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
670 /* sized integer formats */
671 case GL_RGBA32UI_EXT
:
675 case GL_ALPHA32UI_EXT
:
676 case GL_INTENSITY32UI_EXT
:
677 case GL_LUMINANCE32UI_EXT
:
678 case GL_LUMINANCE_ALPHA32UI_EXT
:
679 case GL_RGBA16UI_EXT
:
683 case GL_ALPHA16UI_EXT
:
684 case GL_INTENSITY16UI_EXT
:
685 case GL_LUMINANCE16UI_EXT
:
686 case GL_LUMINANCE_ALPHA16UI_EXT
:
691 case GL_ALPHA8UI_EXT
:
692 case GL_INTENSITY8UI_EXT
:
693 case GL_LUMINANCE8UI_EXT
:
694 case GL_LUMINANCE_ALPHA8UI_EXT
:
699 case GL_ALPHA32I_EXT
:
700 case GL_INTENSITY32I_EXT
:
701 case GL_LUMINANCE32I_EXT
:
702 case GL_LUMINANCE_ALPHA32I_EXT
:
707 case GL_ALPHA16I_EXT
:
708 case GL_INTENSITY16I_EXT
:
709 case GL_LUMINANCE16I_EXT
:
710 case GL_LUMINANCE_ALPHA16I_EXT
:
716 case GL_INTENSITY8I_EXT
:
717 case GL_LUMINANCE8I_EXT
:
718 case GL_LUMINANCE_ALPHA8I_EXT
:
719 /* signed, normalized texture formats */
731 case GL_RGBA16_SNORM
:
733 case GL_ALPHA8_SNORM
:
734 case GL_ALPHA16_SNORM
:
735 case GL_LUMINANCE_SNORM
:
736 case GL_LUMINANCE8_SNORM
:
737 case GL_LUMINANCE16_SNORM
:
738 case GL_LUMINANCE_ALPHA_SNORM
:
739 case GL_LUMINANCE8_ALPHA8_SNORM
:
740 case GL_LUMINANCE16_ALPHA16_SNORM
:
741 case GL_INTENSITY_SNORM
:
742 case GL_INTENSITY8_SNORM
:
743 case GL_INTENSITY16_SNORM
:
745 case GL_R11F_G11F_B10F
:
748 case GL_YCBCR_MESA
: /* not considered to be RGB */
757 * Test if the given image format is a depth component format.
760 _mesa_is_depth_format(GLenum format
)
763 case GL_DEPTH_COMPONENT
:
764 case GL_DEPTH_COMPONENT16
:
765 case GL_DEPTH_COMPONENT24
:
766 case GL_DEPTH_COMPONENT32
:
767 case GL_DEPTH_COMPONENT32F
:
776 * Test if the given image format is a stencil format.
779 _mesa_is_stencil_format(GLenum format
)
782 case GL_STENCIL_INDEX
:
791 * Test if the given image format is a YCbCr format.
794 _mesa_is_ycbcr_format(GLenum format
)
806 * Test if the given image format is a depth+stencil format.
809 _mesa_is_depthstencil_format(GLenum format
)
812 case GL_DEPTH24_STENCIL8_EXT
:
813 case GL_DEPTH_STENCIL_EXT
:
814 case GL_DEPTH32F_STENCIL8
:
823 * Test if the given image format is a depth or stencil format.
826 _mesa_is_depth_or_stencil_format(GLenum format
)
829 case GL_DEPTH_COMPONENT
:
830 case GL_DEPTH_COMPONENT16
:
831 case GL_DEPTH_COMPONENT24
:
832 case GL_DEPTH_COMPONENT32
:
833 case GL_STENCIL_INDEX
:
834 case GL_STENCIL_INDEX1_EXT
:
835 case GL_STENCIL_INDEX4_EXT
:
836 case GL_STENCIL_INDEX8_EXT
:
837 case GL_STENCIL_INDEX16_EXT
:
838 case GL_DEPTH_STENCIL_EXT
:
839 case GL_DEPTH24_STENCIL8_EXT
:
840 case GL_DEPTH_COMPONENT32F
:
841 case GL_DEPTH32F_STENCIL8
:
850 * Test if the given image format is a dudv format.
853 _mesa_is_dudv_format(GLenum format
)
866 * Test if an image format is a supported compressed format.
867 * \param format the internal format token provided by the user.
868 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
871 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
874 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
875 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
876 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
877 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
878 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
880 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
885 return _mesa_is_desktop_gl(ctx
) &&
886 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
887 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
888 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
889 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
890 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
891 return _mesa_is_desktop_gl(ctx
)
892 && ctx
->Extensions
.EXT_texture_sRGB
893 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
894 case GL_COMPRESSED_RGB_FXT1_3DFX
:
895 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
896 return _mesa_is_desktop_gl(ctx
)
897 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
898 case GL_COMPRESSED_RED_RGTC1
:
899 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
900 case GL_COMPRESSED_RG_RGTC2
:
901 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
902 return _mesa_is_desktop_gl(ctx
)
903 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
904 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
905 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
906 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
907 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
908 return ctx
->API
== API_OPENGL_COMPAT
909 && ctx
->Extensions
.EXT_texture_compression_latc
;
910 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
911 return ctx
->API
== API_OPENGL_COMPAT
912 && ctx
->Extensions
.ATI_texture_compression_3dc
;
913 case GL_ETC1_RGB8_OES
:
914 return _mesa_is_gles(ctx
)
915 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
916 case GL_COMPRESSED_RGB8_ETC2
:
917 case GL_COMPRESSED_SRGB8_ETC2
:
918 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
919 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
920 case GL_COMPRESSED_R11_EAC
:
921 case GL_COMPRESSED_RG11_EAC
:
922 case GL_COMPRESSED_SIGNED_R11_EAC
:
923 case GL_COMPRESSED_SIGNED_RG11_EAC
:
924 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
925 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
926 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
927 case GL_PALETTE4_RGB8_OES
:
928 case GL_PALETTE4_RGBA8_OES
:
929 case GL_PALETTE4_R5_G6_B5_OES
:
930 case GL_PALETTE4_RGBA4_OES
:
931 case GL_PALETTE4_RGB5_A1_OES
:
932 case GL_PALETTE8_RGB8_OES
:
933 case GL_PALETTE8_RGBA8_OES
:
934 case GL_PALETTE8_R5_G6_B5_OES
:
935 case GL_PALETTE8_RGBA4_OES
:
936 case GL_PALETTE8_RGB5_A1_OES
:
937 return ctx
->API
== API_OPENGLES
;
945 * Convert various base formats to the cooresponding integer format.
948 _mesa_base_format_to_integer_format(GLenum format
)
952 return GL_RED_INTEGER
;
954 return GL_GREEN_INTEGER
;
956 return GL_BLUE_INTEGER
;
958 return GL_RG_INTEGER
;
960 return GL_RGB_INTEGER
;
962 return GL_RGBA_INTEGER
;
964 return GL_BGR_INTEGER
;
966 return GL_BGRA_INTEGER
;
968 return GL_ALPHA_INTEGER
;
970 return GL_LUMINANCE_INTEGER_EXT
;
971 case GL_LUMINANCE_ALPHA
:
972 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
980 * Does the given base texture/renderbuffer format have the channel
984 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
987 case GL_TEXTURE_RED_SIZE
:
988 case GL_TEXTURE_RED_TYPE
:
989 case GL_RENDERBUFFER_RED_SIZE_EXT
:
990 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
991 if (base_format
== GL_RED
||
992 base_format
== GL_RG
||
993 base_format
== GL_RGB
||
994 base_format
== GL_RGBA
) {
998 case GL_TEXTURE_GREEN_SIZE
:
999 case GL_TEXTURE_GREEN_TYPE
:
1000 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1001 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1002 if (base_format
== GL_RG
||
1003 base_format
== GL_RGB
||
1004 base_format
== GL_RGBA
) {
1008 case GL_TEXTURE_BLUE_SIZE
:
1009 case GL_TEXTURE_BLUE_TYPE
:
1010 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1011 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1012 if (base_format
== GL_RGB
||
1013 base_format
== GL_RGBA
) {
1017 case GL_TEXTURE_ALPHA_SIZE
:
1018 case GL_TEXTURE_ALPHA_TYPE
:
1019 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1020 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1021 if (base_format
== GL_RGBA
||
1022 base_format
== GL_ALPHA
||
1023 base_format
== GL_LUMINANCE_ALPHA
) {
1027 case GL_TEXTURE_LUMINANCE_SIZE
:
1028 case GL_TEXTURE_LUMINANCE_TYPE
:
1029 if (base_format
== GL_LUMINANCE
||
1030 base_format
== GL_LUMINANCE_ALPHA
) {
1034 case GL_TEXTURE_INTENSITY_SIZE
:
1035 case GL_TEXTURE_INTENSITY_TYPE
:
1036 if (base_format
== GL_INTENSITY
) {
1040 case GL_TEXTURE_DEPTH_SIZE
:
1041 case GL_TEXTURE_DEPTH_TYPE
:
1042 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1043 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1044 if (base_format
== GL_DEPTH_STENCIL
||
1045 base_format
== GL_DEPTH_COMPONENT
) {
1049 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1050 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1051 if (base_format
== GL_DEPTH_STENCIL
||
1052 base_format
== GL_STENCIL_INDEX
) {
1057 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1058 __FUNCTION__
, pname
);
1067 * Returns the number of channels/components for a base format.
1070 _mesa_base_format_component_count(GLenum base_format
)
1072 switch (base_format
) {
1076 case GL_DEPTH_COMPONENT
:
1079 case GL_LUMINANCE_ALPHA
:
1080 case GL_DEPTH_STENCIL
:
1093 * If format is a generic compressed format, return the corresponding
1094 * non-compressed format. For other formats, return the format as-is.
1097 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1100 case GL_COMPRESSED_RED
:
1102 case GL_COMPRESSED_RG
:
1104 case GL_COMPRESSED_RGB
:
1106 case GL_COMPRESSED_RGBA
:
1108 case GL_COMPRESSED_ALPHA
:
1110 case GL_COMPRESSED_LUMINANCE
:
1111 return GL_LUMINANCE
;
1112 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1113 return GL_LUMINANCE_ALPHA
;
1114 case GL_COMPRESSED_INTENSITY
:
1115 return GL_INTENSITY
;
1117 case GL_COMPRESSED_SRGB
:
1119 case GL_COMPRESSED_SRGB_ALPHA
:
1120 return GL_SRGB_ALPHA
;
1121 case GL_COMPRESSED_SLUMINANCE
:
1122 return GL_SLUMINANCE
;
1123 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1124 return GL_SLUMINANCE_ALPHA
;
1132 * Return the equivalent non-generic internal format.
1133 * This is useful for comparing whether two internal formats are equivalent.
1136 _mesa_get_nongeneric_internalformat(GLenum format
)
1139 /* GL 1.1 formats. */
1147 case GL_LUMINANCE_ALPHA
:
1148 return GL_LUMINANCE8_ALPHA8
;
1151 return GL_LUMINANCE8
;
1155 return GL_INTENSITY8
;
1157 /* GL_ARB_texture_rg */
1163 /* GL_EXT_texture_sRGB */
1167 return GL_SRGB8_ALPHA8
;
1169 return GL_SLUMINANCE8
;
1170 case GL_SLUMINANCE_ALPHA
:
1171 return GL_SLUMINANCE8_ALPHA8
;
1173 /* GL_EXT_texture_snorm */
1175 return GL_RGBA8_SNORM
;
1177 return GL_RGB8_SNORM
;
1179 return GL_RG8_SNORM
;
1182 case GL_LUMINANCE_ALPHA_SNORM
:
1183 return GL_LUMINANCE8_ALPHA8_SNORM
;
1184 case GL_LUMINANCE_SNORM
:
1185 return GL_LUMINANCE8_SNORM
;
1186 case GL_ALPHA_SNORM
:
1187 return GL_ALPHA8_SNORM
;
1188 case GL_INTENSITY_SNORM
:
1189 return GL_INTENSITY8_SNORM
;
1198 * Convert an sRGB internal format to linear.
1201 _mesa_get_linear_internalformat(GLenum format
)
1210 case GL_SRGB8_ALPHA8
:
1212 case GL_SLUMINANCE8
:
1213 return GL_LUMINANCE8
;
1215 return GL_LUMINANCE
;
1216 case GL_SLUMINANCE_ALPHA
:
1217 return GL_LUMINANCE_ALPHA
;
1218 case GL_SLUMINANCE8_ALPHA8
:
1219 return GL_LUMINANCE8_ALPHA8
;
1227 * Do error checking of format/type combinations for glReadPixels,
1228 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1229 * and type values, we may either generate GL_INVALID_OPERATION or
1232 * \param format pixel format.
1233 * \param type pixel type.
1235 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1238 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1239 GLenum format
, GLenum type
)
1241 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1244 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1245 return GL_INVALID_ENUM
;
1249 case GL_UNSIGNED_BYTE_3_3_2
:
1250 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1251 case GL_UNSIGNED_SHORT_5_6_5
:
1252 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1253 if (format
== GL_RGB
) {
1256 if (format
== GL_RGB_INTEGER_EXT
&&
1257 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1260 return GL_INVALID_OPERATION
;
1262 case GL_UNSIGNED_SHORT_4_4_4_4
:
1263 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1264 case GL_UNSIGNED_SHORT_5_5_5_1
:
1265 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1266 case GL_UNSIGNED_INT_8_8_8_8
:
1267 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1268 case GL_UNSIGNED_INT_10_10_10_2
:
1269 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1270 if (format
== GL_RGBA
||
1271 format
== GL_BGRA
||
1272 format
== GL_ABGR_EXT
) {
1275 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1276 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1279 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1280 ctx
->API
== API_OPENGLES2
) {
1281 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1283 return GL_INVALID_OPERATION
;
1285 case GL_UNSIGNED_INT_24_8
:
1286 if (format
!= GL_DEPTH_STENCIL
) {
1287 return GL_INVALID_OPERATION
;
1291 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1292 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1293 return GL_INVALID_ENUM
;
1295 if (format
!= GL_DEPTH_STENCIL
) {
1296 return GL_INVALID_OPERATION
;
1300 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1301 if (!ctx
->Extensions
.EXT_packed_float
) {
1302 return GL_INVALID_ENUM
;
1304 if (format
!= GL_RGB
) {
1305 return GL_INVALID_OPERATION
;
1310 ; /* fall-through */
1313 /* now, for each format, check the type for compatibility */
1315 case GL_COLOR_INDEX
:
1316 case GL_STENCIL_INDEX
:
1320 case GL_UNSIGNED_BYTE
:
1322 case GL_UNSIGNED_SHORT
:
1324 case GL_UNSIGNED_INT
:
1329 return GL_INVALID_ENUM
;
1336 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1340 case GL_LUMINANCE_ALPHA
:
1341 case GL_DEPTH_COMPONENT
:
1344 case GL_UNSIGNED_BYTE
:
1346 case GL_UNSIGNED_SHORT
:
1348 case GL_UNSIGNED_INT
:
1353 return GL_INVALID_ENUM
;
1357 if (!ctx
->Extensions
.ARB_texture_rg
)
1358 return GL_INVALID_ENUM
;
1361 case GL_UNSIGNED_BYTE
:
1363 case GL_UNSIGNED_SHORT
:
1365 case GL_UNSIGNED_INT
:
1370 return GL_INVALID_ENUM
;
1376 case GL_UNSIGNED_BYTE
:
1378 case GL_UNSIGNED_SHORT
:
1380 case GL_UNSIGNED_INT
:
1382 case GL_UNSIGNED_BYTE_3_3_2
:
1383 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1384 case GL_UNSIGNED_SHORT_5_6_5
:
1385 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1388 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1389 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1390 return (ctx
->API
== API_OPENGLES2
)
1391 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1392 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1393 return ctx
->Extensions
.EXT_texture_shared_exponent
1394 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1395 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1396 return ctx
->Extensions
.EXT_packed_float
1397 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1399 return GL_INVALID_ENUM
;
1404 /* NOTE: no packed types are supported with BGR. That's
1405 * intentional, according to the GL spec.
1408 case GL_UNSIGNED_BYTE
:
1410 case GL_UNSIGNED_SHORT
:
1412 case GL_UNSIGNED_INT
:
1417 return GL_INVALID_ENUM
;
1425 case GL_UNSIGNED_BYTE
:
1427 case GL_UNSIGNED_SHORT
:
1429 case GL_UNSIGNED_INT
:
1431 case GL_UNSIGNED_SHORT_4_4_4_4
:
1432 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1433 case GL_UNSIGNED_SHORT_5_5_5_1
:
1434 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1435 case GL_UNSIGNED_INT_8_8_8_8
:
1436 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1437 case GL_UNSIGNED_INT_10_10_10_2
:
1438 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1442 return GL_INVALID_ENUM
;
1446 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1447 return GL_INVALID_ENUM
;
1448 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1449 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1452 return GL_INVALID_OPERATION
;
1454 case GL_DEPTH_STENCIL
:
1455 if (type
== GL_UNSIGNED_INT_24_8
)
1457 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1458 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1461 return GL_INVALID_ENUM
;
1465 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1466 return GL_INVALID_ENUM
;
1469 case GL_UNSIGNED_BYTE
:
1471 case GL_UNSIGNED_SHORT
:
1473 case GL_UNSIGNED_INT
:
1477 return GL_INVALID_ENUM
;
1480 /* integer-valued formats */
1481 case GL_RED_INTEGER_EXT
:
1482 case GL_GREEN_INTEGER_EXT
:
1483 case GL_BLUE_INTEGER_EXT
:
1484 case GL_ALPHA_INTEGER_EXT
:
1488 case GL_UNSIGNED_BYTE
:
1490 case GL_UNSIGNED_SHORT
:
1492 case GL_UNSIGNED_INT
:
1493 return (ctx
->Version
>= 30 ||
1494 ctx
->Extensions
.EXT_texture_integer
)
1495 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1497 return GL_INVALID_ENUM
;
1500 case GL_RGB_INTEGER_EXT
:
1503 case GL_UNSIGNED_BYTE
:
1505 case GL_UNSIGNED_SHORT
:
1507 case GL_UNSIGNED_INT
:
1508 return (ctx
->Version
>= 30 ||
1509 ctx
->Extensions
.EXT_texture_integer
)
1510 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1511 case GL_UNSIGNED_BYTE_3_3_2
:
1512 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1513 case GL_UNSIGNED_SHORT_5_6_5
:
1514 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1515 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1516 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1518 return GL_INVALID_ENUM
;
1521 case GL_BGR_INTEGER_EXT
:
1524 case GL_UNSIGNED_BYTE
:
1526 case GL_UNSIGNED_SHORT
:
1528 case GL_UNSIGNED_INT
:
1529 /* NOTE: no packed formats w/ BGR format */
1530 return (ctx
->Version
>= 30 ||
1531 ctx
->Extensions
.EXT_texture_integer
)
1532 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1534 return GL_INVALID_ENUM
;
1537 case GL_RGBA_INTEGER_EXT
:
1538 case GL_BGRA_INTEGER_EXT
:
1541 case GL_UNSIGNED_BYTE
:
1543 case GL_UNSIGNED_SHORT
:
1545 case GL_UNSIGNED_INT
:
1546 return (ctx
->Version
>= 30 ||
1547 ctx
->Extensions
.EXT_texture_integer
)
1548 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1549 case GL_UNSIGNED_SHORT_4_4_4_4
:
1550 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1551 case GL_UNSIGNED_SHORT_5_5_5_1
:
1552 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1553 case GL_UNSIGNED_INT_8_8_8_8
:
1554 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1555 case GL_UNSIGNED_INT_10_10_10_2
:
1556 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1557 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1558 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1560 return GL_INVALID_ENUM
;
1563 case GL_LUMINANCE_INTEGER_EXT
:
1564 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1567 case GL_UNSIGNED_BYTE
:
1569 case GL_UNSIGNED_SHORT
:
1571 case GL_UNSIGNED_INT
:
1572 return ctx
->Extensions
.EXT_texture_integer
1573 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1575 return GL_INVALID_ENUM
;
1579 return GL_INVALID_ENUM
;
1586 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1587 * and glTex[Sub]Image.
1588 * \return error code, or GL_NO_ERROR.
1591 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1592 unsigned dimensions
)
1594 GLboolean type_valid
= GL_TRUE
;
1599 case GL_LUMINANCE_ALPHA
:
1600 type_valid
= (type
== GL_UNSIGNED_BYTE
1602 || type
== GL_HALF_FLOAT_OES
);
1606 type_valid
= (type
== GL_UNSIGNED_BYTE
1607 || type
== GL_UNSIGNED_SHORT_5_6_5
1609 || type
== GL_HALF_FLOAT_OES
);
1613 type_valid
= (type
== GL_UNSIGNED_BYTE
1614 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1615 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1617 || type
== GL_HALF_FLOAT_OES
1618 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1621 case GL_DEPTH_COMPONENT
:
1622 /* This format is filtered against invalid dimensionalities elsewhere.
1624 type_valid
= (type
== GL_UNSIGNED_SHORT
1625 || type
== GL_UNSIGNED_INT
);
1628 case GL_DEPTH_STENCIL
:
1629 /* This format is filtered against invalid dimensionalities elsewhere.
1631 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1635 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1637 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1638 * the format does not appear to be allowed for 3D textures in OpenGL
1641 if (dimensions
!= 2)
1642 return GL_INVALID_VALUE
;
1647 return GL_INVALID_VALUE
;
1650 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1655 * Do error checking of format/type combinations for OpenGL ES 3
1657 * \return error code, or GL_NO_ERROR.
1660 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1661 GLenum internalFormat
)
1666 case GL_UNSIGNED_BYTE
:
1667 switch (internalFormat
) {
1672 case GL_SRGB8_ALPHA8_EXT
:
1675 return GL_INVALID_OPERATION
;
1680 if (internalFormat
!= GL_RGBA8_SNORM
)
1681 return GL_INVALID_OPERATION
;
1684 case GL_UNSIGNED_SHORT_4_4_4_4
:
1685 switch (internalFormat
) {
1690 return GL_INVALID_OPERATION
;
1694 case GL_UNSIGNED_SHORT_5_5_5_1
:
1695 switch (internalFormat
) {
1700 return GL_INVALID_OPERATION
;
1704 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1705 switch (internalFormat
) {
1706 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1711 return GL_INVALID_OPERATION
;
1716 if (internalFormat
!= GL_RGBA16F
)
1717 return GL_INVALID_OPERATION
;
1721 switch (internalFormat
) {
1726 return GL_INVALID_OPERATION
;
1731 return GL_INVALID_OPERATION
;
1735 case GL_RGBA_INTEGER
:
1737 case GL_UNSIGNED_BYTE
:
1738 if (internalFormat
!= GL_RGBA8UI
)
1739 return GL_INVALID_OPERATION
;
1743 if (internalFormat
!= GL_RGBA8I
)
1744 return GL_INVALID_OPERATION
;
1747 case GL_UNSIGNED_SHORT
:
1748 if (internalFormat
!= GL_RGBA16UI
)
1749 return GL_INVALID_OPERATION
;
1753 if (internalFormat
!= GL_RGBA16I
)
1754 return GL_INVALID_OPERATION
;
1757 case GL_UNSIGNED_INT
:
1758 if (internalFormat
!= GL_RGBA32UI
)
1759 return GL_INVALID_OPERATION
;
1763 if (internalFormat
!= GL_RGBA32I
)
1764 return GL_INVALID_OPERATION
;
1767 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1768 if (internalFormat
!= GL_RGB10_A2UI
)
1769 return GL_INVALID_OPERATION
;
1773 return GL_INVALID_OPERATION
;
1779 case GL_UNSIGNED_BYTE
:
1780 switch (internalFormat
) {
1787 return GL_INVALID_OPERATION
;
1792 if (internalFormat
!= GL_RGB8_SNORM
)
1793 return GL_INVALID_OPERATION
;
1796 case GL_UNSIGNED_SHORT_5_6_5
:
1797 switch (internalFormat
) {
1802 return GL_INVALID_OPERATION
;
1806 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1807 if (internalFormat
!= GL_R11F_G11F_B10F
)
1808 return GL_INVALID_OPERATION
;
1811 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1812 if (internalFormat
!= GL_RGB9_E5
)
1813 return GL_INVALID_OPERATION
;
1817 switch (internalFormat
) {
1819 case GL_R11F_G11F_B10F
:
1823 return GL_INVALID_OPERATION
;
1828 switch (internalFormat
) {
1831 case GL_R11F_G11F_B10F
:
1835 return GL_INVALID_OPERATION
;
1839 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1840 switch (internalFormat
) {
1841 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1844 return GL_INVALID_OPERATION
;
1849 return GL_INVALID_OPERATION
;
1853 case GL_RGB_INTEGER
:
1855 case GL_UNSIGNED_BYTE
:
1856 if (internalFormat
!= GL_RGB8UI
)
1857 return GL_INVALID_OPERATION
;
1861 if (internalFormat
!= GL_RGB8I
)
1862 return GL_INVALID_OPERATION
;
1865 case GL_UNSIGNED_SHORT
:
1866 if (internalFormat
!= GL_RGB16UI
)
1867 return GL_INVALID_OPERATION
;
1871 if (internalFormat
!= GL_RGB16I
)
1872 return GL_INVALID_OPERATION
;
1875 case GL_UNSIGNED_INT
:
1876 if (internalFormat
!= GL_RGB32UI
)
1877 return GL_INVALID_OPERATION
;
1881 if (internalFormat
!= GL_RGB32I
)
1882 return GL_INVALID_OPERATION
;
1886 return GL_INVALID_OPERATION
;
1892 case GL_UNSIGNED_BYTE
:
1893 if (internalFormat
!= GL_RG8
)
1894 return GL_INVALID_OPERATION
;
1898 if (internalFormat
!= GL_RG8_SNORM
)
1899 return GL_INVALID_OPERATION
;
1903 if (internalFormat
!= GL_RG16F
)
1904 return GL_INVALID_OPERATION
;
1908 switch (internalFormat
) {
1913 return GL_INVALID_OPERATION
;
1918 return GL_INVALID_OPERATION
;
1924 case GL_UNSIGNED_BYTE
:
1925 if (internalFormat
!= GL_RG8UI
)
1926 return GL_INVALID_OPERATION
;
1930 if (internalFormat
!= GL_RG8I
)
1931 return GL_INVALID_OPERATION
;
1934 case GL_UNSIGNED_SHORT
:
1935 if (internalFormat
!= GL_RG16UI
)
1936 return GL_INVALID_OPERATION
;
1940 if (internalFormat
!= GL_RG16I
)
1941 return GL_INVALID_OPERATION
;
1944 case GL_UNSIGNED_INT
:
1945 if (internalFormat
!= GL_RG32UI
)
1946 return GL_INVALID_OPERATION
;
1950 if (internalFormat
!= GL_RG32I
)
1951 return GL_INVALID_OPERATION
;
1955 return GL_INVALID_OPERATION
;
1961 case GL_UNSIGNED_BYTE
:
1962 if (internalFormat
!= GL_R8
)
1963 return GL_INVALID_OPERATION
;
1967 if (internalFormat
!= GL_R8_SNORM
)
1968 return GL_INVALID_OPERATION
;
1972 if (internalFormat
!= GL_R16F
)
1973 return GL_INVALID_OPERATION
;
1977 switch (internalFormat
) {
1982 return GL_INVALID_OPERATION
;
1987 return GL_INVALID_OPERATION
;
1991 case GL_RED_INTEGER
:
1993 case GL_UNSIGNED_BYTE
:
1994 if (internalFormat
!= GL_R8UI
)
1995 return GL_INVALID_OPERATION
;
1999 if (internalFormat
!= GL_R8I
)
2000 return GL_INVALID_OPERATION
;
2003 case GL_UNSIGNED_SHORT
:
2004 if (internalFormat
!= GL_R16UI
)
2005 return GL_INVALID_OPERATION
;
2009 if (internalFormat
!= GL_R16I
)
2010 return GL_INVALID_OPERATION
;
2013 case GL_UNSIGNED_INT
:
2014 if (internalFormat
!= GL_R32UI
)
2015 return GL_INVALID_OPERATION
;
2019 if (internalFormat
!= GL_R32I
)
2020 return GL_INVALID_OPERATION
;
2024 return GL_INVALID_OPERATION
;
2028 case GL_DEPTH_COMPONENT
:
2030 case GL_UNSIGNED_SHORT
:
2031 if (internalFormat
!= GL_DEPTH_COMPONENT
2032 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2033 return GL_INVALID_OPERATION
;
2036 case GL_UNSIGNED_INT
:
2037 switch (internalFormat
) {
2038 case GL_DEPTH_COMPONENT
:
2039 case GL_DEPTH_COMPONENT16
:
2040 case GL_DEPTH_COMPONENT24
:
2043 return GL_INVALID_OPERATION
;
2048 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2049 return GL_INVALID_OPERATION
;
2053 return GL_INVALID_OPERATION
;
2057 case GL_DEPTH_STENCIL
:
2059 case GL_UNSIGNED_INT_24_8
:
2060 if (internalFormat
!= GL_DEPTH_STENCIL
2061 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2062 return GL_INVALID_OPERATION
;
2065 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2066 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2067 return GL_INVALID_OPERATION
;
2071 return GL_INVALID_OPERATION
;
2077 case GL_LUMINANCE_ALPHA
:
2078 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2079 return GL_INVALID_OPERATION
;