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
:
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 integer (non-normalized) format.
903 _mesa_is_enum_format_integer(GLenum format
)
905 return _mesa_is_enum_format_unsigned_int(format
) ||
906 _mesa_is_enum_format_signed_int(format
);
911 _mesa_is_type_unsigned(GLenum type
)
914 case GL_UNSIGNED_INT
:
915 case GL_UNSIGNED_INT_8_8_8_8
:
916 case GL_UNSIGNED_INT_8_8_8_8_REV
:
917 case GL_UNSIGNED_INT_10_10_10_2
:
918 case GL_UNSIGNED_INT_2_10_10_10_REV
:
920 case GL_UNSIGNED_SHORT
:
921 case GL_UNSIGNED_SHORT_4_4_4_4
:
922 case GL_UNSIGNED_SHORT_5_5_5_1
:
923 case GL_UNSIGNED_SHORT_5_6_5
:
924 case GL_UNSIGNED_SHORT_5_6_5_REV
:
925 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
926 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
927 case GL_UNSIGNED_SHORT_8_8_MESA
:
928 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
930 case GL_UNSIGNED_BYTE
:
931 case GL_UNSIGNED_BYTE_3_3_2
:
932 case GL_UNSIGNED_BYTE_2_3_3_REV
:
942 * Test if the given image format is a color/RGBA format (i.e., not color
943 * index, depth, stencil, etc).
944 * \param format the image format value (may by an internal texture format)
945 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
948 _mesa_is_color_format(GLenum format
)
966 case GL_LUMINANCE_ALPHA
:
967 case GL_LUMINANCE4_ALPHA4
:
968 case GL_LUMINANCE6_ALPHA2
:
969 case GL_LUMINANCE8_ALPHA8
:
970 case GL_LUMINANCE12_ALPHA4
:
971 case GL_LUMINANCE12_ALPHA12
:
972 case GL_LUMINANCE16_ALPHA16
:
1005 /* float texture formats */
1006 case GL_ALPHA16F_ARB
:
1007 case GL_ALPHA32F_ARB
:
1008 case GL_LUMINANCE16F_ARB
:
1009 case GL_LUMINANCE32F_ARB
:
1010 case GL_LUMINANCE_ALPHA16F_ARB
:
1011 case GL_LUMINANCE_ALPHA32F_ARB
:
1012 case GL_INTENSITY16F_ARB
:
1013 case GL_INTENSITY32F_ARB
:
1020 case GL_RGBA16F_ARB
:
1021 case GL_RGBA32F_ARB
:
1022 /* compressed formats */
1023 case GL_COMPRESSED_ALPHA
:
1024 case GL_COMPRESSED_LUMINANCE
:
1025 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1026 case GL_COMPRESSED_INTENSITY
:
1027 case GL_COMPRESSED_RED
:
1028 case GL_COMPRESSED_RG
:
1029 case GL_COMPRESSED_RGB
:
1030 case GL_COMPRESSED_RGBA
:
1035 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1036 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1037 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1038 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1039 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1040 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1043 case GL_SRGB_ALPHA_EXT
:
1044 case GL_SRGB8_ALPHA8_EXT
:
1045 case GL_SLUMINANCE_ALPHA_EXT
:
1046 case GL_SLUMINANCE8_ALPHA8_EXT
:
1047 case GL_SLUMINANCE_EXT
:
1048 case GL_SLUMINANCE8_EXT
:
1049 case GL_COMPRESSED_SRGB_EXT
:
1050 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1051 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
1052 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1053 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1054 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1055 case GL_COMPRESSED_SLUMINANCE_EXT
:
1056 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
1057 case GL_COMPRESSED_RED_RGTC1
:
1058 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1059 case GL_COMPRESSED_RG_RGTC2
:
1060 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1061 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1062 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1063 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1064 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1065 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1066 case GL_ETC1_RGB8_OES
:
1067 case GL_COMPRESSED_RGB8_ETC2
:
1068 case GL_COMPRESSED_SRGB8_ETC2
:
1069 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1070 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1071 case GL_COMPRESSED_R11_EAC
:
1072 case GL_COMPRESSED_RG11_EAC
:
1073 case GL_COMPRESSED_SIGNED_R11_EAC
:
1074 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1075 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1076 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1077 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1078 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1079 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1080 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1081 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
1082 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
1083 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
1084 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
1085 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
1086 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
1087 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
1088 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
1089 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
1090 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
1091 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
1092 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
1093 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
1094 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
1095 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1096 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1097 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1098 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1099 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1100 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1101 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1102 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1103 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1104 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1105 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1106 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1107 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1108 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1109 /* generic integer formats */
1110 case GL_RED_INTEGER_EXT
:
1111 case GL_GREEN_INTEGER_EXT
:
1112 case GL_BLUE_INTEGER_EXT
:
1113 case GL_ALPHA_INTEGER_EXT
:
1114 case GL_RGB_INTEGER_EXT
:
1115 case GL_RGBA_INTEGER_EXT
:
1116 case GL_BGR_INTEGER_EXT
:
1117 case GL_BGRA_INTEGER_EXT
:
1119 case GL_LUMINANCE_INTEGER_EXT
:
1120 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1121 /* sized integer formats */
1122 case GL_RGBA32UI_EXT
:
1123 case GL_RGB32UI_EXT
:
1126 case GL_ALPHA32UI_EXT
:
1127 case GL_INTENSITY32UI_EXT
:
1128 case GL_LUMINANCE32UI_EXT
:
1129 case GL_LUMINANCE_ALPHA32UI_EXT
:
1130 case GL_RGBA16UI_EXT
:
1131 case GL_RGB16UI_EXT
:
1134 case GL_ALPHA16UI_EXT
:
1135 case GL_INTENSITY16UI_EXT
:
1136 case GL_LUMINANCE16UI_EXT
:
1137 case GL_LUMINANCE_ALPHA16UI_EXT
:
1138 case GL_RGBA8UI_EXT
:
1142 case GL_ALPHA8UI_EXT
:
1143 case GL_INTENSITY8UI_EXT
:
1144 case GL_LUMINANCE8UI_EXT
:
1145 case GL_LUMINANCE_ALPHA8UI_EXT
:
1146 case GL_RGBA32I_EXT
:
1150 case GL_ALPHA32I_EXT
:
1151 case GL_INTENSITY32I_EXT
:
1152 case GL_LUMINANCE32I_EXT
:
1153 case GL_LUMINANCE_ALPHA32I_EXT
:
1154 case GL_RGBA16I_EXT
:
1158 case GL_ALPHA16I_EXT
:
1159 case GL_INTENSITY16I_EXT
:
1160 case GL_LUMINANCE16I_EXT
:
1161 case GL_LUMINANCE_ALPHA16I_EXT
:
1166 case GL_ALPHA8I_EXT
:
1167 case GL_INTENSITY8I_EXT
:
1168 case GL_LUMINANCE8I_EXT
:
1169 case GL_LUMINANCE_ALPHA8I_EXT
:
1170 /* signed, normalized texture formats */
1179 case GL_RGB16_SNORM
:
1181 case GL_RGBA8_SNORM
:
1182 case GL_RGBA16_SNORM
:
1183 case GL_ALPHA_SNORM
:
1184 case GL_ALPHA8_SNORM
:
1185 case GL_ALPHA16_SNORM
:
1186 case GL_LUMINANCE_SNORM
:
1187 case GL_LUMINANCE8_SNORM
:
1188 case GL_LUMINANCE16_SNORM
:
1189 case GL_LUMINANCE_ALPHA_SNORM
:
1190 case GL_LUMINANCE8_ALPHA8_SNORM
:
1191 case GL_LUMINANCE16_ALPHA16_SNORM
:
1192 case GL_INTENSITY_SNORM
:
1193 case GL_INTENSITY8_SNORM
:
1194 case GL_INTENSITY16_SNORM
:
1196 case GL_R11F_G11F_B10F
:
1199 case GL_YCBCR_MESA
: /* not considered to be RGB */
1208 * Test if the given image format is a depth component format.
1211 _mesa_is_depth_format(GLenum format
)
1214 case GL_DEPTH_COMPONENT
:
1215 case GL_DEPTH_COMPONENT16
:
1216 case GL_DEPTH_COMPONENT24
:
1217 case GL_DEPTH_COMPONENT32
:
1218 case GL_DEPTH_COMPONENT32F
:
1227 * Test if the given image format is a stencil format.
1230 _mesa_is_stencil_format(GLenum format
)
1233 case GL_STENCIL_INDEX
:
1242 * Test if the given image format is a YCbCr format.
1245 _mesa_is_ycbcr_format(GLenum format
)
1257 * Test if the given image format is a depth+stencil format.
1260 _mesa_is_depthstencil_format(GLenum format
)
1263 case GL_DEPTH24_STENCIL8_EXT
:
1264 case GL_DEPTH_STENCIL_EXT
:
1265 case GL_DEPTH32F_STENCIL8
:
1274 * Test if the given image format is a depth or stencil format.
1277 _mesa_is_depth_or_stencil_format(GLenum format
)
1280 case GL_DEPTH_COMPONENT
:
1281 case GL_DEPTH_COMPONENT16
:
1282 case GL_DEPTH_COMPONENT24
:
1283 case GL_DEPTH_COMPONENT32
:
1284 case GL_STENCIL_INDEX
:
1285 case GL_STENCIL_INDEX1_EXT
:
1286 case GL_STENCIL_INDEX4_EXT
:
1287 case GL_STENCIL_INDEX8_EXT
:
1288 case GL_STENCIL_INDEX16_EXT
:
1289 case GL_DEPTH_STENCIL_EXT
:
1290 case GL_DEPTH24_STENCIL8_EXT
:
1291 case GL_DEPTH_COMPONENT32F
:
1292 case GL_DEPTH32F_STENCIL8
:
1301 * Test if an image format is a supported compressed format.
1302 * \param format the internal format token provided by the user.
1303 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1306 _mesa_is_compressed_format(const struct gl_context
*ctx
, GLenum format
)
1308 mesa_format m_format
= _mesa_glenum_to_compressed_format(format
);
1310 /* Some formats in this switch have an equivalent mesa_format_layout
1311 * to the compressed formats in the layout switch below and thus
1312 * must be handled first.
1319 return _mesa_is_desktop_gl(ctx
) &&
1320 ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1321 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1322 return ctx
->API
== API_OPENGL_COMPAT
1323 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1324 case GL_PALETTE4_RGB8_OES
:
1325 case GL_PALETTE4_RGBA8_OES
:
1326 case GL_PALETTE4_R5_G6_B5_OES
:
1327 case GL_PALETTE4_RGBA4_OES
:
1328 case GL_PALETTE4_RGB5_A1_OES
:
1329 case GL_PALETTE8_RGB8_OES
:
1330 case GL_PALETTE8_RGBA8_OES
:
1331 case GL_PALETTE8_R5_G6_B5_OES
:
1332 case GL_PALETTE8_RGBA4_OES
:
1333 case GL_PALETTE8_RGB5_A1_OES
:
1334 return ctx
->API
== API_OPENGLES
;
1337 switch (_mesa_get_format_layout(m_format
)) {
1338 case MESA_FORMAT_LAYOUT_S3TC
:
1339 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1340 /* Assume that the ANGLE flag will always be set if the
1343 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1345 return _mesa_is_desktop_gl(ctx
)
1346 && ctx
->Extensions
.EXT_texture_sRGB
1347 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1349 case MESA_FORMAT_LAYOUT_FXT1
:
1350 return _mesa_is_desktop_gl(ctx
)
1351 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1352 case MESA_FORMAT_LAYOUT_RGTC
:
1353 return _mesa_is_desktop_gl(ctx
)
1354 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1355 case MESA_FORMAT_LAYOUT_LATC
:
1356 return ctx
->API
== API_OPENGL_COMPAT
1357 && ctx
->Extensions
.EXT_texture_compression_latc
;
1358 case MESA_FORMAT_LAYOUT_ETC1
:
1359 return _mesa_is_gles(ctx
)
1360 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1361 case MESA_FORMAT_LAYOUT_ETC2
:
1362 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1363 case MESA_FORMAT_LAYOUT_BPTC
:
1364 return _mesa_is_desktop_gl(ctx
) &&
1365 ctx
->Extensions
.ARB_texture_compression_bptc
;
1366 case MESA_FORMAT_LAYOUT_ASTC
:
1367 return ctx
->Extensions
.KHR_texture_compression_astc_ldr
;
1374 * Test if the given format represents an sRGB format.
1375 * \param format the GL format (can be an internal format)
1376 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1379 _mesa_is_srgb_format(GLenum format
)
1385 case GL_SRGB8_ALPHA8
:
1386 case GL_COMPRESSED_SRGB
:
1387 case GL_COMPRESSED_SRGB_ALPHA
:
1388 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1389 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1390 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1391 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1392 case GL_COMPRESSED_SRGB8_ETC2
:
1393 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1394 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1395 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1396 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1397 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1398 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1399 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1400 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1401 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1402 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1403 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1404 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1405 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1406 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1407 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1408 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1409 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1419 * Convert various unpack formats to the corresponding base format.
1422 _mesa_unpack_format_to_base_format(GLenum format
)
1425 case GL_RED_INTEGER
:
1427 case GL_GREEN_INTEGER
:
1429 case GL_BLUE_INTEGER
:
1431 case GL_ALPHA_INTEGER
:
1435 case GL_RGB_INTEGER
:
1437 case GL_RGBA_INTEGER
:
1439 case GL_BGR_INTEGER
:
1441 case GL_BGRA_INTEGER
:
1443 case GL_LUMINANCE_INTEGER_EXT
:
1444 return GL_LUMINANCE
;
1445 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1446 return GL_LUMINANCE_ALPHA
;
1457 case GL_LUMINANCE_ALPHA
:
1464 * Convert various base formats to the corresponding integer format.
1467 _mesa_base_format_to_integer_format(GLenum format
)
1471 return GL_RED_INTEGER
;
1473 return GL_GREEN_INTEGER
;
1475 return GL_BLUE_INTEGER
;
1477 return GL_RG_INTEGER
;
1479 return GL_RGB_INTEGER
;
1481 return GL_RGBA_INTEGER
;
1483 return GL_BGR_INTEGER
;
1485 return GL_BGRA_INTEGER
;
1487 return GL_ALPHA_INTEGER
;
1489 return GL_LUMINANCE_INTEGER_EXT
;
1490 case GL_LUMINANCE_ALPHA
:
1491 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1499 * Does the given base texture/renderbuffer format have the channel
1503 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1506 case GL_TEXTURE_RED_SIZE
:
1507 case GL_TEXTURE_RED_TYPE
:
1508 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1509 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1510 case GL_INTERNALFORMAT_RED_SIZE
:
1511 case GL_INTERNALFORMAT_RED_TYPE
:
1512 if (base_format
== GL_RED
||
1513 base_format
== GL_RG
||
1514 base_format
== GL_RGB
||
1515 base_format
== GL_RGBA
) {
1519 case GL_TEXTURE_GREEN_SIZE
:
1520 case GL_TEXTURE_GREEN_TYPE
:
1521 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1522 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1523 case GL_INTERNALFORMAT_GREEN_SIZE
:
1524 case GL_INTERNALFORMAT_GREEN_TYPE
:
1525 if (base_format
== GL_RG
||
1526 base_format
== GL_RGB
||
1527 base_format
== GL_RGBA
) {
1531 case GL_TEXTURE_BLUE_SIZE
:
1532 case GL_TEXTURE_BLUE_TYPE
:
1533 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1534 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1535 case GL_INTERNALFORMAT_BLUE_SIZE
:
1536 case GL_INTERNALFORMAT_BLUE_TYPE
:
1537 if (base_format
== GL_RGB
||
1538 base_format
== GL_RGBA
) {
1542 case GL_TEXTURE_ALPHA_SIZE
:
1543 case GL_TEXTURE_ALPHA_TYPE
:
1544 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1545 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1546 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1547 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1548 if (base_format
== GL_RGBA
||
1549 base_format
== GL_ALPHA
||
1550 base_format
== GL_LUMINANCE_ALPHA
) {
1554 case GL_TEXTURE_LUMINANCE_SIZE
:
1555 case GL_TEXTURE_LUMINANCE_TYPE
:
1556 if (base_format
== GL_LUMINANCE
||
1557 base_format
== GL_LUMINANCE_ALPHA
) {
1561 case GL_TEXTURE_INTENSITY_SIZE
:
1562 case GL_TEXTURE_INTENSITY_TYPE
:
1563 if (base_format
== GL_INTENSITY
) {
1567 case GL_TEXTURE_DEPTH_SIZE
:
1568 case GL_TEXTURE_DEPTH_TYPE
:
1569 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1570 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1571 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1572 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1573 if (base_format
== GL_DEPTH_STENCIL
||
1574 base_format
== GL_DEPTH_COMPONENT
) {
1578 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1579 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1580 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1581 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1582 if (base_format
== GL_DEPTH_STENCIL
||
1583 base_format
== GL_STENCIL_INDEX
) {
1588 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1598 * Returns the number of channels/components for a base format.
1601 _mesa_base_format_component_count(GLenum base_format
)
1603 switch (base_format
) {
1608 case GL_DEPTH_COMPONENT
:
1611 case GL_LUMINANCE_ALPHA
:
1612 case GL_DEPTH_STENCIL
:
1625 * If format is a generic compressed format, return the corresponding
1626 * non-compressed format. For other formats, return the format as-is.
1629 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1632 case GL_COMPRESSED_RED
:
1634 case GL_COMPRESSED_RG
:
1636 case GL_COMPRESSED_RGB
:
1638 case GL_COMPRESSED_RGBA
:
1640 case GL_COMPRESSED_ALPHA
:
1642 case GL_COMPRESSED_LUMINANCE
:
1643 return GL_LUMINANCE
;
1644 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1645 return GL_LUMINANCE_ALPHA
;
1646 case GL_COMPRESSED_INTENSITY
:
1647 return GL_INTENSITY
;
1649 case GL_COMPRESSED_SRGB
:
1651 case GL_COMPRESSED_SRGB_ALPHA
:
1652 return GL_SRGB_ALPHA
;
1653 case GL_COMPRESSED_SLUMINANCE
:
1654 return GL_SLUMINANCE
;
1655 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1656 return GL_SLUMINANCE_ALPHA
;
1664 * Return the equivalent non-generic internal format.
1665 * This is useful for comparing whether two internal formats are equivalent.
1668 _mesa_get_nongeneric_internalformat(GLenum format
)
1671 /* GL 1.1 formats. */
1679 case GL_LUMINANCE_ALPHA
:
1680 return GL_LUMINANCE8_ALPHA8
;
1683 return GL_LUMINANCE8
;
1687 return GL_INTENSITY8
;
1689 /* GL_ARB_texture_rg */
1695 /* GL_EXT_texture_sRGB */
1699 return GL_SRGB8_ALPHA8
;
1701 return GL_SLUMINANCE8
;
1702 case GL_SLUMINANCE_ALPHA
:
1703 return GL_SLUMINANCE8_ALPHA8
;
1705 /* GL_EXT_texture_snorm */
1707 return GL_RGBA8_SNORM
;
1709 return GL_RGB8_SNORM
;
1711 return GL_RG8_SNORM
;
1714 case GL_LUMINANCE_ALPHA_SNORM
:
1715 return GL_LUMINANCE8_ALPHA8_SNORM
;
1716 case GL_LUMINANCE_SNORM
:
1717 return GL_LUMINANCE8_SNORM
;
1718 case GL_ALPHA_SNORM
:
1719 return GL_ALPHA8_SNORM
;
1720 case GL_INTENSITY_SNORM
:
1721 return GL_INTENSITY8_SNORM
;
1730 * Convert an sRGB internal format to linear.
1733 _mesa_get_linear_internalformat(GLenum format
)
1742 case GL_SRGB8_ALPHA8
:
1744 case GL_SLUMINANCE8
:
1745 return GL_LUMINANCE8
;
1747 return GL_LUMINANCE
;
1748 case GL_SLUMINANCE_ALPHA
:
1749 return GL_LUMINANCE_ALPHA
;
1750 case GL_SLUMINANCE8_ALPHA8
:
1751 return GL_LUMINANCE8_ALPHA8
;
1759 * Do error checking of format/type combinations for glReadPixels,
1760 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1761 * and type values, we may either generate GL_INVALID_OPERATION or
1764 * \param format pixel format.
1765 * \param type pixel type.
1767 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1770 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1771 GLenum format
, GLenum type
)
1773 /* From OpenGL 3.3 spec, page 220:
1774 * "If the format is DEPTH_STENCIL, then values are taken from
1775 * both the depth buffer and the stencil buffer. If there is no
1776 * depth buffer or if there is no stencil buffer, then the error
1777 * INVALID_OPERATION occurs. If the type parameter is not
1778 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1779 * error INVALID_ENUM occurs."
1781 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1782 * cannot be used to read depth or stencil in that API.
1784 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1785 && type
!= GL_UNSIGNED_INT_24_8
1786 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1787 return GL_INVALID_ENUM
;
1789 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1792 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1793 return GL_INVALID_ENUM
;
1797 case GL_UNSIGNED_BYTE_3_3_2
:
1798 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1799 case GL_UNSIGNED_SHORT_5_6_5
:
1800 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1801 if (format
== GL_RGB
) {
1804 if (format
== GL_RGB_INTEGER_EXT
&&
1805 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1808 return GL_INVALID_OPERATION
;
1810 case GL_UNSIGNED_SHORT_4_4_4_4
:
1811 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1812 case GL_UNSIGNED_INT_8_8_8_8
:
1813 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1814 if (format
== GL_RGBA
||
1815 format
== GL_BGRA
||
1816 format
== GL_ABGR_EXT
) {
1819 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1820 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1823 return GL_INVALID_OPERATION
;
1825 case GL_UNSIGNED_SHORT_5_5_5_1
:
1826 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1827 case GL_UNSIGNED_INT_10_10_10_2
:
1828 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1829 if (format
== GL_RGBA
||
1830 format
== GL_BGRA
) {
1833 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1834 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1837 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1838 ctx
->API
== API_OPENGLES2
) {
1839 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1841 return GL_INVALID_OPERATION
;
1843 case GL_UNSIGNED_INT_24_8
:
1844 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1845 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1848 if (format
!= GL_DEPTH_STENCIL
) {
1849 return GL_INVALID_OPERATION
;
1853 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1854 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1855 return GL_INVALID_ENUM
;
1857 if (format
!= GL_DEPTH_STENCIL
) {
1858 return GL_INVALID_OPERATION
;
1862 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1863 if (!ctx
->Extensions
.EXT_packed_float
) {
1864 return GL_INVALID_ENUM
;
1866 if (format
!= GL_RGB
) {
1867 return GL_INVALID_OPERATION
;
1871 case GL_HALF_FLOAT_OES
:
1875 case GL_LUMINANCE_ALPHA
:
1881 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1884 return GL_INVALID_OPERATION
;
1888 ; /* fall-through */
1891 /* now, for each format, check the type for compatibility */
1893 case GL_COLOR_INDEX
:
1894 case GL_STENCIL_INDEX
:
1898 case GL_UNSIGNED_BYTE
:
1900 case GL_UNSIGNED_SHORT
:
1902 case GL_UNSIGNED_INT
:
1907 return GL_INVALID_ENUM
;
1914 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1918 case GL_LUMINANCE_ALPHA
:
1919 case GL_DEPTH_COMPONENT
:
1922 case GL_UNSIGNED_BYTE
:
1924 case GL_UNSIGNED_SHORT
:
1926 case GL_UNSIGNED_INT
:
1931 return GL_INVALID_ENUM
;
1935 if (!ctx
->Extensions
.ARB_texture_rg
)
1936 return GL_INVALID_ENUM
;
1939 case GL_UNSIGNED_BYTE
:
1941 case GL_UNSIGNED_SHORT
:
1943 case GL_UNSIGNED_INT
:
1948 return GL_INVALID_ENUM
;
1954 case GL_UNSIGNED_BYTE
:
1956 case GL_UNSIGNED_SHORT
:
1958 case GL_UNSIGNED_INT
:
1960 case GL_UNSIGNED_BYTE_3_3_2
:
1961 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1962 case GL_UNSIGNED_SHORT_5_6_5
:
1963 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1966 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1967 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1968 return (ctx
->API
== API_OPENGLES2
)
1969 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1970 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1971 return ctx
->Extensions
.EXT_texture_shared_exponent
1972 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1973 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1974 return ctx
->Extensions
.EXT_packed_float
1975 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1977 return GL_INVALID_ENUM
;
1982 /* NOTE: no packed types are supported with BGR. That's
1983 * intentional, according to the GL spec.
1986 case GL_UNSIGNED_BYTE
:
1988 case GL_UNSIGNED_SHORT
:
1990 case GL_UNSIGNED_INT
:
1995 return GL_INVALID_ENUM
;
2002 case GL_UNSIGNED_BYTE
:
2004 case GL_UNSIGNED_SHORT
:
2006 case GL_UNSIGNED_INT
:
2008 case GL_UNSIGNED_SHORT_4_4_4_4
:
2009 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2010 case GL_UNSIGNED_SHORT_5_5_5_1
:
2011 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2012 case GL_UNSIGNED_INT_8_8_8_8
:
2013 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2014 case GL_UNSIGNED_INT_10_10_10_2
:
2015 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2019 return GL_INVALID_ENUM
;
2025 case GL_UNSIGNED_BYTE
:
2027 case GL_UNSIGNED_SHORT
:
2029 case GL_UNSIGNED_INT
:
2031 case GL_UNSIGNED_SHORT_4_4_4_4
:
2032 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2033 case GL_UNSIGNED_INT_8_8_8_8
:
2034 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2038 return GL_INVALID_ENUM
;
2042 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2043 return GL_INVALID_ENUM
;
2044 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2045 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2048 return GL_INVALID_OPERATION
;
2050 case GL_DEPTH_STENCIL
:
2051 if (type
== GL_UNSIGNED_INT_24_8
)
2053 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2054 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2057 return GL_INVALID_ENUM
;
2059 /* integer-valued formats */
2060 case GL_RED_INTEGER_EXT
:
2061 case GL_GREEN_INTEGER_EXT
:
2062 case GL_BLUE_INTEGER_EXT
:
2063 case GL_ALPHA_INTEGER_EXT
:
2067 case GL_UNSIGNED_BYTE
:
2069 case GL_UNSIGNED_SHORT
:
2071 case GL_UNSIGNED_INT
:
2072 return (ctx
->Version
>= 30 ||
2073 ctx
->Extensions
.EXT_texture_integer
)
2074 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2076 return GL_INVALID_ENUM
;
2079 case GL_RGB_INTEGER_EXT
:
2082 case GL_UNSIGNED_BYTE
:
2084 case GL_UNSIGNED_SHORT
:
2086 case GL_UNSIGNED_INT
:
2087 return (ctx
->Version
>= 30 ||
2088 ctx
->Extensions
.EXT_texture_integer
)
2089 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2090 case GL_UNSIGNED_BYTE_3_3_2
:
2091 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2092 case GL_UNSIGNED_SHORT_5_6_5
:
2093 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2094 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2095 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2097 return GL_INVALID_ENUM
;
2100 case GL_BGR_INTEGER_EXT
:
2103 case GL_UNSIGNED_BYTE
:
2105 case GL_UNSIGNED_SHORT
:
2107 case GL_UNSIGNED_INT
:
2108 /* NOTE: no packed formats w/ BGR format */
2109 return (ctx
->Version
>= 30 ||
2110 ctx
->Extensions
.EXT_texture_integer
)
2111 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2113 return GL_INVALID_ENUM
;
2116 case GL_RGBA_INTEGER_EXT
:
2117 case GL_BGRA_INTEGER_EXT
:
2120 case GL_UNSIGNED_BYTE
:
2122 case GL_UNSIGNED_SHORT
:
2124 case GL_UNSIGNED_INT
:
2125 return (ctx
->Version
>= 30 ||
2126 ctx
->Extensions
.EXT_texture_integer
)
2127 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2128 case GL_UNSIGNED_SHORT_4_4_4_4
:
2129 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2130 case GL_UNSIGNED_SHORT_5_5_5_1
:
2131 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2132 case GL_UNSIGNED_INT_8_8_8_8
:
2133 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2134 case GL_UNSIGNED_INT_10_10_10_2
:
2135 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2136 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2137 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2139 return GL_INVALID_ENUM
;
2142 case GL_LUMINANCE_INTEGER_EXT
:
2143 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2146 case GL_UNSIGNED_BYTE
:
2148 case GL_UNSIGNED_SHORT
:
2150 case GL_UNSIGNED_INT
:
2151 return ctx
->Extensions
.EXT_texture_integer
2152 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2154 return GL_INVALID_ENUM
;
2158 return GL_INVALID_ENUM
;
2165 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2166 * and glTex[Sub]Image.
2167 * \return error code, or GL_NO_ERROR.
2170 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2171 GLenum format
, GLenum type
,
2172 unsigned dimensions
)
2174 GLboolean type_valid
= GL_TRUE
;
2179 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2180 return GL_INVALID_VALUE
;
2184 case GL_LUMINANCE_ALPHA
:
2185 type_valid
= (type
== GL_UNSIGNED_BYTE
2187 || type
== GL_HALF_FLOAT_OES
);
2191 type_valid
= (type
== GL_UNSIGNED_BYTE
2192 || type
== GL_UNSIGNED_SHORT_5_6_5
2194 || type
== GL_HALF_FLOAT_OES
);
2198 type_valid
= (type
== GL_UNSIGNED_BYTE
2199 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2200 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2202 || type
== GL_HALF_FLOAT_OES
2203 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
2206 case GL_DEPTH_COMPONENT
:
2207 /* This format is filtered against invalid dimensionalities elsewhere.
2209 type_valid
= (type
== GL_UNSIGNED_SHORT
2210 || type
== GL_UNSIGNED_INT
);
2213 case GL_DEPTH_STENCIL
:
2214 /* This format is filtered against invalid dimensionalities elsewhere.
2216 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2220 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2222 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2223 * the format does not appear to be allowed for 3D textures in OpenGL
2226 if (dimensions
!= 2)
2227 return GL_INVALID_VALUE
;
2232 return GL_INVALID_VALUE
;
2235 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2239 * Return the simple base format for a given internal texture format.
2240 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2242 * \param ctx GL context.
2243 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2245 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2246 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2248 * This is the format which is used during texture application (i.e. the
2249 * texture format and env mode determine the arithmetic used.
2252 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2254 switch (internalFormat
) {
2260 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2265 case GL_LUMINANCE12
:
2266 case GL_LUMINANCE16
:
2267 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2269 case GL_LUMINANCE_ALPHA
:
2270 case GL_LUMINANCE4_ALPHA4
:
2271 case GL_LUMINANCE6_ALPHA2
:
2272 case GL_LUMINANCE8_ALPHA8
:
2273 case GL_LUMINANCE12_ALPHA4
:
2274 case GL_LUMINANCE12_ALPHA12
:
2275 case GL_LUMINANCE16_ALPHA16
:
2276 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2280 case GL_INTENSITY12
:
2281 case GL_INTENSITY16
:
2282 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2284 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2295 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2309 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2311 if (_mesa_is_gles(ctx
)) {
2312 switch (internalFormat
) {
2320 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
2321 switch (internalFormat
) {
2329 if (ctx
->Extensions
.ARB_depth_texture
) {
2330 switch (internalFormat
) {
2331 case GL_DEPTH_COMPONENT
:
2332 case GL_DEPTH_COMPONENT16
:
2333 case GL_DEPTH_COMPONENT24
:
2334 case GL_DEPTH_COMPONENT32
:
2335 return GL_DEPTH_COMPONENT
;
2336 case GL_DEPTH_STENCIL
:
2337 case GL_DEPTH24_STENCIL8
:
2338 return GL_DEPTH_STENCIL
;
2344 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2345 switch (internalFormat
) {
2346 case GL_STENCIL_INDEX
:
2347 case GL_STENCIL_INDEX1
:
2348 case GL_STENCIL_INDEX4
:
2349 case GL_STENCIL_INDEX8
:
2350 case GL_STENCIL_INDEX16
:
2351 return GL_STENCIL_INDEX
;
2357 switch (internalFormat
) {
2358 case GL_COMPRESSED_ALPHA
:
2360 case GL_COMPRESSED_LUMINANCE
:
2361 return GL_LUMINANCE
;
2362 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2363 return GL_LUMINANCE_ALPHA
;
2364 case GL_COMPRESSED_INTENSITY
:
2365 return GL_INTENSITY
;
2366 case GL_COMPRESSED_RGB
:
2368 case GL_COMPRESSED_RGBA
:
2374 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2375 GLenum base_compressed
=
2376 _mesa_gl_compressed_format_base_format(internalFormat
);
2377 if (base_compressed
)
2378 return base_compressed
;
2381 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2382 _mesa_is_astc_format(internalFormat
))
2385 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2386 if (internalFormat
== GL_YCBCR_MESA
)
2387 return GL_YCBCR_MESA
;
2390 if (ctx
->Extensions
.ARB_texture_float
) {
2391 switch (internalFormat
) {
2392 case GL_ALPHA16F_ARB
:
2393 case GL_ALPHA32F_ARB
:
2395 case GL_RGBA16F_ARB
:
2396 case GL_RGBA32F_ARB
:
2401 case GL_INTENSITY16F_ARB
:
2402 case GL_INTENSITY32F_ARB
:
2403 return GL_INTENSITY
;
2404 case GL_LUMINANCE16F_ARB
:
2405 case GL_LUMINANCE32F_ARB
:
2406 return GL_LUMINANCE
;
2407 case GL_LUMINANCE_ALPHA16F_ARB
:
2408 case GL_LUMINANCE_ALPHA32F_ARB
:
2409 return GL_LUMINANCE_ALPHA
;
2415 if (ctx
->Extensions
.EXT_texture_snorm
) {
2416 switch (internalFormat
) {
2427 case GL_RGB16_SNORM
:
2430 case GL_RGBA8_SNORM
:
2431 case GL_RGBA16_SNORM
:
2433 case GL_ALPHA_SNORM
:
2434 case GL_ALPHA8_SNORM
:
2435 case GL_ALPHA16_SNORM
:
2437 case GL_LUMINANCE_SNORM
:
2438 case GL_LUMINANCE8_SNORM
:
2439 case GL_LUMINANCE16_SNORM
:
2440 return GL_LUMINANCE
;
2441 case GL_LUMINANCE_ALPHA_SNORM
:
2442 case GL_LUMINANCE8_ALPHA8_SNORM
:
2443 case GL_LUMINANCE16_ALPHA16_SNORM
:
2444 return GL_LUMINANCE_ALPHA
;
2445 case GL_INTENSITY_SNORM
:
2446 case GL_INTENSITY8_SNORM
:
2447 case GL_INTENSITY16_SNORM
:
2448 return GL_INTENSITY
;
2454 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2455 switch (internalFormat
) {
2458 case GL_COMPRESSED_SRGB_EXT
:
2460 case GL_SRGB_ALPHA_EXT
:
2461 case GL_SRGB8_ALPHA8_EXT
:
2462 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2464 case GL_SLUMINANCE_ALPHA_EXT
:
2465 case GL_SLUMINANCE8_ALPHA8_EXT
:
2466 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2467 return GL_LUMINANCE_ALPHA
;
2468 case GL_SLUMINANCE_EXT
:
2469 case GL_SLUMINANCE8_EXT
:
2470 case GL_COMPRESSED_SLUMINANCE_EXT
:
2471 return GL_LUMINANCE
;
2477 if (ctx
->Version
>= 30 ||
2478 ctx
->Extensions
.EXT_texture_integer
) {
2479 switch (internalFormat
) {
2480 case GL_RGBA8UI_EXT
:
2481 case GL_RGBA16UI_EXT
:
2482 case GL_RGBA32UI_EXT
:
2484 case GL_RGBA16I_EXT
:
2485 case GL_RGBA32I_EXT
:
2489 case GL_RGB16UI_EXT
:
2490 case GL_RGB32UI_EXT
:
2498 if (ctx
->Extensions
.EXT_texture_integer
) {
2499 switch (internalFormat
) {
2500 case GL_ALPHA8UI_EXT
:
2501 case GL_ALPHA16UI_EXT
:
2502 case GL_ALPHA32UI_EXT
:
2503 case GL_ALPHA8I_EXT
:
2504 case GL_ALPHA16I_EXT
:
2505 case GL_ALPHA32I_EXT
:
2507 case GL_INTENSITY8UI_EXT
:
2508 case GL_INTENSITY16UI_EXT
:
2509 case GL_INTENSITY32UI_EXT
:
2510 case GL_INTENSITY8I_EXT
:
2511 case GL_INTENSITY16I_EXT
:
2512 case GL_INTENSITY32I_EXT
:
2513 return GL_INTENSITY
;
2514 case GL_LUMINANCE8UI_EXT
:
2515 case GL_LUMINANCE16UI_EXT
:
2516 case GL_LUMINANCE32UI_EXT
:
2517 case GL_LUMINANCE8I_EXT
:
2518 case GL_LUMINANCE16I_EXT
:
2519 case GL_LUMINANCE32I_EXT
:
2520 return GL_LUMINANCE
;
2521 case GL_LUMINANCE_ALPHA8UI_EXT
:
2522 case GL_LUMINANCE_ALPHA16UI_EXT
:
2523 case GL_LUMINANCE_ALPHA32UI_EXT
:
2524 case GL_LUMINANCE_ALPHA8I_EXT
:
2525 case GL_LUMINANCE_ALPHA16I_EXT
:
2526 case GL_LUMINANCE_ALPHA32I_EXT
:
2527 return GL_LUMINANCE_ALPHA
;
2533 if (ctx
->Extensions
.ARB_texture_rg
) {
2534 switch (internalFormat
) {
2537 if (!ctx
->Extensions
.ARB_texture_float
)
2546 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2552 case GL_COMPRESSED_RED
:
2557 if (!ctx
->Extensions
.ARB_texture_float
)
2566 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2572 case GL_COMPRESSED_RG
:
2579 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2580 switch (internalFormat
) {
2581 case GL_RGB9_E5_EXT
:
2588 if (ctx
->Extensions
.EXT_packed_float
) {
2589 switch (internalFormat
) {
2590 case GL_R11F_G11F_B10F_EXT
:
2597 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2598 switch (internalFormat
) {
2599 case GL_DEPTH_COMPONENT32F
:
2600 return GL_DEPTH_COMPONENT
;
2601 case GL_DEPTH32F_STENCIL8
:
2602 return GL_DEPTH_STENCIL
;
2608 return -1; /* error */
2612 * Returns the effective internal format from a texture format and type.
2613 * This is used by texture image operations internally for validation, when
2614 * the specified internal format is a base (unsized) format.
2616 * This method will only return a valid effective internal format if the
2617 * combination of format, type and internal format in base form, is acceptable.
2619 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2620 * in extensions, to unambiguously correspond to the given base format, then
2621 * that internal format is returned as the effective. Otherwise, if the
2622 * combination is accepted but a single effective format is not defined, the
2623 * passed base format will be returned instead.
2625 * \param format the texture format
2626 * \param type the texture type
2629 _mesa_es3_effective_internal_format_for_format_and_type(GLenum format
,
2633 case GL_UNSIGNED_BYTE
:
2643 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2644 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2645 * internal formats, they do not correspond to GL constants, so the base
2646 * format is returned instead.
2649 case GL_LUMINANCE_ALPHA
:
2656 case GL_UNSIGNED_SHORT_4_4_4_4
:
2657 if (format
== GL_RGBA
)
2661 case GL_UNSIGNED_SHORT_5_5_5_1
:
2662 if (format
== GL_RGBA
)
2666 case GL_UNSIGNED_SHORT_5_6_5
:
2667 if (format
== GL_RGB
)
2671 /* OES_packed_depth_stencil */
2672 case GL_UNSIGNED_INT_24_8
:
2673 if (format
== GL_DEPTH_STENCIL
)
2674 return GL_DEPTH24_STENCIL8
;
2677 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2678 if (format
== GL_DEPTH_STENCIL
)
2679 return GL_DEPTH32F_STENCIL8
;
2682 case GL_UNSIGNED_SHORT
:
2683 if (format
== GL_DEPTH_COMPONENT
)
2684 return GL_DEPTH_COMPONENT16
;
2687 case GL_UNSIGNED_INT
:
2688 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2691 if (format
== GL_DEPTH_COMPONENT
)
2695 /* OES_texture_float and OES_texture_half_float */
2697 if (format
== GL_DEPTH_COMPONENT
)
2698 return GL_DEPTH_COMPONENT32F
;
2700 case GL_HALF_FLOAT_OES
:
2704 case GL_LUMINANCE_ALPHA
:
2720 /* GL_EXT_texture_type_2_10_10_10_REV */
2721 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2730 /* fall through and return NONE */
2738 * Do error checking of format/type combinations for OpenGL ES 3
2740 * \return error code, or GL_NO_ERROR.
2743 _mesa_es3_error_check_format_and_type(const struct gl_context
*ctx
,
2744 GLenum format
, GLenum type
,
2745 GLenum internalFormat
)
2747 /* If internalFormat is an unsized format, then the effective internal
2748 * format derived from format and type should be used instead. Page 127,
2749 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2751 * "if internalformat is a base internal format, the effective
2752 * internal format is a sized internal format that is derived
2753 * from the format and type for internal use by the GL.
2754 * Table 3.12 specifies the mapping of format and type to effective
2755 * internal formats. The effective internal format is used by the GL
2756 * for purposes such as texture completeness or type checks for
2757 * CopyTex* commands. In these cases, the GL is required to operate
2758 * as if the effective internal format was used as the internalformat
2759 * when specifying the texture data."
2761 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2762 GLenum effectiveInternalFormat
=
2763 _mesa_es3_effective_internal_format_for_format_and_type(format
, type
);
2765 if (effectiveInternalFormat
== GL_NONE
)
2766 return GL_INVALID_OPERATION
;
2768 GLenum baseInternalFormat
;
2769 if (internalFormat
== GL_BGRA_EXT
) {
2770 /* Unfortunately, _mesa_base_tex_format returns a base format of
2771 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2772 * asking the question, "what channels does this format have?"
2773 * However, if we're trying to determine if two internal formats
2774 * match in the ES3 sense, we actually want GL_BGRA.
2776 baseInternalFormat
= GL_BGRA_EXT
;
2778 baseInternalFormat
=
2779 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2782 if (internalFormat
!= baseInternalFormat
)
2783 return GL_INVALID_OPERATION
;
2785 internalFormat
= effectiveInternalFormat
;
2790 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2791 return GL_INVALID_OPERATION
;
2796 case GL_UNSIGNED_BYTE
:
2797 switch (internalFormat
) {
2802 case GL_SRGB8_ALPHA8_EXT
:
2805 return GL_INVALID_OPERATION
;
2810 if (internalFormat
!= GL_RGBA8_SNORM
)
2811 return GL_INVALID_OPERATION
;
2814 case GL_UNSIGNED_SHORT_4_4_4_4
:
2815 switch (internalFormat
) {
2820 return GL_INVALID_OPERATION
;
2824 case GL_UNSIGNED_SHORT_5_5_5_1
:
2825 switch (internalFormat
) {
2830 return GL_INVALID_OPERATION
;
2834 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2835 switch (internalFormat
) {
2836 case GL_RGBA
: /* GL_EXT_texture_type_2_10_10_10_REV */
2841 return GL_INVALID_OPERATION
;
2846 if (internalFormat
!= GL_RGBA16F
)
2847 return GL_INVALID_OPERATION
;
2851 switch (internalFormat
) {
2856 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2859 return GL_INVALID_OPERATION
;
2863 case GL_HALF_FLOAT_OES
:
2864 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2867 return GL_INVALID_OPERATION
;
2871 case GL_RGBA_INTEGER
:
2873 case GL_UNSIGNED_BYTE
:
2874 if (internalFormat
!= GL_RGBA8UI
)
2875 return GL_INVALID_OPERATION
;
2879 if (internalFormat
!= GL_RGBA8I
)
2880 return GL_INVALID_OPERATION
;
2883 case GL_UNSIGNED_SHORT
:
2884 if (internalFormat
!= GL_RGBA16UI
)
2885 return GL_INVALID_OPERATION
;
2889 if (internalFormat
!= GL_RGBA16I
)
2890 return GL_INVALID_OPERATION
;
2893 case GL_UNSIGNED_INT
:
2894 if (internalFormat
!= GL_RGBA32UI
)
2895 return GL_INVALID_OPERATION
;
2899 if (internalFormat
!= GL_RGBA32I
)
2900 return GL_INVALID_OPERATION
;
2903 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2904 if (internalFormat
!= GL_RGB10_A2UI
)
2905 return GL_INVALID_OPERATION
;
2909 return GL_INVALID_OPERATION
;
2915 case GL_UNSIGNED_BYTE
:
2916 switch (internalFormat
) {
2923 return GL_INVALID_OPERATION
;
2928 if (internalFormat
!= GL_RGB8_SNORM
)
2929 return GL_INVALID_OPERATION
;
2932 case GL_UNSIGNED_SHORT_5_6_5
:
2933 switch (internalFormat
) {
2938 return GL_INVALID_OPERATION
;
2942 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
2943 if (internalFormat
!= GL_R11F_G11F_B10F
)
2944 return GL_INVALID_OPERATION
;
2947 case GL_UNSIGNED_INT_5_9_9_9_REV
:
2948 if (internalFormat
!= GL_RGB9_E5
)
2949 return GL_INVALID_OPERATION
;
2953 switch (internalFormat
) {
2955 case GL_R11F_G11F_B10F
:
2959 return GL_INVALID_OPERATION
;
2964 switch (internalFormat
) {
2967 case GL_R11F_G11F_B10F
:
2971 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2974 return GL_INVALID_OPERATION
;
2978 case GL_HALF_FLOAT_OES
:
2979 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
2980 return GL_INVALID_OPERATION
;
2983 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2984 switch (internalFormat
) {
2985 case GL_RGB
: /* GL_EXT_texture_type_2_10_10_10_REV */
2988 return GL_INVALID_OPERATION
;
2993 return GL_INVALID_OPERATION
;
2997 case GL_RGB_INTEGER
:
2999 case GL_UNSIGNED_BYTE
:
3000 if (internalFormat
!= GL_RGB8UI
)
3001 return GL_INVALID_OPERATION
;
3005 if (internalFormat
!= GL_RGB8I
)
3006 return GL_INVALID_OPERATION
;
3009 case GL_UNSIGNED_SHORT
:
3010 if (internalFormat
!= GL_RGB16UI
)
3011 return GL_INVALID_OPERATION
;
3015 if (internalFormat
!= GL_RGB16I
)
3016 return GL_INVALID_OPERATION
;
3019 case GL_UNSIGNED_INT
:
3020 if (internalFormat
!= GL_RGB32UI
)
3021 return GL_INVALID_OPERATION
;
3025 if (internalFormat
!= GL_RGB32I
)
3026 return GL_INVALID_OPERATION
;
3030 return GL_INVALID_OPERATION
;
3036 case GL_UNSIGNED_BYTE
:
3037 if (internalFormat
!= GL_RG8
)
3038 return GL_INVALID_OPERATION
;
3042 if (internalFormat
!= GL_RG8_SNORM
)
3043 return GL_INVALID_OPERATION
;
3047 case GL_HALF_FLOAT_OES
:
3048 switch (internalFormat
) {
3052 if (ctx
->Extensions
.ARB_texture_rg
&&
3053 ctx
->Extensions
.OES_texture_half_float
)
3057 return GL_INVALID_OPERATION
;
3062 switch (internalFormat
) {
3067 if (ctx
->Extensions
.ARB_texture_rg
&&
3068 ctx
->Extensions
.OES_texture_float
)
3072 return GL_INVALID_OPERATION
;
3077 return GL_INVALID_OPERATION
;
3083 case GL_UNSIGNED_BYTE
:
3084 if (internalFormat
!= GL_RG8UI
)
3085 return GL_INVALID_OPERATION
;
3089 if (internalFormat
!= GL_RG8I
)
3090 return GL_INVALID_OPERATION
;
3093 case GL_UNSIGNED_SHORT
:
3094 if (internalFormat
!= GL_RG16UI
)
3095 return GL_INVALID_OPERATION
;
3099 if (internalFormat
!= GL_RG16I
)
3100 return GL_INVALID_OPERATION
;
3103 case GL_UNSIGNED_INT
:
3104 if (internalFormat
!= GL_RG32UI
)
3105 return GL_INVALID_OPERATION
;
3109 if (internalFormat
!= GL_RG32I
)
3110 return GL_INVALID_OPERATION
;
3114 return GL_INVALID_OPERATION
;
3120 case GL_UNSIGNED_BYTE
:
3121 if (internalFormat
!= GL_R8
)
3122 return GL_INVALID_OPERATION
;
3126 if (internalFormat
!= GL_R8_SNORM
)
3127 return GL_INVALID_OPERATION
;
3131 case GL_HALF_FLOAT_OES
:
3132 switch (internalFormat
) {
3137 if (ctx
->Extensions
.ARB_texture_rg
&&
3138 ctx
->Extensions
.OES_texture_half_float
)
3142 return GL_INVALID_OPERATION
;
3147 switch (internalFormat
) {
3152 if (ctx
->Extensions
.ARB_texture_rg
&&
3153 ctx
->Extensions
.OES_texture_float
)
3157 return GL_INVALID_OPERATION
;
3162 return GL_INVALID_OPERATION
;
3166 case GL_RED_INTEGER
:
3168 case GL_UNSIGNED_BYTE
:
3169 if (internalFormat
!= GL_R8UI
)
3170 return GL_INVALID_OPERATION
;
3174 if (internalFormat
!= GL_R8I
)
3175 return GL_INVALID_OPERATION
;
3178 case GL_UNSIGNED_SHORT
:
3179 if (internalFormat
!= GL_R16UI
)
3180 return GL_INVALID_OPERATION
;
3184 if (internalFormat
!= GL_R16I
)
3185 return GL_INVALID_OPERATION
;
3188 case GL_UNSIGNED_INT
:
3189 if (internalFormat
!= GL_R32UI
)
3190 return GL_INVALID_OPERATION
;
3194 if (internalFormat
!= GL_R32I
)
3195 return GL_INVALID_OPERATION
;
3199 return GL_INVALID_OPERATION
;
3203 case GL_DEPTH_COMPONENT
:
3205 case GL_UNSIGNED_SHORT
:
3206 if (internalFormat
!= GL_DEPTH_COMPONENT
3207 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3208 return GL_INVALID_OPERATION
;
3211 case GL_UNSIGNED_INT
:
3212 switch (internalFormat
) {
3213 case GL_DEPTH_COMPONENT
:
3214 case GL_DEPTH_COMPONENT16
:
3215 case GL_DEPTH_COMPONENT24
:
3218 return GL_INVALID_OPERATION
;
3223 if (internalFormat
!= GL_DEPTH_COMPONENT32F
)
3224 return GL_INVALID_OPERATION
;
3228 return GL_INVALID_OPERATION
;
3232 case GL_DEPTH_STENCIL
:
3234 case GL_UNSIGNED_INT_24_8
:
3235 if (internalFormat
!= GL_DEPTH_STENCIL
3236 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3237 return GL_INVALID_OPERATION
;
3240 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3241 if (internalFormat
!= GL_DEPTH32F_STENCIL8
)
3242 return GL_INVALID_OPERATION
;
3246 return GL_INVALID_OPERATION
;
3250 case GL_STENCIL_INDEX
:
3251 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3252 type
!= GL_UNSIGNED_BYTE
||
3253 internalFormat
!= GL_STENCIL_INDEX8
) {
3254 return GL_INVALID_OPERATION
;
3260 case GL_LUMINANCE_ALPHA
:
3263 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3265 case GL_HALF_FLOAT_OES
:
3266 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
3269 if (type
!= GL_UNSIGNED_BYTE
|| format
!= internalFormat
)
3270 return GL_INVALID_OPERATION
;
3278 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3280 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3281 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3282 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3283 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3287 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3291 case GL_RGBA_INTEGER_EXT
:
3292 set_swizzle(swizzle
, 0, 1, 2, 3);
3295 case GL_BGRA_INTEGER_EXT
:
3296 set_swizzle(swizzle
, 2, 1, 0, 3);
3299 set_swizzle(swizzle
, 3, 2, 1, 0);
3302 case GL_RGB_INTEGER_EXT
:
3303 set_swizzle(swizzle
, 0, 1, 2, 5);
3306 case GL_BGR_INTEGER_EXT
:
3307 set_swizzle(swizzle
, 2, 1, 0, 5);
3309 case GL_LUMINANCE_ALPHA
:
3310 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3311 set_swizzle(swizzle
, 0, 0, 0, 1);
3315 set_swizzle(swizzle
, 0, 1, 4, 5);
3318 case GL_RED_INTEGER_EXT
:
3319 set_swizzle(swizzle
, 0, 4, 4, 5);
3322 case GL_GREEN_INTEGER_EXT
:
3323 set_swizzle(swizzle
, 4, 0, 4, 5);
3326 case GL_BLUE_INTEGER_EXT
:
3327 set_swizzle(swizzle
, 4, 4, 0, 5);
3330 case GL_ALPHA_INTEGER_EXT
:
3331 set_swizzle(swizzle
, 4, 4, 4, 0);
3334 case GL_LUMINANCE_INTEGER_EXT
:
3335 set_swizzle(swizzle
, 0, 0, 0, 5);
3338 set_swizzle(swizzle
, 0, 0, 0, 0);
3346 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3347 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3348 * otherwise (for non-array formats).
3350 * This function will typically be used to compute a mesa format from a GL type
3351 * so we can then call _mesa_format_convert. This function does
3352 * not consider byte swapping, so it returns types assuming that no byte
3353 * swapping is involved. If byte swapping is involved then clients are supposed
3354 * to handle that on their side before calling _mesa_format_convert.
3356 * This function returns an uint32_t that can pack a mesa_format or a
3357 * mesa_array_format. Clients must check the mesa array format bit
3358 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3359 * format is a mesa_array_format or a mesa_format.
3362 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3364 bool is_array_format
= true;
3366 bool normalized
= false, is_float
= false, is_signed
= false;
3367 int num_channels
= 0, type_size
= 0;
3369 /* Extract array format type information from the OpenGL data type */
3371 case GL_UNSIGNED_BYTE
:
3378 case GL_UNSIGNED_SHORT
:
3385 case GL_UNSIGNED_INT
:
3393 case GL_HALF_FLOAT_OES
:
3404 is_array_format
= false;
3408 /* Extract array format swizzle information from the OpenGL format */
3409 if (is_array_format
)
3410 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3412 /* If this is an array format type after checking data type and format,
3413 * create the array format
3415 if (is_array_format
) {
3416 normalized
= !_mesa_is_enum_format_integer(format
);
3417 num_channels
= _mesa_components_in_format(format
);
3419 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3420 normalized
, num_channels
,
3421 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3424 /* Otherwise this is not an array format, so return the mesa_format
3425 * matching the OpenGL format and data type
3428 case GL_UNSIGNED_SHORT_5_6_5
:
3429 if (format
== GL_RGB
)
3430 return MESA_FORMAT_B5G6R5_UNORM
;
3431 else if (format
== GL_BGR
)
3432 return MESA_FORMAT_R5G6B5_UNORM
;
3433 else if (format
== GL_RGB_INTEGER
)
3434 return MESA_FORMAT_B5G6R5_UINT
;
3436 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3437 if (format
== GL_RGB
)
3438 return MESA_FORMAT_R5G6B5_UNORM
;
3439 else if (format
== GL_BGR
)
3440 return MESA_FORMAT_B5G6R5_UNORM
;
3441 else if (format
== GL_RGB_INTEGER
)
3442 return MESA_FORMAT_R5G6B5_UINT
;
3444 case GL_UNSIGNED_SHORT_4_4_4_4
:
3445 if (format
== GL_RGBA
)
3446 return MESA_FORMAT_A4B4G4R4_UNORM
;
3447 else if (format
== GL_BGRA
)
3448 return MESA_FORMAT_A4R4G4B4_UNORM
;
3449 else if (format
== GL_ABGR_EXT
)
3450 return MESA_FORMAT_R4G4B4A4_UNORM
;
3451 else if (format
== GL_RGBA_INTEGER
)
3452 return MESA_FORMAT_A4B4G4R4_UINT
;
3453 else if (format
== GL_BGRA_INTEGER
)
3454 return MESA_FORMAT_A4R4G4B4_UINT
;
3456 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3457 if (format
== GL_RGBA
)
3458 return MESA_FORMAT_R4G4B4A4_UNORM
;
3459 else if (format
== GL_BGRA
)
3460 return MESA_FORMAT_B4G4R4A4_UNORM
;
3461 else if (format
== GL_ABGR_EXT
)
3462 return MESA_FORMAT_A4B4G4R4_UNORM
;
3463 else if (format
== GL_RGBA_INTEGER
)
3464 return MESA_FORMAT_R4G4B4A4_UINT
;
3465 else if (format
== GL_BGRA_INTEGER
)
3466 return MESA_FORMAT_B4G4R4A4_UINT
;
3468 case GL_UNSIGNED_SHORT_5_5_5_1
:
3469 if (format
== GL_RGBA
)
3470 return MESA_FORMAT_A1B5G5R5_UNORM
;
3471 else if (format
== GL_BGRA
)
3472 return MESA_FORMAT_A1R5G5B5_UNORM
;
3473 else if (format
== GL_RGBA_INTEGER
)
3474 return MESA_FORMAT_A1B5G5R5_UINT
;
3475 else if (format
== GL_BGRA_INTEGER
)
3476 return MESA_FORMAT_A1R5G5B5_UINT
;
3478 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3479 if (format
== GL_RGBA
)
3480 return MESA_FORMAT_R5G5B5A1_UNORM
;
3481 else if (format
== GL_BGRA
)
3482 return MESA_FORMAT_B5G5R5A1_UNORM
;
3483 else if (format
== GL_RGBA_INTEGER
)
3484 return MESA_FORMAT_R5G5B5A1_UINT
;
3485 else if (format
== GL_BGRA_INTEGER
)
3486 return MESA_FORMAT_B5G5R5A1_UINT
;
3488 case GL_UNSIGNED_BYTE_3_3_2
:
3489 if (format
== GL_RGB
)
3490 return MESA_FORMAT_B2G3R3_UNORM
;
3491 else if (format
== GL_RGB_INTEGER
)
3492 return MESA_FORMAT_B2G3R3_UINT
;
3494 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3495 if (format
== GL_RGB
)
3496 return MESA_FORMAT_R3G3B2_UNORM
;
3497 else if (format
== GL_RGB_INTEGER
)
3498 return MESA_FORMAT_R3G3B2_UINT
;
3500 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3501 if (format
== GL_RGB
)
3502 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3504 case GL_UNSIGNED_INT_10_10_10_2
:
3505 if (format
== GL_RGBA
)
3506 return MESA_FORMAT_A2B10G10R10_UNORM
;
3507 else if (format
== GL_RGBA_INTEGER
)
3508 return MESA_FORMAT_A2B10G10R10_UINT
;
3509 else if (format
== GL_BGRA
)
3510 return MESA_FORMAT_A2R10G10B10_UNORM
;
3511 else if (format
== GL_BGRA_INTEGER
)
3512 return MESA_FORMAT_A2R10G10B10_UINT
;
3514 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3515 if (format
== GL_RGB
)
3516 return MESA_FORMAT_R10G10B10X2_UNORM
;
3517 if (format
== GL_RGBA
)
3518 return MESA_FORMAT_R10G10B10A2_UNORM
;
3519 else if (format
== GL_RGBA_INTEGER
)
3520 return MESA_FORMAT_R10G10B10A2_UINT
;
3521 else if (format
== GL_BGRA
)
3522 return MESA_FORMAT_B10G10R10A2_UNORM
;
3523 else if (format
== GL_BGRA_INTEGER
)
3524 return MESA_FORMAT_B10G10R10A2_UINT
;
3526 case GL_UNSIGNED_INT_8_8_8_8
:
3527 if (format
== GL_RGBA
)
3528 return MESA_FORMAT_A8B8G8R8_UNORM
;
3529 else if (format
== GL_BGRA
)
3530 return MESA_FORMAT_A8R8G8B8_UNORM
;
3531 else if (format
== GL_ABGR_EXT
)
3532 return MESA_FORMAT_R8G8B8A8_UNORM
;
3533 else if (format
== GL_RGBA_INTEGER
)
3534 return MESA_FORMAT_A8B8G8R8_UINT
;
3535 else if (format
== GL_BGRA_INTEGER
)
3536 return MESA_FORMAT_A8R8G8B8_UINT
;
3538 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3539 if (format
== GL_RGBA
)
3540 return MESA_FORMAT_R8G8B8A8_UNORM
;
3541 else if (format
== GL_BGRA
)
3542 return MESA_FORMAT_B8G8R8A8_UNORM
;
3543 else if (format
== GL_ABGR_EXT
)
3544 return MESA_FORMAT_A8B8G8R8_UNORM
;
3545 else if (format
== GL_RGBA_INTEGER
)
3546 return MESA_FORMAT_R8G8B8A8_UINT
;
3547 else if (format
== GL_BGRA_INTEGER
)
3548 return MESA_FORMAT_B8G8R8A8_UINT
;
3550 case GL_UNSIGNED_SHORT_8_8_MESA
:
3551 if (format
== GL_YCBCR_MESA
)
3552 return MESA_FORMAT_YCBCR
;
3554 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3555 if (format
== GL_YCBCR_MESA
)
3556 return MESA_FORMAT_YCBCR_REV
;
3558 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3559 if (format
== GL_RGB
)
3560 return MESA_FORMAT_R11G11B10_FLOAT
;
3563 if (format
== GL_DEPTH_COMPONENT
)
3564 return MESA_FORMAT_Z_FLOAT32
;
3566 case GL_UNSIGNED_INT
:
3567 if (format
== GL_DEPTH_COMPONENT
)
3568 return MESA_FORMAT_Z_UNORM32
;
3570 case GL_UNSIGNED_SHORT
:
3571 if (format
== GL_DEPTH_COMPONENT
)
3572 return MESA_FORMAT_Z_UNORM16
;
3574 case GL_UNSIGNED_INT_24_8
:
3575 if (format
== GL_DEPTH_STENCIL
)
3576 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3578 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3579 if (format
== GL_DEPTH_STENCIL
)
3580 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3586 /* If we got here it means that we could not find a Mesa format that
3587 * matches the GL format/type provided. We may need to add a new Mesa
3588 * format in that case.
3590 unreachable("Unsupported format");
3594 * Returns true if \p internal_format is a sized internal format that
3595 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3598 _mesa_is_es3_color_renderable(GLenum internal_format
)
3600 switch (internal_format
) {
3610 case GL_SRGB8_ALPHA8
:
3617 case GL_R11F_G11F_B10F
:
3643 * Returns true if \p internal_format is a sized internal format that
3644 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3647 _mesa_is_es3_texture_filterable(GLenum internal_format
)
3649 switch (internal_format
) {
3660 case GL_RGBA8_SNORM
:
3663 case GL_SRGB8_ALPHA8
:
3668 case GL_R11F_G11F_B10F
: