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 ctx
->API
== API_OPENGL_COMPAT
1358 && ctx
->Extensions
.ATI_texture_compression_3dc
;
1359 case GL_PALETTE4_RGB8_OES
:
1360 case GL_PALETTE4_RGBA8_OES
:
1361 case GL_PALETTE4_R5_G6_B5_OES
:
1362 case GL_PALETTE4_RGBA4_OES
:
1363 case GL_PALETTE4_RGB5_A1_OES
:
1364 case GL_PALETTE8_RGB8_OES
:
1365 case GL_PALETTE8_RGBA8_OES
:
1366 case GL_PALETTE8_R5_G6_B5_OES
:
1367 case GL_PALETTE8_RGBA4_OES
:
1368 case GL_PALETTE8_RGB5_A1_OES
:
1369 return ctx
->API
== API_OPENGLES
;
1372 switch (_mesa_get_format_layout(m_format
)) {
1373 case MESA_FORMAT_LAYOUT_S3TC
:
1374 if (_mesa_get_format_color_encoding(m_format
) == GL_LINEAR
) {
1375 /* Assume that the ANGLE flag will always be set if the
1378 return ctx
->Extensions
.ANGLE_texture_compression_dxt
;
1380 return _mesa_has_EXT_texture_sRGB(ctx
) &&
1381 _mesa_has_EXT_texture_compression_s3tc(ctx
);
1383 case MESA_FORMAT_LAYOUT_FXT1
:
1384 return _mesa_is_desktop_gl(ctx
)
1385 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1386 case MESA_FORMAT_LAYOUT_RGTC
:
1387 return _mesa_is_desktop_gl(ctx
)
1388 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
1389 case MESA_FORMAT_LAYOUT_LATC
:
1390 return ctx
->API
== API_OPENGL_COMPAT
1391 && ctx
->Extensions
.EXT_texture_compression_latc
;
1392 case MESA_FORMAT_LAYOUT_ETC1
:
1393 return _mesa_is_gles(ctx
)
1394 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1395 case MESA_FORMAT_LAYOUT_ETC2
:
1396 return _mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
;
1397 case MESA_FORMAT_LAYOUT_BPTC
:
1398 return _mesa_is_desktop_gl(ctx
) &&
1399 ctx
->Extensions
.ARB_texture_compression_bptc
;
1400 case MESA_FORMAT_LAYOUT_ASTC
:
1401 return ctx
->Extensions
.KHR_texture_compression_astc_ldr
;
1408 * Test if the given format represents an sRGB format.
1409 * \param format the GL format (can be an internal format)
1410 * \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1413 _mesa_is_srgb_format(GLenum format
)
1419 case GL_SRGB8_ALPHA8
:
1420 case GL_COMPRESSED_SRGB
:
1421 case GL_COMPRESSED_SRGB_ALPHA
:
1422 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1423 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1424 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1425 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1426 case GL_COMPRESSED_SRGB8_ETC2
:
1427 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
1428 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
1429 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
1430 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
:
1431 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
:
1432 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
:
1433 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
:
1434 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
:
1435 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
:
1436 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
:
1437 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
:
1438 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
:
1439 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
:
1440 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
:
1441 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
:
1442 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
:
1443 case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
:
1453 * Convert various unpack formats to the corresponding base format.
1456 _mesa_unpack_format_to_base_format(GLenum format
)
1459 case GL_RED_INTEGER
:
1461 case GL_GREEN_INTEGER
:
1463 case GL_BLUE_INTEGER
:
1465 case GL_ALPHA_INTEGER
:
1469 case GL_RGB_INTEGER
:
1471 case GL_RGBA_INTEGER
:
1473 case GL_BGR_INTEGER
:
1475 case GL_BGRA_INTEGER
:
1477 case GL_LUMINANCE_INTEGER_EXT
:
1478 return GL_LUMINANCE
;
1479 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1480 return GL_LUMINANCE_ALPHA
;
1491 case GL_LUMINANCE_ALPHA
:
1498 * Convert various base formats to the corresponding integer format.
1501 _mesa_base_format_to_integer_format(GLenum format
)
1505 return GL_RED_INTEGER
;
1507 return GL_GREEN_INTEGER
;
1509 return GL_BLUE_INTEGER
;
1511 return GL_RG_INTEGER
;
1513 return GL_RGB_INTEGER
;
1515 return GL_RGBA_INTEGER
;
1517 return GL_BGR_INTEGER
;
1519 return GL_BGRA_INTEGER
;
1521 return GL_ALPHA_INTEGER
;
1523 return GL_LUMINANCE_INTEGER_EXT
;
1524 case GL_LUMINANCE_ALPHA
:
1525 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
1533 * Does the given base texture/renderbuffer format have the channel
1537 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1540 case GL_TEXTURE_RED_SIZE
:
1541 case GL_TEXTURE_RED_TYPE
:
1542 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1543 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1544 case GL_INTERNALFORMAT_RED_SIZE
:
1545 case GL_INTERNALFORMAT_RED_TYPE
:
1546 if (base_format
== GL_RED
||
1547 base_format
== GL_RG
||
1548 base_format
== GL_RGB
||
1549 base_format
== GL_RGBA
) {
1553 case GL_TEXTURE_GREEN_SIZE
:
1554 case GL_TEXTURE_GREEN_TYPE
:
1555 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1556 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1557 case GL_INTERNALFORMAT_GREEN_SIZE
:
1558 case GL_INTERNALFORMAT_GREEN_TYPE
:
1559 if (base_format
== GL_RG
||
1560 base_format
== GL_RGB
||
1561 base_format
== GL_RGBA
) {
1565 case GL_TEXTURE_BLUE_SIZE
:
1566 case GL_TEXTURE_BLUE_TYPE
:
1567 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1568 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1569 case GL_INTERNALFORMAT_BLUE_SIZE
:
1570 case GL_INTERNALFORMAT_BLUE_TYPE
:
1571 if (base_format
== GL_RGB
||
1572 base_format
== GL_RGBA
) {
1576 case GL_TEXTURE_ALPHA_SIZE
:
1577 case GL_TEXTURE_ALPHA_TYPE
:
1578 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1579 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1580 case GL_INTERNALFORMAT_ALPHA_SIZE
:
1581 case GL_INTERNALFORMAT_ALPHA_TYPE
:
1582 if (base_format
== GL_RGBA
||
1583 base_format
== GL_ALPHA
||
1584 base_format
== GL_LUMINANCE_ALPHA
) {
1588 case GL_TEXTURE_LUMINANCE_SIZE
:
1589 case GL_TEXTURE_LUMINANCE_TYPE
:
1590 if (base_format
== GL_LUMINANCE
||
1591 base_format
== GL_LUMINANCE_ALPHA
) {
1595 case GL_TEXTURE_INTENSITY_SIZE
:
1596 case GL_TEXTURE_INTENSITY_TYPE
:
1597 if (base_format
== GL_INTENSITY
) {
1601 case GL_TEXTURE_DEPTH_SIZE
:
1602 case GL_TEXTURE_DEPTH_TYPE
:
1603 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1604 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1605 case GL_INTERNALFORMAT_DEPTH_SIZE
:
1606 case GL_INTERNALFORMAT_DEPTH_TYPE
:
1607 if (base_format
== GL_DEPTH_STENCIL
||
1608 base_format
== GL_DEPTH_COMPONENT
) {
1612 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1613 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1614 case GL_INTERNALFORMAT_STENCIL_SIZE
:
1615 case GL_INTERNALFORMAT_STENCIL_TYPE
:
1616 if (base_format
== GL_DEPTH_STENCIL
||
1617 base_format
== GL_STENCIL_INDEX
) {
1622 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1632 * If format is a generic compressed format, return the corresponding
1633 * non-compressed format. For other formats, return the format as-is.
1636 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
1639 case GL_COMPRESSED_RED
:
1641 case GL_COMPRESSED_RG
:
1643 case GL_COMPRESSED_RGB
:
1645 case GL_COMPRESSED_RGBA
:
1647 case GL_COMPRESSED_ALPHA
:
1649 case GL_COMPRESSED_LUMINANCE
:
1650 return GL_LUMINANCE
;
1651 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1652 return GL_LUMINANCE_ALPHA
;
1653 case GL_COMPRESSED_INTENSITY
:
1654 return GL_INTENSITY
;
1656 case GL_COMPRESSED_SRGB
:
1658 case GL_COMPRESSED_SRGB_ALPHA
:
1659 return GL_SRGB_ALPHA
;
1660 case GL_COMPRESSED_SLUMINANCE
:
1661 return GL_SLUMINANCE
;
1662 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1663 return GL_SLUMINANCE_ALPHA
;
1671 * Return the equivalent non-generic internal format.
1672 * This is useful for comparing whether two internal formats are equivalent.
1675 _mesa_get_nongeneric_internalformat(GLenum format
)
1678 /* GL 1.1 formats. */
1686 case GL_LUMINANCE_ALPHA
:
1687 return GL_LUMINANCE8_ALPHA8
;
1690 return GL_LUMINANCE8
;
1694 return GL_INTENSITY8
;
1696 /* GL_ARB_texture_rg */
1702 /* GL_EXT_texture_sRGB */
1706 return GL_SRGB8_ALPHA8
;
1708 return GL_SLUMINANCE8
;
1709 case GL_SLUMINANCE_ALPHA
:
1710 return GL_SLUMINANCE8_ALPHA8
;
1712 /* GL_EXT_texture_snorm */
1714 return GL_RGBA8_SNORM
;
1716 return GL_RGB8_SNORM
;
1718 return GL_RG8_SNORM
;
1721 case GL_LUMINANCE_ALPHA_SNORM
:
1722 return GL_LUMINANCE8_ALPHA8_SNORM
;
1723 case GL_LUMINANCE_SNORM
:
1724 return GL_LUMINANCE8_SNORM
;
1725 case GL_ALPHA_SNORM
:
1726 return GL_ALPHA8_SNORM
;
1727 case GL_INTENSITY_SNORM
:
1728 return GL_INTENSITY8_SNORM
;
1737 * Convert an sRGB internal format to linear.
1740 _mesa_get_linear_internalformat(GLenum format
)
1749 case GL_SRGB8_ALPHA8
:
1751 case GL_SLUMINANCE8
:
1752 return GL_LUMINANCE8
;
1754 return GL_LUMINANCE
;
1755 case GL_SLUMINANCE_ALPHA
:
1756 return GL_LUMINANCE_ALPHA
;
1757 case GL_SLUMINANCE8_ALPHA8
:
1758 return GL_LUMINANCE8_ALPHA8
;
1766 * Do error checking of format/type combinations for glReadPixels,
1767 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1768 * and type values, we may either generate GL_INVALID_OPERATION or
1771 * \param format pixel format.
1772 * \param type pixel type.
1774 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1777 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1778 GLenum format
, GLenum type
)
1780 /* From OpenGL 3.3 spec, page 220:
1781 * "If the format is DEPTH_STENCIL, then values are taken from
1782 * both the depth buffer and the stencil buffer. If there is no
1783 * depth buffer or if there is no stencil buffer, then the error
1784 * INVALID_OPERATION occurs. If the type parameter is not
1785 * UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1786 * error INVALID_ENUM occurs."
1788 * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1789 * cannot be used to read depth or stencil in that API.
1791 if (_mesa_is_desktop_gl(ctx
) && format
== GL_DEPTH_STENCIL
1792 && type
!= GL_UNSIGNED_INT_24_8
1793 && type
!= GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1794 return GL_INVALID_ENUM
;
1796 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1799 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1800 return GL_INVALID_ENUM
;
1804 case GL_UNSIGNED_BYTE_3_3_2
:
1805 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1806 case GL_UNSIGNED_SHORT_5_6_5
:
1807 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1808 if (format
== GL_RGB
) {
1811 if (format
== GL_RGB_INTEGER_EXT
&&
1812 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1815 return GL_INVALID_OPERATION
;
1817 case GL_UNSIGNED_SHORT_4_4_4_4
:
1818 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1819 case GL_UNSIGNED_INT_8_8_8_8
:
1820 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1821 if (format
== GL_RGBA
||
1822 format
== GL_BGRA
||
1823 format
== GL_ABGR_EXT
) {
1826 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1827 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1830 return GL_INVALID_OPERATION
;
1832 case GL_UNSIGNED_SHORT_5_5_5_1
:
1833 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1834 case GL_UNSIGNED_INT_10_10_10_2
:
1835 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1836 if (format
== GL_RGBA
||
1837 format
== GL_BGRA
) {
1840 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1841 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1844 if (type
== GL_UNSIGNED_INT_2_10_10_10_REV
&& format
== GL_RGB
&&
1845 ctx
->API
== API_OPENGLES2
) {
1846 break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1848 return GL_INVALID_OPERATION
;
1850 case GL_UNSIGNED_INT_24_8
:
1851 /* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1852 if (ctx
->API
== API_OPENGLES2
&& format
== GL_DEPTH_COMPONENT
)
1855 if (format
!= GL_DEPTH_STENCIL
) {
1856 return GL_INVALID_OPERATION
;
1860 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1861 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1862 return GL_INVALID_ENUM
;
1864 if (format
!= GL_DEPTH_STENCIL
) {
1865 return GL_INVALID_OPERATION
;
1869 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1870 if (!ctx
->Extensions
.EXT_packed_float
) {
1871 return GL_INVALID_ENUM
;
1873 if (format
!= GL_RGB
) {
1874 return GL_INVALID_OPERATION
;
1878 case GL_HALF_FLOAT_OES
:
1882 case GL_LUMINANCE_ALPHA
:
1888 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_texture_rg
)
1891 return GL_INVALID_OPERATION
;
1895 ; /* fall-through */
1898 /* now, for each format, check the type for compatibility */
1900 case GL_COLOR_INDEX
:
1901 case GL_STENCIL_INDEX
:
1905 case GL_UNSIGNED_BYTE
:
1907 case GL_UNSIGNED_SHORT
:
1909 case GL_UNSIGNED_INT
:
1914 return GL_INVALID_ENUM
;
1921 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1925 case GL_LUMINANCE_ALPHA
:
1926 case GL_DEPTH_COMPONENT
:
1929 case GL_UNSIGNED_BYTE
:
1931 case GL_UNSIGNED_SHORT
:
1933 case GL_UNSIGNED_INT
:
1938 return GL_INVALID_ENUM
;
1942 if (!ctx
->Extensions
.ARB_texture_rg
)
1943 return GL_INVALID_ENUM
;
1946 case GL_UNSIGNED_BYTE
:
1948 case GL_UNSIGNED_SHORT
:
1950 case GL_UNSIGNED_INT
:
1955 return GL_INVALID_ENUM
;
1961 case GL_UNSIGNED_BYTE
:
1963 case GL_UNSIGNED_SHORT
:
1965 case GL_UNSIGNED_INT
:
1967 case GL_UNSIGNED_BYTE_3_3_2
:
1968 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1969 case GL_UNSIGNED_SHORT_5_6_5
:
1970 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1973 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1974 /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1975 return (ctx
->API
== API_OPENGLES2
)
1976 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1977 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1978 return ctx
->Extensions
.EXT_texture_shared_exponent
1979 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1980 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1981 return ctx
->Extensions
.EXT_packed_float
1982 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1984 return GL_INVALID_ENUM
;
1989 /* NOTE: no packed types are supported with BGR. That's
1990 * intentional, according to the GL spec.
1993 case GL_UNSIGNED_BYTE
:
1995 case GL_UNSIGNED_SHORT
:
1997 case GL_UNSIGNED_INT
:
2002 return GL_INVALID_ENUM
;
2009 case GL_UNSIGNED_BYTE
:
2011 case GL_UNSIGNED_SHORT
:
2013 case GL_UNSIGNED_INT
:
2015 case GL_UNSIGNED_SHORT_4_4_4_4
:
2016 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2017 case GL_UNSIGNED_SHORT_5_5_5_1
:
2018 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2019 case GL_UNSIGNED_INT_8_8_8_8
:
2020 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2021 case GL_UNSIGNED_INT_10_10_10_2
:
2022 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2026 return GL_INVALID_ENUM
;
2032 case GL_UNSIGNED_BYTE
:
2034 case GL_UNSIGNED_SHORT
:
2036 case GL_UNSIGNED_INT
:
2038 case GL_UNSIGNED_SHORT_4_4_4_4
:
2039 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2040 case GL_UNSIGNED_INT_8_8_8_8
:
2041 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2045 return GL_INVALID_ENUM
;
2049 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
2050 return GL_INVALID_ENUM
;
2051 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
2052 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
2055 return GL_INVALID_OPERATION
;
2057 case GL_DEPTH_STENCIL
:
2058 if (type
== GL_UNSIGNED_INT_24_8
)
2060 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
2061 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
2064 return GL_INVALID_ENUM
;
2066 /* integer-valued formats */
2067 case GL_RED_INTEGER_EXT
:
2068 case GL_GREEN_INTEGER_EXT
:
2069 case GL_BLUE_INTEGER_EXT
:
2070 case GL_ALPHA_INTEGER_EXT
:
2074 case GL_UNSIGNED_BYTE
:
2076 case GL_UNSIGNED_SHORT
:
2078 case GL_UNSIGNED_INT
:
2079 return (ctx
->Version
>= 30 ||
2080 ctx
->Extensions
.EXT_texture_integer
)
2081 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2083 return GL_INVALID_ENUM
;
2086 case GL_RGB_INTEGER_EXT
:
2089 case GL_UNSIGNED_BYTE
:
2091 case GL_UNSIGNED_SHORT
:
2093 case GL_UNSIGNED_INT
:
2094 return (ctx
->Version
>= 30 ||
2095 ctx
->Extensions
.EXT_texture_integer
)
2096 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2097 case GL_UNSIGNED_BYTE_3_3_2
:
2098 case GL_UNSIGNED_BYTE_2_3_3_REV
:
2099 case GL_UNSIGNED_SHORT_5_6_5
:
2100 case GL_UNSIGNED_SHORT_5_6_5_REV
:
2101 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2102 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2104 return GL_INVALID_ENUM
;
2107 case GL_BGR_INTEGER_EXT
:
2110 case GL_UNSIGNED_BYTE
:
2112 case GL_UNSIGNED_SHORT
:
2114 case GL_UNSIGNED_INT
:
2115 /* NOTE: no packed formats w/ BGR format */
2116 return (ctx
->Version
>= 30 ||
2117 ctx
->Extensions
.EXT_texture_integer
)
2118 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2120 return GL_INVALID_ENUM
;
2123 case GL_RGBA_INTEGER_EXT
:
2124 case GL_BGRA_INTEGER_EXT
:
2127 case GL_UNSIGNED_BYTE
:
2129 case GL_UNSIGNED_SHORT
:
2131 case GL_UNSIGNED_INT
:
2132 return (ctx
->Version
>= 30 ||
2133 ctx
->Extensions
.EXT_texture_integer
)
2134 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2135 case GL_UNSIGNED_SHORT_4_4_4_4
:
2136 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
2137 case GL_UNSIGNED_SHORT_5_5_5_1
:
2138 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
2139 case GL_UNSIGNED_INT_8_8_8_8
:
2140 case GL_UNSIGNED_INT_8_8_8_8_REV
:
2141 case GL_UNSIGNED_INT_10_10_10_2
:
2142 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2143 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
2144 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2146 return GL_INVALID_ENUM
;
2149 case GL_LUMINANCE_INTEGER_EXT
:
2150 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
2153 case GL_UNSIGNED_BYTE
:
2155 case GL_UNSIGNED_SHORT
:
2157 case GL_UNSIGNED_INT
:
2158 return ctx
->Extensions
.EXT_texture_integer
2159 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
2161 return GL_INVALID_ENUM
;
2165 return GL_INVALID_ENUM
;
2172 * Do error checking of format/type combinations for OpenGL ES glReadPixels
2173 * and glTex[Sub]Image.
2174 * \return error code, or GL_NO_ERROR.
2177 _mesa_es_error_check_format_and_type(const struct gl_context
*ctx
,
2178 GLenum format
, GLenum type
,
2179 unsigned dimensions
)
2181 GLboolean type_valid
= GL_TRUE
;
2186 if (ctx
->API
== API_OPENGLES
|| !ctx
->Extensions
.ARB_texture_rg
)
2187 return GL_INVALID_VALUE
;
2191 case GL_LUMINANCE_ALPHA
:
2192 type_valid
= (type
== GL_UNSIGNED_BYTE
2194 || type
== GL_HALF_FLOAT_OES
);
2198 type_valid
= (type
== GL_UNSIGNED_BYTE
2199 || type
== GL_UNSIGNED_SHORT_5_6_5
2201 || type
== GL_HALF_FLOAT_OES
);
2205 type_valid
= (type
== GL_UNSIGNED_BYTE
2206 || type
== GL_UNSIGNED_SHORT_4_4_4_4
2207 || type
== GL_UNSIGNED_SHORT_5_5_5_1
2209 || type
== GL_HALF_FLOAT_OES
2210 || (ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
&&
2211 type
== GL_UNSIGNED_INT_2_10_10_10_REV
));
2214 case GL_DEPTH_COMPONENT
:
2215 /* This format is filtered against invalid dimensionalities elsewhere.
2217 type_valid
= (type
== GL_UNSIGNED_SHORT
2218 || type
== GL_UNSIGNED_INT
);
2221 case GL_DEPTH_STENCIL
:
2222 /* This format is filtered against invalid dimensionalities elsewhere.
2224 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
2228 type_valid
= (type
== GL_UNSIGNED_BYTE
);
2230 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2231 * the format does not appear to be allowed for 3D textures in OpenGL
2234 if (dimensions
!= 2)
2235 return GL_INVALID_VALUE
;
2240 return GL_INVALID_VALUE
;
2243 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;
2247 * Return the simple base format for a given internal texture format.
2248 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2250 * \param ctx GL context.
2251 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2253 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2254 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2256 * This is the format which is used during texture application (i.e. the
2257 * texture format and env mode determine the arithmetic used.
2260 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
2262 switch (internalFormat
) {
2268 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
2273 case GL_LUMINANCE12
:
2274 case GL_LUMINANCE16
:
2275 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
2277 case GL_LUMINANCE_ALPHA
:
2278 case GL_LUMINANCE4_ALPHA4
:
2279 case GL_LUMINANCE6_ALPHA2
:
2280 case GL_LUMINANCE8_ALPHA8
:
2281 case GL_LUMINANCE12_ALPHA4
:
2282 case GL_LUMINANCE12_ALPHA12
:
2283 case GL_LUMINANCE16_ALPHA16
:
2284 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
2288 case GL_INTENSITY12
:
2289 case GL_INTENSITY16
:
2290 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
2292 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
2303 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
2317 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2319 if (_mesa_is_gles(ctx
)) {
2320 switch (internalFormat
) {
2328 if (_mesa_has_ARB_ES2_compatibility(ctx
) || _mesa_is_gles(ctx
)) {
2329 switch (internalFormat
) {
2337 if (ctx
->Extensions
.ARB_depth_texture
) {
2338 switch (internalFormat
) {
2339 case GL_DEPTH_COMPONENT
:
2340 case GL_DEPTH_COMPONENT16
:
2341 case GL_DEPTH_COMPONENT24
:
2342 case GL_DEPTH_COMPONENT32
:
2343 return GL_DEPTH_COMPONENT
;
2344 case GL_DEPTH_STENCIL
:
2345 case GL_DEPTH24_STENCIL8
:
2346 return GL_DEPTH_STENCIL
;
2352 if (ctx
->Extensions
.ARB_texture_stencil8
) {
2353 switch (internalFormat
) {
2354 case GL_STENCIL_INDEX
:
2355 case GL_STENCIL_INDEX1
:
2356 case GL_STENCIL_INDEX4
:
2357 case GL_STENCIL_INDEX8
:
2358 case GL_STENCIL_INDEX16
:
2359 return GL_STENCIL_INDEX
;
2365 switch (internalFormat
) {
2366 case GL_COMPRESSED_ALPHA
:
2368 case GL_COMPRESSED_LUMINANCE
:
2369 return GL_LUMINANCE
;
2370 case GL_COMPRESSED_LUMINANCE_ALPHA
:
2371 return GL_LUMINANCE_ALPHA
;
2372 case GL_COMPRESSED_INTENSITY
:
2373 return GL_INTENSITY
;
2374 case GL_COMPRESSED_RGB
:
2376 case GL_COMPRESSED_RGBA
:
2382 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2383 GLenum base_compressed
=
2384 _mesa_gl_compressed_format_base_format(internalFormat
);
2385 if (base_compressed
)
2386 return base_compressed
;
2389 if ((ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
2390 is_astc_2d_format(internalFormat
)) ||
2391 (ctx
->Extensions
.OES_texture_compression_astc
&&
2392 is_astc_3d_format(internalFormat
)))
2395 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
2396 if (internalFormat
== GL_YCBCR_MESA
)
2397 return GL_YCBCR_MESA
;
2400 if (ctx
->Extensions
.ARB_texture_float
) {
2401 switch (internalFormat
) {
2402 case GL_ALPHA16F_ARB
:
2403 case GL_ALPHA32F_ARB
:
2405 case GL_RGBA16F_ARB
:
2406 case GL_RGBA32F_ARB
:
2411 case GL_INTENSITY16F_ARB
:
2412 case GL_INTENSITY32F_ARB
:
2413 return GL_INTENSITY
;
2414 case GL_LUMINANCE16F_ARB
:
2415 case GL_LUMINANCE32F_ARB
:
2416 return GL_LUMINANCE
;
2417 case GL_LUMINANCE_ALPHA16F_ARB
:
2418 case GL_LUMINANCE_ALPHA32F_ARB
:
2419 return GL_LUMINANCE_ALPHA
;
2425 if (ctx
->Extensions
.EXT_texture_snorm
) {
2426 switch (internalFormat
) {
2437 case GL_RGB16_SNORM
:
2440 case GL_RGBA8_SNORM
:
2441 case GL_RGBA16_SNORM
:
2443 case GL_ALPHA_SNORM
:
2444 case GL_ALPHA8_SNORM
:
2445 case GL_ALPHA16_SNORM
:
2447 case GL_LUMINANCE_SNORM
:
2448 case GL_LUMINANCE8_SNORM
:
2449 case GL_LUMINANCE16_SNORM
:
2450 return GL_LUMINANCE
;
2451 case GL_LUMINANCE_ALPHA_SNORM
:
2452 case GL_LUMINANCE8_ALPHA8_SNORM
:
2453 case GL_LUMINANCE16_ALPHA16_SNORM
:
2454 return GL_LUMINANCE_ALPHA
;
2455 case GL_INTENSITY_SNORM
:
2456 case GL_INTENSITY8_SNORM
:
2457 case GL_INTENSITY16_SNORM
:
2458 return GL_INTENSITY
;
2464 if (ctx
->Extensions
.EXT_texture_sRGB
) {
2465 switch (internalFormat
) {
2468 case GL_COMPRESSED_SRGB_EXT
:
2470 case GL_SRGB_ALPHA_EXT
:
2471 case GL_SRGB8_ALPHA8_EXT
:
2472 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
2474 case GL_SLUMINANCE_ALPHA_EXT
:
2475 case GL_SLUMINANCE8_ALPHA8_EXT
:
2476 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
2477 return GL_LUMINANCE_ALPHA
;
2478 case GL_SLUMINANCE_EXT
:
2479 case GL_SLUMINANCE8_EXT
:
2480 case GL_COMPRESSED_SLUMINANCE_EXT
:
2481 return GL_LUMINANCE
;
2487 if (ctx
->Extensions
.EXT_texture_sRGB_R8
) {
2488 switch (internalFormat
) {
2496 if (ctx
->Version
>= 30 ||
2497 ctx
->Extensions
.EXT_texture_integer
) {
2498 switch (internalFormat
) {
2499 case GL_RGBA8UI_EXT
:
2500 case GL_RGBA16UI_EXT
:
2501 case GL_RGBA32UI_EXT
:
2503 case GL_RGBA16I_EXT
:
2504 case GL_RGBA32I_EXT
:
2507 case GL_RGB16UI_EXT
:
2508 case GL_RGB32UI_EXT
:
2516 if (ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
2517 switch (internalFormat
) {
2523 if (ctx
->Extensions
.EXT_texture_integer
) {
2524 switch (internalFormat
) {
2525 case GL_ALPHA8UI_EXT
:
2526 case GL_ALPHA16UI_EXT
:
2527 case GL_ALPHA32UI_EXT
:
2528 case GL_ALPHA8I_EXT
:
2529 case GL_ALPHA16I_EXT
:
2530 case GL_ALPHA32I_EXT
:
2532 case GL_INTENSITY8UI_EXT
:
2533 case GL_INTENSITY16UI_EXT
:
2534 case GL_INTENSITY32UI_EXT
:
2535 case GL_INTENSITY8I_EXT
:
2536 case GL_INTENSITY16I_EXT
:
2537 case GL_INTENSITY32I_EXT
:
2538 return GL_INTENSITY
;
2539 case GL_LUMINANCE8UI_EXT
:
2540 case GL_LUMINANCE16UI_EXT
:
2541 case GL_LUMINANCE32UI_EXT
:
2542 case GL_LUMINANCE8I_EXT
:
2543 case GL_LUMINANCE16I_EXT
:
2544 case GL_LUMINANCE32I_EXT
:
2545 return GL_LUMINANCE
;
2546 case GL_LUMINANCE_ALPHA8UI_EXT
:
2547 case GL_LUMINANCE_ALPHA16UI_EXT
:
2548 case GL_LUMINANCE_ALPHA32UI_EXT
:
2549 case GL_LUMINANCE_ALPHA8I_EXT
:
2550 case GL_LUMINANCE_ALPHA16I_EXT
:
2551 case GL_LUMINANCE_ALPHA32I_EXT
:
2552 return GL_LUMINANCE_ALPHA
;
2558 if (ctx
->Extensions
.ARB_texture_rg
) {
2559 switch (internalFormat
) {
2562 if (!ctx
->Extensions
.ARB_texture_float
)
2571 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2577 case GL_COMPRESSED_RED
:
2582 if (!ctx
->Extensions
.ARB_texture_float
)
2591 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
2597 case GL_COMPRESSED_RG
:
2604 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
2605 switch (internalFormat
) {
2606 case GL_RGB9_E5_EXT
:
2613 if (ctx
->Extensions
.EXT_packed_float
) {
2614 switch (internalFormat
) {
2615 case GL_R11F_G11F_B10F_EXT
:
2622 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
2623 switch (internalFormat
) {
2624 case GL_DEPTH_COMPONENT32F
:
2625 return GL_DEPTH_COMPONENT
;
2626 case GL_DEPTH32F_STENCIL8
:
2627 return GL_DEPTH_STENCIL
;
2633 return -1; /* error */
2637 * Returns the effective internal format from a texture format and type.
2638 * This is used by texture image operations internally for validation, when
2639 * the specified internal format is a base (unsized) format.
2641 * This method will only return a valid effective internal format if the
2642 * combination of format, type and internal format in base form, is acceptable.
2644 * If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2645 * in extensions, to unambiguously correspond to the given base format, then
2646 * that internal format is returned as the effective. Otherwise, if the
2647 * combination is accepted but a single effective format is not defined, the
2648 * passed base format will be returned instead.
2650 * \param format the texture format
2651 * \param type the texture type
2654 gles_effective_internal_format_for_format_and_type(GLenum format
,
2658 case GL_UNSIGNED_BYTE
:
2668 /* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2669 * (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2670 * internal formats, they do not correspond to GL constants, so the base
2671 * format is returned instead.
2674 case GL_LUMINANCE_ALPHA
:
2681 case GL_UNSIGNED_SHORT_4_4_4_4
:
2682 if (format
== GL_RGBA
)
2686 case GL_UNSIGNED_SHORT_5_5_5_1
:
2687 if (format
== GL_RGBA
)
2691 case GL_UNSIGNED_SHORT_5_6_5
:
2692 if (format
== GL_RGB
)
2696 /* OES_packed_depth_stencil */
2697 case GL_UNSIGNED_INT_24_8
:
2698 if (format
== GL_DEPTH_STENCIL
)
2699 return GL_DEPTH24_STENCIL8
;
2702 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
2703 if (format
== GL_DEPTH_STENCIL
)
2704 return GL_DEPTH32F_STENCIL8
;
2707 case GL_UNSIGNED_SHORT
:
2708 if (format
== GL_DEPTH_COMPONENT
)
2709 return GL_DEPTH_COMPONENT16
;
2712 case GL_UNSIGNED_INT
:
2713 /* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2716 if (format
== GL_DEPTH_COMPONENT
)
2720 /* OES_texture_float and OES_texture_half_float */
2722 if (format
== GL_DEPTH_COMPONENT
)
2723 return GL_DEPTH_COMPONENT32F
;
2725 case GL_HALF_FLOAT_OES
:
2729 case GL_LUMINANCE_ALPHA
:
2745 /* GL_EXT_texture_type_2_10_10_10_REV */
2746 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2755 /* fall through and return NONE */
2763 * Do error checking of format/type combinations for OpenGL ES 3
2764 * glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat.
2765 * \return error code, or GL_NO_ERROR.
2768 _mesa_gles_error_check_format_and_type(const struct gl_context
*ctx
,
2769 GLenum format
, GLenum type
,
2770 GLenum internalFormat
)
2772 /* If internalFormat is an unsized format, then the effective internal
2773 * format derived from format and type should be used instead. Page 127,
2774 * section "3.8 Texturing" of the GLES 3.0.4 spec states:
2776 * "if internalformat is a base internal format, the effective
2777 * internal format is a sized internal format that is derived
2778 * from the format and type for internal use by the GL.
2779 * Table 3.12 specifies the mapping of format and type to effective
2780 * internal formats. The effective internal format is used by the GL
2781 * for purposes such as texture completeness or type checks for
2782 * CopyTex* commands. In these cases, the GL is required to operate
2783 * as if the effective internal format was used as the internalformat
2784 * when specifying the texture data."
2786 if (_mesa_is_enum_format_unsized(internalFormat
)) {
2787 GLenum effectiveInternalFormat
=
2788 gles_effective_internal_format_for_format_and_type(format
, type
);
2790 if (effectiveInternalFormat
== GL_NONE
)
2791 return GL_INVALID_OPERATION
;
2793 GLenum baseInternalFormat
;
2794 if (internalFormat
== GL_BGRA_EXT
) {
2795 /* Unfortunately, _mesa_base_tex_format returns a base format of
2796 * GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
2797 * asking the question, "what channels does this format have?"
2798 * However, if we're trying to determine if two internal formats
2799 * match in the ES3 sense, we actually want GL_BGRA.
2801 baseInternalFormat
= GL_BGRA_EXT
;
2803 baseInternalFormat
=
2804 _mesa_base_tex_format(ctx
, effectiveInternalFormat
);
2807 if (internalFormat
!= baseInternalFormat
)
2808 return GL_INVALID_OPERATION
;
2810 internalFormat
= effectiveInternalFormat
;
2813 /* The GLES variant of EXT_texture_compression_s3tc is very vague and
2814 * doesn't list valid types. Just do exactly what the spec says.
2816 if (ctx
->Extensions
.EXT_texture_compression_s3tc
&&
2817 (internalFormat
== GL_COMPRESSED_RGB_S3TC_DXT1_EXT
||
2818 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
||
2819 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
||
2820 internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
))
2821 return format
== GL_RGB
|| format
== GL_RGBA
? GL_NO_ERROR
:
2822 GL_INVALID_OPERATION
;
2826 if (type
!= GL_UNSIGNED_BYTE
|| internalFormat
!= GL_BGRA
)
2827 return GL_INVALID_OPERATION
;
2832 case GL_UNSIGNED_BYTE
:
2833 switch (internalFormat
) {
2839 case GL_SRGB8_ALPHA8_EXT
:
2840 if (ctx
->Version
<= 20)
2841 return GL_INVALID_OPERATION
;
2844 return GL_INVALID_OPERATION
;
2849 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA8_SNORM
)
2850 return GL_INVALID_OPERATION
;
2853 case GL_UNSIGNED_SHORT
:
2854 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGBA16
)
2855 return GL_INVALID_OPERATION
;
2859 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2860 internalFormat
!= GL_RGBA16_SNORM
)
2861 return GL_INVALID_OPERATION
;
2864 case GL_UNSIGNED_SHORT_4_4_4_4
:
2865 switch (internalFormat
) {
2870 return GL_INVALID_OPERATION
;
2874 case GL_UNSIGNED_SHORT_5_5_5_1
:
2875 switch (internalFormat
) {
2880 return GL_INVALID_OPERATION
;
2884 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2885 switch (internalFormat
) {
2889 if (!ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
)
2890 return GL_INVALID_OPERATION
;
2893 return GL_INVALID_OPERATION
;
2898 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGBA16F
)
2899 return GL_INVALID_OPERATION
;
2903 switch (internalFormat
) {
2906 if (ctx
->Version
<= 20)
2907 return GL_INVALID_OPERATION
;
2910 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
2913 return GL_INVALID_OPERATION
;
2917 case GL_HALF_FLOAT_OES
:
2918 if (ctx
->Extensions
.OES_texture_half_float
&& internalFormat
== format
)
2921 return GL_INVALID_OPERATION
;
2925 case GL_RGBA_INTEGER
:
2926 if (ctx
->Version
<= 20)
2927 return GL_INVALID_OPERATION
;
2929 case GL_UNSIGNED_BYTE
:
2930 if (internalFormat
!= GL_RGBA8UI
)
2931 return GL_INVALID_OPERATION
;
2935 if (internalFormat
!= GL_RGBA8I
)
2936 return GL_INVALID_OPERATION
;
2939 case GL_UNSIGNED_SHORT
:
2940 if (internalFormat
!= GL_RGBA16UI
)
2941 return GL_INVALID_OPERATION
;
2945 if (internalFormat
!= GL_RGBA16I
)
2946 return GL_INVALID_OPERATION
;
2949 case GL_UNSIGNED_INT
:
2950 if (internalFormat
!= GL_RGBA32UI
)
2951 return GL_INVALID_OPERATION
;
2955 if (internalFormat
!= GL_RGBA32I
)
2956 return GL_INVALID_OPERATION
;
2959 case GL_UNSIGNED_INT_2_10_10_10_REV
:
2960 if (internalFormat
!= GL_RGB10_A2UI
)
2961 return GL_INVALID_OPERATION
;
2965 return GL_INVALID_OPERATION
;
2971 case GL_UNSIGNED_BYTE
:
2972 switch (internalFormat
) {
2978 if (ctx
->Version
<= 20)
2979 return GL_INVALID_OPERATION
;
2982 return GL_INVALID_OPERATION
;
2987 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB8_SNORM
)
2988 return GL_INVALID_OPERATION
;
2991 case GL_UNSIGNED_SHORT
:
2992 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RGB16
)
2993 return GL_INVALID_OPERATION
;
2997 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
2998 internalFormat
!= GL_RGB16_SNORM
)
2999 return GL_INVALID_OPERATION
;
3002 case GL_UNSIGNED_SHORT_5_6_5
:
3003 switch (internalFormat
) {
3008 return GL_INVALID_OPERATION
;
3012 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3013 if (ctx
->Version
<= 20 || internalFormat
!= GL_R11F_G11F_B10F
)
3014 return GL_INVALID_OPERATION
;
3017 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3018 if (ctx
->Version
<= 20 || internalFormat
!= GL_RGB9_E5
)
3019 return GL_INVALID_OPERATION
;
3023 if (ctx
->Version
<= 20)
3024 return GL_INVALID_OPERATION
;
3025 switch (internalFormat
) {
3027 case GL_R11F_G11F_B10F
:
3031 return GL_INVALID_OPERATION
;
3036 switch (internalFormat
) {
3039 case GL_R11F_G11F_B10F
:
3041 if (ctx
->Version
<= 20)
3042 return GL_INVALID_OPERATION
;
3045 if (ctx
->Extensions
.OES_texture_float
&& internalFormat
== format
)
3048 return GL_INVALID_OPERATION
;
3052 case GL_HALF_FLOAT_OES
:
3053 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
3054 return GL_INVALID_OPERATION
;
3057 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3058 switch (internalFormat
) {
3063 /* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though
3064 * GLES3 doesn't, and GL_OES_required_internalformat extends that
3065 * to allow the sized RGB internalformats as well.
3067 if (!ctx
->Extensions
.EXT_texture_type_2_10_10_10_REV
)
3068 return GL_INVALID_OPERATION
;
3071 return GL_INVALID_OPERATION
;
3076 return GL_INVALID_OPERATION
;
3080 case GL_RGB_INTEGER
:
3081 if (ctx
->Version
<= 20)
3082 return GL_INVALID_OPERATION
;
3084 case GL_UNSIGNED_BYTE
:
3085 if (internalFormat
!= GL_RGB8UI
)
3086 return GL_INVALID_OPERATION
;
3090 if (internalFormat
!= GL_RGB8I
)
3091 return GL_INVALID_OPERATION
;
3094 case GL_UNSIGNED_SHORT
:
3095 if (internalFormat
!= GL_RGB16UI
)
3096 return GL_INVALID_OPERATION
;
3100 if (internalFormat
!= GL_RGB16I
)
3101 return GL_INVALID_OPERATION
;
3104 case GL_UNSIGNED_INT
:
3105 if (internalFormat
!= GL_RGB32UI
)
3106 return GL_INVALID_OPERATION
;
3110 if (internalFormat
!= GL_RGB32I
)
3111 return GL_INVALID_OPERATION
;
3115 return GL_INVALID_OPERATION
;
3120 if (!ctx
->Extensions
.ARB_texture_rg
)
3121 return GL_INVALID_OPERATION
;
3123 case GL_UNSIGNED_BYTE
:
3124 if (internalFormat
!= GL_RG8
)
3125 return GL_INVALID_OPERATION
;
3129 if (internalFormat
!= GL_RG8_SNORM
)
3130 return GL_INVALID_OPERATION
;
3133 case GL_UNSIGNED_SHORT
:
3134 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_RG16
)
3135 return GL_INVALID_OPERATION
;
3139 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3140 internalFormat
!= GL_RG16_SNORM
)
3141 return GL_INVALID_OPERATION
;
3145 case GL_HALF_FLOAT_OES
:
3146 switch (internalFormat
) {
3148 if (ctx
->Version
<= 20)
3149 return GL_INVALID_OPERATION
;
3152 if (ctx
->Extensions
.ARB_texture_rg
&&
3153 ctx
->Extensions
.OES_texture_half_float
)
3157 return GL_INVALID_OPERATION
;
3162 switch (internalFormat
) {
3167 if (ctx
->Extensions
.ARB_texture_rg
&&
3168 ctx
->Extensions
.OES_texture_float
)
3172 return GL_INVALID_OPERATION
;
3177 return GL_INVALID_OPERATION
;
3182 if (ctx
->Version
<= 20)
3183 return GL_INVALID_OPERATION
;
3185 case GL_UNSIGNED_BYTE
:
3186 if (internalFormat
!= GL_RG8UI
)
3187 return GL_INVALID_OPERATION
;
3191 if (internalFormat
!= GL_RG8I
)
3192 return GL_INVALID_OPERATION
;
3195 case GL_UNSIGNED_SHORT
:
3196 if (internalFormat
!= GL_RG16UI
)
3197 return GL_INVALID_OPERATION
;
3201 if (internalFormat
!= GL_RG16I
)
3202 return GL_INVALID_OPERATION
;
3205 case GL_UNSIGNED_INT
:
3206 if (internalFormat
!= GL_RG32UI
)
3207 return GL_INVALID_OPERATION
;
3211 if (internalFormat
!= GL_RG32I
)
3212 return GL_INVALID_OPERATION
;
3216 return GL_INVALID_OPERATION
;
3221 if (!ctx
->Extensions
.ARB_texture_rg
)
3222 return GL_INVALID_OPERATION
;
3224 case GL_UNSIGNED_BYTE
:
3225 if (internalFormat
== GL_R8
||
3226 ((internalFormat
== GL_SR8_EXT
) &&
3227 ctx
->Extensions
.EXT_texture_sRGB_R8
))
3229 return GL_INVALID_OPERATION
;
3232 if (internalFormat
!= GL_R8_SNORM
)
3233 return GL_INVALID_OPERATION
;
3236 case GL_UNSIGNED_SHORT
:
3237 if (!_mesa_has_EXT_texture_norm16(ctx
) || internalFormat
!= GL_R16
)
3238 return GL_INVALID_OPERATION
;
3242 if (!_mesa_has_EXT_texture_norm16(ctx
) ||
3243 internalFormat
!= GL_R16_SNORM
)
3244 return GL_INVALID_OPERATION
;
3248 case GL_HALF_FLOAT_OES
:
3249 switch (internalFormat
) {
3251 if (ctx
->Version
<= 20)
3252 return GL_INVALID_OPERATION
;
3256 if (ctx
->Extensions
.ARB_texture_rg
&&
3257 ctx
->Extensions
.OES_texture_half_float
)
3261 return GL_INVALID_OPERATION
;
3266 switch (internalFormat
) {
3271 if (ctx
->Extensions
.ARB_texture_rg
&&
3272 ctx
->Extensions
.OES_texture_float
)
3276 return GL_INVALID_OPERATION
;
3281 return GL_INVALID_OPERATION
;
3285 case GL_RED_INTEGER
:
3286 if (ctx
->Version
<= 20)
3287 return GL_INVALID_OPERATION
;
3289 case GL_UNSIGNED_BYTE
:
3290 if (internalFormat
!= GL_R8UI
)
3291 return GL_INVALID_OPERATION
;
3295 if (internalFormat
!= GL_R8I
)
3296 return GL_INVALID_OPERATION
;
3299 case GL_UNSIGNED_SHORT
:
3300 if (internalFormat
!= GL_R16UI
)
3301 return GL_INVALID_OPERATION
;
3305 if (internalFormat
!= GL_R16I
)
3306 return GL_INVALID_OPERATION
;
3309 case GL_UNSIGNED_INT
:
3310 if (internalFormat
!= GL_R32UI
)
3311 return GL_INVALID_OPERATION
;
3315 if (internalFormat
!= GL_R32I
)
3316 return GL_INVALID_OPERATION
;
3320 return GL_INVALID_OPERATION
;
3324 case GL_DEPTH_COMPONENT
:
3326 case GL_UNSIGNED_SHORT
:
3327 if (internalFormat
!= GL_DEPTH_COMPONENT
3328 && internalFormat
!= GL_DEPTH_COMPONENT16
)
3329 return GL_INVALID_OPERATION
;
3332 case GL_UNSIGNED_INT
:
3333 switch (internalFormat
) {
3334 case GL_DEPTH_COMPONENT
:
3335 case GL_DEPTH_COMPONENT16
:
3336 case GL_DEPTH_COMPONENT24
:
3339 return GL_INVALID_OPERATION
;
3344 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH_COMPONENT32F
)
3345 return GL_INVALID_OPERATION
;
3349 return GL_INVALID_OPERATION
;
3353 case GL_DEPTH_STENCIL
:
3355 case GL_UNSIGNED_INT_24_8
:
3356 if (internalFormat
!= GL_DEPTH_STENCIL
3357 && internalFormat
!= GL_DEPTH24_STENCIL8
)
3358 return GL_INVALID_OPERATION
;
3361 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3362 if (ctx
->Version
<= 20 || internalFormat
!= GL_DEPTH32F_STENCIL8
)
3363 return GL_INVALID_OPERATION
;
3367 return GL_INVALID_OPERATION
;
3371 case GL_STENCIL_INDEX
:
3372 if (!_mesa_has_OES_texture_stencil8(ctx
) ||
3373 type
!= GL_UNSIGNED_BYTE
||
3374 internalFormat
!= GL_STENCIL_INDEX8
) {
3375 return GL_INVALID_OPERATION
;
3381 case GL_LUMINANCE_ALPHA
:
3384 if (!ctx
->Extensions
.OES_texture_float
|| internalFormat
!= format
)
3385 return GL_INVALID_OPERATION
;
3387 case GL_HALF_FLOAT_OES
:
3388 if (!ctx
->Extensions
.OES_texture_half_float
|| internalFormat
!= format
)
3389 return GL_INVALID_OPERATION
;
3391 case GL_UNSIGNED_BYTE
:
3392 if (!(format
== internalFormat
||
3393 (format
== GL_ALPHA
&& internalFormat
== GL_ALPHA8
) ||
3394 (format
== GL_LUMINANCE
&& internalFormat
== GL_LUMINANCE8
) ||
3395 (format
== GL_LUMINANCE_ALPHA
&&
3396 ((internalFormat
== GL_LUMINANCE8_ALPHA8
) ||
3397 (internalFormat
== GL_LUMINANCE4_ALPHA4
))))) {
3398 return GL_INVALID_OPERATION
;
3402 return GL_INVALID_OPERATION
;
3411 set_swizzle(uint8_t *swizzle
, int x
, int y
, int z
, int w
)
3413 swizzle
[MESA_FORMAT_SWIZZLE_X
] = x
;
3414 swizzle
[MESA_FORMAT_SWIZZLE_Y
] = y
;
3415 swizzle
[MESA_FORMAT_SWIZZLE_Z
] = z
;
3416 swizzle
[MESA_FORMAT_SWIZZLE_W
] = w
;
3420 get_swizzle_from_gl_format(GLenum format
, uint8_t *swizzle
)
3424 case GL_RGBA_INTEGER_EXT
:
3425 set_swizzle(swizzle
, 0, 1, 2, 3);
3428 case GL_BGRA_INTEGER_EXT
:
3429 set_swizzle(swizzle
, 2, 1, 0, 3);
3432 set_swizzle(swizzle
, 3, 2, 1, 0);
3435 case GL_RGB_INTEGER_EXT
:
3436 set_swizzle(swizzle
, 0, 1, 2, 5);
3439 case GL_BGR_INTEGER_EXT
:
3440 set_swizzle(swizzle
, 2, 1, 0, 5);
3442 case GL_LUMINANCE_ALPHA
:
3443 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
3444 set_swizzle(swizzle
, 0, 0, 0, 1);
3448 set_swizzle(swizzle
, 0, 1, 4, 5);
3451 case GL_RED_INTEGER_EXT
:
3452 set_swizzle(swizzle
, 0, 4, 4, 5);
3455 case GL_GREEN_INTEGER_EXT
:
3456 set_swizzle(swizzle
, 4, 0, 4, 5);
3459 case GL_BLUE_INTEGER_EXT
:
3460 set_swizzle(swizzle
, 4, 4, 0, 5);
3463 case GL_ALPHA_INTEGER_EXT
:
3464 set_swizzle(swizzle
, 4, 4, 4, 0);
3467 case GL_LUMINANCE_INTEGER_EXT
:
3468 set_swizzle(swizzle
, 0, 0, 0, 5);
3471 set_swizzle(swizzle
, 0, 0, 0, 0);
3479 * Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3480 * GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3481 * otherwise (for non-array formats).
3483 * This function will typically be used to compute a mesa format from a GL type
3484 * so we can then call _mesa_format_convert. This function does
3485 * not consider byte swapping, so it returns types assuming that no byte
3486 * swapping is involved. If byte swapping is involved then clients are supposed
3487 * to handle that on their side before calling _mesa_format_convert.
3489 * This function returns an uint32_t that can pack a mesa_format or a
3490 * mesa_array_format. Clients must check the mesa array format bit
3491 * (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3492 * format is a mesa_array_format or a mesa_format.
3495 _mesa_format_from_format_and_type(GLenum format
, GLenum type
)
3497 bool is_array_format
= true;
3499 bool normalized
= false, is_float
= false, is_signed
= false;
3500 int num_channels
= 0, type_size
= 0;
3502 /* Extract array format type information from the OpenGL data type */
3504 case GL_UNSIGNED_BYTE
:
3511 case GL_UNSIGNED_SHORT
:
3518 case GL_UNSIGNED_INT
:
3526 case GL_HALF_FLOAT_OES
:
3537 is_array_format
= false;
3541 /* Extract array format swizzle information from the OpenGL format */
3542 if (is_array_format
)
3543 is_array_format
= get_swizzle_from_gl_format(format
, swizzle
);
3545 /* If this is an array format type after checking data type and format,
3546 * create the array format
3548 if (is_array_format
) {
3549 normalized
= !_mesa_is_enum_format_integer(format
);
3550 num_channels
= _mesa_components_in_format(format
);
3552 return MESA_ARRAY_FORMAT(type_size
, is_signed
, is_float
,
3553 normalized
, num_channels
,
3554 swizzle
[0], swizzle
[1], swizzle
[2], swizzle
[3]);
3557 /* Otherwise this is not an array format, so return the mesa_format
3558 * matching the OpenGL format and data type
3561 case GL_UNSIGNED_SHORT_5_6_5
:
3562 if (format
== GL_RGB
)
3563 return MESA_FORMAT_B5G6R5_UNORM
;
3564 else if (format
== GL_BGR
)
3565 return MESA_FORMAT_R5G6B5_UNORM
;
3566 else if (format
== GL_RGB_INTEGER
)
3567 return MESA_FORMAT_B5G6R5_UINT
;
3569 case GL_UNSIGNED_SHORT_5_6_5_REV
:
3570 if (format
== GL_RGB
)
3571 return MESA_FORMAT_R5G6B5_UNORM
;
3572 else if (format
== GL_BGR
)
3573 return MESA_FORMAT_B5G6R5_UNORM
;
3574 else if (format
== GL_RGB_INTEGER
)
3575 return MESA_FORMAT_R5G6B5_UINT
;
3577 case GL_UNSIGNED_SHORT_4_4_4_4
:
3578 if (format
== GL_RGBA
)
3579 return MESA_FORMAT_A4B4G4R4_UNORM
;
3580 else if (format
== GL_BGRA
)
3581 return MESA_FORMAT_A4R4G4B4_UNORM
;
3582 else if (format
== GL_ABGR_EXT
)
3583 return MESA_FORMAT_R4G4B4A4_UNORM
;
3584 else if (format
== GL_RGBA_INTEGER
)
3585 return MESA_FORMAT_A4B4G4R4_UINT
;
3586 else if (format
== GL_BGRA_INTEGER
)
3587 return MESA_FORMAT_A4R4G4B4_UINT
;
3589 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
3590 if (format
== GL_RGBA
)
3591 return MESA_FORMAT_R4G4B4A4_UNORM
;
3592 else if (format
== GL_BGRA
)
3593 return MESA_FORMAT_B4G4R4A4_UNORM
;
3594 else if (format
== GL_ABGR_EXT
)
3595 return MESA_FORMAT_A4B4G4R4_UNORM
;
3596 else if (format
== GL_RGBA_INTEGER
)
3597 return MESA_FORMAT_R4G4B4A4_UINT
;
3598 else if (format
== GL_BGRA_INTEGER
)
3599 return MESA_FORMAT_B4G4R4A4_UINT
;
3601 case GL_UNSIGNED_SHORT_5_5_5_1
:
3602 if (format
== GL_RGBA
)
3603 return MESA_FORMAT_A1B5G5R5_UNORM
;
3604 else if (format
== GL_BGRA
)
3605 return MESA_FORMAT_A1R5G5B5_UNORM
;
3606 else if (format
== GL_RGBA_INTEGER
)
3607 return MESA_FORMAT_A1B5G5R5_UINT
;
3608 else if (format
== GL_BGRA_INTEGER
)
3609 return MESA_FORMAT_A1R5G5B5_UINT
;
3611 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
3612 if (format
== GL_RGBA
)
3613 return MESA_FORMAT_R5G5B5A1_UNORM
;
3614 else if (format
== GL_BGRA
)
3615 return MESA_FORMAT_B5G5R5A1_UNORM
;
3616 else if (format
== GL_RGBA_INTEGER
)
3617 return MESA_FORMAT_R5G5B5A1_UINT
;
3618 else if (format
== GL_BGRA_INTEGER
)
3619 return MESA_FORMAT_B5G5R5A1_UINT
;
3621 case GL_UNSIGNED_BYTE_3_3_2
:
3622 if (format
== GL_RGB
)
3623 return MESA_FORMAT_B2G3R3_UNORM
;
3624 else if (format
== GL_RGB_INTEGER
)
3625 return MESA_FORMAT_B2G3R3_UINT
;
3627 case GL_UNSIGNED_BYTE_2_3_3_REV
:
3628 if (format
== GL_RGB
)
3629 return MESA_FORMAT_R3G3B2_UNORM
;
3630 else if (format
== GL_RGB_INTEGER
)
3631 return MESA_FORMAT_R3G3B2_UINT
;
3633 case GL_UNSIGNED_INT_5_9_9_9_REV
:
3634 if (format
== GL_RGB
)
3635 return MESA_FORMAT_R9G9B9E5_FLOAT
;
3637 case GL_UNSIGNED_INT_10_10_10_2
:
3638 if (format
== GL_RGBA
)
3639 return MESA_FORMAT_A2B10G10R10_UNORM
;
3640 else if (format
== GL_RGBA_INTEGER
)
3641 return MESA_FORMAT_A2B10G10R10_UINT
;
3642 else if (format
== GL_BGRA
)
3643 return MESA_FORMAT_A2R10G10B10_UNORM
;
3644 else if (format
== GL_BGRA_INTEGER
)
3645 return MESA_FORMAT_A2R10G10B10_UINT
;
3647 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3648 if (format
== GL_RGB
)
3649 return MESA_FORMAT_R10G10B10X2_UNORM
;
3650 if (format
== GL_RGBA
)
3651 return MESA_FORMAT_R10G10B10A2_UNORM
;
3652 else if (format
== GL_RGBA_INTEGER
)
3653 return MESA_FORMAT_R10G10B10A2_UINT
;
3654 else if (format
== GL_BGRA
)
3655 return MESA_FORMAT_B10G10R10A2_UNORM
;
3656 else if (format
== GL_BGRA_INTEGER
)
3657 return MESA_FORMAT_B10G10R10A2_UINT
;
3659 case GL_UNSIGNED_INT_8_8_8_8
:
3660 if (format
== GL_RGBA
)
3661 return MESA_FORMAT_A8B8G8R8_UNORM
;
3662 else if (format
== GL_BGRA
)
3663 return MESA_FORMAT_A8R8G8B8_UNORM
;
3664 else if (format
== GL_ABGR_EXT
)
3665 return MESA_FORMAT_R8G8B8A8_UNORM
;
3666 else if (format
== GL_RGBA_INTEGER
)
3667 return MESA_FORMAT_A8B8G8R8_UINT
;
3668 else if (format
== GL_BGRA_INTEGER
)
3669 return MESA_FORMAT_A8R8G8B8_UINT
;
3671 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3672 if (format
== GL_RGBA
)
3673 return MESA_FORMAT_R8G8B8A8_UNORM
;
3674 else if (format
== GL_BGRA
)
3675 return MESA_FORMAT_B8G8R8A8_UNORM
;
3676 else if (format
== GL_ABGR_EXT
)
3677 return MESA_FORMAT_A8B8G8R8_UNORM
;
3678 else if (format
== GL_RGBA_INTEGER
)
3679 return MESA_FORMAT_R8G8B8A8_UINT
;
3680 else if (format
== GL_BGRA_INTEGER
)
3681 return MESA_FORMAT_B8G8R8A8_UINT
;
3683 case GL_UNSIGNED_SHORT_8_8_MESA
:
3684 if (format
== GL_YCBCR_MESA
)
3685 return MESA_FORMAT_YCBCR
;
3687 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
3688 if (format
== GL_YCBCR_MESA
)
3689 return MESA_FORMAT_YCBCR_REV
;
3691 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
3692 if (format
== GL_RGB
)
3693 return MESA_FORMAT_R11G11B10_FLOAT
;
3696 if (format
== GL_DEPTH_COMPONENT
)
3697 return MESA_FORMAT_Z_FLOAT32
;
3699 case GL_UNSIGNED_INT
:
3700 if (format
== GL_DEPTH_COMPONENT
)
3701 return MESA_FORMAT_Z_UNORM32
;
3703 case GL_UNSIGNED_SHORT
:
3704 if (format
== GL_DEPTH_COMPONENT
)
3705 return MESA_FORMAT_Z_UNORM16
;
3707 case GL_UNSIGNED_INT_24_8
:
3708 if (format
== GL_DEPTH_STENCIL
)
3709 return MESA_FORMAT_Z24_UNORM_S8_UINT
;
3711 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
3712 if (format
== GL_DEPTH_STENCIL
)
3713 return MESA_FORMAT_Z32_FLOAT_S8X24_UINT
;
3719 /* If we got here it means that we could not find a Mesa format that
3720 * matches the GL format/type provided. We may need to add a new Mesa
3721 * format in that case.
3723 unreachable("Unsupported format");
3727 _mesa_tex_format_from_format_and_type(const struct gl_context
*ctx
,
3728 GLenum gl_format
, GLenum type
)
3730 mesa_format format
= _mesa_format_from_format_and_type(gl_format
, type
);
3732 if (_mesa_format_is_mesa_array_format(format
))
3733 format
= _mesa_format_from_array_format(format
);
3735 if (format
== MESA_FORMAT_NONE
|| !ctx
->TextureFormatSupported
[format
])
3736 return MESA_FORMAT_NONE
;
3742 * Returns true if \p internal_format is a sized internal format that
3743 * is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
3746 _mesa_is_es3_color_renderable(const struct gl_context
*ctx
,
3747 GLenum internal_format
)
3749 switch (internal_format
) {
3759 case GL_SRGB8_ALPHA8
:
3766 case GL_R11F_G11F_B10F
:
3789 return _mesa_has_EXT_texture_norm16(ctx
);
3792 case GL_RGBA8_SNORM
:
3793 return _mesa_has_EXT_render_snorm(ctx
);
3796 case GL_RGBA16_SNORM
:
3797 return _mesa_has_EXT_texture_norm16(ctx
) &&
3798 _mesa_has_EXT_render_snorm(ctx
);
3805 * Returns true if \p internal_format is a sized internal format that
3806 * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
3809 _mesa_is_es3_texture_filterable(const struct gl_context
*ctx
,
3810 GLenum internal_format
)
3812 switch (internal_format
) {
3823 case GL_RGBA8_SNORM
:
3826 case GL_SRGB8_ALPHA8
:
3831 case GL_R11F_G11F_B10F
:
3839 case GL_RGB16_SNORM
:
3841 case GL_RGBA16_SNORM
:
3842 return _mesa_has_EXT_texture_norm16(ctx
);
3847 /* The OES_texture_float_linear spec says:
3849 * "When implemented against OpenGL ES 3.0 or later versions, sized
3850 * 32-bit floating-point formats become texture-filterable. This
3851 * should be noted by, for example, checking the ``TF'' column of
3852 * table 8.13 in the ES 3.1 Specification (``Correspondence of sized
3853 * internal formats to base internal formats ... and use cases ...'')
3854 * for the R32F, RG32F, RGB32F, and RGBA32F formats."
3856 return _mesa_has_OES_texture_float_linear(ctx
);