aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/mesh__block__manager_8cpp-source.html
blob: 8341c5cca550ddfaae6342728e311d18657c7d90 (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
<!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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</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>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><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="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>
&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="http://www.nevrax.org/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:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>mesh_block_manager.cpp</h1><a href="mesh__block__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="mesh__block__manager_8h.html">3d/mesh_block_manager.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="hierarchical__timer_8h.html">nel/misc/hierarchical_timer.h</a>"</font>
00030 
00031 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00032 
00033 <font class="keyword">namespace </font>NL3D 
00034 {
00035 
00036 
<a name="l00037"></a><a class="code" href="mesh__block__manager_8cpp.html#a0">00037</a> <font class="preprocessor">#define NL3D_MBM_MAX_VBHEAP                     255</font>
<a name="l00038"></a><a class="code" href="mesh__block__manager_8cpp.html#a1">00038</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_MBM_VBHEAP_MESH_SHIFT      8</font>
<a name="l00039"></a><a class="code" href="mesh__block__manager_8cpp.html#a2">00039</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_MBM_VBHEAP_MESH_MASK       0xFFFFFF00</font>
<a name="l00040"></a><a class="code" href="mesh__block__manager_8cpp.html#a3">00040</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_MBM_VBHEAP_HEAP_MASK       0x000000FF</font>
00041 <font class="preprocessor"></font>
00042 
00043 <font class="comment">// ***************************************************************************</font>
<a name="l00044"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#a0">00044</a> CMeshBlockManager::CMeshBlockManager()
00045 {
00046         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.Driver= NULL;
00047         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.Scene= NULL;
00048         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.RenderTrav= NULL;
00049 
00050         <font class="comment">// Allocate at least the 0th heap</font>
00051         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.resize(1);
00052         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[0]= <font class="keyword">new</font> CVBHeapBlock;
00053         <font class="comment">// some reserve, avoiding first reallocation.</font>
00054         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[0]-&gt;RdrInstances.reserve(100);
00055         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[0]-&gt;RdrMeshGeoms.reserve(100);
00056 }
00057 
00058 <font class="comment">// ***************************************************************************</font>
<a name="l00059"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#a1">00059</a> CMeshBlockManager::~CMeshBlockManager()
00060 {
00061         <font class="comment">// must release any user heap.</font>
00062         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#z584_0">releaseVBHeaps</a>();
00063         <font class="comment">// Release the 0th one.</font>
00064         <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[0];
00065         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.clear();
00066 }
00067 
00068 <font class="comment">// ***************************************************************************</font>
<a name="l00069"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#a2">00069</a> <font class="keywordtype">void</font>                    CMeshBlockManager::addInstance(IMeshGeom *meshGeom, CMeshBaseInstance *inst, <font class="keywordtype">float</font> polygonCount)
00070 {
00071         <font class="comment">// If the meshGeom has never been added to the manager, may do some precalc</font>
00072         <font class="keywordflow">if</font>(meshGeom-&gt;_MeshBlockManager==NULL)
00073         {
00074                 <font class="comment">// Fill </font>
00075                 meshGeom-&gt;_MeshBlockManager= <font class="keyword">this</font>;
00076                 <font class="comment">// try to fit the meshGeom in one of our VBHeap.</font>
00077                 <a class="code" href="classNL3D_1_1CMeshBlockManager.html#c0">allocateMeshVBHeap</a>(meshGeom);
00078         }
00079 
00080         <font class="comment">// TestYoyo</font>
00081         <font class="comment">/*extern uint   TEMP_Yoyo_NInstVBHeap;</font>
00082 <font class="comment">        extern uint     TEMP_Yoyo_NInstNoVBHeap;</font>
00083 <font class="comment">        if( meshGeom-&gt;_MeshVBHeapId &amp; NL3D_MBM_VBHEAP_HEAP_MASK )</font>
00084 <font class="comment">                TEMP_Yoyo_NInstVBHeap++; </font>
00085 <font class="comment">        else</font>
00086 <font class="comment">                TEMP_Yoyo_NInstNoVBHeap++;*/</font>
00087         <font class="comment">// End TestYoyo</font>
00088 
00089         <font class="comment">// Choose the HeapBlock to fit in.</font>
00090         CVBHeapBlock    *hb= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[meshGeom-&gt;_MeshVBHeapId &amp; <a class="code" href="mesh__block__manager_8cpp.html#a3">NL3D_MBM_VBHEAP_HEAP_MASK</a>];
00091 
00092         <font class="comment">// If the mesh geom is not added to this manager, add it.</font>
00093         <font class="keywordflow">if</font>(meshGeom-&gt;_RootInstanceId==-1)
00094         {
00095                 hb-&gt;RdrMeshGeoms.push_back(meshGeom);
00096         }
00097 
00098         <font class="comment">// setup the instance.</font>
00099         CInstanceInfo           instInfo;
00100         instInfo.MeshGeom= meshGeom;
00101         instInfo.MBI= inst;
00102         instInfo.PolygonCount= polygonCount;
00103 
00104         <font class="comment">// link to the head of the list.</font>
00105         instInfo.NextInstance= meshGeom-&gt;_RootInstanceId;
00106         meshGeom-&gt;_RootInstanceId= hb-&gt;RdrInstances.size();
00107 
00108         <font class="comment">// add this instance</font>
00109         hb-&gt;RdrInstances.push_back(instInfo);
00110 
00111 }
00112 
00113 <font class="comment">// ***************************************************************************</font>
<a name="l00114"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#a3">00114</a> <font class="keywordtype">void</font>                    CMeshBlockManager::flush(IDriver *drv, CScene *scene, CRenderTrav *renderTrav)
00115 {
00116         uint    i,j;
00117 
00118         <a class="code" href="hierarchical__timer_8h.html#a4">H_AUTO</a>( NL3D_MeshBlockManager );
00119 
00120         <font class="comment">// setup the manager</font>
00121         <a class="code" href="debug_8h.html#a6">nlassert</a>(drv &amp;&amp; scene &amp;&amp; renderTrav);
00122         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.Driver= drv;
00123         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.Scene= scene;
00124         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.RenderTrav= renderTrav;
00125         
00126 
00127         <font class="comment">// render</font>
00128         <font class="comment">//==========</font>
00129 
00130         <font class="comment">// sort by Heap first =&gt; small setup of VBs.</font>
00131         <font class="keywordflow">for</font>(j=0; j&lt;<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.size();j++)
00132         {
00133                 CVBHeapBlock    *hb= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[j];
00134                 <font class="comment">// if not the special 0th heap, must activate VB.</font>
00135                 <font class="keywordflow">if</font>(j==0)
00136                 {
00137                         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.RenderThroughVBHeap= <font class="keyword">false</font>;
00138                 }
00139                 <font class="keywordflow">else</font>
00140                 {
00141                         <font class="comment">// set to true =&gt; avoid mesh to setup their own VB.</font>
00142                         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>.RenderThroughVBHeap= <font class="keyword">true</font>;
00143                         <font class="comment">// activate current VB in driver</font>
00144                         hb-&gt;VBHeap.activate();
00145                 }
00146 
00147 
00148                 <font class="comment">// Always sort by MeshGeom, in this heap</font>
00149                 <font class="keywordflow">for</font>(i=0; i&lt;hb-&gt;RdrMeshGeoms.size();i++)
00150                 {
00151                         <font class="comment">// render the meshGeom and his instances</font>
00152                         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#c1">render</a>(hb-&gt;RdrMeshGeoms[i], hb-&gt;RdrInstances);
00153                 }
00154         }
00155 
00156 
00157         <font class="comment">// reset.</font>
00158         <font class="comment">//==========</font>
00159 
00160         <font class="comment">// For all vb heaps</font>
00161         <font class="keywordflow">for</font>(j=0; j&lt;<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.size();j++)
00162         {
00163                 CVBHeapBlock    *hb= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[j];
00164 
00165                 <font class="comment">// Parse all MehsGeoms, and flag them as Not Added to me</font>
00166                 <font class="keywordflow">for</font>(i=0; i&lt;hb-&gt;RdrMeshGeoms.size();i++)
00167                 {
00168                         hb-&gt;RdrMeshGeoms[i]-&gt;_RootInstanceId= -1;
00169                 }
00170 
00171                 <font class="comment">// clear rdr arrays</font>
00172                 hb-&gt;RdrInstances.clear();
00173                 hb-&gt;RdrMeshGeoms.clear();
00174         }
00175 }
00176 
00177 
00178 <font class="comment">// ***************************************************************************</font>
<a name="l00179"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#c1">00179</a> <font class="keywordtype">void</font>                    CMeshBlockManager::render(IMeshGeom *meshGeom, std::vector&lt;CInstanceInfo&gt; &amp;rdrInstances)
00180 {
00181         <font class="comment">// TestYoyo</font>
00182         <font class="comment">/*extern uint TEMP_Yoyo_NMeshVBHeap;</font>
00183 <font class="comment">        extern uint TEMP_Yoyo_NMeshNoVBHeap;</font>
00184 <font class="comment">        if( _RenderCtx.RenderThroughVBHeap )</font>
00185 <font class="comment">                TEMP_Yoyo_NMeshVBHeap++;</font>
00186 <font class="comment">        else</font>
00187 <font class="comment">                TEMP_Yoyo_NMeshNoVBHeap++;*/</font>
00188         <font class="comment">// End TestYoyo</font>
00189 
00190         <font class="comment">// Start for this mesh.</font>
00191         meshGeom-&gt;beginMesh(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>);
00192 
00193         <font class="comment">// number of renderPasses for this mesh.</font>
00194         uint    numRdrPass= meshGeom-&gt;getNumRdrPasses();
00195 
00196         <font class="comment">// sort per material first?</font>
00197         <font class="keywordflow">if</font>( meshGeom-&gt;sortPerMaterial() )
00198         {
00199                 <font class="comment">// for all material.</font>
00200                 <font class="keywordflow">for</font>(uint rdrPass=0;rdrPass&lt;numRdrPass;rdrPass++)
00201                 {
00202                         <font class="comment">// for all instance.</font>
00203                         sint32  instId= meshGeom-&gt;_RootInstanceId;
00204                         <font class="keywordflow">while</font>( instId!=-1 )
00205                         {
00206                                 CInstanceInfo           &amp;instInfo= rdrInstances[instId];
00207 
00208                                 <font class="comment">// activate this instance</font>
00209                                 meshGeom-&gt;activeInstance(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>, instInfo.MBI, instInfo.PolygonCount);
00210 
00211                                 <font class="comment">// render the pass.</font>
00212                                 meshGeom-&gt;renderPass(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>, instInfo.MBI, instInfo.PolygonCount, rdrPass);
00213 
00214                                 <font class="comment">// next instance</font>
00215                                 instId= instInfo.NextInstance;
00216                         }
00217                 }
00218         }
00219         <font class="comment">// else sort per instance first</font>
00220         <font class="keywordflow">else</font>
00221         {
00222                 <font class="comment">// for all instance.</font>
00223                 sint32  instId= meshGeom-&gt;_RootInstanceId;
00224                 <font class="keywordflow">while</font>( instId!=-1 )
00225                 {
00226                         CInstanceInfo           &amp;instInfo= rdrInstances[instId];
00227 
00228                         <font class="comment">// activate this instance</font>
00229                         meshGeom-&gt;activeInstance(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>, instInfo.MBI, instInfo.PolygonCount);
00230 
00231                         <font class="comment">// for all material.</font>
00232                         <font class="keywordflow">for</font>(uint rdrPass=0;rdrPass&lt;numRdrPass;rdrPass++)
00233                         {
00234                                 <font class="comment">// render the pass.</font>
00235                                 meshGeom-&gt;renderPass(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>, instInfo.MBI, instInfo.PolygonCount, rdrPass);
00236                         }
00237 
00238                         <font class="comment">// next instance</font>
00239                         instId= instInfo.NextInstance;
00240                 }
00241         }
00242 
00243         <font class="comment">// End for this mesh.</font>
00244         meshGeom-&gt;endMesh(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o2">_RenderCtx</a>);
00245 }
00246 
00247 
00248 <font class="comment">// ***************************************************************************</font>
00249 <font class="comment">// ***************************************************************************</font>
00250 <font class="comment">// VBHeap mgt</font>
00251 <font class="comment">// ***************************************************************************</font>
00252 <font class="comment">// ***************************************************************************</font>
00253 
00254 
00255 <font class="comment">// ***************************************************************************</font>
<a name="l00256"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#c0">00256</a> <font class="keywordtype">void</font>                    CMeshBlockManager::allocateMeshVBHeap(IMeshGeom *mesh)
00257 {
00258         <font class="comment">// Get info from mesh. </font>
00259         uint vertexFormat, numVertices;
00260         <font class="comment">// if the mesh do not support VBHeap, quit.</font>
00261         <font class="keywordflow">if</font>( !mesh-&gt;getVBHeapInfo(vertexFormat, numVertices) )
00262                 <font class="keywordflow">return</font>;
00263 
00264         <font class="comment">// In case of ...</font>
00265         <font class="keywordflow">if</font>( numVertices==0 )
00266                 <font class="keywordflow">return</font>;
00267 
00268         <font class="comment">// try to find a VBHeap with this vertexFormat.</font>
00269         TVBHeapMap::iterator    it= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>.find(vertexFormat);
00270         <font class="comment">// if not found, abort</font>
00271         <font class="keywordflow">if</font>(it==<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>.end())
00272                 <font class="keywordflow">return</font>;
00273 
00274         <font class="comment">// access to this VBHeap.</font>
00275         uint    vbHeapId= it-&gt;second;
00276         CVBHeapBlock    *vbHeapBlock= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[vbHeapId];
00277         <font class="comment">// try to allocate sapce into the heap. Fail=&gt; abort.</font>
00278         uint    indexStart;
00279         <font class="keywordflow">if</font>( !vbHeapBlock-&gt;VBHeap.allocate(numVertices, indexStart) )
00280                 <font class="keywordflow">return</font>;
00281 
00282         <font class="comment">// All is Ok here =&gt; setup infos.</font>
00283         <font class="comment">//==================</font>
00284 
00285         <font class="comment">// Keep track of the mesh =&gt; allocate.</font>
00286         uint    meshId;
00287         <font class="comment">// try to get a free id.</font>
00288         <font class="keywordflow">if</font>( !vbHeapBlock-&gt;FreeIds.empty() )
00289         {
00290                 meshId= vbHeapBlock-&gt;FreeIds.back();
00291                 vbHeapBlock-&gt;FreeIds.pop_back();
00292                 vbHeapBlock-&gt;AllocatedMeshGeoms[meshId]= mesh;
00293         }
00294         <font class="comment">// else, must add to the array</font>
00295         <font class="keywordflow">else</font>
00296         {
00297                 meshId= vbHeapBlock-&gt;AllocatedMeshGeoms.size();
00298                 vbHeapBlock-&gt;AllocatedMeshGeoms.push_back(mesh);
00299         }
00300 
00301         <font class="comment">// info for delete in mesh</font>
00302         mesh-&gt;_MeshVBHeapIndexStart= indexStart;
00303         mesh-&gt;_MeshVBHeapId= vbHeapId + (meshId&lt;&lt;<a class="code" href="mesh__block__manager_8cpp.html#a1">NL3D_MBM_VBHEAP_MESH_SHIFT</a>);
00304 
00305 
00306         <font class="comment">// Fill VB.</font>
00307         <font class="comment">//==================</font>
00308         uint8   *dst= vbHeapBlock-&gt;VBHeap.lock(indexStart);
00309         mesh-&gt;computeMeshVBHeap(dst, indexStart);
00310         <font class="comment">// unlock only what vertices have changed (ATI problem)</font>
00311         vbHeapBlock-&gt;VBHeap.unlock(indexStart, indexStart+numVertices);
00312 }
00313 
00314 <font class="comment">// ***************************************************************************</font>
<a name="l00315"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#z584_2">00315</a> <font class="keywordtype">void</font>                    CMeshBlockManager::freeMeshVBHeap(IMeshGeom *mesh)
00316 {
00317         <a class="code" href="debug_8h.html#a6">nlassert</a>(mesh-&gt;_MeshVBHeapId);
00318 
00319         <font class="comment">// unpack heap and mesh id.</font>
00320         uint    vbHeapId= mesh-&gt;_MeshVBHeapId &amp; <a class="code" href="mesh__block__manager_8cpp.html#a3">NL3D_MBM_VBHEAP_HEAP_MASK</a>;
00321         uint    meshId= (mesh-&gt;_MeshVBHeapId &amp; <a class="code" href="mesh__block__manager_8cpp.html#a2">NL3D_MBM_VBHEAP_MESH_MASK</a>) &gt;&gt; <a class="code" href="mesh__block__manager_8cpp.html#a1">NL3D_MBM_VBHEAP_MESH_SHIFT</a>;
00322 
00323         <font class="comment">// access to this VBHeap.</font>
00324         CVBHeapBlock    *vbHeapBlock= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[vbHeapId];
00325 
00326         <font class="comment">// free VB memory.</font>
00327         vbHeapBlock-&gt;VBHeap.free(mesh-&gt;_MeshVBHeapIndexStart);
00328 
00329         <font class="comment">// free this space</font>
00330         <a class="code" href="debug_8h.html#a6">nlassert</a>(meshId&lt;vbHeapBlock-&gt;AllocatedMeshGeoms.size());
00331         vbHeapBlock-&gt;AllocatedMeshGeoms[meshId]= NULL;
00332         vbHeapBlock-&gt;FreeIds.push_back(meshId);
00333 
00334         <font class="comment">// reset mesh info.</font>
00335         mesh-&gt;_MeshVBHeapId= 0;
00336         mesh-&gt;_MeshVBHeapIndexStart= 0;
00337 }
00338 
00339 <font class="comment">// ***************************************************************************</font>
<a name="l00340"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#z584_0">00340</a> <font class="keywordtype">void</font>                    CMeshBlockManager::releaseVBHeaps()
00341 {
00342         uint    i,j;
00343 
00344         <font class="comment">// For all blocks but the 0th</font>
00345         <font class="keywordflow">for</font>(j=1; j&lt;<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.size();j++)
00346         {
00347                 CVBHeapBlock    *hb= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>[j];
00348 
00349                 <font class="comment">// For all allocated mesh of this heap.</font>
00350                 <font class="keywordflow">for</font>(i=0;i&lt;hb-&gt;AllocatedMeshGeoms.size();i++)
00351                 {
00352                         IMeshGeom       *mesh= hb-&gt;AllocatedMeshGeoms[i];
00353                         <font class="comment">// if the mesh exist.</font>
00354                         <font class="keywordflow">if</font>(mesh)
00355                         {
00356                                 <font class="comment">// free his VBHeap Data.</font>
00357                                 <a class="code" href="classNL3D_1_1CMeshBlockManager.html#z584_2">freeMeshVBHeap</a>(mesh);
00358                                 <a class="code" href="debug_8h.html#a6">nlassert</a>( hb-&gt;AllocatedMeshGeoms[i] == NULL );
00359                         }
00360                 }
00361 
00362                 <font class="comment">// delete the block. NB: VBHeap auto released</font>
00363                 <font class="keyword">delete</font> hb;
00364         }
00365 
00366         <font class="comment">// erase all blocks but 0th</font>
00367         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.resize(1);
00368 
00369         <font class="comment">// clear the map.</font>
00370         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>);
00371 }
00372 
00373 <font class="comment">// ***************************************************************************</font>
<a name="l00374"></a><a class="code" href="classNL3D_1_1CMeshBlockManager.html#z584_1">00374</a> <font class="keywordtype">bool</font>                    CMeshBlockManager::addVBHeap(IDriver *drv, uint vertexFormat, uint maxVertices)
00375 {
00376         <font class="comment">// if find an existing vertexFormat, abort.</font>
00377         TVBHeapMap::iterator    it= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>.find(vertexFormat);
00378         <font class="comment">// if found, abort</font>
00379         <font class="keywordflow">if</font>( it!=<a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>.end() )
00380                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00381 
00382         <font class="comment">// create the block</font>
00383         CVBHeapBlock    *hb= <font class="keyword">new</font> CVBHeapBlock;
00384 
00385         <font class="comment">// allocate vertex space</font>
00386         hb-&gt;VBHeap.init(drv, vertexFormat, maxVertices);
00387 
00388         <font class="comment">// add an entry to the array, and the map.</font>
00389         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.push_back(hb);
00390         <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o0">_VBHeapMap</a>[vertexFormat]= <a class="code" href="classNL3D_1_1CMeshBlockManager.html#o1">_VBHeapBlocks</a>.size()-1;
00391 
00392         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00393 }
00394 
00395 
00396 } <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=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>