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
|
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 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.
Doom 3 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 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 Doom 3 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 "sys/platform.h"
#include "framework/Session.h"
#include "framework/DeclSkin.h"
#include "renderer/GuiModel.h"
#include "renderer/RenderWorld_local.h"
#include "renderer/tr_local.h"
/*
===================
R_ListRenderLightDefs_f
===================
*/
void R_ListRenderLightDefs_f( const idCmdArgs &args ) {
int i;
idRenderLightLocal *ldef;
if ( !tr.primaryWorld ) {
return;
}
int active = 0;
int totalRef = 0;
int totalIntr = 0;
for ( i = 0 ; i < tr.primaryWorld->lightDefs.Num() ; i++ ) {
ldef = tr.primaryWorld->lightDefs[i];
if ( !ldef ) {
common->Printf( "%4i: FREED\n", i );
continue;
}
// count up the interactions
int iCount = 0;
for ( idInteraction *inter = ldef->firstInteraction; inter != NULL; inter = inter->lightNext ) {
iCount++;
}
totalIntr += iCount;
// count up the references
int rCount = 0;
for ( areaReference_t *ref = ldef->references ; ref ; ref = ref->ownerNext ) {
rCount++;
}
totalRef += rCount;
common->Printf( "%4i: %3i intr %2i refs %s\n", i, iCount, rCount, ldef->lightShader->GetName());
active++;
}
common->Printf( "%i lightDefs, %i interactions, %i areaRefs\n", active, totalIntr, totalRef );
}
/*
===================
R_ListRenderEntityDefs_f
===================
*/
void R_ListRenderEntityDefs_f( const idCmdArgs &args ) {
int i;
idRenderEntityLocal *mdef;
if ( !tr.primaryWorld ) {
return;
}
int active = 0;
int totalRef = 0;
int totalIntr = 0;
for ( i = 0 ; i < tr.primaryWorld->entityDefs.Num() ; i++ ) {
mdef = tr.primaryWorld->entityDefs[i];
if ( !mdef ) {
common->Printf( "%4i: FREED\n", i );
continue;
}
// count up the interactions
int iCount = 0;
for ( idInteraction *inter = mdef->firstInteraction; inter != NULL; inter = inter->entityNext ) {
iCount++;
}
totalIntr += iCount;
// count up the references
int rCount = 0;
for ( areaReference_t *ref = mdef->entityRefs ; ref ; ref = ref->ownerNext ) {
rCount++;
}
totalRef += rCount;
common->Printf( "%4i: %3i intr %2i refs %s\n", i, iCount, rCount, mdef->parms.hModel->Name());
active++;
}
common->Printf( "total active: %i\n", active );
}
/*
===================
idRenderWorldLocal::idRenderWorldLocal
===================
*/
idRenderWorldLocal::idRenderWorldLocal() {
mapName.Clear();
mapTimeStamp = FILE_NOT_FOUND_TIMESTAMP;
generateAllInteractionsCalled = false;
areaNodes = NULL;
numAreaNodes = 0;
portalAreas = NULL;
numPortalAreas = 0;
doublePortals = NULL;
numInterAreaPortals = 0;
interactionTable = 0;
interactionTableWidth = 0;
interactionTableHeight = 0;
}
/*
===================
idRenderWorldLocal::~idRenderWorldLocal
===================
*/
idRenderWorldLocal::~idRenderWorldLocal() {
// free all the entityDefs, lightDefs, portals, etc
FreeWorld();
// free up the debug lines, polys, and text
RB_ClearDebugPolygons( 0 );
RB_ClearDebugLines( 0 );
RB_ClearDebugText( 0 );
}
/*
===================
ResizeInteractionTable
===================
*/
void idRenderWorldLocal::ResizeInteractionTable() {
// we overflowed the interaction table, so dump it
// we may want to resize this in the future if it turns out to be common
common->Printf( "idRenderWorldLocal::ResizeInteractionTable: overflowed interactionTableWidth, dumping\n" );
R_StaticFree( interactionTable );
interactionTable = NULL;
}
/*
===================
AddEntityDef
===================
*/
qhandle_t idRenderWorldLocal::AddEntityDef( const renderEntity_t *re ){
// try and reuse a free spot
int entityHandle = entityDefs.FindNull();
if ( entityHandle == -1 ) {
entityHandle = entityDefs.Append( NULL );
if ( interactionTable && entityDefs.Num() > interactionTableWidth ) {
ResizeInteractionTable();
}
}
UpdateEntityDef( entityHandle, re );
return entityHandle;
}
/*
==============
UpdateEntityDef
Does not write to the demo file, which will only be updated for
visible entities
==============
*/
int c_callbackUpdate;
void idRenderWorldLocal::UpdateEntityDef( qhandle_t entityHandle, const renderEntity_t *re ) {
if ( r_skipUpdates.GetBool() ) {
return;
}
tr.pc.c_entityUpdates++;
if ( !re->hModel && !re->callback ) {
common->Error( "idRenderWorld::UpdateEntityDef: NULL hModel" );
}
// create new slots if needed
if ( entityHandle < 0 || entityHandle > LUDICROUS_INDEX ) {
common->Error( "idRenderWorld::UpdateEntityDef: index = %i", entityHandle );
}
while ( entityHandle >= entityDefs.Num() ) {
entityDefs.Append( NULL );
}
idRenderEntityLocal *def = entityDefs[entityHandle];
if ( def ) {
if ( !re->forceUpdate ) {
// check for exact match (OPTIMIZE: check through pointers more)
if ( !re->joints && !re->callbackData && !def->dynamicModel && !memcmp( re, &def->parms, sizeof( *re ) ) ) {
return;
}
// if the only thing that changed was shaderparms, we can just leave things as they are
// after updating parms
// if we have a callback function and the bounds, origin, axis and model match,
// then we can leave the references as they are
if ( re->callback ) {
bool axisMatch = ( re->axis == def->parms.axis );
bool originMatch = ( re->origin == def->parms.origin );
bool boundsMatch = ( re->bounds == def->referenceBounds );
bool modelMatch = ( re->hModel == def->parms.hModel );
if ( boundsMatch && originMatch && axisMatch && modelMatch ) {
// only clear the dynamic model and interaction surfaces if they exist
c_callbackUpdate++;
R_ClearEntityDefDynamicModel( def );
def->parms = *re;
return;
}
}
}
// save any decals if the model is the same, allowing marks to move with entities
if ( def->parms.hModel == re->hModel ) {
R_FreeEntityDefDerivedData( def, true, true );
} else {
R_FreeEntityDefDerivedData( def, false, false );
}
} else {
// creating a new one
def = new idRenderEntityLocal;
entityDefs[entityHandle] = def;
def->world = this;
def->index = entityHandle;
}
def->parms = *re;
R_AxisToModelMatrix( def->parms.axis, def->parms.origin, def->modelMatrix );
def->lastModifiedFrameNum = tr.frameCount;
if ( session->writeDemo && def->archived ) {
WriteFreeEntity( entityHandle );
def->archived = false;
}
// optionally immediately issue any callbacks
if ( !r_useEntityCallbacks.GetBool() && def->parms.callback ) {
R_IssueEntityDefCallback( def );
}
// based on the model bounds, add references in each area
// that may contain the updated surface
R_CreateEntityRefs( def );
}
/*
===================
FreeEntityDef
Frees all references and lit surfaces from the model, and
NULL's out it's entry in the world list
===================
*/
void idRenderWorldLocal::FreeEntityDef( qhandle_t entityHandle ) {
idRenderEntityLocal *def;
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
common->Printf( "idRenderWorld::FreeEntityDef: handle %i > %i\n", entityHandle, entityDefs.Num() );
return;
}
def = entityDefs[entityHandle];
if ( !def ) {
common->Printf( "idRenderWorld::FreeEntityDef: handle %i is NULL\n", entityHandle );
return;
}
R_FreeEntityDefDerivedData( def, false, false );
if ( session->writeDemo && def->archived ) {
WriteFreeEntity( entityHandle );
}
// if we are playing a demo, these will have been freed
// in R_FreeEntityDefDerivedData(), otherwise the gui
// object still exists in the game
def->parms.gui[ 0 ] = NULL;
def->parms.gui[ 1 ] = NULL;
def->parms.gui[ 2 ] = NULL;
delete def;
entityDefs[ entityHandle ] = NULL;
}
/*
==================
GetRenderEntity
==================
*/
const renderEntity_t *idRenderWorldLocal::GetRenderEntity( qhandle_t entityHandle ) const {
idRenderEntityLocal *def;
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
common->Printf( "idRenderWorld::GetRenderEntity: invalid handle %i [0, %i]\n", entityHandle, entityDefs.Num() );
return NULL;
}
def = entityDefs[entityHandle];
if ( !def ) {
common->Printf( "idRenderWorld::GetRenderEntity: handle %i is NULL\n", entityHandle );
return NULL;
}
return &def->parms;
}
/*
==================
AddLightDef
==================
*/
qhandle_t idRenderWorldLocal::AddLightDef( const renderLight_t *rlight ) {
// try and reuse a free spot
int lightHandle = lightDefs.FindNull();
if ( lightHandle == -1 ) {
lightHandle = lightDefs.Append( NULL );
if ( interactionTable && lightDefs.Num() > interactionTableHeight ) {
ResizeInteractionTable();
}
}
UpdateLightDef( lightHandle, rlight );
return lightHandle;
}
/*
=================
UpdateLightDef
The generation of all the derived interaction data will
usually be deferred until it is visible in a scene
Does not write to the demo file, which will only be done for visible lights
=================
*/
void idRenderWorldLocal::UpdateLightDef( qhandle_t lightHandle, const renderLight_t *rlight ) {
if ( r_skipUpdates.GetBool() ) {
return;
}
tr.pc.c_lightUpdates++;
// create new slots if needed
if ( lightHandle < 0 || lightHandle > LUDICROUS_INDEX ) {
common->Error( "idRenderWorld::UpdateLightDef: index = %i", lightHandle );
}
while ( lightHandle >= lightDefs.Num() ) {
lightDefs.Append( NULL );
}
bool justUpdate = false;
idRenderLightLocal *light = lightDefs[lightHandle];
if ( light ) {
// if the shape of the light stays the same, we don't need to dump
// any of our derived data, because shader parms are calculated every frame
if ( rlight->axis == light->parms.axis && rlight->end == light->parms.end &&
rlight->lightCenter == light->parms.lightCenter && rlight->lightRadius == light->parms.lightRadius &&
rlight->noShadows == light->parms.noShadows && rlight->origin == light->parms.origin &&
rlight->parallel == light->parms.parallel && rlight->pointLight == light->parms.pointLight &&
rlight->right == light->parms.right && rlight->start == light->parms.start &&
rlight->target == light->parms.target && rlight->up == light->parms.up &&
rlight->shader == light->lightShader && rlight->prelightModel == light->parms.prelightModel ) {
justUpdate = true;
} else {
// if we are updating shadows, the prelight model is no longer valid
light->lightHasMoved = true;
R_FreeLightDefDerivedData( light );
}
} else {
// create a new one
light = new idRenderLightLocal;
lightDefs[lightHandle] = light;
light->world = this;
light->index = lightHandle;
}
light->parms = *rlight;
light->lastModifiedFrameNum = tr.frameCount;
if ( session->writeDemo && light->archived ) {
WriteFreeLight( lightHandle );
light->archived = false;
}
if ( light->lightHasMoved ) {
light->parms.prelightModel = NULL;
}
if (!justUpdate) {
R_DeriveLightData( light );
R_CreateLightRefs( light );
R_CreateLightDefFogPortals( light );
}
}
/*
====================
FreeLightDef
Frees all references and lit surfaces from the light, and
NULL's out it's entry in the world list
====================
*/
void idRenderWorldLocal::FreeLightDef( qhandle_t lightHandle ) {
idRenderLightLocal *light;
if ( lightHandle < 0 || lightHandle >= lightDefs.Num() ) {
common->Printf( "idRenderWorld::FreeLightDef: invalid handle %i [0, %i]\n", lightHandle, lightDefs.Num() );
return;
}
light = lightDefs[lightHandle];
if ( !light ) {
common->Printf( "idRenderWorld::FreeLightDef: handle %i is NULL\n", lightHandle );
return;
}
R_FreeLightDefDerivedData( light );
if ( session->writeDemo && light->archived ) {
WriteFreeLight( lightHandle );
}
delete light;
lightDefs[lightHandle] = NULL;
}
/*
==================
GetRenderLight
==================
*/
const renderLight_t *idRenderWorldLocal::GetRenderLight( qhandle_t lightHandle ) const {
idRenderLightLocal *def;
if ( lightHandle < 0 || lightHandle >= lightDefs.Num() ) {
common->Printf( "idRenderWorld::GetRenderLight: handle %i > %i\n", lightHandle, lightDefs.Num() );
return NULL;
}
def = lightDefs[lightHandle];
if ( !def ) {
common->Printf( "idRenderWorld::GetRenderLight: handle %i is NULL\n", lightHandle );
return NULL;
}
return &def->parms;
}
/*
================
idRenderWorldLocal::ProjectDecalOntoWorld
================
*/
void idRenderWorldLocal::ProjectDecalOntoWorld( const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime ) {
int i, areas[10], numAreas;
const areaReference_t *ref;
const portalArea_t *area;
const idRenderModel *model;
idRenderEntityLocal *def;
decalProjectionInfo_t info, localInfo;
if ( !idRenderModelDecal::CreateProjectionInfo( info, winding, projectionOrigin, parallel, fadeDepth, material, startTime ) ) {
return;
}
// get the world areas touched by the projection volume
numAreas = BoundsInAreas( info.projectionBounds, areas, 10 );
// check all areas for models
for ( i = 0; i < numAreas; i++ ) {
area = &portalAreas[ areas[i] ];
// check all models in this area
for ( ref = area->entityRefs.areaNext; ref != &area->entityRefs; ref = ref->areaNext ) {
def = ref->entity;
// completely ignore any dynamic or callback models
model = def->parms.hModel;
if ( model == NULL || model->IsDynamicModel() != DM_STATIC || def->parms.callback ) {
continue;
}
if ( def->parms.customShader != NULL && !def->parms.customShader->AllowOverlays() ) {
continue;
}
idBounds bounds;
bounds.FromTransformedBounds( model->Bounds( &def->parms ), def->parms.origin, def->parms.axis );
// if the model bounds do not overlap with the projection bounds
if ( !info.projectionBounds.IntersectsBounds( bounds ) ) {
continue;
}
// transform the bounding planes, fade planes and texture axis into local space
idRenderModelDecal::GlobalProjectionInfoToLocal( localInfo, info, def->parms.origin, def->parms.axis );
localInfo.force = ( def->parms.customShader != NULL );
if ( !def->decals ) {
def->decals = idRenderModelDecal::Alloc();
}
def->decals->CreateDecal( model, localInfo );
}
}
}
/*
====================
idRenderWorldLocal::ProjectDecal
====================
*/
void idRenderWorldLocal::ProjectDecal( qhandle_t entityHandle, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime ) {
decalProjectionInfo_t info, localInfo;
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
common->Error( "idRenderWorld::ProjectOverlay: index = %i", entityHandle );
return;
}
idRenderEntityLocal *def = entityDefs[ entityHandle ];
if ( !def ) {
return;
}
const idRenderModel *model = def->parms.hModel;
if ( model == NULL || model->IsDynamicModel() != DM_STATIC || def->parms.callback ) {
return;
}
if ( !idRenderModelDecal::CreateProjectionInfo( info, winding, projectionOrigin, parallel, fadeDepth, material, startTime ) ) {
return;
}
idBounds bounds;
bounds.FromTransformedBounds( model->Bounds( &def->parms ), def->parms.origin, def->parms.axis );
// if the model bounds do not overlap with the projection bounds
if ( !info.projectionBounds.IntersectsBounds( bounds ) ) {
return;
}
// transform the bounding planes, fade planes and texture axis into local space
idRenderModelDecal::GlobalProjectionInfoToLocal( localInfo, info, def->parms.origin, def->parms.axis );
localInfo.force = ( def->parms.customShader != NULL );
if ( def->decals == NULL ) {
def->decals = idRenderModelDecal::Alloc();
}
def->decals->CreateDecal( model, localInfo );
}
/*
====================
idRenderWorldLocal::ProjectOverlay
====================
*/
void idRenderWorldLocal::ProjectOverlay( qhandle_t entityHandle, const idPlane localTextureAxis[2], const idMaterial *material ) {
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
common->Error( "idRenderWorld::ProjectOverlay: index = %i", entityHandle );
return;
}
idRenderEntityLocal *def = entityDefs[ entityHandle ];
if ( !def ) {
return;
}
const renderEntity_t *refEnt = &def->parms;
idRenderModel *model = refEnt->hModel;
if ( model->IsDynamicModel() != DM_CACHED ) { // FIXME: probably should be MD5 only
return;
}
model = R_EntityDefDynamicModel( def );
if ( def->overlay == NULL ) {
def->overlay = idRenderModelOverlay::Alloc();
}
def->overlay->CreateOverlay( model, localTextureAxis, material );
}
/*
====================
idRenderWorldLocal::RemoveDecals
====================
*/
void idRenderWorldLocal::RemoveDecals( qhandle_t entityHandle ) {
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
common->Error( "idRenderWorld::ProjectOverlay: index = %i", entityHandle );
return;
}
idRenderEntityLocal *def = entityDefs[ entityHandle ];
if ( !def ) {
return;
}
R_FreeEntityDefDecals( def );
R_FreeEntityDefOverlay( def );
}
/*
====================
SetRenderView
Sets the current view so any calls to the render world will use the correct parms.
====================
*/
void idRenderWorldLocal::SetRenderView( const renderView_t *renderView ) {
tr.primaryRenderView = *renderView;
}
/*
====================
RenderScene
Draw a 3D view into a part of the window, then return
to 2D drawing.
Rendering a scene may require multiple views to be rendered
to handle mirrors,
====================
*/
void idRenderWorldLocal::RenderScene( const renderView_t *renderView ) {
#ifndef ID_DEDICATED
renderView_t copy;
if ( !glConfig.isInitialized ) {
return;
}
copy = *renderView;
// skip front end rendering work, which will result
// in only gui drawing
if ( r_skipFrontEnd.GetBool() ) {
return;
}
if ( renderView->fov_x <= 0 || renderView->fov_y <= 0 ) {
common->Error( "idRenderWorld::RenderScene: bad FOVs: %f, %f", renderView->fov_x, renderView->fov_y );
}
// close any gui drawing
tr.guiModel->EmitFullScreen();
tr.guiModel->Clear();
int startTime = Sys_Milliseconds();
// setup view parms for the initial view
//
viewDef_t *parms = (viewDef_t *)R_ClearedFrameAlloc( sizeof( *parms ) );
parms->renderView = *renderView;
if ( tr.takingScreenshot ) {
parms->renderView.forceUpdate = true;
}
// set up viewport, adjusted for resolution and OpenGL style 0 at the bottom
tr.RenderViewToViewport( &parms->renderView, &parms->viewport );
// the scissor bounds may be shrunk in subviews even if
// the viewport stays the same
// this scissor range is local inside the viewport
parms->scissor.x1 = 0;
parms->scissor.y1 = 0;
parms->scissor.x2 = parms->viewport.x2 - parms->viewport.x1;
parms->scissor.y2 = parms->viewport.y2 - parms->viewport.y1;
parms->isSubview = false;
parms->initialViewAreaOrigin = renderView->vieworg;
parms->floatTime = parms->renderView.time * 0.001f;
parms->renderWorld = this;
// use this time for any subsequent 2D rendering, so damage blobs/etc
// can use level time
tr.frameShaderTime = parms->floatTime;
// see if the view needs to reverse the culling sense in mirrors
// or environment cube sides
idVec3 cross;
cross = parms->renderView.viewaxis[1].Cross( parms->renderView.viewaxis[2] );
if ( cross * parms->renderView.viewaxis[0] > 0 ) {
parms->isMirror = false;
} else {
parms->isMirror = true;
}
if ( r_lockSurfaces.GetBool() ) {
R_LockSurfaceScene( parms );
return;
}
// save this world for use by some console commands
tr.primaryWorld = this;
tr.primaryRenderView = *renderView;
tr.primaryView = parms;
// rendering this view may cause other views to be rendered
// for mirrors / portals / shadows / environment maps
// this will also cause any necessary entities and lights to be
// updated to the demo file
R_RenderView( parms );
// now write delete commands for any modified-but-not-visible entities, and
// add the renderView command to the demo
if ( session->writeDemo ) {
WriteRenderView( renderView );
}
#if 0
for ( int i = 0 ; i < entityDefs.Num() ; i++ ) {
idRenderEntityLocal *def = entityDefs[i];
if ( !def ) {
continue;
}
if ( def->parms.callback ) {
continue;
}
if ( def->parms.hModel->IsDynamicModel() == DM_CONTINUOUS ) {
}
}
#endif
int endTime = Sys_Milliseconds();
tr.pc.frontEndMsec += endTime - startTime;
// prepare for any 2D drawing after this
tr.guiModel->Clear();
#endif
}
/*
===================
NumAreas
===================
*/
int idRenderWorldLocal::NumAreas( void ) const {
return numPortalAreas;
}
/*
===================
NumPortalsInArea
===================
*/
int idRenderWorldLocal::NumPortalsInArea( int areaNum ) {
portalArea_t *area;
int count;
portal_t *portal;
if ( areaNum >= numPortalAreas || areaNum < 0 ) {
common->Error( "idRenderWorld::NumPortalsInArea: bad areanum %i", areaNum );
}
area = &portalAreas[areaNum];
count = 0;
for ( portal = area->portals ; portal ; portal = portal->next ) {
count++;
}
return count;
}
/*
===================
GetPortal
===================
*/
exitPortal_t idRenderWorldLocal::GetPortal( int areaNum, int portalNum ) {
portalArea_t *area;
int count;
portal_t *portal;
exitPortal_t ret;
if ( areaNum > numPortalAreas ) {
common->Error( "idRenderWorld::GetPortal: areaNum > numAreas" );
}
area = &portalAreas[areaNum];
count = 0;
for ( portal = area->portals ; portal ; portal = portal->next ) {
if ( count == portalNum ) {
ret.areas[0] = areaNum;
ret.areas[1] = portal->intoArea;
ret.w = portal->w;
ret.blockingBits = portal->doublePortal->blockingBits;
ret.portalHandle = portal->doublePortal - doublePortals + 1;
return ret;
}
count++;
}
common->Error( "idRenderWorld::GetPortal: portalNum > numPortals" );
memset( &ret, 0, sizeof( ret ) );
return ret;
}
/*
===============
PointInAreaNum
Will return -1 if the point is not in an area, otherwise
it will return 0 <= value < tr.world->numPortalAreas
===============
*/
int idRenderWorldLocal::PointInArea( const idVec3 &point ) const {
areaNode_t *node;
int nodeNum;
float d;
node = areaNodes;
if ( !node ) {
return -1;
}
while( 1 ) {
d = point * node->plane.Normal() + node->plane[3];
if (d > 0) {
nodeNum = node->children[0];
} else {
nodeNum = node->children[1];
}
if ( nodeNum == 0 ) {
return -1; // in solid
}
if ( nodeNum < 0 ) {
nodeNum = -1 - nodeNum;
if ( nodeNum >= numPortalAreas ) {
common->Error( "idRenderWorld::PointInArea: area out of range" );
}
return nodeNum;
}
node = areaNodes + nodeNum;
}
return -1;
}
/*
===================
BoundsInAreas_r
===================
*/
void idRenderWorldLocal::BoundsInAreas_r( int nodeNum, const idBounds &bounds, int *areas, int *numAreas, int maxAreas ) const {
int side, i;
areaNode_t *node;
do {
if ( nodeNum < 0 ) {
nodeNum = -1 - nodeNum;
for ( i = 0; i < (*numAreas); i++ ) {
if ( areas[i] == nodeNum ) {
break;
}
}
if ( i >= (*numAreas) && (*numAreas) < maxAreas ) {
areas[(*numAreas)++] = nodeNum;
}
return;
}
node = areaNodes + nodeNum;
side = bounds.PlaneSide( node->plane );
if ( side == PLANESIDE_FRONT ) {
nodeNum = node->children[0];
}
else if ( side == PLANESIDE_BACK ) {
nodeNum = node->children[1];
}
else {
if ( node->children[1] != 0 ) {
BoundsInAreas_r( node->children[1], bounds, areas, numAreas, maxAreas );
if ( (*numAreas) >= maxAreas ) {
return;
}
}
nodeNum = node->children[0];
}
} while( nodeNum != 0 );
return;
}
/*
===================
BoundsInAreas
fills the *areas array with the number of the areas the bounds are in
returns the total number of areas the bounds are in
===================
*/
int idRenderWorldLocal::BoundsInAreas( const idBounds &bounds, int *areas, int maxAreas ) const {
int numAreas = 0;
assert( areas );
assert( bounds[0][0] <= bounds[1][0] && bounds[0][1] <= bounds[1][1] && bounds[0][2] <= bounds[1][2] );
assert( bounds[1][0] - bounds[0][0] < 1e4f && bounds[1][1] - bounds[0][1] < 1e4f && bounds[1][2] - bounds[0][2] < 1e4f );
if ( !areaNodes ) {
return numAreas;
}
BoundsInAreas_r( 0, bounds, areas, &numAreas, maxAreas );
return numAreas;
}
/*
================
GuiTrace
checks a ray trace against any gui surfaces in an entity, returning the
fraction location of the trace on the gui surface, or -1,-1 if no hit.
this doesn't do any occlusion testing, simply ignoring non-gui surfaces.
start / end are in global world coordinates.
================
*/
guiPoint_t idRenderWorldLocal::GuiTrace( qhandle_t entityHandle, const idVec3 start, const idVec3 end ) const {
localTrace_t local;
idVec3 localStart, localEnd, bestPoint;
int j;
idRenderModel *model;
srfTriangles_t *tri;
const idMaterial *shader;
guiPoint_t pt;
pt.x = pt.y = -1;
pt.guiId = 0;
if ( ( entityHandle < 0 ) || ( entityHandle >= entityDefs.Num() ) ) {
common->Printf( "idRenderWorld::GuiTrace: invalid handle %i\n", entityHandle );
return pt;
}
idRenderEntityLocal *def = entityDefs[entityHandle];
if ( !def ) {
common->Printf( "idRenderWorld::GuiTrace: handle %i is NULL\n", entityHandle );
return pt;
}
model = def->parms.hModel;
if ( def->parms.callback || !def->parms.hModel || def->parms.hModel->IsDynamicModel() != DM_STATIC ) {
return pt;
}
// transform the points into local space
R_GlobalPointToLocal( def->modelMatrix, start, localStart );
R_GlobalPointToLocal( def->modelMatrix, end, localEnd );
for ( j = 0 ; j < model->NumSurfaces() ; j++ ) {
const modelSurface_t *surf = model->Surface( j );
tri = surf->geometry;
if ( !tri ) {
continue;
}
shader = R_RemapShaderBySkin( surf->shader, def->parms.customSkin, def->parms.customShader );
if ( !shader ) {
continue;
}
// only trace against gui surfaces
if (!shader->HasGui()) {
continue;
}
local = R_LocalTrace( localStart, localEnd, 0.0f, tri );
if ( local.fraction < 1.0 ) {
idVec3 origin, axis[3];
idVec3 cursor;
float axisLen[2];
R_SurfaceToTextureAxis( tri, origin, axis );
cursor = local.point - origin;
axisLen[0] = axis[0].Length();
axisLen[1] = axis[1].Length();
pt.x = ( cursor * axis[0] ) / ( axisLen[0] * axisLen[0] );
pt.y = ( cursor * axis[1] ) / ( axisLen[1] * axisLen[1] );
pt.guiId = shader->GetEntityGui();
return pt;
}
}
return pt;
}
/*
===================
idRenderWorldLocal::ModelTrace
===================
*/
bool idRenderWorldLocal::ModelTrace( modelTrace_t &trace, qhandle_t entityHandle, const idVec3 &start, const idVec3 &end, const float radius ) const {
int i;
bool collisionSurface;
const modelSurface_t *surf;
localTrace_t localTrace;
idRenderModel *model;
float modelMatrix[16];
idVec3 localStart, localEnd;
const idMaterial *shader;
trace.fraction = 1.0f;
if ( entityHandle < 0 || entityHandle >= entityDefs.Num() ) {
// common->Error( "idRenderWorld::ModelTrace: index = %i", entityHandle );
return false;
}
idRenderEntityLocal *def = entityDefs[entityHandle];
if ( !def ) {
return false;
}
renderEntity_t *refEnt = &def->parms;
model = R_EntityDefDynamicModel( def );
if ( !model ) {
return false;
}
// transform the points into local space
R_AxisToModelMatrix( refEnt->axis, refEnt->origin, modelMatrix );
R_GlobalPointToLocal( modelMatrix, start, localStart );
R_GlobalPointToLocal( modelMatrix, end, localEnd );
// if we have explicit collision surfaces, only collide against them
// (FIXME, should probably have a parm to control this)
collisionSurface = false;
for ( i = 0; i < model->NumBaseSurfaces(); i++ ) {
surf = model->Surface( i );
shader = R_RemapShaderBySkin( surf->shader, def->parms.customSkin, def->parms.customShader );
if ( shader->GetSurfaceFlags() & SURF_COLLISION ) {
collisionSurface = true;
break;
}
}
// only use baseSurfaces, not any overlays
for ( i = 0; i < model->NumBaseSurfaces(); i++ ) {
surf = model->Surface( i );
shader = R_RemapShaderBySkin( surf->shader, def->parms.customSkin, def->parms.customShader );
if ( !surf->geometry || !shader ) {
continue;
}
if ( collisionSurface ) {
// only trace vs collision surfaces
if ( !( shader->GetSurfaceFlags() & SURF_COLLISION ) ) {
continue;
}
} else {
// skip if not drawn or translucent
if ( !shader->IsDrawn() || ( shader->Coverage() != MC_OPAQUE && shader->Coverage() != MC_PERFORATED ) ) {
continue;
}
}
localTrace = R_LocalTrace( localStart, localEnd, radius, surf->geometry );
if ( localTrace.fraction < trace.fraction ) {
trace.fraction = localTrace.fraction;
R_LocalPointToGlobal( modelMatrix, localTrace.point, trace.point );
trace.normal = localTrace.normal * refEnt->axis;
trace.material = shader;
trace.entity = &def->parms;
trace.jointNumber = refEnt->hModel->NearestJoint( i, localTrace.indexes[0], localTrace.indexes[1], localTrace.indexes[2] );
}
}
return ( trace.fraction < 1.0f );
}
/*
===================
idRenderWorldLocal::Trace
===================
*/
// FIXME: _D3XP added those.
const char* playerModelExcludeList[] = {
"models/md5/characters/player/d3xp_spplayer.md5mesh",
"models/md5/characters/player/head/d3xp_head.md5mesh",
"models/md5/weapons/pistol_world/worldpistol.md5mesh",
NULL
};
const char* playerMaterialExcludeList[] = {
"muzzlesmokepuff",
NULL
};
bool idRenderWorldLocal::Trace( modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic, bool skipPlayer /*_D3XP*/ ) const {
areaReference_t * ref;
idRenderEntityLocal *def;
portalArea_t * area;
idRenderModel * model;
srfTriangles_t * tri;
localTrace_t localTrace;
int areas[128], numAreas, i, j, numSurfaces;
idBounds traceBounds, bounds;
float modelMatrix[16];
idVec3 localStart, localEnd;
const idMaterial *shader;
trace.fraction = 1.0f;
trace.point = end;
// bounds for the whole trace
traceBounds.Clear();
traceBounds.AddPoint( start );
traceBounds.AddPoint( end );
// get the world areas the trace is in
numAreas = BoundsInAreas( traceBounds, areas, 128 );
numSurfaces = 0;
// check all areas for models
for ( i = 0; i < numAreas; i++ ) {
area = &portalAreas[ areas[i] ];
// check all models in this area
for ( ref = area->entityRefs.areaNext; ref != &area->entityRefs; ref = ref->areaNext ) {
def = ref->entity;
model = def->parms.hModel;
if ( !model ) {
continue;
}
if ( model->IsDynamicModel() != DM_STATIC ) {
if ( skipDynamic ) {
continue;
}
#if 1 /* _D3XP addition. could use a cleaner approach */
if ( skipPlayer ) {
idStr name = model->Name();
const char *exclude;
int k;
for ( k = 0; playerModelExcludeList[k]; k++ ) {
exclude = playerModelExcludeList[k];
if ( name == exclude ) {
break;
}
}
if ( playerModelExcludeList[k] ) {
continue;
}
}
#endif
model = R_EntityDefDynamicModel( def );
if ( !model ) {
continue; // can happen with particle systems, which don't instantiate without a valid view
}
}
bounds.FromTransformedBounds( model->Bounds( &def->parms ), def->parms.origin, def->parms.axis );
// if the model bounds do not overlap with the trace bounds
if ( !traceBounds.IntersectsBounds( bounds ) || !bounds.LineIntersection( start, trace.point ) ) {
continue;
}
// check all model surfaces
for ( j = 0; j < model->NumSurfaces(); j++ ) {
const modelSurface_t *surf = model->Surface( j );
shader = R_RemapShaderBySkin( surf->shader, def->parms.customSkin, def->parms.customShader );
// if no geometry or no shader
if ( !surf->geometry || !shader ) {
continue;
}
#if 1 /* _D3XP addition. could use a cleaner approach */
if ( skipPlayer ) {
idStr name = shader->GetName();
const char *exclude;
int k;
for ( k = 0; playerMaterialExcludeList[k]; k++ ) {
exclude = playerMaterialExcludeList[k];
if ( name == exclude ) {
break;
}
}
if ( playerMaterialExcludeList[k] ) {
continue;
}
}
#endif
tri = surf->geometry;
bounds.FromTransformedBounds( tri->bounds, def->parms.origin, def->parms.axis );
// if triangle bounds do not overlap with the trace bounds
if ( !traceBounds.IntersectsBounds( bounds ) || !bounds.LineIntersection( start, trace.point ) ) {
continue;
}
numSurfaces++;
// transform the points into local space
R_AxisToModelMatrix( def->parms.axis, def->parms.origin, modelMatrix );
R_GlobalPointToLocal( modelMatrix, start, localStart );
R_GlobalPointToLocal( modelMatrix, end, localEnd );
localTrace = R_LocalTrace( localStart, localEnd, radius, surf->geometry );
if ( localTrace.fraction < trace.fraction ) {
trace.fraction = localTrace.fraction;
R_LocalPointToGlobal( modelMatrix, localTrace.point, trace.point );
trace.normal = localTrace.normal * def->parms.axis;
trace.material = shader;
trace.entity = &def->parms;
trace.jointNumber = model->NearestJoint( j, localTrace.indexes[0], localTrace.indexes[1], localTrace.indexes[2] );
traceBounds.Clear();
traceBounds.AddPoint( start );
traceBounds.AddPoint( start + trace.fraction * (end - start) );
}
}
}
}
return ( trace.fraction < 1.0f );
}
/*
==================
idRenderWorldLocal::RecurseProcBSP
==================
*/
void idRenderWorldLocal::RecurseProcBSP_r( modelTrace_t *results, int parentNodeNum, int nodeNum, float p1f, float p2f, const idVec3 &p1, const idVec3 &p2 ) const {
float t1, t2;
float frac;
idVec3 mid;
int side;
float midf;
areaNode_t *node;
if ( results->fraction <= p1f) {
return; // already hit something nearer
}
// empty leaf
if ( nodeNum < 0 ) {
return;
}
// if solid leaf node
if ( nodeNum == 0 ) {
if ( parentNodeNum != -1 ) {
results->fraction = p1f;
results->point = p1;
node = &areaNodes[parentNodeNum];
results->normal = node->plane.Normal();
return;
}
}
node = &areaNodes[nodeNum];
// distance from plane for trace start and end
t1 = node->plane.Normal() * p1 + node->plane[3];
t2 = node->plane.Normal() * p2 + node->plane[3];
if ( t1 >= 0.0f && t2 >= 0.0f ) {
RecurseProcBSP_r( results, nodeNum, node->children[0], p1f, p2f, p1, p2 );
return;
}
if ( t1 < 0.0f && t2 < 0.0f ) {
RecurseProcBSP_r( results, nodeNum, node->children[1], p1f, p2f, p1, p2 );
return;
}
side = t1 < t2;
frac = t1 / (t1 - t2);
midf = p1f + frac*(p2f - p1f);
mid[0] = p1[0] + frac*(p2[0] - p1[0]);
mid[1] = p1[1] + frac*(p2[1] - p1[1]);
mid[2] = p1[2] + frac*(p2[2] - p1[2]);
RecurseProcBSP_r( results, nodeNum, node->children[side], p1f, midf, p1, mid );
RecurseProcBSP_r( results, nodeNum, node->children[side^1], midf, p2f, mid, p2 );
}
/*
==================
idRenderWorldLocal::FastWorldTrace
==================
*/
bool idRenderWorldLocal::FastWorldTrace( modelTrace_t &results, const idVec3 &start, const idVec3 &end ) const {
memset( &results, 0, sizeof( modelTrace_t ) );
results.fraction = 1.0f;
if ( areaNodes != NULL ) {
RecurseProcBSP_r( &results, -1, 0, 0.0f, 1.0f, start, end );
return ( results.fraction < 1.0f );
}
return false;
}
/*
=================================================================================
CREATE MODEL REFS
=================================================================================
*/
/*
=================
AddEntityRefToArea
This is called by R_PushVolumeIntoTree and also directly
for the world model references that are precalculated.
=================
*/
void idRenderWorldLocal::AddEntityRefToArea( idRenderEntityLocal *def, portalArea_t *area ) {
areaReference_t *ref;
if ( !def ) {
common->Error( "idRenderWorldLocal::AddEntityRefToArea: NULL def" );
}
ref = areaReferenceAllocator.Alloc();
tr.pc.c_entityReferences++;
ref->entity = def;
// link to entityDef
ref->ownerNext = def->entityRefs;
def->entityRefs = ref;
// link to end of area list
ref->area = area;
ref->areaNext = &area->entityRefs;
ref->areaPrev = area->entityRefs.areaPrev;
ref->areaNext->areaPrev = ref;
ref->areaPrev->areaNext = ref;
}
/*
===================
AddLightRefToArea
===================
*/
void idRenderWorldLocal::AddLightRefToArea( idRenderLightLocal *light, portalArea_t *area ) {
areaReference_t *lref;
// add a lightref to this area
lref = areaReferenceAllocator.Alloc();
lref->light = light;
lref->area = area;
lref->ownerNext = light->references;
light->references = lref;
tr.pc.c_lightReferences++;
// doubly linked list so we can free them easily later
area->lightRefs.areaNext->areaPrev = lref;
lref->areaNext = area->lightRefs.areaNext;
lref->areaPrev = &area->lightRefs;
area->lightRefs.areaNext = lref;
}
/*
===================
GenerateAllInteractions
Force the generation of all light / surface interactions at the start of a level
If this isn't called, they will all be dynamically generated
This really isn't all that helpful anymore, because the calculation of shadows
and light interactions is deferred from idRenderWorldLocal::CreateLightDefInteractions(), but we
use it as an oportunity to size the interactionTable
===================
*/
void idRenderWorldLocal::GenerateAllInteractions() {
if ( !glConfig.isInitialized ) {
return;
}
int start = Sys_Milliseconds();
generateAllInteractionsCalled = false;
// watch how much memory we allocate
tr.staticAllocCount = 0;
// let idRenderWorldLocal::CreateLightDefInteractions() know that it shouldn't
// try and do any view specific optimizations
tr.viewDef = NULL;
for ( int i = 0 ; i < this->lightDefs.Num() ; i++ ) {
idRenderLightLocal *ldef = this->lightDefs[i];
if ( !ldef ) {
continue;
}
this->CreateLightDefInteractions( ldef );
}
int end = Sys_Milliseconds();
int msec = end - start;
common->Printf( "idRenderWorld::GenerateAllInteractions, msec = %i, staticAllocCount = %i.\n", msec, tr.staticAllocCount );
// build the interaction table
if ( r_useInteractionTable.GetBool() ) {
interactionTableWidth = entityDefs.Num() + 100;
interactionTableHeight = lightDefs.Num() + 100;
int size = interactionTableWidth * interactionTableHeight * sizeof( *interactionTable );
interactionTable = (idInteraction **)R_ClearedStaticAlloc( size );
int count = 0;
for ( int i = 0 ; i < this->lightDefs.Num() ; i++ ) {
idRenderLightLocal *ldef = this->lightDefs[i];
if ( !ldef ) {
continue;
}
idInteraction *inter;
for ( inter = ldef->firstInteraction; inter != NULL; inter = inter->lightNext ) {
idRenderEntityLocal *edef = inter->entityDef;
int index = ldef->index * interactionTableWidth + edef->index;
interactionTable[ index ] = inter;
count++;
}
}
common->Printf( "interactionTable size: %i bytes\n", size );
common->Printf( "%d interaction take %zd bytes\n", count, count * sizeof( idInteraction ) );
}
// entities flagged as noDynamicInteractions will no longer make any
generateAllInteractionsCalled = true;
}
/*
===================
idRenderWorldLocal::FreeInteractions
===================
*/
void idRenderWorldLocal::FreeInteractions() {
int i;
idRenderEntityLocal *def;
for ( i = 0 ; i < entityDefs.Num(); i++ ) {
def = entityDefs[i];
if ( !def ) {
continue;
}
// free all the interactions
while ( def->firstInteraction != NULL ) {
def->firstInteraction->UnlinkAndFree();
}
}
}
/*
==================
PushVolumeIntoTree
Used for both light volumes and model volumes.
This does not clip the points by the planes, so some slop
occurs.
tr.viewCount should be bumped before calling, allowing it
to prevent double checking areas.
We might alternatively choose to do this with an area flow.
==================
*/
void idRenderWorldLocal::PushVolumeIntoTree_r( idRenderEntityLocal *def, idRenderLightLocal *light, const idSphere *sphere, int numPoints, const idVec3 (*points),
int nodeNum ) {
int i;
areaNode_t *node;
bool front, back;
if ( nodeNum < 0 ) {
portalArea_t *area;
int areaNum = -1 - nodeNum;
area = &portalAreas[ areaNum ];
if ( area->viewCount == tr.viewCount ) {
return; // already added a reference here
}
area->viewCount = tr.viewCount;
if ( def ) {
AddEntityRefToArea( def, area );
}
if ( light ) {
AddLightRefToArea( light, area );
}
return;
}
node = areaNodes + nodeNum;
// if we know that all possible children nodes only touch an area
// we have already marked, we can early out
if ( r_useNodeCommonChildren.GetBool() &&
node->commonChildrenArea != CHILDREN_HAVE_MULTIPLE_AREAS ) {
// note that we do NOT try to set a reference in this area
// yet, because the test volume may yet wind up being in the
// solid part, which would cause bounds slightly poked into
// a wall to show up in the next room
if ( portalAreas[ node->commonChildrenArea ].viewCount == tr.viewCount ) {
return;
}
}
// if the bounding sphere is completely on one side, don't
// bother checking the individual points
float sd = node->plane.Distance( sphere->GetOrigin() );
if ( sd >= sphere->GetRadius() ) {
nodeNum = node->children[0];
if ( nodeNum ) { // 0 = solid
PushVolumeIntoTree_r( def, light, sphere, numPoints, points, nodeNum );
}
return;
}
if ( sd <= -sphere->GetRadius() ) {
nodeNum = node->children[1];
if ( nodeNum ) { // 0 = solid
PushVolumeIntoTree_r( def, light, sphere, numPoints, points, nodeNum );
}
return;
}
// exact check all the points against the node plane
front = back = false;
#ifdef MACOS_X //loop unrolling & pre-fetching for performance
const idVec3 norm = node->plane.Normal();
const float plane3 = node->plane[3];
float D0, D1, D2, D3;
for ( i = 0 ; i < numPoints - 4; i+=4 ) {
D0 = points[i+0] * norm + plane3;
D1 = points[i+1] * norm + plane3;
if ( !front && D0 >= 0.0f ) {
front = true;
} else if ( !back && D0 <= 0.0f ) {
back = true;
}
D2 = points[i+1] * norm + plane3;
if ( !front && D1 >= 0.0f ) {
front = true;
} else if ( !back && D1 <= 0.0f ) {
back = true;
}
D3 = points[i+1] * norm + plane3;
if ( !front && D2 >= 0.0f ) {
front = true;
} else if ( !back && D2 <= 0.0f ) {
back = true;
}
if ( !front && D3 >= 0.0f ) {
front = true;
} else if ( !back && D3 <= 0.0f ) {
back = true;
}
if ( back && front ) {
break;
}
}
if(!(back && front)) {
for (; i < numPoints ; i++ ) {
float d;
d = points[i] * node->plane.Normal() + node->plane[3];
if ( d >= 0.0f ) {
front = true;
} else if ( d <= 0.0f ) {
back = true;
}
if ( back && front ) {
break;
}
}
}
#else
for ( i = 0 ; i < numPoints ; i++ ) {
float d;
d = points[i] * node->plane.Normal() + node->plane[3];
if ( d >= 0.0f ) {
front = true;
} else if ( d <= 0.0f ) {
back = true;
}
if ( back && front ) {
break;
}
}
#endif
if ( front ) {
nodeNum = node->children[0];
if ( nodeNum ) { // 0 = solid
PushVolumeIntoTree_r( def, light, sphere, numPoints, points, nodeNum );
}
}
if ( back ) {
nodeNum = node->children[1];
if ( nodeNum ) { // 0 = solid
PushVolumeIntoTree_r( def, light, sphere, numPoints, points, nodeNum );
}
}
}
/*
==============
PushVolumeIntoTree
==============
*/
void idRenderWorldLocal::PushVolumeIntoTree( idRenderEntityLocal *def, idRenderLightLocal *light, int numPoints, const idVec3 (*points) ) {
int i;
float radSquared, lr;
idVec3 mid, dir;
if ( areaNodes == NULL ) {
return;
}
// calculate a bounding sphere for the points
mid.Zero();
for ( i = 0; i < numPoints; i++ ) {
mid += points[i];
}
mid *= ( 1.0f / numPoints );
radSquared = 0;
for ( i = 0; i < numPoints; i++ ) {
dir = points[i] - mid;
lr = dir * dir;
if ( lr > radSquared ) {
radSquared = lr;
}
}
idSphere sphere( mid, sqrt( radSquared ) );
PushVolumeIntoTree_r( def, light, &sphere, numPoints, points, 0 );
}
//===================================================================
/*
====================
idRenderWorldLocal::DebugClearLines
====================
*/
void idRenderWorldLocal::DebugClearLines( int time ) {
RB_ClearDebugLines( time );
RB_ClearDebugText( time );
}
/*
====================
idRenderWorldLocal::DebugLine
====================
*/
void idRenderWorldLocal::DebugLine( const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime, const bool depthTest ) {
RB_AddDebugLine( color, start, end, lifetime, depthTest );
}
/*
================
idRenderWorldLocal::DebugArrow
================
*/
void idRenderWorldLocal::DebugArrow( const idVec4 &color, const idVec3 &start, const idVec3 &end, int size, const int lifetime ) {
idVec3 forward, right, up, v1, v2;
float a, s;
int i;
static float arrowCos[40];
static float arrowSin[40];
static int arrowStep;
DebugLine( color, start, end, lifetime );
if ( r_debugArrowStep.GetInteger() <= 10 ) {
return;
}
// calculate sine and cosine when step size changes
if ( arrowStep != r_debugArrowStep.GetInteger() ) {
arrowStep = r_debugArrowStep.GetInteger();
for (i = 0, a = 0; a < 360.0f; a += arrowStep, i++) {
arrowCos[i] = idMath::Cos16( DEG2RAD( a ) );
arrowSin[i] = idMath::Sin16( DEG2RAD( a ) );
}
arrowCos[i] = arrowCos[0];
arrowSin[i] = arrowSin[0];
}
// draw a nice arrow
forward = end - start;
forward.Normalize();
forward.NormalVectors( right, up);
for (i = 0, a = 0; a < 360.0f; a += arrowStep, i++) {
s = 0.5f * size * arrowCos[i];
v1 = end - size * forward;
v1 = v1 + s * right;
s = 0.5f * size * arrowSin[i];
v1 = v1 + s * up;
s = 0.5f * size * arrowCos[i+1];
v2 = end - size * forward;
v2 = v2 + s * right;
s = 0.5f * size * arrowSin[i+1];
v2 = v2 + s * up;
DebugLine( color, v1, end, lifetime );
DebugLine( color, v1, v2, lifetime );
}
}
/*
====================
idRenderWorldLocal::DebugWinding
====================
*/
void idRenderWorldLocal::DebugWinding( const idVec4 &color, const idWinding &w, const idVec3 &origin, const idMat3 &axis, const int lifetime, const bool depthTest ) {
int i;
idVec3 point, lastPoint;
if ( w.GetNumPoints() < 2 ) {
return;
}
lastPoint = origin + w[w.GetNumPoints()-1].ToVec3() * axis;
for ( i = 0; i < w.GetNumPoints(); i++ ) {
point = origin + w[i].ToVec3() * axis;
DebugLine( color, lastPoint, point, lifetime, depthTest );
lastPoint = point;
}
}
/*
====================
idRenderWorldLocal::DebugCircle
====================
*/
void idRenderWorldLocal::DebugCircle( const idVec4 &color, const idVec3 &origin, const idVec3 &dir, const float radius, const int numSteps, const int lifetime, const bool depthTest ) {
int i;
float a;
idVec3 left, up, point, lastPoint;
dir.OrthogonalBasis( left, up );
left *= radius;
up *= radius;
lastPoint = origin + up;
for ( i = 1; i <= numSteps; i++ ) {
a = idMath::TWO_PI * i / numSteps;
point = origin + idMath::Sin16( a ) * left + idMath::Cos16( a ) * up;
DebugLine( color, lastPoint, point, lifetime, depthTest );
lastPoint = point;
}
}
/*
============
idRenderWorldLocal::DebugSphere
============
*/
void idRenderWorldLocal::DebugSphere( const idVec4 &color, const idSphere &sphere, const int lifetime, const bool depthTest /*_D3XP*/ ) {
int i, j, n, num;
float s, c;
idVec3 p, lastp, *lastArray;
num = 360 / 15;
lastArray = (idVec3 *) _alloca16( num * sizeof( idVec3 ) );
lastArray[0] = sphere.GetOrigin() + idVec3( 0, 0, sphere.GetRadius() );
for ( n = 1; n < num; n++ ) {
lastArray[n] = lastArray[0];
}
for ( i = 15; i <= 360; i += 15 ) {
s = idMath::Sin16( DEG2RAD(i) );
c = idMath::Cos16( DEG2RAD(i) );
lastp[0] = sphere.GetOrigin()[0];
lastp[1] = sphere.GetOrigin()[1] + sphere.GetRadius() * s;
lastp[2] = sphere.GetOrigin()[2] + sphere.GetRadius() * c;
for ( n = 0, j = 15; j <= 360; j += 15, n++ ) {
p[0] = sphere.GetOrigin()[0] + idMath::Sin16( DEG2RAD(j) ) * sphere.GetRadius() * s;
p[1] = sphere.GetOrigin()[1] + idMath::Cos16( DEG2RAD(j) ) * sphere.GetRadius() * s;
p[2] = lastp[2];
DebugLine( color, lastp, p, lifetime,depthTest );
DebugLine( color, lastp, lastArray[n], lifetime, depthTest );
lastArray[n] = lastp;
lastp = p;
}
}
}
/*
====================
idRenderWorldLocal::DebugBounds
====================
*/
void idRenderWorldLocal::DebugBounds( const idVec4 &color, const idBounds &bounds, const idVec3 &org, const int lifetime ) {
int i;
idVec3 v[8];
if ( bounds.IsCleared() ) {
return;
}
for ( i = 0; i < 8; i++ ) {
v[i][0] = org[0] + bounds[(i^(i>>1))&1][0];
v[i][1] = org[1] + bounds[(i>>1)&1][1];
v[i][2] = org[2] + bounds[(i>>2)&1][2];
}
for ( i = 0; i < 4; i++ ) {
DebugLine( color, v[i], v[(i+1)&3], lifetime );
DebugLine( color, v[4+i], v[4+((i+1)&3)], lifetime );
DebugLine( color, v[i], v[4+i], lifetime );
}
}
/*
====================
idRenderWorldLocal::DebugBox
====================
*/
void idRenderWorldLocal::DebugBox( const idVec4 &color, const idBox &box, const int lifetime ) {
int i;
idVec3 v[8];
box.ToPoints( v );
for ( i = 0; i < 4; i++ ) {
DebugLine( color, v[i], v[(i+1)&3], lifetime );
DebugLine( color, v[4+i], v[4+((i+1)&3)], lifetime );
DebugLine( color, v[i], v[4+i], lifetime );
}
}
/*
================
idRenderWorldLocal::DebugFrustum
================
*/
void idRenderWorldLocal::DebugFrustum( const idVec4 &color, const idFrustum &frustum, const bool showFromOrigin, const int lifetime ) {
int i;
idVec3 v[8];
frustum.ToPoints( v );
if ( frustum.GetNearDistance() > 0.0f ) {
for ( i = 0; i < 4; i++ ) {
DebugLine( color, v[i], v[(i+1)&3], lifetime );
}
if ( showFromOrigin ) {
for ( i = 0; i < 4; i++ ) {
DebugLine( color, frustum.GetOrigin(), v[i], lifetime );
}
}
}
for ( i = 0; i < 4; i++ ) {
DebugLine( color, v[4+i], v[4+((i+1)&3)], lifetime );
DebugLine( color, v[i], v[4+i], lifetime );
}
}
/*
============
idRenderWorldLocal::DebugCone
dir is the cone axis
radius1 is the radius at the apex
radius2 is the radius at apex+dir
============
*/
void idRenderWorldLocal::DebugCone( const idVec4 &color, const idVec3 &apex, const idVec3 &dir, float radius1, float radius2, const int lifetime ) {
int i;
idMat3 axis;
idVec3 top, p1, p2, lastp1, lastp2, d;
axis[2] = dir;
axis[2].Normalize();
axis[2].NormalVectors( axis[0], axis[1] );
axis[1] = -axis[1];
top = apex + dir;
lastp2 = top + radius2 * axis[1];
if ( radius1 == 0.0f ) {
for ( i = 20; i <= 360; i += 20 ) {
d = idMath::Sin16( DEG2RAD(i) ) * axis[0] + idMath::Cos16( DEG2RAD(i) ) * axis[1];
p2 = top + d * radius2;
DebugLine( color, lastp2, p2, lifetime );
DebugLine( color, p2, apex, lifetime );
lastp2 = p2;
}
} else {
lastp1 = apex + radius1 * axis[1];
for ( i = 20; i <= 360; i += 20 ) {
d = idMath::Sin16( DEG2RAD(i) ) * axis[0] + idMath::Cos16( DEG2RAD(i) ) * axis[1];
p1 = apex + d * radius1;
p2 = top + d * radius2;
DebugLine( color, lastp1, p1, lifetime );
DebugLine( color, lastp2, p2, lifetime );
DebugLine( color, p1, p2, lifetime );
lastp1 = p1;
lastp2 = p2;
}
}
}
/*
================
idRenderWorldLocal::DebugAxis
================
*/
void idRenderWorldLocal::DebugAxis( const idVec3 &origin, const idMat3 &axis ) {
idVec3 start = origin;
idVec3 end = start + axis[0] * 20.0f;
DebugArrow( colorWhite, start, end, 2 );
end = start + axis[0] * -20.0f;
DebugArrow( colorWhite, start, end, 2 );
end = start + axis[1] * +20.0f;
DebugArrow( colorGreen, start, end, 2 );
end = start + axis[1] * -20.0f;
DebugArrow( colorGreen, start, end, 2 );
end = start + axis[2] * +20.0f;
DebugArrow( colorBlue, start, end, 2 );
end = start + axis[2] * -20.0f;
DebugArrow( colorBlue, start, end, 2 );
}
/*
====================
idRenderWorldLocal::DebugClearPolygons
====================
*/
void idRenderWorldLocal::DebugClearPolygons( int time ) {
RB_ClearDebugPolygons( time );
}
/*
====================
idRenderWorldLocal::DebugPolygon
====================
*/
void idRenderWorldLocal::DebugPolygon( const idVec4 &color, const idWinding &winding, const int lifeTime, const bool depthTest ) {
RB_AddDebugPolygon( color, winding, lifeTime, depthTest );
}
/*
================
idRenderWorldLocal::DebugScreenRect
================
*/
void idRenderWorldLocal::DebugScreenRect( const idVec4 &color, const idScreenRect &rect, const viewDef_t *viewDef, const int lifetime ) {
int i;
float centerx, centery, dScale, hScale, vScale;
idBounds bounds;
idVec3 p[4];
centerx = ( viewDef->viewport.x2 - viewDef->viewport.x1 ) * 0.5f;
centery = ( viewDef->viewport.y2 - viewDef->viewport.y1 ) * 0.5f;
dScale = r_znear.GetFloat() + 1.0f;
hScale = dScale * idMath::Tan16( DEG2RAD( viewDef->renderView.fov_x * 0.5f ) );
vScale = dScale * idMath::Tan16( DEG2RAD( viewDef->renderView.fov_y * 0.5f ) );
bounds[0][0] = bounds[1][0] = dScale;
bounds[0][1] = -( rect.x1 - centerx ) / centerx * hScale;
bounds[1][1] = -( rect.x2 - centerx ) / centerx * hScale;
bounds[0][2] = ( rect.y1 - centery ) / centery * vScale;
bounds[1][2] = ( rect.y2 - centery ) / centery * vScale;
for ( i = 0; i < 4; i++ ) {
p[i].x = bounds[0][0];
p[i].y = bounds[(i^(i>>1))&1].y;
p[i].z = bounds[(i>>1)&1].z;
p[i] = viewDef->renderView.vieworg + p[i] * viewDef->renderView.viewaxis;
}
for ( i = 0; i < 4; i++ ) {
DebugLine( color, p[i], p[(i+1)&3], false );
}
}
/*
================
idRenderWorldLocal::DrawTextLength
returns the length of the given text
================
*/
float idRenderWorldLocal::DrawTextLength( const char *text, float scale, int len ) {
return RB_DrawTextLength( text, scale, len );
}
/*
================
idRenderWorldLocal::DrawText
oriented on the viewaxis
align can be 0-left, 1-center (default), 2-right
================
*/
void idRenderWorldLocal::DrawText( const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align, const int lifetime, const bool depthTest ) {
RB_AddDebugText( text, origin, scale, color, viewAxis, align, lifetime, depthTest );
}
/*
===============
idRenderWorldLocal::RegenerateWorld
===============
*/
void idRenderWorldLocal::RegenerateWorld() {
R_RegenerateWorld_f( idCmdArgs() );
}
/*
===============
R_GlobalShaderOverride
===============
*/
bool R_GlobalShaderOverride( const idMaterial **shader ) {
if ( !(*shader)->IsDrawn() ) {
return false;
}
if ( tr.primaryRenderView.globalMaterial ) {
*shader = tr.primaryRenderView.globalMaterial;
return true;
}
if ( r_materialOverride.GetString()[0] != '\0' ) {
*shader = declManager->FindMaterial( r_materialOverride.GetString() );
return true;
}
return false;
}
/*
===============
R_RemapShaderBySkin
===============
*/
const idMaterial *R_RemapShaderBySkin( const idMaterial *shader, const idDeclSkin *skin, const idMaterial *customShader ) {
if ( !shader ) {
return NULL;
}
// never remap surfaces that were originally nodraw, like collision hulls
if ( !shader->IsDrawn() ) {
return shader;
}
if ( customShader ) {
// this is sort of a hack, but cause deformed surfaces to map to empty surfaces,
// so the item highlight overlay doesn't highlight the autosprite surface
if ( shader->Deform() ) {
return NULL;
}
return const_cast<idMaterial *>(customShader);
}
if ( !skin || !shader ) {
return const_cast<idMaterial *>(shader);
}
return skin->RemapShaderBySkin( shader );
}
|