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:
1081
case GL_SRGB_ALPHA_EXT:
1082
case GL_SRGB8_ALPHA8_EXT:
1083
case GL_SLUMINANCE_ALPHA_EXT:
1084
case GL_SLUMINANCE8_ALPHA8_EXT:
1085
case GL_SLUMINANCE_EXT:
1086
case GL_SLUMINANCE8_EXT:
1087
case GL_COMPRESSED_SRGB_EXT:
1088
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1089
case GL_COMPRESSED_SRGB_ALPHA_EXT:
1090
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1091
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1092
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1093
case GL_COMPRESSED_SLUMINANCE_EXT:
1094
case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
1095
case GL_COMPRESSED_RED_RGTC1:
1096
case GL_COMPRESSED_SIGNED_RED_RGTC1:
1097
case GL_COMPRESSED_RG_RGTC2:
1098
case GL_COMPRESSED_SIGNED_RG_RGTC2:
1099
case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
1100
case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
1101
case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
1102
case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
1103
case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1104
case GL_ETC1_RGB8_OES:
1105
case GL_COMPRESSED_RGB8_ETC2:
1106
case GL_COMPRESSED_SRGB8_ETC2:
1107
case GL_COMPRESSED_RGBA8_ETC2_EAC:
1108
case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1109
case GL_COMPRESSED_R11_EAC:
1110
case GL_COMPRESSED_RG11_EAC:
1111
case GL_COMPRESSED_SIGNED_R11_EAC:
1112
case GL_COMPRESSED_SIGNED_RG11_EAC:
1113
case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1114
case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1115
case GL_COMPRESSED_RGBA_BPTC_UNORM:
1116
case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
1117
case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
1118
case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
1119
case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
1120
case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
1121
case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
1122
case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
1123
case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
1124
case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
1125
case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
1126
case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
1127
case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
1128
case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
1129
case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
1130
case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
1131
case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
1132
case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
1133
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1134
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1135
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1136
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1137
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1138
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1139
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1140
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1141
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1142
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1143
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1144
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1145
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1146
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1147
case GL_ATC_RGB_AMD:
1148
case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
1149
case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
1150
/* generic integer formats */
1151
case GL_RED_INTEGER_EXT:
1152
case GL_GREEN_INTEGER_EXT:
1153
case GL_BLUE_INTEGER_EXT:
1154
case GL_ALPHA_INTEGER_EXT:
1155
case GL_RGB_INTEGER_EXT:
1156
case GL_RGBA_INTEGER_EXT:
1157
case GL_BGR_INTEGER_EXT:
1158
case GL_BGRA_INTEGER_EXT:
1160
case GL_LUMINANCE_INTEGER_EXT:
1161
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
1162
/* sized integer formats */
1163
case GL_RGBA32UI_EXT:
1164
case GL_RGB32UI_EXT:
1167
case GL_ALPHA32UI_EXT:
1168
case GL_INTENSITY32UI_EXT:
1169
case GL_LUMINANCE32UI_EXT:
1170
case GL_LUMINANCE_ALPHA32UI_EXT:
1171
case GL_RGBA16UI_EXT:
1172
case GL_RGB16UI_EXT:
1175
case GL_ALPHA16UI_EXT:
1176
case GL_INTENSITY16UI_EXT:
1177
case GL_LUMINANCE16UI_EXT:
1178
case GL_LUMINANCE_ALPHA16UI_EXT:
1179
case GL_RGBA8UI_EXT:
1183
case GL_ALPHA8UI_EXT:
1184
case GL_INTENSITY8UI_EXT:
1185
case GL_LUMINANCE8UI_EXT:
1186
case GL_LUMINANCE_ALPHA8UI_EXT:
1187
case GL_RGBA32I_EXT:
1191
case GL_ALPHA32I_EXT:
1192
case GL_INTENSITY32I_EXT:
1193
case GL_LUMINANCE32I_EXT:
1194
case GL_LUMINANCE_ALPHA32I_EXT:
1195
case GL_RGBA16I_EXT:
1199
case GL_ALPHA16I_EXT:
1200
case GL_INTENSITY16I_EXT:
1201
case GL_LUMINANCE16I_EXT:
1202
case GL_LUMINANCE_ALPHA16I_EXT:
1207
case GL_ALPHA8I_EXT:
1208
case GL_INTENSITY8I_EXT:
1209
case GL_LUMINANCE8I_EXT:
1210
case GL_LUMINANCE_ALPHA8I_EXT:
1211
/* signed, normalized texture formats */
1220
case GL_RGB16_SNORM:
1222
case GL_RGBA8_SNORM:
1223
case GL_RGBA16_SNORM:
1224
case GL_ALPHA_SNORM:
1225
case GL_ALPHA8_SNORM:
1226
case GL_ALPHA16_SNORM:
1227
case GL_LUMINANCE_SNORM:
1228
case GL_LUMINANCE8_SNORM:
1229
case GL_LUMINANCE16_SNORM:
1230
case GL_LUMINANCE_ALPHA_SNORM:
1231
case GL_LUMINANCE8_ALPHA8_SNORM:
1232
case GL_LUMINANCE16_ALPHA16_SNORM:
1233
case GL_INTENSITY_SNORM:
1234
case GL_INTENSITY8_SNORM:
1235
case GL_INTENSITY16_SNORM:
1237
case GL_R11F_G11F_B10F:
1240
case GL_YCBCR_MESA: /* not considered to be RGB */
1249
* Test if the given image format is a depth component format.
1252
_mesa_is_depth_format(GLenum format)
1255
case GL_DEPTH_COMPONENT:
1256
case GL_DEPTH_COMPONENT16:
1257
case GL_DEPTH_COMPONENT24:
1258
case GL_DEPTH_COMPONENT32:
1259
case GL_DEPTH_COMPONENT32F:
1268
* Test if the given image format is a stencil format.
1271
_mesa_is_stencil_format(GLenum format)
1274
case GL_STENCIL_INDEX:
1283
* Test if the given image format is a YCbCr format.
1286
_mesa_is_ycbcr_format(GLenum format)
1298
* Test if the given image format is a depth+stencil format.
1301
_mesa_is_depthstencil_format(GLenum format)
1304
case GL_DEPTH24_STENCIL8_EXT:
1305
case GL_DEPTH_STENCIL_EXT:
1306
case GL_DEPTH32F_STENCIL8:
1315
* Test if the given image format is a depth or stencil format.
1318
_mesa_is_depth_or_stencil_format(GLenum format)
1321
case GL_DEPTH_COMPONENT:
1322
case GL_DEPTH_COMPONENT16:
1323
case GL_DEPTH_COMPONENT24:
1324
case GL_DEPTH_COMPONENT32:
1325
case GL_STENCIL_INDEX:
1326
case GL_STENCIL_INDEX1_EXT:
1327
case GL_STENCIL_INDEX4_EXT:
1328
case GL_STENCIL_INDEX8_EXT:
1329
case GL_STENCIL_INDEX16_EXT:
1330
case GL_DEPTH_STENCIL_EXT:
1331
case GL_DEPTH24_STENCIL8_EXT:
1332
case GL_DEPTH_COMPONENT32F:
1333
case GL_DEPTH32F_STENCIL8:
1341
* Test if the given image format has a floating-point depth component.
1344
_mesa_has_depth_float_channel(GLenum internalFormat)
1346
return internalFormat == GL_DEPTH32F_STENCIL8 ||
1347
internalFormat == GL_DEPTH_COMPONENT32F;
1351
* Test if an image format is a supported compressed format.
1352
* \param format the internal format token provided by the user.
1353
* \return GL_TRUE if compressed, GL_FALSE if uncompressed
1356
_mesa_is_compressed_format(const struct gl_context *ctx, GLenum format)
1358
mesa_format m_format = _mesa_glenum_to_compressed_format(format);
1360
/* Some formats in this switch have an equivalent mesa_format_layout
1361
* to the compressed formats in the layout switch below and thus
1362
* must be handled first.
1369
return _mesa_has_S3_s3tc(ctx);
1370
case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1371
return _mesa_has_ATI_texture_compression_3dc(ctx);
1372
case GL_PALETTE4_RGB8_OES:
1373
case GL_PALETTE4_RGBA8_OES:
1374
case GL_PALETTE4_R5_G6_B5_OES:
1375
case GL_PALETTE4_RGBA4_OES:
1376
case GL_PALETTE4_RGB5_A1_OES:
1377
case GL_PALETTE8_RGB8_OES:
1378
case GL_PALETTE8_RGBA8_OES:
1379
case GL_PALETTE8_R5_G6_B5_OES:
1380
case GL_PALETTE8_RGBA4_OES:
1381
case GL_PALETTE8_RGB5_A1_OES:
1382
return ctx->API == API_OPENGLES;
1385
switch (_mesa_get_format_layout(m_format)) {
1386
case MESA_FORMAT_LAYOUT_S3TC:
1387
if (!_mesa_is_format_srgb(m_format)) {
1388
return _mesa_has_EXT_texture_compression_s3tc(ctx);
1390
return (_mesa_has_EXT_texture_sRGB(ctx) ||
1391
_mesa_has_EXT_texture_compression_s3tc_srgb(ctx)) &&
1392
_mesa_has_EXT_texture_compression_s3tc(ctx);
1394
case MESA_FORMAT_LAYOUT_FXT1:
1395
return _mesa_has_3DFX_texture_compression_FXT1(ctx);
1396
case MESA_FORMAT_LAYOUT_RGTC:
1397
return _mesa_has_ARB_texture_compression_rgtc(ctx) ||
1398
_mesa_has_EXT_texture_compression_rgtc(ctx);
1399
case MESA_FORMAT_LAYOUT_LATC:
1400
return _mesa_has_EXT_texture_compression_latc(ctx);
1401
case MESA_FORMAT_LAYOUT_ETC1:
1402
return _mesa_has_OES_compressed_ETC1_RGB8_texture(ctx);
1403
case MESA_FORMAT_LAYOUT_ETC2:
1404
return _mesa_is_gles3(ctx) || _mesa_has_ARB_ES3_compatibility(ctx);
1405
case MESA_FORMAT_LAYOUT_BPTC:
1406
return _mesa_has_ARB_texture_compression_bptc(ctx) ||
1407
_mesa_has_EXT_texture_compression_bptc(ctx);
1408
case MESA_FORMAT_LAYOUT_ASTC:
1409
return _mesa_has_KHR_texture_compression_astc_ldr(ctx);
1410
case MESA_FORMAT_LAYOUT_ATC:
1411
return _mesa_has_AMD_compressed_ATC_texture(ctx);
1418
* Test if the given format represents an sRGB format.
1419
* \param format the GL format (can be an internal format)
1420
* \return GL_TRUE if format is sRGB, GL_FALSE otherwise
1423
_mesa_is_srgb_format(GLenum format)
1431
case GL_SRGB8_ALPHA8:
1432
case GL_COMPRESSED_SRGB:
1433
case GL_COMPRESSED_SRGB_ALPHA:
1434
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1435
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1436
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1437
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1438
case GL_COMPRESSED_SRGB8_ETC2:
1439
case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
1440
case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
1441
case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
1442
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
1443
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
1444
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
1445
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
1446
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
1447
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
1448
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
1449
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
1450
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
1451
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
1452
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
1453
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
1454
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
1455
case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
1465
* Convert various unpack formats to the corresponding base format.
1468
_mesa_unpack_format_to_base_format(GLenum format)
1471
case GL_RED_INTEGER:
1473
case GL_GREEN_INTEGER:
1475
case GL_BLUE_INTEGER:
1477
case GL_ALPHA_INTEGER:
1481
case GL_RGB_INTEGER:
1483
case GL_RGBA_INTEGER:
1485
case GL_BGR_INTEGER:
1487
case GL_BGRA_INTEGER:
1489
case GL_LUMINANCE_INTEGER_EXT:
1490
return GL_LUMINANCE;
1491
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
1492
return GL_LUMINANCE_ALPHA;
1503
case GL_LUMINANCE_ALPHA:
1510
* Convert various base formats to the corresponding integer format.
1513
_mesa_base_format_to_integer_format(GLenum format)
1517
return GL_RED_INTEGER;
1519
return GL_GREEN_INTEGER;
1521
return GL_BLUE_INTEGER;
1523
return GL_RG_INTEGER;
1525
return GL_RGB_INTEGER;
1527
return GL_RGBA_INTEGER;
1529
return GL_BGR_INTEGER;
1531
return GL_BGRA_INTEGER;
1533
return GL_ALPHA_INTEGER;
1535
return GL_LUMINANCE_INTEGER_EXT;
1536
case GL_LUMINANCE_ALPHA:
1537
return GL_LUMINANCE_ALPHA_INTEGER_EXT;
1545
* Does the given base texture/renderbuffer format have the channel
1549
_mesa_base_format_has_channel(GLenum base_format, GLenum pname)
1552
case GL_TEXTURE_RED_SIZE:
1553
case GL_TEXTURE_RED_TYPE:
1554
case GL_RENDERBUFFER_RED_SIZE_EXT:
1555
case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1556
case GL_INTERNALFORMAT_RED_SIZE:
1557
case GL_INTERNALFORMAT_RED_TYPE:
1558
if (base_format == GL_RED ||
1559
base_format == GL_RG ||
1560
base_format == GL_RGB ||
1561
base_format == GL_RGBA) {
1565
case GL_TEXTURE_GREEN_SIZE:
1566
case GL_TEXTURE_GREEN_TYPE:
1567
case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1568
case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1569
case GL_INTERNALFORMAT_GREEN_SIZE:
1570
case GL_INTERNALFORMAT_GREEN_TYPE:
1571
if (base_format == GL_RG ||
1572
base_format == GL_RGB ||
1573
base_format == GL_RGBA) {
1577
case GL_TEXTURE_BLUE_SIZE:
1578
case GL_TEXTURE_BLUE_TYPE:
1579
case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1580
case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1581
case GL_INTERNALFORMAT_BLUE_SIZE:
1582
case GL_INTERNALFORMAT_BLUE_TYPE:
1583
if (base_format == GL_RGB ||
1584
base_format == GL_RGBA) {
1588
case GL_TEXTURE_ALPHA_SIZE:
1589
case GL_TEXTURE_ALPHA_TYPE:
1590
case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1591
case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1592
case GL_INTERNALFORMAT_ALPHA_SIZE:
1593
case GL_INTERNALFORMAT_ALPHA_TYPE:
1594
if (base_format == GL_RGBA ||
1595
base_format == GL_ALPHA ||
1596
base_format == GL_LUMINANCE_ALPHA) {
1600
case GL_TEXTURE_LUMINANCE_SIZE:
1601
case GL_TEXTURE_LUMINANCE_TYPE:
1602
if (base_format == GL_LUMINANCE ||
1603
base_format == GL_LUMINANCE_ALPHA) {
1607
case GL_TEXTURE_INTENSITY_SIZE:
1608
case GL_TEXTURE_INTENSITY_TYPE:
1609
if (base_format == GL_INTENSITY) {
1613
case GL_TEXTURE_DEPTH_SIZE:
1614
case GL_TEXTURE_DEPTH_TYPE:
1615
case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1616
case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1617
case GL_INTERNALFORMAT_DEPTH_SIZE:
1618
case GL_INTERNALFORMAT_DEPTH_TYPE:
1619
if (base_format == GL_DEPTH_STENCIL ||
1620
base_format == GL_DEPTH_COMPONENT) {
1624
case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1625
case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1626
case GL_INTERNALFORMAT_STENCIL_SIZE:
1627
case GL_INTERNALFORMAT_STENCIL_TYPE:
1628
if (base_format == GL_DEPTH_STENCIL ||
1629
base_format == GL_STENCIL_INDEX) {
1634
_mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n",
1644
* If format is a generic compressed format, return the corresponding
1645
* non-compressed format. For other formats, return the format as-is.
1648
_mesa_generic_compressed_format_to_uncompressed_format(GLenum format)
1651
case GL_COMPRESSED_RED:
1653
case GL_COMPRESSED_RG:
1655
case GL_COMPRESSED_RGB:
1657
case GL_COMPRESSED_RGBA:
1659
case GL_COMPRESSED_ALPHA:
1661
case GL_COMPRESSED_LUMINANCE:
1662
return GL_LUMINANCE;
1663
case GL_COMPRESSED_LUMINANCE_ALPHA:
1664
return GL_LUMINANCE_ALPHA;
1665
case GL_COMPRESSED_INTENSITY:
1666
return GL_INTENSITY;
1668
case GL_COMPRESSED_SRGB:
1670
case GL_COMPRESSED_SRGB_ALPHA:
1671
return GL_SRGB_ALPHA;
1672
case GL_COMPRESSED_SLUMINANCE:
1673
return GL_SLUMINANCE;
1674
case GL_COMPRESSED_SLUMINANCE_ALPHA:
1675
return GL_SLUMINANCE_ALPHA;
1683
* Return the equivalent non-generic internal format.
1684
* This is useful for comparing whether two internal formats are equivalent.
1687
_mesa_get_nongeneric_internalformat(GLenum format)
1690
/* GL 1.1 formats. */
1698
case GL_LUMINANCE_ALPHA:
1699
return GL_LUMINANCE8_ALPHA8;
1702
return GL_LUMINANCE8;
1706
return GL_INTENSITY8;
1708
/* GL_ARB_texture_rg */
1714
/* GL_EXT_texture_sRGB */
1718
return GL_SRGB8_ALPHA8;
1720
return GL_SLUMINANCE8;
1721
case GL_SLUMINANCE_ALPHA:
1722
return GL_SLUMINANCE8_ALPHA8;
1724
/* GL_EXT_texture_snorm */
1726
return GL_RGBA8_SNORM;
1728
return GL_RGB8_SNORM;
1730
return GL_RG8_SNORM;
1733
case GL_LUMINANCE_ALPHA_SNORM:
1734
return GL_LUMINANCE8_ALPHA8_SNORM;
1735
case GL_LUMINANCE_SNORM:
1736
return GL_LUMINANCE8_SNORM;
1737
case GL_ALPHA_SNORM:
1738
return GL_ALPHA8_SNORM;
1739
case GL_INTENSITY_SNORM:
1740
return GL_INTENSITY8_SNORM;
1749
* Convert an sRGB internal format to linear.
1752
_mesa_get_linear_internalformat(GLenum format)
1761
case GL_SRGB8_ALPHA8:
1763
case GL_SLUMINANCE8:
1764
return GL_LUMINANCE8;
1766
return GL_LUMINANCE;
1767
case GL_SLUMINANCE_ALPHA:
1768
return GL_LUMINANCE_ALPHA;
1769
case GL_SLUMINANCE8_ALPHA8:
1770
return GL_LUMINANCE8_ALPHA8;
1778
* Do error checking of format/type combinations for glReadPixels,
1779
* glDrawPixels and glTex[Sub]Image. Note that depending on the format
1780
* and type values, we may either generate GL_INVALID_OPERATION or
1783
* \param format pixel format.
1784
* \param type pixel type.
1786
* \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1789
_mesa_error_check_format_and_type(const struct gl_context *ctx,
1790
GLenum format, GLenum type)
1792
/* From OpenGL 3.3 spec, page 220:
1793
* "If the format is DEPTH_STENCIL, then values are taken from
1794
* both the depth buffer and the stencil buffer. If there is no
1795
* depth buffer or if there is no stencil buffer, then the error
1796
* INVALID_OPERATION occurs. If the type parameter is not
1797
* UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
1798
* error INVALID_ENUM occurs."
1800
* OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
1801
* cannot be used to read depth or stencil in that API.
1803
if (_mesa_is_desktop_gl(ctx) && format == GL_DEPTH_STENCIL
1804
&& type != GL_UNSIGNED_INT_24_8
1805
&& type != GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
1806
return GL_INVALID_ENUM;
1808
/* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1811
if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) {
1812
return GL_INVALID_ENUM;
1816
case GL_UNSIGNED_BYTE_3_3_2:
1817
case GL_UNSIGNED_BYTE_2_3_3_REV:
1818
case GL_UNSIGNED_SHORT_5_6_5:
1819
case GL_UNSIGNED_SHORT_5_6_5_REV:
1820
if (format == GL_RGB) {
1823
if (format == GL_RGB_INTEGER_EXT &&
1824
_mesa_has_texture_rgb10_a2ui(ctx)) {
1827
return GL_INVALID_OPERATION;
1829
case GL_UNSIGNED_SHORT_4_4_4_4:
1830
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1831
case GL_UNSIGNED_INT_8_8_8_8:
1832
case GL_UNSIGNED_INT_8_8_8_8_REV:
1833
if (format == GL_RGBA ||
1834
format == GL_BGRA ||
1835
format == GL_ABGR_EXT) {
1838
if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
1839
_mesa_has_texture_rgb10_a2ui(ctx)) {
1842
return GL_INVALID_OPERATION;
1844
case GL_UNSIGNED_SHORT_5_5_5_1:
1845
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1846
case GL_UNSIGNED_INT_10_10_10_2:
1847
case GL_UNSIGNED_INT_2_10_10_10_REV:
1848
if (format == GL_RGBA ||
1849
format == GL_BGRA) {
1852
if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
1853
_mesa_has_texture_rgb10_a2ui(ctx)) {
1856
if (type == GL_UNSIGNED_INT_2_10_10_10_REV && format == GL_RGB &&
1857
ctx->API == API_OPENGLES2) {
1858
break; /* OK by GL_EXT_texture_type_2_10_10_10_REV */
1860
return GL_INVALID_OPERATION;
1862
case GL_UNSIGNED_INT_24_8:
1863
/* Depth buffer OK to read in OpenGL ES (NV_read_depth). */
1864
if (ctx->API == API_OPENGLES2 && format == GL_DEPTH_COMPONENT)
1867
if (format != GL_DEPTH_STENCIL) {
1868
return GL_INVALID_OPERATION;
1872
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1873
if (!_mesa_has_float_depth_buffer(ctx)) {
1874
return GL_INVALID_ENUM;
1876
if (format != GL_DEPTH_STENCIL) {
1877
return GL_INVALID_OPERATION;
1881
case GL_UNSIGNED_INT_10F_11F_11F_REV:
1882
if (!_mesa_has_packed_float(ctx)) {
1883
return GL_INVALID_ENUM;
1885
if (format != GL_RGB) {
1886
return GL_INVALID_OPERATION;
1890
case GL_HALF_FLOAT_OES:
1894
case GL_LUMINANCE_ALPHA:
1900
if (_mesa_has_rg_textures(ctx))
1904
return GL_INVALID_OPERATION;
1908
; /* fall-through */
1911
/* now, for each format, check the type for compatibility */
1913
case GL_COLOR_INDEX:
1914
case GL_STENCIL_INDEX:
1918
case GL_UNSIGNED_BYTE:
1920
case GL_UNSIGNED_SHORT:
1922
case GL_UNSIGNED_INT:
1927
return GL_INVALID_ENUM;
1934
#if 0 /* not legal! see table 3.6 of the 1.5 spec */
1938
case GL_LUMINANCE_ALPHA:
1939
case GL_DEPTH_COMPONENT:
1942
case GL_UNSIGNED_BYTE:
1944
case GL_UNSIGNED_SHORT:
1946
case GL_UNSIGNED_INT:
1951
return GL_INVALID_ENUM;
1955
if (!_mesa_has_rg_textures(ctx))
1956
return GL_INVALID_ENUM;
1959
case GL_UNSIGNED_BYTE:
1961
case GL_UNSIGNED_SHORT:
1963
case GL_UNSIGNED_INT:
1968
return GL_INVALID_ENUM;
1974
case GL_UNSIGNED_BYTE:
1976
case GL_UNSIGNED_SHORT:
1978
case GL_UNSIGNED_INT:
1980
case GL_UNSIGNED_BYTE_3_3_2:
1981
case GL_UNSIGNED_BYTE_2_3_3_REV:
1982
case GL_UNSIGNED_SHORT_5_6_5:
1983
case GL_UNSIGNED_SHORT_5_6_5_REV:
1986
case GL_UNSIGNED_INT_2_10_10_10_REV:
1987
/* OK by GL_EXT_texture_type_2_10_10_10_REV */
1988
return (ctx->API == API_OPENGLES2)
1989
? GL_NO_ERROR : GL_INVALID_ENUM;
1990
case GL_UNSIGNED_INT_5_9_9_9_REV:
1991
return _mesa_has_texture_shared_exponent(ctx)
1992
? GL_NO_ERROR : GL_INVALID_ENUM;
1993
case GL_UNSIGNED_INT_10F_11F_11F_REV:
1994
return _mesa_has_packed_float(ctx)
1995
? GL_NO_ERROR : GL_INVALID_ENUM;
1997
return GL_INVALID_ENUM;
2002
/* NOTE: no packed types are supported with BGR. That's
2003
* intentional, according to the GL spec.
2006
case GL_UNSIGNED_BYTE:
2008
case GL_UNSIGNED_SHORT:
2010
case GL_UNSIGNED_INT:
2015
return GL_INVALID_ENUM;
2022
case GL_UNSIGNED_BYTE:
2024
case GL_UNSIGNED_SHORT:
2026
case GL_UNSIGNED_INT:
2028
case GL_UNSIGNED_SHORT_4_4_4_4:
2029
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2030
case GL_UNSIGNED_SHORT_5_5_5_1:
2031
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2032
case GL_UNSIGNED_INT_8_8_8_8:
2033
case GL_UNSIGNED_INT_8_8_8_8_REV:
2034
case GL_UNSIGNED_INT_10_10_10_2:
2035
case GL_UNSIGNED_INT_2_10_10_10_REV:
2039
return GL_INVALID_ENUM;
2045
case GL_UNSIGNED_BYTE:
2047
case GL_UNSIGNED_SHORT:
2049
case GL_UNSIGNED_INT:
2051
case GL_UNSIGNED_SHORT_4_4_4_4:
2052
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2053
case GL_UNSIGNED_INT_8_8_8_8:
2054
case GL_UNSIGNED_INT_8_8_8_8_REV:
2058
return GL_INVALID_ENUM;
2062
if (!_mesa_has_MESA_ycbcr_texture(ctx))
2063
return GL_INVALID_ENUM;
2064
if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
2065
type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
2068
return GL_INVALID_OPERATION;
2070
case GL_DEPTH_STENCIL:
2071
if (type == GL_UNSIGNED_INT_24_8)
2073
else if (_mesa_has_float_depth_buffer(ctx) &&
2074
type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
2077
return GL_INVALID_ENUM;
2079
/* integer-valued formats */
2080
case GL_RED_INTEGER_EXT:
2081
case GL_GREEN_INTEGER_EXT:
2082
case GL_BLUE_INTEGER_EXT:
2083
case GL_ALPHA_INTEGER_EXT:
2087
case GL_UNSIGNED_BYTE:
2089
case GL_UNSIGNED_SHORT:
2091
case GL_UNSIGNED_INT:
2092
return _mesa_has_integer_textures(ctx)
2093
? GL_NO_ERROR : GL_INVALID_ENUM;
2095
return GL_INVALID_ENUM;
2098
case GL_RGB_INTEGER_EXT:
2101
case GL_UNSIGNED_BYTE:
2103
case GL_UNSIGNED_SHORT:
2105
case GL_UNSIGNED_INT:
2106
return _mesa_has_integer_textures(ctx)
2107
? GL_NO_ERROR : GL_INVALID_ENUM;
2108
case GL_UNSIGNED_BYTE_3_3_2:
2109
case GL_UNSIGNED_BYTE_2_3_3_REV:
2110
case GL_UNSIGNED_SHORT_5_6_5:
2111
case GL_UNSIGNED_SHORT_5_6_5_REV:
2112
return _mesa_has_texture_rgb10_a2ui(ctx)
2113
? GL_NO_ERROR : GL_INVALID_ENUM;
2115
return GL_INVALID_ENUM;
2118
case GL_BGR_INTEGER_EXT:
2121
case GL_UNSIGNED_BYTE:
2123
case GL_UNSIGNED_SHORT:
2125
case GL_UNSIGNED_INT:
2126
/* NOTE: no packed formats w/ BGR format */
2127
return _mesa_has_integer_textures(ctx)
2128
? GL_NO_ERROR : GL_INVALID_ENUM;
2130
return GL_INVALID_ENUM;
2133
case GL_RGBA_INTEGER_EXT:
2134
case GL_BGRA_INTEGER_EXT:
2137
case GL_UNSIGNED_BYTE:
2139
case GL_UNSIGNED_SHORT:
2141
case GL_UNSIGNED_INT:
2142
return _mesa_has_integer_textures(ctx)
2143
? GL_NO_ERROR : GL_INVALID_ENUM;
2144
case GL_UNSIGNED_SHORT_4_4_4_4:
2145
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
2146
case GL_UNSIGNED_SHORT_5_5_5_1:
2147
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2148
case GL_UNSIGNED_INT_8_8_8_8:
2149
case GL_UNSIGNED_INT_8_8_8_8_REV:
2150
case GL_UNSIGNED_INT_10_10_10_2:
2151
case GL_UNSIGNED_INT_2_10_10_10_REV:
2152
return _mesa_has_texture_rgb10_a2ui(ctx)
2153
? GL_NO_ERROR : GL_INVALID_ENUM;
2155
return GL_INVALID_ENUM;
2158
case GL_LUMINANCE_INTEGER_EXT:
2159
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
2162
case GL_UNSIGNED_BYTE:
2164
case GL_UNSIGNED_SHORT:
2166
case GL_UNSIGNED_INT:
2167
return _mesa_has_integer_textures(ctx)
2168
? GL_NO_ERROR : GL_INVALID_ENUM;
2170
return GL_INVALID_ENUM;
2174
return GL_INVALID_ENUM;
2181
* Do error checking of format/type combinations for OpenGL ES glReadPixels
2182
* and glTex[Sub]Image.
2183
* \return error code, or GL_NO_ERROR.
2186
_mesa_es_error_check_format_and_type(const struct gl_context *ctx,
2187
GLenum format, GLenum type,
2188
unsigned dimensions)
2190
GLboolean type_valid = GL_TRUE;
2195
if (!_mesa_has_rg_textures(ctx))
2196
return GL_INVALID_VALUE;
2200
case GL_LUMINANCE_ALPHA:
2201
type_valid = (type == GL_UNSIGNED_BYTE
2203
|| type == GL_HALF_FLOAT_OES);
2207
type_valid = (type == GL_UNSIGNED_BYTE
2208
|| type == GL_UNSIGNED_SHORT_5_6_5
2210
|| type == GL_HALF_FLOAT_OES);
2214
type_valid = (type == GL_UNSIGNED_BYTE
2215
|| type == GL_UNSIGNED_SHORT_4_4_4_4
2216
|| type == GL_UNSIGNED_SHORT_5_5_5_1
2218
|| type == GL_HALF_FLOAT_OES
2219
|| (_mesa_has_texture_type_2_10_10_10_REV(ctx) &&
2220
type == GL_UNSIGNED_INT_2_10_10_10_REV));
2223
case GL_DEPTH_COMPONENT:
2224
/* This format is filtered against invalid dimensionalities elsewhere.
2226
type_valid = (type == GL_UNSIGNED_SHORT
2227
|| type == GL_UNSIGNED_INT);
2230
case GL_DEPTH_STENCIL:
2231
/* This format is filtered against invalid dimensionalities elsewhere.
2233
type_valid = (type == GL_UNSIGNED_INT_24_8);
2237
type_valid = (type == GL_UNSIGNED_BYTE);
2239
/* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
2240
* the format does not appear to be allowed for 3D textures in OpenGL
2243
if (dimensions != 2)
2244
return GL_INVALID_VALUE;
2249
return GL_INVALID_VALUE;
2252
return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
2256
* Return the simple base format for a given internal texture format.
2257
* For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
2259
* \param ctx GL context.
2260
* \param internalFormat the internal texture format token or 1, 2, 3, or 4.
2262
* \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
2263
* GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
2265
* This is the format which is used during texture application (i.e. the
2266
* texture format and env mode determine the arithmetic used.
2269
_mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
2271
switch (internalFormat) {
2277
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2282
case GL_LUMINANCE12:
2283
case GL_LUMINANCE16:
2284
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2286
case GL_LUMINANCE_ALPHA:
2287
case GL_LUMINANCE4_ALPHA4:
2288
case GL_LUMINANCE6_ALPHA2:
2289
case GL_LUMINANCE8_ALPHA8:
2290
case GL_LUMINANCE12_ALPHA4:
2291
case GL_LUMINANCE12_ALPHA12:
2292
case GL_LUMINANCE16_ALPHA16:
2293
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2297
case GL_INTENSITY12:
2298
case GL_INTENSITY16:
2299
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2301
return (ctx->API != API_OPENGL_CORE) ? GL_RGB : -1;
2312
return (ctx->API != API_OPENGL_CORE) ? GL_RGBA : -1;
2326
/* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
2328
if (_mesa_is_gles(ctx)) {
2329
switch (internalFormat) {
2337
if (_mesa_has_ARB_ES2_compatibility(ctx) ||
2338
_mesa_has_OES_framebuffer_object(ctx) ||
2339
ctx->API == API_OPENGLES2) {
2340
switch (internalFormat) {
2348
if (ctx->API != API_OPENGLES) {
2349
switch (internalFormat) {
2350
case GL_DEPTH_COMPONENT:
2351
case GL_DEPTH_COMPONENT16:
2352
case GL_DEPTH_COMPONENT24:
2353
case GL_DEPTH_COMPONENT32:
2354
return GL_DEPTH_COMPONENT;
2355
case GL_DEPTH_STENCIL:
2356
case GL_DEPTH24_STENCIL8:
2357
return GL_DEPTH_STENCIL;
2363
if (_mesa_has_ARB_texture_stencil8(ctx) ||
2364
_mesa_has_OES_texture_stencil8(ctx)) {
2365
switch (internalFormat) {
2366
case GL_STENCIL_INDEX:
2367
case GL_STENCIL_INDEX1:
2368
case GL_STENCIL_INDEX4:
2369
case GL_STENCIL_INDEX8:
2370
case GL_STENCIL_INDEX16:
2371
return GL_STENCIL_INDEX;
2377
switch (internalFormat) {
2378
case GL_COMPRESSED_ALPHA:
2379
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2380
case GL_COMPRESSED_LUMINANCE:
2381
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2382
case GL_COMPRESSED_LUMINANCE_ALPHA:
2383
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2384
case GL_COMPRESSED_INTENSITY:
2385
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2386
case GL_COMPRESSED_RGB:
2388
case GL_COMPRESSED_RGBA:
2394
if (_mesa_is_compressed_format(ctx, internalFormat)) {
2395
GLenum base_compressed =
2396
_mesa_gl_compressed_format_base_format(internalFormat);
2397
if (base_compressed)
2398
return base_compressed;
2401
if ((_mesa_has_KHR_texture_compression_astc_ldr(ctx) &&
2402
is_astc_2d_format(internalFormat)) ||
2403
(_mesa_has_OES_texture_compression_astc(ctx) &&
2404
is_astc_3d_format(internalFormat)))
2407
if (_mesa_has_MESA_ycbcr_texture(ctx)) {
2408
if (internalFormat == GL_YCBCR_MESA)
2409
return GL_YCBCR_MESA;
2412
if (_mesa_has_half_float_textures(ctx)) {
2413
switch (internalFormat) {
2414
case GL_ALPHA16F_ARB:
2415
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2416
case GL_RGBA16F_ARB:
2420
case GL_INTENSITY16F_ARB:
2421
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2422
case GL_LUMINANCE16F_ARB:
2423
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2424
case GL_LUMINANCE_ALPHA16F_ARB:
2425
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2429
if (_mesa_has_float_textures(ctx)) {
2430
switch (internalFormat) {
2431
case GL_ALPHA32F_ARB:
2432
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2433
case GL_RGBA32F_ARB:
2437
case GL_INTENSITY32F_ARB:
2438
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2439
case GL_LUMINANCE32F_ARB:
2440
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2441
case GL_LUMINANCE_ALPHA32F_ARB:
2442
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2446
if (_mesa_has_EXT_texture_snorm(ctx) || _mesa_is_gles3(ctx)) {
2447
switch (internalFormat) {
2458
case GL_RGB16_SNORM:
2461
case GL_RGBA8_SNORM:
2462
case GL_RGBA16_SNORM:
2464
case GL_ALPHA_SNORM:
2465
case GL_ALPHA8_SNORM:
2466
case GL_ALPHA16_SNORM:
2467
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2468
case GL_LUMINANCE_SNORM:
2469
case GL_LUMINANCE8_SNORM:
2470
case GL_LUMINANCE16_SNORM:
2471
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2472
case GL_LUMINANCE_ALPHA_SNORM:
2473
case GL_LUMINANCE8_ALPHA8_SNORM:
2474
case GL_LUMINANCE16_ALPHA16_SNORM:
2475
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2476
case GL_INTENSITY_SNORM:
2477
case GL_INTENSITY8_SNORM:
2478
case GL_INTENSITY16_SNORM:
2479
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2485
if (_mesa_has_EXT_texture_sRGB(ctx) || _mesa_is_gles3(ctx)) {
2486
switch (internalFormat) {
2489
case GL_COMPRESSED_SRGB_EXT:
2491
case GL_SRGB_ALPHA_EXT:
2492
case GL_SRGB8_ALPHA8_EXT:
2493
case GL_COMPRESSED_SRGB_ALPHA_EXT:
2495
case GL_SLUMINANCE_ALPHA_EXT:
2496
case GL_SLUMINANCE8_ALPHA8_EXT:
2497
case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
2498
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2499
case GL_SLUMINANCE_EXT:
2500
case GL_SLUMINANCE8_EXT:
2501
case GL_COMPRESSED_SLUMINANCE_EXT:
2502
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2508
if (_mesa_has_EXT_texture_sRGB_R8(ctx)) {
2509
switch (internalFormat) {
2517
if (_mesa_has_EXT_texture_sRGB_RG8(ctx)) {
2518
switch (internalFormat) {
2526
if (_mesa_has_integer_textures(ctx)) {
2527
switch (internalFormat) {
2528
case GL_RGBA8UI_EXT:
2529
case GL_RGBA16UI_EXT:
2530
case GL_RGBA32UI_EXT:
2532
case GL_RGBA16I_EXT:
2533
case GL_RGBA32I_EXT:
2536
case GL_RGB16UI_EXT:
2537
case GL_RGB32UI_EXT:
2545
if (_mesa_has_texture_rgb10_a2ui(ctx)) {
2546
switch (internalFormat) {
2552
if (_mesa_has_integer_textures(ctx)) {
2553
switch (internalFormat) {
2554
case GL_ALPHA8UI_EXT:
2555
case GL_ALPHA16UI_EXT:
2556
case GL_ALPHA32UI_EXT:
2557
case GL_ALPHA8I_EXT:
2558
case GL_ALPHA16I_EXT:
2559
case GL_ALPHA32I_EXT:
2560
return (ctx->API != API_OPENGL_CORE) ? GL_ALPHA : -1;
2561
case GL_INTENSITY8UI_EXT:
2562
case GL_INTENSITY16UI_EXT:
2563
case GL_INTENSITY32UI_EXT:
2564
case GL_INTENSITY8I_EXT:
2565
case GL_INTENSITY16I_EXT:
2566
case GL_INTENSITY32I_EXT:
2567
return (ctx->API != API_OPENGL_CORE) ? GL_INTENSITY : -1;
2568
case GL_LUMINANCE8UI_EXT:
2569
case GL_LUMINANCE16UI_EXT:
2570
case GL_LUMINANCE32UI_EXT:
2571
case GL_LUMINANCE8I_EXT:
2572
case GL_LUMINANCE16I_EXT:
2573
case GL_LUMINANCE32I_EXT:
2574
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE : -1;
2575
case GL_LUMINANCE_ALPHA8UI_EXT:
2576
case GL_LUMINANCE_ALPHA16UI_EXT:
2577
case GL_LUMINANCE_ALPHA32UI_EXT:
2578
case GL_LUMINANCE_ALPHA8I_EXT:
2579
case GL_LUMINANCE_ALPHA16I_EXT:
2580
case GL_LUMINANCE_ALPHA32I_EXT:
2581
return (ctx->API != API_OPENGL_CORE) ? GL_LUMINANCE_ALPHA : -1;
2587
if (_mesa_has_rg_textures(ctx)) {
2588
switch (internalFormat) {
2590
if (!_mesa_has_half_float_textures(ctx))
2594
if (!_mesa_has_float_textures(ctx))
2603
if (!_mesa_has_integer_textures(ctx))
2609
case GL_COMPRESSED_RED:
2613
if (!_mesa_has_half_float_textures(ctx))
2617
if (!_mesa_has_float_textures(ctx))
2626
if (!_mesa_has_integer_textures(ctx))
2632
case GL_COMPRESSED_RG:
2639
if (_mesa_has_texture_shared_exponent(ctx)) {
2640
switch (internalFormat) {
2641
case GL_RGB9_E5_EXT:
2648
if (_mesa_has_packed_float(ctx)) {
2649
switch (internalFormat) {
2650
case GL_R11F_G11F_B10F_EXT:
2657
if (_mesa_has_float_depth_buffer(ctx)) {
2658
switch (internalFormat) {
2659
case GL_DEPTH_COMPONENT32F:
2660
return GL_DEPTH_COMPONENT;
2661
case GL_DEPTH32F_STENCIL8:
2662
return GL_DEPTH_STENCIL;
2668
return -1; /* error */
2672
* Returns the effective internal format from a texture format and type.
2673
* This is used by texture image operations internally for validation, when
2674
* the specified internal format is a base (unsized) format.
2676
* This method will only return a valid effective internal format if the
2677
* combination of format, type and internal format in base form, is acceptable.
2679
* If a single sized internal format is defined in the spec (OpenGL-ES 3.0.4) or
2680
* in extensions, to unambiguously correspond to the given base format, then
2681
* that internal format is returned as the effective. Otherwise, if the
2682
* combination is accepted but a single effective format is not defined, the
2683
* passed base format will be returned instead.
2685
* \param format the texture format
2686
* \param type the texture type
2689
gles_effective_internal_format_for_format_and_type(GLenum format,
2693
case GL_UNSIGNED_BYTE:
2703
/* Although LUMINANCE_ALPHA, LUMINANCE and ALPHA appear in table 3.12,
2704
* (section 3.8 Texturing, page 128 of the OpenGL-ES 3.0.4) as effective
2705
* internal formats, they do not correspond to GL constants, so the base
2706
* format is returned instead.
2709
case GL_LUMINANCE_ALPHA:
2716
case GL_UNSIGNED_SHORT_4_4_4_4:
2717
if (format == GL_RGBA)
2721
case GL_UNSIGNED_SHORT_5_5_5_1:
2722
if (format == GL_RGBA)
2726
case GL_UNSIGNED_SHORT_5_6_5:
2727
if (format == GL_RGB)
2731
/* OES_packed_depth_stencil */
2732
case GL_UNSIGNED_INT_24_8:
2733
if (format == GL_DEPTH_STENCIL)
2734
return GL_DEPTH24_STENCIL8;
2737
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
2738
if (format == GL_DEPTH_STENCIL)
2739
return GL_DEPTH32F_STENCIL8;
2742
case GL_UNSIGNED_SHORT:
2743
if (format == GL_DEPTH_COMPONENT)
2744
return GL_DEPTH_COMPONENT16;
2747
case GL_UNSIGNED_INT:
2748
/* It can be DEPTH_COMPONENT16 or DEPTH_COMPONENT24, so just return
2751
if (format == GL_DEPTH_COMPONENT)
2755
/* OES_texture_float and OES_texture_half_float */
2757
if (format == GL_DEPTH_COMPONENT)
2758
return GL_DEPTH_COMPONENT32F;
2760
case GL_HALF_FLOAT_OES:
2764
case GL_LUMINANCE_ALPHA:
2780
/* GL_EXT_texture_type_2_10_10_10_REV */
2781
case GL_UNSIGNED_INT_2_10_10_10_REV:
2790
/* fall through and return NONE */
2798
* Error checking if internalformat for glTex[Sub]Image is valid
2799
* within OpenGL ES 3.2 (or introduced by an ES extension).
2801
* Note, further checks in _mesa_gles_error_check_format_and_type
2802
* are required for complete checking between format and type.
2805
_mesa_gles_check_internalformat(const struct gl_context *ctx,
2806
GLenum internalFormat)
2808
switch (internalFormat) {
2812
case GL_LUMINANCE_ALPHA:
2816
/* GL_OES_depth_texture */
2817
case GL_DEPTH_COMPONENT:
2819
/* GL_EXT_texture_format_BGRA8888 */
2822
/* GL_OES_required_internalformat */
2828
case GL_DEPTH_COMPONENT16:
2829
case GL_DEPTH_COMPONENT24:
2830
case GL_DEPTH_COMPONENT32:
2831
case GL_DEPTH24_STENCIL8:
2833
case GL_RGB10_A2_EXT:
2836
case GL_LUMINANCE8_ALPHA8:
2837
case GL_LUMINANCE4_ALPHA4:
2844
if (!_mesa_has_rg_textures(ctx))
2845
return GL_INVALID_VALUE;
2848
/* GL_OES_texture_stencil8 */
2849
case GL_STENCIL_INDEX8:
2850
if (!_mesa_has_OES_texture_stencil8(ctx))
2851
return GL_INVALID_VALUE;
2854
case GL_COMPRESSED_RGBA_BPTC_UNORM:
2855
case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
2856
case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
2857
case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
2858
if (!_mesa_has_EXT_texture_compression_bptc(ctx))
2859
return GL_INVALID_VALUE;
2862
case GL_COMPRESSED_RED_RGTC1:
2863
case GL_COMPRESSED_SIGNED_RED_RGTC1:
2864
case GL_COMPRESSED_RED_GREEN_RGTC2_EXT:
2865
case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT:
2866
if (!_mesa_has_EXT_texture_compression_rgtc(ctx))
2867
return GL_INVALID_VALUE;
2870
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2871
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
2872
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
2873
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
2874
if (!_mesa_has_EXT_texture_compression_s3tc(ctx))
2875
return GL_INVALID_VALUE;
2878
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
2879
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
2880
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
2881
case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
2882
if (!_mesa_has_EXT_texture_compression_s3tc_srgb(ctx))
2883
return GL_INVALID_VALUE;
2890
if (!_mesa_has_EXT_texture_norm16(ctx))
2891
return GL_INVALID_VALUE;
2896
case GL_RGB16_SNORM:
2897
case GL_RGBA16_SNORM:
2898
if (!_mesa_has_EXT_texture_norm16(ctx) &&
2899
!_mesa_has_EXT_texture_snorm(ctx))
2900
return GL_INVALID_VALUE;
2904
if (!_mesa_has_EXT_texture_sRGB_R8(ctx))
2905
return GL_INVALID_VALUE;
2909
if (!_mesa_has_EXT_texture_sRGB_RG8(ctx))
2910
return GL_INVALID_VALUE;
2914
case GL_SRGB8_ALPHA8:
2915
case GL_RGBA8_SNORM:
2927
case GL_R11F_G11F_B10F:
2955
case GL_DEPTH_COMPONENT32F:
2956
case GL_DEPTH32F_STENCIL8:
2957
if (!_mesa_is_gles3(ctx))
2958
return GL_INVALID_VALUE;
2961
return GL_INVALID_VALUE;
2966
* Do error checking of format/type combinations for OpenGL ES 3
2967
* glTex[Sub]Image, or ES1/ES2 with GL_OES_required_internalformat.
2968
* \return error code, or GL_NO_ERROR.
2971
_mesa_gles_error_check_format_and_type(const struct gl_context *ctx,
2972
GLenum format, GLenum type,
2973
GLenum internalFormat)
2975
/* If internalFormat is an unsized format, then the effective internal
2976
* format derived from format and type should be used instead. Page 127,
2977
* section "3.8 Texturing" of the GLES 3.0.4 spec states:
2979
* "if internalformat is a base internal format, the effective
2980
* internal format is a sized internal format that is derived
2981
* from the format and type for internal use by the GL.
2982
* Table 3.12 specifies the mapping of format and type to effective
2983
* internal formats. The effective internal format is used by the GL
2984
* for purposes such as texture completeness or type checks for
2985
* CopyTex* commands. In these cases, the GL is required to operate
2986
* as if the effective internal format was used as the internalformat
2987
* when specifying the texture data."
2989
if (_mesa_is_enum_format_unsized(internalFormat)) {
2990
GLenum effectiveInternalFormat =
2991
gles_effective_internal_format_for_format_and_type(format, type);
2993
if (effectiveInternalFormat == GL_NONE)
2994
return GL_INVALID_OPERATION;
2996
GLenum baseInternalFormat;
2997
if (internalFormat == GL_BGRA_EXT) {
2998
/* Unfortunately, _mesa_base_tex_format returns a base format of
2999
* GL_RGBA for GL_BGRA_EXT. This makes perfect sense if you're
3000
* asking the question, "what channels does this format have?"
3001
* However, if we're trying to determine if two internal formats
3002
* match in the ES3 sense, we actually want GL_BGRA.
3004
baseInternalFormat = GL_BGRA_EXT;
3006
baseInternalFormat =
3007
_mesa_base_tex_format(ctx, effectiveInternalFormat);
3010
if (internalFormat != baseInternalFormat)
3011
return GL_INVALID_OPERATION;
3013
internalFormat = effectiveInternalFormat;
3016
/* The GLES variant of EXT_texture_compression_s3tc is very vague and
3017
* doesn't list valid types. Just do exactly what the spec says.
3019
if (internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
3020
internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
3021
internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
3022
internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
3023
return format == GL_RGB || format == GL_RGBA ? GL_NO_ERROR :
3024
GL_INVALID_OPERATION;
3026
/* Before checking for the combination, verify that
3027
* given internalformat is legal for OpenGL ES.
3029
GLenum internal_format_error =
3030
_mesa_gles_check_internalformat(ctx, internalFormat);
3032
if (internal_format_error != GL_NO_ERROR)
3033
return internal_format_error;
3037
if (type != GL_UNSIGNED_BYTE ||
3038
(internalFormat != GL_BGRA &&
3039
internalFormat != GL_RGBA8 &&
3040
internalFormat != GL_SRGB8_ALPHA8))
3041
return GL_INVALID_OPERATION;
3045
if (type != GL_UNSIGNED_BYTE ||
3046
(internalFormat != GL_RGB8 &&
3047
internalFormat != GL_SRGB8))
3048
return GL_INVALID_OPERATION;
3053
case GL_UNSIGNED_BYTE:
3054
switch (internalFormat) {
3060
case GL_SRGB8_ALPHA8_EXT:
3061
if (ctx->Version <= 20)
3062
return GL_INVALID_OPERATION;
3064
case GL_COMPRESSED_RGBA_BPTC_UNORM:
3065
case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
3068
return GL_INVALID_OPERATION;
3073
if (ctx->Version <= 20 || internalFormat != GL_RGBA8_SNORM)
3074
return GL_INVALID_OPERATION;
3077
case GL_UNSIGNED_SHORT:
3078
if (internalFormat != GL_RGBA16)
3079
return GL_INVALID_OPERATION;
3083
if (internalFormat != GL_RGBA16_SNORM)
3084
return GL_INVALID_OPERATION;
3087
case GL_UNSIGNED_SHORT_4_4_4_4:
3088
switch (internalFormat) {
3093
return GL_INVALID_OPERATION;
3097
case GL_UNSIGNED_SHORT_5_5_5_1:
3098
switch (internalFormat) {
3103
return GL_INVALID_OPERATION;
3107
case GL_UNSIGNED_INT_2_10_10_10_REV:
3108
switch (internalFormat) {
3112
if (!_mesa_has_texture_type_2_10_10_10_REV(ctx))
3113
return GL_INVALID_OPERATION;
3116
return GL_INVALID_OPERATION;
3121
if (ctx->Version <= 20 || internalFormat != GL_RGBA16F)
3122
return GL_INVALID_OPERATION;
3126
switch (internalFormat) {
3129
if (ctx->Version <= 20)
3130
return GL_INVALID_OPERATION;
3133
if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format)
3134
return GL_INVALID_OPERATION;
3137
return GL_INVALID_OPERATION;
3141
case GL_HALF_FLOAT_OES:
3142
if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format)
3143
return GL_INVALID_OPERATION;
3146
return GL_INVALID_OPERATION;
3150
case GL_RGBA_INTEGER:
3151
if (ctx->Version <= 20)
3152
return GL_INVALID_OPERATION;
3154
case GL_UNSIGNED_BYTE:
3155
if (internalFormat != GL_RGBA8UI)
3156
return GL_INVALID_OPERATION;
3160
if (internalFormat != GL_RGBA8I)
3161
return GL_INVALID_OPERATION;
3164
case GL_UNSIGNED_SHORT:
3165
if (internalFormat != GL_RGBA16UI)
3166
return GL_INVALID_OPERATION;
3170
if (internalFormat != GL_RGBA16I)
3171
return GL_INVALID_OPERATION;
3174
case GL_UNSIGNED_INT:
3175
if (internalFormat != GL_RGBA32UI)
3176
return GL_INVALID_OPERATION;
3180
if (internalFormat != GL_RGBA32I)
3181
return GL_INVALID_OPERATION;
3184
case GL_UNSIGNED_INT_2_10_10_10_REV:
3185
if (internalFormat != GL_RGB10_A2UI)
3186
return GL_INVALID_OPERATION;
3190
return GL_INVALID_OPERATION;
3196
case GL_UNSIGNED_BYTE:
3197
switch (internalFormat) {
3203
if (ctx->Version <= 20)
3204
return GL_INVALID_OPERATION;
3207
return GL_INVALID_OPERATION;
3212
if (ctx->Version <= 20 || internalFormat != GL_RGB8_SNORM)
3213
return GL_INVALID_OPERATION;
3216
case GL_UNSIGNED_SHORT:
3217
if (internalFormat != GL_RGB16)
3218
return GL_INVALID_OPERATION;
3222
if (internalFormat != GL_RGB16_SNORM)
3223
return GL_INVALID_OPERATION;
3226
case GL_UNSIGNED_SHORT_5_6_5:
3227
switch (internalFormat) {
3232
return GL_INVALID_OPERATION;
3236
case GL_UNSIGNED_INT_10F_11F_11F_REV:
3237
if (ctx->Version <= 20 || internalFormat != GL_R11F_G11F_B10F)
3238
return GL_INVALID_OPERATION;
3241
case GL_UNSIGNED_INT_5_9_9_9_REV:
3242
if (ctx->Version <= 20 || internalFormat != GL_RGB9_E5)
3243
return GL_INVALID_OPERATION;
3247
if (ctx->Version <= 20)
3248
return GL_INVALID_OPERATION;
3249
switch (internalFormat) {
3251
case GL_R11F_G11F_B10F:
3255
return GL_INVALID_OPERATION;
3260
switch (internalFormat) {
3263
case GL_R11F_G11F_B10F:
3265
if (ctx->Version <= 20)
3266
return GL_INVALID_OPERATION;
3268
case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
3269
case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
3272
if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format)
3273
return GL_INVALID_OPERATION;
3276
return GL_INVALID_OPERATION;
3280
case GL_HALF_FLOAT_OES:
3281
if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format)
3282
return GL_INVALID_OPERATION;
3285
case GL_UNSIGNED_INT_2_10_10_10_REV:
3286
switch (internalFormat) {
3291
/* GL_EXT_texture_type_2_10_10_10_REV allows GL_RGB even though
3292
* GLES3 doesn't, and GL_OES_required_internalformat extends that
3293
* to allow the sized RGB internalformats as well.
3295
if (!_mesa_has_texture_type_2_10_10_10_REV(ctx))
3296
return GL_INVALID_OPERATION;
3299
return GL_INVALID_OPERATION;
3304
return GL_INVALID_OPERATION;
3308
case GL_RGB_INTEGER:
3309
if (ctx->Version <= 20)
3310
return GL_INVALID_OPERATION;
3312
case GL_UNSIGNED_BYTE:
3313
if (internalFormat != GL_RGB8UI)
3314
return GL_INVALID_OPERATION;
3318
if (internalFormat != GL_RGB8I)
3319
return GL_INVALID_OPERATION;
3322
case GL_UNSIGNED_SHORT:
3323
if (internalFormat != GL_RGB16UI)
3324
return GL_INVALID_OPERATION;
3328
if (internalFormat != GL_RGB16I)
3329
return GL_INVALID_OPERATION;
3332
case GL_UNSIGNED_INT:
3333
if (internalFormat != GL_RGB32UI)
3334
return GL_INVALID_OPERATION;
3338
if (internalFormat != GL_RGB32I)
3339
return GL_INVALID_OPERATION;
3343
return GL_INVALID_OPERATION;
3348
if (!_mesa_has_rg_textures(ctx))
3349
return GL_INVALID_OPERATION;
3351
case GL_UNSIGNED_BYTE:
3352
if (internalFormat != GL_RG8 &&
3353
internalFormat != GL_COMPRESSED_RED_GREEN_RGTC2_EXT &&
3354
internalFormat != GL_SRG8_EXT)
3355
return GL_INVALID_OPERATION;
3359
if (internalFormat != GL_RG8_SNORM &&
3360
internalFormat != GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT)
3361
return GL_INVALID_OPERATION;
3364
case GL_UNSIGNED_SHORT:
3365
if (internalFormat != GL_RG16)
3366
return GL_INVALID_OPERATION;
3370
if (internalFormat != GL_RG16_SNORM)
3371
return GL_INVALID_OPERATION;
3375
case GL_HALF_FLOAT_OES:
3376
switch (internalFormat) {
3378
if (ctx->Version <= 20)
3379
return GL_INVALID_OPERATION;
3382
if (!_mesa_has_OES_texture_half_float(ctx))
3383
return GL_INVALID_OPERATION;
3386
return GL_INVALID_OPERATION;
3391
switch (internalFormat) {
3396
if (!_mesa_has_OES_texture_float(ctx))
3397
return GL_INVALID_OPERATION;
3400
return GL_INVALID_OPERATION;
3405
return GL_INVALID_OPERATION;
3410
if (ctx->Version <= 20)
3411
return GL_INVALID_OPERATION;
3413
case GL_UNSIGNED_BYTE:
3414
if (internalFormat != GL_RG8UI)
3415
return GL_INVALID_OPERATION;
3419
if (internalFormat != GL_RG8I)
3420
return GL_INVALID_OPERATION;
3423
case GL_UNSIGNED_SHORT:
3424
if (internalFormat != GL_RG16UI)
3425
return GL_INVALID_OPERATION;
3429
if (internalFormat != GL_RG16I)
3430
return GL_INVALID_OPERATION;
3433
case GL_UNSIGNED_INT:
3434
if (internalFormat != GL_RG32UI)
3435
return GL_INVALID_OPERATION;
3439
if (internalFormat != GL_RG32I)
3440
return GL_INVALID_OPERATION;
3444
return GL_INVALID_OPERATION;
3449
if (!_mesa_has_rg_textures(ctx))
3450
return GL_INVALID_OPERATION;
3452
case GL_UNSIGNED_BYTE:
3453
if (internalFormat != GL_R8 &&
3454
internalFormat != GL_SR8_EXT &&
3455
internalFormat != GL_COMPRESSED_RED_RGTC1_EXT) {
3456
return GL_INVALID_OPERATION;
3461
if (internalFormat != GL_R8_SNORM &&
3462
internalFormat != GL_COMPRESSED_SIGNED_RED_RGTC1_EXT)
3463
return GL_INVALID_OPERATION;
3466
case GL_UNSIGNED_SHORT:
3467
if (internalFormat != GL_R16)
3468
return GL_INVALID_OPERATION;
3472
if (internalFormat != GL_R16_SNORM)
3473
return GL_INVALID_OPERATION;
3477
case GL_HALF_FLOAT_OES:
3478
switch (internalFormat) {
3480
if (ctx->Version <= 20)
3481
return GL_INVALID_OPERATION;
3485
if (!_mesa_has_OES_texture_half_float(ctx))
3486
return GL_INVALID_OPERATION;
3489
return GL_INVALID_OPERATION;
3494
switch (internalFormat) {
3499
if (!_mesa_has_OES_texture_float(ctx))
3500
return GL_INVALID_OPERATION;
3503
return GL_INVALID_OPERATION;
3508
return GL_INVALID_OPERATION;
3512
case GL_RED_INTEGER:
3513
if (ctx->Version <= 20)
3514
return GL_INVALID_OPERATION;
3516
case GL_UNSIGNED_BYTE:
3517
if (internalFormat != GL_R8UI)
3518
return GL_INVALID_OPERATION;
3522
if (internalFormat != GL_R8I)
3523
return GL_INVALID_OPERATION;
3526
case GL_UNSIGNED_SHORT:
3527
if (internalFormat != GL_R16UI)
3528
return GL_INVALID_OPERATION;
3532
if (internalFormat != GL_R16I)
3533
return GL_INVALID_OPERATION;
3536
case GL_UNSIGNED_INT:
3537
if (internalFormat != GL_R32UI)
3538
return GL_INVALID_OPERATION;
3542
if (internalFormat != GL_R32I)
3543
return GL_INVALID_OPERATION;
3547
return GL_INVALID_OPERATION;
3551
case GL_DEPTH_COMPONENT:
3553
case GL_UNSIGNED_SHORT:
3554
if (internalFormat != GL_DEPTH_COMPONENT &&
3555
internalFormat != GL_DEPTH_COMPONENT16)
3556
return GL_INVALID_OPERATION;
3559
case GL_UNSIGNED_INT:
3560
switch (internalFormat) {
3561
case GL_DEPTH_COMPONENT:
3562
case GL_DEPTH_COMPONENT16:
3563
case GL_DEPTH_COMPONENT24:
3566
return GL_INVALID_OPERATION;
3571
if (ctx->Version <= 20 || internalFormat != GL_DEPTH_COMPONENT32F)
3572
return GL_INVALID_OPERATION;
3576
return GL_INVALID_OPERATION;
3580
case GL_DEPTH_STENCIL:
3582
case GL_UNSIGNED_INT_24_8:
3583
if (internalFormat != GL_DEPTH_STENCIL &&
3584
internalFormat != GL_DEPTH24_STENCIL8)
3585
return GL_INVALID_OPERATION;
3588
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
3589
if (ctx->Version <= 20 || internalFormat != GL_DEPTH32F_STENCIL8)
3590
return GL_INVALID_OPERATION;
3594
return GL_INVALID_OPERATION;
3598
case GL_STENCIL_INDEX:
3599
if (type != GL_UNSIGNED_BYTE ||
3600
internalFormat != GL_STENCIL_INDEX8) {
3601
return GL_INVALID_OPERATION;
3607
case GL_LUMINANCE_ALPHA:
3610
if (!_mesa_has_OES_texture_float(ctx) || internalFormat != format)
3611
return GL_INVALID_OPERATION;
3613
case GL_HALF_FLOAT_OES:
3614
if (!_mesa_has_OES_texture_half_float(ctx) || internalFormat != format)
3615
return GL_INVALID_OPERATION;
3617
case GL_UNSIGNED_BYTE:
3618
if (!(format == internalFormat ||
3619
(format == GL_ALPHA && internalFormat == GL_ALPHA8) ||
3620
(format == GL_LUMINANCE && internalFormat == GL_LUMINANCE8) ||
3621
(format == GL_LUMINANCE_ALPHA &&
3622
((internalFormat == GL_LUMINANCE8_ALPHA8) ||
3623
(internalFormat == GL_LUMINANCE4_ALPHA4))))) {
3624
return GL_INVALID_OPERATION;
3628
return GL_INVALID_OPERATION;
3637
set_swizzle(uint8_t *swizzle, int x, int y, int z, int w)
3639
swizzle[MESA_FORMAT_SWIZZLE_X] = x;
3640
swizzle[MESA_FORMAT_SWIZZLE_Y] = y;
3641
swizzle[MESA_FORMAT_SWIZZLE_Z] = z;
3642
swizzle[MESA_FORMAT_SWIZZLE_W] = w;
3646
get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
3650
case GL_RGBA_INTEGER_EXT:
3651
set_swizzle(swizzle, 0, 1, 2, 3);
3654
case GL_BGRA_INTEGER_EXT:
3655
set_swizzle(swizzle, 2, 1, 0, 3);
3658
set_swizzle(swizzle, 3, 2, 1, 0);
3661
case GL_RGB_INTEGER_EXT:
3662
set_swizzle(swizzle, 0, 1, 2, 5);
3665
case GL_BGR_INTEGER_EXT:
3666
set_swizzle(swizzle, 2, 1, 0, 5);
3668
case GL_LUMINANCE_ALPHA:
3669
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
3670
set_swizzle(swizzle, 0, 0, 0, 1);
3674
set_swizzle(swizzle, 0, 1, 4, 5);
3677
case GL_RED_INTEGER_EXT:
3678
set_swizzle(swizzle, 0, 4, 4, 5);
3681
case GL_GREEN_INTEGER_EXT:
3682
set_swizzle(swizzle, 4, 0, 4, 5);
3685
case GL_BLUE_INTEGER_EXT:
3686
set_swizzle(swizzle, 4, 4, 0, 5);
3689
case GL_ALPHA_INTEGER_EXT:
3690
set_swizzle(swizzle, 4, 4, 4, 0);
3693
case GL_LUMINANCE_INTEGER_EXT:
3694
set_swizzle(swizzle, 0, 0, 0, 5);
3697
set_swizzle(swizzle, 0, 0, 0, 0);
3699
case GL_DEPTH_COMPONENT:
3700
set_swizzle(swizzle, 0, 6, 6, 6);
3702
case GL_STENCIL_INDEX:
3703
set_swizzle(swizzle, 6, 0, 6, 6);
3711
_mesa_swap_bytes_in_type_enum(GLenum *type)
3714
case GL_UNSIGNED_INT_8_8_8_8:
3715
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
3717
case GL_UNSIGNED_INT_8_8_8_8_REV:
3718
*type = GL_UNSIGNED_INT_8_8_8_8;
3720
case GL_UNSIGNED_SHORT_8_8_MESA:
3721
*type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
3723
case GL_UNSIGNED_SHORT_8_8_REV_MESA:
3724
*type = GL_UNSIGNED_SHORT_8_8_MESA;
3727
case GL_UNSIGNED_BYTE:
3728
/* format/types that are arrays of 8-bit values are unaffected by
3733
/* swapping bytes on 4444, 1555, or >8 bit per channel types etc. will
3734
* never match a Mesa format.
3741
* Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
3742
* GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
3743
* otherwise (for non-array formats).
3745
* This function will typically be used to compute a mesa format from a GL type
3746
* so we can then call _mesa_format_convert. This function does
3747
* not consider byte swapping, so it returns types assuming that no byte
3748
* swapping is involved. If byte swapping is involved then clients are supposed
3749
* to handle that on their side before calling _mesa_format_convert.
3751
* This function returns an uint32_t that can pack a mesa_format or a
3752
* mesa_array_format. Clients must check the mesa array format bit
3753
* (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
3754
* format is a mesa_array_format or a mesa_format.
3757
_mesa_format_from_format_and_type(GLenum format, GLenum type)
3759
bool is_array_format = true;
3761
bool normalized = false, is_float = false, is_signed = false;
3762
int num_channels = 0, type_size = 0;
3764
if (format == GL_COLOR_INDEX)
3765
return MESA_FORMAT_NONE;
3767
/* Extract array format type information from the OpenGL data type */
3769
case GL_UNSIGNED_BYTE:
3776
case GL_UNSIGNED_SHORT:
3783
case GL_UNSIGNED_INT:
3791
case GL_HALF_FLOAT_OES:
3802
is_array_format = false;
3806
/* Extract array format swizzle information from the OpenGL format */
3807
if (is_array_format)
3808
is_array_format = get_swizzle_from_gl_format(format, swizzle);
3810
/* If this is an array format type after checking data type and format,
3811
* create the array format
3813
if (is_array_format) {
3814
enum mesa_array_format_base_format bf;
3816
case GL_DEPTH_COMPONENT:
3817
bf = MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH;
3819
case GL_STENCIL_INDEX:
3820
bf = MESA_ARRAY_FORMAT_BASE_FORMAT_STENCIL;
3823
bf = MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS;
3827
normalized = !(_mesa_is_enum_format_integer(format) ||
3828
format == GL_STENCIL_INDEX);
3829
num_channels = _mesa_components_in_format(format);
3831
return MESA_ARRAY_FORMAT(bf, type_size, is_signed, is_float,
3832
normalized, num_channels,
3833
swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
3836
/* Otherwise this is not an array format, so return the mesa_format
3837
* matching the OpenGL format and data type
3840
case GL_UNSIGNED_SHORT_5_6_5:
3841
if (format == GL_RGB)
3842
return MESA_FORMAT_B5G6R5_UNORM;
3843
else if (format == GL_BGR)
3844
return MESA_FORMAT_R5G6B5_UNORM;
3845
else if (format == GL_RGB_INTEGER)
3846
return MESA_FORMAT_B5G6R5_UINT;
3848
case GL_UNSIGNED_SHORT_5_6_5_REV:
3849
if (format == GL_RGB)
3850
return MESA_FORMAT_R5G6B5_UNORM;
3851
else if (format == GL_BGR)
3852
return MESA_FORMAT_B5G6R5_UNORM;
3853
else if (format == GL_RGB_INTEGER)
3854
return MESA_FORMAT_R5G6B5_UINT;
3856
case GL_UNSIGNED_SHORT_4_4_4_4:
3857
if (format == GL_RGBA)
3858
return MESA_FORMAT_A4B4G4R4_UNORM;
3859
else if (format == GL_BGRA)
3860
return MESA_FORMAT_A4R4G4B4_UNORM;
3861
else if (format == GL_ABGR_EXT)
3862
return MESA_FORMAT_R4G4B4A4_UNORM;
3863
else if (format == GL_RGBA_INTEGER)
3864
return MESA_FORMAT_A4B4G4R4_UINT;
3865
else if (format == GL_BGRA_INTEGER)
3866
return MESA_FORMAT_A4R4G4B4_UINT;
3868
case GL_UNSIGNED_SHORT_4_4_4_4_REV:
3869
if (format == GL_RGBA)
3870
return MESA_FORMAT_R4G4B4A4_UNORM;
3871
else if (format == GL_BGRA)
3872
return MESA_FORMAT_B4G4R4A4_UNORM;
3873
else if (format == GL_ABGR_EXT)
3874
return MESA_FORMAT_A4B4G4R4_UNORM;
3875
else if (format == GL_RGBA_INTEGER)
3876
return MESA_FORMAT_R4G4B4A4_UINT;
3877
else if (format == GL_BGRA_INTEGER)
3878
return MESA_FORMAT_B4G4R4A4_UINT;
3880
case GL_UNSIGNED_SHORT_5_5_5_1:
3881
if (format == GL_RGBA)
3882
return MESA_FORMAT_A1B5G5R5_UNORM;
3883
else if (format == GL_BGRA)
3884
return MESA_FORMAT_A1R5G5B5_UNORM;
3885
else if (format == GL_RGBA_INTEGER)
3886
return MESA_FORMAT_A1B5G5R5_UINT;
3887
else if (format == GL_BGRA_INTEGER)
3888
return MESA_FORMAT_A1R5G5B5_UINT;
3890
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
3891
if (format == GL_RGBA)
3892
return MESA_FORMAT_R5G5B5A1_UNORM;
3893
else if (format == GL_BGRA)
3894
return MESA_FORMAT_B5G5R5A1_UNORM;
3895
else if (format == GL_RGBA_INTEGER)
3896
return MESA_FORMAT_R5G5B5A1_UINT;
3897
else if (format == GL_BGRA_INTEGER)
3898
return MESA_FORMAT_B5G5R5A1_UINT;
3900
case GL_UNSIGNED_BYTE_3_3_2:
3901
if (format == GL_RGB)
3902
return MESA_FORMAT_B2G3R3_UNORM;
3903
else if (format == GL_RGB_INTEGER)
3904
return MESA_FORMAT_B2G3R3_UINT;
3906
case GL_UNSIGNED_BYTE_2_3_3_REV:
3907
if (format == GL_RGB)
3908
return MESA_FORMAT_R3G3B2_UNORM;
3909
else if (format == GL_RGB_INTEGER)
3910
return MESA_FORMAT_R3G3B2_UINT;
3912
case GL_UNSIGNED_INT_5_9_9_9_REV:
3913
if (format == GL_RGB)
3914
return MESA_FORMAT_R9G9B9E5_FLOAT;
3916
case GL_UNSIGNED_INT_10_10_10_2:
3917
if (format == GL_RGBA)
3918
return MESA_FORMAT_A2B10G10R10_UNORM;
3919
else if (format == GL_RGBA_INTEGER)
3920
return MESA_FORMAT_A2B10G10R10_UINT;
3921
else if (format == GL_BGRA)
3922
return MESA_FORMAT_A2R10G10B10_UNORM;
3923
else if (format == GL_BGRA_INTEGER)
3924
return MESA_FORMAT_A2R10G10B10_UINT;
3926
case GL_UNSIGNED_INT_2_10_10_10_REV:
3927
if (format == GL_RGB)
3928
return MESA_FORMAT_R10G10B10X2_UNORM;
3929
if (format == GL_RGBA)
3930
return MESA_FORMAT_R10G10B10A2_UNORM;
3931
else if (format == GL_RGBA_INTEGER)
3932
return MESA_FORMAT_R10G10B10A2_UINT;
3933
else if (format == GL_BGRA)
3934
return MESA_FORMAT_B10G10R10A2_UNORM;
3935
else if (format == GL_BGRA_INTEGER)
3936
return MESA_FORMAT_B10G10R10A2_UINT;
3938
case GL_UNSIGNED_INT_8_8_8_8:
3939
if (format == GL_RGBA)
3940
return MESA_FORMAT_A8B8G8R8_UNORM;
3941
else if (format == GL_BGRA)
3942
return MESA_FORMAT_A8R8G8B8_UNORM;
3943
else if (format == GL_ABGR_EXT)
3944
return MESA_FORMAT_R8G8B8A8_UNORM;
3945
else if (format == GL_RGBA_INTEGER)
3946
return MESA_FORMAT_A8B8G8R8_UINT;
3947
else if (format == GL_BGRA_INTEGER)
3948
return MESA_FORMAT_A8R8G8B8_UINT;
3950
case GL_UNSIGNED_INT_8_8_8_8_REV:
3951
if (format == GL_RGBA)
3952
return MESA_FORMAT_R8G8B8A8_UNORM;
3953
else if (format == GL_BGRA)
3954
return MESA_FORMAT_B8G8R8A8_UNORM;
3955
else if (format == GL_ABGR_EXT)
3956
return MESA_FORMAT_A8B8G8R8_UNORM;
3957
else if (format == GL_RGBA_INTEGER)
3958
return MESA_FORMAT_R8G8B8A8_UINT;
3959
else if (format == GL_BGRA_INTEGER)
3960
return MESA_FORMAT_B8G8R8A8_UINT;
3962
case GL_UNSIGNED_SHORT_8_8_MESA:
3963
if (format == GL_YCBCR_MESA)
3964
return MESA_FORMAT_YCBCR;
3966
case GL_UNSIGNED_SHORT_8_8_REV_MESA:
3967
if (format == GL_YCBCR_MESA)
3968
return MESA_FORMAT_YCBCR_REV;
3970
case GL_UNSIGNED_INT_10F_11F_11F_REV:
3971
if (format == GL_RGB)
3972
return MESA_FORMAT_R11G11B10_FLOAT;
3975
if (format == GL_DEPTH_COMPONENT)
3976
return MESA_FORMAT_Z_FLOAT32;
3978
case GL_UNSIGNED_INT:
3979
if (format == GL_DEPTH_COMPONENT)
3980
return MESA_FORMAT_Z_UNORM32;
3982
case GL_UNSIGNED_SHORT:
3983
if (format == GL_DEPTH_COMPONENT)
3984
return MESA_FORMAT_Z_UNORM16;
3986
case GL_UNSIGNED_INT_24_8:
3987
if (format == GL_DEPTH_STENCIL)
3988
return MESA_FORMAT_S8_UINT_Z24_UNORM;
3989
else if (format == GL_DEPTH_COMPONENT)
3990
return MESA_FORMAT_X8_UINT_Z24_UNORM;
3992
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
3993
if (format == GL_DEPTH_STENCIL)
3994
return MESA_FORMAT_Z32_FLOAT_S8X24_UINT;
4000
fprintf(stderr, "Unsupported format/type: %s/%s\n",
4001
_mesa_enum_to_string(format),
4002
_mesa_enum_to_string(type));
4004
/* If we got here it means that we could not find a Mesa format that
4005
* matches the GL format/type provided. We may need to add a new Mesa
4006
* format in that case.
4008
unreachable("Unsupported format");
4012
_mesa_tex_format_from_format_and_type(const struct gl_context *ctx,
4013
GLenum gl_format, GLenum type)
4015
mesa_format format = _mesa_format_from_format_and_type(gl_format, type);
4017
if (_mesa_format_is_mesa_array_format(format))
4018
format = _mesa_format_from_array_format(format);
4020
if (format == MESA_FORMAT_NONE || !ctx->TextureFormatSupported[format])
4021
return MESA_FORMAT_NONE;
4027
* Returns true if \p internal_format is a sized internal format that
4028
* is marked "Color Renderable" in Table 8.10 of the ES 3.2 specification.
4031
_mesa_is_es3_color_renderable(const struct gl_context *ctx,
4032
GLenum internal_format)
4034
switch (internal_format) {
4044
case GL_SRGB8_ALPHA8:
4051
case GL_R11F_G11F_B10F:
4074
return _mesa_has_EXT_texture_norm16(ctx);
4077
case GL_RGBA8_SNORM:
4078
return _mesa_has_EXT_render_snorm(ctx);
4081
case GL_RGBA16_SNORM:
4082
return _mesa_has_EXT_texture_norm16(ctx) &&
4083
_mesa_has_EXT_render_snorm(ctx);
4090
* Returns true if \p internal_format is a sized internal format that
4091
* is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
4094
_mesa_is_es3_texture_filterable(const struct gl_context *ctx,
4095
GLenum internal_format)
4097
switch (internal_format) {
4108
case GL_RGBA8_SNORM:
4111
case GL_SRGB8_ALPHA8:
4116
case GL_R11F_G11F_B10F:
4124
case GL_RGB16_SNORM:
4126
case GL_RGBA16_SNORM:
4127
return _mesa_has_EXT_texture_norm16(ctx);
4132
/* The OES_texture_float_linear spec says:
4134
* "When implemented against OpenGL ES 3.0 or later versions, sized
4135
* 32-bit floating-point formats become texture-filterable. This
4136
* should be noted by, for example, checking the ``TF'' column of
4137
* table 8.13 in the ES 3.1 Specification (``Correspondence of sized
4138
* internal formats to base internal formats ... and use cases ...'')
4139
* for the R32F, RG32F, RGB32F, and RGBA32F formats."
4141
return _mesa_has_OES_texture_float_linear(ctx);