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
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>landscape.cpp</h1><a href="landscape_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027
00028
00029 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="bsphere_8h.html">nel/misc/bsphere.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="texture__file_8h.html">3d/texture_file.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="texture__far_8h.html">3d/texture_far.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="landscape__profile_8h.html">3d/landscape_profile.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="height__map_8h.html">nel/3d/height_map.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="tile__noise__map_8h.html">3d/tile_noise_map.h</a>"</font>
00036 <font class="preprocessor">#include "<a class="code" href="vegetable__manager_8h.html">3d/vegetable_manager.h</a>"</font>
00037 <font class="preprocessor">#include "<a class="code" href="vegetable_8h.html">3d/vegetable.h</a>"</font>
00038 <font class="preprocessor">#include "<a class="code" href="landscape__vegetable__block_8h.html">3d/landscape_vegetable_block.h</a>"</font>
00039 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
00040 <font class="preprocessor">#include "<a class="code" href="tile__vegetable__desc_8h.html">3d/tile_vegetable_desc.h</a>"</font>
00041 <font class="preprocessor">#include "<a class="code" href="texture__dlm_8h.html">3d/texture_dlm.h</a>"</font>
00042 <font class="preprocessor">#include "<a class="code" href="patchdlm__context_8h.html">3d/patchdlm_context.h</a>"</font>
00043 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font>
00044
00045
00046 <font class="preprocessor">#include "<a class="code" href="vertex__program_8h.html">3d/vertex_program.h</a>"</font>
00047
00048
00049
00050 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00051 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00052
00053
00054 <font class="keyword">namespace </font>NL3D
00055 {
00056
00057
00058 <font class="comment">// ***************************************************************************</font>
00059 <font class="comment">/* </font>
00060 <font class="comment"> Target is 20K faces in frustum.</font>
00061 <font class="comment"> So 80K faces at same time</font>
00062 <font class="comment"> So 160K elements (bin tree).</font>
00063 <font class="comment"> A good BlockSize (in my opinion) is EstimatedMaxSize / 10, to have less memory leak as possible,</font>
00064 <font class="comment"> and to make not so many system allocation.</font>
00065 <font class="comment"></font>
00066 <font class="comment"> NL3D_TESSRDR_ALLOC_BLOCKSIZE is 2 times less, because elements are in Far zone or in Near zone only</font>
00067 <font class="comment"> (approx same size...)</font>
00068 <font class="comment">*/</font>
<a name="l00069"></a><a class="code" href="landscape_8cpp.html#a0">00069</a> <font class="preprocessor">#define NL3D_TESS_ALLOC_BLOCKSIZE 16000</font>
<a name="l00070"></a><a class="code" href="landscape_8cpp.html#a1">00070</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_TESSRDR_ALLOC_BLOCKSIZE 8000</font>
00071 <font class="preprocessor"></font>
00072
00073 <font class="comment">// ***************************************************************************</font>
00074 <font class="comment">// This value is important for the precision of the priority list</font>
<a name="l00075"></a><a class="code" href="landscape_8cpp.html#a2">00075</a> <font class="preprocessor">#define NL3D_REFINE_PLIST_DIST_STEP 0.0625</font>
00076 <font class="preprocessor"></font><font class="comment">/* This value is important, because faces will be inserted at maximum at this entry in the priority list.</font>
00077 <font class="comment"> If not so big (eg 50 meters), a big bunch of faces may be inserted in this entry, which may cause slow down</font>
00078 <font class="comment"> sometimes, when all this bunch comes to 0 in the priority list.</font>
00079 <font class="comment"> To avoid such a thing, see CTessFacePriorityList::init(), and use of NL3D_REFINE_PLIST_DIST_MAX_MOD.</font>
00080 <font class="comment"> Here, distMax= 2048*0.0625= 128</font>
00081 <font class="comment">*/</font>
<a name="l00082"></a><a class="code" href="landscape_8cpp.html#a3">00082</a> <font class="preprocessor">#define NL3D_REFINE_PLIST_NUM_ENTRIES 2048</font>
<a name="l00083"></a><a class="code" href="landscape_8cpp.html#a4">00083</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_REFINE_PLIST_DIST_MAX_MOD 0.7f</font>
00084 <font class="preprocessor"></font><font class="comment">// For the Split priority list only, numbers of quadrants. MergeList has 0 quadrants.</font>
<a name="l00085"></a><a class="code" href="landscape_8cpp.html#a5">00085</a> <font class="preprocessor">#define NL3D_REFINE_PLIST_SPLIT_NUMQUADRANT 16</font>
00086 <font class="preprocessor"></font>
00087
00088 <font class="comment">/*</font>
00089 <font class="comment"> OverHead size of one RollingTable of priority list is 8 * (NL3D_REFINE_PLIST_NUM_ENTRIES)</font>
00090 <font class="comment"> So here, it is "only" 16K.</font>
00091 <font class="comment"></font>
00092 <font class="comment"> Since we have 2 Priority list and 16 quadrants for the split one, the total overhead is 18*12.8= 288K</font>
00093 <font class="comment">*/</font>
00094
00095
00096 <font class="comment">// ***************************************************************************</font>
00097 <font class="comment">// Size (in cases) of the quadgrid. must be e power of 2.</font>
<a name="l00098"></a><a class="code" href="classNL3D_1_1CLandscape.html#z493_3">00098</a> <font class="keyword">const</font> uint CLandscape::_PatchQuadGridSize= 128;
00099 <font class="comment">// Size of a case of the quadgrid.</font>
<a name="l00100"></a><a class="code" href="classNL3D_1_1CLandscape.html#z493_4">00100</a> <font class="keyword">const</font> <font class="keywordtype">float</font> CLandscape::_PatchQuadGridEltSize= 16;
00101
00102
00103 <font class="comment">// ***************************************************************************</font>
00104
00105 <font class="comment">// Bitmap Cross</font>
00106
<a name="l00107"></a><a class="code" href="classNL3D_1_1CTextureCross.html">00107</a> <font class="keyword">class </font>CTextureCross : <font class="keyword">public</font> ITexture
00108 {
00109 <font class="keyword">public</font>:
<a name="l00115"></a><a class="code" href="classNL3D_1_1CTextureCross.html#a0">00115</a> <font class="keyword">virtual</font> <font class="keywordtype">void</font> <a class="code" href="classNL3D_1_1CTextureCross.html#a0">doGenerate</a>()
00116 {
00117 <font class="comment">// Resize</font>
00118 <a class="code" href="classNLMISC_1_1CBitmap.html#a15">resize</a> (16, 16);
00119
00120 <font class="comment">// Cross</font>
00121 <font class="keyword">static</font> <font class="keyword">const</font> uint32 cross[16*16]=
00122 {
00123 <font class="comment">// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15</font>
00124 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
00125 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00126 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00127 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00128 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00129 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00130 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00131 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00132 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00133 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00134 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00135 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00136 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00137 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00138 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffffffff,
00139 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
00140 };
00141
00142 <font class="comment">// Null</font>
00143 memcpy (&<a class="code" href="classNLMISC_1_1CBitmap.html#n0">_Data</a>[0][0], cross, 16*16*4);
00144 }
00145
00146 <font class="comment">// Dummy serial...</font>
<a name="l00147"></a><a class="code" href="classNL3D_1_1CTextureCross.html#a1">00147</a> <font class="keyword">virtual</font> <font class="keywordtype">void</font> <a class="code" href="classNL3D_1_1CTextureCross.html#a1">serial</a>(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) <font class="keywordflow">throw</font>(NLMISC::EStream) {<a class="code" href="debug_8h.html#a12">nlstop</a>;}
00148 <a class="code" href="classNL3D_1_1CTextureCross.html#a2">NLMISC_DECLARE_CLASS</a>(CTextureCross);
00149 };
00150
00151
00152 <font class="comment">// ***************************************************************************</font>
<a name="l00153"></a><a class="code" href="structNL3D_1_1EBadBind.html#a2">00153</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *EBadBind::what() <font class="keyword">const</font> <font class="keywordflow">throw</font>()
00154 {
00155 sint numErr= 0;
00156 <font class="keyword">const</font> sint NErrByLines= 4;
00157
00158 _Output= <font class="stringliteral">"Landscape Bind Error in (3DSMax indices!! (+1) ): "</font>;
00159
00160 <a class="code" href="classstd_1_1list.html">std::list<CBindError></a>::const_iterator it;
00161 <font class="keywordflow">for</font>(it= BindErrors.begin();it!=BindErrors.end(); it++, numErr++)
00162 {
00163 <font class="keywordtype">char</font> tmp[256];
00164 sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= it->ZoneId & 255;
00165 sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= it->ZoneId >> 8;
00166 sprintf(tmp, <font class="stringliteral">"zone%3d_%c%c.patch%3d; "</font>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1, (<font class="keywordtype">char</font>)(<font class="charliteral">'A'</font>+(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>/26)), (<font class="keywordtype">char</font>)(<font class="charliteral">'A'</font>+(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>%26)), it->PatchId+1);
00167 <font class="keywordflow">if</font>( (numErr%NErrByLines) == 0)
00168 _Output+= <font class="stringliteral">"\n"</font>;
00169 _Output+= tmp;
00170 }
00171 <font class="keywordflow">return</font> _Output.c_str();
00172 }
00173
00174
00175 <font class="comment">// ***************************************************************************</font>
00176 <font class="comment">// Init BlockAllcoator with standard BlockMemory.</font>
<a name="l00177"></a><a class="code" href="classNL3D_1_1CLandscape.html#a0">00177</a> CLandscape::CLandscape() :
00178 TessFaceAllocator(<a class="code" href="landscape_8cpp.html#a0">NL3D_TESS_ALLOC_BLOCKSIZE</a>),
00179 TessVertexAllocator(<a class="code" href="landscape_8cpp.html#a0">NL3D_TESS_ALLOC_BLOCKSIZE</a>),
00180 TessNearVertexAllocator(<a class="code" href="landscape_8cpp.html#a1">NL3D_TESSRDR_ALLOC_BLOCKSIZE</a>),
00181 TessFarVertexAllocator(<a class="code" href="landscape_8cpp.html#a1">NL3D_TESSRDR_ALLOC_BLOCKSIZE</a>),
00182 TileMaterialAllocator(<a class="code" href="landscape_8cpp.html#a1">NL3D_TESSRDR_ALLOC_BLOCKSIZE</a>),
00183 TileFaceAllocator(<a class="code" href="landscape_8cpp.html#a1">NL3D_TESSRDR_ALLOC_BLOCKSIZE</a>),
00184 _Far0VB(CLandscapeVBAllocator::Far0),
00185 _Far1VB(CLandscapeVBAllocator::Far1),
00186 _TileVB(CLandscapeVBAllocator::Tile)
00187 {
00188 <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>.resize(NL3D::NbTilesMax);
00189
00190 <font class="comment">// Resize the vectors of sert of render pass for the far texture</font>
00191 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>.resize (<a class="code" href="classNL3D_1_1CLandscape.html#f0">getRdrPassIndexWithSize</a> (<a class="code" href="landscape_8h.html#a1">NL_MAX_SIZE_OF_TEXTURE_EDGE</a>, <a class="code" href="landscape_8h.html#a1">NL_MAX_SIZE_OF_TEXTURE_EDGE</a>)+1);
00192
00193 <font class="comment">// Far texture not initialized till initTileBanks is not called</font>
00194 <a class="code" href="classNL3D_1_1CLandscape.html#o16">_FarInitialized</a>=<font class="keyword">false</font>;
00195
00196 <font class="comment">// Init far lighting with White/black</font>
00197 <a class="code" href="classNL3D_1_1CLandscape.html#z483_0">setupStaticLight</a> (CRGBA(255,255,255), CRGBA(0,0,0), 1.f);
00198 <font class="comment">// Default material for pointLights</font>
00199 <a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>= CRGBA::White;
00200
00201
00202 fill(<a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>.begin(), <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>.end(), (CTileInfo*)NULL);
00203
00204 <a class="code" href="classNL3D_1_1CLandscape.html#o4">_FarTransition</a>= 10; <font class="comment">// 10 meters.</font>
00205 <a class="code" href="classNL3D_1_1CLandscape.html#o1">_TileDistNear</a>=100.f;
00206 <a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a>= 0.001f;
00207 <a class="code" href="classNL3D_1_1CLandscape.html#o3">_RefineMode</a>=<font class="keyword">true</font>;
00208
00209 <a class="code" href="classNL3D_1_1CLandscape.html#o5">_TileMaxSubdivision</a>= 0;
00210
00211 <a class="code" href="classNL3D_1_1CLandscape.html#o11">_NFreeLightMaps</a>= 0;
00212
00213 <font class="comment">// By default Automatic light comes from up.</font>
00214 <a class="code" href="classNL3D_1_1CLandscape.html#o18">_AutomaticLighting</a> = <font class="keyword">false</font>;
00215 <a class="code" href="classNL3D_1_1CLandscape.html#o19">_AutomaticLightDir</a>= -CVector::K;
00216
00217 <font class="comment">// By default, noise is enabled.</font>
00218 <a class="code" href="classNL3D_1_1CLandscape.html#z494_0">_NoiseEnabled</a>= <font class="keyword">true</font>;
00219
00220 <font class="comment">// By default, we compute Geomorph and Alpha in software.</font>
00221 <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>= <font class="keyword">false</font>;
00222 <a class="code" href="classNL3D_1_1CLandscape.html#o6">_VPThresholdChange</a>= <font class="keyword">false</font>;
00223
00224 <a class="code" href="classNL3D_1_1CLandscape.html#z491_5">_RenderMustRefillVB</a>= <font class="keyword">false</font>;
00225
00226 <font class="comment">// priority list.</font>
00227 <a class="code" href="classNL3D_1_1CLandscape.html#z495_3">_OldRefineCenterSetuped</a>= <font class="keyword">false</font>;
00228 <a class="code" href="classNL3D_1_1CLandscape.html#z495_0">_SplitPriorityList</a>.init(<a class="code" href="landscape_8cpp.html#a2">NL3D_REFINE_PLIST_DIST_STEP</a>, <a class="code" href="landscape_8cpp.html#a3">NL3D_REFINE_PLIST_NUM_ENTRIES</a>, <a class="code" href="landscape_8cpp.html#a4">NL3D_REFINE_PLIST_DIST_MAX_MOD</a>, <a class="code" href="landscape_8cpp.html#a5">NL3D_REFINE_PLIST_SPLIT_NUMQUADRANT</a>);
00229 <font class="comment">// See updateRefine* Doc in tesselation.cpp for why the merge list do not need quadrants.</font>
00230 <a class="code" href="classNL3D_1_1CLandscape.html#z495_1">_MergePriorityList</a>.init(<a class="code" href="landscape_8cpp.html#a2">NL3D_REFINE_PLIST_DIST_STEP</a>, <a class="code" href="landscape_8cpp.html#a3">NL3D_REFINE_PLIST_NUM_ENTRIES</a>, <a class="code" href="landscape_8cpp.html#a4">NL3D_REFINE_PLIST_DIST_MAX_MOD</a>, 0);
00231 <font class="comment">// just for getTesselatedPos to work properly.</font>
00232 <a class="code" href="classNL3D_1_1CLandscape.html#z495_2">_OldRefineCenter</a>= CVector::Null;
00233
00234 <font class="comment">// create / Init the vegetable manager.</font>
00235 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>= <font class="keyword">new</font> CVegetableManager(<a class="code" href="landscape__def_8h.html#a8">NL3D_LANDSCAPE_VEGETABLE_MAX_AGP_VERTEX_UNLIT</a>, <a class="code" href="landscape__def_8h.html#a9">NL3D_LANDSCAPE_VEGETABLE_MAX_AGP_VERTEX_LIGHTED</a>);
00236
00237 <font class="comment">// Init vegetable setup.</font>
00238 <a class="code" href="classNL3D_1_1CLandscape.html#z496_2">_VegetableManagerEnabled</a>= <font class="keyword">false</font>;
00239 <a class="code" href="classNL3D_1_1CLandscape.html#z496_3">_DriverOkForVegetable</a>= <font class="keyword">false</font>;
00240 <font class="comment">// default global vegetable color, used for dynamic lighting only (arbitrary).</font>
00241 <a class="code" href="classNL3D_1_1CLandscape.html#z499_5">_DLMGlobalVegetableColor</a>.set(180, 180, 180);
00242
00243 <a class="code" href="classNL3D_1_1CLandscape.html#z497_0">_PZBModelPosition</a>= CVector::Null;
00244
00245
00246 <font class="comment">// Default: no updateLighting.</font>
00247 <a class="code" href="classNL3D_1_1CLandscape.html#z498_7">_ULFrequency</a>= 0;
00248 <a class="code" href="classNL3D_1_1CLandscape.html#z498_5">_ULPrecTimeInit</a>= <font class="keyword">false</font>;
00249 <font class="comment">// Default: no textureFar created.</font>
00250 <a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>= 0;
00251 <a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a>= 0;
00252 <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>= NULL;
00253 <a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>= 0;
00254 <font class="comment">// Default: no patch created</font>
00255 <a class="code" href="classNL3D_1_1CLandscape.html#z498_12">_ULTotalNearPixels</a>= 0;
00256 <a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a>= 0;
00257 <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>= NULL;
00258 <a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>= 0;
00259
00260
00261 <font class="comment">// Dynamic Lighting.</font>
00262 <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>= <font class="keyword">new</font> CTextureDLM(<a class="code" href="landscape__def_8h.html#a13">NL3D_LANDSCAPE_DLM_WIDTH</a>, <a class="code" href="landscape__def_8h.html#a14">NL3D_LANDSCAPE_DLM_HEIGHT</a>);
00263 <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>= <font class="keyword">new</font> CPatchDLMContextList;
00264 <a class="code" href="classNL3D_1_1CLandscape.html#z499_4">_DLMMaxAttEnd</a>= 30.f;
00265
00266
00267 <font class="comment">// Alloc some global space for tri rendering.</font>
00268 <font class="keywordflow">if</font>( CLandscapeGlobals::PassTriArray.size() < 1000 )
00269 CLandscapeGlobals::PassTriArray.resize( 1000 );
00270
00271 }
00272 <font class="comment">// ***************************************************************************</font>
<a name="l00273"></a><a class="code" href="classNL3D_1_1CLandscape.html#a1">00273</a> CLandscape::~CLandscape()
00274 {
00275 <a class="code" href="classNL3D_1_1CLandscape.html#z477_3">clear</a>();
00276
00277 <font class="comment">// release the VegetableManager.</font>
00278 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>;
00279 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>= NULL;
00280
00281 <font class="comment">// Dynamic Lighting.</font>
00282 <font class="comment">// smartPtr delete</font>
00283 <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>= NULL;
00284 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>;
00285 <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>= NULL;
00286 }
00287
00288
00289 <font class="comment">// ***************************************************************************</font>
<a name="l00290"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_0">00290</a> <font class="keywordtype">void</font> CLandscape::init()
00291 {
00292 <font class="comment">// Fill Far mat.</font>
00293 <font class="comment">// Must init his BlendFunction here!!! becaus it switch between blend on/off during rendering.</font>
00294 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.initUnlit();
00295 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setSrcBlend(CMaterial::srcalpha);
00296 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setDstBlend(CMaterial::invsrcalpha);
00297
00298 <font class="comment">// FarMaterial: pass trhough Alpha from diffuse.</font>
00299 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvOpAlpha(0, CMaterial::Replace);
00300 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvArg0Alpha(0, CMaterial::Diffuse, CMaterial::SrcAlpha);
00301 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvOpAlpha(1, CMaterial::Replace);
00302 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvArg0Alpha(1, CMaterial::Diffuse, CMaterial::SrcAlpha);
00303 <font class="comment">// FarMaterial: Add RGB from static lightmap and dynamic lightmap</font>
00304 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvOpRGB(0, CMaterial::Replace);
00305 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor);
00306 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvOpRGB(1, CMaterial::Add);
00307 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
00308 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.texEnvArg1RGB(1, CMaterial::Previous, CMaterial::SrcColor);
00309
00310
00311 <font class="comment">// Init material for tile.</font>
00312 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.initUnlit();
00313
00314 <font class="comment">// init quadGrid.</font>
00315 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.create(<a class="code" href="classNL3D_1_1CLandscape.html#z493_3">_PatchQuadGridSize</a>, <a class="code" href="classNL3D_1_1CLandscape.html#z493_4">_PatchQuadGridEltSize</a>);
00316 }
00317
00318
00319 <font class="comment">// ***************************************************************************</font>
<a name="l00320"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_2">00320</a> <font class="keywordtype">void</font> CLandscape::setThreshold (<font class="keywordtype">float</font> thre)
00321 {
00322 thre= max(thre, 0.f);
00323 <font class="keywordflow">if</font>(thre != <a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a>)
00324 {
00325 <a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a>= thre;
00326 <a class="code" href="classNL3D_1_1CLandscape.html#o6">_VPThresholdChange</a>= <font class="keyword">true</font>;
00327 }
00328 }
00329
00330
00331 <font class="comment">// ***************************************************************************</font>
<a name="l00332"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_0">00332</a> <font class="keywordtype">void</font> CLandscape::setTileNear (<font class="keywordtype">float</font> tileNear)
00333 {
00334 tileNear= max(tileNear, <a class="code" href="classNL3D_1_1CLandscape.html#o4">_FarTransition</a>);
00335
00336 <font class="keywordflow">if</font>(tileNear!=<a class="code" href="classNL3D_1_1CLandscape.html#o1">_TileDistNear</a>)
00337 {
00338 <a class="code" href="classNL3D_1_1CLandscape.html#o1">_TileDistNear</a>= tileNear;
00339 <a class="code" href="classNL3D_1_1CLandscape.html#c4">resetRenderFarAndDeleteVBFV</a>();
00340 }
00341
00342 }
00343
00344
00345 <font class="comment">// ***************************************************************************</font>
<a name="l00346"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_6">00346</a> <font class="keywordtype">void</font> CLandscape::setTileMaxSubdivision (uint tileDiv)
00347 {
00348 <a class="code" href="debug_8h.html#a6">nlassert</a>(tileDiv>=0 && tileDiv<=4);
00349
00350 <font class="keywordflow">if</font>(tileDiv!=<a class="code" href="classNL3D_1_1CLandscape.html#o5">_TileMaxSubdivision</a>)
00351 {
00352 <a class="code" href="classNL3D_1_1CLandscape.html#o5">_TileMaxSubdivision</a>= tileDiv;
00353 <font class="comment">// Force at Tile==0. Nex refine will split correctly.</font>
00354 <a class="code" href="classNL3D_1_1CLandscape.html#c5">forceMergeAtTileLevel</a>();
00355 }
00356 }
00357 <font class="comment">// ***************************************************************************</font>
<a name="l00358"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_7">00358</a> uint CLandscape::getTileMaxSubdivision ()
00359 {
00360 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#o5">_TileMaxSubdivision</a>;
00361 }
00362
00363
00364 <font class="comment">// ***************************************************************************</font>
<a name="l00365"></a><a class="code" href="classNL3D_1_1CLandscape.html#c4">00365</a> <font class="keywordtype">void</font> CLandscape::resetRenderFarAndDeleteVBFV()
00366 {
00367 <font class="comment">// For all patch of all zones.</font>
00368 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00369 {
00370 ((*it).second)->resetRenderFarAndDeleteVBFV();
00371 }
00372 }
00373
00374
00375 <font class="comment">// ***************************************************************************</font>
<a name="l00376"></a><a class="code" href="classNL3D_1_1CLandscape.html#c5">00376</a> <font class="keywordtype">void</font> CLandscape::forceMergeAtTileLevel()
00377 {
00378 <font class="comment">// For all patch of all zones.</font>
00379 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00380 {
00381 ((*it).second)->forceMergeAtTileLevel();
00382 }
00383 }
00384
00385
00386 <font class="comment">// ***************************************************************************</font>
<a name="l00387"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_1">00387</a> <font class="keywordtype">bool</font> CLandscape::addZone(<font class="keyword">const</font> CZone &newZone)
00388 {
00389 <font class="comment">// -1. Update globals</font>
00390 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (CVector::Null);
00391 <font class="comment">// NB: adding a zone may add vertices in VB in visible patchs (because of binds)=> buffers are locked.</font>
00392
00393 uint16 zoneId= newZone.getZoneId();
00394
00395 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId)!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
00396 {
00397 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00398 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00399 }
00400 <a class="code" href="classNL3D_1_1CLandscape.html#l2">CZone</a> *zone= <font class="keyword">new</font> <a class="code" href="classNL3D_1_1CLandscape.html#l2">CZone</a>;
00401
00402 <font class="comment">// copy zone.</font>
00403 zone->build(newZone);
00404
00405 <font class="comment">// Affect the current lighting of pointLight to the zone.</font>
00406 <a class="code" href="classNL3D_1_1CLandscape.html#u10">ItLightGroupColorMap</a> itLGC= <a class="code" href="classNL3D_1_1CLandscape.html#o20">_LightGroupColorMap</a>.begin();
00407 <font class="keywordflow">while</font>( itLGC != <a class="code" href="classNL3D_1_1CLandscape.html#o20">_LightGroupColorMap</a>.end() )
00408 {
00409 zone->_PointLightArray.setPointLightFactor(itLGC->first, itLGC->second);
00410 itLGC++;
00411 }
00412
00413
00414 <font class="comment">// apply the landscape heightField, modifying BBoxes.</font>
00415 zone->applyHeightField(*<font class="keyword">this</font>);
00416
00417 <font class="comment">// compile the zone for this landscape.</font>
00418 zone->compile(<font class="keyword">this</font>, <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>);
00419
00420 <font class="comment">// For test of _PatchQuadGrid erase.</font>
00421 CAABBox zoneBBForErase= zone->getZoneBB().getAABBox();
00422 <font class="comment">// Avoid precision problems by enlarging a little bbox size of zone for erase</font>
00423 zoneBBForErase.setHalfSize( zoneBBForErase.getHalfSize() * 1.1f);
00424
00425 <font class="comment">// add patchs of this zone to the quadgrid.</font>
00426 <font class="keywordflow">for</font>(sint i= 0; i<zone->getNumPatchs(); i++)
00427 {
00428 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= ((<font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l2">CZone</a>*)zone)->getPatch(i);
00429 CPatchIdentEx paId;
00430 paId.ZoneId= zoneId;
00431 paId.PatchId= i;
00432 paId.Patch= pa;
00433 CAABBox bb= pa->buildBBox();
00434 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.insert(bb.getMin(), bb.getMax(), paId);
00435 <font class="comment">// NB: the bbox of zone is used to remove patch. Hence it is VERY important that zoneBBox includes</font>
00436 <font class="comment">// all patchs bbox (else some patchs entries may not be deleted in removeZone()).</font>
00437 <a class="code" href="debug_8h.html#a6">nlassert</a>(zoneBBForErase.include(bb));
00438 }
00439
00440 <font class="comment">// Must realase VB Buffers</font>
00441 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00442
00443 <font class="comment">// Because bind may add faces in other (visible) zones because of enforced split, we must check</font>
00444 <font class="comment">// and update any FaceVector.</font>
00445 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00446
00447 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00448 }
00449 <font class="comment">// ***************************************************************************</font>
<a name="l00450"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_2">00450</a> <font class="keywordtype">bool</font> CLandscape::removeZone(uint16 zoneId)
00451 {
00452 <font class="comment">// -1. Update globals</font>
00453 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (CVector::Null);
00454 <font class="comment">// NB: remove a zone may change vertices in VB in visible patchs => buffers are locked.</font>
00455
00456 <font class="comment">// find the zone.</font>
00457 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId)==<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
00458 {
00459 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00460 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00461 }
00462 <a class="code" href="classNL3D_1_1CLandscape.html#l2">CZone</a> *zone= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>[zoneId];
00463
00464
00465 <font class="comment">// delete patchs from this zone to the quadgrid.</font>
00466 <font class="comment">// use the quadgrid itself to find where patch are. do this using bbox of zone.</font>
00467 CAABBox zoneBBForErase= zone->getZoneBB().getAABBox();
00468 <font class="comment">// Avoid precision problems by enlarging a little bbox size of zone for erase</font>
00469 zoneBBForErase.setHalfSize( zoneBBForErase.getHalfSize() * 1.1f);
00470 <font class="comment">// select iterators in the area of this zone.</font>
00471 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.clearSelection();
00472 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.select(zoneBBForErase.getMin(), zoneBBForErase.getMax());
00473 <font class="comment">// for each patch, remove it if from deleted zone.</font>
00474 CQuadGrid<CPatchIdentEx>::CIterator it;
00475 sint nPatchRemoved= 0;
00476 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.begin(); it!= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.end();)
00477 {
00478 <font class="comment">// if the patch belong to the zone to remove</font>
00479 <font class="keywordflow">if</font>( (*it).ZoneId== zone->getZoneId() )
00480 {
00481 <font class="comment">// remove from the quadgrid.</font>
00482 it= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.erase(it);
00483 nPatchRemoved++;
00484 }
00485 <font class="keywordflow">else</font>
00486 it++;
00487 }
00488 <font class="comment">// verify we have removed all patch in the quadGrid for this zone</font>
00489 <a class="code" href="debug_8h.html#a6">nlassert</a>(nPatchRemoved==zone->getNumPatchs());
00490
00491
00492 <font class="comment">// remove the zone.</font>
00493 zone->release(<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>);
00494 <font class="keyword">delete</font> zone;
00495
00496 <font class="comment">// Must realase VB Buffers</font>
00497 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00498
00499 <font class="comment">// because of forceMerge() at unbind, removeZone() can cause change in faces in other (visible) zones.</font>
00500 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00501
00502 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00503 }
00504 <font class="comment">// ***************************************************************************</font>
<a name="l00505"></a><a class="code" href="classNL3D_1_1CLandscape.html#z481_2">00505</a> <font class="keywordtype">void</font> CLandscape::getZoneList(std::vector<uint16> &zoneIds)<font class="keyword"> const</font>
00506 <font class="keyword"></font>{
00507 zoneIds.clear();
00508 zoneIds.reserve(<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.size());
00509 std::map<uint16, CZone*>::const_iterator it;
00510 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00511 {
00512 zoneIds.push_back((*it).first);
00513 }
00514 }
00515 <font class="comment">// ***************************************************************************</font>
<a name="l00516"></a><a class="code" href="classNL3D_1_1CLandscape.html#z481_3">00516</a> <font class="keywordtype">void</font> CLandscape::buildZoneName(sint zoneId, std::string &zoneName)
00517 {
00518 <font class="keywordtype">char</font> tmp[256];
00519 sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= zoneId & 255;
00520 sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= zoneId >> 8;
00521 sprintf(tmp, <font class="stringliteral">"%d_%c%c"</font>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1, (<font class="keywordtype">char</font>)(<font class="charliteral">'A'</font>+(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>/26)), (<font class="keywordtype">char</font>)(<font class="charliteral">'A'</font>+(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>%26)));
00522 zoneName= tmp;
00523 }
00524 <font class="comment">// ***************************************************************************</font>
<a name="l00525"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_3">00525</a> <font class="keywordtype">void</font> CLandscape::clear()
00526 {
00527 <font class="comment">// Build the list of zoneId.</font>
00528 vector<uint16> zoneIds;
00529 <a class="code" href="classNL3D_1_1CLandscape.html#z481_2">getZoneList</a>(zoneIds);
00530
00531 <font class="comment">// Remove each zone one by one.</font>
00532 sint i;
00533 <font class="keywordflow">for</font>(i=0;i<(sint)zoneIds.size();i++)
00534 {
00535 <a class="code" href="debug_8h.html#a9">nlverify</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z477_2">removeZone</a>(zoneIds[i]));
00536 }
00537
00538 <font class="comment">// ensure the quadgrid is empty.</font>
00539 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.clear();
00540
00541
00542 <font class="comment">// If not done, delete all VBhards allocated.</font>
00543 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.clear();
00544 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.clear();
00545 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.clear();
00546
00547
00548 <font class="comment">// Reset All Far Texture and unlink _ULRootTextureFar ciruclarList.</font>
00549 <font class="comment">// First "free" the Free list. </font>
00550 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>.size();i++)
00551 {
00552 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[i].clear();
00553 }
00554 <font class="comment">// Then free all Far RdrPass.</font>
00555 <a class="code" href="classNL3D_1_1CLandscape.html#u7">ItSPRenderPassSet</a> itFar;
00556 <font class="comment">// unitl set is empty</font>
00557 <font class="keywordflow">while</font>( (itFar= <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.begin()) != <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.end())
00558 {
00559 <font class="comment">// erase with link update.</font>
00560 <a class="code" href="classNL3D_1_1CLandscape.html#c11">eraseFarRenderPassFromSet</a>(*itFar);
00561 }
00562
00563
00564 <font class="comment">// reset driver.</font>
00565 <a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>= NULL;
00566 }
00567
00568 <font class="comment">// ***************************************************************************</font>
<a name="l00569"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_0">00569</a> <font class="keywordtype">void</font> CLandscape::setDriver(IDriver *drv)
00570 {
00571 <a class="code" href="debug_8h.html#a6">nlassert</a>(drv);
00572 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a> != drv)
00573 {
00574 <a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>= drv;
00575
00576 <font class="comment">// Does the driver support VertexShader???</font>
00577 <font class="comment">// only if VP supported by GPU.</font>
00578 <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>= (<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>->isVertexProgramSupported() && !<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>->isVertexProgramEmulated());
00579
00580
00581 <font class="comment">// Does the driver has sufficient requirements for Vegetable???</font>
00582 <font class="comment">// only if VP supported by GPU, and Only if max vertices allowed.</font>
00583 <a class="code" href="classNL3D_1_1CLandscape.html#z496_3">_DriverOkForVegetable</a>= <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a> && (<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>->getMaxVerticesByVertexBufferHard()>=(uint)<a class="code" href="landscape__def_8h.html#a10">NL3D_LANDSCAPE_VEGETABLE_MAX_AGP_VERTEX_MAX</a>);
00584
00585 }
00586 }
00587
00588 <font class="comment">// ***************************************************************************</font>
<a name="l00589"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_1">00589</a> <font class="keywordtype">void</font> CLandscape::clip(<font class="keyword">const</font> CVector &refineCenter, <font class="keyword">const</font> std::vector<CPlane> &pyramid)
00590 {
00591 <font class="comment">// -1. Update globals</font>
00592 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (refineCenter);
00593 <font class="comment">// NB: clip may add/remove vertices in VB in visible patchs => buffers are locked.</font>
00594
00595
00596 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00597 {
00598 (*it).second->clip(pyramid);
00599 }
00600
00601 <font class="comment">// Must realase VB Buffers</font>
00602 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00603
00604 <font class="comment">// clip() should not cause change in faces in visible patchs.</font>
00605 <font class="comment">// It should not happens, but check for security.</font>
00606 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z490_19">_TessBlockModificationRoot</a>.getNextToModify()==NULL);
00607 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00608
00609 }
00610 <font class="comment">// ***************************************************************************</font>
<a name="l00611"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_2">00611</a> <font class="keywordtype">void</font> CLandscape::refine(<font class="keyword">const</font> CVector &refineCenter)
00612 {
00613 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a77">ProfNRefineFaces</a>, 0);
00614 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a78">ProfNRefineComputeFaces</a>, 0);
00615 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a79">ProfNRefineLeaves</a>, 0);
00616 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a80">ProfNSplits</a>, 0);
00617 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a81">ProfNMerges</a>, 0);
00618 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a82">ProfNRefineInTileTransition</a>, 0);
00619 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a83">ProfNRefineWithLowDistance</a>, 0);
00620 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a84">ProfNSplitsPass</a>, 0);
00621
00622 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#o3">_RefineMode</a>)
00623 <font class="keywordflow">return</font>;
00624
00625 <font class="comment">// Update the priority list.</font>
00626 <font class="comment">// ==========================</font>
00627 CTessFacePListNode rootSplitTessFaceToUpdate;
00628 CTessFacePListNode rootMergeTessFaceToUpdate;
00629 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CLandscape.html#z495_3">_OldRefineCenterSetuped</a> )
00630 {
00631 <font class="comment">// If never refine, and setup OldRefineCetner</font>
00632 <a class="code" href="classNL3D_1_1CLandscape.html#z495_3">_OldRefineCenterSetuped</a>= <font class="keyword">true</font>;
00633 <a class="code" href="classNL3D_1_1CLandscape.html#z495_2">_OldRefineCenter</a>= refineCenter;
00634
00635 <font class="comment">// then shift all faces</font>
00636 <a class="code" href="classNL3D_1_1CLandscape.html#z495_0">_SplitPriorityList</a>.shiftAll(rootSplitTessFaceToUpdate);
00637 <a class="code" href="classNL3D_1_1CLandscape.html#z495_1">_MergePriorityList</a>.shiftAll(rootMergeTessFaceToUpdate);
00638 }
00639 <font class="keywordflow">else</font>
00640 {
00641 <font class="comment">// else, compute delta between positions</font>
00642 CVector diff= refineCenter - <a class="code" href="classNL3D_1_1CLandscape.html#z495_2">_OldRefineCenter</a>;
00643 <a class="code" href="classNL3D_1_1CLandscape.html#z495_2">_OldRefineCenter</a>= refineCenter;
00644
00645 <font class="comment">// and shift according to distance of deplacement.</font>
00646 <a class="code" href="classNL3D_1_1CLandscape.html#z495_0">_SplitPriorityList</a>.shift(diff, rootSplitTessFaceToUpdate);
00647 <a class="code" href="classNL3D_1_1CLandscape.html#z495_1">_MergePriorityList</a>.shift(diff, rootMergeTessFaceToUpdate);
00648 }
00649
00650
00651 <font class="comment">// Refine Faces which may need it.</font>
00652 <font class="comment">// ==========================</font>
00653 <font class="comment">// Update globals</font>
00654 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (refineCenter);
00655 <font class="comment">// NB: refine may change vertices in VB in visible patchs => buffers are locked.</font>
00656
00657 <font class="comment">// Increment the update date.</font>
00658 CLandscapeGlobals::CurrentDate++;
00659
00660 <font class="comment">// Because CTessFacePriorityList::insert use it.</font>
00661 <a class="code" href="namespaceNL3D.html#a360">OptFastFloorBegin</a>();
00662
00663 <font class="comment">/* While there is still face in list, update them</font>
00664 <font class="comment"> NB: updateRefine() always insert the face in _***PriorityList, so face is removed from </font>
00665 <font class="comment"> root***TessFaceToUpdate list.</font>
00666 <font class="comment"> NB: it is possible ( with enforced merge() ) that faces dissapears from root***TessFaceToUpdate list </font>
00667 <font class="comment"> before they are traversed here. It is why we must use a Circular list system, and not an array of elements.</font>
00668 <font class="comment"> Basically. TessFaces are ALWAYS in a list, either in one of the entry list in _***PriorityList, or in</font>
00669 <font class="comment"> root***TessFaceToUpdate list.</font>
00670 <font class="comment"></font>
00671 <font class="comment"> It is newTessFace() and deleteTessFace() which insert/remove the nodes in the list.</font>
00672 <font class="comment"> */</font>
00673 <font class="comment">// Update the Merge priority list.</font>
00674 <font class="keywordflow">while</font>( rootMergeTessFaceToUpdate.nextInPList() != &rootMergeTessFaceToUpdate )
00675 {
00676 <font class="comment">// Get the face.</font>
00677 <a class="code" href="classNL3D_1_1CLandscape.html#l0">CTessFace</a> *face= static_cast<CTessFace*>(rootMergeTessFaceToUpdate.nextInPList());
00678
00679 <font class="comment">// update the refine of this face. This may lead in deletion (merge) of other faces which are still in </font>
00680 <font class="comment">// root***TessFaceToUpdate, but it's work.</font>
00681 face->updateRefineMerge();
00682 }
00683
00684
00685 <font class="comment">// Update the Split priority list.</font>
00686 <font class="keywordflow">do</font>
00687 {
00688 <a class="code" href="landscape__profile_8h.html#a2">NL3D_PROFILE_LAND_ADD</a>(<a class="code" href="namespaceNL3D.html#a84">ProfNSplitsPass</a>, 1);
00689
00690 <font class="comment">// Append the new leaves, to the list of triangles to update</font>
00691 rootSplitTessFaceToUpdate.appendPList(<a class="code" href="classNL3D_1_1CLandscape.html#z495_4">_RootNewLeaves</a>);
00692
00693 <font class="comment">// While triangle to test for split exists</font>
00694 <font class="keywordflow">while</font>( rootSplitTessFaceToUpdate.nextInPList() != &rootSplitTessFaceToUpdate )
00695 {
00696 <font class="comment">// Get the face.</font>
00697 <a class="code" href="classNL3D_1_1CLandscape.html#l0">CTessFace</a> *face= static_cast<CTessFace*>(rootSplitTessFaceToUpdate.nextInPList());
00698
00699 <font class="comment">// update the refine of this face.</font>
00700 face->updateRefineSplit();
00701 }
00702
00703 }
00704 <font class="comment">// do it until we are sure no more split is needed, ie no more faces are created</font>
00705 <font class="keywordflow">while</font>( <a class="code" href="classNL3D_1_1CLandscape.html#z495_4">_RootNewLeaves</a>.nextInPList() != &<a class="code" href="classNL3D_1_1CLandscape.html#z495_4">_RootNewLeaves</a> );
00706
00707 <font class="comment">// Because CTessFacePriorityList::insert use it.</font>
00708 <a class="code" href="namespaceNL3D.html#a361">OptFastFloorEnd</a>();
00709
00710
00711 <font class="comment">// Before unlockBuffers, test for vegetable IG creation.</font>
00712 {
00713 <a class="code" href="hierarchical__timer_8h.html#a4">H_AUTO</a>( NL3D_Vegetable_Update );
00714
00715 <font class="comment">// Because CLandscapeVegetableBlock::update() use OptFastFloor..</font>
00716 <a class="code" href="namespaceNL3D.html#a360">OptFastFloorBegin</a>();
00717
00718 <font class="comment">// For each vegetableBlock, test IG creation</font>
00719 CLandscapeVegetableBlock *vegetBlock= <a class="code" href="classNL3D_1_1CLandscape.html#z496_4">_VegetableBlockList</a>.begin();
00720 <font class="keywordflow">for</font>(;vegetBlock!=NULL; vegetBlock= (CLandscapeVegetableBlock*)vegetBlock->Next)
00721 {
00722 vegetBlock->update(refineCenter, <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>);
00723 }
00724
00725 <font class="comment">// update lighting for vegetables</font>
00726 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->updateLighting();
00727
00728 <font class="comment">// Stop fastFloor optim.</font>
00729 <a class="code" href="namespaceNL3D.html#a361">OptFastFloorEnd</a>();
00730 }
00731
00732
00733 <font class="comment">// Must realase VB Buffers</font>
00734 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00735
00736 <font class="comment">// refine() may cause change in faces in visible patchs.</font>
00737 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00738
00739 }
00740
00741
00742 <font class="comment">// ***************************************************************************</font>
<a name="l00743"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_4">00743</a> <font class="keywordtype">void</font> CLandscape::refineAll(<font class="keyword">const</font> CVector &refineCenter)
00744 {
00745 <font class="comment">// -1. Update globals</font>
00746 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (refineCenter);
00747 <font class="comment">// NB: refineAll may change vertices in VB in visible patchs => buffers are locked.</font>
00748
00749 <font class="comment">// Increment the update date.</font>
00750 CLandscapeGlobals::CurrentDate++;
00751
00752 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00753 {
00754 (*it).second->refineAll();
00755 }
00756
00757 <font class="comment">// Must realase VB Buffers</font>
00758 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00759
00760 <font class="comment">// refineAll() may cause change in faces in visible patchs.</font>
00761 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00762 }
00763
00764
00765 <font class="comment">// ***************************************************************************</font>
<a name="l00766"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_5">00766</a> <font class="keywordtype">void</font> CLandscape::excludePatchFromRefineAll(sint zoneId, uint patch, <font class="keywordtype">bool</font> exclude)
00767 {
00768 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId);
00769 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
00770 {
00771 it->second->excludePatchFromRefineAll(patch, exclude);
00772 }
00773
00774 }
00775
00776
00777 <font class="comment">// ***************************************************************************</font>
<a name="l00778"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_6">00778</a> <font class="keywordtype">void</font> CLandscape::averageTesselationVertices()
00779 {
00780 <font class="comment">// -1. Update globals</font>
00781 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (CVector::Null);
00782 <font class="comment">// NB: averageTesselationVertices may change vertices in VB in visible patchs => buffers are locked.</font>
00783
00784 <font class="comment">// Increment the update date.</font>
00785 CLandscapeGlobals::CurrentDate++;
00786
00787 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
00788 {
00789 (*it).second->averageTesselationVertices();
00790 }
00791
00792 <font class="comment">// Must realase VB Buffers</font>
00793 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
00794
00795 <font class="comment">// averageTesselationVertices() should not cause change in faces in any patchs.</font>
00796 <font class="comment">// It should not happens, but check for security.</font>
00797 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z490_19">_TessBlockModificationRoot</a>.getNextToModify()==NULL);
00798 <a class="code" href="classNL3D_1_1CLandscape.html#c10">updateTessBlocksFaceVector</a>();
00799
00800 }
00801
00802
00803
00804 <font class="comment">// ***************************************************************************</font>
<a name="l00805"></a><a class="code" href="classNL3D_1_1CLandscape.html#c6">00805</a> <font class="keywordtype">void</font> CLandscape::updateGlobalsAndLockBuffers (<font class="keyword">const</font> CVector &refineCenter)
00806 {
00807 <font class="comment">// Setup CLandscapeGlobals static members...</font>
00808
00809 <font class="comment">// Far limits.</font>
00810 CLandscapeGlobals::FarTransition= <a class="code" href="classNL3D_1_1CLandscape.html#o4">_FarTransition</a>;
00811
00812 <font class="comment">// Tile subdivsion part.</font>
00813 CLandscapeGlobals::TileMaxSubdivision= <a class="code" href="classNL3D_1_1CLandscape.html#o5">_TileMaxSubdivision</a>;
00814 CLandscapeGlobals::TileDistNear = <a class="code" href="classNL3D_1_1CLandscape.html#o1">_TileDistNear</a>;
00815 CLandscapeGlobals::TileDistFar = CLandscapeGlobals::TileDistNear+20;
00816 CLandscapeGlobals::TileDistNearSqr = <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(CLandscapeGlobals::TileDistNear);
00817 CLandscapeGlobals::TileDistFarSqr = <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(CLandscapeGlobals::TileDistFar);
00818 CLandscapeGlobals::OOTileDistDeltaSqr = 1.0f / (CLandscapeGlobals::TileDistFarSqr - CLandscapeGlobals::TileDistNearSqr);
00819
00820 <font class="comment">// Tile Pixel size part.</font>
00821 <font class="comment">// \todo yoyo: choose according to wanted tile pixel size.</font>
00822 CLandscapeGlobals::TilePixelSize= 128.0f;
00823 CLandscapeGlobals::TilePixelBias128= 0.5f/CLandscapeGlobals::TilePixelSize;
00824 CLandscapeGlobals::TilePixelScale128= 1-1/CLandscapeGlobals::TilePixelSize;
00825 CLandscapeGlobals::TilePixelBias256= 0.5f/(CLandscapeGlobals::TilePixelSize*2);
00826 CLandscapeGlobals::TilePixelScale256= 1-1/(CLandscapeGlobals::TilePixelSize*2);
00827
00828 <font class="comment">// RefineThreshold.</font>
00829 CLandscapeGlobals::RefineThreshold= <a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a>;
00830
00831 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a> == 0.0f)
00832 CLandscapeGlobals::OORefineThreshold = FLT_MAX;
00833 <font class="keywordflow">else</font>
00834 CLandscapeGlobals::OORefineThreshold = 1.0f / CLandscapeGlobals::RefineThreshold;
00835
00836 <font class="comment">// Refine Center*.</font>
00837 CLandscapeGlobals::RefineCenter= refineCenter;
00838 CLandscapeGlobals::TileFarSphere.Center= CLandscapeGlobals::RefineCenter;
00839 CLandscapeGlobals::TileFarSphere.Radius= CLandscapeGlobals::TileDistFar;
00840 CLandscapeGlobals::TileNearSphere.Center= CLandscapeGlobals::RefineCenter;
00841 CLandscapeGlobals::TileNearSphere.Radius= CLandscapeGlobals::TileDistNear;
00842
00843 <font class="comment">// PZBModelPosition</font>
00844 CLandscapeGlobals::PZBModelPosition= <a class="code" href="classNL3D_1_1CLandscape.html#z497_0">_PZBModelPosition</a>;
00845
00846 <font class="comment">// VB Allocators.</font>
00847 CLandscapeGlobals::CurrentFar0VBAllocator= &<a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>;
00848 CLandscapeGlobals::CurrentFar1VBAllocator= &<a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>;
00849 CLandscapeGlobals::CurrentTileVBAllocator= &<a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>;
00850
00851 <font class="comment">// Must check driver, and create VB infos,locking buffers.</font>
00852 <font class="keywordflow">if</font>(_Driver)
00853 {
00854 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.updateDriver(<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>);
00855 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.updateDriver(<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>);
00856 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.updateDriver(<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>);
00857
00858 <font class="comment">// must do the same for _VegetableManager.</font>
00859 <font class="keywordflow">if</font>(_DriverOkForVegetable)
00860 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->updateDriver(<a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>);
00861
00862 <a class="code" href="classNL3D_1_1CLandscape.html#c7">lockBuffers</a> ();
00863 }
00864 }
00865
00866
00867 <font class="comment">// ***************************************************************************</font>
<a name="l00868"></a><a class="code" href="classNL3D_1_1CLandscape.html#c7">00868</a> <font class="keywordtype">void</font> CLandscape::lockBuffers ()
00869 {
00870 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.lockBuffer(CLandscapeGlobals::CurrentFar0VBInfo);
00871 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.lockBuffer(CLandscapeGlobals::CurrentFar1VBInfo);
00872 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.lockBuffer(CLandscapeGlobals::CurrentTileVBInfo);
00873
00874 <font class="comment">// lock buffer of the vegetable manager.</font>
00875 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->lockBuffers();
00876
00877 <font class="comment">// VertexProgrma mode???</font>
00878 CLandscapeGlobals::VertexProgramEnabled= <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>;
00879 }
00880
00881
00882 <font class="comment">// ***************************************************************************</font>
<a name="l00883"></a><a class="code" href="classNL3D_1_1CLandscape.html#c8">00883</a> <font class="keywordtype">void</font> CLandscape::unlockBuffers()
00884 {
00885 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.unlockBuffer();
00886 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.unlockBuffer();
00887 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.unlockBuffer();
00888
00889 <font class="comment">// unlock buffer of the vegetable manager.</font>
00890 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->unlockBuffers();
00891 }
00892
00893 <font class="comment">// ***************************************************************************</font>
<a name="l00894"></a><a class="code" href="classNL3D_1_1CLandscape.html#c9">00894</a> <font class="keywordtype">void</font> CLandscape::synchronizeATIVBHards()
00895 {
00896 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.synchronizeATIVBHard();
00897 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.synchronizeATIVBHard();
00898 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.synchronizeATIVBHard();
00899 }
00900
00901 <font class="comment">// ***************************************************************************</font>
<a name="l00902"></a><a class="code" href="classNL3D_1_1CLandscape.html#c10">00902</a> <font class="keywordtype">void</font> CLandscape::updateTessBlocksFaceVector()
00903 {
00904 <font class="comment">// while some tessBlock to update remains.</font>
00905 CTessBlock *tb;
00906 <font class="keywordflow">while</font>( (tb=<a class="code" href="classNL3D_1_1CLandscape.html#z490_19">_TessBlockModificationRoot</a>.getNextToModify()) !=NULL )
00907 {
00908 <font class="comment">// Get the patch which owns this TessBlock.</font>
00909 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *patch= tb->getPatch();
00910
00911 <font class="comment">// If this patch is visible, recreate faceVector for his tessBlock.</font>
00912 patch->recreateTessBlockFaceVector(*tb);
00913
00914 <font class="comment">// remove from list.</font>
00915 tb->removeFromModifyList();
00916 }
00917 }
00918
00919
00920 <font class="comment">// ***************************************************************************</font>
00921 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(CPatchRdrPass &pass)
00922 {
00923 uint numIndices= pass.getMaxRenderedFaces()*3;
00924 <font class="comment">// realloc if necessary</font>
00925 <font class="keywordflow">if</font>( CLandscapeGlobals::PassTriArray.size() < numIndices )
00926 CLandscapeGlobals::PassTriArray.resize( numIndices );
00927 <font class="comment">// reset ptr.</font>
00928 <a class="code" href="namespaceNL3D.html#a71">NL3D_LandscapeGlobals_PassTriCurPtr</a>= &CLandscapeGlobals::PassTriArray[0];
00929 }
00930
00931
00932 <font class="comment">// ***************************************************************************</font>
00933 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(CMaterial &mat)
00934 {
00935 <font class="keywordflow">if</font>(<a class="code" href="namespaceNL3D.html#a70">NL3D_LandscapeGlobals_PassNTri</a>>0)
00936 {
00937 CLandscapeGlobals::PatchCurrentDriver->setupMaterial(mat);
00938 CLandscapeGlobals::PatchCurrentDriver->renderSimpleTriangles(&CLandscapeGlobals::PassTriArray[0], <a class="code" href="namespaceNL3D.html#a70">NL3D_LandscapeGlobals_PassNTri</a>);
00939 <a class="code" href="namespaceNL3D.html#a70">NL3D_LandscapeGlobals_PassNTri</a>= 0;
00940 }
00941 }
00942
00943
00944 <font class="comment">// ***************************************************************************</font>
<a name="l00945"></a><a class="code" href="classNL3D_1_1CLandscape.html#z479_3">00945</a> <font class="keywordtype">void</font> CLandscape::render(<font class="keyword">const</font> CVector &refineCenter, <font class="keyword">const</font> CVector &frontVector, <font class="keyword">const</font> CPlane pyramid[<a class="code" href="tess__block_8h.html#a0">NL3D_TESSBLOCK_NUM_CLIP_PLANE</a>], <font class="keywordtype">bool</font> doTileAddPass)
00946 {
00947 IDriver *driver= <a class="code" href="classNL3D_1_1CLandscape.html#z491_0">_Driver</a>;
00948 <a class="code" href="debug_8h.html#a6">nlassert</a>(driver);
00949
00950 <font class="comment">// Increment the update date for preRender.</font>
00951 CLandscapeGlobals::CurrentRenderDate++;
00952
00953
00954 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it;
00955 sint i;
00956 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> itTile;
00957 <a class="code" href="classNL3D_1_1CLandscape.html#u7">ItSPRenderPassSet</a> itFar;
00958
00959 <font class="comment">// Yoyo: profile.</font>
00960 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a74">ProfNRdrFar0</a>, 0);
00961 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a75">ProfNRdrFar1</a>, 0);
00962 <font class="keywordflow">for</font>(i=0;i<<a class="code" href="landscape__def_8h.html#a0">NL3D_MAX_TILE_PASS</a>;i++)
00963 {
00964 <a class="code" href="landscape__profile_8h.html#a1">NL3D_PROFILE_LAND_SET</a>(<a class="code" href="namespaceNL3D.html#a76">ProfNRdrTile</a>[i], 0);
00965 }
00966
00967
00968 <font class="comment">// -2. Update globals</font>
00969 <font class="comment">//====================</font>
00970 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (refineCenter);
00971 <font class="comment">// NB: render may change vertices in VB in visible patchs => buffers are locked.</font>
00972
00973
00974 <font class="comment">// -1. clear all PatchRenderPass renderList</font>
00975 <font class="comment">//===================</font>
00976
00977 <font class="comment">// Fars.</font>
00978 <font class="keywordflow">for</font>(itFar= <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.begin(); itFar!= <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.end(); itFar++)
00979 {
00980 CPatchRdrPass &pass= **itFar;
00981 <font class="comment">// clear list.</font>
00982 pass.clearAllRenderList();
00983 }
00984
00985 <font class="comment">// Tiles.</font>
00986 <font class="keywordflow">for</font>(itTile= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.begin(); itTile!= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.end(); itTile++)
00987 {
00988 CPatchRdrPass &pass= const_cast<CPatchRdrPass&>(*itTile);
00989 <font class="comment">// clear list.</font>
00990 pass.clearAllRenderList();
00991 }
00992
00993 <font class="comment">// Lightmaps.</font>
00994 <font class="keywordflow">for</font>(sint lightRdrPass=0; lightRdrPass<(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size(); lightRdrPass++)
00995 {
00996 CPatchRdrPass &pass= *<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>[lightRdrPass];
00997 <font class="comment">// clear list.</font>
00998 pass.clearAllRenderList();
00999 }
01000
01001 <font class="comment">// 0. preRender pass.</font>
01002 <font class="comment">//===================</font>
01003
01004 <font class="comment">// change Far0 / Far1.</font>
01005 <font class="comment">// Clip TessBlocks against pyramid and Far Limit.</font>
01006 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="tess__block_8h.html#a0">NL3D_TESSBLOCK_NUM_CLIP_PLANE</a>; i++)
01007 {
01008 CTessBlock::CurrentPyramid[i]= pyramid[i];
01009 }
01010 <font class="comment">// Update VB with change of Far0 / Far1.</font>
01011 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
01012 {
01013 (*it).second->preRender();
01014 }
01015
01016
01017 <font class="comment">// Reallocation Mgt. If any of the VB is reallocated, we must refill it entirely.</font>
01018 <font class="comment">// NB: all VBs are refilled entirely. It is not optimal (maybe 3* too slow), but reallocation are supposed</font>
01019 <font class="comment">// to be very rare.</font>
01020 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.reallocationOccurs() || <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.reallocationOccurs() || <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.reallocationOccurs() )
01021 <a class="code" href="classNL3D_1_1CLandscape.html#z491_5">_RenderMustRefillVB</a>= <font class="keyword">true</font>;
01022
01023 <font class="comment">// VertexProgram dependency on RefineThreshold Management. If VertexShader, and if the refineThreshold has</font>
01024 <font class="comment">// changed since the last time, we must refill All the VB, because data are out of date.</font>
01025 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a> && <a class="code" href="classNL3D_1_1CLandscape.html#o6">_VPThresholdChange</a> )
01026 {
01027 <a class="code" href="classNL3D_1_1CLandscape.html#o6">_VPThresholdChange</a>= <font class="keyword">false</font>;
01028 <a class="code" href="classNL3D_1_1CLandscape.html#z491_5">_RenderMustRefillVB</a>= <font class="keyword">true</font>;
01029 }
01030
01031 <font class="comment">// If we must refill the VB (for any reason).</font>
01032 <font class="keywordflow">if</font>(_RenderMustRefillVB )
01033 {
01034 <font class="comment">// Ok, ok, we refill All the VB with good data.</font>
01035 <a class="code" href="classNL3D_1_1CLandscape.html#z491_5">_RenderMustRefillVB</a>= <font class="keyword">false</font>;
01036
01037 <font class="comment">// First reset the flag, so fillVB() will effectively fill the VB.</font>
01038 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.resetReallocation();
01039 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.resetReallocation();
01040 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.resetReallocation();
01041
01042 <font class="comment">// Then recompute good VBInfo (those in CurrentVBInfo are false!!).</font>
01043 <font class="comment">// Do it by unlocking then re-locking Buffers.</font>
01044 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
01045 <a class="code" href="classNL3D_1_1CLandscape.html#c7">lockBuffers</a>();
01046
01047 <font class="comment">// Finally, fill the VB for all patchs visible.</font>
01048 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
01049 {
01050 <font class="keywordflow">if</font>((*it).second->ClipResult==CZone::ClipOut)
01051 <font class="keywordflow">continue</font>;
01052 <font class="keywordflow">for</font>(sint i=0;i<(*it).second->getNumPatchs(); i++)
01053 {
01054 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *patch= (*it).second->getPatch(i);
01055 patch->fillVBIfVisible();
01056 }
01057 }
01058 }
01059
01060
01061 <font class="comment">// If software GeoMorph / Alpha Transition (no VertexShader), do it now.</font>
01062 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>)
01063 {
01064 <font class="comment">// For all patch visible, compute geomoprh and alpha in software.</font>
01065 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
01066 {
01067 <font class="keywordflow">if</font>((*it).second->ClipResult==CZone::ClipOut)
01068 <font class="keywordflow">continue</font>;
01069 <font class="keywordflow">for</font>(sint i=0;i<(*it).second->getNumPatchs(); i++)
01070 {
01071 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *patch= (*it).second->getPatch(i);
01072 <font class="comment">// If visible, compute Geomorph And Alpha</font>
01073 patch->computeSoftwareGeomorphAndAlpha();
01074 }
01075 }
01076
01077 <font class="comment">/*</font>
01078 <font class="comment"> Optim note: here, lot of vertices are </font>
01079 <font class="comment"> 1/ geomorphed twice (vertices on edges of patchs)</font>
01080 <font class="comment"> 2/ vertices are geomorphed, but not used (because o the Tessblock clip), </font>
01081 <font class="comment"> because lot of vertices used by faces in small TessBlocks are still in MasterBlock.</font>
01082 <font class="comment"></font>
01083 <font class="comment"> Some tries have been made to solve this, but result are even worse (2 times or more), because:</font>
01084 <font class="comment"> 1/</font>
01085 <font class="comment"> - does not really matter edges of patchs (and corner) because the majority is in interior of patch.</font>
01086 <font class="comment"> - in this case, we need to reset all the flags which is very costly (reparse all zones...) .</font>
01087 <font class="comment"> 2/ Except for the old CTessBlockEdge management which not solve all the thing, the other solution is</font>
01088 <font class="comment"> to test all faces not clipped (on a per TessBlock basis), to compute only vertices needed.</font>
01089 <font class="comment"> But in this cases, result are worse, maybe because there is 6 times more tests, and with bad BTB cache.</font>
01090 <font class="comment"> */</font>
01091 }
01092
01093
01094 <font class="comment">// Must realase VB Buffers Now!! The VBuffers are now OK!</font>
01095 <font class="comment">// NB: no parallelism is made between 3dCard and Fill of vertices.</font>
01096 <font class="comment">// We Suppose Fill of vertices is rare, and so do not need to be parallelized.</font>
01097 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
01098
01099
01100 <font class="comment">// Special for ATI: only copy all VBs to VBHard one time per frame</font>
01101 <a class="code" href="classNL3D_1_1CLandscape.html#c9">synchronizeATIVBHards</a>();
01102
01103
01104 <font class="comment">// If VertexShader enabled, setup VertexProgram Constants.</font>
01105 <font class="keywordflow">if</font>(_VertexShaderOk)
01106 {
01107 <font class="comment">// c[0..3] take the ModelViewProjection Matrix.</font>
01108 driver->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
01109 <font class="comment">// c[4] take usefull constants.</font>
01110 driver->setConstant(4, 0, 1, 0.5f, 0);
01111 <font class="comment">// c[5] take RefineCenter</font>
01112 driver->setConstant(5, refineCenter);
01113 <font class="comment">// c[6] take info for Geomorph trnasition to TileNear.</font>
01114 driver->setConstant(6, CLandscapeGlobals::TileDistFarSqr, CLandscapeGlobals::OOTileDistDeltaSqr, 0, 0);
01115 <font class="comment">// c[8..11] take the ModelView Matrix.</font>
01116 driver->setConstantMatrix(8, IDriver::ModelView, IDriver::Identity);
01117 <font class="comment">// c[12] take the current landscape Center / delta Pos to apply</font>
01118 driver->setConstant(12, <a class="code" href="classNL3D_1_1CLandscape.html#z497_0">_PZBModelPosition</a>);
01119 }
01120
01121
01122 <font class="comment">// 1. TileRender pass.</font>
01123 <font class="comment">//====================</font>
01124
01125
01126 <font class="comment">// First, update Dynamic Lighting for Near, ie multiply Dynamic Lightmap with UserColor, and upload to texture.</font>
01127 <font class="comment">// ==================</font>
01128 CPatchDLMContext *dlmCtxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
01129 <font class="keywordflow">while</font>(dlmCtxPtr!=NULL)
01130 {
01131 <font class="comment">// do it only if the patch has some Near stuff to render, and if it is visible</font>
01132 <font class="keywordflow">if</font>(dlmCtxPtr->getPatch()->getFar0() == 0
01133 && !dlmCtxPtr->getPatch()->isRenderClipped() )
01134 {
01135 <font class="comment">// upload lightmap into textureDLM, modulating before with patch TileColor.</font>
01136 <font class="comment">// NB: no-op if both src and dst are already full black.</font>
01137 dlmCtxPtr->compileLighting(CPatchDLMContext::ModulateTileColor);
01138 }
01139
01140 <font class="comment">// next</font>
01141 dlmCtxPtr= (CPatchDLMContext*)dlmCtxPtr->Next;
01142 }
01143
01144
01145 <font class="comment">// Active VB.</font>
01146 <font class="comment">// ==================</font>
01147
01148 <font class="comment">// Active the good VB, and maybe activate the VertexProgram N�0.</font>
01149 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.activate(0);
01150
01151
01152 <font class="comment">// Render.</font>
01153 <font class="comment">// ==================</font>
01154 <font class="comment">// Before any render call. Set the global driver used to render.</font>
01155 CLandscapeGlobals::PatchCurrentDriver= driver;
01156
01157
01158 <font class="comment">// Render Order. Must "invert", since initial order is NOT the render order. This is done because the lightmap pass</font>
01159 <font class="comment">// DO NOT have to do any renderTile(), since it is computed in RGB0 pass.</font>
01160 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="landscape__def_8h.html#a0">NL3D_MAX_TILE_PASS</a>==5);
01161 <font class="keyword">static</font> sint RenderOrder[<a class="code" href="landscape__def_8h.html#a0">NL3D_MAX_TILE_PASS</a>]= {<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>, <a class="code" href="landscape__def_8h.html#a3">NL3D_TILE_PASS_RGB1</a>, <a class="code" href="landscape__def_8h.html#a4">NL3D_TILE_PASS_RGB2</a>,
01162 <a class="code" href="landscape__def_8h.html#a6">NL3D_TILE_PASS_LIGHTMAP</a>, <a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>};
01163 <font class="comment">// For ALL pass..</font>
01164 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="landscape__def_8h.html#a0">NL3D_MAX_TILE_PASS</a>; i++)
01165 {
01166 sint passOrder= RenderOrder[i];
01167
01168
01169 <font class="comment">// If VertexShader enabled, and if lightmap or post Add pass, must setup good VertexProgram</font>
01170 <font class="keywordflow">if</font>(_VertexShaderOk)
01171 {
01172 <font class="keywordflow">if</font>(passOrder == <a class="code" href="landscape__def_8h.html#a6">NL3D_TILE_PASS_LIGHTMAP</a>)
01173 {
01174 <font class="comment">// Must activate the vertexProgram to take TexCoord2 to stage0</font>
01175 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.activate(1);
01176 }
01177 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(passOrder == <a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>)
01178 {
01179 <font class="comment">// Must re-activate the standard VertexProgram</font>
01180 <a class="code" href="classNL3D_1_1CLandscape.html#z491_3">_TileVB</a>.activate(0);
01181 }
01182 }
01183
01184
01185 <font class="comment">// Do add pass???</font>
01186 <font class="keywordflow">if</font>((passOrder==<a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>) && !doTileAddPass)
01187 <font class="keywordflow">continue</font>;
01188
01189
01190 <font class="comment">// Setup common material for this pass.</font>
01191 <font class="comment">//=============================</font>
01192 <font class="comment">// Default: Replace envmode.</font>
01193 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpRGB(0, CMaterial::Replace);
01194 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor);
01195 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpAlpha(0, CMaterial::Replace);
01196 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0Alpha(0, CMaterial::Texture, CMaterial::SrcAlpha);
01197 <font class="comment">// NB: important to set Replace and not modulate, because in case of VerexProgram enabled, </font>
01198 <font class="comment">// Diffuse o[COL0] is undefined.</font>
01199
01200 <font class="comment">// Copy from stage 0 to stage 1.</font>
01201 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexEnvMode(1, <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.getTexEnvMode(0));
01202
01203 <font class="comment">// setup multitex / blending.</font>
01204 <font class="keywordflow">if</font>(passOrder==<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>)
01205 {
01206 <font class="comment">// first pass, no blend.</font>
01207 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setBlend(<font class="keyword">false</font>);
01208 }
01209 <font class="keywordflow">else</font>
01210 {
01211 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setBlend(<font class="keyword">true</font>);
01212 <font class="keywordflow">switch</font>(passOrder)
01213 {
01214 <font class="keywordflow">case</font> <a class="code" href="landscape__def_8h.html#a3">NL3D_TILE_PASS_RGB1</a>:
01215 <font class="keywordflow">case</font> <a class="code" href="landscape__def_8h.html#a4">NL3D_TILE_PASS_RGB2</a>:
01216 <font class="comment">// alpha blending.</font>
01217 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
01218
01219 <font class="comment">// Must use a special envmode for stage1: "separateAlpha"!!.</font>
01220 <font class="comment">// keep the color from previous stage.</font>
01221 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpRGB(1, CMaterial::Replace);
01222 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0RGB(1, CMaterial::Previous, CMaterial::SrcColor);
01223 <font class="comment">// take the alpha from current stage.</font>
01224 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpAlpha(1, CMaterial::Replace);
01225 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0Alpha(1, CMaterial::Texture, CMaterial::SrcAlpha);
01226 <font class="keywordflow">break</font>;
01227 <font class="keywordflow">case</font> <a class="code" href="landscape__def_8h.html#a6">NL3D_TILE_PASS_LIGHTMAP</a>:
01228 <font class="comment">// modulate alpha blending.</font>
01229 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setBlendFunc(CMaterial::zero, CMaterial::srccolor);
01230
01231 <font class="comment">// Setup the material envCombine so DynamicLightmap (stage 0) is added to static lightmap.</font>
01232 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpRGB(1, CMaterial::Add);
01233 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0RGB(1, CMaterial::Texture, CMaterial::SrcColor);
01234 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg1RGB(1, CMaterial::Previous, CMaterial::SrcColor);
01235
01236 <font class="keywordflow">break</font>;
01237 <font class="keywordflow">case</font> <a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>:
01238 <font class="comment">// Use srcalpha for src (and not ONE), since additive are blended with alpha Cte/AlphaTexture</font>
01239 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setBlendFunc(CMaterial::srcalpha, CMaterial::one);
01240
01241 <font class="comment">// for MAYBE LATER smooth night transition, setup Alpha cte of stage0, and setup alpha stage.</font>
01242 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpAlpha(0, CMaterial::Replace);
01243 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0Alpha(0, CMaterial::Constant, CMaterial::SrcAlpha);
01244 <font class="comment">// Temp, just setup alpha to 1.</font>
01245 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texConstantColor(0, CRGBA(255, 255, 255, 255));
01246
01247 <font class="comment">// Must use a special envmode for stage1: "separateAlpha"!!.</font>
01248 <font class="comment">// NB: it still works if The RdrPass has no texture.</font>
01249 <font class="comment">// keep the color from previous stage.</font>
01250 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpRGB(1, CMaterial::Replace);
01251 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0RGB(1, CMaterial::Previous, CMaterial::SrcColor);
01252 <font class="comment">// modulate the alpha of current stage with previous</font>
01253 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvOpAlpha(1, CMaterial::Modulate);
01254 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg0Alpha(1, CMaterial::Texture, CMaterial::SrcAlpha);
01255 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.texEnvArg1Alpha(1, CMaterial::Previous, CMaterial::SrcAlpha);
01256
01257 <font class="keywordflow">break</font>;
01258 <font class="keywordflow">default</font>:
01259 <a class="code" href="debug_8h.html#a12">nlstop</a>;
01260 };
01261 }
01262 <font class="comment">// Reset the textures (so there is none in Addtive pass or in Lightmap).</font>
01263 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(0, NULL);
01264 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(1, NULL);
01265 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(2, NULL);
01266
01267
01268 <font class="comment">// Render All material RdrPass.</font>
01269 <font class="comment">//=============================</font>
01270 <font class="comment">// Special code for Lightmap and RGB0, for faster render.</font>
01271 <font class="keywordflow">if</font>(passOrder==<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>)
01272 {
01273 <font class="comment">// RGB0 pass.</font>
01274 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> itTile;
01275 <font class="keywordflow">for</font>(itTile= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.begin(); itTile!= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.end(); itTile++)
01276 {
01277 <font class="comment">// Get a ref on the render pass. Const cast work because we only modify attribut from CPatchRdrPass </font>
01278 <font class="comment">// that don't affect the operator< of this class</font>
01279 CPatchRdrPass &pass= const_cast<CPatchRdrPass&>(*itTile);
01280
01281 <font class="comment">// Enlarge PassTriArray as needed</font>
01282 <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(pass);
01283
01284 <font class="comment">// Setup Diffuse texture of the tile.</font>
01285 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(0, pass.TextureDiffuse);
01286
01287 <font class="comment">// Add triangles to array</font>
01288 CRdrTileId *tileToRdr= pass.getRdrTileRoot(passOrder);
01289 <font class="keywordflow">while</font>(tileToRdr)
01290 {
01291 <font class="comment">// renderSimpleTriangles() with the material setuped.</font>
01292 tileToRdr->TileMaterial->renderTilePassRGB0();
01293 tileToRdr= (CRdrTileId*)tileToRdr->getNext();
01294 }
01295 <font class="comment">// Render triangles.</font>
01296 <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>);
01297 }
01298 }
01299 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(passOrder==<a class="code" href="landscape__def_8h.html#a6">NL3D_TILE_PASS_LIGHTMAP</a>)
01300 {
01301 <font class="comment">// Lightmap Pass.</font>
01302 <font class="comment">/* \todo yoyo: TODO_CLOUD: setup stage2, and setup texcoord generation. COMPLEX because of interaction</font>
01303 <font class="comment"> with Dynamic LightMap</font>
01304 <font class="comment"> */</font>
01305
01306 <font class="comment">// Setup the Dynamic Lightmap into stage 0.</font>
01307 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(0, <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>);
01308
01309 <font class="comment">// if vertex shader not used.</font>
01310 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>)
01311 {
01312 <font class="comment">// special setup such that stage0 takes Uv2.</font>
01313 driver->mapTextureStageToUV(0, 2);
01314 }
01315 <font class="comment">// else VertexProgram map itself the good vertex Attribute to UV0.</font>
01316
01317
01318 <font class="comment">// Render All the lightmaps.</font>
01319 <font class="keywordflow">for</font>(sint lightRdrPass=0; lightRdrPass<(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size(); lightRdrPass++)
01320 {
01321 CPatchRdrPass &pass= *<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>[lightRdrPass];
01322
01323 <font class="comment">// Enlarge PassTriArray as needed</font>
01324 <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(pass);
01325
01326 <font class="comment">// Setup Lightmap into stage1. Because we share UV with pass RGB0. So we use UV1.</font>
01327 <font class="comment">// Also, now stage0 is used for DynamicLightmap</font>
01328 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(1, pass.TextureDiffuse);
01329
01330 <font class="comment">// Add triangles to array</font>
01331 CRdrTileId *tileToRdr= pass.getRdrTileRoot(passOrder);
01332 <font class="keywordflow">while</font>(tileToRdr)
01333 {
01334 <font class="comment">// renderSimpleTriangles() with the material setuped.</font>
01335 tileToRdr->TileMaterial->renderTilePassLightmap();
01336 tileToRdr= (CRdrTileId*)tileToRdr->getNext();
01337 }
01338 <font class="comment">// Render triangles.</font>
01339 <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>);
01340 }
01341
01342 <font class="comment">// if vertex shader not used.</font>
01343 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>)
01344 {
01345 <font class="comment">// Reset special stage/UV setup to normal behavior</font>
01346 driver->mapTextureStageToUV(0, 0);
01347 }
01348 }
01349 <font class="keywordflow">else</font>
01350 {
01351 <font class="comment">// RGB1, RGB2, and ADD pass.</font>
01352
01353 <font class="comment">// Render Base, Transitions or Additives.</font>
01354
01355 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> itTile;
01356 <font class="keywordflow">for</font>(itTile= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.begin(); itTile!= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.end(); itTile++)
01357 {
01358 <font class="comment">// Get a ref on the render pass. Const cast work because we only modify attribut from CPatchRdrPass </font>
01359 <font class="comment">// that don't affect the operator< of this class</font>
01360 CPatchRdrPass &pass= const_cast<CPatchRdrPass&>(*itTile);
01361
01362 <font class="comment">// Enlarge PassTriArray as needed</font>
01363 <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(pass);
01364
01365 <font class="comment">// Add triangles to array</font>
01366 CRdrTileId *tileToRdr= pass.getRdrTileRoot(passOrder);
01367 <font class="keywordflow">while</font>(tileToRdr)
01368 {
01369 <font class="comment">// renderSimpleTriangles() with the material setuped.</font>
01370 tileToRdr->TileMaterial->renderTile(passOrder);
01371 tileToRdr= (CRdrTileId*)tileToRdr->getNext();
01372 }
01373
01374 <font class="comment">// Pass not empty ?</font>
01375 <font class="keywordflow">if</font>(<a class="code" href="namespaceNL3D.html#a70">NL3D_LandscapeGlobals_PassNTri</a>>0)
01376 {
01377 <font class="comment">// Setup material.</font>
01378 <font class="comment">// Setup Diffuse texture of the tile.</font>
01379 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(0, pass.TextureDiffuse);
01380
01381 <font class="comment">// If transition tile, must enable the alpha for this pass.</font>
01382 <font class="comment">// NB: Additive pass may have pass.TextureAlpha==NULL</font>
01383 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(1, pass.TextureAlpha);
01384 }
01385
01386 <font class="comment">// Render triangles.</font>
01387 <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>);
01388 }
01389 }
01390 }
01391
01392
01393 <font class="comment">// 2. Far0Render pass.</font>
01394 <font class="comment">//====================</font>
01395
01396
01397 <font class="comment">// First, update Dynamic Lighting for Far, ie multiply Dynamic Lightmap with TextureFar, and upload to texture.</font>
01398 <font class="comment">// ==================</font>
01399 dlmCtxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
01400 <font class="keywordflow">while</font>(dlmCtxPtr!=NULL)
01401 {
01402 <font class="comment">// do it only if the patch has some Far stuff to render, and if it is visible</font>
01403 <font class="keywordflow">if</font>( (dlmCtxPtr->getPatch()->getFar0()>0 || dlmCtxPtr->getPatch()->getFar1()>0)
01404 && !dlmCtxPtr->getPatch()->isRenderClipped() )
01405 {
01406 <font class="comment">// upload lightmap into textureDLM, modulating before with patch TextureFar.</font>
01407 <font class="comment">// NB: no-op if both src and dst are already full black.</font>
01408 dlmCtxPtr->compileLighting(CPatchDLMContext::ModulateTextureFar);
01409 }
01410
01411 <font class="comment">// next</font>
01412 dlmCtxPtr= (CPatchDLMContext*)dlmCtxPtr->Next;
01413 }
01414
01415
01416 <font class="comment">// Active VB.</font>
01417 <font class="comment">// ==================</font>
01418
01419 <font class="comment">// Active the good VB, and maybe activate the std VertexProgram.</font>
01420 <a class="code" href="classNL3D_1_1CLandscape.html#z491_1">_Far0VB</a>.activate(0);
01421
01422
01423 <font class="comment">// Render.</font>
01424 <font class="comment">// ==================</font>
01425
01426 <font class="comment">// Setup common material.</font>
01427 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setBlend(<font class="keyword">false</font>);
01428 <font class="comment">// set the DLM texture.</font>
01429 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(1, <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>);
01430
01431 <font class="comment">// Render All material RdrPass0.</font>
01432 itFar=<a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.begin();
01433 <font class="keywordflow">while</font> (itFar!=<a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.end())
01434 {
01435 CPatchRdrPass &pass= **itFar;
01436
01437 <font class="comment">// Enlarge PassTriArray as needed</font>
01438 <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(pass);
01439
01440 <font class="comment">// Setup the material.</font>
01441 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(0, pass.TextureDiffuse);
01442 <font class="comment">// If the texture need to be updated, do it now.</font>
01443 <font class="keywordflow">if</font>(pass.TextureDiffuse && pass.TextureDiffuse->touched())
01444 driver->setupTexture(*pass.TextureDiffuse);
01445
01446 <font class="comment">// Add triangles to array</font>
01447 CRdrPatchId *patchToRdr= pass.getRdrPatchFar0();
01448 <font class="keywordflow">while</font>(patchToRdr)
01449 {
01450 <font class="comment">// renderSimpleTriangles() with the material setuped.</font>
01451 patchToRdr->Patch->renderFar0();
01452 patchToRdr= (CRdrPatchId*)patchToRdr->getNext();
01453 }
01454 <font class="comment">// Render triangles.</font>
01455 <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>);
01456
01457 <font class="comment">// Next render pass</font>
01458 itFar++;
01459 }
01460
01461
01462
01463 <font class="comment">// 3. Far1Render pass.</font>
01464 <font class="comment">//====================</font>
01465
01466 <font class="comment">// Active VB.</font>
01467 <font class="comment">// ==================</font>
01468
01469 <font class="comment">// Active the good VB, and maybe activate the std VertexProgram.</font>
01470 <a class="code" href="classNL3D_1_1CLandscape.html#z491_2">_Far1VB</a>.activate(0);
01471
01472
01473 <font class="comment">// Render</font>
01474 <font class="comment">// ==================</font>
01475
01476 <font class="comment">// Setup common material.</font>
01477 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setBlend(<font class="keyword">true</font>);
01478 <font class="comment">// set the DLM texture.</font>
01479 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(1, <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>);
01480
01481
01482 <font class="comment">// Render All material RdrPass1.</font>
01483 itFar=<a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.begin();
01484 <font class="keywordflow">while</font> (itFar!=<a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.end())
01485 {
01486 CPatchRdrPass &pass= **itFar;
01487
01488 <font class="comment">// Enlarge PassTriArray as needed</font>
01489 <a class="code" href="namespaceNL3D.html#a370">initPassTriArray</a>(pass);
01490
01491 <font class="comment">// Setup the material.</font>
01492 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(0, pass.TextureDiffuse);
01493 <font class="comment">// If the texture need to be updated, do it now.</font>
01494 <font class="keywordflow">if</font>(pass.TextureDiffuse && pass.TextureDiffuse->touched())
01495 driver->setupTexture(*pass.TextureDiffuse);
01496
01497 <font class="comment">// Add triangles to array</font>
01498 CRdrPatchId *patchToRdr= pass.getRdrPatchFar1();
01499 <font class="keywordflow">while</font>(patchToRdr)
01500 {
01501 <font class="comment">// renderSimpleTriangles() with the material setuped.</font>
01502 patchToRdr->Patch->renderFar1();
01503 patchToRdr= (CRdrPatchId*)patchToRdr->getNext();
01504 }
01505 <font class="comment">// Render triangles.</font>
01506 <a class="code" href="namespaceNL3D.html#a371">drawPassTriArray</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>);
01507
01508 <font class="comment">// Next render pass</font>
01509 itFar++;
01510 }
01511
01512
01513 <font class="comment">// 4. "Release" texture materials.</font>
01514 <font class="comment">//================================</font>
01515 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(0, NULL);
01516 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(1, NULL);
01517 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(2, NULL);
01518 <a class="code" href="classNL3D_1_1CLandscape.html#o13">FarMaterial</a>.setTexture(3, NULL);
01519 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(0, NULL);
01520 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(1, NULL);
01521 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(2, NULL);
01522 <a class="code" href="classNL3D_1_1CLandscape.html#o12">TileMaterial</a>.setTexture(3, NULL);
01523
01524 <font class="comment">// To ensure no use but in render()..</font>
01525 CLandscapeGlobals::PatchCurrentDriver= NULL;
01526
01527 <font class="comment">// Desactive the vertex program (if anyone)</font>
01528 <font class="keywordflow">if</font>(_VertexShaderOk)
01529 driver->activeVertexProgram (NULL);
01530
01531
01532 <font class="comment">// 5. Vegetable Management.</font>
01533 <font class="comment">//================================</font>
01534
01535 <font class="comment">// First, update Dynamic Lighting for Vegetable, ie just copy.</font>
01536 <font class="comment">// ==================</font>
01537 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z485_4">isVegetableActive</a>())
01538 {
01539 <font class="comment">/* Actually we modulate the DLM with an arbitrary constant for this reason:</font>
01540 <font class="comment"> Color of vegetable (ie their material) are NOT modulated with DLM.</font>
01541 <font class="comment"> Doing this without using PixelShader / additional UVs seems to be impossible.</font>
01542 <font class="comment"> And add new UVs (+700K in AGP) just for this is not worth the effort.</font>
01543 <font class="comment"></font>
01544 <font class="comment"> We prefer using a constant to simulate the "global vegetable color", which is a big trick.</font>
01545 <font class="comment"></font>
01546 <font class="comment"> Additionally, the vegetable take the diffuse lighting of landscape, which is</font>
01547 <font class="comment"> false because it replaces the diffuse lighting it should have (ie with his own Normal and </font>
01548 <font class="comment"> his own "global vegetable color")</font>
01549 <font class="comment"></font>
01550 <font class="comment"> We can't do anything for "correct normal vegetable", but it is possible to replace landscape</font>
01551 <font class="comment"> material with vegetable material, by dividing _DLMGlobalVegetableColor by LandscapeDiffuseMaterial.</font>
01552 <font class="comment"> This is a very approximate result because of CRGBA clamp, but it is acceptable.</font>
01553 <font class="comment"> */</font>
01554 CRGBA vegetDLMCte;
01555 <font class="comment">// the constant is _DLMGlobalVegetableColor / PointLightDiffuseMaterial</font>
01556 uint <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
01557 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= (<a class="code" href="classNL3D_1_1CLandscape.html#z499_5">_DLMGlobalVegetableColor</a>.R*256) / (<a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>.R+1);
01558 vegetDLMCte.R= (uint8)<a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, 255U);
01559 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= (<a class="code" href="classNL3D_1_1CLandscape.html#z499_5">_DLMGlobalVegetableColor</a>.G*256) / (<a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>.G+1);
01560 vegetDLMCte.G= (uint8)<a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, 255U);
01561 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= (<a class="code" href="classNL3D_1_1CLandscape.html#z499_5">_DLMGlobalVegetableColor</a>.B*256) / (<a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>.B+1);
01562 vegetDLMCte.B= (uint8)<a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, 255U);
01563
01564 <font class="comment">// Parse all patch which have some vegetables</font>
01565 dlmCtxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
01566 <font class="keywordflow">while</font>(dlmCtxPtr!=NULL)
01567 {
01568 <font class="comment">// do it only if the patch has some vegetable stuff to render, and if it is visible</font>
01569 <font class="comment">// NB: we may have some vegetable stuff to render if the patch has some TileMaterial created.</font>
01570 <font class="keywordflow">if</font>(dlmCtxPtr->getPatch()->getTileMaterialRefCount()>0
01571 && !dlmCtxPtr->getPatch()->isRenderClipped() )
01572 {
01573 <font class="comment">// NB: no-op if both src and dst are already full black.</font>
01574 dlmCtxPtr->compileLighting(CPatchDLMContext::ModulateConstant, vegetDLMCte);
01575 }
01576
01577 <font class="comment">// next</font>
01578 dlmCtxPtr= (CPatchDLMContext*)dlmCtxPtr->Next;
01579 }
01580 }
01581
01582
01583 <font class="comment">// profile.</font>
01584 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->resetNumVegetableFaceRendered();
01585
01586 <font class="comment">// render all vegetables, only if driver support VertexProgram.</font>
01587 <font class="comment">// ==================</font>
01588 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z485_4">isVegetableActive</a>())
01589 {
01590 <font class="comment">// Use same plane as TessBlock for faster clipping.</font>
01591 vector<CPlane> vegetablePyramid;
01592 vegetablePyramid.resize(<a class="code" href="tess__block_8h.html#a0">NL3D_TESSBLOCK_NUM_CLIP_PLANE</a>);
01593 <font class="keywordflow">for</font>(i=0;i<<a class="code" href="tess__block_8h.html#a0">NL3D_TESSBLOCK_NUM_CLIP_PLANE</a>;i++)
01594 {
01595 vegetablePyramid[i]= pyramid[i];
01596 }
01597 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->render(refineCenter, frontVector, vegetablePyramid, <a class="code" href="classNL3D_1_1CLandscape.html#z499_2">_TextureDLM</a>, driver);
01598 }
01599
01600 }
01601
01602
01603 <font class="comment">// ***************************************************************************</font>
01604 <font class="comment">// ***************************************************************************</font>
01605 <font class="comment">// Tile mgt.</font>
01606 <font class="comment">// ***************************************************************************</font>
01607 <font class="comment">// ***************************************************************************</font>
01608
01609
01610 <font class="comment">// ***************************************************************************</font>
<a name="l01611"></a><a class="code" href="classNL3D_1_1CLandscape.html#c17">01611</a> ITexture *CLandscape::findTileTexture(<font class="keyword">const</font> std::string &textName)
01612 {
01613 ITexture *text;
01614 text= <a class="code" href="classNL3D_1_1CLandscape.html#o7">TileTextureMap</a>[textName];
01615 <font class="comment">// If just inserted, RefPtr is NULL!! :)</font>
01616 <font class="comment">// This test too if the RefPtr is NULL... (tile released)</font>
01617 <font class="comment">// The object is not owned by this map. It will be own by the multiple RdrPass via CSmartPtr.</font>
01618 <font class="comment">// They will destroy it when no more points to them.</font>
01619 <font class="keywordflow">if</font>(!text)
01620 {
01621 <a class="code" href="classNL3D_1_1CLandscape.html#o7">TileTextureMap</a>[textName]= text= <font class="keyword">new</font> CTextureFile(textName);
01622 text->setWrapS(ITexture::Clamp);
01623 text->setWrapT(ITexture::Clamp);
01624 text->setUploadFormat(ITexture::DXTC5);
01625 }
01626 <font class="keywordflow">return</font> text;
01627 }
01628
01629
01630 <font class="comment">// ***************************************************************************</font>
<a name="l01631"></a><a class="code" href="classNL3D_1_1CLandscape.html#c18">01631</a> CPatchRdrPass *CLandscape::findTileRdrPass(<font class="keyword">const</font> CPatchRdrPass &pass)
01632 {
01633 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> it;
01634 <font class="comment">// If already here, find it, else insert.</font>
01635 it= (<a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.insert(pass)).first;
01636
01637 <font class="keywordflow">return</font> const_cast<CPatchRdrPass*>(&(*it));
01638 }
01639
01640
01641 <font class="comment">// ***************************************************************************</font>
<a name="l01642"></a><a class="code" href="classNL3D_1_1CLandscape.html#c15">01642</a> <font class="keywordtype">void</font> CLandscape::loadTile(uint16 tileId)
01643 {
01644 CTile *tile;
01645 CTileInfo *tileInfo;
01646 string textName;
01647
01648 <font class="comment">// Retrieve or create texture.</font>
01649 <font class="comment">// ===========================</font>
01650 <font class="comment">// Tile Must exist.</font>
01651 <font class="comment">// nlassert(tileId==0xFFFF || tileId<TileBank.getTileCount());</font>
01652 <font class="keywordflow">if</font>(tileId<<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileCount())
01653 tile= <a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTile(tileId);
01654 <font class="keywordflow">else</font>
01655 tile= NULL;
01656 <font class="comment">// TileInfo must not exist.</font>
01657 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId]==NULL);
01658 <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId]= tileInfo= <font class="keyword">new</font> CTileInfo;
01659
01660 <font class="comment">// Fill additive part.</font>
01661 <font class="comment">// ===================</font>
01662 <font class="keywordflow">if</font>(tile)
01663 textName= tile->getRelativeFileName(CTile::additive);
01664 <font class="keywordflow">else</font>
01665 textName= <font class="stringliteral">""</font>;
01666 <font class="comment">// If no additive for this tile, rdrpass is NULL.</font>
01667 <font class="keywordflow">if</font>(textName==<font class="stringliteral">""</font>)
01668 tileInfo->AdditiveRdrPass= NULL;
01669 <font class="keywordflow">else</font>
01670 {
01671 <font class="comment">// Fill rdrpass.</font>
01672 CPatchRdrPass pass;
01673 pass.TextureDiffuse= <a class="code" href="classNL3D_1_1CLandscape.html#c17">findTileTexture</a>(<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getAbsPath()+textName);
01674
01675 <font class="comment">// We may have an alpha part for additive.</font>
01676 textName= tile->getRelativeFileName (CTile::alpha);
01677 <font class="keywordflow">if</font>(textName!=<font class="stringliteral">""</font>)
01678 pass.TextureAlpha= <a class="code" href="classNL3D_1_1CLandscape.html#c17">findTileTexture</a>(<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getAbsPath()+textName);
01679
01680 <font class="comment">// Fill tileInfo.</font>
01681 tileInfo->AdditiveRdrPass= <a class="code" href="classNL3D_1_1CLandscape.html#c18">findTileRdrPass</a>(pass);
01682 <font class="comment">// Fill UV Info.</font>
01683 <font class="comment">// NB: for now, One Tile== One Texture, so UVScaleBias is simple.</font>
01684 tileInfo->AdditiveUvScaleBias.x= 0;
01685 tileInfo->AdditiveUvScaleBias.y= 0;
01686 tileInfo->AdditiveUvScaleBias.z= 1;
01687 }
01688
01689
01690 <font class="comment">// Fill diffuse part.</font>
01691 <font class="comment">// =======================</font>
01692 <font class="comment">// Fill rdrpass.</font>
01693 CPatchRdrPass pass;
01694 <font class="comment">// The diffuse part for a tile is inevitable.</font>
01695 <font class="keywordflow">if</font>(tile)
01696 {
01697 textName= tile->getRelativeFileName(CTile::diffuse);
01698 <font class="keywordflow">if</font>(textName!=<font class="stringliteral">""</font>)
01699 pass.TextureDiffuse= <a class="code" href="classNL3D_1_1CLandscape.html#c17">findTileTexture</a>(<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getAbsPath()+textName);
01700 <font class="keywordflow">else</font>
01701 {
01702 pass.TextureDiffuse= <font class="keyword">new</font> CTextureCross;
01703 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"Missing Tile diffuse texname: %d"</font>, tileId);
01704 }
01705 }
01706 <font class="keywordflow">else</font>
01707 pass.TextureDiffuse= <font class="keyword">new</font> CTextureCross;
01708 <font class="keywordflow">if</font>(tile)
01709 {
01710 textName= tile->getRelativeFileName (CTile::alpha);
01711 <font class="keywordflow">if</font>(textName!=<font class="stringliteral">""</font>)
01712 pass.TextureAlpha= <a class="code" href="classNL3D_1_1CLandscape.html#c17">findTileTexture</a>(<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getAbsPath()+textName);
01713 }
01714
01715
01716 <font class="comment">// Fill tileInfo.</font>
01717 tileInfo->DiffuseRdrPass= <a class="code" href="classNL3D_1_1CLandscape.html#c18">findTileRdrPass</a>(pass);
01718 <font class="comment">// Fill UV Info.</font>
01719 <font class="comment">// NB: for now, One Tile== One Texture, so UVScaleBias is simple.</font>
01720 tileInfo->DiffuseUvScaleBias.x= 0;
01721 tileInfo->DiffuseUvScaleBias.y= 0;
01722 tileInfo->DiffuseUvScaleBias.z= 1;
01723 tileInfo->AlphaUvScaleBias.x= 0;
01724 tileInfo->AlphaUvScaleBias.y= 0;
01725 tileInfo->AlphaUvScaleBias.z= 1;
01726 <font class="comment">// Retrieve the good rot alpha decal.</font>
01727 <font class="keywordflow">if</font>(tile)
01728 tileInfo->RotAlpha= tile->getRotAlpha();
01729 <font class="keywordflow">else</font>
01730 tileInfo->RotAlpha= 0;
01731
01732
01733 <font class="comment">// Increment RefCount of RenderPart.</font>
01734 <font class="comment">// =================================</font>
01735 <font class="keywordflow">if</font>(tileInfo->AdditiveRdrPass)
01736 tileInfo->AdditiveRdrPass->RefCount++;
01737 <font class="keywordflow">if</font>(tileInfo->DiffuseRdrPass)
01738 tileInfo->DiffuseRdrPass->RefCount++;
01739
01740 }
01741
01742
01743 <font class="comment">// ***************************************************************************</font>
<a name="l01744"></a><a class="code" href="classNL3D_1_1CLandscape.html#c16">01744</a> <font class="keywordtype">void</font> CLandscape::releaseTile(uint16 tileId)
01745 {
01746 CTileInfo *tileInfo;
01747 tileInfo= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01748 <a class="code" href="debug_8h.html#a6">nlassert</a>(tileInfo!=NULL);
01749
01750 <font class="comment">// "Release" the rdr pass.</font>
01751 <font class="keywordflow">if</font>(tileInfo->AdditiveRdrPass)
01752 tileInfo->AdditiveRdrPass->RefCount--;
01753 <font class="keywordflow">if</font>(tileInfo->DiffuseRdrPass)
01754 tileInfo->DiffuseRdrPass->RefCount--;
01755
01756 <font class="keyword">delete</font> tileInfo;
01757 <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId]= NULL;
01758 }
01759
01760
01761 <font class="comment">// ***************************************************************************</font>
<a name="l01762"></a><a class="code" href="classNL3D_1_1CLandscape.html#c2">01762</a> CPatchRdrPass *CLandscape::getTileRenderPass(uint16 tileId, <font class="keywordtype">bool</font> additiveRdrPass)
01763 {
01764 CTileInfo *tile= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01765
01766 <font class="comment">// If not here, create it.</font>
01767 <font class="comment">//========================</font>
01768 <font class="keywordflow">if</font>(tile==NULL)
01769 {
01770 <font class="comment">// Force loading of tile.</font>
01771 <a class="code" href="classNL3D_1_1CLandscape.html#c15">loadTile</a>(tileId);
01772
01773 tile= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01774 <a class="code" href="debug_8h.html#a6">nlassert</a>(tile!=NULL);
01775 }
01776
01777 <font class="comment">// Retrieve.</font>
01778 <font class="comment">//========================</font>
01779 <font class="keywordflow">if</font>(additiveRdrPass)
01780 {
01781 <font class="comment">// NB: additive pass is not lighted by the lightmap, so there is no lighted version of this rednerpass.</font>
01782 <font class="keywordflow">return</font> tile->AdditiveRdrPass;
01783 }
01784 <font class="keywordflow">else</font>
01785 {
01786 <font class="keywordflow">return</font> tile->DiffuseRdrPass;
01787 }
01788 }
01789
01790
01791 <font class="comment">// ***************************************************************************</font>
<a name="l01792"></a><a class="code" href="classNL3D_1_1CLandscape.html#c3">01792</a> <font class="keywordtype">void</font> CLandscape::getTileUvScaleBiasRot(uint16 tileId, CTile::TBitmap bitmapType, CVector &uvScaleBias, uint8 &rotAlpha)
01793 {
01794 CTileInfo *tile= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01795 <font class="comment">// tile should not be NULL.</font>
01796 <font class="comment">// Because load of tiles are always done in getTileRenderPass(), and this insertion always succeed.</font>
01797 <a class="code" href="debug_8h.html#a6">nlassert</a>(tile);
01798
01799 rotAlpha= 0;
01800 <font class="keywordflow">switch</font>(bitmapType)
01801 {
01802 <font class="keywordflow">case</font> CTile::diffuse:
01803 uvScaleBias= tile->DiffuseUvScaleBias; <font class="keywordflow">break</font>;
01804 <font class="keywordflow">case</font> CTile::additive:
01805 uvScaleBias= tile->AdditiveUvScaleBias; <font class="keywordflow">break</font>;
01806 <font class="keywordflow">case</font> CTile::alpha:
01807 uvScaleBias= tile->AlphaUvScaleBias;
01808 rotAlpha= tile->RotAlpha;
01809 <font class="keywordflow">break</font>;
01810 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>;
01811 }
01812 }
01813
01814
01815 <font class="comment">// ***************************************************************************</font>
<a name="l01816"></a><a class="code" href="classNL3D_1_1CLandscape.html#z482_2">01816</a> <a class="code" href="classNLMISC_1_1CSmartPtr.html">NLMISC::CSmartPtr<ITexture></a> CLandscape::getTileTexture(uint16 tileId, CTile::TBitmap bitmapType, CVector &uvScaleBias)
01817 {
01818 CPatchRdrPass *pass;
01819 <font class="keywordflow">if</font>(bitmapType== CTile::additive)
01820 pass= <a class="code" href="classNL3D_1_1CLandscape.html#c2">getTileRenderPass</a>(tileId, <font class="keyword">true</font>);
01821 <font class="keywordflow">else</font>
01822 pass= <a class="code" href="classNL3D_1_1CLandscape.html#c2">getTileRenderPass</a>(tileId, <font class="keyword">false</font>);
01823 <font class="keywordflow">if</font>(!pass)
01824 <font class="keywordflow">return</font> NULL;
01825 uint8 dummy;
01826 <a class="code" href="classNL3D_1_1CLandscape.html#c3">getTileUvScaleBiasRot</a>(tileId, bitmapType, uvScaleBias, dummy);
01827
01828 <font class="comment">// return the wanted texture.</font>
01829 <font class="keywordflow">if</font>(bitmapType==CTile::diffuse || bitmapType==CTile::additive)
01830 <font class="keywordflow">return</font> pass->TextureDiffuse;
01831 <font class="keywordflow">else</font>
01832 <font class="keywordflow">return</font> pass->TextureAlpha;
01833 }
01834
01835
01836 <font class="comment">// ***************************************************************************</font>
<a name="l01837"></a><a class="code" href="classNL3D_1_1CLandscape.html#z482_3">01837</a> CTileElement *CLandscape::getTileElement(<font class="keyword">const</font> CPatchIdent &patchId, <font class="keyword">const</font> CUV &uv)
01838 {
01839 <font class="comment">// \todo yoyo: TODO_ZONEID: change ZoneId in 32 bits...</font>
01840 std::map<uint16, CZone*>::const_iterator it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find((uint16)patchId.ZoneId);
01841 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
01842 {
01843 sint N= (*it).second->getNumPatchs();
01844 <font class="comment">// patch must exist in the zone.</font>
01845 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId.PatchId<N);
01846 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<CZone*>((*it).second)->getPatch(patchId.PatchId);
01847 <font class="keywordflow">return</font> pa->getTileElement (uv);
01848 }
01849 <font class="keywordflow">else</font>
01850 <font class="comment">// Return not found</font>
01851 <font class="keywordflow">return</font> NULL;
01852 }
01853
01854
01855 <font class="comment">// ***************************************************************************</font>
<a name="l01856"></a><a class="code" href="classNL3D_1_1CLandscape.html#z482_0">01856</a> <font class="keywordtype">void</font> CLandscape::flushTiles(IDriver *drv, uint16 tileStart, uint16 nbTiles)
01857 {
01858 <font class="comment">// Load tile rdrpass, force setup the texture.</font>
01859 <font class="keywordflow">for</font>(sint tileId= tileStart; tileId<tileStart+nbTiles; tileId++)
01860 {
01861 CTileInfo *tile= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01862 <font class="keywordflow">if</font>(tile==NULL)
01863 {
01864 <a class="code" href="classNL3D_1_1CLandscape.html#c15">loadTile</a>(tileId);
01865 }
01866 }
01867
01868 <font class="comment">// For all rdrpass, force setup the texture.</font>
01869 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> it;
01870 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.begin(); it!=<a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.end(); it++)
01871 {
01872 <font class="keyword">const</font> CPatchRdrPass &pass= *it;
01873 <font class="comment">// If present and not already setuped...</font>
01874 <font class="keywordflow">if</font>(pass.TextureDiffuse && !pass.TextureDiffuse->setupedIntoDriver())
01875 drv->setupTexture(*pass.TextureDiffuse);
01876 <font class="comment">// If present and not already setuped...</font>
01877 <font class="keywordflow">if</font>(pass.TextureAlpha && !pass.TextureAlpha->setupedIntoDriver())
01878 drv->setupTexture(*pass.TextureAlpha);
01879 }
01880 }
01881
01882
01883 <font class="comment">// ***************************************************************************</font>
<a name="l01884"></a><a class="code" href="classNL3D_1_1CLandscape.html#z482_1">01884</a> <font class="keywordtype">void</font> CLandscape::releaseTiles(uint16 tileStart, uint16 nbTiles)
01885 {
01886 <font class="comment">// release tiles.</font>
01887 <font class="keywordflow">for</font>(sint tileId= tileStart; tileId<tileStart+nbTiles; tileId++)
01888 {
01889 CTileInfo *tile= <a class="code" href="classNL3D_1_1CLandscape.html#o9">TileInfos</a>[tileId];
01890 <font class="keywordflow">if</font>(tile!=NULL)
01891 {
01892 <a class="code" href="classNL3D_1_1CLandscape.html#c16">releaseTile</a>(tileId);
01893 }
01894 }
01895
01896 <font class="comment">// For all rdrpass, release one that are no more referenced.</font>
01897 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> it;
01898 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.begin(); it!=<a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.end();)
01899 {
01900 <font class="comment">// If no more tile access the rdrpass, delete it.</font>
01901 <font class="keywordflow">if</font>((*it).RefCount==0)
01902 {
01903 <a class="code" href="classNL3D_1_1CLandscape.html#u4">ItTileRdrPassSet</a> itDel=it++;
01904 <a class="code" href="classNL3D_1_1CLandscape.html#o8">TileRdrPassSet</a>.erase(itDel);
01905 }
01906 <font class="keywordflow">else</font>
01907 it++;
01908 }
01909
01910 <font class="comment">// Textures are automaticly deleted by smartptr, but not their entry int the map (TileTextureMap). </font>
01911 <font class="comment">// => doesn't matter since findTileTexture() manages this case.</font>
01912 <font class="comment">// And the memory overhead is not a problem (we talk about pointers).</font>
01913 }
01914
01915
01916 <font class="comment">// ***************************************************************************</font>
<a name="l01917"></a><a class="code" href="classNL3D_1_1CLandscape.html#z492_0">01917</a> uint CLandscape::getTileLightMap(CRGBA map[<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>*<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>], CPatchRdrPass *&lightmapRdrPass)
01918 {
01919 sint textNum;
01920 uint lightMapId;
01921 <font class="comment">/* </font>
01922 <font class="comment"> NB: TextureNear are a grow only Array... TextureNear are never deleted. Why? :</font>
01923 <font class="comment"> 2/ Unused near texture may be uncahced by opengl (and maybe by windows, to disk).</font>
01924 <font class="comment"></font>
01925 <font class="comment"> (old reason, no longer valid, since lightmaps are unlinked from tiles.</font>
01926 <font class="comment"> 1/ There is an important issue with releasing texture nears: tiles may acces them (see getTileRenderPass())</font>
01927 <font class="comment"> )</font>
01928 <font class="comment"> */</font>
01929 <font class="comment">// 0. Alloc Near Texture if necessary.</font>
01930 <font class="comment">//====================================</font>
01931 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#o11">_NFreeLightMaps</a>==0)
01932 {
01933 CTextureNear *text= <font class="keyword">new</font> CTextureNear(<a class="code" href="namespaceNL3D.html#a67">TextureNearSize</a>);
01934 <a class="code" href="classNLMISC_1_1CSmartPtr.html">TSPRenderPass</a> newPass= <font class="keyword">new</font> CPatchRdrPass;
01935
01936 newPass->TextureDiffuse= text;
01937
01938 <a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.push_back(newPass);
01939 <a class="code" href="classNL3D_1_1CLandscape.html#o11">_NFreeLightMaps</a>+= text->getNbAvailableTiles();
01940 }
01941
01942 <font class="comment">// 1. Search the first texture which has a free tile.</font>
01943 <font class="comment">//==================================================</font>
01944 CTextureNear *nearText= NULL;
01945 CPatchRdrPass *nearRdrPass= NULL;
01946 <font class="keywordflow">for</font>(textNum=0;textNum<(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size();textNum++)
01947 {
01948 nearRdrPass= <a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>[textNum];
01949 nearText= (CTextureNear*)(ITexture*)nearRdrPass->TextureDiffuse;
01950 <font class="keywordflow">if</font>(nearText->getNbAvailableTiles()!=0)
01951 <font class="keywordflow">break</font>;
01952 }
01953 <a class="code" href="debug_8h.html#a6">nlassert</a>(textNum<(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size());
01954 <font class="comment">// A empty space has been found.</font>
01955 <a class="code" href="classNL3D_1_1CLandscape.html#o11">_NFreeLightMaps</a>--;
01956
01957 <font class="comment">// 2. Fill the texture with the data, and updaterect.</font>
01958 <font class="comment">//===================================================</font>
01959 lightMapId= nearText->getTileAndFillRect(map);
01960 <font class="comment">// Compute the Id.</font>
01961 lightMapId= textNum*<a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a> + lightMapId;
01962
01963
01964 <font class="comment">// 3. updateLighting</font>
01965 <font class="comment">//===================================================</font>
01966 <font class="comment">// Increment number of pixels to update for near.</font>
01967 <a class="code" href="classNL3D_1_1CLandscape.html#z498_12">_ULTotalNearPixels</a>+= <a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>*<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>;
01968
01969
01970 <font class="comment">// Result:</font>
01971 lightmapRdrPass= nearRdrPass;
01972 <font class="keywordflow">return</font> lightMapId;
01973 }
01974 <font class="comment">// ***************************************************************************</font>
<a name="l01975"></a><a class="code" href="classNL3D_1_1CLandscape.html#z492_1">01975</a> <font class="keywordtype">void</font> CLandscape::getTileLightMapUvInfo(uint tileLightMapId, CVector &uvScaleBias)
01976 {
01977 uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
01978
01979 <font class="comment">// Scale.</font>
01980 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">float</font> scale10= (float)<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>/<a class="code" href="namespaceNL3D.html#a67">TextureNearSize</a>;
01981 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">float</font> scale4= 4.f/<a class="code" href="namespaceNL3D.html#a67">TextureNearSize</a>;
01982 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">float</font> scale1= 1.f/<a class="code" href="namespaceNL3D.html#a67">TextureNearSize</a>;
01983 <font class="comment">// The size of a minilightmap, mapped onto the polygon, is still 4 pixels.</font>
01984 uvScaleBias.z= scale4;
01985
01986 <font class="comment">// Get the id local in the texture.</font>
01987 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>= tileLightMapId%<a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a>;
01988
01989 <font class="comment">// Commpute UVBias.</font>
01990 <font class="comment">// Get the coordinate of the tile, in tile number.</font>
01991 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>%<a class="code" href="namespaceNL3D.html#a68">NbTileLightMapByLine</a>;
01992 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>/<a class="code" href="namespaceNL3D.html#a68">NbTileLightMapByLine</a>;
01993 <font class="comment">// But the real size of a minilightmap is 10 pixels, and we must reach the pixel 1,1.</font>
01994 uvScaleBias.x= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>*scale10 + scale1;
01995 uvScaleBias.y= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*scale10 + scale1;
01996 }
01997 <font class="comment">// ***************************************************************************</font>
<a name="l01998"></a><a class="code" href="classNL3D_1_1CLandscape.html#z492_2">01998</a> <font class="keywordtype">void</font> CLandscape::releaseTileLightMap(uint tileLightMapId)
01999 {
02000 uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, textNum;
02001
02002 <font class="comment">// Get the id local in the texture.</font>
02003 textNum= tileLightMapId / <a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a>;
02004 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>= tileLightMapId % <a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a>;
02005 <a class="code" href="debug_8h.html#a6">nlassert</a>(textNum>=0 && textNum<<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size());
02006
02007 <font class="comment">// Release the tile in this texture.</font>
02008 CPatchRdrPass *nearRdrPass= <a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>[textNum];
02009 CTextureNear *nearText= (CTextureNear*)(ITexture*)nearRdrPass->TextureDiffuse;
02010 nearText->releaseTile(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
02011 <a class="code" href="classNL3D_1_1CLandscape.html#o11">_NFreeLightMaps</a>++;
02012
02013 <font class="comment">// updateLighting</font>
02014 <font class="comment">// Decrement number of pixels to update for near.</font>
02015 <a class="code" href="classNL3D_1_1CLandscape.html#z498_12">_ULTotalNearPixels</a>-= <a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>*<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>;
02016 }
02017
02018
02019 <font class="comment">// ***************************************************************************</font>
<a name="l02020"></a><a class="code" href="classNL3D_1_1CLandscape.html#z492_3">02020</a> <font class="keywordtype">void</font> CLandscape::refillTileLightMap(uint tileLightMapId, CRGBA map[<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>*<a class="code" href="texture__near_8h.html#a0">NL_TILE_LIGHTMAP_SIZE</a>])
02021 {
02022 uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, textNum;
02023
02024 <font class="comment">// Get the id local in the texture.</font>
02025 textNum= tileLightMapId / <a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a>;
02026 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>= tileLightMapId % <a class="code" href="namespaceNL3D.html#a69">NbTileLightMapByTexture</a>;
02027 <a class="code" href="debug_8h.html#a6">nlassert</a>(textNum>=0 && textNum<<a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>.size());
02028
02029 <font class="comment">// get a ptr on the texture.</font>
02030 CPatchRdrPass *nearRdrPass= <a class="code" href="classNL3D_1_1CLandscape.html#o10">_TextureNears</a>[textNum];
02031 CTextureNear *nearText= (CTextureNear*)(ITexture*)nearRdrPass->TextureDiffuse;
02032
02033 <font class="comment">// refill this tile</font>
02034 nearText->refillRect(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, map);
02035 }
02036
02037
02038
02039 <font class="comment">// ***************************************************************************</font>
02040 <font class="comment">// ***************************************************************************</font>
02041 <font class="comment">// Far.</font>
02042 <font class="comment">// ***************************************************************************</font>
02043 <font class="comment">// ***************************************************************************</font>
02044
02045
02046 <font class="comment">// ***************************************************************************</font>
<a name="l02047"></a><a class="code" href="classNL3D_1_1CLandscape.html#c0">02047</a> CPatchRdrPass* CLandscape::getFarRenderPass(CPatch* pPatch, uint farIndex, <font class="keywordtype">float</font>& farUScale, <font class="keywordtype">float</font>& farVScale, <font class="keywordtype">float</font>& farUBias, <font class="keywordtype">float</font>& farVBias, <font class="keywordtype">bool</font>& bRot)
02048 {
02049 <font class="comment">// Check args</font>
02050 <a class="code" href="debug_8h.html#a6">nlassert</a> (farIndex>0);
02051
02052 <font class="comment">// Get size of the far texture</font>
02053 uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>=(pPatch->getOrderS ()*<a class="code" href="tile__far__bank_8h.html#a1">NL_NUM_PIXELS_ON_FAR_TILE_EDGE</a>)>>(farIndex-1);
02054 uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=(pPatch->getOrderT ()*<a class="code" href="tile__far__bank_8h.html#a1">NL_NUM_PIXELS_ON_FAR_TILE_EDGE</a>)>>(farIndex-1);
02055
02056 <font class="comment">// For updateLighting: increment total of pixels to update.</font>
02057 <a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>+= <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>;
02058
02059 <font class="comment">// Render pass index</font>
02060 uint passIndex=<a class="code" href="classNL3D_1_1CLandscape.html#f0">getRdrPassIndexWithSize</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02061
02062 <font class="comment">// Look for a free render pass</font>
02063 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].begin()==<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].end())
02064 {
02065 <font class="comment">// Empty, add a new render pass</font>
02066 CPatchRdrPass *pass=<font class="keyword">new</font> CPatchRdrPass;
02067
02068 <font class="comment">// Fill the render pass</font>
02069 CTextureFar *pTextureFar=<font class="keyword">new</font> CTextureFar;
02070
02071 <font class="comment">// Append this textureFar to the list of TextureFar to updateLighting.</font>
02072 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>==NULL)
02073 <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>= pTextureFar;
02074 <font class="keywordflow">else</font>
02075 pTextureFar->linkBeforeUL(<a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>);
02076
02077 <font class="comment">// Set the bank</font>
02078 pTextureFar->_Bank=&<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>;
02079
02080 <font class="comment">// Set as diffuse texture for this renderpass</font>
02081 pass->TextureDiffuse=pTextureFar;
02082
02083 <font class="comment">// Set the size for this texture</font>
02084 pTextureFar->setSizeOfFarPatch (std::max (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>), std::min (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>));
02085
02086 <font class="comment">// Add the render pass</font>
02087 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].insert (pass);
02088 <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.insert (pass);
02089 }
02090
02091 <font class="comment">// Ok, add the patch to the first render pass in the free list</font>
02092 <a class="code" href="classNLMISC_1_1CSmartPtr.html">TSPRenderPass</a> pass=*<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].begin();
02093
02094 <font class="comment">// Get a pointer on the diffuse far texture</font>
02095 CTextureFar *pTextureFar=(CTextureFar*)(&*(pass->TextureDiffuse));
02096
02097 <font class="comment">// Add the patch to the far texture</font>
02098 <font class="keywordflow">if</font> (pTextureFar->addPatch (pPatch, farUScale, farVScale, farUBias, farVBias, bRot))
02099 {
02100 <font class="comment">// The render state is full, remove from the free list..</font>
02101 _FarRdrPassSetVectorFree[passIndex].erase (pass);
02102 }
02103
02104 <font class="comment">// Return the renderpass</font>
02105 <font class="keywordflow">return</font> pass;
02106 }
02107
02108
02109 <font class="comment">// ***************************************************************************</font>
<a name="l02110"></a><a class="code" href="classNL3D_1_1CLandscape.html#c1">02110</a> <font class="keywordtype">void</font> CLandscape::freeFarRenderPass (CPatch* pPatch, CPatchRdrPass* pass, uint farIndex)
02111 {
02112 <font class="comment">// Get size of the far texture</font>
02113 uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>=(pPatch->getOrderS ()*<a class="code" href="tile__far__bank_8h.html#a1">NL_NUM_PIXELS_ON_FAR_TILE_EDGE</a>)>>(farIndex-1);
02114 uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=(pPatch->getOrderT ()*<a class="code" href="tile__far__bank_8h.html#a1">NL_NUM_PIXELS_ON_FAR_TILE_EDGE</a>)>>(farIndex-1);
02115
02116 <font class="comment">// For updateLighting: decrement total of pixels to update.</font>
02117 <a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>-= <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>;
02118 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>>=0);
02119
02120 <font class="comment">// Render pass index</font>
02121 uint passIndex=<a class="code" href="classNL3D_1_1CLandscape.html#f0">getRdrPassIndexWithSize</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02122
02123 <font class="comment">// Get a pointer on the diffuse far texture</font>
02124 CTextureFar *pTextureFar=(CTextureFar*)(&*(pass->TextureDiffuse));
02125
02126 <font class="comment">// Remove from the patch from the texture if empty</font>
02127 <font class="keywordflow">if</font> (pTextureFar->removePatch (pPatch))
02128 {
02129 <font class="comment">// Free list empty ?</font>
02130 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].begin()==<a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].end())
02131 {
02132 <font class="comment">// Let this render pass in the free list</font>
02133 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].insert (pass);
02134 }
02135 <font class="keywordflow">else</font>
02136 {
02137 <font class="comment">// Release for good</font>
02138 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].erase (pass);
02139
02140 <font class="comment">// update UL links, and Remove from draw list</font>
02141 <a class="code" href="classNL3D_1_1CLandscape.html#c11">eraseFarRenderPassFromSet</a> (pass);
02142 }
02143 }
02144 <font class="keywordflow">else</font>
02145 {
02146 <font class="comment">// Insert in the free list</font>
02147 <a class="code" href="classNL3D_1_1CLandscape.html#o15">_FarRdrPassSetVectorFree</a>[passIndex].insert (pass);
02148 }
02149 }
02150
02151
02152 <font class="comment">// ***************************************************************************</font>
<a name="l02153"></a><a class="code" href="classNL3D_1_1CLandscape.html#c11">02153</a> <font class="keywordtype">void</font> CLandscape::eraseFarRenderPassFromSet (CPatchRdrPass* pass)
02154 {
02155 <font class="comment">// Before deleting, must remove TextureFar from UpdateLighting list.</font>
02156
02157 <font class="comment">// Get a pointer on the diffuse far texture</font>
02158 CTextureFar *pTextureFar=(CTextureFar*)(&*(pass->TextureDiffuse));
02159
02160 <font class="comment">// If I delete the textureFar which is the current root</font>
02161 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>==pTextureFar)
02162 {
02163 <font class="comment">// switch to next</font>
02164 <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>= pTextureFar->getNextUL();
02165 <font class="comment">// if still the same, it means that the circular list is now empty</font>
02166 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>==pTextureFar)
02167 <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>= NULL;
02168 <font class="comment">// reset patch counter.</font>
02169 <a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>= 0;
02170 }
02171
02172 <font class="comment">// unlink the texture from list</font>
02173 pTextureFar->unlinkUL();
02174
02175
02176 <font class="comment">// Remove from draw list</font>
02177 <a class="code" href="classNL3D_1_1CLandscape.html#o14">_FarRdrPassSet</a>.erase (pass);
02178 }
02179
02180
02181 <font class="comment">// ***************************************************************************</font>
02182 <font class="comment">// ***************************************************************************</font>
02183 <font class="comment">// Misc.</font>
02184 <font class="comment">// ***************************************************************************</font>
02185 <font class="comment">// ***************************************************************************</font>
02186
02187
02188 <font class="comment">// ***************************************************************************</font>
<a name="l02189"></a><a class="code" href="classNL3D_1_1CLandscape.html#z481_0">02189</a> CZone* CLandscape::getZone (sint zoneId)
02190 {
02191 TZoneMap::iterator it;
02192 it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId);
02193 <font class="keywordflow">if</font> (it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
02194 <font class="keywordflow">return</font> (*it).second;
02195 <font class="keywordflow">else</font>
02196 <font class="keywordflow">return</font> NULL;
02197 }
02198
02199
02200 <font class="comment">// ***************************************************************************</font>
<a name="l02201"></a><a class="code" href="classNL3D_1_1CLandscape.html#z481_1">02201</a> <font class="keyword">const</font> CZone* CLandscape::getZone (sint zoneId)<font class="keyword"> const</font>
02202 <font class="keyword"></font>{
02203 TZoneMap::const_iterator it;
02204
02205 it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId);
02206 <font class="keywordflow">if</font> (it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
02207 <font class="keywordflow">return</font> (*it).second;
02208 <font class="keywordflow">else</font>
02209 <font class="keywordflow">return</font> NULL;
02210 }
02211
02212
02213
02214 <font class="comment">// ***************************************************************************</font>
<a name="l02215"></a><a class="code" href="classNL3D_1_1CLandscape.html#c19">02215</a> <font class="keywordtype">void</font> CLandscape::checkZoneBinds(CZone &curZone, EBadBind &bindError)
02216 {
02217 <font class="keywordflow">for</font>(sint i=0;i<curZone.getNumPatchs();i++)
02218 {
02219 <font class="keyword">const</font> CZone::CPatchConnect &pa= *curZone.getPatchConnect(i);
02220
02221 <font class="comment">// Check the bindInfos.</font>
02222 <font class="keywordflow">for</font>(sint j=0;j<4;j++)
02223 {
02224 <font class="keyword">const</font> CPatchInfo::CBindInfo &bd=pa.BindEdges[j];
02225 <font class="comment">// Just 1/1 for now.</font>
02226 <font class="keywordflow">if</font>(bd.NPatchs==1)
02227 {
02228 <a class="code" href="classNL3D_1_1CLandscape.html#l2">CZone</a> *oZone= <a class="code" href="classNL3D_1_1CLandscape.html#z481_0">getZone</a>(bd.ZoneId);
02229 <font class="comment">// If loaded zone.</font>
02230 <font class="keywordflow">if</font>(oZone)
02231 {
02232 <font class="keyword">const</font> CZone::CPatchConnect &po= *(oZone->getPatchConnect(bd.Next[0]));
02233 <font class="keyword">const</font> CPatchInfo::CBindInfo &bo= po.BindEdges[bd.Edge[0]];
02234 <font class="keywordflow">if</font>(bo.NPatchs!=1 || bo.Next[0]!=i || bo.Edge[0]!=j)
02235 bindError.BindErrors.push_back( EBadBind::CBindError(curZone.getZoneId(), i));
02236 }
02237 }
02238 }
02239 }
02240 }
02241
02242
02243 <font class="comment">// ***************************************************************************</font>
<a name="l02244"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_4">02244</a> <font class="keywordtype">void</font> CLandscape::checkBinds() <font class="keywordflow">throw</font>(EBadBind)
02245 {
02246 EBadBind bindError;
02247
02248 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= Zones.begin();it!=Zones.end();it++)
02249 {
02250 CZone &curZone= *(*it).second;
02251 checkZoneBinds(curZone, bindError);
02252 }
02253
02254 <font class="keywordflow">if</font>(!bindError.BindErrors.empty())
02255 <font class="keywordflow">throw</font> bindError;
02256 }
02257
02258
02259 <font class="comment">// ***************************************************************************</font>
<a name="l02260"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_5">02260</a> <font class="keywordtype">void</font> CLandscape::checkBinds(uint16 zoneId) <font class="keywordflow">throw</font>(EBadBind)
02261 {
02262 EBadBind bindError;
02263
02264 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= Zones.find(zoneId);
02265 <font class="keywordflow">if</font>(it!= Zones.end())
02266 {
02267 CZone &curZone= *(*it).second;
02268 checkZoneBinds(curZone, bindError);
02269 <font class="keywordflow">if</font>(!bindError.BindErrors.empty())
02270 <font class="keywordflow">throw</font> bindError;
02271 }
02272 }
02273
02274
02275
02276 <font class="comment">// ***************************************************************************</font>
<a name="l02277"></a><a class="code" href="classNL3D_1_1CLandscape.html#z493_0">02277</a> <font class="keywordtype">void</font> CLandscape::addTrianglesInBBox(<font class="keyword">const</font> CPatchIdentEx &paIdEx, <font class="keyword">const</font> CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tileTessLevel)<font class="keyword"> const</font>
02278 <font class="keyword"></font>{
02279 <font class="comment">// No clear here, just add triangles to the array.</font>
02280 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= paIdEx.Patch;
02281
02282 CPatchIdent paId;
02283 paId.ZoneId= paIdEx.ZoneId;
02284 paId.PatchId= paIdEx.PatchId;
02285 pa->addTrianglesInBBox(paId, bbox, triangles, tileTessLevel);
02286 }
02287
02288
02289 <font class="comment">// ***************************************************************************</font>
<a name="l02290"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_2">02290</a> <font class="keywordtype">void</font> CLandscape::buildTrianglesInBBox(<font class="keyword">const</font> CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tileTessLevel)
02291 {
02292 <font class="comment">// clear selection.</font>
02293 triangles.clear();
02294
02295 <font class="comment">// search path of interest.</font>
02296 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.clearSelection();
02297 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.select(bbox.getMin(), bbox.getMax());
02298 CQuadGrid<CPatchIdentEx>::CIterator it;
02299
02300 <font class="comment">// for each patch, add triangles to the array.</font>
02301 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.begin(); it!= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.end(); it++)
02302 {
02303 <a class="code" href="classNL3D_1_1CLandscape.html#z493_0">addTrianglesInBBox</a>((*it), bbox, triangles, tileTessLevel);
02304 }
02305 }
02306
02307
02308
02309 <font class="comment">// ***************************************************************************</font>
<a name="l02310"></a><a class="code" href="classNL3D_1_1CLandscape.html#z493_1">02310</a> <font class="keywordtype">void</font> CLandscape::addPatchBlocksInBBox(<font class="keyword">const</font> CPatchIdentEx &paIdEx, <font class="keyword">const</font> CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds)
02311 {
02312 <font class="comment">// No clear here, just add blocks to the array.</font>
02313 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= paIdEx.Patch;
02314
02315 CPatchIdent paId;
02316 paId.ZoneId= paIdEx.ZoneId;
02317 paId.PatchId= paIdEx.PatchId;
02318 pa->addPatchBlocksInBBox(paId, bbox, paBlockIds);
02319 }
02320
02321
02322 <font class="comment">// ***************************************************************************</font>
<a name="l02323"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_3">02323</a> <font class="keywordtype">void</font> CLandscape::buildPatchBlocksInBBox(<font class="keyword">const</font> CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds)
02324 {
02325 <font class="comment">// clear selection.</font>
02326 paBlockIds.clear();
02327
02328 <font class="comment">// search path of interest.</font>
02329 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.clearSelection();
02330 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.select(bbox.getMin(), bbox.getMax());
02331 CQuadGrid<CPatchIdentEx>::CIterator it;
02332
02333 <font class="comment">// for each patch, add blocks to the array.</font>
02334 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.begin(); it!= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.end(); it++)
02335 {
02336 <a class="code" href="classNL3D_1_1CLandscape.html#z493_1">addPatchBlocksInBBox</a>((*it), bbox, paBlockIds);
02337 }
02338 }
02339
02340
02341 <font class="comment">// ***************************************************************************</font>
<a name="l02342"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_4">02342</a> <font class="keywordtype">void</font> CLandscape::fillPatchQuadBlock(CPatchQuadBlock &quadBlock)<font class="keyword"> const</font>
02343 <font class="keyword"></font>{
02344 sint zoneId= quadBlock.PatchBlockId.PatchId.ZoneId;
02345 sint patchId= quadBlock.PatchBlockId.PatchId.PatchId;
02346 std::map<uint16, CZone*>::const_iterator it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId);
02347 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
02348 {
02349 sint N= (*it).second->getNumPatchs();
02350 <font class="comment">// patch must exist in the zone.</font>
02351 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId>=0);
02352 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId<N);
02353
02354 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(patchId);
02355 pa->fillPatchQuadBlock(quadBlock);
02356 }
02357 }
02358
02359
02360
02361
02362 <font class="comment">// ***************************************************************************</font>
<a name="l02363"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_0">02363</a> <font class="keywordtype">void</font> CLandscape::buildCollideFaces(<font class="keyword">const</font> CAABBoxExt &bbox, vector<CTriangle> &faces, <font class="keywordtype">bool</font> faceClip)
02364 {
02365 CBSphere bsWanted(bbox.getCenter(), bbox.getRadius());
02366
02367 faces.clear();
02368 <font class="comment">// For all zones.</font>
02369 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
02370 {
02371 <font class="keyword">const</font> CAABBoxExt &bb= (*it).second->getZoneBB();
02372 CBSphere bs(bb.getCenter(), bb.getRadius());
02373 <font class="comment">// If zone intersect the wanted area.</font>
02374 <font class="comment">//===================================</font>
02375 <font class="keywordflow">if</font>(bs.intersect(bsWanted))
02376 {
02377 <font class="comment">// Then trace all patch.</font>
02378 sint N= (*it).second->getNumPatchs();
02379 <font class="keywordflow">for</font>(sint i=0;i<N;i++)
02380 {
02381 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(i);
02382
02383 <font class="comment">// If patch in wanted area....</font>
02384 <font class="comment">//============================</font>
02385 <font class="keywordflow">if</font>(bsWanted.intersect(pa->getBSphere()))
02386 {
02387 <font class="comment">// 0. Build the faces.</font>
02388 <font class="comment">//====================</font>
02389 sint ordS= pa->getOrderS();
02390 sint ordT= pa->getOrderT();
02391 sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>,j;
02392 vector<CTriangle> tmpFaces;
02393 tmpFaces.reserve(ordS*ordT);
02394 <font class="keywordtype">float</font> OOS= 1.0f/ordS;
02395 <font class="keywordtype">float</font> OOT= 1.0f/ordT;
02396 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><ordT;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
02397 {
02398 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><ordS;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
02399 {
02400 CTriangle f;
02401 f.V0= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02402 f.V1= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02403 f.V2= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02404 tmpFaces.push_back(f);
02405 f.V0= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02406 f.V1= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02407 f.V2= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02408 tmpFaces.push_back(f);
02409 }
02410 }
02411
02412 <font class="comment">// 1. Clip the faces.</font>
02413 <font class="comment">//===================</font>
02414 <font class="keywordflow">if</font>(faceClip)
02415 {
02416 <font class="comment">// Insert only faces which are In the area.</font>
02417 <font class="keywordflow">for</font>(j=0;j<(sint)tmpFaces.size();j++)
02418 {
02419 CTriangle &f= tmpFaces[j];
02420 <font class="keywordflow">if</font>(bbox.intersect(f.V0, f.V1, f.V2))
02421 {
02422 faces.push_back(f);
02423 }
02424 }
02425 }
02426 <font class="keywordflow">else</font>
02427 {
02428 <font class="comment">// Else insert ALL.</font>
02429 faces.insert(faces.end(), tmpFaces.begin(), tmpFaces.end());
02430 }
02431 }
02432 }
02433 }
02434 }
02435 }
02436
02437
02438 <font class="comment">// ***************************************************************************</font>
<a name="l02439"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_1">02439</a> <font class="keywordtype">void</font> CLandscape::buildCollideFaces(sint zoneId, sint patch, std::vector<CTriangle> &faces)
02440 {
02441 faces.clear();
02442
02443 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find(zoneId);
02444 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
02445 {
02446 <font class="comment">// Then trace all patch.</font>
02447 sint N= (*it).second->getNumPatchs();
02448 <a class="code" href="debug_8h.html#a6">nlassert</a>(patch>=0);
02449 <a class="code" href="debug_8h.html#a6">nlassert</a>(patch<N);
02450 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(patch);
02451
02452 <font class="comment">// Build the faces.</font>
02453 <font class="comment">//=================</font>
02454 sint ordS= pa->getOrderS();
02455 sint ordT= pa->getOrderT();
02456 sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
02457 <font class="keywordtype">float</font> OOS= 1.0f/ordS;
02458 <font class="keywordtype">float</font> OOT= 1.0f/ordT;
02459 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><ordT;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
02460 {
02461 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><ordS;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
02462 {
02463 CTriangle f;
02464 f.V0= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02465 f.V1= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02466 f.V2= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02467 faces.push_back(f);
02468 f.V0= pa->computeVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02469 f.V1= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, (<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1)*OOT);
02470 f.V2= pa->computeVertex((<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1)*OOS, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*OOT);
02471 faces.push_back(f);
02472 }
02473 }
02474 }
02475 }
02476
02477
02478 <font class="comment">// ***************************************************************************</font>
<a name="l02479"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_5">02479</a> CVector CLandscape::getTesselatedPos(<font class="keyword">const</font> CPatchIdent &patchId, <font class="keyword">const</font> CUV &uv)<font class="keyword"> const</font>
02480 <font class="keyword"></font>{
02481 <font class="comment">// First, must update globals, for CTessFace::computeTesselatedPos() to work properly.</font>
02482
02483 <font class="comment">// VertexProgrma mode???</font>
02484 CLandscapeGlobals::VertexProgramEnabled= <a class="code" href="classNL3D_1_1CLandscape.html#z491_4">_VertexShaderOk</a>;
02485
02486 <font class="comment">// If VertexProgram enabled</font>
02487 <font class="keywordflow">if</font>( CLandscapeGlobals::VertexProgramEnabled )
02488 {
02489 <font class="comment">/* because VertexProgram enabled, CTessVertex::Pos (geomorphed Pos) are not computed each frame</font>
02490 <font class="comment"> Hence, CTessFace::computeTesselatedPos() will call CTessVertex::computeGeomPos() to have correct </font>
02491 <font class="comment"> CTessVertex::Pos. ThereFore we must setup globals so CTessVertex::computeGeomPos() works properly.</font>
02492 <font class="comment"> */</font>
02493
02494 <font class="comment">// see copy in updateGlobalsAndLockBuffers(). NB: Just copy what needed here!!!!</font>
02495
02496 <font class="comment">// Tile subdivsion part.</font>
02497 CLandscapeGlobals::TileDistNear = <a class="code" href="classNL3D_1_1CLandscape.html#o1">_TileDistNear</a>;
02498 CLandscapeGlobals::TileDistFar = CLandscapeGlobals::TileDistNear+20;
02499 CLandscapeGlobals::TileDistNearSqr = <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(CLandscapeGlobals::TileDistNear);
02500 CLandscapeGlobals::TileDistFarSqr = <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(CLandscapeGlobals::TileDistFar);
02501 CLandscapeGlobals::OOTileDistDeltaSqr = 1.0f / (CLandscapeGlobals::TileDistFarSqr - CLandscapeGlobals::TileDistNearSqr);
02502
02503 <font class="comment">// RefineThreshold.</font>
02504 CLandscapeGlobals::RefineThreshold= <a class="code" href="classNL3D_1_1CLandscape.html#o2">_Threshold</a>;
02505 CLandscapeGlobals::OORefineThreshold= 1.0f / CLandscapeGlobals::RefineThreshold;
02506
02507 <font class="comment">// Refine Center*.</font>
02508 <font class="comment">// NB: setup the last setuped refineCenter.</font>
02509 CLandscapeGlobals::RefineCenter= <a class="code" href="classNL3D_1_1CLandscape.html#z495_2">_OldRefineCenter</a>;
02510 }
02511
02512
02513 <font class="comment">// \todo yoyo: TODO_ZONEID: change ZoneId in 32 bits...</font>
02514 std::map<uint16, CZone*>::const_iterator it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find((uint16)patchId.ZoneId);
02515 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
02516 {
02517 sint N= (*it).second->getNumPatchs();
02518 <font class="comment">// patch must exist in the zone.</font>
02519 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId.PatchId<N);
02520 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(patchId.PatchId);
02521
02522 <font class="keywordflow">return</font> pa->getTesselatedPos(uv);
02523 }
02524 <font class="keywordflow">else</font>
02525 <font class="keywordflow">return</font> CVector::Null;
02526 }
02527
02528
02529 <font class="comment">// ***************************************************************************</font>
<a name="l02530"></a><a class="code" href="classNL3D_1_1CLandscape.html#f0">02530</a> uint CLandscape::getRdrPassIndexWithSize (uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>)
02531 {
02532 <font class="comment">// Check no NULL size</font>
02533 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>);
02534 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02535
02536 <font class="comment">// Find width order</font>
02537 <font class="keywordtype">int</font> orderWidth=0;
02538 <font class="keywordflow">while</font> (!(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>&(1<<orderWidth)))
02539 orderWidth++;
02540
02541 <font class="comment">// Find heightorder</font>
02542 <font class="keywordtype">int</font> orderHeight=0;
02543 <font class="keywordflow">while</font> (!(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>&(1<<orderHeight)))
02544 orderHeight++;
02545
02546 <font class="keywordflow">if</font> (orderWidth>orderHeight)
02547 {
02548 <font class="keywordflow">return</font> <a class="code" href="landscape_8h.html#a0">NL_MAX_SIZE_OF_TEXTURE_EDGE_SHIFT</a>*orderHeight+orderWidth;
02549 }
02550 <font class="keywordflow">else</font>
02551 {
02552 <font class="keywordflow">return</font> <a class="code" href="landscape_8h.html#a0">NL_MAX_SIZE_OF_TEXTURE_EDGE_SHIFT</a>*orderWidth+orderHeight;
02553 }
02554 }
02555
<a name="l02556"></a><a class="code" href="landscape_8cpp.html#a6">02556</a> <font class="preprocessor">#define NL_TILE_FAR_SIZE_ORDER0 (NL_NUM_PIXELS_ON_FAR_TILE_EDGE*NL_NUM_PIXELS_ON_FAR_TILE_EDGE)</font>
<a name="l02557"></a><a class="code" href="landscape_8cpp.html#a7">02557</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_TILE_FAR_SIZE_ORDER1 ((NL_NUM_PIXELS_ON_FAR_TILE_EDGE>>1)*(NL_NUM_PIXELS_ON_FAR_TILE_EDGE>>1))</font>
<a name="l02558"></a><a class="code" href="landscape_8cpp.html#a8">02558</a> <font class="preprocessor"></font><font class="preprocessor">#define NL_TILE_FAR_SIZE_ORDER2 ((NL_NUM_PIXELS_ON_FAR_TILE_EDGE>>2)*(NL_NUM_PIXELS_ON_FAR_TILE_EDGE>>2))</font>
02559 <font class="preprocessor"></font>
02560 <font class="comment">// ***************************************************************************</font>
02561 <font class="comment">// internal use</font>
<a name="l02562"></a><a class="code" href="classNL3D_1_1CLandscape.html#c12">02562</a> <font class="keywordtype">bool</font> CLandscape::eraseTileFarIfNotGood (uint tileNumber, uint sizeOrder0, uint sizeOrder1, uint sizeOrder2)
02563 {
02564 <font class="comment">// The same tiles ?</font>
02565 <font class="keywordtype">bool</font> bSame=<font class="keyword">true</font>;
02566
02567 <font class="comment">// It is the same tile ?</font>
02568 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->isFill (CTileFarBank::diffuse))
02569 {
02570 <font class="comment">// Good diffuse size ?</font>
02571 <font class="keywordflow">if</font> (
02572 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::diffuse, CTileFarBank::order0) != sizeOrder0) ||
02573 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::diffuse, CTileFarBank::order1) != sizeOrder1) ||
02574 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::diffuse, CTileFarBank::order2) != sizeOrder2)
02575 )
02576 {
02577 <a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->erasePixels (CTileFarBank::diffuse);
02578 bSame=<font class="keyword">false</font>;
02579 }
02580 }
02581
02582 <font class="comment">// It is the same tile ?</font>
02583 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->isFill (CTileFarBank::additive))
02584 {
02585 <font class="comment">// Good additive size ?</font>
02586 <font class="keywordflow">if</font> (
02587 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::additive, CTileFarBank::order0) != sizeOrder0) ||
02588 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::additive, CTileFarBank::order1) != sizeOrder1) ||
02589 (<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->getSize (CTileFarBank::additive, CTileFarBank::order2) != sizeOrder2)
02590 )
02591 {
02592 <a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getTile (tileNumber)->erasePixels (CTileFarBank::additive);
02593 bSame=<font class="keyword">false</font>;
02594 }
02595 }
02596
02597 <font class="comment">// Return true if the tiles seem to be the sames</font>
02598 <font class="keywordflow">return</font> bSame;
02599 }
02600
02601 <font class="comment">// ***************************************************************************</font>
<a name="l02602"></a><a class="code" href="classNL3D_1_1CLandscape.html#z477_6">02602</a> <font class="keywordtype">bool</font> CLandscape::initTileBanks ()
02603 {
02604 <font class="comment">// *** Check the two banks are OK</font>
02605 <a class="code" href="classNL3D_1_1CLandscape.html#o16">_FarInitialized</a>=<font class="keyword">false</font>;
02606
02607 <font class="comment">// Compatibility check</font>
02608 <font class="keywordtype">bool</font> bCompatibility=<font class="keyword">true</font>;
02609
02610 <font class="comment">// Same number of tiles</font>
02611 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileCount()==<a class="code" href="classNL3D_1_1CLandscape.html#m1">TileFarBank</a>.getNumTile())
02612 {
02613 <font class="comment">// Same tileSet</font>
02614 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> tileSet=0; tileSet<<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSetCount(); tileSet++)
02615 {
02616 <font class="comment">// Same tile128</font>
02617 <font class="keywordtype">int</font> tile;
02618 <font class="keywordflow">for</font> (tile=0; tile<<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSet(tileSet)->getNumTile128(); tile++)
02619 {
02620 <font class="comment">// tile number</font>
02621 uint tileNumber=<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSet(tileSet)->getTile128(tile);
02622
02623 <font class="comment">// erase the tiles if not good</font>
02624 bCompatibility&=<a class="code" href="classNL3D_1_1CLandscape.html#c12">eraseTileFarIfNotGood</a> (tileNumber, <a class="code" href="landscape_8cpp.html#a6">NL_TILE_FAR_SIZE_ORDER0</a>, <a class="code" href="landscape_8cpp.html#a7">NL_TILE_FAR_SIZE_ORDER1</a>, <a class="code" href="landscape_8cpp.html#a8">NL_TILE_FAR_SIZE_ORDER2</a>);
02625 }
02626
02627 <font class="comment">// Same tile256</font>
02628 <font class="keywordflow">for</font> (tile=0; tile<<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSet(tileSet)->getNumTile256(); tile++)
02629 {
02630 <font class="comment">// tile number</font>
02631 uint tileNumber=<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSet(tileSet)->getTile256(tile);
02632
02633 <font class="comment">// erase the tiles if not good</font>
02634 bCompatibility&=<a class="code" href="classNL3D_1_1CLandscape.html#c12">eraseTileFarIfNotGood</a> (tileNumber, <a class="code" href="landscape_8cpp.html#a6">NL_TILE_FAR_SIZE_ORDER0</a><<2, <a class="code" href="landscape_8cpp.html#a7">NL_TILE_FAR_SIZE_ORDER1</a><<2, <a class="code" href="landscape_8cpp.html#a8">NL_TILE_FAR_SIZE_ORDER2</a><<2);
02635 }
02636
02637 <font class="comment">// Same transition</font>
02638 <font class="keywordflow">for</font> (tile=0; tile<CTileSet::count; tile++)
02639 {
02640 <font class="comment">// tile number</font>
02641 uint tileNumber=<a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileSet(tileSet)->getTransition(tile)->getTile();
02642
02643 <font class="comment">// erase the tiles if not good</font>
02644 bCompatibility&=<a class="code" href="classNL3D_1_1CLandscape.html#c12">eraseTileFarIfNotGood</a> (tileNumber, <a class="code" href="landscape_8cpp.html#a6">NL_TILE_FAR_SIZE_ORDER0</a>, <a class="code" href="landscape_8cpp.html#a7">NL_TILE_FAR_SIZE_ORDER1</a>, <a class="code" href="landscape_8cpp.html#a8">NL_TILE_FAR_SIZE_ORDER2</a>);
02645 }
02646 }
02647
02648 <font class="comment">// Far actived!</font>
02649 <a class="code" href="classNL3D_1_1CLandscape.html#o16">_FarInitialized</a>=<font class="keyword">true</font>;
02650 }
02651
02652 <font class="comment">// Register / Load the vegetables.</font>
02653 <a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.initTileVegetableDescs(<a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>);
02654
02655 <font class="keywordflow">return</font> bCompatibility;
02656 }
02657
02658
02659 <font class="comment">// ***************************************************************************</font>
<a name="l02660"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_0">02660</a> <font class="keywordtype">void</font> CLandscape::setupStaticLight (<font class="keyword">const</font> CRGBA &diffuse, <font class="keyword">const</font> CRGBA &ambiant, <font class="keywordtype">float</font> multiply)
02661 {
02662 sint nMultiply=(sint)(256.f*multiply);
02663 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i=0; i<256; i++)
02664 {
02665 sint max=0;
02666 sint <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>=(((nMultiply*diffuse.R*i)>>8)+ambiant.R*(256-i))>>8;
02667 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>>max)
02668 max=<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>;
02669 sint g=(((nMultiply*diffuse.G*i)>>8)+ambiant.G*(256-i))>>8;
02670 <font class="keywordflow">if</font> (g>max)
02671 max=g;
02672 sint b=(((nMultiply*diffuse.B*i)>>8)+ambiant.B*(256-i))>>8;
02673 <font class="keywordflow">if</font> (b>max)
02674 max=b;
02675 <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a><<=8;
02676 g<<=8;
02677 b<<=8;
02678 max=std::max(max, 256);
02679 <a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>/=max;
02680 g/=max;
02681 b/=max;
02682 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>, 0, 255);
02683 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (g, 0, 255);
02684 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (b, 0, 255);
02685 <a class="code" href="classNL3D_1_1CLandscape.html#o17">_LightValue</a>[i].R=<a class="code" href="driver__opengl__extension__def_8h.html#a385">r</a>;
02686 <a class="code" href="classNL3D_1_1CLandscape.html#o17">_LightValue</a>[i].G=g;
02687 <a class="code" href="classNL3D_1_1CLandscape.html#o17">_LightValue</a>[i].B=b;
02688 <a class="code" href="classNL3D_1_1CLandscape.html#o17">_LightValue</a>[i].A=255;
02689 }
02690 }
02691
02692 <font class="comment">// ***************************************************************************</font>
<a name="l02693"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_4">02693</a> <font class="keywordtype">void</font> CLandscape::enableAutomaticLighting(<font class="keywordtype">bool</font> enable)
02694 {
02695 <a class="code" href="classNL3D_1_1CLandscape.html#o18">_AutomaticLighting</a>= enable;
02696 }
02697
02698 <font class="comment">// ***************************************************************************</font>
<a name="l02699"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_5">02699</a> <font class="keywordtype">void</font> CLandscape::setupAutomaticLightDir(<font class="keyword">const</font> CVector &lightDir)
02700 {
02701 <a class="code" href="classNL3D_1_1CLandscape.html#o19">_AutomaticLightDir</a>= lightDir;
02702 <a class="code" href="classNL3D_1_1CLandscape.html#o19">_AutomaticLightDir</a>.normalize();
02703 }
02704
02705
02706 <font class="comment">// ***************************************************************************</font>
<a name="l02707"></a><a class="code" href="classNL3D_1_1CLandscape.html#z484_0">02707</a> CVector CLandscape::getHeightFieldDeltaZ(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>)<font class="keyword"> const</font>
02708 <font class="keyword"></font>{
02709 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>.size()==0)
02710 <font class="keywordflow">return</font> CVector::Null;
02711
02712 <font class="comment">// map to _HeightField coordinates.</font>
02713 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m1">OriginX</a>;
02714 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m2">OriginY</a>;
02715 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m5">OOSizeX</a>;
02716 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m6">OOSizeY</a>;
02717 <font class="comment">// get patch on the grid.</font>
02718 sint ix, iy;
02719 ix= (sint)floor(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
02720 iy= (sint)floor(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
02721 <font class="comment">// out of the grid?</font>
02722 <font class="keywordflow">if</font>( ix<0 || ix>=(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m7">Width</a> || iy<0 || iy>=(sint)<a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m8">Height</a>)
02723 <font class="keywordflow">return</font> CVector::Null;
02724
02725 <font class="comment">// get patch.</font>
02726 <font class="keyword">const</font> CBezierPatchZ &paz= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>[iy*<a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m7">Width</a> + ix];
02727
02728 <font class="comment">// compute result.</font>
02729 CVector ret=CVector::Null;
02730 ret.x= 0;
02731 ret.y= 0;
02732 ret.z= paz.eval(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-ix, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-iy);
02733
02734 <font class="keywordflow">return</font> ret;
02735 }
02736
02737
02738
02739 <font class="comment">// ***************************************************************************</font>
<a name="l02740"></a><a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#a0">02740</a> <font class="keywordtype">void</font> CLandscape::CBezierPatchZ::makeInteriors()
02741 {
02742 <font class="keywordtype">float</font> &a = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[0];
02743 <font class="keywordtype">float</font> &b = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[1];
02744 <font class="keywordtype">float</font> &c = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[2];
02745 <font class="keywordtype">float</font> &d = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[3];
02746 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[0] = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[7] + <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[0] - a;
02747 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[1] = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[1] + <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[2] - b;
02748 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[2] = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[3] + <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[4] - c;
02749 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[3] = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[5] + <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[6] - d;
02750 }
02751 <font class="comment">// ***************************************************************************</font>
<a name="l02752"></a><a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#a1">02752</a> <font class="keywordtype">float</font> CLandscape::CBezierPatchZ::eval(<font class="keywordtype">float</font> ps, <font class="keywordtype">float</font> pt)<font class="keyword"> const</font>
02753 <font class="keyword"></font>{
02754 <font class="keywordtype">float</font> p;
02755
02756 <font class="keywordtype">float</font> ps2 = ps * ps;
02757 <font class="keywordtype">float</font> ps1 = 1.0f - ps;
02758 <font class="keywordtype">float</font> ps12 = ps1 * ps1;
02759 <font class="keywordtype">float</font> s0 = ps12 * ps1;
02760 <font class="keywordtype">float</font> s1 = 3.0f * ps * ps12;
02761 <font class="keywordtype">float</font> s2 = 3.0f * ps2 * ps1;
02762 <font class="keywordtype">float</font> s3 = ps2 * ps;
02763 <font class="keywordtype">float</font> pt2 = pt * pt;
02764 <font class="keywordtype">float</font> pt1 = 1.0f - pt;
02765 <font class="keywordtype">float</font> pt12 = pt1 * pt1;
02766 <font class="keywordtype">float</font> t0 = pt12 * pt1;
02767 <font class="keywordtype">float</font> t1 = 3.0f * pt * pt12;
02768 <font class="keywordtype">float</font> t2 = 3.0f * pt2 * pt1;
02769 <font class="keywordtype">float</font> t3 = pt2 * pt;
02770
02771 p = <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[0] * s0 * t0 +
02772 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[7] * s1 * t0 +
02773 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[6] * s2 * t0 +
02774 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[3] * s3 * t0;
02775 p+= <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[0] * s0 * t1 +
02776 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[0]* s1 * t1 +
02777 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[3]* s2 * t1 +
02778 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[5] * s3 * t1;
02779 p+= <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[1] * s0 * t2 +
02780 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[1]* s1 * t2 +
02781 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m2">Interiors</a>[2]* s2 * t2 +
02782 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[4] * s3 * t2;
02783 p+= <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[1] * s0 * t3 +
02784 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[2] * s1 * t3 +
02785 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m1">Tangents</a>[3] * s2 * t3 +
02786 <a class="code" href="structNL3D_1_1CLandscape_1_1CBezierPatchZ.html#m0">Vertices</a>[2] * s3 * t3;
02787
02788 <font class="keywordflow">return</font> p;
02789 }
02790
02791
02792 <font class="comment">// ***************************************************************************</font>
<a name="l02793"></a><a class="code" href="classNL3D_1_1CLandscape.html#z484_1">02793</a> <font class="keywordtype">void</font> CLandscape::setHeightField(<font class="keyword">const</font> CHeightMap &hf)
02794 {
02795 <font class="keywordflow">if</font>(hf.getWidth()<2)
02796 <font class="keywordflow">return</font>;
02797 <font class="keywordflow">if</font>(hf.getHeight()<2)
02798 <font class="keywordflow">return</font>;
02799
02800 <font class="comment">// Fill basics.</font>
02801 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m1">OriginX</a>= hf.OriginX;
02802 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m2">OriginY</a>= hf.OriginY;
02803 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m3">SizeX</a>= hf.SizeX;
02804 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m4">SizeY</a>= hf.SizeY;
02805 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m5">OOSizeX</a>= 1/hf.SizeX;
02806 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m6">OOSizeY</a>= 1/hf.SizeY;
02807 uint <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= hf.getWidth()-1;
02808 uint h= hf.getHeight()-1;
02809 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m7">Width</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>;
02810 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m8">Height</a>= h;
02811 <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>.resize(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> * h);
02812
02813 <font class="comment">// compute patchs</font>
02814 sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
02815
02816 <font class="comment">// compute vertices / tangents on each patch</font>
02817 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><(sint)h;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
02818 {
02819 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><(sint)<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
02820 {
02821 CBezierPatchZ &paz= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
02822 <font class="comment">// vertices.</font>
02823 paz.Vertices[0]= hf.getZ(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
02824 paz.Vertices[1]= hf.getZ(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1);
02825 paz.Vertices[2]= hf.getZ(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1);
02826 paz.Vertices[3]= hf.getZ(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
02827 }
02828 }
02829
02830 <font class="comment">// compute tangents</font>
02831 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><(sint)h;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
02832 {
02833 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><(sint)<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
02834 {
02835 CBezierPatchZ &paz= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
02836 sint tg;
02837 <font class="comment">// For each tangent, what vertex (relative to x,y) we must take.</font>
02838 <font class="keyword">struct </font>CDeltaPos
02839 {
02840 sint ox,oy;
02841 sint dx1,dy1;
02842 sint dx2,dy2;
02843 };
02844 <font class="keyword">static</font> CDeltaPos deltas[8]= {
02845 {0,0, 0,1, 0,-1} ,
02846 {0,1, 0,0, 0,2} ,
02847 {0,1, 1,1, -1,1} ,
02848 {1,1, 0,1, 2,1} ,
02849 {1,1, 1,0, 1,2} ,
02850 {1,0, 1,1, 1,-1} ,
02851 {1,0, 0,0, 2,0} ,
02852 {0,0, 1,0, -1,0} ,
02853 };
02854
02855 <font class="comment">// compute each tangent of this patch.</font>
02856 <font class="keywordflow">for</font>(tg=0; tg<8;tg++)
02857 {
02858 sint x0,y0;
02859 sint x1,y1;
02860 sint x2,y2;
02861 x0= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+deltas[tg].ox; y0= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+deltas[tg].oy;
02862 x1= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+deltas[tg].dx1; y1= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+deltas[tg].dy1;
02863 x2= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+deltas[tg].dx2; y2= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+deltas[tg].dy2;
02864
02865 <font class="comment">// borders case.</font>
02866 <font class="keywordflow">if</font>(x2<0 || x2>=(sint)hf.getWidth() || y2<0 || y2>=(sint)hf.getHeight())
02867 {
02868 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>,dv;
02869 <font class="comment">// base of tangents.</font>
02870 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= hf.getZ(x0,y0);
02871 <font class="comment">// target tangents.</font>
02872 dv= hf.getZ(x1,y1) - <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
02873 <font class="comment">// result of tangent.</font>
02874 paz.Tangents[tg]= <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>+dv/3;
02875 }
02876 <font class="comment">// middle case.</font>
02877 <font class="keywordflow">else</font>
02878 {
02879 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>,dv;
02880 <font class="comment">// base of tangents.</font>
02881 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= hf.getZ(x0,y0);
02882 <font class="comment">// target tangents.</font>
02883 dv= hf.getZ(x1,y1) - <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
02884 <font class="comment">// add mirror target tangent.</font>
02885 dv+= -(hf.getZ(x2,y2) - <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
02886 dv/=2;
02887 <font class="comment">// result of tangent.</font>
02888 paz.Tangents[tg]= <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>+dv/3;
02889 }
02890 }
02891 }
02892 }
02893
02894 <font class="comment">// compute interiors.</font>
02895 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a><(sint)h;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
02896 {
02897 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a><(sint)<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
02898 {
02899 CBezierPatchZ &paz= <a class="code" href="classNL3D_1_1CLandscape.html#o21">_HeightField</a>.<a class="code" href="structNL3D_1_1CLandscape_1_1CHeightField.html#m0">ZPatchs</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
02900 paz.makeInteriors();
02901 }
02902 }
02903
02904 }
02905
02906
02907 <font class="comment">// ***************************************************************************</font>
<a name="l02908"></a><a class="code" href="classNL3D_1_1CLandscape.html#z480_6">02908</a> <font class="keywordtype">void</font> CLandscape::getTessellationLeaves(std::vector<const CTessFace*> &leaves)<font class="keyword"> const</font>
02909 <font class="keyword"></font>{
02910 leaves.clear();
02911
02912 std::map<uint16, CZone*>::const_iterator it;
02913 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
02914 {
02915 <font class="comment">// Then trace all patch.</font>
02916 sint N= (*it).second->getNumPatchs();
02917 <font class="keywordflow">for</font>(sint i=0;i<N;i++)
02918 {
02919 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(i);
02920
02921 pa->appendTessellationLeaves(leaves);
02922 }
02923 }
02924
02925 }
02926
02927
02928 <font class="comment">// ***************************************************************************</font>
<a name="l02929"></a><a class="code" href="classNL3D_1_1CLandscape.html#z487_0">02929</a> <font class="keywordtype">void</font> CLandscape::setPZBModelPosition(<font class="keyword">const</font> CVector &pos)
02930 {
02931 <a class="code" href="classNL3D_1_1CLandscape.html#z497_0">_PZBModelPosition</a>= pos;
02932 }
02933
02934
02935
02936 <font class="comment">// ***************************************************************************</font>
02937 <font class="comment">// ***************************************************************************</font>
02938 <font class="comment">// Allocators.</font>
02939 <font class="comment">// ***************************************************************************</font>
02940 <font class="comment">// ***************************************************************************</font>
02941
02942
02943 <font class="comment">// ***************************************************************************</font>
<a name="l02944"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_0">02944</a> CTessFace *CLandscape::newTessFace()
02945 {
02946 <font class="comment">// allcoate the face.</font>
02947 <a class="code" href="classNL3D_1_1CLandscape.html#l0">CTessFace</a> *face= <a class="code" href="classNL3D_1_1CLandscape.html#z490_12">TessFaceAllocator</a>.allocate();
02948
02949 <font class="comment">// for refine() mgt, append the face to the list of newLeaves, so they will be tested in refine()</font>
02950 face->linkInPList(<a class="code" href="classNL3D_1_1CLandscape.html#z495_4">_RootNewLeaves</a>);
02951
02952 <font class="keywordflow">return</font> face;
02953 }
02954
02955 <font class="comment">// ***************************************************************************</font>
<a name="l02956"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_1">02956</a> CTessVertex *CLandscape::newTessVertex()
02957 {
02958 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z490_13">TessVertexAllocator</a>.allocate();
02959 }
02960
02961 <font class="comment">// ***************************************************************************</font>
<a name="l02962"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_2">02962</a> CTessNearVertex *CLandscape::newTessNearVertex()
02963 {
02964 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z490_14">TessNearVertexAllocator</a>.allocate();
02965 }
02966
02967 <font class="comment">// ***************************************************************************</font>
<a name="l02968"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_3">02968</a> CTessFarVertex *CLandscape::newTessFarVertex()
02969 {
02970 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z490_15">TessFarVertexAllocator</a>.allocate();
02971 }
02972
02973 <font class="comment">// ***************************************************************************</font>
<a name="l02974"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_4">02974</a> CTileMaterial *CLandscape::newTileMaterial()
02975 {
02976 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z490_16">TileMaterialAllocator</a>.allocate();
02977 }
02978
02979 <font class="comment">// ***************************************************************************</font>
<a name="l02980"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_5">02980</a> CTileFace *CLandscape::newTileFace()
02981 {
02982 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z490_17">TileFaceAllocator</a>.allocate();
02983 }
02984
02985 <font class="comment">// ***************************************************************************</font>
<a name="l02986"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_6">02986</a> <font class="keywordtype">void</font> CLandscape::deleteTessFace(CTessFace *f)
02987 {
02988 <font class="comment">// for refine() mgt, must remove from refine priority list, or from the temp rootTessFaceToUpdate list.</font>
02989 f->unlinkInPList();
02990
02991 <a class="code" href="classNL3D_1_1CLandscape.html#z490_12">TessFaceAllocator</a>.free(f);
02992 }
02993
02994 <font class="comment">// ***************************************************************************</font>
<a name="l02995"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_7">02995</a> <font class="keywordtype">void</font> CLandscape::deleteTessVertex(CTessVertex *<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
02996 {
02997 <a class="code" href="classNL3D_1_1CLandscape.html#z490_13">TessVertexAllocator</a>.free(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
02998 }
02999
03000 <font class="comment">// ***************************************************************************</font>
<a name="l03001"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_8">03001</a> <font class="keywordtype">void</font> CLandscape::deleteTessNearVertex(CTessNearVertex *<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
03002 {
03003 <a class="code" href="classNL3D_1_1CLandscape.html#z490_14">TessNearVertexAllocator</a>.free(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
03004 }
03005
03006 <font class="comment">// ***************************************************************************</font>
<a name="l03007"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_9">03007</a> <font class="keywordtype">void</font> CLandscape::deleteTessFarVertex(CTessFarVertex *<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
03008 {
03009 <a class="code" href="classNL3D_1_1CLandscape.html#z490_15">TessFarVertexAllocator</a>.free(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
03010 }
03011
03012 <font class="comment">// ***************************************************************************</font>
<a name="l03013"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_10">03013</a> <font class="keywordtype">void</font> CLandscape::deleteTileMaterial(CTileMaterial *tm)
03014 {
03015 <a class="code" href="classNL3D_1_1CLandscape.html#z490_16">TileMaterialAllocator</a>.free(tm);
03016 }
03017
03018 <font class="comment">// ***************************************************************************</font>
<a name="l03019"></a><a class="code" href="classNL3D_1_1CLandscape.html#z490_11">03019</a> <font class="keywordtype">void</font> CLandscape::deleteTileFace(CTileFace *tf)
03020 {
03021 <a class="code" href="classNL3D_1_1CLandscape.html#z490_17">TileFaceAllocator</a>.free(tf);
03022 }
03023
03024
03025
03026 <font class="comment">// ***************************************************************************</font>
03027 <font class="comment">// ***************************************************************************</font>
03028 <font class="comment">// Noise</font>
03029 <font class="comment">// ***************************************************************************</font>
03030 <font class="comment">// ***************************************************************************</font>
03031
03032
03033 <font class="comment">// ***************************************************************************</font>
<a name="l03034"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_8">03034</a> <font class="keywordtype">void</font> CLandscape::setNoiseMode(<font class="keywordtype">bool</font> enable)
03035 {
03036 <a class="code" href="classNL3D_1_1CLandscape.html#z494_0">_NoiseEnabled</a>= enable;
03037 }
03038
03039 <font class="comment">// ***************************************************************************</font>
<a name="l03040"></a><a class="code" href="classNL3D_1_1CLandscape.html#z478_9">03040</a> <font class="keywordtype">bool</font> CLandscape::getNoiseMode()<font class="keyword"> const</font>
03041 <font class="keyword"></font>{
03042 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z494_0">_NoiseEnabled</a>;
03043 }
03044
03045
03046 <font class="comment">// ***************************************************************************</font>
03047 <font class="comment">// ***************************************************************************</font>
03048 <font class="comment">// Micro vegetation</font>
03049 <font class="comment">// ***************************************************************************</font>
03050 <font class="comment">// ***************************************************************************</font>
03051
03052
03053 <font class="comment">// ***************************************************************************</font>
<a name="l03054"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_3">03054</a> <font class="keywordtype">void</font> CLandscape::enableVegetable(<font class="keywordtype">bool</font> enable)
03055 {
03056 <a class="code" href="classNL3D_1_1CLandscape.html#z496_2">_VegetableManagerEnabled</a>= enable;
03057
03058 <font class="comment">// if false, delete all Vegetable IGs.</font>
03059 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#z496_2">_VegetableManagerEnabled</a>)
03060 {
03061 <font class="comment">// Landscape always create ClipBlokcs, but IGs/addInstances() are created only if isVegetableActive().</font>
03062 <font class="comment">// For all zones.</font>
03063 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
03064 {
03065 <font class="comment">// for all patch.</font>
03066 sint N= (*it).second->getNumPatchs();
03067 <font class="keywordflow">for</font>(sint i=0;i<N;i++)
03068 {
03069 <font class="comment">// delete vegetable Igs of this patch</font>
03070 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= ((*it).second)->getPatch(i);
03071 pa->deleteAllVegetableIgs();
03072 }
03073
03074 }
03075 }
03076 <font class="comment">// if true</font>
03077 <font class="keywordflow">else</font>
03078 {
03079 <font class="comment">// reload all Shapes (actually load only new shapes)</font>
03080 <a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.initTileVegetableDescs(<a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>);
03081
03082 <font class="comment">// And recreate vegetable igs.</font>
03083 <font class="comment">// Landscape always create ClipBlokcs, but IGs/addInstances() are created only if isVegetableActive().</font>
03084 <font class="comment">// For all zones.</font>
03085 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
03086 {
03087 <font class="comment">// for all patch.</font>
03088 sint N= (*it).second->getNumPatchs();
03089 <font class="keywordflow">for</font>(sint i=0;i<N;i++)
03090 {
03091 <font class="comment">// recreate vegetable Igs of this patch</font>
03092 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= ((*it).second)->getPatch(i);
03093 pa->recreateAllVegetableIgs();
03094 }
03095
03096 }
03097 }
03098
03099 }
03100
03101 <font class="comment">// ***************************************************************************</font>
<a name="l03102"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_4">03102</a> <font class="keywordtype">bool</font> CLandscape::isVegetableActive()<font class="keyword"> const</font>
03103 <font class="keyword"></font>{
03104 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z496_2">_VegetableManagerEnabled</a> && <a class="code" href="classNL3D_1_1CLandscape.html#z496_3">_DriverOkForVegetable</a>;
03105 }
03106
03107 <font class="comment">// ***************************************************************************</font>
03108 <font class="keywordtype">void</font> CLandscape::loadVegetableTexture(<font class="keyword">const</font> string &textureFileName)
03109 {
03110 <font class="comment">// load the texture in the manager</font>
03111 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->loadTexture(textureFileName);
03112 }
03113
03114 <font class="comment">// ***************************************************************************</font>
<a name="l03115"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_6">03115</a> <font class="keywordtype">void</font> CLandscape::setupVegetableLighting(<font class="keyword">const</font> CRGBA &ambient, <font class="keyword">const</font> CRGBA &diffuse, <font class="keyword">const</font> CVector &directionalLight)
03116 {
03117 <font class="comment">// set the directional light to the manager</font>
03118 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->setDirectionalLight(ambient, diffuse, directionalLight);
03119 }
03120
03121 <font class="comment">// ***************************************************************************</font>
<a name="l03122"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_7">03122</a> <font class="keywordtype">void</font> CLandscape::setVegetableWind(<font class="keyword">const</font> CVector &windDir, <font class="keywordtype">float</font> windFreq, <font class="keywordtype">float</font> windPower, <font class="keywordtype">float</font> windBendMin)
03123 {
03124 <font class="comment">// setup vegetable manager</font>
03125 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->setWind(windDir, windFreq, windPower, windBendMin);
03126 }
03127
03128
03129 <font class="comment">// ***************************************************************************</font>
<a name="l03130"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_1">03130</a> <font class="keywordtype">void</font> CLandscape::setVegetableTime(<font class="keywordtype">double</font> time)
03131 {
03132 <font class="comment">// setup vegetable manager</font>
03133 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->setTime(time);
03134 }
03135
03136 <font class="comment">// ***************************************************************************</font>
<a name="l03137"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_2">03137</a> <font class="keywordtype">void</font> CLandscape::setVegetableUpdateLightingTime(<font class="keywordtype">double</font> time)
03138 {
03139 <font class="comment">// setup vegetable manager</font>
03140 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->setUpdateLightingTime(time);
03141 }
03142
03143
03144 <font class="comment">// ***************************************************************************</font>
<a name="l03145"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_8">03145</a> uint CLandscape::getNumVegetableFaceRendered()<font class="keyword"> const</font>
03146 <font class="keyword"></font>{
03147 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->getNumVegetableFaceRendered();
03148 }
03149
03150
03151 <font class="comment">// ***************************************************************************</font>
<a name="l03152"></a><a class="code" href="classNL3D_1_1CLandscape.html#z496_0">03152</a> <font class="keyword">const</font> CTileVegetableDesc &CLandscape::getTileVegetableDesc(uint16 tileId)
03153 {
03154 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CLandscape.html#m0">TileBank</a>.getTileVegetableDesc(tileId);
03155 }
03156
03157
03158 <font class="comment">// ***************************************************************************</font>
<a name="l03159"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_0">03159</a> <font class="keywordtype">void</font> CLandscape::createVegetableBlendLayersModels(CScene *scene)
03160 {
03161 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->createVegetableBlendLayersModels(scene);
03162 }
03163
03164
03165 <font class="comment">// ***************************************************************************</font>
<a name="l03166"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_9">03166</a> <font class="keywordtype">void</font> CLandscape::setVegetableUpdateLightingFrequency(<font class="keywordtype">float</font> freq)
03167 {
03168 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->setUpdateLightingFrequency(freq);
03169 }
03170
03171 <font class="comment">// ***************************************************************************</font>
<a name="l03172"></a><a class="code" href="classNL3D_1_1CLandscape.html#z485_10">03172</a> <font class="keywordtype">void</font> CLandscape::setupColorsFromTileFlags(<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> colors[4])
03173 {
03174 <font class="keywordflow">for</font> (TZoneMap::iterator it = <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin(); it != <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end(); ++it)
03175 {
03176 it->second->setupColorsFromTileFlags(colors);
03177 }
03178 }
03179
03180 <font class="comment">// ***************************************************************************</font>
03181 <font class="comment">// ***************************************************************************</font>
03182 <font class="comment">// Lightmap Get interface.</font>
03183 <font class="comment">// ***************************************************************************</font>
03184 <font class="comment">// ***************************************************************************</font>
03185
03186
03187 <font class="comment">// ***************************************************************************</font>
<a name="l03188"></a><a class="code" href="classNL3D_1_1CLandscape.html#z486_0">03188</a> uint8 CLandscape::getLumel(<font class="keyword">const</font> CPatchIdent &patchId, <font class="keyword">const</font> CUV &uv)<font class="keyword"> const</font>
03189 <font class="keyword"></font>{
03190 <font class="comment">// \todo yoyo: TODO_ZONEID: change ZoneId in 32 bits...</font>
03191 std::map<uint16, CZone*>::const_iterator it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find((uint16)patchId.ZoneId);
03192 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
03193 {
03194 sint N= (*it).second->getNumPatchs();
03195 <font class="comment">// patch must exist in the zone.</font>
03196 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId.PatchId<N);
03197 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(patchId.PatchId);
03198
03199 <font class="keywordflow">return</font> pa->getLumel(uv);
03200 }
03201 <font class="keywordflow">else</font>
03202 <font class="comment">// Return full sun contribution as default</font>
03203 <font class="keywordflow">return</font> 255;
03204 }
03205
03206 <font class="comment">// ***************************************************************************</font>
<a name="l03207"></a><a class="code" href="classNL3D_1_1CLandscape.html#z486_1">03207</a> <font class="keywordtype">void</font> CLandscape::appendTileLightInfluences(<font class="keyword">const</font> CPatchIdent &patchId, <font class="keyword">const</font> CUV &uv,
03208 std::vector<CPointLightInfluence> &pointLightList)<font class="keyword"> const</font>
03209 <font class="keyword"></font>{
03210 <font class="comment">// \todo yoyo: TODO_ZONEID: change ZoneId in 32 bits...</font>
03211 std::map<uint16, CZone*>::const_iterator it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.find((uint16)patchId.ZoneId);
03212 <font class="keywordflow">if</font>(it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end())
03213 {
03214 sint N= (*it).second->getNumPatchs();
03215 <font class="comment">// patch must exist in the zone.</font>
03216 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId.PatchId<N);
03217 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= const_cast<const CZone*>((*it).second)->getPatch(patchId.PatchId);
03218
03219 pa->appendTileLightInfluences(uv, pointLightList);
03220 }
03221 }
03222
03223
03224 <font class="comment">// ***************************************************************************</font>
03225 <font class="comment">// ***************************************************************************</font>
03226 <font class="comment">// Lighting</font>
03227 <font class="comment">// ***************************************************************************</font>
03228 <font class="comment">// ***************************************************************************</font>
03229
03230
03231 <font class="comment">// ***************************************************************************</font>
<a name="l03232"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_8">03232</a> <font class="keywordtype">void</font> CLandscape::removeAllPointLights()
03233 {
03234 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
03235 {
03236 <font class="comment">// for all patch.</font>
03237 sint N= (*it).second->getNumPatchs();
03238 <font class="keywordflow">for</font>(sint i=0;i<N;i++)
03239 {
03240 <font class="comment">// Clear TileLightInfluences</font>
03241 <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= ((*it).second)->getPatch(i);
03242 pa->resetTileLightInfluences();
03243 }
03244
03245 <font class="comment">// Remove all PointLights.</font>
03246 (*it).second->_PointLightArray.clear();
03247 }
03248
03249 }
03250
03251
03252 <font class="comment">// ***************************************************************************</font>
<a name="l03253"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_9">03253</a> <font class="keywordtype">void</font> CLandscape::setPointLightFactor(<font class="keyword">const</font> std::string &lightGroupName, <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> nFactor)
03254 {
03255 <font class="comment">// Store the result in the map for addZone().</font>
03256 <a class="code" href="classNL3D_1_1CLandscape.html#o20">_LightGroupColorMap</a>[lightGroupName]= nFactor;
03257
03258 <font class="comment">// Affect currently added zones.</font>
03259 <font class="keywordflow">for</font>(<a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> it= <a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.begin();it!=<a class="code" href="classNL3D_1_1CLandscape.html#o0">Zones</a>.end();it++)
03260 {
03261 (*it).second->_PointLightArray.setPointLightFactor(lightGroupName, nFactor);
03262 }
03263 }
03264
03265
03266 <font class="comment">// ***************************************************************************</font>
<a name="l03267"></a><a class="code" href="classNL3D_1_1CLandscape.html#z488_0">03267</a> <font class="keywordtype">void</font> CLandscape::updateLighting(<font class="keywordtype">double</font> time)
03268 {
03269 <a class="code" href="classNL3D_1_1CLandscape.html#z498_6">_ULTime</a>= time;
03270
03271 <font class="comment">// first time in this method??</font>
03272 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CLandscape.html#z498_5">_ULPrecTimeInit</a>)
03273 {
03274 <a class="code" href="classNL3D_1_1CLandscape.html#z498_5">_ULPrecTimeInit</a>= <font class="keyword">true</font>;
03275 <a class="code" href="classNL3D_1_1CLandscape.html#z498_4">_ULPrecTime</a>= <a class="code" href="classNL3D_1_1CLandscape.html#z498_6">_ULTime</a>;
03276 }
03277 <font class="comment">// compute delta time from last update.</font>
03278 <font class="keywordtype">float</font> dt= float(<a class="code" href="classNL3D_1_1CLandscape.html#z498_6">_ULTime</a> - <a class="code" href="classNL3D_1_1CLandscape.html#z498_4">_ULPrecTime</a>);
03279 <a class="code" href="classNL3D_1_1CLandscape.html#z498_4">_ULPrecTime</a>= <a class="code" href="classNL3D_1_1CLandscape.html#z498_6">_ULTime</a>;
03280
03281
03282 <font class="comment">// If not disabled</font>
03283 <font class="keywordflow">if</font>(_ULFrequency)
03284 {
03285 <font class="comment">// Do it for near and far in 2 distinct ways.</font>
03286 <a class="code" href="classNL3D_1_1CLandscape.html#z498_2">updateLightingTextureFar</a>(dt * <a class="code" href="classNL3D_1_1CLandscape.html#z498_7">_ULFrequency</a>);
03287 <a class="code" href="classNL3D_1_1CLandscape.html#z498_3">updateLightingTextureNear</a>(dt * <a class="code" href="classNL3D_1_1CLandscape.html#z498_7">_ULFrequency</a>);
03288 }
03289
03290 }
03291
03292
03293 <font class="comment">// ***************************************************************************</font>
<a name="l03294"></a><a class="code" href="classNL3D_1_1CLandscape.html#z488_2">03294</a> <font class="keywordtype">void</font> CLandscape::updateLightingAll()
03295 {
03296 <font class="comment">// Do it for near and far in 2 distinct ways.</font>
03297 <font class="comment">//================</font>
03298 <a class="code" href="classNL3D_1_1CLandscape.html#z498_2">updateLightingTextureFar</a>(1);
03299 <a class="code" href="classNL3D_1_1CLandscape.html#z498_3">updateLightingTextureNear</a>(1);
03300
03301
03302 <font class="comment">// update lighting for vegetables</font>
03303 <font class="comment">//================</font>
03304
03305 <font class="comment">// Must lock buffers for update Lighting of vegetables.</font>
03306 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (CVector::Null);
03307
03308 <font class="comment">// Because updateLighting() may use OptFastFloor..</font>
03309 <a class="code" href="namespaceNL3D.html#a360">OptFastFloorBegin</a>();
03310
03311 <font class="comment">// update ALL lighting for vegetables</font>
03312 <a class="code" href="classNL3D_1_1CLandscape.html#z496_1">_VegetableManager</a>->updateLightingAll();
03313
03314 <font class="comment">// Stop fastFloor optim.</font>
03315 <a class="code" href="namespaceNL3D.html#a361">OptFastFloorEnd</a>();
03316
03317 <font class="comment">// Must realase VB Buffers</font>
03318 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
03319 }
03320
03321
03322 <font class="comment">// ***************************************************************************</font>
<a name="l03323"></a><a class="code" href="classNL3D_1_1CLandscape.html#z488_1">03323</a> <font class="keywordtype">void</font> CLandscape::setUpdateLightingFrequency(<font class="keywordtype">float</font> freq)
03324 {
03325 freq= max(freq, 0.f);
03326 <a class="code" href="classNL3D_1_1CLandscape.html#z498_7">_ULFrequency</a>= freq;
03327 }
03328
03329
03330 <font class="comment">// ***************************************************************************</font>
<a name="l03331"></a><a class="code" href="classNL3D_1_1CLandscape.html#z498_0">03331</a> <font class="keywordtype">void</font> CLandscape::linkPatchToNearUL(CPatch *patch)
03332 {
03333 <font class="comment">// Append this patch to the list of patch to updateLighting.</font>
03334 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>==NULL)
03335 <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>= patch;
03336 <font class="keywordflow">else</font>
03337 patch->linkBeforeNearUL(<a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>);
03338 }
03339
03340 <font class="comment">// ***************************************************************************</font>
<a name="l03341"></a><a class="code" href="classNL3D_1_1CLandscape.html#z498_1">03341</a> <font class="keywordtype">void</font> CLandscape::unlinkPatchFromNearUL(CPatch *patch)
03342 {
03343 <font class="comment">// If I unlink the patch which is the current root</font>
03344 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>==patch)
03345 {
03346 <font class="comment">// switch to next</font>
03347 <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>= patch->getNextNearUL();
03348 <font class="comment">// if still the same, it means that the circular list is now empty</font>
03349 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>==patch)
03350 <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>= NULL;
03351 <font class="comment">// reset tessBlock counter.</font>
03352 <a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>= 0;
03353 }
03354
03355 <font class="comment">// unlink the patch from list</font>
03356 patch->unlinkNearUL();
03357 }
03358
03359
03360 <font class="comment">// ***************************************************************************</font>
<a name="l03361"></a><a class="code" href="classNL3D_1_1CLandscape.html#z498_2">03361</a> <font class="keywordtype">void</font> CLandscape::updateLightingTextureFar(<font class="keywordtype">float</font> ratio)
03362 {
03363 <font class="comment">// compute number of pixels to update.</font>
03364 <a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a>+= ratio * <a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>;
03365 <font class="comment">// maximize, so at max, it computes all patchs, just one time.</font>
03366 <a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a>= <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a>, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CLandscape.html#z498_8">_ULTotalFarPixels</a>);
03367
03368 <font class="comment">// Test Profile Yoyo</font>
03369 <font class="comment">/*extern bool YOYO_LandULTest;</font>
03370 <font class="comment"> if(YOYO_LandULTest)</font>
03371 <font class="comment"> {</font>
03372 <font class="comment"> nlinfo("YOYO_UL Far: %dK, %dK", (sint)_ULFarPixelsToUpdate/1024, (sint)_ULTotalFarPixels/1024);</font>
03373 <font class="comment"> }*/</font>
03374
03375 <font class="comment">// while there is still some pixels to update.</font>
03376 <font class="keywordflow">while</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a> > 0 && <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>)
03377 {
03378 <font class="comment">// update patch (if not null) in the textureFar.</font>
03379 <a class="code" href="classNL3D_1_1CLandscape.html#z498_9">_ULFarPixelsToUpdate</a>-= <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>->touchPatch(<a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>);
03380 <font class="comment">// Next patch to process.</font>
03381 <a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>++;
03382
03383 <font class="comment">// last patch in the texture??</font>
03384 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>>=<a class="code" href="texture__far_8h.html#a3">NL_NUM_FAR_PATCHES_BY_TEXTURE</a>)
03385 {
03386 <font class="comment">// yes, go to next texture.</font>
03387 <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>= <a class="code" href="classNL3D_1_1CLandscape.html#z498_10">_ULRootTextureFar</a>->getNextUL();
03388 <font class="comment">// reset to 0th patch.</font>
03389 <a class="code" href="classNL3D_1_1CLandscape.html#z498_11">_ULFarCurrentPatchId</a>=0;
03390 }
03391 }
03392
03393 <font class="comment">// Now, _ULFarPixelsToUpdate should be <=0. (most of the time < 0)</font>
03394 }
03395
03396
03397 <font class="comment">// ***************************************************************************</font>
<a name="l03398"></a><a class="code" href="classNL3D_1_1CLandscape.html#z498_3">03398</a> <font class="keywordtype">void</font> CLandscape::updateLightingTextureNear(<font class="keywordtype">float</font> ratio)
03399 {
03400 <font class="comment">// compute number of pixels to update.</font>
03401 <a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a>+= ratio * <a class="code" href="classNL3D_1_1CLandscape.html#z498_12">_ULTotalNearPixels</a>;
03402 <font class="comment">// maximize, so at max, it computes all patchs, just one time.</font>
03403 <a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a>= <a class="code" href="bit__set_8cpp.html#a0">min</a>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a>, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CLandscape.html#z498_12">_ULTotalNearPixels</a>);
03404
03405
03406 <font class="comment">// while there is still some pixels to update.</font>
03407 <font class="keywordflow">while</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a> > 0 && <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>)
03408 {
03409 <font class="comment">// update tessBlock (if lightmap exist for this tessBlock) in the patch.</font>
03410 <a class="code" href="classNL3D_1_1CLandscape.html#z498_13">_ULNearPixelsToUpdate</a>-= <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>->updateTessBlockLighting(<a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>);
03411 <font class="comment">// Next tessBlock to process.</font>
03412 <a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>++;
03413
03414 <font class="comment">// last tessBlock in the patch??</font>
03415 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>>=<a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>->getNumNearTessBlocks())
03416 {
03417 <font class="comment">// yes, go to next patch.</font>
03418 <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>= <a class="code" href="classNL3D_1_1CLandscape.html#z498_14">_ULRootNearPatch</a>->getNextNearUL();
03419 <font class="comment">// reset to 0th tessBlock.</font>
03420 <a class="code" href="classNL3D_1_1CLandscape.html#z498_15">_ULNearCurrentTessBlockId</a>=0;
03421 }
03422 }
03423
03424 }
03425
03426
03427 <font class="comment">// ***************************************************************************</font>
<a name="l03428"></a><a class="code" href="classNL3D_1_1CLandscape.html#z489_0">03428</a> <font class="keywordtype">void</font> CLandscape::computeDynamicLighting(<font class="keyword">const</font> std::vector<CPointLight*> &pls)
03429 {
03430 uint i;
03431
03432 <font class="comment">// Update globals, and lock buffers</font>
03433 <font class="comment">//====================</font>
03434 <a class="code" href="classNL3D_1_1CLandscape.html#c6">updateGlobalsAndLockBuffers</a> (CVector::Null);
03435 <font class="comment">// NB: averageTesselationVertices may change vertices in VB in visible patchs => buffers are locked.</font>
03436
03437
03438 <font class="comment">// Run all DLM Context create, to init Lighting process.</font>
03439 <font class="comment">//===============</font>
03440 CPatchDLMContext *ctxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
03441 <font class="keywordflow">while</font>(ctxPtr!=NULL)
03442 {
03443 <font class="comment">// init lighting process, do differential from last computeDynamicLighting()</font>
03444 ctxPtr->getPatch()->beginDLMLighting();
03445
03446 <font class="comment">// next</font>
03447 ctxPtr= (CPatchDLMContext*)ctxPtr->Next;
03448 }
03449
03450
03451 <font class="comment">// compile all pointLights</font>
03452 <font class="comment">//===============</font>
03453 <font class="keyword">static</font> vector<CPatchDLMPointLight> dlmPls;
03454 dlmPls.resize(pls.size());
03455 <font class="keywordflow">for</font>(i=0;i<dlmPls.size();i++)
03456 {
03457 <font class="comment">// compile the pl.</font>
03458 dlmPls[i].compile(*pls[i], <a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>, <a class="code" href="classNL3D_1_1CLandscape.html#z499_4">_DLMMaxAttEnd</a>);
03459 }
03460
03461
03462 <font class="comment">// For all pointLight, intersect patch.</font>
03463 <font class="comment">//===============</font>
03464 <font class="keywordflow">for</font>(i=0;i<dlmPls.size();i++)
03465 {
03466 CPatchDLMPointLight &pl= dlmPls[i];
03467
03468 <font class="comment">// search patchs of interest: those which interssect the pointLight</font>
03469 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.clearSelection();
03470 <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.select(pl.BBox.getMin(), pl.BBox.getMax());
03471 CQuadGrid<CPatchIdentEx>::CIterator it;
03472
03473 <font class="comment">// for each patch, light it with the light.</font>
03474 <font class="keywordflow">for</font>(it= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.begin(); it!= <a class="code" href="classNL3D_1_1CLandscape.html#z493_2">_PatchQuadGrid</a>.end(); it++)
03475 {
03476 <font class="comment">// get the patch</font>
03477 <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CLandscape.html#l1">CPatch</a> *pa= (*it).Patch;
03478
03479 <font class="comment">// More precise clipping: </font>
03480 <font class="keywordflow">if</font>( pa->getBSphere().intersect( pl.BSphere ) )
03481 {
03482 <font class="comment">// Ok, light the patch with this spotLight</font>
03483 const_cast<CPatch*>(pa)->processDLMLight(pl);
03484 }
03485 }
03486
03487 }
03488
03489
03490 <font class="comment">// Run all DLM Context create, to end Lighting process.</font>
03491 <font class="comment">//===============</font>
03492 ctxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
03493 <font class="keywordflow">while</font>(ctxPtr!=NULL)
03494 {
03495 <font class="comment">// get enxt now, because the DLM itself may be deleted in endDLMLighting()</font>
03496 CPatchDLMContext *next= (CPatchDLMContext*)ctxPtr->Next;
03497
03498 <font class="comment">// delete the DLM if no more needed (near don't use nor pointLights)</font>
03499 ctxPtr->getPatch()->endDLMLighting();
03500
03501 <font class="comment">// next</font>
03502 ctxPtr= next;
03503 }
03504
03505
03506 <font class="comment">// Must realase VB Buffers</font>
03507 <font class="comment">//====================</font>
03508 <a class="code" href="classNL3D_1_1CLandscape.html#c8">unlockBuffers</a>();
03509
03510 }
03511
03512
03513 <font class="comment">// ***************************************************************************</font>
<a name="l03514"></a><a class="code" href="classNL3D_1_1CLandscape.html#z489_2">03514</a> <font class="keywordtype">void</font> CLandscape::setDynamicLightingMaxAttEnd(<font class="keywordtype">float</font> maxAttEnd)
03515 {
03516 maxAttEnd= max(maxAttEnd, 1.f);
03517 <a class="code" href="classNL3D_1_1CLandscape.html#z499_4">_DLMMaxAttEnd</a>= maxAttEnd;
03518 }
03519
03520
03521 <font class="comment">// ***************************************************************************</font>
<a name="l03522"></a><a class="code" href="classNL3D_1_1CLandscape.html#z489_1">03522</a> uint CLandscape::getDynamicLightingMemoryLoad()<font class="keyword"> const</font>
03523 <font class="keyword"></font>{
03524 uint mem= 0;
03525 <font class="comment">// First, set size of global texture overhead.</font>
03526 mem= <a class="code" href="landscape__def_8h.html#a13">NL3D_LANDSCAPE_DLM_WIDTH</a> * <a class="code" href="landscape__def_8h.html#a14">NL3D_LANDSCAPE_DLM_HEIGHT</a> * <font class="keyword">sizeof</font>(CRGBA);
03527
03528 <font class="comment">// Then, for each patchContext created</font>
03529 CPatchDLMContext *ctxPtr= <a class="code" href="classNL3D_1_1CLandscape.html#z499_3">_PatchDLMContextList</a>->begin();
03530 <font class="keywordflow">while</font>(ctxPtr!=NULL)
03531 {
03532 <font class="comment">// add its memory load.</font>
03533 mem+= ctxPtr->getMemorySize();
03534
03535 <font class="comment">// next</font>
03536 ctxPtr= (CPatchDLMContext*)ctxPtr->Next;
03537 }
03538
03539 <font class="keywordflow">return</font> mem;
03540 }
03541
03542
03543 <font class="comment">// ***************************************************************************</font>
<a name="l03544"></a><a class="code" href="classNL3D_1_1CLandscape.html#z489_4">03544</a> <font class="keywordtype">void</font> CLandscape::setDLMGlobalVegetableColor(CRGBA gvc)
03545 {
03546 <a class="code" href="classNL3D_1_1CLandscape.html#z499_5">_DLMGlobalVegetableColor</a>= gvc;
03547 }
03548
03549
03550 <font class="comment">// ***************************************************************************</font>
<a name="l03551"></a><a class="code" href="classNL3D_1_1CLandscape.html#z483_2">03551</a> <font class="keywordtype">void</font> CLandscape::setPointLightDiffuseMaterial(CRGBA diffuse)
03552 {
03553 <a class="code" href="classNL3D_1_1CLandscape.html#z499_6">_PointLightDiffuseMaterial</a>= diffuse;
03554 }
03555
03556
03557 } <font class="comment">// NL3D</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|