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"
31 #include "texcompress.h"
56 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
57 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
58 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
59 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
75 MAP4(ZERO
, ZERO
, ZERO
, 0),
105 MAP4(0, ZERO
, ZERO
, ONE
),
111 MAP4(ZERO
, 0, ZERO
, ONE
),
117 MAP4(ZERO
, ZERO
, 0, ONE
),
141 MAP4(0, 1, ZERO
, ONE
),
147 * Convert a GL image format enum to an IDX_* value (see above).
150 get_map_idx(GLenum value
)
154 case GL_LUMINANCE_INTEGER_EXT
:
155 return IDX_LUMINANCE
;
157 case GL_ALPHA_INTEGER
:
160 return IDX_INTENSITY
;
161 case GL_LUMINANCE_ALPHA
:
162 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
163 return IDX_LUMINANCE_ALPHA
;
168 case GL_RGBA_INTEGER
:
181 case GL_BGRA_INTEGER
:
189 _mesa_problem(NULL
, "Unexpected inFormat %s",
190 _mesa_enum_to_string(value
));
196 * When promoting texture formats (see below) we need to compute the
197 * mapping of dest components back to source components.
198 * This function does that.
199 * \param inFormat the incoming format of the texture
200 * \param outFormat the final texture format
201 * \return map[6] a full 6-component map
204 _mesa_compute_component_mapping(GLenum inFormat
, GLenum outFormat
, GLubyte
*map
)
206 const int inFmt
= get_map_idx(inFormat
);
207 const int outFmt
= get_map_idx(outFormat
);
208 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
209 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
212 for (i
= 0; i
< 4; i
++)
213 map
[i
] = in2rgba
[rgba2out
[i
]];
219 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
220 inFormat
, _mesa_enum_to_string(inFormat
),
221 outFormat
, _mesa_enum_to_string(outFormat
),
232 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
235 _mesa_type_is_packed(GLenum type
)
238 case GL_UNSIGNED_BYTE_3_3_2
:
239 case GL_UNSIGNED_BYTE_2_3_3_REV
:
240 case MESA_UNSIGNED_BYTE_4_4
:
241 case GL_UNSIGNED_SHORT_5_6_5
:
242 case GL_UNSIGNED_SHORT_5_6_5_REV
:
243 case GL_UNSIGNED_SHORT_4_4_4_4
:
244 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
245 case GL_UNSIGNED_SHORT_5_5_5_1
:
246 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
247 case GL_UNSIGNED_INT_8_8_8_8
:
248 case GL_UNSIGNED_INT_8_8_8_8_REV
:
249 case GL_UNSIGNED_INT_10_10_10_2
:
250 case GL_UNSIGNED_INT_2_10_10_10_REV
:
251 case GL_UNSIGNED_SHORT_8_8_MESA
:
252 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
253 case GL_UNSIGNED_INT_24_8_EXT
:
254 case GL_UNSIGNED_INT_5_9_9_9_REV
:
255 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
256 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
265 * Get the size of a GL data type.
267 * \param type GL data type.
269 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
270 * if an invalid type enum.
273 _mesa_sizeof_type(GLenum type
)
278 case GL_UNSIGNED_BYTE
:
279 return sizeof(GLubyte
);
281 return sizeof(GLbyte
);
282 case GL_UNSIGNED_SHORT
:
283 return sizeof(GLushort
);
285 return sizeof(GLshort
);
286 case GL_UNSIGNED_INT
:
287 return sizeof(GLuint
);
289 return sizeof(GLint
);
291 return sizeof(GLfloat
);
293 return sizeof(GLdouble
);
294 case GL_HALF_FLOAT_ARB
:
295 case GL_HALF_FLOAT_OES
:
296 return sizeof(GLhalfARB
);
298 return sizeof(GLfixed
);
306 * Same as _mesa_sizeof_type() but also accepting the packed pixel
310 _mesa_sizeof_packed_type(GLenum type
)
315 case GL_UNSIGNED_BYTE
:
316 return sizeof(GLubyte
);
318 return sizeof(GLbyte
);
319 case GL_UNSIGNED_SHORT
:
320 return sizeof(GLushort
);
322 return sizeof(GLshort
);
323 case GL_UNSIGNED_INT
:
324 return sizeof(GLuint
);
326 return sizeof(GLint
);
327 case GL_HALF_FLOAT_ARB
:
328 case GL_HALF_FLOAT_OES
:
329 return sizeof(GLhalfARB
);
331 return sizeof(GLfloat
);
332 case GL_UNSIGNED_BYTE_3_3_2
:
333 case GL_UNSIGNED_BYTE_2_3_3_REV
:
334 case MESA_UNSIGNED_BYTE_4_4
:
335 return sizeof(GLubyte
);
336 case GL_UNSIGNED_SHORT_5_6_5
:
337 case GL_UNSIGNED_SHORT_5_6_5_REV
:
338 case GL_UNSIGNED_SHORT_4_4_4_4
:
339 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
340 case GL_UNSIGNED_SHORT_5_5_5_1
:
341 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
342 case GL_UNSIGNED_SHORT_8_8_MESA
:
343 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
344 return sizeof(GLushort
);
345 case GL_UNSIGNED_INT_8_8_8_8
:
346 case GL_UNSIGNED_INT_8_8_8_8_REV
:
347 case GL_UNSIGNED_INT_10_10_10_2
:
348 case GL_UNSIGNED_INT_2_10_10_10_REV
:
349 case GL_UNSIGNED_INT_24_8_EXT
:
350 case GL_UNSIGNED_INT_5_9_9_9_REV
:
351 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
352 return sizeof(GLuint
);
353 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
362 * Get the number of components in a pixel format.
364 * \param format pixel format.
366 * \return the number of components in the given format, or -1 if a bad format.
369 _mesa_components_in_format(GLenum format
)
373 case GL_STENCIL_INDEX
:
374 case GL_DEPTH_COMPONENT
:
376 case GL_RED_INTEGER_EXT
:
378 case GL_GREEN_INTEGER_EXT
:
380 case GL_BLUE_INTEGER_EXT
:
382 case GL_ALPHA_INTEGER_EXT
:
384 case GL_LUMINANCE_INTEGER_EXT
:
388 case GL_LUMINANCE_ALPHA
:
389 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
392 case GL_DEPTH_STENCIL_EXT
:
398 case GL_RGB_INTEGER_EXT
:
399 case GL_BGR_INTEGER_EXT
:
405 case GL_RGBA_INTEGER_EXT
:
406 case GL_BGRA_INTEGER_EXT
:
416 * Get the bytes per pixel of pixel format type pair.
418 * \param format pixel format.
419 * \param type pixel type.
421 * \return bytes per pixel, or -1 if a bad format or type was given.
424 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
426 GLint comps
= _mesa_components_in_format(format
);
432 return 0; /* special case */
434 case GL_UNSIGNED_BYTE
:
435 return comps
* sizeof(GLubyte
);
437 case GL_UNSIGNED_SHORT
:
438 return comps
* sizeof(GLshort
);
440 case GL_UNSIGNED_INT
:
441 return comps
* sizeof(GLint
);
443 return comps
* sizeof(GLfloat
);
444 case GL_HALF_FLOAT_ARB
:
445 case GL_HALF_FLOAT_OES
:
446 return comps
* sizeof(GLhalfARB
);
447 case GL_UNSIGNED_BYTE_3_3_2
:
448 case GL_UNSIGNED_BYTE_2_3_3_REV
:
449 if (format
== GL_RGB
|| format
== GL_BGR
||
450 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
451 return sizeof(GLubyte
);
453 return -1; /* error */
454 case GL_UNSIGNED_SHORT_5_6_5
:
455 case GL_UNSIGNED_SHORT_5_6_5_REV
:
456 if (format
== GL_RGB
|| format
== GL_BGR
||
457 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
458 return sizeof(GLushort
);
460 return -1; /* error */
461 case GL_UNSIGNED_SHORT_4_4_4_4
:
462 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
463 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
464 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
465 return sizeof(GLushort
);
468 case GL_UNSIGNED_SHORT_5_5_5_1
:
469 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
470 if (format
== GL_RGBA
|| format
== GL_BGRA
||
471 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
472 return sizeof(GLushort
);
475 case GL_UNSIGNED_INT_8_8_8_8
:
476 case GL_UNSIGNED_INT_8_8_8_8_REV
:
477 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
478 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
480 return sizeof(GLuint
);
483 case GL_UNSIGNED_INT_10_10_10_2
:
484 case GL_UNSIGNED_INT_2_10_10_10_REV
:
485 if (format
== GL_RGBA
|| format
== GL_BGRA
||
486 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
488 return sizeof(GLuint
);
491 case GL_UNSIGNED_SHORT_8_8_MESA
:
492 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
493 if (format
== GL_YCBCR_MESA
)
494 return sizeof(GLushort
);
497 case GL_UNSIGNED_INT_24_8_EXT
:
498 if (format
== GL_DEPTH_COMPONENT
||
499 format
== GL_DEPTH_STENCIL_EXT
)
500 return sizeof(GLuint
);
503 case GL_UNSIGNED_INT_5_9_9_9_REV
:
504 if (format
== GL_RGB
)
505 return sizeof(GLuint
);
508 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
509 if (format
== GL_RGB
)
510 return sizeof(GLuint
);
513 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
514 if (format
== GL_DEPTH_STENCIL
)
525 * Get the number of bytes for a vertex attrib with the given number of
526 * components and type.
528 * \param comps number of components.
529 * \param type data type.
531 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
534 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
538 case GL_UNSIGNED_BYTE
:
539 return comps
* sizeof(GLubyte
);
541 case GL_UNSIGNED_SHORT
:
542 return comps
* sizeof(GLshort
);
544 case GL_UNSIGNED_INT
:
545 return comps
* sizeof(GLint
);
547 return comps
* sizeof(GLfloat
);
548 case GL_HALF_FLOAT_ARB
:
549 return comps
* sizeof(GLhalfARB
);
551 return comps
* sizeof(GLdouble
);
553 return comps
* sizeof(GLfixed
);
554 case GL_INT_2_10_10_10_REV
:
555 case GL_UNSIGNED_INT_2_10_10_10_REV
:
557 return sizeof(GLuint
);
560 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
562 return sizeof(GLuint
);
571 * Test if the given format is unsized.
574 _mesa_is_enum_format_unsized(GLenum format
)
589 case GL_LUMINANCE_ALPHA
:
594 case GL_SLUMINANCE_ALPHA
:
601 case GL_INTENSITY_SNORM
:
602 case GL_LUMINANCE_SNORM
:
603 case GL_LUMINANCE_ALPHA_SNORM
:
606 case GL_GREEN_INTEGER
:
607 case GL_BLUE_INTEGER
:
608 case GL_ALPHA_INTEGER
:
610 case GL_RGBA_INTEGER
:
612 case GL_BGRA_INTEGER
:
614 case GL_LUMINANCE_INTEGER_EXT
:
615 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
617 case GL_DEPTH_COMPONENT
:
618 case GL_DEPTH_STENCIL
:
619 case GL_STENCIL_INDEX
:
627 * Test if the given format is a UNORM (unsigned-normalized) format.
630 _mesa_is_enum_format_unorm(GLenum format
)
649 case GL_LUMINANCE_ALPHA
:
650 case GL_SLUMINANCE_ALPHA
:
651 case GL_LUMINANCE4_ALPHA4
:
652 case GL_LUMINANCE6_ALPHA2
:
653 case GL_LUMINANCE8_ALPHA8
:
654 case GL_LUMINANCE12_ALPHA4
:
655 case GL_LUMINANCE12_ALPHA12
:
656 case GL_LUMINANCE16_ALPHA16
:
698 * Test if the given format is a SNORM (signed-normalized) format.
701 _mesa_is_enum_format_snorm(GLenum format
)
704 /* signed, normalized texture formats */
716 case GL_RGBA16_SNORM
:
718 case GL_ALPHA8_SNORM
:
719 case GL_ALPHA16_SNORM
:
720 case GL_LUMINANCE_SNORM
:
721 case GL_LUMINANCE8_SNORM
:
722 case GL_LUMINANCE16_SNORM
:
723 case GL_LUMINANCE_ALPHA_SNORM
:
724 case GL_LUMINANCE8_ALPHA8_SNORM
:
725 case GL_LUMINANCE16_ALPHA16_SNORM
:
726 case GL_INTENSITY_SNORM
:
727 case GL_INTENSITY8_SNORM
:
728 case GL_INTENSITY16_SNORM
:
736 * Test if the given format is an integer (non-normalized) format.
739 _mesa_is_enum_format_unsigned_int(GLenum format
)
742 /* specific integer formats */
743 case GL_RGBA32UI_EXT
:
747 case GL_ALPHA32UI_EXT
:
748 case GL_INTENSITY32UI_EXT
:
749 case GL_LUMINANCE32UI_EXT
:
750 case GL_LUMINANCE_ALPHA32UI_EXT
:
751 case GL_RGBA16UI_EXT
:
755 case GL_ALPHA16UI_EXT
:
756 case GL_INTENSITY16UI_EXT
:
757 case GL_LUMINANCE16UI_EXT
:
758 case GL_LUMINANCE_ALPHA16UI_EXT
:
763 case GL_ALPHA8UI_EXT
:
764 case GL_INTENSITY8UI_EXT
:
765 case GL_LUMINANCE8UI_EXT
:
766 case GL_LUMINANCE_ALPHA8UI_EXT
:
776 * Test if the given format is an integer (non-normalized) format.
779 _mesa_is_enum_format_signed_int(GLenum format
)
782 /* generic integer formats */
783 case GL_RED_INTEGER_EXT
:
784 case GL_GREEN_INTEGER_EXT
:
785 case GL_BLUE_INTEGER_EXT
:
786 case GL_ALPHA_INTEGER_EXT
:
787 case GL_RGB_INTEGER_EXT
:
788 case GL_RGBA_INTEGER_EXT
:
789 case GL_BGR_INTEGER_EXT
:
790 case GL_BGRA_INTEGER_EXT
:
791 case GL_LUMINANCE_INTEGER_EXT
:
792 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
794 /* specific integer formats */
799 case GL_ALPHA32I_EXT
:
800 case GL_INTENSITY32I_EXT
:
801 case GL_LUMINANCE32I_EXT
:
802 case GL_LUMINANCE_ALPHA32I_EXT
:
807 case GL_ALPHA16I_EXT
:
808 case GL_INTENSITY16I_EXT
:
809 case GL_LUMINANCE16I_EXT
:
810 case GL_LUMINANCE_ALPHA16I_EXT
:
816 case GL_INTENSITY8I_EXT
:
817 case GL_LUMINANCE8I_EXT
:
818 case GL_LUMINANCE_ALPHA8I_EXT
:
826 * Test if the given format is an ASTC format.
829 _mesa_is_astc_format(GLenum internalFormat
)
831 switch (internalFormat
) {
832 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
833 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
834 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
835 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
836 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
837 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
838 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
839 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
840 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
841 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
842 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
843 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
844 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
845 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
846 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
847 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
848 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
849 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
850 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
851 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
852 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
853 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
854 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
855 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
856 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
857 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
858 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
859 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
868 * Test if the given format is an integer (non-normalized) format.
871 _mesa_is_enum_format_integer(GLenum format
)
873 return _mesa_is_enum_format_unsigned_int(format
) ||
874 _mesa_is_enum_format_signed_int(format
);
879 _mesa_is_type_unsigned(GLenum type
)
882 case GL_UNSIGNED_INT
:
883 case GL_UNSIGNED_INT_8_8_8_8
:
884 case GL_UNSIGNED_INT_8_8_8_8_REV
:
885 case GL_UNSIGNED_INT_10_10_10_2
:
886 case GL_UNSIGNED_INT_2_10_10_10_REV
:
888 case GL_UNSIGNED_SHORT
:
889 case GL_UNSIGNED_SHORT_4_4_4_4
:
890 case GL_UNSIGNED_SHORT_5_5_5_1
:
891 case GL_UNSIGNED_SHORT_5_6_5
:
892 case GL_UNSIGNED_SHORT_5_6_5_REV
:
893 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
894 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
895 case GL_UNSIGNED_SHORT_8_8_MESA
:
896 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
898 case GL_UNSIGNED_BYTE
:
899 case GL_UNSIGNED_BYTE_3_3_2
:
900 case GL_UNSIGNED_BYTE_2_3_3_REV
:
910 * Test if the given image format is a color/RGBA format (i.e., not color
911 * index, depth, stencil, etc).
912 * \param format the image format value (may by an internal texture format)
913 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
916 _mesa_is_color_format(GLenum format
)
934 case GL_LUMINANCE_ALPHA
:
935 case GL_LUMINANCE4_ALPHA4
:
936 case GL_LUMINANCE6_ALPHA2
:
937 case GL_LUMINANCE8_ALPHA8
:
938 case GL_LUMINANCE12_ALPHA4
:
939 case GL_LUMINANCE12_ALPHA12
:
940 case GL_LUMINANCE16_ALPHA16
:
973 /* float texture formats */
974 case GL_ALPHA16F_ARB
:
975 case GL_ALPHA32F_ARB
:
976 case GL_LUMINANCE16F_ARB
:
977 case GL_LUMINANCE32F_ARB
:
978 case GL_LUMINANCE_ALPHA16F_ARB
:
979 case GL_LUMINANCE_ALPHA32F_ARB
:
980 case GL_INTENSITY16F_ARB
:
981 case GL_INTENSITY32F_ARB
:
990 /* compressed formats */
991 case GL_COMPRESSED_ALPHA
:
992 case GL_COMPRESSED_LUMINANCE
:
993 case GL_COMPRESSED_LUMINANCE_ALPHA
:
994 case GL_COMPRESSED_INTENSITY
:
995 case GL_COMPRESSED_RED
:
996 case GL_COMPRESSED_RG
:
997 case GL_COMPRESSED_RGB
:
998 case GL_COMPRESSED_RGBA
:
1003 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1004 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1005 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1006 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1007 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1008 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1011 case GL_SRGB_ALPHA_EXT
:
1012 case GL_SRGB8_ALPHA8_EXT
:
1013 case GL_SLUMINANCE_ALPHA_EXT
:
1014 case GL_SLUMINANCE8_ALPHA8_EXT
:
1015 case GL_SLUMINANCE_EXT
:
1016 case GL_SLUMINANCE8_EXT
:
1017 case GL_COMPRESSED_SRGB_EXT
:
1018 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1019 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
1020 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1021 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1022 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1023 case GL_COMPRESSED_SLUMINANCE_EXT
:
1024 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
1025 case GL_COMPRESSED_RED_RGTC1
:
1026 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1027 case GL_COMPRESSED_RG_RGTC2
:
1028 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1029 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1030 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1031 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1032 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1033 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1034 case GL_ETC1_RGB8_OES
:
1035 case GL_COMPRESSED_RGB8_ETC2
:
1036 case GL_COMPRESSED_SRGB8_ETC2
:
1037 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1038 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1039 case GL_COMPRESSED_R11_EAC
:
1040 case GL_COMPRESSED_RG11_EAC
:
1041 case GL_COMPRESSED_SIGNED_R11_EAC
:
1042 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1043 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1044 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1045 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1046 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1047 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1048 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1049 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
1050 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
1051 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
1052 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
1053 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
1054 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
1055 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
1056 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
1057 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
1058 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
1059 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
1060 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
1061 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
1062 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
1063 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1064 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1065 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1066 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1067 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1068 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1069 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1070 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1071 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1072 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1073 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1074 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1075 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1076 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1077 /* generic integer formats */
1078 case GL_RED_INTEGER_EXT
:
1079 case GL_GREEN_INTEGER_EXT
:
1080 case GL_BLUE_INTEGER_EXT
:
1081 case GL_ALPHA_INTEGER_EXT
:
1082 case GL_RGB_INTEGER_EXT
:
1083 case GL_RGBA_INTEGER_EXT
:
1084 case GL_BGR_INTEGER_EXT
:
1085 case GL_BGRA_INTEGER_EXT
:
1087 case GL_LUMINANCE_INTEGER_EXT
:
1088 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1089 /* sized integer formats */
1090 case GL_RGBA32UI_EXT
:
1091 case GL_RGB32UI_EXT
:
1094 case GL_ALPHA32UI_EXT
:
1095 case GL_INTENSITY32UI_EXT
:
1096 case GL_LUMINANCE32UI_EXT
:
1097 case GL_LUMINANCE_ALPHA32UI_EXT
:
1098 case GL_RGBA16UI_EXT
:
1099 case GL_RGB16UI_EXT
:
1102 case GL_ALPHA16UI_EXT
:
1103 case GL_INTENSITY16UI_EXT
:
1104 case GL_LUMINANCE16UI_EXT
:
1105 case GL_LUMINANCE_ALPHA16UI_EXT
:
1106 case GL_RGBA8UI_EXT
:
1110 case GL_ALPHA8UI_EXT
:
1111 case GL_INTENSITY8UI_EXT
:
1112 case GL_LUMINANCE8UI_EXT
:
1113 case GL_LUMINANCE_ALPHA8UI_EXT
:
1114 case GL_RGBA32I_EXT
:
1118 case GL_ALPHA32I_EXT
:
1119 case GL_INTENSITY32I_EXT
:
1120 case GL_LUMINANCE32I_EXT
:
1121 case GL_LUMINANCE_ALPHA32I_EXT
:
1122 case GL_RGBA16I_EXT
:
1126 case GL_ALPHA16I_EXT
:
1127 case GL_INTENSITY16I_EXT
:
1128 case GL_LUMINANCE16I_EXT
:
1129 case GL_LUMINANCE_ALPHA16I_EXT
:
1134 case GL_ALPHA8I_EXT
:
1135 case GL_INTENSITY8I_EXT
:
1136 case GL_LUMINANCE8I_EXT
:
1137 case GL_LUMINANCE_ALPHA8I_EXT
:
1138 /* signed, normalized texture formats */
1147 case GL_RGB16_SNORM
:
1149 case GL_RGBA8_SNORM
:
1150 case GL_RGBA16_SNORM
:
1151 case GL_ALPHA_SNORM
:
1152 case GL_ALPHA8_SNORM
:
1153 case GL_ALPHA16_SNORM
:
1154 case GL_LUMINANCE_SNORM
:
1155 case GL_LUMINANCE8_SNORM
:
1156 case GL_LUMINANCE16_SNORM
:
1157 case GL_LUMINANCE_ALPHA_SNORM
:
1158 case GL_LUMINANCE8_ALPHA8_SNORM
:
1159 case GL_LUMINANCE16_ALPHA16_SNORM
:
1160 case GL_INTENSITY_SNORM
:
1161 case GL_INTENSITY8_SNORM
:
1162 case GL_INTENSITY16_SNORM
:
1164 case GL_R11F_G11F_B10F
:
1167 case GL_YCBCR_MESA
: /* not considered to be RGB */
1176 * Test if the given image format is a depth component format.
1179 _mesa_is_depth_format(GLenum format
)
1182 case GL_DEPTH_COMPONENT
:
1183 case GL_DEPTH_COMPONENT16
:
1184 case GL_DEPTH_COMPONENT24
:
1185 case GL_DEPTH_COMPONENT32
:
1186 case GL_DEPTH_COMPONENT32F
:
1195 * Test if the given image format is a stencil format.
1198 _mesa_is_stencil_format(GLenum format
)
1201 case GL_STENCIL_INDEX
:
1210 * Test if the given image format is a YCbCr format.
1213 _mesa_is_ycbcr_format(GLenum format
)
1225 * Test if the given image format is a depth+stencil format.
1228 _mesa_is_depthstencil_format(GLenum format
)
1231 case GL_DEPTH24_STENCIL8_EXT
:
1232 case GL_DEPTH_STENCIL_EXT
:
1233 case GL_DEPTH32F_STENCIL8
:
1242 * Test if the given image format is a depth or stencil format.
1245 _mesa_is_depth_or_stencil_format(GLenum format
)
1248 case GL_DEPTH_COMPONENT
:
1249 case GL_DEPTH_COMPONENT16
:
1250 case GL_DEPTH_COMPONENT24
:
1251 case GL_DEPTH_COMPONENT32
:
1252 case GL_STENCIL_INDEX
:
1253 case GL_STENCIL_INDEX1_EXT
:
1254 case GL_STENCIL_INDEX4_EXT
:
1255 case GL_STENCIL_INDEX8_EXT
:
1256 case GL_STENCIL_INDEX16_EXT
:
1257 case GL_DEPTH_STENCIL_EXT
:
1258 case GL_DEPTH24_STENCIL8_EXT
:
1259 case GL_DEPTH_COMPONENT32F
:
1260 case GL_DEPTH32F_STENCIL8
:
1269 * Test if an image format is a supported compressed format.
1270 * \param format the internal format token provided by the user.
1271 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1274 _mesa_is_compressed_format(const struct gl_context
*ctx
, GLenum format
)
1276 mesa_format m_format
= _mesa_glenum_to_compressed_format(format
);
1278 /* Some formats in this switch have an equivalent mesa_format_layout
1279 * to the compressed formats in the layout switch below and thus
1280 * must be handled first.
1287 return _mesa_is_desktop_gl(ctx
) &&
1288 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1289 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1290 return ctx
->API
== API_OPENGL_COMPAT
1291 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1292 case GL_PALETTE4_RGB8_OES
:
1293 case GL_PALETTE4_RGBA8_OES
:
1294 case GL_PALETTE4_R5_G6_B5_OES
:
1295 case GL_PALETTE4_RGBA4_OES
:
1296 case GL_PALETTE4_RGB5_A1_OES
:
1297 case GL_PALETTE8_RGB8_OES
:
1298 case GL_PALETTE8_RGBA8_OES
:
1299 case GL_PALETTE8_R5_G6_B5_OES
:
1300 case GL_PALETTE8_RGBA4_OES
:
1301 case GL_PALETTE8_RGB5_A1_OES
:
1302 return ctx
->API
== API_OPENGLES
;
1305 switch (_mesa_get_format_layout(m_format
)) {
1306 case MESA_FORMAT_LAYOUT_S3TC
:
1307 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1308 /* Assume that the ANGLE flag will always be set if the
1311 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1313 return _mesa_is_desktop_gl(ctx
)
1314 && ctx
->Extensions
.EXT_texture_sRGB
1315 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1317 case MESA_FORMAT_LAYOUT_FXT1
:
1318 return _mesa_is_desktop_gl(ctx
)
1319 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1320 case MESA_FORMAT_LAYOUT_RGTC
:
1321 return _mesa_is_desktop_gl(ctx
)
1322 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1323 case MESA_FORMAT_LAYOUT_LATC
:
1324 return ctx
->API
== API_OPENGL_COMPAT
1325 && ctx
->Extensions
.EXT_texture_compression_latc
;
1326 case MESA_FORMAT_LAYOUT_ETC1
:
1327 return _mesa_is_gles(ctx
)
1328 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1329 case MESA_FORMAT_LAYOUT_ETC2
:
1330 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1331 case MESA_FORMAT_LAYOUT_BPTC
:
1332 return _mesa_is_desktop_gl(ctx
) &&
1333 ctx
->Extensions
.ARB_texture_compression_bptc
;
1334 case MESA_FORMAT_LAYOUT_ASTC
:
1335 return ctx
->Extensions
.KHR_texture_compression_astc_ldr
;
1342 * Convert various unpack formats to the corresponding base format.
1345 _mesa_unpack_format_to_base_format(GLenum format
)
1348 case GL_RED_INTEGER
:
1350 case GL_GREEN_INTEGER
:
1352 case GL_BLUE_INTEGER
:
1354 case GL_ALPHA_INTEGER
:
1358 case GL_RGB_INTEGER
:
1360 case GL_RGBA_INTEGER
:
1362 case GL_BGR_INTEGER
:
1364 case GL_BGRA_INTEGER
:
1366 case GL_LUMINANCE_INTEGER_EXT
:
1367 return GL_LUMINANCE
;
1368 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1369 return GL_LUMINANCE_ALPHA
;
1380 case GL_LUMINANCE_ALPHA
:
1387 * Convert various base formats to the corresponding integer format.
1390 _mesa_base_format_to_integer_format(GLenum format
)
1394 return GL_RED_INTEGER
;
1396 return GL_GREEN_INTEGER
;
1398 return GL_BLUE_INTEGER
;
1400 return GL_RG_INTEGER
;
1402 return GL_RGB_INTEGER
;
1404 return GL_RGBA_INTEGER
;
1406 return GL_BGR_INTEGER
;
1408 return GL_BGRA_INTEGER
;
1410 return GL_ALPHA_INTEGER
;
1412 return GL_LUMINANCE_INTEGER_EXT
;
1413 case GL_LUMINANCE_ALPHA
:
1414 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1422 * Does the given base texture/renderbuffer format have the channel
1426 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1429 case GL_TEXTURE_RED_SIZE
:
1430 case GL_TEXTURE_RED_TYPE
:
1431 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1432 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1433 case GL_INTERNALFORMAT_RED_SIZE
:
1434 case GL_INTERNALFORMAT_RED_TYPE
:
1435 if (base_format
== GL_RED
||
1436 base_format
== GL_RG
||
1437 base_format
== GL_RGB
||
1438 base_format
== GL_RGBA
) {
1442 case GL_TEXTURE_GREEN_SIZE
:
1443 case GL_TEXTURE_GREEN_TYPE
:
1444 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1445 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1446 case GL_INTERNALFORMAT_GREEN_SIZE
:
1447 case GL_INTERNALFORMAT_GREEN_TYPE
:
1448 if (base_format
== GL_RG
||
1449 base_format
== GL_RGB
||
1450 base_format
== GL_RGBA
) {
1454 case GL_TEXTURE_BLUE_SIZE
:
1455 case GL_TEXTURE_BLUE_TYPE
:
1456 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1457 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1458 case GL_INTERNALFORMAT_BLUE_SIZE
:
1459 case GL_INTERNALFORMAT_BLUE_TYPE
:
1460 if (base_format
== GL_RGB
||
1461 base_format
== GL_RGBA
) {
1465 case GL_TEXTURE_ALPHA_SIZE
:
1466 case GL_TEXTURE_ALPHA_TYPE
:
1467 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1468 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1469 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1470 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1471 if (base_format
== GL_RGBA
||
1472 base_format
== GL_ALPHA
||
1473 base_format
== GL_LUMINANCE_ALPHA
) {
1477 case GL_TEXTURE_LUMINANCE_SIZE
:
1478 case GL_TEXTURE_LUMINANCE_TYPE
:
1479 if (base_format
== GL_LUMINANCE
||
1480 base_format
== GL_LUMINANCE_ALPHA
) {
1484 case GL_TEXTURE_INTENSITY_SIZE
:
1485 case GL_TEXTURE_INTENSITY_TYPE
:
1486 if (base_format
== GL_INTENSITY
) {
1490 case GL_TEXTURE_DEPTH_SIZE
:
1491 case GL_TEXTURE_DEPTH_TYPE
:
1492 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1493 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1494 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1495 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1496 if (base_format
== GL_DEPTH_STENCIL
||
1497 base_format
== GL_DEPTH_COMPONENT
) {
1501 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1502 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1503 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1504 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1505 if (base_format
== GL_DEPTH_STENCIL
||
1506 base_format
== GL_STENCIL_INDEX
) {
1511 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1521 * Returns the number of channels/components for a base format.
1524 _mesa_base_format_component_count(GLenum base_format
)
1526 switch (base_format
) {
1530 case GL_DEPTH_COMPONENT
:
1533 case GL_LUMINANCE_ALPHA
:
1534 case GL_DEPTH_STENCIL
:
1547 * If format is a generic compressed format, return the corresponding
1548 * non-compressed format. For other formats, return the format as-is.
1551 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1554 case GL_COMPRESSED_RED
:
1556 case GL_COMPRESSED_RG
:
1558 case GL_COMPRESSED_RGB
:
1560 case GL_COMPRESSED_RGBA
:
1562 case GL_COMPRESSED_ALPHA
:
1564 case GL_COMPRESSED_LUMINANCE
:
1565 return GL_LUMINANCE
;
1566 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1567 return GL_LUMINANCE_ALPHA
;
1568 case GL_COMPRESSED_INTENSITY
:
1569 return GL_INTENSITY
;
1571 case GL_COMPRESSED_SRGB
:
1573 case GL_COMPRESSED_SRGB_ALPHA
:
1574 return GL_SRGB_ALPHA
;
1575 case GL_COMPRESSED_SLUMINANCE
:
1576 return GL_SLUMINANCE
;
1577 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1578 return GL_SLUMINANCE_ALPHA
;
1586 * Return the equivalent non-generic internal format.
1587 * This is useful for comparing whether two internal formats are equivalent.
1590 _mesa_get_nongeneric_internalformat(GLenum format
)
1593 /* GL 1.1 formats. */
1601 case GL_LUMINANCE_ALPHA
:
1602 return GL_LUMINANCE8_ALPHA8
;
1605 return GL_LUMINANCE8
;
1609 return GL_INTENSITY8
;
1611 /* GL_ARB_texture_rg */
1617 /* GL_EXT_texture_sRGB */
1621 return GL_SRGB8_ALPHA8
;
1623 return GL_SLUMINANCE8
;
1624 case GL_SLUMINANCE_ALPHA
:
1625 return GL_SLUMINANCE8_ALPHA8
;
1627 /* GL_EXT_texture_snorm */
1629 return GL_RGBA8_SNORM
;
1631 return GL_RGB8_SNORM
;
1633 return GL_RG8_SNORM
;
1636 case GL_LUMINANCE_ALPHA_SNORM
:
1637 return GL_LUMINANCE8_ALPHA8_SNORM
;
1638 case GL_LUMINANCE_SNORM
:
1639 return GL_LUMINANCE8_SNORM
;
1640 case GL_ALPHA_SNORM
:
1641 return GL_ALPHA8_SNORM
;
1642 case GL_INTENSITY_SNORM
:
1643 return GL_INTENSITY8_SNORM
;
1652 * Convert an sRGB internal format to linear.
1655 _mesa_get_linear_internalformat(GLenum format
)
1664 case GL_SRGB8_ALPHA8
:
1666 case GL_SLUMINANCE8
:
1667 return GL_LUMINANCE8
;
1669 return GL_LUMINANCE
;
1670 case GL_SLUMINANCE_ALPHA
:
1671 return GL_LUMINANCE_ALPHA
;
1672 case GL_SLUMINANCE8_ALPHA8
:
1673 return GL_LUMINANCE8_ALPHA8
;
1681 * Do error checking of format/type combinations for glReadPixels,
1682 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1683 * and type values, we may either generate GL_INVALID_OPERATION or
1686 * \param format pixel format.
1687 * \param type pixel type.
1689 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1692 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1693 GLenum format
, GLenum type
)
1695 /* From OpenGL 3.3 spec, page 220:
1696 * "If the format is DEPTH_STENCIL, then values are taken from
1697 * both the depth buffer and the stencil buffer. If there is no
1698 * depth buffer or if there is no stencil buffer, then the error
1699 * INVALID_OPERATION occurs. If the type parameter is not
1700 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1701 * error INVALID_ENUM occurs."
1703 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1704 * cannot be used to read depth or stencil in that API.
1706 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1707 && type
!= GL_UNSIGNED_INT_24_8
1708 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1709 return GL_INVALID_ENUM
;
1711 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1714 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1715 return GL_INVALID_ENUM
;
1719 case GL_UNSIGNED_BYTE_3_3_2
:
1720 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1721 case GL_UNSIGNED_SHORT_5_6_5
:
1722 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1723 if (format
== GL_RGB
) {
1726 if (format
== GL_RGB_INTEGER_EXT
&&
1727 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1730 return GL_INVALID_OPERATION
;
1732 case GL_UNSIGNED_SHORT_4_4_4_4
:
1733 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1734 case GL_UNSIGNED_INT_8_8_8_8
:
1735 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1736 if (format
== GL_RGBA
||
1737 format
== GL_BGRA
||
1738 format
== GL_ABGR_EXT
) {
1741 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1742 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1745 return GL_INVALID_OPERATION
;
1747 case GL_UNSIGNED_SHORT_5_5_5_1
:
1748 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1749 case GL_UNSIGNED_INT_10_10_10_2
:
1750 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1751 if (format
== GL_RGBA
||
1752 format
== GL_BGRA
) {
1755 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1756 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1759 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1760 ctx
->API
== API_OPENGLES2
) {
1761 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1763 return GL_INVALID_OPERATION
;
1765 case GL_UNSIGNED_INT_24_8
:
1766 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1767 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1770 if (format
!= GL_DEPTH_STENCIL
) {
1771 return GL_INVALID_OPERATION
;
1775 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1776 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1777 return GL_INVALID_ENUM
;
1779 if (format
!= GL_DEPTH_STENCIL
) {
1780 return GL_INVALID_OPERATION
;
1784 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1785 if (!ctx
->Extensions
.EXT_packed_float
) {
1786 return GL_INVALID_ENUM
;
1788 if (format
!= GL_RGB
) {
1789 return GL_INVALID_OPERATION
;
1793 case GL_HALF_FLOAT_OES
:
1797 case GL_LUMINANCE_ALPHA
:
1803 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1806 return GL_INVALID_OPERATION
;
1810 ; /* fall-through */
1813 /* now, for each format, check the type for compatibility */
1815 case GL_COLOR_INDEX
:
1816 case GL_STENCIL_INDEX
:
1820 case GL_UNSIGNED_BYTE
:
1822 case GL_UNSIGNED_SHORT
:
1824 case GL_UNSIGNED_INT
:
1829 return GL_INVALID_ENUM
;
1836 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1840 case GL_LUMINANCE_ALPHA
:
1841 case GL_DEPTH_COMPONENT
:
1844 case GL_UNSIGNED_BYTE
:
1846 case GL_UNSIGNED_SHORT
:
1848 case GL_UNSIGNED_INT
:
1853 return GL_INVALID_ENUM
;
1857 if (!ctx
->Extensions
.ARB_texture_rg
)
1858 return GL_INVALID_ENUM
;
1861 case GL_UNSIGNED_BYTE
:
1863 case GL_UNSIGNED_SHORT
:
1865 case GL_UNSIGNED_INT
:
1870 return GL_INVALID_ENUM
;
1876 case GL_UNSIGNED_BYTE
:
1878 case GL_UNSIGNED_SHORT
:
1880 case GL_UNSIGNED_INT
:
1882 case GL_UNSIGNED_BYTE_3_3_2
:
1883 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1884 case GL_UNSIGNED_SHORT_5_6_5
:
1885 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1888 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1889 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1890 return (ctx
->API
== API_OPENGLES2
)
1891 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1892 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1893 return ctx
->Extensions
.EXT_texture_shared_exponent
1894 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1895 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1896 return ctx
->Extensions
.EXT_packed_float
1897 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1899 return GL_INVALID_ENUM
;
1904 /* NOTE: no packed types are supported with BGR. That's
1905 * intentional, according to the GL spec.
1908 case GL_UNSIGNED_BYTE
:
1910 case GL_UNSIGNED_SHORT
:
1912 case GL_UNSIGNED_INT
:
1917 return GL_INVALID_ENUM
;
1924 case GL_UNSIGNED_BYTE
:
1926 case GL_UNSIGNED_SHORT
:
1928 case GL_UNSIGNED_INT
:
1930 case GL_UNSIGNED_SHORT_4_4_4_4
:
1931 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1932 case GL_UNSIGNED_SHORT_5_5_5_1
:
1933 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1934 case GL_UNSIGNED_INT_8_8_8_8
:
1935 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1936 case GL_UNSIGNED_INT_10_10_10_2
:
1937 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1941 return GL_INVALID_ENUM
;
1947 case GL_UNSIGNED_BYTE
:
1949 case GL_UNSIGNED_SHORT
:
1951 case GL_UNSIGNED_INT
:
1953 case GL_UNSIGNED_SHORT_4_4_4_4
:
1954 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1955 case GL_UNSIGNED_INT_8_8_8_8
:
1956 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1960 return GL_INVALID_ENUM
;
1964 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1965 return GL_INVALID_ENUM
;
1966 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1967 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1970 return GL_INVALID_OPERATION
;
1972 case GL_DEPTH_STENCIL
:
1973 if (type
== GL_UNSIGNED_INT_24_8
)
1975 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1976 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1979 return GL_INVALID_ENUM
;
1981 /* integer-valued formats */
1982 case GL_RED_INTEGER_EXT
:
1983 case GL_GREEN_INTEGER_EXT
:
1984 case GL_BLUE_INTEGER_EXT
:
1985 case GL_ALPHA_INTEGER_EXT
:
1989 case GL_UNSIGNED_BYTE
:
1991 case GL_UNSIGNED_SHORT
:
1993 case GL_UNSIGNED_INT
:
1994 return (ctx
->Version
>= 30 ||
1995 ctx
->Extensions
.EXT_texture_integer
)
1996 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1998 return GL_INVALID_ENUM
;
2001 case GL_RGB_INTEGER_EXT
:
2004 case GL_UNSIGNED_BYTE
:
2006 case GL_UNSIGNED_SHORT
:
2008 case GL_UNSIGNED_INT
:
2009 return (ctx
->Version
>= 30 ||
2010 ctx
->Extensions
.EXT_texture_integer
)
2011 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2012 case GL_UNSIGNED_BYTE_3_3_2
:
2013 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2014 case GL_UNSIGNED_SHORT_5_6_5
:
2015 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2016 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2017 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2019 return GL_INVALID_ENUM
;
2022 case GL_BGR_INTEGER_EXT
:
2025 case GL_UNSIGNED_BYTE
:
2027 case GL_UNSIGNED_SHORT
:
2029 case GL_UNSIGNED_INT
:
2030 /* NOTE: no packed formats w/ BGR format */
2031 return (ctx
->Version
>= 30 ||
2032 ctx
->Extensions
.EXT_texture_integer
)
2033 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2035 return GL_INVALID_ENUM
;
2038 case GL_RGBA_INTEGER_EXT
:
2039 case GL_BGRA_INTEGER_EXT
:
2042 case GL_UNSIGNED_BYTE
:
2044 case GL_UNSIGNED_SHORT
:
2046 case GL_UNSIGNED_INT
:
2047 return (ctx
->Version
>= 30 ||
2048 ctx
->Extensions
.EXT_texture_integer
)
2049 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2050 case GL_UNSIGNED_SHORT_4_4_4_4
:
2051 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2052 case GL_UNSIGNED_SHORT_5_5_5_1
:
2053 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2054 case GL_UNSIGNED_INT_8_8_8_8
:
2055 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2056 case GL_UNSIGNED_INT_10_10_10_2
:
2057 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2058 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2059 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2061 return GL_INVALID_ENUM
;
2064 case GL_LUMINANCE_INTEGER_EXT
:
2065 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2068 case GL_UNSIGNED_BYTE
:
2070 case GL_UNSIGNED_SHORT
:
2072 case GL_UNSIGNED_INT
:
2073 return ctx
->Extensions
.EXT_texture_integer
2074 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2076 return GL_INVALID_ENUM
;
2080 return GL_INVALID_ENUM
;
2087 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2088 * and glTex[Sub]Image.
2089 * \return error code, or GL_NO_ERROR.
2092 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2093 GLenum format
, GLenum type
,
2094 unsigned dimensions
)
2096 GLboolean type_valid
= GL_TRUE
;
2101 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2102 return GL_INVALID_VALUE
;
2106 case GL_LUMINANCE_ALPHA
:
2107 type_valid
= (type
== GL_UNSIGNED_BYTE
2109 || type
== GL_HALF_FLOAT_OES
);
2113 type_valid
= (type
== GL_UNSIGNED_BYTE
2114 || type
== GL_UNSIGNED_SHORT_5_6_5
2116 || type
== GL_HALF_FLOAT_OES
);
2120 type_valid
= (type
== GL_UNSIGNED_BYTE
2121 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2122 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2124 || type
== GL_HALF_FLOAT_OES
2125 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2128 case GL_DEPTH_COMPONENT
:
2129 /* This format is filtered against invalid dimensionalities elsewhere.
2131 type_valid
= (type
== GL_UNSIGNED_SHORT
2132 || type
== GL_UNSIGNED_INT
);
2135 case GL_DEPTH_STENCIL
:
2136 /* This format is filtered against invalid dimensionalities elsewhere.
2138 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2142 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2144 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2145 * the format does not appear to be allowed for 3D textures in OpenGL
2148 if (dimensions
!= 2)
2149 return GL_INVALID_VALUE
;
2154 return GL_INVALID_VALUE
;
2157 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2161 * Return the simple base format for a given internal texture format.
2162 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2164 * \param ctx GL context.
2165 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2167 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2168 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2170 * This is the format which is used during texture application (i.e. the
2171 * texture format and env mode determine the arithmetic used.
2174 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2176 switch (internalFormat
) {
2182 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2187 case GL_LUMINANCE12
:
2188 case GL_LUMINANCE16
:
2189 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2191 case GL_LUMINANCE_ALPHA
:
2192 case GL_LUMINANCE4_ALPHA4
:
2193 case GL_LUMINANCE6_ALPHA2
:
2194 case GL_LUMINANCE8_ALPHA8
:
2195 case GL_LUMINANCE12_ALPHA4
:
2196 case GL_LUMINANCE12_ALPHA12
:
2197 case GL_LUMINANCE16_ALPHA16
:
2198 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2202 case GL_INTENSITY12
:
2203 case GL_INTENSITY16
:
2204 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2206 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2217 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2231 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2233 if (_mesa_is_gles(ctx
)) {
2234 switch (internalFormat
) {
2242 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2243 switch (internalFormat
) {
2251 if (ctx
->Extensions
.ARB_depth_texture
) {
2252 switch (internalFormat
) {
2253 case GL_DEPTH_COMPONENT
:
2254 case GL_DEPTH_COMPONENT16
:
2255 case GL_DEPTH_COMPONENT24
:
2256 case GL_DEPTH_COMPONENT32
:
2257 return GL_DEPTH_COMPONENT
;
2258 case GL_DEPTH_STENCIL
:
2259 case GL_DEPTH24_STENCIL8
:
2260 return GL_DEPTH_STENCIL
;
2266 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2267 switch (internalFormat
) {
2268 case GL_STENCIL_INDEX
:
2269 case GL_STENCIL_INDEX1
:
2270 case GL_STENCIL_INDEX4
:
2271 case GL_STENCIL_INDEX8
:
2272 case GL_STENCIL_INDEX16
:
2273 return GL_STENCIL_INDEX
;
2279 switch (internalFormat
) {
2280 case GL_COMPRESSED_ALPHA
:
2282 case GL_COMPRESSED_LUMINANCE
:
2283 return GL_LUMINANCE
;
2284 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2285 return GL_LUMINANCE_ALPHA
;
2286 case GL_COMPRESSED_INTENSITY
:
2287 return GL_INTENSITY
;
2288 case GL_COMPRESSED_RGB
:
2290 case GL_COMPRESSED_RGBA
:
2296 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2297 GLenum base_compressed
=
2298 _mesa_gl_compressed_format_base_format(internalFormat
);
2299 if (base_compressed
)
2300 return base_compressed
;
2303 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2304 _mesa_is_astc_format(internalFormat
))
2307 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2308 if (internalFormat
== GL_YCBCR_MESA
)
2309 return GL_YCBCR_MESA
;
2312 if (ctx
->Extensions
.ARB_texture_float
) {
2313 switch (internalFormat
) {
2314 case GL_ALPHA16F_ARB
:
2315 case GL_ALPHA32F_ARB
:
2317 case GL_RGBA16F_ARB
:
2318 case GL_RGBA32F_ARB
:
2323 case GL_INTENSITY16F_ARB
:
2324 case GL_INTENSITY32F_ARB
:
2325 return GL_INTENSITY
;
2326 case GL_LUMINANCE16F_ARB
:
2327 case GL_LUMINANCE32F_ARB
:
2328 return GL_LUMINANCE
;
2329 case GL_LUMINANCE_ALPHA16F_ARB
:
2330 case GL_LUMINANCE_ALPHA32F_ARB
:
2331 return GL_LUMINANCE_ALPHA
;
2337 if (ctx
->Extensions
.EXT_texture_snorm
) {
2338 switch (internalFormat
) {
2349 case GL_RGB16_SNORM
:
2352 case GL_RGBA8_SNORM
:
2353 case GL_RGBA16_SNORM
:
2355 case GL_ALPHA_SNORM
:
2356 case GL_ALPHA8_SNORM
:
2357 case GL_ALPHA16_SNORM
:
2359 case GL_LUMINANCE_SNORM
:
2360 case GL_LUMINANCE8_SNORM
:
2361 case GL_LUMINANCE16_SNORM
:
2362 return GL_LUMINANCE
;
2363 case GL_LUMINANCE_ALPHA_SNORM
:
2364 case GL_LUMINANCE8_ALPHA8_SNORM
:
2365 case GL_LUMINANCE16_ALPHA16_SNORM
:
2366 return GL_LUMINANCE_ALPHA
;
2367 case GL_INTENSITY_SNORM
:
2368 case GL_INTENSITY8_SNORM
:
2369 case GL_INTENSITY16_SNORM
:
2370 return GL_INTENSITY
;
2376 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2377 switch (internalFormat
) {
2380 case GL_COMPRESSED_SRGB_EXT
:
2382 case GL_SRGB_ALPHA_EXT
:
2383 case GL_SRGB8_ALPHA8_EXT
:
2384 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2386 case GL_SLUMINANCE_ALPHA_EXT
:
2387 case GL_SLUMINANCE8_ALPHA8_EXT
:
2388 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2389 return GL_LUMINANCE_ALPHA
;
2390 case GL_SLUMINANCE_EXT
:
2391 case GL_SLUMINANCE8_EXT
:
2392 case GL_COMPRESSED_SLUMINANCE_EXT
:
2393 return GL_LUMINANCE
;
2399 if (ctx
->Version
>= 30 ||
2400 ctx
->Extensions
.EXT_texture_integer
) {
2401 switch (internalFormat
) {
2402 case GL_RGBA8UI_EXT
:
2403 case GL_RGBA16UI_EXT
:
2404 case GL_RGBA32UI_EXT
:
2406 case GL_RGBA16I_EXT
:
2407 case GL_RGBA32I_EXT
:
2411 case GL_RGB16UI_EXT
:
2412 case GL_RGB32UI_EXT
:
2420 if (ctx
->Extensions
.EXT_texture_integer
) {
2421 switch (internalFormat
) {
2422 case GL_ALPHA8UI_EXT
:
2423 case GL_ALPHA16UI_EXT
:
2424 case GL_ALPHA32UI_EXT
:
2425 case GL_ALPHA8I_EXT
:
2426 case GL_ALPHA16I_EXT
:
2427 case GL_ALPHA32I_EXT
:
2429 case GL_INTENSITY8UI_EXT
:
2430 case GL_INTENSITY16UI_EXT
:
2431 case GL_INTENSITY32UI_EXT
:
2432 case GL_INTENSITY8I_EXT
:
2433 case GL_INTENSITY16I_EXT
:
2434 case GL_INTENSITY32I_EXT
:
2435 return GL_INTENSITY
;
2436 case GL_LUMINANCE8UI_EXT
:
2437 case GL_LUMINANCE16UI_EXT
:
2438 case GL_LUMINANCE32UI_EXT
:
2439 case GL_LUMINANCE8I_EXT
:
2440 case GL_LUMINANCE16I_EXT
:
2441 case GL_LUMINANCE32I_EXT
:
2442 return GL_LUMINANCE
;
2443 case GL_LUMINANCE_ALPHA8UI_EXT
:
2444 case GL_LUMINANCE_ALPHA16UI_EXT
:
2445 case GL_LUMINANCE_ALPHA32UI_EXT
:
2446 case GL_LUMINANCE_ALPHA8I_EXT
:
2447 case GL_LUMINANCE_ALPHA16I_EXT
:
2448 case GL_LUMINANCE_ALPHA32I_EXT
:
2449 return GL_LUMINANCE_ALPHA
;
2455 if (ctx
->Extensions
.ARB_texture_rg
) {
2456 switch (internalFormat
) {
2459 if (!ctx
->Extensions
.ARB_texture_float
)
2468 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2474 case GL_COMPRESSED_RED
:
2479 if (!ctx
->Extensions
.ARB_texture_float
)
2488 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2494 case GL_COMPRESSED_RG
:
2501 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2502 switch (internalFormat
) {
2503 case GL_RGB9_E5_EXT
:
2510 if (ctx
->Extensions
.EXT_packed_float
) {
2511 switch (internalFormat
) {
2512 case GL_R11F_G11F_B10F_EXT
:
2519 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2520 switch (internalFormat
) {
2521 case GL_DEPTH_COMPONENT32F
:
2522 return GL_DEPTH_COMPONENT
;
2523 case GL_DEPTH32F_STENCIL8
:
2524 return GL_DEPTH_STENCIL
;
2530 return -1; /* error */
2534 * Returns the effective internal format from a texture format and type.
2535 * This is used by texture image operations internally for validation, when
2536 * the specified internal format is a base (unsized) format.
2538 * This method will only return a valid effective internal format if the
2539 * combination of format, type and internal format in base form, is acceptable.
2541 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2542 * in extensions, to unambiguously correspond to the given base format, then
2543 * that internal format is returned as the effective. Otherwise, if the
2544 * combination is accepted but a single effective format is not defined, the
2545 * passed base format will be returned instead.
2547 * \param format the texture format
2548 * \param type the texture type
2551 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2555 case GL_UNSIGNED_BYTE
:
2561 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2562 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2563 * internal formats, they do not correspond to GL constants, so the base
2564 * format is returned instead.
2567 case GL_LUMINANCE_ALPHA
:
2574 case GL_UNSIGNED_SHORT_4_4_4_4
:
2575 if (format
== GL_RGBA
)
2579 case GL_UNSIGNED_SHORT_5_5_5_1
:
2580 if (format
== GL_RGBA
)
2584 case GL_UNSIGNED_SHORT_5_6_5
:
2585 if (format
== GL_RGB
)
2589 /* OES_packed_depth_stencil */
2590 case GL_UNSIGNED_INT_24_8
:
2591 if (format
== GL_DEPTH_STENCIL
)
2592 return GL_DEPTH24_STENCIL8
;
2595 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2596 if (format
== GL_DEPTH_STENCIL
)
2597 return GL_DEPTH32F_STENCIL8
;
2600 case GL_UNSIGNED_SHORT
:
2601 if (format
== GL_DEPTH_COMPONENT
)
2602 return GL_DEPTH_COMPONENT16
;
2605 case GL_UNSIGNED_INT
:
2606 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2609 if (format
== GL_DEPTH_COMPONENT
)
2613 /* OES_texture_float and OES_texture_half_float */
2615 if (format
== GL_DEPTH_COMPONENT
)
2616 return GL_DEPTH_COMPONENT32F
;
2618 case GL_HALF_FLOAT_OES
:
2622 case GL_LUMINANCE_ALPHA
:
2638 /* GL_EXT_texture_type_2_10_10_10_REV */
2639 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2648 /* fall through and return NONE */
2656 * Do error checking of format/type combinations for OpenGL ES 3
2658 * \return error code, or GL_NO_ERROR.
2661 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2662 GLenum format
, GLenum type
,
2663 GLenum internalFormat
)
2665 /* If internalFormat is an unsized format, then the effective internal
2666 * format derived from format and type should be used instead. Page 127,
2667 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2669 * "if internalformat is a base internal format, the effective
2670 * internal format is a sized internal format that is derived
2671 * from the format and type for internal use by the GL.
2672 * Table 3.12 specifies the mapping of format and type to effective
2673 * internal formats. The effective internal format is used by the GL
2674 * for purposes such as texture completeness or type checks for
2675 * CopyTex* commands. In these cases, the GL is required to operate
2676 * as if the effective internal format was used as the internalformat
2677 * when specifying the texture data."
2679 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2680 GLenum effectiveInternalFormat
=
2681 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2683 if (effectiveInternalFormat
== GL_NONE
)
2684 return GL_INVALID_OPERATION
;
2686 GLenum baseInternalFormat
;
2687 if (internalFormat
== GL_BGRA_EXT
) {
2688 /* Unfortunately, _mesa_base_tex_format returns a base format of
2689 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2690 * asking the question, "what channels does this format have?"
2691 * However, if we're trying to determine if two internal formats
2692 * match in the ES3 sense, we actually want GL_BGRA.
2694 baseInternalFormat
= GL_BGRA_EXT
;
2696 baseInternalFormat
=
2697 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2700 if (internalFormat
!= baseInternalFormat
)
2701 return GL_INVALID_OPERATION
;
2703 internalFormat
= effectiveInternalFormat
;
2708 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2709 return GL_INVALID_OPERATION
;
2714 case GL_UNSIGNED_BYTE
:
2715 switch (internalFormat
) {
2720 case GL_SRGB8_ALPHA8_EXT
:
2723 return GL_INVALID_OPERATION
;
2728 if (internalFormat
!= GL_RGBA8_SNORM
)
2729 return GL_INVALID_OPERATION
;
2732 case GL_UNSIGNED_SHORT_4_4_4_4
:
2733 switch (internalFormat
) {
2738 return GL_INVALID_OPERATION
;
2742 case GL_UNSIGNED_SHORT_5_5_5_1
:
2743 switch (internalFormat
) {
2748 return GL_INVALID_OPERATION
;
2752 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2753 switch (internalFormat
) {
2754 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2759 return GL_INVALID_OPERATION
;
2764 if (internalFormat
!= GL_RGBA16F
)
2765 return GL_INVALID_OPERATION
;
2769 switch (internalFormat
) {
2774 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2777 return GL_INVALID_OPERATION
;
2781 case GL_HALF_FLOAT_OES
:
2782 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2785 return GL_INVALID_OPERATION
;
2789 case GL_RGBA_INTEGER
:
2791 case GL_UNSIGNED_BYTE
:
2792 if (internalFormat
!= GL_RGBA8UI
)
2793 return GL_INVALID_OPERATION
;
2797 if (internalFormat
!= GL_RGBA8I
)
2798 return GL_INVALID_OPERATION
;
2801 case GL_UNSIGNED_SHORT
:
2802 if (internalFormat
!= GL_RGBA16UI
)
2803 return GL_INVALID_OPERATION
;
2807 if (internalFormat
!= GL_RGBA16I
)
2808 return GL_INVALID_OPERATION
;
2811 case GL_UNSIGNED_INT
:
2812 if (internalFormat
!= GL_RGBA32UI
)
2813 return GL_INVALID_OPERATION
;
2817 if (internalFormat
!= GL_RGBA32I
)
2818 return GL_INVALID_OPERATION
;
2821 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2822 if (internalFormat
!= GL_RGB10_A2UI
)
2823 return GL_INVALID_OPERATION
;
2827 return GL_INVALID_OPERATION
;
2833 case GL_UNSIGNED_BYTE
:
2834 switch (internalFormat
) {
2841 return GL_INVALID_OPERATION
;
2846 if (internalFormat
!= GL_RGB8_SNORM
)
2847 return GL_INVALID_OPERATION
;
2850 case GL_UNSIGNED_SHORT_5_6_5
:
2851 switch (internalFormat
) {
2856 return GL_INVALID_OPERATION
;
2860 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2861 if (internalFormat
!= GL_R11F_G11F_B10F
)
2862 return GL_INVALID_OPERATION
;
2865 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2866 if (internalFormat
!= GL_RGB9_E5
)
2867 return GL_INVALID_OPERATION
;
2871 switch (internalFormat
) {
2873 case GL_R11F_G11F_B10F
:
2877 return GL_INVALID_OPERATION
;
2882 switch (internalFormat
) {
2885 case GL_R11F_G11F_B10F
:
2889 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2892 return GL_INVALID_OPERATION
;
2896 case GL_HALF_FLOAT_OES
:
2897 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2898 return GL_INVALID_OPERATION
;
2901 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2902 switch (internalFormat
) {
2903 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2906 return GL_INVALID_OPERATION
;
2911 return GL_INVALID_OPERATION
;
2915 case GL_RGB_INTEGER
:
2917 case GL_UNSIGNED_BYTE
:
2918 if (internalFormat
!= GL_RGB8UI
)
2919 return GL_INVALID_OPERATION
;
2923 if (internalFormat
!= GL_RGB8I
)
2924 return GL_INVALID_OPERATION
;
2927 case GL_UNSIGNED_SHORT
:
2928 if (internalFormat
!= GL_RGB16UI
)
2929 return GL_INVALID_OPERATION
;
2933 if (internalFormat
!= GL_RGB16I
)
2934 return GL_INVALID_OPERATION
;
2937 case GL_UNSIGNED_INT
:
2938 if (internalFormat
!= GL_RGB32UI
)
2939 return GL_INVALID_OPERATION
;
2943 if (internalFormat
!= GL_RGB32I
)
2944 return GL_INVALID_OPERATION
;
2948 return GL_INVALID_OPERATION
;
2954 case GL_UNSIGNED_BYTE
:
2955 if (internalFormat
!= GL_RG8
)
2956 return GL_INVALID_OPERATION
;
2960 if (internalFormat
!= GL_RG8_SNORM
)
2961 return GL_INVALID_OPERATION
;
2965 case GL_HALF_FLOAT_OES
:
2966 switch (internalFormat
) {
2970 if (ctx
->Extensions
.ARB_texture_rg
&&
2971 ctx
->Extensions
.OES_texture_half_float
)
2975 return GL_INVALID_OPERATION
;
2980 switch (internalFormat
) {
2985 if (ctx
->Extensions
.ARB_texture_rg
&&
2986 ctx
->Extensions
.OES_texture_float
)
2990 return GL_INVALID_OPERATION
;
2995 return GL_INVALID_OPERATION
;
3001 case GL_UNSIGNED_BYTE
:
3002 if (internalFormat
!= GL_RG8UI
)
3003 return GL_INVALID_OPERATION
;
3007 if (internalFormat
!= GL_RG8I
)
3008 return GL_INVALID_OPERATION
;
3011 case GL_UNSIGNED_SHORT
:
3012 if (internalFormat
!= GL_RG16UI
)
3013 return GL_INVALID_OPERATION
;
3017 if (internalFormat
!= GL_RG16I
)
3018 return GL_INVALID_OPERATION
;
3021 case GL_UNSIGNED_INT
:
3022 if (internalFormat
!= GL_RG32UI
)
3023 return GL_INVALID_OPERATION
;
3027 if (internalFormat
!= GL_RG32I
)
3028 return GL_INVALID_OPERATION
;
3032 return GL_INVALID_OPERATION
;
3038 case GL_UNSIGNED_BYTE
:
3039 if (internalFormat
!= GL_R8
)
3040 return GL_INVALID_OPERATION
;
3044 if (internalFormat
!= GL_R8_SNORM
)
3045 return GL_INVALID_OPERATION
;
3049 case GL_HALF_FLOAT_OES
:
3050 switch (internalFormat
) {
3055 if (ctx
->Extensions
.ARB_texture_rg
&&
3056 ctx
->Extensions
.OES_texture_half_float
)
3060 return GL_INVALID_OPERATION
;
3065 switch (internalFormat
) {
3070 if (ctx
->Extensions
.ARB_texture_rg
&&
3071 ctx
->Extensions
.OES_texture_float
)
3075 return GL_INVALID_OPERATION
;
3080 return GL_INVALID_OPERATION
;
3084 case GL_RED_INTEGER
:
3086 case GL_UNSIGNED_BYTE
:
3087 if (internalFormat
!= GL_R8UI
)
3088 return GL_INVALID_OPERATION
;
3092 if (internalFormat
!= GL_R8I
)
3093 return GL_INVALID_OPERATION
;
3096 case GL_UNSIGNED_SHORT
:
3097 if (internalFormat
!= GL_R16UI
)
3098 return GL_INVALID_OPERATION
;
3102 if (internalFormat
!= GL_R16I
)
3103 return GL_INVALID_OPERATION
;
3106 case GL_UNSIGNED_INT
:
3107 if (internalFormat
!= GL_R32UI
)
3108 return GL_INVALID_OPERATION
;
3112 if (internalFormat
!= GL_R32I
)
3113 return GL_INVALID_OPERATION
;
3117 return GL_INVALID_OPERATION
;
3121 case GL_DEPTH_COMPONENT
:
3123 case GL_UNSIGNED_SHORT
:
3124 if (internalFormat
!= GL_DEPTH_COMPONENT
3125 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3126 return GL_INVALID_OPERATION
;
3129 case GL_UNSIGNED_INT
:
3130 switch (internalFormat
) {
3131 case GL_DEPTH_COMPONENT
:
3132 case GL_DEPTH_COMPONENT16
:
3133 case GL_DEPTH_COMPONENT24
:
3136 return GL_INVALID_OPERATION
;
3141 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3142 return GL_INVALID_OPERATION
;
3146 return GL_INVALID_OPERATION
;
3150 case GL_DEPTH_STENCIL
:
3152 case GL_UNSIGNED_INT_24_8
:
3153 if (internalFormat
!= GL_DEPTH_STENCIL
3154 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3155 return GL_INVALID_OPERATION
;
3158 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3159 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3160 return GL_INVALID_OPERATION
;
3164 return GL_INVALID_OPERATION
;
3168 case GL_STENCIL_INDEX
:
3169 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3170 type
!= GL_UNSIGNED_BYTE
||
3171 internalFormat
!= GL_STENCIL_INDEX8
) {
3172 return GL_INVALID_OPERATION
;
3178 case GL_LUMINANCE_ALPHA
:
3181 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3183 case GL_HALF_FLOAT_OES
:
3184 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3187 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3188 return GL_INVALID_OPERATION
;
3196 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3198 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3199 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3200 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3201 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3205 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3209 case GL_RGBA_INTEGER_EXT
:
3210 set_swizzle(swizzle
, 0, 1, 2, 3);
3213 case GL_BGRA_INTEGER_EXT
:
3214 set_swizzle(swizzle
, 2, 1, 0, 3);
3217 set_swizzle(swizzle
, 3, 2, 1, 0);
3220 case GL_RGB_INTEGER_EXT
:
3221 set_swizzle(swizzle
, 0, 1, 2, 5);
3224 case GL_BGR_INTEGER_EXT
:
3225 set_swizzle(swizzle
, 2, 1, 0, 5);
3227 case GL_LUMINANCE_ALPHA
:
3228 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3229 set_swizzle(swizzle
, 0, 0, 0, 1);
3233 set_swizzle(swizzle
, 0, 1, 4, 5);
3236 case GL_RED_INTEGER_EXT
:
3237 set_swizzle(swizzle
, 0, 4, 4, 5);
3240 case GL_GREEN_INTEGER_EXT
:
3241 set_swizzle(swizzle
, 4, 0, 4, 5);
3244 case GL_BLUE_INTEGER_EXT
:
3245 set_swizzle(swizzle
, 4, 4, 0, 5);
3248 case GL_ALPHA_INTEGER_EXT
:
3249 set_swizzle(swizzle
, 4, 4, 4, 0);
3252 case GL_LUMINANCE_INTEGER_EXT
:
3253 set_swizzle(swizzle
, 0, 0, 0, 5);
3256 set_swizzle(swizzle
, 0, 0, 0, 0);
3264 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3265 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3266 * otherwise (for non-array formats).
3268 * This function will typically be used to compute a mesa format from a GL type
3269 * so we can then call _mesa_format_convert. This function does
3270 * not consider byte swapping, so it returns types assuming that no byte
3271 * swapping is involved. If byte swapping is involved then clients are supposed
3272 * to handle that on their side before calling _mesa_format_convert.
3274 * This function returns an uint32_t that can pack a mesa_format or a
3275 * mesa_array_format. Clients must check the mesa array format bit
3276 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3277 * format is a mesa_array_format or a mesa_format.
3280 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3282 bool is_array_format
= true;
3284 bool normalized
= false, is_float
= false, is_signed
= false;
3285 int num_channels
= 0, type_size
= 0;
3287 /* Extract array format type information from the OpenGL data type */
3289 case GL_UNSIGNED_BYTE
:
3296 case GL_UNSIGNED_SHORT
:
3303 case GL_UNSIGNED_INT
:
3311 case GL_HALF_FLOAT_OES
:
3322 is_array_format
= false;
3326 /* Extract array format swizzle information from the OpenGL format */
3327 if (is_array_format
)
3328 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3330 /* If this is an array format type after checking data type and format,
3331 * create the array format
3333 if (is_array_format
) {
3334 normalized
= !_mesa_is_enum_format_integer(format
);
3335 num_channels
= _mesa_components_in_format(format
);
3337 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3338 normalized
, num_channels
,
3339 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3342 /* Otherwise this is not an array format, so return the mesa_format
3343 * matching the OpenGL format and data type
3346 case GL_UNSIGNED_SHORT_5_6_5
:
3347 if (format
== GL_RGB
)
3348 return MESA_FORMAT_B5G6R5_UNORM
;
3349 else if (format
== GL_BGR
)
3350 return MESA_FORMAT_R5G6B5_UNORM
;
3351 else if (format
== GL_RGB_INTEGER
)
3352 return MESA_FORMAT_B5G6R5_UINT
;
3354 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3355 if (format
== GL_RGB
)
3356 return MESA_FORMAT_R5G6B5_UNORM
;
3357 else if (format
== GL_BGR
)
3358 return MESA_FORMAT_B5G6R5_UNORM
;
3359 else if (format
== GL_RGB_INTEGER
)
3360 return MESA_FORMAT_R5G6B5_UINT
;
3362 case GL_UNSIGNED_SHORT_4_4_4_4
:
3363 if (format
== GL_RGBA
)
3364 return MESA_FORMAT_A4B4G4R4_UNORM
;
3365 else if (format
== GL_BGRA
)
3366 return MESA_FORMAT_A4R4G4B4_UNORM
;
3367 else if (format
== GL_ABGR_EXT
)
3368 return MESA_FORMAT_R4G4B4A4_UNORM
;
3369 else if (format
== GL_RGBA_INTEGER
)
3370 return MESA_FORMAT_A4B4G4R4_UINT
;
3371 else if (format
== GL_BGRA_INTEGER
)
3372 return MESA_FORMAT_A4R4G4B4_UINT
;
3374 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3375 if (format
== GL_RGBA
)
3376 return MESA_FORMAT_R4G4B4A4_UNORM
;
3377 else if (format
== GL_BGRA
)
3378 return MESA_FORMAT_B4G4R4A4_UNORM
;
3379 else if (format
== GL_ABGR_EXT
)
3380 return MESA_FORMAT_A4B4G4R4_UNORM
;
3381 else if (format
== GL_RGBA_INTEGER
)
3382 return MESA_FORMAT_R4G4B4A4_UINT
;
3383 else if (format
== GL_BGRA_INTEGER
)
3384 return MESA_FORMAT_B4G4R4A4_UINT
;
3386 case GL_UNSIGNED_SHORT_5_5_5_1
:
3387 if (format
== GL_RGBA
)
3388 return MESA_FORMAT_A1B5G5R5_UNORM
;
3389 else if (format
== GL_BGRA
)
3390 return MESA_FORMAT_A1R5G5B5_UNORM
;
3391 else if (format
== GL_RGBA_INTEGER
)
3392 return MESA_FORMAT_A1B5G5R5_UINT
;
3393 else if (format
== GL_BGRA_INTEGER
)
3394 return MESA_FORMAT_A1R5G5B5_UINT
;
3396 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3397 if (format
== GL_RGBA
)
3398 return MESA_FORMAT_R5G5B5A1_UNORM
;
3399 else if (format
== GL_BGRA
)
3400 return MESA_FORMAT_B5G5R5A1_UNORM
;
3401 else if (format
== GL_RGBA_INTEGER
)
3402 return MESA_FORMAT_R5G5B5A1_UINT
;
3403 else if (format
== GL_BGRA_INTEGER
)
3404 return MESA_FORMAT_B5G5R5A1_UINT
;
3406 case GL_UNSIGNED_BYTE_3_3_2
:
3407 if (format
== GL_RGB
)
3408 return MESA_FORMAT_B2G3R3_UNORM
;
3409 else if (format
== GL_RGB_INTEGER
)
3410 return MESA_FORMAT_B2G3R3_UINT
;
3412 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3413 if (format
== GL_RGB
)
3414 return MESA_FORMAT_R3G3B2_UNORM
;
3415 else if (format
== GL_RGB_INTEGER
)
3416 return MESA_FORMAT_R3G3B2_UINT
;
3418 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3419 if (format
== GL_RGB
)
3420 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3422 case GL_UNSIGNED_INT_10_10_10_2
:
3423 if (format
== GL_RGBA
)
3424 return MESA_FORMAT_A2B10G10R10_UNORM
;
3425 else if (format
== GL_RGBA_INTEGER
)
3426 return MESA_FORMAT_A2B10G10R10_UINT
;
3427 else if (format
== GL_BGRA
)
3428 return MESA_FORMAT_A2R10G10B10_UNORM
;
3429 else if (format
== GL_BGRA_INTEGER
)
3430 return MESA_FORMAT_A2R10G10B10_UINT
;
3432 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3433 if (format
== GL_RGB
)
3434 return MESA_FORMAT_R10G10B10X2_UNORM
;
3435 if (format
== GL_RGBA
)
3436 return MESA_FORMAT_R10G10B10A2_UNORM
;
3437 else if (format
== GL_RGBA_INTEGER
)
3438 return MESA_FORMAT_R10G10B10A2_UINT
;
3439 else if (format
== GL_BGRA
)
3440 return MESA_FORMAT_B10G10R10A2_UNORM
;
3441 else if (format
== GL_BGRA_INTEGER
)
3442 return MESA_FORMAT_B10G10R10A2_UINT
;
3444 case GL_UNSIGNED_INT_8_8_8_8
:
3445 if (format
== GL_RGBA
)
3446 return MESA_FORMAT_A8B8G8R8_UNORM
;
3447 else if (format
== GL_BGRA
)
3448 return MESA_FORMAT_A8R8G8B8_UNORM
;
3449 else if (format
== GL_ABGR_EXT
)
3450 return MESA_FORMAT_R8G8B8A8_UNORM
;
3451 else if (format
== GL_RGBA_INTEGER
)
3452 return MESA_FORMAT_A8B8G8R8_UINT
;
3453 else if (format
== GL_BGRA_INTEGER
)
3454 return MESA_FORMAT_A8R8G8B8_UINT
;
3456 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3457 if (format
== GL_RGBA
)
3458 return MESA_FORMAT_R8G8B8A8_UNORM
;
3459 else if (format
== GL_BGRA
)
3460 return MESA_FORMAT_B8G8R8A8_UNORM
;
3461 else if (format
== GL_ABGR_EXT
)
3462 return MESA_FORMAT_A8B8G8R8_UNORM
;
3463 else if (format
== GL_RGBA_INTEGER
)
3464 return MESA_FORMAT_R8G8B8A8_UINT
;
3465 else if (format
== GL_BGRA_INTEGER
)
3466 return MESA_FORMAT_B8G8R8A8_UINT
;
3468 case GL_UNSIGNED_SHORT_8_8_MESA
:
3469 if (format
== GL_YCBCR_MESA
)
3470 return MESA_FORMAT_YCBCR
;
3472 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3473 if (format
== GL_YCBCR_MESA
)
3474 return MESA_FORMAT_YCBCR_REV
;
3476 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3477 if (format
== GL_RGB
)
3478 return MESA_FORMAT_R11G11B10_FLOAT
;
3483 /* If we got here it means that we could not find a Mesa format that
3484 * matches the GL format/type provided. We may need to add a new Mesa
3485 * format in that case.
3487 unreachable("Unsupported format");