2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "glformats.h"
33 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
36 _mesa_type_is_packed(GLenum type
)
39 case GL_UNSIGNED_BYTE_3_3_2
:
40 case GL_UNSIGNED_BYTE_2_3_3_REV
:
41 case MESA_UNSIGNED_BYTE_4_4
:
42 case GL_UNSIGNED_SHORT_5_6_5
:
43 case GL_UNSIGNED_SHORT_5_6_5_REV
:
44 case GL_UNSIGNED_SHORT_4_4_4_4
:
45 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
46 case GL_UNSIGNED_SHORT_5_5_5_1
:
47 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
48 case GL_UNSIGNED_INT_8_8_8_8
:
49 case GL_UNSIGNED_INT_8_8_8_8_REV
:
50 case GL_UNSIGNED_INT_10_10_10_2
:
51 case GL_UNSIGNED_INT_2_10_10_10_REV
:
52 case GL_UNSIGNED_SHORT_8_8_MESA
:
53 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
54 case GL_UNSIGNED_INT_24_8_EXT
:
55 case GL_UNSIGNED_INT_5_9_9_9_REV
:
56 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
57 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
66 * Get the size of a GL data type.
68 * \param type GL data type.
70 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
71 * if an invalid type enum.
74 _mesa_sizeof_type(GLenum type
)
79 case GL_UNSIGNED_BYTE
:
80 return sizeof(GLubyte
);
82 return sizeof(GLbyte
);
83 case GL_UNSIGNED_SHORT
:
84 return sizeof(GLushort
);
86 return sizeof(GLshort
);
88 return sizeof(GLuint
);
92 return sizeof(GLfloat
);
94 return sizeof(GLdouble
);
95 case GL_HALF_FLOAT_ARB
:
96 return sizeof(GLhalfARB
);
98 return sizeof(GLfixed
);
106 * Same as _mesa_sizeof_type() but also accepting the packed pixel
110 _mesa_sizeof_packed_type(GLenum type
)
115 case GL_UNSIGNED_BYTE
:
116 return sizeof(GLubyte
);
118 return sizeof(GLbyte
);
119 case GL_UNSIGNED_SHORT
:
120 return sizeof(GLushort
);
122 return sizeof(GLshort
);
123 case GL_UNSIGNED_INT
:
124 return sizeof(GLuint
);
126 return sizeof(GLint
);
127 case GL_HALF_FLOAT_ARB
:
128 return sizeof(GLhalfARB
);
130 return sizeof(GLfloat
);
131 case GL_UNSIGNED_BYTE_3_3_2
:
132 case GL_UNSIGNED_BYTE_2_3_3_REV
:
133 case MESA_UNSIGNED_BYTE_4_4
:
134 return sizeof(GLubyte
);
135 case GL_UNSIGNED_SHORT_5_6_5
:
136 case GL_UNSIGNED_SHORT_5_6_5_REV
:
137 case GL_UNSIGNED_SHORT_4_4_4_4
:
138 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
139 case GL_UNSIGNED_SHORT_5_5_5_1
:
140 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
141 case GL_UNSIGNED_SHORT_8_8_MESA
:
142 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
143 return sizeof(GLushort
);
144 case GL_UNSIGNED_INT_8_8_8_8
:
145 case GL_UNSIGNED_INT_8_8_8_8_REV
:
146 case GL_UNSIGNED_INT_10_10_10_2
:
147 case GL_UNSIGNED_INT_2_10_10_10_REV
:
148 case GL_UNSIGNED_INT_24_8_EXT
:
149 case GL_UNSIGNED_INT_5_9_9_9_REV
:
150 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
151 return sizeof(GLuint
);
152 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
161 * Get the number of components in a pixel format.
163 * \param format pixel format.
165 * \return the number of components in the given format, or -1 if a bad format.
168 _mesa_components_in_format(GLenum format
)
172 case GL_STENCIL_INDEX
:
173 case GL_DEPTH_COMPONENT
:
175 case GL_RED_INTEGER_EXT
:
177 case GL_GREEN_INTEGER_EXT
:
179 case GL_BLUE_INTEGER_EXT
:
181 case GL_ALPHA_INTEGER_EXT
:
183 case GL_LUMINANCE_INTEGER_EXT
:
187 case GL_LUMINANCE_ALPHA
:
188 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
191 case GL_DEPTH_STENCIL_EXT
:
197 case GL_RGB_INTEGER_EXT
:
198 case GL_BGR_INTEGER_EXT
:
204 case GL_RGBA_INTEGER_EXT
:
205 case GL_BGRA_INTEGER_EXT
:
215 * Get the bytes per pixel of pixel format type pair.
217 * \param format pixel format.
218 * \param type pixel type.
220 * \return bytes per pixel, or -1 if a bad format or type was given.
223 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
225 GLint comps
= _mesa_components_in_format(format
);
231 return 0; /* special case */
233 case GL_UNSIGNED_BYTE
:
234 return comps
* sizeof(GLubyte
);
236 case GL_UNSIGNED_SHORT
:
237 return comps
* sizeof(GLshort
);
239 case GL_UNSIGNED_INT
:
240 return comps
* sizeof(GLint
);
242 return comps
* sizeof(GLfloat
);
243 case GL_HALF_FLOAT_ARB
:
244 return comps
* sizeof(GLhalfARB
);
245 case GL_UNSIGNED_BYTE_3_3_2
:
246 case GL_UNSIGNED_BYTE_2_3_3_REV
:
247 if (format
== GL_RGB
|| format
== GL_BGR
||
248 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
249 return sizeof(GLubyte
);
251 return -1; /* error */
252 case GL_UNSIGNED_SHORT_5_6_5
:
253 case GL_UNSIGNED_SHORT_5_6_5_REV
:
254 if (format
== GL_RGB
|| format
== GL_BGR
||
255 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
256 return sizeof(GLushort
);
258 return -1; /* error */
259 case GL_UNSIGNED_SHORT_4_4_4_4
:
260 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
261 case GL_UNSIGNED_SHORT_5_5_5_1
:
262 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
263 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
264 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
265 return sizeof(GLushort
);
268 case GL_UNSIGNED_INT_8_8_8_8
:
269 case GL_UNSIGNED_INT_8_8_8_8_REV
:
270 case GL_UNSIGNED_INT_10_10_10_2
:
271 case GL_UNSIGNED_INT_2_10_10_10_REV
:
272 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
273 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
275 return sizeof(GLuint
);
278 case GL_UNSIGNED_SHORT_8_8_MESA
:
279 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
280 if (format
== GL_YCBCR_MESA
)
281 return sizeof(GLushort
);
284 case GL_UNSIGNED_INT_24_8_EXT
:
285 if (format
== GL_DEPTH_STENCIL_EXT
)
286 return sizeof(GLuint
);
289 case GL_UNSIGNED_INT_5_9_9_9_REV
:
290 if (format
== GL_RGB
)
291 return sizeof(GLuint
);
294 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
295 if (format
== GL_RGB
)
296 return sizeof(GLuint
);
299 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
300 if (format
== GL_DEPTH_STENCIL
)
311 * Get the number of bytes for a vertex attrib with the given number of
312 * components and type.
314 * \param comps number of components.
315 * \param type data type.
317 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
320 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
324 case GL_UNSIGNED_BYTE
:
325 return comps
* sizeof(GLubyte
);
327 case GL_UNSIGNED_SHORT
:
328 return comps
* sizeof(GLshort
);
330 case GL_UNSIGNED_INT
:
331 return comps
* sizeof(GLint
);
333 return comps
* sizeof(GLfloat
);
334 case GL_HALF_FLOAT_ARB
:
335 return comps
* sizeof(GLhalfARB
);
337 return comps
* sizeof(GLdouble
);
339 return comps
* sizeof(GLfixed
);
340 case GL_INT_2_10_10_10_REV
:
341 case GL_UNSIGNED_INT_2_10_10_10_REV
:
343 return sizeof(GLuint
);
346 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
348 return sizeof(GLuint
);
358 * Test if the given format is an integer (non-normalized) format.
361 _mesa_is_enum_format_unsigned_int(GLenum format
)
364 /* specific integer formats */
365 case GL_RGBA32UI_EXT
:
369 case GL_ALPHA32UI_EXT
:
370 case GL_INTENSITY32UI_EXT
:
371 case GL_LUMINANCE32UI_EXT
:
372 case GL_LUMINANCE_ALPHA32UI_EXT
:
373 case GL_RGBA16UI_EXT
:
377 case GL_ALPHA16UI_EXT
:
378 case GL_INTENSITY16UI_EXT
:
379 case GL_LUMINANCE16UI_EXT
:
380 case GL_LUMINANCE_ALPHA16UI_EXT
:
385 case GL_ALPHA8UI_EXT
:
386 case GL_INTENSITY8UI_EXT
:
387 case GL_LUMINANCE8UI_EXT
:
388 case GL_LUMINANCE_ALPHA8UI_EXT
:
398 * Test if the given format is an integer (non-normalized) format.
401 _mesa_is_enum_format_signed_int(GLenum format
)
404 /* generic integer formats */
405 case GL_RED_INTEGER_EXT
:
406 case GL_GREEN_INTEGER_EXT
:
407 case GL_BLUE_INTEGER_EXT
:
408 case GL_ALPHA_INTEGER_EXT
:
409 case GL_RGB_INTEGER_EXT
:
410 case GL_RGBA_INTEGER_EXT
:
411 case GL_BGR_INTEGER_EXT
:
412 case GL_BGRA_INTEGER_EXT
:
413 case GL_LUMINANCE_INTEGER_EXT
:
414 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
416 /* specific integer formats */
421 case GL_ALPHA32I_EXT
:
422 case GL_INTENSITY32I_EXT
:
423 case GL_LUMINANCE32I_EXT
:
424 case GL_LUMINANCE_ALPHA32I_EXT
:
429 case GL_ALPHA16I_EXT
:
430 case GL_INTENSITY16I_EXT
:
431 case GL_LUMINANCE16I_EXT
:
432 case GL_LUMINANCE_ALPHA16I_EXT
:
438 case GL_INTENSITY8I_EXT
:
439 case GL_LUMINANCE8I_EXT
:
440 case GL_LUMINANCE_ALPHA8I_EXT
:
449 * Test if the given format is an integer (non-normalized) format.
452 _mesa_is_enum_format_integer(GLenum format
)
454 return _mesa_is_enum_format_unsigned_int(format
) ||
455 _mesa_is_enum_format_signed_int(format
);
460 _mesa_is_type_unsigned(GLenum type
)
463 case GL_UNSIGNED_INT
:
464 case GL_UNSIGNED_INT_8_8_8_8
:
465 case GL_UNSIGNED_INT_8_8_8_8_REV
:
466 case GL_UNSIGNED_INT_10_10_10_2
:
467 case GL_UNSIGNED_INT_2_10_10_10_REV
:
469 case GL_UNSIGNED_SHORT
:
470 case GL_UNSIGNED_SHORT_4_4_4_4
:
471 case GL_UNSIGNED_SHORT_5_5_5_1
:
472 case GL_UNSIGNED_SHORT_5_6_5
:
473 case GL_UNSIGNED_SHORT_5_6_5_REV
:
474 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
475 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
476 case GL_UNSIGNED_SHORT_8_8_MESA
:
477 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
479 case GL_UNSIGNED_BYTE
:
480 case GL_UNSIGNED_BYTE_3_3_2
:
481 case GL_UNSIGNED_BYTE_2_3_3_REV
:
491 * Test if the given image format is a color/RGBA format (i.e., not color
492 * index, depth, stencil, etc).
493 * \param format the image format value (may by an internal texture format)
494 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
497 _mesa_is_color_format(GLenum format
)
515 case GL_LUMINANCE_ALPHA
:
516 case GL_LUMINANCE4_ALPHA4
:
517 case GL_LUMINANCE6_ALPHA2
:
518 case GL_LUMINANCE8_ALPHA8
:
519 case GL_LUMINANCE12_ALPHA4
:
520 case GL_LUMINANCE12_ALPHA12
:
521 case GL_LUMINANCE16_ALPHA16
:
554 /* float texture formats */
555 case GL_ALPHA16F_ARB
:
556 case GL_ALPHA32F_ARB
:
557 case GL_LUMINANCE16F_ARB
:
558 case GL_LUMINANCE32F_ARB
:
559 case GL_LUMINANCE_ALPHA16F_ARB
:
560 case GL_LUMINANCE_ALPHA32F_ARB
:
561 case GL_INTENSITY16F_ARB
:
562 case GL_INTENSITY32F_ARB
:
571 /* compressed formats */
572 case GL_COMPRESSED_ALPHA
:
573 case GL_COMPRESSED_LUMINANCE
:
574 case GL_COMPRESSED_LUMINANCE_ALPHA
:
575 case GL_COMPRESSED_INTENSITY
:
576 case GL_COMPRESSED_RED
:
577 case GL_COMPRESSED_RG
:
578 case GL_COMPRESSED_RGB
:
579 case GL_COMPRESSED_RGBA
:
584 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
585 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
586 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
587 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
588 case GL_COMPRESSED_RGB_FXT1_3DFX
:
589 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
592 case GL_SRGB_ALPHA_EXT
:
593 case GL_SRGB8_ALPHA8_EXT
:
594 case GL_SLUMINANCE_ALPHA_EXT
:
595 case GL_SLUMINANCE8_ALPHA8_EXT
:
596 case GL_SLUMINANCE_EXT
:
597 case GL_SLUMINANCE8_EXT
:
598 case GL_COMPRESSED_SRGB_EXT
:
599 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
600 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
601 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
602 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
603 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
604 case GL_COMPRESSED_SLUMINANCE_EXT
:
605 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
606 case GL_COMPRESSED_RED_RGTC1
:
607 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
608 case GL_COMPRESSED_RG_RGTC2
:
609 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
610 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
611 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
612 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
613 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
614 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
615 case GL_ETC1_RGB8_OES
:
616 case GL_COMPRESSED_RGB8_ETC2
:
617 case GL_COMPRESSED_SRGB8_ETC2
:
618 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
619 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
620 case GL_COMPRESSED_R11_EAC
:
621 case GL_COMPRESSED_RG11_EAC
:
622 case GL_COMPRESSED_SIGNED_R11_EAC
:
623 case GL_COMPRESSED_SIGNED_RG11_EAC
:
624 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
625 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
626 /* generic integer formats */
627 case GL_RED_INTEGER_EXT
:
628 case GL_GREEN_INTEGER_EXT
:
629 case GL_BLUE_INTEGER_EXT
:
630 case GL_ALPHA_INTEGER_EXT
:
631 case GL_RGB_INTEGER_EXT
:
632 case GL_RGBA_INTEGER_EXT
:
633 case GL_BGR_INTEGER_EXT
:
634 case GL_BGRA_INTEGER_EXT
:
636 case GL_LUMINANCE_INTEGER_EXT
:
637 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
638 /* sized integer formats */
639 case GL_RGBA32UI_EXT
:
643 case GL_ALPHA32UI_EXT
:
644 case GL_INTENSITY32UI_EXT
:
645 case GL_LUMINANCE32UI_EXT
:
646 case GL_LUMINANCE_ALPHA32UI_EXT
:
647 case GL_RGBA16UI_EXT
:
651 case GL_ALPHA16UI_EXT
:
652 case GL_INTENSITY16UI_EXT
:
653 case GL_LUMINANCE16UI_EXT
:
654 case GL_LUMINANCE_ALPHA16UI_EXT
:
659 case GL_ALPHA8UI_EXT
:
660 case GL_INTENSITY8UI_EXT
:
661 case GL_LUMINANCE8UI_EXT
:
662 case GL_LUMINANCE_ALPHA8UI_EXT
:
667 case GL_ALPHA32I_EXT
:
668 case GL_INTENSITY32I_EXT
:
669 case GL_LUMINANCE32I_EXT
:
670 case GL_LUMINANCE_ALPHA32I_EXT
:
675 case GL_ALPHA16I_EXT
:
676 case GL_INTENSITY16I_EXT
:
677 case GL_LUMINANCE16I_EXT
:
678 case GL_LUMINANCE_ALPHA16I_EXT
:
684 case GL_INTENSITY8I_EXT
:
685 case GL_LUMINANCE8I_EXT
:
686 case GL_LUMINANCE_ALPHA8I_EXT
:
687 /* signed, normalized texture formats */
699 case GL_RGBA16_SNORM
:
701 case GL_ALPHA8_SNORM
:
702 case GL_ALPHA16_SNORM
:
703 case GL_LUMINANCE_SNORM
:
704 case GL_LUMINANCE8_SNORM
:
705 case GL_LUMINANCE16_SNORM
:
706 case GL_LUMINANCE_ALPHA_SNORM
:
707 case GL_LUMINANCE8_ALPHA8_SNORM
:
708 case GL_LUMINANCE16_ALPHA16_SNORM
:
709 case GL_INTENSITY_SNORM
:
710 case GL_INTENSITY8_SNORM
:
711 case GL_INTENSITY16_SNORM
:
713 case GL_R11F_G11F_B10F
:
716 case GL_YCBCR_MESA
: /* not considered to be RGB */
725 * Test if the given image format is a depth component format.
728 _mesa_is_depth_format(GLenum format
)
731 case GL_DEPTH_COMPONENT
:
732 case GL_DEPTH_COMPONENT16
:
733 case GL_DEPTH_COMPONENT24
:
734 case GL_DEPTH_COMPONENT32
:
735 case GL_DEPTH_COMPONENT32F
:
744 * Test if the given image format is a stencil format.
747 _mesa_is_stencil_format(GLenum format
)
750 case GL_STENCIL_INDEX
:
759 * Test if the given image format is a YCbCr format.
762 _mesa_is_ycbcr_format(GLenum format
)
774 * Test if the given image format is a depth+stencil format.
777 _mesa_is_depthstencil_format(GLenum format
)
780 case GL_DEPTH24_STENCIL8_EXT
:
781 case GL_DEPTH_STENCIL_EXT
:
782 case GL_DEPTH32F_STENCIL8
:
791 * Test if the given image format is a depth or stencil format.
794 _mesa_is_depth_or_stencil_format(GLenum format
)
797 case GL_DEPTH_COMPONENT
:
798 case GL_DEPTH_COMPONENT16
:
799 case GL_DEPTH_COMPONENT24
:
800 case GL_DEPTH_COMPONENT32
:
801 case GL_STENCIL_INDEX
:
802 case GL_STENCIL_INDEX1_EXT
:
803 case GL_STENCIL_INDEX4_EXT
:
804 case GL_STENCIL_INDEX8_EXT
:
805 case GL_STENCIL_INDEX16_EXT
:
806 case GL_DEPTH_STENCIL_EXT
:
807 case GL_DEPTH24_STENCIL8_EXT
:
808 case GL_DEPTH_COMPONENT32F
:
809 case GL_DEPTH32F_STENCIL8
:
818 * Test if an image format is a supported compressed format.
819 * \param format the internal format token provided by the user.
820 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
823 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
826 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
827 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
828 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
829 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
830 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
832 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
837 return _mesa_is_desktop_gl(ctx
) &&
838 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
839 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
840 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
841 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
842 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
843 return _mesa_is_desktop_gl(ctx
)
844 && ctx
->Extensions
.EXT_texture_sRGB
845 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
846 case GL_COMPRESSED_RGB_FXT1_3DFX
:
847 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
848 return _mesa_is_desktop_gl(ctx
)
849 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
850 case GL_COMPRESSED_RED_RGTC1
:
851 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
852 case GL_COMPRESSED_RG_RGTC2
:
853 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
854 return _mesa_is_desktop_gl(ctx
)
855 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
856 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
857 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
858 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
859 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
860 return ctx
->API
== API_OPENGL_COMPAT
861 && ctx
->Extensions
.EXT_texture_compression_latc
;
862 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
863 return ctx
->API
== API_OPENGL_COMPAT
864 && ctx
->Extensions
.ATI_texture_compression_3dc
;
865 case GL_ETC1_RGB8_OES
:
866 return _mesa_is_gles(ctx
)
867 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
868 case GL_COMPRESSED_RGB8_ETC2
:
869 case GL_COMPRESSED_SRGB8_ETC2
:
870 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
871 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
872 case GL_COMPRESSED_R11_EAC
:
873 case GL_COMPRESSED_RG11_EAC
:
874 case GL_COMPRESSED_SIGNED_R11_EAC
:
875 case GL_COMPRESSED_SIGNED_RG11_EAC
:
876 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
877 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
878 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
879 case GL_PALETTE4_RGB8_OES
:
880 case GL_PALETTE4_RGBA8_OES
:
881 case GL_PALETTE4_R5_G6_B5_OES
:
882 case GL_PALETTE4_RGBA4_OES
:
883 case GL_PALETTE4_RGB5_A1_OES
:
884 case GL_PALETTE8_RGB8_OES
:
885 case GL_PALETTE8_RGBA8_OES
:
886 case GL_PALETTE8_R5_G6_B5_OES
:
887 case GL_PALETTE8_RGBA4_OES
:
888 case GL_PALETTE8_RGB5_A1_OES
:
889 return ctx
->API
== API_OPENGLES
;
897 * Convert various base formats to the cooresponding integer format.
900 _mesa_base_format_to_integer_format(GLenum format
)
904 return GL_RED_INTEGER
;
906 return GL_GREEN_INTEGER
;
908 return GL_BLUE_INTEGER
;
910 return GL_RG_INTEGER
;
912 return GL_RGB_INTEGER
;
914 return GL_RGBA_INTEGER
;
916 return GL_BGR_INTEGER
;
918 return GL_BGRA_INTEGER
;
920 return GL_ALPHA_INTEGER
;
922 return GL_LUMINANCE_INTEGER_EXT
;
923 case GL_LUMINANCE_ALPHA
:
924 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
932 * Does the given base texture/renderbuffer format have the channel
936 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
939 case GL_TEXTURE_RED_SIZE
:
940 case GL_TEXTURE_RED_TYPE
:
941 case GL_RENDERBUFFER_RED_SIZE_EXT
:
942 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
943 if (base_format
== GL_RED
||
944 base_format
== GL_RG
||
945 base_format
== GL_RGB
||
946 base_format
== GL_RGBA
) {
950 case GL_TEXTURE_GREEN_SIZE
:
951 case GL_TEXTURE_GREEN_TYPE
:
952 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
953 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
954 if (base_format
== GL_RG
||
955 base_format
== GL_RGB
||
956 base_format
== GL_RGBA
) {
960 case GL_TEXTURE_BLUE_SIZE
:
961 case GL_TEXTURE_BLUE_TYPE
:
962 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
963 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
964 if (base_format
== GL_RGB
||
965 base_format
== GL_RGBA
) {
969 case GL_TEXTURE_ALPHA_SIZE
:
970 case GL_TEXTURE_ALPHA_TYPE
:
971 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
972 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
973 if (base_format
== GL_RGBA
||
974 base_format
== GL_ALPHA
||
975 base_format
== GL_LUMINANCE_ALPHA
) {
979 case GL_TEXTURE_LUMINANCE_SIZE
:
980 case GL_TEXTURE_LUMINANCE_TYPE
:
981 if (base_format
== GL_LUMINANCE
||
982 base_format
== GL_LUMINANCE_ALPHA
) {
986 case GL_TEXTURE_INTENSITY_SIZE
:
987 case GL_TEXTURE_INTENSITY_TYPE
:
988 if (base_format
== GL_INTENSITY
) {
992 case GL_TEXTURE_DEPTH_SIZE
:
993 case GL_TEXTURE_DEPTH_TYPE
:
994 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
995 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
996 if (base_format
== GL_DEPTH_STENCIL
||
997 base_format
== GL_DEPTH_COMPONENT
) {
1001 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1002 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1003 if (base_format
== GL_DEPTH_STENCIL
||
1004 base_format
== GL_STENCIL_INDEX
) {
1009 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1010 __FUNCTION__
, pname
);
1019 * Returns the number of channels/components for a base format.
1022 _mesa_base_format_component_count(GLenum base_format
)
1024 switch (base_format
) {
1028 case GL_DEPTH_COMPONENT
:
1031 case GL_LUMINANCE_ALPHA
:
1032 case GL_DEPTH_STENCIL
:
1045 * If format is a generic compressed format, return the corresponding
1046 * non-compressed format. For other formats, return the format as-is.
1049 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1052 case GL_COMPRESSED_RED
:
1054 case GL_COMPRESSED_RG
:
1056 case GL_COMPRESSED_RGB
:
1058 case GL_COMPRESSED_RGBA
:
1060 case GL_COMPRESSED_ALPHA
:
1062 case GL_COMPRESSED_LUMINANCE
:
1063 return GL_LUMINANCE
;
1064 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1065 return GL_LUMINANCE_ALPHA
;
1066 case GL_COMPRESSED_INTENSITY
:
1067 return GL_INTENSITY
;
1069 case GL_COMPRESSED_SRGB
:
1071 case GL_COMPRESSED_SRGB_ALPHA
:
1072 return GL_SRGB_ALPHA
;
1073 case GL_COMPRESSED_SLUMINANCE
:
1074 return GL_SLUMINANCE
;
1075 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1076 return GL_SLUMINANCE_ALPHA
;
1084 * Return the equivalent non-generic internal format.
1085 * This is useful for comparing whether two internal formats are equivalent.
1088 _mesa_get_nongeneric_internalformat(GLenum format
)
1091 /* GL 1.1 formats. */
1099 case GL_LUMINANCE_ALPHA
:
1100 return GL_LUMINANCE8_ALPHA8
;
1103 return GL_LUMINANCE8
;
1107 return GL_INTENSITY8
;
1109 /* GL_ARB_texture_rg */
1115 /* GL_EXT_texture_sRGB */
1119 return GL_SRGB8_ALPHA8
;
1121 return GL_SLUMINANCE8
;
1122 case GL_SLUMINANCE_ALPHA
:
1123 return GL_SLUMINANCE8_ALPHA8
;
1125 /* GL_EXT_texture_snorm */
1127 return GL_RGBA8_SNORM
;
1129 return GL_RGB8_SNORM
;
1131 return GL_RG8_SNORM
;
1134 case GL_LUMINANCE_ALPHA_SNORM
:
1135 return GL_LUMINANCE8_ALPHA8_SNORM
;
1136 case GL_LUMINANCE_SNORM
:
1137 return GL_LUMINANCE8_SNORM
;
1138 case GL_ALPHA_SNORM
:
1139 return GL_ALPHA8_SNORM
;
1140 case GL_INTENSITY_SNORM
:
1141 return GL_INTENSITY8_SNORM
;
1150 * Convert an sRGB internal format to linear.
1153 _mesa_get_linear_internalformat(GLenum format
)
1162 case GL_SRGB8_ALPHA8
:
1164 case GL_SLUMINANCE8
:
1165 return GL_LUMINANCE8
;
1167 return GL_LUMINANCE
;
1168 case GL_SLUMINANCE_ALPHA
:
1169 return GL_LUMINANCE_ALPHA
;
1170 case GL_SLUMINANCE8_ALPHA8
:
1171 return GL_LUMINANCE8_ALPHA8
;
1179 * Do error checking of format/type combinations for glReadPixels,
1180 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1181 * and type values, we may either generate GL_INVALID_OPERATION or
1184 * \param format pixel format.
1185 * \param type pixel type.
1187 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1190 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1191 GLenum format
, GLenum type
)
1193 /* From OpenGL 3.3 spec, page 220:
1194 * "If the format is DEPTH_STENCIL, then values are taken from
1195 * both the depth buffer and the stencil buffer. If there is no
1196 * depth buffer or if there is no stencil buffer, then the error
1197 * INVALID_OPERATION occurs. If the type parameter is not
1198 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1199 * error INVALID_ENUM occurs."
1201 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1202 * cannot be used to read depth or stencil in that API.
1204 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1205 && type
!= GL_UNSIGNED_INT_24_8
1206 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1207 return GL_INVALID_ENUM
;
1209 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1212 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1213 return GL_INVALID_ENUM
;
1217 case GL_UNSIGNED_BYTE_3_3_2
:
1218 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1219 case GL_UNSIGNED_SHORT_5_6_5
:
1220 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1221 if (format
== GL_RGB
) {
1224 if (format
== GL_RGB_INTEGER_EXT
&&
1225 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1228 return GL_INVALID_OPERATION
;
1230 case GL_UNSIGNED_SHORT_4_4_4_4
:
1231 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1232 case GL_UNSIGNED_SHORT_5_5_5_1
:
1233 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1234 case GL_UNSIGNED_INT_8_8_8_8
:
1235 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1236 case GL_UNSIGNED_INT_10_10_10_2
:
1237 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1238 if (format
== GL_RGBA
||
1239 format
== GL_BGRA
||
1240 format
== GL_ABGR_EXT
) {
1243 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1244 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1247 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1248 ctx
->API
== API_OPENGLES2
) {
1249 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1251 return GL_INVALID_OPERATION
;
1253 case GL_UNSIGNED_INT_24_8
:
1254 if (format
!= GL_DEPTH_STENCIL
) {
1255 return GL_INVALID_OPERATION
;
1259 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1260 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1261 return GL_INVALID_ENUM
;
1263 if (format
!= GL_DEPTH_STENCIL
) {
1264 return GL_INVALID_OPERATION
;
1268 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1269 if (!ctx
->Extensions
.EXT_packed_float
) {
1270 return GL_INVALID_ENUM
;
1272 if (format
!= GL_RGB
) {
1273 return GL_INVALID_OPERATION
;
1278 ; /* fall-through */
1281 /* now, for each format, check the type for compatibility */
1283 case GL_COLOR_INDEX
:
1284 case GL_STENCIL_INDEX
:
1288 case GL_UNSIGNED_BYTE
:
1290 case GL_UNSIGNED_SHORT
:
1292 case GL_UNSIGNED_INT
:
1297 return GL_INVALID_ENUM
;
1304 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1308 case GL_LUMINANCE_ALPHA
:
1309 case GL_DEPTH_COMPONENT
:
1312 case GL_UNSIGNED_BYTE
:
1314 case GL_UNSIGNED_SHORT
:
1316 case GL_UNSIGNED_INT
:
1321 return GL_INVALID_ENUM
;
1325 if (!ctx
->Extensions
.ARB_texture_rg
)
1326 return GL_INVALID_ENUM
;
1329 case GL_UNSIGNED_BYTE
:
1331 case GL_UNSIGNED_SHORT
:
1333 case GL_UNSIGNED_INT
:
1338 return GL_INVALID_ENUM
;
1344 case GL_UNSIGNED_BYTE
:
1346 case GL_UNSIGNED_SHORT
:
1348 case GL_UNSIGNED_INT
:
1350 case GL_UNSIGNED_BYTE_3_3_2
:
1351 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1352 case GL_UNSIGNED_SHORT_5_6_5
:
1353 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1356 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1357 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1358 return (ctx
->API
== API_OPENGLES2
)
1359 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1360 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1361 return ctx
->Extensions
.EXT_texture_shared_exponent
1362 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1363 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1364 return ctx
->Extensions
.EXT_packed_float
1365 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1367 return GL_INVALID_ENUM
;
1372 /* NOTE: no packed types are supported with BGR. That's
1373 * intentional, according to the GL spec.
1376 case GL_UNSIGNED_BYTE
:
1378 case GL_UNSIGNED_SHORT
:
1380 case GL_UNSIGNED_INT
:
1385 return GL_INVALID_ENUM
;
1393 case GL_UNSIGNED_BYTE
:
1395 case GL_UNSIGNED_SHORT
:
1397 case GL_UNSIGNED_INT
:
1399 case GL_UNSIGNED_SHORT_4_4_4_4
:
1400 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1401 case GL_UNSIGNED_SHORT_5_5_5_1
:
1402 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1403 case GL_UNSIGNED_INT_8_8_8_8
:
1404 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1405 case GL_UNSIGNED_INT_10_10_10_2
:
1406 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1410 return GL_INVALID_ENUM
;
1414 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1415 return GL_INVALID_ENUM
;
1416 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1417 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1420 return GL_INVALID_OPERATION
;
1422 case GL_DEPTH_STENCIL
:
1423 if (type
== GL_UNSIGNED_INT_24_8
)
1425 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1426 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1429 return GL_INVALID_ENUM
;
1431 /* integer-valued formats */
1432 case GL_RED_INTEGER_EXT
:
1433 case GL_GREEN_INTEGER_EXT
:
1434 case GL_BLUE_INTEGER_EXT
:
1435 case GL_ALPHA_INTEGER_EXT
:
1439 case GL_UNSIGNED_BYTE
:
1441 case GL_UNSIGNED_SHORT
:
1443 case GL_UNSIGNED_INT
:
1444 return (ctx
->Version
>= 30 ||
1445 ctx
->Extensions
.EXT_texture_integer
)
1446 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1448 return GL_INVALID_ENUM
;
1451 case GL_RGB_INTEGER_EXT
:
1454 case GL_UNSIGNED_BYTE
:
1456 case GL_UNSIGNED_SHORT
:
1458 case GL_UNSIGNED_INT
:
1459 return (ctx
->Version
>= 30 ||
1460 ctx
->Extensions
.EXT_texture_integer
)
1461 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1462 case GL_UNSIGNED_BYTE_3_3_2
:
1463 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1464 case GL_UNSIGNED_SHORT_5_6_5
:
1465 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1466 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1467 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1469 return GL_INVALID_ENUM
;
1472 case GL_BGR_INTEGER_EXT
:
1475 case GL_UNSIGNED_BYTE
:
1477 case GL_UNSIGNED_SHORT
:
1479 case GL_UNSIGNED_INT
:
1480 /* NOTE: no packed formats w/ BGR format */
1481 return (ctx
->Version
>= 30 ||
1482 ctx
->Extensions
.EXT_texture_integer
)
1483 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1485 return GL_INVALID_ENUM
;
1488 case GL_RGBA_INTEGER_EXT
:
1489 case GL_BGRA_INTEGER_EXT
:
1492 case GL_UNSIGNED_BYTE
:
1494 case GL_UNSIGNED_SHORT
:
1496 case GL_UNSIGNED_INT
:
1497 return (ctx
->Version
>= 30 ||
1498 ctx
->Extensions
.EXT_texture_integer
)
1499 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1500 case GL_UNSIGNED_SHORT_4_4_4_4
:
1501 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1502 case GL_UNSIGNED_SHORT_5_5_5_1
:
1503 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1504 case GL_UNSIGNED_INT_8_8_8_8
:
1505 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1506 case GL_UNSIGNED_INT_10_10_10_2
:
1507 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1508 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1509 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1511 return GL_INVALID_ENUM
;
1514 case GL_LUMINANCE_INTEGER_EXT
:
1515 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1518 case GL_UNSIGNED_BYTE
:
1520 case GL_UNSIGNED_SHORT
:
1522 case GL_UNSIGNED_INT
:
1523 return ctx
->Extensions
.EXT_texture_integer
1524 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1526 return GL_INVALID_ENUM
;
1530 return GL_INVALID_ENUM
;
1537 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1538 * and glTex[Sub]Image.
1539 * \return error code, or GL_NO_ERROR.
1542 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1543 unsigned dimensions
)
1545 GLboolean type_valid
= GL_TRUE
;
1550 case GL_LUMINANCE_ALPHA
:
1551 type_valid
= (type
== GL_UNSIGNED_BYTE
1553 || type
== GL_HALF_FLOAT_OES
);
1557 type_valid
= (type
== GL_UNSIGNED_BYTE
1558 || type
== GL_UNSIGNED_SHORT_5_6_5
1560 || type
== GL_HALF_FLOAT_OES
);
1564 type_valid
= (type
== GL_UNSIGNED_BYTE
1565 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1566 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1568 || type
== GL_HALF_FLOAT_OES
1569 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1572 case GL_DEPTH_COMPONENT
:
1573 /* This format is filtered against invalid dimensionalities elsewhere.
1575 type_valid
= (type
== GL_UNSIGNED_SHORT
1576 || type
== GL_UNSIGNED_INT
);
1579 case GL_DEPTH_STENCIL
:
1580 /* This format is filtered against invalid dimensionalities elsewhere.
1582 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1586 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1588 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1589 * the format does not appear to be allowed for 3D textures in OpenGL
1592 if (dimensions
!= 2)
1593 return GL_INVALID_VALUE
;
1598 return GL_INVALID_VALUE
;
1601 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1606 * Do error checking of format/type combinations for OpenGL ES 3
1608 * \return error code, or GL_NO_ERROR.
1611 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1612 GLenum internalFormat
)
1617 case GL_UNSIGNED_BYTE
:
1618 switch (internalFormat
) {
1623 case GL_SRGB8_ALPHA8_EXT
:
1626 return GL_INVALID_OPERATION
;
1631 if (internalFormat
!= GL_RGBA8_SNORM
)
1632 return GL_INVALID_OPERATION
;
1635 case GL_UNSIGNED_SHORT_4_4_4_4
:
1636 switch (internalFormat
) {
1641 return GL_INVALID_OPERATION
;
1645 case GL_UNSIGNED_SHORT_5_5_5_1
:
1646 switch (internalFormat
) {
1651 return GL_INVALID_OPERATION
;
1655 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1656 switch (internalFormat
) {
1657 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1662 return GL_INVALID_OPERATION
;
1667 if (internalFormat
!= GL_RGBA16F
)
1668 return GL_INVALID_OPERATION
;
1672 switch (internalFormat
) {
1677 return GL_INVALID_OPERATION
;
1682 return GL_INVALID_OPERATION
;
1686 case GL_RGBA_INTEGER
:
1688 case GL_UNSIGNED_BYTE
:
1689 if (internalFormat
!= GL_RGBA8UI
)
1690 return GL_INVALID_OPERATION
;
1694 if (internalFormat
!= GL_RGBA8I
)
1695 return GL_INVALID_OPERATION
;
1698 case GL_UNSIGNED_SHORT
:
1699 if (internalFormat
!= GL_RGBA16UI
)
1700 return GL_INVALID_OPERATION
;
1704 if (internalFormat
!= GL_RGBA16I
)
1705 return GL_INVALID_OPERATION
;
1708 case GL_UNSIGNED_INT
:
1709 if (internalFormat
!= GL_RGBA32UI
)
1710 return GL_INVALID_OPERATION
;
1714 if (internalFormat
!= GL_RGBA32I
)
1715 return GL_INVALID_OPERATION
;
1718 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1719 if (internalFormat
!= GL_RGB10_A2UI
)
1720 return GL_INVALID_OPERATION
;
1724 return GL_INVALID_OPERATION
;
1730 case GL_UNSIGNED_BYTE
:
1731 switch (internalFormat
) {
1738 return GL_INVALID_OPERATION
;
1743 if (internalFormat
!= GL_RGB8_SNORM
)
1744 return GL_INVALID_OPERATION
;
1747 case GL_UNSIGNED_SHORT_5_6_5
:
1748 switch (internalFormat
) {
1753 return GL_INVALID_OPERATION
;
1757 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1758 if (internalFormat
!= GL_R11F_G11F_B10F
)
1759 return GL_INVALID_OPERATION
;
1762 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1763 if (internalFormat
!= GL_RGB9_E5
)
1764 return GL_INVALID_OPERATION
;
1768 switch (internalFormat
) {
1770 case GL_R11F_G11F_B10F
:
1774 return GL_INVALID_OPERATION
;
1779 switch (internalFormat
) {
1782 case GL_R11F_G11F_B10F
:
1786 return GL_INVALID_OPERATION
;
1790 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1791 switch (internalFormat
) {
1792 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1795 return GL_INVALID_OPERATION
;
1800 return GL_INVALID_OPERATION
;
1804 case GL_RGB_INTEGER
:
1806 case GL_UNSIGNED_BYTE
:
1807 if (internalFormat
!= GL_RGB8UI
)
1808 return GL_INVALID_OPERATION
;
1812 if (internalFormat
!= GL_RGB8I
)
1813 return GL_INVALID_OPERATION
;
1816 case GL_UNSIGNED_SHORT
:
1817 if (internalFormat
!= GL_RGB16UI
)
1818 return GL_INVALID_OPERATION
;
1822 if (internalFormat
!= GL_RGB16I
)
1823 return GL_INVALID_OPERATION
;
1826 case GL_UNSIGNED_INT
:
1827 if (internalFormat
!= GL_RGB32UI
)
1828 return GL_INVALID_OPERATION
;
1832 if (internalFormat
!= GL_RGB32I
)
1833 return GL_INVALID_OPERATION
;
1837 return GL_INVALID_OPERATION
;
1843 case GL_UNSIGNED_BYTE
:
1844 if (internalFormat
!= GL_RG8
)
1845 return GL_INVALID_OPERATION
;
1849 if (internalFormat
!= GL_RG8_SNORM
)
1850 return GL_INVALID_OPERATION
;
1854 if (internalFormat
!= GL_RG16F
)
1855 return GL_INVALID_OPERATION
;
1859 switch (internalFormat
) {
1864 return GL_INVALID_OPERATION
;
1869 return GL_INVALID_OPERATION
;
1875 case GL_UNSIGNED_BYTE
:
1876 if (internalFormat
!= GL_RG8UI
)
1877 return GL_INVALID_OPERATION
;
1881 if (internalFormat
!= GL_RG8I
)
1882 return GL_INVALID_OPERATION
;
1885 case GL_UNSIGNED_SHORT
:
1886 if (internalFormat
!= GL_RG16UI
)
1887 return GL_INVALID_OPERATION
;
1891 if (internalFormat
!= GL_RG16I
)
1892 return GL_INVALID_OPERATION
;
1895 case GL_UNSIGNED_INT
:
1896 if (internalFormat
!= GL_RG32UI
)
1897 return GL_INVALID_OPERATION
;
1901 if (internalFormat
!= GL_RG32I
)
1902 return GL_INVALID_OPERATION
;
1906 return GL_INVALID_OPERATION
;
1912 case GL_UNSIGNED_BYTE
:
1913 if (internalFormat
!= GL_R8
)
1914 return GL_INVALID_OPERATION
;
1918 if (internalFormat
!= GL_R8_SNORM
)
1919 return GL_INVALID_OPERATION
;
1923 if (internalFormat
!= GL_R16F
)
1924 return GL_INVALID_OPERATION
;
1928 switch (internalFormat
) {
1933 return GL_INVALID_OPERATION
;
1938 return GL_INVALID_OPERATION
;
1942 case GL_RED_INTEGER
:
1944 case GL_UNSIGNED_BYTE
:
1945 if (internalFormat
!= GL_R8UI
)
1946 return GL_INVALID_OPERATION
;
1950 if (internalFormat
!= GL_R8I
)
1951 return GL_INVALID_OPERATION
;
1954 case GL_UNSIGNED_SHORT
:
1955 if (internalFormat
!= GL_R16UI
)
1956 return GL_INVALID_OPERATION
;
1960 if (internalFormat
!= GL_R16I
)
1961 return GL_INVALID_OPERATION
;
1964 case GL_UNSIGNED_INT
:
1965 if (internalFormat
!= GL_R32UI
)
1966 return GL_INVALID_OPERATION
;
1970 if (internalFormat
!= GL_R32I
)
1971 return GL_INVALID_OPERATION
;
1975 return GL_INVALID_OPERATION
;
1979 case GL_DEPTH_COMPONENT
:
1981 case GL_UNSIGNED_SHORT
:
1982 if (internalFormat
!= GL_DEPTH_COMPONENT
1983 && internalFormat
!= GL_DEPTH_COMPONENT16
)
1984 return GL_INVALID_OPERATION
;
1987 case GL_UNSIGNED_INT
:
1988 switch (internalFormat
) {
1989 case GL_DEPTH_COMPONENT
:
1990 case GL_DEPTH_COMPONENT16
:
1991 case GL_DEPTH_COMPONENT24
:
1994 return GL_INVALID_OPERATION
;
1999 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2000 return GL_INVALID_OPERATION
;
2004 return GL_INVALID_OPERATION
;
2008 case GL_DEPTH_STENCIL
:
2010 case GL_UNSIGNED_INT_24_8
:
2011 if (internalFormat
!= GL_DEPTH_STENCIL
2012 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2013 return GL_INVALID_OPERATION
;
2016 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2017 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2018 return GL_INVALID_OPERATION
;
2022 return GL_INVALID_OPERATION
;
2028 case GL_LUMINANCE_ALPHA
:
2029 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2030 return GL_INVALID_OPERATION
;