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
) {
1576 case GL_DEPTH_COMPONENT
:
1579 case GL_LUMINANCE_ALPHA
:
1580 case GL_DEPTH_STENCIL
:
1593 * If format is a generic compressed format, return the corresponding
1594 * non-compressed format. For other formats, return the format as-is.
1597 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1600 case GL_COMPRESSED_RED
:
1602 case GL_COMPRESSED_RG
:
1604 case GL_COMPRESSED_RGB
:
1606 case GL_COMPRESSED_RGBA
:
1608 case GL_COMPRESSED_ALPHA
:
1610 case GL_COMPRESSED_LUMINANCE
:
1611 return GL_LUMINANCE
;
1612 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1613 return GL_LUMINANCE_ALPHA
;
1614 case GL_COMPRESSED_INTENSITY
:
1615 return GL_INTENSITY
;
1617 case GL_COMPRESSED_SRGB
:
1619 case GL_COMPRESSED_SRGB_ALPHA
:
1620 return GL_SRGB_ALPHA
;
1621 case GL_COMPRESSED_SLUMINANCE
:
1622 return GL_SLUMINANCE
;
1623 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1624 return GL_SLUMINANCE_ALPHA
;
1632 * Return the equivalent non-generic internal format.
1633 * This is useful for comparing whether two internal formats are equivalent.
1636 _mesa_get_nongeneric_internalformat(GLenum format
)
1639 /* GL 1.1 formats. */
1647 case GL_LUMINANCE_ALPHA
:
1648 return GL_LUMINANCE8_ALPHA8
;
1651 return GL_LUMINANCE8
;
1655 return GL_INTENSITY8
;
1657 /* GL_ARB_texture_rg */
1663 /* GL_EXT_texture_sRGB */
1667 return GL_SRGB8_ALPHA8
;
1669 return GL_SLUMINANCE8
;
1670 case GL_SLUMINANCE_ALPHA
:
1671 return GL_SLUMINANCE8_ALPHA8
;
1673 /* GL_EXT_texture_snorm */
1675 return GL_RGBA8_SNORM
;
1677 return GL_RGB8_SNORM
;
1679 return GL_RG8_SNORM
;
1682 case GL_LUMINANCE_ALPHA_SNORM
:
1683 return GL_LUMINANCE8_ALPHA8_SNORM
;
1684 case GL_LUMINANCE_SNORM
:
1685 return GL_LUMINANCE8_SNORM
;
1686 case GL_ALPHA_SNORM
:
1687 return GL_ALPHA8_SNORM
;
1688 case GL_INTENSITY_SNORM
:
1689 return GL_INTENSITY8_SNORM
;
1698 * Convert an sRGB internal format to linear.
1701 _mesa_get_linear_internalformat(GLenum format
)
1710 case GL_SRGB8_ALPHA8
:
1712 case GL_SLUMINANCE8
:
1713 return GL_LUMINANCE8
;
1715 return GL_LUMINANCE
;
1716 case GL_SLUMINANCE_ALPHA
:
1717 return GL_LUMINANCE_ALPHA
;
1718 case GL_SLUMINANCE8_ALPHA8
:
1719 return GL_LUMINANCE8_ALPHA8
;
1727 * Do error checking of format/type combinations for glReadPixels,
1728 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1729 * and type values, we may either generate GL_INVALID_OPERATION or
1732 * \param format pixel format.
1733 * \param type pixel type.
1735 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1738 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1739 GLenum format
, GLenum type
)
1741 /* From OpenGL 3.3 spec, page 220:
1742 * "If the format is DEPTH_STENCIL, then values are taken from
1743 * both the depth buffer and the stencil buffer. If there is no
1744 * depth buffer or if there is no stencil buffer, then the error
1745 * INVALID_OPERATION occurs. If the type parameter is not
1746 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1747 * error INVALID_ENUM occurs."
1749 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1750 * cannot be used to read depth or stencil in that API.
1752 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1753 && type
!= GL_UNSIGNED_INT_24_8
1754 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1755 return GL_INVALID_ENUM
;
1757 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1760 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1761 return GL_INVALID_ENUM
;
1765 case GL_UNSIGNED_BYTE_3_3_2
:
1766 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1767 case GL_UNSIGNED_SHORT_5_6_5
:
1768 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1769 if (format
== GL_RGB
) {
1772 if (format
== GL_RGB_INTEGER_EXT
&&
1773 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1776 return GL_INVALID_OPERATION
;
1778 case GL_UNSIGNED_SHORT_4_4_4_4
:
1779 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1780 case GL_UNSIGNED_INT_8_8_8_8
:
1781 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1782 if (format
== GL_RGBA
||
1783 format
== GL_BGRA
||
1784 format
== GL_ABGR_EXT
) {
1787 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1788 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1791 return GL_INVALID_OPERATION
;
1793 case GL_UNSIGNED_SHORT_5_5_5_1
:
1794 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1795 case GL_UNSIGNED_INT_10_10_10_2
:
1796 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1797 if (format
== GL_RGBA
||
1798 format
== GL_BGRA
) {
1801 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1802 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1805 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1806 ctx
->API
== API_OPENGLES2
) {
1807 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1809 return GL_INVALID_OPERATION
;
1811 case GL_UNSIGNED_INT_24_8
:
1812 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1813 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1816 if (format
!= GL_DEPTH_STENCIL
) {
1817 return GL_INVALID_OPERATION
;
1821 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1822 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1823 return GL_INVALID_ENUM
;
1825 if (format
!= GL_DEPTH_STENCIL
) {
1826 return GL_INVALID_OPERATION
;
1830 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1831 if (!ctx
->Extensions
.EXT_packed_float
) {
1832 return GL_INVALID_ENUM
;
1834 if (format
!= GL_RGB
) {
1835 return GL_INVALID_OPERATION
;
1839 case GL_HALF_FLOAT_OES
:
1843 case GL_LUMINANCE_ALPHA
:
1849 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1852 return GL_INVALID_OPERATION
;
1856 ; /* fall-through */
1859 /* now, for each format, check the type for compatibility */
1861 case GL_COLOR_INDEX
:
1862 case GL_STENCIL_INDEX
:
1866 case GL_UNSIGNED_BYTE
:
1868 case GL_UNSIGNED_SHORT
:
1870 case GL_UNSIGNED_INT
:
1875 return GL_INVALID_ENUM
;
1882 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1886 case GL_LUMINANCE_ALPHA
:
1887 case GL_DEPTH_COMPONENT
:
1890 case GL_UNSIGNED_BYTE
:
1892 case GL_UNSIGNED_SHORT
:
1894 case GL_UNSIGNED_INT
:
1899 return GL_INVALID_ENUM
;
1903 if (!ctx
->Extensions
.ARB_texture_rg
)
1904 return GL_INVALID_ENUM
;
1907 case GL_UNSIGNED_BYTE
:
1909 case GL_UNSIGNED_SHORT
:
1911 case GL_UNSIGNED_INT
:
1916 return GL_INVALID_ENUM
;
1922 case GL_UNSIGNED_BYTE
:
1924 case GL_UNSIGNED_SHORT
:
1926 case GL_UNSIGNED_INT
:
1928 case GL_UNSIGNED_BYTE_3_3_2
:
1929 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1930 case GL_UNSIGNED_SHORT_5_6_5
:
1931 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1934 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1935 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1936 return (ctx
->API
== API_OPENGLES2
)
1937 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1938 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1939 return ctx
->Extensions
.EXT_texture_shared_exponent
1940 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1941 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1942 return ctx
->Extensions
.EXT_packed_float
1943 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1945 return GL_INVALID_ENUM
;
1950 /* NOTE: no packed types are supported with BGR. That's
1951 * intentional, according to the GL spec.
1954 case GL_UNSIGNED_BYTE
:
1956 case GL_UNSIGNED_SHORT
:
1958 case GL_UNSIGNED_INT
:
1963 return GL_INVALID_ENUM
;
1970 case GL_UNSIGNED_BYTE
:
1972 case GL_UNSIGNED_SHORT
:
1974 case GL_UNSIGNED_INT
:
1976 case GL_UNSIGNED_SHORT_4_4_4_4
:
1977 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1978 case GL_UNSIGNED_SHORT_5_5_5_1
:
1979 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1980 case GL_UNSIGNED_INT_8_8_8_8
:
1981 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1982 case GL_UNSIGNED_INT_10_10_10_2
:
1983 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1987 return GL_INVALID_ENUM
;
1993 case GL_UNSIGNED_BYTE
:
1995 case GL_UNSIGNED_SHORT
:
1997 case GL_UNSIGNED_INT
:
1999 case GL_UNSIGNED_SHORT_4_4_4_4
:
2000 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2001 case GL_UNSIGNED_INT_8_8_8_8
:
2002 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2006 return GL_INVALID_ENUM
;
2010 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2011 return GL_INVALID_ENUM
;
2012 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2013 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2016 return GL_INVALID_OPERATION
;
2018 case GL_DEPTH_STENCIL
:
2019 if (type
== GL_UNSIGNED_INT_24_8
)
2021 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2022 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2025 return GL_INVALID_ENUM
;
2027 /* integer-valued formats */
2028 case GL_RED_INTEGER_EXT
:
2029 case GL_GREEN_INTEGER_EXT
:
2030 case GL_BLUE_INTEGER_EXT
:
2031 case GL_ALPHA_INTEGER_EXT
:
2035 case GL_UNSIGNED_BYTE
:
2037 case GL_UNSIGNED_SHORT
:
2039 case GL_UNSIGNED_INT
:
2040 return (ctx
->Version
>= 30 ||
2041 ctx
->Extensions
.EXT_texture_integer
)
2042 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2044 return GL_INVALID_ENUM
;
2047 case GL_RGB_INTEGER_EXT
:
2050 case GL_UNSIGNED_BYTE
:
2052 case GL_UNSIGNED_SHORT
:
2054 case GL_UNSIGNED_INT
:
2055 return (ctx
->Version
>= 30 ||
2056 ctx
->Extensions
.EXT_texture_integer
)
2057 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2058 case GL_UNSIGNED_BYTE_3_3_2
:
2059 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2060 case GL_UNSIGNED_SHORT_5_6_5
:
2061 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2062 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2063 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2065 return GL_INVALID_ENUM
;
2068 case GL_BGR_INTEGER_EXT
:
2071 case GL_UNSIGNED_BYTE
:
2073 case GL_UNSIGNED_SHORT
:
2075 case GL_UNSIGNED_INT
:
2076 /* NOTE: no packed formats w/ BGR format */
2077 return (ctx
->Version
>= 30 ||
2078 ctx
->Extensions
.EXT_texture_integer
)
2079 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2081 return GL_INVALID_ENUM
;
2084 case GL_RGBA_INTEGER_EXT
:
2085 case GL_BGRA_INTEGER_EXT
:
2088 case GL_UNSIGNED_BYTE
:
2090 case GL_UNSIGNED_SHORT
:
2092 case GL_UNSIGNED_INT
:
2093 return (ctx
->Version
>= 30 ||
2094 ctx
->Extensions
.EXT_texture_integer
)
2095 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2096 case GL_UNSIGNED_SHORT_4_4_4_4
:
2097 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2098 case GL_UNSIGNED_SHORT_5_5_5_1
:
2099 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2100 case GL_UNSIGNED_INT_8_8_8_8
:
2101 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2102 case GL_UNSIGNED_INT_10_10_10_2
:
2103 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2104 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2105 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2107 return GL_INVALID_ENUM
;
2110 case GL_LUMINANCE_INTEGER_EXT
:
2111 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2114 case GL_UNSIGNED_BYTE
:
2116 case GL_UNSIGNED_SHORT
:
2118 case GL_UNSIGNED_INT
:
2119 return ctx
->Extensions
.EXT_texture_integer
2120 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2122 return GL_INVALID_ENUM
;
2126 return GL_INVALID_ENUM
;
2133 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2134 * and glTex[Sub]Image.
2135 * \return error code, or GL_NO_ERROR.
2138 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2139 GLenum format
, GLenum type
,
2140 unsigned dimensions
)
2142 GLboolean type_valid
= GL_TRUE
;
2147 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2148 return GL_INVALID_VALUE
;
2152 case GL_LUMINANCE_ALPHA
:
2153 type_valid
= (type
== GL_UNSIGNED_BYTE
2155 || type
== GL_HALF_FLOAT_OES
);
2159 type_valid
= (type
== GL_UNSIGNED_BYTE
2160 || type
== GL_UNSIGNED_SHORT_5_6_5
2162 || type
== GL_HALF_FLOAT_OES
);
2166 type_valid
= (type
== GL_UNSIGNED_BYTE
2167 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2168 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2170 || type
== GL_HALF_FLOAT_OES
2171 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2174 case GL_DEPTH_COMPONENT
:
2175 /* This format is filtered against invalid dimensionalities elsewhere.
2177 type_valid
= (type
== GL_UNSIGNED_SHORT
2178 || type
== GL_UNSIGNED_INT
);
2181 case GL_DEPTH_STENCIL
:
2182 /* This format is filtered against invalid dimensionalities elsewhere.
2184 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2188 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2190 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2191 * the format does not appear to be allowed for 3D textures in OpenGL
2194 if (dimensions
!= 2)
2195 return GL_INVALID_VALUE
;
2200 return GL_INVALID_VALUE
;
2203 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2207 * Return the simple base format for a given internal texture format.
2208 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2210 * \param ctx GL context.
2211 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2213 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2214 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2216 * This is the format which is used during texture application (i.e. the
2217 * texture format and env mode determine the arithmetic used.
2220 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2222 switch (internalFormat
) {
2228 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2233 case GL_LUMINANCE12
:
2234 case GL_LUMINANCE16
:
2235 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2237 case GL_LUMINANCE_ALPHA
:
2238 case GL_LUMINANCE4_ALPHA4
:
2239 case GL_LUMINANCE6_ALPHA2
:
2240 case GL_LUMINANCE8_ALPHA8
:
2241 case GL_LUMINANCE12_ALPHA4
:
2242 case GL_LUMINANCE12_ALPHA12
:
2243 case GL_LUMINANCE16_ALPHA16
:
2244 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2248 case GL_INTENSITY12
:
2249 case GL_INTENSITY16
:
2250 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2252 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2263 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2277 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2279 if (_mesa_is_gles(ctx
)) {
2280 switch (internalFormat
) {
2288 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2289 switch (internalFormat
) {
2297 if (ctx
->Extensions
.ARB_depth_texture
) {
2298 switch (internalFormat
) {
2299 case GL_DEPTH_COMPONENT
:
2300 case GL_DEPTH_COMPONENT16
:
2301 case GL_DEPTH_COMPONENT24
:
2302 case GL_DEPTH_COMPONENT32
:
2303 return GL_DEPTH_COMPONENT
;
2304 case GL_DEPTH_STENCIL
:
2305 case GL_DEPTH24_STENCIL8
:
2306 return GL_DEPTH_STENCIL
;
2312 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2313 switch (internalFormat
) {
2314 case GL_STENCIL_INDEX
:
2315 case GL_STENCIL_INDEX1
:
2316 case GL_STENCIL_INDEX4
:
2317 case GL_STENCIL_INDEX8
:
2318 case GL_STENCIL_INDEX16
:
2319 return GL_STENCIL_INDEX
;
2325 switch (internalFormat
) {
2326 case GL_COMPRESSED_ALPHA
:
2328 case GL_COMPRESSED_LUMINANCE
:
2329 return GL_LUMINANCE
;
2330 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2331 return GL_LUMINANCE_ALPHA
;
2332 case GL_COMPRESSED_INTENSITY
:
2333 return GL_INTENSITY
;
2334 case GL_COMPRESSED_RGB
:
2336 case GL_COMPRESSED_RGBA
:
2342 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2343 GLenum base_compressed
=
2344 _mesa_gl_compressed_format_base_format(internalFormat
);
2345 if (base_compressed
)
2346 return base_compressed
;
2349 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2350 _mesa_is_astc_format(internalFormat
))
2353 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2354 if (internalFormat
== GL_YCBCR_MESA
)
2355 return GL_YCBCR_MESA
;
2358 if (ctx
->Extensions
.ARB_texture_float
) {
2359 switch (internalFormat
) {
2360 case GL_ALPHA16F_ARB
:
2361 case GL_ALPHA32F_ARB
:
2363 case GL_RGBA16F_ARB
:
2364 case GL_RGBA32F_ARB
:
2369 case GL_INTENSITY16F_ARB
:
2370 case GL_INTENSITY32F_ARB
:
2371 return GL_INTENSITY
;
2372 case GL_LUMINANCE16F_ARB
:
2373 case GL_LUMINANCE32F_ARB
:
2374 return GL_LUMINANCE
;
2375 case GL_LUMINANCE_ALPHA16F_ARB
:
2376 case GL_LUMINANCE_ALPHA32F_ARB
:
2377 return GL_LUMINANCE_ALPHA
;
2383 if (ctx
->Extensions
.EXT_texture_snorm
) {
2384 switch (internalFormat
) {
2395 case GL_RGB16_SNORM
:
2398 case GL_RGBA8_SNORM
:
2399 case GL_RGBA16_SNORM
:
2401 case GL_ALPHA_SNORM
:
2402 case GL_ALPHA8_SNORM
:
2403 case GL_ALPHA16_SNORM
:
2405 case GL_LUMINANCE_SNORM
:
2406 case GL_LUMINANCE8_SNORM
:
2407 case GL_LUMINANCE16_SNORM
:
2408 return GL_LUMINANCE
;
2409 case GL_LUMINANCE_ALPHA_SNORM
:
2410 case GL_LUMINANCE8_ALPHA8_SNORM
:
2411 case GL_LUMINANCE16_ALPHA16_SNORM
:
2412 return GL_LUMINANCE_ALPHA
;
2413 case GL_INTENSITY_SNORM
:
2414 case GL_INTENSITY8_SNORM
:
2415 case GL_INTENSITY16_SNORM
:
2416 return GL_INTENSITY
;
2422 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2423 switch (internalFormat
) {
2426 case GL_COMPRESSED_SRGB_EXT
:
2428 case GL_SRGB_ALPHA_EXT
:
2429 case GL_SRGB8_ALPHA8_EXT
:
2430 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2432 case GL_SLUMINANCE_ALPHA_EXT
:
2433 case GL_SLUMINANCE8_ALPHA8_EXT
:
2434 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2435 return GL_LUMINANCE_ALPHA
;
2436 case GL_SLUMINANCE_EXT
:
2437 case GL_SLUMINANCE8_EXT
:
2438 case GL_COMPRESSED_SLUMINANCE_EXT
:
2439 return GL_LUMINANCE
;
2445 if (ctx
->Version
>= 30 ||
2446 ctx
->Extensions
.EXT_texture_integer
) {
2447 switch (internalFormat
) {
2448 case GL_RGBA8UI_EXT
:
2449 case GL_RGBA16UI_EXT
:
2450 case GL_RGBA32UI_EXT
:
2452 case GL_RGBA16I_EXT
:
2453 case GL_RGBA32I_EXT
:
2457 case GL_RGB16UI_EXT
:
2458 case GL_RGB32UI_EXT
:
2466 if (ctx
->Extensions
.EXT_texture_integer
) {
2467 switch (internalFormat
) {
2468 case GL_ALPHA8UI_EXT
:
2469 case GL_ALPHA16UI_EXT
:
2470 case GL_ALPHA32UI_EXT
:
2471 case GL_ALPHA8I_EXT
:
2472 case GL_ALPHA16I_EXT
:
2473 case GL_ALPHA32I_EXT
:
2475 case GL_INTENSITY8UI_EXT
:
2476 case GL_INTENSITY16UI_EXT
:
2477 case GL_INTENSITY32UI_EXT
:
2478 case GL_INTENSITY8I_EXT
:
2479 case GL_INTENSITY16I_EXT
:
2480 case GL_INTENSITY32I_EXT
:
2481 return GL_INTENSITY
;
2482 case GL_LUMINANCE8UI_EXT
:
2483 case GL_LUMINANCE16UI_EXT
:
2484 case GL_LUMINANCE32UI_EXT
:
2485 case GL_LUMINANCE8I_EXT
:
2486 case GL_LUMINANCE16I_EXT
:
2487 case GL_LUMINANCE32I_EXT
:
2488 return GL_LUMINANCE
;
2489 case GL_LUMINANCE_ALPHA8UI_EXT
:
2490 case GL_LUMINANCE_ALPHA16UI_EXT
:
2491 case GL_LUMINANCE_ALPHA32UI_EXT
:
2492 case GL_LUMINANCE_ALPHA8I_EXT
:
2493 case GL_LUMINANCE_ALPHA16I_EXT
:
2494 case GL_LUMINANCE_ALPHA32I_EXT
:
2495 return GL_LUMINANCE_ALPHA
;
2501 if (ctx
->Extensions
.ARB_texture_rg
) {
2502 switch (internalFormat
) {
2505 if (!ctx
->Extensions
.ARB_texture_float
)
2514 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2520 case GL_COMPRESSED_RED
:
2525 if (!ctx
->Extensions
.ARB_texture_float
)
2534 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2540 case GL_COMPRESSED_RG
:
2547 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2548 switch (internalFormat
) {
2549 case GL_RGB9_E5_EXT
:
2556 if (ctx
->Extensions
.EXT_packed_float
) {
2557 switch (internalFormat
) {
2558 case GL_R11F_G11F_B10F_EXT
:
2565 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2566 switch (internalFormat
) {
2567 case GL_DEPTH_COMPONENT32F
:
2568 return GL_DEPTH_COMPONENT
;
2569 case GL_DEPTH32F_STENCIL8
:
2570 return GL_DEPTH_STENCIL
;
2576 return -1; /* error */
2580 * Returns the effective internal format from a texture format and type.
2581 * This is used by texture image operations internally for validation, when
2582 * the specified internal format is a base (unsized) format.
2584 * This method will only return a valid effective internal format if the
2585 * combination of format, type and internal format in base form, is acceptable.
2587 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2588 * in extensions, to unambiguously correspond to the given base format, then
2589 * that internal format is returned as the effective. Otherwise, if the
2590 * combination is accepted but a single effective format is not defined, the
2591 * passed base format will be returned instead.
2593 * \param format the texture format
2594 * \param type the texture type
2597 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2601 case GL_UNSIGNED_BYTE
:
2611 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2612 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2613 * internal formats, they do not correspond to GL constants, so the base
2614 * format is returned instead.
2617 case GL_LUMINANCE_ALPHA
:
2624 case GL_UNSIGNED_SHORT_4_4_4_4
:
2625 if (format
== GL_RGBA
)
2629 case GL_UNSIGNED_SHORT_5_5_5_1
:
2630 if (format
== GL_RGBA
)
2634 case GL_UNSIGNED_SHORT_5_6_5
:
2635 if (format
== GL_RGB
)
2639 /* OES_packed_depth_stencil */
2640 case GL_UNSIGNED_INT_24_8
:
2641 if (format
== GL_DEPTH_STENCIL
)
2642 return GL_DEPTH24_STENCIL8
;
2645 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2646 if (format
== GL_DEPTH_STENCIL
)
2647 return GL_DEPTH32F_STENCIL8
;
2650 case GL_UNSIGNED_SHORT
:
2651 if (format
== GL_DEPTH_COMPONENT
)
2652 return GL_DEPTH_COMPONENT16
;
2655 case GL_UNSIGNED_INT
:
2656 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2659 if (format
== GL_DEPTH_COMPONENT
)
2663 /* OES_texture_float and OES_texture_half_float */
2665 if (format
== GL_DEPTH_COMPONENT
)
2666 return GL_DEPTH_COMPONENT32F
;
2668 case GL_HALF_FLOAT_OES
:
2672 case GL_LUMINANCE_ALPHA
:
2688 /* GL_EXT_texture_type_2_10_10_10_REV */
2689 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2698 /* fall through and return NONE */
2706 * Do error checking of format/type combinations for OpenGL ES 3
2708 * \return error code, or GL_NO_ERROR.
2711 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2712 GLenum format
, GLenum type
,
2713 GLenum internalFormat
)
2715 /* If internalFormat is an unsized format, then the effective internal
2716 * format derived from format and type should be used instead. Page 127,
2717 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2719 * "if internalformat is a base internal format, the effective
2720 * internal format is a sized internal format that is derived
2721 * from the format and type for internal use by the GL.
2722 * Table 3.12 specifies the mapping of format and type to effective
2723 * internal formats. The effective internal format is used by the GL
2724 * for purposes such as texture completeness or type checks for
2725 * CopyTex* commands. In these cases, the GL is required to operate
2726 * as if the effective internal format was used as the internalformat
2727 * when specifying the texture data."
2729 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2730 GLenum effectiveInternalFormat
=
2731 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2733 if (effectiveInternalFormat
== GL_NONE
)
2734 return GL_INVALID_OPERATION
;
2736 GLenum baseInternalFormat
;
2737 if (internalFormat
== GL_BGRA_EXT
) {
2738 /* Unfortunately, _mesa_base_tex_format returns a base format of
2739 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2740 * asking the question, "what channels does this format have?"
2741 * However, if we're trying to determine if two internal formats
2742 * match in the ES3 sense, we actually want GL_BGRA.
2744 baseInternalFormat
= GL_BGRA_EXT
;
2746 baseInternalFormat
=
2747 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2750 if (internalFormat
!= baseInternalFormat
)
2751 return GL_INVALID_OPERATION
;
2753 internalFormat
= effectiveInternalFormat
;
2758 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2759 return GL_INVALID_OPERATION
;
2764 case GL_UNSIGNED_BYTE
:
2765 switch (internalFormat
) {
2770 case GL_SRGB8_ALPHA8_EXT
:
2773 return GL_INVALID_OPERATION
;
2778 if (internalFormat
!= GL_RGBA8_SNORM
)
2779 return GL_INVALID_OPERATION
;
2782 case GL_UNSIGNED_SHORT_4_4_4_4
:
2783 switch (internalFormat
) {
2788 return GL_INVALID_OPERATION
;
2792 case GL_UNSIGNED_SHORT_5_5_5_1
:
2793 switch (internalFormat
) {
2798 return GL_INVALID_OPERATION
;
2802 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2803 switch (internalFormat
) {
2804 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2809 return GL_INVALID_OPERATION
;
2814 if (internalFormat
!= GL_RGBA16F
)
2815 return GL_INVALID_OPERATION
;
2819 switch (internalFormat
) {
2824 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2827 return GL_INVALID_OPERATION
;
2831 case GL_HALF_FLOAT_OES
:
2832 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2835 return GL_INVALID_OPERATION
;
2839 case GL_RGBA_INTEGER
:
2841 case GL_UNSIGNED_BYTE
:
2842 if (internalFormat
!= GL_RGBA8UI
)
2843 return GL_INVALID_OPERATION
;
2847 if (internalFormat
!= GL_RGBA8I
)
2848 return GL_INVALID_OPERATION
;
2851 case GL_UNSIGNED_SHORT
:
2852 if (internalFormat
!= GL_RGBA16UI
)
2853 return GL_INVALID_OPERATION
;
2857 if (internalFormat
!= GL_RGBA16I
)
2858 return GL_INVALID_OPERATION
;
2861 case GL_UNSIGNED_INT
:
2862 if (internalFormat
!= GL_RGBA32UI
)
2863 return GL_INVALID_OPERATION
;
2867 if (internalFormat
!= GL_RGBA32I
)
2868 return GL_INVALID_OPERATION
;
2871 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2872 if (internalFormat
!= GL_RGB10_A2UI
)
2873 return GL_INVALID_OPERATION
;
2877 return GL_INVALID_OPERATION
;
2883 case GL_UNSIGNED_BYTE
:
2884 switch (internalFormat
) {
2891 return GL_INVALID_OPERATION
;
2896 if (internalFormat
!= GL_RGB8_SNORM
)
2897 return GL_INVALID_OPERATION
;
2900 case GL_UNSIGNED_SHORT_5_6_5
:
2901 switch (internalFormat
) {
2906 return GL_INVALID_OPERATION
;
2910 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2911 if (internalFormat
!= GL_R11F_G11F_B10F
)
2912 return GL_INVALID_OPERATION
;
2915 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2916 if (internalFormat
!= GL_RGB9_E5
)
2917 return GL_INVALID_OPERATION
;
2921 switch (internalFormat
) {
2923 case GL_R11F_G11F_B10F
:
2927 return GL_INVALID_OPERATION
;
2932 switch (internalFormat
) {
2935 case GL_R11F_G11F_B10F
:
2939 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2942 return GL_INVALID_OPERATION
;
2946 case GL_HALF_FLOAT_OES
:
2947 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2948 return GL_INVALID_OPERATION
;
2951 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2952 switch (internalFormat
) {
2953 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2956 return GL_INVALID_OPERATION
;
2961 return GL_INVALID_OPERATION
;
2965 case GL_RGB_INTEGER
:
2967 case GL_UNSIGNED_BYTE
:
2968 if (internalFormat
!= GL_RGB8UI
)
2969 return GL_INVALID_OPERATION
;
2973 if (internalFormat
!= GL_RGB8I
)
2974 return GL_INVALID_OPERATION
;
2977 case GL_UNSIGNED_SHORT
:
2978 if (internalFormat
!= GL_RGB16UI
)
2979 return GL_INVALID_OPERATION
;
2983 if (internalFormat
!= GL_RGB16I
)
2984 return GL_INVALID_OPERATION
;
2987 case GL_UNSIGNED_INT
:
2988 if (internalFormat
!= GL_RGB32UI
)
2989 return GL_INVALID_OPERATION
;
2993 if (internalFormat
!= GL_RGB32I
)
2994 return GL_INVALID_OPERATION
;
2998 return GL_INVALID_OPERATION
;
3004 case GL_UNSIGNED_BYTE
:
3005 if (internalFormat
!= GL_RG8
)
3006 return GL_INVALID_OPERATION
;
3010 if (internalFormat
!= GL_RG8_SNORM
)
3011 return GL_INVALID_OPERATION
;
3015 case GL_HALF_FLOAT_OES
:
3016 switch (internalFormat
) {
3020 if (ctx
->Extensions
.ARB_texture_rg
&&
3021 ctx
->Extensions
.OES_texture_half_float
)
3025 return GL_INVALID_OPERATION
;
3030 switch (internalFormat
) {
3035 if (ctx
->Extensions
.ARB_texture_rg
&&
3036 ctx
->Extensions
.OES_texture_float
)
3040 return GL_INVALID_OPERATION
;
3045 return GL_INVALID_OPERATION
;
3051 case GL_UNSIGNED_BYTE
:
3052 if (internalFormat
!= GL_RG8UI
)
3053 return GL_INVALID_OPERATION
;
3057 if (internalFormat
!= GL_RG8I
)
3058 return GL_INVALID_OPERATION
;
3061 case GL_UNSIGNED_SHORT
:
3062 if (internalFormat
!= GL_RG16UI
)
3063 return GL_INVALID_OPERATION
;
3067 if (internalFormat
!= GL_RG16I
)
3068 return GL_INVALID_OPERATION
;
3071 case GL_UNSIGNED_INT
:
3072 if (internalFormat
!= GL_RG32UI
)
3073 return GL_INVALID_OPERATION
;
3077 if (internalFormat
!= GL_RG32I
)
3078 return GL_INVALID_OPERATION
;
3082 return GL_INVALID_OPERATION
;
3088 case GL_UNSIGNED_BYTE
:
3089 if (internalFormat
!= GL_R8
)
3090 return GL_INVALID_OPERATION
;
3094 if (internalFormat
!= GL_R8_SNORM
)
3095 return GL_INVALID_OPERATION
;
3099 case GL_HALF_FLOAT_OES
:
3100 switch (internalFormat
) {
3105 if (ctx
->Extensions
.ARB_texture_rg
&&
3106 ctx
->Extensions
.OES_texture_half_float
)
3110 return GL_INVALID_OPERATION
;
3115 switch (internalFormat
) {
3120 if (ctx
->Extensions
.ARB_texture_rg
&&
3121 ctx
->Extensions
.OES_texture_float
)
3125 return GL_INVALID_OPERATION
;
3130 return GL_INVALID_OPERATION
;
3134 case GL_RED_INTEGER
:
3136 case GL_UNSIGNED_BYTE
:
3137 if (internalFormat
!= GL_R8UI
)
3138 return GL_INVALID_OPERATION
;
3142 if (internalFormat
!= GL_R8I
)
3143 return GL_INVALID_OPERATION
;
3146 case GL_UNSIGNED_SHORT
:
3147 if (internalFormat
!= GL_R16UI
)
3148 return GL_INVALID_OPERATION
;
3152 if (internalFormat
!= GL_R16I
)
3153 return GL_INVALID_OPERATION
;
3156 case GL_UNSIGNED_INT
:
3157 if (internalFormat
!= GL_R32UI
)
3158 return GL_INVALID_OPERATION
;
3162 if (internalFormat
!= GL_R32I
)
3163 return GL_INVALID_OPERATION
;
3167 return GL_INVALID_OPERATION
;
3171 case GL_DEPTH_COMPONENT
:
3173 case GL_UNSIGNED_SHORT
:
3174 if (internalFormat
!= GL_DEPTH_COMPONENT
3175 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3176 return GL_INVALID_OPERATION
;
3179 case GL_UNSIGNED_INT
:
3180 switch (internalFormat
) {
3181 case GL_DEPTH_COMPONENT
:
3182 case GL_DEPTH_COMPONENT16
:
3183 case GL_DEPTH_COMPONENT24
:
3186 return GL_INVALID_OPERATION
;
3191 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3192 return GL_INVALID_OPERATION
;
3196 return GL_INVALID_OPERATION
;
3200 case GL_DEPTH_STENCIL
:
3202 case GL_UNSIGNED_INT_24_8
:
3203 if (internalFormat
!= GL_DEPTH_STENCIL
3204 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3205 return GL_INVALID_OPERATION
;
3208 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3209 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3210 return GL_INVALID_OPERATION
;
3214 return GL_INVALID_OPERATION
;
3218 case GL_STENCIL_INDEX
:
3219 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3220 type
!= GL_UNSIGNED_BYTE
||
3221 internalFormat
!= GL_STENCIL_INDEX8
) {
3222 return GL_INVALID_OPERATION
;
3228 case GL_LUMINANCE_ALPHA
:
3231 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3233 case GL_HALF_FLOAT_OES
:
3234 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3237 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3238 return GL_INVALID_OPERATION
;
3246 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3248 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3249 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3250 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3251 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3255 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3259 case GL_RGBA_INTEGER_EXT
:
3260 set_swizzle(swizzle
, 0, 1, 2, 3);
3263 case GL_BGRA_INTEGER_EXT
:
3264 set_swizzle(swizzle
, 2, 1, 0, 3);
3267 set_swizzle(swizzle
, 3, 2, 1, 0);
3270 case GL_RGB_INTEGER_EXT
:
3271 set_swizzle(swizzle
, 0, 1, 2, 5);
3274 case GL_BGR_INTEGER_EXT
:
3275 set_swizzle(swizzle
, 2, 1, 0, 5);
3277 case GL_LUMINANCE_ALPHA
:
3278 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3279 set_swizzle(swizzle
, 0, 0, 0, 1);
3283 set_swizzle(swizzle
, 0, 1, 4, 5);
3286 case GL_RED_INTEGER_EXT
:
3287 set_swizzle(swizzle
, 0, 4, 4, 5);
3290 case GL_GREEN_INTEGER_EXT
:
3291 set_swizzle(swizzle
, 4, 0, 4, 5);
3294 case GL_BLUE_INTEGER_EXT
:
3295 set_swizzle(swizzle
, 4, 4, 0, 5);
3298 case GL_ALPHA_INTEGER_EXT
:
3299 set_swizzle(swizzle
, 4, 4, 4, 0);
3302 case GL_LUMINANCE_INTEGER_EXT
:
3303 set_swizzle(swizzle
, 0, 0, 0, 5);
3306 set_swizzle(swizzle
, 0, 0, 0, 0);
3314 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3315 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3316 * otherwise (for non-array formats).
3318 * This function will typically be used to compute a mesa format from a GL type
3319 * so we can then call _mesa_format_convert. This function does
3320 * not consider byte swapping, so it returns types assuming that no byte
3321 * swapping is involved. If byte swapping is involved then clients are supposed
3322 * to handle that on their side before calling _mesa_format_convert.
3324 * This function returns an uint32_t that can pack a mesa_format or a
3325 * mesa_array_format. Clients must check the mesa array format bit
3326 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3327 * format is a mesa_array_format or a mesa_format.
3330 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3332 bool is_array_format
= true;
3334 bool normalized
= false, is_float
= false, is_signed
= false;
3335 int num_channels
= 0, type_size
= 0;
3337 /* Extract array format type information from the OpenGL data type */
3339 case GL_UNSIGNED_BYTE
:
3346 case GL_UNSIGNED_SHORT
:
3353 case GL_UNSIGNED_INT
:
3361 case GL_HALF_FLOAT_OES
:
3372 is_array_format
= false;
3376 /* Extract array format swizzle information from the OpenGL format */
3377 if (is_array_format
)
3378 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3380 /* If this is an array format type after checking data type and format,
3381 * create the array format
3383 if (is_array_format
) {
3384 normalized
= !_mesa_is_enum_format_integer(format
);
3385 num_channels
= _mesa_components_in_format(format
);
3387 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3388 normalized
, num_channels
,
3389 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3392 /* Otherwise this is not an array format, so return the mesa_format
3393 * matching the OpenGL format and data type
3396 case GL_UNSIGNED_SHORT_5_6_5
:
3397 if (format
== GL_RGB
)
3398 return MESA_FORMAT_B5G6R5_UNORM
;
3399 else if (format
== GL_BGR
)
3400 return MESA_FORMAT_R5G6B5_UNORM
;
3401 else if (format
== GL_RGB_INTEGER
)
3402 return MESA_FORMAT_B5G6R5_UINT
;
3404 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3405 if (format
== GL_RGB
)
3406 return MESA_FORMAT_R5G6B5_UNORM
;
3407 else if (format
== GL_BGR
)
3408 return MESA_FORMAT_B5G6R5_UNORM
;
3409 else if (format
== GL_RGB_INTEGER
)
3410 return MESA_FORMAT_R5G6B5_UINT
;
3412 case GL_UNSIGNED_SHORT_4_4_4_4
:
3413 if (format
== GL_RGBA
)
3414 return MESA_FORMAT_A4B4G4R4_UNORM
;
3415 else if (format
== GL_BGRA
)
3416 return MESA_FORMAT_A4R4G4B4_UNORM
;
3417 else if (format
== GL_ABGR_EXT
)
3418 return MESA_FORMAT_R4G4B4A4_UNORM
;
3419 else if (format
== GL_RGBA_INTEGER
)
3420 return MESA_FORMAT_A4B4G4R4_UINT
;
3421 else if (format
== GL_BGRA_INTEGER
)
3422 return MESA_FORMAT_A4R4G4B4_UINT
;
3424 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3425 if (format
== GL_RGBA
)
3426 return MESA_FORMAT_R4G4B4A4_UNORM
;
3427 else if (format
== GL_BGRA
)
3428 return MESA_FORMAT_B4G4R4A4_UNORM
;
3429 else if (format
== GL_ABGR_EXT
)
3430 return MESA_FORMAT_A4B4G4R4_UNORM
;
3431 else if (format
== GL_RGBA_INTEGER
)
3432 return MESA_FORMAT_R4G4B4A4_UINT
;
3433 else if (format
== GL_BGRA_INTEGER
)
3434 return MESA_FORMAT_B4G4R4A4_UINT
;
3436 case GL_UNSIGNED_SHORT_5_5_5_1
:
3437 if (format
== GL_RGBA
)
3438 return MESA_FORMAT_A1B5G5R5_UNORM
;
3439 else if (format
== GL_BGRA
)
3440 return MESA_FORMAT_A1R5G5B5_UNORM
;
3441 else if (format
== GL_RGBA_INTEGER
)
3442 return MESA_FORMAT_A1B5G5R5_UINT
;
3443 else if (format
== GL_BGRA_INTEGER
)
3444 return MESA_FORMAT_A1R5G5B5_UINT
;
3446 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3447 if (format
== GL_RGBA
)
3448 return MESA_FORMAT_R5G5B5A1_UNORM
;
3449 else if (format
== GL_BGRA
)
3450 return MESA_FORMAT_B5G5R5A1_UNORM
;
3451 else if (format
== GL_RGBA_INTEGER
)
3452 return MESA_FORMAT_R5G5B5A1_UINT
;
3453 else if (format
== GL_BGRA_INTEGER
)
3454 return MESA_FORMAT_B5G5R5A1_UINT
;
3456 case GL_UNSIGNED_BYTE_3_3_2
:
3457 if (format
== GL_RGB
)
3458 return MESA_FORMAT_B2G3R3_UNORM
;
3459 else if (format
== GL_RGB_INTEGER
)
3460 return MESA_FORMAT_B2G3R3_UINT
;
3462 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3463 if (format
== GL_RGB
)
3464 return MESA_FORMAT_R3G3B2_UNORM
;
3465 else if (format
== GL_RGB_INTEGER
)
3466 return MESA_FORMAT_R3G3B2_UINT
;
3468 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3469 if (format
== GL_RGB
)
3470 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3472 case GL_UNSIGNED_INT_10_10_10_2
:
3473 if (format
== GL_RGBA
)
3474 return MESA_FORMAT_A2B10G10R10_UNORM
;
3475 else if (format
== GL_RGBA_INTEGER
)
3476 return MESA_FORMAT_A2B10G10R10_UINT
;
3477 else if (format
== GL_BGRA
)
3478 return MESA_FORMAT_A2R10G10B10_UNORM
;
3479 else if (format
== GL_BGRA_INTEGER
)
3480 return MESA_FORMAT_A2R10G10B10_UINT
;
3482 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3483 if (format
== GL_RGB
)
3484 return MESA_FORMAT_R10G10B10X2_UNORM
;
3485 if (format
== GL_RGBA
)
3486 return MESA_FORMAT_R10G10B10A2_UNORM
;
3487 else if (format
== GL_RGBA_INTEGER
)
3488 return MESA_FORMAT_R10G10B10A2_UINT
;
3489 else if (format
== GL_BGRA
)
3490 return MESA_FORMAT_B10G10R10A2_UNORM
;
3491 else if (format
== GL_BGRA_INTEGER
)
3492 return MESA_FORMAT_B10G10R10A2_UINT
;
3494 case GL_UNSIGNED_INT_8_8_8_8
:
3495 if (format
== GL_RGBA
)
3496 return MESA_FORMAT_A8B8G8R8_UNORM
;
3497 else if (format
== GL_BGRA
)
3498 return MESA_FORMAT_A8R8G8B8_UNORM
;
3499 else if (format
== GL_ABGR_EXT
)
3500 return MESA_FORMAT_R8G8B8A8_UNORM
;
3501 else if (format
== GL_RGBA_INTEGER
)
3502 return MESA_FORMAT_A8B8G8R8_UINT
;
3503 else if (format
== GL_BGRA_INTEGER
)
3504 return MESA_FORMAT_A8R8G8B8_UINT
;
3506 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3507 if (format
== GL_RGBA
)
3508 return MESA_FORMAT_R8G8B8A8_UNORM
;
3509 else if (format
== GL_BGRA
)
3510 return MESA_FORMAT_B8G8R8A8_UNORM
;
3511 else if (format
== GL_ABGR_EXT
)
3512 return MESA_FORMAT_A8B8G8R8_UNORM
;
3513 else if (format
== GL_RGBA_INTEGER
)
3514 return MESA_FORMAT_R8G8B8A8_UINT
;
3515 else if (format
== GL_BGRA_INTEGER
)
3516 return MESA_FORMAT_B8G8R8A8_UINT
;
3518 case GL_UNSIGNED_SHORT_8_8_MESA
:
3519 if (format
== GL_YCBCR_MESA
)
3520 return MESA_FORMAT_YCBCR
;
3522 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3523 if (format
== GL_YCBCR_MESA
)
3524 return MESA_FORMAT_YCBCR_REV
;
3526 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3527 if (format
== GL_RGB
)
3528 return MESA_FORMAT_R11G11B10_FLOAT
;
3531 if (format
== GL_DEPTH_COMPONENT
)
3532 return MESA_FORMAT_Z_FLOAT32
;
3534 case GL_UNSIGNED_INT
:
3535 if (format
== GL_DEPTH_COMPONENT
)
3536 return MESA_FORMAT_Z_UNORM32
;
3538 case GL_UNSIGNED_SHORT
:
3539 if (format
== GL_DEPTH_COMPONENT
)
3540 return MESA_FORMAT_Z_UNORM16
;
3542 case GL_UNSIGNED_INT_24_8
:
3543 if (format
== GL_DEPTH_STENCIL
)
3544 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3546 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3547 if (format
== GL_DEPTH_STENCIL
)
3548 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3554 /* If we got here it means that we could not find a Mesa format that
3555 * matches the GL format/type provided. We may need to add a new Mesa
3556 * format in that case.
3558 unreachable("Unsupported format");
3562 * Returns true if \p internal_format is a sized internal format that
3563 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3566 _mesa_is_es3_color_renderable(GLenum internal_format
)
3568 switch (internal_format
) {
3578 case GL_SRGB8_ALPHA8
:
3585 case GL_R11F_G11F_B10F
:
3611 * Returns true if \p internal_format is a sized internal format that
3612 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3615 _mesa_is_es3_texture_filterable(GLenum internal_format
)
3617 switch (internal_format
) {
3628 case GL_RGBA8_SNORM
:
3631 case GL_SRGB8_ALPHA8
:
3636 case GL_R11F_G11F_B10F
: