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 2D format.
829 is_astc_2d_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
:
867 * Test if the given format is an ASTC 3D format.
870 is_astc_3d_format(GLenum internalFormat
)
872 switch (internalFormat
) {
873 case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES
:
874 case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES
:
875 case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES
:
876 case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES
:
877 case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES
:
878 case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES
:
879 case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES
:
880 case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES
:
881 case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES
:
882 case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES
:
883 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES
:
884 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES
:
885 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES
:
886 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES
:
887 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES
:
888 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES
:
889 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES
:
890 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES
:
891 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES
:
892 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES
:
900 * Test if the given format is an ASTC format.
903 _mesa_is_astc_format(GLenum internalFormat
)
905 return is_astc_2d_format(internalFormat
) ||
906 is_astc_3d_format(internalFormat
);
910 * Test if the given format is an integer (non-normalized) format.
913 _mesa_is_enum_format_integer(GLenum format
)
915 return _mesa_is_enum_format_unsigned_int(format
) ||
916 _mesa_is_enum_format_signed_int(format
);
921 _mesa_is_type_unsigned(GLenum type
)
924 case GL_UNSIGNED_INT
:
925 case GL_UNSIGNED_INT_8_8_8_8
:
926 case GL_UNSIGNED_INT_8_8_8_8_REV
:
927 case GL_UNSIGNED_INT_10_10_10_2
:
928 case GL_UNSIGNED_INT_2_10_10_10_REV
:
930 case GL_UNSIGNED_SHORT
:
931 case GL_UNSIGNED_SHORT_4_4_4_4
:
932 case GL_UNSIGNED_SHORT_5_5_5_1
:
933 case GL_UNSIGNED_SHORT_5_6_5
:
934 case GL_UNSIGNED_SHORT_5_6_5_REV
:
935 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
936 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
937 case GL_UNSIGNED_SHORT_8_8_MESA
:
938 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
940 case GL_UNSIGNED_BYTE
:
941 case GL_UNSIGNED_BYTE_3_3_2
:
942 case GL_UNSIGNED_BYTE_2_3_3_REV
:
952 * Test if the given image format is a color/RGBA format (i.e., not color
953 * index, depth, stencil, etc).
954 * \param format the image format value (may by an internal texture format)
955 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
958 _mesa_is_color_format(GLenum format
)
976 case GL_LUMINANCE_ALPHA
:
977 case GL_LUMINANCE4_ALPHA4
:
978 case GL_LUMINANCE6_ALPHA2
:
979 case GL_LUMINANCE8_ALPHA8
:
980 case GL_LUMINANCE12_ALPHA4
:
981 case GL_LUMINANCE12_ALPHA12
:
982 case GL_LUMINANCE16_ALPHA16
:
1015 /* float texture formats */
1016 case GL_ALPHA16F_ARB
:
1017 case GL_ALPHA32F_ARB
:
1018 case GL_LUMINANCE16F_ARB
:
1019 case GL_LUMINANCE32F_ARB
:
1020 case GL_LUMINANCE_ALPHA16F_ARB
:
1021 case GL_LUMINANCE_ALPHA32F_ARB
:
1022 case GL_INTENSITY16F_ARB
:
1023 case GL_INTENSITY32F_ARB
:
1030 case GL_RGBA16F_ARB
:
1031 case GL_RGBA32F_ARB
:
1032 /* compressed formats */
1033 case GL_COMPRESSED_ALPHA
:
1034 case GL_COMPRESSED_LUMINANCE
:
1035 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1036 case GL_COMPRESSED_INTENSITY
:
1037 case GL_COMPRESSED_RED
:
1038 case GL_COMPRESSED_RG
:
1039 case GL_COMPRESSED_RGB
:
1040 case GL_COMPRESSED_RGBA
:
1045 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1046 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1047 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1048 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1049 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1050 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1053 case GL_SRGB_ALPHA_EXT
:
1054 case GL_SRGB8_ALPHA8_EXT
:
1055 case GL_SLUMINANCE_ALPHA_EXT
:
1056 case GL_SLUMINANCE8_ALPHA8_EXT
:
1057 case GL_SLUMINANCE_EXT
:
1058 case GL_SLUMINANCE8_EXT
:
1059 case GL_COMPRESSED_SRGB_EXT
:
1060 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1061 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
1062 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1063 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1064 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1065 case GL_COMPRESSED_SLUMINANCE_EXT
:
1066 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
1067 case GL_COMPRESSED_RED_RGTC1
:
1068 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1069 case GL_COMPRESSED_RG_RGTC2
:
1070 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1071 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1072 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1073 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1074 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1075 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1076 case GL_ETC1_RGB8_OES
:
1077 case GL_COMPRESSED_RGB8_ETC2
:
1078 case GL_COMPRESSED_SRGB8_ETC2
:
1079 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1080 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1081 case GL_COMPRESSED_R11_EAC
:
1082 case GL_COMPRESSED_RG11_EAC
:
1083 case GL_COMPRESSED_SIGNED_R11_EAC
:
1084 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1085 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1086 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1087 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1088 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1089 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1090 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1091 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
1092 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
1093 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
1094 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
1095 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
1096 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
1097 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
1098 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
1099 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
1100 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
1101 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
1102 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
1103 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
1104 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
1105 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1106 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1107 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1108 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1109 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1110 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1111 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1112 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1113 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1114 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1115 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1116 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1117 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1118 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1119 /* generic integer formats */
1120 case GL_RED_INTEGER_EXT
:
1121 case GL_GREEN_INTEGER_EXT
:
1122 case GL_BLUE_INTEGER_EXT
:
1123 case GL_ALPHA_INTEGER_EXT
:
1124 case GL_RGB_INTEGER_EXT
:
1125 case GL_RGBA_INTEGER_EXT
:
1126 case GL_BGR_INTEGER_EXT
:
1127 case GL_BGRA_INTEGER_EXT
:
1129 case GL_LUMINANCE_INTEGER_EXT
:
1130 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1131 /* sized integer formats */
1132 case GL_RGBA32UI_EXT
:
1133 case GL_RGB32UI_EXT
:
1136 case GL_ALPHA32UI_EXT
:
1137 case GL_INTENSITY32UI_EXT
:
1138 case GL_LUMINANCE32UI_EXT
:
1139 case GL_LUMINANCE_ALPHA32UI_EXT
:
1140 case GL_RGBA16UI_EXT
:
1141 case GL_RGB16UI_EXT
:
1144 case GL_ALPHA16UI_EXT
:
1145 case GL_INTENSITY16UI_EXT
:
1146 case GL_LUMINANCE16UI_EXT
:
1147 case GL_LUMINANCE_ALPHA16UI_EXT
:
1148 case GL_RGBA8UI_EXT
:
1152 case GL_ALPHA8UI_EXT
:
1153 case GL_INTENSITY8UI_EXT
:
1154 case GL_LUMINANCE8UI_EXT
:
1155 case GL_LUMINANCE_ALPHA8UI_EXT
:
1156 case GL_RGBA32I_EXT
:
1160 case GL_ALPHA32I_EXT
:
1161 case GL_INTENSITY32I_EXT
:
1162 case GL_LUMINANCE32I_EXT
:
1163 case GL_LUMINANCE_ALPHA32I_EXT
:
1164 case GL_RGBA16I_EXT
:
1168 case GL_ALPHA16I_EXT
:
1169 case GL_INTENSITY16I_EXT
:
1170 case GL_LUMINANCE16I_EXT
:
1171 case GL_LUMINANCE_ALPHA16I_EXT
:
1176 case GL_ALPHA8I_EXT
:
1177 case GL_INTENSITY8I_EXT
:
1178 case GL_LUMINANCE8I_EXT
:
1179 case GL_LUMINANCE_ALPHA8I_EXT
:
1180 /* signed, normalized texture formats */
1189 case GL_RGB16_SNORM
:
1191 case GL_RGBA8_SNORM
:
1192 case GL_RGBA16_SNORM
:
1193 case GL_ALPHA_SNORM
:
1194 case GL_ALPHA8_SNORM
:
1195 case GL_ALPHA16_SNORM
:
1196 case GL_LUMINANCE_SNORM
:
1197 case GL_LUMINANCE8_SNORM
:
1198 case GL_LUMINANCE16_SNORM
:
1199 case GL_LUMINANCE_ALPHA_SNORM
:
1200 case GL_LUMINANCE8_ALPHA8_SNORM
:
1201 case GL_LUMINANCE16_ALPHA16_SNORM
:
1202 case GL_INTENSITY_SNORM
:
1203 case GL_INTENSITY8_SNORM
:
1204 case GL_INTENSITY16_SNORM
:
1206 case GL_R11F_G11F_B10F
:
1209 case GL_YCBCR_MESA
: /* not considered to be RGB */
1218 * Test if the given image format is a depth component format.
1221 _mesa_is_depth_format(GLenum format
)
1224 case GL_DEPTH_COMPONENT
:
1225 case GL_DEPTH_COMPONENT16
:
1226 case GL_DEPTH_COMPONENT24
:
1227 case GL_DEPTH_COMPONENT32
:
1228 case GL_DEPTH_COMPONENT32F
:
1237 * Test if the given image format is a stencil format.
1240 _mesa_is_stencil_format(GLenum format
)
1243 case GL_STENCIL_INDEX
:
1252 * Test if the given image format is a YCbCr format.
1255 _mesa_is_ycbcr_format(GLenum format
)
1267 * Test if the given image format is a depth+stencil format.
1270 _mesa_is_depthstencil_format(GLenum format
)
1273 case GL_DEPTH24_STENCIL8_EXT
:
1274 case GL_DEPTH_STENCIL_EXT
:
1275 case GL_DEPTH32F_STENCIL8
:
1284 * Test if the given image format is a depth or stencil format.
1287 _mesa_is_depth_or_stencil_format(GLenum format
)
1290 case GL_DEPTH_COMPONENT
:
1291 case GL_DEPTH_COMPONENT16
:
1292 case GL_DEPTH_COMPONENT24
:
1293 case GL_DEPTH_COMPONENT32
:
1294 case GL_STENCIL_INDEX
:
1295 case GL_STENCIL_INDEX1_EXT
:
1296 case GL_STENCIL_INDEX4_EXT
:
1297 case GL_STENCIL_INDEX8_EXT
:
1298 case GL_STENCIL_INDEX16_EXT
:
1299 case GL_DEPTH_STENCIL_EXT
:
1300 case GL_DEPTH24_STENCIL8_EXT
:
1301 case GL_DEPTH_COMPONENT32F
:
1302 case GL_DEPTH32F_STENCIL8
:
1311 * Test if an image format is a supported compressed format.
1312 * \param format the internal format token provided by the user.
1313 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1316 _mesa_is_compressed_format(const struct gl_context
*ctx
, GLenum format
)
1318 mesa_format m_format
= _mesa_glenum_to_compressed_format(format
);
1320 /* Some formats in this switch have an equivalent mesa_format_layout
1321 * to the compressed formats in the layout switch below and thus
1322 * must be handled first.
1329 return _mesa_is_desktop_gl(ctx
) &&
1330 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1331 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1332 return ctx
->API
== API_OPENGL_COMPAT
1333 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1334 case GL_PALETTE4_RGB8_OES
:
1335 case GL_PALETTE4_RGBA8_OES
:
1336 case GL_PALETTE4_R5_G6_B5_OES
:
1337 case GL_PALETTE4_RGBA4_OES
:
1338 case GL_PALETTE4_RGB5_A1_OES
:
1339 case GL_PALETTE8_RGB8_OES
:
1340 case GL_PALETTE8_RGBA8_OES
:
1341 case GL_PALETTE8_R5_G6_B5_OES
:
1342 case GL_PALETTE8_RGBA4_OES
:
1343 case GL_PALETTE8_RGB5_A1_OES
:
1344 return ctx
->API
== API_OPENGLES
;
1347 switch (_mesa_get_format_layout(m_format
)) {
1348 case MESA_FORMAT_LAYOUT_S3TC
:
1349 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1350 /* Assume that the ANGLE flag will always be set if the
1353 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1355 return _mesa_is_desktop_gl(ctx
)
1356 && ctx
->Extensions
.EXT_texture_sRGB
1357 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1359 case MESA_FORMAT_LAYOUT_FXT1
:
1360 return _mesa_is_desktop_gl(ctx
)
1361 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1362 case MESA_FORMAT_LAYOUT_RGTC
:
1363 return _mesa_is_desktop_gl(ctx
)
1364 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1365 case MESA_FORMAT_LAYOUT_LATC
:
1366 return ctx
->API
== API_OPENGL_COMPAT
1367 && ctx
->Extensions
.EXT_texture_compression_latc
;
1368 case MESA_FORMAT_LAYOUT_ETC1
:
1369 return _mesa_is_gles(ctx
)
1370 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1371 case MESA_FORMAT_LAYOUT_ETC2
:
1372 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1373 case MESA_FORMAT_LAYOUT_BPTC
:
1374 return _mesa_is_desktop_gl(ctx
) &&
1375 ctx
->Extensions
.ARB_texture_compression_bptc
;
1376 case MESA_FORMAT_LAYOUT_ASTC
:
1377 return ctx
->Extensions
.KHR_texture_compression_astc_ldr
;
1384 * Test if the given format represents an sRGB format.
1385 * \param format the GL format (can be an internal format)
1386 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1389 _mesa_is_srgb_format(GLenum format
)
1395 case GL_SRGB8_ALPHA8
:
1396 case GL_COMPRESSED_SRGB
:
1397 case GL_COMPRESSED_SRGB_ALPHA
:
1398 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1399 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1400 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1401 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1402 case GL_COMPRESSED_SRGB8_ETC2
:
1403 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1404 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1405 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1406 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1407 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1408 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1409 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1410 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1411 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1412 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1413 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1414 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1415 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1416 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1417 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1418 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1419 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1429 * Convert various unpack formats to the corresponding base format.
1432 _mesa_unpack_format_to_base_format(GLenum format
)
1435 case GL_RED_INTEGER
:
1437 case GL_GREEN_INTEGER
:
1439 case GL_BLUE_INTEGER
:
1441 case GL_ALPHA_INTEGER
:
1445 case GL_RGB_INTEGER
:
1447 case GL_RGBA_INTEGER
:
1449 case GL_BGR_INTEGER
:
1451 case GL_BGRA_INTEGER
:
1453 case GL_LUMINANCE_INTEGER_EXT
:
1454 return GL_LUMINANCE
;
1455 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1456 return GL_LUMINANCE_ALPHA
;
1467 case GL_LUMINANCE_ALPHA
:
1474 * Convert various base formats to the corresponding integer format.
1477 _mesa_base_format_to_integer_format(GLenum format
)
1481 return GL_RED_INTEGER
;
1483 return GL_GREEN_INTEGER
;
1485 return GL_BLUE_INTEGER
;
1487 return GL_RG_INTEGER
;
1489 return GL_RGB_INTEGER
;
1491 return GL_RGBA_INTEGER
;
1493 return GL_BGR_INTEGER
;
1495 return GL_BGRA_INTEGER
;
1497 return GL_ALPHA_INTEGER
;
1499 return GL_LUMINANCE_INTEGER_EXT
;
1500 case GL_LUMINANCE_ALPHA
:
1501 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1509 * Does the given base texture/renderbuffer format have the channel
1513 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1516 case GL_TEXTURE_RED_SIZE
:
1517 case GL_TEXTURE_RED_TYPE
:
1518 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1519 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1520 case GL_INTERNALFORMAT_RED_SIZE
:
1521 case GL_INTERNALFORMAT_RED_TYPE
:
1522 if (base_format
== GL_RED
||
1523 base_format
== GL_RG
||
1524 base_format
== GL_RGB
||
1525 base_format
== GL_RGBA
) {
1529 case GL_TEXTURE_GREEN_SIZE
:
1530 case GL_TEXTURE_GREEN_TYPE
:
1531 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1532 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1533 case GL_INTERNALFORMAT_GREEN_SIZE
:
1534 case GL_INTERNALFORMAT_GREEN_TYPE
:
1535 if (base_format
== GL_RG
||
1536 base_format
== GL_RGB
||
1537 base_format
== GL_RGBA
) {
1541 case GL_TEXTURE_BLUE_SIZE
:
1542 case GL_TEXTURE_BLUE_TYPE
:
1543 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1544 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1545 case GL_INTERNALFORMAT_BLUE_SIZE
:
1546 case GL_INTERNALFORMAT_BLUE_TYPE
:
1547 if (base_format
== GL_RGB
||
1548 base_format
== GL_RGBA
) {
1552 case GL_TEXTURE_ALPHA_SIZE
:
1553 case GL_TEXTURE_ALPHA_TYPE
:
1554 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1555 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1556 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1557 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1558 if (base_format
== GL_RGBA
||
1559 base_format
== GL_ALPHA
||
1560 base_format
== GL_LUMINANCE_ALPHA
) {
1564 case GL_TEXTURE_LUMINANCE_SIZE
:
1565 case GL_TEXTURE_LUMINANCE_TYPE
:
1566 if (base_format
== GL_LUMINANCE
||
1567 base_format
== GL_LUMINANCE_ALPHA
) {
1571 case GL_TEXTURE_INTENSITY_SIZE
:
1572 case GL_TEXTURE_INTENSITY_TYPE
:
1573 if (base_format
== GL_INTENSITY
) {
1577 case GL_TEXTURE_DEPTH_SIZE
:
1578 case GL_TEXTURE_DEPTH_TYPE
:
1579 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1580 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1581 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1582 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1583 if (base_format
== GL_DEPTH_STENCIL
||
1584 base_format
== GL_DEPTH_COMPONENT
) {
1588 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1589 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1590 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1591 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1592 if (base_format
== GL_DEPTH_STENCIL
||
1593 base_format
== GL_STENCIL_INDEX
) {
1598 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1608 * Returns the number of channels/components for a base format.
1611 _mesa_base_format_component_count(GLenum base_format
)
1613 switch (base_format
) {
1618 case GL_DEPTH_COMPONENT
:
1621 case GL_LUMINANCE_ALPHA
:
1622 case GL_DEPTH_STENCIL
:
1635 * If format is a generic compressed format, return the corresponding
1636 * non-compressed format. For other formats, return the format as-is.
1639 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1642 case GL_COMPRESSED_RED
:
1644 case GL_COMPRESSED_RG
:
1646 case GL_COMPRESSED_RGB
:
1648 case GL_COMPRESSED_RGBA
:
1650 case GL_COMPRESSED_ALPHA
:
1652 case GL_COMPRESSED_LUMINANCE
:
1653 return GL_LUMINANCE
;
1654 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1655 return GL_LUMINANCE_ALPHA
;
1656 case GL_COMPRESSED_INTENSITY
:
1657 return GL_INTENSITY
;
1659 case GL_COMPRESSED_SRGB
:
1661 case GL_COMPRESSED_SRGB_ALPHA
:
1662 return GL_SRGB_ALPHA
;
1663 case GL_COMPRESSED_SLUMINANCE
:
1664 return GL_SLUMINANCE
;
1665 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1666 return GL_SLUMINANCE_ALPHA
;
1674 * Return the equivalent non-generic internal format.
1675 * This is useful for comparing whether two internal formats are equivalent.
1678 _mesa_get_nongeneric_internalformat(GLenum format
)
1681 /* GL 1.1 formats. */
1689 case GL_LUMINANCE_ALPHA
:
1690 return GL_LUMINANCE8_ALPHA8
;
1693 return GL_LUMINANCE8
;
1697 return GL_INTENSITY8
;
1699 /* GL_ARB_texture_rg */
1705 /* GL_EXT_texture_sRGB */
1709 return GL_SRGB8_ALPHA8
;
1711 return GL_SLUMINANCE8
;
1712 case GL_SLUMINANCE_ALPHA
:
1713 return GL_SLUMINANCE8_ALPHA8
;
1715 /* GL_EXT_texture_snorm */
1717 return GL_RGBA8_SNORM
;
1719 return GL_RGB8_SNORM
;
1721 return GL_RG8_SNORM
;
1724 case GL_LUMINANCE_ALPHA_SNORM
:
1725 return GL_LUMINANCE8_ALPHA8_SNORM
;
1726 case GL_LUMINANCE_SNORM
:
1727 return GL_LUMINANCE8_SNORM
;
1728 case GL_ALPHA_SNORM
:
1729 return GL_ALPHA8_SNORM
;
1730 case GL_INTENSITY_SNORM
:
1731 return GL_INTENSITY8_SNORM
;
1740 * Convert an sRGB internal format to linear.
1743 _mesa_get_linear_internalformat(GLenum format
)
1752 case GL_SRGB8_ALPHA8
:
1754 case GL_SLUMINANCE8
:
1755 return GL_LUMINANCE8
;
1757 return GL_LUMINANCE
;
1758 case GL_SLUMINANCE_ALPHA
:
1759 return GL_LUMINANCE_ALPHA
;
1760 case GL_SLUMINANCE8_ALPHA8
:
1761 return GL_LUMINANCE8_ALPHA8
;
1769 * Do error checking of format/type combinations for glReadPixels,
1770 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1771 * and type values, we may either generate GL_INVALID_OPERATION or
1774 * \param format pixel format.
1775 * \param type pixel type.
1777 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1780 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1781 GLenum format
, GLenum type
)
1783 /* From OpenGL 3.3 spec, page 220:
1784 * "If the format is DEPTH_STENCIL, then values are taken from
1785 * both the depth buffer and the stencil buffer. If there is no
1786 * depth buffer or if there is no stencil buffer, then the error
1787 * INVALID_OPERATION occurs. If the type parameter is not
1788 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1789 * error INVALID_ENUM occurs."
1791 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1792 * cannot be used to read depth or stencil in that API.
1794 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1795 && type
!= GL_UNSIGNED_INT_24_8
1796 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1797 return GL_INVALID_ENUM
;
1799 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1802 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1803 return GL_INVALID_ENUM
;
1807 case GL_UNSIGNED_BYTE_3_3_2
:
1808 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1809 case GL_UNSIGNED_SHORT_5_6_5
:
1810 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1811 if (format
== GL_RGB
) {
1814 if (format
== GL_RGB_INTEGER_EXT
&&
1815 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1818 return GL_INVALID_OPERATION
;
1820 case GL_UNSIGNED_SHORT_4_4_4_4
:
1821 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1822 case GL_UNSIGNED_INT_8_8_8_8
:
1823 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1824 if (format
== GL_RGBA
||
1825 format
== GL_BGRA
||
1826 format
== GL_ABGR_EXT
) {
1829 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1830 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1833 return GL_INVALID_OPERATION
;
1835 case GL_UNSIGNED_SHORT_5_5_5_1
:
1836 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1837 case GL_UNSIGNED_INT_10_10_10_2
:
1838 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1839 if (format
== GL_RGBA
||
1840 format
== GL_BGRA
) {
1843 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1844 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1847 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1848 ctx
->API
== API_OPENGLES2
) {
1849 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1851 return GL_INVALID_OPERATION
;
1853 case GL_UNSIGNED_INT_24_8
:
1854 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1855 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1858 if (format
!= GL_DEPTH_STENCIL
) {
1859 return GL_INVALID_OPERATION
;
1863 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1864 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1865 return GL_INVALID_ENUM
;
1867 if (format
!= GL_DEPTH_STENCIL
) {
1868 return GL_INVALID_OPERATION
;
1872 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1873 if (!ctx
->Extensions
.EXT_packed_float
) {
1874 return GL_INVALID_ENUM
;
1876 if (format
!= GL_RGB
) {
1877 return GL_INVALID_OPERATION
;
1881 case GL_HALF_FLOAT_OES
:
1885 case GL_LUMINANCE_ALPHA
:
1891 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1894 return GL_INVALID_OPERATION
;
1898 ; /* fall-through */
1901 /* now, for each format, check the type for compatibility */
1903 case GL_COLOR_INDEX
:
1904 case GL_STENCIL_INDEX
:
1908 case GL_UNSIGNED_BYTE
:
1910 case GL_UNSIGNED_SHORT
:
1912 case GL_UNSIGNED_INT
:
1917 return GL_INVALID_ENUM
;
1924 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1928 case GL_LUMINANCE_ALPHA
:
1929 case GL_DEPTH_COMPONENT
:
1932 case GL_UNSIGNED_BYTE
:
1934 case GL_UNSIGNED_SHORT
:
1936 case GL_UNSIGNED_INT
:
1941 return GL_INVALID_ENUM
;
1945 if (!ctx
->Extensions
.ARB_texture_rg
)
1946 return GL_INVALID_ENUM
;
1949 case GL_UNSIGNED_BYTE
:
1951 case GL_UNSIGNED_SHORT
:
1953 case GL_UNSIGNED_INT
:
1958 return GL_INVALID_ENUM
;
1964 case GL_UNSIGNED_BYTE
:
1966 case GL_UNSIGNED_SHORT
:
1968 case GL_UNSIGNED_INT
:
1970 case GL_UNSIGNED_BYTE_3_3_2
:
1971 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1972 case GL_UNSIGNED_SHORT_5_6_5
:
1973 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1976 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1977 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1978 return (ctx
->API
== API_OPENGLES2
)
1979 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1980 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1981 return ctx
->Extensions
.EXT_texture_shared_exponent
1982 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1983 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1984 return ctx
->Extensions
.EXT_packed_float
1985 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1987 return GL_INVALID_ENUM
;
1992 /* NOTE: no packed types are supported with BGR. That's
1993 * intentional, according to the GL spec.
1996 case GL_UNSIGNED_BYTE
:
1998 case GL_UNSIGNED_SHORT
:
2000 case GL_UNSIGNED_INT
:
2005 return GL_INVALID_ENUM
;
2012 case GL_UNSIGNED_BYTE
:
2014 case GL_UNSIGNED_SHORT
:
2016 case GL_UNSIGNED_INT
:
2018 case GL_UNSIGNED_SHORT_4_4_4_4
:
2019 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2020 case GL_UNSIGNED_SHORT_5_5_5_1
:
2021 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2022 case GL_UNSIGNED_INT_8_8_8_8
:
2023 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2024 case GL_UNSIGNED_INT_10_10_10_2
:
2025 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2029 return GL_INVALID_ENUM
;
2035 case GL_UNSIGNED_BYTE
:
2037 case GL_UNSIGNED_SHORT
:
2039 case GL_UNSIGNED_INT
:
2041 case GL_UNSIGNED_SHORT_4_4_4_4
:
2042 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2043 case GL_UNSIGNED_INT_8_8_8_8
:
2044 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2048 return GL_INVALID_ENUM
;
2052 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2053 return GL_INVALID_ENUM
;
2054 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2055 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2058 return GL_INVALID_OPERATION
;
2060 case GL_DEPTH_STENCIL
:
2061 if (type
== GL_UNSIGNED_INT_24_8
)
2063 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2064 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2067 return GL_INVALID_ENUM
;
2069 /* integer-valued formats */
2070 case GL_RED_INTEGER_EXT
:
2071 case GL_GREEN_INTEGER_EXT
:
2072 case GL_BLUE_INTEGER_EXT
:
2073 case GL_ALPHA_INTEGER_EXT
:
2077 case GL_UNSIGNED_BYTE
:
2079 case GL_UNSIGNED_SHORT
:
2081 case GL_UNSIGNED_INT
:
2082 return (ctx
->Version
>= 30 ||
2083 ctx
->Extensions
.EXT_texture_integer
)
2084 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2086 return GL_INVALID_ENUM
;
2089 case GL_RGB_INTEGER_EXT
:
2092 case GL_UNSIGNED_BYTE
:
2094 case GL_UNSIGNED_SHORT
:
2096 case GL_UNSIGNED_INT
:
2097 return (ctx
->Version
>= 30 ||
2098 ctx
->Extensions
.EXT_texture_integer
)
2099 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2100 case GL_UNSIGNED_BYTE_3_3_2
:
2101 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2102 case GL_UNSIGNED_SHORT_5_6_5
:
2103 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2104 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2105 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2107 return GL_INVALID_ENUM
;
2110 case GL_BGR_INTEGER_EXT
:
2113 case GL_UNSIGNED_BYTE
:
2115 case GL_UNSIGNED_SHORT
:
2117 case GL_UNSIGNED_INT
:
2118 /* NOTE: no packed formats w/ BGR format */
2119 return (ctx
->Version
>= 30 ||
2120 ctx
->Extensions
.EXT_texture_integer
)
2121 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2123 return GL_INVALID_ENUM
;
2126 case GL_RGBA_INTEGER_EXT
:
2127 case GL_BGRA_INTEGER_EXT
:
2130 case GL_UNSIGNED_BYTE
:
2132 case GL_UNSIGNED_SHORT
:
2134 case GL_UNSIGNED_INT
:
2135 return (ctx
->Version
>= 30 ||
2136 ctx
->Extensions
.EXT_texture_integer
)
2137 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2138 case GL_UNSIGNED_SHORT_4_4_4_4
:
2139 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2140 case GL_UNSIGNED_SHORT_5_5_5_1
:
2141 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2142 case GL_UNSIGNED_INT_8_8_8_8
:
2143 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2144 case GL_UNSIGNED_INT_10_10_10_2
:
2145 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2146 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2147 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2149 return GL_INVALID_ENUM
;
2152 case GL_LUMINANCE_INTEGER_EXT
:
2153 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2156 case GL_UNSIGNED_BYTE
:
2158 case GL_UNSIGNED_SHORT
:
2160 case GL_UNSIGNED_INT
:
2161 return ctx
->Extensions
.EXT_texture_integer
2162 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2164 return GL_INVALID_ENUM
;
2168 return GL_INVALID_ENUM
;
2175 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2176 * and glTex[Sub]Image.
2177 * \return error code, or GL_NO_ERROR.
2180 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2181 GLenum format
, GLenum type
,
2182 unsigned dimensions
)
2184 GLboolean type_valid
= GL_TRUE
;
2189 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2190 return GL_INVALID_VALUE
;
2194 case GL_LUMINANCE_ALPHA
:
2195 type_valid
= (type
== GL_UNSIGNED_BYTE
2197 || type
== GL_HALF_FLOAT_OES
);
2201 type_valid
= (type
== GL_UNSIGNED_BYTE
2202 || type
== GL_UNSIGNED_SHORT_5_6_5
2204 || type
== GL_HALF_FLOAT_OES
);
2208 type_valid
= (type
== GL_UNSIGNED_BYTE
2209 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2210 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2212 || type
== GL_HALF_FLOAT_OES
2213 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2216 case GL_DEPTH_COMPONENT
:
2217 /* This format is filtered against invalid dimensionalities elsewhere.
2219 type_valid
= (type
== GL_UNSIGNED_SHORT
2220 || type
== GL_UNSIGNED_INT
);
2223 case GL_DEPTH_STENCIL
:
2224 /* This format is filtered against invalid dimensionalities elsewhere.
2226 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2230 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2232 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2233 * the format does not appear to be allowed for 3D textures in OpenGL
2236 if (dimensions
!= 2)
2237 return GL_INVALID_VALUE
;
2242 return GL_INVALID_VALUE
;
2245 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2249 * Return the simple base format for a given internal texture format.
2250 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2252 * \param ctx GL context.
2253 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2255 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2256 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2258 * This is the format which is used during texture application (i.e. the
2259 * texture format and env mode determine the arithmetic used.
2262 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2264 switch (internalFormat
) {
2270 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2275 case GL_LUMINANCE12
:
2276 case GL_LUMINANCE16
:
2277 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2279 case GL_LUMINANCE_ALPHA
:
2280 case GL_LUMINANCE4_ALPHA4
:
2281 case GL_LUMINANCE6_ALPHA2
:
2282 case GL_LUMINANCE8_ALPHA8
:
2283 case GL_LUMINANCE12_ALPHA4
:
2284 case GL_LUMINANCE12_ALPHA12
:
2285 case GL_LUMINANCE16_ALPHA16
:
2286 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2290 case GL_INTENSITY12
:
2291 case GL_INTENSITY16
:
2292 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2294 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2305 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2319 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2321 if (_mesa_is_gles(ctx
)) {
2322 switch (internalFormat
) {
2330 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2331 switch (internalFormat
) {
2339 if (ctx
->Extensions
.ARB_depth_texture
) {
2340 switch (internalFormat
) {
2341 case GL_DEPTH_COMPONENT
:
2342 case GL_DEPTH_COMPONENT16
:
2343 case GL_DEPTH_COMPONENT24
:
2344 case GL_DEPTH_COMPONENT32
:
2345 return GL_DEPTH_COMPONENT
;
2346 case GL_DEPTH_STENCIL
:
2347 case GL_DEPTH24_STENCIL8
:
2348 return GL_DEPTH_STENCIL
;
2354 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2355 switch (internalFormat
) {
2356 case GL_STENCIL_INDEX
:
2357 case GL_STENCIL_INDEX1
:
2358 case GL_STENCIL_INDEX4
:
2359 case GL_STENCIL_INDEX8
:
2360 case GL_STENCIL_INDEX16
:
2361 return GL_STENCIL_INDEX
;
2367 switch (internalFormat
) {
2368 case GL_COMPRESSED_ALPHA
:
2370 case GL_COMPRESSED_LUMINANCE
:
2371 return GL_LUMINANCE
;
2372 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2373 return GL_LUMINANCE_ALPHA
;
2374 case GL_COMPRESSED_INTENSITY
:
2375 return GL_INTENSITY
;
2376 case GL_COMPRESSED_RGB
:
2378 case GL_COMPRESSED_RGBA
:
2384 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2385 GLenum base_compressed
=
2386 _mesa_gl_compressed_format_base_format(internalFormat
);
2387 if (base_compressed
)
2388 return base_compressed
;
2391 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2392 _mesa_is_astc_format(internalFormat
))
2395 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2396 if (internalFormat
== GL_YCBCR_MESA
)
2397 return GL_YCBCR_MESA
;
2400 if (ctx
->Extensions
.ARB_texture_float
) {
2401 switch (internalFormat
) {
2402 case GL_ALPHA16F_ARB
:
2403 case GL_ALPHA32F_ARB
:
2405 case GL_RGBA16F_ARB
:
2406 case GL_RGBA32F_ARB
:
2411 case GL_INTENSITY16F_ARB
:
2412 case GL_INTENSITY32F_ARB
:
2413 return GL_INTENSITY
;
2414 case GL_LUMINANCE16F_ARB
:
2415 case GL_LUMINANCE32F_ARB
:
2416 return GL_LUMINANCE
;
2417 case GL_LUMINANCE_ALPHA16F_ARB
:
2418 case GL_LUMINANCE_ALPHA32F_ARB
:
2419 return GL_LUMINANCE_ALPHA
;
2425 if (ctx
->Extensions
.EXT_texture_snorm
) {
2426 switch (internalFormat
) {
2437 case GL_RGB16_SNORM
:
2440 case GL_RGBA8_SNORM
:
2441 case GL_RGBA16_SNORM
:
2443 case GL_ALPHA_SNORM
:
2444 case GL_ALPHA8_SNORM
:
2445 case GL_ALPHA16_SNORM
:
2447 case GL_LUMINANCE_SNORM
:
2448 case GL_LUMINANCE8_SNORM
:
2449 case GL_LUMINANCE16_SNORM
:
2450 return GL_LUMINANCE
;
2451 case GL_LUMINANCE_ALPHA_SNORM
:
2452 case GL_LUMINANCE8_ALPHA8_SNORM
:
2453 case GL_LUMINANCE16_ALPHA16_SNORM
:
2454 return GL_LUMINANCE_ALPHA
;
2455 case GL_INTENSITY_SNORM
:
2456 case GL_INTENSITY8_SNORM
:
2457 case GL_INTENSITY16_SNORM
:
2458 return GL_INTENSITY
;
2464 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2465 switch (internalFormat
) {
2468 case GL_COMPRESSED_SRGB_EXT
:
2470 case GL_SRGB_ALPHA_EXT
:
2471 case GL_SRGB8_ALPHA8_EXT
:
2472 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2474 case GL_SLUMINANCE_ALPHA_EXT
:
2475 case GL_SLUMINANCE8_ALPHA8_EXT
:
2476 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2477 return GL_LUMINANCE_ALPHA
;
2478 case GL_SLUMINANCE_EXT
:
2479 case GL_SLUMINANCE8_EXT
:
2480 case GL_COMPRESSED_SLUMINANCE_EXT
:
2481 return GL_LUMINANCE
;
2487 if (ctx
->Version
>= 30 ||
2488 ctx
->Extensions
.EXT_texture_integer
) {
2489 switch (internalFormat
) {
2490 case GL_RGBA8UI_EXT
:
2491 case GL_RGBA16UI_EXT
:
2492 case GL_RGBA32UI_EXT
:
2494 case GL_RGBA16I_EXT
:
2495 case GL_RGBA32I_EXT
:
2499 case GL_RGB16UI_EXT
:
2500 case GL_RGB32UI_EXT
:
2508 if (ctx
->Extensions
.EXT_texture_integer
) {
2509 switch (internalFormat
) {
2510 case GL_ALPHA8UI_EXT
:
2511 case GL_ALPHA16UI_EXT
:
2512 case GL_ALPHA32UI_EXT
:
2513 case GL_ALPHA8I_EXT
:
2514 case GL_ALPHA16I_EXT
:
2515 case GL_ALPHA32I_EXT
:
2517 case GL_INTENSITY8UI_EXT
:
2518 case GL_INTENSITY16UI_EXT
:
2519 case GL_INTENSITY32UI_EXT
:
2520 case GL_INTENSITY8I_EXT
:
2521 case GL_INTENSITY16I_EXT
:
2522 case GL_INTENSITY32I_EXT
:
2523 return GL_INTENSITY
;
2524 case GL_LUMINANCE8UI_EXT
:
2525 case GL_LUMINANCE16UI_EXT
:
2526 case GL_LUMINANCE32UI_EXT
:
2527 case GL_LUMINANCE8I_EXT
:
2528 case GL_LUMINANCE16I_EXT
:
2529 case GL_LUMINANCE32I_EXT
:
2530 return GL_LUMINANCE
;
2531 case GL_LUMINANCE_ALPHA8UI_EXT
:
2532 case GL_LUMINANCE_ALPHA16UI_EXT
:
2533 case GL_LUMINANCE_ALPHA32UI_EXT
:
2534 case GL_LUMINANCE_ALPHA8I_EXT
:
2535 case GL_LUMINANCE_ALPHA16I_EXT
:
2536 case GL_LUMINANCE_ALPHA32I_EXT
:
2537 return GL_LUMINANCE_ALPHA
;
2543 if (ctx
->Extensions
.ARB_texture_rg
) {
2544 switch (internalFormat
) {
2547 if (!ctx
->Extensions
.ARB_texture_float
)
2556 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2562 case GL_COMPRESSED_RED
:
2567 if (!ctx
->Extensions
.ARB_texture_float
)
2576 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2582 case GL_COMPRESSED_RG
:
2589 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2590 switch (internalFormat
) {
2591 case GL_RGB9_E5_EXT
:
2598 if (ctx
->Extensions
.EXT_packed_float
) {
2599 switch (internalFormat
) {
2600 case GL_R11F_G11F_B10F_EXT
:
2607 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2608 switch (internalFormat
) {
2609 case GL_DEPTH_COMPONENT32F
:
2610 return GL_DEPTH_COMPONENT
;
2611 case GL_DEPTH32F_STENCIL8
:
2612 return GL_DEPTH_STENCIL
;
2618 return -1; /* error */
2622 * Returns the effective internal format from a texture format and type.
2623 * This is used by texture image operations internally for validation, when
2624 * the specified internal format is a base (unsized) format.
2626 * This method will only return a valid effective internal format if the
2627 * combination of format, type and internal format in base form, is acceptable.
2629 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2630 * in extensions, to unambiguously correspond to the given base format, then
2631 * that internal format is returned as the effective. Otherwise, if the
2632 * combination is accepted but a single effective format is not defined, the
2633 * passed base format will be returned instead.
2635 * \param format the texture format
2636 * \param type the texture type
2639 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2643 case GL_UNSIGNED_BYTE
:
2653 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2654 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2655 * internal formats, they do not correspond to GL constants, so the base
2656 * format is returned instead.
2659 case GL_LUMINANCE_ALPHA
:
2666 case GL_UNSIGNED_SHORT_4_4_4_4
:
2667 if (format
== GL_RGBA
)
2671 case GL_UNSIGNED_SHORT_5_5_5_1
:
2672 if (format
== GL_RGBA
)
2676 case GL_UNSIGNED_SHORT_5_6_5
:
2677 if (format
== GL_RGB
)
2681 /* OES_packed_depth_stencil */
2682 case GL_UNSIGNED_INT_24_8
:
2683 if (format
== GL_DEPTH_STENCIL
)
2684 return GL_DEPTH24_STENCIL8
;
2687 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2688 if (format
== GL_DEPTH_STENCIL
)
2689 return GL_DEPTH32F_STENCIL8
;
2692 case GL_UNSIGNED_SHORT
:
2693 if (format
== GL_DEPTH_COMPONENT
)
2694 return GL_DEPTH_COMPONENT16
;
2697 case GL_UNSIGNED_INT
:
2698 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2701 if (format
== GL_DEPTH_COMPONENT
)
2705 /* OES_texture_float and OES_texture_half_float */
2707 if (format
== GL_DEPTH_COMPONENT
)
2708 return GL_DEPTH_COMPONENT32F
;
2710 case GL_HALF_FLOAT_OES
:
2714 case GL_LUMINANCE_ALPHA
:
2730 /* GL_EXT_texture_type_2_10_10_10_REV */
2731 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2740 /* fall through and return NONE */
2748 * Do error checking of format/type combinations for OpenGL ES 3
2750 * \return error code, or GL_NO_ERROR.
2753 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2754 GLenum format
, GLenum type
,
2755 GLenum internalFormat
)
2757 /* If internalFormat is an unsized format, then the effective internal
2758 * format derived from format and type should be used instead. Page 127,
2759 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2761 * "if internalformat is a base internal format, the effective
2762 * internal format is a sized internal format that is derived
2763 * from the format and type for internal use by the GL.
2764 * Table 3.12 specifies the mapping of format and type to effective
2765 * internal formats. The effective internal format is used by the GL
2766 * for purposes such as texture completeness or type checks for
2767 * CopyTex* commands. In these cases, the GL is required to operate
2768 * as if the effective internal format was used as the internalformat
2769 * when specifying the texture data."
2771 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2772 GLenum effectiveInternalFormat
=
2773 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2775 if (effectiveInternalFormat
== GL_NONE
)
2776 return GL_INVALID_OPERATION
;
2778 GLenum baseInternalFormat
;
2779 if (internalFormat
== GL_BGRA_EXT
) {
2780 /* Unfortunately, _mesa_base_tex_format returns a base format of
2781 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2782 * asking the question, "what channels does this format have?"
2783 * However, if we're trying to determine if two internal formats
2784 * match in the ES3 sense, we actually want GL_BGRA.
2786 baseInternalFormat
= GL_BGRA_EXT
;
2788 baseInternalFormat
=
2789 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2792 if (internalFormat
!= baseInternalFormat
)
2793 return GL_INVALID_OPERATION
;
2795 internalFormat
= effectiveInternalFormat
;
2800 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2801 return GL_INVALID_OPERATION
;
2806 case GL_UNSIGNED_BYTE
:
2807 switch (internalFormat
) {
2812 case GL_SRGB8_ALPHA8_EXT
:
2815 return GL_INVALID_OPERATION
;
2820 if (internalFormat
!= GL_RGBA8_SNORM
)
2821 return GL_INVALID_OPERATION
;
2824 case GL_UNSIGNED_SHORT_4_4_4_4
:
2825 switch (internalFormat
) {
2830 return GL_INVALID_OPERATION
;
2834 case GL_UNSIGNED_SHORT_5_5_5_1
:
2835 switch (internalFormat
) {
2840 return GL_INVALID_OPERATION
;
2844 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2845 switch (internalFormat
) {
2846 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2851 return GL_INVALID_OPERATION
;
2856 if (internalFormat
!= GL_RGBA16F
)
2857 return GL_INVALID_OPERATION
;
2861 switch (internalFormat
) {
2866 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2869 return GL_INVALID_OPERATION
;
2873 case GL_HALF_FLOAT_OES
:
2874 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2877 return GL_INVALID_OPERATION
;
2881 case GL_RGBA_INTEGER
:
2883 case GL_UNSIGNED_BYTE
:
2884 if (internalFormat
!= GL_RGBA8UI
)
2885 return GL_INVALID_OPERATION
;
2889 if (internalFormat
!= GL_RGBA8I
)
2890 return GL_INVALID_OPERATION
;
2893 case GL_UNSIGNED_SHORT
:
2894 if (internalFormat
!= GL_RGBA16UI
)
2895 return GL_INVALID_OPERATION
;
2899 if (internalFormat
!= GL_RGBA16I
)
2900 return GL_INVALID_OPERATION
;
2903 case GL_UNSIGNED_INT
:
2904 if (internalFormat
!= GL_RGBA32UI
)
2905 return GL_INVALID_OPERATION
;
2909 if (internalFormat
!= GL_RGBA32I
)
2910 return GL_INVALID_OPERATION
;
2913 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2914 if (internalFormat
!= GL_RGB10_A2UI
)
2915 return GL_INVALID_OPERATION
;
2919 return GL_INVALID_OPERATION
;
2925 case GL_UNSIGNED_BYTE
:
2926 switch (internalFormat
) {
2933 return GL_INVALID_OPERATION
;
2938 if (internalFormat
!= GL_RGB8_SNORM
)
2939 return GL_INVALID_OPERATION
;
2942 case GL_UNSIGNED_SHORT_5_6_5
:
2943 switch (internalFormat
) {
2948 return GL_INVALID_OPERATION
;
2952 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2953 if (internalFormat
!= GL_R11F_G11F_B10F
)
2954 return GL_INVALID_OPERATION
;
2957 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2958 if (internalFormat
!= GL_RGB9_E5
)
2959 return GL_INVALID_OPERATION
;
2963 switch (internalFormat
) {
2965 case GL_R11F_G11F_B10F
:
2969 return GL_INVALID_OPERATION
;
2974 switch (internalFormat
) {
2977 case GL_R11F_G11F_B10F
:
2981 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2984 return GL_INVALID_OPERATION
;
2988 case GL_HALF_FLOAT_OES
:
2989 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2990 return GL_INVALID_OPERATION
;
2993 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2994 switch (internalFormat
) {
2995 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2998 return GL_INVALID_OPERATION
;
3003 return GL_INVALID_OPERATION
;
3007 case GL_RGB_INTEGER
:
3009 case GL_UNSIGNED_BYTE
:
3010 if (internalFormat
!= GL_RGB8UI
)
3011 return GL_INVALID_OPERATION
;
3015 if (internalFormat
!= GL_RGB8I
)
3016 return GL_INVALID_OPERATION
;
3019 case GL_UNSIGNED_SHORT
:
3020 if (internalFormat
!= GL_RGB16UI
)
3021 return GL_INVALID_OPERATION
;
3025 if (internalFormat
!= GL_RGB16I
)
3026 return GL_INVALID_OPERATION
;
3029 case GL_UNSIGNED_INT
:
3030 if (internalFormat
!= GL_RGB32UI
)
3031 return GL_INVALID_OPERATION
;
3035 if (internalFormat
!= GL_RGB32I
)
3036 return GL_INVALID_OPERATION
;
3040 return GL_INVALID_OPERATION
;
3046 case GL_UNSIGNED_BYTE
:
3047 if (internalFormat
!= GL_RG8
)
3048 return GL_INVALID_OPERATION
;
3052 if (internalFormat
!= GL_RG8_SNORM
)
3053 return GL_INVALID_OPERATION
;
3057 case GL_HALF_FLOAT_OES
:
3058 switch (internalFormat
) {
3062 if (ctx
->Extensions
.ARB_texture_rg
&&
3063 ctx
->Extensions
.OES_texture_half_float
)
3067 return GL_INVALID_OPERATION
;
3072 switch (internalFormat
) {
3077 if (ctx
->Extensions
.ARB_texture_rg
&&
3078 ctx
->Extensions
.OES_texture_float
)
3082 return GL_INVALID_OPERATION
;
3087 return GL_INVALID_OPERATION
;
3093 case GL_UNSIGNED_BYTE
:
3094 if (internalFormat
!= GL_RG8UI
)
3095 return GL_INVALID_OPERATION
;
3099 if (internalFormat
!= GL_RG8I
)
3100 return GL_INVALID_OPERATION
;
3103 case GL_UNSIGNED_SHORT
:
3104 if (internalFormat
!= GL_RG16UI
)
3105 return GL_INVALID_OPERATION
;
3109 if (internalFormat
!= GL_RG16I
)
3110 return GL_INVALID_OPERATION
;
3113 case GL_UNSIGNED_INT
:
3114 if (internalFormat
!= GL_RG32UI
)
3115 return GL_INVALID_OPERATION
;
3119 if (internalFormat
!= GL_RG32I
)
3120 return GL_INVALID_OPERATION
;
3124 return GL_INVALID_OPERATION
;
3130 case GL_UNSIGNED_BYTE
:
3131 if (internalFormat
!= GL_R8
)
3132 return GL_INVALID_OPERATION
;
3136 if (internalFormat
!= GL_R8_SNORM
)
3137 return GL_INVALID_OPERATION
;
3141 case GL_HALF_FLOAT_OES
:
3142 switch (internalFormat
) {
3147 if (ctx
->Extensions
.ARB_texture_rg
&&
3148 ctx
->Extensions
.OES_texture_half_float
)
3152 return GL_INVALID_OPERATION
;
3157 switch (internalFormat
) {
3162 if (ctx
->Extensions
.ARB_texture_rg
&&
3163 ctx
->Extensions
.OES_texture_float
)
3167 return GL_INVALID_OPERATION
;
3172 return GL_INVALID_OPERATION
;
3176 case GL_RED_INTEGER
:
3178 case GL_UNSIGNED_BYTE
:
3179 if (internalFormat
!= GL_R8UI
)
3180 return GL_INVALID_OPERATION
;
3184 if (internalFormat
!= GL_R8I
)
3185 return GL_INVALID_OPERATION
;
3188 case GL_UNSIGNED_SHORT
:
3189 if (internalFormat
!= GL_R16UI
)
3190 return GL_INVALID_OPERATION
;
3194 if (internalFormat
!= GL_R16I
)
3195 return GL_INVALID_OPERATION
;
3198 case GL_UNSIGNED_INT
:
3199 if (internalFormat
!= GL_R32UI
)
3200 return GL_INVALID_OPERATION
;
3204 if (internalFormat
!= GL_R32I
)
3205 return GL_INVALID_OPERATION
;
3209 return GL_INVALID_OPERATION
;
3213 case GL_DEPTH_COMPONENT
:
3215 case GL_UNSIGNED_SHORT
:
3216 if (internalFormat
!= GL_DEPTH_COMPONENT
3217 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3218 return GL_INVALID_OPERATION
;
3221 case GL_UNSIGNED_INT
:
3222 switch (internalFormat
) {
3223 case GL_DEPTH_COMPONENT
:
3224 case GL_DEPTH_COMPONENT16
:
3225 case GL_DEPTH_COMPONENT24
:
3228 return GL_INVALID_OPERATION
;
3233 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3234 return GL_INVALID_OPERATION
;
3238 return GL_INVALID_OPERATION
;
3242 case GL_DEPTH_STENCIL
:
3244 case GL_UNSIGNED_INT_24_8
:
3245 if (internalFormat
!= GL_DEPTH_STENCIL
3246 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3247 return GL_INVALID_OPERATION
;
3250 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3251 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3252 return GL_INVALID_OPERATION
;
3256 return GL_INVALID_OPERATION
;
3260 case GL_STENCIL_INDEX
:
3261 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3262 type
!= GL_UNSIGNED_BYTE
||
3263 internalFormat
!= GL_STENCIL_INDEX8
) {
3264 return GL_INVALID_OPERATION
;
3270 case GL_LUMINANCE_ALPHA
:
3273 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3275 case GL_HALF_FLOAT_OES
:
3276 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3279 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3280 return GL_INVALID_OPERATION
;
3288 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3290 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3291 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3292 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3293 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3297 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3301 case GL_RGBA_INTEGER_EXT
:
3302 set_swizzle(swizzle
, 0, 1, 2, 3);
3305 case GL_BGRA_INTEGER_EXT
:
3306 set_swizzle(swizzle
, 2, 1, 0, 3);
3309 set_swizzle(swizzle
, 3, 2, 1, 0);
3312 case GL_RGB_INTEGER_EXT
:
3313 set_swizzle(swizzle
, 0, 1, 2, 5);
3316 case GL_BGR_INTEGER_EXT
:
3317 set_swizzle(swizzle
, 2, 1, 0, 5);
3319 case GL_LUMINANCE_ALPHA
:
3320 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3321 set_swizzle(swizzle
, 0, 0, 0, 1);
3325 set_swizzle(swizzle
, 0, 1, 4, 5);
3328 case GL_RED_INTEGER_EXT
:
3329 set_swizzle(swizzle
, 0, 4, 4, 5);
3332 case GL_GREEN_INTEGER_EXT
:
3333 set_swizzle(swizzle
, 4, 0, 4, 5);
3336 case GL_BLUE_INTEGER_EXT
:
3337 set_swizzle(swizzle
, 4, 4, 0, 5);
3340 case GL_ALPHA_INTEGER_EXT
:
3341 set_swizzle(swizzle
, 4, 4, 4, 0);
3344 case GL_LUMINANCE_INTEGER_EXT
:
3345 set_swizzle(swizzle
, 0, 0, 0, 5);
3348 set_swizzle(swizzle
, 0, 0, 0, 0);
3356 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3357 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3358 * otherwise (for non-array formats).
3360 * This function will typically be used to compute a mesa format from a GL type
3361 * so we can then call _mesa_format_convert. This function does
3362 * not consider byte swapping, so it returns types assuming that no byte
3363 * swapping is involved. If byte swapping is involved then clients are supposed
3364 * to handle that on their side before calling _mesa_format_convert.
3366 * This function returns an uint32_t that can pack a mesa_format or a
3367 * mesa_array_format. Clients must check the mesa array format bit
3368 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3369 * format is a mesa_array_format or a mesa_format.
3372 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3374 bool is_array_format
= true;
3376 bool normalized
= false, is_float
= false, is_signed
= false;
3377 int num_channels
= 0, type_size
= 0;
3379 /* Extract array format type information from the OpenGL data type */
3381 case GL_UNSIGNED_BYTE
:
3388 case GL_UNSIGNED_SHORT
:
3395 case GL_UNSIGNED_INT
:
3403 case GL_HALF_FLOAT_OES
:
3414 is_array_format
= false;
3418 /* Extract array format swizzle information from the OpenGL format */
3419 if (is_array_format
)
3420 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3422 /* If this is an array format type after checking data type and format,
3423 * create the array format
3425 if (is_array_format
) {
3426 normalized
= !_mesa_is_enum_format_integer(format
);
3427 num_channels
= _mesa_components_in_format(format
);
3429 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3430 normalized
, num_channels
,
3431 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3434 /* Otherwise this is not an array format, so return the mesa_format
3435 * matching the OpenGL format and data type
3438 case GL_UNSIGNED_SHORT_5_6_5
:
3439 if (format
== GL_RGB
)
3440 return MESA_FORMAT_B5G6R5_UNORM
;
3441 else if (format
== GL_BGR
)
3442 return MESA_FORMAT_R5G6B5_UNORM
;
3443 else if (format
== GL_RGB_INTEGER
)
3444 return MESA_FORMAT_B5G6R5_UINT
;
3446 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3447 if (format
== GL_RGB
)
3448 return MESA_FORMAT_R5G6B5_UNORM
;
3449 else if (format
== GL_BGR
)
3450 return MESA_FORMAT_B5G6R5_UNORM
;
3451 else if (format
== GL_RGB_INTEGER
)
3452 return MESA_FORMAT_R5G6B5_UINT
;
3454 case GL_UNSIGNED_SHORT_4_4_4_4
:
3455 if (format
== GL_RGBA
)
3456 return MESA_FORMAT_A4B4G4R4_UNORM
;
3457 else if (format
== GL_BGRA
)
3458 return MESA_FORMAT_A4R4G4B4_UNORM
;
3459 else if (format
== GL_ABGR_EXT
)
3460 return MESA_FORMAT_R4G4B4A4_UNORM
;
3461 else if (format
== GL_RGBA_INTEGER
)
3462 return MESA_FORMAT_A4B4G4R4_UINT
;
3463 else if (format
== GL_BGRA_INTEGER
)
3464 return MESA_FORMAT_A4R4G4B4_UINT
;
3466 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3467 if (format
== GL_RGBA
)
3468 return MESA_FORMAT_R4G4B4A4_UNORM
;
3469 else if (format
== GL_BGRA
)
3470 return MESA_FORMAT_B4G4R4A4_UNORM
;
3471 else if (format
== GL_ABGR_EXT
)
3472 return MESA_FORMAT_A4B4G4R4_UNORM
;
3473 else if (format
== GL_RGBA_INTEGER
)
3474 return MESA_FORMAT_R4G4B4A4_UINT
;
3475 else if (format
== GL_BGRA_INTEGER
)
3476 return MESA_FORMAT_B4G4R4A4_UINT
;
3478 case GL_UNSIGNED_SHORT_5_5_5_1
:
3479 if (format
== GL_RGBA
)
3480 return MESA_FORMAT_A1B5G5R5_UNORM
;
3481 else if (format
== GL_BGRA
)
3482 return MESA_FORMAT_A1R5G5B5_UNORM
;
3483 else if (format
== GL_RGBA_INTEGER
)
3484 return MESA_FORMAT_A1B5G5R5_UINT
;
3485 else if (format
== GL_BGRA_INTEGER
)
3486 return MESA_FORMAT_A1R5G5B5_UINT
;
3488 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3489 if (format
== GL_RGBA
)
3490 return MESA_FORMAT_R5G5B5A1_UNORM
;
3491 else if (format
== GL_BGRA
)
3492 return MESA_FORMAT_B5G5R5A1_UNORM
;
3493 else if (format
== GL_RGBA_INTEGER
)
3494 return MESA_FORMAT_R5G5B5A1_UINT
;
3495 else if (format
== GL_BGRA_INTEGER
)
3496 return MESA_FORMAT_B5G5R5A1_UINT
;
3498 case GL_UNSIGNED_BYTE_3_3_2
:
3499 if (format
== GL_RGB
)
3500 return MESA_FORMAT_B2G3R3_UNORM
;
3501 else if (format
== GL_RGB_INTEGER
)
3502 return MESA_FORMAT_B2G3R3_UINT
;
3504 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3505 if (format
== GL_RGB
)
3506 return MESA_FORMAT_R3G3B2_UNORM
;
3507 else if (format
== GL_RGB_INTEGER
)
3508 return MESA_FORMAT_R3G3B2_UINT
;
3510 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3511 if (format
== GL_RGB
)
3512 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3514 case GL_UNSIGNED_INT_10_10_10_2
:
3515 if (format
== GL_RGBA
)
3516 return MESA_FORMAT_A2B10G10R10_UNORM
;
3517 else if (format
== GL_RGBA_INTEGER
)
3518 return MESA_FORMAT_A2B10G10R10_UINT
;
3519 else if (format
== GL_BGRA
)
3520 return MESA_FORMAT_A2R10G10B10_UNORM
;
3521 else if (format
== GL_BGRA_INTEGER
)
3522 return MESA_FORMAT_A2R10G10B10_UINT
;
3524 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3525 if (format
== GL_RGB
)
3526 return MESA_FORMAT_R10G10B10X2_UNORM
;
3527 if (format
== GL_RGBA
)
3528 return MESA_FORMAT_R10G10B10A2_UNORM
;
3529 else if (format
== GL_RGBA_INTEGER
)
3530 return MESA_FORMAT_R10G10B10A2_UINT
;
3531 else if (format
== GL_BGRA
)
3532 return MESA_FORMAT_B10G10R10A2_UNORM
;
3533 else if (format
== GL_BGRA_INTEGER
)
3534 return MESA_FORMAT_B10G10R10A2_UINT
;
3536 case GL_UNSIGNED_INT_8_8_8_8
:
3537 if (format
== GL_RGBA
)
3538 return MESA_FORMAT_A8B8G8R8_UNORM
;
3539 else if (format
== GL_BGRA
)
3540 return MESA_FORMAT_A8R8G8B8_UNORM
;
3541 else if (format
== GL_ABGR_EXT
)
3542 return MESA_FORMAT_R8G8B8A8_UNORM
;
3543 else if (format
== GL_RGBA_INTEGER
)
3544 return MESA_FORMAT_A8B8G8R8_UINT
;
3545 else if (format
== GL_BGRA_INTEGER
)
3546 return MESA_FORMAT_A8R8G8B8_UINT
;
3548 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3549 if (format
== GL_RGBA
)
3550 return MESA_FORMAT_R8G8B8A8_UNORM
;
3551 else if (format
== GL_BGRA
)
3552 return MESA_FORMAT_B8G8R8A8_UNORM
;
3553 else if (format
== GL_ABGR_EXT
)
3554 return MESA_FORMAT_A8B8G8R8_UNORM
;
3555 else if (format
== GL_RGBA_INTEGER
)
3556 return MESA_FORMAT_R8G8B8A8_UINT
;
3557 else if (format
== GL_BGRA_INTEGER
)
3558 return MESA_FORMAT_B8G8R8A8_UINT
;
3560 case GL_UNSIGNED_SHORT_8_8_MESA
:
3561 if (format
== GL_YCBCR_MESA
)
3562 return MESA_FORMAT_YCBCR
;
3564 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3565 if (format
== GL_YCBCR_MESA
)
3566 return MESA_FORMAT_YCBCR_REV
;
3568 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3569 if (format
== GL_RGB
)
3570 return MESA_FORMAT_R11G11B10_FLOAT
;
3573 if (format
== GL_DEPTH_COMPONENT
)
3574 return MESA_FORMAT_Z_FLOAT32
;
3576 case GL_UNSIGNED_INT
:
3577 if (format
== GL_DEPTH_COMPONENT
)
3578 return MESA_FORMAT_Z_UNORM32
;
3580 case GL_UNSIGNED_SHORT
:
3581 if (format
== GL_DEPTH_COMPONENT
)
3582 return MESA_FORMAT_Z_UNORM16
;
3584 case GL_UNSIGNED_INT_24_8
:
3585 if (format
== GL_DEPTH_STENCIL
)
3586 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3588 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3589 if (format
== GL_DEPTH_STENCIL
)
3590 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3596 /* If we got here it means that we could not find a Mesa format that
3597 * matches the GL format/type provided. We may need to add a new Mesa
3598 * format in that case.
3600 unreachable("Unsupported format");
3604 * Returns true if \p internal_format is a sized internal format that
3605 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3608 _mesa_is_es3_color_renderable(GLenum internal_format
)
3610 switch (internal_format
) {
3620 case GL_SRGB8_ALPHA8
:
3627 case GL_R11F_G11F_B10F
:
3653 * Returns true if \p internal_format is a sized internal format that
3654 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3657 _mesa_is_es3_texture_filterable(GLenum internal_format
)
3659 switch (internal_format
) {
3670 case GL_RGBA8_SNORM
:
3673 case GL_SRGB8_ALPHA8
:
3678 case GL_R11F_G11F_B10F
: