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 case MESA_FORMAT_LAYOUT_LATC
:
1384 return _mesa_has_EXT_texture_compression_latc(ctx
);
1385 case MESA_FORMAT_LAYOUT_ETC1
:
1386 return _mesa_has_OES_compressed_ETC1_RGB8_texture(ctx
);
1387 case MESA_FORMAT_LAYOUT_ETC2
:
1388 return _mesa_is_gles3(ctx
) || _mesa_has_ARB_ES3_compatibility(ctx
);
1389 case MESA_FORMAT_LAYOUT_BPTC
:
1390 return _mesa_has_ARB_texture_compression_bptc(ctx
);
1391 case MESA_FORMAT_LAYOUT_ASTC
:
1392 return _mesa_has_KHR_texture_compression_astc_ldr(ctx
);
1399 * Test if the given format represents an sRGB format.
1400 * \param format the GL format (can be an internal format)
1401 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1404 _mesa_is_srgb_format(GLenum format
)
1410 case GL_SRGB8_ALPHA8
:
1411 case GL_COMPRESSED_SRGB
:
1412 case GL_COMPRESSED_SRGB_ALPHA
:
1413 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1414 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1415 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1416 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1417 case GL_COMPRESSED_SRGB8_ETC2
:
1418 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1419 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1420 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1421 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1422 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1423 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1424 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1425 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1426 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1427 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1428 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1429 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1430 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1431 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1432 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1444 * Convert various unpack formats to the corresponding base format.
1447 _mesa_unpack_format_to_base_format(GLenum format
)
1450 case GL_RED_INTEGER
:
1452 case GL_GREEN_INTEGER
:
1454 case GL_BLUE_INTEGER
:
1456 case GL_ALPHA_INTEGER
:
1460 case GL_RGB_INTEGER
:
1462 case GL_RGBA_INTEGER
:
1464 case GL_BGR_INTEGER
:
1466 case GL_BGRA_INTEGER
:
1468 case GL_LUMINANCE_INTEGER_EXT
:
1469 return GL_LUMINANCE
;
1470 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1471 return GL_LUMINANCE_ALPHA
;
1482 case GL_LUMINANCE_ALPHA
:
1489 * Convert various base formats to the corresponding integer format.
1492 _mesa_base_format_to_integer_format(GLenum format
)
1496 return GL_RED_INTEGER
;
1498 return GL_GREEN_INTEGER
;
1500 return GL_BLUE_INTEGER
;
1502 return GL_RG_INTEGER
;
1504 return GL_RGB_INTEGER
;
1506 return GL_RGBA_INTEGER
;
1508 return GL_BGR_INTEGER
;
1510 return GL_BGRA_INTEGER
;
1512 return GL_ALPHA_INTEGER
;
1514 return GL_LUMINANCE_INTEGER_EXT
;
1515 case GL_LUMINANCE_ALPHA
:
1516 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1524 * Does the given base texture/renderbuffer format have the channel
1528 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1531 case GL_TEXTURE_RED_SIZE
:
1532 case GL_TEXTURE_RED_TYPE
:
1533 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1534 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1535 case GL_INTERNALFORMAT_RED_SIZE
:
1536 case GL_INTERNALFORMAT_RED_TYPE
:
1537 if (base_format
== GL_RED
||
1538 base_format
== GL_RG
||
1539 base_format
== GL_RGB
||
1540 base_format
== GL_RGBA
) {
1544 case GL_TEXTURE_GREEN_SIZE
:
1545 case GL_TEXTURE_GREEN_TYPE
:
1546 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1547 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1548 case GL_INTERNALFORMAT_GREEN_SIZE
:
1549 case GL_INTERNALFORMAT_GREEN_TYPE
:
1550 if (base_format
== GL_RG
||
1551 base_format
== GL_RGB
||
1552 base_format
== GL_RGBA
) {
1556 case GL_TEXTURE_BLUE_SIZE
:
1557 case GL_TEXTURE_BLUE_TYPE
:
1558 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1559 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1560 case GL_INTERNALFORMAT_BLUE_SIZE
:
1561 case GL_INTERNALFORMAT_BLUE_TYPE
:
1562 if (base_format
== GL_RGB
||
1563 base_format
== GL_RGBA
) {
1567 case GL_TEXTURE_ALPHA_SIZE
:
1568 case GL_TEXTURE_ALPHA_TYPE
:
1569 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1570 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1571 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1572 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1573 if (base_format
== GL_RGBA
||
1574 base_format
== GL_ALPHA
||
1575 base_format
== GL_LUMINANCE_ALPHA
) {
1579 case GL_TEXTURE_LUMINANCE_SIZE
:
1580 case GL_TEXTURE_LUMINANCE_TYPE
:
1581 if (base_format
== GL_LUMINANCE
||
1582 base_format
== GL_LUMINANCE_ALPHA
) {
1586 case GL_TEXTURE_INTENSITY_SIZE
:
1587 case GL_TEXTURE_INTENSITY_TYPE
:
1588 if (base_format
== GL_INTENSITY
) {
1592 case GL_TEXTURE_DEPTH_SIZE
:
1593 case GL_TEXTURE_DEPTH_TYPE
:
1594 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1595 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1596 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1597 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1598 if (base_format
== GL_DEPTH_STENCIL
||
1599 base_format
== GL_DEPTH_COMPONENT
) {
1603 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1604 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1605 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1606 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1607 if (base_format
== GL_DEPTH_STENCIL
||
1608 base_format
== GL_STENCIL_INDEX
) {
1613 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1623 * If format is a generic compressed format, return the corresponding
1624 * non-compressed format. For other formats, return the format as-is.
1627 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1630 case GL_COMPRESSED_RED
:
1632 case GL_COMPRESSED_RG
:
1634 case GL_COMPRESSED_RGB
:
1636 case GL_COMPRESSED_RGBA
:
1638 case GL_COMPRESSED_ALPHA
:
1640 case GL_COMPRESSED_LUMINANCE
:
1641 return GL_LUMINANCE
;
1642 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1643 return GL_LUMINANCE_ALPHA
;
1644 case GL_COMPRESSED_INTENSITY
:
1645 return GL_INTENSITY
;
1647 case GL_COMPRESSED_SRGB
:
1649 case GL_COMPRESSED_SRGB_ALPHA
:
1650 return GL_SRGB_ALPHA
;
1651 case GL_COMPRESSED_SLUMINANCE
:
1652 return GL_SLUMINANCE
;
1653 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1654 return GL_SLUMINANCE_ALPHA
;
1662 * Return the equivalent non-generic internal format.
1663 * This is useful for comparing whether two internal formats are equivalent.
1666 _mesa_get_nongeneric_internalformat(GLenum format
)
1669 /* GL 1.1 formats. */
1677 case GL_LUMINANCE_ALPHA
:
1678 return GL_LUMINANCE8_ALPHA8
;
1681 return GL_LUMINANCE8
;
1685 return GL_INTENSITY8
;
1687 /* GL_ARB_texture_rg */
1693 /* GL_EXT_texture_sRGB */
1697 return GL_SRGB8_ALPHA8
;
1699 return GL_SLUMINANCE8
;
1700 case GL_SLUMINANCE_ALPHA
:
1701 return GL_SLUMINANCE8_ALPHA8
;
1703 /* GL_EXT_texture_snorm */
1705 return GL_RGBA8_SNORM
;
1707 return GL_RGB8_SNORM
;
1709 return GL_RG8_SNORM
;
1712 case GL_LUMINANCE_ALPHA_SNORM
:
1713 return GL_LUMINANCE8_ALPHA8_SNORM
;
1714 case GL_LUMINANCE_SNORM
:
1715 return GL_LUMINANCE8_SNORM
;
1716 case GL_ALPHA_SNORM
:
1717 return GL_ALPHA8_SNORM
;
1718 case GL_INTENSITY_SNORM
:
1719 return GL_INTENSITY8_SNORM
;
1728 * Convert an sRGB internal format to linear.
1731 _mesa_get_linear_internalformat(GLenum format
)
1740 case GL_SRGB8_ALPHA8
:
1742 case GL_SLUMINANCE8
:
1743 return GL_LUMINANCE8
;
1745 return GL_LUMINANCE
;
1746 case GL_SLUMINANCE_ALPHA
:
1747 return GL_LUMINANCE_ALPHA
;
1748 case GL_SLUMINANCE8_ALPHA8
:
1749 return GL_LUMINANCE8_ALPHA8
;
1757 * Do error checking of format/type combinations for glReadPixels,
1758 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1759 * and type values, we may either generate GL_INVALID_OPERATION or
1762 * \param format pixel format.
1763 * \param type pixel type.
1765 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1768 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1769 GLenum format
, GLenum type
)
1771 /* From OpenGL 3.3 spec, page 220:
1772 * "If the format is DEPTH_STENCIL, then values are taken from
1773 * both the depth buffer and the stencil buffer. If there is no
1774 * depth buffer or if there is no stencil buffer, then the error
1775 * INVALID_OPERATION occurs. If the type parameter is not
1776 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1777 * error INVALID_ENUM occurs."
1779 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1780 * cannot be used to read depth or stencil in that API.
1782 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1783 && type
!= GL_UNSIGNED_INT_24_8
1784 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1785 return GL_INVALID_ENUM
;
1787 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1790 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1791 return GL_INVALID_ENUM
;
1795 case GL_UNSIGNED_BYTE_3_3_2
:
1796 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1797 case GL_UNSIGNED_SHORT_5_6_5
:
1798 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1799 if (format
== GL_RGB
) {
1802 if (format
== GL_RGB_INTEGER_EXT
&&
1803 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1806 return GL_INVALID_OPERATION
;
1808 case GL_UNSIGNED_SHORT_4_4_4_4
:
1809 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1810 case GL_UNSIGNED_INT_8_8_8_8
:
1811 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1812 if (format
== GL_RGBA
||
1813 format
== GL_BGRA
||
1814 format
== GL_ABGR_EXT
) {
1817 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1818 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1821 return GL_INVALID_OPERATION
;
1823 case GL_UNSIGNED_SHORT_5_5_5_1
:
1824 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1825 case GL_UNSIGNED_INT_10_10_10_2
:
1826 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1827 if (format
== GL_RGBA
||
1828 format
== GL_BGRA
) {
1831 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1832 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1835 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1836 ctx
->API
== API_OPENGLES2
) {
1837 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1839 return GL_INVALID_OPERATION
;
1841 case GL_UNSIGNED_INT_24_8
:
1842 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1843 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1846 if (format
!= GL_DEPTH_STENCIL
) {
1847 return GL_INVALID_OPERATION
;
1851 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1852 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1853 return GL_INVALID_ENUM
;
1855 if (format
!= GL_DEPTH_STENCIL
) {
1856 return GL_INVALID_OPERATION
;
1860 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1861 if (!ctx
->Extensions
.EXT_packed_float
) {
1862 return GL_INVALID_ENUM
;
1864 if (format
!= GL_RGB
) {
1865 return GL_INVALID_OPERATION
;
1869 case GL_HALF_FLOAT_OES
:
1873 case GL_LUMINANCE_ALPHA
:
1879 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1882 return GL_INVALID_OPERATION
;
1886 ; /* fall-through */
1889 /* now, for each format, check the type for compatibility */
1891 case GL_COLOR_INDEX
:
1892 case GL_STENCIL_INDEX
:
1896 case GL_UNSIGNED_BYTE
:
1898 case GL_UNSIGNED_SHORT
:
1900 case GL_UNSIGNED_INT
:
1905 return GL_INVALID_ENUM
;
1912 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1916 case GL_LUMINANCE_ALPHA
:
1917 case GL_DEPTH_COMPONENT
:
1920 case GL_UNSIGNED_BYTE
:
1922 case GL_UNSIGNED_SHORT
:
1924 case GL_UNSIGNED_INT
:
1929 return GL_INVALID_ENUM
;
1933 if (!ctx
->Extensions
.ARB_texture_rg
)
1934 return GL_INVALID_ENUM
;
1937 case GL_UNSIGNED_BYTE
:
1939 case GL_UNSIGNED_SHORT
:
1941 case GL_UNSIGNED_INT
:
1946 return GL_INVALID_ENUM
;
1952 case GL_UNSIGNED_BYTE
:
1954 case GL_UNSIGNED_SHORT
:
1956 case GL_UNSIGNED_INT
:
1958 case GL_UNSIGNED_BYTE_3_3_2
:
1959 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1960 case GL_UNSIGNED_SHORT_5_6_5
:
1961 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1964 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1965 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1966 return (ctx
->API
== API_OPENGLES2
)
1967 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1968 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1969 return ctx
->Extensions
.EXT_texture_shared_exponent
1970 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1971 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1972 return ctx
->Extensions
.EXT_packed_float
1973 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1975 return GL_INVALID_ENUM
;
1980 /* NOTE: no packed types are supported with BGR. That's
1981 * intentional, according to the GL spec.
1984 case GL_UNSIGNED_BYTE
:
1986 case GL_UNSIGNED_SHORT
:
1988 case GL_UNSIGNED_INT
:
1993 return GL_INVALID_ENUM
;
2000 case GL_UNSIGNED_BYTE
:
2002 case GL_UNSIGNED_SHORT
:
2004 case GL_UNSIGNED_INT
:
2006 case GL_UNSIGNED_SHORT_4_4_4_4
:
2007 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2008 case GL_UNSIGNED_SHORT_5_5_5_1
:
2009 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2010 case GL_UNSIGNED_INT_8_8_8_8
:
2011 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2012 case GL_UNSIGNED_INT_10_10_10_2
:
2013 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2017 return GL_INVALID_ENUM
;
2023 case GL_UNSIGNED_BYTE
:
2025 case GL_UNSIGNED_SHORT
:
2027 case GL_UNSIGNED_INT
:
2029 case GL_UNSIGNED_SHORT_4_4_4_4
:
2030 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2031 case GL_UNSIGNED_INT_8_8_8_8
:
2032 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2036 return GL_INVALID_ENUM
;
2040 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2041 return GL_INVALID_ENUM
;
2042 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2043 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2046 return GL_INVALID_OPERATION
;
2048 case GL_DEPTH_STENCIL
:
2049 if (type
== GL_UNSIGNED_INT_24_8
)
2051 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2052 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2055 return GL_INVALID_ENUM
;
2057 /* integer-valued formats */
2058 case GL_RED_INTEGER_EXT
:
2059 case GL_GREEN_INTEGER_EXT
:
2060 case GL_BLUE_INTEGER_EXT
:
2061 case GL_ALPHA_INTEGER_EXT
:
2065 case GL_UNSIGNED_BYTE
:
2067 case GL_UNSIGNED_SHORT
:
2069 case GL_UNSIGNED_INT
:
2070 return _mesa_has_integer_textures(ctx
)
2071 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2073 return GL_INVALID_ENUM
;
2076 case GL_RGB_INTEGER_EXT
:
2079 case GL_UNSIGNED_BYTE
:
2081 case GL_UNSIGNED_SHORT
:
2083 case GL_UNSIGNED_INT
:
2084 return _mesa_has_integer_textures(ctx
)
2085 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2086 case GL_UNSIGNED_BYTE_3_3_2
:
2087 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2088 case GL_UNSIGNED_SHORT_5_6_5
:
2089 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2090 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2091 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2093 return GL_INVALID_ENUM
;
2096 case GL_BGR_INTEGER_EXT
:
2099 case GL_UNSIGNED_BYTE
:
2101 case GL_UNSIGNED_SHORT
:
2103 case GL_UNSIGNED_INT
:
2104 /* NOTE: no packed formats w/ BGR format */
2105 return _mesa_has_integer_textures(ctx
)
2106 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2108 return GL_INVALID_ENUM
;
2111 case GL_RGBA_INTEGER_EXT
:
2112 case GL_BGRA_INTEGER_EXT
:
2115 case GL_UNSIGNED_BYTE
:
2117 case GL_UNSIGNED_SHORT
:
2119 case GL_UNSIGNED_INT
:
2120 return _mesa_has_integer_textures(ctx
)
2121 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2122 case GL_UNSIGNED_SHORT_4_4_4_4
:
2123 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2124 case GL_UNSIGNED_SHORT_5_5_5_1
:
2125 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2126 case GL_UNSIGNED_INT_8_8_8_8
:
2127 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2128 case GL_UNSIGNED_INT_10_10_10_2
:
2129 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2130 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2131 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2133 return GL_INVALID_ENUM
;
2136 case GL_LUMINANCE_INTEGER_EXT
:
2137 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2140 case GL_UNSIGNED_BYTE
:
2142 case GL_UNSIGNED_SHORT
:
2144 case GL_UNSIGNED_INT
:
2145 return ctx
->Extensions
.EXT_texture_integer
2146 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2148 return GL_INVALID_ENUM
;
2152 return GL_INVALID_ENUM
;
2159 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2160 * and glTex[Sub]Image.
2161 * \return error code, or GL_NO_ERROR.
2164 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2165 GLenum format
, GLenum type
,
2166 unsigned dimensions
)
2168 GLboolean type_valid
= GL_TRUE
;
2173 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2174 return GL_INVALID_VALUE
;
2178 case GL_LUMINANCE_ALPHA
:
2179 type_valid
= (type
== GL_UNSIGNED_BYTE
2181 || type
== GL_HALF_FLOAT_OES
);
2185 type_valid
= (type
== GL_UNSIGNED_BYTE
2186 || type
== GL_UNSIGNED_SHORT_5_6_5
2188 || type
== GL_HALF_FLOAT_OES
);
2192 type_valid
= (type
== GL_UNSIGNED_BYTE
2193 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2194 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2196 || type
== GL_HALF_FLOAT_OES
2197 || (ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
&&
2198 type
== GL_UNSIGNED_INT_2_10_10_10_REV
));
2201 case GL_DEPTH_COMPONENT
:
2202 /* This format is filtered against invalid dimensionalities elsewhere.
2204 type_valid
= (type
== GL_UNSIGNED_SHORT
2205 || type
== GL_UNSIGNED_INT
);
2208 case GL_DEPTH_STENCIL
:
2209 /* This format is filtered against invalid dimensionalities elsewhere.
2211 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2215 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2217 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2218 * the format does not appear to be allowed for 3D textures in OpenGL
2221 if (dimensions
!= 2)
2222 return GL_INVALID_VALUE
;
2227 return GL_INVALID_VALUE
;
2230 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2234 * Return the simple base format for a given internal texture format.
2235 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2237 * \param ctx GL context.
2238 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2240 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2241 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2243 * This is the format which is used during texture application (i.e. the
2244 * texture format and env mode determine the arithmetic used.
2247 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2249 switch (internalFormat
) {
2255 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2260 case GL_LUMINANCE12
:
2261 case GL_LUMINANCE16
:
2262 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2264 case GL_LUMINANCE_ALPHA
:
2265 case GL_LUMINANCE4_ALPHA4
:
2266 case GL_LUMINANCE6_ALPHA2
:
2267 case GL_LUMINANCE8_ALPHA8
:
2268 case GL_LUMINANCE12_ALPHA4
:
2269 case GL_LUMINANCE12_ALPHA12
:
2270 case GL_LUMINANCE16_ALPHA16
:
2271 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2275 case GL_INTENSITY12
:
2276 case GL_INTENSITY16
:
2277 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2279 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2290 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2304 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2306 if (_mesa_is_gles(ctx
)) {
2307 switch (internalFormat
) {
2315 if (_mesa_has_ARB_ES2_compatibility(ctx
) || _mesa_is_gles(ctx
)) {
2316 switch (internalFormat
) {
2324 if (_mesa_has_ARB_depth_texture(ctx
) || _mesa_has_OES_depth_texture(ctx
) ||
2325 ctx
->API
== API_OPENGL_CORE
) {
2326 switch (internalFormat
) {
2327 case GL_DEPTH_COMPONENT
:
2328 case GL_DEPTH_COMPONENT16
:
2329 case GL_DEPTH_COMPONENT24
:
2330 case GL_DEPTH_COMPONENT32
:
2331 return GL_DEPTH_COMPONENT
;
2332 case GL_DEPTH_STENCIL
:
2333 case GL_DEPTH24_STENCIL8
:
2334 return GL_DEPTH_STENCIL
;
2340 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2341 switch (internalFormat
) {
2342 case GL_STENCIL_INDEX
:
2343 case GL_STENCIL_INDEX1
:
2344 case GL_STENCIL_INDEX4
:
2345 case GL_STENCIL_INDEX8
:
2346 case GL_STENCIL_INDEX16
:
2347 return GL_STENCIL_INDEX
;
2353 switch (internalFormat
) {
2354 case GL_COMPRESSED_ALPHA
:
2356 case GL_COMPRESSED_LUMINANCE
:
2357 return GL_LUMINANCE
;
2358 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2359 return GL_LUMINANCE_ALPHA
;
2360 case GL_COMPRESSED_INTENSITY
:
2361 return GL_INTENSITY
;
2362 case GL_COMPRESSED_RGB
:
2364 case GL_COMPRESSED_RGBA
:
2370 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2371 GLenum base_compressed
=
2372 _mesa_gl_compressed_format_base_format(internalFormat
);
2373 if (base_compressed
)
2374 return base_compressed
;
2377 if ((_mesa_has_KHR_texture_compression_astc_ldr(ctx
) &&
2378 is_astc_2d_format(internalFormat
)) ||
2379 (_mesa_has_OES_texture_compression_astc(ctx
) &&
2380 is_astc_3d_format(internalFormat
)))
2383 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2384 if (internalFormat
== GL_YCBCR_MESA
)
2385 return GL_YCBCR_MESA
;
2388 if (ctx
->Extensions
.ARB_texture_float
) {
2389 switch (internalFormat
) {
2390 case GL_ALPHA16F_ARB
:
2391 case GL_ALPHA32F_ARB
:
2393 case GL_RGBA16F_ARB
:
2394 case GL_RGBA32F_ARB
:
2399 case GL_INTENSITY16F_ARB
:
2400 case GL_INTENSITY32F_ARB
:
2401 return GL_INTENSITY
;
2402 case GL_LUMINANCE16F_ARB
:
2403 case GL_LUMINANCE32F_ARB
:
2404 return GL_LUMINANCE
;
2405 case GL_LUMINANCE_ALPHA16F_ARB
:
2406 case GL_LUMINANCE_ALPHA32F_ARB
:
2407 return GL_LUMINANCE_ALPHA
;
2413 if (ctx
->Extensions
.EXT_texture_snorm
) {
2414 switch (internalFormat
) {
2425 case GL_RGB16_SNORM
:
2428 case GL_RGBA8_SNORM
:
2429 case GL_RGBA16_SNORM
:
2431 case GL_ALPHA_SNORM
:
2432 case GL_ALPHA8_SNORM
:
2433 case GL_ALPHA16_SNORM
:
2435 case GL_LUMINANCE_SNORM
:
2436 case GL_LUMINANCE8_SNORM
:
2437 case GL_LUMINANCE16_SNORM
:
2438 return GL_LUMINANCE
;
2439 case GL_LUMINANCE_ALPHA_SNORM
:
2440 case GL_LUMINANCE8_ALPHA8_SNORM
:
2441 case GL_LUMINANCE16_ALPHA16_SNORM
:
2442 return GL_LUMINANCE_ALPHA
;
2443 case GL_INTENSITY_SNORM
:
2444 case GL_INTENSITY8_SNORM
:
2445 case GL_INTENSITY16_SNORM
:
2446 return GL_INTENSITY
;
2452 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2453 switch (internalFormat
) {
2456 case GL_COMPRESSED_SRGB_EXT
:
2458 case GL_SRGB_ALPHA_EXT
:
2459 case GL_SRGB8_ALPHA8_EXT
:
2460 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2462 case GL_SLUMINANCE_ALPHA_EXT
:
2463 case GL_SLUMINANCE8_ALPHA8_EXT
:
2464 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2465 return GL_LUMINANCE_ALPHA
;
2466 case GL_SLUMINANCE_EXT
:
2467 case GL_SLUMINANCE8_EXT
:
2468 case GL_COMPRESSED_SLUMINANCE_EXT
:
2469 return GL_LUMINANCE
;
2475 if (ctx
->Extensions
.EXT_texture_sRGB_R8
) {
2476 switch (internalFormat
) {
2484 if (_mesa_has_integer_textures(ctx
)) {
2485 switch (internalFormat
) {
2486 case GL_RGBA8UI_EXT
:
2487 case GL_RGBA16UI_EXT
:
2488 case GL_RGBA32UI_EXT
:
2490 case GL_RGBA16I_EXT
:
2491 case GL_RGBA32I_EXT
:
2494 case GL_RGB16UI_EXT
:
2495 case GL_RGB32UI_EXT
:
2503 if (ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
2504 switch (internalFormat
) {
2510 if (ctx
->Extensions
.EXT_texture_integer
) {
2511 switch (internalFormat
) {
2512 case GL_ALPHA8UI_EXT
:
2513 case GL_ALPHA16UI_EXT
:
2514 case GL_ALPHA32UI_EXT
:
2515 case GL_ALPHA8I_EXT
:
2516 case GL_ALPHA16I_EXT
:
2517 case GL_ALPHA32I_EXT
:
2519 case GL_INTENSITY8UI_EXT
:
2520 case GL_INTENSITY16UI_EXT
:
2521 case GL_INTENSITY32UI_EXT
:
2522 case GL_INTENSITY8I_EXT
:
2523 case GL_INTENSITY16I_EXT
:
2524 case GL_INTENSITY32I_EXT
:
2525 return GL_INTENSITY
;
2526 case GL_LUMINANCE8UI_EXT
:
2527 case GL_LUMINANCE16UI_EXT
:
2528 case GL_LUMINANCE32UI_EXT
:
2529 case GL_LUMINANCE8I_EXT
:
2530 case GL_LUMINANCE16I_EXT
:
2531 case GL_LUMINANCE32I_EXT
:
2532 return GL_LUMINANCE
;
2533 case GL_LUMINANCE_ALPHA8UI_EXT
:
2534 case GL_LUMINANCE_ALPHA16UI_EXT
:
2535 case GL_LUMINANCE_ALPHA32UI_EXT
:
2536 case GL_LUMINANCE_ALPHA8I_EXT
:
2537 case GL_LUMINANCE_ALPHA16I_EXT
:
2538 case GL_LUMINANCE_ALPHA32I_EXT
:
2539 return GL_LUMINANCE_ALPHA
;
2545 if (ctx
->Extensions
.ARB_texture_rg
) {
2546 switch (internalFormat
) {
2549 if (!ctx
->Extensions
.ARB_texture_float
)
2558 if (!_mesa_has_integer_textures(ctx
))
2564 case GL_COMPRESSED_RED
:
2569 if (!ctx
->Extensions
.ARB_texture_float
)
2578 if (!_mesa_has_integer_textures(ctx
))
2584 case GL_COMPRESSED_RG
:
2591 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2592 switch (internalFormat
) {
2593 case GL_RGB9_E5_EXT
:
2600 if (ctx
->Extensions
.EXT_packed_float
) {
2601 switch (internalFormat
) {
2602 case GL_R11F_G11F_B10F_EXT
:
2609 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2610 switch (internalFormat
) {
2611 case GL_DEPTH_COMPONENT32F
:
2612 return GL_DEPTH_COMPONENT
;
2613 case GL_DEPTH32F_STENCIL8
:
2614 return GL_DEPTH_STENCIL
;
2620 return -1; /* error */
2624 * Returns the effective internal format from a texture format and type.
2625 * This is used by texture image operations internally for validation, when
2626 * the specified internal format is a base (unsized) format.
2628 * This method will only return a valid effective internal format if the
2629 * combination of format, type and internal format in base form, is acceptable.
2631 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2632 * in extensions, to unambiguously correspond to the given base format, then
2633 * that internal format is returned as the effective. Otherwise, if the
2634 * combination is accepted but a single effective format is not defined, the
2635 * passed base format will be returned instead.
2637 * \param format the texture format
2638 * \param type the texture type
2641 gles_effective_internal_format_for_format_and_type(GLenum format
,
2645 case GL_UNSIGNED_BYTE
:
2655 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2656 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2657 * internal formats, they do not correspond to GL constants, so the base
2658 * format is returned instead.
2661 case GL_LUMINANCE_ALPHA
:
2668 case GL_UNSIGNED_SHORT_4_4_4_4
:
2669 if (format
== GL_RGBA
)
2673 case GL_UNSIGNED_SHORT_5_5_5_1
:
2674 if (format
== GL_RGBA
)
2678 case GL_UNSIGNED_SHORT_5_6_5
:
2679 if (format
== GL_RGB
)
2683 /* OES_packed_depth_stencil */
2684 case GL_UNSIGNED_INT_24_8
:
2685 if (format
== GL_DEPTH_STENCIL
)
2686 return GL_DEPTH24_STENCIL8
;
2689 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2690 if (format
== GL_DEPTH_STENCIL
)
2691 return GL_DEPTH32F_STENCIL8
;
2694 case GL_UNSIGNED_SHORT
:
2695 if (format
== GL_DEPTH_COMPONENT
)
2696 return GL_DEPTH_COMPONENT16
;
2699 case GL_UNSIGNED_INT
:
2700 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2703 if (format
== GL_DEPTH_COMPONENT
)
2707 /* OES_texture_float and OES_texture_half_float */
2709 if (format
== GL_DEPTH_COMPONENT
)
2710 return GL_DEPTH_COMPONENT32F
;
2712 case GL_HALF_FLOAT_OES
:
2716 case GL_LUMINANCE_ALPHA
:
2732 /* GL_EXT_texture_type_2_10_10_10_REV */
2733 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2742 /* fall through and return NONE */
2750 * Do error checking of format/type combinations for OpenGL ES 3
2751 * glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat.
2752 * \return error code, or GL_NO_ERROR.
2755 _mesa_gles_error_check_format_and_type(const struct gl_context
*ctx
,
2756 GLenum format
, GLenum type
,
2757 GLenum internalFormat
)
2759 /* If internalFormat is an unsized format, then the effective internal
2760 * format derived from format and type should be used instead. Page 127,
2761 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2763 * "if internalformat is a base internal format, the effective
2764 * internal format is a sized internal format that is derived
2765 * from the format and type for internal use by the GL.
2766 * Table 3.12 specifies the mapping of format and type to effective
2767 * internal formats. The effective internal format is used by the GL
2768 * for purposes such as texture completeness or type checks for
2769 * CopyTex* commands. In these cases, the GL is required to operate
2770 * as if the effective internal format was used as the internalformat
2771 * when specifying the texture data."
2773 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2774 GLenum effectiveInternalFormat
=
2775 gles_effective_internal_format_for_format_and_type(format
, type
);
2777 if (effectiveInternalFormat
== GL_NONE
)
2778 return GL_INVALID_OPERATION
;
2780 GLenum baseInternalFormat
;
2781 if (internalFormat
== GL_BGRA_EXT
) {
2782 /* Unfortunately, _mesa_base_tex_format returns a base format of
2783 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2784 * asking the question, "what channels does this format have?"
2785 * However, if we're trying to determine if two internal formats
2786 * match in the ES3 sense, we actually want GL_BGRA.
2788 baseInternalFormat
= GL_BGRA_EXT
;
2790 baseInternalFormat
=
2791 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2794 if (internalFormat
!= baseInternalFormat
)
2795 return GL_INVALID_OPERATION
;
2797 internalFormat
= effectiveInternalFormat
;
2800 /* The GLES variant of EXT_texture_compression_s3tc is very vague and
2801 * doesn't list valid types. Just do exactly what the spec says.
2803 if (_mesa_has_EXT_texture_compression_s3tc(ctx
) &&
2804 (internalFormat
== GL_COMPRESSED_RGB_S3TC_DXT1_EXT
||
2805 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
||
2806 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
||
2807 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
))
2808 return format
== GL_RGB
|| format
== GL_RGBA
? GL_NO_ERROR
:
2809 GL_INVALID_OPERATION
;
2813 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2814 return GL_INVALID_OPERATION
;
2819 case GL_UNSIGNED_BYTE
:
2820 switch (internalFormat
) {
2826 case GL_SRGB8_ALPHA8_EXT
:
2827 if (ctx
->Version
<= 20)
2828 return GL_INVALID_OPERATION
;
2831 return GL_INVALID_OPERATION
;
2836 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA8_SNORM
)
2837 return GL_INVALID_OPERATION
;
2840 case GL_UNSIGNED_SHORT
:
2841 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGBA16
)
2842 return GL_INVALID_OPERATION
;
2846 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2847 internalFormat
!= GL_RGBA16_SNORM
)
2848 return GL_INVALID_OPERATION
;
2851 case GL_UNSIGNED_SHORT_4_4_4_4
:
2852 switch (internalFormat
) {
2857 return GL_INVALID_OPERATION
;
2861 case GL_UNSIGNED_SHORT_5_5_5_1
:
2862 switch (internalFormat
) {
2867 return GL_INVALID_OPERATION
;
2871 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2872 switch (internalFormat
) {
2876 if (!ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
)
2877 return GL_INVALID_OPERATION
;
2880 return GL_INVALID_OPERATION
;
2885 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA16F
)
2886 return GL_INVALID_OPERATION
;
2890 switch (internalFormat
) {
2893 if (ctx
->Version
<= 20)
2894 return GL_INVALID_OPERATION
;
2897 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2900 return GL_INVALID_OPERATION
;
2904 case GL_HALF_FLOAT_OES
:
2905 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2908 return GL_INVALID_OPERATION
;
2912 case GL_RGBA_INTEGER
:
2913 if (ctx
->Version
<= 20)
2914 return GL_INVALID_OPERATION
;
2916 case GL_UNSIGNED_BYTE
:
2917 if (internalFormat
!= GL_RGBA8UI
)
2918 return GL_INVALID_OPERATION
;
2922 if (internalFormat
!= GL_RGBA8I
)
2923 return GL_INVALID_OPERATION
;
2926 case GL_UNSIGNED_SHORT
:
2927 if (internalFormat
!= GL_RGBA16UI
)
2928 return GL_INVALID_OPERATION
;
2932 if (internalFormat
!= GL_RGBA16I
)
2933 return GL_INVALID_OPERATION
;
2936 case GL_UNSIGNED_INT
:
2937 if (internalFormat
!= GL_RGBA32UI
)
2938 return GL_INVALID_OPERATION
;
2942 if (internalFormat
!= GL_RGBA32I
)
2943 return GL_INVALID_OPERATION
;
2946 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2947 if (internalFormat
!= GL_RGB10_A2UI
)
2948 return GL_INVALID_OPERATION
;
2952 return GL_INVALID_OPERATION
;
2958 case GL_UNSIGNED_BYTE
:
2959 switch (internalFormat
) {
2965 if (ctx
->Version
<= 20)
2966 return GL_INVALID_OPERATION
;
2969 return GL_INVALID_OPERATION
;
2974 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB8_SNORM
)
2975 return GL_INVALID_OPERATION
;
2978 case GL_UNSIGNED_SHORT
:
2979 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGB16
)
2980 return GL_INVALID_OPERATION
;
2984 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2985 internalFormat
!= GL_RGB16_SNORM
)
2986 return GL_INVALID_OPERATION
;
2989 case GL_UNSIGNED_SHORT_5_6_5
:
2990 switch (internalFormat
) {
2995 return GL_INVALID_OPERATION
;
2999 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3000 if (ctx
->Version
<= 20 || internalFormat
!= GL_R11F_G11F_B10F
)
3001 return GL_INVALID_OPERATION
;
3004 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3005 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB9_E5
)
3006 return GL_INVALID_OPERATION
;
3010 if (ctx
->Version
<= 20)
3011 return GL_INVALID_OPERATION
;
3012 switch (internalFormat
) {
3014 case GL_R11F_G11F_B10F
:
3018 return GL_INVALID_OPERATION
;
3023 switch (internalFormat
) {
3026 case GL_R11F_G11F_B10F
:
3028 if (ctx
->Version
<= 20)
3029 return GL_INVALID_OPERATION
;
3032 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3035 return GL_INVALID_OPERATION
;
3039 case GL_HALF_FLOAT_OES
:
3040 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
3041 return GL_INVALID_OPERATION
;
3044 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3045 switch (internalFormat
) {
3050 /* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though
3051 * GLES3 doesn't, and GL_OES_required_internalformat extends that
3052 * to allow the sized RGB internalformats as well.
3054 if (!ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
)
3055 return GL_INVALID_OPERATION
;
3058 return GL_INVALID_OPERATION
;
3063 return GL_INVALID_OPERATION
;
3067 case GL_RGB_INTEGER
:
3068 if (ctx
->Version
<= 20)
3069 return GL_INVALID_OPERATION
;
3071 case GL_UNSIGNED_BYTE
:
3072 if (internalFormat
!= GL_RGB8UI
)
3073 return GL_INVALID_OPERATION
;
3077 if (internalFormat
!= GL_RGB8I
)
3078 return GL_INVALID_OPERATION
;
3081 case GL_UNSIGNED_SHORT
:
3082 if (internalFormat
!= GL_RGB16UI
)
3083 return GL_INVALID_OPERATION
;
3087 if (internalFormat
!= GL_RGB16I
)
3088 return GL_INVALID_OPERATION
;
3091 case GL_UNSIGNED_INT
:
3092 if (internalFormat
!= GL_RGB32UI
)
3093 return GL_INVALID_OPERATION
;
3097 if (internalFormat
!= GL_RGB32I
)
3098 return GL_INVALID_OPERATION
;
3102 return GL_INVALID_OPERATION
;
3107 if (!ctx
->Extensions
.ARB_texture_rg
)
3108 return GL_INVALID_OPERATION
;
3110 case GL_UNSIGNED_BYTE
:
3111 if (internalFormat
!= GL_RG8
)
3112 return GL_INVALID_OPERATION
;
3116 if (internalFormat
!= GL_RG8_SNORM
)
3117 return GL_INVALID_OPERATION
;
3120 case GL_UNSIGNED_SHORT
:
3121 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RG16
)
3122 return GL_INVALID_OPERATION
;
3126 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3127 internalFormat
!= GL_RG16_SNORM
)
3128 return GL_INVALID_OPERATION
;
3132 case GL_HALF_FLOAT_OES
:
3133 switch (internalFormat
) {
3135 if (ctx
->Version
<= 20)
3136 return GL_INVALID_OPERATION
;
3139 if (ctx
->Extensions
.ARB_texture_rg
&&
3140 ctx
->Extensions
.OES_texture_half_float
)
3144 return GL_INVALID_OPERATION
;
3149 switch (internalFormat
) {
3154 if (ctx
->Extensions
.ARB_texture_rg
&&
3155 ctx
->Extensions
.OES_texture_float
)
3159 return GL_INVALID_OPERATION
;
3164 return GL_INVALID_OPERATION
;
3169 if (ctx
->Version
<= 20)
3170 return GL_INVALID_OPERATION
;
3172 case GL_UNSIGNED_BYTE
:
3173 if (internalFormat
!= GL_RG8UI
)
3174 return GL_INVALID_OPERATION
;
3178 if (internalFormat
!= GL_RG8I
)
3179 return GL_INVALID_OPERATION
;
3182 case GL_UNSIGNED_SHORT
:
3183 if (internalFormat
!= GL_RG16UI
)
3184 return GL_INVALID_OPERATION
;
3188 if (internalFormat
!= GL_RG16I
)
3189 return GL_INVALID_OPERATION
;
3192 case GL_UNSIGNED_INT
:
3193 if (internalFormat
!= GL_RG32UI
)
3194 return GL_INVALID_OPERATION
;
3198 if (internalFormat
!= GL_RG32I
)
3199 return GL_INVALID_OPERATION
;
3203 return GL_INVALID_OPERATION
;
3208 if (!ctx
->Extensions
.ARB_texture_rg
)
3209 return GL_INVALID_OPERATION
;
3211 case GL_UNSIGNED_BYTE
:
3212 if (internalFormat
== GL_R8
||
3213 ((internalFormat
== GL_SR8_EXT
) &&
3214 ctx
->Extensions
.EXT_texture_sRGB_R8
))
3216 return GL_INVALID_OPERATION
;
3219 if (internalFormat
!= GL_R8_SNORM
)
3220 return GL_INVALID_OPERATION
;
3223 case GL_UNSIGNED_SHORT
:
3224 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_R16
)
3225 return GL_INVALID_OPERATION
;
3229 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3230 internalFormat
!= GL_R16_SNORM
)
3231 return GL_INVALID_OPERATION
;
3235 case GL_HALF_FLOAT_OES
:
3236 switch (internalFormat
) {
3238 if (ctx
->Version
<= 20)
3239 return GL_INVALID_OPERATION
;
3243 if (ctx
->Extensions
.ARB_texture_rg
&&
3244 ctx
->Extensions
.OES_texture_half_float
)
3248 return GL_INVALID_OPERATION
;
3253 switch (internalFormat
) {
3258 if (ctx
->Extensions
.ARB_texture_rg
&&
3259 ctx
->Extensions
.OES_texture_float
)
3263 return GL_INVALID_OPERATION
;
3268 return GL_INVALID_OPERATION
;
3272 case GL_RED_INTEGER
:
3273 if (ctx
->Version
<= 20)
3274 return GL_INVALID_OPERATION
;
3276 case GL_UNSIGNED_BYTE
:
3277 if (internalFormat
!= GL_R8UI
)
3278 return GL_INVALID_OPERATION
;
3282 if (internalFormat
!= GL_R8I
)
3283 return GL_INVALID_OPERATION
;
3286 case GL_UNSIGNED_SHORT
:
3287 if (internalFormat
!= GL_R16UI
)
3288 return GL_INVALID_OPERATION
;
3292 if (internalFormat
!= GL_R16I
)
3293 return GL_INVALID_OPERATION
;
3296 case GL_UNSIGNED_INT
:
3297 if (internalFormat
!= GL_R32UI
)
3298 return GL_INVALID_OPERATION
;
3302 if (internalFormat
!= GL_R32I
)
3303 return GL_INVALID_OPERATION
;
3307 return GL_INVALID_OPERATION
;
3311 case GL_DEPTH_COMPONENT
:
3313 case GL_UNSIGNED_SHORT
:
3314 if (internalFormat
!= GL_DEPTH_COMPONENT
3315 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3316 return GL_INVALID_OPERATION
;
3319 case GL_UNSIGNED_INT
:
3320 switch (internalFormat
) {
3321 case GL_DEPTH_COMPONENT
:
3322 case GL_DEPTH_COMPONENT16
:
3323 case GL_DEPTH_COMPONENT24
:
3326 return GL_INVALID_OPERATION
;
3331 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH_COMPONENT32F
)
3332 return GL_INVALID_OPERATION
;
3336 return GL_INVALID_OPERATION
;
3340 case GL_DEPTH_STENCIL
:
3342 case GL_UNSIGNED_INT_24_8
:
3343 if (internalFormat
!= GL_DEPTH_STENCIL
3344 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3345 return GL_INVALID_OPERATION
;
3348 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3349 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH32F_STENCIL8
)
3350 return GL_INVALID_OPERATION
;
3354 return GL_INVALID_OPERATION
;
3358 case GL_STENCIL_INDEX
:
3359 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3360 type
!= GL_UNSIGNED_BYTE
||
3361 internalFormat
!= GL_STENCIL_INDEX8
) {
3362 return GL_INVALID_OPERATION
;
3368 case GL_LUMINANCE_ALPHA
:
3371 if (!ctx
->Extensions
.OES_texture_float
|| internalFormat
!= format
)
3372 return GL_INVALID_OPERATION
;
3374 case GL_HALF_FLOAT_OES
:
3375 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
3376 return GL_INVALID_OPERATION
;
3378 case GL_UNSIGNED_BYTE
:
3379 if (!(format
== internalFormat
||
3380 (format
== GL_ALPHA
&& internalFormat
== GL_ALPHA8
) ||
3381 (format
== GL_LUMINANCE
&& internalFormat
== GL_LUMINANCE8
) ||
3382 (format
== GL_LUMINANCE_ALPHA
&&
3383 ((internalFormat
== GL_LUMINANCE8_ALPHA8
) ||
3384 (internalFormat
== GL_LUMINANCE4_ALPHA4
))))) {
3385 return GL_INVALID_OPERATION
;
3389 return GL_INVALID_OPERATION
;
3398 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3400 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3401 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3402 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3403 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3407 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3411 case GL_RGBA_INTEGER_EXT
:
3412 set_swizzle(swizzle
, 0, 1, 2, 3);
3415 case GL_BGRA_INTEGER_EXT
:
3416 set_swizzle(swizzle
, 2, 1, 0, 3);
3419 set_swizzle(swizzle
, 3, 2, 1, 0);
3422 case GL_RGB_INTEGER_EXT
:
3423 set_swizzle(swizzle
, 0, 1, 2, 5);
3426 case GL_BGR_INTEGER_EXT
:
3427 set_swizzle(swizzle
, 2, 1, 0, 5);
3429 case GL_LUMINANCE_ALPHA
:
3430 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3431 set_swizzle(swizzle
, 0, 0, 0, 1);
3435 set_swizzle(swizzle
, 0, 1, 4, 5);
3438 case GL_RED_INTEGER_EXT
:
3439 set_swizzle(swizzle
, 0, 4, 4, 5);
3442 case GL_GREEN_INTEGER_EXT
:
3443 set_swizzle(swizzle
, 4, 0, 4, 5);
3446 case GL_BLUE_INTEGER_EXT
:
3447 set_swizzle(swizzle
, 4, 4, 0, 5);
3450 case GL_ALPHA_INTEGER_EXT
:
3451 set_swizzle(swizzle
, 4, 4, 4, 0);
3454 case GL_LUMINANCE_INTEGER_EXT
:
3455 set_swizzle(swizzle
, 0, 0, 0, 5);
3458 set_swizzle(swizzle
, 0, 0, 0, 0);
3466 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3467 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3468 * otherwise (for non-array formats).
3470 * This function will typically be used to compute a mesa format from a GL type
3471 * so we can then call _mesa_format_convert. This function does
3472 * not consider byte swapping, so it returns types assuming that no byte
3473 * swapping is involved. If byte swapping is involved then clients are supposed
3474 * to handle that on their side before calling _mesa_format_convert.
3476 * This function returns an uint32_t that can pack a mesa_format or a
3477 * mesa_array_format. Clients must check the mesa array format bit
3478 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3479 * format is a mesa_array_format or a mesa_format.
3482 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3484 bool is_array_format
= true;
3486 bool normalized
= false, is_float
= false, is_signed
= false;
3487 int num_channels
= 0, type_size
= 0;
3489 /* Extract array format type information from the OpenGL data type */
3491 case GL_UNSIGNED_BYTE
:
3498 case GL_UNSIGNED_SHORT
:
3505 case GL_UNSIGNED_INT
:
3513 case GL_HALF_FLOAT_OES
:
3524 is_array_format
= false;
3528 /* Extract array format swizzle information from the OpenGL format */
3529 if (is_array_format
)
3530 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3532 /* If this is an array format type after checking data type and format,
3533 * create the array format
3535 if (is_array_format
) {
3536 normalized
= !_mesa_is_enum_format_integer(format
);
3537 num_channels
= _mesa_components_in_format(format
);
3539 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3540 normalized
, num_channels
,
3541 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3544 /* Otherwise this is not an array format, so return the mesa_format
3545 * matching the OpenGL format and data type
3548 case GL_UNSIGNED_SHORT_5_6_5
:
3549 if (format
== GL_RGB
)
3550 return MESA_FORMAT_B5G6R5_UNORM
;
3551 else if (format
== GL_BGR
)
3552 return MESA_FORMAT_R5G6B5_UNORM
;
3553 else if (format
== GL_RGB_INTEGER
)
3554 return MESA_FORMAT_B5G6R5_UINT
;
3556 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3557 if (format
== GL_RGB
)
3558 return MESA_FORMAT_R5G6B5_UNORM
;
3559 else if (format
== GL_BGR
)
3560 return MESA_FORMAT_B5G6R5_UNORM
;
3561 else if (format
== GL_RGB_INTEGER
)
3562 return MESA_FORMAT_R5G6B5_UINT
;
3564 case GL_UNSIGNED_SHORT_4_4_4_4
:
3565 if (format
== GL_RGBA
)
3566 return MESA_FORMAT_A4B4G4R4_UNORM
;
3567 else if (format
== GL_BGRA
)
3568 return MESA_FORMAT_A4R4G4B4_UNORM
;
3569 else if (format
== GL_ABGR_EXT
)
3570 return MESA_FORMAT_R4G4B4A4_UNORM
;
3571 else if (format
== GL_RGBA_INTEGER
)
3572 return MESA_FORMAT_A4B4G4R4_UINT
;
3573 else if (format
== GL_BGRA_INTEGER
)
3574 return MESA_FORMAT_A4R4G4B4_UINT
;
3576 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3577 if (format
== GL_RGBA
)
3578 return MESA_FORMAT_R4G4B4A4_UNORM
;
3579 else if (format
== GL_BGRA
)
3580 return MESA_FORMAT_B4G4R4A4_UNORM
;
3581 else if (format
== GL_ABGR_EXT
)
3582 return MESA_FORMAT_A4B4G4R4_UNORM
;
3583 else if (format
== GL_RGBA_INTEGER
)
3584 return MESA_FORMAT_R4G4B4A4_UINT
;
3585 else if (format
== GL_BGRA_INTEGER
)
3586 return MESA_FORMAT_B4G4R4A4_UINT
;
3588 case GL_UNSIGNED_SHORT_5_5_5_1
:
3589 if (format
== GL_RGBA
)
3590 return MESA_FORMAT_A1B5G5R5_UNORM
;
3591 else if (format
== GL_BGRA
)
3592 return MESA_FORMAT_A1R5G5B5_UNORM
;
3593 else if (format
== GL_RGBA_INTEGER
)
3594 return MESA_FORMAT_A1B5G5R5_UINT
;
3595 else if (format
== GL_BGRA_INTEGER
)
3596 return MESA_FORMAT_A1R5G5B5_UINT
;
3598 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3599 if (format
== GL_RGBA
)
3600 return MESA_FORMAT_R5G5B5A1_UNORM
;
3601 else if (format
== GL_BGRA
)
3602 return MESA_FORMAT_B5G5R5A1_UNORM
;
3603 else if (format
== GL_RGBA_INTEGER
)
3604 return MESA_FORMAT_R5G5B5A1_UINT
;
3605 else if (format
== GL_BGRA_INTEGER
)
3606 return MESA_FORMAT_B5G5R5A1_UINT
;
3608 case GL_UNSIGNED_BYTE_3_3_2
:
3609 if (format
== GL_RGB
)
3610 return MESA_FORMAT_B2G3R3_UNORM
;
3611 else if (format
== GL_RGB_INTEGER
)
3612 return MESA_FORMAT_B2G3R3_UINT
;
3614 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3615 if (format
== GL_RGB
)
3616 return MESA_FORMAT_R3G3B2_UNORM
;
3617 else if (format
== GL_RGB_INTEGER
)
3618 return MESA_FORMAT_R3G3B2_UINT
;
3620 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3621 if (format
== GL_RGB
)
3622 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3624 case GL_UNSIGNED_INT_10_10_10_2
:
3625 if (format
== GL_RGBA
)
3626 return MESA_FORMAT_A2B10G10R10_UNORM
;
3627 else if (format
== GL_RGBA_INTEGER
)
3628 return MESA_FORMAT_A2B10G10R10_UINT
;
3629 else if (format
== GL_BGRA
)
3630 return MESA_FORMAT_A2R10G10B10_UNORM
;
3631 else if (format
== GL_BGRA_INTEGER
)
3632 return MESA_FORMAT_A2R10G10B10_UINT
;
3634 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3635 if (format
== GL_RGB
)
3636 return MESA_FORMAT_R10G10B10X2_UNORM
;
3637 if (format
== GL_RGBA
)
3638 return MESA_FORMAT_R10G10B10A2_UNORM
;
3639 else if (format
== GL_RGBA_INTEGER
)
3640 return MESA_FORMAT_R10G10B10A2_UINT
;
3641 else if (format
== GL_BGRA
)
3642 return MESA_FORMAT_B10G10R10A2_UNORM
;
3643 else if (format
== GL_BGRA_INTEGER
)
3644 return MESA_FORMAT_B10G10R10A2_UINT
;
3646 case GL_UNSIGNED_INT_8_8_8_8
:
3647 if (format
== GL_RGBA
)
3648 return MESA_FORMAT_A8B8G8R8_UNORM
;
3649 else if (format
== GL_BGRA
)
3650 return MESA_FORMAT_A8R8G8B8_UNORM
;
3651 else if (format
== GL_ABGR_EXT
)
3652 return MESA_FORMAT_R8G8B8A8_UNORM
;
3653 else if (format
== GL_RGBA_INTEGER
)
3654 return MESA_FORMAT_A8B8G8R8_UINT
;
3655 else if (format
== GL_BGRA_INTEGER
)
3656 return MESA_FORMAT_A8R8G8B8_UINT
;
3658 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3659 if (format
== GL_RGBA
)
3660 return MESA_FORMAT_R8G8B8A8_UNORM
;
3661 else if (format
== GL_BGRA
)
3662 return MESA_FORMAT_B8G8R8A8_UNORM
;
3663 else if (format
== GL_ABGR_EXT
)
3664 return MESA_FORMAT_A8B8G8R8_UNORM
;
3665 else if (format
== GL_RGBA_INTEGER
)
3666 return MESA_FORMAT_R8G8B8A8_UINT
;
3667 else if (format
== GL_BGRA_INTEGER
)
3668 return MESA_FORMAT_B8G8R8A8_UINT
;
3670 case GL_UNSIGNED_SHORT_8_8_MESA
:
3671 if (format
== GL_YCBCR_MESA
)
3672 return MESA_FORMAT_YCBCR
;
3674 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3675 if (format
== GL_YCBCR_MESA
)
3676 return MESA_FORMAT_YCBCR_REV
;
3678 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3679 if (format
== GL_RGB
)
3680 return MESA_FORMAT_R11G11B10_FLOAT
;
3683 if (format
== GL_DEPTH_COMPONENT
)
3684 return MESA_FORMAT_Z_FLOAT32
;
3686 case GL_UNSIGNED_INT
:
3687 if (format
== GL_DEPTH_COMPONENT
)
3688 return MESA_FORMAT_Z_UNORM32
;
3690 case GL_UNSIGNED_SHORT
:
3691 if (format
== GL_DEPTH_COMPONENT
)
3692 return MESA_FORMAT_Z_UNORM16
;
3694 case GL_UNSIGNED_INT_24_8
:
3695 if (format
== GL_DEPTH_STENCIL
)
3696 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3698 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3699 if (format
== GL_DEPTH_STENCIL
)
3700 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3706 /* If we got here it means that we could not find a Mesa format that
3707 * matches the GL format/type provided. We may need to add a new Mesa
3708 * format in that case.
3710 unreachable("Unsupported format");
3714 _mesa_tex_format_from_format_and_type(const struct gl_context
*ctx
,
3715 GLenum gl_format
, GLenum type
)
3717 mesa_format format
= _mesa_format_from_format_and_type(gl_format
, type
);
3719 if (_mesa_format_is_mesa_array_format(format
))
3720 format
= _mesa_format_from_array_format(format
);
3722 if (format
== MESA_FORMAT_NONE
|| !ctx
->TextureFormatSupported
[format
])
3723 return MESA_FORMAT_NONE
;
3729 * Returns true if \p internal_format is a sized internal format that
3730 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3733 _mesa_is_es3_color_renderable(const struct gl_context
*ctx
,
3734 GLenum internal_format
)
3736 switch (internal_format
) {
3746 case GL_SRGB8_ALPHA8
:
3753 case GL_R11F_G11F_B10F
:
3776 return _mesa_has_EXT_texture_norm16(ctx
);
3779 case GL_RGBA8_SNORM
:
3780 return _mesa_has_EXT_render_snorm(ctx
);
3783 case GL_RGBA16_SNORM
:
3784 return _mesa_has_EXT_texture_norm16(ctx
) &&
3785 _mesa_has_EXT_render_snorm(ctx
);
3792 * Returns true if \p internal_format is a sized internal format that
3793 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3796 _mesa_is_es3_texture_filterable(const struct gl_context
*ctx
,
3797 GLenum internal_format
)
3799 switch (internal_format
) {
3810 case GL_RGBA8_SNORM
:
3813 case GL_SRGB8_ALPHA8
:
3818 case GL_R11F_G11F_B10F
:
3826 case GL_RGB16_SNORM
:
3828 case GL_RGBA16_SNORM
:
3829 return _mesa_has_EXT_texture_norm16(ctx
);
3834 /* The OES_texture_float_linear spec says:
3836 * "When implemented against OpenGL ES 3.0 or later versions, sized
3837 * 32-bit floating-point formats become texture-filterable. This
3838 * should be noted by, for example, checking the ``TF'' column of
3839 * table 8.13 in the ES 3.1 Specification (``Correspondence of sized
3840 * internal formats to base internal formats ... and use cases ...'')
3841 * for the R32F, RG32F, RGB32F, and RGBA32F formats."
3843 return _mesa_has_OES_texture_float_linear(ctx
);