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 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "glformats.h"
32 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
35 _mesa_type_is_packed(GLenum type
)
38 case GL_UNSIGNED_BYTE_3_3_2
:
39 case GL_UNSIGNED_BYTE_2_3_3_REV
:
40 case MESA_UNSIGNED_BYTE_4_4
:
41 case GL_UNSIGNED_SHORT_5_6_5
:
42 case GL_UNSIGNED_SHORT_5_6_5_REV
:
43 case GL_UNSIGNED_SHORT_4_4_4_4
:
44 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
45 case GL_UNSIGNED_SHORT_5_5_5_1
:
46 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
47 case GL_UNSIGNED_INT_8_8_8_8
:
48 case GL_UNSIGNED_INT_8_8_8_8_REV
:
49 case GL_UNSIGNED_INT_10_10_10_2
:
50 case GL_UNSIGNED_INT_2_10_10_10_REV
:
51 case GL_UNSIGNED_SHORT_8_8_MESA
:
52 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
53 case GL_UNSIGNED_INT_24_8_EXT
:
54 case GL_UNSIGNED_INT_5_9_9_9_REV
:
55 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
56 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
65 * Get the size of a GL data type.
67 * \param type GL data type.
69 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
70 * if an invalid type enum.
73 _mesa_sizeof_type(GLenum type
)
78 case GL_UNSIGNED_BYTE
:
79 return sizeof(GLubyte
);
81 return sizeof(GLbyte
);
82 case GL_UNSIGNED_SHORT
:
83 return sizeof(GLushort
);
85 return sizeof(GLshort
);
87 return sizeof(GLuint
);
91 return sizeof(GLfloat
);
93 return sizeof(GLdouble
);
94 case GL_HALF_FLOAT_ARB
:
95 return sizeof(GLhalfARB
);
97 return sizeof(GLfixed
);
105 * Same as _mesa_sizeof_type() but also accepting the packed pixel
109 _mesa_sizeof_packed_type(GLenum type
)
114 case GL_UNSIGNED_BYTE
:
115 return sizeof(GLubyte
);
117 return sizeof(GLbyte
);
118 case GL_UNSIGNED_SHORT
:
119 return sizeof(GLushort
);
121 return sizeof(GLshort
);
122 case GL_UNSIGNED_INT
:
123 return sizeof(GLuint
);
125 return sizeof(GLint
);
126 case GL_HALF_FLOAT_ARB
:
127 return sizeof(GLhalfARB
);
129 return sizeof(GLfloat
);
130 case GL_UNSIGNED_BYTE_3_3_2
:
131 case GL_UNSIGNED_BYTE_2_3_3_REV
:
132 case MESA_UNSIGNED_BYTE_4_4
:
133 return sizeof(GLubyte
);
134 case GL_UNSIGNED_SHORT_5_6_5
:
135 case GL_UNSIGNED_SHORT_5_6_5_REV
:
136 case GL_UNSIGNED_SHORT_4_4_4_4
:
137 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
138 case GL_UNSIGNED_SHORT_5_5_5_1
:
139 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
140 case GL_UNSIGNED_SHORT_8_8_MESA
:
141 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
142 return sizeof(GLushort
);
143 case GL_UNSIGNED_INT_8_8_8_8
:
144 case GL_UNSIGNED_INT_8_8_8_8_REV
:
145 case GL_UNSIGNED_INT_10_10_10_2
:
146 case GL_UNSIGNED_INT_2_10_10_10_REV
:
147 case GL_UNSIGNED_INT_24_8_EXT
:
148 case GL_UNSIGNED_INT_5_9_9_9_REV
:
149 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
150 return sizeof(GLuint
);
151 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
160 * Get the number of components in a pixel format.
162 * \param format pixel format.
164 * \return the number of components in the given format, or -1 if a bad format.
167 _mesa_components_in_format(GLenum format
)
171 case GL_STENCIL_INDEX
:
172 case GL_DEPTH_COMPONENT
:
174 case GL_RED_INTEGER_EXT
:
176 case GL_GREEN_INTEGER_EXT
:
178 case GL_BLUE_INTEGER_EXT
:
180 case GL_ALPHA_INTEGER_EXT
:
182 case GL_LUMINANCE_INTEGER_EXT
:
186 case GL_LUMINANCE_ALPHA
:
187 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
190 case GL_DEPTH_STENCIL_EXT
:
198 case GL_RGB_INTEGER_EXT
:
199 case GL_BGR_INTEGER_EXT
:
205 case GL_RGBA_INTEGER_EXT
:
206 case GL_BGRA_INTEGER_EXT
:
216 * Get the bytes per pixel of pixel format type pair.
218 * \param format pixel format.
219 * \param type pixel type.
221 * \return bytes per pixel, or -1 if a bad format or type was given.
224 _mesa_bytes_per_pixel(GLenum format
, GLenum type
)
226 GLint comps
= _mesa_components_in_format(format
);
232 return 0; /* special case */
234 case GL_UNSIGNED_BYTE
:
235 return comps
* sizeof(GLubyte
);
237 case GL_UNSIGNED_SHORT
:
238 return comps
* sizeof(GLshort
);
240 case GL_UNSIGNED_INT
:
241 return comps
* sizeof(GLint
);
243 return comps
* sizeof(GLfloat
);
244 case GL_HALF_FLOAT_ARB
:
245 return comps
* sizeof(GLhalfARB
);
246 case GL_UNSIGNED_BYTE_3_3_2
:
247 case GL_UNSIGNED_BYTE_2_3_3_REV
:
248 if (format
== GL_RGB
|| format
== GL_BGR
||
249 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
250 return sizeof(GLubyte
);
252 return -1; /* error */
253 case GL_UNSIGNED_SHORT_5_6_5
:
254 case GL_UNSIGNED_SHORT_5_6_5_REV
:
255 if (format
== GL_RGB
|| format
== GL_BGR
||
256 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
257 return sizeof(GLushort
);
259 return -1; /* error */
260 case GL_UNSIGNED_SHORT_4_4_4_4
:
261 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
262 case GL_UNSIGNED_SHORT_5_5_5_1
:
263 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
264 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
265 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
266 return sizeof(GLushort
);
269 case GL_UNSIGNED_INT_8_8_8_8
:
270 case GL_UNSIGNED_INT_8_8_8_8_REV
:
271 case GL_UNSIGNED_INT_10_10_10_2
:
272 case GL_UNSIGNED_INT_2_10_10_10_REV
:
273 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
274 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
275 return sizeof(GLuint
);
278 case GL_UNSIGNED_SHORT_8_8_MESA
:
279 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
280 if (format
== GL_YCBCR_MESA
)
281 return sizeof(GLushort
);
284 case GL_UNSIGNED_INT_24_8_EXT
:
285 if (format
== GL_DEPTH_STENCIL_EXT
)
286 return sizeof(GLuint
);
289 case GL_UNSIGNED_INT_5_9_9_9_REV
:
290 if (format
== GL_RGB
)
291 return sizeof(GLuint
);
294 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
295 if (format
== GL_RGB
)
296 return sizeof(GLuint
);
299 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
300 if (format
== GL_DEPTH_STENCIL
)
311 * Test if the given format is an integer (non-normalized) format.
314 _mesa_is_enum_format_integer(GLenum format
)
317 /* generic integer formats */
318 case GL_RED_INTEGER_EXT
:
319 case GL_GREEN_INTEGER_EXT
:
320 case GL_BLUE_INTEGER_EXT
:
321 case GL_ALPHA_INTEGER_EXT
:
322 case GL_RGB_INTEGER_EXT
:
323 case GL_RGBA_INTEGER_EXT
:
324 case GL_BGR_INTEGER_EXT
:
325 case GL_BGRA_INTEGER_EXT
:
326 case GL_LUMINANCE_INTEGER_EXT
:
327 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
329 /* specific integer formats */
330 case GL_RGBA32UI_EXT
:
334 case GL_ALPHA32UI_EXT
:
335 case GL_INTENSITY32UI_EXT
:
336 case GL_LUMINANCE32UI_EXT
:
337 case GL_LUMINANCE_ALPHA32UI_EXT
:
338 case GL_RGBA16UI_EXT
:
342 case GL_ALPHA16UI_EXT
:
343 case GL_INTENSITY16UI_EXT
:
344 case GL_LUMINANCE16UI_EXT
:
345 case GL_LUMINANCE_ALPHA16UI_EXT
:
350 case GL_ALPHA8UI_EXT
:
351 case GL_INTENSITY8UI_EXT
:
352 case GL_LUMINANCE8UI_EXT
:
353 case GL_LUMINANCE_ALPHA8UI_EXT
:
358 case GL_ALPHA32I_EXT
:
359 case GL_INTENSITY32I_EXT
:
360 case GL_LUMINANCE32I_EXT
:
361 case GL_LUMINANCE_ALPHA32I_EXT
:
366 case GL_ALPHA16I_EXT
:
367 case GL_INTENSITY16I_EXT
:
368 case GL_LUMINANCE16I_EXT
:
369 case GL_LUMINANCE_ALPHA16I_EXT
:
375 case GL_INTENSITY8I_EXT
:
376 case GL_LUMINANCE8I_EXT
:
377 case GL_LUMINANCE_ALPHA8I_EXT
:
387 * Test if the given type is an integer (non-normalized) format.
390 _mesa_is_type_integer(GLenum type
)
394 case GL_UNSIGNED_INT
:
396 case GL_UNSIGNED_SHORT
:
398 case GL_UNSIGNED_BYTE
:
407 * Test if the given format or type is an integer (non-normalized) format.
410 _mesa_is_enum_format_or_type_integer(GLenum format
, GLenum type
)
412 return _mesa_is_enum_format_integer(format
) || _mesa_is_type_integer(type
);
417 _mesa_is_type_unsigned(GLenum type
)
420 case GL_UNSIGNED_INT
:
421 case GL_UNSIGNED_INT_8_8_8_8
:
422 case GL_UNSIGNED_INT_8_8_8_8_REV
:
423 case GL_UNSIGNED_INT_10_10_10_2
:
424 case GL_UNSIGNED_INT_2_10_10_10_REV
:
426 case GL_UNSIGNED_SHORT
:
427 case GL_UNSIGNED_SHORT_4_4_4_4
:
428 case GL_UNSIGNED_SHORT_5_5_5_1
:
429 case GL_UNSIGNED_SHORT_5_6_5
:
430 case GL_UNSIGNED_SHORT_5_6_5_REV
:
431 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
432 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
433 case GL_UNSIGNED_SHORT_8_8_MESA
:
434 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
436 case GL_UNSIGNED_BYTE
:
437 case GL_UNSIGNED_BYTE_3_3_2
:
438 case GL_UNSIGNED_BYTE_2_3_3_REV
:
448 * Test if the given image format is a color/RGBA format (i.e., not color
449 * index, depth, stencil, etc).
450 * \param format the image format value (may by an internal texture format)
451 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
454 _mesa_is_color_format(GLenum format
)
472 case GL_LUMINANCE_ALPHA
:
473 case GL_LUMINANCE4_ALPHA4
:
474 case GL_LUMINANCE6_ALPHA2
:
475 case GL_LUMINANCE8_ALPHA8
:
476 case GL_LUMINANCE12_ALPHA4
:
477 case GL_LUMINANCE12_ALPHA12
:
478 case GL_LUMINANCE16_ALPHA16
:
511 /* float texture formats */
512 case GL_ALPHA16F_ARB
:
513 case GL_ALPHA32F_ARB
:
514 case GL_LUMINANCE16F_ARB
:
515 case GL_LUMINANCE32F_ARB
:
516 case GL_LUMINANCE_ALPHA16F_ARB
:
517 case GL_LUMINANCE_ALPHA32F_ARB
:
518 case GL_INTENSITY16F_ARB
:
519 case GL_INTENSITY32F_ARB
:
528 /* compressed formats */
529 case GL_COMPRESSED_ALPHA
:
530 case GL_COMPRESSED_LUMINANCE
:
531 case GL_COMPRESSED_LUMINANCE_ALPHA
:
532 case GL_COMPRESSED_INTENSITY
:
533 case GL_COMPRESSED_RED
:
534 case GL_COMPRESSED_RG
:
535 case GL_COMPRESSED_RGB
:
536 case GL_COMPRESSED_RGBA
:
541 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
542 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
543 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
544 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
545 case GL_COMPRESSED_RGB_FXT1_3DFX
:
546 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
549 case GL_SRGB_ALPHA_EXT
:
550 case GL_SRGB8_ALPHA8_EXT
:
551 case GL_SLUMINANCE_ALPHA_EXT
:
552 case GL_SLUMINANCE8_ALPHA8_EXT
:
553 case GL_SLUMINANCE_EXT
:
554 case GL_SLUMINANCE8_EXT
:
555 case GL_COMPRESSED_SRGB_EXT
:
556 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
557 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
558 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
559 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
560 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
561 case GL_COMPRESSED_SLUMINANCE_EXT
:
562 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
563 case GL_COMPRESSED_RED_RGTC1
:
564 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
565 case GL_COMPRESSED_RG_RGTC2
:
566 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
567 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
568 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
569 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
570 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
571 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
572 case GL_ETC1_RGB8_OES
:
573 /* generic integer formats */
574 case GL_RED_INTEGER_EXT
:
575 case GL_GREEN_INTEGER_EXT
:
576 case GL_BLUE_INTEGER_EXT
:
577 case GL_ALPHA_INTEGER_EXT
:
578 case GL_RGB_INTEGER_EXT
:
579 case GL_RGBA_INTEGER_EXT
:
580 case GL_BGR_INTEGER_EXT
:
581 case GL_BGRA_INTEGER_EXT
:
583 case GL_LUMINANCE_INTEGER_EXT
:
584 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
585 /* sized integer formats */
586 case GL_RGBA32UI_EXT
:
590 case GL_ALPHA32UI_EXT
:
591 case GL_INTENSITY32UI_EXT
:
592 case GL_LUMINANCE32UI_EXT
:
593 case GL_LUMINANCE_ALPHA32UI_EXT
:
594 case GL_RGBA16UI_EXT
:
598 case GL_ALPHA16UI_EXT
:
599 case GL_INTENSITY16UI_EXT
:
600 case GL_LUMINANCE16UI_EXT
:
601 case GL_LUMINANCE_ALPHA16UI_EXT
:
606 case GL_ALPHA8UI_EXT
:
607 case GL_INTENSITY8UI_EXT
:
608 case GL_LUMINANCE8UI_EXT
:
609 case GL_LUMINANCE_ALPHA8UI_EXT
:
614 case GL_ALPHA32I_EXT
:
615 case GL_INTENSITY32I_EXT
:
616 case GL_LUMINANCE32I_EXT
:
617 case GL_LUMINANCE_ALPHA32I_EXT
:
622 case GL_ALPHA16I_EXT
:
623 case GL_INTENSITY16I_EXT
:
624 case GL_LUMINANCE16I_EXT
:
625 case GL_LUMINANCE_ALPHA16I_EXT
:
631 case GL_INTENSITY8I_EXT
:
632 case GL_LUMINANCE8I_EXT
:
633 case GL_LUMINANCE_ALPHA8I_EXT
:
634 /* signed, normalized texture formats */
646 case GL_RGBA16_SNORM
:
648 case GL_ALPHA8_SNORM
:
649 case GL_ALPHA16_SNORM
:
650 case GL_LUMINANCE_SNORM
:
651 case GL_LUMINANCE8_SNORM
:
652 case GL_LUMINANCE16_SNORM
:
653 case GL_LUMINANCE_ALPHA_SNORM
:
654 case GL_LUMINANCE8_ALPHA8_SNORM
:
655 case GL_LUMINANCE16_ALPHA16_SNORM
:
656 case GL_INTENSITY_SNORM
:
657 case GL_INTENSITY8_SNORM
:
658 case GL_INTENSITY16_SNORM
:
660 case GL_R11F_G11F_B10F
:
663 case GL_YCBCR_MESA
: /* not considered to be RGB */
672 * Test if the given image format is a depth component format.
675 _mesa_is_depth_format(GLenum format
)
678 case GL_DEPTH_COMPONENT
:
679 case GL_DEPTH_COMPONENT16
:
680 case GL_DEPTH_COMPONENT24
:
681 case GL_DEPTH_COMPONENT32
:
682 case GL_DEPTH_COMPONENT32F
:
691 * Test if the given image format is a stencil format.
694 _mesa_is_stencil_format(GLenum format
)
697 case GL_STENCIL_INDEX
:
706 * Test if the given image format is a YCbCr format.
709 _mesa_is_ycbcr_format(GLenum format
)
721 * Test if the given image format is a depth+stencil format.
724 _mesa_is_depthstencil_format(GLenum format
)
727 case GL_DEPTH24_STENCIL8_EXT
:
728 case GL_DEPTH_STENCIL_EXT
:
729 case GL_DEPTH32F_STENCIL8
:
738 * Test if the given image format is a depth or stencil format.
741 _mesa_is_depth_or_stencil_format(GLenum format
)
744 case GL_DEPTH_COMPONENT
:
745 case GL_DEPTH_COMPONENT16
:
746 case GL_DEPTH_COMPONENT24
:
747 case GL_DEPTH_COMPONENT32
:
748 case GL_STENCIL_INDEX
:
749 case GL_STENCIL_INDEX1_EXT
:
750 case GL_STENCIL_INDEX4_EXT
:
751 case GL_STENCIL_INDEX8_EXT
:
752 case GL_STENCIL_INDEX16_EXT
:
753 case GL_DEPTH_STENCIL_EXT
:
754 case GL_DEPTH24_STENCIL8_EXT
:
755 case GL_DEPTH_COMPONENT32F
:
756 case GL_DEPTH32F_STENCIL8
:
765 * Test if the given image format is a dudv format.
768 _mesa_is_dudv_format(GLenum format
)
781 * Test if an image format is a supported compressed format.
782 * \param format the internal format token provided by the user.
783 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
786 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
789 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
790 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
791 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
792 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
793 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
794 return (_mesa_is_desktop_gl(ctx
) &&
795 ctx
->Extensions
.EXT_texture_compression_s3tc
) ||
796 (ctx
->API
== API_OPENGLES2
&&
797 ctx
->Extensions
.ANGLE_texture_compression_dxt
);
802 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.S3_s3tc
;
803 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
804 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
805 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
806 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
807 return _mesa_is_desktop_gl(ctx
)
808 && ctx
->Extensions
.EXT_texture_sRGB
809 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
810 case GL_COMPRESSED_RGB_FXT1_3DFX
:
811 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
812 return _mesa_is_desktop_gl(ctx
)
813 && ctx
->Extensions
.TDFX_texture_compression_FXT1
;
814 case GL_COMPRESSED_RED_RGTC1
:
815 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
816 case GL_COMPRESSED_RG_RGTC2
:
817 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
818 return _mesa_is_desktop_gl(ctx
)
819 && ctx
->Extensions
.ARB_texture_compression_rgtc
;
820 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
821 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
822 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
823 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
824 return ctx
->API
== API_OPENGL_COMPAT
825 && ctx
->Extensions
.EXT_texture_compression_latc
;
826 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
827 return ctx
->API
== API_OPENGL_COMPAT
828 && ctx
->Extensions
.ATI_texture_compression_3dc
;
829 case GL_ETC1_RGB8_OES
:
830 return _mesa_is_gles(ctx
)
831 && ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
832 case GL_PALETTE4_RGB8_OES
:
833 case GL_PALETTE4_RGBA8_OES
:
834 case GL_PALETTE4_R5_G6_B5_OES
:
835 case GL_PALETTE4_RGBA4_OES
:
836 case GL_PALETTE4_RGB5_A1_OES
:
837 case GL_PALETTE8_RGB8_OES
:
838 case GL_PALETTE8_RGBA8_OES
:
839 case GL_PALETTE8_R5_G6_B5_OES
:
840 case GL_PALETTE8_RGBA4_OES
:
841 case GL_PALETTE8_RGB5_A1_OES
:
842 return ctx
->API
== API_OPENGLES
;
850 * Convert various base formats to the cooresponding integer format.
853 _mesa_base_format_to_integer_format(GLenum format
)
857 return GL_RED_INTEGER
;
859 return GL_GREEN_INTEGER
;
861 return GL_BLUE_INTEGER
;
863 return GL_RG_INTEGER
;
865 return GL_RGB_INTEGER
;
867 return GL_RGBA_INTEGER
;
869 return GL_BGR_INTEGER
;
871 return GL_BGRA_INTEGER
;
873 return GL_ALPHA_INTEGER
;
875 return GL_LUMINANCE_INTEGER_EXT
;
876 case GL_LUMINANCE_ALPHA
:
877 return GL_LUMINANCE_ALPHA_INTEGER_EXT
;
885 * Does the given base texture/renderbuffer format have the channel
889 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
892 case GL_TEXTURE_RED_SIZE
:
893 case GL_TEXTURE_RED_TYPE
:
894 case GL_RENDERBUFFER_RED_SIZE_EXT
:
895 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
896 if (base_format
== GL_RED
||
897 base_format
== GL_RG
||
898 base_format
== GL_RGB
||
899 base_format
== GL_RGBA
) {
903 case GL_TEXTURE_GREEN_SIZE
:
904 case GL_TEXTURE_GREEN_TYPE
:
905 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
906 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
907 if (base_format
== GL_RG
||
908 base_format
== GL_RGB
||
909 base_format
== GL_RGBA
) {
913 case GL_TEXTURE_BLUE_SIZE
:
914 case GL_TEXTURE_BLUE_TYPE
:
915 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
916 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
917 if (base_format
== GL_RGB
||
918 base_format
== GL_RGBA
) {
922 case GL_TEXTURE_ALPHA_SIZE
:
923 case GL_TEXTURE_ALPHA_TYPE
:
924 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
925 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
926 if (base_format
== GL_RGBA
||
927 base_format
== GL_ALPHA
||
928 base_format
== GL_LUMINANCE_ALPHA
) {
932 case GL_TEXTURE_LUMINANCE_SIZE
:
933 case GL_TEXTURE_LUMINANCE_TYPE
:
934 if (base_format
== GL_LUMINANCE
||
935 base_format
== GL_LUMINANCE_ALPHA
) {
939 case GL_TEXTURE_INTENSITY_SIZE
:
940 case GL_TEXTURE_INTENSITY_TYPE
:
941 if (base_format
== GL_INTENSITY
) {
945 case GL_TEXTURE_DEPTH_SIZE
:
946 case GL_TEXTURE_DEPTH_TYPE
:
947 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
948 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
949 if (base_format
== GL_DEPTH_STENCIL
||
950 base_format
== GL_DEPTH_COMPONENT
) {
954 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
955 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
956 if (base_format
== GL_DEPTH_STENCIL
||
957 base_format
== GL_STENCIL_INDEX
) {
962 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
963 __FUNCTION__
, pname
);
972 * If format is a generic compressed format, return the corresponding
973 * non-compressed format. For other formats, return the format as-is.
976 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format
)
979 case GL_COMPRESSED_RED
:
981 case GL_COMPRESSED_RG
:
983 case GL_COMPRESSED_RGB
:
985 case GL_COMPRESSED_RGBA
:
987 case GL_COMPRESSED_ALPHA
:
989 case GL_COMPRESSED_LUMINANCE
:
991 case GL_COMPRESSED_LUMINANCE_ALPHA
:
992 return GL_LUMINANCE_ALPHA
;
993 case GL_COMPRESSED_INTENSITY
:
996 case GL_COMPRESSED_SRGB
:
998 case GL_COMPRESSED_SRGB_ALPHA
:
999 return GL_SRGB_ALPHA
;
1000 case GL_COMPRESSED_SLUMINANCE
:
1001 return GL_SLUMINANCE
;
1002 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
1003 return GL_SLUMINANCE_ALPHA
;
1011 * Return the equivalent non-generic internal format.
1012 * This is useful for comparing whether two internal formats are equivalent.
1015 _mesa_get_nongeneric_internalformat(GLenum format
)
1018 /* GL 1.1 formats. */
1028 case GL_LUMINANCE_ALPHA
:
1029 return GL_LUMINANCE8_ALPHA8
;
1033 return GL_LUMINANCE8
;
1039 return GL_INTENSITY8
;
1041 /* GL_ARB_texture_rg */
1048 /* GL_EXT_texture_sRGB */
1053 return GL_SRGB8_ALPHA8
;
1056 return GL_SLUMINANCE8
;
1058 case GL_SLUMINANCE_ALPHA
:
1059 return GL_SLUMINANCE8_ALPHA8
;
1061 /* GL_EXT_texture_snorm */
1063 return GL_RGBA8_SNORM
;
1066 return GL_RGB8_SNORM
;
1069 return GL_RG8_SNORM
;
1074 case GL_LUMINANCE_ALPHA_SNORM
:
1075 return GL_LUMINANCE8_ALPHA8_SNORM
;
1077 case GL_LUMINANCE_SNORM
:
1078 return GL_LUMINANCE8_SNORM
;
1080 case GL_ALPHA_SNORM
:
1081 return GL_ALPHA8_SNORM
;
1083 case GL_INTENSITY_SNORM
:
1084 return GL_INTENSITY8_SNORM
;
1093 * Convert an sRGB internal format to linear.
1096 _mesa_get_linear_internalformat(GLenum format
)
1108 case GL_SRGB8_ALPHA8
:
1112 return GL_LUMINANCE8
;
1114 case GL_SLUMINANCE_ALPHA
:
1115 return GL_LUMINANCE8_ALPHA8
;
1124 * Do error checking of format/type combinations for glReadPixels,
1125 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1126 * and type values, we may either generate GL_INVALID_OPERATION or
1129 * \param format pixel format.
1130 * \param type pixel type.
1132 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1135 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
1136 GLenum format
, GLenum type
)
1138 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1141 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
1142 return GL_INVALID_ENUM
;
1146 case GL_UNSIGNED_BYTE_3_3_2
:
1147 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1148 case GL_UNSIGNED_SHORT_5_6_5
:
1149 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1150 if (format
== GL_RGB
) {
1153 if (format
== GL_RGB_INTEGER_EXT
&&
1154 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1157 return GL_INVALID_OPERATION
;
1159 case GL_UNSIGNED_SHORT_4_4_4_4
:
1160 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1161 case GL_UNSIGNED_SHORT_5_5_5_1
:
1162 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1163 case GL_UNSIGNED_INT_8_8_8_8
:
1164 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1165 case GL_UNSIGNED_INT_10_10_10_2
:
1166 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1167 if (format
== GL_RGBA
||
1168 format
== GL_BGRA
||
1169 format
== GL_ABGR_EXT
) {
1172 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
1173 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
1176 return GL_INVALID_OPERATION
;
1178 case GL_UNSIGNED_INT_24_8
:
1179 if (!ctx
->Extensions
.EXT_packed_depth_stencil
) {
1180 return GL_INVALID_ENUM
;
1182 if (format
!= GL_DEPTH_STENCIL
) {
1183 return GL_INVALID_OPERATION
;
1187 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
1188 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
1189 return GL_INVALID_ENUM
;
1191 if (format
!= GL_DEPTH_STENCIL
) {
1192 return GL_INVALID_OPERATION
;
1196 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1197 if (!ctx
->Extensions
.EXT_packed_float
) {
1198 return GL_INVALID_ENUM
;
1200 if (format
!= GL_RGB
) {
1201 return GL_INVALID_OPERATION
;
1206 ; /* fall-through */
1209 /* now, for each format, check the type for compatibility */
1211 case GL_COLOR_INDEX
:
1212 case GL_STENCIL_INDEX
:
1216 case GL_UNSIGNED_BYTE
:
1218 case GL_UNSIGNED_SHORT
:
1220 case GL_UNSIGNED_INT
:
1224 return ctx
->Extensions
.ARB_half_float_pixel
1225 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1227 return GL_INVALID_ENUM
;
1234 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1238 case GL_LUMINANCE_ALPHA
:
1239 case GL_DEPTH_COMPONENT
:
1242 case GL_UNSIGNED_BYTE
:
1244 case GL_UNSIGNED_SHORT
:
1246 case GL_UNSIGNED_INT
:
1250 return ctx
->Extensions
.ARB_half_float_pixel
1251 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1253 return GL_INVALID_ENUM
;
1257 if (!ctx
->Extensions
.ARB_texture_rg
)
1258 return GL_INVALID_ENUM
;
1261 case GL_UNSIGNED_BYTE
:
1263 case GL_UNSIGNED_SHORT
:
1265 case GL_UNSIGNED_INT
:
1269 return ctx
->Extensions
.ARB_half_float_pixel
1270 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1272 return GL_INVALID_ENUM
;
1278 case GL_UNSIGNED_BYTE
:
1280 case GL_UNSIGNED_SHORT
:
1282 case GL_UNSIGNED_INT
:
1284 case GL_UNSIGNED_BYTE_3_3_2
:
1285 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1286 case GL_UNSIGNED_SHORT_5_6_5
:
1287 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1290 return ctx
->Extensions
.ARB_half_float_pixel
1291 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1292 case GL_UNSIGNED_INT_5_9_9_9_REV
:
1293 return ctx
->Extensions
.EXT_texture_shared_exponent
1294 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1295 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
1296 return ctx
->Extensions
.EXT_packed_float
1297 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1299 return GL_INVALID_ENUM
;
1304 /* NOTE: no packed types are supported with BGR. That's
1305 * intentional, according to the GL spec.
1308 case GL_UNSIGNED_BYTE
:
1310 case GL_UNSIGNED_SHORT
:
1312 case GL_UNSIGNED_INT
:
1316 return ctx
->Extensions
.ARB_half_float_pixel
1317 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1319 return GL_INVALID_ENUM
;
1327 case GL_UNSIGNED_BYTE
:
1329 case GL_UNSIGNED_SHORT
:
1331 case GL_UNSIGNED_INT
:
1333 case GL_UNSIGNED_SHORT_4_4_4_4
:
1334 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1335 case GL_UNSIGNED_SHORT_5_5_5_1
:
1336 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1337 case GL_UNSIGNED_INT_8_8_8_8
:
1338 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1339 case GL_UNSIGNED_INT_10_10_10_2
:
1340 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1343 return ctx
->Extensions
.ARB_half_float_pixel
1344 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1346 return GL_INVALID_ENUM
;
1350 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
1351 return GL_INVALID_ENUM
;
1352 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
1353 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
1356 return GL_INVALID_OPERATION
;
1358 case GL_DEPTH_STENCIL_EXT
:
1359 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
1360 type
== GL_UNSIGNED_INT_24_8
)
1362 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
1363 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
1366 return GL_INVALID_ENUM
;
1370 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
1371 return GL_INVALID_ENUM
;
1374 case GL_UNSIGNED_BYTE
:
1376 case GL_UNSIGNED_SHORT
:
1378 case GL_UNSIGNED_INT
:
1382 return GL_INVALID_ENUM
;
1385 /* integer-valued formats */
1386 case GL_RED_INTEGER_EXT
:
1387 case GL_GREEN_INTEGER_EXT
:
1388 case GL_BLUE_INTEGER_EXT
:
1389 case GL_ALPHA_INTEGER_EXT
:
1393 case GL_UNSIGNED_BYTE
:
1395 case GL_UNSIGNED_SHORT
:
1397 case GL_UNSIGNED_INT
:
1398 return (ctx
->Version
>= 30 ||
1399 ctx
->Extensions
.EXT_texture_integer
)
1400 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1402 return GL_INVALID_ENUM
;
1405 case GL_RGB_INTEGER_EXT
:
1408 case GL_UNSIGNED_BYTE
:
1410 case GL_UNSIGNED_SHORT
:
1412 case GL_UNSIGNED_INT
:
1413 return (ctx
->Version
>= 30 ||
1414 ctx
->Extensions
.EXT_texture_integer
)
1415 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1416 case GL_UNSIGNED_BYTE_3_3_2
:
1417 case GL_UNSIGNED_BYTE_2_3_3_REV
:
1418 case GL_UNSIGNED_SHORT_5_6_5
:
1419 case GL_UNSIGNED_SHORT_5_6_5_REV
:
1420 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1421 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1423 return GL_INVALID_ENUM
;
1426 case GL_BGR_INTEGER_EXT
:
1429 case GL_UNSIGNED_BYTE
:
1431 case GL_UNSIGNED_SHORT
:
1433 case GL_UNSIGNED_INT
:
1434 /* NOTE: no packed formats w/ BGR format */
1435 return (ctx
->Version
>= 30 ||
1436 ctx
->Extensions
.EXT_texture_integer
)
1437 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1439 return GL_INVALID_ENUM
;
1442 case GL_RGBA_INTEGER_EXT
:
1443 case GL_BGRA_INTEGER_EXT
:
1446 case GL_UNSIGNED_BYTE
:
1448 case GL_UNSIGNED_SHORT
:
1450 case GL_UNSIGNED_INT
:
1451 return (ctx
->Version
>= 30 ||
1452 ctx
->Extensions
.EXT_texture_integer
)
1453 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1454 case GL_UNSIGNED_SHORT_4_4_4_4
:
1455 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
1456 case GL_UNSIGNED_SHORT_5_5_5_1
:
1457 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
1458 case GL_UNSIGNED_INT_8_8_8_8
:
1459 case GL_UNSIGNED_INT_8_8_8_8_REV
:
1460 case GL_UNSIGNED_INT_10_10_10_2
:
1461 case GL_UNSIGNED_INT_2_10_10_10_REV
:
1462 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
1463 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1465 return GL_INVALID_ENUM
;
1468 case GL_LUMINANCE_INTEGER_EXT
:
1469 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1472 case GL_UNSIGNED_BYTE
:
1474 case GL_UNSIGNED_SHORT
:
1476 case GL_UNSIGNED_INT
:
1477 return ctx
->Extensions
.EXT_texture_integer
1478 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
1480 return GL_INVALID_ENUM
;
1484 return GL_INVALID_ENUM
;
1491 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1492 * and glTex[Sub]Image.
1493 * \return error code, or GL_NO_ERROR.
1496 _mesa_es_error_check_format_and_type(GLenum format
, GLenum type
,
1497 unsigned dimensions
)
1499 GLboolean type_valid
= GL_TRUE
;
1504 case GL_LUMINANCE_ALPHA
:
1505 type_valid
= (type
== GL_UNSIGNED_BYTE
1507 || type
== GL_HALF_FLOAT_OES
);
1511 type_valid
= (type
== GL_UNSIGNED_BYTE
1512 || type
== GL_UNSIGNED_SHORT_5_6_5
1514 || type
== GL_HALF_FLOAT_OES
);
1518 type_valid
= (type
== GL_UNSIGNED_BYTE
1519 || type
== GL_UNSIGNED_SHORT_4_4_4_4
1520 || type
== GL_UNSIGNED_SHORT_5_5_5_1
1522 || type
== GL_HALF_FLOAT_OES
1523 || type
== GL_UNSIGNED_INT_2_10_10_10_REV
);
1526 case GL_DEPTH_COMPONENT
:
1527 /* This format is filtered against invalid dimensionalities elsewhere.
1529 type_valid
= (type
== GL_UNSIGNED_SHORT
1530 || type
== GL_UNSIGNED_INT
);
1533 case GL_DEPTH_STENCIL
:
1534 /* This format is filtered against invalid dimensionalities elsewhere.
1536 type_valid
= (type
== GL_UNSIGNED_INT_24_8
);
1540 type_valid
= (type
== GL_UNSIGNED_BYTE
);
1542 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1543 * the format does not appear to be allowed for 3D textures in OpenGL
1546 if (dimensions
!= 2)
1547 return GL_INVALID_VALUE
;
1552 return GL_INVALID_VALUE
;
1555 return type_valid
? GL_NO_ERROR
: GL_INVALID_OPERATION
;