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 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
|
// rendergl.cpp: core opengl rendering stuff
#include "engine.h"
bool hasVBO = false, hasDRE = false, hasOQ = false, hasTR = false, hasFBO = false, hasDS = false, hasTF = false, hasBE = false, hasBC = false, hasCM = false, hasNP2 = false, hasTC = false, hasS3TC = false, hasFXT1 = false, hasTE = false, hasMT = false, hasD3 = false, hasAF = false, hasVP2 = false, hasVP3 = false, hasPP = false, hasMDA = false, hasTE3 = false, hasTE4 = false, hasVP = false, hasFP = false, hasGLSL = false, hasGM = false, hasNVFB = false, hasSGIDT = false, hasSGISH = false, hasDT = false, hasSH = false, hasNVPCF = false, hasRN = false, hasPBO = false, hasFBB = false, hasUBO = false, hasBUE = false, hasMBR = false, hasFC = false, hasTEX = false;
int hasstencil = 0;
VAR(renderpath, 1, 0, 0);
VAR(glversion, 1, 0, 0);
VAR(glslversion, 1, 0, 0);
// GL_ARB_vertex_buffer_object, GL_ARB_pixel_buffer_object
PFNGLGENBUFFERSARBPROC glGenBuffers_ = NULL;
PFNGLBINDBUFFERARBPROC glBindBuffer_ = NULL;
PFNGLMAPBUFFERARBPROC glMapBuffer_ = NULL;
PFNGLUNMAPBUFFERARBPROC glUnmapBuffer_ = NULL;
PFNGLBUFFERDATAARBPROC glBufferData_ = NULL;
PFNGLBUFFERSUBDATAARBPROC glBufferSubData_ = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers_ = NULL;
PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubData_ = NULL;
// GL_ARB_multitexture
PFNGLACTIVETEXTUREARBPROC glActiveTexture_ = NULL;
PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTexture_ = NULL;
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2f_ = NULL;
PFNGLMULTITEXCOORD3FARBPROC glMultiTexCoord3f_ = NULL;
PFNGLMULTITEXCOORD4FARBPROC glMultiTexCoord4f_ = NULL;
// GL_ARB_vertex_program, GL_ARB_fragment_program
PFNGLGENPROGRAMSARBPROC glGenProgramsARB_ = NULL;
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB_ = NULL;
PFNGLBINDPROGRAMARBPROC glBindProgramARB_ = NULL;
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB_ = NULL;
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB_ = NULL;
PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB_ = NULL;
PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB_ = NULL;
// GL_EXT_gpu_program_parameters
PFNGLPROGRAMENVPARAMETERS4FVEXTPROC glProgramEnvParameters4fv_ = NULL;
PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC glProgramLocalParameters4fv_ = NULL;
// GL_ARB_occlusion_query
PFNGLGENQUERIESARBPROC glGenQueries_ = NULL;
PFNGLDELETEQUERIESARBPROC glDeleteQueries_ = NULL;
PFNGLBEGINQUERYARBPROC glBeginQuery_ = NULL;
PFNGLENDQUERYARBPROC glEndQuery_ = NULL;
PFNGLGETQUERYIVARBPROC glGetQueryiv_ = NULL;
PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectiv_ = NULL;
PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuiv_ = NULL;
// GL_EXT_framebuffer_object
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbuffer_ = NULL;
PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffers_ = NULL;
PFNGLGENFRAMEBUFFERSEXTPROC glGenRenderbuffers_ = NULL;
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorage_ = NULL;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatus_ = NULL;
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebuffer_ = NULL;
PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffers_ = NULL;
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffers_ = NULL;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2D_ = NULL;
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbuffer_ = NULL;
PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmap_ = NULL;
// GL_EXT_framebuffer_blit
PFNGLBLITFRAMEBUFFEREXTPROC glBlitFramebuffer_ = NULL;
// OpenGL 2.0: GL_ARB_shading_language_100, GL_ARB_shader_objects, GL_ARB_fragment_shader, GL_ARB_vertex_shader
#ifndef __APPLE__
PFNGLCREATEPROGRAMPROC glCreateProgram_ = NULL;
PFNGLDELETEPROGRAMPROC glDeleteProgram_ = NULL;
PFNGLUSEPROGRAMPROC glUseProgram_ = NULL;
PFNGLCREATESHADERPROC glCreateShader_ = NULL;
PFNGLDELETESHADERPROC glDeleteShader_ = NULL;
PFNGLSHADERSOURCEPROC glShaderSource_ = NULL;
PFNGLCOMPILESHADERPROC glCompileShader_ = NULL;
PFNGLGETSHADERIVPROC glGetShaderiv_ = NULL;
PFNGLGETPROGRAMIVPROC glGetProgramiv_ = NULL;
PFNGLATTACHSHADERPROC glAttachShader_ = NULL;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog_ = NULL;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog_ = NULL;
PFNGLLINKPROGRAMPROC glLinkProgram_ = NULL;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation_ = NULL;
PFNGLUNIFORM1FPROC glUniform1f_ = NULL;
PFNGLUNIFORM2FPROC glUniform2f_ = NULL;
PFNGLUNIFORM3FPROC glUniform3f_ = NULL;
PFNGLUNIFORM4FPROC glUniform4f_ = NULL;
PFNGLUNIFORM1FVPROC glUniform1fv_ = NULL;
PFNGLUNIFORM2FVPROC glUniform2fv_ = NULL;
PFNGLUNIFORM3FVPROC glUniform3fv_ = NULL;
PFNGLUNIFORM4FVPROC glUniform4fv_ = NULL;
PFNGLUNIFORM1IPROC glUniform1i_ = NULL;
PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation_ = NULL;
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform_ = NULL;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray_ = NULL;
PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray_ = NULL;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer_ = NULL;
PFNGLUNIFORMMATRIX2X3FVPROC glUniformMatrix2x3fv_ = NULL;
PFNGLUNIFORMMATRIX3X2FVPROC glUniformMatrix3x2fv_ = NULL;
PFNGLUNIFORMMATRIX2X4FVPROC glUniformMatrix2x4fv_ = NULL;
PFNGLUNIFORMMATRIX4X2FVPROC glUniformMatrix4x2fv_ = NULL;
PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv_ = NULL;
PFNGLUNIFORMMATRIX4X3FVPROC glUniformMatrix4x3fv_ = NULL;
#endif
// GL_EXT_draw_range_elements
PFNGLDRAWRANGEELEMENTSEXTPROC glDrawRangeElements_ = NULL;
// GL_EXT_blend_minmax
PFNGLBLENDEQUATIONEXTPROC glBlendEquation_ = NULL;
// GL_EXT_blend_color
PFNGLBLENDCOLOREXTPROC glBlendColor_ = NULL;
// GL_EXT_multi_draw_arrays
PFNGLMULTIDRAWARRAYSEXTPROC glMultiDrawArrays_ = NULL;
PFNGLMULTIDRAWELEMENTSEXTPROC glMultiDrawElements_ = NULL;
// GL_ARB_texture_compression
PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3D_ = NULL;
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2D_ = NULL;
PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1D_ = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3D_ = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2D_ = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1D_ = NULL;
PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImage_ = NULL;
// GL_ARB_uniform_buffer_object
PFNGLGETUNIFORMINDICESPROC glGetUniformIndices_ = NULL;
PFNGLGETACTIVEUNIFORMSIVPROC glGetActiveUniformsiv_ = NULL;
PFNGLGETUNIFORMBLOCKINDEXPROC glGetUniformBlockIndex_ = NULL;
PFNGLGETACTIVEUNIFORMBLOCKIVPROC glGetActiveUniformBlockiv_ = NULL;
PFNGLUNIFORMBLOCKBINDINGPROC glUniformBlockBinding_ = NULL;
PFNGLBINDBUFFERBASEPROC glBindBufferBase_ = NULL;
PFNGLBINDBUFFERRANGEPROC glBindBufferRange_ = NULL;
// GL_EXT_bindable_uniform
PFNGLUNIFORMBUFFEREXTPROC glUniformBuffer_ = NULL;
PFNGLGETUNIFORMBUFFERSIZEEXTPROC glGetUniformBufferSize_ = NULL;
PFNGLGETUNIFORMOFFSETEXTPROC glGetUniformOffset_ = NULL;
// GL_EXT_fog_coord
PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ = NULL;
// GL_ARB_map_buffer_range
PFNGLMAPBUFFERRANGEPROC glMapBufferRange_ = NULL;
PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange_ = NULL;
void *getprocaddress(const char *name)
{
return SDL_GL_GetProcAddress(name);
}
VARP(ati_skybox_bug, 0, 0, 1);
VAR(ati_oq_bug, 0, 0, 1);
VAR(ati_minmax_bug, 0, 0, 1);
VAR(ati_dph_bug, 0, 0, 1);
VAR(ati_line_bug, 0, 0, 1);
VAR(ati_cubemap_bug, 0, 0, 1);
VAR(ati_ubo_bug, 0, 0, 1);
VAR(nvidia_scissor_bug, 0, 0, 1);
VAR(intel_immediate_bug, 0, 0, 1);
VAR(intel_vertexarray_bug, 0, 0, 1);
VAR(apple_glsldepth_bug, 0, 0, 1);
VAR(apple_ff_bug, 0, 0, 1);
VAR(apple_vp_bug, 0, 0, 1);
VAR(sdl_backingstore_bug, -1, 0, 1);
VAR(avoidshaders, 1, 0, 0);
VAR(preferglsl, 1, 0, 0);
VAR(minimizetcusage, 1, 0, 0);
VAR(emulatefog, 1, 0, 0);
VAR(usevp2, 1, 0, 0);
VAR(usevp3, 1, 0, 0);
VAR(usetexrect, 1, 0, 0);
VAR(hasglsl, 1, 0, 0);
VAR(useubo, 1, 0, 0);
VAR(usebue, 1, 0, 0);
VAR(usetexcompress, 1, 0, 0);
VAR(rtscissor, 0, 1, 1);
VAR(blurtile, 0, 1, 1);
VAR(rtsharefb, 0, 1, 1);
static bool checkseries(const char *s, int low, int high)
{
while(*s && !isdigit(*s)) ++s;
if(!*s) return false;
int n = 0;
while(isdigit(*s)) n = n*10 + (*s++ - '0');
return n >= low && n < high;
}
VAR(dbgexts, 0, 0, 1);
bool hasext(const char *exts, const char *ext)
{
int len = strlen(ext);
if(len) for(const char *cur = exts; (cur = strstr(cur, ext)); cur += len)
{
if((cur == exts || cur[-1] == ' ') && (cur[len] == ' ' || !cur[len])) return true;
}
return false;
}
void gl_checkextensions()
{
const char *vendor = (const char *)glGetString(GL_VENDOR);
const char *exts = (const char *)glGetString(GL_EXTENSIONS);
const char *renderer = (const char *)glGetString(GL_RENDERER);
const char *version = (const char *)glGetString(GL_VERSION);
conoutf(CON_INIT, "Renderer: %s (%s)", renderer, vendor);
conoutf(CON_INIT, "Driver: %s", version);
#ifdef __APPLE__
extern int mac_osversion();
int osversion = mac_osversion(); /* 0x0A0500 = 10.5 (Leopard) */
sdl_backingstore_bug = -1;
#endif
bool mesa = false, intel = false, ati = false, nvidia = false;
if(strstr(renderer, "Mesa") || strstr(version, "Mesa"))
{
mesa = true;
if(strstr(renderer, "Intel")) intel = true;
}
else if(strstr(vendor, "NVIDIA"))
nvidia = true;
else if(strstr(vendor, "ATI") || strstr(vendor, "Advanced Micro Devices"))
ati = true;
else if(strstr(vendor, "Intel"))
intel = true;
uint glmajorversion, glminorversion;
if(sscanf(version, " %u.%u", &glmajorversion, &glminorversion) != 2) glversion = 100;
else glversion = glmajorversion*100 + glminorversion*10;
//extern int shaderprecision;
// default to low precision shaders on certain cards, can be overridden with -f3
// char *weakcards[] = { "GeForce FX", "Quadro FX", "6200", "9500", "9550", "9600", "9700", "9800", "X300", "X600", "FireGL", "Intel", "Chrome", NULL }
// if(shaderprecision==2) for(char **wc = weakcards; *wc; wc++) if(strstr(renderer, *wc)) shaderprecision = 1;
GLint val;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &val);
hwtexsize = val;
if(hasext(exts, "GL_EXT_texture_env_combine") || hasext(exts, "GL_ARB_texture_env_combine"))
{
hasTE = true;
if(hasext(exts, "GL_ARB_texture_env_crossbar")) hasTEX = true;
if(hasext(exts, "GL_ATI_texture_env_combine3")) hasTE3 = true;
if(hasext(exts, "GL_NV_texture_env_combine4")) hasTE4 = true;
if(hasext(exts, "GL_EXT_texture_env_dot3") || hasext(exts, "GL_ARB_texture_env_dot3")) hasD3 = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_env_combine extension.");
}
else conoutf(CON_WARN, "WARNING: No texture_env_combine extension! (your video card is WAY too old)");
if(hasext(exts, "GL_ARB_multitexture"))
{
glActiveTexture_ = (PFNGLACTIVETEXTUREARBPROC) getprocaddress("glActiveTextureARB");
glClientActiveTexture_ = (PFNGLCLIENTACTIVETEXTUREARBPROC)getprocaddress("glClientActiveTextureARB");
glMultiTexCoord2f_ = (PFNGLMULTITEXCOORD2FARBPROC) getprocaddress("glMultiTexCoord2fARB");
glMultiTexCoord3f_ = (PFNGLMULTITEXCOORD3FARBPROC) getprocaddress("glMultiTexCoord3fARB");
glMultiTexCoord4f_ = (PFNGLMULTITEXCOORD4FARBPROC) getprocaddress("glMultiTexCoord4fARB");
hasMT = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_multitexture extension.");
}
else conoutf(CON_WARN, "WARNING: No multitexture extension!");
if(hasext(exts, "GL_ARB_vertex_buffer_object"))
{
hasVBO = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_vertex_buffer_object extension.");
}
else conoutf(CON_WARN, "WARNING: No vertex_buffer_object extension! (geometry heavy maps will be SLOW)");
#ifdef __APPLE__
/* VBOs over 256KB seem to destroy performance on 10.5, but not in 10.6 */
extern int maxvbosize;
if(osversion < 0x0A0600) maxvbosize = min(maxvbosize, 8192);
#endif
if(hasext(exts, "GL_ARB_pixel_buffer_object"))
{
hasPBO = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_pixel_buffer_object extension.");
}
if(hasVBO || hasPBO)
{
glGenBuffers_ = (PFNGLGENBUFFERSARBPROC) getprocaddress("glGenBuffersARB");
glBindBuffer_ = (PFNGLBINDBUFFERARBPROC) getprocaddress("glBindBufferARB");
glMapBuffer_ = (PFNGLMAPBUFFERARBPROC) getprocaddress("glMapBufferARB");
glUnmapBuffer_ = (PFNGLUNMAPBUFFERARBPROC) getprocaddress("glUnmapBufferARB");
glBufferData_ = (PFNGLBUFFERDATAARBPROC) getprocaddress("glBufferDataARB");
glBufferSubData_ = (PFNGLBUFFERSUBDATAARBPROC) getprocaddress("glBufferSubDataARB");
glDeleteBuffers_ = (PFNGLDELETEBUFFERSARBPROC) getprocaddress("glDeleteBuffersARB");
glGetBufferSubData_ = (PFNGLGETBUFFERSUBDATAARBPROC)getprocaddress("glGetBufferSubDataARB");
}
if(hasext(exts, "GL_EXT_draw_range_elements"))
{
glDrawRangeElements_ = (PFNGLDRAWRANGEELEMENTSEXTPROC)getprocaddress("glDrawRangeElementsEXT");
hasDRE = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_draw_range_elements extension.");
}
if(hasext(exts, "GL_EXT_multi_draw_arrays"))
{
glMultiDrawArrays_ = (PFNGLMULTIDRAWARRAYSEXTPROC) getprocaddress("glMultiDrawArraysEXT");
glMultiDrawElements_ = (PFNGLMULTIDRAWELEMENTSEXTPROC)getprocaddress("glMultiDrawElementsEXT");
hasMDA = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_multi_draw_arrays extension.");
}
#ifdef __APPLE__
// floating point FBOs not fully supported until 10.5
if(osversion>=0x0A0500)
#endif
if(hasext(exts, "GL_ARB_texture_float") || hasext(exts, "GL_ATI_texture_float"))
{
hasTF = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_float extension.");
shadowmap = 1;
extern int smoothshadowmappeel;
smoothshadowmappeel = 1;
}
if(hasext(exts, "GL_NV_float_buffer"))
{
hasNVFB = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_NV_float_buffer extension.");
}
if(hasext(exts, "GL_EXT_framebuffer_object"))
{
glBindRenderbuffer_ = (PFNGLBINDRENDERBUFFEREXTPROC) getprocaddress("glBindRenderbufferEXT");
glDeleteRenderbuffers_ = (PFNGLDELETERENDERBUFFERSEXTPROC) getprocaddress("glDeleteRenderbuffersEXT");
glGenRenderbuffers_ = (PFNGLGENFRAMEBUFFERSEXTPROC) getprocaddress("glGenRenderbuffersEXT");
glRenderbufferStorage_ = (PFNGLRENDERBUFFERSTORAGEEXTPROC) getprocaddress("glRenderbufferStorageEXT");
glCheckFramebufferStatus_ = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) getprocaddress("glCheckFramebufferStatusEXT");
glBindFramebuffer_ = (PFNGLBINDFRAMEBUFFEREXTPROC) getprocaddress("glBindFramebufferEXT");
glDeleteFramebuffers_ = (PFNGLDELETEFRAMEBUFFERSEXTPROC) getprocaddress("glDeleteFramebuffersEXT");
glGenFramebuffers_ = (PFNGLGENFRAMEBUFFERSEXTPROC) getprocaddress("glGenFramebuffersEXT");
glFramebufferTexture2D_ = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) getprocaddress("glFramebufferTexture2DEXT");
glFramebufferRenderbuffer_ = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)getprocaddress("glFramebufferRenderbufferEXT");
glGenerateMipmap_ = (PFNGLGENERATEMIPMAPEXTPROC) getprocaddress("glGenerateMipmapEXT");
hasFBO = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_framebuffer_object extension.");
if(hasext(exts, "GL_EXT_framebuffer_blit"))
{
glBlitFramebuffer_ = (PFNGLBLITFRAMEBUFFEREXTPROC) getprocaddress("glBlitFramebufferEXT");
hasFBB = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_framebuffer_blit extension.");
}
}
else conoutf(CON_WARN, "WARNING: No framebuffer object support. (reflective water may be slow)");
if(hasext(exts, "GL_ARB_occlusion_query"))
{
GLint bits;
glGetQueryiv_ = (PFNGLGETQUERYIVARBPROC)getprocaddress("glGetQueryivARB");
glGetQueryiv_(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &bits);
if(bits)
{
glGenQueries_ = (PFNGLGENQUERIESARBPROC) getprocaddress("glGenQueriesARB");
glDeleteQueries_ = (PFNGLDELETEQUERIESARBPROC) getprocaddress("glDeleteQueriesARB");
glBeginQuery_ = (PFNGLBEGINQUERYARBPROC) getprocaddress("glBeginQueryARB");
glEndQuery_ = (PFNGLENDQUERYARBPROC) getprocaddress("glEndQueryARB");
glGetQueryObjectiv_ = (PFNGLGETQUERYOBJECTIVARBPROC) getprocaddress("glGetQueryObjectivARB");
glGetQueryObjectuiv_ = (PFNGLGETQUERYOBJECTUIVARBPROC)getprocaddress("glGetQueryObjectuivARB");
hasOQ = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_occlusion_query extension.");
#if defined(__APPLE__) && SDL_BYTEORDER == SDL_BIG_ENDIAN
if(ati && (osversion<0x0A0500)) ati_oq_bug = 1;
#endif
//if(ati_oq_bug) conoutf(CON_WARN, "WARNING: Using ATI occlusion query bug workaround. (use \"/ati_oq_bug 0\" to disable if unnecessary)");
}
}
if(!hasOQ)
{
conoutf(CON_WARN, "WARNING: No occlusion query support! (large maps may be SLOW)");
extern int vacubesize;
vacubesize = 64;
waterreflect = 0;
}
if(hasext(exts, "GL_ARB_vertex_program") && hasext(exts, "GL_ARB_fragment_program"))
{
hasVP = hasFP = true;
glGenProgramsARB_ = (PFNGLGENPROGRAMSARBPROC) getprocaddress("glGenProgramsARB");
glDeleteProgramsARB_ = (PFNGLDELETEPROGRAMSARBPROC) getprocaddress("glDeleteProgramsARB");
glBindProgramARB_ = (PFNGLBINDPROGRAMARBPROC) getprocaddress("glBindProgramARB");
glProgramStringARB_ = (PFNGLPROGRAMSTRINGARBPROC) getprocaddress("glProgramStringARB");
glGetProgramivARB_ = (PFNGLGETPROGRAMIVARBPROC) getprocaddress("glGetProgramivARB");
glProgramEnvParameter4fARB_ = (PFNGLPROGRAMENVPARAMETER4FARBPROC) getprocaddress("glProgramEnvParameter4fARB");
glProgramEnvParameter4fvARB_ = (PFNGLPROGRAMENVPARAMETER4FVARBPROC) getprocaddress("glProgramEnvParameter4fvARB");
#ifndef __APPLE__
glEnableVertexAttribArray_ = (PFNGLENABLEVERTEXATTRIBARRAYPROC) getprocaddress("glEnableVertexAttribArrayARB");
glDisableVertexAttribArray_ = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) getprocaddress("glDisableVertexAttribArrayARB");
glVertexAttribPointer_ = (PFNGLVERTEXATTRIBPOINTERPROC) getprocaddress("glVertexAttribPointerARB");
#endif
if(ati) ati_dph_bug = ati_line_bug = 1;
#ifdef __APPLE__
if(osversion>=0x0A0500) // fixed in 1055 for some hardware.. but not all..
{
apple_ff_bug = 1;
//conoutf(CON_WARN, "WARNING: Using Leopard ARB_position_invariant bug workaround. (use \"/apple_ff_bug 0\" to disable if unnecessary)");
}
#endif
}
if(glversion >= 200)
{
#ifndef __APPLE__
glCreateProgram_ = (PFNGLCREATEPROGRAMPROC) getprocaddress("glCreateProgram");
glDeleteProgram_ = (PFNGLDELETEPROGRAMPROC) getprocaddress("glDeleteProgram");
glUseProgram_ = (PFNGLUSEPROGRAMPROC) getprocaddress("glUseProgram");
glCreateShader_ = (PFNGLCREATESHADERPROC) getprocaddress("glCreateShader");
glDeleteShader_ = (PFNGLDELETESHADERPROC) getprocaddress("glDeleteShader");
glShaderSource_ = (PFNGLSHADERSOURCEPROC) getprocaddress("glShaderSource");
glCompileShader_ = (PFNGLCOMPILESHADERPROC) getprocaddress("glCompileShader");
glGetShaderiv_ = (PFNGLGETSHADERIVPROC) getprocaddress("glGetShaderiv");
glGetProgramiv_ = (PFNGLGETPROGRAMIVPROC) getprocaddress("glGetProgramiv");
glAttachShader_ = (PFNGLATTACHSHADERPROC) getprocaddress("glAttachShader");
glGetProgramInfoLog_ = (PFNGLGETPROGRAMINFOLOGPROC) getprocaddress("glGetProgramInfoLog");
glGetShaderInfoLog_ = (PFNGLGETSHADERINFOLOGPROC) getprocaddress("glGetShaderInfoLog");
glLinkProgram_ = (PFNGLLINKPROGRAMPROC) getprocaddress("glLinkProgram");
glGetUniformLocation_ = (PFNGLGETUNIFORMLOCATIONPROC) getprocaddress("glGetUniformLocation");
glUniform1f_ = (PFNGLUNIFORM1FPROC) getprocaddress("glUniform1f");
glUniform2f_ = (PFNGLUNIFORM2FPROC) getprocaddress("glUniform2f");
glUniform3f_ = (PFNGLUNIFORM3FPROC) getprocaddress("glUniform3f");
glUniform4f_ = (PFNGLUNIFORM4FPROC) getprocaddress("glUniform4f");
glUniform1fv_ = (PFNGLUNIFORM1FVPROC) getprocaddress("glUniform1fv");
glUniform2fv_ = (PFNGLUNIFORM2FVPROC) getprocaddress("glUniform2fv");
glUniform3fv_ = (PFNGLUNIFORM3FVPROC) getprocaddress("glUniform3fv");
glUniform4fv_ = (PFNGLUNIFORM4FVPROC) getprocaddress("glUniform4fv");
glUniform1i_ = (PFNGLUNIFORM1IPROC) getprocaddress("glUniform1i");
glBindAttribLocation_ = (PFNGLBINDATTRIBLOCATIONPROC) getprocaddress("glBindAttribLocation");
glGetActiveUniform_ = (PFNGLGETACTIVEUNIFORMPROC) getprocaddress("glGetActiveUniform");
glEnableVertexAttribArray_ = (PFNGLENABLEVERTEXATTRIBARRAYPROC) getprocaddress("glEnableVertexAttribArray");
glDisableVertexAttribArray_ = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) getprocaddress("glDisableVertexAttribArray");
glVertexAttribPointer_ = (PFNGLVERTEXATTRIBPOINTERPROC) getprocaddress("glVertexAttribPointer");
if(glversion >= 210)
{
glUniformMatrix2x3fv_ = (PFNGLUNIFORMMATRIX2X3FVPROC) getprocaddress("glUniformMatrix2x3fv");
glUniformMatrix3x2fv_ = (PFNGLUNIFORMMATRIX3X2FVPROC) getprocaddress("glUniformMatrix3x2fv");
glUniformMatrix2x4fv_ = (PFNGLUNIFORMMATRIX2X4FVPROC) getprocaddress("glUniformMatrix2x4fv");
glUniformMatrix4x2fv_ = (PFNGLUNIFORMMATRIX4X2FVPROC) getprocaddress("glUniformMatrix4x2fv");
glUniformMatrix3x4fv_ = (PFNGLUNIFORMMATRIX3X4FVPROC) getprocaddress("glUniformMatrix3x4fv");
glUniformMatrix4x3fv_ = (PFNGLUNIFORMMATRIX4X3FVPROC) getprocaddress("glUniformMatrix4x3fv");
}
#endif
extern bool checkglslsupport();
if(checkglslsupport())
{
hasGLSL = true;
hasglsl = 1;
#ifdef __APPLE__
//if(osversion<0x0A0500) ??
if(hasVP && hasFP) apple_glsldepth_bug = 1;
#endif
//if(apple_glsldepth_bug) conoutf(CON_WARN, "WARNING: Using Apple GLSL depth bug workaround. (use \"/apple_glsldepth_bug 0\" to disable if unnecessary");
const char *str = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
uint majorversion, minorversion;
if(!str || sscanf(str, " %u.%u", &majorversion, &minorversion) != 2) glslversion = 100;
else glslversion = majorversion*100 + minorversion;
#ifdef __APPLE__
if(osversion >= 0x0A0600) { if(glslversion >= 120) preferglsl = 1; }
else
#endif
if(glslversion >= 130) preferglsl = 1;
}
}
extern int reservedynlighttc, reserveshadowmaptc, batchlightmaps, ffdynlights, fpdepthfx;
if(ati)
{
//conoutf(CON_WARN, "WARNING: ATI cards may show garbage in skybox. (use \"/ati_skybox_bug 1\" to fix)");
reservedynlighttc = 2;
reserveshadowmaptc = 3;
minimizetcusage = 1;
emulatefog = 1;
if(hasTF && hasNVFB) fpdepthfx = 1;
}
else if(nvidia)
{
reservevpparams = 10;
rtsharefb = 0; // work-around for strange driver stalls involving when using many FBOs
extern int filltjoints;
if(!hasext(exts, "GL_EXT_gpu_shader4")) filltjoints = 0; // DX9 or less NV cards seem to not cause many sparklies
if(hasFBO && !hasTF) nvidia_scissor_bug = 1; // 5200 bug, clearing with scissor on an FBO messes up on reflections, may affect lesser cards too
extern int fpdepthfx;
if(hasTF && (!strstr(renderer, "GeForce") || !checkseries(renderer, 6000, 6600)))
fpdepthfx = 1; // FP filtering causes software fallback on 6200?
}
else
{
if(intel)
{
#ifdef __APPLE__
apple_vp_bug = 1;
intel_immediate_bug = 1;
#endif
#ifdef WIN32
intel_immediate_bug = 1;
intel_vertexarray_bug = 1;
#endif
}
if(!hasGLSL || !preferglsl)
{
avoidshaders = 1;
if(hwtexsize < 4096)
{
maxtexsize = hwtexsize >= 2048 ? 512 : 256;
batchlightmaps = 0;
}
if(!hasTF) ffdynlights = 0;
}
reservevpparams = 20;
if(!hasOQ) waterrefract = 0;
}
bool hasshaders = (hasVP && hasFP) || hasGLSL;
if(hasshaders)
{
extern int matskel;
if(!avoidshaders)
{
matskel = 0;
}
}
if(hasext(exts, "GL_NV_vertex_program2_option")) { usevp2 = 1; hasVP2 = true; }
if(hasext(exts, "GL_NV_vertex_program3")) { usevp3 = 1; hasVP3 = true; }
if(hasext(exts, "GL_EXT_gpu_program_parameters"))
{
glProgramEnvParameters4fv_ = (PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) getprocaddress("glProgramEnvParameters4fvEXT");
glProgramLocalParameters4fv_ = (PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC)getprocaddress("glProgramLocalParameters4fvEXT");
hasPP = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_gpu_program_parameters extension.");
}
if(hasext(exts, "GL_ARB_map_buffer_range"))
{
glMapBufferRange_ = (PFNGLMAPBUFFERRANGEPROC) getprocaddress("glMapBufferRange");
glFlushMappedBufferRange_ = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC)getprocaddress("glFlushMappedBufferRange");
hasMBR = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_map_buffer_range.");
}
if(hasext(exts, "GL_ARB_uniform_buffer_object"))
{
glGetUniformIndices_ = (PFNGLGETUNIFORMINDICESPROC) getprocaddress("glGetUniformIndices");
glGetActiveUniformsiv_ = (PFNGLGETACTIVEUNIFORMSIVPROC) getprocaddress("glGetActiveUniformsiv");
glGetUniformBlockIndex_ = (PFNGLGETUNIFORMBLOCKINDEXPROC) getprocaddress("glGetUniformBlockIndex");
glGetActiveUniformBlockiv_ = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC)getprocaddress("glGetActiveUniformBlockiv");
glUniformBlockBinding_ = (PFNGLUNIFORMBLOCKBINDINGPROC) getprocaddress("glUniformBlockBinding");
glBindBufferBase_ = (PFNGLBINDBUFFERBASEPROC) getprocaddress("glBindBufferBase");
glBindBufferRange_ = (PFNGLBINDBUFFERRANGEPROC) getprocaddress("glBindBufferRange");
useubo = 1;
hasUBO = true;
if(ati) ati_ubo_bug = 1;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_uniform_buffer_object extension.");
}
else if(hasext(exts, "GL_EXT_bindable_uniform"))
{
glUniformBuffer_ = (PFNGLUNIFORMBUFFEREXTPROC) getprocaddress("glUniformBufferEXT");
glGetUniformBufferSize_ = (PFNGLGETUNIFORMBUFFERSIZEEXTPROC)getprocaddress("glGetUniformBufferSizeEXT");
glGetUniformOffset_ = (PFNGLGETUNIFORMOFFSETEXTPROC) getprocaddress("glGetUniformOffsetEXT");
usebue = 1;
hasBUE = true;
if(ati) ati_ubo_bug = 1;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_bindable_uniform extension.");
}
if(hasext(exts, "GL_EXT_texture_rectangle") || hasext(exts, "GL_ARB_texture_rectangle"))
{
usetexrect = 1;
hasTR = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_rectangle extension.");
}
else if(hasMT && hasshaders) conoutf(CON_WARN, "WARNING: No texture rectangle support. (no full screen shaders)");
if(hasext(exts, "GL_EXT_packed_depth_stencil") || hasext(exts, "GL_NV_packed_depth_stencil"))
{
hasDS = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_packed_depth_stencil extension.");
}
if(hasext(exts, "GL_EXT_blend_minmax"))
{
glBlendEquation_ = (PFNGLBLENDEQUATIONEXTPROC) getprocaddress("glBlendEquationEXT");
hasBE = true;
if(ati) ati_minmax_bug = 1;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_blend_minmax extension.");
}
if(hasext(exts, "GL_EXT_blend_color"))
{
glBlendColor_ = (PFNGLBLENDCOLOREXTPROC) getprocaddress("glBlendColorEXT");
hasBC = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_blend_color extension.");
}
if(hasext(exts, "GL_EXT_fog_coord"))
{
glFogCoordPointer_ = (PFNGLFOGCOORDPOINTEREXTPROC) getprocaddress("glFogCoordPointerEXT");
hasFC = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_fog_coord extension.");
}
if(hasext(exts, "GL_ARB_texture_cube_map"))
{
GLint val;
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &val);
hwcubetexsize = val;
hasCM = true;
// On Catalyst 10.2, issuing an occlusion query on the first draw using a given cubemap texture causes a nasty crash
if(ati) ati_cubemap_bug = 1;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_cube_map extension.");
}
else conoutf(CON_WARN, "WARNING: No cube map texture support. (no reflective glass)");
extern int usenp2;
if(hasext(exts, "GL_ARB_texture_non_power_of_two"))
{
hasNP2 = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_non_power_of_two extension.");
}
else if(usenp2) conoutf(CON_WARN, "WARNING: Non-power-of-two textures not supported!");
if(hasext(exts, "GL_ARB_texture_compression"))
{
glCompressedTexImage3D_ = (PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) getprocaddress("glCompressedTexImage3DARB");
glCompressedTexImage2D_ = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) getprocaddress("glCompressedTexImage2DARB");
glCompressedTexImage1D_ = (PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) getprocaddress("glCompressedTexImage1DARB");
glCompressedTexSubImage3D_ = (PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC)getprocaddress("glCompressedTexSubImage3DARB");
glCompressedTexSubImage2D_ = (PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC)getprocaddress("glCompressedTexSubImage2DARB");
glCompressedTexSubImage1D_ = (PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC)getprocaddress("glCompressedTexSubImage1DARB");
glGetCompressedTexImage_ = (PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) getprocaddress("glGetCompressedTexImageARB");
hasTC = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_texture_compression.");
if(hasext(exts, "GL_EXT_texture_compression_s3tc"))
{
hasS3TC = true;
#ifdef __APPLE__
usetexcompress = 1;
#else
if(!mesa) usetexcompress = 2;
#endif
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_texture_compression_s3tc extension.");
}
else if(hasext(exts, "GL_EXT_texture_compression_dxt1") && hasext(exts, "GL_ANGLE_texture_compression_dxt3") && hasext(exts, "GL_ANGLE_texture_compression_dxt5"))
{
hasS3TC = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_texture_compression_dxt1 extension.");
}
if(hasext(exts, "GL_3DFX_texture_compression_FXT1"))
{
hasFXT1 = true;
if(mesa) usetexcompress = max(usetexcompress, 1);
if(dbgexts) conoutf(CON_INIT, "Using GL_3DFX_texture_compression_FXT1.");
}
}
if(hasext(exts, "GL_EXT_texture_filter_anisotropic"))
{
GLint val;
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &val);
hwmaxaniso = val;
hasAF = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_texture_filter_anisotropic extension.");
}
if(hasext(exts, "GL_SGIS_generate_mipmap"))
{
hasGM = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_SGIS_generate_mipmap extension.");
}
if(hasext(exts, "GL_ARB_depth_texture"))
{
hasSGIDT = hasDT = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_depth_texture extension.");
}
else if(hasext(exts, "GL_SGIX_depth_texture"))
{
hasSGIDT = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_SGIX_depth_texture extension.");
}
if(hasext(exts, "GL_ARB_shadow"))
{
hasSGISH = hasSH = true;
if(nvidia || (ati && strstr(renderer, "Radeon HD"))) hasNVPCF = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_ARB_shadow extension.");
}
else if(hasext(exts, "GL_SGIX_shadow"))
{
hasSGISH = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_SGIX_shadow extension.");
}
if(hasext(exts, "GL_EXT_rescale_normal"))
{
hasRN = true;
if(dbgexts) conoutf(CON_INIT, "Using GL_EXT_rescale_normal extension.");
}
if(!hasSGIDT && !hasSGISH) shadowmap = 0;
if(hasext(exts, "GL_EXT_gpu_shader4") && !avoidshaders)
{
// on DX10 or above class cards (i.e. GF8 or RadeonHD) enable expensive features
extern int grass, glare, maxdynlights, depthfxsize, depthfxrect, depthfxfilter, blurdepthfx;
grass = 1;
if(hasOQ)
{
waterfallrefract = 1;
glare = 1;
maxdynlights = MAXDYNLIGHTS;
if(hasTR)
{
depthfxsize = 10;
depthfxrect = 1;
depthfxfilter = 0;
blurdepthfx = 0;
}
}
}
}
void glext(char *ext)
{
const char *exts = (const char *)glGetString(GL_EXTENSIONS);
intret(hasext(exts, ext) ? 1 : 0);
}
COMMAND(glext, "s");
void gl_init(int w, int h, int bpp, int depth, int fsaa)
{
glViewport(0, 0, w, h);
glClearColor(0, 0, 0, 0);
glClearDepth(1);
glDepthFunc(GL_LESS);
glDisable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glDisable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
//glHint(GL_FOG_HINT, GL_NICEST);
GLfloat fogcolor[4] = { 0, 0, 0, 0 };
glFogfv(GL_FOG_COLOR, fogcolor);
glEnable(GL_LINE_SMOOTH);
//glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
#ifdef __APPLE__
if(sdl_backingstore_bug)
{
if(fsaa)
{
sdl_backingstore_bug = 1;
// since SDL doesn't add kCGLPFABackingStore to the pixelformat and so it isn't guaranteed to be preserved - only manifests when using fsaa?
//conoutf(CON_WARN, "WARNING: Using SDL backingstore workaround. (use \"/sdl_backingstore_bug 0\" to disable if unnecessary)");
}
else sdl_backingstore_bug = -1;
}
#endif
extern int useshaders, forceglsl;
bool hasshaders = (hasVP && hasFP) || hasGLSL;
if(!useshaders || (useshaders<0 && avoidshaders) || !hasMT || !hasshaders)
{
if(!hasMT || !hasshaders) conoutf(CON_WARN, "WARNING: No shader support! Using fixed-function fallback. (no fancy visuals for you)");
else if(useshaders<0 && avoidshaders) conoutf(CON_WARN, "WARNING: Disabling shaders for extra performance. (use \"/shaders 1\" to enable shaders if desired)");
renderpath = R_FIXEDFUNCTION;
}
else renderpath = hasGLSL ? ((forceglsl && (forceglsl > 0 || preferglsl)) || !hasVP || !hasFP ? (forceglsl ? R_GLSLANG : R_FIXEDFUNCTION) : R_ASMGLSLANG) : R_ASMSHADER;
extern void setupshaders();
setupshaders();
static const char * const rpnames[4] = { "fixed-function", "assembly shader", "GLSL shader", "assembly/GLSL shader" };
conoutf(CON_INIT, "Rendering using the OpenGL %s path.", rpnames[renderpath]);
inittmus();
setuptexcompress();
}
void cleanupgl()
{
extern int nomasks, nolights, nowater;
nomasks = nolights = nowater = 0;
extern void cleanupmotionblur();
cleanupmotionblur();
extern void clearminimap();
clearminimap();
}
#define VARRAY_INTERNAL
#include "varray.h"
VAR(wireframe, 0, 0, 1);
ICOMMAND(getcamyaw, "", (), floatret(camera1->yaw));
ICOMMAND(getcampitch, "", (), floatret(camera1->pitch));
ICOMMAND(getcamroll, "", (), floatret(camera1->roll));
ICOMMAND(getcampos, "", (),
{
defformatstring(pos)("%s %s %s", floatstr(camera1->o.x), floatstr(camera1->o.y), floatstr(camera1->o.z));
result(pos);
});
vec worldpos, camdir, camright, camup;
void findorientation()
{
vecfromyawpitch(camera1->yaw, camera1->pitch, 1, 0, camdir);
vecfromyawpitch(camera1->yaw, 0, 0, -1, camright);
vecfromyawpitch(camera1->yaw, camera1->pitch+90, 1, 0, camup);
if(raycubepos(camera1->o, camdir, worldpos, 0, RAY_CLIPMAT|RAY_SKIPFIRST) == -1)
worldpos = vec(camdir).mul(2*worldsize).add(camera1->o); //otherwise 3dgui won't work when outside of map
}
void transplayer()
{
// move from RH to Z-up LH quake style worldspace
glLoadMatrixf(viewmatrix.v);
glRotatef(camera1->roll, 0, 1, 0);
glRotatef(camera1->pitch, -1, 0, 0);
glRotatef(camera1->yaw, 0, 0, -1);
glTranslatef(-camera1->o.x, -camera1->o.y, -camera1->o.z);
}
float curfov = 100, curavatarfov = 65, fovy, aspect;
int farplane;
VARP(zoominvel, 0, 250, 5000);
VARP(zoomoutvel, 0, 100, 5000);
VARP(zoomfov, 10, 35, 60);
VARP(fov, 10, 100, 150);
VAR(avatarzoomfov, 10, 25, 60);
VAR(avatarfov, 10, 65, 150);
FVAR(avatardepth, 0, 0.5f, 1);
FVARNP(aspect, forceaspect, 0, 0, 1e3f);
static int zoommillis = 0;
VARF(zoom, -1, 0, 1,
if(zoom) zoommillis = totalmillis;
);
void disablezoom()
{
zoom = 0;
zoommillis = totalmillis;
}
void computezoom()
{
if(!zoom) { curfov = fov; curavatarfov = avatarfov; return; }
if(zoom < 0 && curfov >= fov) { zoom = 0; curfov = fov; curavatarfov = avatarfov; return; } // don't zoom-out if not zoomed-in
int zoomvel = zoom > 0 ? zoominvel : zoomoutvel,
oldfov = zoom > 0 ? fov : zoomfov,
newfov = zoom > 0 ? zoomfov : fov,
oldavatarfov = zoom > 0 ? avatarfov : avatarzoomfov,
newavatarfov = zoom > 0 ? avatarzoomfov : avatarfov;
float t = zoomvel ? float(zoomvel - (totalmillis - zoommillis)) / zoomvel : 0;
if(t <= 0)
{
if(!zoomvel && fabs(newfov - curfov) >= 1)
{
curfov = newfov;
curavatarfov = newavatarfov;
}
zoom = max(zoom, 0);
}
else
{
curfov = oldfov*t + newfov*(1 - t);
curavatarfov = oldavatarfov*t + newavatarfov*(1 - t);
}
}
FVARP(zoomsens, 1e-3f, 1, 1000);
FVARP(zoomaccel, 0, 0, 1000);
VARP(zoomautosens, 0, 1, 1);
FVARP(sensitivity, 1e-3f, 3, 1000);
FVARP(sensitivityscale, 1e-3f, 1, 1000);
VARP(invmouse, 0, 0, 1);
FVARP(mouseaccel, 0, 0, 1000);
VAR(thirdperson, 0, 0, 2);
FVAR(thirdpersondistance, 0, 20, 50);
FVAR(thirdpersonup, -25, 0, 25);
FVAR(thirdpersonside, -25, 0, 25);
physent *camera1 = NULL;
bool detachedcamera = false;
bool isthirdperson() { return player!=camera1 || detachedcamera || reflecting; }
void fixcamerarange()
{
const float MAXPITCH = 90.0f;
if(camera1->pitch>MAXPITCH) camera1->pitch = MAXPITCH;
if(camera1->pitch<-MAXPITCH) camera1->pitch = -MAXPITCH;
while(camera1->yaw<0.0f) camera1->yaw += 360.0f;
while(camera1->yaw>=360.0f) camera1->yaw -= 360.0f;
}
void mousemove(int dx, int dy)
{
if(!game::allowmouselook()) return;
float cursens = sensitivity, curaccel = mouseaccel;
if(zoom)
{
if(zoomautosens)
{
cursens = float(sensitivity*zoomfov)/fov;
curaccel = float(mouseaccel*zoomfov)/fov;
}
else
{
cursens = zoomsens;
curaccel = zoomaccel;
}
}
if(curaccel && curtime && (dx || dy)) cursens += curaccel * sqrtf(dx*dx + dy*dy)/curtime;
cursens /= 33.0f*sensitivityscale;
camera1->yaw += dx*cursens;
camera1->pitch -= dy*cursens*(invmouse ? -1 : 1);
fixcamerarange();
if(camera1!=player && !detachedcamera)
{
player->yaw = camera1->yaw;
player->pitch = camera1->pitch;
}
}
void recomputecamera()
{
game::setupcamera();
computezoom();
bool shoulddetach = thirdperson > 1 || game::detachcamera();
if(!thirdperson && !shoulddetach)
{
camera1 = player;
detachedcamera = false;
}
else
{
static physent tempcamera;
camera1 = &tempcamera;
if(detachedcamera && shoulddetach) camera1->o = player->o;
else
{
*camera1 = *player;
detachedcamera = shoulddetach;
}
camera1->reset();
camera1->type = ENT_CAMERA;
camera1->collidetype = COLLIDE_AABB;
camera1->move = -1;
camera1->eyeheight = camera1->aboveeye = camera1->radius = camera1->xradius = camera1->yradius = 2;
vec dir, up, side;
vecfromyawpitch(camera1->yaw, camera1->pitch, -1, 0, dir);
vecfromyawpitch(camera1->yaw, camera1->pitch+90, 1, 0, up);
vecfromyawpitch(camera1->yaw, 0, 0, -1, side);
if(game::collidecamera())
{
movecamera(camera1, dir, thirdpersondistance, 1);
movecamera(camera1, dir, clamp(thirdpersondistance - camera1->o.dist(player->o), 0.0f, 1.0f), 0.1f);
if(thirdpersonup)
{
vec pos = camera1->o;
float dist = fabs(thirdpersonup);
if(thirdpersonup < 0) up.neg();
movecamera(camera1, up, dist, 1);
movecamera(camera1, up, clamp(dist - camera1->o.dist(pos), 0.0f, 1.0f), 0.1f);
}
if(thirdpersonside)
{
vec pos = camera1->o;
float dist = fabs(thirdpersonside);
if(thirdpersonside < 0) side.neg();
movecamera(camera1, side, dist, 1);
movecamera(camera1, side, clamp(dist - camera1->o.dist(pos), 0.0f, 1.0f), 0.1f);
}
}
else
{
camera1->o.add(vec(dir).mul(thirdpersondistance));
if(thirdpersonup) camera1->o.add(vec(up).mul(thirdpersonup));
if(thirdpersonside) camera1->o.add(vec(side).mul(thirdpersonside));
}
}
setviewcell(camera1->o);
}
extern const glmatrixf viewmatrix(vec4(-1, 0, 0, 0), vec4(0, 0, 1, 0), vec4(0, -1, 0, 0));
glmatrixf mvmatrix, projmatrix, mvpmatrix, invmvmatrix, invmvpmatrix;
void readmatrices()
{
glGetFloatv(GL_MODELVIEW_MATRIX, mvmatrix.v);
glGetFloatv(GL_PROJECTION_MATRIX, projmatrix.v);
mvpmatrix.mul(projmatrix, mvmatrix);
invmvmatrix.invert(mvmatrix);
invmvpmatrix.invert(mvpmatrix);
}
FVAR(nearplane, 0.01f, 0.54f, 2.0f);
void project(float fovy, float aspect, int farplane, bool flipx = false, bool flipy = false, bool swapxy = false, float zscale = 1)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(swapxy) glRotatef(90, 0, 0, 1);
if(flipx || flipy!=swapxy || zscale!=1) glScalef(flipx ? -1 : 1, flipy!=swapxy ? -1 : 1, zscale);
GLdouble ydist = nearplane * tan(fovy/2*RAD), xdist = ydist * aspect;
glFrustum(-xdist, xdist, -ydist, ydist, nearplane, farplane);
glMatrixMode(GL_MODELVIEW);
}
vec calcavatarpos(const vec &pos, float dist)
{
vec eyepos;
mvmatrix.transform(pos, eyepos);
GLdouble ydist = nearplane * tan(curavatarfov/2*RAD), xdist = ydist * aspect;
vec4 scrpos;
scrpos.x = eyepos.x*nearplane/xdist;
scrpos.y = eyepos.y*nearplane/ydist;
scrpos.z = (eyepos.z*(farplane + nearplane) - 2*nearplane*farplane) / (farplane - nearplane);
scrpos.w = -eyepos.z;
vec worldpos = invmvpmatrix.perspectivetransform(scrpos);
vec dir = vec(worldpos).sub(camera1->o).rescale(dist);
return dir.add(camera1->o);
}
VAR(reflectclip, 0, 6, 64);
VAR(reflectclipavatar, -64, 0, 64);
glmatrixf clipmatrix;
static const glmatrixf dummymatrix;
static int projectioncount = 0;
void pushprojection(const glmatrixf &m = dummymatrix)
{
glMatrixMode(GL_PROJECTION);
if(projectioncount <= 0) glPushMatrix();
if(&m != &dummymatrix) glLoadMatrixf(m.v);
if(fogging)
{
glMultMatrixf(mvmatrix.v);
glMultMatrixf(invfogmatrix.v);
}
glMatrixMode(GL_MODELVIEW);
projectioncount++;
}
void popprojection()
{
--projectioncount;
glMatrixMode(GL_PROJECTION);
glPopMatrix();
if(projectioncount > 0)
{
glPushMatrix();
if(fogging)
{
glMultMatrixf(mvmatrix.v);
glMultMatrixf(invfogmatrix.v);
}
}
glMatrixMode(GL_MODELVIEW);
}
FVAR(polygonoffsetfactor, -1e4f, -3.0f, 1e4f);
FVAR(polygonoffsetunits, -1e4f, -3.0f, 1e4f);
FVAR(depthoffset, -1e4f, 0.01f, 1e4f);
void enablepolygonoffset(GLenum type)
{
if(!depthoffset)
{
glPolygonOffset(polygonoffsetfactor, polygonoffsetunits);
glEnable(type);
return;
}
bool clipped = reflectz < 1e15f && reflectclip;
glmatrixf offsetmatrix = clipped ? clipmatrix : projmatrix;
offsetmatrix[14] += depthoffset * projmatrix[10];
glMatrixMode(GL_PROJECTION);
if(!clipped) glPushMatrix();
glLoadMatrixf(offsetmatrix.v);
if(fogging)
{
glMultMatrixf(mvmatrix.v);
glMultMatrixf(invfogmatrix.v);
}
glMatrixMode(GL_MODELVIEW);
}
void disablepolygonoffset(GLenum type)
{
if(!depthoffset)
{
glDisable(type);
return;
}
bool clipped = reflectz < 1e15f && reflectclip;
glMatrixMode(GL_PROJECTION);
if(clipped)
{
glLoadMatrixf(clipmatrix.v);
if(fogging)
{
glMultMatrixf(mvmatrix.v);
glMultMatrixf(invfogmatrix.v);
}
}
else glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void calcspherescissor(const vec ¢er, float size, float &sx1, float &sy1, float &sx2, float &sy2)
{
vec worldpos(center);
if(reflecting) worldpos.z = 2*reflectz - worldpos.z;
vec e(mvmatrix.transformx(worldpos),
mvmatrix.transformy(worldpos),
mvmatrix.transformz(worldpos));
if(e.z > 2*size) { sx1 = sy1 = 1; sx2 = sy2 = -1; return; }
float zzrr = e.z*e.z - size*size,
dx = e.x*e.x + zzrr, dy = e.y*e.y + zzrr,
focaldist = 1.0f/tan(fovy*0.5f*RAD);
sx1 = sy1 = -1;
sx2 = sy2 = 1;
#define CHECKPLANE(c, dir, focaldist, low, high) \
do { \
float nzc = (cz*cz + 1) / (cz dir drt) - cz, \
pz = (d##c)/(nzc*e.c - e.z); \
if(pz > 0) \
{ \
float c = (focaldist)*nzc, \
pc = pz*nzc; \
if(pc < e.c) low = c; \
else if(pc > e.c) high = c; \
} \
} while(0)
if(dx > 0)
{
float cz = e.x/e.z, drt = sqrtf(dx)/size;
CHECKPLANE(x, -, focaldist/aspect, sx1, sx2);
CHECKPLANE(x, +, focaldist/aspect, sx1, sx2);
}
if(dy > 0)
{
float cz = e.y/e.z, drt = sqrtf(dy)/size;
CHECKPLANE(y, -, focaldist, sy1, sy2);
CHECKPLANE(y, +, focaldist, sy1, sy2);
}
}
static int scissoring = 0;
static GLint oldscissor[4];
int pushscissor(float sx1, float sy1, float sx2, float sy2)
{
scissoring = 0;
if(sx1 <= -1 && sy1 <= -1 && sx2 >= 1 && sy2 >= 1) return 0;
sx1 = max(sx1, -1.0f);
sy1 = max(sy1, -1.0f);
sx2 = min(sx2, 1.0f);
sy2 = min(sy2, 1.0f);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
int sx = viewport[0] + int(floor((sx1+1)*0.5f*viewport[2])),
sy = viewport[1] + int(floor((sy1+1)*0.5f*viewport[3])),
sw = viewport[0] + int(ceil((sx2+1)*0.5f*viewport[2])) - sx,
sh = viewport[1] + int(ceil((sy2+1)*0.5f*viewport[3])) - sy;
if(sw <= 0 || sh <= 0) return 0;
if(glIsEnabled(GL_SCISSOR_TEST))
{
glGetIntegerv(GL_SCISSOR_BOX, oldscissor);
sw += sx;
sh += sy;
sx = max(sx, int(oldscissor[0]));
sy = max(sy, int(oldscissor[1]));
sw = min(sw, int(oldscissor[0] + oldscissor[2])) - sx;
sh = min(sh, int(oldscissor[1] + oldscissor[3])) - sy;
if(sw <= 0 || sh <= 0) return 0;
scissoring = 2;
}
else scissoring = 1;
glScissor(sx, sy, sw, sh);
if(scissoring<=1) glEnable(GL_SCISSOR_TEST);
return scissoring;
}
void popscissor()
{
if(scissoring>1) glScissor(oldscissor[0], oldscissor[1], oldscissor[2], oldscissor[3]);
else if(scissoring) glDisable(GL_SCISSOR_TEST);
scissoring = 0;
}
glmatrixf envmatrix;
void setenvmatrix()
{
envmatrix = fogging ? fogmatrix : mvmatrix;
if(reflecting) envmatrix.reflectz(reflectz);
envmatrix.transpose();
}
VARR(fog, 16, 4000, 1000024);
bvec fogcolor(0x80, 0x99, 0xB3);
HVARFR(fogcolour, 0, 0x8099B3, 0xFFFFFF,
{
fogcolor = bvec((fogcolour>>16)&0xFF, (fogcolour>>8)&0xFF, fogcolour&0xFF);
});
static float findsurface(int fogmat, const vec &v, int &abovemat)
{
fogmat &= MATF_VOLUME;
ivec o(v), co;
int csize;
do
{
cube &c = lookupcube(o.x, o.y, o.z, 0, co, csize);
int mat = c.material&MATF_VOLUME;
if(mat != fogmat)
{
abovemat = isliquid(mat) ? c.material : MAT_AIR;
return o.z;
}
o.z = co.z + csize;
}
while(o.z < worldsize);
abovemat = MAT_AIR;
return worldsize;
}
static void blendfog(int fogmat, float blend, float logblend, float &start, float &end, float *fogc)
{
switch(fogmat&MATF_VOLUME)
{
case MAT_WATER:
{
const bvec &wcol = getwatercolor(fogmat);
int wfog = getwaterfog(fogmat);
loopk(3) fogc[k] += blend*wcol[k]/255.0f;
end += logblend*min(fog, max(wfog*4, 32));
break;
}
case MAT_LAVA:
{
const bvec &lcol = getlavacolor(fogmat);
int lfog = getlavafog(fogmat);
loopk(3) fogc[k] += blend*lcol[k]/255.0f;
end += logblend*min(fog, max(lfog*4, 32));
break;
}
default:
loopk(3) fogc[k] += blend*fogcolor[k]/255.0f;
start += logblend*(fog+64)/8;
end += logblend*fog;
break;
}
}
static void setfog(int fogmat, float below = 1, int abovemat = MAT_AIR)
{
float fogc[4] = { 0, 0, 0, 1 };
float start = 0, end = 0;
float logscale = 256, logblend = log(1 + (logscale - 1)*below) / log(logscale);
blendfog(fogmat, below, logblend, start, end, fogc);
if(below < 1) blendfog(abovemat, 1-below, 1-logblend, start, end, fogc);
glFogf(GL_FOG_START, start);
glFogf(GL_FOG_END, end);
glFogfv(GL_FOG_COLOR, fogc);
glClearColor(fogc[0], fogc[1], fogc[2], 1.0f);
}
static void blendfogoverlay(int fogmat, float blend, float *overlay)
{
float maxc;
switch(fogmat&MATF_VOLUME)
{
case MAT_WATER:
{
const bvec &wcol = getwatercolor(fogmat);
maxc = max(wcol[0], max(wcol[1], wcol[2]));
loopk(3) overlay[k] += blend*max(0.4f, wcol[k]/min(32.0f + maxc*7.0f/8.0f, 255.0f));
break;
}
case MAT_LAVA:
{
const bvec &lcol = getlavacolor(fogmat);
maxc = max(lcol[0], max(lcol[1], lcol[2]));
loopk(3) overlay[k] += blend*max(0.4f, lcol[k]/min(32.0f + maxc*7.0f/8.0f, 255.0f));
break;
}
default:
loopk(3) overlay[k] += blend;
break;
}
}
void drawfogoverlay(int fogmat, float fogblend, int abovemat)
{
notextureshader->set();
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
float overlay[3] = { 0, 0, 0 };
blendfogoverlay(fogmat, fogblend, overlay);
blendfogoverlay(abovemat, 1-fogblend, overlay);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3fv(overlay);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(-1, -1);
glVertex2f(1, -1);
glVertex2f(-1, 1);
glVertex2f(1, 1);
glEnd();
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_TEXTURE_2D);
defaultshader->set();
}
bool renderedgame = false;
void rendergame(bool mainpass)
{
game::rendergame(mainpass);
if(!shadowmapping) renderedgame = true;
}
VARP(skyboxglare, 0, 1, 1);
void drawglare()
{
glaring = true;
refracting = -1;
float oldfogstart, oldfogend, oldfogcolor[4], zerofog[4] = { 0, 0, 0, 1 };
glGetFloatv(GL_FOG_START, &oldfogstart);
glGetFloatv(GL_FOG_END, &oldfogend);
glGetFloatv(GL_FOG_COLOR, oldfogcolor);
glFogf(GL_FOG_START, (fog+64)/8);
glFogf(GL_FOG_END, fog);
glFogfv(GL_FOG_COLOR, zerofog);
glClearColor(0, 0, 0, 1);
glClear((skyboxglare ? 0 : GL_COLOR_BUFFER_BIT) | GL_DEPTH_BUFFER_BIT);
rendergeom();
if(skyboxglare) drawskybox(farplane, false);
renderreflectedmapmodels();
rendergame();
if(!isthirdperson())
{
project(curavatarfov, aspect, farplane, false, false, false, avatardepth);
game::renderavatar();
project(fovy, aspect, farplane);
}
renderwater();
rendermaterials();
renderalphageom();
renderparticles();
glFogf(GL_FOG_START, oldfogstart);
glFogf(GL_FOG_END, oldfogend);
glFogfv(GL_FOG_COLOR, oldfogcolor);
refracting = 0;
glaring = false;
}
VARP(reflectmms, 0, 1, 1);
VARR(refractsky, 0, 0, 1);
glmatrixf fogmatrix, invfogmatrix;
void drawreflection(float z, bool refract, int fogdepth, const bvec &col)
{
reflectz = z < 0 ? 1e16f : z;
reflecting = !refract;
refracting = refract ? (z < 0 || camera1->o.z >= z ? -1 : 1) : 0;
fading = renderpath!=R_FIXEDFUNCTION && waterrefract && waterfade && hasFBO && z>=0;
fogging = refracting<0 && z>=0;
refractfog = fogdepth;
refractcolor = fogging ? col : fogcolor;
float oldfogstart, oldfogend, oldfogcolor[4];
glGetFloatv(GL_FOG_START, &oldfogstart);
glGetFloatv(GL_FOG_END, &oldfogend);
glGetFloatv(GL_FOG_COLOR, oldfogcolor);
if(fogging)
{
glFogf(GL_FOG_START, camera1->o.z - z);
glFogf(GL_FOG_END, camera1->o.z - (z-max(refractfog, 1)));
GLfloat m[16] =
{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
-camera1->o.x, -camera1->o.y, -camera1->o.z, 1
};
memcpy(fogmatrix.v, m, sizeof(m));
invfogmatrix.invert(fogmatrix);
pushprojection();
glPushMatrix();
glLoadMatrixf(fogmatrix.v);
float fogc[4] = { col.x/255.0f, col.y/255.0f, col.z/255.0f, 1.0f };
glFogfv(GL_FOG_COLOR, fogc);
}
else
{
glFogf(GL_FOG_START, (fog+64)/8);
glFogf(GL_FOG_END, fog);
float fogc[4] = { fogcolor.x/255.0f, fogcolor.y/255.0f, fogcolor.z/255.0f, 1.0f };
glFogfv(GL_FOG_COLOR, fogc);
}
if(fading)
{
float scale = fogging ? -0.25f : 0.25f, offset = 2*fabs(scale) - scale*z;
setenvparamf("waterfadeparams", SHPARAM_VERTEX, 8, scale, offset, -scale, offset + camera1->o.z*scale);
setenvparamf("waterfadeparams", SHPARAM_PIXEL, 8, scale, offset, -scale, offset + camera1->o.z*scale);
}
if(reflecting)
{
glPushMatrix();
glTranslatef(0, 0, 2*z);
glScalef(1, 1, -1);
glFrontFace(GL_CCW);
}
setenvmatrix();
if(reflectclip && z>=0)
{
float zoffset = reflectclip/4.0f, zclip;
if(refracting<0)
{
zclip = z+zoffset;
if(camera1->o.z<=zclip) zclip = z;
}
else
{
zclip = z-zoffset;
if(camera1->o.z>=zclip && camera1->o.z<=z+4.0f) zclip = z;
if(reflecting) zclip = 2*z - zclip;
}
plane clipplane;
invmvmatrix.transposedtransform(plane(0, 0, refracting>0 ? 1 : -1, refracting>0 ? -zclip : zclip), clipplane);
clipmatrix.clip(clipplane, projmatrix);
pushprojection(clipmatrix);
}
renderreflectedgeom(refracting<0 && z>=0 && caustics, fogging);
if(reflecting || refracting>0 || (refracting<0 && refractsky) || z<0)
{
if(fading) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
if(reflectclip && z>=0) popprojection();
if(fogging)
{
popprojection();
glPopMatrix();
}
drawskybox(farplane, false);
if(fogging)
{
pushprojection();
glPushMatrix();
glLoadMatrixf(fogmatrix.v);
}
if(reflectclip && z>=0) pushprojection(clipmatrix);
if(fading) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
}
else if(fading) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
renderdecals();
if(reflectmms) renderreflectedmapmodels();
rendergame();
if(refracting && z>=0 && !isthirdperson() && fabs(camera1->o.z-z) <= 0.5f*(player->eyeheight + player->aboveeye))
{
glmatrixf avatarproj;
avatarproj.perspective(curavatarfov, aspect, nearplane, farplane);
if(reflectclip)
{
popprojection();
glmatrixf avatarclip;
plane clipplane;
invmvmatrix.transposedtransform(plane(0, 0, refracting, reflectclipavatar/4.0f - refracting*z), clipplane);
avatarclip.clip(clipplane, avatarproj);
pushprojection(avatarclip);
}
else pushprojection(avatarproj);
game::renderavatar();
popprojection();
if(reflectclip) pushprojection(clipmatrix);
}
if(refracting) rendergrass();
rendermaterials();
renderalphageom(fogging);
renderparticles();
if(fading) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
if(reflectclip && z>=0) popprojection();
if(reflecting)
{
glPopMatrix();
glFrontFace(GL_CW);
}
if(fogging)
{
popprojection();
glPopMatrix();
}
glFogf(GL_FOG_START, oldfogstart);
glFogf(GL_FOG_END, oldfogend);
glFogfv(GL_FOG_COLOR, oldfogcolor);
reflectz = 1e16f;
refracting = 0;
reflecting = fading = fogging = false;
setenvmatrix();
}
bool envmapping = false;
void drawcubemap(int size, const vec &o, float yaw, float pitch, const cubemapside &side)
{
envmapping = true;
physent *oldcamera = camera1;
static physent cmcamera;
cmcamera = *player;
cmcamera.reset();
cmcamera.type = ENT_CAMERA;
cmcamera.o = o;
cmcamera.yaw = yaw;
cmcamera.pitch = pitch;
cmcamera.roll = 0;
camera1 = &cmcamera;
setviewcell(camera1->o);
defaultshader->set();
int fogmat = lookupmaterial(o)&(MATF_VOLUME|MATF_INDEX);
setfog(fogmat);
glClear(GL_DEPTH_BUFFER_BIT);
int farplane = worldsize*2;
project(90.0f, 1.0f, farplane, !side.flipx, !side.flipy, side.swapxy);
transplayer();
readmatrices();
findorientation();
setenvmatrix();
glEnable(GL_FOG);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
xtravertsva = xtraverts = glde = gbatches = 0;
visiblecubes();
if(limitsky()) drawskybox(farplane, true);
rendergeom();
if(!limitsky()) drawskybox(farplane, false);
// queryreflections();
rendermapmodels();
renderalphageom();
// drawreflections();
// renderwater();
// rendermaterials();
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_FOG);
camera1 = oldcamera;
envmapping = false;
}
bool modelpreviewing = false;
namespace modelpreview
{
physent *oldcamera;
float oldfogstart, oldfogend, oldfogcolor[4];
physent camera;
void start(bool background)
{
float fovy = 90.f, aspect = 1.f;
envmapping = modelpreviewing = true;
oldcamera = camera1;
camera = *camera1;
camera.reset();
camera.type = ENT_CAMERA;
camera.o = vec(0, 0, 0);
camera.yaw = 0;
camera.pitch = 0;
camera.roll = 0;
camera1 = &camera;
glGetFloatv(GL_FOG_START, &oldfogstart);
glGetFloatv(GL_FOG_END, &oldfogend);
glGetFloatv(GL_FOG_COLOR, oldfogcolor);
GLfloat fogc[4] = { 0, 0, 0, 1 };
glFogf(GL_FOG_START, 0);
glFogf(GL_FOG_END, 1000000);
glFogfv(GL_FOG_COLOR, fogc);
glClearColor(fogc[0], fogc[1], fogc[2], fogc[3]);
glClear((background ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
project(fovy, aspect, 1024);
transplayer();
readmatrices();
setenvmatrix();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
}
void end()
{
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
defaultshader->set();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glFogf(GL_FOG_START, oldfogstart);
glFogf(GL_FOG_END, oldfogend);
glFogfv(GL_FOG_COLOR, oldfogcolor);
glClearColor(oldfogcolor[0], oldfogcolor[1], oldfogcolor[2], oldfogcolor[3]);
camera1 = oldcamera;
envmapping = modelpreviewing = false;
}
}
bool minimapping = false;
GLuint minimaptex = 0;
vec minimapcenter(0, 0, 0), minimapradius(0, 0, 0), minimapscale(0, 0, 0);
void clearminimap()
{
if(minimaptex) { glDeleteTextures(1, &minimaptex); minimaptex = 0; }
}
VARR(minimapheight, 0, 0, 2<<16);
bvec minimapcolor(0, 0, 0);
HVARFR(minimapcolour, 0, 0, 0xFFFFFF,
{
minimapcolor = bvec((minimapcolour>>16)&0xFF, (minimapcolour>>8)&0xFF, minimapcolour&0xFF);
});
VARR(minimapclip, 0, 0, 1);
VARFP(minimapsize, 7, 8, 10, { if(minimaptex) drawminimap(); });
void bindminimap()
{
glBindTexture(GL_TEXTURE_2D, minimaptex);
}
void clipminimap(ivec &bbmin, ivec &bbmax, cube *c = worldroot, int x = 0, int y = 0, int z = 0, int size = worldsize>>1)
{
loopi(8)
{
ivec o(i, x, y, z, size);
if(c[i].children) clipminimap(bbmin, bbmax, c[i].children, o.x, o.y, o.z, size>>1);
else if(!isentirelysolid(c[i]) && (c[i].material&MATF_CLIP)!=MAT_CLIP)
{
loopk(3) bbmin[k] = min(bbmin[k], o[k]);
loopk(3) bbmax[k] = max(bbmax[k], o[k] + size);
}
}
}
void drawminimap()
{
if(!game::needminimap()) { clearminimap(); return; }
renderprogress(0, "generating mini-map...", 0, !renderedframe);
int size = 1<<minimapsize, sizelimit = min(hwtexsize, min(screen->w, screen->h));
while(size > sizelimit) size /= 2;
if(!minimaptex) glGenTextures(1, &minimaptex);
extern vector<vtxarray *> valist;
ivec bbmin(worldsize, worldsize, worldsize), bbmax(0, 0, 0);
loopv(valist)
{
vtxarray *va = valist[i];
loopk(3)
{
if(va->geommin[k]>va->geommax[k]) continue;
bbmin[k] = min(bbmin[k], va->geommin[k]);
bbmax[k] = max(bbmax[k], va->geommax[k]);
}
}
if(minimapclip)
{
ivec clipmin(worldsize, worldsize, worldsize), clipmax(0, 0, 0);
clipminimap(clipmin, clipmax);
loopk(2) bbmin[k] = max(bbmin[k], clipmin[k]);
loopk(2) bbmax[k] = min(bbmax[k], clipmax[k]);
}
minimapradius = bbmax.tovec().sub(bbmin.tovec()).mul(0.5f);
minimapcenter = bbmin.tovec().add(minimapradius);
minimapradius.x = minimapradius.y = max(minimapradius.x, minimapradius.y);
minimapscale = vec((0.5f - 1.0f/size)/minimapradius.x, (0.5f - 1.0f/size)/minimapradius.y, 1.0f);
envmapping = minimapping = true;
physent *oldcamera = camera1;
static physent cmcamera;
cmcamera = *player;
cmcamera.reset();
cmcamera.type = ENT_CAMERA;
cmcamera.o = vec(minimapcenter.x, minimapcenter.y, max(minimapcenter.z + minimapradius.z + 1, float(minimapheight)));
cmcamera.yaw = 0;
cmcamera.pitch = -90;
cmcamera.roll = 0;
camera1 = &cmcamera;
setviewcell(vec(-1, -1, -1));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-minimapradius.x, minimapradius.x, -minimapradius.y, minimapradius.y, 0, camera1->o.z + 1);
glScalef(-1, 1, 1);
glMatrixMode(GL_MODELVIEW);
transplayer();
defaultshader->set();
GLfloat fogc[4] = { minimapcolor.x/255.0f, minimapcolor.y/255.0f, minimapcolor.z/255.0f, 1.0f };
glFogf(GL_FOG_START, 0);
glFogf(GL_FOG_END, 1000000);
glFogfv(GL_FOG_COLOR, fogc);
glClearColor(fogc[0], fogc[1], fogc[2], fogc[3]);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glViewport(0, 0, size, size);
glDisable(GL_FOG);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glFrontFace(GL_CCW);
xtravertsva = xtraverts = glde = gbatches = 0;
visiblecubes(false);
queryreflections();
drawreflections();
loopi(minimapheight > 0 && minimapheight < minimapcenter.z + minimapradius.z ? 2 : 1)
{
if(i)
{
glClear(GL_DEPTH_BUFFER_BIT);
camera1->o.z = minimapheight;
transplayer();
}
rendergeom();
rendermapmodels();
renderwater();
rendermaterials();
renderalphageom();
}
glFrontFace(GL_CW);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_FOG);
glViewport(0, 0, screen->w, screen->h);
camera1 = oldcamera;
envmapping = minimapping = false;
glBindTexture(GL_TEXTURE_2D, minimaptex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5, 0, 0, size, size, 0);
setuptexparameters(minimaptex, NULL, 3, 1, GL_RGB5, GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
GLfloat border[4] = { minimapcolor.x/255.0f, minimapcolor.y/255.0f, minimapcolor.z/255.0f, 1.0f };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
glBindTexture(GL_TEXTURE_2D, 0);
}
bool deferdrawtextures = false;
void drawtextures()
{
if(minimized) { deferdrawtextures = true; return; }
deferdrawtextures = false;
genenvmaps();
drawminimap();
}
GLuint motiontex = 0;
int motionw = 0, motionh = 0, lastmotion = 0;
void cleanupmotionblur()
{
if(motiontex) { glDeleteTextures(1, &motiontex); motiontex = 0; }
motionw = motionh = 0;
lastmotion = 0;
}
VARFP(motionblur, 0, 0, 1, { if(!motionblur) cleanupmotionblur(); });
VARP(motionblurmillis, 1, 5, 1000);
FVARP(motionblurscale, 0, 0.5f, 1);
void addmotionblur()
{
if(!motionblur || !hasTR || max(screen->w, screen->h) > hwtexsize) return;
if(game::ispaused()) { lastmotion = 0; return; }
if(!motiontex || motionw != screen->w || motionh != screen->h)
{
if(!motiontex) glGenTextures(1, &motiontex);
motionw = screen->w;
motionh = screen->h;
lastmotion = 0;
createtexture(motiontex, motionw, motionh, NULL, 3, 0, GL_RGB, GL_TEXTURE_RECTANGLE_ARB);
}
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, motiontex);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
rectshader->set();
glColor4f(1, 1, 1, lastmotion ? pow(motionblurscale, max(float(lastmillis - lastmotion)/motionblurmillis, 1.0f)) : 0);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f( 0, 0); glVertex2f(-1, -1);
glTexCoord2f(motionw, 0); glVertex2f( 1, -1);
glTexCoord2f( 0, motionh); glVertex2f(-1, 1);
glTexCoord2f(motionw, motionh); glVertex2f( 1, 1);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
if(lastmillis - lastmotion >= motionblurmillis)
{
lastmotion = lastmillis - lastmillis%motionblurmillis;
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, 0, 0, screen->w, screen->h);
}
}
bool dopostfx = false;
void invalidatepostfx()
{
dopostfx = false;
}
void gl_drawhud(int w, int h);
int xtraverts, xtravertsva;
void gl_drawframe(int w, int h)
{
if(deferdrawtextures) drawtextures();
defaultshader->set();
updatedynlights();
aspect = forceaspect ? forceaspect : w/float(h);
fovy = 2*atan2(tan(curfov/2*RAD), aspect)/RAD;
int fogmat = lookupmaterial(camera1->o)&(MATF_VOLUME|MATF_INDEX), abovemat = MAT_AIR;
float fogblend = 1.0f, causticspass = 0.0f;
if(isliquid(fogmat&MATF_VOLUME))
{
float z = findsurface(fogmat, camera1->o, abovemat) - WATER_OFFSET;
if(camera1->o.z < z + 1) fogblend = min(z + 1 - camera1->o.z, 1.0f);
else fogmat = abovemat;
if(caustics && (fogmat&MATF_VOLUME)==MAT_WATER && camera1->o.z < z)
causticspass = renderpath==R_FIXEDFUNCTION ? 1.0f : min(z - camera1->o.z, 1.0f);
}
else fogmat = MAT_AIR;
setfog(fogmat, fogblend, abovemat);
if(fogmat!=MAT_AIR)
{
float blend = abovemat==MAT_AIR ? fogblend : 1.0f;
fovy += blend*sinf(lastmillis/1000.0)*2.0f;
aspect += blend*sinf(lastmillis/1000.0+PI)*0.1f;
}
farplane = worldsize*2;
project(fovy, aspect, farplane);
transplayer();
readmatrices();
findorientation();
setenvmatrix();
glEnable(GL_FOG);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
xtravertsva = xtraverts = glde = gbatches = 0;
if(!hasFBO)
{
if(dopostfx)
{
drawglaretex();
drawdepthfxtex();
drawreflections();
}
else dopostfx = true;
}
visiblecubes();
if(shadowmap && !hasFBO) rendershadowmap();
glClear(GL_DEPTH_BUFFER_BIT|(wireframe && editmode ? GL_COLOR_BUFFER_BIT : 0)|(hasstencil ? GL_STENCIL_BUFFER_BIT : 0));
if(wireframe && editmode) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if(limitsky()) drawskybox(farplane, true);
rendergeom(causticspass);
extern int outline;
if(!wireframe && editmode && outline) renderoutline();
queryreflections();
generategrass();
if(!limitsky()) drawskybox(farplane, false);
renderdecals(true);
rendermapmodels();
rendergame(true);
if(!isthirdperson())
{
project(curavatarfov, aspect, farplane, false, false, false, avatardepth);
game::renderavatar();
project(fovy, aspect, farplane);
}
if(wireframe && editmode) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(hasFBO)
{
drawglaretex();
drawdepthfxtex();
drawreflections();
}
if(wireframe && editmode) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
renderwater();
rendergrass();
rendermaterials();
renderalphageom();
if(wireframe && editmode) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
renderparticles(true);
glDisable(GL_FOG);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
addmotionblur();
addglare();
if(isliquid(fogmat&MATF_VOLUME)) drawfogoverlay(fogmat, fogblend, abovemat);
renderpostfx();
defaultshader->set();
g3d_render();
glDisable(GL_TEXTURE_2D);
notextureshader->set();
gl_drawhud(w, h);
renderedgame = false;
}
void gl_drawmainmenu(int w, int h)
{
xtravertsva = xtraverts = glde = gbatches = 0;
renderbackground(NULL, NULL, NULL, NULL, true, true);
renderpostfx();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
defaultshader->set();
glEnable(GL_TEXTURE_2D);
g3d_render();
notextureshader->set();
glDisable(GL_TEXTURE_2D);
gl_drawhud(w, h);
}
VARNP(damagecompass, usedamagecompass, 0, 1, 1);
VARP(damagecompassfade, 1, 1000, 10000);
VARP(damagecompasssize, 1, 30, 100);
VARP(damagecompassalpha, 1, 25, 100);
VARP(damagecompassmin, 1, 25, 1000);
VARP(damagecompassmax, 1, 200, 1000);
float dcompass[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
void damagecompass(int n, const vec &loc)
{
if(!usedamagecompass || minimized) return;
vec delta(loc);
delta.sub(camera1->o);
float yaw, pitch;
if(delta.magnitude()<4) yaw = camera1->yaw;
else vectoyawpitch(delta, yaw, pitch);
yaw -= camera1->yaw;
if(yaw >= 360) yaw = fmod(yaw, 360);
else if(yaw < 0) yaw = 360 - fmod(-yaw, 360);
int dir = (int(yaw+22.5f)%360)/45;
dcompass[dir] += max(n, damagecompassmin)/float(damagecompassmax);
if(dcompass[dir]>1) dcompass[dir] = 1;
}
void drawdamagecompass(int w, int h)
{
int dirs = 0;
float size = damagecompasssize/100.0f*min(h, w)/2.0f;
loopi(8) if(dcompass[i]>0)
{
if(!dirs)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 0, 0, damagecompassalpha/100.0f);
}
dirs++;
glPushMatrix();
glTranslatef(w/2, h/2, 0);
glRotatef(i*45, 0, 0, 1);
glTranslatef(0, -size/2.0f-min(h, w)/4.0f, 0);
float logscale = 32,
scale = log(1 + (logscale - 1)*dcompass[i]) / log(logscale);
glScalef(size*scale, size*scale, 0);
glBegin(GL_TRIANGLES);
glVertex3f(1, 1, 0);
glVertex3f(-1, 1, 0);
glVertex3f(0, 0, 0);
glEnd();
glPopMatrix();
// fade in log space so short blips don't disappear too quickly
scale -= float(curtime)/damagecompassfade;
dcompass[i] = scale > 0 ? (pow(logscale, scale) - 1) / (logscale - 1) : 0;
}
}
int damageblendmillis = 0;
VARFP(damagescreen, 0, 1, 1, { if(!damagescreen) damageblendmillis = 0; });
VARP(damagescreenfactor, 1, 7, 100);
VARP(damagescreenalpha, 1, 45, 100);
VARP(damagescreenfade, 0, 125, 1000);
VARP(damagescreenmin, 1, 10, 1000);
VARP(damagescreenmax, 1, 100, 1000);
void damageblend(int n)
{
if(!damagescreen || minimized) return;
if(lastmillis > damageblendmillis) damageblendmillis = lastmillis;
damageblendmillis += clamp(n, damagescreenmin, damagescreenmax)*damagescreenfactor;
}
void drawdamagescreen(int w, int h)
{
if(lastmillis >= damageblendmillis) return;
defaultshader->set();
glEnable(GL_TEXTURE_2D);
static Texture *damagetex = NULL;
if(!damagetex) damagetex = textureload("packages/hud/damage.png", 3);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, damagetex->id);
float fade = damagescreenalpha/100.0f;
if(damageblendmillis - lastmillis < damagescreenfade)
fade *= float(damageblendmillis - lastmillis)/damagescreenfade;
glColor4f(fade, fade, fade, fade);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(1, 0); glVertex2f(w, 0);
glTexCoord2f(0, 1); glVertex2f(0, h);
glTexCoord2f(1, 1); glVertex2f(w, h);
glEnd();
glDisable(GL_TEXTURE_2D);
notextureshader->set();
}
VAR(hidestats, 0, 0, 1);
VAR(hidehud, 0, 0, 1);
VARP(crosshairsize, 0, 15, 50);
VARP(cursorsize, 0, 30, 50);
VARP(crosshairfx, 0, 1, 1);
VARP(crosshaircolors, 0, 1, 1);
#define MAXCROSSHAIRS 4
static Texture *crosshairs[MAXCROSSHAIRS] = { NULL, NULL, NULL, NULL };
void loadcrosshair(const char *name, int i)
{
if(i < 0 || i >= MAXCROSSHAIRS) return;
crosshairs[i] = name ? textureload(name, 3, true) : notexture;
if(crosshairs[i] == notexture)
{
name = game::defaultcrosshair(i);
if(!name) name = "data/crosshair.png";
crosshairs[i] = textureload(name, 3, true);
}
}
void loadcrosshair_(const char *name, int *i)
{
loadcrosshair(name, *i);
}
COMMANDN(loadcrosshair, loadcrosshair_, "si");
ICOMMAND(getcrosshair, "i", (int *i),
{
const char *name = "";
if(*i >= 0 && *i < MAXCROSSHAIRS)
{
name = crosshairs[*i] ? crosshairs[*i]->name : game::defaultcrosshair(*i);
if(!name) name = "data/crosshair.png";
}
result(name);
});
void writecrosshairs(stream *f)
{
loopi(MAXCROSSHAIRS) if(crosshairs[i] && crosshairs[i]!=notexture)
f->printf("loadcrosshair %s %d\n", escapestring(crosshairs[i]->name), i);
f->printf("\n");
}
void drawcrosshair(int w, int h)
{
bool windowhit = g3d_windowhit(true, false);
if(!windowhit && (hidehud || mainmenu)) return; //(hidehud || player->state==CS_SPECTATOR || player->state==CS_DEAD)) return;
float r = 1, g = 1, b = 1, cx = 0.5f, cy = 0.5f, chsize;
Texture *crosshair;
if(windowhit)
{
static Texture *cursor = NULL;
if(!cursor) cursor = textureload("data/guicursor.png", 3, true);
crosshair = cursor;
chsize = cursorsize*w/900.0f;
g3d_cursorpos(cx, cy);
}
else
{
int index = game::selectcrosshair(r, g, b);
if(index < 0) return;
if(!crosshairfx) index = 0;
if(!crosshairfx || !crosshaircolors) r = g = b = 1;
crosshair = crosshairs[index];
if(!crosshair)
{
loadcrosshair(NULL, index);
crosshair = crosshairs[index];
}
chsize = crosshairsize*w/900.0f;
}
if(crosshair->type&Texture::ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else glBlendFunc(GL_ONE, GL_ONE);
glColor3f(r, g, b);
float x = cx*w - (windowhit ? 0 : chsize/2.0f);
float y = cy*h - (windowhit ? 0 : chsize/2.0f);
glBindTexture(GL_TEXTURE_2D, crosshair->id);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0, 0); glVertex2f(x, y);
glTexCoord2f(1, 0); glVertex2f(x + chsize, y);
glTexCoord2f(0, 1); glVertex2f(x, y + chsize);
glTexCoord2f(1, 1); glVertex2f(x + chsize, y + chsize);
glEnd();
}
VARP(wallclock, 0, 0, 1);
VARP(wallclock24, 0, 0, 1);
VARP(wallclocksecs, 0, 0, 1);
static time_t walltime = 0;
VARP(showfps, 0, 1, 1);
VARP(showfpsrange, 0, 0, 1);
VAR(showeditstats, 0, 0, 1);
VAR(statrate, 1, 200, 1000);
FVARP(conscale, 1e-3f, 0.33f, 1e3f);
void gl_drawhud(int w, int h)
{
if(forceaspect) w = int(ceil(h*forceaspect));
if(editmode && !hidehud && !mainmenu)
{
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
renderblendbrush();
rendereditcursor();
glDepthMask(GL_TRUE);
glDisable(GL_DEPTH_TEST);
}
gettextres(w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1, 1, 1);
extern int debugsm;
if(debugsm)
{
extern void viewshadowmap();
viewshadowmap();
}
extern int debugglare;
if(debugglare)
{
extern void viewglaretex();
viewglaretex();
}
extern int debugdepthfx;
if(debugdepthfx)
{
extern void viewdepthfxtex();
viewdepthfxtex();
}
glEnable(GL_BLEND);
if(!mainmenu)
{
drawdamagescreen(w, h);
drawdamagecompass(w, h);
}
glEnable(GL_TEXTURE_2D);
defaultshader->set();
int conw = int(w/conscale), conh = int(h/conscale), abovehud = conh - FONTH, limitgui = abovehud;
if(!hidehud && !mainmenu)
{
if(!hidestats)
{
glPushMatrix();
glScalef(conscale, conscale, 1);
int roffset = 0;
if(showfps)
{
static int lastfps = 0, prevfps[3] = { 0, 0, 0 }, curfps[3] = { 0, 0, 0 };
if(totalmillis - lastfps >= statrate)
{
memcpy(prevfps, curfps, sizeof(prevfps));
lastfps = totalmillis - (totalmillis%statrate);
}
int nextfps[3];
getfps(nextfps[0], nextfps[1], nextfps[2]);
loopi(3) if(prevfps[i]==curfps[i]) curfps[i] = nextfps[i];
if(showfpsrange) draw_textf("fps %d+%d-%d", conw-7*FONTH, conh-FONTH*3/2, curfps[0], curfps[1], curfps[2]);
else draw_textf("fps %d", conw-5*FONTH, conh-FONTH*3/2, curfps[0]);
roffset += FONTH;
}
if(wallclock)
{
if(!walltime) { walltime = time(NULL); walltime -= totalmillis/1000; if(!walltime) walltime++; }
time_t walloffset = walltime + totalmillis/1000;
struct tm *localvals = localtime(&walloffset);
static string buf;
if(localvals && strftime(buf, sizeof(buf), wallclocksecs ? (wallclock24 ? "%H:%M:%S" : "%I:%M:%S%p") : (wallclock24 ? "%H:%M" : "%I:%M%p"), localvals))
{
// hack because not all platforms (windows) support %P lowercase option
// also strip leading 0 from 12 hour time
char *dst = buf;
const char *src = &buf[!wallclock24 && buf[0]=='0' ? 1 : 0];
while(*src) *dst++ = tolower(*src++);
*dst++ = '\0';
draw_text(buf, conw-5*FONTH, conh-FONTH*3/2-roffset);
roffset += FONTH;
}
}
if(editmode || showeditstats)
{
static int laststats = 0, prevstats[8] = { 0, 0, 0, 0, 0, 0, 0 }, curstats[8] = { 0, 0, 0, 0, 0, 0, 0 };
if(totalmillis - laststats >= statrate)
{
memcpy(prevstats, curstats, sizeof(prevstats));
laststats = totalmillis - (totalmillis%statrate);
}
int nextstats[8] =
{
vtris*100/max(wtris, 1),
vverts*100/max(wverts, 1),
xtraverts/1024,
xtravertsva/1024,
glde,
gbatches,
getnumqueries(),
rplanes
};
loopi(8) if(prevstats[i]==curstats[i]) curstats[i] = nextstats[i];
abovehud -= 2*FONTH;
draw_textf("wtr:%dk(%d%%) wvt:%dk(%d%%) evt:%dk eva:%dk", FONTH/2, abovehud, wtris/1024, curstats[0], wverts/1024, curstats[1], curstats[2], curstats[3]);
draw_textf("ond:%d va:%d gl:%d(%d) oq:%d lm:%d rp:%d pvs:%d", FONTH/2, abovehud+FONTH, allocnodes*8, allocva, curstats[4], curstats[5], curstats[6], lightmaps.length(), curstats[7], getnumviewcells());
limitgui = abovehud;
}
if(editmode)
{
abovehud -= FONTH;
draw_textf("cube %s%d%s", FONTH/2, abovehud, selchildcount<0 ? "1/" : "", abs(selchildcount), showmat && selchildmat > 0 ? getmaterialdesc(selchildmat, ": ") : "");
char *editinfo = executestr("edithud");
if(editinfo)
{
if(editinfo[0])
{
int tw, th;
text_bounds(editinfo, tw, th);
th += FONTH-1; th -= th%FONTH;
abovehud -= max(th, FONTH);
draw_text(editinfo, FONTH/2, abovehud);
}
DELETEA(editinfo);
}
}
else if(identexists("gamehud"))
{
char *gameinfo = executestr("gamehud");
if(gameinfo)
{
if(gameinfo[0])
{
int tw, th;
text_bounds(gameinfo, tw, th);
th += FONTH-1; th -= th%FONTH;
roffset += max(th, FONTH);
draw_text(gameinfo, conw-max(5*FONTH, 2*FONTH+tw), conh-FONTH/2-roffset);
}
DELETEA(gameinfo);
}
}
glPopMatrix();
}
if(hidestats || (!editmode && !showeditstats))
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
game::gameplayhud(w, h);
limitgui = abovehud = min(abovehud, int(conh*game::abovegameplayhud(w, h)));
}
rendertexturepanel(w, h);
}
g3d_limitscale((2*limitgui - conh) / float(conh));
glPushMatrix();
glScalef(conscale, conscale, 1);
abovehud -= rendercommand(FONTH/2, abovehud - FONTH/2, conw-FONTH);
extern int fullconsole;
if(!hidehud || fullconsole) renderconsole(conw, conh, abovehud - FONTH/2);
glPopMatrix();
drawcrosshair(w, h);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
|