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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "glformats.h"
32 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
35 _mesa_type_is_packed(GLenum type
)
38 case GL_UNSIGNED_BYTE_3_3_2
:
39 case GL_UNSIGNED_BYTE_2_3_3_REV
:
40 case MESA_UNSIGNED_BYTE_4_4
:
41 case GL_UNSIGNED_SHORT_5_6_5
:
42 case GL_UNSIGNED_SHORT_5_6_5_REV
:
43 case GL_UNSIGNED_SHORT_4_4_4_4
:
44 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
45 case GL_UNSIGNED_SHORT_5_5_5_1
:
46 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
47 case GL_UNSIGNED_INT_8_8_8_8
:
48 case GL_UNSIGNED_INT_8_8_8_8_REV
:
49 case GL_UNSIGNED_INT_10_10_10_2
:
50 case GL_UNSIGNED_INT_2_10_10_10_REV
:
51 case GL_UNSIGNED_SHORT_8_8_MESA
:
52 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
53 case GL_UNSIGNED_INT_24_8_EXT
:
54 case GL_UNSIGNED_INT_5_9_9_9_REV
:
55 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
56 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
65 * Get the size of a GL data type.
67 * \param type GL data type.
69 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
70 * if an invalid type enum.
73 _mesa_sizeof_type(GLenum type
)
78 case GL_UNSIGNED_BYTE
:
79 return sizeof(GLubyte
);
81 return sizeof(GLbyte
);
82 case GL_UNSIGNED_SHORT
:
83 return sizeof(GLushort
);
85 return sizeof(GLshort
);
87 return sizeof(GLuint
);
91 return sizeof(GLfloat
);
93 return sizeof(GLdouble
);
94 case GL_HALF_FLOAT_ARB
:
95 return sizeof(GLhalfARB
);
97 return sizeof(GLfixed
);
105 * Same as _mesa_sizeof_type() but also accepting the packed pixel
109 _mesa_sizeof_packed_type(GLenum type
)
114 case GL_UNSIGNED_BYTE
:
115 return sizeof(GLubyte
);
117 return sizeof(GLbyte
);
118 case GL_UNSIGNED_SHORT
:
119 return sizeof(GLushort
);
121 return sizeof(GLshort
);
122 case GL_UNSIGNED_INT
:
123 return sizeof(GLuint
);
125 return sizeof(GLint
);
126 case GL_HALF_FLOAT_ARB
:
127 return sizeof(GLhalfARB
);
129 return sizeof(GLfloat
);
130 case GL_UNSIGNED_BYTE_3_3_2
:
131 case GL_UNSIGNED_BYTE_2_3_3_REV
:
132 case MESA_UNSIGNED_BYTE_4_4
:
133 return sizeof(GLubyte
);
134 case GL_UNSIGNED_SHORT_5_6_5
:
135 case GL_UNSIGNED_SHORT_5_6_5_REV
:
136 case GL_UNSIGNED_SHORT_4_4_4_4
:
137 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
138 case GL_UNSIGNED_SHORT_5_5_5_1
:
139 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
140 case GL_UNSIGNED_SHORT_8_8_MESA
:
141 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
142 return sizeof(GLushort
);
143 case GL_UNSIGNED_INT_8_8_8_8
:
144 case GL_UNSIGNED_INT_8_8_8_8_REV
:
145 case GL_UNSIGNED_INT_10_10_10_2
:
146 case GL_UNSIGNED_INT_2_10_10_10_REV
:
147 case GL_UNSIGNED_INT_24_8_EXT
:
148 case GL_UNSIGNED_INT_5_9_9_9_REV
:
149 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
150 return sizeof(GLuint
);
151 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
160 * Get the number of components in a pixel format.
162 * \param format pixel format.
164 * \return the number of components in the given format, or -1 if a bad format.
167 _mesa_components_in_format(GLenum format
)
171 case GL_STENCIL_INDEX
:
172 case GL_DEPTH_COMPONENT
:
174 case GL_RED_INTEGER_EXT
:
176 case GL_GREEN_INTEGER_EXT
:
178 case GL_BLUE_INTEGER_EXT
:
180 case GL_ALPHA_INTEGER_EXT
:
182 case GL_LUMINANCE_INTEGER_EXT
:
186 case GL_LUMINANCE_ALPHA
:
187 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
190 case GL_DEPTH_STENCIL_EXT
:
198 case GL_RGB_INTEGER_EXT
:
199 case GL_BGR_INTEGER_EXT
:
205 case GL_RGBA_INTEGER_EXT
:
206 case GL_BGRA_INTEGER_EXT
:
216 * Get the bytes per pixel of pixel format type pair.
218 * \param format pixel format.
219 * \param type pixel type.
221 * \return bytes per pixel, or -1 if a bad format or type was given.
224 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
226 GLint comps
= _mesa_components_in_format(format
);
232 return 0; /* special case */
234 case GL_UNSIGNED_BYTE
:
235 return comps
* sizeof(GLubyte
);
237 case GL_UNSIGNED_SHORT
:
238 return comps
* sizeof(GLshort
);
240 case GL_UNSIGNED_INT
:
241 return comps
* sizeof(GLint
);
243 return comps
* sizeof(GLfloat
);
244 case GL_HALF_FLOAT_ARB
:
245 return comps
* sizeof(GLhalfARB
);
246 case GL_UNSIGNED_BYTE_3_3_2
:
247 case GL_UNSIGNED_BYTE_2_3_3_REV
:
248 if (format
== GL_RGB
|| format
== GL_BGR
||
249 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
250 return sizeof(GLubyte
);
252 return -1; /* error */
253 case GL_UNSIGNED_SHORT_5_6_5
:
254 case GL_UNSIGNED_SHORT_5_6_5_REV
:
255 if (format
== GL_RGB
|| format
== GL_BGR
||
256 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
257 return sizeof(GLushort
);
259 return -1; /* error */
260 case GL_UNSIGNED_SHORT_4_4_4_4
:
261 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
262 case GL_UNSIGNED_SHORT_5_5_5_1
:
263 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
264 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
265 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
266 return sizeof(GLushort
);
269 case GL_UNSIGNED_INT_8_8_8_8
:
270 case GL_UNSIGNED_INT_8_8_8_8_REV
:
271 case GL_UNSIGNED_INT_10_10_10_2
:
272 case GL_UNSIGNED_INT_2_10_10_10_REV
:
273 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
274 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
276 return sizeof(GLuint
);
279 case GL_UNSIGNED_SHORT_8_8_MESA
:
280 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
281 if (format
== GL_YCBCR_MESA
)
282 return sizeof(GLushort
);
285 case GL_UNSIGNED_INT_24_8_EXT
:
286 if (format
== GL_DEPTH_STENCIL_EXT
)
287 return sizeof(GLuint
);
290 case GL_UNSIGNED_INT_5_9_9_9_REV
:
291 if (format
== GL_RGB
)
292 return sizeof(GLuint
);
295 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
296 if (format
== GL_RGB
)
297 return sizeof(GLuint
);
300 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
301 if (format
== GL_DEPTH_STENCIL
)
312 * Get the number of bytes for a vertex attrib with the given number of
313 * components and type.
315 * \param comps number of components.
316 * \param type data type.
318 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
321 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
325 case GL_UNSIGNED_BYTE
:
326 return comps
* sizeof(GLubyte
);
328 case GL_UNSIGNED_SHORT
:
329 return comps
* sizeof(GLshort
);
331 case GL_UNSIGNED_INT
:
332 return comps
* sizeof(GLint
);
334 return comps
* sizeof(GLfloat
);
335 case GL_HALF_FLOAT_ARB
:
336 return comps
* sizeof(GLhalfARB
);
338 return comps
* sizeof(GLdouble
);
340 return comps
* sizeof(GLfixed
);
341 case GL_INT_2_10_10_10_REV
:
342 case GL_UNSIGNED_INT_2_10_10_10_REV
:
344 return sizeof(GLuint
);
354 * Test if the given format is an integer (non-normalized) format.
357 _mesa_is_enum_format_unsigned_int(GLenum format
)
360 /* specific integer formats */
361 case GL_RGBA32UI_EXT
:
365 case GL_ALPHA32UI_EXT
:
366 case GL_INTENSITY32UI_EXT
:
367 case GL_LUMINANCE32UI_EXT
:
368 case GL_LUMINANCE_ALPHA32UI_EXT
:
369 case GL_RGBA16UI_EXT
:
373 case GL_ALPHA16UI_EXT
:
374 case GL_INTENSITY16UI_EXT
:
375 case GL_LUMINANCE16UI_EXT
:
376 case GL_LUMINANCE_ALPHA16UI_EXT
:
381 case GL_ALPHA8UI_EXT
:
382 case GL_INTENSITY8UI_EXT
:
383 case GL_LUMINANCE8UI_EXT
:
384 case GL_LUMINANCE_ALPHA8UI_EXT
:
394 * Test if the given format is an integer (non-normalized) format.
397 _mesa_is_enum_format_signed_int(GLenum format
)
400 /* generic integer formats */
401 case GL_RED_INTEGER_EXT
:
402 case GL_GREEN_INTEGER_EXT
:
403 case GL_BLUE_INTEGER_EXT
:
404 case GL_ALPHA_INTEGER_EXT
:
405 case GL_RGB_INTEGER_EXT
:
406 case GL_RGBA_INTEGER_EXT
:
407 case GL_BGR_INTEGER_EXT
:
408 case GL_BGRA_INTEGER_EXT
:
409 case GL_LUMINANCE_INTEGER_EXT
:
410 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
412 /* specific integer formats */
417 case GL_ALPHA32I_EXT
:
418 case GL_INTENSITY32I_EXT
:
419 case GL_LUMINANCE32I_EXT
:
420 case GL_LUMINANCE_ALPHA32I_EXT
:
425 case GL_ALPHA16I_EXT
:
426 case GL_INTENSITY16I_EXT
:
427 case GL_LUMINANCE16I_EXT
:
428 case GL_LUMINANCE_ALPHA16I_EXT
:
434 case GL_INTENSITY8I_EXT
:
435 case GL_LUMINANCE8I_EXT
:
436 case GL_LUMINANCE_ALPHA8I_EXT
:
445 * Test if the given format is an integer (non-normalized) format.
448 _mesa_is_enum_format_integer(GLenum format
)
450 return _mesa_is_enum_format_unsigned_int(format
) ||
451 _mesa_is_enum_format_signed_int(format
);
456 * Test if the given type is an integer (non-normalized) format.
459 _mesa_is_type_integer(GLenum type
)
463 case GL_UNSIGNED_INT
:
465 case GL_UNSIGNED_SHORT
:
467 case GL_UNSIGNED_BYTE
:
476 * Test if the given format or type is an integer (non-normalized) format.
479 _mesa_is_enum_format_or_type_integer(GLenum format
, GLenum type
)
481 return _mesa_is_enum_format_integer(format
) || _mesa_is_type_integer(type
);
486 _mesa_is_type_unsigned(GLenum type
)
489 case GL_UNSIGNED_INT
:
490 case GL_UNSIGNED_INT_8_8_8_8
:
491 case GL_UNSIGNED_INT_8_8_8_8_REV
:
492 case GL_UNSIGNED_INT_10_10_10_2
:
493 case GL_UNSIGNED_INT_2_10_10_10_REV
:
495 case GL_UNSIGNED_SHORT
:
496 case GL_UNSIGNED_SHORT_4_4_4_4
:
497 case GL_UNSIGNED_SHORT_5_5_5_1
:
498 case GL_UNSIGNED_SHORT_5_6_5
:
499 case GL_UNSIGNED_SHORT_5_6_5_REV
:
500 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
501 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
502 case GL_UNSIGNED_SHORT_8_8_MESA
:
503 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
505 case GL_UNSIGNED_BYTE
:
506 case GL_UNSIGNED_BYTE_3_3_2
:
507 case GL_UNSIGNED_BYTE_2_3_3_REV
:
517 * Test if the given image format is a color/RGBA format (i.e., not color
518 * index, depth, stencil, etc).
519 * \param format the image format value (may by an internal texture format)
520 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
523 _mesa_is_color_format(GLenum format
)
541 case GL_LUMINANCE_ALPHA
:
542 case GL_LUMINANCE4_ALPHA4
:
543 case GL_LUMINANCE6_ALPHA2
:
544 case GL_LUMINANCE8_ALPHA8
:
545 case GL_LUMINANCE12_ALPHA4
:
546 case GL_LUMINANCE12_ALPHA12
:
547 case GL_LUMINANCE16_ALPHA16
:
580 /* float texture formats */
581 case GL_ALPHA16F_ARB
:
582 case GL_ALPHA32F_ARB
:
583 case GL_LUMINANCE16F_ARB
:
584 case GL_LUMINANCE32F_ARB
:
585 case GL_LUMINANCE_ALPHA16F_ARB
:
586 case GL_LUMINANCE_ALPHA32F_ARB
:
587 case GL_INTENSITY16F_ARB
:
588 case GL_INTENSITY32F_ARB
:
597 /* compressed formats */
598 case GL_COMPRESSED_ALPHA
:
599 case GL_COMPRESSED_LUMINANCE
:
600 case GL_COMPRESSED_LUMINANCE_ALPHA
:
601 case GL_COMPRESSED_INTENSITY
:
602 case GL_COMPRESSED_RED
:
603 case GL_COMPRESSED_RG
:
604 case GL_COMPRESSED_RGB
:
605 case GL_COMPRESSED_RGBA
:
610 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
611 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
612 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
613 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
614 case GL_COMPRESSED_RGB_FXT1_3DFX
:
615 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
618 case GL_SRGB_ALPHA_EXT
:
619 case GL_SRGB8_ALPHA8_EXT
:
620 case GL_SLUMINANCE_ALPHA_EXT
:
621 case GL_SLUMINANCE8_ALPHA8_EXT
:
622 case GL_SLUMINANCE_EXT
:
623 case GL_SLUMINANCE8_EXT
:
624 case GL_COMPRESSED_SRGB_EXT
:
625 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
626 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
627 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
628 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
629 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
630 case GL_COMPRESSED_SLUMINANCE_EXT
:
631 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
632 case GL_COMPRESSED_RED_RGTC1
:
633 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
634 case GL_COMPRESSED_RG_RGTC2
:
635 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
636 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
637 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
638 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
639 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
640 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
641 case GL_ETC1_RGB8_OES
:
642 case GL_COMPRESSED_RGB8_ETC2
:
643 case GL_COMPRESSED_SRGB8_ETC2
:
644 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
645 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
646 case GL_COMPRESSED_R11_EAC
:
647 case GL_COMPRESSED_RG11_EAC
:
648 case GL_COMPRESSED_SIGNED_R11_EAC
:
649 case GL_COMPRESSED_SIGNED_RG11_EAC
:
650 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
651 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
652 /* generic integer formats */
653 case GL_RED_INTEGER_EXT
:
654 case GL_GREEN_INTEGER_EXT
:
655 case GL_BLUE_INTEGER_EXT
:
656 case GL_ALPHA_INTEGER_EXT
:
657 case GL_RGB_INTEGER_EXT
:
658 case GL_RGBA_INTEGER_EXT
:
659 case GL_BGR_INTEGER_EXT
:
660 case GL_BGRA_INTEGER_EXT
:
662 case GL_LUMINANCE_INTEGER_EXT
:
663 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
664 /* sized integer formats */
665 case GL_RGBA32UI_EXT
:
669 case GL_ALPHA32UI_EXT
:
670 case GL_INTENSITY32UI_EXT
:
671 case GL_LUMINANCE32UI_EXT
:
672 case GL_LUMINANCE_ALPHA32UI_EXT
:
673 case GL_RGBA16UI_EXT
:
677 case GL_ALPHA16UI_EXT
:
678 case GL_INTENSITY16UI_EXT
:
679 case GL_LUMINANCE16UI_EXT
:
680 case GL_LUMINANCE_ALPHA16UI_EXT
:
685 case GL_ALPHA8UI_EXT
:
686 case GL_INTENSITY8UI_EXT
:
687 case GL_LUMINANCE8UI_EXT
:
688 case GL_LUMINANCE_ALPHA8UI_EXT
:
693 case GL_ALPHA32I_EXT
:
694 case GL_INTENSITY32I_EXT
:
695 case GL_LUMINANCE32I_EXT
:
696 case GL_LUMINANCE_ALPHA32I_EXT
:
701 case GL_ALPHA16I_EXT
:
702 case GL_INTENSITY16I_EXT
:
703 case GL_LUMINANCE16I_EXT
:
704 case GL_LUMINANCE_ALPHA16I_EXT
:
710 case GL_INTENSITY8I_EXT
:
711 case GL_LUMINANCE8I_EXT
:
712 case GL_LUMINANCE_ALPHA8I_EXT
:
713 /* signed, normalized texture formats */
725 case GL_RGBA16_SNORM
:
727 case GL_ALPHA8_SNORM
:
728 case GL_ALPHA16_SNORM
:
729 case GL_LUMINANCE_SNORM
:
730 case GL_LUMINANCE8_SNORM
:
731 case GL_LUMINANCE16_SNORM
:
732 case GL_LUMINANCE_ALPHA_SNORM
:
733 case GL_LUMINANCE8_ALPHA8_SNORM
:
734 case GL_LUMINANCE16_ALPHA16_SNORM
:
735 case GL_INTENSITY_SNORM
:
736 case GL_INTENSITY8_SNORM
:
737 case GL_INTENSITY16_SNORM
:
739 case GL_R11F_G11F_B10F
:
742 case GL_YCBCR_MESA
: /* not considered to be RGB */
751 * Test if the given image format is a depth component format.
754 _mesa_is_depth_format(GLenum format
)
757 case GL_DEPTH_COMPONENT
:
758 case GL_DEPTH_COMPONENT16
:
759 case GL_DEPTH_COMPONENT24
:
760 case GL_DEPTH_COMPONENT32
:
761 case GL_DEPTH_COMPONENT32F
:
770 * Test if the given image format is a stencil format.
773 _mesa_is_stencil_format(GLenum format
)
776 case GL_STENCIL_INDEX
:
785 * Test if the given image format is a YCbCr format.
788 _mesa_is_ycbcr_format(GLenum format
)
800 * Test if the given image format is a depth+stencil format.
803 _mesa_is_depthstencil_format(GLenum format
)
806 case GL_DEPTH24_STENCIL8_EXT
:
807 case GL_DEPTH_STENCIL_EXT
:
808 case GL_DEPTH32F_STENCIL8
:
817 * Test if the given image format is a depth or stencil format.
820 _mesa_is_depth_or_stencil_format(GLenum format
)
823 case GL_DEPTH_COMPONENT
:
824 case GL_DEPTH_COMPONENT16
:
825 case GL_DEPTH_COMPONENT24
:
826 case GL_DEPTH_COMPONENT32
:
827 case GL_STENCIL_INDEX
:
828 case GL_STENCIL_INDEX1_EXT
:
829 case GL_STENCIL_INDEX4_EXT
:
830 case GL_STENCIL_INDEX8_EXT
:
831 case GL_STENCIL_INDEX16_EXT
:
832 case GL_DEPTH_STENCIL_EXT
:
833 case GL_DEPTH24_STENCIL8_EXT
:
834 case GL_DEPTH_COMPONENT32F
:
835 case GL_DEPTH32F_STENCIL8
:
844 * Test if the given image format is a dudv format.
847 _mesa_is_dudv_format(GLenum format
)
860 * Test if an image format is a supported compressed format.
861 * \param format the internal format token provided by the user.
862 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
865 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
868 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
869 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
870 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
871 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
872 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
873 return (_mesa_is_desktop_gl(ctx
) &&
874 ctx
->Extensions
.EXT_texture_compression_s3tc
) ||
875 (ctx
->API
== API_OPENGLES2
&&
876 ctx
->Extensions
.ANGLE_texture_compression_dxt
);
881 return _mesa_is_desktop_gl(ctx
) &&
882 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
883 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
884 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
885 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
886 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
887 return _mesa_is_desktop_gl(ctx
)
888 && ctx
->Extensions
.EXT_texture_sRGB
889 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
890 case GL_COMPRESSED_RGB_FXT1_3DFX
:
891 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
892 return _mesa_is_desktop_gl(ctx
)
893 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
894 case GL_COMPRESSED_RED_RGTC1
:
895 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
896 case GL_COMPRESSED_RG_RGTC2
:
897 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
898 return _mesa_is_desktop_gl(ctx
)
899 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
900 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
901 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
902 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
903 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
904 return ctx
->API
== API_OPENGL_COMPAT
905 && ctx
->Extensions
.EXT_texture_compression_latc
;
906 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
907 return ctx
->API
== API_OPENGL_COMPAT
908 && ctx
->Extensions
.ATI_texture_compression_3dc
;
909 case GL_ETC1_RGB8_OES
:
910 return _mesa_is_gles(ctx
)
911 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
912 case GL_COMPRESSED_RGB8_ETC2
:
913 case GL_COMPRESSED_SRGB8_ETC2
:
914 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
915 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
916 case GL_COMPRESSED_R11_EAC
:
917 case GL_COMPRESSED_RG11_EAC
:
918 case GL_COMPRESSED_SIGNED_R11_EAC
:
919 case GL_COMPRESSED_SIGNED_RG11_EAC
:
920 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
921 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
922 return _mesa_is_gles3(ctx
);
923 case GL_PALETTE4_RGB8_OES
:
924 case GL_PALETTE4_RGBA8_OES
:
925 case GL_PALETTE4_R5_G6_B5_OES
:
926 case GL_PALETTE4_RGBA4_OES
:
927 case GL_PALETTE4_RGB5_A1_OES
:
928 case GL_PALETTE8_RGB8_OES
:
929 case GL_PALETTE8_RGBA8_OES
:
930 case GL_PALETTE8_R5_G6_B5_OES
:
931 case GL_PALETTE8_RGBA4_OES
:
932 case GL_PALETTE8_RGB5_A1_OES
:
933 return ctx
->API
== API_OPENGLES
;
941 * Convert various base formats to the cooresponding integer format.
944 _mesa_base_format_to_integer_format(GLenum format
)
948 return GL_RED_INTEGER
;
950 return GL_GREEN_INTEGER
;
952 return GL_BLUE_INTEGER
;
954 return GL_RG_INTEGER
;
956 return GL_RGB_INTEGER
;
958 return GL_RGBA_INTEGER
;
960 return GL_BGR_INTEGER
;
962 return GL_BGRA_INTEGER
;
964 return GL_ALPHA_INTEGER
;
966 return GL_LUMINANCE_INTEGER_EXT
;
967 case GL_LUMINANCE_ALPHA
:
968 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
976 * Does the given base texture/renderbuffer format have the channel
980 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
983 case GL_TEXTURE_RED_SIZE
:
984 case GL_TEXTURE_RED_TYPE
:
985 case GL_RENDERBUFFER_RED_SIZE_EXT
:
986 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
987 if (base_format
== GL_RED
||
988 base_format
== GL_RG
||
989 base_format
== GL_RGB
||
990 base_format
== GL_RGBA
) {
994 case GL_TEXTURE_GREEN_SIZE
:
995 case GL_TEXTURE_GREEN_TYPE
:
996 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
997 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
998 if (base_format
== GL_RG
||
999 base_format
== GL_RGB
||
1000 base_format
== GL_RGBA
) {
1004 case GL_TEXTURE_BLUE_SIZE
:
1005 case GL_TEXTURE_BLUE_TYPE
:
1006 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1007 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1008 if (base_format
== GL_RGB
||
1009 base_format
== GL_RGBA
) {
1013 case GL_TEXTURE_ALPHA_SIZE
:
1014 case GL_TEXTURE_ALPHA_TYPE
:
1015 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1016 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1017 if (base_format
== GL_RGBA
||
1018 base_format
== GL_ALPHA
||
1019 base_format
== GL_LUMINANCE_ALPHA
) {
1023 case GL_TEXTURE_LUMINANCE_SIZE
:
1024 case GL_TEXTURE_LUMINANCE_TYPE
:
1025 if (base_format
== GL_LUMINANCE
||
1026 base_format
== GL_LUMINANCE_ALPHA
) {
1030 case GL_TEXTURE_INTENSITY_SIZE
:
1031 case GL_TEXTURE_INTENSITY_TYPE
:
1032 if (base_format
== GL_INTENSITY
) {
1036 case GL_TEXTURE_DEPTH_SIZE
:
1037 case GL_TEXTURE_DEPTH_TYPE
:
1038 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1039 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1040 if (base_format
== GL_DEPTH_STENCIL
||
1041 base_format
== GL_DEPTH_COMPONENT
) {
1045 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1046 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1047 if (base_format
== GL_DEPTH_STENCIL
||
1048 base_format
== GL_STENCIL_INDEX
) {
1053 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1054 __FUNCTION__
, pname
);
1063 * Returns the number of channels/components for a base format.
1066 _mesa_base_format_component_count(GLenum base_format
)
1068 switch (base_format
) {
1072 case GL_DEPTH_COMPONENT
:
1075 case GL_LUMINANCE_ALPHA
:
1076 case GL_DEPTH_STENCIL
:
1089 * If format is a generic compressed format, return the corresponding
1090 * non-compressed format. For other formats, return the format as-is.
1093 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1096 case GL_COMPRESSED_RED
:
1098 case GL_COMPRESSED_RG
:
1100 case GL_COMPRESSED_RGB
:
1102 case GL_COMPRESSED_RGBA
:
1104 case GL_COMPRESSED_ALPHA
:
1106 case GL_COMPRESSED_LUMINANCE
:
1107 return GL_LUMINANCE
;
1108 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1109 return GL_LUMINANCE_ALPHA
;
1110 case GL_COMPRESSED_INTENSITY
:
1111 return GL_INTENSITY
;
1113 case GL_COMPRESSED_SRGB
:
1115 case GL_COMPRESSED_SRGB_ALPHA
:
1116 return GL_SRGB_ALPHA
;
1117 case GL_COMPRESSED_SLUMINANCE
:
1118 return GL_SLUMINANCE
;
1119 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1120 return GL_SLUMINANCE_ALPHA
;
1128 * Return the equivalent non-generic internal format.
1129 * This is useful for comparing whether two internal formats are equivalent.
1132 _mesa_get_nongeneric_internalformat(GLenum format
)
1135 /* GL 1.1 formats. */
1145 case GL_LUMINANCE_ALPHA
:
1146 return GL_LUMINANCE8_ALPHA8
;
1150 return GL_LUMINANCE8
;
1156 return GL_INTENSITY8
;
1158 /* GL_ARB_texture_rg */
1165 /* GL_EXT_texture_sRGB */
1170 return GL_SRGB8_ALPHA8
;
1173 return GL_SLUMINANCE8
;
1175 case GL_SLUMINANCE_ALPHA
:
1176 return GL_SLUMINANCE8_ALPHA8
;
1178 /* GL_EXT_texture_snorm */
1180 return GL_RGBA8_SNORM
;
1183 return GL_RGB8_SNORM
;
1186 return GL_RG8_SNORM
;
1191 case GL_LUMINANCE_ALPHA_SNORM
:
1192 return GL_LUMINANCE8_ALPHA8_SNORM
;
1194 case GL_LUMINANCE_SNORM
:
1195 return GL_LUMINANCE8_SNORM
;
1197 case GL_ALPHA_SNORM
:
1198 return GL_ALPHA8_SNORM
;
1200 case GL_INTENSITY_SNORM
:
1201 return GL_INTENSITY8_SNORM
;
1210 * Convert an sRGB internal format to linear.
1213 _mesa_get_linear_internalformat(GLenum format
)
1225 case GL_SRGB8_ALPHA8
:
1229 return GL_LUMINANCE8
;
1231 case GL_SLUMINANCE_ALPHA
:
1232 return GL_LUMINANCE8_ALPHA8
;
1241 * Do error checking of format/type combinations for glReadPixels,
1242 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1243 * and type values, we may either generate GL_INVALID_OPERATION or
1246 * \param format pixel format.
1247 * \param type pixel type.
1249 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1252 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1253 GLenum format
, GLenum type
)
1255 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1258 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1259 return GL_INVALID_ENUM
;
1263 case GL_UNSIGNED_BYTE_3_3_2
:
1264 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1265 case GL_UNSIGNED_SHORT_5_6_5
:
1266 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1267 if (format
== GL_RGB
) {
1270 if (format
== GL_RGB_INTEGER_EXT
&&
1271 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1274 return GL_INVALID_OPERATION
;
1276 case GL_UNSIGNED_SHORT_4_4_4_4
:
1277 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1278 case GL_UNSIGNED_SHORT_5_5_5_1
:
1279 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1280 case GL_UNSIGNED_INT_8_8_8_8
:
1281 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1282 case GL_UNSIGNED_INT_10_10_10_2
:
1283 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1284 if (format
== GL_RGBA
||
1285 format
== GL_BGRA
||
1286 format
== GL_ABGR_EXT
) {
1289 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1290 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1293 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1294 ctx
->API
== API_OPENGLES2
) {
1295 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1297 return GL_INVALID_OPERATION
;
1299 case GL_UNSIGNED_INT_24_8
:
1300 if (!ctx
->Extensions
.EXT_packed_depth_stencil
) {
1301 return GL_INVALID_ENUM
;
1303 if (format
!= GL_DEPTH_STENCIL
) {
1304 return GL_INVALID_OPERATION
;
1308 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1309 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1310 return GL_INVALID_ENUM
;
1312 if (format
!= GL_DEPTH_STENCIL
) {
1313 return GL_INVALID_OPERATION
;
1317 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1318 if (!ctx
->Extensions
.EXT_packed_float
) {
1319 return GL_INVALID_ENUM
;
1321 if (format
!= GL_RGB
) {
1322 return GL_INVALID_OPERATION
;
1327 ; /* fall-through */
1330 /* now, for each format, check the type for compatibility */
1332 case GL_COLOR_INDEX
:
1333 case GL_STENCIL_INDEX
:
1337 case GL_UNSIGNED_BYTE
:
1339 case GL_UNSIGNED_SHORT
:
1341 case GL_UNSIGNED_INT
:
1345 return ctx
->Extensions
.ARB_half_float_pixel
1346 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1348 return GL_INVALID_ENUM
;
1355 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1359 case GL_LUMINANCE_ALPHA
:
1360 case GL_DEPTH_COMPONENT
:
1363 case GL_UNSIGNED_BYTE
:
1365 case GL_UNSIGNED_SHORT
:
1367 case GL_UNSIGNED_INT
:
1371 return ctx
->Extensions
.ARB_half_float_pixel
1372 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1374 return GL_INVALID_ENUM
;
1378 if (!ctx
->Extensions
.ARB_texture_rg
)
1379 return GL_INVALID_ENUM
;
1382 case GL_UNSIGNED_BYTE
:
1384 case GL_UNSIGNED_SHORT
:
1386 case GL_UNSIGNED_INT
:
1390 return ctx
->Extensions
.ARB_half_float_pixel
1391 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1393 return GL_INVALID_ENUM
;
1399 case GL_UNSIGNED_BYTE
:
1401 case GL_UNSIGNED_SHORT
:
1403 case GL_UNSIGNED_INT
:
1405 case GL_UNSIGNED_BYTE_3_3_2
:
1406 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1407 case GL_UNSIGNED_SHORT_5_6_5
:
1408 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1410 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1411 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1412 return (ctx
->API
== API_OPENGLES2
)
1413 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1415 return ctx
->Extensions
.ARB_half_float_pixel
1416 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1417 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1418 return ctx
->Extensions
.EXT_texture_shared_exponent
1419 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1420 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1421 return ctx
->Extensions
.EXT_packed_float
1422 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1424 return GL_INVALID_ENUM
;
1429 /* NOTE: no packed types are supported with BGR. That's
1430 * intentional, according to the GL spec.
1433 case GL_UNSIGNED_BYTE
:
1435 case GL_UNSIGNED_SHORT
:
1437 case GL_UNSIGNED_INT
:
1441 return ctx
->Extensions
.ARB_half_float_pixel
1442 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1444 return GL_INVALID_ENUM
;
1452 case GL_UNSIGNED_BYTE
:
1454 case GL_UNSIGNED_SHORT
:
1456 case GL_UNSIGNED_INT
:
1458 case GL_UNSIGNED_SHORT_4_4_4_4
:
1459 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1460 case GL_UNSIGNED_SHORT_5_5_5_1
:
1461 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1462 case GL_UNSIGNED_INT_8_8_8_8
:
1463 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1464 case GL_UNSIGNED_INT_10_10_10_2
:
1465 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1468 return ctx
->Extensions
.ARB_half_float_pixel
1469 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1471 return GL_INVALID_ENUM
;
1475 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1476 return GL_INVALID_ENUM
;
1477 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1478 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1481 return GL_INVALID_OPERATION
;
1483 case GL_DEPTH_STENCIL_EXT
:
1484 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
1485 type
== GL_UNSIGNED_INT_24_8
)
1487 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1488 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1492 case GL_UNSIGNED_BYTE
:
1494 case GL_UNSIGNED_SHORT
:
1496 case GL_UNSIGNED_INT
:
1498 return GL_INVALID_OPERATION
;
1500 return GL_INVALID_ENUM
;
1505 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1506 return GL_INVALID_ENUM
;
1509 case GL_UNSIGNED_BYTE
:
1511 case GL_UNSIGNED_SHORT
:
1513 case GL_UNSIGNED_INT
:
1517 return GL_INVALID_ENUM
;
1520 /* integer-valued formats */
1521 case GL_RED_INTEGER_EXT
:
1522 case GL_GREEN_INTEGER_EXT
:
1523 case GL_BLUE_INTEGER_EXT
:
1524 case GL_ALPHA_INTEGER_EXT
:
1528 case GL_UNSIGNED_BYTE
:
1530 case GL_UNSIGNED_SHORT
:
1532 case GL_UNSIGNED_INT
:
1533 return (ctx
->Version
>= 30 ||
1534 ctx
->Extensions
.EXT_texture_integer
)
1535 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1537 return GL_INVALID_ENUM
;
1540 case GL_RGB_INTEGER_EXT
:
1543 case GL_UNSIGNED_BYTE
:
1545 case GL_UNSIGNED_SHORT
:
1547 case GL_UNSIGNED_INT
:
1548 return (ctx
->Version
>= 30 ||
1549 ctx
->Extensions
.EXT_texture_integer
)
1550 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1551 case GL_UNSIGNED_BYTE_3_3_2
:
1552 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1553 case GL_UNSIGNED_SHORT_5_6_5
:
1554 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1555 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1556 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1558 return GL_INVALID_ENUM
;
1561 case GL_BGR_INTEGER_EXT
:
1564 case GL_UNSIGNED_BYTE
:
1566 case GL_UNSIGNED_SHORT
:
1568 case GL_UNSIGNED_INT
:
1569 /* NOTE: no packed formats w/ BGR format */
1570 return (ctx
->Version
>= 30 ||
1571 ctx
->Extensions
.EXT_texture_integer
)
1572 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1574 return GL_INVALID_ENUM
;
1577 case GL_RGBA_INTEGER_EXT
:
1578 case GL_BGRA_INTEGER_EXT
:
1581 case GL_UNSIGNED_BYTE
:
1583 case GL_UNSIGNED_SHORT
:
1585 case GL_UNSIGNED_INT
:
1586 return (ctx
->Version
>= 30 ||
1587 ctx
->Extensions
.EXT_texture_integer
)
1588 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1589 case GL_UNSIGNED_SHORT_4_4_4_4
:
1590 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1591 case GL_UNSIGNED_SHORT_5_5_5_1
:
1592 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1593 case GL_UNSIGNED_INT_8_8_8_8
:
1594 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1595 case GL_UNSIGNED_INT_10_10_10_2
:
1596 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1597 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1598 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1600 return GL_INVALID_ENUM
;
1603 case GL_LUMINANCE_INTEGER_EXT
:
1604 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1607 case GL_UNSIGNED_BYTE
:
1609 case GL_UNSIGNED_SHORT
:
1611 case GL_UNSIGNED_INT
:
1612 return ctx
->Extensions
.EXT_texture_integer
1613 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1615 return GL_INVALID_ENUM
;
1619 return GL_INVALID_ENUM
;
1626 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1627 * and glTex[Sub]Image.
1628 * \return error code, or GL_NO_ERROR.
1631 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1632 unsigned dimensions
)
1634 GLboolean type_valid
= GL_TRUE
;
1639 case GL_LUMINANCE_ALPHA
:
1640 type_valid
= (type
== GL_UNSIGNED_BYTE
1642 || type
== GL_HALF_FLOAT_OES
);
1646 type_valid
= (type
== GL_UNSIGNED_BYTE
1647 || type
== GL_UNSIGNED_SHORT_5_6_5
1649 || type
== GL_HALF_FLOAT_OES
);
1653 type_valid
= (type
== GL_UNSIGNED_BYTE
1654 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1655 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1657 || type
== GL_HALF_FLOAT_OES
1658 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1661 case GL_DEPTH_COMPONENT
:
1662 /* This format is filtered against invalid dimensionalities elsewhere.
1664 type_valid
= (type
== GL_UNSIGNED_SHORT
1665 || type
== GL_UNSIGNED_INT
);
1668 case GL_DEPTH_STENCIL
:
1669 /* This format is filtered against invalid dimensionalities elsewhere.
1671 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1675 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1677 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1678 * the format does not appear to be allowed for 3D textures in OpenGL
1681 if (dimensions
!= 2)
1682 return GL_INVALID_VALUE
;
1687 return GL_INVALID_VALUE
;
1690 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1695 * Do error checking of format/type combinations for OpenGL ES 3
1697 * \return error code, or GL_NO_ERROR.
1700 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1701 GLenum internalFormat
)
1703 GLboolean type_valid
= GL_TRUE
;
1708 case GL_UNSIGNED_BYTE
:
1709 switch (internalFormat
) {
1714 case GL_SRGB8_ALPHA8_EXT
:
1717 return GL_INVALID_OPERATION
;
1722 if (internalFormat
!= GL_RGBA8_SNORM
)
1723 return GL_INVALID_OPERATION
;
1726 case GL_UNSIGNED_SHORT_4_4_4_4
:
1727 switch (internalFormat
) {
1732 return GL_INVALID_OPERATION
;
1736 case GL_UNSIGNED_SHORT_5_5_5_1
:
1737 switch (internalFormat
) {
1742 return GL_INVALID_OPERATION
;
1746 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1747 switch (internalFormat
) {
1748 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1753 return GL_INVALID_OPERATION
;
1758 if (internalFormat
!= GL_RGBA16F
)
1759 return GL_INVALID_OPERATION
;
1763 switch (internalFormat
) {
1768 return GL_INVALID_OPERATION
;
1773 return GL_INVALID_OPERATION
;
1777 case GL_RGBA_INTEGER
:
1779 case GL_UNSIGNED_BYTE
:
1780 if (internalFormat
!= GL_RGBA8UI
)
1781 return GL_INVALID_OPERATION
;
1785 if (internalFormat
!= GL_RGBA8I
)
1786 return GL_INVALID_OPERATION
;
1789 case GL_UNSIGNED_SHORT
:
1790 if (internalFormat
!= GL_RGBA16UI
)
1791 return GL_INVALID_OPERATION
;
1795 if (internalFormat
!= GL_RGBA16I
)
1796 return GL_INVALID_OPERATION
;
1799 case GL_UNSIGNED_INT
:
1800 if (internalFormat
!= GL_RGBA32UI
)
1801 return GL_INVALID_OPERATION
;
1805 if (internalFormat
!= GL_RGBA32I
)
1806 return GL_INVALID_OPERATION
;
1809 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1810 if (internalFormat
!= GL_RGB10_A2UI
)
1811 return GL_INVALID_OPERATION
;
1815 return GL_INVALID_OPERATION
;
1821 case GL_UNSIGNED_BYTE
:
1822 switch (internalFormat
) {
1829 return GL_INVALID_OPERATION
;
1834 if (internalFormat
!= GL_RGB8_SNORM
)
1835 return GL_INVALID_OPERATION
;
1838 case GL_UNSIGNED_SHORT_5_6_5
:
1839 switch (internalFormat
) {
1844 return GL_INVALID_OPERATION
;
1848 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1849 if (internalFormat
!= GL_R11F_G11F_B10F
)
1850 return GL_INVALID_OPERATION
;
1853 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1854 if (internalFormat
!= GL_RGB9_E5
)
1855 return GL_INVALID_OPERATION
;
1859 switch (internalFormat
) {
1861 case GL_R11F_G11F_B10F
:
1865 return GL_INVALID_OPERATION
;
1870 switch (internalFormat
) {
1873 case GL_R11F_G11F_B10F
:
1877 return GL_INVALID_OPERATION
;
1881 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1882 switch (internalFormat
) {
1883 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1886 return GL_INVALID_OPERATION
;
1891 return GL_INVALID_OPERATION
;
1895 case GL_RGB_INTEGER
:
1897 case GL_UNSIGNED_BYTE
:
1898 if (internalFormat
!= GL_RGB8UI
)
1899 return GL_INVALID_OPERATION
;
1903 if (internalFormat
!= GL_RGB8I
)
1904 return GL_INVALID_OPERATION
;
1907 case GL_UNSIGNED_SHORT
:
1908 if (internalFormat
!= GL_RGB16UI
)
1909 return GL_INVALID_OPERATION
;
1913 if (internalFormat
!= GL_RGB16I
)
1914 return GL_INVALID_OPERATION
;
1917 case GL_UNSIGNED_INT
:
1918 if (internalFormat
!= GL_RGB32UI
)
1919 return GL_INVALID_OPERATION
;
1923 if (internalFormat
!= GL_RGB32I
)
1924 return GL_INVALID_OPERATION
;
1928 return GL_INVALID_OPERATION
;
1934 case GL_UNSIGNED_BYTE
:
1935 if (internalFormat
!= GL_RG8
)
1936 return GL_INVALID_OPERATION
;
1940 if (internalFormat
!= GL_RG8_SNORM
)
1941 return GL_INVALID_OPERATION
;
1945 if (internalFormat
!= GL_RG16F
)
1946 return GL_INVALID_OPERATION
;
1950 switch (internalFormat
) {
1955 return GL_INVALID_OPERATION
;
1960 return GL_INVALID_OPERATION
;
1966 case GL_UNSIGNED_BYTE
:
1967 if (internalFormat
!= GL_RG8UI
)
1968 return GL_INVALID_OPERATION
;
1972 if (internalFormat
!= GL_RG8I
)
1973 return GL_INVALID_OPERATION
;
1976 case GL_UNSIGNED_SHORT
:
1977 if (internalFormat
!= GL_RG16UI
)
1978 return GL_INVALID_OPERATION
;
1982 if (internalFormat
!= GL_RG16I
)
1983 return GL_INVALID_OPERATION
;
1986 case GL_UNSIGNED_INT
:
1987 if (internalFormat
!= GL_RG32UI
)
1988 return GL_INVALID_OPERATION
;
1992 if (internalFormat
!= GL_RG32I
)
1993 return GL_INVALID_OPERATION
;
1997 return GL_INVALID_OPERATION
;
2003 case GL_UNSIGNED_BYTE
:
2004 if (internalFormat
!= GL_R8
)
2005 return GL_INVALID_OPERATION
;
2009 if (internalFormat
!= GL_R8_SNORM
)
2010 return GL_INVALID_OPERATION
;
2014 if (internalFormat
!= GL_R16F
)
2015 return GL_INVALID_OPERATION
;
2019 switch (internalFormat
) {
2024 return GL_INVALID_OPERATION
;
2029 return GL_INVALID_OPERATION
;
2033 case GL_RED_INTEGER
:
2035 case GL_UNSIGNED_BYTE
:
2036 if (internalFormat
!= GL_R8UI
)
2037 return GL_INVALID_OPERATION
;
2041 if (internalFormat
!= GL_R8I
)
2042 return GL_INVALID_OPERATION
;
2045 case GL_UNSIGNED_SHORT
:
2046 if (internalFormat
!= GL_R16UI
)
2047 return GL_INVALID_OPERATION
;
2051 if (internalFormat
!= GL_R16I
)
2052 return GL_INVALID_OPERATION
;
2055 case GL_UNSIGNED_INT
:
2056 if (internalFormat
!= GL_R32UI
)
2057 return GL_INVALID_OPERATION
;
2061 if (internalFormat
!= GL_R32I
)
2062 return GL_INVALID_OPERATION
;
2066 return GL_INVALID_OPERATION
;
2070 case GL_DEPTH_COMPONENT
:
2072 case GL_UNSIGNED_SHORT
:
2073 if (internalFormat
!= GL_DEPTH_COMPONENT
2074 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2075 return GL_INVALID_OPERATION
;
2078 case GL_UNSIGNED_INT
:
2079 switch (internalFormat
) {
2080 case GL_DEPTH_COMPONENT
:
2081 case GL_DEPTH_COMPONENT16
:
2082 case GL_DEPTH_COMPONENT24
:
2085 return GL_INVALID_OPERATION
;
2090 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2091 return GL_INVALID_OPERATION
;
2095 return GL_INVALID_OPERATION
;
2099 case GL_DEPTH_STENCIL
:
2101 case GL_UNSIGNED_INT_24_8
:
2102 if (internalFormat
!= GL_DEPTH_STENCIL
2103 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2104 return GL_INVALID_OPERATION
;
2107 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2108 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2109 return GL_INVALID_OPERATION
;
2113 return GL_INVALID_OPERATION
;
2119 case GL_LUMINANCE_ALPHA
:
2120 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2121 return GL_INVALID_OPERATION
;
2125 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;