2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "glformats.h"
33 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
36 _mesa_type_is_packed(GLenum type
)
39 case GL_UNSIGNED_BYTE_3_3_2
:
40 case GL_UNSIGNED_BYTE_2_3_3_REV
:
41 case MESA_UNSIGNED_BYTE_4_4
:
42 case GL_UNSIGNED_SHORT_5_6_5
:
43 case GL_UNSIGNED_SHORT_5_6_5_REV
:
44 case GL_UNSIGNED_SHORT_4_4_4_4
:
45 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
46 case GL_UNSIGNED_SHORT_5_5_5_1
:
47 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
48 case GL_UNSIGNED_INT_8_8_8_8
:
49 case GL_UNSIGNED_INT_8_8_8_8_REV
:
50 case GL_UNSIGNED_INT_10_10_10_2
:
51 case GL_UNSIGNED_INT_2_10_10_10_REV
:
52 case GL_UNSIGNED_SHORT_8_8_MESA
:
53 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
54 case GL_UNSIGNED_INT_24_8_EXT
:
55 case GL_UNSIGNED_INT_5_9_9_9_REV
:
56 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
57 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
66 * Get the size of a GL data type.
68 * \param type GL data type.
70 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
71 * if an invalid type enum.
74 _mesa_sizeof_type(GLenum type
)
79 case GL_UNSIGNED_BYTE
:
80 return sizeof(GLubyte
);
82 return sizeof(GLbyte
);
83 case GL_UNSIGNED_SHORT
:
84 return sizeof(GLushort
);
86 return sizeof(GLshort
);
88 return sizeof(GLuint
);
92 return sizeof(GLfloat
);
94 return sizeof(GLdouble
);
95 case GL_HALF_FLOAT_ARB
:
96 return sizeof(GLhalfARB
);
98 return sizeof(GLfixed
);
106 * Same as _mesa_sizeof_type() but also accepting the packed pixel
110 _mesa_sizeof_packed_type(GLenum type
)
115 case GL_UNSIGNED_BYTE
:
116 return sizeof(GLubyte
);
118 return sizeof(GLbyte
);
119 case GL_UNSIGNED_SHORT
:
120 return sizeof(GLushort
);
122 return sizeof(GLshort
);
123 case GL_UNSIGNED_INT
:
124 return sizeof(GLuint
);
126 return sizeof(GLint
);
127 case GL_HALF_FLOAT_ARB
:
128 return sizeof(GLhalfARB
);
130 return sizeof(GLfloat
);
131 case GL_UNSIGNED_BYTE_3_3_2
:
132 case GL_UNSIGNED_BYTE_2_3_3_REV
:
133 case MESA_UNSIGNED_BYTE_4_4
:
134 return sizeof(GLubyte
);
135 case GL_UNSIGNED_SHORT_5_6_5
:
136 case GL_UNSIGNED_SHORT_5_6_5_REV
:
137 case GL_UNSIGNED_SHORT_4_4_4_4
:
138 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
139 case GL_UNSIGNED_SHORT_5_5_5_1
:
140 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
141 case GL_UNSIGNED_SHORT_8_8_MESA
:
142 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
143 return sizeof(GLushort
);
144 case GL_UNSIGNED_INT_8_8_8_8
:
145 case GL_UNSIGNED_INT_8_8_8_8_REV
:
146 case GL_UNSIGNED_INT_10_10_10_2
:
147 case GL_UNSIGNED_INT_2_10_10_10_REV
:
148 case GL_UNSIGNED_INT_24_8_EXT
:
149 case GL_UNSIGNED_INT_5_9_9_9_REV
:
150 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
151 return sizeof(GLuint
);
152 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
161 * Get the number of components in a pixel format.
163 * \param format pixel format.
165 * \return the number of components in the given format, or -1 if a bad format.
168 _mesa_components_in_format(GLenum format
)
172 case GL_STENCIL_INDEX
:
173 case GL_DEPTH_COMPONENT
:
175 case GL_RED_INTEGER_EXT
:
177 case GL_GREEN_INTEGER_EXT
:
179 case GL_BLUE_INTEGER_EXT
:
181 case GL_ALPHA_INTEGER_EXT
:
183 case GL_LUMINANCE_INTEGER_EXT
:
187 case GL_LUMINANCE_ALPHA
:
188 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
191 case GL_DEPTH_STENCIL_EXT
:
199 case GL_RGB_INTEGER_EXT
:
200 case GL_BGR_INTEGER_EXT
:
206 case GL_RGBA_INTEGER_EXT
:
207 case GL_BGRA_INTEGER_EXT
:
217 * Get the bytes per pixel of pixel format type pair.
219 * \param format pixel format.
220 * \param type pixel type.
222 * \return bytes per pixel, or -1 if a bad format or type was given.
225 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
227 GLint comps
= _mesa_components_in_format(format
);
233 return 0; /* special case */
235 case GL_UNSIGNED_BYTE
:
236 return comps
* sizeof(GLubyte
);
238 case GL_UNSIGNED_SHORT
:
239 return comps
* sizeof(GLshort
);
241 case GL_UNSIGNED_INT
:
242 return comps
* sizeof(GLint
);
244 return comps
* sizeof(GLfloat
);
245 case GL_HALF_FLOAT_ARB
:
246 return comps
* sizeof(GLhalfARB
);
247 case GL_UNSIGNED_BYTE_3_3_2
:
248 case GL_UNSIGNED_BYTE_2_3_3_REV
:
249 if (format
== GL_RGB
|| format
== GL_BGR
||
250 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
251 return sizeof(GLubyte
);
253 return -1; /* error */
254 case GL_UNSIGNED_SHORT_5_6_5
:
255 case GL_UNSIGNED_SHORT_5_6_5_REV
:
256 if (format
== GL_RGB
|| format
== GL_BGR
||
257 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
258 return sizeof(GLushort
);
260 return -1; /* error */
261 case GL_UNSIGNED_SHORT_4_4_4_4
:
262 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
263 case GL_UNSIGNED_SHORT_5_5_5_1
:
264 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
265 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
266 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
267 return sizeof(GLushort
);
270 case GL_UNSIGNED_INT_8_8_8_8
:
271 case GL_UNSIGNED_INT_8_8_8_8_REV
:
272 case GL_UNSIGNED_INT_10_10_10_2
:
273 case GL_UNSIGNED_INT_2_10_10_10_REV
:
274 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
275 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
277 return sizeof(GLuint
);
280 case GL_UNSIGNED_SHORT_8_8_MESA
:
281 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
282 if (format
== GL_YCBCR_MESA
)
283 return sizeof(GLushort
);
286 case GL_UNSIGNED_INT_24_8_EXT
:
287 if (format
== GL_DEPTH_STENCIL_EXT
)
288 return sizeof(GLuint
);
291 case GL_UNSIGNED_INT_5_9_9_9_REV
:
292 if (format
== GL_RGB
)
293 return sizeof(GLuint
);
296 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
297 if (format
== GL_RGB
)
298 return sizeof(GLuint
);
301 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
302 if (format
== GL_DEPTH_STENCIL
)
313 * Get the number of bytes for a vertex attrib with the given number of
314 * components and type.
316 * \param comps number of components.
317 * \param type data type.
319 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
322 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
326 case GL_UNSIGNED_BYTE
:
327 return comps
* sizeof(GLubyte
);
329 case GL_UNSIGNED_SHORT
:
330 return comps
* sizeof(GLshort
);
332 case GL_UNSIGNED_INT
:
333 return comps
* sizeof(GLint
);
335 return comps
* sizeof(GLfloat
);
336 case GL_HALF_FLOAT_ARB
:
337 return comps
* sizeof(GLhalfARB
);
339 return comps
* sizeof(GLdouble
);
341 return comps
* sizeof(GLfixed
);
342 case GL_INT_2_10_10_10_REV
:
343 case GL_UNSIGNED_INT_2_10_10_10_REV
:
345 return sizeof(GLuint
);
348 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
350 return sizeof(GLuint
);
360 * Test if the given format is an integer (non-normalized) format.
363 _mesa_is_enum_format_unsigned_int(GLenum format
)
366 /* specific integer formats */
367 case GL_RGBA32UI_EXT
:
371 case GL_ALPHA32UI_EXT
:
372 case GL_INTENSITY32UI_EXT
:
373 case GL_LUMINANCE32UI_EXT
:
374 case GL_LUMINANCE_ALPHA32UI_EXT
:
375 case GL_RGBA16UI_EXT
:
379 case GL_ALPHA16UI_EXT
:
380 case GL_INTENSITY16UI_EXT
:
381 case GL_LUMINANCE16UI_EXT
:
382 case GL_LUMINANCE_ALPHA16UI_EXT
:
387 case GL_ALPHA8UI_EXT
:
388 case GL_INTENSITY8UI_EXT
:
389 case GL_LUMINANCE8UI_EXT
:
390 case GL_LUMINANCE_ALPHA8UI_EXT
:
400 * Test if the given format is an integer (non-normalized) format.
403 _mesa_is_enum_format_signed_int(GLenum format
)
406 /* generic integer formats */
407 case GL_RED_INTEGER_EXT
:
408 case GL_GREEN_INTEGER_EXT
:
409 case GL_BLUE_INTEGER_EXT
:
410 case GL_ALPHA_INTEGER_EXT
:
411 case GL_RGB_INTEGER_EXT
:
412 case GL_RGBA_INTEGER_EXT
:
413 case GL_BGR_INTEGER_EXT
:
414 case GL_BGRA_INTEGER_EXT
:
415 case GL_LUMINANCE_INTEGER_EXT
:
416 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
418 /* specific integer formats */
423 case GL_ALPHA32I_EXT
:
424 case GL_INTENSITY32I_EXT
:
425 case GL_LUMINANCE32I_EXT
:
426 case GL_LUMINANCE_ALPHA32I_EXT
:
431 case GL_ALPHA16I_EXT
:
432 case GL_INTENSITY16I_EXT
:
433 case GL_LUMINANCE16I_EXT
:
434 case GL_LUMINANCE_ALPHA16I_EXT
:
440 case GL_INTENSITY8I_EXT
:
441 case GL_LUMINANCE8I_EXT
:
442 case GL_LUMINANCE_ALPHA8I_EXT
:
451 * Test if the given format is an integer (non-normalized) format.
454 _mesa_is_enum_format_integer(GLenum format
)
456 return _mesa_is_enum_format_unsigned_int(format
) ||
457 _mesa_is_enum_format_signed_int(format
);
462 _mesa_is_type_unsigned(GLenum type
)
465 case GL_UNSIGNED_INT
:
466 case GL_UNSIGNED_INT_8_8_8_8
:
467 case GL_UNSIGNED_INT_8_8_8_8_REV
:
468 case GL_UNSIGNED_INT_10_10_10_2
:
469 case GL_UNSIGNED_INT_2_10_10_10_REV
:
471 case GL_UNSIGNED_SHORT
:
472 case GL_UNSIGNED_SHORT_4_4_4_4
:
473 case GL_UNSIGNED_SHORT_5_5_5_1
:
474 case GL_UNSIGNED_SHORT_5_6_5
:
475 case GL_UNSIGNED_SHORT_5_6_5_REV
:
476 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
477 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
478 case GL_UNSIGNED_SHORT_8_8_MESA
:
479 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
481 case GL_UNSIGNED_BYTE
:
482 case GL_UNSIGNED_BYTE_3_3_2
:
483 case GL_UNSIGNED_BYTE_2_3_3_REV
:
493 * Test if the given image format is a color/RGBA format (i.e., not color
494 * index, depth, stencil, etc).
495 * \param format the image format value (may by an internal texture format)
496 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
499 _mesa_is_color_format(GLenum format
)
517 case GL_LUMINANCE_ALPHA
:
518 case GL_LUMINANCE4_ALPHA4
:
519 case GL_LUMINANCE6_ALPHA2
:
520 case GL_LUMINANCE8_ALPHA8
:
521 case GL_LUMINANCE12_ALPHA4
:
522 case GL_LUMINANCE12_ALPHA12
:
523 case GL_LUMINANCE16_ALPHA16
:
556 /* float texture formats */
557 case GL_ALPHA16F_ARB
:
558 case GL_ALPHA32F_ARB
:
559 case GL_LUMINANCE16F_ARB
:
560 case GL_LUMINANCE32F_ARB
:
561 case GL_LUMINANCE_ALPHA16F_ARB
:
562 case GL_LUMINANCE_ALPHA32F_ARB
:
563 case GL_INTENSITY16F_ARB
:
564 case GL_INTENSITY32F_ARB
:
573 /* compressed formats */
574 case GL_COMPRESSED_ALPHA
:
575 case GL_COMPRESSED_LUMINANCE
:
576 case GL_COMPRESSED_LUMINANCE_ALPHA
:
577 case GL_COMPRESSED_INTENSITY
:
578 case GL_COMPRESSED_RED
:
579 case GL_COMPRESSED_RG
:
580 case GL_COMPRESSED_RGB
:
581 case GL_COMPRESSED_RGBA
:
586 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
587 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
588 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
589 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
590 case GL_COMPRESSED_RGB_FXT1_3DFX
:
591 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
594 case GL_SRGB_ALPHA_EXT
:
595 case GL_SRGB8_ALPHA8_EXT
:
596 case GL_SLUMINANCE_ALPHA_EXT
:
597 case GL_SLUMINANCE8_ALPHA8_EXT
:
598 case GL_SLUMINANCE_EXT
:
599 case GL_SLUMINANCE8_EXT
:
600 case GL_COMPRESSED_SRGB_EXT
:
601 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
602 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
603 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
604 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
605 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
606 case GL_COMPRESSED_SLUMINANCE_EXT
:
607 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
608 case GL_COMPRESSED_RED_RGTC1
:
609 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
610 case GL_COMPRESSED_RG_RGTC2
:
611 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
612 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
613 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
614 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
615 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
616 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
617 case GL_ETC1_RGB8_OES
:
618 case GL_COMPRESSED_RGB8_ETC2
:
619 case GL_COMPRESSED_SRGB8_ETC2
:
620 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
621 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
622 case GL_COMPRESSED_R11_EAC
:
623 case GL_COMPRESSED_RG11_EAC
:
624 case GL_COMPRESSED_SIGNED_R11_EAC
:
625 case GL_COMPRESSED_SIGNED_RG11_EAC
:
626 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
627 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
628 /* generic integer formats */
629 case GL_RED_INTEGER_EXT
:
630 case GL_GREEN_INTEGER_EXT
:
631 case GL_BLUE_INTEGER_EXT
:
632 case GL_ALPHA_INTEGER_EXT
:
633 case GL_RGB_INTEGER_EXT
:
634 case GL_RGBA_INTEGER_EXT
:
635 case GL_BGR_INTEGER_EXT
:
636 case GL_BGRA_INTEGER_EXT
:
638 case GL_LUMINANCE_INTEGER_EXT
:
639 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
640 /* sized integer formats */
641 case GL_RGBA32UI_EXT
:
645 case GL_ALPHA32UI_EXT
:
646 case GL_INTENSITY32UI_EXT
:
647 case GL_LUMINANCE32UI_EXT
:
648 case GL_LUMINANCE_ALPHA32UI_EXT
:
649 case GL_RGBA16UI_EXT
:
653 case GL_ALPHA16UI_EXT
:
654 case GL_INTENSITY16UI_EXT
:
655 case GL_LUMINANCE16UI_EXT
:
656 case GL_LUMINANCE_ALPHA16UI_EXT
:
661 case GL_ALPHA8UI_EXT
:
662 case GL_INTENSITY8UI_EXT
:
663 case GL_LUMINANCE8UI_EXT
:
664 case GL_LUMINANCE_ALPHA8UI_EXT
:
669 case GL_ALPHA32I_EXT
:
670 case GL_INTENSITY32I_EXT
:
671 case GL_LUMINANCE32I_EXT
:
672 case GL_LUMINANCE_ALPHA32I_EXT
:
677 case GL_ALPHA16I_EXT
:
678 case GL_INTENSITY16I_EXT
:
679 case GL_LUMINANCE16I_EXT
:
680 case GL_LUMINANCE_ALPHA16I_EXT
:
686 case GL_INTENSITY8I_EXT
:
687 case GL_LUMINANCE8I_EXT
:
688 case GL_LUMINANCE_ALPHA8I_EXT
:
689 /* signed, normalized texture formats */
701 case GL_RGBA16_SNORM
:
703 case GL_ALPHA8_SNORM
:
704 case GL_ALPHA16_SNORM
:
705 case GL_LUMINANCE_SNORM
:
706 case GL_LUMINANCE8_SNORM
:
707 case GL_LUMINANCE16_SNORM
:
708 case GL_LUMINANCE_ALPHA_SNORM
:
709 case GL_LUMINANCE8_ALPHA8_SNORM
:
710 case GL_LUMINANCE16_ALPHA16_SNORM
:
711 case GL_INTENSITY_SNORM
:
712 case GL_INTENSITY8_SNORM
:
713 case GL_INTENSITY16_SNORM
:
715 case GL_R11F_G11F_B10F
:
718 case GL_YCBCR_MESA
: /* not considered to be RGB */
727 * Test if the given image format is a depth component format.
730 _mesa_is_depth_format(GLenum format
)
733 case GL_DEPTH_COMPONENT
:
734 case GL_DEPTH_COMPONENT16
:
735 case GL_DEPTH_COMPONENT24
:
736 case GL_DEPTH_COMPONENT32
:
737 case GL_DEPTH_COMPONENT32F
:
746 * Test if the given image format is a stencil format.
749 _mesa_is_stencil_format(GLenum format
)
752 case GL_STENCIL_INDEX
:
761 * Test if the given image format is a YCbCr format.
764 _mesa_is_ycbcr_format(GLenum format
)
776 * Test if the given image format is a depth+stencil format.
779 _mesa_is_depthstencil_format(GLenum format
)
782 case GL_DEPTH24_STENCIL8_EXT
:
783 case GL_DEPTH_STENCIL_EXT
:
784 case GL_DEPTH32F_STENCIL8
:
793 * Test if the given image format is a depth or stencil format.
796 _mesa_is_depth_or_stencil_format(GLenum format
)
799 case GL_DEPTH_COMPONENT
:
800 case GL_DEPTH_COMPONENT16
:
801 case GL_DEPTH_COMPONENT24
:
802 case GL_DEPTH_COMPONENT32
:
803 case GL_STENCIL_INDEX
:
804 case GL_STENCIL_INDEX1_EXT
:
805 case GL_STENCIL_INDEX4_EXT
:
806 case GL_STENCIL_INDEX8_EXT
:
807 case GL_STENCIL_INDEX16_EXT
:
808 case GL_DEPTH_STENCIL_EXT
:
809 case GL_DEPTH24_STENCIL8_EXT
:
810 case GL_DEPTH_COMPONENT32F
:
811 case GL_DEPTH32F_STENCIL8
:
820 * Test if the given image format is a dudv format.
823 _mesa_is_dudv_format(GLenum format
)
836 * Test if an image format is a supported compressed format.
837 * \param format the internal format token provided by the user.
838 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
841 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
844 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
845 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
846 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
847 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
848 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
850 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
855 return _mesa_is_desktop_gl(ctx
) &&
856 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
857 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
858 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
859 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
860 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
861 return _mesa_is_desktop_gl(ctx
)
862 && ctx
->Extensions
.EXT_texture_sRGB
863 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
864 case GL_COMPRESSED_RGB_FXT1_3DFX
:
865 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
866 return _mesa_is_desktop_gl(ctx
)
867 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
868 case GL_COMPRESSED_RED_RGTC1
:
869 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
870 case GL_COMPRESSED_RG_RGTC2
:
871 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
872 return _mesa_is_desktop_gl(ctx
)
873 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
874 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
875 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
876 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
877 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
878 return ctx
->API
== API_OPENGL_COMPAT
879 && ctx
->Extensions
.EXT_texture_compression_latc
;
880 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
881 return ctx
->API
== API_OPENGL_COMPAT
882 && ctx
->Extensions
.ATI_texture_compression_3dc
;
883 case GL_ETC1_RGB8_OES
:
884 return _mesa_is_gles(ctx
)
885 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
886 case GL_COMPRESSED_RGB8_ETC2
:
887 case GL_COMPRESSED_SRGB8_ETC2
:
888 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
889 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
890 case GL_COMPRESSED_R11_EAC
:
891 case GL_COMPRESSED_RG11_EAC
:
892 case GL_COMPRESSED_SIGNED_R11_EAC
:
893 case GL_COMPRESSED_SIGNED_RG11_EAC
:
894 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
895 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
896 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
897 case GL_PALETTE4_RGB8_OES
:
898 case GL_PALETTE4_RGBA8_OES
:
899 case GL_PALETTE4_R5_G6_B5_OES
:
900 case GL_PALETTE4_RGBA4_OES
:
901 case GL_PALETTE4_RGB5_A1_OES
:
902 case GL_PALETTE8_RGB8_OES
:
903 case GL_PALETTE8_RGBA8_OES
:
904 case GL_PALETTE8_R5_G6_B5_OES
:
905 case GL_PALETTE8_RGBA4_OES
:
906 case GL_PALETTE8_RGB5_A1_OES
:
907 return ctx
->API
== API_OPENGLES
;
915 * Convert various base formats to the cooresponding integer format.
918 _mesa_base_format_to_integer_format(GLenum format
)
922 return GL_RED_INTEGER
;
924 return GL_GREEN_INTEGER
;
926 return GL_BLUE_INTEGER
;
928 return GL_RG_INTEGER
;
930 return GL_RGB_INTEGER
;
932 return GL_RGBA_INTEGER
;
934 return GL_BGR_INTEGER
;
936 return GL_BGRA_INTEGER
;
938 return GL_ALPHA_INTEGER
;
940 return GL_LUMINANCE_INTEGER_EXT
;
941 case GL_LUMINANCE_ALPHA
:
942 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
950 * Does the given base texture/renderbuffer format have the channel
954 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
957 case GL_TEXTURE_RED_SIZE
:
958 case GL_TEXTURE_RED_TYPE
:
959 case GL_RENDERBUFFER_RED_SIZE_EXT
:
960 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
961 if (base_format
== GL_RED
||
962 base_format
== GL_RG
||
963 base_format
== GL_RGB
||
964 base_format
== GL_RGBA
) {
968 case GL_TEXTURE_GREEN_SIZE
:
969 case GL_TEXTURE_GREEN_TYPE
:
970 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
971 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
972 if (base_format
== GL_RG
||
973 base_format
== GL_RGB
||
974 base_format
== GL_RGBA
) {
978 case GL_TEXTURE_BLUE_SIZE
:
979 case GL_TEXTURE_BLUE_TYPE
:
980 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
981 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
982 if (base_format
== GL_RGB
||
983 base_format
== GL_RGBA
) {
987 case GL_TEXTURE_ALPHA_SIZE
:
988 case GL_TEXTURE_ALPHA_TYPE
:
989 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
990 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
991 if (base_format
== GL_RGBA
||
992 base_format
== GL_ALPHA
||
993 base_format
== GL_LUMINANCE_ALPHA
) {
997 case GL_TEXTURE_LUMINANCE_SIZE
:
998 case GL_TEXTURE_LUMINANCE_TYPE
:
999 if (base_format
== GL_LUMINANCE
||
1000 base_format
== GL_LUMINANCE_ALPHA
) {
1004 case GL_TEXTURE_INTENSITY_SIZE
:
1005 case GL_TEXTURE_INTENSITY_TYPE
:
1006 if (base_format
== GL_INTENSITY
) {
1010 case GL_TEXTURE_DEPTH_SIZE
:
1011 case GL_TEXTURE_DEPTH_TYPE
:
1012 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1013 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1014 if (base_format
== GL_DEPTH_STENCIL
||
1015 base_format
== GL_DEPTH_COMPONENT
) {
1019 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1020 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1021 if (base_format
== GL_DEPTH_STENCIL
||
1022 base_format
== GL_STENCIL_INDEX
) {
1027 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1028 __FUNCTION__
, pname
);
1037 * Returns the number of channels/components for a base format.
1040 _mesa_base_format_component_count(GLenum base_format
)
1042 switch (base_format
) {
1046 case GL_DEPTH_COMPONENT
:
1049 case GL_LUMINANCE_ALPHA
:
1050 case GL_DEPTH_STENCIL
:
1063 * If format is a generic compressed format, return the corresponding
1064 * non-compressed format. For other formats, return the format as-is.
1067 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1070 case GL_COMPRESSED_RED
:
1072 case GL_COMPRESSED_RG
:
1074 case GL_COMPRESSED_RGB
:
1076 case GL_COMPRESSED_RGBA
:
1078 case GL_COMPRESSED_ALPHA
:
1080 case GL_COMPRESSED_LUMINANCE
:
1081 return GL_LUMINANCE
;
1082 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1083 return GL_LUMINANCE_ALPHA
;
1084 case GL_COMPRESSED_INTENSITY
:
1085 return GL_INTENSITY
;
1087 case GL_COMPRESSED_SRGB
:
1089 case GL_COMPRESSED_SRGB_ALPHA
:
1090 return GL_SRGB_ALPHA
;
1091 case GL_COMPRESSED_SLUMINANCE
:
1092 return GL_SLUMINANCE
;
1093 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1094 return GL_SLUMINANCE_ALPHA
;
1102 * Return the equivalent non-generic internal format.
1103 * This is useful for comparing whether two internal formats are equivalent.
1106 _mesa_get_nongeneric_internalformat(GLenum format
)
1109 /* GL 1.1 formats. */
1117 case GL_LUMINANCE_ALPHA
:
1118 return GL_LUMINANCE8_ALPHA8
;
1121 return GL_LUMINANCE8
;
1125 return GL_INTENSITY8
;
1127 /* GL_ARB_texture_rg */
1133 /* GL_EXT_texture_sRGB */
1137 return GL_SRGB8_ALPHA8
;
1139 return GL_SLUMINANCE8
;
1140 case GL_SLUMINANCE_ALPHA
:
1141 return GL_SLUMINANCE8_ALPHA8
;
1143 /* GL_EXT_texture_snorm */
1145 return GL_RGBA8_SNORM
;
1147 return GL_RGB8_SNORM
;
1149 return GL_RG8_SNORM
;
1152 case GL_LUMINANCE_ALPHA_SNORM
:
1153 return GL_LUMINANCE8_ALPHA8_SNORM
;
1154 case GL_LUMINANCE_SNORM
:
1155 return GL_LUMINANCE8_SNORM
;
1156 case GL_ALPHA_SNORM
:
1157 return GL_ALPHA8_SNORM
;
1158 case GL_INTENSITY_SNORM
:
1159 return GL_INTENSITY8_SNORM
;
1168 * Convert an sRGB internal format to linear.
1171 _mesa_get_linear_internalformat(GLenum format
)
1180 case GL_SRGB8_ALPHA8
:
1182 case GL_SLUMINANCE8
:
1183 return GL_LUMINANCE8
;
1185 return GL_LUMINANCE
;
1186 case GL_SLUMINANCE_ALPHA
:
1187 return GL_LUMINANCE_ALPHA
;
1188 case GL_SLUMINANCE8_ALPHA8
:
1189 return GL_LUMINANCE8_ALPHA8
;
1197 * Do error checking of format/type combinations for glReadPixels,
1198 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1199 * and type values, we may either generate GL_INVALID_OPERATION or
1202 * \param format pixel format.
1203 * \param type pixel type.
1205 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1208 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1209 GLenum format
, GLenum type
)
1211 /* From OpenGL 3.3 spec, page 220:
1212 * "If the format is DEPTH_STENCIL, then values are taken from
1213 * both the depth buffer and the stencil buffer. If there is no
1214 * depth buffer or if there is no stencil buffer, then the error
1215 * INVALID_OPERATION occurs. If the type parameter is not
1216 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1217 * error INVALID_ENUM occurs."
1219 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1220 * cannot be used to read depth or stencil in that API.
1222 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1223 && type
!= GL_UNSIGNED_INT_24_8
1224 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1225 return GL_INVALID_ENUM
;
1227 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1230 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1231 return GL_INVALID_ENUM
;
1235 case GL_UNSIGNED_BYTE_3_3_2
:
1236 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1237 case GL_UNSIGNED_SHORT_5_6_5
:
1238 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1239 if (format
== GL_RGB
) {
1242 if (format
== GL_RGB_INTEGER_EXT
&&
1243 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1246 return GL_INVALID_OPERATION
;
1248 case GL_UNSIGNED_SHORT_4_4_4_4
:
1249 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1250 case GL_UNSIGNED_SHORT_5_5_5_1
:
1251 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1252 case GL_UNSIGNED_INT_8_8_8_8
:
1253 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1254 case GL_UNSIGNED_INT_10_10_10_2
:
1255 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1256 if (format
== GL_RGBA
||
1257 format
== GL_BGRA
||
1258 format
== GL_ABGR_EXT
) {
1261 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1262 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1265 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1266 ctx
->API
== API_OPENGLES2
) {
1267 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1269 return GL_INVALID_OPERATION
;
1271 case GL_UNSIGNED_INT_24_8
:
1272 if (format
!= GL_DEPTH_STENCIL
) {
1273 return GL_INVALID_OPERATION
;
1277 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1278 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1279 return GL_INVALID_ENUM
;
1281 if (format
!= GL_DEPTH_STENCIL
) {
1282 return GL_INVALID_OPERATION
;
1286 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1287 if (!ctx
->Extensions
.EXT_packed_float
) {
1288 return GL_INVALID_ENUM
;
1290 if (format
!= GL_RGB
) {
1291 return GL_INVALID_OPERATION
;
1296 ; /* fall-through */
1299 /* now, for each format, check the type for compatibility */
1301 case GL_COLOR_INDEX
:
1302 case GL_STENCIL_INDEX
:
1306 case GL_UNSIGNED_BYTE
:
1308 case GL_UNSIGNED_SHORT
:
1310 case GL_UNSIGNED_INT
:
1315 return GL_INVALID_ENUM
;
1322 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1326 case GL_LUMINANCE_ALPHA
:
1327 case GL_DEPTH_COMPONENT
:
1330 case GL_UNSIGNED_BYTE
:
1332 case GL_UNSIGNED_SHORT
:
1334 case GL_UNSIGNED_INT
:
1339 return GL_INVALID_ENUM
;
1343 if (!ctx
->Extensions
.ARB_texture_rg
)
1344 return GL_INVALID_ENUM
;
1347 case GL_UNSIGNED_BYTE
:
1349 case GL_UNSIGNED_SHORT
:
1351 case GL_UNSIGNED_INT
:
1356 return GL_INVALID_ENUM
;
1362 case GL_UNSIGNED_BYTE
:
1364 case GL_UNSIGNED_SHORT
:
1366 case GL_UNSIGNED_INT
:
1368 case GL_UNSIGNED_BYTE_3_3_2
:
1369 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1370 case GL_UNSIGNED_SHORT_5_6_5
:
1371 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1374 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1375 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1376 return (ctx
->API
== API_OPENGLES2
)
1377 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1378 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1379 return ctx
->Extensions
.EXT_texture_shared_exponent
1380 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1381 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1382 return ctx
->Extensions
.EXT_packed_float
1383 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1385 return GL_INVALID_ENUM
;
1390 /* NOTE: no packed types are supported with BGR. That's
1391 * intentional, according to the GL spec.
1394 case GL_UNSIGNED_BYTE
:
1396 case GL_UNSIGNED_SHORT
:
1398 case GL_UNSIGNED_INT
:
1403 return GL_INVALID_ENUM
;
1411 case GL_UNSIGNED_BYTE
:
1413 case GL_UNSIGNED_SHORT
:
1415 case GL_UNSIGNED_INT
:
1417 case GL_UNSIGNED_SHORT_4_4_4_4
:
1418 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1419 case GL_UNSIGNED_SHORT_5_5_5_1
:
1420 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1421 case GL_UNSIGNED_INT_8_8_8_8
:
1422 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1423 case GL_UNSIGNED_INT_10_10_10_2
:
1424 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1428 return GL_INVALID_ENUM
;
1432 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1433 return GL_INVALID_ENUM
;
1434 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1435 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1438 return GL_INVALID_OPERATION
;
1440 case GL_DEPTH_STENCIL
:
1441 if (type
== GL_UNSIGNED_INT_24_8
)
1443 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1444 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1447 return GL_INVALID_ENUM
;
1451 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1452 return GL_INVALID_ENUM
;
1455 case GL_UNSIGNED_BYTE
:
1457 case GL_UNSIGNED_SHORT
:
1459 case GL_UNSIGNED_INT
:
1463 return GL_INVALID_ENUM
;
1466 /* integer-valued formats */
1467 case GL_RED_INTEGER_EXT
:
1468 case GL_GREEN_INTEGER_EXT
:
1469 case GL_BLUE_INTEGER_EXT
:
1470 case GL_ALPHA_INTEGER_EXT
:
1474 case GL_UNSIGNED_BYTE
:
1476 case GL_UNSIGNED_SHORT
:
1478 case GL_UNSIGNED_INT
:
1479 return (ctx
->Version
>= 30 ||
1480 ctx
->Extensions
.EXT_texture_integer
)
1481 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1483 return GL_INVALID_ENUM
;
1486 case GL_RGB_INTEGER_EXT
:
1489 case GL_UNSIGNED_BYTE
:
1491 case GL_UNSIGNED_SHORT
:
1493 case GL_UNSIGNED_INT
:
1494 return (ctx
->Version
>= 30 ||
1495 ctx
->Extensions
.EXT_texture_integer
)
1496 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1497 case GL_UNSIGNED_BYTE_3_3_2
:
1498 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1499 case GL_UNSIGNED_SHORT_5_6_5
:
1500 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1501 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1502 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1504 return GL_INVALID_ENUM
;
1507 case GL_BGR_INTEGER_EXT
:
1510 case GL_UNSIGNED_BYTE
:
1512 case GL_UNSIGNED_SHORT
:
1514 case GL_UNSIGNED_INT
:
1515 /* NOTE: no packed formats w/ BGR format */
1516 return (ctx
->Version
>= 30 ||
1517 ctx
->Extensions
.EXT_texture_integer
)
1518 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1520 return GL_INVALID_ENUM
;
1523 case GL_RGBA_INTEGER_EXT
:
1524 case GL_BGRA_INTEGER_EXT
:
1527 case GL_UNSIGNED_BYTE
:
1529 case GL_UNSIGNED_SHORT
:
1531 case GL_UNSIGNED_INT
:
1532 return (ctx
->Version
>= 30 ||
1533 ctx
->Extensions
.EXT_texture_integer
)
1534 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1535 case GL_UNSIGNED_SHORT_4_4_4_4
:
1536 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1537 case GL_UNSIGNED_SHORT_5_5_5_1
:
1538 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1539 case GL_UNSIGNED_INT_8_8_8_8
:
1540 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1541 case GL_UNSIGNED_INT_10_10_10_2
:
1542 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1543 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1544 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1546 return GL_INVALID_ENUM
;
1549 case GL_LUMINANCE_INTEGER_EXT
:
1550 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1553 case GL_UNSIGNED_BYTE
:
1555 case GL_UNSIGNED_SHORT
:
1557 case GL_UNSIGNED_INT
:
1558 return ctx
->Extensions
.EXT_texture_integer
1559 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1561 return GL_INVALID_ENUM
;
1565 return GL_INVALID_ENUM
;
1572 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1573 * and glTex[Sub]Image.
1574 * \return error code, or GL_NO_ERROR.
1577 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1578 unsigned dimensions
)
1580 GLboolean type_valid
= GL_TRUE
;
1585 case GL_LUMINANCE_ALPHA
:
1586 type_valid
= (type
== GL_UNSIGNED_BYTE
1588 || type
== GL_HALF_FLOAT_OES
);
1592 type_valid
= (type
== GL_UNSIGNED_BYTE
1593 || type
== GL_UNSIGNED_SHORT_5_6_5
1595 || type
== GL_HALF_FLOAT_OES
);
1599 type_valid
= (type
== GL_UNSIGNED_BYTE
1600 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1601 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1603 || type
== GL_HALF_FLOAT_OES
1604 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1607 case GL_DEPTH_COMPONENT
:
1608 /* This format is filtered against invalid dimensionalities elsewhere.
1610 type_valid
= (type
== GL_UNSIGNED_SHORT
1611 || type
== GL_UNSIGNED_INT
);
1614 case GL_DEPTH_STENCIL
:
1615 /* This format is filtered against invalid dimensionalities elsewhere.
1617 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1621 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1623 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1624 * the format does not appear to be allowed for 3D textures in OpenGL
1627 if (dimensions
!= 2)
1628 return GL_INVALID_VALUE
;
1633 return GL_INVALID_VALUE
;
1636 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
1641 * Do error checking of format/type combinations for OpenGL ES 3
1643 * \return error code, or GL_NO_ERROR.
1646 _mesa_es3_error_check_format_and_type(GLenum format
, GLenum type
,
1647 GLenum internalFormat
)
1652 case GL_UNSIGNED_BYTE
:
1653 switch (internalFormat
) {
1658 case GL_SRGB8_ALPHA8_EXT
:
1661 return GL_INVALID_OPERATION
;
1666 if (internalFormat
!= GL_RGBA8_SNORM
)
1667 return GL_INVALID_OPERATION
;
1670 case GL_UNSIGNED_SHORT_4_4_4_4
:
1671 switch (internalFormat
) {
1676 return GL_INVALID_OPERATION
;
1680 case GL_UNSIGNED_SHORT_5_5_5_1
:
1681 switch (internalFormat
) {
1686 return GL_INVALID_OPERATION
;
1690 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1691 switch (internalFormat
) {
1692 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
1697 return GL_INVALID_OPERATION
;
1702 if (internalFormat
!= GL_RGBA16F
)
1703 return GL_INVALID_OPERATION
;
1707 switch (internalFormat
) {
1712 return GL_INVALID_OPERATION
;
1717 return GL_INVALID_OPERATION
;
1721 case GL_RGBA_INTEGER
:
1723 case GL_UNSIGNED_BYTE
:
1724 if (internalFormat
!= GL_RGBA8UI
)
1725 return GL_INVALID_OPERATION
;
1729 if (internalFormat
!= GL_RGBA8I
)
1730 return GL_INVALID_OPERATION
;
1733 case GL_UNSIGNED_SHORT
:
1734 if (internalFormat
!= GL_RGBA16UI
)
1735 return GL_INVALID_OPERATION
;
1739 if (internalFormat
!= GL_RGBA16I
)
1740 return GL_INVALID_OPERATION
;
1743 case GL_UNSIGNED_INT
:
1744 if (internalFormat
!= GL_RGBA32UI
)
1745 return GL_INVALID_OPERATION
;
1749 if (internalFormat
!= GL_RGBA32I
)
1750 return GL_INVALID_OPERATION
;
1753 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1754 if (internalFormat
!= GL_RGB10_A2UI
)
1755 return GL_INVALID_OPERATION
;
1759 return GL_INVALID_OPERATION
;
1765 case GL_UNSIGNED_BYTE
:
1766 switch (internalFormat
) {
1773 return GL_INVALID_OPERATION
;
1778 if (internalFormat
!= GL_RGB8_SNORM
)
1779 return GL_INVALID_OPERATION
;
1782 case GL_UNSIGNED_SHORT_5_6_5
:
1783 switch (internalFormat
) {
1788 return GL_INVALID_OPERATION
;
1792 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1793 if (internalFormat
!= GL_R11F_G11F_B10F
)
1794 return GL_INVALID_OPERATION
;
1797 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1798 if (internalFormat
!= GL_RGB9_E5
)
1799 return GL_INVALID_OPERATION
;
1803 switch (internalFormat
) {
1805 case GL_R11F_G11F_B10F
:
1809 return GL_INVALID_OPERATION
;
1814 switch (internalFormat
) {
1817 case GL_R11F_G11F_B10F
:
1821 return GL_INVALID_OPERATION
;
1825 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1826 switch (internalFormat
) {
1827 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
1830 return GL_INVALID_OPERATION
;
1835 return GL_INVALID_OPERATION
;
1839 case GL_RGB_INTEGER
:
1841 case GL_UNSIGNED_BYTE
:
1842 if (internalFormat
!= GL_RGB8UI
)
1843 return GL_INVALID_OPERATION
;
1847 if (internalFormat
!= GL_RGB8I
)
1848 return GL_INVALID_OPERATION
;
1851 case GL_UNSIGNED_SHORT
:
1852 if (internalFormat
!= GL_RGB16UI
)
1853 return GL_INVALID_OPERATION
;
1857 if (internalFormat
!= GL_RGB16I
)
1858 return GL_INVALID_OPERATION
;
1861 case GL_UNSIGNED_INT
:
1862 if (internalFormat
!= GL_RGB32UI
)
1863 return GL_INVALID_OPERATION
;
1867 if (internalFormat
!= GL_RGB32I
)
1868 return GL_INVALID_OPERATION
;
1872 return GL_INVALID_OPERATION
;
1878 case GL_UNSIGNED_BYTE
:
1879 if (internalFormat
!= GL_RG8
)
1880 return GL_INVALID_OPERATION
;
1884 if (internalFormat
!= GL_RG8_SNORM
)
1885 return GL_INVALID_OPERATION
;
1889 if (internalFormat
!= GL_RG16F
)
1890 return GL_INVALID_OPERATION
;
1894 switch (internalFormat
) {
1899 return GL_INVALID_OPERATION
;
1904 return GL_INVALID_OPERATION
;
1910 case GL_UNSIGNED_BYTE
:
1911 if (internalFormat
!= GL_RG8UI
)
1912 return GL_INVALID_OPERATION
;
1916 if (internalFormat
!= GL_RG8I
)
1917 return GL_INVALID_OPERATION
;
1920 case GL_UNSIGNED_SHORT
:
1921 if (internalFormat
!= GL_RG16UI
)
1922 return GL_INVALID_OPERATION
;
1926 if (internalFormat
!= GL_RG16I
)
1927 return GL_INVALID_OPERATION
;
1930 case GL_UNSIGNED_INT
:
1931 if (internalFormat
!= GL_RG32UI
)
1932 return GL_INVALID_OPERATION
;
1936 if (internalFormat
!= GL_RG32I
)
1937 return GL_INVALID_OPERATION
;
1941 return GL_INVALID_OPERATION
;
1947 case GL_UNSIGNED_BYTE
:
1948 if (internalFormat
!= GL_R8
)
1949 return GL_INVALID_OPERATION
;
1953 if (internalFormat
!= GL_R8_SNORM
)
1954 return GL_INVALID_OPERATION
;
1958 if (internalFormat
!= GL_R16F
)
1959 return GL_INVALID_OPERATION
;
1963 switch (internalFormat
) {
1968 return GL_INVALID_OPERATION
;
1973 return GL_INVALID_OPERATION
;
1977 case GL_RED_INTEGER
:
1979 case GL_UNSIGNED_BYTE
:
1980 if (internalFormat
!= GL_R8UI
)
1981 return GL_INVALID_OPERATION
;
1985 if (internalFormat
!= GL_R8I
)
1986 return GL_INVALID_OPERATION
;
1989 case GL_UNSIGNED_SHORT
:
1990 if (internalFormat
!= GL_R16UI
)
1991 return GL_INVALID_OPERATION
;
1995 if (internalFormat
!= GL_R16I
)
1996 return GL_INVALID_OPERATION
;
1999 case GL_UNSIGNED_INT
:
2000 if (internalFormat
!= GL_R32UI
)
2001 return GL_INVALID_OPERATION
;
2005 if (internalFormat
!= GL_R32I
)
2006 return GL_INVALID_OPERATION
;
2010 return GL_INVALID_OPERATION
;
2014 case GL_DEPTH_COMPONENT
:
2016 case GL_UNSIGNED_SHORT
:
2017 if (internalFormat
!= GL_DEPTH_COMPONENT
2018 && internalFormat
!= GL_DEPTH_COMPONENT16
)
2019 return GL_INVALID_OPERATION
;
2022 case GL_UNSIGNED_INT
:
2023 switch (internalFormat
) {
2024 case GL_DEPTH_COMPONENT
:
2025 case GL_DEPTH_COMPONENT16
:
2026 case GL_DEPTH_COMPONENT24
:
2029 return GL_INVALID_OPERATION
;
2034 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
2035 return GL_INVALID_OPERATION
;
2039 return GL_INVALID_OPERATION
;
2043 case GL_DEPTH_STENCIL
:
2045 case GL_UNSIGNED_INT_24_8
:
2046 if (internalFormat
!= GL_DEPTH_STENCIL
2047 && internalFormat
!= GL_DEPTH24_STENCIL8
)
2048 return GL_INVALID_OPERATION
;
2051 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2052 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
2053 return GL_INVALID_OPERATION
;
2057 return GL_INVALID_OPERATION
;
2063 case GL_LUMINANCE_ALPHA
:
2064 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
2065 return GL_INVALID_OPERATION
;