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(ctx
);
1379 case MESA_FORMAT_LAYOUT_FXT1
:
1380 return _mesa_has_3DFX_texture_compression_FXT1(ctx
);
1381 case MESA_FORMAT_LAYOUT_RGTC
:
1382 return _mesa_has_ARB_texture_compression_rgtc(ctx
) ||
1383 _mesa_has_EXT_texture_compression_rgtc(ctx
);
1384 case MESA_FORMAT_LAYOUT_LATC
:
1385 return _mesa_has_EXT_texture_compression_latc(ctx
);
1386 case MESA_FORMAT_LAYOUT_ETC1
:
1387 return _mesa_has_OES_compressed_ETC1_RGB8_texture(ctx
);
1388 case MESA_FORMAT_LAYOUT_ETC2
:
1389 return _mesa_is_gles3(ctx
) || _mesa_has_ARB_ES3_compatibility(ctx
);
1390 case MESA_FORMAT_LAYOUT_BPTC
:
1391 return _mesa_has_ARB_texture_compression_bptc(ctx
) ||
1392 _mesa_has_EXT_texture_compression_bptc(ctx
);
1393 case MESA_FORMAT_LAYOUT_ASTC
:
1394 return _mesa_has_KHR_texture_compression_astc_ldr(ctx
);
1401 * Test if the given format represents an sRGB format.
1402 * \param format the GL format (can be an internal format)
1403 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1406 _mesa_is_srgb_format(GLenum format
)
1412 case GL_SRGB8_ALPHA8
:
1413 case GL_COMPRESSED_SRGB
:
1414 case GL_COMPRESSED_SRGB_ALPHA
:
1415 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1416 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1417 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1418 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1419 case GL_COMPRESSED_SRGB8_ETC2
:
1420 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1421 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1422 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1423 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1424 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1425 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1426 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1427 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1428 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1429 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1430 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1431 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1432 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1435 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1436 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1446 * Convert various unpack formats to the corresponding base format.
1449 _mesa_unpack_format_to_base_format(GLenum format
)
1452 case GL_RED_INTEGER
:
1454 case GL_GREEN_INTEGER
:
1456 case GL_BLUE_INTEGER
:
1458 case GL_ALPHA_INTEGER
:
1462 case GL_RGB_INTEGER
:
1464 case GL_RGBA_INTEGER
:
1466 case GL_BGR_INTEGER
:
1468 case GL_BGRA_INTEGER
:
1470 case GL_LUMINANCE_INTEGER_EXT
:
1471 return GL_LUMINANCE
;
1472 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1473 return GL_LUMINANCE_ALPHA
;
1484 case GL_LUMINANCE_ALPHA
:
1491 * Convert various base formats to the corresponding integer format.
1494 _mesa_base_format_to_integer_format(GLenum format
)
1498 return GL_RED_INTEGER
;
1500 return GL_GREEN_INTEGER
;
1502 return GL_BLUE_INTEGER
;
1504 return GL_RG_INTEGER
;
1506 return GL_RGB_INTEGER
;
1508 return GL_RGBA_INTEGER
;
1510 return GL_BGR_INTEGER
;
1512 return GL_BGRA_INTEGER
;
1514 return GL_ALPHA_INTEGER
;
1516 return GL_LUMINANCE_INTEGER_EXT
;
1517 case GL_LUMINANCE_ALPHA
:
1518 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1526 * Does the given base texture/renderbuffer format have the channel
1530 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1533 case GL_TEXTURE_RED_SIZE
:
1534 case GL_TEXTURE_RED_TYPE
:
1535 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1536 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1537 case GL_INTERNALFORMAT_RED_SIZE
:
1538 case GL_INTERNALFORMAT_RED_TYPE
:
1539 if (base_format
== GL_RED
||
1540 base_format
== GL_RG
||
1541 base_format
== GL_RGB
||
1542 base_format
== GL_RGBA
) {
1546 case GL_TEXTURE_GREEN_SIZE
:
1547 case GL_TEXTURE_GREEN_TYPE
:
1548 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1549 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1550 case GL_INTERNALFORMAT_GREEN_SIZE
:
1551 case GL_INTERNALFORMAT_GREEN_TYPE
:
1552 if (base_format
== GL_RG
||
1553 base_format
== GL_RGB
||
1554 base_format
== GL_RGBA
) {
1558 case GL_TEXTURE_BLUE_SIZE
:
1559 case GL_TEXTURE_BLUE_TYPE
:
1560 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1561 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1562 case GL_INTERNALFORMAT_BLUE_SIZE
:
1563 case GL_INTERNALFORMAT_BLUE_TYPE
:
1564 if (base_format
== GL_RGB
||
1565 base_format
== GL_RGBA
) {
1569 case GL_TEXTURE_ALPHA_SIZE
:
1570 case GL_TEXTURE_ALPHA_TYPE
:
1571 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1572 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1573 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1574 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1575 if (base_format
== GL_RGBA
||
1576 base_format
== GL_ALPHA
||
1577 base_format
== GL_LUMINANCE_ALPHA
) {
1581 case GL_TEXTURE_LUMINANCE_SIZE
:
1582 case GL_TEXTURE_LUMINANCE_TYPE
:
1583 if (base_format
== GL_LUMINANCE
||
1584 base_format
== GL_LUMINANCE_ALPHA
) {
1588 case GL_TEXTURE_INTENSITY_SIZE
:
1589 case GL_TEXTURE_INTENSITY_TYPE
:
1590 if (base_format
== GL_INTENSITY
) {
1594 case GL_TEXTURE_DEPTH_SIZE
:
1595 case GL_TEXTURE_DEPTH_TYPE
:
1596 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1597 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1598 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1599 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1600 if (base_format
== GL_DEPTH_STENCIL
||
1601 base_format
== GL_DEPTH_COMPONENT
) {
1605 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1606 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1607 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1608 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1609 if (base_format
== GL_DEPTH_STENCIL
||
1610 base_format
== GL_STENCIL_INDEX
) {
1615 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
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 _mesa_has_texture_rgb10_a2ui(ctx
)) {
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 _mesa_has_texture_rgb10_a2ui(ctx
)) {
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 _mesa_has_texture_rgb10_a2ui(ctx
)) {
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 (!_mesa_has_float_depth_buffer(ctx
)) {
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 (!_mesa_has_packed_float(ctx
)) {
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_has_rg_textures(ctx
))
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 (!_mesa_has_rg_textures(ctx
))
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 _mesa_has_texture_shared_exponent(ctx
)
1972 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1973 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1974 return _mesa_has_packed_float(ctx
)
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 (!_mesa_has_MESA_ycbcr_texture(ctx
))
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 (_mesa_has_float_depth_buffer(ctx
) &&
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 _mesa_has_integer_textures(ctx
)
2073 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2075 return GL_INVALID_ENUM
;
2078 case GL_RGB_INTEGER_EXT
:
2081 case GL_UNSIGNED_BYTE
:
2083 case GL_UNSIGNED_SHORT
:
2085 case GL_UNSIGNED_INT
:
2086 return _mesa_has_integer_textures(ctx
)
2087 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2088 case GL_UNSIGNED_BYTE_3_3_2
:
2089 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2090 case GL_UNSIGNED_SHORT_5_6_5
:
2091 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2092 return _mesa_has_texture_rgb10_a2ui(ctx
)
2093 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2095 return GL_INVALID_ENUM
;
2098 case GL_BGR_INTEGER_EXT
:
2101 case GL_UNSIGNED_BYTE
:
2103 case GL_UNSIGNED_SHORT
:
2105 case GL_UNSIGNED_INT
:
2106 /* NOTE: no packed formats w/ BGR format */
2107 return _mesa_has_integer_textures(ctx
)
2108 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2110 return GL_INVALID_ENUM
;
2113 case GL_RGBA_INTEGER_EXT
:
2114 case GL_BGRA_INTEGER_EXT
:
2117 case GL_UNSIGNED_BYTE
:
2119 case GL_UNSIGNED_SHORT
:
2121 case GL_UNSIGNED_INT
:
2122 return _mesa_has_integer_textures(ctx
)
2123 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2124 case GL_UNSIGNED_SHORT_4_4_4_4
:
2125 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2126 case GL_UNSIGNED_SHORT_5_5_5_1
:
2127 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2128 case GL_UNSIGNED_INT_8_8_8_8
:
2129 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2130 case GL_UNSIGNED_INT_10_10_10_2
:
2131 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2132 return _mesa_has_texture_rgb10_a2ui(ctx
)
2133 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2135 return GL_INVALID_ENUM
;
2138 case GL_LUMINANCE_INTEGER_EXT
:
2139 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2142 case GL_UNSIGNED_BYTE
:
2144 case GL_UNSIGNED_SHORT
:
2146 case GL_UNSIGNED_INT
:
2147 return _mesa_has_integer_textures(ctx
)
2148 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2150 return GL_INVALID_ENUM
;
2154 return GL_INVALID_ENUM
;
2161 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2162 * and glTex[Sub]Image.
2163 * \return error code, or GL_NO_ERROR.
2166 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2167 GLenum format
, GLenum type
,
2168 unsigned dimensions
)
2170 GLboolean type_valid
= GL_TRUE
;
2175 if (!_mesa_has_rg_textures(ctx
))
2176 return GL_INVALID_VALUE
;
2180 case GL_LUMINANCE_ALPHA
:
2181 type_valid
= (type
== GL_UNSIGNED_BYTE
2183 || type
== GL_HALF_FLOAT_OES
);
2187 type_valid
= (type
== GL_UNSIGNED_BYTE
2188 || type
== GL_UNSIGNED_SHORT_5_6_5
2190 || type
== GL_HALF_FLOAT_OES
);
2194 type_valid
= (type
== GL_UNSIGNED_BYTE
2195 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2196 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2198 || type
== GL_HALF_FLOAT_OES
2199 || (_mesa_has_texture_type_2_10_10_10_REV(ctx
) &&
2200 type
== GL_UNSIGNED_INT_2_10_10_10_REV
));
2203 case GL_DEPTH_COMPONENT
:
2204 /* This format is filtered against invalid dimensionalities elsewhere.
2206 type_valid
= (type
== GL_UNSIGNED_SHORT
2207 || type
== GL_UNSIGNED_INT
);
2210 case GL_DEPTH_STENCIL
:
2211 /* This format is filtered against invalid dimensionalities elsewhere.
2213 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2217 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2219 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2220 * the format does not appear to be allowed for 3D textures in OpenGL
2223 if (dimensions
!= 2)
2224 return GL_INVALID_VALUE
;
2229 return GL_INVALID_VALUE
;
2232 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2236 * Return the simple base format for a given internal texture format.
2237 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2239 * \param ctx GL context.
2240 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2242 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2243 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2245 * This is the format which is used during texture application (i.e. the
2246 * texture format and env mode determine the arithmetic used.
2249 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2251 switch (internalFormat
) {
2257 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2262 case GL_LUMINANCE12
:
2263 case GL_LUMINANCE16
:
2264 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2266 case GL_LUMINANCE_ALPHA
:
2267 case GL_LUMINANCE4_ALPHA4
:
2268 case GL_LUMINANCE6_ALPHA2
:
2269 case GL_LUMINANCE8_ALPHA8
:
2270 case GL_LUMINANCE12_ALPHA4
:
2271 case GL_LUMINANCE12_ALPHA12
:
2272 case GL_LUMINANCE16_ALPHA16
:
2273 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2277 case GL_INTENSITY12
:
2278 case GL_INTENSITY16
:
2279 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2281 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2292 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2306 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2308 if (_mesa_is_gles(ctx
)) {
2309 switch (internalFormat
) {
2317 if (_mesa_has_ARB_ES2_compatibility(ctx
) ||
2318 _mesa_has_OES_framebuffer_object(ctx
) ||
2319 ctx
->API
== API_OPENGLES2
) {
2320 switch (internalFormat
) {
2328 if (_mesa_has_ARB_depth_texture(ctx
) || _mesa_has_OES_depth_texture(ctx
) ||
2329 ctx
->API
== API_OPENGL_CORE
) {
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 (_mesa_has_ARB_texture_stencil8(ctx
) ||
2345 _mesa_has_OES_texture_stencil8(ctx
)) {
2346 switch (internalFormat
) {
2347 case GL_STENCIL_INDEX
:
2348 case GL_STENCIL_INDEX1
:
2349 case GL_STENCIL_INDEX4
:
2350 case GL_STENCIL_INDEX8
:
2351 case GL_STENCIL_INDEX16
:
2352 return GL_STENCIL_INDEX
;
2358 switch (internalFormat
) {
2359 case GL_COMPRESSED_ALPHA
:
2361 case GL_COMPRESSED_LUMINANCE
:
2362 return GL_LUMINANCE
;
2363 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2364 return GL_LUMINANCE_ALPHA
;
2365 case GL_COMPRESSED_INTENSITY
:
2366 return GL_INTENSITY
;
2367 case GL_COMPRESSED_RGB
:
2369 case GL_COMPRESSED_RGBA
:
2375 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2376 GLenum base_compressed
=
2377 _mesa_gl_compressed_format_base_format(internalFormat
);
2378 if (base_compressed
)
2379 return base_compressed
;
2382 if ((_mesa_has_KHR_texture_compression_astc_ldr(ctx
) &&
2383 is_astc_2d_format(internalFormat
)) ||
2384 (_mesa_has_OES_texture_compression_astc(ctx
) &&
2385 is_astc_3d_format(internalFormat
)))
2388 if (!_mesa_has_MESA_ycbcr_texture(ctx
)) {
2389 if (internalFormat
== GL_YCBCR_MESA
)
2390 return GL_YCBCR_MESA
;
2393 if (_mesa_has_half_float_textures(ctx
)) {
2394 switch (internalFormat
) {
2395 case GL_ALPHA16F_ARB
:
2397 case GL_RGBA16F_ARB
:
2401 case GL_INTENSITY16F_ARB
:
2402 return GL_INTENSITY
;
2403 case GL_LUMINANCE16F_ARB
:
2404 return GL_LUMINANCE
;
2405 case GL_LUMINANCE_ALPHA16F_ARB
:
2406 return GL_LUMINANCE_ALPHA
;
2410 if (_mesa_has_float_textures(ctx
)) {
2411 switch (internalFormat
) {
2412 case GL_ALPHA32F_ARB
:
2414 case GL_RGBA32F_ARB
:
2418 case GL_INTENSITY32F_ARB
:
2419 return GL_INTENSITY
;
2420 case GL_LUMINANCE32F_ARB
:
2421 return GL_LUMINANCE
;
2422 case GL_LUMINANCE_ALPHA32F_ARB
:
2423 return GL_LUMINANCE_ALPHA
;
2427 if (_mesa_has_EXT_texture_snorm(ctx
) || _mesa_is_gles3(ctx
)) {
2428 switch (internalFormat
) {
2439 case GL_RGB16_SNORM
:
2442 case GL_RGBA8_SNORM
:
2443 case GL_RGBA16_SNORM
:
2445 case GL_ALPHA_SNORM
:
2446 case GL_ALPHA8_SNORM
:
2447 case GL_ALPHA16_SNORM
:
2449 case GL_LUMINANCE_SNORM
:
2450 case GL_LUMINANCE8_SNORM
:
2451 case GL_LUMINANCE16_SNORM
:
2452 return GL_LUMINANCE
;
2453 case GL_LUMINANCE_ALPHA_SNORM
:
2454 case GL_LUMINANCE8_ALPHA8_SNORM
:
2455 case GL_LUMINANCE16_ALPHA16_SNORM
:
2456 return GL_LUMINANCE_ALPHA
;
2457 case GL_INTENSITY_SNORM
:
2458 case GL_INTENSITY8_SNORM
:
2459 case GL_INTENSITY16_SNORM
:
2460 return GL_INTENSITY
;
2466 if (_mesa_has_EXT_texture_sRGB(ctx
) || _mesa_is_gles3(ctx
)) {
2467 switch (internalFormat
) {
2470 case GL_COMPRESSED_SRGB_EXT
:
2472 case GL_SRGB_ALPHA_EXT
:
2473 case GL_SRGB8_ALPHA8_EXT
:
2474 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2476 case GL_SLUMINANCE_ALPHA_EXT
:
2477 case GL_SLUMINANCE8_ALPHA8_EXT
:
2478 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2479 return GL_LUMINANCE_ALPHA
;
2480 case GL_SLUMINANCE_EXT
:
2481 case GL_SLUMINANCE8_EXT
:
2482 case GL_COMPRESSED_SLUMINANCE_EXT
:
2483 return GL_LUMINANCE
;
2489 if (_mesa_has_EXT_texture_sRGB_R8(ctx
)) {
2490 switch (internalFormat
) {
2498 if (_mesa_has_integer_textures(ctx
)) {
2499 switch (internalFormat
) {
2500 case GL_RGBA8UI_EXT
:
2501 case GL_RGBA16UI_EXT
:
2502 case GL_RGBA32UI_EXT
:
2504 case GL_RGBA16I_EXT
:
2505 case GL_RGBA32I_EXT
:
2508 case GL_RGB16UI_EXT
:
2509 case GL_RGB32UI_EXT
:
2517 if (_mesa_has_texture_rgb10_a2ui(ctx
)) {
2518 switch (internalFormat
) {
2524 if (_mesa_has_integer_textures(ctx
)) {
2525 switch (internalFormat
) {
2526 case GL_ALPHA8UI_EXT
:
2527 case GL_ALPHA16UI_EXT
:
2528 case GL_ALPHA32UI_EXT
:
2529 case GL_ALPHA8I_EXT
:
2530 case GL_ALPHA16I_EXT
:
2531 case GL_ALPHA32I_EXT
:
2533 case GL_INTENSITY8UI_EXT
:
2534 case GL_INTENSITY16UI_EXT
:
2535 case GL_INTENSITY32UI_EXT
:
2536 case GL_INTENSITY8I_EXT
:
2537 case GL_INTENSITY16I_EXT
:
2538 case GL_INTENSITY32I_EXT
:
2539 return GL_INTENSITY
;
2540 case GL_LUMINANCE8UI_EXT
:
2541 case GL_LUMINANCE16UI_EXT
:
2542 case GL_LUMINANCE32UI_EXT
:
2543 case GL_LUMINANCE8I_EXT
:
2544 case GL_LUMINANCE16I_EXT
:
2545 case GL_LUMINANCE32I_EXT
:
2546 return GL_LUMINANCE
;
2547 case GL_LUMINANCE_ALPHA8UI_EXT
:
2548 case GL_LUMINANCE_ALPHA16UI_EXT
:
2549 case GL_LUMINANCE_ALPHA32UI_EXT
:
2550 case GL_LUMINANCE_ALPHA8I_EXT
:
2551 case GL_LUMINANCE_ALPHA16I_EXT
:
2552 case GL_LUMINANCE_ALPHA32I_EXT
:
2553 return GL_LUMINANCE_ALPHA
;
2559 if (_mesa_has_rg_textures(ctx
)) {
2560 switch (internalFormat
) {
2562 if (!_mesa_has_half_float_textures(ctx
))
2566 if (!_mesa_has_float_textures(ctx
))
2575 if (!_mesa_has_integer_textures(ctx
))
2581 case GL_COMPRESSED_RED
:
2585 if (!_mesa_has_half_float_textures(ctx
))
2589 if (!_mesa_has_float_textures(ctx
))
2598 if (!_mesa_has_integer_textures(ctx
))
2604 case GL_COMPRESSED_RG
:
2611 if (_mesa_has_texture_shared_exponent(ctx
)) {
2612 switch (internalFormat
) {
2613 case GL_RGB9_E5_EXT
:
2620 if (_mesa_has_packed_float(ctx
)) {
2621 switch (internalFormat
) {
2622 case GL_R11F_G11F_B10F_EXT
:
2629 if (_mesa_has_float_depth_buffer(ctx
)) {
2630 switch (internalFormat
) {
2631 case GL_DEPTH_COMPONENT32F
:
2632 return GL_DEPTH_COMPONENT
;
2633 case GL_DEPTH32F_STENCIL8
:
2634 return GL_DEPTH_STENCIL
;
2640 return -1; /* error */
2644 * Returns the effective internal format from a texture format and type.
2645 * This is used by texture image operations internally for validation, when
2646 * the specified internal format is a base (unsized) format.
2648 * This method will only return a valid effective internal format if the
2649 * combination of format, type and internal format in base form, is acceptable.
2651 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2652 * in extensions, to unambiguously correspond to the given base format, then
2653 * that internal format is returned as the effective. Otherwise, if the
2654 * combination is accepted but a single effective format is not defined, the
2655 * passed base format will be returned instead.
2657 * \param format the texture format
2658 * \param type the texture type
2661 gles_effective_internal_format_for_format_and_type(GLenum format
,
2665 case GL_UNSIGNED_BYTE
:
2675 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2676 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2677 * internal formats, they do not correspond to GL constants, so the base
2678 * format is returned instead.
2681 case GL_LUMINANCE_ALPHA
:
2688 case GL_UNSIGNED_SHORT_4_4_4_4
:
2689 if (format
== GL_RGBA
)
2693 case GL_UNSIGNED_SHORT_5_5_5_1
:
2694 if (format
== GL_RGBA
)
2698 case GL_UNSIGNED_SHORT_5_6_5
:
2699 if (format
== GL_RGB
)
2703 /* OES_packed_depth_stencil */
2704 case GL_UNSIGNED_INT_24_8
:
2705 if (format
== GL_DEPTH_STENCIL
)
2706 return GL_DEPTH24_STENCIL8
;
2709 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2710 if (format
== GL_DEPTH_STENCIL
)
2711 return GL_DEPTH32F_STENCIL8
;
2714 case GL_UNSIGNED_SHORT
:
2715 if (format
== GL_DEPTH_COMPONENT
)
2716 return GL_DEPTH_COMPONENT16
;
2719 case GL_UNSIGNED_INT
:
2720 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2723 if (format
== GL_DEPTH_COMPONENT
)
2727 /* OES_texture_float and OES_texture_half_float */
2729 if (format
== GL_DEPTH_COMPONENT
)
2730 return GL_DEPTH_COMPONENT32F
;
2732 case GL_HALF_FLOAT_OES
:
2736 case GL_LUMINANCE_ALPHA
:
2752 /* GL_EXT_texture_type_2_10_10_10_REV */
2753 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2762 /* fall through and return NONE */
2770 * Do error checking of format/type combinations for OpenGL ES 3
2771 * glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat.
2772 * \return error code, or GL_NO_ERROR.
2775 _mesa_gles_error_check_format_and_type(const struct gl_context
*ctx
,
2776 GLenum format
, GLenum type
,
2777 GLenum internalFormat
)
2779 /* If internalFormat is an unsized format, then the effective internal
2780 * format derived from format and type should be used instead. Page 127,
2781 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2783 * "if internalformat is a base internal format, the effective
2784 * internal format is a sized internal format that is derived
2785 * from the format and type for internal use by the GL.
2786 * Table 3.12 specifies the mapping of format and type to effective
2787 * internal formats. The effective internal format is used by the GL
2788 * for purposes such as texture completeness or type checks for
2789 * CopyTex* commands. In these cases, the GL is required to operate
2790 * as if the effective internal format was used as the internalformat
2791 * when specifying the texture data."
2793 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2794 GLenum effectiveInternalFormat
=
2795 gles_effective_internal_format_for_format_and_type(format
, type
);
2797 if (effectiveInternalFormat
== GL_NONE
)
2798 return GL_INVALID_OPERATION
;
2800 GLenum baseInternalFormat
;
2801 if (internalFormat
== GL_BGRA_EXT
) {
2802 /* Unfortunately, _mesa_base_tex_format returns a base format of
2803 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2804 * asking the question, "what channels does this format have?"
2805 * However, if we're trying to determine if two internal formats
2806 * match in the ES3 sense, we actually want GL_BGRA.
2808 baseInternalFormat
= GL_BGRA_EXT
;
2810 baseInternalFormat
=
2811 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2814 if (internalFormat
!= baseInternalFormat
)
2815 return GL_INVALID_OPERATION
;
2817 internalFormat
= effectiveInternalFormat
;
2820 /* The GLES variant of EXT_texture_compression_s3tc is very vague and
2821 * doesn't list valid types. Just do exactly what the spec says.
2823 if (_mesa_has_EXT_texture_compression_s3tc(ctx
) &&
2824 (internalFormat
== GL_COMPRESSED_RGB_S3TC_DXT1_EXT
||
2825 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
||
2826 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
||
2827 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
))
2828 return format
== GL_RGB
|| format
== GL_RGBA
? GL_NO_ERROR
:
2829 GL_INVALID_OPERATION
;
2833 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2834 return GL_INVALID_OPERATION
;
2839 case GL_UNSIGNED_BYTE
:
2840 switch (internalFormat
) {
2846 case GL_SRGB8_ALPHA8_EXT
:
2847 if (ctx
->Version
<= 20)
2848 return GL_INVALID_OPERATION
;
2850 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
2851 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
2852 if (!_mesa_has_EXT_texture_compression_bptc(ctx
))
2853 return GL_INVALID_OPERATION
;
2856 return GL_INVALID_OPERATION
;
2861 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA8_SNORM
)
2862 return GL_INVALID_OPERATION
;
2865 case GL_UNSIGNED_SHORT
:
2866 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGBA16
)
2867 return GL_INVALID_OPERATION
;
2871 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2872 internalFormat
!= GL_RGBA16_SNORM
)
2873 return GL_INVALID_OPERATION
;
2876 case GL_UNSIGNED_SHORT_4_4_4_4
:
2877 switch (internalFormat
) {
2882 return GL_INVALID_OPERATION
;
2886 case GL_UNSIGNED_SHORT_5_5_5_1
:
2887 switch (internalFormat
) {
2892 return GL_INVALID_OPERATION
;
2896 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2897 switch (internalFormat
) {
2901 if (!_mesa_has_texture_type_2_10_10_10_REV(ctx
))
2902 return GL_INVALID_OPERATION
;
2905 return GL_INVALID_OPERATION
;
2910 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA16F
)
2911 return GL_INVALID_OPERATION
;
2915 switch (internalFormat
) {
2918 if (ctx
->Version
<= 20)
2919 return GL_INVALID_OPERATION
;
2922 if (_mesa_has_OES_texture_float(ctx
) && internalFormat
== format
)
2925 return GL_INVALID_OPERATION
;
2929 case GL_HALF_FLOAT_OES
:
2930 if (_mesa_has_OES_texture_half_float(ctx
) && internalFormat
== format
)
2933 return GL_INVALID_OPERATION
;
2937 case GL_RGBA_INTEGER
:
2938 if (ctx
->Version
<= 20)
2939 return GL_INVALID_OPERATION
;
2941 case GL_UNSIGNED_BYTE
:
2942 if (internalFormat
!= GL_RGBA8UI
)
2943 return GL_INVALID_OPERATION
;
2947 if (internalFormat
!= GL_RGBA8I
)
2948 return GL_INVALID_OPERATION
;
2951 case GL_UNSIGNED_SHORT
:
2952 if (internalFormat
!= GL_RGBA16UI
)
2953 return GL_INVALID_OPERATION
;
2957 if (internalFormat
!= GL_RGBA16I
)
2958 return GL_INVALID_OPERATION
;
2961 case GL_UNSIGNED_INT
:
2962 if (internalFormat
!= GL_RGBA32UI
)
2963 return GL_INVALID_OPERATION
;
2967 if (internalFormat
!= GL_RGBA32I
)
2968 return GL_INVALID_OPERATION
;
2971 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2972 if (internalFormat
!= GL_RGB10_A2UI
)
2973 return GL_INVALID_OPERATION
;
2977 return GL_INVALID_OPERATION
;
2983 case GL_UNSIGNED_BYTE
:
2984 switch (internalFormat
) {
2990 if (ctx
->Version
<= 20)
2991 return GL_INVALID_OPERATION
;
2994 return GL_INVALID_OPERATION
;
2999 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB8_SNORM
)
3000 return GL_INVALID_OPERATION
;
3003 case GL_UNSIGNED_SHORT
:
3004 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGB16
)
3005 return GL_INVALID_OPERATION
;
3009 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3010 internalFormat
!= GL_RGB16_SNORM
)
3011 return GL_INVALID_OPERATION
;
3014 case GL_UNSIGNED_SHORT_5_6_5
:
3015 switch (internalFormat
) {
3020 return GL_INVALID_OPERATION
;
3024 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3025 if (ctx
->Version
<= 20 || internalFormat
!= GL_R11F_G11F_B10F
)
3026 return GL_INVALID_OPERATION
;
3029 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3030 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB9_E5
)
3031 return GL_INVALID_OPERATION
;
3035 if (ctx
->Version
<= 20)
3036 return GL_INVALID_OPERATION
;
3037 switch (internalFormat
) {
3039 case GL_R11F_G11F_B10F
:
3043 return GL_INVALID_OPERATION
;
3048 switch (internalFormat
) {
3051 case GL_R11F_G11F_B10F
:
3053 if (ctx
->Version
<= 20)
3054 return GL_INVALID_OPERATION
;
3057 if (_mesa_has_OES_texture_float(ctx
) && internalFormat
== format
)
3059 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
3060 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
3061 if (!_mesa_has_EXT_texture_compression_bptc(ctx
))
3062 return GL_INVALID_OPERATION
;
3065 return GL_INVALID_OPERATION
;
3069 case GL_HALF_FLOAT_OES
:
3070 if (!_mesa_has_OES_texture_half_float(ctx
) || internalFormat
!= format
)
3071 return GL_INVALID_OPERATION
;
3074 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3075 switch (internalFormat
) {
3080 /* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though
3081 * GLES3 doesn't, and GL_OES_required_internalformat extends that
3082 * to allow the sized RGB internalformats as well.
3084 if (!_mesa_has_texture_type_2_10_10_10_REV(ctx
))
3085 return GL_INVALID_OPERATION
;
3088 return GL_INVALID_OPERATION
;
3093 return GL_INVALID_OPERATION
;
3097 case GL_RGB_INTEGER
:
3098 if (ctx
->Version
<= 20)
3099 return GL_INVALID_OPERATION
;
3101 case GL_UNSIGNED_BYTE
:
3102 if (internalFormat
!= GL_RGB8UI
)
3103 return GL_INVALID_OPERATION
;
3107 if (internalFormat
!= GL_RGB8I
)
3108 return GL_INVALID_OPERATION
;
3111 case GL_UNSIGNED_SHORT
:
3112 if (internalFormat
!= GL_RGB16UI
)
3113 return GL_INVALID_OPERATION
;
3117 if (internalFormat
!= GL_RGB16I
)
3118 return GL_INVALID_OPERATION
;
3121 case GL_UNSIGNED_INT
:
3122 if (internalFormat
!= GL_RGB32UI
)
3123 return GL_INVALID_OPERATION
;
3127 if (internalFormat
!= GL_RGB32I
)
3128 return GL_INVALID_OPERATION
;
3132 return GL_INVALID_OPERATION
;
3137 if (!_mesa_has_rg_textures(ctx
))
3138 return GL_INVALID_OPERATION
;
3140 case GL_UNSIGNED_BYTE
:
3141 if (internalFormat
!= GL_RG8
&&
3142 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3143 internalFormat
!= GL_COMPRESSED_RED_GREEN_RGTC2_EXT
))
3144 return GL_INVALID_OPERATION
;
3148 if (internalFormat
!= GL_RG8_SNORM
&&
3149 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3150 internalFormat
!= GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
))
3151 return GL_INVALID_OPERATION
;
3154 case GL_UNSIGNED_SHORT
:
3155 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RG16
)
3156 return GL_INVALID_OPERATION
;
3160 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3161 internalFormat
!= GL_RG16_SNORM
)
3162 return GL_INVALID_OPERATION
;
3166 case GL_HALF_FLOAT_OES
:
3167 switch (internalFormat
) {
3169 if (ctx
->Version
<= 20)
3170 return GL_INVALID_OPERATION
;
3173 if (_mesa_has_rg_textures(ctx
) &&
3174 _mesa_has_OES_texture_half_float(ctx
))
3178 return GL_INVALID_OPERATION
;
3183 switch (internalFormat
) {
3188 if (_mesa_has_rg_textures(ctx
) &&
3189 _mesa_has_OES_texture_float(ctx
))
3193 return GL_INVALID_OPERATION
;
3198 return GL_INVALID_OPERATION
;
3203 if (ctx
->Version
<= 20)
3204 return GL_INVALID_OPERATION
;
3206 case GL_UNSIGNED_BYTE
:
3207 if (internalFormat
!= GL_RG8UI
)
3208 return GL_INVALID_OPERATION
;
3212 if (internalFormat
!= GL_RG8I
)
3213 return GL_INVALID_OPERATION
;
3216 case GL_UNSIGNED_SHORT
:
3217 if (internalFormat
!= GL_RG16UI
)
3218 return GL_INVALID_OPERATION
;
3222 if (internalFormat
!= GL_RG16I
)
3223 return GL_INVALID_OPERATION
;
3226 case GL_UNSIGNED_INT
:
3227 if (internalFormat
!= GL_RG32UI
)
3228 return GL_INVALID_OPERATION
;
3232 if (internalFormat
!= GL_RG32I
)
3233 return GL_INVALID_OPERATION
;
3237 return GL_INVALID_OPERATION
;
3242 if (!_mesa_has_rg_textures(ctx
))
3243 return GL_INVALID_OPERATION
;
3245 case GL_UNSIGNED_BYTE
:
3246 if (internalFormat
== GL_R8
||
3247 ((internalFormat
== GL_SR8_EXT
) &&
3248 _mesa_has_EXT_texture_sRGB_R8(ctx
)) ||
3249 (internalFormat
== GL_COMPRESSED_RED_RGTC1_EXT
&&
3250 _mesa_has_EXT_texture_compression_rgtc(ctx
)))
3252 return GL_INVALID_OPERATION
;
3255 if (internalFormat
!= GL_R8_SNORM
&&
3256 (!_mesa_has_EXT_texture_compression_rgtc(ctx
) ||
3257 internalFormat
!= GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
))
3258 return GL_INVALID_OPERATION
;
3261 case GL_UNSIGNED_SHORT
:
3262 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_R16
)
3263 return GL_INVALID_OPERATION
;
3267 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3268 internalFormat
!= GL_R16_SNORM
)
3269 return GL_INVALID_OPERATION
;
3273 case GL_HALF_FLOAT_OES
:
3274 switch (internalFormat
) {
3276 if (ctx
->Version
<= 20)
3277 return GL_INVALID_OPERATION
;
3281 if (_mesa_has_rg_textures(ctx
) &&
3282 _mesa_has_OES_texture_half_float(ctx
))
3286 return GL_INVALID_OPERATION
;
3291 switch (internalFormat
) {
3296 if (_mesa_has_rg_textures(ctx
) &&
3297 _mesa_has_OES_texture_float(ctx
))
3301 return GL_INVALID_OPERATION
;
3306 return GL_INVALID_OPERATION
;
3310 case GL_RED_INTEGER
:
3311 if (ctx
->Version
<= 20)
3312 return GL_INVALID_OPERATION
;
3314 case GL_UNSIGNED_BYTE
:
3315 if (internalFormat
!= GL_R8UI
)
3316 return GL_INVALID_OPERATION
;
3320 if (internalFormat
!= GL_R8I
)
3321 return GL_INVALID_OPERATION
;
3324 case GL_UNSIGNED_SHORT
:
3325 if (internalFormat
!= GL_R16UI
)
3326 return GL_INVALID_OPERATION
;
3330 if (internalFormat
!= GL_R16I
)
3331 return GL_INVALID_OPERATION
;
3334 case GL_UNSIGNED_INT
:
3335 if (internalFormat
!= GL_R32UI
)
3336 return GL_INVALID_OPERATION
;
3340 if (internalFormat
!= GL_R32I
)
3341 return GL_INVALID_OPERATION
;
3345 return GL_INVALID_OPERATION
;
3349 case GL_DEPTH_COMPONENT
:
3351 case GL_UNSIGNED_SHORT
:
3352 if (internalFormat
!= GL_DEPTH_COMPONENT
3353 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3354 return GL_INVALID_OPERATION
;
3357 case GL_UNSIGNED_INT
:
3358 switch (internalFormat
) {
3359 case GL_DEPTH_COMPONENT
:
3360 case GL_DEPTH_COMPONENT16
:
3361 case GL_DEPTH_COMPONENT24
:
3364 return GL_INVALID_OPERATION
;
3369 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH_COMPONENT32F
)
3370 return GL_INVALID_OPERATION
;
3374 return GL_INVALID_OPERATION
;
3378 case GL_DEPTH_STENCIL
:
3380 case GL_UNSIGNED_INT_24_8
:
3381 if (internalFormat
!= GL_DEPTH_STENCIL
3382 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3383 return GL_INVALID_OPERATION
;
3386 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3387 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH32F_STENCIL8
)
3388 return GL_INVALID_OPERATION
;
3392 return GL_INVALID_OPERATION
;
3396 case GL_STENCIL_INDEX
:
3397 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3398 type
!= GL_UNSIGNED_BYTE
||
3399 internalFormat
!= GL_STENCIL_INDEX8
) {
3400 return GL_INVALID_OPERATION
;
3406 case GL_LUMINANCE_ALPHA
:
3409 if (!_mesa_has_OES_texture_float(ctx
) || internalFormat
!= format
)
3410 return GL_INVALID_OPERATION
;
3412 case GL_HALF_FLOAT_OES
:
3413 if (!_mesa_has_OES_texture_half_float(ctx
) || internalFormat
!= format
)
3414 return GL_INVALID_OPERATION
;
3416 case GL_UNSIGNED_BYTE
:
3417 if (!(format
== internalFormat
||
3418 (format
== GL_ALPHA
&& internalFormat
== GL_ALPHA8
) ||
3419 (format
== GL_LUMINANCE
&& internalFormat
== GL_LUMINANCE8
) ||
3420 (format
== GL_LUMINANCE_ALPHA
&&
3421 ((internalFormat
== GL_LUMINANCE8_ALPHA8
) ||
3422 (internalFormat
== GL_LUMINANCE4_ALPHA4
))))) {
3423 return GL_INVALID_OPERATION
;
3427 return GL_INVALID_OPERATION
;
3436 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3438 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3439 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3440 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3441 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3445 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3449 case GL_RGBA_INTEGER_EXT
:
3450 set_swizzle(swizzle
, 0, 1, 2, 3);
3453 case GL_BGRA_INTEGER_EXT
:
3454 set_swizzle(swizzle
, 2, 1, 0, 3);
3457 set_swizzle(swizzle
, 3, 2, 1, 0);
3460 case GL_RGB_INTEGER_EXT
:
3461 set_swizzle(swizzle
, 0, 1, 2, 5);
3464 case GL_BGR_INTEGER_EXT
:
3465 set_swizzle(swizzle
, 2, 1, 0, 5);
3467 case GL_LUMINANCE_ALPHA
:
3468 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3469 set_swizzle(swizzle
, 0, 0, 0, 1);
3473 set_swizzle(swizzle
, 0, 1, 4, 5);
3476 case GL_RED_INTEGER_EXT
:
3477 set_swizzle(swizzle
, 0, 4, 4, 5);
3480 case GL_GREEN_INTEGER_EXT
:
3481 set_swizzle(swizzle
, 4, 0, 4, 5);
3484 case GL_BLUE_INTEGER_EXT
:
3485 set_swizzle(swizzle
, 4, 4, 0, 5);
3488 case GL_ALPHA_INTEGER_EXT
:
3489 set_swizzle(swizzle
, 4, 4, 4, 0);
3492 case GL_LUMINANCE_INTEGER_EXT
:
3493 set_swizzle(swizzle
, 0, 0, 0, 5);
3496 set_swizzle(swizzle
, 0, 0, 0, 0);
3504 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3505 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3506 * otherwise (for non-array formats).
3508 * This function will typically be used to compute a mesa format from a GL type
3509 * so we can then call _mesa_format_convert. This function does
3510 * not consider byte swapping, so it returns types assuming that no byte
3511 * swapping is involved. If byte swapping is involved then clients are supposed
3512 * to handle that on their side before calling _mesa_format_convert.
3514 * This function returns an uint32_t that can pack a mesa_format or a
3515 * mesa_array_format. Clients must check the mesa array format bit
3516 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3517 * format is a mesa_array_format or a mesa_format.
3520 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3522 bool is_array_format
= true;
3524 bool normalized
= false, is_float
= false, is_signed
= false;
3525 int num_channels
= 0, type_size
= 0;
3527 /* Extract array format type information from the OpenGL data type */
3529 case GL_UNSIGNED_BYTE
:
3536 case GL_UNSIGNED_SHORT
:
3543 case GL_UNSIGNED_INT
:
3551 case GL_HALF_FLOAT_OES
:
3562 is_array_format
= false;
3566 /* Extract array format swizzle information from the OpenGL format */
3567 if (is_array_format
)
3568 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3570 /* If this is an array format type after checking data type and format,
3571 * create the array format
3573 if (is_array_format
) {
3574 normalized
= !_mesa_is_enum_format_integer(format
);
3575 num_channels
= _mesa_components_in_format(format
);
3577 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3578 normalized
, num_channels
,
3579 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3582 /* Otherwise this is not an array format, so return the mesa_format
3583 * matching the OpenGL format and data type
3586 case GL_UNSIGNED_SHORT_5_6_5
:
3587 if (format
== GL_RGB
)
3588 return MESA_FORMAT_B5G6R5_UNORM
;
3589 else if (format
== GL_BGR
)
3590 return MESA_FORMAT_R5G6B5_UNORM
;
3591 else if (format
== GL_RGB_INTEGER
)
3592 return MESA_FORMAT_B5G6R5_UINT
;
3594 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3595 if (format
== GL_RGB
)
3596 return MESA_FORMAT_R5G6B5_UNORM
;
3597 else if (format
== GL_BGR
)
3598 return MESA_FORMAT_B5G6R5_UNORM
;
3599 else if (format
== GL_RGB_INTEGER
)
3600 return MESA_FORMAT_R5G6B5_UINT
;
3602 case GL_UNSIGNED_SHORT_4_4_4_4
:
3603 if (format
== GL_RGBA
)
3604 return MESA_FORMAT_A4B4G4R4_UNORM
;
3605 else if (format
== GL_BGRA
)
3606 return MESA_FORMAT_A4R4G4B4_UNORM
;
3607 else if (format
== GL_ABGR_EXT
)
3608 return MESA_FORMAT_R4G4B4A4_UNORM
;
3609 else if (format
== GL_RGBA_INTEGER
)
3610 return MESA_FORMAT_A4B4G4R4_UINT
;
3611 else if (format
== GL_BGRA_INTEGER
)
3612 return MESA_FORMAT_A4R4G4B4_UINT
;
3614 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3615 if (format
== GL_RGBA
)
3616 return MESA_FORMAT_R4G4B4A4_UNORM
;
3617 else if (format
== GL_BGRA
)
3618 return MESA_FORMAT_B4G4R4A4_UNORM
;
3619 else if (format
== GL_ABGR_EXT
)
3620 return MESA_FORMAT_A4B4G4R4_UNORM
;
3621 else if (format
== GL_RGBA_INTEGER
)
3622 return MESA_FORMAT_R4G4B4A4_UINT
;
3623 else if (format
== GL_BGRA_INTEGER
)
3624 return MESA_FORMAT_B4G4R4A4_UINT
;
3626 case GL_UNSIGNED_SHORT_5_5_5_1
:
3627 if (format
== GL_RGBA
)
3628 return MESA_FORMAT_A1B5G5R5_UNORM
;
3629 else if (format
== GL_BGRA
)
3630 return MESA_FORMAT_A1R5G5B5_UNORM
;
3631 else if (format
== GL_RGBA_INTEGER
)
3632 return MESA_FORMAT_A1B5G5R5_UINT
;
3633 else if (format
== GL_BGRA_INTEGER
)
3634 return MESA_FORMAT_A1R5G5B5_UINT
;
3636 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3637 if (format
== GL_RGBA
)
3638 return MESA_FORMAT_R5G5B5A1_UNORM
;
3639 else if (format
== GL_BGRA
)
3640 return MESA_FORMAT_B5G5R5A1_UNORM
;
3641 else if (format
== GL_RGBA_INTEGER
)
3642 return MESA_FORMAT_R5G5B5A1_UINT
;
3643 else if (format
== GL_BGRA_INTEGER
)
3644 return MESA_FORMAT_B5G5R5A1_UINT
;
3646 case GL_UNSIGNED_BYTE_3_3_2
:
3647 if (format
== GL_RGB
)
3648 return MESA_FORMAT_B2G3R3_UNORM
;
3649 else if (format
== GL_RGB_INTEGER
)
3650 return MESA_FORMAT_B2G3R3_UINT
;
3652 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3653 if (format
== GL_RGB
)
3654 return MESA_FORMAT_R3G3B2_UNORM
;
3655 else if (format
== GL_RGB_INTEGER
)
3656 return MESA_FORMAT_R3G3B2_UINT
;
3658 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3659 if (format
== GL_RGB
)
3660 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3662 case GL_UNSIGNED_INT_10_10_10_2
:
3663 if (format
== GL_RGBA
)
3664 return MESA_FORMAT_A2B10G10R10_UNORM
;
3665 else if (format
== GL_RGBA_INTEGER
)
3666 return MESA_FORMAT_A2B10G10R10_UINT
;
3667 else if (format
== GL_BGRA
)
3668 return MESA_FORMAT_A2R10G10B10_UNORM
;
3669 else if (format
== GL_BGRA_INTEGER
)
3670 return MESA_FORMAT_A2R10G10B10_UINT
;
3672 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3673 if (format
== GL_RGB
)
3674 return MESA_FORMAT_R10G10B10X2_UNORM
;
3675 if (format
== GL_RGBA
)
3676 return MESA_FORMAT_R10G10B10A2_UNORM
;
3677 else if (format
== GL_RGBA_INTEGER
)
3678 return MESA_FORMAT_R10G10B10A2_UINT
;
3679 else if (format
== GL_BGRA
)
3680 return MESA_FORMAT_B10G10R10A2_UNORM
;
3681 else if (format
== GL_BGRA_INTEGER
)
3682 return MESA_FORMAT_B10G10R10A2_UINT
;
3684 case GL_UNSIGNED_INT_8_8_8_8
:
3685 if (format
== GL_RGBA
)
3686 return MESA_FORMAT_A8B8G8R8_UNORM
;
3687 else if (format
== GL_BGRA
)
3688 return MESA_FORMAT_A8R8G8B8_UNORM
;
3689 else if (format
== GL_ABGR_EXT
)
3690 return MESA_FORMAT_R8G8B8A8_UNORM
;
3691 else if (format
== GL_RGBA_INTEGER
)
3692 return MESA_FORMAT_A8B8G8R8_UINT
;
3693 else if (format
== GL_BGRA_INTEGER
)
3694 return MESA_FORMAT_A8R8G8B8_UINT
;
3696 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3697 if (format
== GL_RGBA
)
3698 return MESA_FORMAT_R8G8B8A8_UNORM
;
3699 else if (format
== GL_BGRA
)
3700 return MESA_FORMAT_B8G8R8A8_UNORM
;
3701 else if (format
== GL_ABGR_EXT
)
3702 return MESA_FORMAT_A8B8G8R8_UNORM
;
3703 else if (format
== GL_RGBA_INTEGER
)
3704 return MESA_FORMAT_R8G8B8A8_UINT
;
3705 else if (format
== GL_BGRA_INTEGER
)
3706 return MESA_FORMAT_B8G8R8A8_UINT
;
3708 case GL_UNSIGNED_SHORT_8_8_MESA
:
3709 if (format
== GL_YCBCR_MESA
)
3710 return MESA_FORMAT_YCBCR
;
3712 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3713 if (format
== GL_YCBCR_MESA
)
3714 return MESA_FORMAT_YCBCR_REV
;
3716 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3717 if (format
== GL_RGB
)
3718 return MESA_FORMAT_R11G11B10_FLOAT
;
3721 if (format
== GL_DEPTH_COMPONENT
)
3722 return MESA_FORMAT_Z_FLOAT32
;
3724 case GL_UNSIGNED_INT
:
3725 if (format
== GL_DEPTH_COMPONENT
)
3726 return MESA_FORMAT_Z_UNORM32
;
3728 case GL_UNSIGNED_SHORT
:
3729 if (format
== GL_DEPTH_COMPONENT
)
3730 return MESA_FORMAT_Z_UNORM16
;
3732 case GL_UNSIGNED_INT_24_8
:
3733 if (format
== GL_DEPTH_STENCIL
)
3734 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3736 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3737 if (format
== GL_DEPTH_STENCIL
)
3738 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3744 /* If we got here it means that we could not find a Mesa format that
3745 * matches the GL format/type provided. We may need to add a new Mesa
3746 * format in that case.
3748 unreachable("Unsupported format");
3752 _mesa_tex_format_from_format_and_type(const struct gl_context
*ctx
,
3753 GLenum gl_format
, GLenum type
)
3755 mesa_format format
= _mesa_format_from_format_and_type(gl_format
, type
);
3757 if (_mesa_format_is_mesa_array_format(format
))
3758 format
= _mesa_format_from_array_format(format
);
3760 if (format
== MESA_FORMAT_NONE
|| !ctx
->TextureFormatSupported
[format
])
3761 return MESA_FORMAT_NONE
;
3767 * Returns true if \p internal_format is a sized internal format that
3768 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3771 _mesa_is_es3_color_renderable(const struct gl_context
*ctx
,
3772 GLenum internal_format
)
3774 switch (internal_format
) {
3784 case GL_SRGB8_ALPHA8
:
3791 case GL_R11F_G11F_B10F
:
3814 return _mesa_has_EXT_texture_norm16(ctx
);
3817 case GL_RGBA8_SNORM
:
3818 return _mesa_has_EXT_render_snorm(ctx
);
3821 case GL_RGBA16_SNORM
:
3822 return _mesa_has_EXT_texture_norm16(ctx
) &&
3823 _mesa_has_EXT_render_snorm(ctx
);
3830 * Returns true if \p internal_format is a sized internal format that
3831 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3834 _mesa_is_es3_texture_filterable(const struct gl_context
*ctx
,
3835 GLenum internal_format
)
3837 switch (internal_format
) {
3848 case GL_RGBA8_SNORM
:
3851 case GL_SRGB8_ALPHA8
:
3856 case GL_R11F_G11F_B10F
:
3864 case GL_RGB16_SNORM
:
3866 case GL_RGBA16_SNORM
:
3867 return _mesa_has_EXT_texture_norm16(ctx
);
3872 /* The OES_texture_float_linear spec says:
3874 * "When implemented against OpenGL ES 3.0 or later versions, sized
3875 * 32-bit floating-point formats become texture-filterable. This
3876 * should be noted by, for example, checking the ``TF'' column of
3877 * table 8.13 in the ES 3.1 Specification (``Correspondence of sized
3878 * internal formats to base internal formats ... and use cases ...'')
3879 * for the R32F, RG32F, RGB32F, and RGBA32F formats."
3881 return _mesa_has_OES_texture_float_linear(ctx
);