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 * Test if the given format represents an sRGB format.
1343 * \param format the GL format (can be an internal format)
1344 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1347 _mesa_is_srgb_format(GLenum format
)
1353 case GL_SRGB8_ALPHA8
:
1354 case GL_COMPRESSED_SRGB
:
1355 case GL_COMPRESSED_SRGB_ALPHA
:
1356 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1357 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1358 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1359 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1360 case GL_COMPRESSED_SRGB8_ETC2
:
1361 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1362 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1363 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1364 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1365 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1366 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1367 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1368 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1369 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1370 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1371 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1372 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1373 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1374 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1375 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1376 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1377 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1387 * Convert various unpack formats to the corresponding base format.
1390 _mesa_unpack_format_to_base_format(GLenum format
)
1393 case GL_RED_INTEGER
:
1395 case GL_GREEN_INTEGER
:
1397 case GL_BLUE_INTEGER
:
1399 case GL_ALPHA_INTEGER
:
1403 case GL_RGB_INTEGER
:
1405 case GL_RGBA_INTEGER
:
1407 case GL_BGR_INTEGER
:
1409 case GL_BGRA_INTEGER
:
1411 case GL_LUMINANCE_INTEGER_EXT
:
1412 return GL_LUMINANCE
;
1413 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1414 return GL_LUMINANCE_ALPHA
;
1425 case GL_LUMINANCE_ALPHA
:
1432 * Convert various base formats to the corresponding integer format.
1435 _mesa_base_format_to_integer_format(GLenum format
)
1439 return GL_RED_INTEGER
;
1441 return GL_GREEN_INTEGER
;
1443 return GL_BLUE_INTEGER
;
1445 return GL_RG_INTEGER
;
1447 return GL_RGB_INTEGER
;
1449 return GL_RGBA_INTEGER
;
1451 return GL_BGR_INTEGER
;
1453 return GL_BGRA_INTEGER
;
1455 return GL_ALPHA_INTEGER
;
1457 return GL_LUMINANCE_INTEGER_EXT
;
1458 case GL_LUMINANCE_ALPHA
:
1459 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1467 * Does the given base texture/renderbuffer format have the channel
1471 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1474 case GL_TEXTURE_RED_SIZE
:
1475 case GL_TEXTURE_RED_TYPE
:
1476 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1477 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1478 case GL_INTERNALFORMAT_RED_SIZE
:
1479 case GL_INTERNALFORMAT_RED_TYPE
:
1480 if (base_format
== GL_RED
||
1481 base_format
== GL_RG
||
1482 base_format
== GL_RGB
||
1483 base_format
== GL_RGBA
) {
1487 case GL_TEXTURE_GREEN_SIZE
:
1488 case GL_TEXTURE_GREEN_TYPE
:
1489 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1490 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1491 case GL_INTERNALFORMAT_GREEN_SIZE
:
1492 case GL_INTERNALFORMAT_GREEN_TYPE
:
1493 if (base_format
== GL_RG
||
1494 base_format
== GL_RGB
||
1495 base_format
== GL_RGBA
) {
1499 case GL_TEXTURE_BLUE_SIZE
:
1500 case GL_TEXTURE_BLUE_TYPE
:
1501 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1502 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1503 case GL_INTERNALFORMAT_BLUE_SIZE
:
1504 case GL_INTERNALFORMAT_BLUE_TYPE
:
1505 if (base_format
== GL_RGB
||
1506 base_format
== GL_RGBA
) {
1510 case GL_TEXTURE_ALPHA_SIZE
:
1511 case GL_TEXTURE_ALPHA_TYPE
:
1512 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1513 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1514 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1515 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1516 if (base_format
== GL_RGBA
||
1517 base_format
== GL_ALPHA
||
1518 base_format
== GL_LUMINANCE_ALPHA
) {
1522 case GL_TEXTURE_LUMINANCE_SIZE
:
1523 case GL_TEXTURE_LUMINANCE_TYPE
:
1524 if (base_format
== GL_LUMINANCE
||
1525 base_format
== GL_LUMINANCE_ALPHA
) {
1529 case GL_TEXTURE_INTENSITY_SIZE
:
1530 case GL_TEXTURE_INTENSITY_TYPE
:
1531 if (base_format
== GL_INTENSITY
) {
1535 case GL_TEXTURE_DEPTH_SIZE
:
1536 case GL_TEXTURE_DEPTH_TYPE
:
1537 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1538 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1539 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1540 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1541 if (base_format
== GL_DEPTH_STENCIL
||
1542 base_format
== GL_DEPTH_COMPONENT
) {
1546 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1547 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1548 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1549 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1550 if (base_format
== GL_DEPTH_STENCIL
||
1551 base_format
== GL_STENCIL_INDEX
) {
1556 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1566 * Returns the number of channels/components for a base format.
1569 _mesa_base_format_component_count(GLenum base_format
)
1571 switch (base_format
) {
1575 case GL_DEPTH_COMPONENT
:
1578 case GL_LUMINANCE_ALPHA
:
1579 case GL_DEPTH_STENCIL
:
1592 * If format is a generic compressed format, return the corresponding
1593 * non-compressed format. For other formats, return the format as-is.
1596 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1599 case GL_COMPRESSED_RED
:
1601 case GL_COMPRESSED_RG
:
1603 case GL_COMPRESSED_RGB
:
1605 case GL_COMPRESSED_RGBA
:
1607 case GL_COMPRESSED_ALPHA
:
1609 case GL_COMPRESSED_LUMINANCE
:
1610 return GL_LUMINANCE
;
1611 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1612 return GL_LUMINANCE_ALPHA
;
1613 case GL_COMPRESSED_INTENSITY
:
1614 return GL_INTENSITY
;
1616 case GL_COMPRESSED_SRGB
:
1618 case GL_COMPRESSED_SRGB_ALPHA
:
1619 return GL_SRGB_ALPHA
;
1620 case GL_COMPRESSED_SLUMINANCE
:
1621 return GL_SLUMINANCE
;
1622 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1623 return GL_SLUMINANCE_ALPHA
;
1631 * Return the equivalent non-generic internal format.
1632 * This is useful for comparing whether two internal formats are equivalent.
1635 _mesa_get_nongeneric_internalformat(GLenum format
)
1638 /* GL 1.1 formats. */
1646 case GL_LUMINANCE_ALPHA
:
1647 return GL_LUMINANCE8_ALPHA8
;
1650 return GL_LUMINANCE8
;
1654 return GL_INTENSITY8
;
1656 /* GL_ARB_texture_rg */
1662 /* GL_EXT_texture_sRGB */
1666 return GL_SRGB8_ALPHA8
;
1668 return GL_SLUMINANCE8
;
1669 case GL_SLUMINANCE_ALPHA
:
1670 return GL_SLUMINANCE8_ALPHA8
;
1672 /* GL_EXT_texture_snorm */
1674 return GL_RGBA8_SNORM
;
1676 return GL_RGB8_SNORM
;
1678 return GL_RG8_SNORM
;
1681 case GL_LUMINANCE_ALPHA_SNORM
:
1682 return GL_LUMINANCE8_ALPHA8_SNORM
;
1683 case GL_LUMINANCE_SNORM
:
1684 return GL_LUMINANCE8_SNORM
;
1685 case GL_ALPHA_SNORM
:
1686 return GL_ALPHA8_SNORM
;
1687 case GL_INTENSITY_SNORM
:
1688 return GL_INTENSITY8_SNORM
;
1697 * Convert an sRGB internal format to linear.
1700 _mesa_get_linear_internalformat(GLenum format
)
1709 case GL_SRGB8_ALPHA8
:
1711 case GL_SLUMINANCE8
:
1712 return GL_LUMINANCE8
;
1714 return GL_LUMINANCE
;
1715 case GL_SLUMINANCE_ALPHA
:
1716 return GL_LUMINANCE_ALPHA
;
1717 case GL_SLUMINANCE8_ALPHA8
:
1718 return GL_LUMINANCE8_ALPHA8
;
1726 * Do error checking of format/type combinations for glReadPixels,
1727 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1728 * and type values, we may either generate GL_INVALID_OPERATION or
1731 * \param format pixel format.
1732 * \param type pixel type.
1734 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1737 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1738 GLenum format
, GLenum type
)
1740 /* From OpenGL 3.3 spec, page 220:
1741 * "If the format is DEPTH_STENCIL, then values are taken from
1742 * both the depth buffer and the stencil buffer. If there is no
1743 * depth buffer or if there is no stencil buffer, then the error
1744 * INVALID_OPERATION occurs. If the type parameter is not
1745 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1746 * error INVALID_ENUM occurs."
1748 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1749 * cannot be used to read depth or stencil in that API.
1751 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1752 && type
!= GL_UNSIGNED_INT_24_8
1753 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1754 return GL_INVALID_ENUM
;
1756 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1759 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1760 return GL_INVALID_ENUM
;
1764 case GL_UNSIGNED_BYTE_3_3_2
:
1765 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1766 case GL_UNSIGNED_SHORT_5_6_5
:
1767 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1768 if (format
== GL_RGB
) {
1771 if (format
== GL_RGB_INTEGER_EXT
&&
1772 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1775 return GL_INVALID_OPERATION
;
1777 case GL_UNSIGNED_SHORT_4_4_4_4
:
1778 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1779 case GL_UNSIGNED_INT_8_8_8_8
:
1780 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1781 if (format
== GL_RGBA
||
1782 format
== GL_BGRA
||
1783 format
== GL_ABGR_EXT
) {
1786 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1787 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1790 return GL_INVALID_OPERATION
;
1792 case GL_UNSIGNED_SHORT_5_5_5_1
:
1793 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1794 case GL_UNSIGNED_INT_10_10_10_2
:
1795 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1796 if (format
== GL_RGBA
||
1797 format
== GL_BGRA
) {
1800 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1801 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1804 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1805 ctx
->API
== API_OPENGLES2
) {
1806 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1808 return GL_INVALID_OPERATION
;
1810 case GL_UNSIGNED_INT_24_8
:
1811 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1812 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1815 if (format
!= GL_DEPTH_STENCIL
) {
1816 return GL_INVALID_OPERATION
;
1820 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1821 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1822 return GL_INVALID_ENUM
;
1824 if (format
!= GL_DEPTH_STENCIL
) {
1825 return GL_INVALID_OPERATION
;
1829 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1830 if (!ctx
->Extensions
.EXT_packed_float
) {
1831 return GL_INVALID_ENUM
;
1833 if (format
!= GL_RGB
) {
1834 return GL_INVALID_OPERATION
;
1838 case GL_HALF_FLOAT_OES
:
1842 case GL_LUMINANCE_ALPHA
:
1848 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1851 return GL_INVALID_OPERATION
;
1855 ; /* fall-through */
1858 /* now, for each format, check the type for compatibility */
1860 case GL_COLOR_INDEX
:
1861 case GL_STENCIL_INDEX
:
1865 case GL_UNSIGNED_BYTE
:
1867 case GL_UNSIGNED_SHORT
:
1869 case GL_UNSIGNED_INT
:
1874 return GL_INVALID_ENUM
;
1881 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1885 case GL_LUMINANCE_ALPHA
:
1886 case GL_DEPTH_COMPONENT
:
1889 case GL_UNSIGNED_BYTE
:
1891 case GL_UNSIGNED_SHORT
:
1893 case GL_UNSIGNED_INT
:
1898 return GL_INVALID_ENUM
;
1902 if (!ctx
->Extensions
.ARB_texture_rg
)
1903 return GL_INVALID_ENUM
;
1906 case GL_UNSIGNED_BYTE
:
1908 case GL_UNSIGNED_SHORT
:
1910 case GL_UNSIGNED_INT
:
1915 return GL_INVALID_ENUM
;
1921 case GL_UNSIGNED_BYTE
:
1923 case GL_UNSIGNED_SHORT
:
1925 case GL_UNSIGNED_INT
:
1927 case GL_UNSIGNED_BYTE_3_3_2
:
1928 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1929 case GL_UNSIGNED_SHORT_5_6_5
:
1930 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1933 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1934 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1935 return (ctx
->API
== API_OPENGLES2
)
1936 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1937 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1938 return ctx
->Extensions
.EXT_texture_shared_exponent
1939 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1940 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1941 return ctx
->Extensions
.EXT_packed_float
1942 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1944 return GL_INVALID_ENUM
;
1949 /* NOTE: no packed types are supported with BGR. That's
1950 * intentional, according to the GL spec.
1953 case GL_UNSIGNED_BYTE
:
1955 case GL_UNSIGNED_SHORT
:
1957 case GL_UNSIGNED_INT
:
1962 return GL_INVALID_ENUM
;
1969 case GL_UNSIGNED_BYTE
:
1971 case GL_UNSIGNED_SHORT
:
1973 case GL_UNSIGNED_INT
:
1975 case GL_UNSIGNED_SHORT_4_4_4_4
:
1976 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1977 case GL_UNSIGNED_SHORT_5_5_5_1
:
1978 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1979 case GL_UNSIGNED_INT_8_8_8_8
:
1980 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1981 case GL_UNSIGNED_INT_10_10_10_2
:
1982 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1986 return GL_INVALID_ENUM
;
1992 case GL_UNSIGNED_BYTE
:
1994 case GL_UNSIGNED_SHORT
:
1996 case GL_UNSIGNED_INT
:
1998 case GL_UNSIGNED_SHORT_4_4_4_4
:
1999 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2000 case GL_UNSIGNED_INT_8_8_8_8
:
2001 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2005 return GL_INVALID_ENUM
;
2009 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2010 return GL_INVALID_ENUM
;
2011 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2012 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2015 return GL_INVALID_OPERATION
;
2017 case GL_DEPTH_STENCIL
:
2018 if (type
== GL_UNSIGNED_INT_24_8
)
2020 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2021 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2024 return GL_INVALID_ENUM
;
2026 /* integer-valued formats */
2027 case GL_RED_INTEGER_EXT
:
2028 case GL_GREEN_INTEGER_EXT
:
2029 case GL_BLUE_INTEGER_EXT
:
2030 case GL_ALPHA_INTEGER_EXT
:
2034 case GL_UNSIGNED_BYTE
:
2036 case GL_UNSIGNED_SHORT
:
2038 case GL_UNSIGNED_INT
:
2039 return (ctx
->Version
>= 30 ||
2040 ctx
->Extensions
.EXT_texture_integer
)
2041 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2043 return GL_INVALID_ENUM
;
2046 case GL_RGB_INTEGER_EXT
:
2049 case GL_UNSIGNED_BYTE
:
2051 case GL_UNSIGNED_SHORT
:
2053 case GL_UNSIGNED_INT
:
2054 return (ctx
->Version
>= 30 ||
2055 ctx
->Extensions
.EXT_texture_integer
)
2056 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2057 case GL_UNSIGNED_BYTE_3_3_2
:
2058 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2059 case GL_UNSIGNED_SHORT_5_6_5
:
2060 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2061 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2062 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2064 return GL_INVALID_ENUM
;
2067 case GL_BGR_INTEGER_EXT
:
2070 case GL_UNSIGNED_BYTE
:
2072 case GL_UNSIGNED_SHORT
:
2074 case GL_UNSIGNED_INT
:
2075 /* NOTE: no packed formats w/ BGR format */
2076 return (ctx
->Version
>= 30 ||
2077 ctx
->Extensions
.EXT_texture_integer
)
2078 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2080 return GL_INVALID_ENUM
;
2083 case GL_RGBA_INTEGER_EXT
:
2084 case GL_BGRA_INTEGER_EXT
:
2087 case GL_UNSIGNED_BYTE
:
2089 case GL_UNSIGNED_SHORT
:
2091 case GL_UNSIGNED_INT
:
2092 return (ctx
->Version
>= 30 ||
2093 ctx
->Extensions
.EXT_texture_integer
)
2094 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2095 case GL_UNSIGNED_SHORT_4_4_4_4
:
2096 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2097 case GL_UNSIGNED_SHORT_5_5_5_1
:
2098 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2099 case GL_UNSIGNED_INT_8_8_8_8
:
2100 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2101 case GL_UNSIGNED_INT_10_10_10_2
:
2102 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2103 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2104 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2106 return GL_INVALID_ENUM
;
2109 case GL_LUMINANCE_INTEGER_EXT
:
2110 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2113 case GL_UNSIGNED_BYTE
:
2115 case GL_UNSIGNED_SHORT
:
2117 case GL_UNSIGNED_INT
:
2118 return ctx
->Extensions
.EXT_texture_integer
2119 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2121 return GL_INVALID_ENUM
;
2125 return GL_INVALID_ENUM
;
2132 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2133 * and glTex[Sub]Image.
2134 * \return error code, or GL_NO_ERROR.
2137 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2138 GLenum format
, GLenum type
,
2139 unsigned dimensions
)
2141 GLboolean type_valid
= GL_TRUE
;
2146 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2147 return GL_INVALID_VALUE
;
2151 case GL_LUMINANCE_ALPHA
:
2152 type_valid
= (type
== GL_UNSIGNED_BYTE
2154 || type
== GL_HALF_FLOAT_OES
);
2158 type_valid
= (type
== GL_UNSIGNED_BYTE
2159 || type
== GL_UNSIGNED_SHORT_5_6_5
2161 || type
== GL_HALF_FLOAT_OES
);
2165 type_valid
= (type
== GL_UNSIGNED_BYTE
2166 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2167 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2169 || type
== GL_HALF_FLOAT_OES
2170 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2173 case GL_DEPTH_COMPONENT
:
2174 /* This format is filtered against invalid dimensionalities elsewhere.
2176 type_valid
= (type
== GL_UNSIGNED_SHORT
2177 || type
== GL_UNSIGNED_INT
);
2180 case GL_DEPTH_STENCIL
:
2181 /* This format is filtered against invalid dimensionalities elsewhere.
2183 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2187 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2189 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2190 * the format does not appear to be allowed for 3D textures in OpenGL
2193 if (dimensions
!= 2)
2194 return GL_INVALID_VALUE
;
2199 return GL_INVALID_VALUE
;
2202 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2206 * Return the simple base format for a given internal texture format.
2207 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2209 * \param ctx GL context.
2210 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2212 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2213 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2215 * This is the format which is used during texture application (i.e. the
2216 * texture format and env mode determine the arithmetic used.
2219 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2221 switch (internalFormat
) {
2227 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2232 case GL_LUMINANCE12
:
2233 case GL_LUMINANCE16
:
2234 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2236 case GL_LUMINANCE_ALPHA
:
2237 case GL_LUMINANCE4_ALPHA4
:
2238 case GL_LUMINANCE6_ALPHA2
:
2239 case GL_LUMINANCE8_ALPHA8
:
2240 case GL_LUMINANCE12_ALPHA4
:
2241 case GL_LUMINANCE12_ALPHA12
:
2242 case GL_LUMINANCE16_ALPHA16
:
2243 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2247 case GL_INTENSITY12
:
2248 case GL_INTENSITY16
:
2249 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2251 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2262 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2276 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2278 if (_mesa_is_gles(ctx
)) {
2279 switch (internalFormat
) {
2287 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2288 switch (internalFormat
) {
2296 if (ctx
->Extensions
.ARB_depth_texture
) {
2297 switch (internalFormat
) {
2298 case GL_DEPTH_COMPONENT
:
2299 case GL_DEPTH_COMPONENT16
:
2300 case GL_DEPTH_COMPONENT24
:
2301 case GL_DEPTH_COMPONENT32
:
2302 return GL_DEPTH_COMPONENT
;
2303 case GL_DEPTH_STENCIL
:
2304 case GL_DEPTH24_STENCIL8
:
2305 return GL_DEPTH_STENCIL
;
2311 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2312 switch (internalFormat
) {
2313 case GL_STENCIL_INDEX
:
2314 case GL_STENCIL_INDEX1
:
2315 case GL_STENCIL_INDEX4
:
2316 case GL_STENCIL_INDEX8
:
2317 case GL_STENCIL_INDEX16
:
2318 return GL_STENCIL_INDEX
;
2324 switch (internalFormat
) {
2325 case GL_COMPRESSED_ALPHA
:
2327 case GL_COMPRESSED_LUMINANCE
:
2328 return GL_LUMINANCE
;
2329 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2330 return GL_LUMINANCE_ALPHA
;
2331 case GL_COMPRESSED_INTENSITY
:
2332 return GL_INTENSITY
;
2333 case GL_COMPRESSED_RGB
:
2335 case GL_COMPRESSED_RGBA
:
2341 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2342 GLenum base_compressed
=
2343 _mesa_gl_compressed_format_base_format(internalFormat
);
2344 if (base_compressed
)
2345 return base_compressed
;
2348 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2349 _mesa_is_astc_format(internalFormat
))
2352 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2353 if (internalFormat
== GL_YCBCR_MESA
)
2354 return GL_YCBCR_MESA
;
2357 if (ctx
->Extensions
.ARB_texture_float
) {
2358 switch (internalFormat
) {
2359 case GL_ALPHA16F_ARB
:
2360 case GL_ALPHA32F_ARB
:
2362 case GL_RGBA16F_ARB
:
2363 case GL_RGBA32F_ARB
:
2368 case GL_INTENSITY16F_ARB
:
2369 case GL_INTENSITY32F_ARB
:
2370 return GL_INTENSITY
;
2371 case GL_LUMINANCE16F_ARB
:
2372 case GL_LUMINANCE32F_ARB
:
2373 return GL_LUMINANCE
;
2374 case GL_LUMINANCE_ALPHA16F_ARB
:
2375 case GL_LUMINANCE_ALPHA32F_ARB
:
2376 return GL_LUMINANCE_ALPHA
;
2382 if (ctx
->Extensions
.EXT_texture_snorm
) {
2383 switch (internalFormat
) {
2394 case GL_RGB16_SNORM
:
2397 case GL_RGBA8_SNORM
:
2398 case GL_RGBA16_SNORM
:
2400 case GL_ALPHA_SNORM
:
2401 case GL_ALPHA8_SNORM
:
2402 case GL_ALPHA16_SNORM
:
2404 case GL_LUMINANCE_SNORM
:
2405 case GL_LUMINANCE8_SNORM
:
2406 case GL_LUMINANCE16_SNORM
:
2407 return GL_LUMINANCE
;
2408 case GL_LUMINANCE_ALPHA_SNORM
:
2409 case GL_LUMINANCE8_ALPHA8_SNORM
:
2410 case GL_LUMINANCE16_ALPHA16_SNORM
:
2411 return GL_LUMINANCE_ALPHA
;
2412 case GL_INTENSITY_SNORM
:
2413 case GL_INTENSITY8_SNORM
:
2414 case GL_INTENSITY16_SNORM
:
2415 return GL_INTENSITY
;
2421 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2422 switch (internalFormat
) {
2425 case GL_COMPRESSED_SRGB_EXT
:
2427 case GL_SRGB_ALPHA_EXT
:
2428 case GL_SRGB8_ALPHA8_EXT
:
2429 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2431 case GL_SLUMINANCE_ALPHA_EXT
:
2432 case GL_SLUMINANCE8_ALPHA8_EXT
:
2433 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2434 return GL_LUMINANCE_ALPHA
;
2435 case GL_SLUMINANCE_EXT
:
2436 case GL_SLUMINANCE8_EXT
:
2437 case GL_COMPRESSED_SLUMINANCE_EXT
:
2438 return GL_LUMINANCE
;
2444 if (ctx
->Version
>= 30 ||
2445 ctx
->Extensions
.EXT_texture_integer
) {
2446 switch (internalFormat
) {
2447 case GL_RGBA8UI_EXT
:
2448 case GL_RGBA16UI_EXT
:
2449 case GL_RGBA32UI_EXT
:
2451 case GL_RGBA16I_EXT
:
2452 case GL_RGBA32I_EXT
:
2456 case GL_RGB16UI_EXT
:
2457 case GL_RGB32UI_EXT
:
2465 if (ctx
->Extensions
.EXT_texture_integer
) {
2466 switch (internalFormat
) {
2467 case GL_ALPHA8UI_EXT
:
2468 case GL_ALPHA16UI_EXT
:
2469 case GL_ALPHA32UI_EXT
:
2470 case GL_ALPHA8I_EXT
:
2471 case GL_ALPHA16I_EXT
:
2472 case GL_ALPHA32I_EXT
:
2474 case GL_INTENSITY8UI_EXT
:
2475 case GL_INTENSITY16UI_EXT
:
2476 case GL_INTENSITY32UI_EXT
:
2477 case GL_INTENSITY8I_EXT
:
2478 case GL_INTENSITY16I_EXT
:
2479 case GL_INTENSITY32I_EXT
:
2480 return GL_INTENSITY
;
2481 case GL_LUMINANCE8UI_EXT
:
2482 case GL_LUMINANCE16UI_EXT
:
2483 case GL_LUMINANCE32UI_EXT
:
2484 case GL_LUMINANCE8I_EXT
:
2485 case GL_LUMINANCE16I_EXT
:
2486 case GL_LUMINANCE32I_EXT
:
2487 return GL_LUMINANCE
;
2488 case GL_LUMINANCE_ALPHA8UI_EXT
:
2489 case GL_LUMINANCE_ALPHA16UI_EXT
:
2490 case GL_LUMINANCE_ALPHA32UI_EXT
:
2491 case GL_LUMINANCE_ALPHA8I_EXT
:
2492 case GL_LUMINANCE_ALPHA16I_EXT
:
2493 case GL_LUMINANCE_ALPHA32I_EXT
:
2494 return GL_LUMINANCE_ALPHA
;
2500 if (ctx
->Extensions
.ARB_texture_rg
) {
2501 switch (internalFormat
) {
2504 if (!ctx
->Extensions
.ARB_texture_float
)
2513 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2519 case GL_COMPRESSED_RED
:
2524 if (!ctx
->Extensions
.ARB_texture_float
)
2533 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2539 case GL_COMPRESSED_RG
:
2546 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2547 switch (internalFormat
) {
2548 case GL_RGB9_E5_EXT
:
2555 if (ctx
->Extensions
.EXT_packed_float
) {
2556 switch (internalFormat
) {
2557 case GL_R11F_G11F_B10F_EXT
:
2564 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2565 switch (internalFormat
) {
2566 case GL_DEPTH_COMPONENT32F
:
2567 return GL_DEPTH_COMPONENT
;
2568 case GL_DEPTH32F_STENCIL8
:
2569 return GL_DEPTH_STENCIL
;
2575 return -1; /* error */
2579 * Returns the effective internal format from a texture format and type.
2580 * This is used by texture image operations internally for validation, when
2581 * the specified internal format is a base (unsized) format.
2583 * This method will only return a valid effective internal format if the
2584 * combination of format, type and internal format in base form, is acceptable.
2586 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2587 * in extensions, to unambiguously correspond to the given base format, then
2588 * that internal format is returned as the effective. Otherwise, if the
2589 * combination is accepted but a single effective format is not defined, the
2590 * passed base format will be returned instead.
2592 * \param format the texture format
2593 * \param type the texture type
2596 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2600 case GL_UNSIGNED_BYTE
:
2606 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2607 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2608 * internal formats, they do not correspond to GL constants, so the base
2609 * format is returned instead.
2612 case GL_LUMINANCE_ALPHA
:
2619 case GL_UNSIGNED_SHORT_4_4_4_4
:
2620 if (format
== GL_RGBA
)
2624 case GL_UNSIGNED_SHORT_5_5_5_1
:
2625 if (format
== GL_RGBA
)
2629 case GL_UNSIGNED_SHORT_5_6_5
:
2630 if (format
== GL_RGB
)
2634 /* OES_packed_depth_stencil */
2635 case GL_UNSIGNED_INT_24_8
:
2636 if (format
== GL_DEPTH_STENCIL
)
2637 return GL_DEPTH24_STENCIL8
;
2640 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2641 if (format
== GL_DEPTH_STENCIL
)
2642 return GL_DEPTH32F_STENCIL8
;
2645 case GL_UNSIGNED_SHORT
:
2646 if (format
== GL_DEPTH_COMPONENT
)
2647 return GL_DEPTH_COMPONENT16
;
2650 case GL_UNSIGNED_INT
:
2651 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2654 if (format
== GL_DEPTH_COMPONENT
)
2658 /* OES_texture_float and OES_texture_half_float */
2660 if (format
== GL_DEPTH_COMPONENT
)
2661 return GL_DEPTH_COMPONENT32F
;
2663 case GL_HALF_FLOAT_OES
:
2667 case GL_LUMINANCE_ALPHA
:
2683 /* GL_EXT_texture_type_2_10_10_10_REV */
2684 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2693 /* fall through and return NONE */
2701 * Do error checking of format/type combinations for OpenGL ES 3
2703 * \return error code, or GL_NO_ERROR.
2706 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2707 GLenum format
, GLenum type
,
2708 GLenum internalFormat
)
2710 /* If internalFormat is an unsized format, then the effective internal
2711 * format derived from format and type should be used instead. Page 127,
2712 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2714 * "if internalformat is a base internal format, the effective
2715 * internal format is a sized internal format that is derived
2716 * from the format and type for internal use by the GL.
2717 * Table 3.12 specifies the mapping of format and type to effective
2718 * internal formats. The effective internal format is used by the GL
2719 * for purposes such as texture completeness or type checks for
2720 * CopyTex* commands. In these cases, the GL is required to operate
2721 * as if the effective internal format was used as the internalformat
2722 * when specifying the texture data."
2724 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2725 GLenum effectiveInternalFormat
=
2726 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2728 if (effectiveInternalFormat
== GL_NONE
)
2729 return GL_INVALID_OPERATION
;
2731 GLenum baseInternalFormat
;
2732 if (internalFormat
== GL_BGRA_EXT
) {
2733 /* Unfortunately, _mesa_base_tex_format returns a base format of
2734 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2735 * asking the question, "what channels does this format have?"
2736 * However, if we're trying to determine if two internal formats
2737 * match in the ES3 sense, we actually want GL_BGRA.
2739 baseInternalFormat
= GL_BGRA_EXT
;
2741 baseInternalFormat
=
2742 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2745 if (internalFormat
!= baseInternalFormat
)
2746 return GL_INVALID_OPERATION
;
2748 internalFormat
= effectiveInternalFormat
;
2753 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2754 return GL_INVALID_OPERATION
;
2759 case GL_UNSIGNED_BYTE
:
2760 switch (internalFormat
) {
2765 case GL_SRGB8_ALPHA8_EXT
:
2768 return GL_INVALID_OPERATION
;
2773 if (internalFormat
!= GL_RGBA8_SNORM
)
2774 return GL_INVALID_OPERATION
;
2777 case GL_UNSIGNED_SHORT_4_4_4_4
:
2778 switch (internalFormat
) {
2783 return GL_INVALID_OPERATION
;
2787 case GL_UNSIGNED_SHORT_5_5_5_1
:
2788 switch (internalFormat
) {
2793 return GL_INVALID_OPERATION
;
2797 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2798 switch (internalFormat
) {
2799 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2804 return GL_INVALID_OPERATION
;
2809 if (internalFormat
!= GL_RGBA16F
)
2810 return GL_INVALID_OPERATION
;
2814 switch (internalFormat
) {
2819 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2822 return GL_INVALID_OPERATION
;
2826 case GL_HALF_FLOAT_OES
:
2827 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2830 return GL_INVALID_OPERATION
;
2834 case GL_RGBA_INTEGER
:
2836 case GL_UNSIGNED_BYTE
:
2837 if (internalFormat
!= GL_RGBA8UI
)
2838 return GL_INVALID_OPERATION
;
2842 if (internalFormat
!= GL_RGBA8I
)
2843 return GL_INVALID_OPERATION
;
2846 case GL_UNSIGNED_SHORT
:
2847 if (internalFormat
!= GL_RGBA16UI
)
2848 return GL_INVALID_OPERATION
;
2852 if (internalFormat
!= GL_RGBA16I
)
2853 return GL_INVALID_OPERATION
;
2856 case GL_UNSIGNED_INT
:
2857 if (internalFormat
!= GL_RGBA32UI
)
2858 return GL_INVALID_OPERATION
;
2862 if (internalFormat
!= GL_RGBA32I
)
2863 return GL_INVALID_OPERATION
;
2866 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2867 if (internalFormat
!= GL_RGB10_A2UI
)
2868 return GL_INVALID_OPERATION
;
2872 return GL_INVALID_OPERATION
;
2878 case GL_UNSIGNED_BYTE
:
2879 switch (internalFormat
) {
2886 return GL_INVALID_OPERATION
;
2891 if (internalFormat
!= GL_RGB8_SNORM
)
2892 return GL_INVALID_OPERATION
;
2895 case GL_UNSIGNED_SHORT_5_6_5
:
2896 switch (internalFormat
) {
2901 return GL_INVALID_OPERATION
;
2905 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2906 if (internalFormat
!= GL_R11F_G11F_B10F
)
2907 return GL_INVALID_OPERATION
;
2910 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2911 if (internalFormat
!= GL_RGB9_E5
)
2912 return GL_INVALID_OPERATION
;
2916 switch (internalFormat
) {
2918 case GL_R11F_G11F_B10F
:
2922 return GL_INVALID_OPERATION
;
2927 switch (internalFormat
) {
2930 case GL_R11F_G11F_B10F
:
2934 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2937 return GL_INVALID_OPERATION
;
2941 case GL_HALF_FLOAT_OES
:
2942 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2943 return GL_INVALID_OPERATION
;
2946 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2947 switch (internalFormat
) {
2948 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2951 return GL_INVALID_OPERATION
;
2956 return GL_INVALID_OPERATION
;
2960 case GL_RGB_INTEGER
:
2962 case GL_UNSIGNED_BYTE
:
2963 if (internalFormat
!= GL_RGB8UI
)
2964 return GL_INVALID_OPERATION
;
2968 if (internalFormat
!= GL_RGB8I
)
2969 return GL_INVALID_OPERATION
;
2972 case GL_UNSIGNED_SHORT
:
2973 if (internalFormat
!= GL_RGB16UI
)
2974 return GL_INVALID_OPERATION
;
2978 if (internalFormat
!= GL_RGB16I
)
2979 return GL_INVALID_OPERATION
;
2982 case GL_UNSIGNED_INT
:
2983 if (internalFormat
!= GL_RGB32UI
)
2984 return GL_INVALID_OPERATION
;
2988 if (internalFormat
!= GL_RGB32I
)
2989 return GL_INVALID_OPERATION
;
2993 return GL_INVALID_OPERATION
;
2999 case GL_UNSIGNED_BYTE
:
3000 if (internalFormat
!= GL_RG8
)
3001 return GL_INVALID_OPERATION
;
3005 if (internalFormat
!= GL_RG8_SNORM
)
3006 return GL_INVALID_OPERATION
;
3010 case GL_HALF_FLOAT_OES
:
3011 switch (internalFormat
) {
3015 if (ctx
->Extensions
.ARB_texture_rg
&&
3016 ctx
->Extensions
.OES_texture_half_float
)
3020 return GL_INVALID_OPERATION
;
3025 switch (internalFormat
) {
3030 if (ctx
->Extensions
.ARB_texture_rg
&&
3031 ctx
->Extensions
.OES_texture_float
)
3035 return GL_INVALID_OPERATION
;
3040 return GL_INVALID_OPERATION
;
3046 case GL_UNSIGNED_BYTE
:
3047 if (internalFormat
!= GL_RG8UI
)
3048 return GL_INVALID_OPERATION
;
3052 if (internalFormat
!= GL_RG8I
)
3053 return GL_INVALID_OPERATION
;
3056 case GL_UNSIGNED_SHORT
:
3057 if (internalFormat
!= GL_RG16UI
)
3058 return GL_INVALID_OPERATION
;
3062 if (internalFormat
!= GL_RG16I
)
3063 return GL_INVALID_OPERATION
;
3066 case GL_UNSIGNED_INT
:
3067 if (internalFormat
!= GL_RG32UI
)
3068 return GL_INVALID_OPERATION
;
3072 if (internalFormat
!= GL_RG32I
)
3073 return GL_INVALID_OPERATION
;
3077 return GL_INVALID_OPERATION
;
3083 case GL_UNSIGNED_BYTE
:
3084 if (internalFormat
!= GL_R8
)
3085 return GL_INVALID_OPERATION
;
3089 if (internalFormat
!= GL_R8_SNORM
)
3090 return GL_INVALID_OPERATION
;
3094 case GL_HALF_FLOAT_OES
:
3095 switch (internalFormat
) {
3100 if (ctx
->Extensions
.ARB_texture_rg
&&
3101 ctx
->Extensions
.OES_texture_half_float
)
3105 return GL_INVALID_OPERATION
;
3110 switch (internalFormat
) {
3115 if (ctx
->Extensions
.ARB_texture_rg
&&
3116 ctx
->Extensions
.OES_texture_float
)
3120 return GL_INVALID_OPERATION
;
3125 return GL_INVALID_OPERATION
;
3129 case GL_RED_INTEGER
:
3131 case GL_UNSIGNED_BYTE
:
3132 if (internalFormat
!= GL_R8UI
)
3133 return GL_INVALID_OPERATION
;
3137 if (internalFormat
!= GL_R8I
)
3138 return GL_INVALID_OPERATION
;
3141 case GL_UNSIGNED_SHORT
:
3142 if (internalFormat
!= GL_R16UI
)
3143 return GL_INVALID_OPERATION
;
3147 if (internalFormat
!= GL_R16I
)
3148 return GL_INVALID_OPERATION
;
3151 case GL_UNSIGNED_INT
:
3152 if (internalFormat
!= GL_R32UI
)
3153 return GL_INVALID_OPERATION
;
3157 if (internalFormat
!= GL_R32I
)
3158 return GL_INVALID_OPERATION
;
3162 return GL_INVALID_OPERATION
;
3166 case GL_DEPTH_COMPONENT
:
3168 case GL_UNSIGNED_SHORT
:
3169 if (internalFormat
!= GL_DEPTH_COMPONENT
3170 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3171 return GL_INVALID_OPERATION
;
3174 case GL_UNSIGNED_INT
:
3175 switch (internalFormat
) {
3176 case GL_DEPTH_COMPONENT
:
3177 case GL_DEPTH_COMPONENT16
:
3178 case GL_DEPTH_COMPONENT24
:
3181 return GL_INVALID_OPERATION
;
3186 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3187 return GL_INVALID_OPERATION
;
3191 return GL_INVALID_OPERATION
;
3195 case GL_DEPTH_STENCIL
:
3197 case GL_UNSIGNED_INT_24_8
:
3198 if (internalFormat
!= GL_DEPTH_STENCIL
3199 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3200 return GL_INVALID_OPERATION
;
3203 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3204 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3205 return GL_INVALID_OPERATION
;
3209 return GL_INVALID_OPERATION
;
3213 case GL_STENCIL_INDEX
:
3214 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3215 type
!= GL_UNSIGNED_BYTE
||
3216 internalFormat
!= GL_STENCIL_INDEX8
) {
3217 return GL_INVALID_OPERATION
;
3223 case GL_LUMINANCE_ALPHA
:
3226 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3228 case GL_HALF_FLOAT_OES
:
3229 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3232 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3233 return GL_INVALID_OPERATION
;
3241 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3243 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3244 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3245 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3246 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3250 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3254 case GL_RGBA_INTEGER_EXT
:
3255 set_swizzle(swizzle
, 0, 1, 2, 3);
3258 case GL_BGRA_INTEGER_EXT
:
3259 set_swizzle(swizzle
, 2, 1, 0, 3);
3262 set_swizzle(swizzle
, 3, 2, 1, 0);
3265 case GL_RGB_INTEGER_EXT
:
3266 set_swizzle(swizzle
, 0, 1, 2, 5);
3269 case GL_BGR_INTEGER_EXT
:
3270 set_swizzle(swizzle
, 2, 1, 0, 5);
3272 case GL_LUMINANCE_ALPHA
:
3273 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3274 set_swizzle(swizzle
, 0, 0, 0, 1);
3278 set_swizzle(swizzle
, 0, 1, 4, 5);
3281 case GL_RED_INTEGER_EXT
:
3282 set_swizzle(swizzle
, 0, 4, 4, 5);
3285 case GL_GREEN_INTEGER_EXT
:
3286 set_swizzle(swizzle
, 4, 0, 4, 5);
3289 case GL_BLUE_INTEGER_EXT
:
3290 set_swizzle(swizzle
, 4, 4, 0, 5);
3293 case GL_ALPHA_INTEGER_EXT
:
3294 set_swizzle(swizzle
, 4, 4, 4, 0);
3297 case GL_LUMINANCE_INTEGER_EXT
:
3298 set_swizzle(swizzle
, 0, 0, 0, 5);
3301 set_swizzle(swizzle
, 0, 0, 0, 0);
3309 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3310 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3311 * otherwise (for non-array formats).
3313 * This function will typically be used to compute a mesa format from a GL type
3314 * so we can then call _mesa_format_convert. This function does
3315 * not consider byte swapping, so it returns types assuming that no byte
3316 * swapping is involved. If byte swapping is involved then clients are supposed
3317 * to handle that on their side before calling _mesa_format_convert.
3319 * This function returns an uint32_t that can pack a mesa_format or a
3320 * mesa_array_format. Clients must check the mesa array format bit
3321 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3322 * format is a mesa_array_format or a mesa_format.
3325 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3327 bool is_array_format
= true;
3329 bool normalized
= false, is_float
= false, is_signed
= false;
3330 int num_channels
= 0, type_size
= 0;
3332 /* Extract array format type information from the OpenGL data type */
3334 case GL_UNSIGNED_BYTE
:
3341 case GL_UNSIGNED_SHORT
:
3348 case GL_UNSIGNED_INT
:
3356 case GL_HALF_FLOAT_OES
:
3367 is_array_format
= false;
3371 /* Extract array format swizzle information from the OpenGL format */
3372 if (is_array_format
)
3373 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3375 /* If this is an array format type after checking data type and format,
3376 * create the array format
3378 if (is_array_format
) {
3379 normalized
= !_mesa_is_enum_format_integer(format
);
3380 num_channels
= _mesa_components_in_format(format
);
3382 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3383 normalized
, num_channels
,
3384 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3387 /* Otherwise this is not an array format, so return the mesa_format
3388 * matching the OpenGL format and data type
3391 case GL_UNSIGNED_SHORT_5_6_5
:
3392 if (format
== GL_RGB
)
3393 return MESA_FORMAT_B5G6R5_UNORM
;
3394 else if (format
== GL_BGR
)
3395 return MESA_FORMAT_R5G6B5_UNORM
;
3396 else if (format
== GL_RGB_INTEGER
)
3397 return MESA_FORMAT_B5G6R5_UINT
;
3399 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3400 if (format
== GL_RGB
)
3401 return MESA_FORMAT_R5G6B5_UNORM
;
3402 else if (format
== GL_BGR
)
3403 return MESA_FORMAT_B5G6R5_UNORM
;
3404 else if (format
== GL_RGB_INTEGER
)
3405 return MESA_FORMAT_R5G6B5_UINT
;
3407 case GL_UNSIGNED_SHORT_4_4_4_4
:
3408 if (format
== GL_RGBA
)
3409 return MESA_FORMAT_A4B4G4R4_UNORM
;
3410 else if (format
== GL_BGRA
)
3411 return MESA_FORMAT_A4R4G4B4_UNORM
;
3412 else if (format
== GL_ABGR_EXT
)
3413 return MESA_FORMAT_R4G4B4A4_UNORM
;
3414 else if (format
== GL_RGBA_INTEGER
)
3415 return MESA_FORMAT_A4B4G4R4_UINT
;
3416 else if (format
== GL_BGRA_INTEGER
)
3417 return MESA_FORMAT_A4R4G4B4_UINT
;
3419 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3420 if (format
== GL_RGBA
)
3421 return MESA_FORMAT_R4G4B4A4_UNORM
;
3422 else if (format
== GL_BGRA
)
3423 return MESA_FORMAT_B4G4R4A4_UNORM
;
3424 else if (format
== GL_ABGR_EXT
)
3425 return MESA_FORMAT_A4B4G4R4_UNORM
;
3426 else if (format
== GL_RGBA_INTEGER
)
3427 return MESA_FORMAT_R4G4B4A4_UINT
;
3428 else if (format
== GL_BGRA_INTEGER
)
3429 return MESA_FORMAT_B4G4R4A4_UINT
;
3431 case GL_UNSIGNED_SHORT_5_5_5_1
:
3432 if (format
== GL_RGBA
)
3433 return MESA_FORMAT_A1B5G5R5_UNORM
;
3434 else if (format
== GL_BGRA
)
3435 return MESA_FORMAT_A1R5G5B5_UNORM
;
3436 else if (format
== GL_RGBA_INTEGER
)
3437 return MESA_FORMAT_A1B5G5R5_UINT
;
3438 else if (format
== GL_BGRA_INTEGER
)
3439 return MESA_FORMAT_A1R5G5B5_UINT
;
3441 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3442 if (format
== GL_RGBA
)
3443 return MESA_FORMAT_R5G5B5A1_UNORM
;
3444 else if (format
== GL_BGRA
)
3445 return MESA_FORMAT_B5G5R5A1_UNORM
;
3446 else if (format
== GL_RGBA_INTEGER
)
3447 return MESA_FORMAT_R5G5B5A1_UINT
;
3448 else if (format
== GL_BGRA_INTEGER
)
3449 return MESA_FORMAT_B5G5R5A1_UINT
;
3451 case GL_UNSIGNED_BYTE_3_3_2
:
3452 if (format
== GL_RGB
)
3453 return MESA_FORMAT_B2G3R3_UNORM
;
3454 else if (format
== GL_RGB_INTEGER
)
3455 return MESA_FORMAT_B2G3R3_UINT
;
3457 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3458 if (format
== GL_RGB
)
3459 return MESA_FORMAT_R3G3B2_UNORM
;
3460 else if (format
== GL_RGB_INTEGER
)
3461 return MESA_FORMAT_R3G3B2_UINT
;
3463 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3464 if (format
== GL_RGB
)
3465 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3467 case GL_UNSIGNED_INT_10_10_10_2
:
3468 if (format
== GL_RGBA
)
3469 return MESA_FORMAT_A2B10G10R10_UNORM
;
3470 else if (format
== GL_RGBA_INTEGER
)
3471 return MESA_FORMAT_A2B10G10R10_UINT
;
3472 else if (format
== GL_BGRA
)
3473 return MESA_FORMAT_A2R10G10B10_UNORM
;
3474 else if (format
== GL_BGRA_INTEGER
)
3475 return MESA_FORMAT_A2R10G10B10_UINT
;
3477 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3478 if (format
== GL_RGB
)
3479 return MESA_FORMAT_R10G10B10X2_UNORM
;
3480 if (format
== GL_RGBA
)
3481 return MESA_FORMAT_R10G10B10A2_UNORM
;
3482 else if (format
== GL_RGBA_INTEGER
)
3483 return MESA_FORMAT_R10G10B10A2_UINT
;
3484 else if (format
== GL_BGRA
)
3485 return MESA_FORMAT_B10G10R10A2_UNORM
;
3486 else if (format
== GL_BGRA_INTEGER
)
3487 return MESA_FORMAT_B10G10R10A2_UINT
;
3489 case GL_UNSIGNED_INT_8_8_8_8
:
3490 if (format
== GL_RGBA
)
3491 return MESA_FORMAT_A8B8G8R8_UNORM
;
3492 else if (format
== GL_BGRA
)
3493 return MESA_FORMAT_A8R8G8B8_UNORM
;
3494 else if (format
== GL_ABGR_EXT
)
3495 return MESA_FORMAT_R8G8B8A8_UNORM
;
3496 else if (format
== GL_RGBA_INTEGER
)
3497 return MESA_FORMAT_A8B8G8R8_UINT
;
3498 else if (format
== GL_BGRA_INTEGER
)
3499 return MESA_FORMAT_A8R8G8B8_UINT
;
3501 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3502 if (format
== GL_RGBA
)
3503 return MESA_FORMAT_R8G8B8A8_UNORM
;
3504 else if (format
== GL_BGRA
)
3505 return MESA_FORMAT_B8G8R8A8_UNORM
;
3506 else if (format
== GL_ABGR_EXT
)
3507 return MESA_FORMAT_A8B8G8R8_UNORM
;
3508 else if (format
== GL_RGBA_INTEGER
)
3509 return MESA_FORMAT_R8G8B8A8_UINT
;
3510 else if (format
== GL_BGRA_INTEGER
)
3511 return MESA_FORMAT_B8G8R8A8_UINT
;
3513 case GL_UNSIGNED_SHORT_8_8_MESA
:
3514 if (format
== GL_YCBCR_MESA
)
3515 return MESA_FORMAT_YCBCR
;
3517 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3518 if (format
== GL_YCBCR_MESA
)
3519 return MESA_FORMAT_YCBCR_REV
;
3521 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3522 if (format
== GL_RGB
)
3523 return MESA_FORMAT_R11G11B10_FLOAT
;
3526 if (format
== GL_DEPTH_COMPONENT
)
3527 return MESA_FORMAT_Z_FLOAT32
;
3529 case GL_UNSIGNED_INT
:
3530 if (format
== GL_DEPTH_COMPONENT
)
3531 return MESA_FORMAT_Z_UNORM32
;
3533 case GL_UNSIGNED_SHORT
:
3534 if (format
== GL_DEPTH_COMPONENT
)
3535 return MESA_FORMAT_Z_UNORM16
;
3537 case GL_UNSIGNED_INT_24_8
:
3538 if (format
== GL_DEPTH_STENCIL
)
3539 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3541 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3542 if (format
== GL_DEPTH_STENCIL
)
3543 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3549 /* If we got here it means that we could not find a Mesa format that
3550 * matches the GL format/type provided. We may need to add a new Mesa
3551 * format in that case.
3553 unreachable("Unsupported format");