2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "glformats.h"
31 #include "texcompress.h"
56 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
57 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
58 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
59 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
75 MAP4(ZERO
, ZERO
, ZERO
, 0),
105 MAP4(0, ZERO
, ZERO
, ONE
),
111 MAP4(ZERO
, 0, ZERO
, ONE
),
117 MAP4(ZERO
, ZERO
, 0, ONE
),
141 MAP4(0, 1, ZERO
, ONE
),
147 * Convert a GL image format enum to an IDX_* value (see above).
150 get_map_idx(GLenum value
)
154 case GL_LUMINANCE_INTEGER_EXT
:
155 return IDX_LUMINANCE
;
157 case GL_ALPHA_INTEGER
:
160 return IDX_INTENSITY
;
161 case GL_LUMINANCE_ALPHA
:
162 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
163 return IDX_LUMINANCE_ALPHA
;
168 case GL_RGBA_INTEGER
:
181 case GL_BGRA_INTEGER
:
189 _mesa_problem(NULL
, "Unexpected inFormat %s",
190 _mesa_enum_to_string(value
));
196 * When promoting texture formats (see below) we need to compute the
197 * mapping of dest components back to source components.
198 * This function does that.
199 * \param inFormat the incoming format of the texture
200 * \param outFormat the final texture format
201 * \return map[6] a full 6-component map
204 _mesa_compute_component_mapping(GLenum inFormat
, GLenum outFormat
, GLubyte
*map
)
206 const int inFmt
= get_map_idx(inFormat
);
207 const int outFmt
= get_map_idx(outFormat
);
208 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
209 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
212 for (i
= 0; i
< 4; i
++)
213 map
[i
] = in2rgba
[rgba2out
[i
]];
219 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
220 inFormat
, _mesa_enum_to_string(inFormat
),
221 outFormat
, _mesa_enum_to_string(outFormat
),
232 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
235 _mesa_type_is_packed(GLenum type
)
238 case GL_UNSIGNED_BYTE_3_3_2
:
239 case GL_UNSIGNED_BYTE_2_3_3_REV
:
240 case MESA_UNSIGNED_BYTE_4_4
:
241 case GL_UNSIGNED_SHORT_5_6_5
:
242 case GL_UNSIGNED_SHORT_5_6_5_REV
:
243 case GL_UNSIGNED_SHORT_4_4_4_4
:
244 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
245 case GL_UNSIGNED_SHORT_5_5_5_1
:
246 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
247 case GL_UNSIGNED_INT_8_8_8_8
:
248 case GL_UNSIGNED_INT_8_8_8_8_REV
:
249 case GL_UNSIGNED_INT_10_10_10_2
:
250 case GL_UNSIGNED_INT_2_10_10_10_REV
:
251 case GL_UNSIGNED_SHORT_8_8_MESA
:
252 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
253 case GL_UNSIGNED_INT_24_8_EXT
:
254 case GL_UNSIGNED_INT_5_9_9_9_REV
:
255 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
256 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
265 * Get the size of a GL data type.
267 * \param type GL data type.
269 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
270 * if an invalid type enum.
273 _mesa_sizeof_type(GLenum type
)
278 case GL_UNSIGNED_BYTE
:
279 return sizeof(GLubyte
);
281 return sizeof(GLbyte
);
282 case GL_UNSIGNED_SHORT
:
283 return sizeof(GLushort
);
285 return sizeof(GLshort
);
286 case GL_UNSIGNED_INT
:
287 return sizeof(GLuint
);
289 return sizeof(GLint
);
291 return sizeof(GLfloat
);
293 return sizeof(GLdouble
);
294 case GL_HALF_FLOAT_ARB
:
295 case GL_HALF_FLOAT_OES
:
296 return sizeof(GLhalfARB
);
298 return sizeof(GLfixed
);
306 * Same as _mesa_sizeof_type() but also accepting the packed pixel
310 _mesa_sizeof_packed_type(GLenum type
)
315 case GL_UNSIGNED_BYTE
:
316 return sizeof(GLubyte
);
318 return sizeof(GLbyte
);
319 case GL_UNSIGNED_SHORT
:
320 return sizeof(GLushort
);
322 return sizeof(GLshort
);
323 case GL_UNSIGNED_INT
:
324 return sizeof(GLuint
);
326 return sizeof(GLint
);
327 case GL_HALF_FLOAT_ARB
:
328 case GL_HALF_FLOAT_OES
:
329 return sizeof(GLhalfARB
);
331 return sizeof(GLfloat
);
332 case GL_UNSIGNED_BYTE_3_3_2
:
333 case GL_UNSIGNED_BYTE_2_3_3_REV
:
334 case MESA_UNSIGNED_BYTE_4_4
:
335 return sizeof(GLubyte
);
336 case GL_UNSIGNED_SHORT_5_6_5
:
337 case GL_UNSIGNED_SHORT_5_6_5_REV
:
338 case GL_UNSIGNED_SHORT_4_4_4_4
:
339 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
340 case GL_UNSIGNED_SHORT_5_5_5_1
:
341 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
342 case GL_UNSIGNED_SHORT_8_8_MESA
:
343 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
344 return sizeof(GLushort
);
345 case GL_UNSIGNED_INT_8_8_8_8
:
346 case GL_UNSIGNED_INT_8_8_8_8_REV
:
347 case GL_UNSIGNED_INT_10_10_10_2
:
348 case GL_UNSIGNED_INT_2_10_10_10_REV
:
349 case GL_UNSIGNED_INT_24_8_EXT
:
350 case GL_UNSIGNED_INT_5_9_9_9_REV
:
351 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
352 return sizeof(GLuint
);
353 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
362 * Get the number of components in a pixel format.
364 * \param format pixel format.
366 * \return the number of components in the given format, or -1 if a bad format.
369 _mesa_components_in_format(GLenum format
)
373 case GL_STENCIL_INDEX
:
374 case GL_DEPTH_COMPONENT
:
376 case GL_RED_INTEGER_EXT
:
378 case GL_GREEN_INTEGER_EXT
:
380 case GL_BLUE_INTEGER_EXT
:
382 case GL_ALPHA_INTEGER_EXT
:
384 case GL_LUMINANCE_INTEGER_EXT
:
388 case GL_LUMINANCE_ALPHA
:
389 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
392 case GL_DEPTH_STENCIL_EXT
:
398 case GL_RGB_INTEGER_EXT
:
399 case GL_BGR_INTEGER_EXT
:
405 case GL_RGBA_INTEGER_EXT
:
406 case GL_BGRA_INTEGER_EXT
:
416 * Get the bytes per pixel of pixel format type pair.
418 * \param format pixel format.
419 * \param type pixel type.
421 * \return bytes per pixel, or -1 if a bad format or type was given.
424 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
426 GLint comps
= _mesa_components_in_format(format
);
432 return 0; /* special case */
434 case GL_UNSIGNED_BYTE
:
435 return comps
* sizeof(GLubyte
);
437 case GL_UNSIGNED_SHORT
:
438 return comps
* sizeof(GLshort
);
440 case GL_UNSIGNED_INT
:
441 return comps
* sizeof(GLint
);
443 return comps
* sizeof(GLfloat
);
444 case GL_HALF_FLOAT_ARB
:
445 case GL_HALF_FLOAT_OES
:
446 return comps
* sizeof(GLhalfARB
);
447 case GL_UNSIGNED_BYTE_3_3_2
:
448 case GL_UNSIGNED_BYTE_2_3_3_REV
:
449 if (format
== GL_RGB
|| format
== GL_BGR
||
450 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
451 return sizeof(GLubyte
);
453 return -1; /* error */
454 case GL_UNSIGNED_SHORT_5_6_5
:
455 case GL_UNSIGNED_SHORT_5_6_5_REV
:
456 if (format
== GL_RGB
|| format
== GL_BGR
||
457 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
458 return sizeof(GLushort
);
460 return -1; /* error */
461 case GL_UNSIGNED_SHORT_4_4_4_4
:
462 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
463 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
464 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
465 return sizeof(GLushort
);
468 case GL_UNSIGNED_SHORT_5_5_5_1
:
469 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
470 if (format
== GL_RGBA
|| format
== GL_BGRA
||
471 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
472 return sizeof(GLushort
);
475 case GL_UNSIGNED_INT_8_8_8_8
:
476 case GL_UNSIGNED_INT_8_8_8_8_REV
:
477 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
478 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
480 return sizeof(GLuint
);
483 case GL_UNSIGNED_INT_10_10_10_2
:
484 case GL_UNSIGNED_INT_2_10_10_10_REV
:
485 if (format
== GL_RGBA
|| format
== GL_BGRA
||
486 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
||
488 return sizeof(GLuint
);
491 case GL_UNSIGNED_SHORT_8_8_MESA
:
492 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
493 if (format
== GL_YCBCR_MESA
)
494 return sizeof(GLushort
);
497 case GL_UNSIGNED_INT_24_8_EXT
:
498 if (format
== GL_DEPTH_COMPONENT
||
499 format
== GL_DEPTH_STENCIL_EXT
)
500 return sizeof(GLuint
);
503 case GL_UNSIGNED_INT_5_9_9_9_REV
:
504 if (format
== GL_RGB
)
505 return sizeof(GLuint
);
508 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
509 if (format
== GL_RGB
)
510 return sizeof(GLuint
);
513 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
514 if (format
== GL_DEPTH_STENCIL
)
525 * Get the number of bytes for a vertex attrib with the given number of
526 * components and type.
528 * \param comps number of components.
529 * \param type data type.
531 * \return bytes per attribute, or -1 if a bad comps/type combination was given.
534 _mesa_bytes_per_vertex_attrib(GLint comps
, GLenum type
)
538 case GL_UNSIGNED_BYTE
:
539 return comps
* sizeof(GLubyte
);
541 case GL_UNSIGNED_SHORT
:
542 return comps
* sizeof(GLshort
);
544 case GL_UNSIGNED_INT
:
545 return comps
* sizeof(GLint
);
547 return comps
* sizeof(GLfloat
);
548 case GL_HALF_FLOAT_ARB
:
549 return comps
* sizeof(GLhalfARB
);
551 return comps
* sizeof(GLdouble
);
553 return comps
* sizeof(GLfixed
);
554 case GL_INT_2_10_10_10_REV
:
555 case GL_UNSIGNED_INT_2_10_10_10_REV
:
557 return sizeof(GLuint
);
560 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
562 return sizeof(GLuint
);
571 * Test if the given format is unsized.
574 _mesa_is_enum_format_unsized(GLenum format
)
589 case GL_LUMINANCE_ALPHA
:
594 case GL_SLUMINANCE_ALPHA
:
601 case GL_INTENSITY_SNORM
:
602 case GL_LUMINANCE_SNORM
:
603 case GL_LUMINANCE_ALPHA_SNORM
:
606 case GL_GREEN_INTEGER
:
607 case GL_BLUE_INTEGER
:
608 case GL_ALPHA_INTEGER
:
610 case GL_RGBA_INTEGER
:
612 case GL_BGRA_INTEGER
:
614 case GL_LUMINANCE_INTEGER_EXT
:
615 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
617 case GL_DEPTH_COMPONENT
:
618 case GL_DEPTH_STENCIL
:
619 case GL_STENCIL_INDEX
:
627 * Test if the given format is a UNORM (unsigned-normalized) format.
630 _mesa_is_enum_format_unorm(GLenum format
)
649 case GL_LUMINANCE_ALPHA
:
650 case GL_SLUMINANCE_ALPHA
:
651 case GL_LUMINANCE4_ALPHA4
:
652 case GL_LUMINANCE6_ALPHA2
:
653 case GL_LUMINANCE8_ALPHA8
:
654 case GL_LUMINANCE12_ALPHA4
:
655 case GL_LUMINANCE12_ALPHA12
:
656 case GL_LUMINANCE16_ALPHA16
:
698 * Test if the given format is a SNORM (signed-normalized) format.
701 _mesa_is_enum_format_snorm(GLenum format
)
704 /* signed, normalized texture formats */
716 case GL_RGBA16_SNORM
:
718 case GL_ALPHA8_SNORM
:
719 case GL_ALPHA16_SNORM
:
720 case GL_LUMINANCE_SNORM
:
721 case GL_LUMINANCE8_SNORM
:
722 case GL_LUMINANCE16_SNORM
:
723 case GL_LUMINANCE_ALPHA_SNORM
:
724 case GL_LUMINANCE8_ALPHA8_SNORM
:
725 case GL_LUMINANCE16_ALPHA16_SNORM
:
726 case GL_INTENSITY_SNORM
:
727 case GL_INTENSITY8_SNORM
:
728 case GL_INTENSITY16_SNORM
:
736 * Test if the given format is an integer (non-normalized) format.
739 _mesa_is_enum_format_unsigned_int(GLenum format
)
742 /* specific integer formats */
743 case GL_RGBA32UI_EXT
:
747 case GL_ALPHA32UI_EXT
:
748 case GL_INTENSITY32UI_EXT
:
749 case GL_LUMINANCE32UI_EXT
:
750 case GL_LUMINANCE_ALPHA32UI_EXT
:
751 case GL_RGBA16UI_EXT
:
755 case GL_ALPHA16UI_EXT
:
756 case GL_INTENSITY16UI_EXT
:
757 case GL_LUMINANCE16UI_EXT
:
758 case GL_LUMINANCE_ALPHA16UI_EXT
:
763 case GL_ALPHA8UI_EXT
:
764 case GL_INTENSITY8UI_EXT
:
765 case GL_LUMINANCE8UI_EXT
:
766 case GL_LUMINANCE_ALPHA8UI_EXT
:
776 * Test if the given format is an integer (non-normalized) format.
779 _mesa_is_enum_format_signed_int(GLenum format
)
782 /* generic integer formats */
783 case GL_RED_INTEGER_EXT
:
784 case GL_GREEN_INTEGER_EXT
:
785 case GL_BLUE_INTEGER_EXT
:
786 case GL_ALPHA_INTEGER_EXT
:
787 case GL_RGB_INTEGER_EXT
:
788 case GL_RGBA_INTEGER_EXT
:
789 case GL_BGR_INTEGER_EXT
:
790 case GL_BGRA_INTEGER_EXT
:
791 case GL_LUMINANCE_INTEGER_EXT
:
792 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
794 /* specific integer formats */
799 case GL_ALPHA32I_EXT
:
800 case GL_INTENSITY32I_EXT
:
801 case GL_LUMINANCE32I_EXT
:
802 case GL_LUMINANCE_ALPHA32I_EXT
:
807 case GL_ALPHA16I_EXT
:
808 case GL_INTENSITY16I_EXT
:
809 case GL_LUMINANCE16I_EXT
:
810 case GL_LUMINANCE_ALPHA16I_EXT
:
816 case GL_INTENSITY8I_EXT
:
817 case GL_LUMINANCE8I_EXT
:
818 case GL_LUMINANCE_ALPHA8I_EXT
:
826 * Test if the given format is an ASTC format.
829 _mesa_is_astc_format(GLenum internalFormat
)
831 switch (internalFormat
) {
832 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
833 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
834 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
835 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
836 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
837 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
838 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
839 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
840 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
841 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
842 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
843 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
844 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
845 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
846 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
847 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
848 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
849 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
850 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
851 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
852 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
853 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
854 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
855 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
856 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
857 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
858 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
859 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
868 * Test if the given format is an integer (non-normalized) format.
871 _mesa_is_enum_format_integer(GLenum format
)
873 return _mesa_is_enum_format_unsigned_int(format
) ||
874 _mesa_is_enum_format_signed_int(format
);
879 _mesa_is_type_unsigned(GLenum type
)
882 case GL_UNSIGNED_INT
:
883 case GL_UNSIGNED_INT_8_8_8_8
:
884 case GL_UNSIGNED_INT_8_8_8_8_REV
:
885 case GL_UNSIGNED_INT_10_10_10_2
:
886 case GL_UNSIGNED_INT_2_10_10_10_REV
:
888 case GL_UNSIGNED_SHORT
:
889 case GL_UNSIGNED_SHORT_4_4_4_4
:
890 case GL_UNSIGNED_SHORT_5_5_5_1
:
891 case GL_UNSIGNED_SHORT_5_6_5
:
892 case GL_UNSIGNED_SHORT_5_6_5_REV
:
893 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
894 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
895 case GL_UNSIGNED_SHORT_8_8_MESA
:
896 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
898 case GL_UNSIGNED_BYTE
:
899 case GL_UNSIGNED_BYTE_3_3_2
:
900 case GL_UNSIGNED_BYTE_2_3_3_REV
:
910 * Test if the given image format is a color/RGBA format (i.e., not color
911 * index, depth, stencil, etc).
912 * \param format the image format value (may by an internal texture format)
913 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
916 _mesa_is_color_format(GLenum format
)
934 case GL_LUMINANCE_ALPHA
:
935 case GL_LUMINANCE4_ALPHA4
:
936 case GL_LUMINANCE6_ALPHA2
:
937 case GL_LUMINANCE8_ALPHA8
:
938 case GL_LUMINANCE12_ALPHA4
:
939 case GL_LUMINANCE12_ALPHA12
:
940 case GL_LUMINANCE16_ALPHA16
:
973 /* float texture formats */
974 case GL_ALPHA16F_ARB
:
975 case GL_ALPHA32F_ARB
:
976 case GL_LUMINANCE16F_ARB
:
977 case GL_LUMINANCE32F_ARB
:
978 case GL_LUMINANCE_ALPHA16F_ARB
:
979 case GL_LUMINANCE_ALPHA32F_ARB
:
980 case GL_INTENSITY16F_ARB
:
981 case GL_INTENSITY32F_ARB
:
990 /* compressed formats */
991 case GL_COMPRESSED_ALPHA
:
992 case GL_COMPRESSED_LUMINANCE
:
993 case GL_COMPRESSED_LUMINANCE_ALPHA
:
994 case GL_COMPRESSED_INTENSITY
:
995 case GL_COMPRESSED_RED
:
996 case GL_COMPRESSED_RG
:
997 case GL_COMPRESSED_RGB
:
998 case GL_COMPRESSED_RGBA
:
1003 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1004 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1005 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1006 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1007 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1008 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1011 case GL_SRGB_ALPHA_EXT
:
1012 case GL_SRGB8_ALPHA8_EXT
:
1013 case GL_SLUMINANCE_ALPHA_EXT
:
1014 case GL_SLUMINANCE8_ALPHA8_EXT
:
1015 case GL_SLUMINANCE_EXT
:
1016 case GL_SLUMINANCE8_EXT
:
1017 case GL_COMPRESSED_SRGB_EXT
:
1018 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1019 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
1020 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1021 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1022 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1023 case GL_COMPRESSED_SLUMINANCE_EXT
:
1024 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
1025 case GL_COMPRESSED_RED_RGTC1
:
1026 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1027 case GL_COMPRESSED_RG_RGTC2
:
1028 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1029 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1030 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1031 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1032 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1033 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1034 case GL_ETC1_RGB8_OES
:
1035 case GL_COMPRESSED_RGB8_ETC2
:
1036 case GL_COMPRESSED_SRGB8_ETC2
:
1037 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1038 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1039 case GL_COMPRESSED_R11_EAC
:
1040 case GL_COMPRESSED_RG11_EAC
:
1041 case GL_COMPRESSED_SIGNED_R11_EAC
:
1042 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1043 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1044 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1045 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1046 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1047 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1048 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1049 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
1050 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
1051 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
1052 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
1053 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
1054 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
1055 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
1056 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
1057 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
1058 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
1059 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
1060 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
1061 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
1062 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
1063 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1064 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1065 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1066 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1067 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1068 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1069 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1070 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1071 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1072 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1073 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1074 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1075 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1076 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1077 /* generic integer formats */
1078 case GL_RED_INTEGER_EXT
:
1079 case GL_GREEN_INTEGER_EXT
:
1080 case GL_BLUE_INTEGER_EXT
:
1081 case GL_ALPHA_INTEGER_EXT
:
1082 case GL_RGB_INTEGER_EXT
:
1083 case GL_RGBA_INTEGER_EXT
:
1084 case GL_BGR_INTEGER_EXT
:
1085 case GL_BGRA_INTEGER_EXT
:
1087 case GL_LUMINANCE_INTEGER_EXT
:
1088 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1089 /* sized integer formats */
1090 case GL_RGBA32UI_EXT
:
1091 case GL_RGB32UI_EXT
:
1094 case GL_ALPHA32UI_EXT
:
1095 case GL_INTENSITY32UI_EXT
:
1096 case GL_LUMINANCE32UI_EXT
:
1097 case GL_LUMINANCE_ALPHA32UI_EXT
:
1098 case GL_RGBA16UI_EXT
:
1099 case GL_RGB16UI_EXT
:
1102 case GL_ALPHA16UI_EXT
:
1103 case GL_INTENSITY16UI_EXT
:
1104 case GL_LUMINANCE16UI_EXT
:
1105 case GL_LUMINANCE_ALPHA16UI_EXT
:
1106 case GL_RGBA8UI_EXT
:
1110 case GL_ALPHA8UI_EXT
:
1111 case GL_INTENSITY8UI_EXT
:
1112 case GL_LUMINANCE8UI_EXT
:
1113 case GL_LUMINANCE_ALPHA8UI_EXT
:
1114 case GL_RGBA32I_EXT
:
1118 case GL_ALPHA32I_EXT
:
1119 case GL_INTENSITY32I_EXT
:
1120 case GL_LUMINANCE32I_EXT
:
1121 case GL_LUMINANCE_ALPHA32I_EXT
:
1122 case GL_RGBA16I_EXT
:
1126 case GL_ALPHA16I_EXT
:
1127 case GL_INTENSITY16I_EXT
:
1128 case GL_LUMINANCE16I_EXT
:
1129 case GL_LUMINANCE_ALPHA16I_EXT
:
1134 case GL_ALPHA8I_EXT
:
1135 case GL_INTENSITY8I_EXT
:
1136 case GL_LUMINANCE8I_EXT
:
1137 case GL_LUMINANCE_ALPHA8I_EXT
:
1138 /* signed, normalized texture formats */
1147 case GL_RGB16_SNORM
:
1149 case GL_RGBA8_SNORM
:
1150 case GL_RGBA16_SNORM
:
1151 case GL_ALPHA_SNORM
:
1152 case GL_ALPHA8_SNORM
:
1153 case GL_ALPHA16_SNORM
:
1154 case GL_LUMINANCE_SNORM
:
1155 case GL_LUMINANCE8_SNORM
:
1156 case GL_LUMINANCE16_SNORM
:
1157 case GL_LUMINANCE_ALPHA_SNORM
:
1158 case GL_LUMINANCE8_ALPHA8_SNORM
:
1159 case GL_LUMINANCE16_ALPHA16_SNORM
:
1160 case GL_INTENSITY_SNORM
:
1161 case GL_INTENSITY8_SNORM
:
1162 case GL_INTENSITY16_SNORM
:
1164 case GL_R11F_G11F_B10F
:
1167 case GL_YCBCR_MESA
: /* not considered to be RGB */
1176 * Test if the given image format is a depth component format.
1179 _mesa_is_depth_format(GLenum format
)
1182 case GL_DEPTH_COMPONENT
:
1183 case GL_DEPTH_COMPONENT16
:
1184 case GL_DEPTH_COMPONENT24
:
1185 case GL_DEPTH_COMPONENT32
:
1186 case GL_DEPTH_COMPONENT32F
:
1195 * Test if the given image format is a stencil format.
1198 _mesa_is_stencil_format(GLenum format
)
1201 case GL_STENCIL_INDEX
:
1210 * Test if the given image format is a YCbCr format.
1213 _mesa_is_ycbcr_format(GLenum format
)
1225 * Test if the given image format is a depth+stencil format.
1228 _mesa_is_depthstencil_format(GLenum format
)
1231 case GL_DEPTH24_STENCIL8_EXT
:
1232 case GL_DEPTH_STENCIL_EXT
:
1233 case GL_DEPTH32F_STENCIL8
:
1242 * Test if the given image format is a depth or stencil format.
1245 _mesa_is_depth_or_stencil_format(GLenum format
)
1248 case GL_DEPTH_COMPONENT
:
1249 case GL_DEPTH_COMPONENT16
:
1250 case GL_DEPTH_COMPONENT24
:
1251 case GL_DEPTH_COMPONENT32
:
1252 case GL_STENCIL_INDEX
:
1253 case GL_STENCIL_INDEX1_EXT
:
1254 case GL_STENCIL_INDEX4_EXT
:
1255 case GL_STENCIL_INDEX8_EXT
:
1256 case GL_STENCIL_INDEX16_EXT
:
1257 case GL_DEPTH_STENCIL_EXT
:
1258 case GL_DEPTH24_STENCIL8_EXT
:
1259 case GL_DEPTH_COMPONENT32F
:
1260 case GL_DEPTH32F_STENCIL8
:
1269 * Test if an image format is a supported compressed format.
1270 * \param format the internal format token provided by the user.
1271 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1274 _mesa_is_compressed_format(const struct gl_context
*ctx
, GLenum format
)
1276 mesa_format m_format
= _mesa_glenum_to_compressed_format(format
);
1278 /* Some formats in this switch have an equivalent mesa_format_layout
1279 * to the compressed formats in the layout switch below and thus
1280 * must be handled first.
1287 return _mesa_is_desktop_gl(ctx
) &&
1288 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1289 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1290 return ctx
->API
== API_OPENGL_COMPAT
1291 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1292 case GL_PALETTE4_RGB8_OES
:
1293 case GL_PALETTE4_RGBA8_OES
:
1294 case GL_PALETTE4_R5_G6_B5_OES
:
1295 case GL_PALETTE4_RGBA4_OES
:
1296 case GL_PALETTE4_RGB5_A1_OES
:
1297 case GL_PALETTE8_RGB8_OES
:
1298 case GL_PALETTE8_RGBA8_OES
:
1299 case GL_PALETTE8_R5_G6_B5_OES
:
1300 case GL_PALETTE8_RGBA4_OES
:
1301 case GL_PALETTE8_RGB5_A1_OES
:
1302 return ctx
->API
== API_OPENGLES
;
1305 switch (_mesa_get_format_layout(m_format
)) {
1306 case MESA_FORMAT_LAYOUT_S3TC
:
1307 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1308 /* Assume that the ANGLE flag will always be set if the
1311 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1313 return _mesa_is_desktop_gl(ctx
)
1314 && ctx
->Extensions
.EXT_texture_sRGB
1315 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1317 case MESA_FORMAT_LAYOUT_FXT1
:
1318 return _mesa_is_desktop_gl(ctx
)
1319 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1320 case MESA_FORMAT_LAYOUT_RGTC
:
1321 return _mesa_is_desktop_gl(ctx
)
1322 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1323 case MESA_FORMAT_LAYOUT_LATC
:
1324 return ctx
->API
== API_OPENGL_COMPAT
1325 && ctx
->Extensions
.EXT_texture_compression_latc
;
1326 case MESA_FORMAT_LAYOUT_ETC1
:
1327 return _mesa_is_gles(ctx
)
1328 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1329 case MESA_FORMAT_LAYOUT_ETC2
:
1330 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1331 case MESA_FORMAT_LAYOUT_BPTC
:
1332 return _mesa_is_desktop_gl(ctx
) &&
1333 ctx
->Extensions
.ARB_texture_compression_bptc
;
1334 case MESA_FORMAT_LAYOUT_ASTC
:
1335 return ctx
->Extensions
.KHR_texture_compression_astc_ldr
;
1342 * Convert various unpack formats to the corresponding base format.
1345 _mesa_unpack_format_to_base_format(GLenum format
)
1348 case GL_RED_INTEGER
:
1350 case GL_GREEN_INTEGER
:
1352 case GL_BLUE_INTEGER
:
1354 case GL_ALPHA_INTEGER
:
1358 case GL_RGB_INTEGER
:
1360 case GL_RGBA_INTEGER
:
1362 case GL_BGR_INTEGER
:
1364 case GL_BGRA_INTEGER
:
1366 case GL_LUMINANCE_INTEGER_EXT
:
1367 return GL_LUMINANCE
;
1368 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1369 return GL_LUMINANCE_ALPHA
;
1380 case GL_LUMINANCE_ALPHA
:
1387 * Convert various base formats to the corresponding integer format.
1390 _mesa_base_format_to_integer_format(GLenum format
)
1394 return GL_RED_INTEGER
;
1396 return GL_GREEN_INTEGER
;
1398 return GL_BLUE_INTEGER
;
1400 return GL_RG_INTEGER
;
1402 return GL_RGB_INTEGER
;
1404 return GL_RGBA_INTEGER
;
1406 return GL_BGR_INTEGER
;
1408 return GL_BGRA_INTEGER
;
1410 return GL_ALPHA_INTEGER
;
1412 return GL_LUMINANCE_INTEGER_EXT
;
1413 case GL_LUMINANCE_ALPHA
:
1414 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1422 * Does the given base texture/renderbuffer format have the channel
1426 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1429 case GL_TEXTURE_RED_SIZE
:
1430 case GL_TEXTURE_RED_TYPE
:
1431 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1432 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1433 if (base_format
== GL_RED
||
1434 base_format
== GL_RG
||
1435 base_format
== GL_RGB
||
1436 base_format
== GL_RGBA
) {
1440 case GL_TEXTURE_GREEN_SIZE
:
1441 case GL_TEXTURE_GREEN_TYPE
:
1442 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1443 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1444 if (base_format
== GL_RG
||
1445 base_format
== GL_RGB
||
1446 base_format
== GL_RGBA
) {
1450 case GL_TEXTURE_BLUE_SIZE
:
1451 case GL_TEXTURE_BLUE_TYPE
:
1452 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1453 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1454 if (base_format
== GL_RGB
||
1455 base_format
== GL_RGBA
) {
1459 case GL_TEXTURE_ALPHA_SIZE
:
1460 case GL_TEXTURE_ALPHA_TYPE
:
1461 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1462 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1463 if (base_format
== GL_RGBA
||
1464 base_format
== GL_ALPHA
||
1465 base_format
== GL_LUMINANCE_ALPHA
) {
1469 case GL_TEXTURE_LUMINANCE_SIZE
:
1470 case GL_TEXTURE_LUMINANCE_TYPE
:
1471 if (base_format
== GL_LUMINANCE
||
1472 base_format
== GL_LUMINANCE_ALPHA
) {
1476 case GL_TEXTURE_INTENSITY_SIZE
:
1477 case GL_TEXTURE_INTENSITY_TYPE
:
1478 if (base_format
== GL_INTENSITY
) {
1482 case GL_TEXTURE_DEPTH_SIZE
:
1483 case GL_TEXTURE_DEPTH_TYPE
:
1484 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1485 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1486 if (base_format
== GL_DEPTH_STENCIL
||
1487 base_format
== GL_DEPTH_COMPONENT
) {
1491 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1492 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1493 if (base_format
== GL_DEPTH_STENCIL
||
1494 base_format
== GL_STENCIL_INDEX
) {
1499 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1509 * Returns the number of channels/components for a base format.
1512 _mesa_base_format_component_count(GLenum base_format
)
1514 switch (base_format
) {
1518 case GL_DEPTH_COMPONENT
:
1521 case GL_LUMINANCE_ALPHA
:
1522 case GL_DEPTH_STENCIL
:
1535 * If format is a generic compressed format, return the corresponding
1536 * non-compressed format. For other formats, return the format as-is.
1539 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1542 case GL_COMPRESSED_RED
:
1544 case GL_COMPRESSED_RG
:
1546 case GL_COMPRESSED_RGB
:
1548 case GL_COMPRESSED_RGBA
:
1550 case GL_COMPRESSED_ALPHA
:
1552 case GL_COMPRESSED_LUMINANCE
:
1553 return GL_LUMINANCE
;
1554 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1555 return GL_LUMINANCE_ALPHA
;
1556 case GL_COMPRESSED_INTENSITY
:
1557 return GL_INTENSITY
;
1559 case GL_COMPRESSED_SRGB
:
1561 case GL_COMPRESSED_SRGB_ALPHA
:
1562 return GL_SRGB_ALPHA
;
1563 case GL_COMPRESSED_SLUMINANCE
:
1564 return GL_SLUMINANCE
;
1565 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1566 return GL_SLUMINANCE_ALPHA
;
1574 * Return the equivalent non-generic internal format.
1575 * This is useful for comparing whether two internal formats are equivalent.
1578 _mesa_get_nongeneric_internalformat(GLenum format
)
1581 /* GL 1.1 formats. */
1589 case GL_LUMINANCE_ALPHA
:
1590 return GL_LUMINANCE8_ALPHA8
;
1593 return GL_LUMINANCE8
;
1597 return GL_INTENSITY8
;
1599 /* GL_ARB_texture_rg */
1605 /* GL_EXT_texture_sRGB */
1609 return GL_SRGB8_ALPHA8
;
1611 return GL_SLUMINANCE8
;
1612 case GL_SLUMINANCE_ALPHA
:
1613 return GL_SLUMINANCE8_ALPHA8
;
1615 /* GL_EXT_texture_snorm */
1617 return GL_RGBA8_SNORM
;
1619 return GL_RGB8_SNORM
;
1621 return GL_RG8_SNORM
;
1624 case GL_LUMINANCE_ALPHA_SNORM
:
1625 return GL_LUMINANCE8_ALPHA8_SNORM
;
1626 case GL_LUMINANCE_SNORM
:
1627 return GL_LUMINANCE8_SNORM
;
1628 case GL_ALPHA_SNORM
:
1629 return GL_ALPHA8_SNORM
;
1630 case GL_INTENSITY_SNORM
:
1631 return GL_INTENSITY8_SNORM
;
1640 * Convert an sRGB internal format to linear.
1643 _mesa_get_linear_internalformat(GLenum format
)
1652 case GL_SRGB8_ALPHA8
:
1654 case GL_SLUMINANCE8
:
1655 return GL_LUMINANCE8
;
1657 return GL_LUMINANCE
;
1658 case GL_SLUMINANCE_ALPHA
:
1659 return GL_LUMINANCE_ALPHA
;
1660 case GL_SLUMINANCE8_ALPHA8
:
1661 return GL_LUMINANCE8_ALPHA8
;
1669 * Do error checking of format/type combinations for glReadPixels,
1670 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1671 * and type values, we may either generate GL_INVALID_OPERATION or
1674 * \param format pixel format.
1675 * \param type pixel type.
1677 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1680 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1681 GLenum format
, GLenum type
)
1683 /* From OpenGL 3.3 spec, page 220:
1684 * "If the format is DEPTH_STENCIL, then values are taken from
1685 * both the depth buffer and the stencil buffer. If there is no
1686 * depth buffer or if there is no stencil buffer, then the error
1687 * INVALID_OPERATION occurs. If the type parameter is not
1688 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1689 * error INVALID_ENUM occurs."
1691 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1692 * cannot be used to read depth or stencil in that API.
1694 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1695 && type
!= GL_UNSIGNED_INT_24_8
1696 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1697 return GL_INVALID_ENUM
;
1699 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1702 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1703 return GL_INVALID_ENUM
;
1707 case GL_UNSIGNED_BYTE_3_3_2
:
1708 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1709 case GL_UNSIGNED_SHORT_5_6_5
:
1710 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1711 if (format
== GL_RGB
) {
1714 if (format
== GL_RGB_INTEGER_EXT
&&
1715 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1718 return GL_INVALID_OPERATION
;
1720 case GL_UNSIGNED_SHORT_4_4_4_4
:
1721 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1722 case GL_UNSIGNED_INT_8_8_8_8
:
1723 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1724 if (format
== GL_RGBA
||
1725 format
== GL_BGRA
||
1726 format
== GL_ABGR_EXT
) {
1729 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1730 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1733 return GL_INVALID_OPERATION
;
1735 case GL_UNSIGNED_SHORT_5_5_5_1
:
1736 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1737 case GL_UNSIGNED_INT_10_10_10_2
:
1738 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1739 if (format
== GL_RGBA
||
1740 format
== GL_BGRA
) {
1743 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1744 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1747 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1748 ctx
->API
== API_OPENGLES2
) {
1749 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1751 return GL_INVALID_OPERATION
;
1753 case GL_UNSIGNED_INT_24_8
:
1754 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1755 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1758 if (format
!= GL_DEPTH_STENCIL
) {
1759 return GL_INVALID_OPERATION
;
1763 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1764 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1765 return GL_INVALID_ENUM
;
1767 if (format
!= GL_DEPTH_STENCIL
) {
1768 return GL_INVALID_OPERATION
;
1772 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1773 if (!ctx
->Extensions
.EXT_packed_float
) {
1774 return GL_INVALID_ENUM
;
1776 if (format
!= GL_RGB
) {
1777 return GL_INVALID_OPERATION
;
1781 case GL_HALF_FLOAT_OES
:
1785 case GL_LUMINANCE_ALPHA
:
1791 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1794 return GL_INVALID_OPERATION
;
1798 ; /* fall-through */
1801 /* now, for each format, check the type for compatibility */
1803 case GL_COLOR_INDEX
:
1804 case GL_STENCIL_INDEX
:
1808 case GL_UNSIGNED_BYTE
:
1810 case GL_UNSIGNED_SHORT
:
1812 case GL_UNSIGNED_INT
:
1817 return GL_INVALID_ENUM
;
1824 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1828 case GL_LUMINANCE_ALPHA
:
1829 case GL_DEPTH_COMPONENT
:
1832 case GL_UNSIGNED_BYTE
:
1834 case GL_UNSIGNED_SHORT
:
1836 case GL_UNSIGNED_INT
:
1841 return GL_INVALID_ENUM
;
1845 if (!ctx
->Extensions
.ARB_texture_rg
)
1846 return GL_INVALID_ENUM
;
1849 case GL_UNSIGNED_BYTE
:
1851 case GL_UNSIGNED_SHORT
:
1853 case GL_UNSIGNED_INT
:
1858 return GL_INVALID_ENUM
;
1864 case GL_UNSIGNED_BYTE
:
1866 case GL_UNSIGNED_SHORT
:
1868 case GL_UNSIGNED_INT
:
1870 case GL_UNSIGNED_BYTE_3_3_2
:
1871 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1872 case GL_UNSIGNED_SHORT_5_6_5
:
1873 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1876 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1877 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1878 return (ctx
->API
== API_OPENGLES2
)
1879 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1880 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1881 return ctx
->Extensions
.EXT_texture_shared_exponent
1882 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1883 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1884 return ctx
->Extensions
.EXT_packed_float
1885 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1887 return GL_INVALID_ENUM
;
1892 /* NOTE: no packed types are supported with BGR. That's
1893 * intentional, according to the GL spec.
1896 case GL_UNSIGNED_BYTE
:
1898 case GL_UNSIGNED_SHORT
:
1900 case GL_UNSIGNED_INT
:
1905 return GL_INVALID_ENUM
;
1912 case GL_UNSIGNED_BYTE
:
1914 case GL_UNSIGNED_SHORT
:
1916 case GL_UNSIGNED_INT
:
1918 case GL_UNSIGNED_SHORT_4_4_4_4
:
1919 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1920 case GL_UNSIGNED_SHORT_5_5_5_1
:
1921 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1922 case GL_UNSIGNED_INT_8_8_8_8
:
1923 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1924 case GL_UNSIGNED_INT_10_10_10_2
:
1925 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1929 return GL_INVALID_ENUM
;
1935 case GL_UNSIGNED_BYTE
:
1937 case GL_UNSIGNED_SHORT
:
1939 case GL_UNSIGNED_INT
:
1941 case GL_UNSIGNED_SHORT_4_4_4_4
:
1942 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1943 case GL_UNSIGNED_INT_8_8_8_8
:
1944 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1948 return GL_INVALID_ENUM
;
1952 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1953 return GL_INVALID_ENUM
;
1954 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1955 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1958 return GL_INVALID_OPERATION
;
1960 case GL_DEPTH_STENCIL
:
1961 if (type
== GL_UNSIGNED_INT_24_8
)
1963 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1964 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1967 return GL_INVALID_ENUM
;
1969 /* integer-valued formats */
1970 case GL_RED_INTEGER_EXT
:
1971 case GL_GREEN_INTEGER_EXT
:
1972 case GL_BLUE_INTEGER_EXT
:
1973 case GL_ALPHA_INTEGER_EXT
:
1977 case GL_UNSIGNED_BYTE
:
1979 case GL_UNSIGNED_SHORT
:
1981 case GL_UNSIGNED_INT
:
1982 return (ctx
->Version
>= 30 ||
1983 ctx
->Extensions
.EXT_texture_integer
)
1984 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1986 return GL_INVALID_ENUM
;
1989 case GL_RGB_INTEGER_EXT
:
1992 case GL_UNSIGNED_BYTE
:
1994 case GL_UNSIGNED_SHORT
:
1996 case GL_UNSIGNED_INT
:
1997 return (ctx
->Version
>= 30 ||
1998 ctx
->Extensions
.EXT_texture_integer
)
1999 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2000 case GL_UNSIGNED_BYTE_3_3_2
:
2001 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2002 case GL_UNSIGNED_SHORT_5_6_5
:
2003 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2004 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2005 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2007 return GL_INVALID_ENUM
;
2010 case GL_BGR_INTEGER_EXT
:
2013 case GL_UNSIGNED_BYTE
:
2015 case GL_UNSIGNED_SHORT
:
2017 case GL_UNSIGNED_INT
:
2018 /* NOTE: no packed formats w/ BGR format */
2019 return (ctx
->Version
>= 30 ||
2020 ctx
->Extensions
.EXT_texture_integer
)
2021 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2023 return GL_INVALID_ENUM
;
2026 case GL_RGBA_INTEGER_EXT
:
2027 case GL_BGRA_INTEGER_EXT
:
2030 case GL_UNSIGNED_BYTE
:
2032 case GL_UNSIGNED_SHORT
:
2034 case GL_UNSIGNED_INT
:
2035 return (ctx
->Version
>= 30 ||
2036 ctx
->Extensions
.EXT_texture_integer
)
2037 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2038 case GL_UNSIGNED_SHORT_4_4_4_4
:
2039 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2040 case GL_UNSIGNED_SHORT_5_5_5_1
:
2041 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2042 case GL_UNSIGNED_INT_8_8_8_8
:
2043 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2044 case GL_UNSIGNED_INT_10_10_10_2
:
2045 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2046 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2047 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2049 return GL_INVALID_ENUM
;
2052 case GL_LUMINANCE_INTEGER_EXT
:
2053 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2056 case GL_UNSIGNED_BYTE
:
2058 case GL_UNSIGNED_SHORT
:
2060 case GL_UNSIGNED_INT
:
2061 return ctx
->Extensions
.EXT_texture_integer
2062 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2064 return GL_INVALID_ENUM
;
2068 return GL_INVALID_ENUM
;
2075 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2076 * and glTex[Sub]Image.
2077 * \return error code, or GL_NO_ERROR.
2080 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
2081 unsigned dimensions
)
2083 GLboolean type_valid
= GL_TRUE
;
2088 case GL_LUMINANCE_ALPHA
:
2089 type_valid
= (type
== GL_UNSIGNED_BYTE
2091 || type
== GL_HALF_FLOAT_OES
);
2095 type_valid
= (type
== GL_UNSIGNED_BYTE
2096 || type
== GL_UNSIGNED_SHORT_5_6_5
2098 || type
== GL_HALF_FLOAT_OES
);
2102 type_valid
= (type
== GL_UNSIGNED_BYTE
2103 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2104 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2106 || type
== GL_HALF_FLOAT_OES
2107 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2110 case GL_DEPTH_COMPONENT
:
2111 /* This format is filtered against invalid dimensionalities elsewhere.
2113 type_valid
= (type
== GL_UNSIGNED_SHORT
2114 || type
== GL_UNSIGNED_INT
);
2117 case GL_DEPTH_STENCIL
:
2118 /* This format is filtered against invalid dimensionalities elsewhere.
2120 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2124 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2126 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2127 * the format does not appear to be allowed for 3D textures in OpenGL
2130 if (dimensions
!= 2)
2131 return GL_INVALID_VALUE
;
2136 return GL_INVALID_VALUE
;
2139 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2143 * Return the simple base format for a given internal texture format.
2144 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2146 * \param ctx GL context.
2147 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2149 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2150 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2152 * This is the format which is used during texture application (i.e. the
2153 * texture format and env mode determine the arithmetic used.
2156 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2158 switch (internalFormat
) {
2164 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2169 case GL_LUMINANCE12
:
2170 case GL_LUMINANCE16
:
2171 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2173 case GL_LUMINANCE_ALPHA
:
2174 case GL_LUMINANCE4_ALPHA4
:
2175 case GL_LUMINANCE6_ALPHA2
:
2176 case GL_LUMINANCE8_ALPHA8
:
2177 case GL_LUMINANCE12_ALPHA4
:
2178 case GL_LUMINANCE12_ALPHA12
:
2179 case GL_LUMINANCE16_ALPHA16
:
2180 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2184 case GL_INTENSITY12
:
2185 case GL_INTENSITY16
:
2186 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2188 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2199 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2213 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2215 if (_mesa_is_gles(ctx
)) {
2216 switch (internalFormat
) {
2224 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2225 switch (internalFormat
) {
2233 if (ctx
->Extensions
.ARB_depth_texture
) {
2234 switch (internalFormat
) {
2235 case GL_DEPTH_COMPONENT
:
2236 case GL_DEPTH_COMPONENT16
:
2237 case GL_DEPTH_COMPONENT24
:
2238 case GL_DEPTH_COMPONENT32
:
2239 return GL_DEPTH_COMPONENT
;
2240 case GL_DEPTH_STENCIL
:
2241 case GL_DEPTH24_STENCIL8
:
2242 return GL_DEPTH_STENCIL
;
2248 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2249 switch (internalFormat
) {
2250 case GL_STENCIL_INDEX
:
2251 case GL_STENCIL_INDEX1
:
2252 case GL_STENCIL_INDEX4
:
2253 case GL_STENCIL_INDEX8
:
2254 case GL_STENCIL_INDEX16
:
2255 return GL_STENCIL_INDEX
;
2261 switch (internalFormat
) {
2262 case GL_COMPRESSED_ALPHA
:
2264 case GL_COMPRESSED_LUMINANCE
:
2265 return GL_LUMINANCE
;
2266 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2267 return GL_LUMINANCE_ALPHA
;
2268 case GL_COMPRESSED_INTENSITY
:
2269 return GL_INTENSITY
;
2270 case GL_COMPRESSED_RGB
:
2272 case GL_COMPRESSED_RGBA
:
2278 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2279 GLenum base_compressed
=
2280 _mesa_gl_compressed_format_base_format(internalFormat
);
2281 if (base_compressed
)
2282 return base_compressed
;
2285 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2286 _mesa_is_astc_format(internalFormat
))
2289 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2290 if (internalFormat
== GL_YCBCR_MESA
)
2291 return GL_YCBCR_MESA
;
2294 if (ctx
->Extensions
.ARB_texture_float
) {
2295 switch (internalFormat
) {
2296 case GL_ALPHA16F_ARB
:
2297 case GL_ALPHA32F_ARB
:
2299 case GL_RGBA16F_ARB
:
2300 case GL_RGBA32F_ARB
:
2305 case GL_INTENSITY16F_ARB
:
2306 case GL_INTENSITY32F_ARB
:
2307 return GL_INTENSITY
;
2308 case GL_LUMINANCE16F_ARB
:
2309 case GL_LUMINANCE32F_ARB
:
2310 return GL_LUMINANCE
;
2311 case GL_LUMINANCE_ALPHA16F_ARB
:
2312 case GL_LUMINANCE_ALPHA32F_ARB
:
2313 return GL_LUMINANCE_ALPHA
;
2319 if (ctx
->Extensions
.EXT_texture_snorm
) {
2320 switch (internalFormat
) {
2331 case GL_RGB16_SNORM
:
2334 case GL_RGBA8_SNORM
:
2335 case GL_RGBA16_SNORM
:
2337 case GL_ALPHA_SNORM
:
2338 case GL_ALPHA8_SNORM
:
2339 case GL_ALPHA16_SNORM
:
2341 case GL_LUMINANCE_SNORM
:
2342 case GL_LUMINANCE8_SNORM
:
2343 case GL_LUMINANCE16_SNORM
:
2344 return GL_LUMINANCE
;
2345 case GL_LUMINANCE_ALPHA_SNORM
:
2346 case GL_LUMINANCE8_ALPHA8_SNORM
:
2347 case GL_LUMINANCE16_ALPHA16_SNORM
:
2348 return GL_LUMINANCE_ALPHA
;
2349 case GL_INTENSITY_SNORM
:
2350 case GL_INTENSITY8_SNORM
:
2351 case GL_INTENSITY16_SNORM
:
2352 return GL_INTENSITY
;
2358 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2359 switch (internalFormat
) {
2362 case GL_COMPRESSED_SRGB_EXT
:
2364 case GL_SRGB_ALPHA_EXT
:
2365 case GL_SRGB8_ALPHA8_EXT
:
2366 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2368 case GL_SLUMINANCE_ALPHA_EXT
:
2369 case GL_SLUMINANCE8_ALPHA8_EXT
:
2370 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2371 return GL_LUMINANCE_ALPHA
;
2372 case GL_SLUMINANCE_EXT
:
2373 case GL_SLUMINANCE8_EXT
:
2374 case GL_COMPRESSED_SLUMINANCE_EXT
:
2375 return GL_LUMINANCE
;
2381 if (ctx
->Version
>= 30 ||
2382 ctx
->Extensions
.EXT_texture_integer
) {
2383 switch (internalFormat
) {
2384 case GL_RGBA8UI_EXT
:
2385 case GL_RGBA16UI_EXT
:
2386 case GL_RGBA32UI_EXT
:
2388 case GL_RGBA16I_EXT
:
2389 case GL_RGBA32I_EXT
:
2393 case GL_RGB16UI_EXT
:
2394 case GL_RGB32UI_EXT
:
2402 if (ctx
->Extensions
.EXT_texture_integer
) {
2403 switch (internalFormat
) {
2404 case GL_ALPHA8UI_EXT
:
2405 case GL_ALPHA16UI_EXT
:
2406 case GL_ALPHA32UI_EXT
:
2407 case GL_ALPHA8I_EXT
:
2408 case GL_ALPHA16I_EXT
:
2409 case GL_ALPHA32I_EXT
:
2411 case GL_INTENSITY8UI_EXT
:
2412 case GL_INTENSITY16UI_EXT
:
2413 case GL_INTENSITY32UI_EXT
:
2414 case GL_INTENSITY8I_EXT
:
2415 case GL_INTENSITY16I_EXT
:
2416 case GL_INTENSITY32I_EXT
:
2417 return GL_INTENSITY
;
2418 case GL_LUMINANCE8UI_EXT
:
2419 case GL_LUMINANCE16UI_EXT
:
2420 case GL_LUMINANCE32UI_EXT
:
2421 case GL_LUMINANCE8I_EXT
:
2422 case GL_LUMINANCE16I_EXT
:
2423 case GL_LUMINANCE32I_EXT
:
2424 return GL_LUMINANCE
;
2425 case GL_LUMINANCE_ALPHA8UI_EXT
:
2426 case GL_LUMINANCE_ALPHA16UI_EXT
:
2427 case GL_LUMINANCE_ALPHA32UI_EXT
:
2428 case GL_LUMINANCE_ALPHA8I_EXT
:
2429 case GL_LUMINANCE_ALPHA16I_EXT
:
2430 case GL_LUMINANCE_ALPHA32I_EXT
:
2431 return GL_LUMINANCE_ALPHA
;
2437 if (ctx
->Extensions
.ARB_texture_rg
) {
2438 switch (internalFormat
) {
2441 if (!ctx
->Extensions
.ARB_texture_float
)
2450 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2456 case GL_COMPRESSED_RED
:
2461 if (!ctx
->Extensions
.ARB_texture_float
)
2470 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2476 case GL_COMPRESSED_RG
:
2483 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2484 switch (internalFormat
) {
2485 case GL_RGB9_E5_EXT
:
2492 if (ctx
->Extensions
.EXT_packed_float
) {
2493 switch (internalFormat
) {
2494 case GL_R11F_G11F_B10F_EXT
:
2501 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2502 switch (internalFormat
) {
2503 case GL_DEPTH_COMPONENT32F
:
2504 return GL_DEPTH_COMPONENT
;
2505 case GL_DEPTH32F_STENCIL8
:
2506 return GL_DEPTH_STENCIL
;
2512 return -1; /* error */
2516 * Returns the effective internal format from a texture format and type.
2517 * This is used by texture image operations internally for validation, when
2518 * the specified internal format is a base (unsized) format.
2520 * This method will only return a valid effective internal format if the
2521 * combination of format, type and internal format in base form, is acceptable.
2523 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2524 * in extensions, to unambiguously correspond to the given base format, then
2525 * that internal format is returned as the effective. Otherwise, if the
2526 * combination is accepted but a single effective format is not defined, the
2527 * passed base format will be returned instead.
2529 * \param format the texture format
2530 * \param type the texture type
2533 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2537 case GL_UNSIGNED_BYTE
:
2543 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2544 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2545 * internal formats, they do not correspond to GL constants, so the base
2546 * format is returned instead.
2549 case GL_LUMINANCE_ALPHA
:
2556 case GL_UNSIGNED_SHORT_4_4_4_4
:
2557 if (format
== GL_RGBA
)
2561 case GL_UNSIGNED_SHORT_5_5_5_1
:
2562 if (format
== GL_RGBA
)
2566 case GL_UNSIGNED_SHORT_5_6_5
:
2567 if (format
== GL_RGB
)
2571 /* OES_packed_depth_stencil */
2572 case GL_UNSIGNED_INT_24_8
:
2573 if (format
== GL_DEPTH_STENCIL
)
2574 return GL_DEPTH24_STENCIL8
;
2577 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2578 if (format
== GL_DEPTH_STENCIL
)
2579 return GL_DEPTH32F_STENCIL8
;
2582 case GL_UNSIGNED_SHORT
:
2583 if (format
== GL_DEPTH_COMPONENT
)
2584 return GL_DEPTH_COMPONENT16
;
2587 case GL_UNSIGNED_INT
:
2588 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2591 if (format
== GL_DEPTH_COMPONENT
)
2595 /* OES_texture_float and OES_texture_half_float */
2597 if (format
== GL_DEPTH_COMPONENT
)
2598 return GL_DEPTH_COMPONENT32F
;
2600 case GL_HALF_FLOAT_OES
:
2604 case GL_LUMINANCE_ALPHA
:
2620 /* GL_EXT_texture_type_2_10_10_10_REV */
2621 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2630 /* fall through and return NONE */
2638 * Do error checking of format/type combinations for OpenGL ES 3
2640 * \return error code, or GL_NO_ERROR.
2643 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2644 GLenum format
, GLenum type
,
2645 GLenum internalFormat
)
2647 /* If internalFormat is an unsized format, then the effective internal
2648 * format derived from format and type should be used instead. Page 127,
2649 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2651 * "if internalformat is a base internal format, the effective
2652 * internal format is a sized internal format that is derived
2653 * from the format and type for internal use by the GL.
2654 * Table 3.12 specifies the mapping of format and type to effective
2655 * internal formats. The effective internal format is used by the GL
2656 * for purposes such as texture completeness or type checks for
2657 * CopyTex* commands. In these cases, the GL is required to operate
2658 * as if the effective internal format was used as the internalformat
2659 * when specifying the texture data."
2661 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2662 GLenum effectiveInternalFormat
=
2663 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2665 if (effectiveInternalFormat
== GL_NONE
)
2666 return GL_INVALID_OPERATION
;
2668 GLenum baseInternalFormat
;
2669 if (internalFormat
== GL_BGRA_EXT
) {
2670 /* Unfortunately, _mesa_base_tex_format returns a base format of
2671 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2672 * asking the question, "what channels does this format have?"
2673 * However, if we're trying to determine if two internal formats
2674 * match in the ES3 sense, we actually want GL_BGRA.
2676 baseInternalFormat
= GL_BGRA_EXT
;
2678 baseInternalFormat
=
2679 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2682 if (internalFormat
!= baseInternalFormat
)
2683 return GL_INVALID_OPERATION
;
2685 internalFormat
= effectiveInternalFormat
;
2690 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2691 return GL_INVALID_OPERATION
;
2696 case GL_UNSIGNED_BYTE
:
2697 switch (internalFormat
) {
2702 case GL_SRGB8_ALPHA8_EXT
:
2705 return GL_INVALID_OPERATION
;
2710 if (internalFormat
!= GL_RGBA8_SNORM
)
2711 return GL_INVALID_OPERATION
;
2714 case GL_UNSIGNED_SHORT_4_4_4_4
:
2715 switch (internalFormat
) {
2720 return GL_INVALID_OPERATION
;
2724 case GL_UNSIGNED_SHORT_5_5_5_1
:
2725 switch (internalFormat
) {
2730 return GL_INVALID_OPERATION
;
2734 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2735 switch (internalFormat
) {
2736 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2741 return GL_INVALID_OPERATION
;
2746 if (internalFormat
!= GL_RGBA16F
)
2747 return GL_INVALID_OPERATION
;
2751 switch (internalFormat
) {
2756 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2759 return GL_INVALID_OPERATION
;
2763 case GL_HALF_FLOAT_OES
:
2764 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2767 return GL_INVALID_OPERATION
;
2771 case GL_RGBA_INTEGER
:
2773 case GL_UNSIGNED_BYTE
:
2774 if (internalFormat
!= GL_RGBA8UI
)
2775 return GL_INVALID_OPERATION
;
2779 if (internalFormat
!= GL_RGBA8I
)
2780 return GL_INVALID_OPERATION
;
2783 case GL_UNSIGNED_SHORT
:
2784 if (internalFormat
!= GL_RGBA16UI
)
2785 return GL_INVALID_OPERATION
;
2789 if (internalFormat
!= GL_RGBA16I
)
2790 return GL_INVALID_OPERATION
;
2793 case GL_UNSIGNED_INT
:
2794 if (internalFormat
!= GL_RGBA32UI
)
2795 return GL_INVALID_OPERATION
;
2799 if (internalFormat
!= GL_RGBA32I
)
2800 return GL_INVALID_OPERATION
;
2803 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2804 if (internalFormat
!= GL_RGB10_A2UI
)
2805 return GL_INVALID_OPERATION
;
2809 return GL_INVALID_OPERATION
;
2815 case GL_UNSIGNED_BYTE
:
2816 switch (internalFormat
) {
2823 return GL_INVALID_OPERATION
;
2828 if (internalFormat
!= GL_RGB8_SNORM
)
2829 return GL_INVALID_OPERATION
;
2832 case GL_UNSIGNED_SHORT_5_6_5
:
2833 switch (internalFormat
) {
2838 return GL_INVALID_OPERATION
;
2842 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2843 if (internalFormat
!= GL_R11F_G11F_B10F
)
2844 return GL_INVALID_OPERATION
;
2847 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2848 if (internalFormat
!= GL_RGB9_E5
)
2849 return GL_INVALID_OPERATION
;
2853 switch (internalFormat
) {
2855 case GL_R11F_G11F_B10F
:
2859 return GL_INVALID_OPERATION
;
2864 switch (internalFormat
) {
2867 case GL_R11F_G11F_B10F
:
2871 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2874 return GL_INVALID_OPERATION
;
2878 case GL_HALF_FLOAT_OES
:
2879 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2880 return GL_INVALID_OPERATION
;
2883 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2884 switch (internalFormat
) {
2885 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2888 return GL_INVALID_OPERATION
;
2893 return GL_INVALID_OPERATION
;
2897 case GL_RGB_INTEGER
:
2899 case GL_UNSIGNED_BYTE
:
2900 if (internalFormat
!= GL_RGB8UI
)
2901 return GL_INVALID_OPERATION
;
2905 if (internalFormat
!= GL_RGB8I
)
2906 return GL_INVALID_OPERATION
;
2909 case GL_UNSIGNED_SHORT
:
2910 if (internalFormat
!= GL_RGB16UI
)
2911 return GL_INVALID_OPERATION
;
2915 if (internalFormat
!= GL_RGB16I
)
2916 return GL_INVALID_OPERATION
;
2919 case GL_UNSIGNED_INT
:
2920 if (internalFormat
!= GL_RGB32UI
)
2921 return GL_INVALID_OPERATION
;
2925 if (internalFormat
!= GL_RGB32I
)
2926 return GL_INVALID_OPERATION
;
2930 return GL_INVALID_OPERATION
;
2936 case GL_UNSIGNED_BYTE
:
2937 if (internalFormat
!= GL_RG8
)
2938 return GL_INVALID_OPERATION
;
2942 if (internalFormat
!= GL_RG8_SNORM
)
2943 return GL_INVALID_OPERATION
;
2947 case GL_HALF_FLOAT_OES
:
2948 switch (internalFormat
) {
2952 if (ctx
->Extensions
.ARB_texture_rg
&&
2953 ctx
->Extensions
.OES_texture_half_float
)
2957 return GL_INVALID_OPERATION
;
2962 switch (internalFormat
) {
2967 if (ctx
->Extensions
.ARB_texture_rg
&&
2968 ctx
->Extensions
.OES_texture_float
)
2972 return GL_INVALID_OPERATION
;
2977 return GL_INVALID_OPERATION
;
2983 case GL_UNSIGNED_BYTE
:
2984 if (internalFormat
!= GL_RG8UI
)
2985 return GL_INVALID_OPERATION
;
2989 if (internalFormat
!= GL_RG8I
)
2990 return GL_INVALID_OPERATION
;
2993 case GL_UNSIGNED_SHORT
:
2994 if (internalFormat
!= GL_RG16UI
)
2995 return GL_INVALID_OPERATION
;
2999 if (internalFormat
!= GL_RG16I
)
3000 return GL_INVALID_OPERATION
;
3003 case GL_UNSIGNED_INT
:
3004 if (internalFormat
!= GL_RG32UI
)
3005 return GL_INVALID_OPERATION
;
3009 if (internalFormat
!= GL_RG32I
)
3010 return GL_INVALID_OPERATION
;
3014 return GL_INVALID_OPERATION
;
3020 case GL_UNSIGNED_BYTE
:
3021 if (internalFormat
!= GL_R8
)
3022 return GL_INVALID_OPERATION
;
3026 if (internalFormat
!= GL_R8_SNORM
)
3027 return GL_INVALID_OPERATION
;
3031 case GL_HALF_FLOAT_OES
:
3032 switch (internalFormat
) {
3037 if (ctx
->Extensions
.ARB_texture_rg
&&
3038 ctx
->Extensions
.OES_texture_half_float
)
3042 return GL_INVALID_OPERATION
;
3047 switch (internalFormat
) {
3052 if (ctx
->Extensions
.ARB_texture_rg
&&
3053 ctx
->Extensions
.OES_texture_float
)
3057 return GL_INVALID_OPERATION
;
3062 return GL_INVALID_OPERATION
;
3066 case GL_RED_INTEGER
:
3068 case GL_UNSIGNED_BYTE
:
3069 if (internalFormat
!= GL_R8UI
)
3070 return GL_INVALID_OPERATION
;
3074 if (internalFormat
!= GL_R8I
)
3075 return GL_INVALID_OPERATION
;
3078 case GL_UNSIGNED_SHORT
:
3079 if (internalFormat
!= GL_R16UI
)
3080 return GL_INVALID_OPERATION
;
3084 if (internalFormat
!= GL_R16I
)
3085 return GL_INVALID_OPERATION
;
3088 case GL_UNSIGNED_INT
:
3089 if (internalFormat
!= GL_R32UI
)
3090 return GL_INVALID_OPERATION
;
3094 if (internalFormat
!= GL_R32I
)
3095 return GL_INVALID_OPERATION
;
3099 return GL_INVALID_OPERATION
;
3103 case GL_DEPTH_COMPONENT
:
3105 case GL_UNSIGNED_SHORT
:
3106 if (internalFormat
!= GL_DEPTH_COMPONENT
3107 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3108 return GL_INVALID_OPERATION
;
3111 case GL_UNSIGNED_INT
:
3112 switch (internalFormat
) {
3113 case GL_DEPTH_COMPONENT
:
3114 case GL_DEPTH_COMPONENT16
:
3115 case GL_DEPTH_COMPONENT24
:
3118 return GL_INVALID_OPERATION
;
3123 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3124 return GL_INVALID_OPERATION
;
3128 return GL_INVALID_OPERATION
;
3132 case GL_DEPTH_STENCIL
:
3134 case GL_UNSIGNED_INT_24_8
:
3135 if (internalFormat
!= GL_DEPTH_STENCIL
3136 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3137 return GL_INVALID_OPERATION
;
3140 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3141 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3142 return GL_INVALID_OPERATION
;
3146 return GL_INVALID_OPERATION
;
3152 case GL_LUMINANCE_ALPHA
:
3155 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3157 case GL_HALF_FLOAT_OES
:
3158 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3161 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3162 return GL_INVALID_OPERATION
;
3170 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3172 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3173 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3174 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3175 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3179 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3183 case GL_RGBA_INTEGER_EXT
:
3184 set_swizzle(swizzle
, 0, 1, 2, 3);
3187 case GL_BGRA_INTEGER_EXT
:
3188 set_swizzle(swizzle
, 2, 1, 0, 3);
3191 set_swizzle(swizzle
, 3, 2, 1, 0);
3194 case GL_RGB_INTEGER_EXT
:
3195 set_swizzle(swizzle
, 0, 1, 2, 5);
3198 case GL_BGR_INTEGER_EXT
:
3199 set_swizzle(swizzle
, 2, 1, 0, 5);
3201 case GL_LUMINANCE_ALPHA
:
3202 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3203 set_swizzle(swizzle
, 0, 0, 0, 1);
3207 set_swizzle(swizzle
, 0, 1, 4, 5);
3210 case GL_RED_INTEGER_EXT
:
3211 set_swizzle(swizzle
, 0, 4, 4, 5);
3214 case GL_GREEN_INTEGER_EXT
:
3215 set_swizzle(swizzle
, 4, 0, 4, 5);
3218 case GL_BLUE_INTEGER_EXT
:
3219 set_swizzle(swizzle
, 4, 4, 0, 5);
3222 case GL_ALPHA_INTEGER_EXT
:
3223 set_swizzle(swizzle
, 4, 4, 4, 0);
3226 case GL_LUMINANCE_INTEGER_EXT
:
3227 set_swizzle(swizzle
, 0, 0, 0, 5);
3230 set_swizzle(swizzle
, 0, 0, 0, 0);
3238 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3239 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3240 * otherwise (for non-array formats).
3242 * This function will typically be used to compute a mesa format from a GL type
3243 * so we can then call _mesa_format_convert. This function does
3244 * not consider byte swapping, so it returns types assuming that no byte
3245 * swapping is involved. If byte swapping is involved then clients are supposed
3246 * to handle that on their side before calling _mesa_format_convert.
3248 * This function returns an uint32_t that can pack a mesa_format or a
3249 * mesa_array_format. Clients must check the mesa array format bit
3250 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3251 * format is a mesa_array_format or a mesa_format.
3254 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3256 bool is_array_format
= true;
3258 bool normalized
= false, is_float
= false, is_signed
= false;
3259 int num_channels
= 0, type_size
= 0;
3261 /* Extract array format type information from the OpenGL data type */
3263 case GL_UNSIGNED_BYTE
:
3270 case GL_UNSIGNED_SHORT
:
3277 case GL_UNSIGNED_INT
:
3285 case GL_HALF_FLOAT_OES
:
3296 is_array_format
= false;
3300 /* Extract array format swizzle information from the OpenGL format */
3301 if (is_array_format
)
3302 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3304 /* If this is an array format type after checking data type and format,
3305 * create the array format
3307 if (is_array_format
) {
3308 normalized
= !_mesa_is_enum_format_integer(format
);
3309 num_channels
= _mesa_components_in_format(format
);
3311 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3312 normalized
, num_channels
,
3313 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3316 /* Otherwise this is not an array format, so return the mesa_format
3317 * matching the OpenGL format and data type
3320 case GL_UNSIGNED_SHORT_5_6_5
:
3321 if (format
== GL_RGB
)
3322 return MESA_FORMAT_B5G6R5_UNORM
;
3323 else if (format
== GL_BGR
)
3324 return MESA_FORMAT_R5G6B5_UNORM
;
3325 else if (format
== GL_RGB_INTEGER
)
3326 return MESA_FORMAT_B5G6R5_UINT
;
3328 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3329 if (format
== GL_RGB
)
3330 return MESA_FORMAT_R5G6B5_UNORM
;
3331 else if (format
== GL_BGR
)
3332 return MESA_FORMAT_B5G6R5_UNORM
;
3333 else if (format
== GL_RGB_INTEGER
)
3334 return MESA_FORMAT_R5G6B5_UINT
;
3336 case GL_UNSIGNED_SHORT_4_4_4_4
:
3337 if (format
== GL_RGBA
)
3338 return MESA_FORMAT_A4B4G4R4_UNORM
;
3339 else if (format
== GL_BGRA
)
3340 return MESA_FORMAT_A4R4G4B4_UNORM
;
3341 else if (format
== GL_ABGR_EXT
)
3342 return MESA_FORMAT_R4G4B4A4_UNORM
;
3343 else if (format
== GL_RGBA_INTEGER
)
3344 return MESA_FORMAT_A4B4G4R4_UINT
;
3345 else if (format
== GL_BGRA_INTEGER
)
3346 return MESA_FORMAT_A4R4G4B4_UINT
;
3348 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3349 if (format
== GL_RGBA
)
3350 return MESA_FORMAT_R4G4B4A4_UNORM
;
3351 else if (format
== GL_BGRA
)
3352 return MESA_FORMAT_B4G4R4A4_UNORM
;
3353 else if (format
== GL_ABGR_EXT
)
3354 return MESA_FORMAT_A4B4G4R4_UNORM
;
3355 else if (format
== GL_RGBA_INTEGER
)
3356 return MESA_FORMAT_R4G4B4A4_UINT
;
3357 else if (format
== GL_BGRA_INTEGER
)
3358 return MESA_FORMAT_B4G4R4A4_UINT
;
3360 case GL_UNSIGNED_SHORT_5_5_5_1
:
3361 if (format
== GL_RGBA
)
3362 return MESA_FORMAT_A1B5G5R5_UNORM
;
3363 else if (format
== GL_BGRA
)
3364 return MESA_FORMAT_A1R5G5B5_UNORM
;
3365 else if (format
== GL_RGBA_INTEGER
)
3366 return MESA_FORMAT_A1B5G5R5_UINT
;
3367 else if (format
== GL_BGRA_INTEGER
)
3368 return MESA_FORMAT_A1R5G5B5_UINT
;
3370 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3371 if (format
== GL_RGBA
)
3372 return MESA_FORMAT_R5G5B5A1_UNORM
;
3373 else if (format
== GL_BGRA
)
3374 return MESA_FORMAT_B5G5R5A1_UNORM
;
3375 else if (format
== GL_RGBA_INTEGER
)
3376 return MESA_FORMAT_R5G5B5A1_UINT
;
3377 else if (format
== GL_BGRA_INTEGER
)
3378 return MESA_FORMAT_B5G5R5A1_UINT
;
3380 case GL_UNSIGNED_BYTE_3_3_2
:
3381 if (format
== GL_RGB
)
3382 return MESA_FORMAT_B2G3R3_UNORM
;
3383 else if (format
== GL_RGB_INTEGER
)
3384 return MESA_FORMAT_B2G3R3_UINT
;
3386 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3387 if (format
== GL_RGB
)
3388 return MESA_FORMAT_R3G3B2_UNORM
;
3389 else if (format
== GL_RGB_INTEGER
)
3390 return MESA_FORMAT_R3G3B2_UINT
;
3392 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3393 if (format
== GL_RGB
)
3394 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3396 case GL_UNSIGNED_INT_10_10_10_2
:
3397 if (format
== GL_RGBA
)
3398 return MESA_FORMAT_A2B10G10R10_UNORM
;
3399 else if (format
== GL_RGBA_INTEGER
)
3400 return MESA_FORMAT_A2B10G10R10_UINT
;
3401 else if (format
== GL_BGRA
)
3402 return MESA_FORMAT_A2R10G10B10_UNORM
;
3403 else if (format
== GL_BGRA_INTEGER
)
3404 return MESA_FORMAT_A2R10G10B10_UINT
;
3406 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3407 if (format
== GL_RGB
)
3408 return MESA_FORMAT_R10G10B10X2_UNORM
;
3409 if (format
== GL_RGBA
)
3410 return MESA_FORMAT_R10G10B10A2_UNORM
;
3411 else if (format
== GL_RGBA_INTEGER
)
3412 return MESA_FORMAT_R10G10B10A2_UINT
;
3413 else if (format
== GL_BGRA
)
3414 return MESA_FORMAT_B10G10R10A2_UNORM
;
3415 else if (format
== GL_BGRA_INTEGER
)
3416 return MESA_FORMAT_B10G10R10A2_UINT
;
3418 case GL_UNSIGNED_INT_8_8_8_8
:
3419 if (format
== GL_RGBA
)
3420 return MESA_FORMAT_A8B8G8R8_UNORM
;
3421 else if (format
== GL_BGRA
)
3422 return MESA_FORMAT_A8R8G8B8_UNORM
;
3423 else if (format
== GL_ABGR_EXT
)
3424 return MESA_FORMAT_R8G8B8A8_UNORM
;
3425 else if (format
== GL_RGBA_INTEGER
)
3426 return MESA_FORMAT_A8B8G8R8_UINT
;
3427 else if (format
== GL_BGRA_INTEGER
)
3428 return MESA_FORMAT_A8R8G8B8_UINT
;
3430 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3431 if (format
== GL_RGBA
)
3432 return MESA_FORMAT_R8G8B8A8_UNORM
;
3433 else if (format
== GL_BGRA
)
3434 return MESA_FORMAT_B8G8R8A8_UNORM
;
3435 else if (format
== GL_ABGR_EXT
)
3436 return MESA_FORMAT_A8B8G8R8_UNORM
;
3437 else if (format
== GL_RGBA_INTEGER
)
3438 return MESA_FORMAT_R8G8B8A8_UINT
;
3439 else if (format
== GL_BGRA_INTEGER
)
3440 return MESA_FORMAT_B8G8R8A8_UINT
;
3442 case GL_UNSIGNED_SHORT_8_8_MESA
:
3443 if (format
== GL_YCBCR_MESA
)
3444 return MESA_FORMAT_YCBCR
;
3446 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3447 if (format
== GL_YCBCR_MESA
)
3448 return MESA_FORMAT_YCBCR_REV
;
3450 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3451 if (format
== GL_RGB
)
3452 return MESA_FORMAT_R11G11B10_FLOAT
;
3457 /* If we got here it means that we could not find a Mesa format that
3458 * matches the GL format/type provided. We may need to add a new Mesa
3459 * format in that case.
3461 unreachable("Unsupported format");