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. */
1149 case GL_LUMINANCE_ALPHA
:
1150 return GL_LUMINANCE8_ALPHA8
;
1154 return GL_LUMINANCE8
;
1160 return GL_INTENSITY8
;
1162 /* GL_ARB_texture_rg */
1169 /* GL_EXT_texture_sRGB */
1174 return GL_SRGB8_ALPHA8
;
1177 return GL_SLUMINANCE8
;
1179 case GL_SLUMINANCE_ALPHA
:
1180 return GL_SLUMINANCE8_ALPHA8
;
1182 /* GL_EXT_texture_snorm */
1184 return GL_RGBA8_SNORM
;
1187 return GL_RGB8_SNORM
;
1190 return GL_RG8_SNORM
;
1195 case GL_LUMINANCE_ALPHA_SNORM
:
1196 return GL_LUMINANCE8_ALPHA8_SNORM
;
1198 case GL_LUMINANCE_SNORM
:
1199 return GL_LUMINANCE8_SNORM
;
1201 case GL_ALPHA_SNORM
:
1202 return GL_ALPHA8_SNORM
;
1204 case GL_INTENSITY_SNORM
:
1205 return GL_INTENSITY8_SNORM
;
1214 * Convert an sRGB internal format to linear.
1217 _mesa_get_linear_internalformat(GLenum format
)
1229 case GL_SRGB8_ALPHA8
:
1232 case GL_SLUMINANCE8
:
1233 return GL_LUMINANCE8
;
1236 return GL_LUMINANCE
;
1238 case GL_SLUMINANCE_ALPHA
:
1239 return GL_LUMINANCE_ALPHA
;
1241 case GL_SLUMINANCE8_ALPHA8
:
1242 return GL_LUMINANCE8_ALPHA8
;
1251 * Do error checking of format/type combinations for glReadPixels,
1252 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1253 * and type values, we may either generate GL_INVALID_OPERATION or
1256 * \param format pixel format.
1257 * \param type pixel type.
1259 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1262 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1263 GLenum format
, GLenum type
)
1265 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1268 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1269 return GL_INVALID_ENUM
;
1273 case GL_UNSIGNED_BYTE_3_3_2
:
1274 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1275 case GL_UNSIGNED_SHORT_5_6_5
:
1276 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1277 if (format
== GL_RGB
) {
1280 if (format
== GL_RGB_INTEGER_EXT
&&
1281 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1284 return GL_INVALID_OPERATION
;
1286 case GL_UNSIGNED_SHORT_4_4_4_4
:
1287 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1288 case GL_UNSIGNED_SHORT_5_5_5_1
:
1289 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1290 case GL_UNSIGNED_INT_8_8_8_8
:
1291 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1292 case GL_UNSIGNED_INT_10_10_10_2
:
1293 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1294 if (format
== GL_RGBA
||
1295 format
== GL_BGRA
||
1296 format
== GL_ABGR_EXT
) {
1299 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1300 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1303 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1304 ctx
->API
== API_OPENGLES2
) {
1305 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1307 return GL_INVALID_OPERATION
;
1309 case GL_UNSIGNED_INT_24_8
:
1310 if (format
!= GL_DEPTH_STENCIL
) {
1311 return GL_INVALID_OPERATION
;
1315 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1316 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1317 return GL_INVALID_ENUM
;
1319 if (format
!= GL_DEPTH_STENCIL
) {
1320 return GL_INVALID_OPERATION
;
1324 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1325 if (!ctx
->Extensions
.EXT_packed_float
) {
1326 return GL_INVALID_ENUM
;
1328 if (format
!= GL_RGB
) {
1329 return GL_INVALID_OPERATION
;
1334 ; /* fall-through */
1337 /* now, for each format, check the type for compatibility */
1339 case GL_COLOR_INDEX
:
1340 case GL_STENCIL_INDEX
:
1344 case GL_UNSIGNED_BYTE
:
1346 case GL_UNSIGNED_SHORT
:
1348 case GL_UNSIGNED_INT
:
1352 return ctx
->Extensions
.ARB_half_float_pixel
1353 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1355 return GL_INVALID_ENUM
;
1362 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1366 case GL_LUMINANCE_ALPHA
:
1367 case GL_DEPTH_COMPONENT
:
1370 case GL_UNSIGNED_BYTE
:
1372 case GL_UNSIGNED_SHORT
:
1374 case GL_UNSIGNED_INT
:
1378 return ctx
->Extensions
.ARB_half_float_pixel
1379 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1381 return GL_INVALID_ENUM
;
1385 if (!ctx
->Extensions
.ARB_texture_rg
)
1386 return GL_INVALID_ENUM
;
1389 case GL_UNSIGNED_BYTE
:
1391 case GL_UNSIGNED_SHORT
:
1393 case GL_UNSIGNED_INT
:
1397 return ctx
->Extensions
.ARB_half_float_pixel
1398 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1400 return GL_INVALID_ENUM
;
1406 case GL_UNSIGNED_BYTE
:
1408 case GL_UNSIGNED_SHORT
:
1410 case GL_UNSIGNED_INT
:
1412 case GL_UNSIGNED_BYTE_3_3_2
:
1413 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1414 case GL_UNSIGNED_SHORT_5_6_5
:
1415 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1417 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1418 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1419 return (ctx
->API
== API_OPENGLES2
)
1420 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1422 return ctx
->Extensions
.ARB_half_float_pixel
1423 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1424 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1425 return ctx
->Extensions
.EXT_texture_shared_exponent
1426 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1427 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1428 return ctx
->Extensions
.EXT_packed_float
1429 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1431 return GL_INVALID_ENUM
;
1436 /* NOTE: no packed types are supported with BGR. That's
1437 * intentional, according to the GL spec.
1440 case GL_UNSIGNED_BYTE
:
1442 case GL_UNSIGNED_SHORT
:
1444 case GL_UNSIGNED_INT
:
1448 return ctx
->Extensions
.ARB_half_float_pixel
1449 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1451 return GL_INVALID_ENUM
;
1459 case GL_UNSIGNED_BYTE
:
1461 case GL_UNSIGNED_SHORT
:
1463 case GL_UNSIGNED_INT
:
1465 case GL_UNSIGNED_SHORT_4_4_4_4
:
1466 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1467 case GL_UNSIGNED_SHORT_5_5_5_1
:
1468 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1469 case GL_UNSIGNED_INT_8_8_8_8
:
1470 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1471 case GL_UNSIGNED_INT_10_10_10_2
:
1472 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1475 return ctx
->Extensions
.ARB_half_float_pixel
1476 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1478 return GL_INVALID_ENUM
;
1482 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1483 return GL_INVALID_ENUM
;
1484 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1485 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1488 return GL_INVALID_OPERATION
;
1490 case GL_DEPTH_STENCIL
:
1491 if (type
== GL_UNSIGNED_INT_24_8
)
1493 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1494 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1497 return GL_INVALID_ENUM
;
1501 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1502 return GL_INVALID_ENUM
;
1505 case GL_UNSIGNED_BYTE
:
1507 case GL_UNSIGNED_SHORT
:
1509 case GL_UNSIGNED_INT
:
1513 return GL_INVALID_ENUM
;
1516 /* integer-valued formats */
1517 case GL_RED_INTEGER_EXT
:
1518 case GL_GREEN_INTEGER_EXT
:
1519 case GL_BLUE_INTEGER_EXT
:
1520 case GL_ALPHA_INTEGER_EXT
:
1524 case GL_UNSIGNED_BYTE
:
1526 case GL_UNSIGNED_SHORT
:
1528 case GL_UNSIGNED_INT
:
1529 return (ctx
->Version
>= 30 ||
1530 ctx
->Extensions
.EXT_texture_integer
)
1531 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1533 return GL_INVALID_ENUM
;
1536 case GL_RGB_INTEGER_EXT
:
1539 case GL_UNSIGNED_BYTE
:
1541 case GL_UNSIGNED_SHORT
:
1543 case GL_UNSIGNED_INT
:
1544 return (ctx
->Version
>= 30 ||
1545 ctx
->Extensions
.EXT_texture_integer
)
1546 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1547 case GL_UNSIGNED_BYTE_3_3_2
:
1548 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1549 case GL_UNSIGNED_SHORT_5_6_5
:
1550 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1551 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1552 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1554 return GL_INVALID_ENUM
;
1557 case GL_BGR_INTEGER_EXT
:
1560 case GL_UNSIGNED_BYTE
:
1562 case GL_UNSIGNED_SHORT
:
1564 case GL_UNSIGNED_INT
:
1565 /* NOTE: no packed formats w/ BGR format */
1566 return (ctx
->Version
>= 30 ||
1567 ctx
->Extensions
.EXT_texture_integer
)
1568 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1570 return GL_INVALID_ENUM
;
1573 case GL_RGBA_INTEGER_EXT
:
1574 case GL_BGRA_INTEGER_EXT
:
1577 case GL_UNSIGNED_BYTE
:
1579 case GL_UNSIGNED_SHORT
:
1581 case GL_UNSIGNED_INT
:
1582 return (ctx
->Version
>= 30 ||
1583 ctx
->Extensions
.EXT_texture_integer
)
1584 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1585 case GL_UNSIGNED_SHORT_4_4_4_4
:
1586 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1587 case GL_UNSIGNED_SHORT_5_5_5_1
:
1588 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1589 case GL_UNSIGNED_INT_8_8_8_8
:
1590 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1591 case GL_UNSIGNED_INT_10_10_10_2
:
1592 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1593 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1594 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1596 return GL_INVALID_ENUM
;
1599 case GL_LUMINANCE_INTEGER_EXT
:
1600 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1603 case GL_UNSIGNED_BYTE
:
1605 case GL_UNSIGNED_SHORT
:
1607 case GL_UNSIGNED_INT
:
1608 return ctx
->Extensions
.EXT_texture_integer
1609 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1611 return GL_INVALID_ENUM
;
1615 return GL_INVALID_ENUM
;
1622 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1623 * and glTex[Sub]Image.
1624 * \return error code, or GL_NO_ERROR.
1627 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1628 unsigned dimensions
)
1630 GLboolean type_valid
= GL_TRUE
;
1635 case GL_LUMINANCE_ALPHA
:
1636 type_valid
= (type
== GL_UNSIGNED_BYTE
1638 || type
== GL_HALF_FLOAT_OES
);
1642 type_valid
= (type
== GL_UNSIGNED_BYTE
1643 || type
== GL_UNSIGNED_SHORT_5_6_5
1645 || type
== GL_HALF_FLOAT_OES
);
1649 type_valid
= (type
== GL_UNSIGNED_BYTE
1650 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1651 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1653 || type
== GL_HALF_FLOAT_OES
1654 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1657 case GL_DEPTH_COMPONENT
:
1658 /* This format is filtered against invalid dimensionalities elsewhere.
1660 type_valid
= (type
== GL_UNSIGNED_SHORT
1661 || type
== GL_UNSIGNED_INT
);
1664 case GL_DEPTH_STENCIL
:
1665 /* This format is filtered against invalid dimensionalities elsewhere.
1667 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1671 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1673 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1674 * the format does not appear to be allowed for 3D textures in OpenGL
1677 if (dimensions
!= 2)
1678 return GL_INVALID_VALUE
;
1683 return GL_INVALID_VALUE
;
1686 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1691 * Do error checking of format/type combinations for OpenGL ES 3
1693 * \return error code, or GL_NO_ERROR.
1696 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1697 GLenum internalFormat
)
1702 case GL_UNSIGNED_BYTE
:
1703 switch (internalFormat
) {
1708 case GL_SRGB8_ALPHA8_EXT
:
1711 return GL_INVALID_OPERATION
;
1716 if (internalFormat
!= GL_RGBA8_SNORM
)
1717 return GL_INVALID_OPERATION
;
1720 case GL_UNSIGNED_SHORT_4_4_4_4
:
1721 switch (internalFormat
) {
1726 return GL_INVALID_OPERATION
;
1730 case GL_UNSIGNED_SHORT_5_5_5_1
:
1731 switch (internalFormat
) {
1736 return GL_INVALID_OPERATION
;
1740 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1741 switch (internalFormat
) {
1742 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1747 return GL_INVALID_OPERATION
;
1752 if (internalFormat
!= GL_RGBA16F
)
1753 return GL_INVALID_OPERATION
;
1757 switch (internalFormat
) {
1762 return GL_INVALID_OPERATION
;
1767 return GL_INVALID_OPERATION
;
1771 case GL_RGBA_INTEGER
:
1773 case GL_UNSIGNED_BYTE
:
1774 if (internalFormat
!= GL_RGBA8UI
)
1775 return GL_INVALID_OPERATION
;
1779 if (internalFormat
!= GL_RGBA8I
)
1780 return GL_INVALID_OPERATION
;
1783 case GL_UNSIGNED_SHORT
:
1784 if (internalFormat
!= GL_RGBA16UI
)
1785 return GL_INVALID_OPERATION
;
1789 if (internalFormat
!= GL_RGBA16I
)
1790 return GL_INVALID_OPERATION
;
1793 case GL_UNSIGNED_INT
:
1794 if (internalFormat
!= GL_RGBA32UI
)
1795 return GL_INVALID_OPERATION
;
1799 if (internalFormat
!= GL_RGBA32I
)
1800 return GL_INVALID_OPERATION
;
1803 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1804 if (internalFormat
!= GL_RGB10_A2UI
)
1805 return GL_INVALID_OPERATION
;
1809 return GL_INVALID_OPERATION
;
1815 case GL_UNSIGNED_BYTE
:
1816 switch (internalFormat
) {
1823 return GL_INVALID_OPERATION
;
1828 if (internalFormat
!= GL_RGB8_SNORM
)
1829 return GL_INVALID_OPERATION
;
1832 case GL_UNSIGNED_SHORT_5_6_5
:
1833 switch (internalFormat
) {
1838 return GL_INVALID_OPERATION
;
1842 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1843 if (internalFormat
!= GL_R11F_G11F_B10F
)
1844 return GL_INVALID_OPERATION
;
1847 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1848 if (internalFormat
!= GL_RGB9_E5
)
1849 return GL_INVALID_OPERATION
;
1853 switch (internalFormat
) {
1855 case GL_R11F_G11F_B10F
:
1859 return GL_INVALID_OPERATION
;
1864 switch (internalFormat
) {
1867 case GL_R11F_G11F_B10F
:
1871 return GL_INVALID_OPERATION
;
1875 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1876 switch (internalFormat
) {
1877 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1880 return GL_INVALID_OPERATION
;
1885 return GL_INVALID_OPERATION
;
1889 case GL_RGB_INTEGER
:
1891 case GL_UNSIGNED_BYTE
:
1892 if (internalFormat
!= GL_RGB8UI
)
1893 return GL_INVALID_OPERATION
;
1897 if (internalFormat
!= GL_RGB8I
)
1898 return GL_INVALID_OPERATION
;
1901 case GL_UNSIGNED_SHORT
:
1902 if (internalFormat
!= GL_RGB16UI
)
1903 return GL_INVALID_OPERATION
;
1907 if (internalFormat
!= GL_RGB16I
)
1908 return GL_INVALID_OPERATION
;
1911 case GL_UNSIGNED_INT
:
1912 if (internalFormat
!= GL_RGB32UI
)
1913 return GL_INVALID_OPERATION
;
1917 if (internalFormat
!= GL_RGB32I
)
1918 return GL_INVALID_OPERATION
;
1922 return GL_INVALID_OPERATION
;
1928 case GL_UNSIGNED_BYTE
:
1929 if (internalFormat
!= GL_RG8
)
1930 return GL_INVALID_OPERATION
;
1934 if (internalFormat
!= GL_RG8_SNORM
)
1935 return GL_INVALID_OPERATION
;
1939 if (internalFormat
!= GL_RG16F
)
1940 return GL_INVALID_OPERATION
;
1944 switch (internalFormat
) {
1949 return GL_INVALID_OPERATION
;
1954 return GL_INVALID_OPERATION
;
1960 case GL_UNSIGNED_BYTE
:
1961 if (internalFormat
!= GL_RG8UI
)
1962 return GL_INVALID_OPERATION
;
1966 if (internalFormat
!= GL_RG8I
)
1967 return GL_INVALID_OPERATION
;
1970 case GL_UNSIGNED_SHORT
:
1971 if (internalFormat
!= GL_RG16UI
)
1972 return GL_INVALID_OPERATION
;
1976 if (internalFormat
!= GL_RG16I
)
1977 return GL_INVALID_OPERATION
;
1980 case GL_UNSIGNED_INT
:
1981 if (internalFormat
!= GL_RG32UI
)
1982 return GL_INVALID_OPERATION
;
1986 if (internalFormat
!= GL_RG32I
)
1987 return GL_INVALID_OPERATION
;
1991 return GL_INVALID_OPERATION
;
1997 case GL_UNSIGNED_BYTE
:
1998 if (internalFormat
!= GL_R8
)
1999 return GL_INVALID_OPERATION
;
2003 if (internalFormat
!= GL_R8_SNORM
)
2004 return GL_INVALID_OPERATION
;
2008 if (internalFormat
!= GL_R16F
)
2009 return GL_INVALID_OPERATION
;
2013 switch (internalFormat
) {
2018 return GL_INVALID_OPERATION
;
2023 return GL_INVALID_OPERATION
;
2027 case GL_RED_INTEGER
:
2029 case GL_UNSIGNED_BYTE
:
2030 if (internalFormat
!= GL_R8UI
)
2031 return GL_INVALID_OPERATION
;
2035 if (internalFormat
!= GL_R8I
)
2036 return GL_INVALID_OPERATION
;
2039 case GL_UNSIGNED_SHORT
:
2040 if (internalFormat
!= GL_R16UI
)
2041 return GL_INVALID_OPERATION
;
2045 if (internalFormat
!= GL_R16I
)
2046 return GL_INVALID_OPERATION
;
2049 case GL_UNSIGNED_INT
:
2050 if (internalFormat
!= GL_R32UI
)
2051 return GL_INVALID_OPERATION
;
2055 if (internalFormat
!= GL_R32I
)
2056 return GL_INVALID_OPERATION
;
2060 return GL_INVALID_OPERATION
;
2064 case GL_DEPTH_COMPONENT
:
2066 case GL_UNSIGNED_SHORT
:
2067 if (internalFormat
!= GL_DEPTH_COMPONENT
2068 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2069 return GL_INVALID_OPERATION
;
2072 case GL_UNSIGNED_INT
:
2073 switch (internalFormat
) {
2074 case GL_DEPTH_COMPONENT
:
2075 case GL_DEPTH_COMPONENT16
:
2076 case GL_DEPTH_COMPONENT24
:
2079 return GL_INVALID_OPERATION
;
2084 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2085 return GL_INVALID_OPERATION
;
2089 return GL_INVALID_OPERATION
;
2093 case GL_DEPTH_STENCIL
:
2095 case GL_UNSIGNED_INT_24_8
:
2096 if (internalFormat
!= GL_DEPTH_STENCIL
2097 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2098 return GL_INVALID_OPERATION
;
2101 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2102 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2103 return GL_INVALID_OPERATION
;
2107 return GL_INVALID_OPERATION
;
2113 case GL_LUMINANCE_ALPHA
:
2114 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2115 return GL_INVALID_OPERATION
;