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 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (“RTCW MP Source Code”).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "tr_local.h"
// tr_shader.c -- this file deals with the parsing and definition of shaders
static char *s_shaderText;
// the shader is parsed into these global variables, then copied into
// dynamically allocated memory if it is valid.
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
#define FILE_HASH_SIZE 4096
static shader_t* hashTable[FILE_HASH_SIZE];
/*
================
return a hash value for the filename
================
*/
#ifdef __GNUCC__
#warning TODO: check if long is ok here
#endif
static long generateHashValue( const char *fname ) {
int i;
long hash;
char letter;
hash = 0;
i = 0;
while ( fname[i] != '\0' ) {
letter = tolower( fname[i] );
if ( letter == '.' ) {
break; // don't include extension
}
if ( letter == '\\' ) {
letter = '/'; // damn path names
}
if ( letter == PATH_SEP ) {
letter = '/'; // damn path names
}
hash += (long)( letter ) * ( i + 119 );
i++;
}
hash &= ( FILE_HASH_SIZE - 1 );
return hash;
}
void R_RemapShader( const char *shaderName, const char *newShaderName, const char *timeOffset ) {
char strippedName[MAX_QPATH];
int hash;
shader_t *sh, *sh2;
qhandle_t h;
sh = R_FindShaderByName( shaderName );
if ( sh == NULL || sh == tr.defaultShader ) {
h = RE_RegisterShaderLightMap( shaderName, 0 );
sh = R_GetShaderByHandle( h );
}
if ( sh == NULL || sh == tr.defaultShader ) {
ri.Printf( PRINT_WARNING, "WARNING: R_RemapShader: shader %s not found\n", shaderName );
return;
}
sh2 = R_FindShaderByName( newShaderName );
if ( sh2 == NULL || sh2 == tr.defaultShader ) {
h = RE_RegisterShaderLightMap( newShaderName, 0 );
sh2 = R_GetShaderByHandle( h );
}
if ( sh2 == NULL || sh2 == tr.defaultShader ) {
ri.Printf( PRINT_WARNING, "WARNING: R_RemapShader: new shader %s not found\n", newShaderName );
return;
}
// remap all the shaders with the given name
// even tho they might have different lightmaps
COM_StripExtension( shaderName, strippedName, sizeof( strippedName ) );
hash = generateHashValue( strippedName );
for ( sh = hashTable[hash]; sh; sh = sh->next ) {
if ( Q_stricmp( sh->name, strippedName ) == 0 ) {
if ( sh != sh2 ) {
sh->remappedShader = sh2;
} else {
sh->remappedShader = NULL;
}
}
}
if ( timeOffset ) {
sh2->timeOffset = atof( timeOffset );
}
}
/*
===============
ParseVector
===============
*/
static qboolean ParseVector( char **text, int count, float *v ) {
char *token;
int i;
// FIXME: spaces are currently required after parens, should change parseext...
token = COM_ParseExt( text, qfalse );
if ( strcmp( token, "(" ) ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parenthesis in shader '%s'\n", shader.name );
return qfalse;
}
for ( i = 0 ; i < count ; i++ ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing vector element in shader '%s'\n", shader.name );
return qfalse;
}
v[i] = atof( token );
}
token = COM_ParseExt( text, qfalse );
if ( strcmp( token, ")" ) ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parenthesis in shader '%s'\n", shader.name );
return qfalse;
}
return qtrue;
}
/*
===============
NameToAFunc
===============
*/
static unsigned NameToAFunc( const char *funcname ) {
if ( !Q_stricmp( funcname, "GT0" ) ) {
return GLS_ATEST_GT_0;
} else if ( !Q_stricmp( funcname, "LT128" ) ) {
return GLS_ATEST_LT_80;
} else if ( !Q_stricmp( funcname, "GE128" ) ) {
return GLS_ATEST_GE_80;
}
ri.Printf( PRINT_WARNING, "WARNING: invalid alphaFunc name '%s' in shader '%s'\n", funcname, shader.name );
return 0;
}
/*
===============
NameToSrcBlendMode
===============
*/
static int NameToSrcBlendMode( const char *name ) {
if ( !Q_stricmp( name, "GL_ONE" ) ) {
return GLS_SRCBLEND_ONE;
} else if ( !Q_stricmp( name, "GL_ZERO" ) ) {
return GLS_SRCBLEND_ZERO;
} else if ( !Q_stricmp( name, "GL_DST_COLOR" ) ) {
return GLS_SRCBLEND_DST_COLOR;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_DST_COLOR" ) ) {
return GLS_SRCBLEND_ONE_MINUS_DST_COLOR;
} else if ( !Q_stricmp( name, "GL_SRC_ALPHA" ) ) {
return GLS_SRCBLEND_SRC_ALPHA;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_SRC_ALPHA" ) ) {
return GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA;
} else if ( !Q_stricmp( name, "GL_DST_ALPHA" ) ) {
return GLS_SRCBLEND_DST_ALPHA;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_DST_ALPHA" ) ) {
return GLS_SRCBLEND_ONE_MINUS_DST_ALPHA;
} else if ( !Q_stricmp( name, "GL_SRC_ALPHA_SATURATE" ) ) {
return GLS_SRCBLEND_ALPHA_SATURATE;
}
ri.Printf( PRINT_WARNING, "WARNING: unknown blend mode '%s' in shader '%s', substituting GL_ONE\n", name, shader.name );
return GLS_SRCBLEND_ONE;
}
/*
===============
NameToDstBlendMode
===============
*/
static int NameToDstBlendMode( const char *name ) {
if ( !Q_stricmp( name, "GL_ONE" ) ) {
return GLS_DSTBLEND_ONE;
} else if ( !Q_stricmp( name, "GL_ZERO" ) ) {
return GLS_DSTBLEND_ZERO;
} else if ( !Q_stricmp( name, "GL_SRC_ALPHA" ) ) {
return GLS_DSTBLEND_SRC_ALPHA;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_SRC_ALPHA" ) ) {
return GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
} else if ( !Q_stricmp( name, "GL_DST_ALPHA" ) ) {
return GLS_DSTBLEND_DST_ALPHA;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_DST_ALPHA" ) ) {
return GLS_DSTBLEND_ONE_MINUS_DST_ALPHA;
} else if ( !Q_stricmp( name, "GL_SRC_COLOR" ) ) {
return GLS_DSTBLEND_SRC_COLOR;
} else if ( !Q_stricmp( name, "GL_ONE_MINUS_SRC_COLOR" ) ) {
return GLS_DSTBLEND_ONE_MINUS_SRC_COLOR;
}
ri.Printf( PRINT_WARNING, "WARNING: unknown blend mode '%s' in shader '%s', substituting GL_ONE\n", name, shader.name );
return GLS_DSTBLEND_ONE;
}
/*
===============
NameToGenFunc
===============
*/
static genFunc_t NameToGenFunc( const char *funcname ) {
if ( !Q_stricmp( funcname, "sin" ) ) {
return GF_SIN;
} else if ( !Q_stricmp( funcname, "square" ) ) {
return GF_SQUARE;
} else if ( !Q_stricmp( funcname, "triangle" ) ) {
return GF_TRIANGLE;
} else if ( !Q_stricmp( funcname, "sawtooth" ) ) {
return GF_SAWTOOTH;
} else if ( !Q_stricmp( funcname, "inversesawtooth" ) ) {
return GF_INVERSE_SAWTOOTH;
} else if ( !Q_stricmp( funcname, "noise" ) ) {
return GF_NOISE;
}
ri.Printf( PRINT_WARNING, "WARNING: invalid genfunc name '%s' in shader '%s'\n", funcname, shader.name );
return GF_SIN;
}
/*
===================
ParseWaveForm
===================
*/
static void ParseWaveForm( char **text, waveForm_t *wave ) {
char *token;
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing waveform parm in shader '%s'\n", shader.name );
return;
}
wave->func = NameToGenFunc( token );
// BASE, AMP, PHASE, FREQ
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing waveform parm in shader '%s'\n", shader.name );
return;
}
wave->base = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing waveform parm in shader '%s'\n", shader.name );
return;
}
wave->amplitude = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing waveform parm in shader '%s'\n", shader.name );
return;
}
wave->phase = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing waveform parm in shader '%s'\n", shader.name );
return;
}
wave->frequency = atof( token );
}
/*
===================
ParseTexMod
===================
*/
static void ParseTexMod( char *_text, shaderStage_t *stage ) {
const char *token;
char **text = &_text;
texModInfo_t *tmi;
if ( stage->bundle[0].numTexMods == TR_MAX_TEXMODS ) {
ri.Error( ERR_DROP, "ERROR: too many tcMod stages in shader '%s'", shader.name );
return;
}
tmi = &stage->bundle[0].texMods[stage->bundle[0].numTexMods];
stage->bundle[0].numTexMods++;
token = COM_ParseExt( text, qfalse );
//
// swap
//
if ( !Q_stricmp( token, "swap" ) ) { // swap S/T coords (rotate 90d)
tmi->type = TMOD_SWAP;
}
//
// turb
//
// (SA) added 'else' so it wouldn't claim 'swap' was unknown.
else if ( !Q_stricmp( token, "turb" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod turb parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.base = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod turb in shader '%s'\n", shader.name );
return;
}
tmi->wave.amplitude = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod turb in shader '%s'\n", shader.name );
return;
}
tmi->wave.phase = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod turb in shader '%s'\n", shader.name );
return;
}
tmi->wave.frequency = atof( token );
tmi->type = TMOD_TURBULENT;
}
//
// scale
//
else if ( !Q_stricmp( token, "scale" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing scale parms in shader '%s'\n", shader.name );
return;
}
tmi->scale[0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing scale parms in shader '%s'\n", shader.name );
return;
}
tmi->scale[1] = atof( token );
tmi->type = TMOD_SCALE;
}
//
// scroll
//
else if ( !Q_stricmp( token, "scroll" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing scale scroll parms in shader '%s'\n", shader.name );
return;
}
tmi->scroll[0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing scale scroll parms in shader '%s'\n", shader.name );
return;
}
tmi->scroll[1] = atof( token );
tmi->type = TMOD_SCROLL;
}
//
// stretch
//
else if ( !Q_stricmp( token, "stretch" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing stretch parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.func = NameToGenFunc( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing stretch parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.base = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing stretch parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.amplitude = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing stretch parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.phase = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing stretch parms in shader '%s'\n", shader.name );
return;
}
tmi->wave.frequency = atof( token );
tmi->type = TMOD_STRETCH;
}
//
// transform
//
else if ( !Q_stricmp( token, "transform" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[0][0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[0][1] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[1][0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->matrix[1][1] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->translate[0] = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing transform parms in shader '%s'\n", shader.name );
return;
}
tmi->translate[1] = atof( token );
tmi->type = TMOD_TRANSFORM;
}
//
// rotate
//
else if ( !Q_stricmp( token, "rotate" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing tcMod rotate parms in shader '%s'\n", shader.name );
return;
}
tmi->rotateSpeed = atof( token );
tmi->type = TMOD_ROTATE;
}
//
// entityTranslate
//
else if ( !Q_stricmp( token, "entityTranslate" ) ) {
tmi->type = TMOD_ENTITY_TRANSLATE;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown tcMod '%s' in shader '%s'\n", token, shader.name );
}
}
/*
===================
ParseStage
===================
*/
static qboolean ParseStage( shaderStage_t *stage, char **text ) {
char *token;
int depthMaskBits = GLS_DEPTHMASK_TRUE, blendSrcBits = 0, blendDstBits = 0, atestBits = 0, depthFuncBits = 0;
qboolean depthMaskExplicit = qfalse;
stage->active = qtrue;
while ( 1 )
{
token = COM_ParseExt( text, qtrue );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: no matching '}' found\n" );
return qfalse;
}
if ( token[0] == '}' ) {
break;
}
//
// check special case for map16/map32/mapcomp/mapnocomp (compression enabled)
if ( !Q_stricmp( token, "map16" ) ) { // only use this texture if 16 bit color depth
if ( glConfig.colorBits <= 16 ) {
token = "map"; // use this map
} else {
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
} else if ( !Q_stricmp( token, "map32" ) ) { // only use this texture if 16 bit color depth
if ( glConfig.colorBits > 16 ) {
token = "map"; // use this map
} else {
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
} else if ( !Q_stricmp( token, "mapcomp" ) ) { // only use this texture if compression is enabled
if ( glConfig.textureCompression && r_ext_compressed_textures->integer ) {
token = "map"; // use this map
} else {
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
} else if ( !Q_stricmp( token, "mapnocomp" ) ) { // only use this texture if compression is not available or disabled
if ( !glConfig.textureCompression ) {
token = "map"; // use this map
} else {
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
} else if ( !Q_stricmp( token, "animmapcomp" ) ) { // only use this texture if compression is enabled
if ( glConfig.textureCompression && r_ext_compressed_textures->integer ) {
token = "animmap"; // use this map
} else {
while ( token[0] )
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
} else if ( !Q_stricmp( token, "animmapnocomp" ) ) { // only use this texture if compression is not available or disabled
if ( !glConfig.textureCompression ) {
token = "animmap"; // use this map
} else {
while ( token[0] )
COM_ParseExt( text, qfalse ); // ignore the map
continue;
}
}
//
// map <name>
//
if ( !Q_stricmp( token, "map" ) ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'map' keyword in shader '%s'\n", shader.name );
return qfalse;
}
//----(SA) fixes startup error and allows polygon shadows to work again
if ( !Q_stricmp( token, "$whiteimage" ) || !Q_stricmp( token, "*white" ) ) {
//----(SA) end
stage->bundle[0].image[0] = tr.whiteImage;
continue;
}
//----(SA) added
else if ( !Q_stricmp( token, "$dlight" ) ) {
stage->bundle[0].image[0] = tr.dlightImage;
continue;
}
//----(SA) end
else if ( !Q_stricmp( token, "$lightmap" ) ) {
stage->bundle[0].isLightmap = qtrue;
if ( shader.lightmapIndex < 0 || !tr.lightmaps ) {
stage->bundle[0].image[0] = tr.whiteImage;
} else {
stage->bundle[0].image[0] = tr.lightmaps[shader.lightmapIndex];
}
continue;
} else
{
imgType_t type = IMGTYPE_COLORALPHA;
imgFlags_t flags = IMGFLAG_NONE;
if (!shader.noMipMaps)
flags |= IMGFLAG_MIPMAP;
if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
stage->bundle[0].image[0] = R_FindImageFile( token, type, flags );
if ( !stage->bundle[0].image[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
}
}
//
// clampmap <name>
//
else if ( !Q_stricmp( token, "clampmap" ) ) {
imgType_t type = IMGTYPE_COLORALPHA;
imgFlags_t flags = IMGFLAG_CLAMPTOEDGE;
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'clampmap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
if (!shader.noMipMaps)
flags |= IMGFLAG_MIPMAP;
if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
stage->bundle[0].image[0] = R_FindImageFile( token, type, flags );
if ( !stage->bundle[0].image[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
}
//
// animMap <frequency> <image1> .... <imageN>
//
else if ( !Q_stricmp( token, "animMap" ) ) {
int totalImages = 0;
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'animMap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
stage->bundle[0].imageAnimationSpeed = atof( token );
// parse up to MAX_IMAGE_ANIMATIONS animations
while ( 1 ) {
int num;
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
break;
}
num = stage->bundle[0].numImageAnimations;
if ( num < MAX_IMAGE_ANIMATIONS ) {
imgFlags_t flags = IMGFLAG_NONE;
if (!shader.noMipMaps)
flags |= IMGFLAG_MIPMAP;
if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
stage->bundle[0].image[num] = R_FindImageFile( token, IMGTYPE_COLORALPHA, flags );
if ( !stage->bundle[0].image[num] ) {
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
stage->bundle[0].numImageAnimations++;
}
totalImages++;
}
if ( totalImages > MAX_IMAGE_ANIMATIONS ) {
ri.Printf( PRINT_WARNING, "WARNING: ignoring excess images for 'animMap' (found %d, max is %d) in shader '%s'\n",
totalImages, MAX_IMAGE_ANIMATIONS, shader.name );
}
} else if ( !Q_stricmp( token, "videoMap" ) ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'videoMap' keyword in shader '%s'\n", shader.name );
return qfalse;
}
stage->bundle[0].videoMapHandle = ri.CIN_PlayCinematic( token, 0, 0, 256, 256, ( CIN_loop | CIN_silent | CIN_shader ) );
if ( stage->bundle[0].videoMapHandle != -1 ) {
stage->bundle[0].isVideoMap = qtrue;
stage->bundle[0].image[0] = tr.scratchImage[stage->bundle[0].videoMapHandle];
} else {
ri.Printf( PRINT_WARNING, "WARNING: could not load '%s' for 'videoMap' keyword in shader '%s'\n", token, shader.name );
}
}
//
// alphafunc <func>
//
else if ( !Q_stricmp( token, "alphaFunc" ) ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'alphaFunc' keyword in shader '%s'\n", shader.name );
return qfalse;
}
atestBits = NameToAFunc( token );
}
//
// depthFunc <func>
//
else if ( !Q_stricmp( token, "depthfunc" ) ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameter for 'depthfunc' keyword in shader '%s'\n", shader.name );
return qfalse;
}
if ( !Q_stricmp( token, "lequal" ) ) {
depthFuncBits = 0;
} else if ( !Q_stricmp( token, "equal" ) ) {
depthFuncBits = GLS_DEPTHFUNC_EQUAL;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown depthfunc '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// detail
//
else if ( !Q_stricmp( token, "detail" ) ) {
stage->isDetail = qtrue;
}
//
// fog
//
else if ( !Q_stricmp( token, "fog" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parm for fog in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "on" ) ) {
stage->isFogged = qtrue;
} else {
stage->isFogged = qfalse;
}
}
//
// blendfunc <srcFactor> <dstFactor>
// or blendfunc <add|filter|blend>
//
else if ( !Q_stricmp( token, "blendfunc" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parm for blendFunc in shader '%s'\n", shader.name );
continue;
}
// check for "simple" blends first
if ( !Q_stricmp( token, "add" ) ) {
blendSrcBits = GLS_SRCBLEND_ONE;
blendDstBits = GLS_DSTBLEND_ONE;
} else if ( !Q_stricmp( token, "filter" ) ) {
blendSrcBits = GLS_SRCBLEND_DST_COLOR;
blendDstBits = GLS_DSTBLEND_ZERO;
} else if ( !Q_stricmp( token, "blend" ) ) {
blendSrcBits = GLS_SRCBLEND_SRC_ALPHA;
blendDstBits = GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
} else {
// complex double blends
blendSrcBits = NameToSrcBlendMode( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parm for blendFunc in shader '%s'\n", shader.name );
continue;
}
blendDstBits = NameToDstBlendMode( token );
}
// clear depth mask for blended surfaces
if ( !depthMaskExplicit ) {
depthMaskBits = 0;
}
}
//
// rgbGen
//
else if ( !Q_stricmp( token, "rgbGen" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameters for rgbGen in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "wave" ) ) {
ParseWaveForm( text, &stage->rgbWave );
stage->rgbGen = CGEN_WAVEFORM;
} else if ( !Q_stricmp( token, "const" ) ) {
vec3_t color;
VectorClear( color );
ParseVector( text, 3, color );
stage->constantColor[0] = 255 * color[0];
stage->constantColor[1] = 255 * color[1];
stage->constantColor[2] = 255 * color[2];
stage->rgbGen = CGEN_CONST;
} else if ( !Q_stricmp( token, "identity" ) ) {
stage->rgbGen = CGEN_IDENTITY;
} else if ( !Q_stricmp( token, "identityLighting" ) ) {
stage->rgbGen = CGEN_IDENTITY_LIGHTING;
} else if ( !Q_stricmp( token, "entity" ) ) {
stage->rgbGen = CGEN_ENTITY;
} else if ( !Q_stricmp( token, "oneMinusEntity" ) ) {
stage->rgbGen = CGEN_ONE_MINUS_ENTITY;
} else if ( !Q_stricmp( token, "vertex" ) ) {
stage->rgbGen = CGEN_VERTEX;
if ( stage->alphaGen == 0 ) {
stage->alphaGen = AGEN_VERTEX;
}
} else if ( !Q_stricmp( token, "exactVertex" ) ) {
stage->rgbGen = CGEN_EXACT_VERTEX;
} else if ( !Q_stricmp( token, "lightingDiffuse" ) ) {
stage->rgbGen = CGEN_LIGHTING_DIFFUSE;
} else if ( !Q_stricmp( token, "oneMinusVertex" ) ) {
stage->rgbGen = CGEN_ONE_MINUS_VERTEX;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown rgbGen parameter '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// alphaGen
//
else if ( !Q_stricmp( token, "alphaGen" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parameters for alphaGen in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "wave" ) ) {
ParseWaveForm( text, &stage->alphaWave );
stage->alphaGen = AGEN_WAVEFORM;
} else if ( !Q_stricmp( token, "const" ) ) {
token = COM_ParseExt( text, qfalse );
stage->constantColor[3] = 255 * atof( token );
stage->alphaGen = AGEN_CONST;
} else if ( !Q_stricmp( token, "identity" ) ) {
stage->alphaGen = AGEN_IDENTITY;
} else if ( !Q_stricmp( token, "entity" ) ) {
stage->alphaGen = AGEN_ENTITY;
} else if ( !Q_stricmp( token, "oneMinusEntity" ) ) {
stage->alphaGen = AGEN_ONE_MINUS_ENTITY;
}
// Ridah
else if ( !Q_stricmp( token, "normalzfade" ) ) {
stage->alphaGen = AGEN_NORMALZFADE;
token = COM_ParseExt( text, qfalse );
if ( token[0] ) {
stage->constantColor[3] = 255 * atof( token );
} else {
stage->constantColor[3] = 255;
}
token = COM_ParseExt( text, qfalse );
if ( token[0] ) {
stage->zFadeBounds[0] = atof( token ); // lower range
token = COM_ParseExt( text, qfalse );
stage->zFadeBounds[1] = atof( token ); // upper range
} else {
stage->zFadeBounds[0] = -1.0; // lower range
stage->zFadeBounds[1] = 1.0; // upper range
}
}
// done.
else if ( !Q_stricmp( token, "vertex" ) ) {
stage->alphaGen = AGEN_VERTEX;
} else if ( !Q_stricmp( token, "lightingSpecular" ) ) {
stage->alphaGen = AGEN_LIGHTING_SPECULAR;
} else if ( !Q_stricmp( token, "oneMinusVertex" ) ) {
stage->alphaGen = AGEN_ONE_MINUS_VERTEX;
} else if ( !Q_stricmp( token, "portal" ) ) {
stage->alphaGen = AGEN_PORTAL;
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
shader.portalRange = 256;
ri.Printf( PRINT_WARNING, "WARNING: missing range parameter for alphaGen portal in shader '%s', defaulting to 256\n", shader.name );
} else
{
shader.portalRange = atof( token );
}
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown alphaGen parameter '%s' in shader '%s'\n", token, shader.name );
continue;
}
}
//
// tcGen <function>
//
else if ( !Q_stricmp( token, "texgen" ) || !Q_stricmp( token, "tcGen" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing texgen parm in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "environment" ) ) {
stage->bundle[0].tcGen = TCGEN_ENVIRONMENT_MAPPED;
} else if ( !Q_stricmp( token, "firerisenv" ) ) {
stage->bundle[0].tcGen = TCGEN_FIRERISEENV_MAPPED;
} else if ( !Q_stricmp( token, "lightmap" ) ) {
stage->bundle[0].tcGen = TCGEN_LIGHTMAP;
} else if ( !Q_stricmp( token, "texture" ) || !Q_stricmp( token, "base" ) ) {
stage->bundle[0].tcGen = TCGEN_TEXTURE;
} else if ( !Q_stricmp( token, "vector" ) ) {
ParseVector( text, 3, stage->bundle[0].tcGenVectors[0] );
ParseVector( text, 3, stage->bundle[0].tcGenVectors[1] );
stage->bundle[0].tcGen = TCGEN_VECTOR;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown texgen parm in shader '%s'\n", shader.name );
}
}
//
// tcMod <type> <...>
//
else if ( !Q_stricmp( token, "tcMod" ) ) {
char buffer[1024] = "";
while ( 1 )
{
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
break;
}
Q_strcat( buffer, sizeof (buffer), token );
Q_strcat( buffer, sizeof (buffer), " " );
}
ParseTexMod( buffer, stage );
continue;
}
//
// depthmask
//
else if ( !Q_stricmp( token, "depthwrite" ) ) {
depthMaskBits = GLS_DEPTHMASK_TRUE;
depthMaskExplicit = qtrue;
continue;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown parameter '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
}
//
// if cgen isn't explicitly specified, use either identity or identitylighting
//
if ( stage->rgbGen == CGEN_BAD ) {
if ( blendSrcBits == 0 ||
blendSrcBits == GLS_SRCBLEND_ONE ||
blendSrcBits == GLS_SRCBLEND_SRC_ALPHA ) {
stage->rgbGen = CGEN_IDENTITY_LIGHTING;
} else {
stage->rgbGen = CGEN_IDENTITY;
}
}
// allow crosshairs to be colorized for cg_crosshairHealth
if ( strstr( shader.name, "crosshair" ) && shader.lightmapIndex == LIGHTMAP_2D ) {
if ( stage->rgbGen == CGEN_IDENTITY || stage->rgbGen == CGEN_IDENTITY_LIGHTING ) {
stage->rgbGen = CGEN_VERTEX;
}
}
//
// implicitly assume that a GL_ONE GL_ZERO blend mask disables blending
//
if ( ( blendSrcBits == GLS_SRCBLEND_ONE ) &&
( blendDstBits == GLS_DSTBLEND_ZERO ) ) {
blendDstBits = blendSrcBits = 0;
depthMaskBits = GLS_DEPTHMASK_TRUE;
}
// decide which agens we can skip
if ( stage->alphaGen == AGEN_IDENTITY ) {
if ( stage->rgbGen == CGEN_IDENTITY
|| stage->rgbGen == CGEN_LIGHTING_DIFFUSE ) {
stage->alphaGen = AGEN_SKIP;
}
}
//
// compute state bits
//
stage->stateBits = depthMaskBits |
blendSrcBits | blendDstBits |
atestBits |
depthFuncBits;
return qtrue;
}
/*
===============
ParseDeform
deformVertexes wave <spread> <waveform> <base> <amplitude> <phase> <frequency>
deformVertexes normal <frequency> <amplitude>
deformVertexes move <vector> <waveform> <base> <amplitude> <phase> <frequency>
deformVertexes bulge <bulgeWidth> <bulgeHeight> <bulgeSpeed>
deformVertexes projectionShadow
deformVertexes autoSprite
deformVertexes autoSprite2
deformVertexes text[0-7]
===============
*/
static void ParseDeform( char **text ) {
char *token;
deformStage_t *ds;
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deform parm in shader '%s'\n", shader.name );
return;
}
if ( shader.numDeforms == MAX_SHADER_DEFORMS ) {
ri.Printf( PRINT_WARNING, "WARNING: MAX_SHADER_DEFORMS in '%s'\n", shader.name );
return;
}
ds = &shader.deforms[ shader.numDeforms ];
shader.numDeforms++;
if ( !Q_stricmp( token, "projectionShadow" ) ) {
ds->deformation = DEFORM_PROJECTION_SHADOW;
return;
}
if ( !Q_stricmp( token, "autosprite" ) ) {
ds->deformation = DEFORM_AUTOSPRITE;
return;
}
if ( !Q_stricmp( token, "autosprite2" ) ) {
ds->deformation = DEFORM_AUTOSPRITE2;
return;
}
if ( !Q_stricmpn( token, "text", 4 ) ) {
int n;
n = token[4] - '0';
if ( n < 0 || n > 7 ) {
n = 0;
}
ds->deformation = DEFORM_TEXT0 + n;
return;
}
if ( !Q_stricmp( token, "bulge" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes bulge parm in shader '%s'\n", shader.name );
return;
}
ds->bulgeWidth = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes bulge parm in shader '%s'\n", shader.name );
return;
}
ds->bulgeHeight = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes bulge parm in shader '%s'\n", shader.name );
return;
}
ds->bulgeSpeed = atof( token );
ds->deformation = DEFORM_BULGE;
return;
}
if ( !Q_stricmp( token, "wave" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes parm in shader '%s'\n", shader.name );
return;
}
if ( atof( token ) != 0 ) {
ds->deformationSpread = 1.0f / atof( token );
} else
{
ds->deformationSpread = 100.0f;
ri.Printf( PRINT_WARNING, "WARNING: illegal div value of 0 in deformVertexes command for shader '%s'\n", shader.name );
}
ParseWaveForm( text, &ds->deformationWave );
ds->deformation = DEFORM_WAVE;
return;
}
if ( !Q_stricmp( token, "normal" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes parm in shader '%s'\n", shader.name );
return;
}
ds->deformationWave.amplitude = atof( token );
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes parm in shader '%s'\n", shader.name );
return;
}
ds->deformationWave.frequency = atof( token );
ds->deformation = DEFORM_NORMALS;
return;
}
if ( !Q_stricmp( token, "move" ) ) {
int i;
for ( i = 0 ; i < 3 ; i++ ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing deformVertexes parm in shader '%s'\n", shader.name );
return;
}
ds->moveVector[i] = atof( token );
}
ParseWaveForm( text, &ds->deformationWave );
ds->deformation = DEFORM_MOVE;
return;
}
ri.Printf( PRINT_WARNING, "WARNING: unknown deformVertexes subtype '%s' found in shader '%s'\n", token, shader.name );
}
/*
===============
ParseSkyParms
skyParms <outerbox> <cloudheight> <innerbox>
===============
*/
static void ParseSkyParms( char **text ) {
char *token;
static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
char pathname[MAX_QPATH];
int i;
imgFlags_t imgFlags = IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
// outerbox
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: 'skyParms' missing parameter in shader '%s'\n", shader.name );
return;
}
if ( strcmp( token, "-" ) ) {
for ( i = 0 ; i < 6 ; i++ ) {
Com_sprintf( pathname, sizeof( pathname ), "%s_%s.tga"
, token, suf[i] );
shader.sky.outerbox[i] = R_FindImageFile( ( char * ) pathname, IMGTYPE_COLORALPHA, imgFlags | IMGFLAG_CLAMPTOEDGE );
if ( !shader.sky.outerbox[i] ) {
shader.sky.outerbox[i] = tr.defaultImage;
}
}
}
// cloudheight
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: 'skyParms' missing parameter in shader '%s'\n", shader.name );
return;
}
shader.sky.cloudHeight = atof( token );
if ( !shader.sky.cloudHeight ) {
shader.sky.cloudHeight = 512;
}
R_InitSkyTexCoords( shader.sky.cloudHeight );
// innerbox
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: 'skyParms' missing parameter in shader '%s'\n", shader.name );
return;
}
if ( strcmp( token, "-" ) ) {
for ( i = 0 ; i < 6 ; i++ ) {
Com_sprintf( pathname, sizeof( pathname ), "%s_%s.tga"
, token, suf[i] );
shader.sky.innerbox[i] = R_FindImageFile( ( char * ) pathname, IMGTYPE_COLORALPHA, imgFlags );
if ( !shader.sky.innerbox[i] ) {
shader.sky.innerbox[i] = tr.defaultImage;
}
}
}
shader.isSky = qtrue;
}
/*
=================
ParseSort
=================
*/
void ParseSort( char **text ) {
char *token;
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing sort parameter in shader '%s'\n", shader.name );
return;
}
if ( !Q_stricmp( token, "portal" ) ) {
shader.sort = SS_PORTAL;
} else if ( !Q_stricmp( token, "sky" ) ) {
shader.sort = SS_ENVIRONMENT;
} else if ( !Q_stricmp( token, "opaque" ) ) {
shader.sort = SS_OPAQUE;
} else if ( !Q_stricmp( token, "decal" ) ) {
shader.sort = SS_DECAL;
} else if ( !Q_stricmp( token, "seeThrough" ) ) {
shader.sort = SS_SEE_THROUGH;
} else if ( !Q_stricmp( token, "banner" ) ) {
shader.sort = SS_BANNER;
} else if ( !Q_stricmp( token, "additive" ) ) {
shader.sort = SS_BLEND1;
} else if ( !Q_stricmp( token, "nearest" ) ) {
shader.sort = SS_NEAREST;
} else if ( !Q_stricmp( token, "underwater" ) ) {
shader.sort = SS_UNDERWATER;
} else {
shader.sort = atof( token );
}
}
// this table is also present in q3map
typedef struct {
char *name;
int clearSolid, surfaceFlags, contents;
} infoParm_t;
infoParm_t infoParms[] = {
// server relevant contents
//----(SA) modified
{"clipmissile", 1, 0, CONTENTS_MISSILECLIP}, // impact only specific weapons (rl, gl)
//----(SA) end
{"water", 1, 0, CONTENTS_WATER },
{"slag", 1, 0, CONTENTS_SLIME }, // uses the CONTENTS_SLIME flag, but the shader reference is changed to 'slag'
// to idendify that this doesn't work the same as 'slime' did.
// (slime hurts instantly, slag doesn't)
// {"slime", 1, 0, CONTENTS_SLIME }, // mildly damaging
{"lava", 1, 0, CONTENTS_LAVA }, // very damaging
{"playerclip", 1, 0, CONTENTS_PLAYERCLIP },
{"monsterclip", 1, 0, CONTENTS_MONSTERCLIP },
{"nodrop", 1, 0, CONTENTS_NODROP }, // don't drop items or leave bodies (death fog, lava, etc)
{"nonsolid", 1, SURF_NONSOLID, 0}, // clears the solid flag
// utility relevant attributes
{"origin", 1, 0, CONTENTS_ORIGIN }, // center of rotating brushes
{"trans", 0, 0, CONTENTS_TRANSLUCENT }, // don't eat contained surfaces
{"detail", 0, 0, CONTENTS_DETAIL }, // don't include in structural bsp
{"structural", 0, 0, CONTENTS_STRUCTURAL }, // force into structural bsp even if trnas
{"areaportal", 1, 0, CONTENTS_AREAPORTAL }, // divides areas
{"clusterportal", 1,0, CONTENTS_CLUSTERPORTAL }, // for bots
{"donotenter", 1, 0, CONTENTS_DONOTENTER }, // for bots
// Rafael - nopass
{"donotenterlarge", 1, 0, CONTENTS_DONOTENTER_LARGE }, // for larger bots
{"fog", 1, 0, CONTENTS_FOG}, // carves surfaces entering
{"sky", 0, SURF_SKY, 0 }, // emit light from an environment map
{"lightfilter", 0, SURF_LIGHTFILTER, 0 }, // filter light going through it
{"alphashadow", 0, SURF_ALPHASHADOW, 0 }, // test light on a per-pixel basis
{"hint", 0, SURF_HINT, 0 }, // use as a primary splitter
// server attributes
{"slick", 0, SURF_SLICK, 0 },
{"noimpact", 0, SURF_NOIMPACT, 0 }, // don't make impact explosions or marks
{"nomarks", 0, SURF_NOMARKS, 0 }, // don't make impact marks, but still explode
{"ladder", 0, SURF_LADDER, 0 },
{"nodamage", 0, SURF_NODAMAGE, 0 },
{"monsterslick", 0, SURF_MONSTERSLICK, 0}, // surf only slick for monsters
// {"flesh", 0, SURF_FLESH, 0 },
{"glass", 0, SURF_GLASS, 0 }, //----(SA) added
{"ceramic", 0, SURF_CERAMIC, 0 }, //----(SA) added
// steps
{"metal", 0, SURF_METAL, 0 },
{"metalsteps", 0, SURF_METAL, 0 }, // retain bw compatibility with Q3A metal shaders... (SA)
{"nosteps", 0, SURF_NOSTEPS, 0 },
{"woodsteps", 0, SURF_WOOD, 0 },
{"grasssteps", 0, SURF_GRASS, 0 },
{"gravelsteps", 0, SURF_GRAVEL, 0 },
{"carpetsteps", 0, SURF_CARPET, 0 },
{"snowsteps", 0, SURF_SNOW, 0 },
{"roofsteps", 0, SURF_ROOF, 0 }, // tile roof
{"rubble", 0, SURF_RUBBLE, 0 },
// drawsurf attributes
{"nodraw", 0, SURF_NODRAW, 0 }, // don't generate a drawsurface (or a lightmap)
{"pointlight", 0, SURF_POINTLIGHT, 0 }, // sample lighting at vertexes
{"nolightmap", 0, SURF_NOLIGHTMAP,0 }, // don't generate a lightmap
{"nodlight", 0, SURF_NODLIGHT, 0 }, // don't ever add dynamic lights
{"monsterslicknorth", 0, SURF_MONSLICK_N,0},
{"monsterslickeast", 0, SURF_MONSLICK_E,0},
{"monsterslicksouth", 0, SURF_MONSLICK_S,0},
{"monsterslickwest", 0, SURF_MONSLICK_W,0}
};
/*
===============
ParseSurfaceParm
surfaceparm <name>
===============
*/
static void ParseSurfaceParm( char **text ) {
char *token;
int numInfoParms = ARRAY_LEN( infoParms );
int i;
token = COM_ParseExt( text, qfalse );
for ( i = 0 ; i < numInfoParms ; i++ ) {
if ( !Q_stricmp( token, infoParms[i].name ) ) {
shader.surfaceFlags |= infoParms[i].surfaceFlags;
shader.contentFlags |= infoParms[i].contents;
#if 0
if ( infoParms[i].clearSolid ) {
si->contents &= ~CONTENTS_SOLID;
}
#endif
break;
}
}
}
/*
=================
ParseShader
The current text pointer is at the explicit text definition of the
shader. Parse it into the global shader variable. Later functions
will optimize it.
=================
*/
static qboolean ParseShader( char **text ) {
char *token;
int s;
s = 0;
token = COM_ParseExt( text, qtrue );
if ( token[0] != '{' ) {
ri.Printf( PRINT_WARNING, "WARNING: expecting '{', found '%s' instead in shader '%s'\n", token, shader.name );
return qfalse;
}
while ( 1 )
{
token = COM_ParseExt( text, qtrue );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: no concluding '}' in shader %s\n", shader.name );
return qfalse;
}
// end of shader definition
if ( token[0] == '}' ) {
break;
}
// stage definition
else if ( token[0] == '{' ) {
if ( s >= MAX_SHADER_STAGES ) {
ri.Printf( PRINT_WARNING, "WARNING: too many stages in shader %s (max is %i)\n", shader.name, MAX_SHADER_STAGES );
return qfalse;
}
if ( !ParseStage( &stages[s], text ) ) {
return qfalse;
}
stages[s].active = qtrue;
s++;
continue;
}
// skip stuff that only the QuakeEdRadient needs
else if ( !Q_stricmpn( token, "qer", 3 ) ) {
SkipRestOfLine( text );
continue;
}
// sun parms
else if ( !Q_stricmp( token, "q3map_sun" ) || !Q_stricmp( token, "q3map_sunExt" ) ) {
float a, b;
token = COM_ParseExt( text, qfalse );
tr.sunLight[0] = atof( token );
token = COM_ParseExt( text, qfalse );
tr.sunLight[1] = atof( token );
token = COM_ParseExt( text, qfalse );
tr.sunLight[2] = atof( token );
VectorNormalize( tr.sunLight );
token = COM_ParseExt( text, qfalse );
a = atof( token );
VectorScale( tr.sunLight, a, tr.sunLight );
token = COM_ParseExt( text, qfalse );
a = atof( token );
a = a / 180 * M_PI;
token = COM_ParseExt( text, qfalse );
b = atof( token );
b = b / 180 * M_PI;
tr.sunDirection[0] = cos( a ) * cos( b );
tr.sunDirection[1] = sin( a ) * cos( b );
tr.sunDirection[2] = sin( b );
SkipRestOfLine( text );
continue;
} else if ( !Q_stricmp( token, "deformVertexes" ) ) {
ParseDeform( text );
continue;
} else if ( !Q_stricmp( token, "tesssize" ) ) {
SkipRestOfLine( text );
continue;
} else if ( !Q_stricmp( token, "clampTime" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] ) {
shader.clampTime = atof( token );
}
}
// skip stuff that only the q3map needs
else if ( !Q_stricmpn( token, "q3map", 5 ) ) {
SkipRestOfLine( text );
continue;
}
// skip stuff that only q3map or the server needs
else if ( !Q_stricmp( token, "surfaceParm" ) ) {
ParseSurfaceParm( text );
continue;
}
// no mip maps
else if ( ( !Q_stricmp( token, "nomipmaps" ) ) || ( !Q_stricmp( token,"nomipmap" ) ) ) {
shader.noMipMaps = qtrue;
shader.noPicMip = qtrue;
continue;
}
// no picmip adjustment
else if ( !Q_stricmp( token, "nopicmip" ) ) {
shader.noPicMip = qtrue;
continue;
}
// polygonOffset
else if ( !Q_stricmp( token, "polygonOffset" ) ) {
shader.polygonOffset = qtrue;
continue;
}
// entityMergable, allowing sprite surfaces from multiple entities
// to be merged into one batch. This is a savings for smoke
// puffs and blood, but can't be used for anything where the
// shader calcs (not the surface function) reference the entity color or scroll
else if ( !Q_stricmp( token, "entityMergable" ) ) {
shader.entityMergable = qtrue;
continue;
}
// fogParms
else if ( !Q_stricmp( token, "fogParms" ) ) {
if ( !ParseVector( text, 3, shader.fogParms.color ) ) {
return qfalse;
}
if ( r_greyscale->integer )
{
float luminance;
luminance = LUMA( shader.fogParms.color[0], shader.fogParms.color[1], shader.fogParms.color[2] );
VectorSet( shader.fogParms.color, luminance, luminance, luminance );
}
else if ( r_greyscale->value )
{
float luminance;
luminance = LUMA( shader.fogParms.color[0], shader.fogParms.color[1], shader.fogParms.color[2] );
shader.fogParms.color[0] = LERP( shader.fogParms.color[0], luminance, r_greyscale->value );
shader.fogParms.color[1] = LERP( shader.fogParms.color[1], luminance, r_greyscale->value );
shader.fogParms.color[2] = LERP( shader.fogParms.color[2], luminance, r_greyscale->value );
}
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing parm for 'fogParms' keyword in shader '%s'\n", shader.name );
continue;
}
shader.fogParms.depthForOpaque = atof( token );
// skip any old gradient directions
SkipRestOfLine( text );
continue;
}
// portal
else if ( !Q_stricmp( token, "portal" ) ) {
shader.sort = SS_PORTAL;
continue;
}
// skyparms <cloudheight> <outerbox> <innerbox>
else if ( !Q_stricmp( token, "skyparms" ) ) {
ParseSkyParms( text );
continue;
}
// This is fixed fog for the skybox/clouds determined solely by the shader
// it will not change in a level and will not be necessary
// to force clients to use a sky fog the server says to.
// skyfogvars <(r,g,b)> <dist>
else if ( !Q_stricmp( token, "skyfogvars" ) ) {
vec3_t fogColor;
if ( !ParseVector( text, 3, fogColor ) ) {
return qfalse;
}
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing density value for sky fog\n" );
continue;
}
if ( atof( token ) > 1 ) {
ri.Printf( PRINT_WARNING, "WARNING: last value for skyfogvars is 'density' which needs to be 0.0-1.0\n" );
continue;
}
R_SetFog( FOG_SKY, 0, 5, fogColor[0], fogColor[1], fogColor[2], atof( token ) );
continue;
} else if ( !Q_stricmp( token, "sunshader" ) ) {
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing shader name for 'sunshader'\n" );
continue;
}
// tr.sunShaderName = CopyString( token );
tr.sunShaderName = "sun";
}
//----(SA) added
else if ( !Q_stricmp( token, "lightgridmulamb" ) ) { // ambient multiplier for lightgrid
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing value for 'lightgrid ambient multiplier'\n" );
continue;
}
if ( atof( token ) > 0 ) {
tr.lightGridMulAmbient = atof( token );
}
} else if ( !Q_stricmp( token, "lightgridmuldir" ) ) { // directional multiplier for lightgrid
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing value for 'lightgrid directional multiplier'\n" );
continue;
}
if ( atof( token ) > 0 ) {
tr.lightGridMulDirected = atof( token );
}
}
//----(SA) end
else if ( !Q_stricmp( token, "waterfogvars" ) ) {
vec3_t watercolor;
float fogvar;
if ( !ParseVector( text, 3, watercolor ) ) {
return qfalse;
}
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing density/distance value for water fog\n" );
continue;
}
fogvar = atof( token );
//----(SA) right now allow one water color per map. I'm sure this will need
// to change at some point, but I'm not sure how to track fog parameters
// on a "per-water volume" basis yet.
if ( fogvar == 0 ) { // '0' specifies "use the map values for everything except the fog color
// TODO
} else if ( fogvar > 1 ) { // distance "linear" fog
R_SetFog( FOG_WATER, 0, fogvar, watercolor[0], watercolor[1], watercolor[2], 1.1 );
} else { // density "exp" fog
R_SetFog( FOG_WATER, 0, 5, watercolor[0], watercolor[1], watercolor[2], fogvar );
}
continue;
}
// fogvars
else if ( !Q_stricmp( token, "fogvars" ) ) {
vec3_t fogColor;
float fogDensity;
int fogFar;
if ( !ParseVector( text, 3, fogColor ) ) {
return qfalse;
}
token = COM_ParseExt( text, qfalse );
if ( !token[0] ) {
ri.Printf( PRINT_WARNING, "WARNING: missing density value for the fog\n" );
continue;
}
//----(SA) NOTE: fogFar > 1 means the shader is setting the farclip, < 1 means setting
// density (so old maps or maps that just need softening fog don't have to care about farclip)
fogDensity = atof( token );
if ( fogDensity > 1 ) { // linear
fogFar = fogDensity;
} else {
fogFar = 5;
}
R_SetFog( FOG_MAP, 0, fogFar, fogColor[0], fogColor[1], fogColor[2], fogDensity );
R_SetFog( FOG_CMD_SWITCHFOG, FOG_MAP, 50, 0, 0, 0, 0 );
continue;
}
// done.
// Ridah, allow disable fog for some shaders
else if ( !Q_stricmp( token, "nofog" ) ) {
shader.noFog = qtrue;
continue;
}
// done.
// RF, allow each shader to permit compression if available
else if ( !Q_stricmp( token, "allowcompress" ) ) {
tr.allowCompress = qtrue;
continue;
} else if ( !Q_stricmp( token, "nocompress" ) ) {
tr.allowCompress = -1;
continue;
}
// done.
// light <value> determines flaring in q3map, not needed here
else if ( !Q_stricmp( token, "light" ) ) {
COM_ParseExt( text, qfalse );
continue;
}
// cull <face>
else if ( !Q_stricmp( token, "cull" ) ) {
token = COM_ParseExt( text, qfalse );
if ( token[0] == 0 ) {
ri.Printf( PRINT_WARNING, "WARNING: missing cull parms in shader '%s'\n", shader.name );
continue;
}
if ( !Q_stricmp( token, "none" ) || !Q_stricmp( token, "twosided" ) || !Q_stricmp( token, "disable" ) ) {
shader.cullType = CT_TWO_SIDED;
} else if ( !Q_stricmp( token, "back" ) || !Q_stricmp( token, "backside" ) || !Q_stricmp( token, "backsided" ) ) {
shader.cullType = CT_BACK_SIDED;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: invalid cull parm '%s' in shader '%s'\n", token, shader.name );
}
continue;
}
// sort
else if ( !Q_stricmp( token, "sort" ) ) {
ParseSort( text );
continue;
} else
{
ri.Printf( PRINT_WARNING, "WARNING: unknown general shader parameter '%s' in '%s'\n", token, shader.name );
return qfalse;
}
}
//
// ignore shaders that don't have any stages, unless it is a sky or fog
//
if ( s == 0 && !shader.isSky && !( shader.contentFlags & CONTENTS_FOG ) ) {
return qfalse;
}
shader.explicitlyDefined = qtrue;
return qtrue;
}
/*
========================================================================================
SHADER OPTIMIZATION AND FOGGING
========================================================================================
*/
/*
===================
ComputeStageIteratorFunc
See if we can use on of the simple fastpath stage functions,
otherwise set to the generic stage function
===================
*/
static void ComputeStageIteratorFunc( void ) {
shader.optimalStageIteratorFunc = RB_StageIteratorGeneric;
//
// see if this should go into the sky path
//
if ( shader.isSky ) {
shader.optimalStageIteratorFunc = RB_StageIteratorSky;
return;
}
if ( r_ignoreFastPath->integer ) {
return;
}
//
// see if this can go into the vertex lit fast path
//
if ( shader.numUnfoggedPasses == 1 ) {
if ( stages[0].rgbGen == CGEN_LIGHTING_DIFFUSE ) {
if ( stages[0].alphaGen == AGEN_IDENTITY ) {
if ( stages[0].bundle[0].tcGen == TCGEN_TEXTURE ) {
if ( !shader.polygonOffset ) {
if ( !shader.multitextureEnv ) {
if ( !shader.numDeforms ) {
shader.optimalStageIteratorFunc = RB_StageIteratorVertexLitTexture;
return;
}
}
}
}
}
}
}
//
// see if this can go into an optimized LM, multitextured path
//
if ( shader.numUnfoggedPasses == 1 ) {
if ( ( stages[0].rgbGen == CGEN_IDENTITY ) && ( stages[0].alphaGen == AGEN_IDENTITY ) ) {
if ( stages[0].bundle[0].tcGen == TCGEN_TEXTURE &&
stages[0].bundle[1].tcGen == TCGEN_LIGHTMAP ) {
if ( !shader.polygonOffset ) {
if ( !shader.numDeforms ) {
if ( shader.multitextureEnv ) {
shader.optimalStageIteratorFunc = RB_StageIteratorLightmappedMultitexture;
}
}
}
}
}
}
}
typedef struct {
int blendA;
int blendB;
int multitextureEnv;
int multitextureBlend;
} collapse_t;
static collapse_t collapse[] = {
{ 0, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
GL_MODULATE, 0 },
{ 0, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
GL_MODULATE, 0 },
{ GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
{ GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR,
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
{ GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
{ GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO, GLS_DSTBLEND_SRC_COLOR | GLS_SRCBLEND_ZERO,
GL_MODULATE, GLS_DSTBLEND_ZERO | GLS_SRCBLEND_DST_COLOR },
{ 0, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE,
GL_ADD, 0 },
{ GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE,
GL_ADD, GLS_DSTBLEND_ONE | GLS_SRCBLEND_ONE },
#if 0
{ 0, GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_SRCBLEND_SRC_ALPHA,
GL_DECAL, 0 },
#endif
{ -1 }
};
/*
================
CollapseMultitexture
Attempt to combine two stages into a single multitexture stage
FIXME: I think modulated add + modulated add collapses incorrectly
=================
*/
static qboolean CollapseMultitexture( void ) {
int abits, bbits;
int i;
textureBundle_t tmpBundle;
if ( !qglActiveTextureARB ) {
return qfalse;
}
// make sure both stages are active
if ( !stages[0].active || !stages[1].active ) {
return qfalse;
}
// on voodoo2, don't combine different tmus
if ( glConfig.driverType == GLDRV_VOODOO ) {
if ( stages[0].bundle[0].image[0]->TMU ==
stages[1].bundle[0].image[0]->TMU ) {
return qfalse;
}
}
abits = stages[0].stateBits;
bbits = stages[1].stateBits;
// make sure that both stages have identical state other than blend modes
if ( ( abits & ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS | GLS_DEPTHMASK_TRUE ) ) !=
( bbits & ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS | GLS_DEPTHMASK_TRUE ) ) ) {
return qfalse;
}
abits &= ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
bbits &= ( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
// search for a valid multitexture blend function
for ( i = 0; collapse[i].blendA != -1 ; i++ ) {
if ( abits == collapse[i].blendA
&& bbits == collapse[i].blendB ) {
break;
}
}
// nothing found
if ( collapse[i].blendA == -1 ) {
return qfalse;
}
// GL_ADD is a separate extension
if ( collapse[i].multitextureEnv == GL_ADD && !glConfig.textureEnvAddAvailable ) {
return qfalse;
}
// make sure waveforms have identical parameters
if ( ( stages[0].rgbGen != stages[1].rgbGen ) ||
( stages[0].alphaGen != stages[1].alphaGen ) ) {
return qfalse;
}
// an add collapse can only have identity colors
if ( collapse[i].multitextureEnv == GL_ADD && stages[0].rgbGen != CGEN_IDENTITY ) {
return qfalse;
}
if ( stages[0].rgbGen == CGEN_WAVEFORM ) {
if ( memcmp( &stages[0].rgbWave,
&stages[1].rgbWave,
sizeof( stages[0].rgbWave ) ) ) {
return qfalse;
}
}
if ( stages[0].alphaGen == AGEN_WAVEFORM ) {
if ( memcmp( &stages[0].alphaWave,
&stages[1].alphaWave,
sizeof( stages[0].alphaWave ) ) ) {
return qfalse;
}
}
// make sure that lightmaps are in bundle 1 for 3dfx
if ( stages[0].bundle[0].isLightmap ) {
tmpBundle = stages[0].bundle[0];
stages[0].bundle[0] = stages[1].bundle[0];
stages[0].bundle[1] = tmpBundle;
} else
{
stages[0].bundle[1] = stages[1].bundle[0];
}
// set the new blend state bits
shader.multitextureEnv = collapse[i].multitextureEnv;
stages[0].stateBits &= ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
stages[0].stateBits |= collapse[i].multitextureBlend;
//
// move down subsequent shaders
//
memmove( &stages[1], &stages[2], sizeof( stages[0] ) * ( MAX_SHADER_STAGES - 2 ) );
memset( &stages[MAX_SHADER_STAGES - 1], 0, sizeof( stages[0] ) );
return qtrue;
}
/*
=============
FixRenderCommandList
Arnout: this is a nasty issue. Shaders can be registered after drawsurfaces are generated
but before the frame is rendered. This will, for the duration of one frame, cause drawsurfaces
to be rendered with bad shaders. To fix this, need to go through all render commands and fix
sortedIndex.
==============
*/
static void FixRenderCommandList( int newShader ) {
renderCommandList_t *cmdList = &backEndData->commands;
if ( cmdList ) {
const void *curCmd = cmdList->cmds;
while ( 1 ) {
curCmd = PADP(curCmd, sizeof(void *));
switch ( *(const int *)curCmd ) {
case RC_SET_COLOR:
{
const setColorCommand_t *sc_cmd = (const setColorCommand_t *)curCmd;
curCmd = (const void *)( sc_cmd + 1 );
break;
}
case RC_STRETCH_PIC:
case RC_ROTATED_PIC:
case RC_STRETCH_PIC_GRADIENT:
{
const stretchPicCommand_t *sp_cmd = (const stretchPicCommand_t *)curCmd;
curCmd = (const void *)( sp_cmd + 1 );
break;
}
case RC_DRAW_SURFS:
{
int i;
drawSurf_t *drawSurf;
shader_t *shader;
int fogNum;
int entityNum;
int dlightMap;
int sortedIndex;
const drawSurfsCommand_t *ds_cmd = (const drawSurfsCommand_t *)curCmd;
for ( i = 0, drawSurf = ds_cmd->drawSurfs; i < ds_cmd->numDrawSurfs; i++, drawSurf++ ) {
R_DecomposeSort( drawSurf->sort, &entityNum, &shader, &fogNum, &dlightMap );
sortedIndex = ( ( drawSurf->sort >> QSORT_SHADERNUM_SHIFT ) & ( MAX_SHADERS - 1 ) );
if ( sortedIndex >= newShader ) {
sortedIndex++;
drawSurf->sort = ( sortedIndex << QSORT_SHADERNUM_SHIFT ) | entityNum | ( fogNum << QSORT_FOGNUM_SHIFT ) | (int)dlightMap;
}
}
curCmd = (const void *)( ds_cmd + 1 );
break;
}
case RC_DRAW_BUFFER:
{
const drawBufferCommand_t *db_cmd = (const drawBufferCommand_t *)curCmd;
curCmd = (const void *)( db_cmd + 1 );
break;
}
case RC_SWAP_BUFFERS:
{
const swapBuffersCommand_t *sb_cmd = (const swapBuffersCommand_t *)curCmd;
curCmd = (const void *)( sb_cmd + 1 );
break;
}
case RC_END_OF_LIST:
default:
return;
}
}
}
}
/*
==============
SortNewShader
Positions the most recently created shader in the tr.sortedShaders[]
array so that the shader->sort key is sorted relative to the other
shaders.
Sets shader->sortedIndex
==============
*/
static void SortNewShader( void ) {
int i;
float sort;
shader_t *newShader;
newShader = tr.shaders[ tr.numShaders - 1 ];
sort = newShader->sort;
for ( i = tr.numShaders - 2 ; i >= 0 ; i-- ) {
if ( tr.sortedShaders[ i ]->sort <= sort ) {
break;
}
tr.sortedShaders[i + 1] = tr.sortedShaders[i];
tr.sortedShaders[i + 1]->sortedIndex++;
}
// Arnout: fix rendercommandlist
FixRenderCommandList( i + 1 );
newShader->sortedIndex = i + 1;
tr.sortedShaders[i + 1] = newShader;
}
/*
====================
GeneratePermanentShader
====================
*/
static shader_t *GeneratePermanentShader( void ) {
shader_t *newShader;
int i, b;
int size, hash;
if ( tr.numShaders == MAX_SHADERS ) {
ri.Printf( PRINT_WARNING, "WARNING: GeneratePermanentShader - MAX_SHADERS hit\n" );
return tr.defaultShader;
}
newShader = ri.Hunk_Alloc( sizeof( shader_t ), h_low );
*newShader = shader;
if ( shader.sort <= SS_OPAQUE ) {
newShader->fogPass = FP_EQUAL;
} else if ( shader.contentFlags & CONTENTS_FOG ) {
newShader->fogPass = FP_LE;
}
tr.shaders[ tr.numShaders ] = newShader;
newShader->index = tr.numShaders;
tr.sortedShaders[ tr.numShaders ] = newShader;
newShader->sortedIndex = tr.numShaders;
tr.numShaders++;
for ( i = 0 ; i < newShader->numUnfoggedPasses ; i++ ) {
if ( !stages[i].active ) {
newShader->stages[i] = NULL; // Ridah, make sure it's null
break;
}
newShader->stages[i] = ri.Hunk_Alloc( sizeof( stages[i] ), h_low );
*newShader->stages[i] = stages[i];
for ( b = 0 ; b < NUM_TEXTURE_BUNDLES ; b++ ) {
if ( !newShader->stages[i]->bundle[b].numTexMods ) {
// make sure unalloc'd texMods aren't pointing to some random point in memory
newShader->stages[i]->bundle[b].texMods = NULL;
continue;
}
size = newShader->stages[i]->bundle[b].numTexMods * sizeof( texModInfo_t );
newShader->stages[i]->bundle[b].texMods = ri.Hunk_Alloc( size, h_low );
Com_Memcpy( newShader->stages[i]->bundle[b].texMods, stages[i].bundle[b].texMods, size );
}
}
SortNewShader();
hash = generateHashValue( newShader->name );
newShader->next = hashTable[hash];
hashTable[hash] = newShader;
return newShader;
}
/*
=================
VertexLightingCollapse
If vertex lighting is enabled, only render a single
pass, trying to guess which is the correct one to best aproximate
what it is supposed to look like.
=================
*/
static void VertexLightingCollapse( void ) {
int stage;
shaderStage_t *bestStage;
int bestImageRank;
int rank;
// if we aren't opaque, just use the first pass
if ( shader.sort == SS_OPAQUE ) {
// pick the best texture for the single pass
bestStage = &stages[0];
bestImageRank = -999999;
for ( stage = 0; stage < MAX_SHADER_STAGES; stage++ ) {
shaderStage_t *pStage = &stages[stage];
if ( !pStage->active ) {
break;
}
rank = 0;
if ( pStage->bundle[0].isLightmap ) {
rank -= 100;
}
if ( pStage->bundle[0].tcGen != TCGEN_TEXTURE ) {
rank -= 5;
}
if ( pStage->bundle[0].numTexMods ) {
rank -= 5;
}
if ( pStage->rgbGen != CGEN_IDENTITY && pStage->rgbGen != CGEN_IDENTITY_LIGHTING ) {
rank -= 3;
}
if ( rank > bestImageRank ) {
bestImageRank = rank;
bestStage = pStage;
}
}
stages[0].bundle[0] = bestStage->bundle[0];
stages[0].stateBits &= ~( GLS_DSTBLEND_BITS | GLS_SRCBLEND_BITS );
stages[0].stateBits |= GLS_DEPTHMASK_TRUE;
if ( shader.lightmapIndex == LIGHTMAP_NONE ) {
stages[0].rgbGen = CGEN_LIGHTING_DIFFUSE;
} else {
stages[0].rgbGen = CGEN_EXACT_VERTEX;
}
stages[0].alphaGen = AGEN_SKIP;
} else {
// don't use a lightmap (tesla coils)
if ( stages[0].bundle[0].isLightmap ) {
stages[0] = stages[1];
}
// if we were in a cross-fade cgen, hack it to normal
if ( stages[0].rgbGen == CGEN_ONE_MINUS_ENTITY || stages[1].rgbGen == CGEN_ONE_MINUS_ENTITY ) {
stages[0].rgbGen = CGEN_IDENTITY_LIGHTING;
}
if ( ( stages[0].rgbGen == CGEN_WAVEFORM && stages[0].rgbWave.func == GF_SAWTOOTH )
&& ( stages[1].rgbGen == CGEN_WAVEFORM && stages[1].rgbWave.func == GF_INVERSE_SAWTOOTH ) ) {
stages[0].rgbGen = CGEN_IDENTITY_LIGHTING;
}
if ( ( stages[0].rgbGen == CGEN_WAVEFORM && stages[0].rgbWave.func == GF_INVERSE_SAWTOOTH )
&& ( stages[1].rgbGen == CGEN_WAVEFORM && stages[1].rgbWave.func == GF_SAWTOOTH ) ) {
stages[0].rgbGen = CGEN_IDENTITY_LIGHTING;
}
}
for ( stage = 1; stage < MAX_SHADER_STAGES; stage++ ) {
shaderStage_t *pStage = &stages[stage];
if ( !pStage->active ) {
break;
}
memset( pStage, 0, sizeof( *pStage ) );
}
}
/*
===============
InitShader
===============
*/
static void InitShader( const char *name, int lightmapIndex ) {
int i;
// clear the global shader
Com_Memset( &shader, 0, sizeof( shader ) );
Com_Memset( &stages, 0, sizeof( stages ) );
Q_strncpyz( shader.name, name, sizeof( shader.name ) );
shader.lightmapIndex = lightmapIndex;
for ( i = 0 ; i < MAX_SHADER_STAGES ; i++ ) {
stages[i].bundle[0].texMods = texMods[i];
}
}
/*
=========================
FinishShader
Returns a freshly allocated shader with all the needed info
from the current global working shader
=========================
*/
static shader_t *FinishShader( void ) {
int stage;
qboolean hasLightmapStage;
qboolean vertexLightmap;
hasLightmapStage = qfalse;
vertexLightmap = qfalse;
//
// set sky stuff appropriate
//
if ( shader.isSky ) {
shader.sort = SS_ENVIRONMENT;
}
//
// set polygon offset
//
if ( shader.polygonOffset && !shader.sort ) {
shader.sort = SS_DECAL;
}
//
// set appropriate stage information
//
for ( stage = 0; stage < MAX_SHADER_STAGES; ) {
shaderStage_t *pStage = &stages[stage];
if ( !pStage->active ) {
break;
}
// check for a missing texture
if ( !pStage->bundle[0].image[0] ) {
ri.Printf( PRINT_WARNING, "Shader %s has a stage with no image\n", shader.name );
pStage->active = qfalse;
stage++;
continue;
}
//
// ditch this stage if it's detail and detail textures are disabled
//
if ( pStage->isDetail && !r_detailTextures->integer )
{
int index;
for(index = stage + 1; index < MAX_SHADER_STAGES; index++)
{
if(!stages[index].active)
break;
}
if(index < MAX_SHADER_STAGES)
memmove(pStage, pStage + 1, sizeof(*pStage) * (index - stage));
else
{
if(stage + 1 < MAX_SHADER_STAGES)
memmove(pStage, pStage + 1, sizeof(*pStage) * (index - stage - 1));
Com_Memset(&stages[index - 1], 0, sizeof(*stages));
}
continue;
}
//
// default texture coordinate generation
//
if ( pStage->bundle[0].isLightmap ) {
if ( pStage->bundle[0].tcGen == TCGEN_BAD ) {
pStage->bundle[0].tcGen = TCGEN_LIGHTMAP;
}
hasLightmapStage = qtrue;
} else {
if ( pStage->bundle[0].tcGen == TCGEN_BAD ) {
pStage->bundle[0].tcGen = TCGEN_TEXTURE;
}
}
// not a true lightmap but we want to leave existing
// behaviour in place and not print out a warning
//if (pStage->rgbGen == CGEN_VERTEX) {
// vertexLightmap = qtrue;
//}
//
// determine sort order and fog color adjustment
//
if ( ( pStage->stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) &&
( stages[0].stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) ) ) {
int blendSrcBits = pStage->stateBits & GLS_SRCBLEND_BITS;
int blendDstBits = pStage->stateBits & GLS_DSTBLEND_BITS;
// fog color adjustment only works for blend modes that have a contribution
// that aproaches 0 as the modulate values aproach 0 --
// GL_ONE, GL_ONE
// GL_ZERO, GL_ONE_MINUS_SRC_COLOR
// GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
// modulate, additive
if ( ( ( blendSrcBits == GLS_SRCBLEND_ONE ) && ( blendDstBits == GLS_DSTBLEND_ONE ) ) ||
( ( blendSrcBits == GLS_SRCBLEND_ZERO ) && ( blendDstBits == GLS_DSTBLEND_ONE_MINUS_SRC_COLOR ) ) ) {
pStage->adjustColorsForFog = ACFF_MODULATE_RGB;
}
// strict blend
else if ( ( blendSrcBits == GLS_SRCBLEND_SRC_ALPHA ) && ( blendDstBits == GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ) ) {
pStage->adjustColorsForFog = ACFF_MODULATE_ALPHA;
}
// premultiplied alpha
else if ( ( blendSrcBits == GLS_SRCBLEND_ONE ) && ( blendDstBits == GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ) ) {
pStage->adjustColorsForFog = ACFF_MODULATE_RGBA;
} else {
// we can't adjust this one correctly, so it won't be exactly correct in fog
}
// don't screw with sort order if this is a portal or environment
if ( !shader.sort ) {
// see through item, like a grill or grate
if ( pStage->stateBits & GLS_DEPTHMASK_TRUE ) {
shader.sort = SS_SEE_THROUGH;
} else {
shader.sort = SS_BLEND0;
}
}
}
stage++;
}
// there are times when you will need to manually apply a sort to
// opaque alpha tested shaders that have later blend passes
if ( !shader.sort ) {
shader.sort = SS_OPAQUE;
}
//
// if we are in r_vertexLight mode, never use a lightmap texture
//
// NERVE - SMF - temp fix, terrain is having problems with lighting collapse
if ( 0 && ( stage > 1 && ( ( r_vertexLight->integer && !r_uiFullScreen->integer ) || glConfig.hardwareType == GLHW_PERMEDIA2 ) ) ) {
VertexLightingCollapse();
stage = 1;
hasLightmapStage = qfalse;
}
//
// look for multitexture potential
//
if ( stage > 1 && CollapseMultitexture() ) {
stage--;
}
if ( shader.lightmapIndex >= 0 && !hasLightmapStage ) {
if ( vertexLightmap ) {
ri.Printf( PRINT_DEVELOPER, "WARNING: shader '%s' has VERTEX forced lightmap!\n", shader.name );
} else {
ri.Printf( PRINT_DEVELOPER, "WARNING: shader '%s' has lightmap but no lightmap stage!\n", shader.name );
shader.lightmapIndex = LIGHTMAP_NONE;
}
}
//
// compute number of passes
//
shader.numUnfoggedPasses = stage;
// fogonly shaders don't have any normal passes
if (stage == 0 && !shader.isSky)
shader.sort = SS_FOG;
// determine which stage iterator function is appropriate
ComputeStageIteratorFunc();
// RF default back to no compression for next shader
if ( r_ext_compressed_textures->integer == 2 ) {
tr.allowCompress = qfalse;
}
return GeneratePermanentShader();
}
//========================================================================================
/*
====================
FindShaderInShaderText
Scans the combined text description of all the shader files for
the given shader name.
return NULL if not found
If found, it will return a valid shader
=====================
*/
static char *FindShaderInShaderText( const char *shadername ) {
char *p = s_shaderText;
char *token;
if ( !p ) {
return NULL;
}
// look for label
// note that this could get confused if a shader name is used inside
// another shader definition
while ( 1 ) {
token = COM_ParseExt( &p, qtrue );
if ( token[0] == 0 ) {
break;
}
if ( token[0] == '{' ) {
// skip the definition
SkipBracedSection( &p, 0 );
} else if ( !Q_stricmp( token, shadername ) ) {
return p;
} else {
// skip to end of line
SkipRestOfLine( &p );
}
}
return NULL;
}
/*
==================
R_FindShaderByName
Will always return a valid shader, but it might be the
default shader if the real one can't be found.
==================
*/
shader_t *R_FindShaderByName( const char *name ) {
char strippedName[MAX_QPATH];
int hash;
shader_t *sh;
if ( ( name == NULL ) || ( name[0] == 0 ) ) {
return tr.defaultShader;
}
COM_StripExtension( name, strippedName, sizeof( strippedName ) );
hash = generateHashValue( strippedName );
//
// see if the shader is already loaded
//
for ( sh = hashTable[hash]; sh; sh = sh->next ) {
// NOTE: if there was no shader or image available with the name strippedName
// then a default shader is created with lightmapIndex == LIGHTMAP_NONE, so we
// have to check all default shaders otherwise for every call to R_FindShader
// with that same strippedName a new default shader is created.
if ( Q_stricmp( sh->name, strippedName ) == 0 ) {
// match found
return sh;
}
}
return tr.defaultShader;
}
/*
===============
R_FindShader
Will always return a valid shader, but it might be the
default shader if the real one can't be found.
In the interest of not requiring an explicit shader text entry to
be defined for every single image used in the game, three default
shader behaviors can be auto-created for any image:
If lightmapIndex == LIGHTMAP_NONE, then the image will have
dynamic diffuse lighting applied to it, as apropriate for most
entity skin surfaces.
If lightmapIndex == LIGHTMAP_2D, then the image will be used
for 2D rendering unless an explicit shader is found
If lightmapIndex == LIGHTMAP_BY_VERTEX, then the image will use
the vertex rgba modulate values, as apropriate for misc_model
pre-lit surfaces.
Other lightmapIndex values will have a lightmap stage created
and src*dest blending applied with the texture, as apropriate for
most world construction surfaces.
===============
*/
shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImage ) {
char strippedName[MAX_QPATH];
int hash;
char *shaderText;
image_t *image;
shader_t *sh;
if ( name[0] == 0 ) {
return tr.defaultShader;
}
// use (fullbright) vertex lighting if the bsp file doesn't have
// lightmaps
if ( lightmapIndex >= 0 && lightmapIndex >= tr.numLightmaps ) {
lightmapIndex = LIGHTMAP_BY_VERTEX;
} else if ( lightmapIndex < LIGHTMAP_2D ) {
// negative lightmap indexes cause stray pointers (think tr.lightmaps[lightmapIndex])
ri.Printf( PRINT_WARNING, "WARNING: shader '%s' has invalid lightmap index of %d\n", name, lightmapIndex );
lightmapIndex = LIGHTMAP_BY_VERTEX;
}
COM_StripExtension( name, strippedName, sizeof( strippedName ) );
hash = generateHashValue( strippedName );
//
// see if the shader is already loaded
//
for ( sh = hashTable[hash]; sh; sh = sh->next ) {
// NOTE: if there was no shader or image available with the name strippedName
// then a default shader is created with lightmapIndex == LIGHTMAP_NONE, so we
// have to check all default shaders otherwise for every call to R_FindShader
// with that same strippedName a new default shader is created.
if ( ( sh->lightmapIndex == lightmapIndex || sh->defaultShader ) &&
!Q_stricmp( sh->name, strippedName ) ) {
// match found
return sh;
}
}
InitShader( strippedName, lightmapIndex );
// FIXME: set these "need" values apropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
shader.needsST2 = qtrue;
shader.needsColor = qtrue;
//
// attempt to define shader from an explicit parameter file
//
shaderText = FindShaderInShaderText( strippedName );
if ( shaderText ) {
// enable this when building a pak file to get a global list
// of all explicit shaders
if ( r_printShaders->integer ) {
ri.Printf( PRINT_ALL, "*SHADER* %s\n", name );
}
if ( !ParseShader( &shaderText ) ) {
// had errors, so use default shader
shader.defaultShader = qtrue;
}
sh = FinishShader();
return sh;
}
//
// if not defined in the in-memory shader descriptions,
// look for a single supported image file
//
{
imgFlags_t flags;
flags = IMGFLAG_NONE;
if (mipRawImage)
{
flags |= IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
}
else
{
flags |= IMGFLAG_CLAMPTOEDGE;
}
image = R_FindImageFile( name, IMGTYPE_COLORALPHA, flags );
if ( !image ) {
ri.Printf( PRINT_DEVELOPER, "Couldn't find image file for shader %s\n", name );
shader.defaultShader = qtrue;
return FinishShader();
}
}
//
// create the default shading commands
//
if ( shader.lightmapIndex == LIGHTMAP_NONE ) {
// dynamic colors at vertexes
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_LIGHTING_DIFFUSE;
stages[0].stateBits = GLS_DEFAULT;
} else if ( shader.lightmapIndex == LIGHTMAP_BY_VERTEX ) {
// explicit colors at vertexes
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_EXACT_VERTEX;
stages[0].alphaGen = AGEN_SKIP;
stages[0].stateBits = GLS_DEFAULT;
} else if ( shader.lightmapIndex == LIGHTMAP_2D ) {
// GUI elements
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_VERTEX;
stages[0].alphaGen = AGEN_VERTEX;
stages[0].stateBits = GLS_DEPTHTEST_DISABLE |
GLS_SRCBLEND_SRC_ALPHA |
GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
} else if ( shader.lightmapIndex == LIGHTMAP_WHITEIMAGE ) {
// fullbright level
stages[0].bundle[0].image[0] = tr.whiteImage;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_IDENTITY_LIGHTING;
stages[0].stateBits = GLS_DEFAULT;
stages[1].bundle[0].image[0] = image;
stages[1].active = qtrue;
stages[1].rgbGen = CGEN_IDENTITY;
stages[1].stateBits |= GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO;
} else {
// two pass lightmap
stages[0].bundle[0].image[0] = tr.lightmaps[shader.lightmapIndex];
stages[0].bundle[0].isLightmap = qtrue;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_IDENTITY; // lightmaps are scaled on creation
// for identitylight
stages[0].stateBits = GLS_DEFAULT;
stages[1].bundle[0].image[0] = image;
stages[1].active = qtrue;
stages[1].rgbGen = CGEN_IDENTITY;
stages[1].stateBits |= GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO;
}
return FinishShader();
}
qhandle_t RE_RegisterShaderFromImage( const char *name, int lightmapIndex, image_t *image, qboolean mipRawImage ) {
int hash;
shader_t *sh;
hash = generateHashValue( name );
// probably not necessary since this function
// only gets called from tr_font.c with lightmapIndex == LIGHTMAP_2D
// but better safe than sorry.
if ( lightmapIndex >= tr.numLightmaps ) {
lightmapIndex = LIGHTMAP_WHITEIMAGE;
}
//
// see if the shader is already loaded
//
for ( sh = hashTable[hash]; sh; sh = sh->next ) {
// NOTE: if there was no shader or image available with the name strippedName
// then a default shader is created with lightmapIndex == LIGHTMAP_NONE, so we
// have to check all default shaders otherwise for every call to R_FindShader
// with that same strippedName a new default shader is created.
if ( ( sh->lightmapIndex == lightmapIndex || sh->defaultShader ) &&
// index by name
!Q_stricmp( sh->name, name ) ) {
// match found
return sh->index;
}
}
InitShader( name, lightmapIndex );
// FIXME: set these "need" values apropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
shader.needsST2 = qtrue;
shader.needsColor = qtrue;
//
// create the default shading commands
//
if ( shader.lightmapIndex == LIGHTMAP_NONE ) {
// dynamic colors at vertexes
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_LIGHTING_DIFFUSE;
stages[0].stateBits = GLS_DEFAULT;
} else if ( shader.lightmapIndex == LIGHTMAP_BY_VERTEX ) {
// explicit colors at vertexes
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_EXACT_VERTEX;
stages[0].alphaGen = AGEN_SKIP;
stages[0].stateBits = GLS_DEFAULT;
} else if ( shader.lightmapIndex == LIGHTMAP_2D ) {
// GUI elements
stages[0].bundle[0].image[0] = image;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_VERTEX;
stages[0].alphaGen = AGEN_VERTEX;
stages[0].stateBits = GLS_DEPTHTEST_DISABLE |
GLS_SRCBLEND_SRC_ALPHA |
GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA;
} else if ( shader.lightmapIndex == LIGHTMAP_WHITEIMAGE ) {
// fullbright level
stages[0].bundle[0].image[0] = tr.whiteImage;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_IDENTITY_LIGHTING;
stages[0].stateBits = GLS_DEFAULT;
stages[1].bundle[0].image[0] = image;
stages[1].active = qtrue;
stages[1].rgbGen = CGEN_IDENTITY;
stages[1].stateBits |= GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO;
} else {
// two pass lightmap
stages[0].bundle[0].image[0] = tr.lightmaps[shader.lightmapIndex];
stages[0].bundle[0].isLightmap = qtrue;
stages[0].active = qtrue;
stages[0].rgbGen = CGEN_IDENTITY; // lightmaps are scaled on creation
// for identitylight
stages[0].stateBits = GLS_DEFAULT;
stages[1].bundle[0].image[0] = image;
stages[1].active = qtrue;
stages[1].rgbGen = CGEN_IDENTITY;
stages[1].stateBits |= GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO;
}
sh = FinishShader();
return sh->index;
}
/*
====================
RE_RegisterShaderLightMap
This is the exported shader entry point for the rest of the system
It will always return an index that will be valid.
This should really only be used for explicit shaders, because there is no
way to ask for different implicit lighting modes (vertex, lightmap, etc)
====================
*/
qhandle_t RE_RegisterShaderLightMap( const char *name, int lightmapIndex ) {
shader_t *sh;
if ( strlen( name ) >= MAX_QPATH ) {
ri.Printf( PRINT_ALL, "Shader name exceeds MAX_QPATH\n" );
return 0;
}
sh = R_FindShader( name, lightmapIndex, qtrue );
// we want to return 0 if the shader failed to
// load for some reason, but R_FindShader should
// still keep a name allocated for it, so if
// something calls RE_RegisterShader again with
// the same name, we don't try looking for it again
if ( sh->defaultShader ) {
return 0;
}
return sh->index;
}
/*
====================
RE_RegisterShader
This is the exported shader entry point for the rest of the system
It will always return an index that will be valid.
This should really only be used for explicit shaders, because there is no
way to ask for different implicit lighting modes (vertex, lightmap, etc)
====================
*/
qhandle_t RE_RegisterShader( const char *name ) {
shader_t *sh;
if ( strlen( name ) >= MAX_QPATH ) {
ri.Printf( PRINT_ALL, "Shader name exceeds MAX_QPATH\n" );
return 0;
}
sh = R_FindShader( name, LIGHTMAP_2D, qtrue );
// we want to return 0 if the shader failed to
// load for some reason, but R_FindShader should
// still keep a name allocated for it, so if
// something calls RE_RegisterShader again with
// the same name, we don't try looking for it again
if ( sh->defaultShader ) {
return 0;
}
return sh->index;
}
/*
====================
RE_RegisterShaderNoMip
For menu graphics that should never be picmiped
====================
*/
qhandle_t RE_RegisterShaderNoMip( const char *name ) {
shader_t *sh;
if ( strlen( name ) >= MAX_QPATH ) {
ri.Printf( PRINT_ALL, "Shader name exceeds MAX_QPATH\n" );
return 0;
}
sh = R_FindShader( name, LIGHTMAP_2D, qfalse );
// we want to return 0 if the shader failed to
// load for some reason, but R_FindShader should
// still keep a name allocated for it, so if
// something calls RE_RegisterShader again with
// the same name, we don't try looking for it again
if ( sh->defaultShader ) {
return 0;
}
return sh->index;
}
/*
====================
R_GetShaderByHandle
When a handle is passed in by another module, this range checks
it and returns a valid (possibly default) shader_t to be used internally.
====================
*/
shader_t *R_GetShaderByHandle( qhandle_t hShader ) {
if ( hShader < 0 ) {
ri.Printf( PRINT_WARNING, "R_GetShaderByHandle: out of range hShader '%d'\n", hShader );
return tr.defaultShader;
}
if ( hShader >= tr.numShaders ) {
ri.Printf( PRINT_WARNING, "R_GetShaderByHandle: out of range hShader '%d'\n", hShader );
return tr.defaultShader;
}
return tr.shaders[hShader];
}
/*
===============
R_ShaderList_f
Dump information on all valid shaders to the console
A second parameter will cause it to print in sorted order
===============
*/
void R_ShaderList_f( void ) {
int i;
int count;
shader_t *shader;
ri.Printf( PRINT_ALL, "-----------------------\n" );
count = 0;
for ( i = 0 ; i < tr.numShaders ; i++ ) {
if ( ri.Cmd_Argc() > 1 ) {
shader = tr.sortedShaders[i];
} else {
shader = tr.shaders[i];
}
ri.Printf( PRINT_ALL, "%i ", shader->numUnfoggedPasses );
if ( shader->lightmapIndex >= 0 ) {
ri.Printf( PRINT_ALL, "L " );
} else {
ri.Printf( PRINT_ALL, " " );
}
if ( shader->multitextureEnv == GL_ADD ) {
ri.Printf( PRINT_ALL, "MT(a) " );
} else if ( shader->multitextureEnv == GL_MODULATE ) {
ri.Printf( PRINT_ALL, "MT(m) " );
} else if ( shader->multitextureEnv == GL_DECAL ) {
ri.Printf( PRINT_ALL, "MT(d) " );
} else {
ri.Printf( PRINT_ALL, " " );
}
if ( shader->explicitlyDefined ) {
ri.Printf( PRINT_ALL, "E " );
} else {
ri.Printf( PRINT_ALL, " " );
}
if ( shader->optimalStageIteratorFunc == RB_StageIteratorGeneric ) {
ri.Printf( PRINT_ALL, "gen " );
} else if ( shader->optimalStageIteratorFunc == RB_StageIteratorSky ) {
ri.Printf( PRINT_ALL, "sky " );
} else if ( shader->optimalStageIteratorFunc == RB_StageIteratorLightmappedMultitexture ) {
ri.Printf( PRINT_ALL, "lmmt" );
} else if ( shader->optimalStageIteratorFunc == RB_StageIteratorVertexLitTexture ) {
ri.Printf( PRINT_ALL, "vlt " );
} else {
ri.Printf( PRINT_ALL, " " );
}
if ( shader->defaultShader ) {
ri.Printf( PRINT_ALL, ": %s (DEFAULTED)\n", shader->name );
} else {
ri.Printf( PRINT_ALL, ": %s\n", shader->name );
}
count++;
}
ri.Printf( PRINT_ALL, "%i total shaders\n", count );
ri.Printf( PRINT_ALL, "------------------\n" );
}
/*
====================
ScanAndLoadShaderFiles
Finds and loads all .shader files, combining them into
a single large text block that can be scanned for shader names
=====================
*/
#define MAX_SHADER_FILES 4096
static void ScanAndLoadShaderFiles( void ) {
char **shaderFiles;
char *buffers[MAX_SHADER_FILES] = {NULL};
char *p;
int numShaderFiles;
int i;
char *token, *textEnd;
char shaderName[MAX_QPATH];
int shaderLine;
long sum = 0, summand;
// scan for shader files
shaderFiles = ri.FS_ListFiles( "scripts", ".shader", &numShaderFiles );
if ( !shaderFiles || !numShaderFiles ) {
ri.Printf( PRINT_WARNING, "WARNING: no shader files found\n" );
return;
}
if ( numShaderFiles > MAX_SHADER_FILES ) {
numShaderFiles = MAX_SHADER_FILES;
}
// load and parse shader files
for ( i = 0; i < numShaderFiles; i++ )
{
char filename[MAX_QPATH];
Com_sprintf( filename, sizeof( filename ), "scripts/%s", shaderFiles[i] );
ri.Printf( PRINT_DEVELOPER, "...loading '%s'\n", filename );
summand = ri.FS_ReadFile( filename, (void **)&buffers[i] );
if ( !buffers[i] )
ri.Error( ERR_DROP, "Couldn't load %s", filename );
// Do a simple check on the shader structure in that file to make sure one bad shader file cannot fuck up all other shaders.
p = buffers[i];
COM_BeginParseSession(filename);
while(1)
{
token = COM_ParseExt(&p, qtrue);
if(!*token)
break;
Q_strncpyz(shaderName, token, sizeof(shaderName));
shaderLine = COM_GetCurrentParseLine();
token = COM_ParseExt(&p, qtrue);
if( !Q_stricmp( shaderName, token ) ) {
ri.Printf(PRINT_WARNING, "WARNING: In shader file %s...Invalid shader name \"%s\" on line %d.\n",
filename, shaderName, shaderLine);
break;
}
if(token[0] != '{' || token[1] != '\0')
{
ri.Printf(PRINT_WARNING, "WARNING: In shader file %s...Shader \"%s\" on line %d is missing opening brace",
filename, shaderName, shaderLine);
if (token[0])
{
ri.Printf(PRINT_WARNING, " (found \"%s\" on line %d)", token, COM_GetCurrentParseLine());
}
ri.Printf(PRINT_WARNING, "...Ignored\n");
ri.FS_FreeFile(buffers[i]);
buffers[i] = NULL;
break;
}
if(!SkipBracedSection(&p, 1))
{
ri.Printf(PRINT_WARNING, "WARNING: In shader file %s...Shader \"%s\" on line %d is missing closing brace",
filename, shaderName, shaderLine);
if( !Q_stricmp( filename, "common.shader" ) ) { // HACK...Broken shader in pak0.pk3
ri.Printf(PRINT_WARNING, "...Ignored\n");
ri.FS_FreeFile(buffers[i]);
buffers[i] = NULL;
break;
} else {
ri.Printf(PRINT_WARNING, ".\n");
}
}
}
if (buffers[i])
sum += summand;
}
// build single large buffer
s_shaderText = ri.Hunk_Alloc( sum + numShaderFiles*2, h_low );
s_shaderText[ 0 ] = '\0';
textEnd = s_shaderText;
// free in reverse order, so the temp files are all dumped
for ( i = numShaderFiles - 1; i >= 0 ; i-- )
{
if ( !buffers[i] )
continue;
strcat( textEnd, buffers[i] );
strcat( textEnd, "\n" );
textEnd += strlen( textEnd );
ri.FS_FreeFile( buffers[i] );
}
COM_Compress( s_shaderText );
// free up memory
ri.FS_FreeFileList( shaderFiles );
}
/*
====================
CreateInternalShaders
====================
*/
static void CreateInternalShaders( void ) {
tr.numShaders = 0;
// init the default shader
InitShader( "<default>", LIGHTMAP_NONE );
stages[0].bundle[0].image[0] = tr.defaultImage;
stages[0].active = qtrue;
stages[0].stateBits = GLS_DEFAULT;
tr.defaultShader = FinishShader();
// shadow shader is just a marker
Q_strncpyz( shader.name, "<stencil shadow>", sizeof( shader.name ) );
shader.sort = SS_STENCIL_SHADOW;
tr.shadowShader = FinishShader();
}
static void CreateExternalShaders( void ) {
tr.projectionShadowShader = R_FindShader( "projectionShadow", LIGHTMAP_NONE, qtrue );
tr.flareShader = R_FindShader( "flareShader", LIGHTMAP_NONE, qtrue );
// Hack to make fogging work correctly on flares. Fog colors are calculated
// in tr_flare.c already.
if(!tr.flareShader->defaultShader)
{
int index;
for(index = 0; index < tr.flareShader->numUnfoggedPasses; index++)
{
tr.flareShader->stages[index]->adjustColorsForFog = ACFF_NONE;
tr.flareShader->stages[index]->stateBits |= GLS_DEPTHTEST_DISABLE;
}
}
// tr.sunShader = R_FindShader( "sun", LIGHTMAP_NONE, qtrue ); //----(SA) let sky shader set this
tr.sunflareShader[0] = R_FindShader( "sunflare1", LIGHTMAP_NONE, qtrue );
tr.dlightShader = R_FindShader( "dlightshader", LIGHTMAP_NONE, qtrue );
}
/*
==================
R_InitShaders
==================
*/
void R_InitShaders( void ) {
glfogNum = FOG_NONE;
ri.Printf( PRINT_ALL, "Initializing Shaders\n" );
memset( hashTable, 0, sizeof( hashTable ) );
CreateInternalShaders();
ScanAndLoadShaderFiles();
CreateExternalShaders();
}
|