Hash :
86af3d27
Author :
Date :
2015-07-21T15:14:07
ES3: Fix assertion failure in validation edge case. Passing a 2D texture type to a 3D texture function could result in an explosion. BUG=angleproject:1079 TEST=dEQP-GLES3.functional.negative_api.texture.compressedteximage3d Change-Id: Ibfcc4bdb334270f8fa27ebed6bcc3911986e7c7c Reviewed-on: https://chromium-review.googlesource.com/286852 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
//
// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters
#include "libANGLE/validationES3.h"
#include "libANGLE/validationES.h"
#include "libANGLE/Context.h"
#include "libANGLE/Texture.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/FramebufferAttachment.h"
#include "common/mathutil.h"
#include "common/utilities.h"
namespace gl
{
struct ES3FormatCombination
{
GLenum internalFormat;
GLenum format;
GLenum type;
};
bool operator<(const ES3FormatCombination& a, const ES3FormatCombination& b)
{
return memcmp(&a, &b, sizeof(ES3FormatCombination)) < 0;
}
typedef std::set<ES3FormatCombination> ES3FormatCombinationSet;
static inline void InsertES3FormatCombo(ES3FormatCombinationSet *set, GLenum internalFormat, GLenum format, GLenum type)
{
ES3FormatCombination info;
info.internalFormat = internalFormat;
info.format = format;
info.type = type;
set->insert(info);
}
ES3FormatCombinationSet BuildES3FormatSet()
{
ES3FormatCombinationSet set;
// Format combinations from ES 3.0.1 spec, table 3.2
// | Internal format | Format | Type |
// | | | |
InsertES3FormatCombo(&set, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE );
InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 );
InsertES3FormatCombo(&set, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV );
InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV );
InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 );
InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_RGBA32F, GL_RGBA, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE );
InsertES3FormatCombo(&set, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT );
InsertES3FormatCombo(&set, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT );
InsertES3FormatCombo(&set, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT );
InsertES3FormatCombo(&set, GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV );
InsertES3FormatCombo(&set, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGB8_SNORM, GL_RGB, GL_BYTE );
InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 );
InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV );
InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV );
InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_RGB32F, GL_RGB, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_FLOAT );
InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE );
InsertES3FormatCombo(&set, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT );
InsertES3FormatCombo(&set, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT );
InsertES3FormatCombo(&set, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_RGB32I, GL_RGB_INTEGER, GL_INT );
InsertES3FormatCombo(&set, GL_RG8, GL_RG, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RG8_SNORM, GL_RG, GL_BYTE );
InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_RG32F, GL_RG, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RG8I, GL_RG_INTEGER, GL_BYTE );
InsertES3FormatCombo(&set, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT );
InsertES3FormatCombo(&set, GL_RG16I, GL_RG_INTEGER, GL_SHORT );
InsertES3FormatCombo(&set, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_RG32I, GL_RG_INTEGER, GL_INT );
InsertES3FormatCombo(&set, GL_R8, GL_RED, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_R8_SNORM, GL_RED, GL_BYTE );
InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_R32F, GL_RED, GL_FLOAT );
InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_FLOAT );
InsertES3FormatCombo(&set, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_R8I, GL_RED_INTEGER, GL_BYTE );
InsertES3FormatCombo(&set, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT );
InsertES3FormatCombo(&set, GL_R16I, GL_RED_INTEGER, GL_SHORT );
InsertES3FormatCombo(&set, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_R32I, GL_RED_INTEGER, GL_INT );
// Unsized formats
InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 );
InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 );
InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 );
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_FLOAT );
InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 );
// Depth stencil formats
InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT );
InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT );
InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT );
InsertES3FormatCombo(&set, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 );
InsertES3FormatCombo(&set, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
// From GL_EXT_sRGB
InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE );
// From GL_OES_texture_float
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT );
InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_FLOAT );
// From GL_OES_texture_half_float
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES );
// From GL_EXT_texture_format_BGRA8888
InsertES3FormatCombo(&set, GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE );
// From GL_EXT_texture_storage
// | Internal format | Format | Type |
// | | | |
InsertES3FormatCombo(&set, GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT );
InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT_OES );
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT );
InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES );
// From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888
InsertES3FormatCombo(&set, GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT);
InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE );
InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT);
InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE );
// From GL_ANGLE_depth_texture
InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES );
// Compressed formats
// From ES 3.0.1 spec, table 3.16
// | Internal format | Format | Type |
// | | | |
InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE);
// From GL_EXT_texture_compression_dxt1
InsertES3FormatCombo(&set, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE);
InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE);
// From GL_ANGLE_texture_compression_dxt3
InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE);
// From GL_ANGLE_texture_compression_dxt5
InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE);
return set;
}
static bool ValidateTexImageFormatCombination(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type)
{
// Note: dEQP 2013.4 expects an INVALID_VALUE error for TexImage3D with an invalid
// internal format. (dEQP-GLES3.functional.negative_api.texture.teximage3d)
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
// The type and format are valid if any supported internal format has that type and format
bool formatSupported = false;
bool typeSupported = false;
static const ES3FormatCombinationSet es3FormatSet = BuildES3FormatSet();
for (ES3FormatCombinationSet::const_iterator i = es3FormatSet.begin(); i != es3FormatSet.end(); i++)
{
if (i->format == format || i->type == type)
{
const gl::InternalFormat &info = gl::GetInternalFormatInfo(i->internalFormat);
bool supported = info.textureSupport(context->getClientVersion(), context->getExtensions());
if (supported && i->type == type)
{
typeSupported = true;
}
if (supported && i->format == format)
{
formatSupported = true;
}
// Early-out if both type and format are supported now
if (typeSupported && formatSupported)
{
break;
}
}
}
if (!typeSupported || !formatSupported)
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
// Check if this is a valid format combination to load texture data
ES3FormatCombination searchFormat;
searchFormat.internalFormat = internalFormat;
searchFormat.format = format;
searchFormat.type = type;
if (es3FormatSet.find(searchFormat) == es3FormatSet.end())
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
return true;
}
bool ValidateES3TexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, bool isCompressed, bool isSubImage,
GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum format, GLenum type, const GLvoid *pixels)
{
if (!ValidTexture2DDestinationTarget(context, target))
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
// Validate image size
if (!ValidImageSize(context, target, level, width, height, depth))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
// Verify zero border
if (border != 0)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (xoffset < 0 || yoffset < 0 || zoffset < 0 ||
std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height ||
std::numeric_limits<GLsizei>::max() - zoffset < depth)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
const gl::Caps &caps = context->getCaps();
switch (target)
{
case GL_TEXTURE_2D:
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if (!isSubImage && width != height)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
break;
case GL_TEXTURE_3D:
if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
break;
case GL_TEXTURE_2D_ARRAY:
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(depth) > (caps.maxArrayTextureLayers >> level))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
break;
default:
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
if (!texture)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
if (texture->isImmutable() && !isSubImage)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
// Validate texture formats
GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat;
const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat);
if (isCompressed)
{
if (!ValidCompressedImageSize(context, actualInternalFormat, width, height))
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
if (!actualFormatInfo.compressed)
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
if (target == GL_TEXTURE_3D)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
else
{
if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type))
{
return false;
}
if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
// Validate sub image parameters
if (isSubImage)
{
if (isCompressed != actualFormatInfo.compressed)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
if (width == 0 || height == 0 || depth == 0)
{
return false;
}
if (xoffset < 0 || yoffset < 0 || zoffset < 0)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height ||
std::numeric_limits<GLsizei>::max() - zoffset < depth)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) ||
static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
// Check for pixel unpack buffer related API errors
gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER);
if (pixelUnpackBuffer != NULL)
{
// ...the data would be unpacked from the buffer object such that the memory reads required
// would exceed the data store size.
size_t widthSize = static_cast<size_t>(width);
size_t heightSize = static_cast<size_t>(height);
size_t depthSize = static_cast<size_t>(depth);
GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type);
size_t pixelBytes = static_cast<size_t>(gl::GetInternalFormatInfo(sizedFormat).pixelBytes);
if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) ||
!rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) ||
!rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes))
{
// Overflow past the end of the buffer
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat);
size_t copyBytes = formatInfo.computeBlockSize(type, width, height);
size_t offset = reinterpret_cast<size_t>(pixels);
if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) ||
((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize())))
{
// Overflow past the end of the buffer
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
// ...data is not evenly divisible into the number of bytes needed to store in memory a datum
// indicated by type.
if (!isCompressed)
{
size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes);
if ((offset % dataBytesPerPixel) != 0)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
// ...the buffer object's data store is currently mapped.
if (pixelUnpackBuffer->isMapped())
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
return true;
}
struct EffectiveInternalFormatInfo
{
GLenum mEffectiveFormat;
GLenum mDestFormat;
GLuint mMinRedBits;
GLuint mMaxRedBits;
GLuint mMinGreenBits;
GLuint mMaxGreenBits;
GLuint mMinBlueBits;
GLuint mMaxBlueBits;
GLuint mMinAlphaBits;
GLuint mMaxAlphaBits;
EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits,
GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits,
GLuint minAlphaBits, GLuint maxAlphaBits)
: mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits),
mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits),
mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits),
mMaxAlphaBits(maxAlphaBits) {};
};
typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList;
static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList()
{
EffectiveInternalFormatList list;
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
// linear source buffer component sizes.
// | Source channel min/max sizes |
// Effective Internal Format | N/A | R | G | B | A |
list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8));
list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0));
list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0));
list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0));
list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0));
list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4));
list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1));
list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8));
list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2));
return list;
}
static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList()
{
EffectiveInternalFormatList list;
// OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and
// linear source buffer component sizes.
// | Source channel min/max sizes |
// Effective Internal Format | Dest Format | R | G | B | A |
list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX));
list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8));
list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX));
list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX));
list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4));
list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1));
list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8));
return list;
}
static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat,
GLenum *outEffectiveFormat)
{
const EffectiveInternalFormatList *list = NULL;
GLenum targetFormat = GL_NONE;
if (destFormat.pixelBytes > 0)
{
static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList();
list = &sizedList;
}
else
{
static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList();
list = &unsizedList;
targetFormat = destFormat.format;
}
for (size_t curFormat = 0; curFormat < list->size(); ++curFormat)
{
const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat);
if ((formatInfo.mDestFormat == targetFormat) &&
(formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) &&
(formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) &&
(formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) &&
(formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits))
{
*outEffectiveFormat = formatInfo.mEffectiveFormat;
return true;
}
}
return false;
}
struct CopyConversion
{
GLenum mTextureFormat;
GLenum mFramebufferFormat;
CopyConversion(GLenum textureFormat, GLenum framebufferFormat)
: mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { }
bool operator<(const CopyConversion& other) const
{
return memcmp(this, &other, sizeof(CopyConversion)) < 0;
}
};
typedef std::set<CopyConversion> CopyConversionSet;
static CopyConversionSet BuildValidES3CopyTexImageCombinations()
{
CopyConversionSet set;
// From ES 3.0.1 spec, table 3.15
set.insert(CopyConversion(GL_ALPHA, GL_RGBA));
set.insert(CopyConversion(GL_LUMINANCE, GL_RED));
set.insert(CopyConversion(GL_LUMINANCE, GL_RG));
set.insert(CopyConversion(GL_LUMINANCE, GL_RGB));
set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA));
set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA));
set.insert(CopyConversion(GL_RED, GL_RED));
set.insert(CopyConversion(GL_RED, GL_RG));
set.insert(CopyConversion(GL_RED, GL_RGB));
set.insert(CopyConversion(GL_RED, GL_RGBA));
set.insert(CopyConversion(GL_RG, GL_RG));
set.insert(CopyConversion(GL_RG, GL_RGB));
set.insert(CopyConversion(GL_RG, GL_RGBA));
set.insert(CopyConversion(GL_RGB, GL_RGB));
set.insert(CopyConversion(GL_RGB, GL_RGBA));
set.insert(CopyConversion(GL_RGBA, GL_RGBA));
// Necessary for ANGLE back-buffers
set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT));
set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT));
set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT));
set.insert(CopyConversion(GL_RED, GL_BGRA_EXT));
set.insert(CopyConversion(GL_RG, GL_BGRA_EXT));
set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT));
set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT));
set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER));
set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER));
set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER));
set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER));
set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER));
set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER));
set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER));
set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER));
set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER));
set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER));
return set;
}
static bool IsValidES3CopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle)
{
const InternalFormat &textureInternalFormatInfo = GetInternalFormatInfo(textureInternalFormat);
const InternalFormat &framebufferInternalFormatInfo = GetInternalFormatInfo(frameBufferInternalFormat);
static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations();
if (conversionSet.find(CopyConversion(textureInternalFormatInfo.format, framebufferInternalFormatInfo.format)) != conversionSet.end())
{
// Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats
// must both be signed, unsigned, or fixed point and both source and destinations
// must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed
// conversion between fixed and floating point.
if ((textureInternalFormatInfo.colorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.colorEncoding == GL_SRGB))
{
return false;
}
if (((textureInternalFormatInfo.componentType == GL_INT) != (framebufferInternalFormatInfo.componentType == GL_INT )) ||
((textureInternalFormatInfo.componentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.componentType == GL_UNSIGNED_INT)))
{
return false;
}
if ((textureInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED ||
textureInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED ||
textureInternalFormatInfo.componentType == GL_FLOAT) &&
!(framebufferInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED ||
framebufferInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED ||
framebufferInternalFormatInfo.componentType == GL_FLOAT))
{
return false;
}
// GLES specification 3.0.3, sec 3.8.5, pg 139-140:
// The effective internal format of the source buffer is determined with the following rules applied in order:
// * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the
// effective internal format is the source buffer's sized internal format.
// * If the source buffer is a texture that was created with an unsized base internal format, then the
// effective internal format is the source image array's effective internal format, as specified by table
// 3.12, which is determined from the <format> and <type> that were used when the source image array was
// specified by TexImage*.
// * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where
// Destination Internal Format matches internalformat and where the [source channel sizes] are consistent
// with the values of the source buffer's [channel sizes]. Table 3.17 is used if the
// FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING
// is SRGB.
const InternalFormat *sourceEffectiveFormat = NULL;
if (readBufferHandle != 0)
{
// Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer
if (framebufferInternalFormatInfo.pixelBytes > 0)
{
sourceEffectiveFormat = &framebufferInternalFormatInfo;
}
else
{
// Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format
// texture. We can use the same table we use when creating textures to get its effective sized format.
GLenum sizedInternalFormat = GetSizedInternalFormat(framebufferInternalFormatInfo.format, framebufferInternalFormatInfo.type);
sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat);
}
}
else
{
// The effective internal format must be derived from the source framebuffer's channel sizes.
// This is done in GetEffectiveInternalFormat for linear buffers (table 3.17)
if (framebufferInternalFormatInfo.colorEncoding == GL_LINEAR)
{
GLenum effectiveFormat;
if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, &effectiveFormat))
{
sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat);
}
else
{
return false;
}
}
else if (framebufferInternalFormatInfo.colorEncoding == GL_SRGB)
{
// SRGB buffers can only be copied to sized format destinations according to table 3.18
if ((textureInternalFormatInfo.pixelBytes > 0) &&
(framebufferInternalFormatInfo.redBits >= 1 && framebufferInternalFormatInfo.redBits <= 8) &&
(framebufferInternalFormatInfo.greenBits >= 1 && framebufferInternalFormatInfo.greenBits <= 8) &&
(framebufferInternalFormatInfo.blueBits >= 1 && framebufferInternalFormatInfo.blueBits <= 8) &&
(framebufferInternalFormatInfo.alphaBits >= 1 && framebufferInternalFormatInfo.alphaBits <= 8))
{
sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8);
}
else
{
return false;
}
}
else
{
UNREACHABLE();
return false;
}
}
if (textureInternalFormatInfo.pixelBytes > 0)
{
// Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized,
// component sizes of the source and destination formats must exactly match
if (textureInternalFormatInfo.redBits != sourceEffectiveFormat->redBits ||
textureInternalFormatInfo.greenBits != sourceEffectiveFormat->greenBits ||
textureInternalFormatInfo.blueBits != sourceEffectiveFormat->blueBits ||
textureInternalFormatInfo.alphaBits != sourceEffectiveFormat->alphaBits)
{
return false;
}
}
return true; // A conversion function exists, and no rule in the specification has precluded conversion
// between these formats.
}
return false;
}
bool ValidateES3CopyTexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat,
bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset,
GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
GLenum textureInternalFormat;
if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
xoffset, yoffset, zoffset, x, y, width, height,
border, &textureInternalFormat))
{
return false;
}
gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE)
{
context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
if (context->getState().getReadFramebuffer()->id() != 0 &&
framebuffer->getSamples(context->getData()) != 0)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer();
GLenum colorbufferInternalFormat = source->getInternalFormat();
if (isSubImage)
{
if (!IsValidES3CopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
context->getState().getReadFramebuffer()->id()))
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
else
{
if (!gl::IsValidES3CopyTexImageCombination(internalformat, colorbufferInternalFormat,
context->getState().getReadFramebuffer()->id()))
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
// If width or height is zero, it is a no-op. Return false without setting an error.
return (width > 0 && height > 0);
}
bool ValidateES3TexStorageParameters(Context *context, GLenum target, GLsizei levels, GLenum internalformat,
GLsizei width, GLsizei height, GLsizei depth)
{
if (width < 1 || height < 1 || depth < 1 || levels < 1)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::Caps &caps = context->getCaps();
switch (target)
{
case GL_TEXTURE_2D:
{
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
case GL_TEXTURE_CUBE_MAP:
{
if (width != height)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
case GL_TEXTURE_3D:
{
if (static_cast<GLuint>(width) > caps.max3DTextureSize ||
static_cast<GLuint>(height) > caps.max3DTextureSize ||
static_cast<GLuint>(depth) > caps.max3DTextureSize)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
case GL_TEXTURE_2D_ARRAY:
{
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize ||
static_cast<GLuint>(depth) > caps.maxArrayTextureLayers)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
default:
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
gl::Texture *texture = context->getTargetTexture(target);
if (!texture || texture->id() == 0)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
if (texture->isImmutable())
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
if (formatInfo.pixelBytes == 0)
{
context->recordError(Error(GL_INVALID_ENUM));
return false;
}
return true;
}
bool ValidateFramebufferTextureLayer(Context *context, GLenum target, GLenum attachment,
GLuint texture, GLint level, GLint layer)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
if (layer < 0)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
{
return false;
}
const gl::Caps &caps = context->getCaps();
if (texture != 0)
{
gl::Texture *tex = context->getTexture(texture);
ASSERT(tex);
switch (tex->getTarget())
{
case GL_TEXTURE_2D_ARRAY:
{
if (level > gl::log2(caps.max2DTextureSize))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
case GL_TEXTURE_3D:
{
if (level > gl::log2(caps.max3DTextureSize))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
if (static_cast<GLuint>(layer) >= caps.max3DTextureSize)
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
}
break;
default:
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level));
if (internalFormatInfo.compressed)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
}
return true;
}
bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type)
{
const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
switch (format)
{
case GL_RGBA:
switch (type)
{
case GL_UNSIGNED_BYTE:
break;
case GL_UNSIGNED_INT_2_10_10_10_REV:
if (internalFormat != GL_RGB10_A2)
{
return false;
}
break;
case GL_FLOAT:
if (internalFormatInfo.componentType != GL_FLOAT)
{
return false;
}
break;
default:
return false;
}
break;
case GL_RGBA_INTEGER:
switch (type)
{
case GL_INT:
if (internalFormatInfo.componentType != GL_INT)
{
return false;
}
break;
case GL_UNSIGNED_INT:
if (internalFormatInfo.componentType != GL_UNSIGNED_INT)
{
return false;
}
break;
default:
return false;
}
break;
case GL_BGRA_EXT:
switch (type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
break;
default:
return false;
}
break;
case GL_RG_EXT:
case GL_RED_EXT:
if (!context->getExtensions().textureRG)
{
return false;
}
switch (type)
{
case GL_UNSIGNED_BYTE:
break;
default:
return false;
}
break;
default:
return false;
}
return true;
}
bool ValidateES3RenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples,
GLenum internalformat, GLsizei width, GLsizei height)
{
if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height))
{
return false;
}
//The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer format if samples is greater than zero.
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
// The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY.
const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
return true;
}
bool ValidateInvalidateFramebuffer(Context *context, GLenum target, GLsizei numAttachments,
const GLenum *attachments)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION, "Operation only supported on ES 3.0 and above"));
return false;
}
bool defaultFramebuffer = false;
switch (target)
{
case GL_DRAW_FRAMEBUFFER:
case GL_FRAMEBUFFER:
defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0;
break;
case GL_READ_FRAMEBUFFER:
defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0;
break;
default:
context->recordError(Error(GL_INVALID_ENUM, "Invalid framebuffer target"));
return false;
}
return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer);
}
bool ValidateClearBuffer(Context *context)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE)
{
context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
return true;
}
bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint* params)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
return ValidateGetUniformBase(context, program, location);
}
bool ValidateReadBuffer(Context *context, GLenum src)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
Framebuffer *readFBO = context->getState().getReadFramebuffer();
if (readFBO == nullptr)
{
context->recordError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer."));
return false;
}
if (src == GL_NONE)
{
return true;
}
if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT15))
{
context->recordError(gl::Error(GL_INVALID_ENUM, "Unknown enum for 'src' in ReadBuffer"));
return false;
}
if (readFBO->id() == 0)
{
if (src != GL_BACK)
{
const char *errorMsg = "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer.";
context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg));
return false;
}
}
else
{
GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0);
if (drawBuffer >= context->getCaps().maxDrawBuffers)
{
const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS.";
context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg));
return false;
}
}
return true;
}
bool ValidateCompressedTexImage3D(Context *context,
GLenum target,
GLint level,
GLenum internalformat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLsizei imageSize,
const GLvoid *data)
{
if (context->getClientVersion() < 3)
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
}
const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat);
if (imageSize < 0 ||
static_cast<GLuint>(imageSize) !=
formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
{
context->recordError(Error(GL_INVALID_VALUE));
return false;
}
// 3D texture target validation
if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY)
{
context->recordError(
Error(GL_INVALID_ENUM, "Must specify a valid 3D texture destination target"));
return false;
}
// validateES3TexImageFormat sets the error code if there is an error
if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false, 0, 0, 0,
width, height, depth, border, GL_NONE, GL_NONE, data))
{
return false;
}
return true;
}
}