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 case GL_HALF_FLOAT_OES
:
550 return comps
* sizeof(GLhalfARB
);
552 return comps
* sizeof(GLdouble
);
554 return comps
* sizeof(GLfixed
);
555 case GL_INT_2_10_10_10_REV
:
556 case GL_UNSIGNED_INT_2_10_10_10_REV
:
558 return sizeof(GLuint
);
561 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
563 return sizeof(GLuint
);
566 case GL_UNSIGNED_INT64_ARB
:
574 * Test if the given format is unsized.
577 _mesa_is_enum_format_unsized(GLenum format
)
592 case GL_LUMINANCE_ALPHA
:
597 case GL_SLUMINANCE_ALPHA
:
604 case GL_INTENSITY_SNORM
:
605 case GL_LUMINANCE_SNORM
:
606 case GL_LUMINANCE_ALPHA_SNORM
:
609 case GL_GREEN_INTEGER
:
610 case GL_BLUE_INTEGER
:
611 case GL_ALPHA_INTEGER
:
613 case GL_RGBA_INTEGER
:
615 case GL_BGRA_INTEGER
:
617 case GL_LUMINANCE_INTEGER_EXT
:
618 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
620 case GL_DEPTH_COMPONENT
:
621 case GL_DEPTH_STENCIL
:
622 case GL_STENCIL_INDEX
:
630 * Test if the given format is a UNORM (unsigned-normalized) format.
633 _mesa_is_enum_format_unorm(GLenum format
)
652 case GL_LUMINANCE_ALPHA
:
653 case GL_SLUMINANCE_ALPHA
:
654 case GL_LUMINANCE4_ALPHA4
:
655 case GL_LUMINANCE6_ALPHA2
:
656 case GL_LUMINANCE8_ALPHA8
:
657 case GL_LUMINANCE12_ALPHA4
:
658 case GL_LUMINANCE12_ALPHA12
:
659 case GL_LUMINANCE16_ALPHA16
:
701 * Test if the given format is a SNORM (signed-normalized) format.
704 _mesa_is_enum_format_snorm(GLenum format
)
707 /* signed, normalized texture formats */
719 case GL_RGBA16_SNORM
:
721 case GL_ALPHA8_SNORM
:
722 case GL_ALPHA16_SNORM
:
723 case GL_LUMINANCE_SNORM
:
724 case GL_LUMINANCE8_SNORM
:
725 case GL_LUMINANCE16_SNORM
:
726 case GL_LUMINANCE_ALPHA_SNORM
:
727 case GL_LUMINANCE8_ALPHA8_SNORM
:
728 case GL_LUMINANCE16_ALPHA16_SNORM
:
729 case GL_INTENSITY_SNORM
:
730 case GL_INTENSITY8_SNORM
:
731 case GL_INTENSITY16_SNORM
:
739 * Test if the given format is an integer (non-normalized) format.
742 _mesa_is_enum_format_unsigned_int(GLenum format
)
745 /* specific integer formats */
746 case GL_RGBA32UI_EXT
:
750 case GL_ALPHA32UI_EXT
:
751 case GL_INTENSITY32UI_EXT
:
752 case GL_LUMINANCE32UI_EXT
:
753 case GL_LUMINANCE_ALPHA32UI_EXT
:
754 case GL_RGBA16UI_EXT
:
758 case GL_ALPHA16UI_EXT
:
759 case GL_INTENSITY16UI_EXT
:
760 case GL_LUMINANCE16UI_EXT
:
761 case GL_LUMINANCE_ALPHA16UI_EXT
:
766 case GL_ALPHA8UI_EXT
:
767 case GL_INTENSITY8UI_EXT
:
768 case GL_LUMINANCE8UI_EXT
:
769 case GL_LUMINANCE_ALPHA8UI_EXT
:
779 * Test if the given format is an integer (non-normalized) format.
782 _mesa_is_enum_format_signed_int(GLenum format
)
785 /* generic integer formats */
786 case GL_RED_INTEGER_EXT
:
787 case GL_GREEN_INTEGER_EXT
:
788 case GL_BLUE_INTEGER_EXT
:
789 case GL_ALPHA_INTEGER_EXT
:
790 case GL_RGB_INTEGER_EXT
:
791 case GL_RGBA_INTEGER_EXT
:
792 case GL_BGR_INTEGER_EXT
:
793 case GL_BGRA_INTEGER_EXT
:
794 case GL_LUMINANCE_INTEGER_EXT
:
795 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
797 /* specific integer formats */
802 case GL_ALPHA32I_EXT
:
803 case GL_INTENSITY32I_EXT
:
804 case GL_LUMINANCE32I_EXT
:
805 case GL_LUMINANCE_ALPHA32I_EXT
:
810 case GL_ALPHA16I_EXT
:
811 case GL_INTENSITY16I_EXT
:
812 case GL_LUMINANCE16I_EXT
:
813 case GL_LUMINANCE_ALPHA16I_EXT
:
819 case GL_INTENSITY8I_EXT
:
820 case GL_LUMINANCE8I_EXT
:
821 case GL_LUMINANCE_ALPHA8I_EXT
:
829 * Test if the given format is an ASTC 2D format.
832 is_astc_2d_format(GLenum internalFormat
)
834 switch (internalFormat
) {
835 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
836 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
837 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
838 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
839 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
840 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
841 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
842 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
843 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
844 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
845 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
846 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
847 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
848 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
849 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
850 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
851 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
852 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
853 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
854 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
855 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
856 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
857 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
858 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
859 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
860 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
861 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
862 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
870 * Test if the given format is an ASTC 3D format.
873 is_astc_3d_format(GLenum internalFormat
)
875 switch (internalFormat
) {
876 case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES
:
877 case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES
:
878 case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES
:
879 case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES
:
880 case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES
:
881 case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES
:
882 case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES
:
883 case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES
:
884 case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES
:
885 case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES
:
886 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES
:
887 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES
:
888 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES
:
889 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES
:
890 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES
:
891 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES
:
892 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES
:
893 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES
:
894 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES
:
895 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES
:
903 * Test if the given format is an ASTC format.
906 _mesa_is_astc_format(GLenum internalFormat
)
908 return is_astc_2d_format(internalFormat
) ||
909 is_astc_3d_format(internalFormat
);
913 * Test if the given format is an ETC2 format.
916 _mesa_is_etc2_format(GLenum internalFormat
)
918 switch (internalFormat
) {
919 case GL_COMPRESSED_RGB8_ETC2
:
920 case GL_COMPRESSED_SRGB8_ETC2
:
921 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
922 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
923 case GL_COMPRESSED_R11_EAC
:
924 case GL_COMPRESSED_RG11_EAC
:
925 case GL_COMPRESSED_SIGNED_R11_EAC
:
926 case GL_COMPRESSED_SIGNED_RG11_EAC
:
927 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
928 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
936 * Test if the given format is an integer (non-normalized) format.
939 _mesa_is_enum_format_integer(GLenum format
)
941 return _mesa_is_enum_format_unsigned_int(format
) ||
942 _mesa_is_enum_format_signed_int(format
);
947 _mesa_is_type_unsigned(GLenum type
)
950 case GL_UNSIGNED_INT
:
951 case GL_UNSIGNED_INT_8_8_8_8
:
952 case GL_UNSIGNED_INT_8_8_8_8_REV
:
953 case GL_UNSIGNED_INT_10_10_10_2
:
954 case GL_UNSIGNED_INT_2_10_10_10_REV
:
956 case GL_UNSIGNED_SHORT
:
957 case GL_UNSIGNED_SHORT_4_4_4_4
:
958 case GL_UNSIGNED_SHORT_5_5_5_1
:
959 case GL_UNSIGNED_SHORT_5_6_5
:
960 case GL_UNSIGNED_SHORT_5_6_5_REV
:
961 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
962 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
963 case GL_UNSIGNED_SHORT_8_8_MESA
:
964 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
966 case GL_UNSIGNED_BYTE
:
967 case GL_UNSIGNED_BYTE_3_3_2
:
968 case GL_UNSIGNED_BYTE_2_3_3_REV
:
978 * Test if the given image format is a color/RGBA format (i.e., not color
979 * index, depth, stencil, etc).
980 * \param format the image format value (may by an internal texture format)
981 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
984 _mesa_is_color_format(GLenum format
)
1000 case GL_LUMINANCE16
:
1002 case GL_LUMINANCE_ALPHA
:
1003 case GL_LUMINANCE4_ALPHA4
:
1004 case GL_LUMINANCE6_ALPHA2
:
1005 case GL_LUMINANCE8_ALPHA8
:
1006 case GL_LUMINANCE12_ALPHA4
:
1007 case GL_LUMINANCE12_ALPHA12
:
1008 case GL_LUMINANCE16_ALPHA16
:
1012 case GL_INTENSITY12
:
1013 case GL_INTENSITY16
:
1041 /* float texture formats */
1042 case GL_ALPHA16F_ARB
:
1043 case GL_ALPHA32F_ARB
:
1044 case GL_LUMINANCE16F_ARB
:
1045 case GL_LUMINANCE32F_ARB
:
1046 case GL_LUMINANCE_ALPHA16F_ARB
:
1047 case GL_LUMINANCE_ALPHA32F_ARB
:
1048 case GL_INTENSITY16F_ARB
:
1049 case GL_INTENSITY32F_ARB
:
1056 case GL_RGBA16F_ARB
:
1057 case GL_RGBA32F_ARB
:
1058 /* compressed formats */
1059 case GL_COMPRESSED_ALPHA
:
1060 case GL_COMPRESSED_LUMINANCE
:
1061 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1062 case GL_COMPRESSED_INTENSITY
:
1063 case GL_COMPRESSED_RED
:
1064 case GL_COMPRESSED_RG
:
1065 case GL_COMPRESSED_RGB
:
1066 case GL_COMPRESSED_RGBA
:
1071 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1072 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1073 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1074 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1075 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1076 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1079 case GL_SRGB_ALPHA_EXT
:
1080 case GL_SRGB8_ALPHA8_EXT
:
1081 case GL_SLUMINANCE_ALPHA_EXT
:
1082 case GL_SLUMINANCE8_ALPHA8_EXT
:
1083 case GL_SLUMINANCE_EXT
:
1084 case GL_SLUMINANCE8_EXT
:
1085 case GL_COMPRESSED_SRGB_EXT
:
1086 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1087 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
1088 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1089 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1090 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1091 case GL_COMPRESSED_SLUMINANCE_EXT
:
1092 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
1093 case GL_COMPRESSED_RED_RGTC1
:
1094 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1095 case GL_COMPRESSED_RG_RGTC2
:
1096 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1097 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1098 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1099 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1100 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1101 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1102 case GL_ETC1_RGB8_OES
:
1103 case GL_COMPRESSED_RGB8_ETC2
:
1104 case GL_COMPRESSED_SRGB8_ETC2
:
1105 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
1106 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1107 case GL_COMPRESSED_R11_EAC
:
1108 case GL_COMPRESSED_RG11_EAC
:
1109 case GL_COMPRESSED_SIGNED_R11_EAC
:
1110 case GL_COMPRESSED_SIGNED_RG11_EAC
:
1111 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1112 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1113 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
1114 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1115 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
1116 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
1117 case GL_COMPRESSED_RGBA_ASTC_4x4_KHR
:
1118 case GL_COMPRESSED_RGBA_ASTC_5x4_KHR
:
1119 case GL_COMPRESSED_RGBA_ASTC_5x5_KHR
:
1120 case GL_COMPRESSED_RGBA_ASTC_6x5_KHR
:
1121 case GL_COMPRESSED_RGBA_ASTC_6x6_KHR
:
1122 case GL_COMPRESSED_RGBA_ASTC_8x5_KHR
:
1123 case GL_COMPRESSED_RGBA_ASTC_8x6_KHR
:
1124 case GL_COMPRESSED_RGBA_ASTC_8x8_KHR
:
1125 case GL_COMPRESSED_RGBA_ASTC_10x5_KHR
:
1126 case GL_COMPRESSED_RGBA_ASTC_10x6_KHR
:
1127 case GL_COMPRESSED_RGBA_ASTC_10x8_KHR
:
1128 case GL_COMPRESSED_RGBA_ASTC_10x10_KHR
:
1129 case GL_COMPRESSED_RGBA_ASTC_12x10_KHR
:
1130 case GL_COMPRESSED_RGBA_ASTC_12x12_KHR
:
1131 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1132 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1133 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1134 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1135 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1136 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1137 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1138 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1139 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1140 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1141 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1142 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1143 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1144 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1145 /* generic integer formats */
1146 case GL_RED_INTEGER_EXT
:
1147 case GL_GREEN_INTEGER_EXT
:
1148 case GL_BLUE_INTEGER_EXT
:
1149 case GL_ALPHA_INTEGER_EXT
:
1150 case GL_RGB_INTEGER_EXT
:
1151 case GL_RGBA_INTEGER_EXT
:
1152 case GL_BGR_INTEGER_EXT
:
1153 case GL_BGRA_INTEGER_EXT
:
1155 case GL_LUMINANCE_INTEGER_EXT
:
1156 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1157 /* sized integer formats */
1158 case GL_RGBA32UI_EXT
:
1159 case GL_RGB32UI_EXT
:
1162 case GL_ALPHA32UI_EXT
:
1163 case GL_INTENSITY32UI_EXT
:
1164 case GL_LUMINANCE32UI_EXT
:
1165 case GL_LUMINANCE_ALPHA32UI_EXT
:
1166 case GL_RGBA16UI_EXT
:
1167 case GL_RGB16UI_EXT
:
1170 case GL_ALPHA16UI_EXT
:
1171 case GL_INTENSITY16UI_EXT
:
1172 case GL_LUMINANCE16UI_EXT
:
1173 case GL_LUMINANCE_ALPHA16UI_EXT
:
1174 case GL_RGBA8UI_EXT
:
1178 case GL_ALPHA8UI_EXT
:
1179 case GL_INTENSITY8UI_EXT
:
1180 case GL_LUMINANCE8UI_EXT
:
1181 case GL_LUMINANCE_ALPHA8UI_EXT
:
1182 case GL_RGBA32I_EXT
:
1186 case GL_ALPHA32I_EXT
:
1187 case GL_INTENSITY32I_EXT
:
1188 case GL_LUMINANCE32I_EXT
:
1189 case GL_LUMINANCE_ALPHA32I_EXT
:
1190 case GL_RGBA16I_EXT
:
1194 case GL_ALPHA16I_EXT
:
1195 case GL_INTENSITY16I_EXT
:
1196 case GL_LUMINANCE16I_EXT
:
1197 case GL_LUMINANCE_ALPHA16I_EXT
:
1202 case GL_ALPHA8I_EXT
:
1203 case GL_INTENSITY8I_EXT
:
1204 case GL_LUMINANCE8I_EXT
:
1205 case GL_LUMINANCE_ALPHA8I_EXT
:
1206 /* signed, normalized texture formats */
1215 case GL_RGB16_SNORM
:
1217 case GL_RGBA8_SNORM
:
1218 case GL_RGBA16_SNORM
:
1219 case GL_ALPHA_SNORM
:
1220 case GL_ALPHA8_SNORM
:
1221 case GL_ALPHA16_SNORM
:
1222 case GL_LUMINANCE_SNORM
:
1223 case GL_LUMINANCE8_SNORM
:
1224 case GL_LUMINANCE16_SNORM
:
1225 case GL_LUMINANCE_ALPHA_SNORM
:
1226 case GL_LUMINANCE8_ALPHA8_SNORM
:
1227 case GL_LUMINANCE16_ALPHA16_SNORM
:
1228 case GL_INTENSITY_SNORM
:
1229 case GL_INTENSITY8_SNORM
:
1230 case GL_INTENSITY16_SNORM
:
1232 case GL_R11F_G11F_B10F
:
1235 case GL_YCBCR_MESA
: /* not considered to be RGB */
1244 * Test if the given image format is a depth component format.
1247 _mesa_is_depth_format(GLenum format
)
1250 case GL_DEPTH_COMPONENT
:
1251 case GL_DEPTH_COMPONENT16
:
1252 case GL_DEPTH_COMPONENT24
:
1253 case GL_DEPTH_COMPONENT32
:
1254 case GL_DEPTH_COMPONENT32F
:
1263 * Test if the given image format is a stencil format.
1266 _mesa_is_stencil_format(GLenum format
)
1269 case GL_STENCIL_INDEX
:
1278 * Test if the given image format is a YCbCr format.
1281 _mesa_is_ycbcr_format(GLenum format
)
1293 * Test if the given image format is a depth+stencil format.
1296 _mesa_is_depthstencil_format(GLenum format
)
1299 case GL_DEPTH24_STENCIL8_EXT
:
1300 case GL_DEPTH_STENCIL_EXT
:
1301 case GL_DEPTH32F_STENCIL8
:
1310 * Test if the given image format is a depth or stencil format.
1313 _mesa_is_depth_or_stencil_format(GLenum format
)
1316 case GL_DEPTH_COMPONENT
:
1317 case GL_DEPTH_COMPONENT16
:
1318 case GL_DEPTH_COMPONENT24
:
1319 case GL_DEPTH_COMPONENT32
:
1320 case GL_STENCIL_INDEX
:
1321 case GL_STENCIL_INDEX1_EXT
:
1322 case GL_STENCIL_INDEX4_EXT
:
1323 case GL_STENCIL_INDEX8_EXT
:
1324 case GL_STENCIL_INDEX16_EXT
:
1325 case GL_DEPTH_STENCIL_EXT
:
1326 case GL_DEPTH24_STENCIL8_EXT
:
1327 case GL_DEPTH_COMPONENT32F
:
1328 case GL_DEPTH32F_STENCIL8
:
1337 * Test if an image format is a supported compressed format.
1338 * \param format the internal format token provided by the user.
1339 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1342 _mesa_is_compressed_format(const struct gl_context
*ctx
, GLenum format
)
1344 mesa_format m_format
= _mesa_glenum_to_compressed_format(format
);
1346 /* Some formats in this switch have an equivalent mesa_format_layout
1347 * to the compressed formats in the layout switch below and thus
1348 * must be handled first.
1355 return _mesa_has_S3_s3tc(ctx
);
1356 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1357 return _mesa_has_ATI_texture_compression_3dc(ctx
);
1358 case GL_PALETTE4_RGB8_OES
:
1359 case GL_PALETTE4_RGBA8_OES
:
1360 case GL_PALETTE4_R5_G6_B5_OES
:
1361 case GL_PALETTE4_RGBA4_OES
:
1362 case GL_PALETTE4_RGB5_A1_OES
:
1363 case GL_PALETTE8_RGB8_OES
:
1364 case GL_PALETTE8_RGBA8_OES
:
1365 case GL_PALETTE8_R5_G6_B5_OES
:
1366 case GL_PALETTE8_RGBA4_OES
:
1367 case GL_PALETTE8_RGB5_A1_OES
:
1368 return ctx
->API
== API_OPENGLES
;
1371 switch (_mesa_get_format_layout(m_format
)) {
1372 case MESA_FORMAT_LAYOUT_S3TC
:
1373 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1374 return _mesa_has_EXT_texture_compression_s3tc(ctx
);
1376 return (_mesa_has_EXT_texture_sRGB(ctx
) ||
1377 _mesa_has_EXT_texture_compression_s3tc_srgb(ctx
)) &&
1378 _mesa_has_EXT_texture_compression_s3tc(ctx
);
1380 case MESA_FORMAT_LAYOUT_FXT1
:
1381 return _mesa_has_3DFX_texture_compression_FXT1(ctx
);
1382 case MESA_FORMAT_LAYOUT_RGTC
:
1383 return _mesa_has_ARB_texture_compression_rgtc(ctx
) ||
1384 _mesa_has_EXT_texture_compression_rgtc(ctx
);
1385 case MESA_FORMAT_LAYOUT_LATC
:
1386 return _mesa_has_EXT_texture_compression_latc(ctx
);
1387 case MESA_FORMAT_LAYOUT_ETC1
:
1388 return _mesa_has_OES_compressed_ETC1_RGB8_texture(ctx
);
1389 case MESA_FORMAT_LAYOUT_ETC2
:
1390 return _mesa_is_gles3(ctx
) || _mesa_has_ARB_ES3_compatibility(ctx
);
1391 case MESA_FORMAT_LAYOUT_BPTC
:
1392 return _mesa_has_ARB_texture_compression_bptc(ctx
) ||
1393 _mesa_has_EXT_texture_compression_bptc(ctx
);
1394 case MESA_FORMAT_LAYOUT_ASTC
:
1395 return _mesa_has_KHR_texture_compression_astc_ldr(ctx
);
1402 * Test if the given format represents an sRGB format.
1403 * \param format the GL format (can be an internal format)
1404 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1407 _mesa_is_srgb_format(GLenum format
)
1413 case GL_SRGB8_ALPHA8
:
1414 case GL_COMPRESSED_SRGB
:
1415 case GL_COMPRESSED_SRGB_ALPHA
:
1416 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1417 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1418 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1419 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1420 case GL_COMPRESSED_SRGB8_ETC2
:
1421 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1422 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1423 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1424 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1425 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1426 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1427 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1428 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1429 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1430 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1431 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1432 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1435 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1436 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1437 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1447 * Convert various unpack formats to the corresponding base format.
1450 _mesa_unpack_format_to_base_format(GLenum format
)
1453 case GL_RED_INTEGER
:
1455 case GL_GREEN_INTEGER
:
1457 case GL_BLUE_INTEGER
:
1459 case GL_ALPHA_INTEGER
:
1463 case GL_RGB_INTEGER
:
1465 case GL_RGBA_INTEGER
:
1467 case GL_BGR_INTEGER
:
1469 case GL_BGRA_INTEGER
:
1471 case GL_LUMINANCE_INTEGER_EXT
:
1472 return GL_LUMINANCE
;
1473 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1474 return GL_LUMINANCE_ALPHA
;
1485 case GL_LUMINANCE_ALPHA
:
1492 * Convert various base formats to the corresponding integer format.
1495 _mesa_base_format_to_integer_format(GLenum format
)
1499 return GL_RED_INTEGER
;
1501 return GL_GREEN_INTEGER
;
1503 return GL_BLUE_INTEGER
;
1505 return GL_RG_INTEGER
;
1507 return GL_RGB_INTEGER
;
1509 return GL_RGBA_INTEGER
;
1511 return GL_BGR_INTEGER
;
1513 return GL_BGRA_INTEGER
;
1515 return GL_ALPHA_INTEGER
;
1517 return GL_LUMINANCE_INTEGER_EXT
;
1518 case GL_LUMINANCE_ALPHA
:
1519 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1527 * Does the given base texture/renderbuffer format have the channel
1531 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1534 case GL_TEXTURE_RED_SIZE
:
1535 case GL_TEXTURE_RED_TYPE
:
1536 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1537 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1538 case GL_INTERNALFORMAT_RED_SIZE
:
1539 case GL_INTERNALFORMAT_RED_TYPE
:
1540 if (base_format
== GL_RED
||
1541 base_format
== GL_RG
||
1542 base_format
== GL_RGB
||
1543 base_format
== GL_RGBA
) {
1547 case GL_TEXTURE_GREEN_SIZE
:
1548 case GL_TEXTURE_GREEN_TYPE
:
1549 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1550 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1551 case GL_INTERNALFORMAT_GREEN_SIZE
:
1552 case GL_INTERNALFORMAT_GREEN_TYPE
:
1553 if (base_format
== GL_RG
||
1554 base_format
== GL_RGB
||
1555 base_format
== GL_RGBA
) {
1559 case GL_TEXTURE_BLUE_SIZE
:
1560 case GL_TEXTURE_BLUE_TYPE
:
1561 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1562 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1563 case GL_INTERNALFORMAT_BLUE_SIZE
:
1564 case GL_INTERNALFORMAT_BLUE_TYPE
:
1565 if (base_format
== GL_RGB
||
1566 base_format
== GL_RGBA
) {
1570 case GL_TEXTURE_ALPHA_SIZE
:
1571 case GL_TEXTURE_ALPHA_TYPE
:
1572 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1573 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1574 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1575 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1576 if (base_format
== GL_RGBA
||
1577 base_format
== GL_ALPHA
||
1578 base_format
== GL_LUMINANCE_ALPHA
) {
1582 case GL_TEXTURE_LUMINANCE_SIZE
:
1583 case GL_TEXTURE_LUMINANCE_TYPE
:
1584 if (base_format
== GL_LUMINANCE
||
1585 base_format
== GL_LUMINANCE_ALPHA
) {
1589 case GL_TEXTURE_INTENSITY_SIZE
:
1590 case GL_TEXTURE_INTENSITY_TYPE
:
1591 if (base_format
== GL_INTENSITY
) {
1595 case GL_TEXTURE_DEPTH_SIZE
:
1596 case GL_TEXTURE_DEPTH_TYPE
:
1597 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1598 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1599 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1600 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1601 if (base_format
== GL_DEPTH_STENCIL
||
1602 base_format
== GL_DEPTH_COMPONENT
) {
1606 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1607 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1608 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1609 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1610 if (base_format
== GL_DEPTH_STENCIL
||
1611 base_format
== GL_STENCIL_INDEX
) {
1616 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1626 * If format is a generic compressed format, return the corresponding
1627 * non-compressed format. For other formats, return the format as-is.
1630 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1633 case GL_COMPRESSED_RED
:
1635 case GL_COMPRESSED_RG
:
1637 case GL_COMPRESSED_RGB
:
1639 case GL_COMPRESSED_RGBA
:
1641 case GL_COMPRESSED_ALPHA
:
1643 case GL_COMPRESSED_LUMINANCE
:
1644 return GL_LUMINANCE
;
1645 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1646 return GL_LUMINANCE_ALPHA
;
1647 case GL_COMPRESSED_INTENSITY
:
1648 return GL_INTENSITY
;
1650 case GL_COMPRESSED_SRGB
:
1652 case GL_COMPRESSED_SRGB_ALPHA
:
1653 return GL_SRGB_ALPHA
;
1654 case GL_COMPRESSED_SLUMINANCE
:
1655 return GL_SLUMINANCE
;
1656 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1657 return GL_SLUMINANCE_ALPHA
;
1665 * Return the equivalent non-generic internal format.
1666 * This is useful for comparing whether two internal formats are equivalent.
1669 _mesa_get_nongeneric_internalformat(GLenum format
)
1672 /* GL 1.1 formats. */
1680 case GL_LUMINANCE_ALPHA
:
1681 return GL_LUMINANCE8_ALPHA8
;
1684 return GL_LUMINANCE8
;
1688 return GL_INTENSITY8
;
1690 /* GL_ARB_texture_rg */
1696 /* GL_EXT_texture_sRGB */
1700 return GL_SRGB8_ALPHA8
;
1702 return GL_SLUMINANCE8
;
1703 case GL_SLUMINANCE_ALPHA
:
1704 return GL_SLUMINANCE8_ALPHA8
;
1706 /* GL_EXT_texture_snorm */
1708 return GL_RGBA8_SNORM
;
1710 return GL_RGB8_SNORM
;
1712 return GL_RG8_SNORM
;
1715 case GL_LUMINANCE_ALPHA_SNORM
:
1716 return GL_LUMINANCE8_ALPHA8_SNORM
;
1717 case GL_LUMINANCE_SNORM
:
1718 return GL_LUMINANCE8_SNORM
;
1719 case GL_ALPHA_SNORM
:
1720 return GL_ALPHA8_SNORM
;
1721 case GL_INTENSITY_SNORM
:
1722 return GL_INTENSITY8_SNORM
;
1731 * Convert an sRGB internal format to linear.
1734 _mesa_get_linear_internalformat(GLenum format
)
1743 case GL_SRGB8_ALPHA8
:
1745 case GL_SLUMINANCE8
:
1746 return GL_LUMINANCE8
;
1748 return GL_LUMINANCE
;
1749 case GL_SLUMINANCE_ALPHA
:
1750 return GL_LUMINANCE_ALPHA
;
1751 case GL_SLUMINANCE8_ALPHA8
:
1752 return GL_LUMINANCE8_ALPHA8
;
1760 * Do error checking of format/type combinations for glReadPixels,
1761 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1762 * and type values, we may either generate GL_INVALID_OPERATION or
1765 * \param format pixel format.
1766 * \param type pixel type.
1768 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1771 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1772 GLenum format
, GLenum type
)
1774 /* From OpenGL 3.3 spec, page 220:
1775 * "If the format is DEPTH_STENCIL, then values are taken from
1776 * both the depth buffer and the stencil buffer. If there is no
1777 * depth buffer or if there is no stencil buffer, then the error
1778 * INVALID_OPERATION occurs. If the type parameter is not
1779 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1780 * error INVALID_ENUM occurs."
1782 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1783 * cannot be used to read depth or stencil in that API.
1785 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1786 && type
!= GL_UNSIGNED_INT_24_8
1787 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1788 return GL_INVALID_ENUM
;
1790 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1793 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1794 return GL_INVALID_ENUM
;
1798 case GL_UNSIGNED_BYTE_3_3_2
:
1799 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1800 case GL_UNSIGNED_SHORT_5_6_5
:
1801 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1802 if (format
== GL_RGB
) {
1805 if (format
== GL_RGB_INTEGER_EXT
&&
1806 _mesa_has_texture_rgb10_a2ui(ctx
)) {
1809 return GL_INVALID_OPERATION
;
1811 case GL_UNSIGNED_SHORT_4_4_4_4
:
1812 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1813 case GL_UNSIGNED_INT_8_8_8_8
:
1814 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1815 if (format
== GL_RGBA
||
1816 format
== GL_BGRA
||
1817 format
== GL_ABGR_EXT
) {
1820 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1821 _mesa_has_texture_rgb10_a2ui(ctx
)) {
1824 return GL_INVALID_OPERATION
;
1826 case GL_UNSIGNED_SHORT_5_5_5_1
:
1827 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1828 case GL_UNSIGNED_INT_10_10_10_2
:
1829 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1830 if (format
== GL_RGBA
||
1831 format
== GL_BGRA
) {
1834 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1835 _mesa_has_texture_rgb10_a2ui(ctx
)) {
1838 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1839 ctx
->API
== API_OPENGLES2
) {
1840 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1842 return GL_INVALID_OPERATION
;
1844 case GL_UNSIGNED_INT_24_8
:
1845 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1846 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1849 if (format
!= GL_DEPTH_STENCIL
) {
1850 return GL_INVALID_OPERATION
;
1854 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1855 if (!_mesa_has_float_depth_buffer(ctx
)) {
1856 return GL_INVALID_ENUM
;
1858 if (format
!= GL_DEPTH_STENCIL
) {
1859 return GL_INVALID_OPERATION
;
1863 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1864 if (!_mesa_has_packed_float(ctx
)) {
1865 return GL_INVALID_ENUM
;
1867 if (format
!= GL_RGB
) {
1868 return GL_INVALID_OPERATION
;
1872 case GL_HALF_FLOAT_OES
:
1876 case GL_LUMINANCE_ALPHA
:
1882 if (_mesa_has_rg_textures(ctx
))
1885 return GL_INVALID_OPERATION
;
1889 ; /* fall-through */
1892 /* now, for each format, check the type for compatibility */
1894 case GL_COLOR_INDEX
:
1895 case GL_STENCIL_INDEX
:
1899 case GL_UNSIGNED_BYTE
:
1901 case GL_UNSIGNED_SHORT
:
1903 case GL_UNSIGNED_INT
:
1908 return GL_INVALID_ENUM
;
1915 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1919 case GL_LUMINANCE_ALPHA
:
1920 case GL_DEPTH_COMPONENT
:
1923 case GL_UNSIGNED_BYTE
:
1925 case GL_UNSIGNED_SHORT
:
1927 case GL_UNSIGNED_INT
:
1932 return GL_INVALID_ENUM
;
1936 if (!_mesa_has_rg_textures(ctx
))
1937 return GL_INVALID_ENUM
;
1940 case GL_UNSIGNED_BYTE
:
1942 case GL_UNSIGNED_SHORT
:
1944 case GL_UNSIGNED_INT
:
1949 return GL_INVALID_ENUM
;
1955 case GL_UNSIGNED_BYTE
:
1957 case GL_UNSIGNED_SHORT
:
1959 case GL_UNSIGNED_INT
:
1961 case GL_UNSIGNED_BYTE_3_3_2
:
1962 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1963 case GL_UNSIGNED_SHORT_5_6_5
:
1964 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1967 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1968 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1969 return (ctx
->API
== API_OPENGLES2
)
1970 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1971 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1972 return _mesa_has_texture_shared_exponent(ctx
)
1973 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1974 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1975 return _mesa_has_packed_float(ctx
)
1976 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1978 return GL_INVALID_ENUM
;
1983 /* NOTE: no packed types are supported with BGR. That's
1984 * intentional, according to the GL spec.
1987 case GL_UNSIGNED_BYTE
:
1989 case GL_UNSIGNED_SHORT
:
1991 case GL_UNSIGNED_INT
:
1996 return GL_INVALID_ENUM
;
2003 case GL_UNSIGNED_BYTE
:
2005 case GL_UNSIGNED_SHORT
:
2007 case GL_UNSIGNED_INT
:
2009 case GL_UNSIGNED_SHORT_4_4_4_4
:
2010 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2011 case GL_UNSIGNED_SHORT_5_5_5_1
:
2012 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2013 case GL_UNSIGNED_INT_8_8_8_8
:
2014 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2015 case GL_UNSIGNED_INT_10_10_10_2
:
2016 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2020 return GL_INVALID_ENUM
;
2026 case GL_UNSIGNED_BYTE
:
2028 case GL_UNSIGNED_SHORT
:
2030 case GL_UNSIGNED_INT
:
2032 case GL_UNSIGNED_SHORT_4_4_4_4
:
2033 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2034 case GL_UNSIGNED_INT_8_8_8_8
:
2035 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2039 return GL_INVALID_ENUM
;
2043 if (!_mesa_has_MESA_ycbcr_texture(ctx
))
2044 return GL_INVALID_ENUM
;
2045 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2046 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2049 return GL_INVALID_OPERATION
;
2051 case GL_DEPTH_STENCIL
:
2052 if (type
== GL_UNSIGNED_INT_24_8
)
2054 else if (_mesa_has_float_depth_buffer(ctx
) &&
2055 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2058 return GL_INVALID_ENUM
;
2060 /* integer-valued formats */
2061 case GL_RED_INTEGER_EXT
:
2062 case GL_GREEN_INTEGER_EXT
:
2063 case GL_BLUE_INTEGER_EXT
:
2064 case GL_ALPHA_INTEGER_EXT
:
2068 case GL_UNSIGNED_BYTE
:
2070 case GL_UNSIGNED_SHORT
:
2072 case GL_UNSIGNED_INT
:
2073 return _mesa_has_integer_textures(ctx
)
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 _mesa_has_integer_textures(ctx
)
2088 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2089 case GL_UNSIGNED_BYTE_3_3_2
:
2090 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2091 case GL_UNSIGNED_SHORT_5_6_5
:
2092 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2093 return _mesa_has_texture_rgb10_a2ui(ctx
)
2094 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2096 return GL_INVALID_ENUM
;
2099 case GL_BGR_INTEGER_EXT
:
2102 case GL_UNSIGNED_BYTE
:
2104 case GL_UNSIGNED_SHORT
:
2106 case GL_UNSIGNED_INT
:
2107 /* NOTE: no packed formats w/ BGR format */
2108 return _mesa_has_integer_textures(ctx
)
2109 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2111 return GL_INVALID_ENUM
;
2114 case GL_RGBA_INTEGER_EXT
:
2115 case GL_BGRA_INTEGER_EXT
:
2118 case GL_UNSIGNED_BYTE
:
2120 case GL_UNSIGNED_SHORT
:
2122 case GL_UNSIGNED_INT
:
2123 return _mesa_has_integer_textures(ctx
)
2124 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2125 case GL_UNSIGNED_SHORT_4_4_4_4
:
2126 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2127 case GL_UNSIGNED_SHORT_5_5_5_1
:
2128 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2129 case GL_UNSIGNED_INT_8_8_8_8
:
2130 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2131 case GL_UNSIGNED_INT_10_10_10_2
:
2132 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2133 return _mesa_has_texture_rgb10_a2ui(ctx
)
2134 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2136 return GL_INVALID_ENUM
;
2139 case GL_LUMINANCE_INTEGER_EXT
:
2140 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2143 case GL_UNSIGNED_BYTE
:
2145 case GL_UNSIGNED_SHORT
:
2147 case GL_UNSIGNED_INT
:
2148 return _mesa_has_integer_textures(ctx
)
2149 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2151 return GL_INVALID_ENUM
;
2155 return GL_INVALID_ENUM
;
2162 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2163 * and glTex[Sub]Image.
2164 * \return error code, or GL_NO_ERROR.
2167 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2168 GLenum format
, GLenum type
,
2169 unsigned dimensions
)
2171 GLboolean type_valid
= GL_TRUE
;
2176 if (!_mesa_has_rg_textures(ctx
))
2177 return GL_INVALID_VALUE
;
2181 case GL_LUMINANCE_ALPHA
:
2182 type_valid
= (type
== GL_UNSIGNED_BYTE
2184 || type
== GL_HALF_FLOAT_OES
);
2188 type_valid
= (type
== GL_UNSIGNED_BYTE
2189 || type
== GL_UNSIGNED_SHORT_5_6_5
2191 || type
== GL_HALF_FLOAT_OES
);
2195 type_valid
= (type
== GL_UNSIGNED_BYTE
2196 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2197 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2199 || type
== GL_HALF_FLOAT_OES
2200 || (_mesa_has_texture_type_2_10_10_10_REV(ctx
) &&
2201 type
== GL_UNSIGNED_INT_2_10_10_10_REV
));
2204 case GL_DEPTH_COMPONENT
:
2205 /* This format is filtered against invalid dimensionalities elsewhere.
2207 type_valid
= (type
== GL_UNSIGNED_SHORT
2208 || type
== GL_UNSIGNED_INT
);
2211 case GL_DEPTH_STENCIL
:
2212 /* This format is filtered against invalid dimensionalities elsewhere.
2214 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2218 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2220 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2221 * the format does not appear to be allowed for 3D textures in OpenGL
2224 if (dimensions
!= 2)
2225 return GL_INVALID_VALUE
;
2230 return GL_INVALID_VALUE
;
2233 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2237 * Return the simple base format for a given internal texture format.
2238 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2240 * \param ctx GL context.
2241 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2243 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2244 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2246 * This is the format which is used during texture application (i.e. the
2247 * texture format and env mode determine the arithmetic used.
2250 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2252 switch (internalFormat
) {
2258 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2263 case GL_LUMINANCE12
:
2264 case GL_LUMINANCE16
:
2265 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2267 case GL_LUMINANCE_ALPHA
:
2268 case GL_LUMINANCE4_ALPHA4
:
2269 case GL_LUMINANCE6_ALPHA2
:
2270 case GL_LUMINANCE8_ALPHA8
:
2271 case GL_LUMINANCE12_ALPHA4
:
2272 case GL_LUMINANCE12_ALPHA12
:
2273 case GL_LUMINANCE16_ALPHA16
:
2274 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2278 case GL_INTENSITY12
:
2279 case GL_INTENSITY16
:
2280 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2282 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2293 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2307 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2309 if (_mesa_is_gles(ctx
)) {
2310 switch (internalFormat
) {
2318 if (_mesa_has_ARB_ES2_compatibility(ctx
) ||
2319 _mesa_has_OES_framebuffer_object(ctx
) ||
2320 ctx
->API
== API_OPENGLES2
) {
2321 switch (internalFormat
) {
2329 if (_mesa_has_ARB_depth_texture(ctx
) || _mesa_has_OES_depth_texture(ctx
) ||
2330 ctx
->API
== API_OPENGL_CORE
) {
2331 switch (internalFormat
) {
2332 case GL_DEPTH_COMPONENT
:
2333 case GL_DEPTH_COMPONENT16
:
2334 case GL_DEPTH_COMPONENT24
:
2335 case GL_DEPTH_COMPONENT32
:
2336 return GL_DEPTH_COMPONENT
;
2337 case GL_DEPTH_STENCIL
:
2338 case GL_DEPTH24_STENCIL8
:
2339 return GL_DEPTH_STENCIL
;
2345 if (_mesa_has_ARB_texture_stencil8(ctx
) ||
2346 _mesa_has_OES_texture_stencil8(ctx
)) {
2347 switch (internalFormat
) {
2348 case GL_STENCIL_INDEX
:
2349 case GL_STENCIL_INDEX1
:
2350 case GL_STENCIL_INDEX4
:
2351 case GL_STENCIL_INDEX8
:
2352 case GL_STENCIL_INDEX16
:
2353 return GL_STENCIL_INDEX
;
2359 switch (internalFormat
) {
2360 case GL_COMPRESSED_ALPHA
:
2362 case GL_COMPRESSED_LUMINANCE
:
2363 return GL_LUMINANCE
;
2364 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2365 return GL_LUMINANCE_ALPHA
;
2366 case GL_COMPRESSED_INTENSITY
:
2367 return GL_INTENSITY
;
2368 case GL_COMPRESSED_RGB
:
2370 case GL_COMPRESSED_RGBA
:
2376 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2377 GLenum base_compressed
=
2378 _mesa_gl_compressed_format_base_format(internalFormat
);
2379 if (base_compressed
)
2380 return base_compressed
;
2383 if ((_mesa_has_KHR_texture_compression_astc_ldr(ctx
) &&
2384 is_astc_2d_format(internalFormat
)) ||
2385 (_mesa_has_OES_texture_compression_astc(ctx
) &&
2386 is_astc_3d_format(internalFormat
)))
2389 if (!_mesa_has_MESA_ycbcr_texture(ctx
)) {
2390 if (internalFormat
== GL_YCBCR_MESA
)
2391 return GL_YCBCR_MESA
;
2394 if (_mesa_has_half_float_textures(ctx
)) {
2395 switch (internalFormat
) {
2396 case GL_ALPHA16F_ARB
:
2398 case GL_RGBA16F_ARB
:
2402 case GL_INTENSITY16F_ARB
:
2403 return GL_INTENSITY
;
2404 case GL_LUMINANCE16F_ARB
:
2405 return GL_LUMINANCE
;
2406 case GL_LUMINANCE_ALPHA16F_ARB
:
2407 return GL_LUMINANCE_ALPHA
;
2411 if (_mesa_has_float_textures(ctx
)) {
2412 switch (internalFormat
) {
2413 case GL_ALPHA32F_ARB
:
2415 case GL_RGBA32F_ARB
:
2419 case GL_INTENSITY32F_ARB
:
2420 return GL_INTENSITY
;
2421 case GL_LUMINANCE32F_ARB
:
2422 return GL_LUMINANCE
;
2423 case GL_LUMINANCE_ALPHA32F_ARB
:
2424 return GL_LUMINANCE_ALPHA
;
2428 if (_mesa_has_EXT_texture_snorm(ctx
) || _mesa_is_gles3(ctx
)) {
2429 switch (internalFormat
) {
2440 case GL_RGB16_SNORM
:
2443 case GL_RGBA8_SNORM
:
2444 case GL_RGBA16_SNORM
:
2446 case GL_ALPHA_SNORM
:
2447 case GL_ALPHA8_SNORM
:
2448 case GL_ALPHA16_SNORM
:
2450 case GL_LUMINANCE_SNORM
:
2451 case GL_LUMINANCE8_SNORM
:
2452 case GL_LUMINANCE16_SNORM
:
2453 return GL_LUMINANCE
;
2454 case GL_LUMINANCE_ALPHA_SNORM
:
2455 case GL_LUMINANCE8_ALPHA8_SNORM
:
2456 case GL_LUMINANCE16_ALPHA16_SNORM
:
2457 return GL_LUMINANCE_ALPHA
;
2458 case GL_INTENSITY_SNORM
:
2459 case GL_INTENSITY8_SNORM
:
2460 case GL_INTENSITY16_SNORM
:
2461 return GL_INTENSITY
;
2467 if (_mesa_has_EXT_texture_sRGB(ctx
) || _mesa_is_gles3(ctx
)) {
2468 switch (internalFormat
) {
2471 case GL_COMPRESSED_SRGB_EXT
:
2473 case GL_SRGB_ALPHA_EXT
:
2474 case GL_SRGB8_ALPHA8_EXT
:
2475 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2477 case GL_SLUMINANCE_ALPHA_EXT
:
2478 case GL_SLUMINANCE8_ALPHA8_EXT
:
2479 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2480 return GL_LUMINANCE_ALPHA
;
2481 case GL_SLUMINANCE_EXT
:
2482 case GL_SLUMINANCE8_EXT
:
2483 case GL_COMPRESSED_SLUMINANCE_EXT
:
2484 return GL_LUMINANCE
;
2490 if (_mesa_has_EXT_texture_sRGB_R8(ctx
)) {
2491 switch (internalFormat
) {
2499 if (_mesa_has_integer_textures(ctx
)) {
2500 switch (internalFormat
) {
2501 case GL_RGBA8UI_EXT
:
2502 case GL_RGBA16UI_EXT
:
2503 case GL_RGBA32UI_EXT
:
2505 case GL_RGBA16I_EXT
:
2506 case GL_RGBA32I_EXT
:
2509 case GL_RGB16UI_EXT
:
2510 case GL_RGB32UI_EXT
:
2518 if (_mesa_has_texture_rgb10_a2ui(ctx
)) {
2519 switch (internalFormat
) {
2525 if (_mesa_has_integer_textures(ctx
)) {
2526 switch (internalFormat
) {
2527 case GL_ALPHA8UI_EXT
:
2528 case GL_ALPHA16UI_EXT
:
2529 case GL_ALPHA32UI_EXT
:
2530 case GL_ALPHA8I_EXT
:
2531 case GL_ALPHA16I_EXT
:
2532 case GL_ALPHA32I_EXT
:
2534 case GL_INTENSITY8UI_EXT
:
2535 case GL_INTENSITY16UI_EXT
:
2536 case GL_INTENSITY32UI_EXT
:
2537 case GL_INTENSITY8I_EXT
:
2538 case GL_INTENSITY16I_EXT
:
2539 case GL_INTENSITY32I_EXT
:
2540 return GL_INTENSITY
;
2541 case GL_LUMINANCE8UI_EXT
:
2542 case GL_LUMINANCE16UI_EXT
:
2543 case GL_LUMINANCE32UI_EXT
:
2544 case GL_LUMINANCE8I_EXT
:
2545 case GL_LUMINANCE16I_EXT
:
2546 case GL_LUMINANCE32I_EXT
:
2547 return GL_LUMINANCE
;
2548 case GL_LUMINANCE_ALPHA8UI_EXT
:
2549 case GL_LUMINANCE_ALPHA16UI_EXT
:
2550 case GL_LUMINANCE_ALPHA32UI_EXT
:
2551 case GL_LUMINANCE_ALPHA8I_EXT
:
2552 case GL_LUMINANCE_ALPHA16I_EXT
:
2553 case GL_LUMINANCE_ALPHA32I_EXT
:
2554 return GL_LUMINANCE_ALPHA
;
2560 if (_mesa_has_rg_textures(ctx
)) {
2561 switch (internalFormat
) {
2563 if (!_mesa_has_half_float_textures(ctx
))
2567 if (!_mesa_has_float_textures(ctx
))
2576 if (!_mesa_has_integer_textures(ctx
))
2582 case GL_COMPRESSED_RED
:
2586 if (!_mesa_has_half_float_textures(ctx
))
2590 if (!_mesa_has_float_textures(ctx
))
2599 if (!_mesa_has_integer_textures(ctx
))
2605 case GL_COMPRESSED_RG
:
2612 if (_mesa_has_texture_shared_exponent(ctx
)) {
2613 switch (internalFormat
) {
2614 case GL_RGB9_E5_EXT
:
2621 if (_mesa_has_packed_float(ctx
)) {
2622 switch (internalFormat
) {
2623 case GL_R11F_G11F_B10F_EXT
:
2630 if (_mesa_has_float_depth_buffer(ctx
)) {
2631 switch (internalFormat
) {
2632 case GL_DEPTH_COMPONENT32F
:
2633 return GL_DEPTH_COMPONENT
;
2634 case GL_DEPTH32F_STENCIL8
:
2635 return GL_DEPTH_STENCIL
;
2641 return -1; /* error */
2645 * Returns the effective internal format from a texture format and type.
2646 * This is used by texture image operations internally for validation, when
2647 * the specified internal format is a base (unsized) format.
2649 * This method will only return a valid effective internal format if the
2650 * combination of format, type and internal format in base form, is acceptable.
2652 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2653 * in extensions, to unambiguously correspond to the given base format, then
2654 * that internal format is returned as the effective. Otherwise, if the
2655 * combination is accepted but a single effective format is not defined, the
2656 * passed base format will be returned instead.
2658 * \param format the texture format
2659 * \param type the texture type
2662 gles_effective_internal_format_for_format_and_type(GLenum format
,
2666 case GL_UNSIGNED_BYTE
:
2676 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2677 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2678 * internal formats, they do not correspond to GL constants, so the base
2679 * format is returned instead.
2682 case GL_LUMINANCE_ALPHA
:
2689 case GL_UNSIGNED_SHORT_4_4_4_4
:
2690 if (format
== GL_RGBA
)
2694 case GL_UNSIGNED_SHORT_5_5_5_1
:
2695 if (format
== GL_RGBA
)
2699 case GL_UNSIGNED_SHORT_5_6_5
:
2700 if (format
== GL_RGB
)
2704 /* OES_packed_depth_stencil */
2705 case GL_UNSIGNED_INT_24_8
:
2706 if (format
== GL_DEPTH_STENCIL
)
2707 return GL_DEPTH24_STENCIL8
;
2710 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2711 if (format
== GL_DEPTH_STENCIL
)
2712 return GL_DEPTH32F_STENCIL8
;
2715 case GL_UNSIGNED_SHORT
:
2716 if (format
== GL_DEPTH_COMPONENT
)
2717 return GL_DEPTH_COMPONENT16
;
2720 case GL_UNSIGNED_INT
:
2721 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2724 if (format
== GL_DEPTH_COMPONENT
)
2728 /* OES_texture_float and OES_texture_half_float */
2730 if (format
== GL_DEPTH_COMPONENT
)
2731 return GL_DEPTH_COMPONENT32F
;
2733 case GL_HALF_FLOAT_OES
:
2737 case GL_LUMINANCE_ALPHA
:
2753 /* GL_EXT_texture_type_2_10_10_10_REV */
2754 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2763 /* fall through and return NONE */
2771 * Do error checking of format/type combinations for OpenGL ES 3
2772 * glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat.
2773 * \return error code, or GL_NO_ERROR.
2776 _mesa_gles_error_check_format_and_type(const struct gl_context
*ctx
,
2777 GLenum format
, GLenum type
,
2778 GLenum internalFormat
)
2780 /* If internalFormat is an unsized format, then the effective internal
2781 * format derived from format and type should be used instead. Page 127,
2782 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2784 * "if internalformat is a base internal format, the effective
2785 * internal format is a sized internal format that is derived
2786 * from the format and type for internal use by the GL.
2787 * Table 3.12 specifies the mapping of format and type to effective
2788 * internal formats. The effective internal format is used by the GL
2789 * for purposes such as texture completeness or type checks for
2790 * CopyTex* commands. In these cases, the GL is required to operate
2791 * as if the effective internal format was used as the internalformat
2792 * when specifying the texture data."
2794 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2795 GLenum effectiveInternalFormat
=
2796 gles_effective_internal_format_for_format_and_type(format
, type
);
2798 if (effectiveInternalFormat
== GL_NONE
)
2799 return GL_INVALID_OPERATION
;
2801 GLenum baseInternalFormat
;
2802 if (internalFormat
== GL_BGRA_EXT
) {
2803 /* Unfortunately, _mesa_base_tex_format returns a base format of
2804 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2805 * asking the question, "what channels does this format have?"
2806 * However, if we're trying to determine if two internal formats
2807 * match in the ES3 sense, we actually want GL_BGRA.
2809 baseInternalFormat
= GL_BGRA_EXT
;
2811 baseInternalFormat
=
2812 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2815 if (internalFormat
!= baseInternalFormat
)
2816 return GL_INVALID_OPERATION
;
2818 internalFormat
= effectiveInternalFormat
;
2821 /* The GLES variant of EXT_texture_compression_s3tc is very vague and
2822 * doesn't list valid types. Just do exactly what the spec says.
2824 if (_mesa_has_EXT_texture_compression_s3tc(ctx
) &&
2825 (internalFormat
== GL_COMPRESSED_RGB_S3TC_DXT1_EXT
||
2826 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
||
2827 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
||
2828 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
))
2829 return format
== GL_RGB
|| format
== GL_RGBA
? GL_NO_ERROR
:
2830 GL_INVALID_OPERATION
;
2834 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2835 return GL_INVALID_OPERATION
;
2840 case GL_UNSIGNED_BYTE
:
2841 switch (internalFormat
) {
2847 case GL_SRGB8_ALPHA8_EXT
:
2848 if (ctx
->Version
<= 20)
2849 return GL_INVALID_OPERATION
;
2851 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
2852 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
2853 if (!_mesa_has_EXT_texture_compression_bptc(ctx
))
2854 return GL_INVALID_OPERATION
;
2857 return GL_INVALID_OPERATION
;
2862 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA8_SNORM
)
2863 return GL_INVALID_OPERATION
;
2866 case GL_UNSIGNED_SHORT
:
2867 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGBA16
)
2868 return GL_INVALID_OPERATION
;
2872 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2873 internalFormat
!= GL_RGBA16_SNORM
)
2874 return GL_INVALID_OPERATION
;
2877 case GL_UNSIGNED_SHORT_4_4_4_4
:
2878 switch (internalFormat
) {
2883 return GL_INVALID_OPERATION
;
2887 case GL_UNSIGNED_SHORT_5_5_5_1
:
2888 switch (internalFormat
) {
2893 return GL_INVALID_OPERATION
;
2897 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2898 switch (internalFormat
) {
2902 if (!_mesa_has_texture_type_2_10_10_10_REV(ctx
))
2903 return GL_INVALID_OPERATION
;
2906 return GL_INVALID_OPERATION
;
2911 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA16F
)
2912 return GL_INVALID_OPERATION
;
2916 switch (internalFormat
) {
2919 if (ctx
->Version
<= 20)
2920 return GL_INVALID_OPERATION
;
2923 if (_mesa_has_OES_texture_float(ctx
) && internalFormat
== format
)
2926 return GL_INVALID_OPERATION
;
2930 case GL_HALF_FLOAT_OES
:
2931 if (_mesa_has_OES_texture_half_float(ctx
) && internalFormat
== format
)
2934 return GL_INVALID_OPERATION
;
2938 case GL_RGBA_INTEGER
:
2939 if (ctx
->Version
<= 20)
2940 return GL_INVALID_OPERATION
;
2942 case GL_UNSIGNED_BYTE
:
2943 if (internalFormat
!= GL_RGBA8UI
)
2944 return GL_INVALID_OPERATION
;
2948 if (internalFormat
!= GL_RGBA8I
)
2949 return GL_INVALID_OPERATION
;
2952 case GL_UNSIGNED_SHORT
:
2953 if (internalFormat
!= GL_RGBA16UI
)
2954 return GL_INVALID_OPERATION
;
2958 if (internalFormat
!= GL_RGBA16I
)
2959 return GL_INVALID_OPERATION
;
2962 case GL_UNSIGNED_INT
:
2963 if (internalFormat
!= GL_RGBA32UI
)
2964 return GL_INVALID_OPERATION
;
2968 if (internalFormat
!= GL_RGBA32I
)
2969 return GL_INVALID_OPERATION
;
2972 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2973 if (internalFormat
!= GL_RGB10_A2UI
)
2974 return GL_INVALID_OPERATION
;
2978 return GL_INVALID_OPERATION
;
2984 case GL_UNSIGNED_BYTE
:
2985 switch (internalFormat
) {
2991 if (ctx
->Version
<= 20)
2992 return GL_INVALID_OPERATION
;
2995 return GL_INVALID_OPERATION
;
3000 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB8_SNORM
)
3001 return GL_INVALID_OPERATION
;
3004 case GL_UNSIGNED_SHORT
:
3005 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGB16
)
3006 return GL_INVALID_OPERATION
;
3010 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3011 internalFormat
!= GL_RGB16_SNORM
)
3012 return GL_INVALID_OPERATION
;
3015 case GL_UNSIGNED_SHORT_5_6_5
:
3016 switch (internalFormat
) {
3021 return GL_INVALID_OPERATION
;
3025 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3026 if (ctx
->Version
<= 20 || internalFormat
!= GL_R11F_G11F_B10F
)
3027 return GL_INVALID_OPERATION
;
3030 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3031 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB9_E5
)
3032 return GL_INVALID_OPERATION
;
3036 if (ctx
->Version
<= 20)
3037 return GL_INVALID_OPERATION
;
3038 switch (internalFormat
) {
3040 case GL_R11F_G11F_B10F
:
3044 return GL_INVALID_OPERATION
;
3049 switch (internalFormat
) {
3052 case GL_R11F_G11F_B10F
:
3054 if (ctx
->Version
<= 20)
3055 return GL_INVALID_OPERATION
;
3058 if (_mesa_has_OES_texture_float(ctx
) && internalFormat
== format
)
3060 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
3061 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
3062 if (!_mesa_has_EXT_texture_compression_bptc(ctx
))
3063 return GL_INVALID_OPERATION
;
3066 return GL_INVALID_OPERATION
;
3070 case GL_HALF_FLOAT_OES
:
3071 if (!_mesa_has_OES_texture_half_float(ctx
) || internalFormat
!= format
)
3072 return GL_INVALID_OPERATION
;
3075 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3076 switch (internalFormat
) {
3081 /* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though
3082 * GLES3 doesn't, and GL_OES_required_internalformat extends that
3083 * to allow the sized RGB internalformats as well.
3085 if (!_mesa_has_texture_type_2_10_10_10_REV(ctx
))
3086 return GL_INVALID_OPERATION
;
3089 return GL_INVALID_OPERATION
;
3094 return GL_INVALID_OPERATION
;
3098 case GL_RGB_INTEGER
:
3099 if (ctx
->Version
<= 20)
3100 return GL_INVALID_OPERATION
;
3102 case GL_UNSIGNED_BYTE
:
3103 if (internalFormat
!= GL_RGB8UI
)
3104 return GL_INVALID_OPERATION
;
3108 if (internalFormat
!= GL_RGB8I
)
3109 return GL_INVALID_OPERATION
;
3112 case GL_UNSIGNED_SHORT
:
3113 if (internalFormat
!= GL_RGB16UI
)
3114 return GL_INVALID_OPERATION
;
3118 if (internalFormat
!= GL_RGB16I
)
3119 return GL_INVALID_OPERATION
;
3122 case GL_UNSIGNED_INT
:
3123 if (internalFormat
!= GL_RGB32UI
)
3124 return GL_INVALID_OPERATION
;
3128 if (internalFormat
!= GL_RGB32I
)
3129 return GL_INVALID_OPERATION
;
3133 return GL_INVALID_OPERATION
;
3138 if (!_mesa_has_rg_textures(ctx
))
3139 return GL_INVALID_OPERATION
;
3141 case GL_UNSIGNED_BYTE
:
3142 if (internalFormat
!= GL_RG8
&&
3143 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3144 internalFormat
!= GL_COMPRESSED_RED_GREEN_RGTC2_EXT
))
3145 return GL_INVALID_OPERATION
;
3149 if (internalFormat
!= GL_RG8_SNORM
&&
3150 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3151 internalFormat
!= GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
))
3152 return GL_INVALID_OPERATION
;
3155 case GL_UNSIGNED_SHORT
:
3156 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RG16
)
3157 return GL_INVALID_OPERATION
;
3161 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3162 internalFormat
!= GL_RG16_SNORM
)
3163 return GL_INVALID_OPERATION
;
3167 case GL_HALF_FLOAT_OES
:
3168 switch (internalFormat
) {
3170 if (ctx
->Version
<= 20)
3171 return GL_INVALID_OPERATION
;
3174 if (_mesa_has_rg_textures(ctx
) &&
3175 _mesa_has_OES_texture_half_float(ctx
))
3179 return GL_INVALID_OPERATION
;
3184 switch (internalFormat
) {
3189 if (_mesa_has_rg_textures(ctx
) &&
3190 _mesa_has_OES_texture_float(ctx
))
3194 return GL_INVALID_OPERATION
;
3199 return GL_INVALID_OPERATION
;
3204 if (ctx
->Version
<= 20)
3205 return GL_INVALID_OPERATION
;
3207 case GL_UNSIGNED_BYTE
:
3208 if (internalFormat
!= GL_RG8UI
)
3209 return GL_INVALID_OPERATION
;
3213 if (internalFormat
!= GL_RG8I
)
3214 return GL_INVALID_OPERATION
;
3217 case GL_UNSIGNED_SHORT
:
3218 if (internalFormat
!= GL_RG16UI
)
3219 return GL_INVALID_OPERATION
;
3223 if (internalFormat
!= GL_RG16I
)
3224 return GL_INVALID_OPERATION
;
3227 case GL_UNSIGNED_INT
:
3228 if (internalFormat
!= GL_RG32UI
)
3229 return GL_INVALID_OPERATION
;
3233 if (internalFormat
!= GL_RG32I
)
3234 return GL_INVALID_OPERATION
;
3238 return GL_INVALID_OPERATION
;
3243 if (!_mesa_has_rg_textures(ctx
))
3244 return GL_INVALID_OPERATION
;
3246 case GL_UNSIGNED_BYTE
:
3247 if (internalFormat
== GL_R8
||
3248 ((internalFormat
== GL_SR8_EXT
) &&
3249 _mesa_has_EXT_texture_sRGB_R8(ctx
)) ||
3250 (internalFormat
== GL_COMPRESSED_RED_RGTC1_EXT
&&
3251 _mesa_has_EXT_texture_compression_rgtc(ctx
)))
3253 return GL_INVALID_OPERATION
;
3256 if (internalFormat
!= GL_R8_SNORM
&&
3257 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3258 internalFormat
!= GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
))
3259 return GL_INVALID_OPERATION
;
3262 case GL_UNSIGNED_SHORT
:
3263 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_R16
)
3264 return GL_INVALID_OPERATION
;
3268 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3269 internalFormat
!= GL_R16_SNORM
)
3270 return GL_INVALID_OPERATION
;
3274 case GL_HALF_FLOAT_OES
:
3275 switch (internalFormat
) {
3277 if (ctx
->Version
<= 20)
3278 return GL_INVALID_OPERATION
;
3282 if (_mesa_has_rg_textures(ctx
) &&
3283 _mesa_has_OES_texture_half_float(ctx
))
3287 return GL_INVALID_OPERATION
;
3292 switch (internalFormat
) {
3297 if (_mesa_has_rg_textures(ctx
) &&
3298 _mesa_has_OES_texture_float(ctx
))
3302 return GL_INVALID_OPERATION
;
3307 return GL_INVALID_OPERATION
;
3311 case GL_RED_INTEGER
:
3312 if (ctx
->Version
<= 20)
3313 return GL_INVALID_OPERATION
;
3315 case GL_UNSIGNED_BYTE
:
3316 if (internalFormat
!= GL_R8UI
)
3317 return GL_INVALID_OPERATION
;
3321 if (internalFormat
!= GL_R8I
)
3322 return GL_INVALID_OPERATION
;
3325 case GL_UNSIGNED_SHORT
:
3326 if (internalFormat
!= GL_R16UI
)
3327 return GL_INVALID_OPERATION
;
3331 if (internalFormat
!= GL_R16I
)
3332 return GL_INVALID_OPERATION
;
3335 case GL_UNSIGNED_INT
:
3336 if (internalFormat
!= GL_R32UI
)
3337 return GL_INVALID_OPERATION
;
3341 if (internalFormat
!= GL_R32I
)
3342 return GL_INVALID_OPERATION
;
3346 return GL_INVALID_OPERATION
;
3350 case GL_DEPTH_COMPONENT
:
3352 case GL_UNSIGNED_SHORT
:
3353 if (internalFormat
!= GL_DEPTH_COMPONENT
3354 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3355 return GL_INVALID_OPERATION
;
3358 case GL_UNSIGNED_INT
:
3359 switch (internalFormat
) {
3360 case GL_DEPTH_COMPONENT
:
3361 case GL_DEPTH_COMPONENT16
:
3362 case GL_DEPTH_COMPONENT24
:
3365 return GL_INVALID_OPERATION
;
3370 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH_COMPONENT32F
)
3371 return GL_INVALID_OPERATION
;
3375 return GL_INVALID_OPERATION
;
3379 case GL_DEPTH_STENCIL
:
3381 case GL_UNSIGNED_INT_24_8
:
3382 if (internalFormat
!= GL_DEPTH_STENCIL
3383 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3384 return GL_INVALID_OPERATION
;
3387 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3388 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH32F_STENCIL8
)
3389 return GL_INVALID_OPERATION
;
3393 return GL_INVALID_OPERATION
;
3397 case GL_STENCIL_INDEX
:
3398 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3399 type
!= GL_UNSIGNED_BYTE
||
3400 internalFormat
!= GL_STENCIL_INDEX8
) {
3401 return GL_INVALID_OPERATION
;
3407 case GL_LUMINANCE_ALPHA
:
3410 if (!_mesa_has_OES_texture_float(ctx
) || internalFormat
!= format
)
3411 return GL_INVALID_OPERATION
;
3413 case GL_HALF_FLOAT_OES
:
3414 if (!_mesa_has_OES_texture_half_float(ctx
) || internalFormat
!= format
)
3415 return GL_INVALID_OPERATION
;
3417 case GL_UNSIGNED_BYTE
:
3418 if (!(format
== internalFormat
||
3419 (format
== GL_ALPHA
&& internalFormat
== GL_ALPHA8
) ||
3420 (format
== GL_LUMINANCE
&& internalFormat
== GL_LUMINANCE8
) ||
3421 (format
== GL_LUMINANCE_ALPHA
&&
3422 ((internalFormat
== GL_LUMINANCE8_ALPHA8
) ||
3423 (internalFormat
== GL_LUMINANCE4_ALPHA4
))))) {
3424 return GL_INVALID_OPERATION
;
3428 return GL_INVALID_OPERATION
;
3437 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3439 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3440 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3441 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3442 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3446 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3450 case GL_RGBA_INTEGER_EXT
:
3451 set_swizzle(swizzle
, 0, 1, 2, 3);
3454 case GL_BGRA_INTEGER_EXT
:
3455 set_swizzle(swizzle
, 2, 1, 0, 3);
3458 set_swizzle(swizzle
, 3, 2, 1, 0);
3461 case GL_RGB_INTEGER_EXT
:
3462 set_swizzle(swizzle
, 0, 1, 2, 5);
3465 case GL_BGR_INTEGER_EXT
:
3466 set_swizzle(swizzle
, 2, 1, 0, 5);
3468 case GL_LUMINANCE_ALPHA
:
3469 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3470 set_swizzle(swizzle
, 0, 0, 0, 1);
3474 set_swizzle(swizzle
, 0, 1, 4, 5);
3477 case GL_RED_INTEGER_EXT
:
3478 set_swizzle(swizzle
, 0, 4, 4, 5);
3481 case GL_GREEN_INTEGER_EXT
:
3482 set_swizzle(swizzle
, 4, 0, 4, 5);
3485 case GL_BLUE_INTEGER_EXT
:
3486 set_swizzle(swizzle
, 4, 4, 0, 5);
3489 case GL_ALPHA_INTEGER_EXT
:
3490 set_swizzle(swizzle
, 4, 4, 4, 0);
3493 case GL_LUMINANCE_INTEGER_EXT
:
3494 set_swizzle(swizzle
, 0, 0, 0, 5);
3497 set_swizzle(swizzle
, 0, 0, 0, 0);
3505 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3506 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3507 * otherwise (for non-array formats).
3509 * This function will typically be used to compute a mesa format from a GL type
3510 * so we can then call _mesa_format_convert. This function does
3511 * not consider byte swapping, so it returns types assuming that no byte
3512 * swapping is involved. If byte swapping is involved then clients are supposed
3513 * to handle that on their side before calling _mesa_format_convert.
3515 * This function returns an uint32_t that can pack a mesa_format or a
3516 * mesa_array_format. Clients must check the mesa array format bit
3517 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3518 * format is a mesa_array_format or a mesa_format.
3521 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3523 bool is_array_format
= true;
3525 bool normalized
= false, is_float
= false, is_signed
= false;
3526 int num_channels
= 0, type_size
= 0;
3528 /* Extract array format type information from the OpenGL data type */
3530 case GL_UNSIGNED_BYTE
:
3537 case GL_UNSIGNED_SHORT
:
3544 case GL_UNSIGNED_INT
:
3552 case GL_HALF_FLOAT_OES
:
3563 is_array_format
= false;
3567 /* Extract array format swizzle information from the OpenGL format */
3568 if (is_array_format
)
3569 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3571 /* If this is an array format type after checking data type and format,
3572 * create the array format
3574 if (is_array_format
) {
3575 normalized
= !_mesa_is_enum_format_integer(format
);
3576 num_channels
= _mesa_components_in_format(format
);
3578 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3579 normalized
, num_channels
,
3580 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3583 /* Otherwise this is not an array format, so return the mesa_format
3584 * matching the OpenGL format and data type
3587 case GL_UNSIGNED_SHORT_5_6_5
:
3588 if (format
== GL_RGB
)
3589 return MESA_FORMAT_B5G6R5_UNORM
;
3590 else if (format
== GL_BGR
)
3591 return MESA_FORMAT_R5G6B5_UNORM
;
3592 else if (format
== GL_RGB_INTEGER
)
3593 return MESA_FORMAT_B5G6R5_UINT
;
3595 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3596 if (format
== GL_RGB
)
3597 return MESA_FORMAT_R5G6B5_UNORM
;
3598 else if (format
== GL_BGR
)
3599 return MESA_FORMAT_B5G6R5_UNORM
;
3600 else if (format
== GL_RGB_INTEGER
)
3601 return MESA_FORMAT_R5G6B5_UINT
;
3603 case GL_UNSIGNED_SHORT_4_4_4_4
:
3604 if (format
== GL_RGBA
)
3605 return MESA_FORMAT_A4B4G4R4_UNORM
;
3606 else if (format
== GL_BGRA
)
3607 return MESA_FORMAT_A4R4G4B4_UNORM
;
3608 else if (format
== GL_ABGR_EXT
)
3609 return MESA_FORMAT_R4G4B4A4_UNORM
;
3610 else if (format
== GL_RGBA_INTEGER
)
3611 return MESA_FORMAT_A4B4G4R4_UINT
;
3612 else if (format
== GL_BGRA_INTEGER
)
3613 return MESA_FORMAT_A4R4G4B4_UINT
;
3615 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3616 if (format
== GL_RGBA
)
3617 return MESA_FORMAT_R4G4B4A4_UNORM
;
3618 else if (format
== GL_BGRA
)
3619 return MESA_FORMAT_B4G4R4A4_UNORM
;
3620 else if (format
== GL_ABGR_EXT
)
3621 return MESA_FORMAT_A4B4G4R4_UNORM
;
3622 else if (format
== GL_RGBA_INTEGER
)
3623 return MESA_FORMAT_R4G4B4A4_UINT
;
3624 else if (format
== GL_BGRA_INTEGER
)
3625 return MESA_FORMAT_B4G4R4A4_UINT
;
3627 case GL_UNSIGNED_SHORT_5_5_5_1
:
3628 if (format
== GL_RGBA
)
3629 return MESA_FORMAT_A1B5G5R5_UNORM
;
3630 else if (format
== GL_BGRA
)
3631 return MESA_FORMAT_A1R5G5B5_UNORM
;
3632 else if (format
== GL_RGBA_INTEGER
)
3633 return MESA_FORMAT_A1B5G5R5_UINT
;
3634 else if (format
== GL_BGRA_INTEGER
)
3635 return MESA_FORMAT_A1R5G5B5_UINT
;
3637 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3638 if (format
== GL_RGBA
)
3639 return MESA_FORMAT_R5G5B5A1_UNORM
;
3640 else if (format
== GL_BGRA
)
3641 return MESA_FORMAT_B5G5R5A1_UNORM
;
3642 else if (format
== GL_RGBA_INTEGER
)
3643 return MESA_FORMAT_R5G5B5A1_UINT
;
3644 else if (format
== GL_BGRA_INTEGER
)
3645 return MESA_FORMAT_B5G5R5A1_UINT
;
3647 case GL_UNSIGNED_BYTE_3_3_2
:
3648 if (format
== GL_RGB
)
3649 return MESA_FORMAT_B2G3R3_UNORM
;
3650 else if (format
== GL_RGB_INTEGER
)
3651 return MESA_FORMAT_B2G3R3_UINT
;
3653 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3654 if (format
== GL_RGB
)
3655 return MESA_FORMAT_R3G3B2_UNORM
;
3656 else if (format
== GL_RGB_INTEGER
)
3657 return MESA_FORMAT_R3G3B2_UINT
;
3659 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3660 if (format
== GL_RGB
)
3661 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3663 case GL_UNSIGNED_INT_10_10_10_2
:
3664 if (format
== GL_RGBA
)
3665 return MESA_FORMAT_A2B10G10R10_UNORM
;
3666 else if (format
== GL_RGBA_INTEGER
)
3667 return MESA_FORMAT_A2B10G10R10_UINT
;
3668 else if (format
== GL_BGRA
)
3669 return MESA_FORMAT_A2R10G10B10_UNORM
;
3670 else if (format
== GL_BGRA_INTEGER
)
3671 return MESA_FORMAT_A2R10G10B10_UINT
;
3673 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3674 if (format
== GL_RGB
)
3675 return MESA_FORMAT_R10G10B10X2_UNORM
;
3676 if (format
== GL_RGBA
)
3677 return MESA_FORMAT_R10G10B10A2_UNORM
;
3678 else if (format
== GL_RGBA_INTEGER
)
3679 return MESA_FORMAT_R10G10B10A2_UINT
;
3680 else if (format
== GL_BGRA
)
3681 return MESA_FORMAT_B10G10R10A2_UNORM
;
3682 else if (format
== GL_BGRA_INTEGER
)
3683 return MESA_FORMAT_B10G10R10A2_UINT
;
3685 case GL_UNSIGNED_INT_8_8_8_8
:
3686 if (format
== GL_RGBA
)
3687 return MESA_FORMAT_A8B8G8R8_UNORM
;
3688 else if (format
== GL_BGRA
)
3689 return MESA_FORMAT_A8R8G8B8_UNORM
;
3690 else if (format
== GL_ABGR_EXT
)
3691 return MESA_FORMAT_R8G8B8A8_UNORM
;
3692 else if (format
== GL_RGBA_INTEGER
)
3693 return MESA_FORMAT_A8B8G8R8_UINT
;
3694 else if (format
== GL_BGRA_INTEGER
)
3695 return MESA_FORMAT_A8R8G8B8_UINT
;
3697 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3698 if (format
== GL_RGBA
)
3699 return MESA_FORMAT_R8G8B8A8_UNORM
;
3700 else if (format
== GL_BGRA
)
3701 return MESA_FORMAT_B8G8R8A8_UNORM
;
3702 else if (format
== GL_ABGR_EXT
)
3703 return MESA_FORMAT_A8B8G8R8_UNORM
;
3704 else if (format
== GL_RGBA_INTEGER
)
3705 return MESA_FORMAT_R8G8B8A8_UINT
;
3706 else if (format
== GL_BGRA_INTEGER
)
3707 return MESA_FORMAT_B8G8R8A8_UINT
;
3709 case GL_UNSIGNED_SHORT_8_8_MESA
:
3710 if (format
== GL_YCBCR_MESA
)
3711 return MESA_FORMAT_YCBCR
;
3713 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3714 if (format
== GL_YCBCR_MESA
)
3715 return MESA_FORMAT_YCBCR_REV
;
3717 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3718 if (format
== GL_RGB
)
3719 return MESA_FORMAT_R11G11B10_FLOAT
;
3722 if (format
== GL_DEPTH_COMPONENT
)
3723 return MESA_FORMAT_Z_FLOAT32
;
3725 case GL_UNSIGNED_INT
:
3726 if (format
== GL_DEPTH_COMPONENT
)
3727 return MESA_FORMAT_Z_UNORM32
;
3729 case GL_UNSIGNED_SHORT
:
3730 if (format
== GL_DEPTH_COMPONENT
)
3731 return MESA_FORMAT_Z_UNORM16
;
3733 case GL_UNSIGNED_INT_24_8
:
3734 if (format
== GL_DEPTH_STENCIL
)
3735 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3737 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3738 if (format
== GL_DEPTH_STENCIL
)
3739 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3745 /* If we got here it means that we could not find a Mesa format that
3746 * matches the GL format/type provided. We may need to add a new Mesa
3747 * format in that case.
3749 unreachable("Unsupported format");
3753 _mesa_tex_format_from_format_and_type(const struct gl_context
*ctx
,
3754 GLenum gl_format
, GLenum type
)
3756 mesa_format format
= _mesa_format_from_format_and_type(gl_format
, type
);
3758 if (_mesa_format_is_mesa_array_format(format
))
3759 format
= _mesa_format_from_array_format(format
);
3761 if (format
== MESA_FORMAT_NONE
|| !ctx
->TextureFormatSupported
[format
])
3762 return MESA_FORMAT_NONE
;
3768 * Returns true if \p internal_format is a sized internal format that
3769 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3772 _mesa_is_es3_color_renderable(const struct gl_context
*ctx
,
3773 GLenum internal_format
)
3775 switch (internal_format
) {
3785 case GL_SRGB8_ALPHA8
:
3792 case GL_R11F_G11F_B10F
:
3815 return _mesa_has_EXT_texture_norm16(ctx
);
3818 case GL_RGBA8_SNORM
:
3819 return _mesa_has_EXT_render_snorm(ctx
);
3822 case GL_RGBA16_SNORM
:
3823 return _mesa_has_EXT_texture_norm16(ctx
) &&
3824 _mesa_has_EXT_render_snorm(ctx
);
3831 * Returns true if \p internal_format is a sized internal format that
3832 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3835 _mesa_is_es3_texture_filterable(const struct gl_context
*ctx
,
3836 GLenum internal_format
)
3838 switch (internal_format
) {
3849 case GL_RGBA8_SNORM
:
3852 case GL_SRGB8_ALPHA8
:
3857 case GL_R11F_G11F_B10F
:
3865 case GL_RGB16_SNORM
:
3867 case GL_RGBA16_SNORM
:
3868 return _mesa_has_EXT_texture_norm16(ctx
);
3873 /* The OES_texture_float_linear spec says:
3875 * "When implemented against OpenGL ES 3.0 or later versions, sized
3876 * 32-bit floating-point formats become texture-filterable. This
3877 * should be noted by, for example, checking the ``TF'' column of
3878 * table 8.13 in the ES 3.1 Specification (``Correspondence of sized
3879 * internal formats to base internal formats ... and use cases ...'')
3880 * for the R32F, RG32F, RGB32F, and RGBA32F formats."
3882 return _mesa_has_OES_texture_float_linear(ctx
);