aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/async__texture__manager_8cpp-source.html
blob: 6799fe3156c6bd91098f1da12866ab1ebea1b2a6 (plain)
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
<!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="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/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="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- 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="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>async_texture_manager.cpp</h1><a href="async__texture__manager_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2000-2002 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 <font class="preprocessor">#include "<a class="code" href="async__texture__manager_8h.html">3d/async_texture_manager.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="async__file__manager__3d_8h.html">3d/async_file_manager_3d.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="mesh__base__instance_8h.html">3d/mesh_base_instance.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="driver_8h.html">3d/driver.h</a>"</font>
00032 
00033 
00034 <font class="keyword">using</font>   <font class="keyword">namespace </font>std;
00035 <font class="keyword">using</font>   <font class="keyword">namespace </font>NLMISC;
00036 
00037 <font class="keyword">namespace </font>NL3D 
00038 {
00039 
00040 <font class="comment">// ***************************************************************************</font>
<a name="l00041"></a><a class="code" href="async__texture__manager_8cpp.html#a0">00041</a> <font class="preprocessor">#define NL3D_ATM_MIN_DISTANCE           1.0f</font>
00042 <font class="preprocessor"></font>
00043 <font class="comment">// ***************************************************************************</font>
<a name="l00044"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#a0">00044</a> CAsyncTextureManager::CTextureEntry::CTextureEntry()
00045 {
00046         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#n0">IsTextureEntry</a>= <font class="keyword">true</font>;
00047 
00048         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m1">Loaded</a>= <font class="keyword">false</font>;
00049         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m2">UpLoaded</a>= <font class="keyword">false</font>;
00050         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m3">CanHaveLOD</a>= <font class="keyword">false</font>;
00051         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m4">BuildFromHLSManager</a>= <font class="keyword">false</font>;
00052         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m5">HLSManagerTextId</a>= -1;
00053         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m6">BaseSize</a>= 0;
00054         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m9">TotalTextureSizeAsked</a>= 0;
00055 }
00056 
00057 
00058 <font class="comment">// ***************************************************************************</font>
<a name="l00059"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#a1">00059</a> <font class="keywordtype">void</font>            CAsyncTextureManager::CTextureEntry::createCoarseBitmap()
00060 {
00061         <font class="comment">// the texture must exist.</font>
00062         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>);
00063         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>-&gt;getSize()&gt;0);
00064 
00065         <font class="comment">// copy the bitmap.</font>
00066         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>= *<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>;
00067         <font class="comment">// remove all mipmaps, and convert to DXTC1 (if possible, ie if was DXTC5 or DXTC3 as example)</font>
00068         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>.<a class="code" href="classNLMISC_1_1CBitmap.html#a12">releaseMipMaps</a>();
00069         <font class="comment">// TODODO: consersion to DXTC1</font>
00070         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureEntry.html#m11">CoarseBitmap</a>.<a class="code" href="classNLMISC_1_1CBitmap.html#a4">convertToType</a>(CBitmap::DXTC1);
00071 }
00072 
00073 
00074 <font class="comment">// ***************************************************************************</font>
<a name="l00075"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#a0">00075</a> CAsyncTextureManager::CTextureLod::CTextureLod()
00076 {
00077         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#n0">IsTextureEntry</a>= <font class="keyword">false</font>;
00078 
00079         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m0">TextureEntry</a>= NULL;
00080         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m1">Weight</a>= 0;
00081         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m2">Level</a>= 0;
00082         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m3">Loaded</a>= <font class="keyword">false</font>;
00083         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m4">UpLoaded</a>= <font class="keyword">false</font>;
00084         <a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m5">ExtraSize</a>= 0;
00085 }
00086 
00087 
00088 <font class="comment">// ***************************************************************************</font>
<a name="l00089"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a1">00089</a> CAsyncTextureManager::~CAsyncTextureManager()
00090 {
00091         <font class="comment">// For all remaining textures, delete them.</font>
00092         <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++)
00093         {
00094                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i])
00095                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">deleteTexture</a>(i);
00096         }
00097 
00098         <font class="comment">// there must be no waitting textures, nor map, nor current upload texture</font>
00099         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.empty() &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.empty() &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==NULL 
00100                 &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>==NULL);
00101 }
00102 
00103 <font class="comment">// ***************************************************************************</font>
<a name="l00104"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a0">00104</a> CAsyncTextureManager::CAsyncTextureManager()
00105 {
00106         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>= 3;
00107         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>= 1;
00108         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>= 65536;
00109         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>= 20*1024;
00110         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL;
00111         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>= 10*1024*1024;
00112         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>= 0;
00113         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o6">_LastTextureSizeGot</a>= 0;
00114 
00115         <font class="comment">// Do not share this texture, to force uploading of the lods.</font>
00116         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL;
00117 }
00118 
00119 
00120 <font class="comment">// ***************************************************************************</font>
<a name="l00121"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a2">00121</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::setupLod(uint baseLevel, uint maxLevel)
00122 {
00123         <a class="code" href="debug_8h.html#a6">nlassert</a>(baseLevel&gt;=maxLevel);
00124         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>= baseLevel;
00125         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>= maxLevel;
00126 }
00127 
00128 
00129 <font class="comment">// ***************************************************************************</font>
<a name="l00130"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a3">00130</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::setupMaxUploadPerFrame(uint maxup)
00131 {
00132         <font class="keywordflow">if</font>(maxup&gt;0)
00133                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>= maxup;
00134 }
00135 
00136 <font class="comment">// ***************************************************************************</font>
<a name="l00137"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a4">00137</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::setupMaxHLSColoringPerFrame(uint maxCol)
00138 {
00139         <font class="keywordflow">if</font>(maxCol&gt;0)
00140                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>= maxCol;
00141 }
00142 
00143 <font class="comment">// ***************************************************************************</font>
<a name="l00144"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a5">00144</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::setupMaxTotalTextureSize(uint maxText)
00145 {
00146         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>= maxText;
00147 }
00148 
00149 
00150 <font class="comment">// ***************************************************************************</font>
00151 uint                    CAsyncTextureManager::addTextureRef(<font class="keyword">const</font> string &amp;textNameNotLwr, CMeshBaseInstance *instance)
00152 {
00153         uint    ret;
00154 
00155         <font class="comment">// strlwr name</font>
00156         string  textName= textNameNotLwr;
00157         strlwr(textName);
00158 
00159         <font class="comment">// find the texture in map</font>
00160         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#u1">ItTextureEntryMap</a>       it;
00161         it= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.find(textName);
00162 
00163         <font class="comment">// not found, create.</font>
00164         <font class="keywordflow">if</font>(it==<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.end())
00165         {
00166                 <font class="comment">// search a free id.</font>
00167                 uint    i= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();
00168                 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.empty())
00169                 {
00170                         i= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.back();
00171                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.pop_back();
00172                 }
00173                 <font class="comment">// resize if needed.</font>
00174                 <font class="keywordflow">if</font>(i&gt;=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size())
00175                 {
00176                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.push_back(NULL);
00177                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.reserve(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.capacity());
00178                 }
00179 
00180                 <font class="comment">// alloc new.</font>
00181                 CTextureEntry   *text= <font class="keyword">new</font> CTextureEntry();
00182                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i]= text;
00183                 text-&gt;Texture= <font class="keyword">new</font> CTextureFile;
00184                 <font class="comment">// Do not allow degradation.</font>
00185                 text-&gt;Texture-&gt;setAllowDegradation(<font class="keyword">false</font>);
00186 
00187                 <font class="comment">// add to map.</font>
00188                 it= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.insert(make_pair(textName, i)).first;
00189                 <font class="comment">// bkup the it for deletion</font>
00190                 text-&gt;ItMap= it;
00191 
00192                 <font class="comment">// Start Color or Async loading.</font>
00193                 text-&gt;Texture-&gt;setFileName(textName);
00194                 <font class="comment">// First try with the HLSManager</font>
00195                 sint    colorTextId= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#m0">HLSManager</a>.findTexture(textName);
00196                 <font class="comment">// If found</font>
00197                 <font class="keywordflow">if</font>(colorTextId!=-1)
00198                 {
00199                         <font class="comment">// Mark the texture as Loaded, and ready to colorize (done in update()).</font>
00200                         text-&gt;Loaded= <font class="keyword">true</font>;
00201                         text-&gt;BuildFromHLSManager= <font class="keyword">true</font>;
00202                         text-&gt;HLSManagerTextId= colorTextId;
00203                 }
00204                 <font class="comment">// else must async load it.</font>
00205                 <font class="keywordflow">else</font>
00206                 {
00207                         <font class="comment">// start to load a small DDS version if possible</font>
00208                         text-&gt;Texture-&gt;setMipMapSkipAtLoad(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>);
00209                         <font class="comment">// load it async.</font>
00210                         CAsyncFileManager3D::getInstance().loadTexture(text-&gt;Texture, &amp;text-&gt;Loaded);
00211                 }
00212                 <font class="comment">// Add to a list so we can check each frame if it has ended.</font>
00213                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.push_back(i);
00214         }
00215 
00216         <font class="comment">// get the id of the text entry.</font>
00217         ret= it-&gt;second;
00218 
00219         <font class="comment">// add this instance to the list of ones which use this texture.</font>
00220         CTextureEntry   *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[ret];
00221         text-&gt;Instances.push_back(instance);
00222 
00223         <font class="comment">// if the texture is not yet ready, must increment the instance refCount.</font>
00224         <font class="keywordflow">if</font>(!text-&gt;UpLoaded)
00225                 instance-&gt;_AsyncTextureToLoadRefCount++;
00226 
00227         <font class="keywordflow">return</font> ret;
00228 }
00229 
00230 
00231 <font class="comment">// ***************************************************************************</font>
<a name="l00232"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">00232</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::deleteTexture(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>)
00233 {
00234         CTextureEntry   *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>];
00235 
00236 
00237         <font class="comment">// **** Stop AsyncLoading/UpLoading of main texture.</font>
00238 
00239         <font class="comment">// stop async loading if not ended</font>
00240         <font class="keywordflow">if</font>(!text-&gt;Loaded)
00241         {
00242                 CAsyncFileManager3D::getInstance().cancelLoadTexture(text-&gt;Texture);
00243         }
00244 
00245         <font class="comment">// remove map entry</font>
00246         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o9">_TextureEntryMap</a>.erase(text-&gt;ItMap);
00247 
00248         <font class="comment">// remove in list of waiting textures</font>
00249         vector&lt;uint&gt;::iterator  itWait= find(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.begin(),<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end(), <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00250         <font class="keywordflow">if</font>(itWait!=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end())
00251                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.erase(itWait);
00252 
00253         <font class="comment">// If it was the currently uploaded one, abort</font>
00254         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==text)
00255         {
00256                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL;
00257         }
00258 
00259         <font class="comment">// If not uploaded.</font>
00260         <font class="keywordflow">if</font>(!text-&gt;UpLoaded)
00261         {
00262                 <font class="comment">// For all its remainding instances, dec refcount</font>
00263                 <font class="keywordflow">for</font>(uint i=0;i&lt;text-&gt;Instances.size();i++)
00264                 {
00265                         text-&gt;Instances[i]-&gt;_AsyncTextureToLoadRefCount--;
00266                 }
00267         }
00268 
00269         <font class="comment">// remove from bench</font>
00270         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>-= text-&gt;TotalTextureSizeAsked;
00271 
00272 
00273         <font class="comment">// **** Stop AsyncLoading/UpLoading of HDLod 's texture.</font>
00274 
00275         <font class="comment">// Check if must stop TextureLod loading/uploading.</font>
00276         CTextureLod             *textLod= &amp;text-&gt;HDLod;
00277         <font class="keywordflow">if</font>(textLod==<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>)
00278         {
00279                 <font class="comment">// stop the async loading if not ended.</font>
00280                 <font class="keywordflow">if</font>(!textLod-&gt;Loaded)
00281                 {
00282                         CAsyncFileManager3D::getInstance().cancelLoadTexture(textLod-&gt;Texture);
00283                 }
00284                 <font class="comment">// stop uploading if was me</font>
00285                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==textLod)
00286                 {
00287                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL;
00288                 }
00289                 <font class="comment">// stop loading me.</font>
00290                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL;
00291         }
00292 
00293         <font class="comment">// At last delete texture entry.</font>
00294         <font class="keyword">delete</font> text;
00295         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]= NULL;
00296         <font class="comment">// add a new free id.</font>
00297         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o8">_FreeTextureIds</a>.push_back(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00298 }
00299 
00300 
00301 <font class="comment">// ***************************************************************************</font>
<a name="l00302"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a7">00302</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::releaseTexture(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>, CMeshBaseInstance *instance)
00303 {
00304         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>&lt;<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size());
00305         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]);
00306 
00307         <font class="comment">// find an instance in this texture an remove it.</font>
00308         CTextureEntry   *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>];
00309         uint                    instSize= text-&gt;Instances.size();
00310         <font class="keywordflow">for</font>(uint i=0;i&lt;instSize;i++)
00311         {
00312                 <font class="keywordflow">if</font>(text-&gt;Instances[i]== instance)
00313                 {
00314                         <font class="comment">// Must first release the refCount if the texture is not uploaded</font>
00315                         <font class="keywordflow">if</font>(!text-&gt;UpLoaded)
00316                                 text-&gt;Instances[i]-&gt;_AsyncTextureToLoadRefCount--;
00317                         <font class="comment">// remove it by swapping with last texture</font>
00318                         text-&gt;Instances[i]= text-&gt;Instances[instSize-1];
00319                         text-&gt;Instances.pop_back();
00320                         <font class="comment">// must stop: remove only the first occurence of instance.</font>
00321                         <font class="keywordflow">break</font>;
00322                 }
00323         }
00324 
00325         <font class="comment">// if no more instance occurence, the texture is no more used =&gt; release it.</font>
00326         <font class="keywordflow">if</font>(text-&gt;Instances.empty())
00327         {
00328                 <font class="comment">// do all the good stuff</font>
00329                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c0">deleteTexture</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>);
00330         }
00331 }
00332 
00333 <font class="comment">// ***************************************************************************</font>
<a name="l00334"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a8">00334</a> <font class="keywordtype">bool</font>                    CAsyncTextureManager::isTextureUpLoaded(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>)<font class="keyword"> const</font>
00335 <font class="keyword"></font>{
00336         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>&lt;<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size());
00337         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]);
00338         <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>]-&gt;UpLoaded;
00339 }
00340 
00341 
00342 <font class="comment">// ***************************************************************************</font>
<a name="l00343"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a9">00343</a> <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CBitmap.html">NLMISC::CBitmap</a>   *CAsyncTextureManager::getCoarseBitmap(uint <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>)<font class="keyword"> const</font>
00344 <font class="keyword"></font>{
00345         <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>&gt;=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size())
00346                 <font class="keywordflow">return</font> NULL;
00347         CTextureEntry   *textEntry= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>];
00348         <font class="keywordflow">if</font>(!textEntry)
00349                 <font class="keywordflow">return</font> NULL;
00350 
00351         <font class="comment">// if the textEntry not uploaded, return NULL</font>
00352         <font class="keywordflow">if</font>(!textEntry-&gt;UpLoaded)
00353                 <font class="keywordflow">return</font> NULL;
00354 
00355         <font class="comment">// ok return the CoarseBitmap</font>
00356         <font class="keywordflow">return</font> &amp;textEntry-&gt;CoarseBitmap;
00357 }
00358 
00359 
00360 <font class="comment">// ***************************************************************************</font>
<a name="l00361"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#a10">00361</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::update(IDriver *pDriver)
00362 {
00363         uint    nTotalUploaded = 0;
00364         uint    nTotalColored = 0;
00365 
00366         <font class="comment">// if no texture to upload, get the next one</font>
00367         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>==NULL)
00368                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">getNextTextureToUpLoad</a>(nTotalColored, pDriver);
00369 
00370         <font class="comment">// while some texture to upload</font>
00371         <font class="keywordflow">while</font>(_CurrentUploadTexture)
00372         {
00373                 ITexture        *pText= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>-&gt;<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#m0">Texture</a>;
00374                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c2">uploadTexturePart</a>(pText, pDriver, nTotalUploaded))
00375                 {
00376                         <font class="comment">// Stuff for TextureEntry</font>
00377                         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>-&gt;<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureBase.html#a0">isTextureEntry</a>())
00378                         {
00379                                 uint    i;
00380                                 CTextureEntry   *textEntry= static_cast&lt;CTextureEntry*&gt;(_CurrentUploadTexture);
00381                                 <font class="comment">// If we are here, the texture is finally entirely uploaded. Compile it!</font>
00382                                 textEntry-&gt;UpLoaded= <font class="keyword">true</font>;
00383                                 <font class="comment">// Can Have lod if texture is DXTC and have mipMaps! Also disalbe if system disable it</font>
00384                                 textEntry-&gt;CanHaveLOD= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">validDXTCMipMap</a>(pText) &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>&gt;<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>;
00385                                 <font class="comment">// compute the size it takes in VRAM</font>
00386                                 uint    baseMipMapSize= pText-&gt;getSize(0)*CBitmap::bitPerPixels[pText-&gt;getPixelFormat()]/8;
00387                                 <font class="comment">// full size with mipmap</font>
00388                                 textEntry-&gt;BaseSize= (uint)(baseMipMapSize*1.33f);
00389                                 <font class="comment">// UpLoaded !! =&gt; signal all instances.</font>
00390                                 <font class="keywordflow">for</font>(i=0;i&lt;textEntry-&gt;Instances.size();i++)
00391                                 {
00392                                         textEntry-&gt;Instances[i]-&gt;_AsyncTextureToLoadRefCount--;
00393                                 }
00394 
00395                                 <font class="comment">// Create the coarse bitmap with the text (NB: still in memory here)</font>
00396                                 textEntry-&gt;createCoarseBitmap();
00397 
00398                                 <font class="comment">// If CanHaveLOD, create now the lods entries.</font>
00399                                 <font class="keywordflow">if</font>(textEntry-&gt;CanHaveLOD)
00400                                 {
00401                                         <font class="comment">/* Allow only the MaxLod to be loaded async</font>
00402 <font class="comment">                                                This is supposed to be faster since a fseek is much longer than a texture Read.</font>
00403 <font class="comment">                                                Then it is more intelligent to read only One texture (the High Def), than to try to</font>
00404 <font class="comment">                                                read intermediate ones (512, 256, 128) because this made 3 more fseek.</font>
00405 <font class="comment">                                        */</font>
00406                                         <font class="comment">// create only the MaxLod possible entry</font>
00407                                         CTextureLod             &amp;textLod= textEntry-&gt;HDLod;
00408                                         <font class="comment">// fill textLod</font>
00409                                         textLod.TextureEntry= textEntry;
00410                                         textLod.Level= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>;
00411                                         <font class="comment">// extra size of the lod only (important for LoadBalacing in updateTextureLodSystem())</font>
00412                                         textLod.ExtraSize= textEntry-&gt;BaseSize*(1&lt;&lt;(2*(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o0">_BaseLodLevel</a>-<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o1">_MaxLodLevel</a>))) - textEntry-&gt;BaseSize;
00413                                         <font class="comment">// not yet loaded/upLoaded</font>
00414                                         textLod.Loaded= <font class="keyword">false</font>;
00415                                         textLod.UpLoaded= <font class="keyword">false</font>;
00416                                 }
00417 
00418                                 <font class="comment">// compute texture size for bench</font>
00419                                 textEntry-&gt;TotalTextureSizeAsked= textEntry-&gt;BaseSize + textEntry-&gt;HDLod.ExtraSize;
00420 
00421                                 <font class="comment">// Add texture size to global texture size</font>
00422                                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o5">_TotalTextureSizeAsked</a>+= textEntry-&gt;TotalTextureSizeAsked;
00423                         }
00424                         <font class="comment">// else, stuff for textureLod.</font>
00425                         <font class="keywordflow">else</font>
00426                         {
00427                                 CTextureLod             *textLod= static_cast&lt;CTextureLod*&gt;(_CurrentUploadTexture);
00428                                 <font class="comment">// Swap the uploaded Driver Handle with the Main texture.</font>
00429                                 pDriver-&gt;swapTextureHandle(*textLod-&gt;Texture, *textLod-&gt;TextureEntry-&gt;Texture);
00430                                 <font class="comment">// Flag the Lod.</font>
00431                                 textLod-&gt;UpLoaded= <font class="keyword">true</font>;
00432                                 <font class="comment">// Ok, ended to completly load this textureLod.</font>
00433                                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= NULL;
00434                         }
00435 
00436                         <font class="comment">// finally uploaded in VRAM, can release the RAM texture memory</font>
00437                         pText-&gt;release();
00438 
00439                         <font class="comment">// if not break because can't upload all parts, get next texture to upload</font>
00440                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL;
00441                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">getNextTextureToUpLoad</a>(nTotalColored, pDriver);
00442                 }
00443                 <font class="keywordflow">else</font>
00444                         <font class="comment">// Fail to upload all, abort.</font>
00445                         <font class="keywordflow">return</font>;
00446         }
00447 }
00448 
00449 
00450 <font class="comment">// ***************************************************************************</font>
<a name="l00451"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c2">00451</a> <font class="keywordtype">bool</font>                    CAsyncTextureManager::uploadTexturePart(ITexture *pText, IDriver *pDriver, uint &amp;nTotalUploaded)
00452 {
00453         uint            nMipMap;
00454         nMipMap = pText-&gt;getMipMapCount();
00455 
00456 
00457         <font class="comment">// If this is the start of uploading, setup the texture in driver.</font>
00458         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>==0 &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>==0)
00459         {
00460                 <font class="comment">// If the texture is not a valid DXTC with mipmap</font>
00461                 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">validDXTCMipMap</a>(pText))
00462                 {
00463                         <font class="comment">/* For now, prefer do nothing, because this may be an error (texture not found)</font>
00464 <font class="comment">                                and the texture may not be used at all, so don't take VRAM for nothing.</font>
00465 <font class="comment">                                =&gt; if the texture is used, it will be loaded synchronously by the caller later in the process</font>
00466 <font class="comment">                                =&gt; frame freeze.</font>
00467 <font class="comment">                        */</font>
00468                         <font class="comment">/*</font>
00469 <font class="comment">                        // upload All now.</font>
00470 <font class="comment">                        // MipMap generation and compression may be done here =&gt; Maybe Big Freeze.</font>
00471 <font class="comment">                        // approximate*2 instead of *1.33 for mipmaps.</font>
00472 <font class="comment">                        uint    nWeight = pText-&gt;getSize (0) * 2;</font>
00473 <font class="comment">                        nWeight= (nWeight*CBitmap::bitPerPixels[pText-&gt;getPixelFormat()])/8;</font>
00474 <font class="comment">                        nTotalUploaded+= nWeight;</font>
00475 <font class="comment">                        pDriver-&gt;setupTexture(*pText);</font>
00476 <font class="comment">                        return true;*/</font>
00477                         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00478                 }
00479                 <font class="keywordflow">else</font>
00480                 {
00481                         <font class="comment">// Create the texture only and do not upload anything</font>
00482                         <font class="keywordtype">bool</font> isRel = pText-&gt;getReleasable ();
00483                         pText-&gt;setReleasable (<font class="keyword">false</font>);
00484                         <font class="keywordtype">bool</font> isAllUploaded = <font class="keyword">false</font>;
00485                         <font class="comment">/* Even if the shared texture is still referenced and so still exist in driver, we MUST recreate with good size</font>
00486 <font class="comment">                                the texture. This is important for Texture Memory Load Balancing</font>
00487 <font class="comment">                                (this may means that is used elsewhere than in the CAsyncTextureManager)</font>
00488 <font class="comment">                                Hence: bMustRecreateSharedTexture==true</font>
00489 <font class="comment">                        */</font>
00490                         pDriver-&gt;setupTextureEx (*pText, <font class="keyword">false</font>, isAllUploaded, <font class="keyword">true</font>);
00491                         pText-&gt;setReleasable (isRel);
00492                         <font class="comment">// if the texture is already uploaded, abort partial uploading.</font>
00493                         <font class="keywordflow">if</font> (isAllUploaded)
00494                                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00495                 }
00496         }
00497 
00498 
00499         <font class="comment">// try to upload all mipmap</font>
00500         <font class="keywordflow">for</font>(; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>&lt;nMipMap; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>++)
00501         {
00502                 CRect zeRect;
00503                 uint nMM= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>;
00504 
00505                 <font class="comment">// What is left to upload ?</font>
00506                 uint    nWeight = pText-&gt;getSize (nMM) - <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>*pText-&gt;getWidth(nMM);
00507                 nWeight= (nWeight*CBitmap::bitPerPixels[pText-&gt;getPixelFormat()])/8;
00508 
00509                 <font class="keywordflow">if</font> ((nTotalUploaded  + nWeight) &gt; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>)
00510                 {
00511                         <font class="comment">// We cannot upload the whole mipmap -&gt; we have to cut it</font>
00512                         uint nSizeToUpload = <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a> - nTotalUploaded ;
00513                         uint nLineWeight = (pText-&gt;getWidth(nMM)*CBitmap::bitPerPixels[pText-&gt;getPixelFormat()])/8;
00514                         uint nNbLineToUpload = nSizeToUpload / nLineWeight;
00515                         <font class="comment">// Upload 4 line by 4 line, and upload at leat one 4*line.</font>
00516                         nNbLineToUpload = nNbLineToUpload / 4;
00517                         nNbLineToUpload= max(nNbLineToUpload, 1U);
00518                         nNbLineToUpload *= 4;
00519                         <font class="comment">// comput rect to upload</font>
00520                         uint32 nNewLine = <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> + nNbLineToUpload;
00521                         nNewLine= <a class="code" href="bit__set_8cpp.html#a0">min</a>(nNewLine, pText-&gt;getHeight(nMM));
00522                         zeRect.set (0, <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>, pText-&gt;getWidth(nMM), nNewLine);
00523                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> = nNewLine;
00524                         <font class="comment">// if fill all the mipmap, must go to next</font>
00525                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> == pText-&gt;getHeight(nMM))
00526                         {
00527                                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a> = 0;
00528                                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>++;
00529                         }
00530                 }
00531                 <font class="keywordflow">else</font>
00532                 {
00533                         <font class="comment">// We can upload the whole mipmap (or the whole rest of the mipmap)</font>
00534                         zeRect.set (0, <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>, pText-&gt;getWidth(nMM), pText-&gt;getHeight(nMM));
00535                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>= 0;
00536                 }
00537 
00538                 <font class="comment">// upload the texture </font>
00539                 pDriver-&gt;uploadTexture (*pText, zeRect, (uint8)nMM);
00540 
00541                 nTotalUploaded += nWeight;
00542                 <font class="comment">// If outpass max allocated upload, abort.</font>
00543                 <font class="keywordflow">if</font> (nTotalUploaded &gt; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o2">_MaxUploadPerFrame</a>)
00544                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00545         }
00546 
00547         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00548 }
00549 
00550 
00551 <font class="comment">// ***************************************************************************</font>
<a name="l00552"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c1">00552</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::getNextTextureToUpLoad(uint &amp;nTotalColored, IDriver *pDriver)
00553 {
00554         <font class="comment">// Reset texture uploading</font>
00555         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= NULL;
00556         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o12">_CurrentUploadTextureMipMap</a>= 0;
00557         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o13">_CurrentUploadTextureLine</a>= 0;
00558 
00559         <font class="comment">// Search in WaitingTextures if one has ended async loading</font>
00560         vector&lt;uint&gt;::iterator  it;
00561         <font class="keywordflow">for</font>(it=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.begin();it!=<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.end();it++)
00562         {
00563                 CTextureEntry   *text= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[*it];
00564                 <font class="comment">// If Async loading done.</font>
00565                 <font class="keywordflow">if</font>(text-&gt;Loaded)
00566                 {
00567                         <font class="comment">// Is it a "texture to color" with HLSManager? yes=&gt; color it now.</font>
00568                         <font class="keywordflow">if</font>(text-&gt;BuildFromHLSManager)
00569                         {
00570                                 <font class="comment">// If not beyond the max coloring texture</font>
00571                                 <font class="keywordflow">if</font>(nTotalColored&lt;<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o3">_MaxHLSColoringPerFrame</a>)
00572                                 {
00573                                         <font class="comment">// Build the texture directly in the TextureFile.</font>
00574                                         <a class="code" href="debug_8h.html#a9">nlverify</a>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#m0">HLSManager</a>.buildTexture(text-&gt;HLSManagerTextId, *text-&gt;Texture));
00575                                         <font class="comment">// Must validate the textureFile generation. NB: little weird since this is not really a textureFile.</font>
00576                                         <font class="comment">// But it is the easier way to do it.</font>
00577                                         text-&gt;Texture-&gt;validateGenerateFlag();
00578                                         <font class="comment">// compute the texture size (approx). NB: DXTC5 means 1 pixel==1 byte.</font>
00579                                         uint    size= (uint)(text-&gt;Texture-&gt;getSize(0)*1.33);
00580                                         <font class="comment">// Add it to the num of colorised texture done in current update().</font>
00581                                         nTotalColored+= size;
00582                                 }
00583                                 <font class="comment">// Else must quit and don't update any more texture this frame (_CurrentUploadTexture==NULL)</font>
00584                                 <font class="keywordflow">else</font>
00585                                         <font class="keywordflow">return</font>;
00586                         }
00587 
00588                         <font class="comment">// upload this one</font>
00589                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= text;
00590                         <font class="comment">// remove it from list of waiting textures</font>
00591                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.erase(it);
00592                         <font class="comment">// found =&gt; end.</font>
00593                         <font class="keywordflow">return</font>;
00594                 }
00595         }
00596 
00597         <font class="comment">// If here, and if no more waiting textures, update the Lod system.</font>
00598         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o10">_WaitingTextures</a>.empty())
00599         {
00600                 <font class="comment">// if end to load the current lod.</font>
00601                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a> &amp;&amp; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>-&gt;<a class="code" href="classNL3D_1_1CAsyncTextureManager_1_1CTextureLod.html#m3">Loaded</a>)
00602                 {
00603                         <font class="comment">// upload this one</font>
00604                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o11">_CurrentUploadTexture</a>= <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>;
00605                         <font class="keywordflow">return</font>;
00606                 }
00607 
00608                 <font class="comment">// if no Lod texture currently loading, try to load/unload one</font>
00609                 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a> == NULL)
00610                 {
00611                         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c3">updateTextureLodSystem</a>(pDriver);
00612                 }
00613         }
00614 }
00615 
00616 
00617 <font class="comment">// ***************************************************************************</font>
<a name="l00618"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#f0">00618</a> <font class="keywordtype">bool</font>                    CAsyncTextureManager::validDXTCMipMap(ITexture *pText)
00619 {
00620         <font class="keywordflow">return</font> pText-&gt;getMipMapCount()&gt;1 &amp;&amp; (
00621                 pText-&gt;getPixelFormat() == CBitmap::DXTC1 ||
00622                 pText-&gt;getPixelFormat() == CBitmap::DXTC1Alpha ||
00623                 pText-&gt;getPixelFormat() == CBitmap::DXTC3 ||
00624                 pText-&gt;getPixelFormat() == CBitmap::DXTC5 );
00625 }
00626 
00627 
00628 <font class="comment">// ***************************************************************************</font>
<a name="l00629"></a><a class="code" href="classNL3D_1_1CAsyncTextureManager.html#c3">00629</a> <font class="keywordtype">void</font>                    CAsyncTextureManager::updateTextureLodSystem(IDriver *pDriver)
00630 {
00631         sint    i;
00632 
00633         <font class="comment">// the array to sort</font>
00634         <font class="keyword">static</font>  vector&lt;CTextureLod*&gt;    lodArray;
00635         lodArray.clear();
00636         uint    reserveSize= 0;
00637 
00638         <font class="comment">// for each texture entry compute min distance of use</font>
00639         <font class="comment">//=============</font>
00640         uint    currentBaseSize= 0;
00641         <font class="keywordflow">for</font>(i=0;i&lt;(sint)<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++)
00642         {
00643                 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i])
00644                         <font class="keywordflow">continue</font>;
00645                 CTextureEntry   &amp;text= *<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i];
00646                 <font class="comment">// do it only for Lodable textures</font>
00647                 <font class="keywordflow">if</font>(text.CanHaveLOD)
00648                 {
00649                         text.MinDistance= FLT_MAX;
00650                         <font class="comment">// for all instances.</font>
00651                         <font class="keywordflow">for</font>(uint j=0;j&lt;text.Instances.size();j++)
00652                         {
00653                                 <font class="keywordtype">float</font>   instDist= text.Instances[j]-&gt;getAsyncTextureDistance();
00654                                 text.MinDistance= <a class="code" href="bit__set_8cpp.html#a0">min</a>(text.MinDistance, instDist);
00655                         }
00656 
00657                         <font class="comment">// avoid /0</font>
00658                         text.MinDistance= max(<a class="code" href="async__texture__manager_8cpp.html#a0">NL3D_ATM_MIN_DISTANCE</a>, text.MinDistance);
00659 
00660                         <font class="comment">// how many textLods to add</font>
00661                         reserveSize++;
00662 
00663                         <font class="comment">// the minimum mem size the system take with base lod.</font>
00664                         currentBaseSize+= text.BaseSize;
00665                 }
00666         }
00667         <font class="comment">// reserve space</font>
00668         lodArray.reserve(reserveSize);
00669 
00670 
00671         <font class="comment">// for each texture lod compute weight, and append</font>
00672         <font class="comment">//=============</font>
00673         <font class="keywordflow">for</font>(i=0;i&lt;(sint)<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>.size();i++)
00674         {
00675                 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i])
00676                         <font class="keywordflow">continue</font>;
00677                 CTextureEntry   &amp;text= *<a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o7">_TextureEntries</a>[i];
00678                 <font class="comment">// do it only for Lodable textures</font>
00679                 <font class="keywordflow">if</font>(text.CanHaveLOD)
00680                 {
00681                         <font class="comment">// This Weight is actually a screen Pixel Ratio! (divide by distance)</font>
00682                         CTextureLod     *textLod= &amp;text.HDLod;
00683                         textLod-&gt;Weight= (1&lt;&lt;textLod-&gt;Level) / text.MinDistance;
00684                         <font class="comment">// add to array</font>
00685                         lodArray.push_back(textLod);
00686                 }
00687         }
00688 
00689 
00690         <font class="comment">// sort</font>
00691         <font class="comment">//=============</font>
00692         CPredTextLod    pred;
00693         sort(lodArray.begin(), lodArray.end(), pred);
00694 
00695 
00696         <font class="comment">// Compute lod to load/unload</font>
00697         <font class="comment">//=============</font>
00698         <font class="comment">// Compute Pivot, ie what lods have to be loaded, and what lods do not</font>
00699         uint    pivot= 0;
00700         uint    currentWantedSize= currentBaseSize;
00701         uint    currentLoadedSize= currentBaseSize;
00702         <font class="keywordflow">for</font>(i=lodArray.size()-1;i&gt;=0;i--)
00703         {
00704                 uint    lodSize= lodArray[i]-&gt;ExtraSize;
00705                 currentWantedSize+= lodSize;
00706                 <font class="keywordflow">if</font>(lodArray[i]-&gt;UpLoaded)
00707                         currentLoadedSize+= lodSize;
00708                 <font class="comment">// if &gt; max allowed, stop the pivot here. NB: the pivot is included in the "must load them" part.</font>
00709                 <font class="keywordflow">if</font>(currentWantedSize &gt; <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o4">_MaxTotalTextureSize</a>)
00710                 {
00711                         pivot= i;
00712                         <font class="keywordflow">break</font>;
00713                 }
00714         }
00715         <font class="comment">// continue to count currentLoadedSize</font>
00716         <font class="keywordflow">for</font>(;i&gt;=0;i--)
00717         {
00718                 <font class="keywordflow">if</font>(lodArray[i]-&gt;UpLoaded)
00719                         currentLoadedSize+= lodArray[i]-&gt;ExtraSize;
00720         }
00721         <font class="comment">// save bench.</font>
00722         <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o6">_LastTextureSizeGot</a>= currentLoadedSize;
00723 
00724 
00725         <font class="comment">// if the loadedSize is inferior to the wanted size, we can load a new LOD</font>
00726         CTextureLod             *textLod= NULL;
00727         <font class="keywordtype">bool</font>                    unload;
00728         <font class="keywordflow">if</font>(currentLoadedSize&lt;currentWantedSize)
00729         {
00730                 unload= <font class="keyword">false</font>;
00731                 <font class="comment">// search from end of the list to pivot (included), the first LOD (ie the most important) to load.</font>
00732                 <font class="keywordflow">for</font>(i=lodArray.size()-1;i&gt;=(sint)pivot;i--)
00733                 {
00734                         <font class="keywordflow">if</font>(!lodArray[i]-&gt;UpLoaded)
00735                         {
00736                                 textLod= lodArray[i];
00737                                 <font class="keywordflow">break</font>;
00738                         }
00739                 }
00740                 <font class="comment">// One must have been found, since currentLoadedSize&lt;currentWantedSize</font>
00741                 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod);
00742         }
00743         <font class="keywordflow">else</font>
00744         {
00745                 unload= <font class="keyword">true</font>;
00746                 <font class="comment">// search from start to pivot (exclued), the first LOD (ie the less important) to unload.</font>
00747                 <font class="keywordflow">for</font>(i=0;i&lt;(sint)pivot;i++)
00748                 {
00749                         <font class="keywordflow">if</font>(lodArray[i]-&gt;UpLoaded)
00750                         {
00751                                 textLod= lodArray[i];
00752                                 <font class="keywordflow">break</font>;
00753                         }
00754                 }
00755                 <font class="comment">// it is possible that not found here. It means that All is Ok!!</font>
00756                 <font class="keywordflow">if</font>(textLod==NULL)
00757                         <font class="comment">// no-op.</font>
00758                         <font class="keywordflow">return</font>;
00759         }
00760 
00761 
00762         <font class="comment">// load/unload</font>
00763         <font class="comment">//=============</font>
00764         <font class="keywordflow">if</font>(!unload)
00765         {
00766                 <font class="comment">// create a new TextureFile, with no sharing system.</font>
00767                 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod-&gt;Texture==NULL);
00768                 textLod-&gt;Texture= <font class="keyword">new</font> CTextureFile;
00769                 <font class="comment">// Do not allow degradation.</font>
00770                 textLod-&gt;Texture-&gt;setAllowDegradation(<font class="keyword">false</font>);
00771                 textLod-&gt;Texture-&gt;enableSharing(<font class="keyword">false</font>);
00772                 textLod-&gt;Texture-&gt;setFileName(textLod-&gt;TextureEntry-&gt;Texture-&gt;getFileName());
00773                 textLod-&gt;Texture-&gt;setMipMapSkipAtLoad(textLod-&gt;Level);
00774                 <font class="comment">// setup async loading</font>
00775                 <a class="code" href="classNL3D_1_1CAsyncTextureManager.html#o14">_CurrentTextureLodLoaded</a>= textLod;
00776                 <font class="comment">// load it async.</font>
00777                 CAsyncFileManager3D::getInstance().loadTexture(textLod-&gt;Texture, &amp;textLod-&gt;Loaded);
00778         }
00779         <font class="keywordflow">else</font>
00780         {
00781                 <font class="comment">// Swap now the lod.</font>
00782                 <a class="code" href="debug_8h.html#a6">nlassert</a>(textLod-&gt;Texture!=NULL);
00783                 <font class="comment">// Swap the uploaded Driver Handle with the Main texture (ot get the Ugly one)</font>
00784                 pDriver-&gt;swapTextureHandle(*textLod-&gt;Texture, *textLod-&gt;TextureEntry-&gt;Texture);
00785                 <font class="comment">// Flag the Lod.</font>
00786                 textLod-&gt;UpLoaded= <font class="keyword">false</font>;
00787                 textLod-&gt;Loaded= <font class="keyword">false</font>;
00788                 <font class="comment">// Release completly the texture in driver. (SmartPtr delete)</font>
00789                 textLod-&gt;Texture= NULL;
00790         }
00791 
00792 }
00793 
00794 
00795 
00796 } <font class="comment">// NL3D</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>