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
);
355 * Test if the given format is an integer (non-normalized) format.
358 _mesa_is_enum_format_unsigned_int(GLenum format
)
361 /* specific integer formats */
362 case GL_RGBA32UI_EXT
:
366 case GL_ALPHA32UI_EXT
:
367 case GL_INTENSITY32UI_EXT
:
368 case GL_LUMINANCE32UI_EXT
:
369 case GL_LUMINANCE_ALPHA32UI_EXT
:
370 case GL_RGBA16UI_EXT
:
374 case GL_ALPHA16UI_EXT
:
375 case GL_INTENSITY16UI_EXT
:
376 case GL_LUMINANCE16UI_EXT
:
377 case GL_LUMINANCE_ALPHA16UI_EXT
:
382 case GL_ALPHA8UI_EXT
:
383 case GL_INTENSITY8UI_EXT
:
384 case GL_LUMINANCE8UI_EXT
:
385 case GL_LUMINANCE_ALPHA8UI_EXT
:
395 * Test if the given format is an integer (non-normalized) format.
398 _mesa_is_enum_format_signed_int(GLenum format
)
401 /* generic integer formats */
402 case GL_RED_INTEGER_EXT
:
403 case GL_GREEN_INTEGER_EXT
:
404 case GL_BLUE_INTEGER_EXT
:
405 case GL_ALPHA_INTEGER_EXT
:
406 case GL_RGB_INTEGER_EXT
:
407 case GL_RGBA_INTEGER_EXT
:
408 case GL_BGR_INTEGER_EXT
:
409 case GL_BGRA_INTEGER_EXT
:
410 case GL_LUMINANCE_INTEGER_EXT
:
411 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
413 /* specific integer formats */
418 case GL_ALPHA32I_EXT
:
419 case GL_INTENSITY32I_EXT
:
420 case GL_LUMINANCE32I_EXT
:
421 case GL_LUMINANCE_ALPHA32I_EXT
:
426 case GL_ALPHA16I_EXT
:
427 case GL_INTENSITY16I_EXT
:
428 case GL_LUMINANCE16I_EXT
:
429 case GL_LUMINANCE_ALPHA16I_EXT
:
435 case GL_INTENSITY8I_EXT
:
436 case GL_LUMINANCE8I_EXT
:
437 case GL_LUMINANCE_ALPHA8I_EXT
:
446 * Test if the given format is an integer (non-normalized) format.
449 _mesa_is_enum_format_integer(GLenum format
)
451 return _mesa_is_enum_format_unsigned_int(format
) ||
452 _mesa_is_enum_format_signed_int(format
);
457 * Test if the given type is an integer (non-normalized) format.
460 _mesa_is_type_integer(GLenum type
)
464 case GL_UNSIGNED_INT
:
466 case GL_UNSIGNED_SHORT
:
468 case GL_UNSIGNED_BYTE
:
477 * Test if the given format or type is an integer (non-normalized) format.
480 _mesa_is_enum_format_or_type_integer(GLenum format
, GLenum type
)
482 return _mesa_is_enum_format_integer(format
) || _mesa_is_type_integer(type
);
487 _mesa_is_type_unsigned(GLenum type
)
490 case GL_UNSIGNED_INT
:
491 case GL_UNSIGNED_INT_8_8_8_8
:
492 case GL_UNSIGNED_INT_8_8_8_8_REV
:
493 case GL_UNSIGNED_INT_10_10_10_2
:
494 case GL_UNSIGNED_INT_2_10_10_10_REV
:
496 case GL_UNSIGNED_SHORT
:
497 case GL_UNSIGNED_SHORT_4_4_4_4
:
498 case GL_UNSIGNED_SHORT_5_5_5_1
:
499 case GL_UNSIGNED_SHORT_5_6_5
:
500 case GL_UNSIGNED_SHORT_5_6_5_REV
:
501 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
502 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
503 case GL_UNSIGNED_SHORT_8_8_MESA
:
504 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
506 case GL_UNSIGNED_BYTE
:
507 case GL_UNSIGNED_BYTE_3_3_2
:
508 case GL_UNSIGNED_BYTE_2_3_3_REV
:
518 * Test if the given image format is a color/RGBA format (i.e., not color
519 * index, depth, stencil, etc).
520 * \param format the image format value (may by an internal texture format)
521 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
524 _mesa_is_color_format(GLenum format
)
542 case GL_LUMINANCE_ALPHA
:
543 case GL_LUMINANCE4_ALPHA4
:
544 case GL_LUMINANCE6_ALPHA2
:
545 case GL_LUMINANCE8_ALPHA8
:
546 case GL_LUMINANCE12_ALPHA4
:
547 case GL_LUMINANCE12_ALPHA12
:
548 case GL_LUMINANCE16_ALPHA16
:
581 /* float texture formats */
582 case GL_ALPHA16F_ARB
:
583 case GL_ALPHA32F_ARB
:
584 case GL_LUMINANCE16F_ARB
:
585 case GL_LUMINANCE32F_ARB
:
586 case GL_LUMINANCE_ALPHA16F_ARB
:
587 case GL_LUMINANCE_ALPHA32F_ARB
:
588 case GL_INTENSITY16F_ARB
:
589 case GL_INTENSITY32F_ARB
:
598 /* compressed formats */
599 case GL_COMPRESSED_ALPHA
:
600 case GL_COMPRESSED_LUMINANCE
:
601 case GL_COMPRESSED_LUMINANCE_ALPHA
:
602 case GL_COMPRESSED_INTENSITY
:
603 case GL_COMPRESSED_RED
:
604 case GL_COMPRESSED_RG
:
605 case GL_COMPRESSED_RGB
:
606 case GL_COMPRESSED_RGBA
:
611 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
612 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
613 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
614 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
615 case GL_COMPRESSED_RGB_FXT1_3DFX
:
616 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
619 case GL_SRGB_ALPHA_EXT
:
620 case GL_SRGB8_ALPHA8_EXT
:
621 case GL_SLUMINANCE_ALPHA_EXT
:
622 case GL_SLUMINANCE8_ALPHA8_EXT
:
623 case GL_SLUMINANCE_EXT
:
624 case GL_SLUMINANCE8_EXT
:
625 case GL_COMPRESSED_SRGB_EXT
:
626 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
627 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
628 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
629 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
630 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
631 case GL_COMPRESSED_SLUMINANCE_EXT
:
632 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
633 case GL_COMPRESSED_RED_RGTC1
:
634 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
635 case GL_COMPRESSED_RG_RGTC2
:
636 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
637 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
638 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
639 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
640 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
641 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
642 case GL_ETC1_RGB8_OES
:
643 case GL_COMPRESSED_RGB8_ETC2
:
644 case GL_COMPRESSED_SRGB8_ETC2
:
645 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
646 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
647 case GL_COMPRESSED_R11_EAC
:
648 case GL_COMPRESSED_RG11_EAC
:
649 case GL_COMPRESSED_SIGNED_R11_EAC
:
650 case GL_COMPRESSED_SIGNED_RG11_EAC
:
651 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
652 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
653 /* generic integer formats */
654 case GL_RED_INTEGER_EXT
:
655 case GL_GREEN_INTEGER_EXT
:
656 case GL_BLUE_INTEGER_EXT
:
657 case GL_ALPHA_INTEGER_EXT
:
658 case GL_RGB_INTEGER_EXT
:
659 case GL_RGBA_INTEGER_EXT
:
660 case GL_BGR_INTEGER_EXT
:
661 case GL_BGRA_INTEGER_EXT
:
663 case GL_LUMINANCE_INTEGER_EXT
:
664 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
665 /* sized integer formats */
666 case GL_RGBA32UI_EXT
:
670 case GL_ALPHA32UI_EXT
:
671 case GL_INTENSITY32UI_EXT
:
672 case GL_LUMINANCE32UI_EXT
:
673 case GL_LUMINANCE_ALPHA32UI_EXT
:
674 case GL_RGBA16UI_EXT
:
678 case GL_ALPHA16UI_EXT
:
679 case GL_INTENSITY16UI_EXT
:
680 case GL_LUMINANCE16UI_EXT
:
681 case GL_LUMINANCE_ALPHA16UI_EXT
:
686 case GL_ALPHA8UI_EXT
:
687 case GL_INTENSITY8UI_EXT
:
688 case GL_LUMINANCE8UI_EXT
:
689 case GL_LUMINANCE_ALPHA8UI_EXT
:
694 case GL_ALPHA32I_EXT
:
695 case GL_INTENSITY32I_EXT
:
696 case GL_LUMINANCE32I_EXT
:
697 case GL_LUMINANCE_ALPHA32I_EXT
:
702 case GL_ALPHA16I_EXT
:
703 case GL_INTENSITY16I_EXT
:
704 case GL_LUMINANCE16I_EXT
:
705 case GL_LUMINANCE_ALPHA16I_EXT
:
711 case GL_INTENSITY8I_EXT
:
712 case GL_LUMINANCE8I_EXT
:
713 case GL_LUMINANCE_ALPHA8I_EXT
:
714 /* signed, normalized texture formats */
726 case GL_RGBA16_SNORM
:
728 case GL_ALPHA8_SNORM
:
729 case GL_ALPHA16_SNORM
:
730 case GL_LUMINANCE_SNORM
:
731 case GL_LUMINANCE8_SNORM
:
732 case GL_LUMINANCE16_SNORM
:
733 case GL_LUMINANCE_ALPHA_SNORM
:
734 case GL_LUMINANCE8_ALPHA8_SNORM
:
735 case GL_LUMINANCE16_ALPHA16_SNORM
:
736 case GL_INTENSITY_SNORM
:
737 case GL_INTENSITY8_SNORM
:
738 case GL_INTENSITY16_SNORM
:
740 case GL_R11F_G11F_B10F
:
743 case GL_YCBCR_MESA
: /* not considered to be RGB */
752 * Test if the given image format is a depth component format.
755 _mesa_is_depth_format(GLenum format
)
758 case GL_DEPTH_COMPONENT
:
759 case GL_DEPTH_COMPONENT16
:
760 case GL_DEPTH_COMPONENT24
:
761 case GL_DEPTH_COMPONENT32
:
762 case GL_DEPTH_COMPONENT32F
:
771 * Test if the given image format is a stencil format.
774 _mesa_is_stencil_format(GLenum format
)
777 case GL_STENCIL_INDEX
:
786 * Test if the given image format is a YCbCr format.
789 _mesa_is_ycbcr_format(GLenum format
)
801 * Test if the given image format is a depth+stencil format.
804 _mesa_is_depthstencil_format(GLenum format
)
807 case GL_DEPTH24_STENCIL8_EXT
:
808 case GL_DEPTH_STENCIL_EXT
:
809 case GL_DEPTH32F_STENCIL8
:
818 * Test if the given image format is a depth or stencil format.
821 _mesa_is_depth_or_stencil_format(GLenum format
)
824 case GL_DEPTH_COMPONENT
:
825 case GL_DEPTH_COMPONENT16
:
826 case GL_DEPTH_COMPONENT24
:
827 case GL_DEPTH_COMPONENT32
:
828 case GL_STENCIL_INDEX
:
829 case GL_STENCIL_INDEX1_EXT
:
830 case GL_STENCIL_INDEX4_EXT
:
831 case GL_STENCIL_INDEX8_EXT
:
832 case GL_STENCIL_INDEX16_EXT
:
833 case GL_DEPTH_STENCIL_EXT
:
834 case GL_DEPTH24_STENCIL8_EXT
:
835 case GL_DEPTH_COMPONENT32F
:
836 case GL_DEPTH32F_STENCIL8
:
845 * Test if the given image format is a dudv format.
848 _mesa_is_dudv_format(GLenum format
)
861 * Test if an image format is a supported compressed format.
862 * \param format the internal format token provided by the user.
863 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
866 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
869 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
870 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
871 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
872 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
873 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
875 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
880 return _mesa_is_desktop_gl(ctx
) &&
881 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
882 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
883 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
884 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
885 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
886 return _mesa_is_desktop_gl(ctx
)
887 && ctx
->Extensions
.EXT_texture_sRGB
888 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
889 case GL_COMPRESSED_RGB_FXT1_3DFX
:
890 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
891 return _mesa_is_desktop_gl(ctx
)
892 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
893 case GL_COMPRESSED_RED_RGTC1
:
894 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
895 case GL_COMPRESSED_RG_RGTC2
:
896 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
897 return _mesa_is_desktop_gl(ctx
)
898 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
899 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
900 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
901 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
902 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
903 return ctx
->API
== API_OPENGL_COMPAT
904 && ctx
->Extensions
.EXT_texture_compression_latc
;
905 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
906 return ctx
->API
== API_OPENGL_COMPAT
907 && ctx
->Extensions
.ATI_texture_compression_3dc
;
908 case GL_ETC1_RGB8_OES
:
909 return _mesa_is_gles(ctx
)
910 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
911 case GL_COMPRESSED_RGB8_ETC2
:
912 case GL_COMPRESSED_SRGB8_ETC2
:
913 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
914 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
915 case GL_COMPRESSED_R11_EAC
:
916 case GL_COMPRESSED_RG11_EAC
:
917 case GL_COMPRESSED_SIGNED_R11_EAC
:
918 case GL_COMPRESSED_SIGNED_RG11_EAC
:
919 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
920 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
921 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
922 case GL_PALETTE4_RGB8_OES
:
923 case GL_PALETTE4_RGBA8_OES
:
924 case GL_PALETTE4_R5_G6_B5_OES
:
925 case GL_PALETTE4_RGBA4_OES
:
926 case GL_PALETTE4_RGB5_A1_OES
:
927 case GL_PALETTE8_RGB8_OES
:
928 case GL_PALETTE8_RGBA8_OES
:
929 case GL_PALETTE8_R5_G6_B5_OES
:
930 case GL_PALETTE8_RGBA4_OES
:
931 case GL_PALETTE8_RGB5_A1_OES
:
932 return ctx
->API
== API_OPENGLES
;
940 * Convert various base formats to the cooresponding integer format.
943 _mesa_base_format_to_integer_format(GLenum format
)
947 return GL_RED_INTEGER
;
949 return GL_GREEN_INTEGER
;
951 return GL_BLUE_INTEGER
;
953 return GL_RG_INTEGER
;
955 return GL_RGB_INTEGER
;
957 return GL_RGBA_INTEGER
;
959 return GL_BGR_INTEGER
;
961 return GL_BGRA_INTEGER
;
963 return GL_ALPHA_INTEGER
;
965 return GL_LUMINANCE_INTEGER_EXT
;
966 case GL_LUMINANCE_ALPHA
:
967 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
975 * Does the given base texture/renderbuffer format have the channel
979 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
982 case GL_TEXTURE_RED_SIZE
:
983 case GL_TEXTURE_RED_TYPE
:
984 case GL_RENDERBUFFER_RED_SIZE_EXT
:
985 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
986 if (base_format
== GL_RED
||
987 base_format
== GL_RG
||
988 base_format
== GL_RGB
||
989 base_format
== GL_RGBA
) {
993 case GL_TEXTURE_GREEN_SIZE
:
994 case GL_TEXTURE_GREEN_TYPE
:
995 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
996 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
997 if (base_format
== GL_RG
||
998 base_format
== GL_RGB
||
999 base_format
== GL_RGBA
) {
1003 case GL_TEXTURE_BLUE_SIZE
:
1004 case GL_TEXTURE_BLUE_TYPE
:
1005 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1006 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1007 if (base_format
== GL_RGB
||
1008 base_format
== GL_RGBA
) {
1012 case GL_TEXTURE_ALPHA_SIZE
:
1013 case GL_TEXTURE_ALPHA_TYPE
:
1014 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1015 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1016 if (base_format
== GL_RGBA
||
1017 base_format
== GL_ALPHA
||
1018 base_format
== GL_LUMINANCE_ALPHA
) {
1022 case GL_TEXTURE_LUMINANCE_SIZE
:
1023 case GL_TEXTURE_LUMINANCE_TYPE
:
1024 if (base_format
== GL_LUMINANCE
||
1025 base_format
== GL_LUMINANCE_ALPHA
) {
1029 case GL_TEXTURE_INTENSITY_SIZE
:
1030 case GL_TEXTURE_INTENSITY_TYPE
:
1031 if (base_format
== GL_INTENSITY
) {
1035 case GL_TEXTURE_DEPTH_SIZE
:
1036 case GL_TEXTURE_DEPTH_TYPE
:
1037 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1038 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1039 if (base_format
== GL_DEPTH_STENCIL
||
1040 base_format
== GL_DEPTH_COMPONENT
) {
1044 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1045 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1046 if (base_format
== GL_DEPTH_STENCIL
||
1047 base_format
== GL_STENCIL_INDEX
) {
1052 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1053 __FUNCTION__
, pname
);
1062 * Returns the number of channels/components for a base format.
1065 _mesa_base_format_component_count(GLenum base_format
)
1067 switch (base_format
) {
1071 case GL_DEPTH_COMPONENT
:
1074 case GL_LUMINANCE_ALPHA
:
1075 case GL_DEPTH_STENCIL
:
1088 * If format is a generic compressed format, return the corresponding
1089 * non-compressed format. For other formats, return the format as-is.
1092 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1095 case GL_COMPRESSED_RED
:
1097 case GL_COMPRESSED_RG
:
1099 case GL_COMPRESSED_RGB
:
1101 case GL_COMPRESSED_RGBA
:
1103 case GL_COMPRESSED_ALPHA
:
1105 case GL_COMPRESSED_LUMINANCE
:
1106 return GL_LUMINANCE
;
1107 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1108 return GL_LUMINANCE_ALPHA
;
1109 case GL_COMPRESSED_INTENSITY
:
1110 return GL_INTENSITY
;
1112 case GL_COMPRESSED_SRGB
:
1114 case GL_COMPRESSED_SRGB_ALPHA
:
1115 return GL_SRGB_ALPHA
;
1116 case GL_COMPRESSED_SLUMINANCE
:
1117 return GL_SLUMINANCE
;
1118 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1119 return GL_SLUMINANCE_ALPHA
;
1127 * Return the equivalent non-generic internal format.
1128 * This is useful for comparing whether two internal formats are equivalent.
1131 _mesa_get_nongeneric_internalformat(GLenum format
)
1134 /* GL 1.1 formats. */
1144 case GL_LUMINANCE_ALPHA
:
1145 return GL_LUMINANCE8_ALPHA8
;
1149 return GL_LUMINANCE8
;
1155 return GL_INTENSITY8
;
1157 /* GL_ARB_texture_rg */
1164 /* GL_EXT_texture_sRGB */
1169 return GL_SRGB8_ALPHA8
;
1172 return GL_SLUMINANCE8
;
1174 case GL_SLUMINANCE_ALPHA
:
1175 return GL_SLUMINANCE8_ALPHA8
;
1177 /* GL_EXT_texture_snorm */
1179 return GL_RGBA8_SNORM
;
1182 return GL_RGB8_SNORM
;
1185 return GL_RG8_SNORM
;
1190 case GL_LUMINANCE_ALPHA_SNORM
:
1191 return GL_LUMINANCE8_ALPHA8_SNORM
;
1193 case GL_LUMINANCE_SNORM
:
1194 return GL_LUMINANCE8_SNORM
;
1196 case GL_ALPHA_SNORM
:
1197 return GL_ALPHA8_SNORM
;
1199 case GL_INTENSITY_SNORM
:
1200 return GL_INTENSITY8_SNORM
;
1209 * Convert an sRGB internal format to linear.
1212 _mesa_get_linear_internalformat(GLenum format
)
1224 case GL_SRGB8_ALPHA8
:
1228 return GL_LUMINANCE8
;
1230 case GL_SLUMINANCE_ALPHA
:
1231 return GL_LUMINANCE8_ALPHA8
;
1240 * Do error checking of format/type combinations for glReadPixels,
1241 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1242 * and type values, we may either generate GL_INVALID_OPERATION or
1245 * \param format pixel format.
1246 * \param type pixel type.
1248 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1251 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1252 GLenum format
, GLenum type
)
1254 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1257 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1258 return GL_INVALID_ENUM
;
1262 case GL_UNSIGNED_BYTE_3_3_2
:
1263 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1264 case GL_UNSIGNED_SHORT_5_6_5
:
1265 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1266 if (format
== GL_RGB
) {
1269 if (format
== GL_RGB_INTEGER_EXT
&&
1270 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1273 return GL_INVALID_OPERATION
;
1275 case GL_UNSIGNED_SHORT_4_4_4_4
:
1276 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1277 case GL_UNSIGNED_SHORT_5_5_5_1
:
1278 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1279 case GL_UNSIGNED_INT_8_8_8_8
:
1280 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1281 case GL_UNSIGNED_INT_10_10_10_2
:
1282 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1283 if (format
== GL_RGBA
||
1284 format
== GL_BGRA
||
1285 format
== GL_ABGR_EXT
) {
1288 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1289 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1292 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1293 ctx
->API
== API_OPENGLES2
) {
1294 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1296 return GL_INVALID_OPERATION
;
1298 case GL_UNSIGNED_INT_24_8
:
1299 if (!ctx
->Extensions
.EXT_packed_depth_stencil
) {
1300 return GL_INVALID_ENUM
;
1302 if (format
!= GL_DEPTH_STENCIL
) {
1303 return GL_INVALID_OPERATION
;
1307 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1308 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1309 return GL_INVALID_ENUM
;
1311 if (format
!= GL_DEPTH_STENCIL
) {
1312 return GL_INVALID_OPERATION
;
1316 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1317 if (!ctx
->Extensions
.EXT_packed_float
) {
1318 return GL_INVALID_ENUM
;
1320 if (format
!= GL_RGB
) {
1321 return GL_INVALID_OPERATION
;
1326 ; /* fall-through */
1329 /* now, for each format, check the type for compatibility */
1331 case GL_COLOR_INDEX
:
1332 case GL_STENCIL_INDEX
:
1336 case GL_UNSIGNED_BYTE
:
1338 case GL_UNSIGNED_SHORT
:
1340 case GL_UNSIGNED_INT
:
1344 return ctx
->Extensions
.ARB_half_float_pixel
1345 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1347 return GL_INVALID_ENUM
;
1354 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1358 case GL_LUMINANCE_ALPHA
:
1359 case GL_DEPTH_COMPONENT
:
1362 case GL_UNSIGNED_BYTE
:
1364 case GL_UNSIGNED_SHORT
:
1366 case GL_UNSIGNED_INT
:
1370 return ctx
->Extensions
.ARB_half_float_pixel
1371 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1373 return GL_INVALID_ENUM
;
1377 if (!ctx
->Extensions
.ARB_texture_rg
)
1378 return GL_INVALID_ENUM
;
1381 case GL_UNSIGNED_BYTE
:
1383 case GL_UNSIGNED_SHORT
:
1385 case GL_UNSIGNED_INT
:
1389 return ctx
->Extensions
.ARB_half_float_pixel
1390 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1392 return GL_INVALID_ENUM
;
1398 case GL_UNSIGNED_BYTE
:
1400 case GL_UNSIGNED_SHORT
:
1402 case GL_UNSIGNED_INT
:
1404 case GL_UNSIGNED_BYTE_3_3_2
:
1405 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1406 case GL_UNSIGNED_SHORT_5_6_5
:
1407 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1409 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1410 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1411 return (ctx
->API
== API_OPENGLES2
)
1412 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1414 return ctx
->Extensions
.ARB_half_float_pixel
1415 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1416 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1417 return ctx
->Extensions
.EXT_texture_shared_exponent
1418 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1419 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1420 return ctx
->Extensions
.EXT_packed_float
1421 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1423 return GL_INVALID_ENUM
;
1428 /* NOTE: no packed types are supported with BGR. That's
1429 * intentional, according to the GL spec.
1432 case GL_UNSIGNED_BYTE
:
1434 case GL_UNSIGNED_SHORT
:
1436 case GL_UNSIGNED_INT
:
1440 return ctx
->Extensions
.ARB_half_float_pixel
1441 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1443 return GL_INVALID_ENUM
;
1451 case GL_UNSIGNED_BYTE
:
1453 case GL_UNSIGNED_SHORT
:
1455 case GL_UNSIGNED_INT
:
1457 case GL_UNSIGNED_SHORT_4_4_4_4
:
1458 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1459 case GL_UNSIGNED_SHORT_5_5_5_1
:
1460 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1461 case GL_UNSIGNED_INT_8_8_8_8
:
1462 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1463 case GL_UNSIGNED_INT_10_10_10_2
:
1464 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1467 return ctx
->Extensions
.ARB_half_float_pixel
1468 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1470 return GL_INVALID_ENUM
;
1474 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1475 return GL_INVALID_ENUM
;
1476 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1477 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1480 return GL_INVALID_OPERATION
;
1482 case GL_DEPTH_STENCIL_EXT
:
1483 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
1484 type
== GL_UNSIGNED_INT_24_8
)
1486 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1487 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1490 return GL_INVALID_ENUM
;
1494 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1495 return GL_INVALID_ENUM
;
1498 case GL_UNSIGNED_BYTE
:
1500 case GL_UNSIGNED_SHORT
:
1502 case GL_UNSIGNED_INT
:
1506 return GL_INVALID_ENUM
;
1509 /* integer-valued formats */
1510 case GL_RED_INTEGER_EXT
:
1511 case GL_GREEN_INTEGER_EXT
:
1512 case GL_BLUE_INTEGER_EXT
:
1513 case GL_ALPHA_INTEGER_EXT
:
1517 case GL_UNSIGNED_BYTE
:
1519 case GL_UNSIGNED_SHORT
:
1521 case GL_UNSIGNED_INT
:
1522 return (ctx
->Version
>= 30 ||
1523 ctx
->Extensions
.EXT_texture_integer
)
1524 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1526 return GL_INVALID_ENUM
;
1529 case GL_RGB_INTEGER_EXT
:
1532 case GL_UNSIGNED_BYTE
:
1534 case GL_UNSIGNED_SHORT
:
1536 case GL_UNSIGNED_INT
:
1537 return (ctx
->Version
>= 30 ||
1538 ctx
->Extensions
.EXT_texture_integer
)
1539 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1540 case GL_UNSIGNED_BYTE_3_3_2
:
1541 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1542 case GL_UNSIGNED_SHORT_5_6_5
:
1543 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1544 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1545 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1547 return GL_INVALID_ENUM
;
1550 case GL_BGR_INTEGER_EXT
:
1553 case GL_UNSIGNED_BYTE
:
1555 case GL_UNSIGNED_SHORT
:
1557 case GL_UNSIGNED_INT
:
1558 /* NOTE: no packed formats w/ BGR format */
1559 return (ctx
->Version
>= 30 ||
1560 ctx
->Extensions
.EXT_texture_integer
)
1561 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1563 return GL_INVALID_ENUM
;
1566 case GL_RGBA_INTEGER_EXT
:
1567 case GL_BGRA_INTEGER_EXT
:
1570 case GL_UNSIGNED_BYTE
:
1572 case GL_UNSIGNED_SHORT
:
1574 case GL_UNSIGNED_INT
:
1575 return (ctx
->Version
>= 30 ||
1576 ctx
->Extensions
.EXT_texture_integer
)
1577 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1578 case GL_UNSIGNED_SHORT_4_4_4_4
:
1579 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1580 case GL_UNSIGNED_SHORT_5_5_5_1
:
1581 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1582 case GL_UNSIGNED_INT_8_8_8_8
:
1583 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1584 case GL_UNSIGNED_INT_10_10_10_2
:
1585 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1586 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1587 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1589 return GL_INVALID_ENUM
;
1592 case GL_LUMINANCE_INTEGER_EXT
:
1593 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1596 case GL_UNSIGNED_BYTE
:
1598 case GL_UNSIGNED_SHORT
:
1600 case GL_UNSIGNED_INT
:
1601 return ctx
->Extensions
.EXT_texture_integer
1602 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1604 return GL_INVALID_ENUM
;
1608 return GL_INVALID_ENUM
;
1615 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1616 * and glTex[Sub]Image.
1617 * \return error code, or GL_NO_ERROR.
1620 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1621 unsigned dimensions
)
1623 GLboolean type_valid
= GL_TRUE
;
1628 case GL_LUMINANCE_ALPHA
:
1629 type_valid
= (type
== GL_UNSIGNED_BYTE
1631 || type
== GL_HALF_FLOAT_OES
);
1635 type_valid
= (type
== GL_UNSIGNED_BYTE
1636 || type
== GL_UNSIGNED_SHORT_5_6_5
1638 || type
== GL_HALF_FLOAT_OES
);
1642 type_valid
= (type
== GL_UNSIGNED_BYTE
1643 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1644 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1646 || type
== GL_HALF_FLOAT_OES
1647 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1650 case GL_DEPTH_COMPONENT
:
1651 /* This format is filtered against invalid dimensionalities elsewhere.
1653 type_valid
= (type
== GL_UNSIGNED_SHORT
1654 || type
== GL_UNSIGNED_INT
);
1657 case GL_DEPTH_STENCIL
:
1658 /* This format is filtered against invalid dimensionalities elsewhere.
1660 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1664 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1666 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1667 * the format does not appear to be allowed for 3D textures in OpenGL
1670 if (dimensions
!= 2)
1671 return GL_INVALID_VALUE
;
1676 return GL_INVALID_VALUE
;
1679 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1684 * Do error checking of format/type combinations for OpenGL ES 3
1686 * \return error code, or GL_NO_ERROR.
1689 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1690 GLenum internalFormat
)
1692 GLboolean type_valid
= GL_TRUE
;
1697 case GL_UNSIGNED_BYTE
:
1698 switch (internalFormat
) {
1703 case GL_SRGB8_ALPHA8_EXT
:
1706 return GL_INVALID_OPERATION
;
1711 if (internalFormat
!= GL_RGBA8_SNORM
)
1712 return GL_INVALID_OPERATION
;
1715 case GL_UNSIGNED_SHORT_4_4_4_4
:
1716 switch (internalFormat
) {
1721 return GL_INVALID_OPERATION
;
1725 case GL_UNSIGNED_SHORT_5_5_5_1
:
1726 switch (internalFormat
) {
1731 return GL_INVALID_OPERATION
;
1735 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1736 switch (internalFormat
) {
1737 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1742 return GL_INVALID_OPERATION
;
1747 if (internalFormat
!= GL_RGBA16F
)
1748 return GL_INVALID_OPERATION
;
1752 switch (internalFormat
) {
1757 return GL_INVALID_OPERATION
;
1762 return GL_INVALID_OPERATION
;
1766 case GL_RGBA_INTEGER
:
1768 case GL_UNSIGNED_BYTE
:
1769 if (internalFormat
!= GL_RGBA8UI
)
1770 return GL_INVALID_OPERATION
;
1774 if (internalFormat
!= GL_RGBA8I
)
1775 return GL_INVALID_OPERATION
;
1778 case GL_UNSIGNED_SHORT
:
1779 if (internalFormat
!= GL_RGBA16UI
)
1780 return GL_INVALID_OPERATION
;
1784 if (internalFormat
!= GL_RGBA16I
)
1785 return GL_INVALID_OPERATION
;
1788 case GL_UNSIGNED_INT
:
1789 if (internalFormat
!= GL_RGBA32UI
)
1790 return GL_INVALID_OPERATION
;
1794 if (internalFormat
!= GL_RGBA32I
)
1795 return GL_INVALID_OPERATION
;
1798 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1799 if (internalFormat
!= GL_RGB10_A2UI
)
1800 return GL_INVALID_OPERATION
;
1804 return GL_INVALID_OPERATION
;
1810 case GL_UNSIGNED_BYTE
:
1811 switch (internalFormat
) {
1818 return GL_INVALID_OPERATION
;
1823 if (internalFormat
!= GL_RGB8_SNORM
)
1824 return GL_INVALID_OPERATION
;
1827 case GL_UNSIGNED_SHORT_5_6_5
:
1828 switch (internalFormat
) {
1833 return GL_INVALID_OPERATION
;
1837 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1838 if (internalFormat
!= GL_R11F_G11F_B10F
)
1839 return GL_INVALID_OPERATION
;
1842 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1843 if (internalFormat
!= GL_RGB9_E5
)
1844 return GL_INVALID_OPERATION
;
1848 switch (internalFormat
) {
1850 case GL_R11F_G11F_B10F
:
1854 return GL_INVALID_OPERATION
;
1859 switch (internalFormat
) {
1862 case GL_R11F_G11F_B10F
:
1866 return GL_INVALID_OPERATION
;
1870 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1871 switch (internalFormat
) {
1872 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1875 return GL_INVALID_OPERATION
;
1880 return GL_INVALID_OPERATION
;
1884 case GL_RGB_INTEGER
:
1886 case GL_UNSIGNED_BYTE
:
1887 if (internalFormat
!= GL_RGB8UI
)
1888 return GL_INVALID_OPERATION
;
1892 if (internalFormat
!= GL_RGB8I
)
1893 return GL_INVALID_OPERATION
;
1896 case GL_UNSIGNED_SHORT
:
1897 if (internalFormat
!= GL_RGB16UI
)
1898 return GL_INVALID_OPERATION
;
1902 if (internalFormat
!= GL_RGB16I
)
1903 return GL_INVALID_OPERATION
;
1906 case GL_UNSIGNED_INT
:
1907 if (internalFormat
!= GL_RGB32UI
)
1908 return GL_INVALID_OPERATION
;
1912 if (internalFormat
!= GL_RGB32I
)
1913 return GL_INVALID_OPERATION
;
1917 return GL_INVALID_OPERATION
;
1923 case GL_UNSIGNED_BYTE
:
1924 if (internalFormat
!= GL_RG8
)
1925 return GL_INVALID_OPERATION
;
1929 if (internalFormat
!= GL_RG8_SNORM
)
1930 return GL_INVALID_OPERATION
;
1934 if (internalFormat
!= GL_RG16F
)
1935 return GL_INVALID_OPERATION
;
1939 switch (internalFormat
) {
1944 return GL_INVALID_OPERATION
;
1949 return GL_INVALID_OPERATION
;
1955 case GL_UNSIGNED_BYTE
:
1956 if (internalFormat
!= GL_RG8UI
)
1957 return GL_INVALID_OPERATION
;
1961 if (internalFormat
!= GL_RG8I
)
1962 return GL_INVALID_OPERATION
;
1965 case GL_UNSIGNED_SHORT
:
1966 if (internalFormat
!= GL_RG16UI
)
1967 return GL_INVALID_OPERATION
;
1971 if (internalFormat
!= GL_RG16I
)
1972 return GL_INVALID_OPERATION
;
1975 case GL_UNSIGNED_INT
:
1976 if (internalFormat
!= GL_RG32UI
)
1977 return GL_INVALID_OPERATION
;
1981 if (internalFormat
!= GL_RG32I
)
1982 return GL_INVALID_OPERATION
;
1986 return GL_INVALID_OPERATION
;
1992 case GL_UNSIGNED_BYTE
:
1993 if (internalFormat
!= GL_R8
)
1994 return GL_INVALID_OPERATION
;
1998 if (internalFormat
!= GL_R8_SNORM
)
1999 return GL_INVALID_OPERATION
;
2003 if (internalFormat
!= GL_R16F
)
2004 return GL_INVALID_OPERATION
;
2008 switch (internalFormat
) {
2013 return GL_INVALID_OPERATION
;
2018 return GL_INVALID_OPERATION
;
2022 case GL_RED_INTEGER
:
2024 case GL_UNSIGNED_BYTE
:
2025 if (internalFormat
!= GL_R8UI
)
2026 return GL_INVALID_OPERATION
;
2030 if (internalFormat
!= GL_R8I
)
2031 return GL_INVALID_OPERATION
;
2034 case GL_UNSIGNED_SHORT
:
2035 if (internalFormat
!= GL_R16UI
)
2036 return GL_INVALID_OPERATION
;
2040 if (internalFormat
!= GL_R16I
)
2041 return GL_INVALID_OPERATION
;
2044 case GL_UNSIGNED_INT
:
2045 if (internalFormat
!= GL_R32UI
)
2046 return GL_INVALID_OPERATION
;
2050 if (internalFormat
!= GL_R32I
)
2051 return GL_INVALID_OPERATION
;
2055 return GL_INVALID_OPERATION
;
2059 case GL_DEPTH_COMPONENT
:
2061 case GL_UNSIGNED_SHORT
:
2062 if (internalFormat
!= GL_DEPTH_COMPONENT
2063 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2064 return GL_INVALID_OPERATION
;
2067 case GL_UNSIGNED_INT
:
2068 switch (internalFormat
) {
2069 case GL_DEPTH_COMPONENT
:
2070 case GL_DEPTH_COMPONENT16
:
2071 case GL_DEPTH_COMPONENT24
:
2074 return GL_INVALID_OPERATION
;
2079 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2080 return GL_INVALID_OPERATION
;
2084 return GL_INVALID_OPERATION
;
2088 case GL_DEPTH_STENCIL
:
2090 case GL_UNSIGNED_INT_24_8
:
2091 if (internalFormat
!= GL_DEPTH_STENCIL
2092 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2093 return GL_INVALID_OPERATION
;
2096 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2097 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2098 return GL_INVALID_OPERATION
;
2102 return GL_INVALID_OPERATION
;
2108 case GL_LUMINANCE_ALPHA
:
2109 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2110 return GL_INVALID_OPERATION
;
2114 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;